Package org.codehaus.groovy.syntax
Class Reduction
java.lang.Object
org.codehaus.groovy.syntax.CSTNode
org.codehaus.groovy.syntax.Reduction
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an element to the end of this reduction.Creates aReductionfrom this node.get(int index) Returns the element at the specified index, ornullif the index is out of bounds.getRoot()Returns the root token of this reduction.booleanReturnstrueif this node represents a complete expression.booleanisEmpty()Returnstrueif this reduction is completely empty (no elements, not even a root).voidMarks this reduction as a complete expression.static ReductionCreates a new Reduction withToken.NULLas its root.remove(int index) Removes the element at the specified index.Sets the element at the specified index.intsize()Returns the number of elements in this reduction (including the root token).Methods inherited from class org.codehaus.groovy.syntax.CSTNode
addChildrenOf, canMean, children, get, getDescription, getMeaning, getMeaningAs, getRoot, getRootText, getStartColumn, getStartLine, getType, hasChildren, isA, isAllOf, isOneOf, setMeaning, toString, write, write
-
Field Details
-
EMPTY
Singleton empty reduction (read-only).
-
-
Constructor Details
-
Reduction
Constructs a Reduction with the specified root token.- Parameters:
root- the rootTokenof this reduction
-
-
Method Details
-
newContainer
Creates a new Reduction withToken.NULLas its root. Useful for creating container nodes with no specific type.- Returns:
- a new Reduction with a null root token
-
isEmpty
public boolean isEmpty()Returnstrueif this reduction is completely empty (no elements, not even a root). -
size
public int size()Returns the number of elements in this reduction (including the root token). -
get
Returns the element at the specified index, ornullif the index is out of bounds. -
getRoot
Returns the root token of this reduction. The root is always at index 0 and indicates the syntactic type. -
markAsExpression
public void markAsExpression()Marks this reduction as a complete expression. This flag is used by the parser to distinguish complete expressions from partial constructs.- Overrides:
markAsExpressionin classCSTNode
-
isAnExpression
public boolean isAnExpression()Returnstrueif this node represents a complete expression. A reduction is considered an expression if it has theTypes.COMPLEX_EXPRESSIONmeaning or has been explicitly marked as an expression.- Overrides:
isAnExpressionin classCSTNode- Returns:
trueif this is an expression
-
add
Adds an element to the end of this reduction. -
set
Sets the element at the specified index. If the index is beyond the current size, intermediate positions are filled withnull. The root element (index 0) must be aToken.- Overrides:
setin classCSTNode- Parameters:
index- the element indexelement- the element to set- Returns:
- the set element
- Throws:
GroovyBugError- if trying to set a non-Token as root, or if operating onEMPTY
-
remove
Removes the element at the specified index. Cannot remove the root element (index 0).- Parameters:
index- the element index (must be > 0)- Returns:
- the removed element
- Throws:
GroovyBugError- if trying to remove the root element
-
asReduction
Creates aReductionfrom this node. Returns self if the node is already aReduction.- Specified by:
asReductionin classCSTNode- Returns:
- this node as a Reduction
-