use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testCompactDump_1.
@Test
public void testCompactDump_1() throws Exception {
String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:name=ID;";
Grammar grammar = (Grammar) getModel(grammarString);
String actual = NodeModelUtils.compactDump(NodeModelUtils.getNode(grammar.getMetamodelDeclarations().get(0)), true);
String expected = "GeneratedMetamodel {\n" + " hidden WS returns EString: => ' '\n" + " 'generate' => 'generate'\n" + " name=ValidID {\n" + " hidden WS returns EString: => ' '\n" + " ID => 'foo'\n" + " }\n" + " hidden WS returns EString: => ' '\n" + " ePackage=[EPackage] => ''bar''\n" + "}";
assertEquals(expected.toString(), actual);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindActualSemanticObjectFor_11.
@Test
public void testFindActualSemanticObjectFor_11() throws Exception {
String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model<Param>:name=ID;";
Grammar grammar = (Grammar) getModel(grammarString);
ILeafNode lessThan = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf("<"));
EObject object = NodeModelUtils.findActualSemanticObjectFor(lessThan);
assertTrue(object instanceof ParserRule);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindNodesForFeature.
@Test
public void testFindNodesForFeature() throws Exception {
Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model : name=ID;");
List<INode> nodes = NodeModelUtils.findNodesForFeature(grammar, XtextPackage.eINSTANCE.getGrammar_Name());
assertEquals(1, nodes.size());
assertEquals("foo.Bar", nodes.get(0).getText().trim());
nodes = NodeModelUtils.findNodesForFeature(grammar, XtextPackage.eINSTANCE.getGrammar_Rules());
assertEquals(1, nodes.size());
assertEquals("Model : name=ID;", nodes.get(0).getText().trim());
AbstractMetamodelDeclaration declaration = grammar.getMetamodelDeclarations().get(0);
nodes = NodeModelUtils.findNodesForFeature(declaration, XtextPackage.eINSTANCE.getGeneratedMetamodel_Name());
assertEquals(1, nodes.size());
assertEquals("foo", nodes.get(0).getText().trim());
nodes = NodeModelUtils.findNodesForFeature(declaration, null);
assertEquals(0, nodes.size());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindActualNode_02.
@Test
public void testFindActualNode_02() throws Exception {
String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model<Param>:name=ID;";
Grammar grammar = (Grammar) getModel(grammarString);
ParserRule rule = (ParserRule) grammar.getRules().get(0);
ICompositeNode node = NodeModelUtils.findActualNodeFor(rule);
assertEquals(" Model<Param>:name=ID;", node.getText());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindNodesForFeature_Cardinality_2.
@Test
public void testFindNodesForFeature_Cardinality_2() 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(2, nodes.size());
assertEquals("*", nodes.get(0).getText());
assertEquals("?", nodes.get(1).getText());
}
Aggregations