Search in sources :

Example 46 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testDiamondHierarchy.

@Test
public void testDiamondHierarchy() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals generate test 'http://test' Model: name=ID value=SubNamed1 otherValue=SubNamed2 thirdValue=SubNamed3;Named: SubNamed1 | SubNamed2 | SubNamed3;SubNamed1: ConcreteNamed1 | ConcreteNamed2;SubNamed2: ConcreteNamed2 | ConcreteNamed3;SubNamed3: ConcreteNamed1 | ConcreteNamed3;ConcreteNamed1: name=ID bar=ID foo=ID a=ID;ConcreteNamed2: name=ID bar=ID zonk=ID b=ID;ConcreteNamed3: name=ID foo=ID zonk=ID c=ID;";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    Assert.assertEquals(8, ePackage.getEClassifiers().size());
    EClassifier classifier = type(ePackage, "Named");
    Assert.assertNotNull(classifier);
    EClass named = (EClass) classifier;
    EStructuralFeature feature = feature(named, "name");
    Assert.assertNotNull("name", feature);
    Assert.assertEquals("named", 1, features(named).size());
    EClass subNamed1 = (EClass) type(ePackage, "SubNamed1");
    Assert.assertNotNull("subNamed1", subNamed1);
    Assert.assertEquals(1, subNamed1.getESuperTypes().size());
    Assert.assertNotNull("bar", feature(subNamed1, "bar"));
    Assert.assertEquals("subNamed1", 1, features(subNamed1).size());
    EClass subNamed2 = (EClass) type(ePackage, "SubNamed2");
    Assert.assertNotNull("subNamed2", subNamed2);
    Assert.assertEquals(1, subNamed2.getESuperTypes().size());
    Assert.assertNotNull("bar", feature(subNamed2, "zonk"));
    Assert.assertEquals("subNamed2", 1, features(subNamed2).size());
    EClass subNamed3 = (EClass) type(ePackage, "SubNamed3");
    Assert.assertNotNull("subNamed3", subNamed3);
    Assert.assertEquals(1, subNamed3.getESuperTypes().size());
    Assert.assertNotNull("bar", feature(subNamed3, "foo"));
    Assert.assertEquals("subNamed3", 1, features(subNamed3).size());
    EClass concreteNamed1 = (EClass) type(ePackage, "ConcreteNamed1");
    Assert.assertNotNull("concreteNamed1", concreteNamed1);
    Assert.assertEquals("concreteNamed1", 2, concreteNamed1.getESuperTypes().size());
    Assert.assertTrue(concreteNamed1.getESuperTypes().contains(subNamed1));
    Assert.assertTrue(concreteNamed1.getESuperTypes().contains(subNamed3));
    Assert.assertNotNull("a", feature(concreteNamed1, "a"));
    Assert.assertEquals("concreteNamed1", 1, features(concreteNamed1).size());
    EClass concreteNamed2 = (EClass) type(ePackage, "ConcreteNamed2");
    Assert.assertNotNull("concreteNamed2", concreteNamed2);
    Assert.assertEquals("concreteNamed2", 2, concreteNamed2.getESuperTypes().size());
    Assert.assertTrue(concreteNamed2.getESuperTypes().contains(subNamed1));
    Assert.assertTrue(concreteNamed2.getESuperTypes().contains(subNamed2));
    Assert.assertNotNull("b", feature(concreteNamed2, "b"));
    Assert.assertEquals("concreteNamed2", 1, features(concreteNamed2).size());
    EClass concreteNamed3 = (EClass) type(ePackage, "ConcreteNamed3");
    Assert.assertNotNull("concreteNamed3", concreteNamed3);
    Assert.assertEquals("concreteNamed3", 2, concreteNamed3.getESuperTypes().size());
    Assert.assertTrue(concreteNamed3.getESuperTypes().contains(subNamed2));
    Assert.assertTrue(concreteNamed3.getESuperTypes().contains(subNamed3));
    Assert.assertNotNull("c", feature(concreteNamed3, "c"));
    Assert.assertEquals("concreteNamed3", 1, features(concreteNamed3).size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 47 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testParserRuleFragment_07.

@Test
public void testParserRuleFragment_07() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Middle1: Top;\n" + "Middle2: Top;\n" + "fragment Top: name=ID ({Bottom.prev=current} name=ID)*;\n";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    EList<EClassifier> classifiers = ePackage.getEClassifiers();
    Assert.assertEquals(4, classifiers.size());
    EClassifier middleType1 = Iterables.getFirst(classifiers, null);
    Assert.assertEquals("Middle1", middleType1.getName());
    Assert.assertTrue(features(middleType1).isEmpty());
    EClassifier middleType2 = classifiers.get(1);
    Assert.assertEquals("Middle2", middleType2.getName());
    Assert.assertTrue(features(middleType2).isEmpty());
    EClassifier topType = classifiers.get(2);
    Assert.assertEquals("EString", feature(topType, "name").getEType().getName());
    Assert.assertTrue(superTypes(middleType1).contains(topType));
    Assert.assertTrue(superTypes(middleType2).contains(topType));
    EClassifier bottomType = Iterables.getLast(classifiers);
    Assert.assertEquals("Top", feature(bottomType, "prev").getEType().getName());
    Assert.assertTrue(superTypes(bottomType).contains(middleType1));
    Assert.assertTrue(superTypes(bottomType).contains(middleType2));
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 48 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class SlotEntry method findEClasses.

protected Set<EClass> findEClasses(ResourceSet resourceSet, String nsURI2, String typeName2) {
    if (typeName2 == null)
        return Collections.emptySet();
    Set<EClass> result = Sets.newHashSet();
    Set<String> keySet = getNsUris();
    for (String string : keySet) {
        try {
            EPackage ePackage = resourceSet.getPackageRegistry().getEPackage(string);
            if (ePackage != null) {
                EClassifier classifier = ePackage.getEClassifier(typeName2);
                if (classifier instanceof EClass)
                    result.add((EClass) classifier);
            }
        } catch (NoClassDefFoundError e) {
            throw new NoClassDefFoundError("NoClassDefFoundError while loading ePackage: " + string + " - " + e.getMessage());
        }
    }
    if (result.isEmpty()) {
        throw new WorkflowInterruptedException("Couldn't find EClass for name '" + typeName2 + "'.");
    }
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 49 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class XtextReferableElementsUnloader method caseEPackage.

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));
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 50 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class AssignmentFinder method findValidAssignmentsForContainmentRef.

protected Set<AbstractElement> findValidAssignmentsForContainmentRef(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, EObject value) {
    Multimap<ISerializationContext, AbstractElement> children = ArrayListMultimap.create();
    for (Entry<AbstractElement, Collection<ISerializationContext>> e : assignments.asMap().entrySet()) {
        AbstractElement ele = e.getKey();
        if (ele instanceof RuleCall) {
            EClassifier classifier = ((RuleCall) ele).getRule().getType().getClassifier();
            if (!classifier.isInstance(value))
                continue;
        }
        for (ISerializationContext container : e.getValue()) {
            ISerializationContext child = SerializationContext.forChild(container, ele, value);
            children.put(child, ele);
        }
    }
    if (children.size() < 2)
        return Sets.newHashSet(children.values());
    Set<ISerializationContext> found = contextFinder.findByContents(value, children.keySet());
    Set<AbstractElement> result = Sets.newLinkedHashSet();
    for (ISerializationContext ctx : children.keySet()) if (found.contains(ctx))
        result.addAll(children.get(ctx));
    return result;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) Collection(java.util.Collection) EClassifier(org.eclipse.emf.ecore.EClassifier) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5