org.eclipse.xtext.nodemodel.BidiIterator Java Examples
The following examples show how to use
org.eclipse.xtext.nodemodel.BidiIterator.
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: GrammarUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static String getTypeRefName(TypeRef typeRef) { if (typeRef.getClassifier() != null) return typeRef.getClassifier().getName(); final ICompositeNode node = NodeModelUtils.getNode(typeRef); if (node != null) { final BidiIterator<INode> leafNodes = node.getAsTreeIterable().iterator(); while (leafNodes.hasPrevious()) { INode previous = leafNodes.previous(); if (previous instanceof ILeafNode && !((ILeafNode) previous).isHidden()) { String result = previous.getText(); if (result != null && result.startsWith("^")) { result = result.substring(1); } return result; } } } return null; }
Example #2
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 #3
Source File: XtextLinkingService.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException { final ICompositeNode parentNode = text.getParent(); BidiIterator<INode> iterator = parentNode.getChildren().iterator(); while(iterator.hasPrevious()) { INode child = iterator.previous(); if (child instanceof ILeafNode) { ILeafNode leaf = (ILeafNode) child; if (text == leaf) return super.getLinkedObjects(context, ref, text); if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) { IScope scope = getScope(context, ref); return XtextMetamodelReferenceHelper.findBestMetamodelForType( context, text.getText(), leaf.getText(), scope); } } } return Collections.emptyList(); }
Example #4
Source File: BasicNodeIterable.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public BidiIterable<AbstractNode> reverse() { return new BidiIterable<AbstractNode>() { @Override public BidiIterator<AbstractNode> iterator() { BidiIterator<AbstractNode> delegate = BasicNodeIterable.this.iterator(); return new ReversedBidiIterator<AbstractNode>(delegate); } @Override public BidiIterable<AbstractNode> reverse() { return BasicNodeIterable.this; } }; }
Example #5
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 #6
Source File: FixedPartialParsingHelper.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
private void collectNodesEnclosingChangeRegion(final ICompositeNode parent, final Range range, final List<ICompositeNode> nodesEnclosingRegion) { nodesEnclosingRegion.add(parent); BidiIterator<INode> iterator = parent.getChildren().iterator(); while (iterator.hasPrevious()) { INode prev = iterator.previous(); if (prev instanceof ICompositeNode) { if (nodeEnclosesRegion((ICompositeNode) prev, range)) { collectNodesEnclosingChangeRegion((ICompositeNode) prev, range, nodesEnclosingRegion); break; } } } }
Example #7
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"); }
Example #8
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 #9
Source File: PartialParsingHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void collectNodesEnclosingChangeRegion(ICompositeNode parent, Range range, List<ICompositeNode> nodesEnclosingRegion) { nodesEnclosingRegion.add(parent); BidiIterator<INode> iterator = parent.getChildren().iterator(); while(iterator.hasPrevious()) { INode prev = iterator.previous(); if (prev instanceof ICompositeNode) { if (nodeEnclosesRegion((ICompositeNode) prev, range)) { collectNodesEnclosingChangeRegion((ICompositeNode) prev, range, nodesEnclosingRegion); break; } } } }
Example #10
Source File: AbstractNode.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.5 */ @Override public int getEndOffset() { BidiIterator<AbstractNode> iter = basicIterator(); while(iter.hasPrevious()) { INode prev = iter.previous(); if (prev instanceof ILeafNode && !((ILeafNode) prev).isHidden()) { return prev.getTotalEndOffset(); } } return getTotalEndOffset(); }
Example #11
Source File: AbstractNode.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public int getLength() { BidiIterator<AbstractNode> iter = basicIterator(); while(iter.hasPrevious()) { INode prev = iter.previous(); if (prev instanceof ILeafNode && !((ILeafNode) prev).isHidden()) { int offset = getOffset(); return prev.getTotalEndOffset() - offset; } } return getTotalLength(); }
Example #12
Source File: SleighHighlightingCalculator.java From ghidra with Apache License 2.0 | 5 votes |
INode skipWhiteSpaceBackwards(IHighlightedPositionAcceptor acceptor, BidiIterator<INode> it) { INode n = null; while (it.hasPrevious() && (n = it.previous()).getClass() == HiddenLeafNode.class) processHiddenNode(acceptor, (HiddenLeafNode) n); return n; }
Example #13
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 #14
Source File: EmptyBidiIterable.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public BidiIterator<T> iterator() { return EmptyBidiIterator.instance(); }
Example #15
Source File: SingletonBidiIterator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public static <T> BidiIterator<T> create(T t) { return new SingletonBidiIterator<T>(t); }
Example #16
Source File: ReversedBidiIterator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected BidiIterator<T> getDelegate() { return delegate; }
Example #17
Source File: BasicNodeIterable.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public BidiIterator<AbstractNode> iterator() { return new BasicNodeIterator(startWith); }
Example #18
Source File: ReversedBidiIterator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public ReversedBidiIterator(BidiIterator<T> delegate) { this.delegate = delegate; }
Example #19
Source File: EmptyBidiIterator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static <T> BidiIterator<T> instance() { return (BidiIterator<T>) INSTANCE; }
Example #20
Source File: ReversedBidiIterable.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public BidiIterator<T> iterator() { BidiIterator<T> delegate = getDelegate().iterator(); return new ReversedBidiIterator<T>(delegate); }
Example #21
Source File: SingletonBidiIterable.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public BidiIterator<T> iterator() { return SingletonBidiIterator.<T>create(value); }
Example #22
Source File: NodeIterable.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public BidiIterator<INode> iterator() { return new NodeIterator(startWith); }