Class NewExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class NewExpr
    extends Object
    implements Expression
    A constructor call expression - new Type(args), or outer.new Inner(args) when an enclosing instance is present.
    • Constructor Detail

      • NewExpr

        public NewExpr​(Expression enclosingInstance,
                       String className,
                       List<Expression> arguments,
                       SourceType type,
                       SourceLocation location)
        Creates a constructor call, adopting the enclosing instance and arguments as children.
        Parameters:
        enclosingInstance - the outer instance for an inner class creation, or null
        className - the instantiated class in internal format
        arguments - the constructor arguments, or null for none
        type - the expression type; defaults to a reference type over className when null
        location - the source location; defaults to UNKNOWN when null
        Throws:
        NullPointerException - if className is null
      • NewExpr

        public NewExpr​(String className,
                       List<Expression> arguments,
                       SourceType type,
                       SourceLocation location)
        Creates a constructor call with no enclosing instance.
        Parameters:
        className - the instantiated class in internal format
        arguments - the constructor arguments, or null for none
        type - the expression type; defaults to a reference type over className when null
        location - the source location; defaults to UNKNOWN when null
        Throws:
        NullPointerException - if className is null
      • NewExpr

        public NewExpr​(String className,
                       List<Expression> arguments,
                       SourceType type)
        Creates a constructor call at an unknown source location.
        Parameters:
        className - the instantiated class in internal format
        arguments - the constructor arguments, or null for none
        type - the expression type; defaults to a reference type over className when null
        Throws:
        NullPointerException - if className is null
      • NewExpr

        public NewExpr​(String className,
                       List<Expression> arguments)
        Creates a constructor call typed as a reference to the instantiated class.
        Parameters:
        className - the instantiated class in internal format
        arguments - the constructor arguments, or null for none
        Throws:
        NullPointerException - if className is null
      • NewExpr

        public NewExpr​(String className)
        Creates a no-argument constructor call.
        Parameters:
        className - the instantiated class in internal format
        Throws:
        NullPointerException - if className is null
    • Method Detail

      • getEnclosingInstance

        public Expression getEnclosingInstance()
        Returns:
        the enclosing instance
      • setEnclosingInstance

        public void setEnclosingInstance​(Expression enclosingInstance)
        Replaces the enclosing instance, reparenting the new one and releasing the old.
        Parameters:
        enclosingInstance - the outer instance, or null to drop it
      • getClassName

        public String getClassName()
        Returns:
        the class name
      • getDescriptor

        public String getDescriptor()
        Returns:
        the descriptor
      • withDescriptor

        public NewExpr withDescriptor​(String descriptor)
        Records the JVM constructor descriptor recovered from bytecode.
        Parameters:
        descriptor - the constructor descriptor
        Returns:
        this expression
      • getType

        public SourceType getType()
        Description copied from interface: Expression
        Gets the inferred type of this expression.
        Specified by:
        getType in interface Expression
        Returns:
        the type
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Description copied from interface: ASTNode
        Sets the parent node in the AST tree.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the node this expression hangs under
      • addArgument

        public void addArgument​(Expression arg)
        Appends an argument, adopting it as a child.
        Parameters:
        arg - the argument to append
      • getArgumentCount

        public int getArgumentCount()
        Returns:
        the number of constructor arguments
      • getSimpleName

        public String getSimpleName()
        Returns:
        the class name without its package, inner class segments kept
      • isInnerClassCreation

        public boolean isInnerClassCreation()
        Returns:
        true if an enclosing instance is set
      • withEnclosingInstance

        public NewExpr withEnclosingInstance​(Expression enclosingInstance)
        Replaces the enclosing instance, reparenting the new one and releasing the old.
        Parameters:
        enclosingInstance - the outer instance, or null to drop it
        Returns:
        this expression
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor