Java Code Examples for org.eclipse.emf.ecore.EcorePackage#eINSTANCE()

The following examples show how to use org.eclipse.emf.ecore.EcorePackage#eINSTANCE() . 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: EClassInfoTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testContainsCompatibleFeature_01() throws Exception {
	EcorePackage pack = EcorePackage.eINSTANCE;
	EClass eClass = pack.getEClass();
	EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
	assertEquals(true,objectUnderTest.containsCompatibleFeature("name", false, true, pack.getEString(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEString(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEAnnotation(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEShort(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("names", false, true, pack.getEString(), new StringBuilder()));
	
	assertEquals(true,objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEAttribute(), new StringBuilder()));
	assertEquals(true,objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEReference(), new StringBuilder()));
	assertEquals(true,objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEStructuralFeature(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("eStructuralFeatures", false, true, pack.getEStructuralFeature(), new StringBuilder()));
	assertEquals(false,objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEAnnotation(), new StringBuilder()));
}
 
Example 2
Source File: Bug419429SemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
	EPackage epackage = semanticObject.eClass().getEPackage();
	ParserRule rule = context.getParserRule();
	Action action = context.getAssignedAction();
	Set<Parameter> parameters = context.getEnabledBooleanParameters();
	if (epackage == EcorePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePackage.EREFERENCE:
			sequence_EReference(context, (EReference) semanticObject); 
			return; 
		}
	if (errorAcceptor != null)
		errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
 
Example 3
Source File: EClassInfoTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void testChangeable(){
	EcorePackage pack = EcorePackage.eINSTANCE;
	EClass eClass = pack.getEClass();
	EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
	EcoreFactory fac = EcoreFactory.eINSTANCE;
	EReference reference = fac.createEReference();
	reference.setName("newReference");
	reference.setEType(eClass);
	reference.setChangeable(true);
	reference.setContainment(true);
	eClass.getEStructuralFeatures().add(reference);
	assertEquals(true,objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
	reference.setChangeable(false);
	assertEquals(false,objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
}
 
Example 4
Source File: EClassInfoTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testContainsCompatibleFeature_02() throws Exception {
	EcorePackage pack = EcorePackage.eINSTANCE;
	EClass attribute = pack.getEAttribute();
	EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(attribute, false, Collections.<String>emptySet(), null);
	assertEquals(true, objectUnderTest.containsCompatibleFeature("lowerBound", false, true, pack.getEInt(), new StringBuilder()));
	assertEquals(true, objectUnderTest.containsCompatibleFeature("lowerBound", false, true, pack.getEIntegerObject(), new StringBuilder()));
	assertEquals(false, objectUnderTest.containsCompatibleFeature("lowerBound", false, true, pack.getELong(), new StringBuilder()));
}
 
Example 5
Source File: TransformUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Maps Ecore type names to the corresponding Ecore object instance.
 *
 * @param ecoreTypeName
 *          The name of the Ecore primitive type to be mapped to its
 *          instance. Permitted values are EString, EInt, EIntegerObject, EBoolean, EBooleanObject, EChar,
 *          ELong, EShort, EDouble, EDate, EFloat.
 *          Note that the use of EBooleanObject is discouraged, since we want to avoid 3-states logic.
 * @return the corresponding EDataType instance if permitted ecoreTypeName,
 *         else null
 */
public static Object mapType(final String ecoreTypeName) {
  if (ecoreTypeName == null) {
    return null;
  }
  final EcorePackage ecorePkg = EcorePackage.eINSTANCE;
  if ("EString".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEString();
  } else if ("EInt".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEInt();
  } else if ("EIntegerObject".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEIntegerObject();
  } else if ("EBoolean".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEBoolean();
  } else if ("EBooleanObject".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEBooleanObject();
  } else if ("EChar".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEChar();
  } else if ("ELong".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getELong();
  } else if ("EShort".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEShort();
  } else if ("EDouble".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEDouble();
  } else if ("EDate".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEDate();
  } else if ("EFloat".equals(ecoreTypeName)) { //$NON-NLS-1$
    return ecorePkg.getEFloat();
  } else {
    return null;
  }
}
 
Example 6
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public Express2EMF(File schemaFileName, String modelName, String nsUri) {
	schema = new SchemaLoader(schemaFileName.getAbsolutePath()).getSchema();
	eFactory = EcoreFactory.eINSTANCE;
	ePackage = EcorePackage.eINSTANCE;
	schemaPack = eFactory.createEPackage();
	try {
		new DerivedReader(schemaFileName, schema);
	} catch (FileNotFoundException e) {
		LOGGER.error("", e);
	}
	schemaPack.setName(modelName);
	schemaPack.setNsPrefix("iai");
	schemaPack.setNsURI(nsUri);

	createTristate();

	addClasses();
	addSupertypes();
	addSimpleTypes();
	addDerivedTypes();
	addEnumerations();
	addHackedTypes();
	addSelects();
	addAttributes();
	addInverses();
	EClass ifcBooleanClass = (EClass) schemaPack.getEClassifier("IfcBoolean");
	ifcBooleanClass.getESuperTypes().add((EClass) schemaPack.getEClassifier("IfcValue"));
	doRealDerivedAttributes();
	clean();
}
 
Example 7
Source File: PartialSerializationTestLanguageSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
	EPackage epackage = semanticObject.eClass().getEPackage();
	ParserRule rule = context.getParserRule();
	Action action = context.getAssignedAction();
	Set<Parameter> parameters = context.getEnabledBooleanParameters();
	if (epackage == EcorePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePackage.ECLASS:
			sequence_EClassDecl(context, (EClass) semanticObject); 
			return; 
		}
	else if (epackage == PartialSerializationTestLanguagePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case PartialSerializationTestLanguagePackage.CHILD_WITH_SUB_CHILD:
			sequence_ChildWithSubChild(context, (ChildWithSubChild) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.CHILD_WITH_SUB_CHILDS:
			sequence_ChildWithSubChilds(context, (ChildWithSubChilds) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.ECLASS_REF:
			sequence_EClassRef(context, (EClassRef) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.IMPORT:
			sequence_Import(context, (Import) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MANDATORY_CHILD:
			sequence_MandatoryChild(context, (MandatoryChild) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MANDATORY_CHILD_LIST:
			sequence_MandatoryChildList(context, (MandatoryChildList) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MANDATORY_VALUE:
			sequence_MandatoryValue(context, (MandatoryValue) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MANY_MANDATORY_VALUES:
			sequence_ManyMandatoryValues(context, (ManyMandatoryValues) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MANY_VALUES:
			sequence_ManyOptionalValues(context, (ManyValues) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.MODEL:
			sequence_Model(context, (Model) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.NODE:
			sequence_Node(context, (Node) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD:
			sequence_OptionalChild(context, (OptionalChild) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD_LIST:
			sequence_OptionalChildList(context, (OptionalChildList) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.OPTIONAL_VALUE:
			sequence_OptionalValue(context, (OptionalValue) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.SUB_CHILD:
			sequence_SubChild(context, (SubChild) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.TWO_CHILD_LISTS:
			sequence_TwoChildLists(context, (TwoChildLists) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.TWO_CHILDS:
			sequence_TwoChilds(context, (TwoChilds) semanticObject); 
			return; 
		case PartialSerializationTestLanguagePackage.WITH_TRANSIENT_CONTAINER:
			sequence_WithTransientContainer(context, (WithTransientContainer) semanticObject); 
			return; 
		}
	else if (epackage == WithtransientPackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case WithtransientPackage.WITH_TRANSIENT:
			sequence_WithTransient(context, (WithTransient) semanticObject); 
			return; 
		}
	if (errorAcceptor != null)
		errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
 
Example 8
Source File: EcoreReferenceTestLanguageSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
	EPackage epackage = semanticObject.eClass().getEPackage();
	ParserRule rule = context.getParserRule();
	Action action = context.getAssignedAction();
	Set<Parameter> parameters = context.getEnabledBooleanParameters();
	if (epackage == EcorePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePackage.EATTRIBUTE:
			sequence_EAttribute(context, (EAttribute) semanticObject); 
			return; 
		case EcorePackage.EOBJECT:
			sequence_EObject(context, (EObject) semanticObject); 
			return; 
		}
	else if (epackage == EcorePerNsURIPackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePerNsURIPackage.EXTENDS_NS_URIE_OBJECT:
			sequence_ExtendsNsURIEObject(context, (ExtendsNsURIEObject) semanticObject); 
			return; 
		case EcorePerNsURIPackage.MY_EATTRIBUTE:
			sequence_MyEAttribute(context, (EAttribute) semanticObject); 
			return; 
		}
	else if (epackage == EcorePerPlatformPluginPackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePerPlatformPluginPackage.EXTENDS_PLUGIN_EOBJECT:
			sequence_ExtendsPluginEObject(context, (ExtendsPluginEObject) semanticObject); 
			return; 
		}
	else if (epackage == EcorePerPlatformResourcePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcorePerPlatformResourcePackage.EXTENDS_RESOURCE_EOBJECT:
			sequence_ExtendsResourceEObject(context, (ExtendsResourceEObject) semanticObject); 
			return; 
		}
	else if (epackage == EcoreReferencePackage.eINSTANCE)
		switch (semanticObject.eClass().getClassifierID()) {
		case EcoreReferencePackage.MODEL:
			sequence_Model(context, (Model) semanticObject); 
			return; 
		case EcoreReferencePackage.MY_NAMED_ELEMENT_01:
			sequence_Unused_01(context, (MyNamedElement_01) semanticObject); 
			return; 
		case EcoreReferencePackage.MY_NAMED_ELEMENT_02:
			sequence_Unused_02(context, (MyNamedElement_02) semanticObject); 
			return; 
		case EcoreReferencePackage.MY_NAMED_ELEMENT_03:
			sequence_Unused_03(context, (MyNamedElement_03) semanticObject); 
			return; 
		}
	if (errorAcceptor != null)
		errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
 
Example 9
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addTwoDimensionalArray(String entityName, String attribName) {
	EClassifier finalType = null;
	if (entityName.equals("IfcBSplineSurface") && attribName.equals("ControlPointsList")) {
		finalType = schemaPack.getEClassifier("IfcCartesianPoint");
	} else if (entityName.equals("IfcCartesianPointList3D") && attribName.equals("CoordList")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcColourRgbList") && attribName.equals("ColourList")) {
		finalType = schemaPack.getEClassifier("IfcNormalisedRatioMeasure");
	} else if (entityName.equals("IfcIndexedTriangleTextureMap") && attribName.equals("TexCoordIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcRationalBSplineSurfaceWithKnots") && attribName.equals("WeightsData")) {
		finalType = EcorePackage.eINSTANCE.getEDouble();
	} else if (entityName.equals("IfcStructuralLoadConfiguration") && attribName.equals("Locations")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcTessellatedFaceSet") && attribName.equals("Normals")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTextureVertexList") && attribName.equals("TexCoordsList")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("CoordIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcCartesianPointList2D") && attribName.equals("CoordList")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcIndexedPolygonalFaceWithVoids") && attribName.equals("InnerCoordIndices")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("Normals")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("NormalIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else {
		throw new RuntimeException("Unimplemented " + entityName + "." + attribName);
	}
	EClass containerClass = (EClass) schemaPack.getEClassifier("ListOf" + finalType.getName());
	if (containerClass == null) {
		containerClass = EcoreFactory.eINSTANCE.createEClass();
		containerClass.setName("ListOf" + finalType.getName());

		if (finalType.getEPackage() == EcorePackage.eINSTANCE) {
			EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute();
			finalAttribute.setName("List");
			finalAttribute.setEType(finalType);
			finalAttribute.setUpperBound(-1);
			containerClass.getEAttributes().add(finalAttribute);
			
			if (finalType == EcorePackage.eINSTANCE.getEDouble()) {
				EAttribute stringAttribute = EcoreFactory.eINSTANCE.createEAttribute();
				stringAttribute.setName("ListAsString");
				stringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
				stringAttribute.setUpperBound(-1);
				containerClass.getEAttributes().add(stringAttribute);
			}
		} else {
			EReference finalReference = EcoreFactory.eINSTANCE.createEReference();
			finalReference.setName("List");
			finalReference.setEType(finalType);
			finalReference.setUpperBound(-1);
			containerClass.getEReferences().add(finalReference);
		}

		schemaPack.getEClassifiers().add(containerClass);
	}
	
	EReference eReference = EcoreFactory.eINSTANCE.createEReference();
	eReference.getEAnnotations().add(createTwoDimensionalArrayAnnotation());
	eReference.setName(attribName);
	eReference.setUpperBound(-1);
	eReference.setEType(containerClass);
	
	EClass cls = (EClass) schemaPack.getEClassifier(entityName);
	cls.getEStructuralFeatures().add(eReference);
}