Package org.codehaus.groovy.ast.expr
Class RangeExpression
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.expr.Expression
org.codehaus.groovy.ast.expr.RangeExpression
- All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>,NodeMetaDataHandler
Represents a range expression for creating range objects with bounded endpoints.
Supports inclusive ranges (e.g.,
0..10) and exclusive ranges (e.g., 0..<10 or <0..10).
Range expressions are commonly used in for-loops (e.g., for (i in 0..10)) and other iteration contexts.
The type of a range expression is always ClassHelper.RANGE_TYPE.-
Field Summary
Fields inherited from class org.codehaus.groovy.ast.expr.Expression
EMPTY_ARRAYFields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
ConstructorsConstructorDescriptionRangeExpression(Expression from, Expression to, boolean inclusive) Creates an inclusive or exclusive range expression.RangeExpression(Expression from, Expression to, boolean exclusiveLeft, boolean exclusiveRight) Creates a range expression with full control over inclusivity of both endpoints. -
Method Summary
Modifier and TypeMethodDescriptiongetFrom()Returns the starting expression of the range.getText()Returns a human-readable text representation of this AST node.getTo()Returns the ending expression of the range.booleanIndicates whether the left endpoint is exclusive (uses<..).booleanIndicates whether the right endpoint is exclusive (uses..<).booleanIndicates whether this is an inclusive range (no exclusion on the right endpoint).transformExpression(ExpressionTransformer transformer) Transforms this expression and any nested expressions according to the provided transformer.voidvisit(GroovyCodeVisitor visitor) Accepts a code visitor for AST traversal and transformation.Methods inherited from class org.codehaus.groovy.ast.expr.Expression
getType, setType, transformExpressions, transformExpressionsMethods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
RangeExpression
Creates an inclusive or exclusive range expression.- Parameters:
from- the starting expression (non-null)to- the ending expression (non-null)inclusive- true for inclusive range (no exclusion), false for exclusive right endpoint
-
RangeExpression
public RangeExpression(Expression from, Expression to, boolean exclusiveLeft, boolean exclusiveRight) Creates a range expression with full control over inclusivity of both endpoints.- Parameters:
from- the starting expression (non-null)to- the ending expression (non-null)exclusiveLeft- true if the left endpoint should be excluded (using<..)exclusiveRight- true if the right endpoint should be excluded (using..<)
-
-
Method Details
-
visit
Description copied from class:ASTNodeAccepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.- Overrides:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-
transformExpression
Description copied from class:ExpressionTransforms this expression and any nested expressions according to the provided transformer. This method is called during AST transformation phases and must recursively transform any nested expressions to support full AST tree transformation.- Specified by:
transformExpressionin classExpression- Parameters:
transformer- theExpressionTransformerto apply- Returns:
- a transformed copy of this expression (or this expression itself if no changes are needed)
-
getFrom
Returns the starting expression of the range.- Returns:
- the from expression
-
getTo
Returns the ending expression of the range.- Returns:
- the to expression
-
isInclusive
public boolean isInclusive()Indicates whether this is an inclusive range (no exclusion on the right endpoint).- Returns:
- true if the range is inclusive on the right, false if exclusive
-
isExclusiveLeft
public boolean isExclusiveLeft()Indicates whether the left endpoint is exclusive (uses<..).- Returns:
- true if the left endpoint is excluded, false otherwise
-
isExclusiveRight
public boolean isExclusiveRight()Indicates whether the right endpoint is exclusive (uses..<).- Returns:
- true if the right endpoint is excluded, false otherwise
-
getText
Description copied from class:ASTNodeReturns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type.
-