Java Code Examples for org.eclipse.emf.ecore.EPackage#getEClassifiers()

The following examples show how to use org.eclipse.emf.ecore.EPackage#getEClassifiers() . 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: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEscapeChar_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("^MyRule: name=^ID;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(1, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
}
 
Example 2
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testRuleWithoutExplicitReturnType() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: myFeature=INT;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(1, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertEquals("myFeature", IterableExtensions.head(this.features(myRuleType)).getName());
}
 
Example 3
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testParserRuleFragment_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: IntFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment IntFeatureHolder: myFeature=INT;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(2, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertTrue(this.features(myRuleType).isEmpty());
  final EClassifier intFeatureHolder = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("EInt", this.<EStructuralFeature>feature(intFeatureHolder, "myFeature").getEType().getName());
  Assert.assertTrue(this.superTypes(myRuleType).contains(intFeatureHolder));
}
 
Example 4
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testParserRuleFragment_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: IntFeature;");
  _builder.newLine();
  _builder.append("fragment IntFeature*: myFeature=INT;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(1, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertEquals("EInt", this.<EStructuralFeature>feature(myRuleType, "myFeature").getEType().getName());
}
 
Example 5
Source File: ChartDynamicExtension.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static Set<EClass> getEClasses( List<EPackage> packages )
{
	Set<EClass> set = new HashSet<EClass>( );
	for ( EPackage pkg : packages )
	{
		for ( EClassifier eClassifier : pkg.getEClassifiers( ) )
		{
			if ( eClassifier instanceof EClass )
			{
				set.add( (EClass) eClassifier );
			}
		}
	}

	return set;
}
 
Example 6
Source File: XtextReferableElementsUnloader.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void caseEPackage(EPackage ePackage) {
	// guard against infinite recursion
	// EPackage.eSetProxyURI and friends tries to be smart thus
	// we have to make sure to compute all URIs before they are
	// set
	Resource resource = ePackage.eResource();
	URI resourceURI = resource.getURI();
	List<EClassifier> classifiers = ePackage.getEClassifiers();
	List<URI> uris = new ArrayList<URI>(classifiers.size());
	for(int i = 0, size = classifiers.size(); i < size; i++) {
		uris.add(resourceURI.appendFragment(resource.getURIFragment(classifiers.get(i))));
	}
	// and we have to set them in a proper order
	unload(ePackage);
	for(int i = 0, size = classifiers.size(); i < size; i++) {
		InternalEObject classifier = (InternalEObject) classifiers.get(i);
		classifier.eSetProxyURI(uris.get(i));
	}
}
 
Example 7
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void putMappingData(Map<EObject, EObject> result, EPackage usedEPackage, EPackage loadedEPackage) {
	if (loadedEPackage != null && usedEPackage != loadedEPackage) {
		result.put(usedEPackage, loadedEPackage);
		for(EClassifier usedClassifier: usedEPackage.getEClassifiers()) {
			EClassifier loadedClassifier = loadedEPackage.getEClassifier(usedClassifier.getName());
			if (loadedClassifier == null)
				throw new RuntimeException(
						"Cannot find classifier '" + usedClassifier.getName() + "' in loaded EPackage from " + loadedEPackage.eResource().getURI());
			result.put(usedClassifier, loadedClassifier);
		}
		for(EPackage usedNestedPackage: usedEPackage.getESubpackages()) {
			for(EPackage loadedNestedPackage: loadedEPackage.getESubpackages()) {
				if (usedNestedPackage.getName().equals(loadedNestedPackage.getName())) {
					putMappingData(result, usedNestedPackage, loadedNestedPackage);
					break;
				}
			}
		}
	}
}
 
Example 8
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkGeneratedPackageForNameClashes(GeneratedMetamodel metamodel) {
	EPackage pack = metamodel.getEPackage();
	Multimap<String, ENamedElement> constantNameToElement = HashMultimap.create();
	Multimap<String, ENamedElement> accessorNameToElement = HashMultimap.create();
	if (pack != null) {
		for(EClassifier classifier: pack.getEClassifiers()) {
			String accessorName = classifier.getName();
			if ("Class".equals(accessorName) || "Name".equals(accessorName))
				accessorName += "_";
			accessorNameToElement.put("get" + accessorName, classifier);
			String classifierConstantName = CodeGenUtil2.format(classifier.getName(), '_', null, true, true).toUpperCase();
			constantNameToElement.put(classifierConstantName, classifier);
			if (classifier instanceof EClass) {
				for(EStructuralFeature feature: ((EClass) classifier).getEAllStructuralFeatures()) {
					String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, false, false).toUpperCase();
					String featureConstantName = classifierConstantName + "__" + featureConstantPart;
					constantNameToElement.put(featureConstantName, feature);
					String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName());
					accessorNameToElement.put(featureAccessorName, feature);
				}
			}
		}
	}
	createMessageForNameClashes(constantNameToElement);
	createMessageForNameClashes(accessorNameToElement);
}
 
Example 9
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void clearPackage(Resource resource, EPackage pack) {
	Map<InternalEObject, URI> uris = Maps.newHashMap();
	for(EClassifier classifier: pack.getEClassifiers()) {
		InternalEObject internalEObject = (InternalEObject) classifier;
		URI appendFragment = resource.getURI().appendFragment(resource.getURIFragment(internalEObject));
		uris.put(internalEObject, appendFragment);
	}
	pack.getEClassifiers().clear();
	for (Map.Entry<InternalEObject, URI> entry : uris.entrySet()) {
		entry.getKey().eSetProxyURI(entry.getValue());
	}
}
 
Example 10
Source File: GrammarGeneratorTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private boolean addImportedEPackages(EPackage ePackage, Set<EPackage> importedEPackages) {
	if (BROKEN_PACKAGE_NS_URIS.contains(ePackage.getNsURI())) {
		return false;
	}
	if (importedEPackages.add(ePackage)) {
		for (EClassifier eClassifier : ePackage.getEClassifiers()) {
			if (eClassifier instanceof EClass) {
				for (EStructuralFeature feature : ((EClass) eClassifier).getEAllStructuralFeatures()) {
					if (!feature.isTransient() && !feature.isDerived()) {
						EPackage referencedEPackage = feature.getEType().getEPackage();
						if (referencedEPackage == null) {
							return false;
						}
						if (feature instanceof EAttribute) {
							if (((EAttribute) feature).getEAttributeType().isSerializable()) {
								if (!addImportedEPackages(referencedEPackage, importedEPackages)) {
									return false;
								}
							}
						}
						if (feature instanceof EReference) {
							if (((EReference) feature).isContainment()) {
								if (!addImportedEPackages(referencedEPackage, importedEPackages)) {
									return false;
								}
							}
						}
					}
				}
			}
		}
	}
	return true;
}
 
Example 11
Source File: EClasses.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find the {@link EClass} for a given {@link URI}.
 *
 * @param uri
 *          of the EClass to find.
 * @return the EClass, if found, or {@code null} otherwise.
 */
public static EClass getEClass(final URI uri) {
  EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().toString());
  if (ePackage != null) {
    if (ePackage.eResource() != null) {
      return (EClass) ePackage.eResource().getEObject(uri.fragment());
    }
    for (EClassifier eClassifier : ePackage.getEClassifiers()) {
      if (EcoreUtil.getURI(eClassifier).equals(uri) && eClassifier instanceof EClass) {
        return (EClass) eClassifier;
      }
    }
  }
  return null;
}
 
Example 12
Source File: GGraphGsonConfigurator.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
protected void configureClassesOfPackages(GsonBuilder gsonBuilder) {
	for (EPackage pkg : ePackages) {
		for (EClassifier classifier : pkg.getEClassifiers()) {
			if (classifier instanceof EClass && !((EClass) classifier).isAbstract()) {
				Class<? extends EObject> implClass = getImplementationClass((EClass) classifier, pkg);
				gsonBuilder.registerTypeAdapter(classifier.getInstanceClass(),
						new ClassBasedDeserializer(implClass));
			}
		}
	}
}
 
Example 13
Source File: RecordSizeEstimater.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public void init(Set<EPackage> ePackages) {
	// Initialise a map of estimated required buffer sizes
	for (EPackage ePackage : ePackages) {
		for (EClassifier eClassifier : ePackage.getEClassifiers()) {
			if (eClassifier instanceof EClass) {
				EClass eClass = (EClass)eClassifier;
				bufferSizeEstimates.put(eClass, estimateBufferSize(eClass));
			}
		}
	}
}
 
Example 14
Source File: M2DocTypeSelectionDialog.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the {@link List} of all classifiers in the given {@link EPackage}.
 * 
 * @param ePkg
 *            the {@link EPackage}
 * @return the {@link List} of all classifiers in the given {@link EPackage}
 */
private List<String> getEClassifiers(EPackage ePkg) {
    final List<String> res = new ArrayList<>();

    for (EClassifier eClassifier : ePkg.getEClassifiers()) {
        res.add(ePkg.getName() + "::" + eClassifier.getName());
    }
    for (EPackage child : ePkg.getESubpackages()) {
        res.addAll(getEClassifiers(child));
    }

    return res;
}
 
Example 15
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParserRuleFragment_03() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: IntFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment IntFeatureHolder: myFeature=INT NameFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment NameFeatureHolder: name=STRING;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(3, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertTrue(this.features(myRuleType).isEmpty());
  final EClassifier intFeatureHolder = classifiers.get(1);
  Assert.assertEquals("EInt", this.<EStructuralFeature>feature(intFeatureHolder, "myFeature").getEType().getName());
  Assert.assertTrue(this.superTypes(myRuleType).contains(intFeatureHolder));
  final EClassifier nameFeatureHolder = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("EString", this.<EStructuralFeature>feature(nameFeatureHolder, "name").getEType().getName());
  Assert.assertTrue(this.superTypes(intFeatureHolder).contains(nameFeatureHolder));
}
 
Example 16
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParserRuleFragment_04() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: Documentable IntFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment IntFeatureHolder: Documentable myFeature=INT NameFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment NameFeatureHolder: Documentable name=STRING;");
  _builder.newLine();
  _builder.append("fragment Documentable*: doc=STRING;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(3, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertTrue(this.features(myRuleType).isEmpty());
  final EClassifier intFeatureHolder = classifiers.get(1);
  Assert.assertEquals("EInt", this.<EStructuralFeature>feature(intFeatureHolder, "myFeature").getEType().getName());
  Assert.assertEquals(1, this.features(intFeatureHolder).size());
  final EClassifier nameFeatureHolder = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("EString", this.<EStructuralFeature>feature(nameFeatureHolder, "name").getEType().getName());
  Assert.assertEquals(2, this.features(nameFeatureHolder).size());
}
 
Example 17
Source File: Schema.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public void addEPackage(EPackage ePackage) {
	packages.put(ePackage.getName(), ePackage);
	changes.add(new NewPackageChange(ePackage));
	Set<EClass> newClasses = new HashSet<>();
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			newClasses.add((EClass) eClassifier);
		}
	}
	addEClasses(ePackage, newClasses);
}
 
Example 18
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParserRuleFragment_06() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Middle1: Top;");
  _builder.newLine();
  _builder.append("Middle2: Top;");
  _builder.newLine();
  _builder.append("fragment Top: name=ID ({Bottom.prev=current} Top)?;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(4, classifiers.size());
  final EClassifier middleType1 = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("Middle1", middleType1.getName());
  Assert.assertTrue(this.features(middleType1).isEmpty());
  final EClassifier middleType2 = classifiers.get(1);
  Assert.assertEquals("Middle2", middleType2.getName());
  Assert.assertTrue(this.features(middleType2).isEmpty());
  final EClassifier topType = classifiers.get(2);
  Assert.assertEquals("EString", this.<EStructuralFeature>feature(topType, "name").getEType().getName());
  Assert.assertTrue(this.superTypes(middleType1).contains(topType));
  Assert.assertTrue(this.superTypes(middleType2).contains(topType));
  final EClassifier bottomType = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("Top", this.<EStructuralFeature>feature(bottomType, "prev").getEType().getName());
  Assert.assertTrue(this.superTypes(bottomType).contains(middleType1));
  Assert.assertTrue(this.superTypes(bottomType).contains(middleType2));
}
 
Example 19
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParserRuleFragment_07() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Middle1: Top;");
  _builder.newLine();
  _builder.append("Middle2: Top;");
  _builder.newLine();
  _builder.append("fragment Top: name=ID ({Bottom.prev=current} name=ID)*;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(4, classifiers.size());
  final EClassifier middleType1 = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("Middle1", middleType1.getName());
  Assert.assertTrue(this.features(middleType1).isEmpty());
  final EClassifier middleType2 = classifiers.get(1);
  Assert.assertEquals("Middle2", middleType2.getName());
  Assert.assertTrue(this.features(middleType2).isEmpty());
  final EClassifier topType = classifiers.get(2);
  Assert.assertEquals("EString", this.<EStructuralFeature>feature(topType, "name").getEType().getName());
  Assert.assertTrue(this.superTypes(middleType1).contains(topType));
  Assert.assertTrue(this.superTypes(middleType2).contains(topType));
  final EClassifier bottomType = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("Top", this.<EStructuralFeature>feature(bottomType, "prev").getEType().getName());
  Assert.assertTrue(this.superTypes(bottomType).contains(middleType1));
  Assert.assertTrue(this.superTypes(bottomType).contains(middleType2));
}
 
Example 20
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);
}