Class PrefixExpression

All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>, NodeMetaDataHandler

public class PrefixExpression extends Expression
Represents a prefix unary expression like ++i or --value. The operation is applied to the expression before the value is used.

Examples:

  • ++counter - increment counter and return new value
  • --index - decrement index and return new value
See Also:
  • Constructor Details

    • PrefixExpression

      public PrefixExpression(Token operation, Expression expression)
      Creates a prefix expression.
      Parameters:
      operation - the operator token (++ or --)
      expression - the expression to apply the operation to
  • Method Details

    • setExpression

      public void setExpression(Expression expression)
      Sets the expression to apply the prefix operation to.
      Parameters:
      expression - the expression, typically a variable or property
    • getExpression

      public Expression getExpression()
      Returns the expression being modified by the prefix operation.
      Returns:
      the expression
    • getOperation

      public Token getOperation()
      Returns the operator token.
      Returns:
      the ++ or -- token
    • getText

      public String getText()
      Returns a string representation of this prefix expression.
      Overrides:
      getText in class ASTNode
      Returns:
      the text representation, e.g., "(++foo)"
    • getType

      public ClassNode getType()
      Returns the type of this prefix expression, which is the type of the operand.
      Overrides:
      getType in class Expression
      Returns:
      the type of the inner expression
    • toString

      public String toString()
      Returns a debug string representation.
      Overrides:
      toString in class Object
      Returns:
      a string like "PrefixExpression[++foo]"
    • transformExpression

      public Expression transformExpression(ExpressionTransformer transformer)
      Transforms this expression by applying the given transformer to the inner expression, creating a new prefix expression with the transformed operand.
      Specified by:
      transformExpression in class Expression
      Parameters:
      transformer - the ExpressionTransformer to apply
      Returns:
      a new prefix expression with transformed inner expression
    • visit

      public void visit(GroovyCodeVisitor visitor)
      Accepts a GroovyCodeVisitor using the visitor pattern.
      Overrides:
      visit in class ASTNode
      Parameters:
      visitor - the visitor to accept