/** Return all types that may provode constraints to an instance if aType. */ protected @NonNull Set<URI> getTypeClosure(@NonNull EModelElement aType) { Set<URI> typeClosure = typeClosures.get(aType); if (typeClosure == null) { typeClosure = new HashSet<URI>(); List<ConstraintLocator> constraintLocators = ValidityManager.getConstraintLocators(aType.eClass().getEPackage().getNsURI()); if (constraintLocators != null) { for (ConstraintLocator constraintLocator : constraintLocators) { typeClosure.addAll(constraintLocator.getAllTypes(aType)); } } typeClosures.put(aType, typeClosure); } return typeClosure; }
// // Find all constraints for each EClass // protected Map<EModelElement, Set<LeafConstrainingNode>> locateConstraints( @NonNull Map<EPackage, Set<Resource>> ePackage2resources) { Map<EModelElement, Set<LeafConstrainingNode>> allConstraints = new HashMap<EModelElement, Set<LeafConstrainingNode>>(); for (@SuppressWarnings("null") @NonNull EPackage ePackage : ePackage2resources.keySet()) { List<ConstraintLocator> list = ValidityManager.getConstraintLocators(ePackage.getNsURI()); if (list != null) { @SuppressWarnings("null") @NonNull Set<Resource> ePackageResources = ePackage2resources.get(ePackage); for (ConstraintLocator constraintLocator : list) { try { Map<EModelElement, List<LeafConstrainingNode>> availableConstraints = constraintLocator.getConstraints(this, ePackage, ePackageResources); if (availableConstraints != null) { assert !availableConstraints.containsKey(null); for (EModelElement constrainedType : availableConstraints.keySet()) { Set<LeafConstrainingNode> typeConstraints = allConstraints.get(constrainedType); if (typeConstraints == null) { typeConstraints = new HashSet<LeafConstrainingNode>(); allConstraints.put(constrainedType, typeConstraints); } typeConstraints.addAll(availableConstraints.get(constrainedType)); } } } catch (Exception e) { Set<ConstraintLocator> badConstraintLocators2 = badConstraintLocators; if (badConstraintLocators2 == null) { synchronized (this) { badConstraintLocators = badConstraintLocators2 = new HashSet<ConstraintLocator>(); } } if (!badConstraintLocators2.contains(constraintLocator)) { synchronized (badConstraintLocators2) { if (badConstraintLocators2.add(constraintLocator)) { logger.error("ConstraintLocator " + constraintLocator + " failed", e); } } } } } } } return allConstraints; }
// // Find all EPackages in the source Resources // protected @NonNull Map<EPackage, Set<Resource>> analyzeResources( @NonNull Collection<Resource> resources) { List<Resource> allResources = new ArrayList<Resource>(resources); Map<EPackage, Set<Resource>> ePackage2resources = new HashMap<EPackage, Set<Resource>>(); for (int i = 0; i < allResources.size(); i++) { Resource resource = allResources.get(i); System.out.println(i + "/" + allResources.size() + " analyzeResources " + resource.getURI()); // System.out.println(resource); Set<EClass> eClasses = new HashSet<EClass>(); for (TreeIterator<EObject> tit = resource.getAllContents(); tit.hasNext(); ) { @SuppressWarnings("null") @NonNull EObject eObject = tit.next(); @SuppressWarnings("null") @NonNull EClass eClass = eObject.eClass(); eClasses.add(eClass); } Set<EPackage> ePackages = new HashSet<EPackage>(); for (@SuppressWarnings("null") @NonNull EClass eClass : eClasses) { ePackages.add(eClass.getEPackage()); for (@SuppressWarnings("null") @NonNull EClass eSuperClass : eClass.getEAllSuperTypes()) { ePackages.add(eSuperClass.getEPackage()); } } for (@SuppressWarnings("null") @NonNull EPackage ePackage : ePackages) { Set<Resource> ePackageResources = ePackage2resources.get(ePackage); if (ePackageResources == null) { ePackageResources = new HashSet<Resource>(); ePackage2resources.put(ePackage, ePackageResources); } ePackageResources.add(resource); List<ConstraintLocator> list = ValidityManager.getConstraintLocators(ePackage.getNsURI()); if (list != null) { for (ConstraintLocator constraintLocator : list) { try { Collection<Resource> moreResources = constraintLocator.getImports(ePackage, resource); if (moreResources != null) { for (Resource anotherResource : moreResources) { if (!allResources.contains(anotherResource)) { allResources.add(anotherResource); } } } } catch (Exception e) { Set<ConstraintLocator> badConstraintLocators2 = badConstraintLocators; if (badConstraintLocators2 == null) { synchronized (this) { badConstraintLocators = badConstraintLocators2 = new HashSet<ConstraintLocator>(); } } if (!badConstraintLocators2.contains(constraintLocator)) { synchronized (badConstraintLocators2) { if (badConstraintLocators2.add(constraintLocator)) { logger.error("ConstraintLocator " + constraintLocator + " failed", e); } } } } } } } } return ePackage2resources; }