Search in sources :

Example 11 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class ElementFinderTest method testFindRuleCalls.

@Test
public void testFindRuleCalls() {
    AbstractGrammarElementFinder f = grammarFinder();
    AbstractRule r = GrammarUtil.findRuleForName(f.getGrammar(), "FinderKeywords");
    assertEquals(2, f.findRuleCalls(r).size());
}
Also used : AbstractGrammarElementFinder(org.eclipse.xtext.service.AbstractElementFinder.AbstractGrammarElementFinder) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 12 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class ElementFinderTest method testFindCrossReferences.

@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());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) AbstractGrammarElementFinder(org.eclipse.xtext.service.AbstractElementFinder.AbstractGrammarElementFinder) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 13 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class AnotherInheritanceTest method testSimple.

@Test
public void testSimple() throws Exception {
    InheritanceTest2LanguageGrammarAccess g = (InheritanceTest2LanguageGrammarAccess) getGrammarAccess();
    assertNotNull(g.getFQNAccess());
    AbstractRule fromFQN = g.getFQNAccess().getIDTerminalRuleCall_0().getRule();
    assertEquals(fromFQN, g.getIDRule());
    assertNotNull(g.getModelAccess());
}
Also used : InheritanceTest2LanguageGrammarAccess(org.eclipse.xtext.grammarinheritance.services.InheritanceTest2LanguageGrammarAccess) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 14 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class InheritanceTest method testMetamodel.

@Test
public void testMetamodel() throws Exception {
    AbstractRule rule = GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "OverridableParserRule2");
    assertNotNull("rule", rule);
    TypeRef ref = rule.getType();
    assertNotNull("ref", ref);
    final EClass clazz = (EClass) ref.getClassifier();
    assertNotNull("class", clazz);
    assertEquals("AType2", clazz.getName());
    assertEquals(2, clazz.getESuperTypes().size());
    Set<String> expectedNames = new HashSet<String>(Arrays.asList(new String[] { "AType", "RootRule" }));
    Iterator<String> iter = Iterables.transform(clazz.getESuperTypes(), new Function<EClass, String>() {

        @Override
        public String apply(EClass param) {
            return param.getName();
        }
    }).iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        assertTrue("name = '" + name + "'", expectedNames.remove(name));
    }
    assertTrue(expectedNames.toString(), expectedNames.isEmpty());
}
Also used : Function(com.google.common.base.Function) EClass(org.eclipse.emf.ecore.EClass) TypeRef(org.eclipse.xtext.TypeRef) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class OverriddenValueInspectorTest method testUnorderedGroup_06.

@Test
public void testUnorderedGroup_06() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("Model : a = ID b = STRING & a = ID;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Model");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Aggregations

AbstractRule (org.eclipse.xtext.AbstractRule)222 Test (org.junit.Test)128 Grammar (org.eclipse.xtext.Grammar)106 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)96 ParserRule (org.eclipse.xtext.ParserRule)94 EObject (org.eclipse.emf.ecore.EObject)59 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)36 AbstractElement (org.eclipse.xtext.AbstractElement)34 TerminalRule (org.eclipse.xtext.TerminalRule)20 XtextResource (org.eclipse.xtext.resource.XtextResource)17 EClassifier (org.eclipse.emf.ecore.EClassifier)14 EnumRule (org.eclipse.xtext.EnumRule)14 ArrayList (java.util.ArrayList)12 Assignment (org.eclipse.xtext.Assignment)12 Group (org.eclipse.xtext.Group)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)11 EClass (org.eclipse.emf.ecore.EClass)10 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)10