Java Code Examples for org.eclipse.emf.ecore.EClassifier#getEPackage()

The following examples show how to use org.eclipse.emf.ecore.EClassifier#getEPackage() . 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
public static String fqn(final EClassifier it) {
  String _xifexpression = null;
  EPackage _ePackage = it.getEPackage();
  String _uniqueName = null;
  if (_ePackage!=null) {
    _uniqueName=UniqueNameUtil.uniqueName(_ePackage);
  }
  boolean _tripleEquals = (_uniqueName == null);
  if (_tripleEquals) {
    _xifexpression = Ecore2XtextExtensions.quoteIfNeccesary(it.getName());
  } else {
    String _uniqueName_1 = UniqueNameUtil.uniqueName(it.getEPackage());
    String _plus = (_uniqueName_1 + "::");
    String _quoteIfNeccesary = Ecore2XtextExtensions.quoteIfNeccesary(it.getName());
    _xifexpression = (_plus + _quoteIfNeccesary);
  }
  return _xifexpression;
}
 
Example 2
@Test
public void testBug_266440() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate bugreport \'http://bugreport/266440\'");
  _builder.newLine();
  _builder.append("CompositeModel: (type+=EClassifier)+;");
  _builder.newLine();
  _builder.append("EClassifier: EDataType | EClass;");
  _builder.newLine();
  _builder.append("EClass: \'class\' name=ID;");
  _builder.newLine();
  _builder.append("EDataType: \'dt\' name=ID;");
  String grammar = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammar);
  Assert.assertTrue(resource.getErrors().isEmpty());
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar parsedGrammar = ((Grammar) _head);
  EList<AbstractRule> _rules = parsedGrammar.getRules();
  for (final AbstractRule rule : _rules) {
    {
      final EClassifier classifier = rule.getType().getClassifier();
      EPackage pack = classifier.getEPackage();
      Assert.assertEquals("bugreport", pack.getName());
    }
  }
}
 
Example 3
TypeRef getTypeRef(EClassifier classifier) {
	TypeRef result = XtextFactory.eINSTANCE.createTypeRef();
	result.setClassifier(classifier);
	EPackage pack = classifier.getEPackage();
	for(AbstractMetamodelDeclaration decl: GrammarUtil.allMetamodelDeclarations(grammar)) {
		if (pack.equals(decl.getEPackage())) {
			result.setMetamodel(decl);
			return result;
		}
	}
	return result;
}
 
Example 4
public static boolean isEcoreType(final EClassifier it) {
  EPackage _ePackage = it.getEPackage();
  String _nsURI = null;
  if (_ePackage!=null) {
    _nsURI=_ePackage.getNsURI();
  }
  return Objects.equal(_nsURI, "http://www.eclipse.org/emf/2002/Ecore");
}
 
Example 5
@Test public void testReturnTypes_01() {
	ParserRule rule = grammarAccess.getModelRule();
	EClassifier classifier = rule.getType().getClassifier();
	assertEquals("Model", classifier.getName());
	EPackage pack = classifier.getEPackage();
	assertNotNull(pack);
	assertEquals(grammarAccess.getGrammar().getMetamodelDeclarations().get(0).getEPackage(), pack);
	EClassifier superClassifier = ((EClass)classifier).getESuperTypes().get(0);
	assertEquals("Model", superClassifier.getName());
	EPackage superPack = superClassifier.getEPackage();
	assertNotNull(superPack);
	assertEquals(grammarAccess.getGrammar().getUsedGrammars().get(0).getMetamodelDeclarations().get(0).getEPackage(), superPack);
}
 
Example 6
@Test public void testReturnTypes_02() {
	ParserRule rule = grammarAccess.getElementRule();
	EClassifier classifier = rule.getType().getClassifier();
	assertEquals("Element", classifier.getName());
	EPackage pack = classifier.getEPackage();
	assertNotNull(pack);
	assertEquals(grammarAccess.getGrammar().getMetamodelDeclarations().get(0).getEPackage(), pack);
}
 
Example 7
/** Map the reflective classifier to a registered one. */
private EClassifier resolveEClassifier(EClassifier classifier) {
	final EPackage sourcePackage = classifier.getEPackage();
	final EPackage targetPackage = Registry.INSTANCE.getEPackage(sourcePackage
		.getNsURI());
	return targetPackage.getEClassifier(classifier.getName());
}
 
Example 8
public static Set<EPackage> allReferencedEPackages(final EPackage ePack, final boolean includeCrossRefs) {
  final Function1<EClassifier, EPackage> _function = (EClassifier it) -> {
    return it.getEPackage();
  };
  return IterableExtensions.<EPackage>toSet(IterableExtensions.<EPackage>filterNull(IterableExtensions.<EClassifier, EPackage>map(Ecore2XtextExtensions.allReferencedClassifiers(ePack, includeCrossRefs), _function)));
}
 
Example 9
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);
}