Java Code Examples for org.eclipse.xtext.nodemodel.BidiIterator#hasNext()
The following examples show how to use
org.eclipse.xtext.nodemodel.BidiIterator#hasNext() .
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: SleighHighlightingCalculator.java From ghidra with Apache License 2.0 | 5 votes |
void setStyles(IHighlightedPositionAcceptor acceptor, BidiIterator<INode> it, String... styles) { for (String s : styles) { if (!it.hasNext()) return; INode n = skipWhiteSpace(acceptor, it); if (n != null && s != null) acceptor.addPosition(n.getOffset(), n.getLength(), s); } }
Example 3
Source File: SleighHighlightingCalculator.java From ghidra with Apache License 2.0 | 5 votes |
INode skipWhiteSpace(IHighlightedPositionAcceptor acceptor, BidiIterator<INode> it) { INode n = null; while (it.hasNext() && (n = it.next()).getClass() == HiddenLeafNode.class) processHiddenNode(acceptor, (HiddenLeafNode) n); return n; }
Example 4
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 5
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"); }