Class MethodCallExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class MethodCallExpr
    extends Object
    implements Expression
    A method call expression: obj.method(args) or Type.staticMethod(args).
    • Constructor Detail

      • MethodCallExpr

        public MethodCallExpr​(Expression receiver,
                              String methodName,
                              String ownerClass,
                              List<Expression> arguments,
                              boolean isStatic,
                              SourceType type,
                              SourceLocation location)
        Creates a method call, reparenting the receiver and arguments.
        Parameters:
        receiver - the receiver expression, or null for static calls or implicit this
        methodName - the invoked method name
        ownerClass - the declaring class in internal format
        arguments - the call arguments, or null for none
        isStatic - true for a static call
        type - the return type, or null for void
        location - the source location, or null for unknown
        Throws:
        NullPointerException - if methodName or ownerClass is null
      • MethodCallExpr

        public MethodCallExpr​(Expression receiver,
                              String methodName,
                              String ownerClass,
                              List<Expression> arguments,
                              boolean isStatic,
                              SourceType type)
        Creates a method call with an unknown source location.
        Parameters:
        receiver - the receiver expression, or null for static calls or implicit this
        methodName - the invoked method name
        ownerClass - the declaring class in internal format
        arguments - the call arguments, or null for none
        isStatic - true for a static call
        type - the return type, or null for void
        Throws:
        NullPointerException - if methodName or ownerClass is null
    • Method Detail

      • getReceiver

        public Expression getReceiver()
        Returns:
        the receiver
      • setReceiver

        public void setReceiver​(Expression receiver)
        Replaces the receiver, reparenting the new child.
        Parameters:
        receiver - the new receiver, or null for static calls or implicit this
      • getMethodName

        public String getMethodName()
        Returns:
        the method name
      • setMethodName

        public void setMethodName​(String methodName)
        Parameters:
        methodName - the new method name
      • getOwnerClass

        public String getOwnerClass()
        Returns:
        the owner class
      • getDescriptor

        public String getDescriptor()
        Returns:
        the descriptor
      • withDescriptor

        public MethodCallExpr withDescriptor​(String descriptor)
        Records the JVM method descriptor recovered from bytecode.
        Parameters:
        descriptor - the method descriptor
        Returns:
        this expression
      • isSuperCall

        public boolean isSuperCall()
        Returns:
        whether super call
      • withSuperCall

        public MethodCallExpr withSuperCall​(boolean superCall)
        Marks whether this call is an invokespecial dispatch to a superclass method.
        Parameters:
        superCall - true for a super.m() call
        Returns:
        this expression
      • isStatic

        public boolean isStatic()
        Returns:
        whether static
      • 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 enclosing AST node
      • staticCall

        public static MethodCallExpr staticCall​(String ownerClass,
                                                String methodName,
                                                List<Expression> arguments,
                                                SourceType returnType)
        Creates a static method call with no receiver.
        Parameters:
        ownerClass - the declaring class in internal format
        methodName - the invoked method name
        arguments - the call arguments, or null for none
        returnType - the return type, or null for void
        Returns:
        the new call
      • instanceCall

        public static MethodCallExpr instanceCall​(Expression receiver,
                                                  String methodName,
                                                  String ownerClass,
                                                  List<Expression> arguments,
                                                  SourceType returnType)
        Creates an instance method call.
        Parameters:
        receiver - the receiver expression, or null for implicit this
        methodName - the invoked method name
        ownerClass - the declaring class in internal format
        arguments - the call arguments, or null for none
        returnType - the return type, or null for void
        Returns:
        the new call
      • addArgument

        public void addArgument​(Expression arg)
        Appends an argument to the call.
        Parameters:
        arg - the argument expression to add
      • getArgumentCount

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

        public String getOwnerSimpleName()
        Returns:
        the simple name of the owner class, keeping inner-class segments
      • withReceiver

        public MethodCallExpr withReceiver​(Expression receiver)
        Replaces the receiver, reparenting the new child and releasing the former one.
        Parameters:
        receiver - the new receiver, or null for static calls or implicit this
        Returns:
        this expression
      • withMethodName

        public MethodCallExpr withMethodName​(String methodName)
        Replaces the method name.
        Parameters:
        methodName - the new method name
        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