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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations