Search in sources :

Example 96 with EPackage

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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ModelFeatures(org.eclipse.xtext.xtext.ecoreInference.unassignedRuleCallTestLanguage.ModelFeatures) Model(org.eclipse.xtext.xtext.ecoreInference.unassignedRuleCallTestLanguage.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 97 with EPackage

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 98 with EPackage

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 99 with EPackage

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());
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) Grammar(org.eclipse.xtext.Grammar) EEnum(org.eclipse.emf.ecore.EEnum) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 100 with EPackage

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());
}
Also used : EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) Grammar(org.eclipse.xtext.Grammar) EEnum(org.eclipse.emf.ecore.EEnum) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)416 ParserRule (org.eclipse.xtext.ParserRule)194 Action (org.eclipse.xtext.Action)189 Parameter (org.eclipse.xtext.Parameter)189 Test (org.junit.Test)101 EClass (org.eclipse.emf.ecore.EClass)83 EClassifier (org.eclipse.emf.ecore.EClassifier)75 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)60 Resource (org.eclipse.emf.ecore.resource.Resource)50 EObject (org.eclipse.emf.ecore.EObject)45 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