Package org.codehaus.groovy.syntax
Class CSTNode
java.lang.Object
org.codehaus.groovy.syntax.CSTNode
public abstract class CSTNode
extends java.lang.Object
An abstract base class for nodes in the concrete syntax tree that is
 the result of parsing.  Note that the CSTNode is inextricably linked
 with the Token in that every CSTNode has a Token as its root.
- 
Constructor SummaryConstructors Constructor Description CSTNode()
- 
Method SummaryModifier and Type Method Description CSTNodeadd(CSTNode element)Adds an element to the node.voidaddChildrenOf(CSTNode of)Adds all children of the specified node to this one.abstract ReductionasReduction()Creates aReductionfrom this node.booleancanMean(int type)Returns true if the node can be coerced to the specified type.intchildren()Returns the number of non-root elements in the node.abstract CSTNodeget(int index)Returns the specified element, or null.CSTNodeget(int index, boolean safe)Returns the specified element, or Token.NULL if safe is set and the specified element is null (or doesn't exist).java.lang.StringgetDescription()Returns a description of the node.intgetMeaning()Returns the meaning of this node.intgetMeaningAs(int[] types)Returns the first matching meaning of the specified types.abstract TokengetRoot()Returns the root of the node.TokengetRoot(boolean safe)Returns the root of the node, the Token that indicates its type.java.lang.StringgetRootText()Returns the text of the root.intgetStartColumn()Returns the starting column of the node.intgetStartLine()Returns the starting line of the node.intgetType()Returns the actual type of the node.booleanhasChildren()Returns true if the node has any non-root elements.booleanisA(int type)Returns true if the node's meaning matches the specified type.booleanisAllOf(int[] types)Returns true if the node's meaning matches all of the specified types.booleanisAnExpression()Returns true if the node is a complete expression.booleanisEmpty()Returns true if the node is completely empty (no root, even).booleanisOneOf(int[] types)Returns true if the node's meaning matches any of the specified types.voidmarkAsExpression()Marks the node a complete expression.CSTNodeset(int index, CSTNode element)Sets an element node in at the specified index.CSTNodesetMeaning(int meaning)Sets the meaning for this node (and its root Token).abstract intsize()Returns the number of elements in the node (including root).java.lang.StringtoString()Formats the node as aStringand returns it.voidwrite(java.io.PrintWriter writer)Formats the node and writes it to the specifiedWriter.protected voidwrite(java.io.PrintWriter writer, java.lang.String indent)Formats the node and writes it to the specifiedWriter.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
- 
Constructor Details- 
CSTNodepublic CSTNode()
 
- 
- 
Method Details- 
getMeaningpublic int getMeaning()Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.
- 
setMeaningSets the meaning for this node (and its root Token). Not valid if the node isEmpty(). Returns the node, for convenience.
- 
getTypepublic int getType()Returns the actual type of the node. If the node isEmpty(), returns the type of Token.NULL.
- 
canMeanpublic boolean canMean(int type)Returns true if the node can be coerced to the specified type.
- 
isApublic boolean isA(int type)Returns true if the node's meaning matches the specified type.
- 
isOneOfpublic boolean isOneOf(int[] types)Returns true if the node's meaning matches any of the specified types.
- 
isAllOfpublic boolean isAllOf(int[] types)Returns true if the node's meaning matches all of the specified types.
- 
getMeaningAspublic int getMeaningAs(int[] types)Returns the first matching meaning of the specified types. Returns Types.UNKNOWN if there are no matches.
- 
isEmptypublic boolean isEmpty()Returns true if the node is completely empty (no root, even).
- 
sizepublic abstract int size()Returns the number of elements in the node (including root).
- 
hasChildrenpublic boolean hasChildren()Returns true if the node has any non-root elements.
- 
childrenpublic int children()Returns the number of non-root elements in the node.
- 
getReturns the specified element, or null.
- 
getReturns the specified element, or Token.NULL if safe is set and the specified element is null (or doesn't exist).
- 
getRootReturns the root of the node. By convention, all nodes have a Token as the first element (or root), which indicates the type of the node. May return null if the nodeisEmpty().
- 
getRootReturns the root of the node, the Token that indicates its type. Returns a Token.NULL if safe and the actual root is null.
- 
getRootTextpublic java.lang.String getRootText()Returns the text of the root. UsesgetRoot(true)to get the root, so you will only receive null in return if the root token returns it.
- 
getDescriptionpublic java.lang.String getDescription()Returns a description of the node.
- 
getStartLinepublic int getStartLine()Returns the starting line of the node. Returns -1 if not known.
- 
getStartColumnpublic int getStartColumn()Returns the starting column of the node. Returns -1 if not known.
- 
markAsExpressionpublic void markAsExpression()Marks the node a complete expression. Not all nodes support this operation!
- 
isAnExpressionpublic boolean isAnExpression()Returns true if the node is a complete expression.
- 
addAdds an element to the node. Returns the element for convenience. Not all nodes support this operation!
- 
addChildrenOfAdds all children of the specified node to this one. Not all nodes support this operation!
- 
setSets an element node in at the specified index. Returns the element for convenience. Not all nodes support this operation!
- 
asReductionCreates aReductionfrom this node. Returns self if the node is already aReduction.
- 
toStringpublic java.lang.String toString()Formats the node as aStringand returns it.- Overrides:
- toStringin class- java.lang.Object
 
- 
writepublic void write(java.io.PrintWriter writer)Formats the node and writes it to the specifiedWriter.
- 
writeprotected void write(java.io.PrintWriter writer, java.lang.String indent)Formats the node and writes it to the specifiedWriter. The indent is prepended to each output line, and is increased for each recursion.
 
-