Search in sources :

Example 6 with Assignment

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

the class NodeModelUtilsTest method testFindNodesForFeature_Cardinality_0.

@Test
public void testFindNodesForFeature_Cardinality_0() throws Exception {
    Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model: name+='foo'*;");
    Assignment assignment = (Assignment) grammar.getRules().get(0).getAlternatives();
    List<INode> nodes = NodeModelUtils.findNodesForFeature(assignment, XtextPackage.eINSTANCE.getAbstractElement_Cardinality());
    assertEquals(1, nodes.size());
    assertEquals("*", nodes.get(0).getText().trim());
}
Also used : Assignment(org.eclipse.xtext.Assignment) INode(org.eclipse.xtext.nodemodel.INode) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 7 with Assignment

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

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_04.

@Test
public void testFindActualSemanticObjectFor_04() 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("name"));
    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)

Example 8 with Assignment

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

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_07.

@Test
public void testFindActualSemanticObjectFor_07() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:(name=ID|name=STRING?)*;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode star = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('*'));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(star);
    assertTrue(object instanceof Alternatives);
    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) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 9 with Assignment

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

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_08.

@Test
public void testFindActualSemanticObjectFor_08() 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 leadingComment = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('*'));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(leadingComment);
    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 10 with Assignment

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

the class GrammarParserTest method testPrecedencies_05.

@Test
public void testPrecedencies_05() throws Exception {
    UnorderedGroup group = (UnorderedGroup) getModel("name=ID & 'keyword'");
    assertNotNull(group);
    assertEquals(2, group.getElements().size());
    assertTrue(group.getElements().get(0) instanceof Assignment);
    assertTrue(group.getElements().get(1) instanceof Keyword);
}
Also used : Assignment(org.eclipse.xtext.Assignment) Keyword(org.eclipse.xtext.Keyword) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) 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