Java Code Examples for org.eclipse.xtext.nodemodel.BidiIterator#next()
The following examples show how to use
org.eclipse.xtext.nodemodel.BidiIterator#next() .
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: SoliditySemanticHighlighter.java From solidity-ide with Eclipse Public License 1.0 | 6 votes |
private void provideHighLightForNamedElement(NamedElement namedElement, INode nextNode, String textStyle, IHighlightedPositionAcceptor acceptor) { acceptor.addPosition(nextNode.getOffset(), nextNode.getLength(), textStyle); List<ElementReferenceExpression> references = EcoreUtil2.getAllContentsOfType(namedElement.eContainer(), ElementReferenceExpression.class); for (ElementReferenceExpression elementReferenceExpression : references) { EObject reference = elementReferenceExpression.getReference(); if (reference.equals(namedElement)) { ICompositeNode referencingNode = NodeModelUtils.findActualNodeFor(elementReferenceExpression); BidiIterator<INode> bidiIterator = referencingNode.getChildren().iterator(); while (bidiIterator.hasNext()) { INode currentNode = bidiIterator.next(); if (currentNode.getText().trim().equals(namedElement.getName())) { acceptor.addPosition(currentNode.getOffset(), currentNode.getLength(), textStyle); } } } } }
Example 2
Source File: PartialParsingPointers.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @return either a RuleCall or a ParserRule */ public EObject findEntryRuleOrRuleCall(ICompositeNode replaceRootNode) { EObject grammarElement = replaceRootNode.getGrammarElement(); if (grammarElement instanceof CrossReference) { grammarElement = ((CrossReference) grammarElement).getTerminal(); } if (GrammarUtil.isParserRuleCall(grammarElement)) { return grammarElement; } else if (grammarElement instanceof ParserRule) { return grammarElement; } else if (grammarElement instanceof Action) { BidiIterator<INode> iterator = replaceRootNode.getChildren().iterator(); while(iterator.hasNext()) { INode next = iterator.next(); if (next instanceof ICompositeNode) { return findEntryRuleOrRuleCall((ICompositeNode) next); } } throw new IllegalArgumentException("Invalid parsetree: Action node does not have a Composite child"); } else throw new IllegalArgumentException( "Entry rule can only be resolved for parser rules, rule calls, cross-references or actions, but tried to resolve for: " + replaceRootNode.getGrammarElement().eClass().getName()); }
Example 3
Source File: NodeModelSemanticSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected INode findContextNode(EObject semanticObject) { INode node = NodeModelUtils.findActualNodeFor(semanticObject); if (node != null) { BidiIterator<INode> nodes = node.getAsTreeIterable().iterator(); while (nodes.hasNext()) { INode next = nodes.next(); if (next.getGrammarElement() instanceof RuleCall) return next; if (next.getGrammarElement() instanceof ParserRule && ((ParserRule) next.getGrammarElement()).getType().getClassifier() instanceof EClass) return next; } } throw new RuntimeException("no context found"); }