Search in sources :

Example 31 with AbstractMetamodelDeclaration

use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.

the class XtextValidationTest method testGeneratedPackageNotEmpty.

@Test
public void testGeneratedPackageNotEmpty() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Foo: 'a';\n";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(metamodelDeclaration, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackageNotEmpty((GeneratedMetamodel) metamodelDeclaration);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) Test(org.junit.Test)

Example 32 with AbstractMetamodelDeclaration

use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.

the class XtextValidationTest method testCycleInTypeHierarchy.

@Test
public void testCycleInTypeHierarchy() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals" + " generate test 'http://test'";
    grammarAsText += " RuleA: RuleB;";
    grammarAsText += " RuleB: RuleC;";
    grammarAsText += " RuleC: RuleA;";
    grammarAsText += " RuleD: RuleA;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(grammar.getRules().get(0).getType(), true, false);
    messageAcceptor.expectedContext(grammar.getRules().get(1).getType(), grammar.getRules().get(2).getType());
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
Also used : Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) Test(org.junit.Test)

Example 33 with AbstractMetamodelDeclaration

use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testPostProcessorHook.

@Test
public void testPostProcessorHook() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate test \'http://test\' MyRule: myFeature=INT;");
    final String xtextGrammar = _builder.toString();
    EObject _model = this.getModel(xtextGrammar);
    final Grammar grammar = ((Grammar) _model);
    final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
    AbstractMetamodelDeclaration _get = grammar.getMetamodelDeclarations().get(1);
    GeneratedMetamodel testMetamodel = ((GeneratedMetamodel) _get);
    final Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor postProcessor = new Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor(testMetamodel);
    transformer.setPostProcessor(postProcessor);
    transformer.transform();
    Assert.assertEquals("process mthde called once", 1, postProcessor.proccessMethCalled());
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) Test(org.junit.Test)

Aggregations

AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)33 Grammar (org.eclipse.xtext.Grammar)21 Test (org.junit.Test)16 EObject (org.eclipse.emf.ecore.EObject)11 EPackage (org.eclipse.emf.ecore.EPackage)9 AbstractRule (org.eclipse.xtext.AbstractRule)9 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 TypeRef (org.eclipse.xtext.TypeRef)7 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)6 EClass (org.eclipse.emf.ecore.EClass)4 EClassifier (org.eclipse.emf.ecore.EClassifier)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 ParserRule (org.eclipse.xtext.ParserRule)4 RuleCall (org.eclipse.xtext.RuleCall)4 CompoundElement (org.eclipse.xtext.CompoundElement)3 EnumRule (org.eclipse.xtext.EnumRule)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2