Search in sources :

Example 51 with Assignment

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

the class XtextLinkerTest method testNamedParameterAdjustment.

@Test
public void testNamedParameterAdjustment() 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("Root<MyParam>: rule=Rule<true>;");
    _builder.newLine();
    _builder.append("Rule<MyParam>: name=ID child=Root<false>?;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    final ResourceSet resourceSet = grammar.eResource().getResourceSet();
    final Resource otherResource = resourceSet.createResource(URI.createURI("other.xtext"));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("grammar test.SubLang with test.Lang");
    _builder_1.newLine();
    _builder_1.append("import \'http://test\'");
    _builder_1.newLine();
    _builder_1.append("Root<MyParam>: rule=super::Rule<true>;");
    _builder_1.newLine();
    LazyStringInputStream _lazyStringInputStream = new LazyStringInputStream(_builder_1.toString());
    otherResource.load(_lazyStringInputStream, null);
    EObject _head = IterableExtensions.<EObject>head(otherResource.getContents());
    final Grammar subGrammar = ((Grammar) _head);
    AbstractRule _head_1 = IterableExtensions.<AbstractRule>head(subGrammar.getRules());
    final ParserRule rootRule = ((ParserRule) _head_1);
    AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
    final ParserRule parentRule = ((ParserRule) _last);
    AbstractElement _alternatives = parentRule.getAlternatives();
    AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
    final Assignment lastAssignment = ((Assignment) _last_1);
    AbstractElement _terminal = lastAssignment.getTerminal();
    final RuleCall ruleCall = ((RuleCall) _terminal);
    final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
    Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
    Condition _value = argument.getValue();
    Assert.assertFalse(((LiteralCondition) _value).isTrue());
}
Also used : LiteralCondition(org.eclipse.xtext.LiteralCondition) Condition(org.eclipse.xtext.Condition) ParserRule(org.eclipse.xtext.ParserRule) AbstractElement(org.eclipse.xtext.AbstractElement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) Grammar(org.eclipse.xtext.Grammar) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 52 with Assignment

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

the class XtextLinkerTest method testImplicitNamedParameterLinking_01.

@Test
public void testImplicitNamedParameterLinking_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("Root<MyParam>: rule=Rule<MyParam>;");
    _builder.newLine();
    _builder.append("Rule<MyParam>: name=ID child=Root<MyParam>?;");
    _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 ParserRule rootRule = ((ParserRule) _head);
    AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
    final ParserRule lastRule = ((ParserRule) _last);
    AbstractElement _alternatives = lastRule.getAlternatives();
    AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
    final Assignment lastAssignment = ((Assignment) _last_1);
    AbstractElement _terminal = lastAssignment.getTerminal();
    final RuleCall ruleCall = ((RuleCall) _terminal);
    final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
    Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
    Condition _value = argument.getValue();
    Assert.assertEquals(IterableExtensions.<Parameter>head(lastRule.getParameters()), ((ParameterReference) _value).getParameter());
}
Also used : Assignment(org.eclipse.xtext.Assignment) LiteralCondition(org.eclipse.xtext.LiteralCondition) Condition(org.eclipse.xtext.Condition) ParserRule(org.eclipse.xtext.ParserRule) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 53 with Assignment

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

the class XtextValidationTest method testEmptyKeyword.

@Test
public void testEmptyKeyword() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A: foo='';";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
    Assignment valueAssignment = (Assignment) grammar.getRules().get(0).getAlternatives();
    messageAcceptor.expectedContext(valueAssignment.getTerminal());
    configureValidator(validator, messageAcceptor, valueAssignment);
    validator.checkKeywordNotEmpty((Keyword) valueAssignment.getTerminal());
    messageAcceptor.validate();
}
Also used : Assignment(org.eclipse.xtext.Assignment) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 54 with Assignment

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

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_02.

@Test
public void testFindActualSemanticObjectFor_02() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:((name=ID)*)?;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode star = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('*'));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(star);
    assertTrue(object instanceof Assignment);
    ILeafNode questionMark = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('?'));
    object = NodeModelUtils.findActualSemanticObjectFor(questionMark);
    assertTrue(object instanceof Assignment);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 55 with Assignment

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

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_01.

@Test
public void testFindActualSemanticObjectFor_01() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:((name=ID));";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('('));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
    assertTrue(object instanceof Assignment);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Aggregations

Assignment (org.eclipse.xtext.Assignment)60 EObject (org.eclipse.emf.ecore.EObject)27 Test (org.junit.Test)25 RuleCall (org.eclipse.xtext.RuleCall)22 Grammar (org.eclipse.xtext.Grammar)21 AbstractElement (org.eclipse.xtext.AbstractElement)15 ParserRule (org.eclipse.xtext.ParserRule)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 Action (org.eclipse.xtext.Action)13 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)12 AbstractRule (org.eclipse.xtext.AbstractRule)12 Group (org.eclipse.xtext.Group)11 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)9 Alternatives (org.eclipse.xtext.Alternatives)8 CrossReference (org.eclipse.xtext.CrossReference)7 ArrayList (java.util.ArrayList)6 EClass (org.eclipse.emf.ecore.EClass)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)6 NamedArgument (org.eclipse.xtext.NamedArgument)6 LiteralCondition (org.eclipse.xtext.LiteralCondition)5