Package org.codehaus.groovy.syntax
Class CSTNode
- java.lang.Object
- 
- org.codehaus.groovy.syntax.CSTNode
 
- 
 public abstract class CSTNode extends java.lang.ObjectAn 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 it's root.
- 
- 
Constructor SummaryConstructors Constructor Description CSTNode()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier 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 it's 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 it's 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.
 
- 
- 
- 
Method Detail- 
getMeaningpublic int getMeaning() Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.
 - 
setMeaningpublic CSTNode setMeaning(int meaning) Sets the meaning for this node (and it's 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.
 - 
getpublic abstract CSTNode get(int index) Returns the specified element, or null.
 - 
getpublic CSTNode get(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).
 - 
getRootpublic abstract Token getRoot() Returns 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().
 - 
getRootpublic Token getRoot(boolean safe) Returns the root of the node, the Token that indicates it's 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.
 - 
addpublic CSTNode add(CSTNode element) Adds an element to the node. Returns the element for convenience. Not all nodes support this operation!
 - 
addChildrenOfpublic void addChildrenOf(CSTNode of) Adds all children of the specified node to this one. Not all nodes support this operation!
 - 
setpublic CSTNode set(int index, CSTNode element) Sets an element node in at the specified index. Returns the element for convenience. Not all nodes support this operation!
 - 
asReductionpublic abstract Reduction asReduction() Creates 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.
 
- 
 
-