public void testGetAllSuperTypesWithCycle() { EClass a = createEClass("a"); EClass b = createEClass("b"); b.getESuperTypes().add(a); a.getESuperTypes().add(b); // inconsistent and quasi-unpredictable in complex scenarios due to caching assertTrue(a.getEAllSuperTypes().contains(a)); assertFalse(b.getEAllSuperTypes().contains(b)); // always stable assertTrue(EcoreUtil2.getAllSuperTypes(a).contains(a)); assertTrue(EcoreUtil2.getAllSuperTypes(b).contains(b)); }
/** @{inheritDoc */ public boolean isEnable(IPaletteEntryProxy entryProxy) { PaletteEntry entry = entryProxy.getEntry(); // check unicity if (entryProxy instanceof IPaletteAspectToolEntryProxy) { List<IPostAction> postActions = ((IPaletteAspectToolEntryProxy) entryProxy).getPostActions(); for (IPostAction action : postActions) { if (action instanceof AssociationEndPostAction) { return false; } } } // check meta-element is an association if (entry instanceof CombinedTemplateCreationEntry) { EClass eClass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry); List<EClass> superClasses = eClass.getEAllSuperTypes(); if (ASSOCIATION.equals(eClass.getName())) { return true; } for (EClass superClass : superClasses) { if (ASSOCIATION.equals(superClass.getName())) { return true; } } } return false; }
/** * Test if a possibleSub eclass is a sub eclass * * @param aclass, cannot be null * @param possibleSubClasse, cannot be null * @return true if possible eclass is a subtype of a eclass or false */ public boolean isSubClass(EClassifier aclass, EClass possibleSubClasse) { if (aclass.equals(possibleSubClasse)) { return true; } EList<EClass> superTypeList = possibleSubClasse.getEAllSuperTypes(); if (superTypeList.contains(aclass)) { return true; } return false; }
public boolean isSubClass( org.eclipse.emf.ecore.EClass subClassCandidate, org.eclipse.emf.ecore.EClass superClass) { for (org.eclipse.emf.ecore.EClass superClassCandidate : subClassCandidate.getEAllSuperTypes()) { // There seem to be multiple instances of meta classes when accessed through the // generator model. Therefore, we compare by name. if (namesAndPackageURIsAreEqual(superClassCandidate, superClass)) { return true; } } return false; }
private boolean isOnActivity() { // we can't use the isSuperTypeOF directly on EClass because they belong of different model // version. // So compare only the name final String activityEclassName = ProcessPackage.Literals.ACTIVITY.getName(); if (activityEclassName.equals(containerType.getName())) { return true; } for (EClass superType : containerType.getEAllSuperTypes()) { if (activityEclassName.equals(superType.getName())) { return true; } } return false; }
public static List<EClass> getSubClasses(EClass parentClass) { List<EClass> classList = new ArrayList<EClass>(); EList<EClassifier> classifiers = Bpmn2Package.eINSTANCE.getEClassifiers(); for (EClassifier classifier : classifiers) { if (classifier instanceof EClass) { EClass clazz = (EClass) classifier; clazz.getEAllSuperTypes().contains(parentClass); if (parentClass.isSuperTypeOf(clazz) && !clazz.isAbstract()) { classList.add(clazz); } } } return classList; }
/** * Returns <code>true</code> if specified class contains 'visible' attribute. * * @param clazz * @return */ static boolean contanisVisibleElement(EClass clazz) { boolean contains = hasVisibleElementSet.contains(clazz.getName()); if (contains) { return true; } EList<EClass> supers = clazz.getEAllSuperTypes(); if (supers.size() > 0) { for (EClass eSuper : supers) { contains = hasVisibleElementSet.contains(eSuper.getName()); if (contains) { return true; } } } return contains; }
static EPackage resolvePackage(EClass contextEClass, String name) { EPackage result = null; if (name.equals(contextEClass.getEPackage().getName())) { // the easy case result = contextEClass.getEPackage(); } else { // search the superclass hierarchy for a matching package for (EClass next : contextEClass.getEAllSuperTypes()) { if (name.equals(next.getEPackage().getName())) { result = next.getEPackage(); break; } } } return result; }
private void findReferencedPackages(EClassifier classifier) { if (classifier instanceof EClass == false) { return; } EClass cls = (EClass) classifier; for (EClass superClass : cls.getEAllSuperTypes()) { referenced(superClass); } for (EReference ref : cls.getEAllReferences()) { EClassifier type = ref.getEType(); if (type != null) { referenced(type); } } }
public static synchronized List<EclDocCommand> getAllPublicCommands() { if (commands != null) return commands; commands = new ArrayList<EclDocCommand>(); commandsByName = new HashMap<String, EclDocCommand>(); for (Object o : EPackage.Registry.INSTANCE.values().toArray()) { try { if (o instanceof EPackage.Descriptor) o = ((EPackage.Descriptor) o).getEPackage(); if (!(o instanceof EPackage)) continue; EPackage p = (EPackage) o; for (EClassifier classifier : p.getEClassifiers()) { if (!(classifier instanceof EClass)) continue; EClass class_ = (EClass) classifier; if (class_.isAbstract() || !class_.getEAllSuperTypes().contains(COMMAND)) continue; EclDocCommand command = new EclDocCommand(class_); if (command.isInternal() || command.isExcluded()) continue; if (commandsByName.containsKey(command.getName())) continue; commands.add(command); commandsByName.put(command.getName(), command); } } catch (Exception e) { EclDocPlugin.err("Failed to load documentation from: " + o, e); } } Collections.sort( commands, new Comparator<EclDocCommand>() { public int compare(EclDocCommand a, EclDocCommand b) { return a.getName().compareTo(b.getName()); } }); return commands; }
// // 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; }