public void init() { Map<EPackage, Set<Resource>> ePackage2resources = analyzeResources(resources); // Find all EClasses and EPackages in the source Resources printPackage2Resource(ePackage2resources); Map<EModelElement, Set<LeafConstrainingNode>> allConstraints = locateConstraints(ePackage2resources); if (allConstraints != null) { String s = printConstraints(allConstraints); System.out.println("All Constraints\n" + s); } // if (eClasses != null) { // String s = printConstrainingNodes(eClasses); // System.out.println("ConstrainingNodes \n" + s); // } if (allConstraints != null) { createLeafConstrainingNodes(allConstraints); } // if (allConstraints != null) { // String s = printConstraints(allConstraints); // System.out.println("All Constraints\n" + s); // } createResults(resources); sortNodes(rootNode.getConstrainingNodes()); sortNodes(rootNode.getValidatableNodes()); }
/** * Return a new ResultSet object containing an initial result for every enabled combination of * ValidatableNode and ConstrainingNode. Returns null if the creation process was aborted. * * @param monitor * @return */ public /*synchronized*/ @Nullable ResultSet createResultSet(@Nullable IProgressMonitor monitor) { ResultSet resultSet = createResultSet(); List<Result> results = resultSet.getResults(); if (!createResults(results, rootNode.getValidatableNodes(), monitor)) { return null; } else { rootNode.getResultSets().add(resultSet); return resultSet; } }
/** * Return the ConstrainingNode node for EObject creating any parent ConstrainingNodes that are * required to ensure that the returned ConstrainingNode is installed in the root. */ public @NonNull ConstrainingNode getConstrainingNode(@NonNull EObject eObject) { URI uri = getURI(eObject); ConstrainingNode constrainingNode = allConstrainingNodes.get(uri); if (constrainingNode == null) { EObject eContainer = eObject.eContainer(); if (eContainer == null) { RootConstrainingNode rootConstrainingNode = createRootConstrainingNode(); rootNode.getConstrainingNodes().add(rootConstrainingNode); constrainingNode = rootConstrainingNode; } // else if (eObject instanceof EClass) { // constrainingNode = ValidationFactory.eINSTANCE.createLeafConstrainingNode(); // ConstrainingNode parentConstrainingNode = getConstrainingNode(eContainer); // parentConstrainingNode.getChildren().add(constrainingNode); // } else { constrainingNode = createConstrainingNode(); ConstrainingNode parentConstrainingNode = getConstrainingNode(eContainer); parentConstrainingNode.getChildren().add(constrainingNode); } constrainingNode.setConstrainingObject(eObject); constrainingNode.setLabel(validityManager.getLabel(eObject)); constrainingNode.setEnabled(true); allConstrainingNodes.put(uri, constrainingNode); } return constrainingNode; }
/** * Return the ValidatableNode node for EObject creating any ValidatableNodes that are required to * ensure that the returned ValidatableNode is installed in the root. */ protected @NonNull ValidatableNode getValidatableNode(@NonNull EObject eObject) { ValidatableNode validatable = allValidatableNodes.get(eObject); if (validatable == null) { EObject eContainer = eObject.eContainer(); if (eContainer != null) { // ValidatableNode parentValidatableNode = getValidatableNode(eContainer); // parentValidatableNode.getChildren().add(validatable); } else if (eObject instanceof DynamicEObjectImpl) { EClass eClass = eObject.eClass(); for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { String featureName = eStructuralFeature.getName(); if ((featureName != null) && featureName.startsWith( "base_") // org.eclipse.uml2.uml.Extension.METACLASS_ROLE_PREFIX) && (eStructuralFeature instanceof EReference) && eObject.eIsSet( eStructuralFeature)) { // Unset for an applicable stereotype that has not been // applied eContainer = (EObject) eObject.eGet(eStructuralFeature); break; } } } if (eContainer != null) { validatable = createValidatableNode(); ValidatableNode parentValidatableNode = getValidatableNode(eContainer); parentValidatableNode.getChildren().add(validatable); } else { RootValidatableNode rootValidatableNode = createRootValidatableNode(); rootNode.getValidatableNodes().add(rootValidatableNode); validatable = rootValidatableNode; } validatable.setEnabled(true); validatable.setLabel(validityManager.getLabel(eObject)); validatable.setConstrainedObject(eObject); allValidatableNodes.put(eObject, validatable); } return validatable; }