Class AbstractNode
- java.lang.Object
-
- org.eclipse.xtext.nodemodel.impl.AbstractNode
-
- All Implemented Interfaces:
java.lang.Iterable<INode>
,BidiIterable<INode>
,BidiTreeIterable<INode>
,INode
- Direct Known Subclasses:
CompositeNode
,LeafNode
public abstract class AbstractNode extends java.lang.Object implements INode, BidiTreeIterable<INode>
- Noextend:
- This class is not intended to be subclassed by clients.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractNode.NodeType
-
Constructor Summary
Constructors Constructor Description AbstractNode()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
basicGetGrammarElement()
protected int
basicGetLineOfOffset(INode rootNode, int offset)
protected AbstractNode
basicGetNextSibling()
protected CompositeNode
basicGetParent()
protected AbstractNode
basicGetPreviousSibling()
protected org.eclipse.emf.ecore.EObject
basicGetSemanticElement()
protected boolean
basicHasNextSibling()
protected boolean
basicHasPreviousSibling()
protected boolean
basicHasSiblings()
BidiTreeIterator<AbstractNode>
basicIterator()
protected void
basicSetGrammarElement(java.lang.Object grammarElementOrArray)
protected void
basicSetNextSibling(AbstractNode next)
protected void
basicSetParent(CompositeNode parent)
protected void
basicSetPreviousSibling(AbstractNode prev)
BidiTreeIterable<INode>
getAsTreeIterable()
Returns a tree iterable that uses this node as its origin and root instance.int
getEndLine()
Returns the line number relative to the complete input where the node ends (one based, excluding hidden tokens).int
getEndOffset()
Returns the end offset (exclusive) of this node excluding hidden tokens.org.eclipse.emf.ecore.EObject
getGrammarElement()
Returns the grammar element that created this node.java.lang.Iterable<ILeafNode>
getLeafNodes()
Returns an iterable for all contained leaf nodes.int
getLength()
Returns the length of this node excluding hidden tokens.INode
getNextSibling()
Returns the next sibling ornull
.protected abstract AbstractNode.NodeType
getNodeId()
int
getOffset()
Returns the offset of this node excluding hidden tokens.ICompositeNode
getParent()
Returns the parent of the node ornull
if and only if this is the root node.INode
getPreviousSibling()
Returns the previous sibling ornull
.ICompositeNode
getRootNode()
Returns the root node of this parse tree.org.eclipse.emf.ecore.EObject
getSemanticElement()
Returns the nearest semantic object that is associated with the subtree of this node.int
getStartLine()
Returns the line number relative to the complete input where the node begins (one based, excluding hidden tokens).SyntaxErrorMessage
getSyntaxErrorMessage()
Returns the directly associated syntax error message ornull
if none.java.lang.String
getText()
Returns the parsed text that is covered by this node (including hidden tokens).org.eclipse.xtext.util.ITextRegion
getTextRegion()
org.eclipse.xtext.util.ITextRegionWithLineInformation
getTextRegionWithLineInformation()
Returns aregion with line information
for this node excluding hidden tokens: anoffset
of this region is the same as anoffset
of this node; alength
of this region is the same as alength
of this node; aline number
of this region is the same as astart line
of this node; anend line number
of this region is the same as anend line
of this node.protected org.eclipse.xtext.util.ITextRegionWithLineInformation
getTextRegionWithLineInformation(int offset, int length)
int
getTotalEndLine()
Returns the line number relative to the complete input where the node ends (one based, including hidden tokens).int
getTotalEndOffset()
Returns the end offset (exclusive) of this node including hidden tokens.int
getTotalStartLine()
Returns the line number relative to the complete input where the node begins (one based, including hidden tokens).org.eclipse.xtext.util.ITextRegion
getTotalTextRegion()
Returns aregion
for this node including hidden tokens: anoffset
of this region is the same as atotal offset
of this node; and alength
of this region is the same as atotal length
of this node.org.eclipse.xtext.util.ITextRegionWithLineInformation
getTotalTextRegionWithLineInformation()
Returns aregion with line information
for this node including hidden tokens: anoffset
of this region is the same as atotal offset
of this node; alength
of this region is the same as atotal length
of this node; aline number
of this region is the same as atotal start line
of this node; anend line number
of this region is the same as atotal end line
of this node.boolean
hasDirectSemanticElement()
Returnstrue
if this node as a directly associated semantic element.boolean
hasNextSibling()
Returnstrue
if this node is not the last child of its parent.boolean
hasPreviousSibling()
Returnstrue
if this node is not the first child of its parent.boolean
hasSiblings()
Returnstrue
if this node has any siblings.BidiTreeIterator<INode>
iterator()
Returns a tree iterator that can be used forwards and backwards.protected void
readData(java.io.DataInputStream in, DeserializationConversionContext context)
BidiTreeIterable<INode>
reverse()
Returns a reverse version of this iterable that can be used forwards and backwards.protected void
write(java.io.DataOutputStream out, SerializationConversionContext scc)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.xtext.nodemodel.INode
getTotalLength, getTotalOffset
-
-
-
-
Method Detail
-
getTextRegion
public org.eclipse.xtext.util.ITextRegion getTextRegion()
Description copied from interface:INode
Returns a
region
for this node excluding hidden tokens:- an
offset
of this region is the same as anoffset
of this node; - and a
length
of this region is the same as alength
of this node.
This method could be more efficient than calculating an
offset
and alength
of this node separately.- Specified by:
getTextRegion
in interfaceINode
- Returns:
- a
region
for this node excluding hidden tokens - Since:
- 2.5
- an
-
getTotalTextRegion
public org.eclipse.xtext.util.ITextRegion getTotalTextRegion()
Description copied from interface:INode
Returns a
region
for this node including hidden tokens:- an
offset
of this region is the same as atotal offset
of this node; - and a
length
of this region is the same as atotal length
of this node.
This method could be more efficient than calculating a
total offset
and atotal length
of this node separately.- Specified by:
getTotalTextRegion
in interfaceINode
- Returns:
- a
region
for this node including hidden tokens - Since:
- 2.5
- an
-
getTextRegionWithLineInformation
public org.eclipse.xtext.util.ITextRegionWithLineInformation getTextRegionWithLineInformation()
Description copied from interface:INode
Returns a
region with line information
for this node excluding hidden tokens:- an
offset
of this region is the same as anoffset
of this node; - a
length
of this region is the same as alength
of this node; - a
line number
of this region is the same as astart line
of this node; - an
end line number
of this region is the same as anend line
of this node.
A
line number
and anend line number
of the returned region are one based.This method could be more efficient than calculating an
offset
, alength
, astart line
and anend line
of this node separately.- Specified by:
getTextRegionWithLineInformation
in interfaceINode
- Returns:
- a
region with line information
for this node excluding hidden tokens - Since:
- 2.5
- an
-
getTotalTextRegionWithLineInformation
public org.eclipse.xtext.util.ITextRegionWithLineInformation getTotalTextRegionWithLineInformation()
Description copied from interface:INode
Returns a
region with line information
for this node including hidden tokens:- an
offset
of this region is the same as atotal offset
of this node; - a
length
of this region is the same as atotal length
of this node; - a
line number
of this region is the same as atotal start line
of this node; - an
end line number
of this region is the same as atotal end line
of this node.
A
line number
and anend line number
of the returned region are one based.This method could be more efficient than calculating a
total offset
, atotal length
, atotal start line
and atotal end line
of this node separately.- Specified by:
getTotalTextRegionWithLineInformation
in interfaceINode
- Returns:
- a
region with line information
for this node including hidden tokens - Since:
- 2.5
- an
-
getTextRegionWithLineInformation
protected org.eclipse.xtext.util.ITextRegionWithLineInformation getTextRegionWithLineInformation(int offset, int length)
- Since:
- 2.5
-
getParent
public ICompositeNode getParent()
Description copied from interface:INode
Returns the parent of the node ornull
if and only if this is the root node.
-
basicGetParent
protected CompositeNode basicGetParent()
-
basicSetParent
protected void basicSetParent(CompositeNode parent)
-
getAsTreeIterable
public BidiTreeIterable<INode> getAsTreeIterable()
Description copied from interface:INode
Returns a tree iterable that uses this node as its origin and root instance. Its iterator will not return any siblings of this root. However, the first element returned byBidiTreeIterator.previous()
orBidiTreeIterator.next()
will be this instance.- Specified by:
getAsTreeIterable
in interfaceINode
- Returns:
- a tree iterable where this node represents the root instance.
-
iterator
public BidiTreeIterator<INode> iterator()
Description copied from interface:BidiTreeIterable
Returns a tree iterator that can be used forwards and backwards.- Specified by:
iterator
in interfaceBidiIterable<INode>
- Specified by:
iterator
in interfaceBidiTreeIterable<INode>
- Specified by:
iterator
in interfacejava.lang.Iterable<INode>
- Returns:
- an iterator. Never returns
null
.
-
reverse
public BidiTreeIterable<INode> reverse()
Description copied from interface:BidiTreeIterable
Returns a reverse version of this iterable that can be used forwards and backwards. In other words, an iterator provided by the reverse iterable will delegate its
hasNext()
andnext()
invocations toBidiIterator.hasPrevious()
andBidiIterator.previous()
respectively.This allows clients to iterate backwards by means of the enhanced for-loop:
for(T t: iterable.reverse()) { // do something with t }
- Specified by:
reverse
in interfaceBidiIterable<INode>
- Specified by:
reverse
in interfaceBidiTreeIterable<INode>
- Returns:
- the reversed iterable. Never returns
null
.
-
getLeafNodes
public java.lang.Iterable<ILeafNode> getLeafNodes()
Description copied from interface:INode
Returns an iterable for all contained leaf nodes. Nevernull
.- Specified by:
getLeafNodes
in interfaceINode
- Returns:
- an iterable for all contained leaf nodes. Never
null
.
-
basicIterator
public BidiTreeIterator<AbstractNode> basicIterator()
-
getText
public java.lang.String getText()
Description copied from interface:INode
Returns the parsed text that is covered by this node (including hidden tokens). The result is nevernull
but may be empty.
-
getTotalStartLine
public int getTotalStartLine()
Description copied from interface:INode
Returns the line number relative to the complete input where the node begins (one based, including hidden tokens).- Specified by:
getTotalStartLine
in interfaceINode
- Returns:
- the line number relative to the complete input where the node begins.
-
basicGetLineOfOffset
protected int basicGetLineOfOffset(INode rootNode, int offset)
- Since:
- 2.0
-
getStartLine
public int getStartLine()
Description copied from interface:INode
Returns the line number relative to the complete input where the node begins (one based, excluding hidden tokens).- Specified by:
getStartLine
in interfaceINode
- Returns:
- the line number relative to the complete input where the node begins.
-
getEndLine
public int getEndLine()
Description copied from interface:INode
Returns the line number relative to the complete input where the node ends (one based, excluding hidden tokens).- Specified by:
getEndLine
in interfaceINode
- Returns:
- the line number relative to the complete input where the node ends.
-
getTotalEndLine
public int getTotalEndLine()
Description copied from interface:INode
Returns the line number relative to the complete input where the node ends (one based, including hidden tokens).- Specified by:
getTotalEndLine
in interfaceINode
- Returns:
- the line number relative to the complete input where the node ends.
-
getOffset
public int getOffset()
Description copied from interface:INode
Returns the offset of this node excluding hidden tokens. If this node is a hidden leaf node or a composite node that does only contain hidden leaf nodes, the total offset is returned.
-
getLength
public int getLength()
Description copied from interface:INode
Returns the length of this node excluding hidden tokens. If this node is a hidden leaf node, the total length is returned.
-
getTotalEndOffset
public int getTotalEndOffset()
Description copied from interface:INode
Returns the end offset (exclusive) of this node including hidden tokens. Yields the same result asoffset
+
length
but may be more efficient.- Specified by:
getTotalEndOffset
in interfaceINode
- Returns:
- the end offset (exclusive) of this node including hidden tokens.
-
getEndOffset
public int getEndOffset()
Description copied from interface:INode
Returns the end offset (exclusive) of this node excluding hidden tokens. Yields the same result asoffset
+
length
but may be more efficient.- Specified by:
getEndOffset
in interfaceINode
- Returns:
- the end offset (exclusive) of this node excluding hidden tokens.
- Since:
- 2.5
-
getRootNode
public ICompositeNode getRootNode()
Description copied from interface:INode
Returns the root node of this parse tree. Will not returnnull
in a consistent tree.- Specified by:
getRootNode
in interfaceINode
- Returns:
- the root node of this parse tree. Will not return
null
in a consistent tree.
-
getSemanticElement
public org.eclipse.emf.ecore.EObject getSemanticElement()
Description copied from interface:INode
Returns the nearest semantic object that is associated with the subtree of this node. May returnnull
whenever the parser refused to create any objects due to unrecoverable errors. Implementations will usually walk up the node tree to find the semantic object. As the node model structure does not reflect the containment structure of the semantic object graph, clients should usually use the utilities inNodeModelUtils
to obtain the semantic instance.- Specified by:
getSemanticElement
in interfaceINode
- Returns:
- the nearest semantic object that is associated with the subtree of this node. May return
null
. - See Also:
INode.hasDirectSemanticElement()
,NodeModelUtils.findActualSemanticObjectFor(INode)
-
basicGetSemanticElement
protected org.eclipse.emf.ecore.EObject basicGetSemanticElement()
-
hasDirectSemanticElement
public boolean hasDirectSemanticElement()
Description copied from interface:INode
Returnstrue
if this node as a directly associated semantic element.- Specified by:
hasDirectSemanticElement
in interfaceINode
- Returns:
true
if this node as a directly associated semantic element.- See Also:
INode.getSemanticElement()
-
getGrammarElement
public org.eclipse.emf.ecore.EObject getGrammarElement()
Description copied from interface:INode
Returns the grammar element that created this node. May returnnull
in case of unrecoverable syntax errors. This happens usually when a keyword occurred at an unexpected offset.- Specified by:
getGrammarElement
in interfaceINode
- Returns:
- the grammar element that created this node. May return
null
.
-
basicGetGrammarElement
protected java.lang.Object basicGetGrammarElement()
-
basicSetGrammarElement
protected void basicSetGrammarElement(java.lang.Object grammarElementOrArray)
-
getSyntaxErrorMessage
public SyntaxErrorMessage getSyntaxErrorMessage()
Description copied from interface:INode
Returns the directly associated syntax error message ornull
if none.- Specified by:
getSyntaxErrorMessage
in interfaceINode
- Returns:
- the directly associated syntax error message. May return
null
.
-
getPreviousSibling
public INode getPreviousSibling()
Description copied from interface:INode
Returns the previous sibling ornull
. The result has the sameparent
as this node if it is notnull
.- Specified by:
getPreviousSibling
in interfaceINode
- Returns:
- the previous sibling or
null
. - See Also:
INode.hasPreviousSibling()
,INode.hasSiblings()
-
basicGetPreviousSibling
protected AbstractNode basicGetPreviousSibling()
-
basicSetPreviousSibling
protected void basicSetPreviousSibling(AbstractNode prev)
-
getNextSibling
public INode getNextSibling()
Description copied from interface:INode
- Specified by:
getNextSibling
in interfaceINode
- Returns:
- the next sibling or
null
. - See Also:
INode.hasNextSibling()
,INode.hasSiblings()
-
basicGetNextSibling
protected AbstractNode basicGetNextSibling()
-
basicSetNextSibling
protected void basicSetNextSibling(AbstractNode next)
-
hasPreviousSibling
public boolean hasPreviousSibling()
Description copied from interface:INode
Returnstrue
if this node is not the first child of its parent.- Specified by:
hasPreviousSibling
in interfaceINode
- Returns:
true
if this node has a previous sibling thusINode.getPreviousSibling()
will not returnnull
.
-
basicHasPreviousSibling
protected boolean basicHasPreviousSibling()
-
hasNextSibling
public boolean hasNextSibling()
Description copied from interface:INode
Returnstrue
if this node is not the last child of its parent.- Specified by:
hasNextSibling
in interfaceINode
- Returns:
true
if this node has a next sibling thusINode.getNextSibling()
will not returnnull
.
-
basicHasNextSibling
protected boolean basicHasNextSibling()
-
hasSiblings
public boolean hasSiblings()
Description copied from interface:INode
Returnstrue
if this node has any siblings.- Specified by:
hasSiblings
in interfaceINode
- Returns:
true
if this node has any siblings.- See Also:
INode.hasPreviousSibling()
,INode.hasNextSibling()
-
basicHasSiblings
protected boolean basicHasSiblings()
-
getNodeId
protected abstract AbstractNode.NodeType getNodeId()
-
readData
protected void readData(java.io.DataInputStream in, DeserializationConversionContext context) throws java.io.IOException
- Throws:
java.io.IOException
-
write
protected void write(java.io.DataOutputStream out, SerializationConversionContext scc) throws java.io.IOException
- Throws:
java.io.IOException
-
-