use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class UnassignedRuleCallTestLanguageSemanticSequencer 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 == UnassignedRuleCallTestLanguagePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case UnassignedRuleCallTestLanguagePackage.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
case UnassignedRuleCallTestLanguagePackage.MODEL_FEATURES:
sequence_ModelFeatures(context, (ModelFeatures) 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 EcoreUtil2Test method testGetAllReferencedObjects.
@Test
public void testGetAllReferencedObjects() {
EClass a = createEClass("a");
EClass b = createEClass("b");
EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
pack.setName("empty");
pack.setNsPrefix("empty");
pack.setNsURI("empty");
pack.getEClassifiers().add(a);
pack.getEClassifiers().add(b);
EReference ref = EcoreFactory.eINSTANCE.createEReference();
a.getEStructuralFeatures().add(ref);
ref.setUpperBound(1);
ref.setEType(b);
EObject objA = pack.getEFactoryInstance().create(a);
EObject objB = pack.getEFactoryInstance().create(b);
List<EObject> res = EcoreUtil2.getAllReferencedObjects(objA, ref);
assertNotNull(res);
assertTrue(res.isEmpty());
res = EcoreUtil2.getAllReferencedObjects(objA, ref);
assertNotNull(res);
objA.eSet(ref, objB);
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class EcoreUtil2Test method testPathFragment.
@Test
public void testPathFragment() {
EClass foo = EcoreFactory.eINSTANCE.createEClass();
foo.setName("foo");
EClass bar = EcoreFactory.eINSTANCE.createEClass();
foo.setName("bar");
EPackage p = EcoreFactory.eINSTANCE.createEPackage();
bar.setName("p");
p.getEClassifiers().add(foo);
p.getEClassifiers().add(bar);
assertEquals("/-1", EcoreUtil2.getFragmentPath(foo));
assertEquals("/-1", EcoreUtil2.getFragmentPath(bar));
assertEquals("/-1", EcoreUtil2.getFragmentPath(p));
Resource resource = new ResourceImpl(URI.createURI("platform:/resource/res"));
resource.getContents().add(p);
assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.0"), EcoreUtil2.getFragmentPathURI(foo));
assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.1"), EcoreUtil2.getFragmentPathURI(bar));
assertEquals(URI.createURI("platform:/resource/res#/"), EcoreUtil2.getFragmentPathURI(p));
assertEquals(resource.getEObject("//@eClassifiers.0"), foo);
assertEquals(resource.getEObject("//@eClassifiers.1"), bar);
assertEquals(resource.getEObject("/"), p);
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_04.
@Test
public void testEnum_04() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/4'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum");
assertNotNull(eEnum);
assertEquals(3, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName());
assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue());
assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral());
EnumRule rule = (EnumRule) grammar.getRules().get(1);
assertEquals(eEnum, rule.getType().getClassifier());
EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives();
assertEquals(value, decl.getEnumLiteral());
assertNotNull(decl.getLiteral());
assertEquals(value.getLiteral(), decl.getLiteral().getValue());
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_02.
@Test
public void testEnum_02() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2'\n" + "Model: enumValue=MyEnumRule;\n" + "enum MyEnumRule returns MyEnum: Value1;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
assertNotNull(eEnum);
assertEquals(1, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals("Value1", value.getName());
assertEquals(0, value.getValue());
assertEquals("Value1", value.getLiteral());
}
Aggregations