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

The following examples show how to use org.eclipse.emf.ecore.EClass#getEStructuralFeatures() . 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: TypeHierarchyHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void removeFeatures(EClassInfo info, Collection<EStructuralFeature> features, Map<EClass, Collection<EStructuralFeature>> featuresToRemove) {
	EClass clazz = info.getEClass();
	Collection<EStructuralFeature> featuresToBeModified = clazz.getEStructuralFeatures();
	Collection<EStructuralFeature> removeUs = Sets.newLinkedHashSet();
	for (Iterator<EStructuralFeature> iterator = featuresToBeModified.iterator(); iterator.hasNext();) {
		EStructuralFeature feature = iterator.next();
		if (info.containsSemanticallyEqualFeature(features, feature) == FindResult.FeatureExists)
			removeUs.add(feature);
	}
	if (!removeUs.isEmpty() ) {
		Collection<EStructuralFeature> prevRemoveUs = featuresToRemove.get(clazz);
		if (prevRemoveUs == null) {
			featuresToRemove.put(clazz, removeUs);
		} else {
			prevRemoveUs.addAll(removeUs);
		}
	}

}
 
Example 2
Source File: Step0001.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
	public void migrate(Schema schema, DatabaseSession databaseSession) {
		schema.loadEcore("ifc2x3_tc1.ecore", getClass().getResourceAsStream("IFC2X3_TC1.ecore"));
		for (EClassifier eClassifier : schema.getEPackage("ifc2x3tc1").getEClassifiers()) {
			if (eClassifier instanceof EClass) {
				EClass eClass = (EClass)eClassifier;
				for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
					if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
						// A hack because unfortunately not every "Name" field inherits from IfcRoot.Name, same could be true for GlobalId
						if (eStructuralFeature.getName().equals("Name") || eStructuralFeature.getName().equals("GlobalId")) {
//							System.out.println(eClass.getName() + "." + eStructuralFeature.getName());
							schema.addIndex(eStructuralFeature);
						}
					}
				}
			}
		}
	}
 
Example 3
Source File: StringRepresentation.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected String stringRepForEObject(EObject eObject) {
	EClass eClass = eObject.eClass();
	EStructuralFeature nameFeature = eClass.getEStructuralFeature("name");
	String stringRepEClass = stringRep(eClass);
	if (nameFeature != null) {
		Object eGet = eObject.eGet(nameFeature);
		return withType(stringRepEClass, string(eGet));
	}
	EList<EStructuralFeature> eStructuralFeatures = eClass
			.getEStructuralFeatures();
	for (EStructuralFeature feature : eStructuralFeatures) {
		String rep = stringRepForEStructuralFeature(eObject, stringRepEClass, feature);
		if (rep != null) {
			return rep;
		}
	}

	return stringRepEClass;
}
 
Example 4
Source File: TransformUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets structural features whose type is {@link org.eclipse.emf.ecore.EEnum} unsettable.
 *
 * @param source
 *          the class whose features are inspected and made unsettable if the type is EEnum
 */
public static void setEEnumsUnsettable(final EClass source) {
  for (final EStructuralFeature feature : source.getEStructuralFeatures()) {
    if (feature.getEType() instanceof EEnum) {
      feature.setUnsettable(true);
    }
  }
}
 
Example 5
Source File: IfcSchemaToJson.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void convert(OutputStream outputStream, File docs, EPackage ePackage) throws IOException {
	IfcDoc ifcDoc = null;
	if (docs != null) {
		ifcDoc = new IfcDoc(docs);
	}
	
	ObjectMapper objectMapper = new ObjectMapper();
	ObjectNode root = objectMapper.createObjectNode();
	ObjectNode classes = objectMapper.createObjectNode();
	root.set("classes", classes);
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		ObjectNode classifierNode = objectMapper.createObjectNode();
		classes.set(eClassifier.getName(), classifierNode);
		if (eClassifier instanceof EEnum) {
			
		} else if (eClassifier instanceof EClass) {
			EClass eClass = (EClass)eClassifier;
			String domain = "geometry";
			if (ifcDoc != null) {
				domain = ifcDoc.getDomain(eClass.getName());
			}
			classifierNode.put("domain", domain);
			ArrayNode superClassesNode = objectMapper.createArrayNode();
			classifierNode.set("superclasses", superClassesNode);
			
			for (EClass superClass : eClass.getESuperTypes()) {
				superClassesNode.add(superClass.getName());
			}

			ObjectNode fieldsNode = objectMapper.createObjectNode();
			classifierNode.set("fields", fieldsNode);
			for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
				ObjectNode fieldNode = objectMapper.createObjectNode();
				fieldsNode.set(eStructuralFeature.getName(), fieldNode);
				fieldNode.put("type", convertType(eStructuralFeature.getEType()));
				fieldNode.put("reference", eStructuralFeature instanceof EReference);
				fieldNode.put("many", eStructuralFeature.isMany());
				fieldNode.put("inverse", eStructuralFeature.getEAnnotation("inverse") != null);
			}
		}
	}
	objectMapper.writerWithDefaultPrettyPrinter().writeValue(outputStream, root);
}