use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class XtextValidationTest method testDuplicateFeatures_02.
@Test
public void testDuplicateFeatures_02() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A : (b+=B)*;\n" + "B : C | D;\n" + "C : 'c' name=ID ('e' e+=E)+;\n" + "E : name=ID;\n" + "F : C | E;\n" + "D : 'd' name=ID 'ref' ref=[F];";
Grammar grammar = (Grammar) getModel(grammarAsText);
AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
messageAcceptor.expectedContext(grammar.getRules().get(1).getType(), grammar.getRules().get(2).getType(), grammar.getRules().get(4).getType(), ((CompoundElement) grammar.getRules().get(2).getAlternatives()).getElements().get(1), grammar.getRules().get(3).getAlternatives(), ((CompoundElement) grammar.getRules().get(5).getAlternatives()).getElements().get(1));
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 XtextValidationTest method testNameClash_02.
@Test
public void testNameClash_02() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Class returns Class: {Class_} name=ID;\n";
Grammar grammar = (Grammar) getModel(grammarAsText);
AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
CompoundElement element = (CompoundElement) grammar.getRules().get(0).getAlternatives();
messageAcceptor.expectedContext(grammar.getRules().get(0).getType(), ((Action) element.getElements().get(0)).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 XtextValidationTest method testNameClash_01.
@Test
public void testNameClash_01() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "PRINTF: vars=PRINTF_Vars;\n" + "PRINTF_Vars: arg1=ID;";
Grammar grammar = (Grammar) getModel(grammarAsText);
AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
messageAcceptor.expectedContext(grammar.getRules().get(0).getAlternatives(), grammar.getRules().get(1).getType());
validator.setMessageAcceptor(messageAcceptor);
validator.checkGeneratedPackageForNameClashes((GeneratedMetamodel) metamodelDeclaration);
messageAcceptor.validate();
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class GrammarUtilTest method testAllMetamodelDeclarations_03.
@Test
public void testAllMetamodelDeclarations_03() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://3\' as bar");
_builder.newLine();
_builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as bar");
_builder.newLine();
_builder.append("startrule returns bar::startrule: name=ID;");
_builder.newLine();
String model = _builder.toString();
Resource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
Grammar g = ((Grammar) _get);
List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
Assert.assertEquals(3, decls.size());
AbstractMetamodelDeclaration decl = decls.get(0);
Assert.assertTrue((decl instanceof GeneratedMetamodel));
Assert.assertEquals("bar", decl.getAlias());
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
decl = decls.get(1);
Assert.assertTrue((decl instanceof ReferencedMetamodel));
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
Assert.assertEquals("bar", decl.getAlias());
decl = decls.get(2);
Assert.assertTrue((decl instanceof ReferencedMetamodel));
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
Assert.assertEquals("ecore", decl.getAlias());
AbstractRule abstractRule = g.getRules().get(0);
Assert.assertSame(decls.get(0), abstractRule.getType().getMetamodel());
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class GrammarUtilTest method testAllMetamodelDeclarations_01.
@Test
public void testAllMetamodelDeclarations_01() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore");
_builder.newLine();
_builder.append("generate g \'http://3\' as ecore");
_builder.newLine();
_builder.append("startrule returns ecore::startrule: name=ID;");
_builder.newLine();
String model = _builder.toString();
Resource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
Grammar g = ((Grammar) _get);
List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
Assert.assertEquals(2, decls.size());
AbstractMetamodelDeclaration decl = decls.get(0);
Assert.assertTrue((decl instanceof ReferencedMetamodel));
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
Assert.assertEquals("ecore", decl.getAlias());
decl = decls.get(1);
Assert.assertEquals("ecore", decl.getAlias());
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
}
Aggregations