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