Class ConstructorCallExpression

All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>, MethodCall, NodeMetaDataHandler

public class ConstructorCallExpression extends Expression implements MethodCall
Represents a constructor call expression. This includes regular object construction (e.g., new MyClass(args)), as well as special constructor calls like this() and super() calls within constructors. The constructor is identified by the type being constructed, and the arguments are wrapped in a TupleExpression. May optionally use an anonymous inner class.
  • Constructor Details

    • ConstructorCallExpression

      public ConstructorCallExpression(ClassNode type, Expression arguments)
      Creates a constructor call expression. Arguments are automatically wrapped in a TupleExpression if not already.
      Parameters:
      type - the type being constructed (non-null), or ClassNode.THIS/ClassNode.SUPER for special calls
      arguments - the constructor arguments (may be a single expression or already a TupleExpression)
  • 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)
    • getReceiver

      public ASTNode getReceiver()
      Specified by:
      getReceiver in interface MethodCall
    • getMethodAsString

      public String getMethodAsString()
      Specified by:
      getMethodAsString in interface MethodCall
    • getArguments

      public Expression getArguments()
      Returns the constructor arguments.
      Specified by:
      getArguments in interface MethodCall
      Returns:
      a TupleExpression containing the arguments
    • 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.
      Specified by:
      getText in interface MethodCall
      Overrides:
      getText in class ASTNode
      Returns:
      text representation of this node, or placeholder for unimplemented types
    • isSpecialCall

      public boolean isSpecialCall()
      Indicates whether this is a special constructor call (this() or super()).
      Returns:
      true if this is a this() or super() call, false for regular constructor calls
    • isSuperCall

      public boolean isSuperCall()
      Indicates whether this is a super() constructor call.
      Returns:
      true if this calls the superclass constructor, false otherwise
    • isThisCall

      public boolean isThisCall()
      Indicates whether this is a this() constructor call.
      Returns:
      true if this calls another constructor in the same class, false otherwise
    • isUsingAnonymousInnerClass

      public boolean isUsingAnonymousInnerClass()
      Indicates whether this constructor call uses an anonymous inner class.
      Returns:
      true if an anonymous inner class is being created, false for regular construction
    • setUsingAnonymousInnerClass

      public void setUsingAnonymousInnerClass(boolean usage)
      Sets whether this constructor call uses an anonymous inner class.
      Parameters:
      usage - true if an anonymous inner class is being used, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object