Search in sources :

Example 51 with EClass

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

the class DeclarativeScopeProviderTest method testScopeByReference.

@SuppressWarnings("unused")
@Test
public void testScopeByReference() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(a, provider.getScope(details, details));
    assertEquals(a, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 52 with EClass

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

the class DeclarativeScopeProviderTest method testPolymorphic.

@SuppressWarnings("unused")
@Test
public void testPolymorphic() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 53 with EClass

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

the class DeclarativeScopeProviderTest method testScopeByType2.

@SuppressWarnings("unused")
@Test
public void testScopeByType2() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 54 with EClass

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

the class Xtext2EcoreTransformerTest method testCommonTerminalsFeatureTypes.

@Test
public void testCommonTerminalsFeatureTypes() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\' RuleA: featureA=ID featureB=INT featureC=STRING;");
    final String grammar = _builder.toString();
    EPackage ePackage = this.getEPackageFromGrammar(grammar);
    EClassifier _type = this.<EClassifier>type(ePackage, "RuleA");
    EClass ruleA = ((EClass) _type);
    Assert.assertNotNull(ruleA);
    Assert.assertEquals(3, ruleA.getEAttributes().size());
    this.assertAttributeConfiguration(ruleA, 0, "featureA", "EString");
    this.assertAttributeConfiguration(ruleA, 1, "featureB", "EInt");
    this.assertAttributeConfiguration(ruleA, 2, "featureC", "EString");
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 55 with EClass

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

the class Xtext2EcoreTransformerTest method testBug346685_b04.

@Test
public void testBug346685_b04() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\'");
    String grammar = _builder.toString();
    String _grammar = grammar;
    grammar = (_grammar + " Model: A? ({D.a = current} b = B) c=C? ;\n");
    String _grammar_1 = grammar;
    grammar = (_grammar_1 + " A: {A} \'a\';\n");
    String _grammar_2 = grammar;
    grammar = (_grammar_2 + " B: {B} \'c\';\n");
    String _grammar_3 = grammar;
    grammar = (_grammar_3 + " C: {C} \'b\';\n");
    EPackage ePackage = this.getEPackageFromGrammar(grammar);
    Assert.assertEquals(5, ePackage.getEClassifiers().size());
    EClassifier _type = this.<EClassifier>type(ePackage, "Model");
    EClass typeModel = ((EClass) _type);
    Assert.assertNotNull(typeModel);
    Assert.assertTrue(this.features(typeModel).isEmpty());
    EClassifier _type_1 = this.<EClassifier>type(ePackage, "A");
    EClass typeA = ((EClass) _type_1);
    Assert.assertNotNull(typeA);
    Assert.assertTrue(this.features(typeA).isEmpty());
    Assert.assertEquals(1, typeA.getESuperTypes().size());
    Assert.assertSame(typeModel, IterableExtensions.<EClass>head(typeA.getESuperTypes()));
    EClassifier _type_2 = this.<EClassifier>type(ePackage, "B");
    EClass typeB = ((EClass) _type_2);
    Assert.assertNotNull(typeB);
    Assert.assertTrue(this.features(typeB).isEmpty());
    EClassifier _type_3 = this.<EClassifier>type(ePackage, "C");
    EClass typeC = ((EClass) _type_3);
    Assert.assertNotNull(typeC);
    Assert.assertTrue(this.features(typeC).isEmpty());
    EClassifier _type_4 = this.<EClassifier>type(ePackage, "D");
    EClass typeD = ((EClass) _type_4);
    Assert.assertNotNull(typeD);
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeD, "a"));
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeD, "b"));
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeD, "c"));
    Assert.assertEquals(3, this.features(typeD).size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)205 Test (org.junit.Test)99 EPackage (org.eclipse.emf.ecore.EPackage)70 EClassifier (org.eclipse.emf.ecore.EClassifier)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)43 EObject (org.eclipse.emf.ecore.EObject)35 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)27 Resource (org.eclipse.emf.ecore.resource.Resource)23 EReference (org.eclipse.emf.ecore.EReference)22 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)16 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)13 ParserRule (org.eclipse.xtext.ParserRule)12 QualifiedName (org.eclipse.xtext.naming.QualifiedName)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)11 IScope (org.eclipse.xtext.scoping.IScope)11 ArrayList (java.util.ArrayList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 List (java.util.List)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9