Search in sources :

Example 41 with AbstractRule

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

the class OverriddenValueInspectorTest method testBug306281_07.

@Test
public void testBug306281_07() 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 : name=ID (({Binary.left=current} operator = [Model] | {Binary.left=current} operator = [Model]) right=ID)* name=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)

Example 42 with AbstractRule

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

the class SuperCallScopeTest method testGetElementsByName_04.

@Test
public void testGetElementsByName_04() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Rule: name=ID;");
    _builder.newLine();
    _builder.append("terminal ID: super;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
    final SuperCallScope scope = new SuperCallScope(_last);
    Iterable<IEObjectDescription> _elements = scope.getElements(QualifiedName.create("super"));
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.ID");
    Pair<String, AbstractRule> _mappedTo = Pair.<String, AbstractRule>of("super", _findRuleForName);
    this.assertElements(_elements, _mappedTo);
}
Also used : SuperCallScope(org.eclipse.xtext.xtext.SuperCallScope) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 43 with AbstractRule

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

the class SuperCallScopeTest method testGetElementsByEObject_01.

@Test
public void testGetElementsByEObject_01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Rule: name=ID;");
    _builder.newLine();
    _builder.append("terminal ID: super;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    final SuperCallScope scope = new SuperCallScope(grammar);
    final AbstractRule id = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
    Iterable<IEObjectDescription> _elements = scope.getElements(id);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
    Pair<String, AbstractRule> _mappedTo = Pair.<String, AbstractRule>of("Lang.ID", _findRuleForName);
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
    Pair<String, AbstractRule> _mappedTo_1 = Pair.<String, AbstractRule>of("test.Lang.ID", _findRuleForName_1);
    this.assertElements(_elements, _mappedTo, _mappedTo_1);
}
Also used : SuperCallScope(org.eclipse.xtext.xtext.SuperCallScope) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 44 with AbstractRule

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

the class SuperCallScopeTest method testGetElementsByName_03.

@Test
public void testGetElementsByName_03() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Rule: name=ID;");
    _builder.newLine();
    _builder.append("terminal ID: super;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
    final SuperCallScope scope = new SuperCallScope(_head);
    this.assertElements(scope.getElements(QualifiedName.create("super")));
}
Also used : SuperCallScope(org.eclipse.xtext.xtext.SuperCallScope) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 45 with AbstractRule

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

the class SuperCallScopeTest method testGetAllElements_02.

@Test
public void testGetAllElements_02() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Rule: name=ID;");
    _builder.newLine();
    _builder.append("terminal ID: super;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
    final SuperCallScope scope = new SuperCallScope(_last);
    this.assertElementNames(scope.getAllElements(), "Lang.Rule", "test.Lang.Rule", "Lang.ID", "test.Lang.ID", "super", "super.ID", "Terminals.ID", "org.eclipse.xtext.common.Terminals.ID", "super.INT", "Terminals.INT", "org.eclipse.xtext.common.Terminals.INT", "super.STRING", "Terminals.STRING", "org.eclipse.xtext.common.Terminals.STRING", "super.ML_COMMENT", "Terminals.ML_COMMENT", "org.eclipse.xtext.common.Terminals.ML_COMMENT", "super.SL_COMMENT", "Terminals.SL_COMMENT", "org.eclipse.xtext.common.Terminals.SL_COMMENT", "super.WS", "Terminals.WS", "org.eclipse.xtext.common.Terminals.WS", "super.ANY_OTHER", "Terminals.ANY_OTHER", "org.eclipse.xtext.common.Terminals.ANY_OTHER");
}
Also used : SuperCallScope(org.eclipse.xtext.xtext.SuperCallScope) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

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