Java Code Examples for org.eclipse.xtext.nodemodel.ICompositeNode#getAsTreeIterable()
The following examples show how to use
org.eclipse.xtext.nodemodel.ICompositeNode#getAsTreeIterable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug480686Test.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testAllGrammarElementsUnique() throws Exception { ContentAssistFragmentTestLanguageRoot result = parseHelper.parse("newArrayList()"); XtextResource res = (XtextResource) result.eResource(); ICompositeNode root = res.getParseResult().getRootNode(); new InvariantChecker().checkInvariant(root); Set<EObject> set = new HashSet<>(); for (INode node : root.getAsTreeIterable()) { if (node instanceof ICompositeNode) { ICompositeNode compositeNode = (ICompositeNode) node; if (compositeNode.getGrammarElement() != null) { Assert.assertTrue(compositeNode.getGrammarElement().toString(), set.add(compositeNode.getGrammarElement())); } else { Assert.fail("node without grammar element"); } } } }
Example 2
Source File: Bug480686Test.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testAllGrammarElementsUniqueAfterReparse() throws Exception { ContentAssistFragmentTestLanguageRoot result = parseHelper.parse(""); XtextResource res = (XtextResource) result.eResource(); res.update(0, 0, "newArrayList()"); ICompositeNode root = res.getParseResult().getRootNode(); Set<EObject> set = new HashSet<>(); for (INode node : root.getAsTreeIterable()) { if (node instanceof ICompositeNode) { ICompositeNode compositeNode = (ICompositeNode) node; if (compositeNode.getGrammarElement() != null) { Assert.assertTrue(compositeNode.getGrammarElement().toString(), set.add(compositeNode.getGrammarElement())); } else { Assert.fail("node without grammar element"); } } } }
Example 3
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testAllGrammarElementsUnique() throws Exception { XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }"); XtextResource resource = (XtextResource) clazz.eResource(); ICompositeNode root = resource.getParseResult().getRootNode(); new InvariantChecker().checkInvariant(root); assertSame(root, root.getRootNode()); Set<EObject> grammarElements = Sets.newHashSet(); for(INode node: root.getAsTreeIterable()) { if (node instanceof ICompositeNode) { if (node.getGrammarElement() == null) { fail("node without grammar element"); } if (!grammarElements.add(node.getGrammarElement())) { fail(node.getGrammarElement().toString()); } } } }
Example 4
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testAllGrammarElementsUniqueAfterReparse() throws Exception { String text = "class Foo { def m() { newArrayList() } }"; XtendClass clazz = clazz(text); XtextResource resource = (XtextResource) clazz.eResource(); resource.update(text.indexOf('m'), 0, "m"); ICompositeNode root = resource.getParseResult().getRootNode(); assertSame(root, root.getRootNode()); Set<EObject> grammarElements = Sets.newHashSet(); for(INode node: root.getAsTreeIterable()) { if (node instanceof ICompositeNode) { if (node.getGrammarElement() == null) { fail("node without grammar element"); } if (!grammarElements.add(node.getGrammarElement())) { fail(node.getGrammarElement().toString()); } } } }
Example 5
Source File: JavaDocCommentDocumentationProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Retrieves a comment for the given object. * * @param object * an object * @return the comment corresponding to the closest JavaDoc-like comment */ protected String findComment(final EObject object) { String returnValue = null; ICompositeNode node = NodeModelUtils.getNode(object); if (node != null) { // get the last multi line comment before a non hidden leaf node for (INode abstractNode : node.getAsTreeIterable()) { String comment = getJavaDocComment(abstractNode); if (comment != null) { returnValue = comment; break; } } } return returnValue; }
Example 6
Source File: HiddenTokenSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected Set<INode> getLeadingCommentsIncludingWhitespace(ICompositeNode node) { for (INode child : node.getAsTreeIterable()) { if (child instanceof ILeafNode && !((ILeafNode) child).isHidden()) { return getLeadingCommentsIncludingWhitespace((ILeafNode) child); } } return Sets.newHashSet(); }