Java Code Examples for org.eclipse.emf.ecore.EClass#isSuperTypeOf()

The following examples show how to use org.eclipse.emf.ecore.EClass#isSuperTypeOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EClassifierInfo.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean addSupertype(EClassifierInfo superTypeInfo) {
	EClass eClass = getEClass();
	EClass superEClass = (EClass) superTypeInfo.getEClassifier();

	if (superEClass.isSuperTypeOf(eClass)) {
		return true;
	}

	if (!isGenerated()) {
		throw new IllegalStateException("Type " + this.getEClassifier().getName()
				+ " is not generated and cannot be modified.");
	}
	if (!(superTypeInfo instanceof EClassInfo)) {
		throw new IllegalArgumentException("superTypeInfo must represent EClass");
	}

	if (eClass.equals(superEClass))
		// cannot add class as it's own superclass
		// this usually happens due to a rule call
		return false;

	return eClass.getESuperTypes().add(superEClass);
}
 
Example 2
Source File: IfcModel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void buildNameIndex() {
	nameIndex = new HashMap<EClass, Map<String, IdEObject>>();
	for (EClassifier classifier : objects.values().iterator().next().eClass().getEPackage().getEClassifiers()) {
		if (classifier instanceof EClass) {
			Map<String, IdEObject> map = new TreeMap<String, IdEObject>();
			nameIndex.put((EClass) classifier, map);
		}
	}
	EClass ifcRootEclass = packageMetaData.getEClass("IfcRoot");
	EStructuralFeature nameFeature = ifcRootEclass.getEStructuralFeature("Name");
	for (Long key : objects.keySet()) {
		IdEObject value = objects.get((Long) key);
		if (ifcRootEclass.isSuperTypeOf(value.eClass())) {
			Object name = value.eGet(nameFeature);
			if (name != null) {
				nameIndex.get(value.eClass()).put((String)name, value);
			}
		}
	}
}
 
Example 3
Source File: ProcessPaletteLabelProviderTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_all_flow_element_classifiers_supported() throws Exception {
    final EClass flowElementEClass = ProcessPackage.Literals.FLOW_ELEMENT;
    for (final EClassifier eClass : ProcessPackage.eINSTANCE.getEClassifiers()) {
        if (eClass instanceof EClass
                && flowElementEClass.isSuperTypeOf((EClass) eClass)
                && !((EClass) eClass).isAbstract()
                && !eClass.equals(flowElementEClass)
                //Should below eClasses be abstract ?
                && !eClass.equals(ProcessPackage.Literals.GATEWAY)
                && !eClass.equals(ProcessPackage.Literals.MESSAGE_EVENT)
                && !eClass.equals(ProcessPackage.Literals.THROW_MESSAGE_EVENT)
                && !eClass.equals(ProcessPackage.Literals.LINK_EVENT)) {
            assertThat(labelProvider.getProcessPaletteText((EClass) eClass)).isNotNull();
            assertThat(labelProvider.getProcessPaletteDescription((EClass) eClass)).isNotNull();
        }
    }
}
 
Example 4
Source File: EClassComparator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int compare(final EClass o1, final EClass o2) {
  if (o1 == o2) { // NOPMD
    return 0;
  } else if (o1 == null) {
    return 1;
  } else if (o2 == null) {
    return -1;
  } else {
    if (isEObjectType(o1) || o1.isSuperTypeOf(o2)) {
      return 1;
    } else if (isEObjectType(o2) || o2.isSuperTypeOf(o1)) {
      return -1;
    }
  }
  return 0;
}
 
Example 5
Source File: ResourceDescription2.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Figure out whether we do export objects of the given type at all.
 *
 * @param type
 *          to check
 * @return {@code true} if this resource description can basically export objects of the given type; {@code false} otherwise.
 */
private boolean isExportedEClass(final EClass type) {
  if (type == EcorePackage.Literals.EOBJECT || !(strategy instanceof AbstractResourceDescriptionStrategy)) {
    // Anything is an EObject; and if it's not one of our strategies, we have no information and must assume we might have a match.
    return true;
  }
  Set<EClass> exportedEClasses = ((AbstractResourceDescriptionStrategy) strategy).getExportedEClasses(getResource());
  if (exportedEClasses == null || exportedEClasses.contains(type)) {
    // If no information is available, assume there might be matching EObjectDescriptions
    // Otherwise, if the type itself is in the set, we don't need to do costly supertype checks.
    return true;
  }
  for (EClass exported : exportedEClasses) {
    if (type.isSuperTypeOf(exported)) {
      return true;
    }
  }
  // We know that this resource description cannot export objects of a matching type.
  return false;
}
 
Example 6
Source File: EmfDriver.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
public Collection<RailwayElement> collectVertices(final String type) throws Exception {
	final Collection<RailwayElement> vertices = new ArrayList<>();

	final EClass clazz = (EClass) RailwayPackage.eINSTANCE.getEClassifier(type);

	final TreeIterator<EObject> contents = container.eAllContents();
	while (contents.hasNext()) {
		final EObject eObject = contents.next();

		// if eObject's type is a descendant of clazz
		if (clazz.isSuperTypeOf(eObject.eClass())) {
			vertices.add((RailwayElement) eObject);
		}
	}

	return vertices;
}
 
Example 7
Source File: NotationClipboardOperationHelper.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Customized Method to find the semantic target which should contain the
 * copied elements.
 * 
 * @param view
 * @param container
 * @return the semantic target.
 */
public static EObject getSemanticPasteTarget(View view, View container) {
	EObject copiedSemanticObject = view.getElement();
	EObject semanticTarget = container.getElement();
	if (copiedSemanticObject instanceof Transition) {
		semanticTarget = copiedSemanticObject.eContainer();
	}
	EList<EReference> eAllReferences = semanticTarget.eClass()
			.getEAllReferences();
	for (EReference eReference : eAllReferences) {
		EClass eReferenceType = eReference.getEReferenceType();
		if (eReference.isContainment()
				&& eReferenceType.isSuperTypeOf(copiedSemanticObject
						.eClass())) {
			return semanticTarget;
		}
	}
	return null;
}
 
Example 8
Source File: IfcModel.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void indexGuid(IdEObject idEObject) {
	EClass ifcRootEclass = packageMetaData.getEClass("IfcRoot");
	EStructuralFeature guidFeature = ifcRootEclass.getEStructuralFeature("GlobalId");
	if (ifcRootEclass.isSuperTypeOf(idEObject.eClass())) {
		Object guid = idEObject.eGet(guidFeature);
		if (guid != null) {
			guidIndexed.put((String)guid, idEObject);
		}
	}
}
 
Example 9
Source File: ModelHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void findAllElementsByNature(final Element element, final List<Element> foundElement,
        final List<EClass> supertypes) {

    for (final EClass eClass : supertypes) {
        if (eClass.isSuperTypeOf(element.eClass())) {
            if (!foundElement.contains(element)) {
                foundElement.add(element);
            }
        }
    }

    if (element instanceof DataAware) {
        for (final Data d : ((DataAware) element).getData()) {
            findAllElementsByNature(d, foundElement, supertypes);
        }
    }

    if (element instanceof AbstractProcess) {
        for (final Connection c : ((AbstractProcess) element).getConnections()) {
            findAllElementsByNature(c, foundElement, supertypes);
        }
    }

    if (element instanceof Container) {
        for (final Element e : ((Container) element).getElements()) {
            findAllElementsByNature(e, foundElement, supertypes);
        }
    }

}
 
Example 10
Source File: ModelHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specifier {@link ElementProcessor} to all instance of eClass
 * in specified model and children
 *
 * @param model
 * @param eClass
 * @param elementProcessor
 */
@SuppressWarnings("unchecked")
public static <T extends EObject> void applyTo(final EObject model, final EClass eClass,
        final ElementProcessor<T> elementProcessor) {
    if (eClass.isSuperTypeOf(model.eClass())) {
        elementProcessor.apply((T) model);
    }
    for (final EObject content : model.eContents()) {
        applyTo(content, eClass, elementProcessor);
    }
}
 
Example 11
Source File: ModelHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void findAllElements(final Element element, final List<Element> elements, final List<EClass> types) {

        for (final EClass eClass : types) {
            if (eClass.isSuperTypeOf(element.eClass())) {
                elements.add(element);
                break;
            }
        }

        if (element instanceof DataAware) {
            for (final Data d : ((DataAware) element).getData()) {
                findAllElements(d, elements, types);
            }
        }
        // boundary
        if (element instanceof Activity) {
            for (final BoundaryEvent b : ((Activity) element).getBoundaryIntermediateEvents()) {
                findAllElements(b, elements, types);
            }
        }

        if (element instanceof AbstractProcess) {
            for (final Connection c : ((AbstractProcess) element).getConnections()) {
                findAllElements(c, elements, types);
            }
        }

        if (element instanceof Container) {
            for (final Element e : ((Container) element).getElements()) {
                findAllElements(e, elements, types);
            }
        }
    }
 
Example 12
Source File: ByteBufferVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ByteBuffer write() throws BimserverDatabaseException {
		EClass eClass = getDatabaseInterface().getEClassForOid(getOid());
		if (!eClass.isSuperTypeOf(eClass())) {
			throw new BimserverDatabaseException("Object with oid " + getOid() + " is a " + eClass().getName() + " but it's cid-part says it's a " + eClass.getName());
		}
		int nrFeatures = getPackageMetaData().getNrDatabaseFeatures(eClass);
		if (featureCounter > nrFeatures) {
			throw new BimserverDatabaseException("Too many features seem to have been set on " + this.eClass.getName() + " " + featureCounter + " / " + nrFeatures);
		} else if (featureCounter < nrFeatures) {
			throw new BimserverDatabaseException("Not all features seem to have been set on " + this.eClass.getName() + " " + featureCounter + " / " + nrFeatures);
		}
		
		if (referencedBuffers != null) {
			for (int startPosition : referencedBuffers.keySet()) {
				ByteBuffer otherBuffer = referencedBuffers.get(startPosition).write();
				buffer.position(startPosition);
				buffer.put(otherBuffer.array(), 0, otherBuffer.position());
			}
		}
		
		buffer.position(buffer.capacity());
		
		return buffer;
//
//		if (buffer.position() != bufferSize) {
//			throw new BimserverDatabaseException("Value buffer sizes do not match for " + eClass().getName() + " " + buffer.position() + "/" + bufferSize);
//		}
//		return buffer;
	}
 
Example 13
Source File: ModelImpl.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public EList<Instance> getAllInstances(EClass eClass) {
	final EList<Instance> instances = new UniqueEList<Instance>();

	for (final Type type : getTypes()) {
		if (eClass.isSuperTypeOf(type.getEClass())) {
			instances.addAll(type.getInstances());
		}
	}

	return instances;
}
 
Example 14
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<Boolean> applyRuleEClassSubtyping(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass candidate, final EClass superClass) throws RuleFailedException {
  /* superClass.isSuperTypeOf(candidate) */
  if (!superClass.isSuperTypeOf(candidate)) {
    sneakyThrowRuleFailedException("superClass.isSuperTypeOf(candidate)");
  }
  return new Result<Boolean>(true);
}
 
Example 15
Source File: HashMapVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setReference(EReference eReference, WrappedVirtualObject wrappedVirtualObject) throws BimserverDatabaseException {
	EClass definedType = (EClass)eReference.getEType();
	EClass referencedEClass = wrappedVirtualObject.eClass();
	if (!definedType.isSuperTypeOf(referencedEClass)) {
		throw new CannotStoreReferenceInFieldException(DeserializerErrorCode.REFERENCED_OBJECT_CANNOT_BE_STORED_IN_THIS_FIELD, "Cannot store a " + referencedEClass.getName() + " in " + eClass().getName() + "." + eReference.getName() + " of type " + definedType.getName());
	}
	map.put(eReference, wrappedVirtualObject);
}
 
Example 16
Source File: ModelHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private static void addAllDataWithType(final DataAware element, final List<Data> datas, final EClass dataType) {
    if (dataType == null) {
        datas.addAll(element.getData());
    } else {
        for (final Data data : element.getData()) {
            if (dataType.isSuperTypeOf(data.getDataType().eClass())) {
                datas.add(data);
            }
        }
    }
}
 
Example 17
Source File: EClassifierInfo.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
    * Determine whether the class represented by {@code left} is either the same as
    * or is a superclass of the class represented by {@code right}.
 */
protected boolean isAssignableFrom(EClass left, EClass right) {
	if (right != null && left.isSuperTypeOf(right))
		return true;
	EClass eObjectType = GrammarUtil.findEObject(grammar);
	if (left == eObjectType)
		return true;
	if (grammar != null) {
		Resource grammarResource = grammar.eResource();
		if (grammarResource != null) {
			ResourceSet resourceSet = grammarResource.getResourceSet();
			if (resourceSet != null) {
				EPackage.Registry registry = resourceSet.getPackageRegistry();
				if (registry != null) {
					EPackage ecorePackage = registry.getEPackage(EcorePackage.eNS_URI);
					if (ecorePackage != null) {
						EClassifier eObjectFromRegistry = ecorePackage.getEClassifier(EcorePackage.Literals.EOBJECT.getName());
						if (left == eObjectFromRegistry) {
							return true;
						}
					}
				}
			}
		}
	}
	if (right != null && left.getInstanceClass() != null && right.getInstanceClass() != null) {
		boolean result = left.getInstanceClass().isAssignableFrom(right.getInstanceClass());
		return result;
	}
	return false;
}
 
Example 18
Source File: STextNamesAreUniqueValidationHelper.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean shouldValidateEClass(EClass eC) {
	return !eC.isSuperTypeOf(SGraphPackage.Literals.STATECHART);
}
 
Example 19
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends IdEObject> T get(IdEObject idEObject, long oid, IfcModelInterface model, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
	checkOpen();
	if (oid == -1) {
		throw new BimserverDatabaseException("Cannot get object for oid " + oid);
	}
	if (objectsToCommit != null && objectsToCommit.containsOid(oid)) {
		return (T) objectsToCommit.getByOid(oid);
	}
	EClass eClass = getEClassForOid(oid);
	if (idEObject != null) {
		if (!eClass.isSuperTypeOf(idEObject.eClass())) {
			throw new BimserverDatabaseException("Object with oid " + oid + " is a " + idEObject.eClass().getName() + " but it's cid-part says it's a " + eClass.getName());
		}
	}
	IdEObjectImpl cachedObject = (IdEObjectImpl) objectCache.get(oid);
	if (cachedObject != null) {
		idEObject = cachedObject;
		if (cachedObject.getLoadingState() == State.LOADED && cachedObject.getRid() != Integer.MAX_VALUE) {
			cachedObject.load();
			return (T) cachedObject;
		}
	}
	ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[12]);
	mustStartWith.putInt(query.getPid());
	mustStartWith.putLong(oid);
	ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[16]);
	startSearchWith.putInt(query.getPid());
	startSearchWith.putLong(oid);
	startSearchWith.putInt(-query.getRid());

	SearchingRecordIterator recordIterator = database.getKeyValueStore().getRecordIterator(eClass.getEPackage().getName() + "_" + eClass.getName(), mustStartWith.array(),
			startSearchWith.array(), this);
	try {
		Record record = recordIterator.next();
		if (record == null) {
			return null;
		}
		reads++;
		ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
		ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
		keyBuffer.getInt(); // pid
		long keyOid = keyBuffer.getLong();
		int keyRid = -keyBuffer.getInt();
		if (keyRid <= query.getRid()) {
			if (idEObject != null && idEObject.getRid() == Integer.MAX_VALUE) {
				((IdEObjectImpl) idEObject).setRid(keyRid);
			}
			if (model.contains(keyOid) && ((IdEObjectImpl) model.get(keyOid)).getLoadingState() == State.LOADED) {
				return (T) model.get(keyOid);
			} else {
				if (valueBuffer.capacity() == 1 && valueBuffer.get(0) == -1) {
					valueBuffer.position(valueBuffer.position() + 1);
					return null;
					// deleted entity
				} else {
					T convertByteArrayToObject = (T) convertByteArrayToObject(idEObject, eClass, eClass, keyOid, valueBuffer, model, keyRid, query, todoList);
					if (convertByteArrayToObject.getRid() == Integer.MAX_VALUE) {
						((IdEObjectImpl) convertByteArrayToObject).setRid(keyRid);
					}
					objectCache.put(oid, convertByteArrayToObject);
					return convertByteArrayToObject;
				}
			}
		} else {
			return null;
		}
	} finally {
		recordIterator.close();
	}
}
 
Example 20
Source File: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns whether the given super type is the same as, or a super type of, some other class.
 * @param superType the super type
 * @param candidate the subtype
 * @return whether the super type is the same as, or a super type of, some other class. Yields <code>null</code>
 * when either argument is <code>null</code>.
 */
public static boolean isAssignableFrom(EClass superType, EClass candidate) {
	if (superType == null || candidate == null) {
		return false;
	}
	return superType == candidate || superType == EcorePackage.Literals.EOBJECT || superType.isSuperTypeOf(candidate);
}