org.eclipse.xtext.nodemodel.impl
Class SyntheticCompositeNode

java.lang.Object
  extended by org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode
All Implemented Interfaces:
java.lang.Iterable<INode>, BidiIterable<INode>, BidiTreeIterable<INode>, ICompositeNode, INode

public class SyntheticCompositeNode
extends java.lang.Object
implements ICompositeNode, BidiTreeIterable<INode>

Unfolds the array of grammar elements that is associated with a composite node.

Author:
Sebastian Zarnekow - Initial contribution and API
This class is not intended to be subclassed by clients.
This class is not intended to be subclassed by clients.

Constructor Summary
protected SyntheticCompositeNode(CompositeNode delegate, int grammarElementIdx)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 BidiTreeIterable<INode> getAsTreeIterable()
          Returns a tree iterable that uses this node as its origin and root instance.
 BidiIterable<INode> getChildren()
          Returns an iterable that provides access to the children of the composite node.
 int getEndLine()
          Returns the line number relative to the complete input where the node ends (one based, excluding hidden tokens).
 INode getFirstChild()
          Returns the first child of this node.
 org.eclipse.emf.ecore.EObject getGrammarElement()
          Returns the grammar element that created this node.
 INode getLastChild()
          Returns the last child of 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.
 int getLookAhead()
          Return the number of tokens that the parser had to peek before it could decide to create this node.
 INode getNextSibling()
          Returns the next sibling or null.
 int getOffset()
          Returns the offset of this node excluding hidden tokens.
 ICompositeNode getParent()
          Returns the parent of the node or null if and only if this is the root node.
 INode getPreviousSibling()
          Returns the previous sibling or null.
 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 or null if none.
 java.lang.String getText()
          Returns the parsed text that is covered by this node (including hidden tokens).
 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 getTotalLength()
          Returns the length of this node including hidden tokens.
 int getTotalOffset()
          Returns the offset 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).
 boolean hasChildren()
          Returns true if this node has any children.
 boolean hasDirectSemanticElement()
          Returns true if this node as a directly associated semantic element.
 int hashCode()
           
 boolean hasNextSibling()
          Returns true if this node is not the last child of its parent.
 boolean hasPreviousSibling()
          Returns true if this node is not the first child of its parent.
 boolean hasSiblings()
          Returns true if this node has any siblings.
 BidiTreeIterator<INode> iterator()
          Returns a tree iterator that can be used forwards and backwards.
 BidiTreeIterable<INode> reverse()
          Returns a reverse version of this iterable that can be used forwards and backwards.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntheticCompositeNode

protected SyntheticCompositeNode(CompositeNode delegate,
                                 int grammarElementIdx)
Method Detail

getParent

public ICompositeNode getParent()
Description copied from interface: INode
Returns the parent of the node or null if and only if this is the root node.

Specified by:
getParent in interface INode
Returns:
the parent of this node or null.

hasSiblings

public boolean hasSiblings()
Description copied from interface: INode
Returns true if this node has any siblings.

Specified by:
hasSiblings in interface INode
Returns:
true if this node has any siblings.
See Also:
INode.hasPreviousSibling(), INode.hasNextSibling()

hasPreviousSibling

public boolean hasPreviousSibling()
Description copied from interface: INode
Returns true if this node is not the first child of its parent.

Specified by:
hasPreviousSibling in interface INode

hasNextSibling

public boolean hasNextSibling()
Description copied from interface: INode
Returns true if this node is not the last child of its parent.

Specified by:
hasNextSibling in interface INode

getPreviousSibling

public INode getPreviousSibling()
Description copied from interface: INode
Returns the previous sibling or null. The result has the same parent as this node if it is not null.

Specified by:
getPreviousSibling in interface INode
Returns:
the previous sibling or null.
See Also:
INode.hasPreviousSibling(), INode.hasSiblings()

getNextSibling

public INode getNextSibling()
Description copied from interface: INode
Returns the next sibling or null. The result has the same parent as this node if it is not null.

Specified by:
getNextSibling in interface INode
Returns:
the next sibling or null.
See Also:
INode.hasNextSibling(), INode.hasSiblings()

getRootNode

public ICompositeNode getRootNode()
Description copied from interface: INode
Returns the root node of this parse tree. Will not return null in a consistent tree.

Specified by:
getRootNode in interface INode
Returns:
the root node of this parse tree. Will not return null in a consistent tree.

getTotalOffset

public int getTotalOffset()
Description copied from interface: INode
Returns the offset of this node including hidden tokens.

Specified by:
getTotalOffset in interface INode
Returns:
the offset of this node including hidden tokens.

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.

Specified by:
getOffset in interface INode
Returns:
the offset of this node excluding hidden tokens.

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.

Specified by:
getLength in interface INode
Returns:
the length of this node excluding hidden tokens.

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 interface INode
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 interface INode
Returns:
the line number relative to the complete input where the node ends.

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 interface INode
Returns:
the line number relative to the complete input where the node begins.

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 interface INode
Returns:
the line number relative to the complete input where the node ends.

getTotalLength

public int getTotalLength()
Description copied from interface: INode
Returns the length of this node including hidden tokens.

Specified by:
getTotalLength in interface INode
Returns:
the length of this node including hidden tokens.

getTotalEndOffset

public int getTotalEndOffset()
Description copied from interface: INode
Returns the end offset (exclusive) of this node including hidden tokens. Yields the same result as offset + length but may be more efficient.

Specified by:
getTotalEndOffset in interface INode
Returns:
the end offset (exclusive) of this node including hidden tokens.

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 never null but may be empty.

Specified by:
getText in interface INode
Returns:
the parsed text that is covered by this node (including hidden tokens). Never null.

getGrammarElement

public org.eclipse.emf.ecore.EObject getGrammarElement()
Description copied from interface: INode
Returns the grammar element that created this node. May return null in case of unrecoverable syntax errors. This happens usually when a keyword occurred at an unexpected offset.

Specified by:
getGrammarElement in interface INode
Returns:
the grammar element that created this node. May return null.

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 return null 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 in NodeModelUtils to obtain the semantic instance.

Specified by:
getSemanticElement in interface INode
Returns:
the nearest semantic object that is associated with the subtree of this node. May return null.
See Also:
INode.hasDirectSemanticElement(), NodeModelUtils.findActualSemanticObjectFor(INode)

hasDirectSemanticElement

public boolean hasDirectSemanticElement()
Description copied from interface: INode
Returns true if this node as a directly associated semantic element.

Specified by:
hasDirectSemanticElement in interface INode
Returns:
true if this node as a directly associated semantic element.
See Also:
INode.getSemanticElement()

getSyntaxErrorMessage

public SyntaxErrorMessage getSyntaxErrorMessage()
Description copied from interface: INode
Returns the directly associated syntax error message or null if none.

Specified by:
getSyntaxErrorMessage in interface INode
Returns:
the directly associated syntax error message. May return null.

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 by BidiTreeIterator.previous() or BidiTreeIterator.next() will be this instance.

Specified by:
getAsTreeIterable in interface INode
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 interface java.lang.Iterable<INode>
Specified by:
iterator in interface BidiIterable<INode>
Specified by:
iterator in interface BidiTreeIterable<INode>
Returns:
an iterator. Never returns null.

getLeafNodes

public java.lang.Iterable<ILeafNode> getLeafNodes()
Description copied from interface: INode
Returns an iterable for all contained leaf nodes. Never null.

Specified by:
getLeafNodes in interface INode
Returns:
an iterable for all contained leaf nodes. Never 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() and next() invocations to BidiIterator.hasPrevious() and BidiIterator.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 interface BidiIterable<INode>
Specified by:
reverse in interface BidiTreeIterable<INode>
Returns:
the reversed iterable. Never returns null.

getChildren

public BidiIterable<INode> getChildren()
Description copied from interface: ICompositeNode
Returns an iterable that provides access to the children of the composite node. Will never return null but may be empty.

Specified by:
getChildren in interface ICompositeNode
Returns:
an iterable that provides access to the children of the composite node.
See Also:
ICompositeNode.hasChildren(), ICompositeNode.getFirstChild(), ICompositeNode.getLastChild()

hasChildren

public boolean hasChildren()
Description copied from interface: ICompositeNode
Returns true if this node has any children.

Specified by:
hasChildren in interface ICompositeNode
Returns:
true if this node has any children.
See Also:
ICompositeNode.getChildren(), ICompositeNode.getFirstChild(), ICompositeNode.getLastChild()

getFirstChild

public INode getFirstChild()
Description copied from interface: ICompositeNode
Returns the first child of this node. May be null or may be the same as the last child.

Specified by:
getFirstChild in interface ICompositeNode
Returns:
the first child of this node if any.
See Also:
ICompositeNode.hasChildren(), ICompositeNode.getChildren()

getLastChild

public INode getLastChild()
Description copied from interface: ICompositeNode
Returns the last child of this node. May be null or may be the same as the first child.

Specified by:
getLastChild in interface ICompositeNode
Returns:
the last child of this node if any.
See Also:
ICompositeNode.hasChildren(), ICompositeNode.getChildren()

getLookAhead

public int getLookAhead()
Description copied from interface: ICompositeNode
Return the number of tokens that the parser had to peek before it could decide to create this node. Never negative. Clients will usually not have to deal with ICompositeNode.getLookAhead().

Specified by:
getLookAhead in interface ICompositeNode
Returns:
the number of tokens that the parser had to peek before it could decide to create this node.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object