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));
}
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);
}
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());
}
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");
}
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());
}
Aggregations