use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindActualSemanticObjectFor_05.
@Test
public void testFindActualSemanticObjectFor_05() 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("ID"));
EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
assertTrue(object instanceof RuleCall);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindNodesForFeature_Cardinality_1.
@Test
public void testFindNodesForFeature_Cardinality_1() throws Exception {
Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model: name+='foo'* name+='bar'*;");
Group group = (Group) grammar.getRules().get(0).getAlternatives();
List<INode> nodes = NodeModelUtils.findNodesForFeature(group, XtextPackage.eINSTANCE.getAbstractElement_Cardinality());
assertEquals(0, nodes.size());
}
use of org.eclipse.xtext.Grammar 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.Grammar 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.Grammar 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);
}
Aggregations