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

The following examples show how to use org.eclipse.emf.ecore.EClass#getEAllSuperTypes() . 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
/**
    * Determine whether the class represented by {@code left} is either the same as
    * or is a superclass of the class represented by {@code right} comparing the classifier ID
    * and namespace URI.
 */
private boolean isAssignableByID(EClass left, EClass right) {
	if (left.getEPackage() != null) {
		// Compare namespace URI and classifier Id
		if (left.getClassifierID() == right.getClassifierID()
				&& right.getEPackage() != null
				&& left.getEPackage().getNsURI().equals(right.getEPackage().getNsURI())) {
			return true;
		}
		// Check all supertypes of the right class
		for (EClass superClass : right.getEAllSuperTypes()) {
			if (left.getClassifierID() == superClass.getClassifierID()
					&& superClass.getEPackage() != null
					&& left.getEPackage().getNsURI().equals(superClass.getEPackage().getNsURI())) {
				return true;
			}
		}
	}
	return false;
}
 
Example 2
Source File: ChartExtensionValueUpdater.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: LazyExtentMap.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/** Initialize the map. */
private void init() {
	delegate = new HashMap<EClass, Set<Instance>>();
	for (final Type type : model.getTypes()) {
		final EClass clazz = type.getEClass();
		final EList<EClass> types = new UniqueEList<EClass>(clazz.getEAllSuperTypes());
		types.add(clazz);
		for (final EClass t : types) {
			Set<Instance> instances = delegate.get(t);
			if (instances == null) {
				instances = new HashSet<Instance>();
				delegate.put(t, instances);
			}
			instances.addAll(type.getInstances());
		}
	}
}
 
Example 4
Source File: SampleTemplateGenerator.java    From M2Doc with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the sample template {@link XWPFDocument}. The returned {@link XWPFDocument} should be {@link XWPFDocument#close() closed} by the
 * caller.
 * 
 * @param variableName
 *            the variable name
 * @param eCls
 *            the variable {@link EClass}
 * @return the created sample template {@link XWPFDocument}
 * @throws IOException
 *             if the sample template can't be read
 * @throws InvalidFormatException
 *             if the sample template can't be read
 */
@SuppressWarnings("resource")
public XWPFDocument generate(String variableName, EClass eCls) throws InvalidFormatException, IOException {
    final InputStream is = SampleTemplateGenerator.class.getResourceAsStream("/resources/sampleTemplate.docx");
    final OPCPackage pkg = OPCPackage.open(is);

    String featureName = eCls.getEAllAttributes().get(0).getName();
    for (EAttribute attribute : eCls.getEAllAttributes()) {
        if (attribute.getEType() == EcorePackage.eINSTANCE.getEString()) {
            featureName = attribute.getName();
            break;
        }
    }

    final StringBuilder builder = new StringBuilder();
    final byte[] buffer = new byte[BUFFER_SIZE];
    final PackagePart part = pkg.getPart(PackagingURIHelper.createPartName("/word/document.xml"));
    try (InputStream partIS = part.getInputStream()) {
        int nbBytes = partIS.read(buffer);
        while (nbBytes != -1) {
            builder.append(new String(buffer, 0, nbBytes));
            nbBytes = partIS.read(buffer);
        }
    }
    String xml = builder.toString().replace(VARIABLE_NAME_TAG, variableName);
    xml = xml.replace(FEATURE_NAME_TAG, featureName);

    try (OutputStream partOS = part.getOutputStream()) {
        partOS.write(xml.getBytes("UTF-8"));
    }

    final XWPFDocument res = new XWPFDocument(pkg);

    final TemplateCustomProperties customProperties = new TemplateCustomProperties(res);
    customProperties.setM2DocVersion(M2DocUtils.VERSION);
    customProperties.getVariables().put(variableName, eCls.getEPackage().getName() + "::" + eCls.getName());
    final Set<String> packages = new LinkedHashSet<>();
    packages.add(eCls.getEPackage().getNsURI());
    for (EClass superCls : eCls.getEAllSuperTypes()) {
        packages.add(superCls.getEPackage().getNsURI());
    }
    customProperties.getPackagesURIs().addAll(packages);
    customProperties.save();

    return res;
}
 
Example 5
Source File: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static List<EClass> getCompatibleTypesOf(EClass eClass) {
	List<EClass> ca = new ArrayList<EClass>(eClass.getEAllSuperTypes());
	ca.add(eClass);
	return ca;
}
 
Example 6
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void doRealDerivedAttributes() {
	for (EntityDefinition entityDefinition : schema.getEntities()) {
		for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) {
			EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName());
			// EStructuralFeature derivedAttribute =
			// eFactory.createEReference();
			if (attributeName.getType() != null && !attributeName.hasSuper()) {
				// if (attributeName.getType() instanceof EntityDefinition)
				// {
				// derivedAttribute.setEType(schemaPack.getEClassifier(((EntityDefinition)
				// attributeName.getType()).getName()));
				// } else if (attributeName.getType() instanceof
				// IntegerType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcInteger"));
				// } else if (attributeName.getType() instanceof RealType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcReal"));
				// } else if (attributeName.getType() instanceof
				// LogicalType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcLogical"));
				if (attributeName.getType() instanceof DefinedType) {
					EClassifier eType = schemaPack.getEClassifier(((DefinedType) attributeName.getType()).getName());
					boolean found = false;
					for (EClass eSuperType : eClass.getEAllSuperTypes()) {
						if (eSuperType.getEStructuralFeature(attributeName.getName()) != null) {
							found = true;
							break;
						}
					}
					if (eType.getEAnnotation("wrapped") != null) {
						if (!found) {
							EAttribute eAttribute = eFactory.createEAttribute();
							eAttribute.setDerived(true);
							eAttribute.setName(attributeName.getName());
							if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
								eAttribute.setUpperBound(3);
								eAttribute.setUnique(false);
							}
							EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
							eAttribute.setEType(type);
							eAttribute.setUnsettable(true); // TODO find out
															// if its
															// optional
							eClass.getEStructuralFeatures().add(eAttribute);
							if (type == EcorePackage.eINSTANCE.getEDouble()) {
								EAttribute doubleStringAttribute = eFactory.createEAttribute();
								doubleStringAttribute.setName(attributeName.getName() + "AsString");
								doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
								doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
								doubleStringAttribute.setUnsettable(true); // TODO
																			// find
																			// out
																			// if
																			// its
																			// optional
								doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
								eClass.getEStructuralFeatures().add(doubleStringAttribute);
							}
						}
					} else {
						if (!found) {
							EReference eReference = eFactory.createEReference();
							eReference.setName(attributeName.getName());
							eReference.setDerived(true);
							eReference.setUnsettable(true);
							eReference.setEType(eType);
							eClass.getEStructuralFeatures().add(eReference);
						}
					}
					// derivedAttribute.setEType(eType);
				}
			}
			// derivedAttribute.setName(attributeName.getName());
			// derivedAttribute.setDerived(true);
			// derivedAttribute.setTransient(true);
			// derivedAttribute.setVolatile(true);
			// if (attributeName.isCollection()) {
			// derivedAttribute.setUpperBound(-1);
			// }
			// EAnnotation annotation = eFactory.createEAnnotation();
			// annotation.setSource("http://www.iso.org/iso10303-11/EXPRESS");
			// annotation.getDetails().put("code",
			// attributeName.getExpressCode());
			// derivedAttribute.getEAnnotations().add(annotation);
			// if (eClass.getEStructuralFeature(derivedAttribute.getName())
			// == null) {
			// eClass.getEStructuralFeatures().add(derivedAttribute);
			// }
		}
	}
}