Пример #1
0
 protected String printConstraints(
     @NonNull Map<EModelElement, Set<LeafConstrainingNode>> allConstraints) {
   StringBuilder s = new StringBuilder();
   ArrayList<EModelElement> sortedList = new ArrayList<EModelElement>(allConstraints.keySet());
   //		Collections.sort(sortedList, new Comparator<EClassifier>()
   //		{
   //			public int compare(EClassifier o1, EClassifier o2) {
   //				return o1.getName().compareTo(o2.getName());
   //			}
   //		});
   for (@SuppressWarnings("null") @NonNull EModelElement eObject : sortedList) {
     Set<LeafConstrainingNode> constraints = allConstraints.get(eObject);
     if ((constraints != null) && (constraints.size() > 0)) {
       LeafConstrainingNode firstConstraint = constraints.iterator().next();
       ConstraintLocator constraintLocator = firstConstraint.getConstraintLocator();
       s.append("\t");
       s.append(constraintLocator.getLabel(eObject));
       s.append(":");
       for (ConstrainingNode constraint : constraints) {
         s.append(" \'" + constraint.getLabel() + "'");
       }
     }
     s.append("\n");
   }
   return s.toString();
 }
Пример #2
0
 private @NonNull URI getURI(@NonNull EObject eObject) {
   ConstraintLocator constraintLocator = ValidityManager.getConstraintLocator(eObject);
   if (constraintLocator != null) {
     URI uri = constraintLocator.getURI(eObject);
     if (uri != null) {
       return uri;
     }
   }
   return EcoreUtil.getURI(eObject);
 }
Пример #3
0
 /** 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;
 }
Пример #4
0
 //
 //	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;
 }
Пример #5
0
 //
 //	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;
 }