Java Code Examples for org.eclipse.xtext.GrammarUtil#allMetamodelDeclarations()
The following examples show how to use
org.eclipse.xtext.GrammarUtil#allMetamodelDeclarations() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTemplateVariableResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected EClassifier getEClassifierForGrammar(String fqnClassName, Grammar grammar) { int dotIndex = fqnClassName.indexOf('.'); String packageName = null; String className = fqnClassName; if (dotIndex > 0) { packageName = fqnClassName.substring(0, dotIndex); className = fqnClassName.substring(dotIndex + 1); } List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil .allMetamodelDeclarations(grammar); for (AbstractMetamodelDeclaration decl : allMetamodelDeclarations) { EPackage pack = decl.getEPackage(); if (packageName == null || pack.getName().equals(packageName)) { EClassifier eClassifier = pack.getEClassifier(className); if (eClassifier != null) { return eClassifier; } } } return null; }
Example 2
Source File: XtextHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean acceptHyperLink(XtextResource resource, EObject objectAtOffset) { if (objectAtOffset instanceof EClass) { EClass eClass = (EClass) objectAtOffset; Grammar grammar = GrammarUtil.getGrammar(resource.getEObject("/")); List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar); for (GeneratedMetamodel generatedMetamodel : Iterables.filter(allMetamodelDeclarations, GeneratedMetamodel.class)) { if (eClass.getEPackage().equals(generatedMetamodel.getEPackage())) { return false; } } } return true; }
Example 3
Source File: ConcreteSyntaxEValidator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected List<EPackage> getEPackages() { List<EPackage> pkg = new ArrayList<EPackage>(); for (AbstractMetamodelDeclaration a : GrammarUtil.allMetamodelDeclarations(grammar.getGrammar())) pkg.add(a.getEPackage()); return pkg; }
Example 4
Source File: Xtext2EcoreTransformer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
TypeRef getTypeRef(EClassifier classifier) { TypeRef result = XtextFactory.eINSTANCE.createTypeRef(); result.setClassifier(classifier); EPackage pack = classifier.getEPackage(); for(AbstractMetamodelDeclaration decl: GrammarUtil.allMetamodelDeclarations(grammar)) { if (pack.equals(decl.getEPackage())) { result.setMetamodel(decl); return result; } } return result; }
Example 5
Source File: XtextGeneratorLanguage.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void validateAllImports(final Grammar grammar) { List<AbstractMetamodelDeclaration> _allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar); for (final AbstractMetamodelDeclaration amd : _allMetamodelDeclarations) { if ((amd instanceof ReferencedMetamodel)) { this.validateReferencedMetamodel(((ReferencedMetamodel)amd)); } } }
Example 6
Source File: GrammarUtilTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 7
Source File: GrammarUtilTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testAllMetamodelDeclarations_02() 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 bar"); _builder.newLine(); _builder.append("generate g \'http://3\' 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 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(1); Assert.assertEquals("bar", decl.getAlias()); Assert.assertNotNull(decl.getEPackage()); Assert.assertEquals("http://3", decl.getEPackage().getNsURI()); 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(1), abstractRule.getType().getMetamodel()); }
Example 8
Source File: GrammarUtilTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 9
Source File: GrammarHelper.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Gets the name of the bundles required for this grammar. * * @return the required bundle symbolic names */ public Set<String> getRequiredBundleSymbolicNames() { Set<String> set = new HashSet<String>(); for (AbstractMetamodelDeclaration declaration : GrammarUtil.allMetamodelDeclarations(getGrammar())) { set.add(getBundleSymbolicName(getFirstInterface(declaration))); for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) { if (classifier instanceof EClass) { for (EClass superType : ((EClass) classifier).getEAllSuperTypes()) { set.add(getBundleSymbolicName(getFirstInterface(superType.getEPackage()))); } } } } return set; }
Example 10
Source File: LanguageConfig.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.3 */ protected void validateAllImports(Grammar grammar) { for (AbstractMetamodelDeclaration amd : GrammarUtil.allMetamodelDeclarations(grammar)) if (amd instanceof ReferencedMetamodel) validateReferencedMetamodel((ReferencedMetamodel) amd); }