Search in sources :

Example 6 with EEnum

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

the class GrammarParserTest method testEnum_06.

@Test
public void testEnum_06() throws Exception {
    String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/6'\n" + "Model: enumValue=MyEnum;\n" + "enum MyEnum: Value1 | Value2='value' | Value3;";
    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/6", pack.getNsURI());
    EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
    assertNotNull(eEnum);
    assertEquals(3, eEnum.getELiterals().size());
    EEnumLiteral value = eEnum.getELiterals().get(0);
    assertEquals("Value1", value.getName());
    assertEquals(0, value.getValue());
    assertEquals("Value1", value.getLiteral());
    value = eEnum.getELiterals().get(1);
    assertEquals("Value2", value.getName());
    assertEquals(1, value.getValue());
    assertEquals("value", value.getLiteral());
    value = eEnum.getELiterals().get(2);
    assertEquals("Value3", value.getName());
    assertEquals(2, value.getValue());
    assertEquals("Value3", 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)

Example 7 with EEnum

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

the class GrammarParserTest method testEnum_08.

@Test
public void testEnum_08() throws Exception {
    String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8'\n" + "Model: enumValue=MyEnum;\n" + "enum MyEnum: Value | Value = 'foo';";
    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/8", pack.getNsURI());
    EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
    assertNotNull(eEnum);
    assertEquals(1, eEnum.getELiterals().size());
    EEnumLiteral value = eEnum.getELiterals().get(0);
    assertEquals("Value", value.getName());
    assertEquals(0, value.getValue());
    assertEquals("Value", 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)

Example 8 with EEnum

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

the class GrammarParserTest method testEnum_01.

@Test
public void testEnum_01() throws Exception {
    String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/1'\n" + "Model: enumValue=MyEnum;\n" + "enum 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/1", 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)

Example 9 with EEnum

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

the class GrammarParserTest method testEnum_05.

@Test
public void testEnum_05() 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/5'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName = 'value';";
    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", 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 10 with EEnum

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

the class GrammarParserTest method testEnum_03.

@Test
public void testEnum_03() throws Exception {
    String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/3'\n" + "Model: enumValue=MyEnumRule;\n" + "enum MyEnumRule returns MyEnum: Value1 = 'value';";
    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/3", 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("value", 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

EEnum (org.eclipse.emf.ecore.EEnum)14 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)11 EPackage (org.eclipse.emf.ecore.EPackage)10 Grammar (org.eclipse.xtext.Grammar)9 Test (org.junit.Test)9 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)5 EnumRule (org.eclipse.xtext.EnumRule)5 RuleCall (org.eclipse.xtext.RuleCall)2 EAttribute (org.eclipse.emf.ecore.EAttribute)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EObject (org.eclipse.emf.ecore.EObject)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)1 Keyword (org.eclipse.xtext.Keyword)1 ParserRule (org.eclipse.xtext.ParserRule)1