Search in sources :

Example 41 with EPackage

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

the class TerminalRulesTestLanguageSemanticSequencer method sequence.

@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 == TerminalRulesTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TerminalRulesTestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Model(org.eclipse.xtext.parser.terminalrules.terminalRulesTestLanguage.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 42 with EPackage

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

the class Xtext2EcoreTransformerTest method testSimpleHierarchy.

@Test
public void testSimpleHierarchy() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals generate test 'http://test' RuleA: RuleB; RuleB: featureB= INT;";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    Assert.assertEquals(2, ePackage.getEClassifiers().size());
    EClass ruleA = (EClass) type(ePackage, "RuleA");
    Assert.assertNotNull(ruleA);
    EClass ruleB = (EClass) type(ePackage, "RuleB");
    Assert.assertNotNull(ruleB);
    Assert.assertTrue(ruleA.getESuperTypes().isEmpty());
    Assert.assertEquals(1, ruleB.getESuperTypes().size());
    EClass superClass = Iterables.getFirst(ruleB.getESuperTypes(), null);
    Assert.assertEquals(ruleA, superClass);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 43 with EPackage

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

the class Xtext2EcoreTransformerTest method testBug346685_b03.

@Test
public void testBug346685_b03() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals generate test 'http://test'";
    grammar = grammar + " Model: A? ({D.a = current} b = B)? c=C? ;\n";
    grammar = grammar + " A: {A} 'a';\n";
    grammar = grammar + " B: {B} 'c';\n";
    grammar = grammar + " C: {C} 'b';\n";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    Assert.assertEquals(5, ePackage.getEClassifiers().size());
    EClass typeModel = (EClass) type(ePackage, "Model");
    Assert.assertNotNull(typeModel);
    Assert.assertNotNull(feature(typeModel, "c"));
    Assert.assertEquals(1, features(typeModel).size());
    EClass typeA = (EClass) type(ePackage, "A");
    Assert.assertNotNull(typeA);
    Assert.assertTrue(features(typeA).isEmpty());
    Assert.assertEquals(1, typeA.getESuperTypes().size());
    Assert.assertSame(typeModel, Iterables.getFirst(typeA.getESuperTypes(), null));
    EClass typeB = (EClass) type(ePackage, "B");
    Assert.assertNotNull(typeB);
    Assert.assertTrue(features(typeB).isEmpty());
    EClass typeC = (EClass) type(ePackage, "C");
    Assert.assertNotNull(typeC);
    Assert.assertTrue(features(typeC).isEmpty());
    EClass typeD = (EClass) type(ePackage, "D");
    Assert.assertNotNull(typeD);
    Assert.assertNotNull(feature(typeD, "a"));
    Assert.assertNotNull(feature(typeD, "b"));
    Assert.assertEquals(2, features(typeD).size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 44 with EPackage

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

the class Xtext2EcoreTransformerTest method testFeaturesAndInheritanceOfNestedRuleCalls_02.

@Test
public void testFeaturesAndInheritanceOfNestedRuleCalls_02() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals generate test 'http://test'";
    grammar = grammar + " RuleA: ((RuleB|RuleC featureC1=ID)? featureABC=ID | (RuleC|RuleD featureD1=ID) featureCD=ID) featureA=ID;";
    grammar = grammar + " RuleB: featureB2=ID;";
    grammar = grammar + " RuleC: featureC2=ID;";
    grammar = grammar + " RuleD: featureD2=ID;";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    Assert.assertEquals(4, ePackage.getEClassifiers().size());
    EClass ruleA = (EClass) type(ePackage, "RuleA");
    Assert.assertNotNull(ruleA);
    EClass ruleB = (EClass) type(ePackage, "RuleB");
    Assert.assertNotNull(ruleB);
    EClass ruleC = (EClass) type(ePackage, "RuleC");
    Assert.assertNotNull(ruleC);
    EClass ruleD = (EClass) type(ePackage, "RuleD");
    Assert.assertNotNull(ruleD);
    Assert.assertTrue(ruleA.getESuperTypes().isEmpty());
    Assert.assertEquals(1, ruleB.getESuperTypes().size());
    Assert.assertEquals(ruleA, Iterables.getFirst(ruleB.getESuperTypes(), null));
    Assert.assertEquals(1, ruleC.getESuperTypes().size());
    Assert.assertEquals(ruleA, Iterables.getFirst(ruleC.getESuperTypes(), null));
    Assert.assertEquals(1, ruleD.getESuperTypes().size());
    Assert.assertEquals(ruleA, Iterables.getFirst(ruleD.getESuperTypes(), null));
    Assert.assertEquals(2, ruleA.getEAttributes().size());
    assertAttributeConfiguration(ruleA, 0, "featureABC", "EString");
    assertAttributeConfiguration(ruleA, 1, "featureA", "EString");
    Assert.assertEquals(1, ruleB.getEAttributes().size());
    assertAttributeConfiguration(ruleB, 0, "featureB2", "EString");
    Assert.assertEquals(3, ruleC.getEAttributes().size());
    assertAttributeConfiguration(ruleC, 0, "featureC1", "EString");
    assertAttributeConfiguration(ruleC, 1, "featureCD", "EString");
    assertAttributeConfiguration(ruleC, 2, "featureC2", "EString");
    Assert.assertEquals(3, ruleD.getEAttributes().size());
    assertAttributeConfiguration(ruleD, 0, "featureD1", "EString");
    assertAttributeConfiguration(ruleD, 1, "featureCD", "EString");
    assertAttributeConfiguration(ruleD, 2, "featureD2", "EString");
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 45 with EPackage

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

the class Xtext2EcoreTransformerTest method testUplift01.

@Test
public void testUplift01() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals generate test 'http://test'";
    grammar = grammar + " RuleA: (RuleB|RuleC) featureA=ID;";
    grammar = grammar + " RuleB: featureB=INT;";
    grammar = grammar + " RuleC: (featureA=ID)?;";
    EPackage ePackage = getEPackageFromGrammar(grammar);
    Assert.assertEquals(3, ePackage.getEClassifiers().size());
    EClass ruleA = (EClass) type(ePackage, "RuleA");
    Assert.assertNotNull(ruleA);
    EClass ruleB = (EClass) type(ePackage, "RuleB");
    Assert.assertNotNull(ruleB);
    EClass ruleC = (EClass) type(ePackage, "RuleC");
    Assert.assertNotNull(ruleC);
    Assert.assertEquals(1, ruleA.getEAttributes().size());
    assertAttributeConfiguration(ruleA, 0, "featureA", "EString");
    Assert.assertEquals(1, ruleB.getEAttributes().size());
    assertAttributeConfiguration(ruleB, 0, "featureB", "EInt");
    Assert.assertEquals(0, ruleC.getEAttributes().size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)424 ParserRule (org.eclipse.xtext.ParserRule)201 Action (org.eclipse.xtext.Action)196 Parameter (org.eclipse.xtext.Parameter)196 Test (org.junit.Test)101 EClass (org.eclipse.emf.ecore.EClass)85 Resource (org.eclipse.emf.ecore.resource.Resource)50 EObject (org.eclipse.emf.ecore.EObject)39 EClassifier (org.eclipse.emf.ecore.EClassifier)32 URI (org.eclipse.emf.common.util.URI)30 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Grammar (org.eclipse.xtext.Grammar)22 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)16 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)15 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)14 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)14 XtextResource (org.eclipse.xtext.resource.XtextResource)14 EEnum (org.eclipse.emf.ecore.EEnum)13 EReference (org.eclipse.emf.ecore.EReference)12 IOException (java.io.IOException)11