use of org.eclipse.xtext.GeneratedMetamodel in project xtext-core by eclipse.
the class XtextValidator method getInheritedGeneratedMetamodels.
protected List<GeneratedMetamodel> getInheritedGeneratedMetamodels(ReferencedMetamodel metamodel) {
List<GeneratedMetamodel> allGeneratedMetamodels = new ArrayList<GeneratedMetamodel>();
Grammar grammar = GrammarUtil.getGrammar(metamodel);
Set<Grammar> visited = Sets.newHashSet();
for (Grammar usedGrammar : grammar.getUsedGrammars()) Iterables.addAll(allGeneratedMetamodels, getAllGeneratedMetamodels(usedGrammar, visited));
if (allGeneratedMetamodels.isEmpty())
return Collections.emptyList();
return allGeneratedMetamodels;
}
use of org.eclipse.xtext.GeneratedMetamodel in project xtext-core by eclipse.
the class XtextValidator method checkReferencedMetamodel.
@Check
public void checkReferencedMetamodel(ReferencedMetamodel metamodel) throws ValueConverterException {
if (metamodel.getEPackage() == null)
return;
String nsURI = metamodel.getEPackage().getNsURI();
List<GeneratedMetamodel> allGeneratedMetamodels = getInheritedGeneratedMetamodels(metamodel);
String text = getUsedUri(metamodel);
for (GeneratedMetamodel generatedMetamodel : allGeneratedMetamodels) {
EPackage generatedPackage = generatedMetamodel.getEPackage();
if (generatedPackage != null && nsURI.equals((generatedPackage.getNsURI()))) {
if (!text.equals(nsURI)) {
addIssue("Metamodels that have been generated by a super grammar must be referenced by nsURI: " + nsURI, metamodel, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_INHERITED, nsURI);
return;
}
return;
}
}
checkExternalPackage(metamodel, text);
}
use of org.eclipse.xtext.GeneratedMetamodel 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.GeneratedMetamodel 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