use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class AntlrParserTest method testParseWithoutActionCall.
/**
* Model: '<code>myID</code>'
* The following parse tree is expected:
* <pre>
* CompositeNode (GrammarElement: Rule[Model], Element: null)
* |
* CompositeNode (GrammarElement: RuleCall[Child], Element: Child[myID])
* |
* LeafNode (GrammarElement: RuleCall[ID], Element: null)
* </pre>
*/
@Test
public void testParseWithoutActionCall() throws Exception {
XtextResource resource = helper.getResourceFromString("myID");
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
Model model = (Model) resource.getContents().get(0);
assertNotNull("model", model);
assertEquals(model.eClass().getName(), ActionLangPackage.Literals.CHILD, model.eClass());
ICompositeNode node = NodeModelUtils.getNode(model);
assertNotNull("node", node);
assertEquals("node.grammarElement", grammarAccess.getModelAccess().getChildParserRuleCall_0(), node.getGrammarElement());
assertEquals(node.getChildren().toString(), 1, Iterables.size(node.getChildren()));
INode childNode = node.getFirstChild();
assertTrue(childNode.toString(), childNode instanceof ILeafNode);
assertEquals("childNode.grammarElement", grammarAccess.getChildAccess().getNameIDTerminalRuleCall_0(), childNode.getGrammarElement());
assertFalse("childNode.element", childNode.hasDirectSemanticElement());
ICompositeNode rootNode = resource.getParseResult().getRootNode();
assertNotNull("rootNode", rootNode);
assertEquals("rootNode.grammarElement", grammarAccess.getModelRule(), rootNode.getGrammarElement());
assertEquals(rootNode.getChildren().toString(), 1, Iterables.size(rootNode.getChildren()));
assertEquals("node is child of rootNode", rootNode, node.getParent());
assertFalse("rootNode.element", rootNode.hasDirectSemanticElement());
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class HiddenTokenSequencerTest method getNodeSequence.
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
List<String> result = Lists.newArrayList();
GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
// System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model), null, true, true);
while (ni.hasNext()) {
INode next = ni.next();
if (next instanceof ILeafNode)
result.add(titleSwitch.doSwitch(next.getGrammarElement()) + " -> " + next.getText());
if (next instanceof ICompositeNode)
result.add(titleSwitch.doSwitch(next.getGrammarElement()));
}
return result;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode 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.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindLeafNodeAtOffset_1.
@Test
public void testFindLeafNodeAtOffset_1() throws Exception {
String grammarText = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model : (name=ID value=ID);";
Grammar grammar = (Grammar) getModel(grammarText);
int equalsSign = grammarText.indexOf('=');
ICompositeNode grammarNode = NodeModelUtils.getNode(grammar);
ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(grammarNode, equalsSign);
assertEquals("=", leafNodeAtOffset.getText());
boolean syntheticNodeSeen = false;
INode parent = leafNodeAtOffset.getParent();
while (parent != null) {
// walk up the tree to make sure we call #findLeafNodeAtOffset with synthetic nodes, too
ILeafNode otherLeafNode = NodeModelUtils.findLeafNodeAtOffset(parent, equalsSign);
assertSame(leafNodeAtOffset, otherLeafNode);
if (parent instanceof SyntheticCompositeNode)
syntheticNodeSeen = true;
parent = parent.getParent();
}
assertTrue(syntheticNodeSeen);
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class ParseErrorHandlingTest method testBug236425.
/**
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236425
* @throws Exception
*/
@Test
public void testBug236425() throws Exception {
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
String model = "spielplatz 100 }";
EObject object = getModelAndExpect(model, 1);
ICompositeNode node = NodeModelUtils.getNode(object).getRootNode();
assertEquals(1, Iterables.size(allSyntaxErrors(node)));
}
Aggregations