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

The following examples show how to use org.eclipse.emf.ecore.EClass#getEStructuralFeature() . 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: IfcModel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void buildGuidIndex() {
	guidIndex = new HashMap<EClass, Map<String, IdEObject>>();
	if (objects.isEmpty()) {
		return;
	}
	for (EClassifier classifier : objects.values().iterator().next().eClass().getEPackage().getEClassifiers()) {
		if (classifier instanceof EClass) {
			Map<String, IdEObject> map = new TreeMap<String, IdEObject>();
			guidIndex.put((EClass) classifier, map);
		}
	}
	EClass ifcRootEclass = packageMetaData.getEClass("IfcRoot");
	EStructuralFeature guidFeature = ifcRootEclass.getEStructuralFeature("GlobalId");
	for (Long key : objects.keySet()) {
		IdEObject value = objects.get((Long) key);
		if (ifcRootEclass.isSuperTypeOf(value.eClass())) {
			Object guid = value.eGet(guidFeature);
			if (guid != null) {
				guidIndex.get(value.eClass()).put((String)guid, value);
			}
		}
	}
}
 
Example 2
Source File: IfcStepStreamingSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 6 votes vote down vote up
private void writeEmbedded(HashMapWrappedVirtualObject eObject) throws SerializerException, IOException {
	EClass class1 = eObject.eClass();
	print(packageMetaData.getUpperCase(class1));
	print(OPEN_PAREN);
	EStructuralFeature structuralFeature = class1.getEStructuralFeature(WRAPPED_VALUE);
	if (structuralFeature != null) {
		Object realVal = eObject.eGet(structuralFeature);
		if (structuralFeature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) {
			EStructuralFeature asStringFeature = eObject.eClass().getEStructuralFeature(structuralFeature.getName() + "AsString");
			String asString = (String) eObject.eGet(asStringFeature);
			writeDoubleValue((Double)realVal, asString, structuralFeature);
		} else {
			IfcParserWriterUtils.writePrimitive(realVal, printWriter);
		}
	}
	print(CLOSE_PAREN);
}
 
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: HiddensTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(HiddenTerminalsTestLanguageStandaloneSetup.class);
	EPackage pack = HiddenTerminalsTestLanguagePackage.eINSTANCE;
	withoutHiddens = (EClass) pack.getEClassifier("WithoutHiddens");
	withHiddens = (EClass) pack.getEClassifier("WithHiddens");
	datatypeHiddens = (EClass) pack.getEClassifier("DatatypeHiddens");
	overridingHiddens = (EClass) pack.getEClassifier("OverridingHiddens");
	overridingHiddensCall = (EClass) pack.getEClassifier("OverridingHiddensCall");
	inheritingHiddens = (EClass) pack.getEClassifier("InheritingHiddens");
	inheritingHiddensCall = (EClass) pack.getEClassifier("InheritingHiddensCall");
	model = (EClass) pack.getEClassifier("Model");
	spacesWithoutHiddens = withoutHiddens.getEStructuralFeature("spaces");
	valid = model.getEStructuralFeature("valid");
	overridingValid = overridingHiddensCall.getEStructuralFeature("valid");
	inheritingValid = inheritingHiddensCall.getEStructuralFeature("valid");
	inheritingCall = inheritingHiddens.getEStructuralFeature("called");
	overridingCall = overridingHiddens.getEStructuralFeature("called");
}
 
Example 5
Source File: FeatureFinderUtil.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.0
 */
public static EStructuralFeature getFeature(AbstractElement grammarElement, EClass owner) {
	Preconditions.checkNotNull(owner);
	if (grammarElement == null)
		return null;
	String featureName = null;
	if (grammarElement instanceof Action)
		featureName = ((Action) grammarElement).getFeature();
	else {
		Assignment ass = GrammarUtil.containingAssignment(grammarElement);
		if (ass != null)
			featureName = ass.getFeature();
	}
	if (featureName != null)
		return owner.getEStructuralFeature(featureName);
	return null;
}
 
Example 6
Source File: ToEcoreTrafoTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testConcreteLanguageToMetamodel() throws Exception {
	XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.', '/') + ".xtext");
	Grammar element = (Grammar) r.getContents().get(0);
	List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
	assertEquals("Number of lexer-rules in Grammar", 9, lexerRules.size());
	List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
	EPackage metaModel = list.get(0);
	assertNotNull(metaModel);
	assertNotNull(metaModel.getNsPrefix());
	assertNotNull(metaModel.getNsURI());
	assertNotNull(metaModel.getName());
	EList<EClassifier> types = metaModel.getEClassifiers();
	EClass type = (EClass) types.get(1);
	EStructuralFeature feature = type.getEStructuralFeature("elements");
	assertNotNull(feature.getEType());
}
 
Example 7
Source File: AssertStructureAcceptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertElement(String name) {
	if (stack.isEmpty())
		return;
	EClass type = stack.peek().eClass();
	if (type.getEStructuralFeature(name) == null) {
		throw new IllegalStateException("No feature '" + name + "' in EClass " + type.getName());
	}
}
 
Example 8
Source File: ParserTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(TerminalRulesTestLanguageStandaloneSetup.class);
	EPackage pack = TerminalRulesTestLanguagePackage.eINSTANCE;
	EClass model = (EClass) pack.getEClassifier("Model");
	idFeature = model.getEStructuralFeature("idValue");
	intFeature = model.getEStructuralFeature("intValue");
	stringFeature = model.getEStructuralFeature("stringValue");
	richStringFeature = model.getEStructuralFeature("richStringValue");
	mlCommentFeature = model.getEStructuralFeature("mlCommentValue");
	slCommentFeature = model.getEStructuralFeature("slCommentValue");
	wsFeature = model.getEStructuralFeature("wsValue");
	anyOtherFeature = model.getEStructuralFeature("anyValue");
}
 
Example 9
Source File: SerializationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(DatatypeRulesTestLanguageStandaloneSetup.class);
	pack = DatatypeRulesTestLanguagePackage.eINSTANCE;
	factory = pack.getEFactoryInstance();
	compositeModelClass = (EClass) pack.getEClassifier("CompositeModel");
	modelClass = (EClass) pack.getEClassifier("Model");
	modelFeature = compositeModelClass.getEStructuralFeature("model");
	idFeature = modelClass.getEStructuralFeature("id");
	valueFeature = modelClass.getEStructuralFeature("value");
}
 
Example 10
Source File: ParserTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(DatatypeRulesTestLanguageStandaloneSetup.class);
	EPackage pack = DatatypeRulesTestLanguagePackage.eINSTANCE;
	EClass model = (EClass) pack.getEClassifier("Model");
	idFeature = model.getEStructuralFeature("id");
	valueFeature = model.getEStructuralFeature("value");
	vectorFeature = model.getEStructuralFeature("vector");
	dotsFeature = model.getEStructuralFeature("dots");
	EClass compositeModel = (EClass) pack.getEClassifier("CompositeModel");
	modelFeature = compositeModel.getEStructuralFeature("model");
}
 
Example 11
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void subtypeThrowException(final String _error, final String _issue, final Exception _ex, final EClass left, final EClass right, final ErrorInformation[] _errorInformations) throws RuleFailedException {
  String _name = left.getName();
  String _plus = (_name + " is not a subtype of ");
  String _name_1 = right.getName();
  String _plus_1 = (_plus + _name_1);
  String error = _plus_1;
  EObject source = left;
  EStructuralFeature _eStructuralFeature = left.getEStructuralFeature("name");
  EStructuralFeature feature = _eStructuralFeature;
  throwRuleFailedException(error,
  	_issue, _ex, new ErrorInformation(source, feature));
}
 
Example 12
Source File: GrammarUtil.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static EReference getReference(CrossReference ref, EClass referenceOwner) {
	final String feature = GrammarUtil.containingAssignment(ref).getFeature();
	EStructuralFeature result = referenceOwner.getEStructuralFeature(feature);
	if (result instanceof EReference && !((EReference) result).isContainment())
		return (EReference) result;
	return null;
}
 
Example 13
Source File: SemanticNodeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected SemanticNode add(String featureName, INode child, SemanticNode last) {
	if (featureName == null)
		return last;
	EClass eClass = this.semanticObject.eClass();
	EStructuralFeature feature = eClass.getEStructuralFeature(featureName);
	if (feature == null)
		return last;
	SemanticNode sem = new SemanticNode(child);
	if (last != null) {
		last.follower = sem;
	}
	if (this.first == null) {
		this.first = sem;
	}
	int id = eClass.getFeatureID(feature);
	if (feature.isMany()) {
		@SuppressWarnings("unchecked")
		List<SemanticNode> nodes = (List<SemanticNode>) childrenByFeatureIDAndIndex[id];
		if (nodes == null)
			childrenByFeatureIDAndIndex[id] = nodes = Lists.<SemanticNode>newArrayList();
		nodes.add(sem);
	} else {
		childrenByFeatureIDAndIndex[id] = sem;
	}
	if (feature instanceof EReference) {
		EReference reference = (EReference) feature;
		if (reference.isContainment()) {
			EObject semanitcChild = getSemanticChild(child);
			if (semanitcChild != null) {
				if (this.childrenBySemanticChild == null)
					this.childrenBySemanticChild = Maps.newHashMap();
				this.childrenBySemanticChild.put(semanitcChild, sem);
			}
		}
	}
	return sem;
}
 
Example 14
Source File: MaterializingBackwardConverter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected EStructuralFeature resolveFeature(EStructuralFeature feature) {
	final EClass sourceClass = feature.getEContainingClass();
	final EClass targetClass = resolveEClass(sourceClass);
	return targetClass.getEStructuralFeature(feature.getName());
}
 
Example 15
Source File: ConcreteSyntaxConstraintProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EStructuralFeature getAssignmentFeature(EClass clazz) {
	String name = getAssignmentName();
	EStructuralFeature f = clazz.getEStructuralFeature(name);
	if (f == null)
		throw new RuntimeException("Feature " + name + " not found for " + clazz.getName());
	return f;
}
 
Example 16
Source File: CrossReferenceTemplateVariableResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected EReference getReference(String eClassName, String eReferenceName, Grammar grammar) {
	EClass eClass = (EClass) getEClassifierForGrammar(eClassName, grammar);
	if (eClass != null) {
		return (EReference) eClass.getEStructuralFeature(eReferenceName);
	}
	return null;
}
 
Example 17
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void subtypeThrowException(final String _error, final String _issue, final Exception _ex, final EClass left, final EClass right, final ErrorInformation[] _errorInformations) throws RuleFailedException {
  String _name = left.getName();
  String _plus = (_name + " is not a subtype of ");
  String _name_1 = right.getName();
  String _plus_1 = (_plus + _name_1);
  String error = _plus_1;
  EObject source = left;
  EStructuralFeature _eStructuralFeature = left.getEStructuralFeature("name");
  EStructuralFeature feature = _eStructuralFeature;
  throwRuleFailedException(error,
  	_issue, _ex, new ErrorInformation(source, feature));
}
 
Example 18
Source File: BimServer.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateUserPlugin(DatabaseSession session, User user, PluginDescriptor pluginDescriptor, PluginContext pluginContext) throws BimserverDatabaseException {
	if (pluginDescriptor.isInstallForNewUsers()) {
		UserSettings userSettings = user.getUserSettings();
		if (userSettings == null) {
			userSettings = session.create(UserSettings.class);
			user.setUserSettings(userSettings);
			session.store(user);
		}
		
		Class<?> pluginInterface = getPluginInterface(pluginContext.getPlugin().getClass());
		String originalPluginInterfaceName = pluginInterface.getSimpleName();
		String pluginInterfaceName = pluginInterface.getSimpleName();
		if (pluginInterfaceName.endsWith("Plugin")) {
			pluginInterfaceName = pluginInterfaceName.substring(0, pluginInterfaceName.length() - 6);
		}
		
		if (pluginInterfaceName.equals("StreamingSerializer")) {
			pluginInterfaceName = "Serializer";
		} else if (pluginInterfaceName.equals("MessagingStreamingSerializer")) {
			pluginInterfaceName = "MessagingSerializer";
		}

		if (pluginInterfaceName.equals("StreamingDeserializer")) {
			pluginInterfaceName = "Deserializer";
		}
		
		if (pluginInterfaceName.equals("ModelChecker") || pluginInterfaceName.equals("WebModule")) {
			// ModelChecker and WebModule are not coupled to UserSettings but to
			// ServerSettings
			return;
		}
		
		EClass userSettingsClass = StorePackage.eINSTANCE.getUserSettings();
		String listRefName = StringUtils.firstLowerCase(pluginInterfaceName) + "s";
		if (listRefName.equals("messagingSerializers")) {
			listRefName = "serializers";
		}
		EReference listReference = (EReference) userSettingsClass.getEStructuralFeature(listRefName);
		if (listReference == null) {
			LOGGER.warn(listRefName + " not found");
			return;
		}
		EReference defaultReference = (EReference) userSettingsClass.getEStructuralFeature("default" + pluginInterfaceName);
		EClass pluginConfigurationClass = (EClass) StorePackage.eINSTANCE.getEClassifier((pluginInterfaceName.equals("Service") ? "Internal" : "") + pluginInterfaceName + "PluginConfiguration");
		
		List<PluginConfiguration> list = (List<PluginConfiguration>) userSettings.eGet(listReference);
		PluginConfiguration pluginConfiguration = find(list, pluginContext.getIdentifier());
		if (pluginConfiguration == null) {
			pluginConfiguration = (PluginConfiguration) session.create(pluginConfigurationClass);
			if (pluginConfiguration instanceof SerializerPluginConfiguration) {
				boolean streaming = originalPluginInterfaceName.equals("StreamingSerializerPlugin") || originalPluginInterfaceName.equals("MessagingStreamingSerializerPlugin");
				((SerializerPluginConfiguration) pluginConfiguration).setStreaming(streaming);
			} else if (pluginConfiguration instanceof InternalServicePluginConfiguration) {
				((InternalServicePluginConfiguration)pluginConfiguration).setUserSettings(userSettings);
			}

			list.add(pluginConfiguration);
			genericPluginConversion(pluginContext, session, pluginConfiguration, pluginDescriptor);
		}

		if (pluginInterfaceName.equals("Service")) {
			activateService(user.getOid(), (InternalServicePluginConfiguration) pluginConfiguration);
		}
		
		if (defaultReference != null) {
			if (userSettings.eGet(defaultReference) == null && pluginInterfaceName.contentEquals("RenderEngine")) {
				PluginDescriptor defaultRenderEnginePlugin = getServerSettingsCache().getServerSettings().getDefaultRenderEnginePlugin();
				if (defaultRenderEnginePlugin != null && pluginDescriptor.getOid() == defaultRenderEnginePlugin.getOid()) {
					LOGGER.info("Setting default render engine for user " + user.getUsername() + " to " + defaultRenderEnginePlugin.getName());
					userSettings.eSet(defaultReference, pluginConfiguration);
				}
			}
		}
		
		session.store(userSettings);
	}
}
 
Example 19
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);
			// }
		}
	}
}
 
Example 20
Source File: AbstractScopeNameProvider.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns the default name to be used if no names were returned by {@link #internalGetNameFunctions(EClass)}. This implementation returns a
 * name function corresponding to the "name" feature if present. If not an exception is raised. Subclasses may override this
 * method.
 *
 * @param type
 *          type to return default name for
 * @return default name functions
 */
protected Iterable<INameFunction> getDefaultNames(final EClass type) {
  final EStructuralFeature nameFeature = type.getEStructuralFeature("name"); //$NON-NLS-1$
  if (nameFeature != null) {
    return NameFunctions.fromFeatures(nameFeature);
  }

  throw new IllegalArgumentException("unknown type: " + type); //$NON-NLS-1$
}