Class RangeExpression

All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>, NodeMetaDataHandler

public class RangeExpression extends Expression
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.
  • Constructor Details

    • RangeExpression

      public RangeExpression(Expression from, Expression to, boolean inclusive)
      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

      public void visit(GroovyCodeVisitor visitor)
      Description copied from class: ASTNode
      Accepts 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:
      visit in class ASTNode
      Parameters:
      visitor - the GroovyCodeVisitor to process this node
    • transformExpression

      public Expression transformExpression(ExpressionTransformer transformer)
      Description copied from class: Expression
      Transforms 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:
      transformExpression in class Expression
      Parameters:
      transformer - the ExpressionTransformer to apply
      Returns:
      a transformed copy of this expression (or this expression itself if no changes are needed)
    • getFrom

      public Expression getFrom()
      Returns the starting expression of the range.
      Returns:
      the from expression
    • getTo

      public 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

      public String getText()
      Description copied from class: ASTNode
      Returns 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.
      Overrides:
      getText in class ASTNode
      Returns:
      text representation of this node, or placeholder for unimplemented types