private AbstractGrammarElementFinder grammarFinder() { final String file = "classpath:/org/eclipse/xtext/generator/grammarAccess/ElementFinderTestLanguage.xtext"; XtextResourceSet rs = get(XtextResourceSet.class); rs.setClasspathURIContext(getClass()); final Resource r = rs.getResource(URI.createURI(file), true); return new AbstractGrammarElementFinder() { @Override public Grammar getGrammar() { return (Grammar) r.getContents().get(0); } }; }
@Test public void testFindCrossReferences() { AbstractGrammarElementFinder f = grammarFinder(); AbstractRule r = GrammarUtil.findRuleForName(f.getGrammar(), "FQN"); assertNotNull(r); assertEquals(1, f.findCrossReferences(r).size()); EClass type = (EClass) GrammarUtil.findRuleForName(f.getGrammar(), "Type").getType().getClassifier(); assertNotNull(type); assertEquals(1, f.findCrossReferences(type).size()); }
@Test public void testFindRuleCalls() { AbstractGrammarElementFinder f = grammarFinder(); AbstractRule r = GrammarUtil.findRuleForName(f.getGrammar(), "FinderKeywords"); assertEquals(2, f.findRuleCalls(r).size()); }