Groovy 1.7.0

org.codehaus.groovy.syntax
Class CSTNode

java.lang.Object
  org.codehaus.groovy.syntax.CSTNode

class CSTNode
extends 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 it's root.

see:
Parser
see:
Token
see:
Reduction
see:
Types
author:
bob mcwhirter
author:
Chris Poirier
version:
$Id: CSTNode.java 7922 2007-09-04 01:42:57Z paulk $


Constructor Summary
CSTNode()

 
Method Summary
CSTNode add(CSTNode element)

Adds an element to the node.

void addChildrenOf(CSTNode of)

Adds all children of the specified node to this one.

Reduction asReduction()

Creates a Reduction from this node.

boolean canMean(int type)

Returns true if the node can be coerced to the specified type.

int children()

Returns the number of non-root elements in the node.

CSTNode get(int index)

Returns the specified element, or null.

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).

String getDescription()

Returns a description of the node.

int getMeaning()

Returns the meaning of this node.

int getMeaningAs(int[] types)

Returns the first matching meaning of the specified types.

Token getRoot()

Returns the root of the node.

Token getRoot(boolean safe)

Returns the root of the node, the Token that indicates it's type.

String getRootText()

Returns the text of the root.

int getStartColumn()

Returns the starting column of the node.

int getStartLine()

Returns the starting line of the node.

int getType()

Returns the actual type of the node.

boolean hasChildren()

Returns true if the node has any non-root elements.

boolean isA(int type)

Returns true if the node's meaning matches the specified type.

boolean isAllOf(int[] types)

Returns true if the node's meaning matches all of the specified types.

boolean isAnExpression()

Returns true if the node is a complete expression.

boolean isEmpty()

Returns true if the node is completely empty (no root, even).

boolean isOneOf(int[] types)

Returns true if the node's meaning matches any of the specified types.

void markAsExpression()

Marks the node a complete expression.

boolean matches(int type)

Returns true if the node matches the specified type.

boolean matches(int type, int child1)

Returns true if the node and it's first child match the specified types.

boolean matches(int type, int child1, int child2)

Returns true if the node and it's first and second child match the specified types.

boolean matches(int type, int child1, int child2, int child3)

Returns true if the node and it's first three children match the specified types.

boolean matches(int type, int child1, int child2, int child3, int child4)

Returns true if the node an it's first four children match the specified types.

CSTNode set(int index, CSTNode element)

Sets an element node in at the specified index.

CSTNode setMeaning(int meaning)

Sets the meaning for this node (and it's root Token).

int size()

Returns the number of elements in the node (including root).

String toString()

Formats the node as a String and returns it.

void write(PrintWriter writer)

Formats the node and writes it to the specified Writer.

protected void write(PrintWriter writer, String indent)

Formats the node and writes it to the specified Writer.

 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Constructor Detail

CSTNode

CSTNode()


 
Method Detail

add

public CSTNode add(CSTNode element)
Adds an element to the node. Returns the element for convenience. Not all nodes support this operation!


addChildrenOf

public void addChildrenOf(CSTNode of)
Adds all children of the specified node to this one. Not all nodes support this operation!


asReduction

public Reduction asReduction()
Creates a Reduction from this node. Returns self if the node is already a Reduction.


canMean

public boolean canMean(int type)
Returns true if the node can be coerced to the specified type.


children

public int children()
Returns the number of non-root elements in the node.


get

public CSTNode get(int index)
Returns the specified element, or null.


get

public 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).


getDescription

public String getDescription()
Returns a description of the node.


getMeaning

public int getMeaning()
Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.


getMeaningAs

public int getMeaningAs(int[] types)
Returns the first matching meaning of the specified types. Returns Types.UNKNOWN if there are no matches.


getRoot

public 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 node isEmpty().


getRoot

public 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.


getRootText

public String getRootText()
Returns the text of the root. Uses getRoot(true) to get the root, so you will only receive null in return if the root token returns it.


getStartColumn

public int getStartColumn()
Returns the starting column of the node. Returns -1 if not known.


getStartLine

public int getStartLine()
Returns the starting line of the node. Returns -1 if not known.


getType

public int getType()
Returns the actual type of the node. If the node isEmpty(), returns the type of Token.NULL.


hasChildren

public boolean hasChildren()
Returns true if the node has any non-root elements.


isA

public boolean isA(int type)
Returns true if the node's meaning matches the specified type.


isAllOf

public boolean isAllOf(int[] types)
Returns true if the node's meaning matches all of the specified types.


isAnExpression

public boolean isAnExpression()
Returns true if the node is a complete expression.


isEmpty

public boolean isEmpty()
Returns true if the node is completely empty (no root, even).


isOneOf

public boolean isOneOf(int[] types)
Returns true if the node's meaning matches any of the specified types.


markAsExpression

public void markAsExpression()
Marks the node a complete expression. Not all nodes support this operation!


matches

public boolean matches(int type)
Returns true if the node matches the specified type. Effectively a synonym for isA(). Missing nodes are Token.NULL.


matches

public boolean matches(int type, int child1)
Returns true if the node and it's first child match the specified types. Missing nodes are Token.NULL.


matches

public boolean matches(int type, int child1, int child2)
Returns true if the node and it's first and second child match the specified types. Missing nodes are Token.NULL.


matches

public boolean matches(int type, int child1, int child2, int child3)
Returns true if the node and it's first three children match the specified types. Missing nodes are Token.NULL.


matches

public boolean matches(int type, int child1, int child2, int child3, int child4)
Returns true if the node an it's first four children match the specified types. Missing nodes have type Types.NULL.


set

public 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!


setMeaning

public 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.


size

public int size()
Returns the number of elements in the node (including root).


toString

public String toString()
Formats the node as a String and returns it.


write

public void write(PrintWriter writer)
Formats the node and writes it to the specified Writer.


write

protected void write(PrintWriter writer, String indent)
Formats the node and writes it to the specified Writer. The indent is prepended to each output line, and is increased for each recursion.


 

Copyright © 2003-2009 The Codehaus. All rights reserved.