Class MethodCallExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.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 Summary
Constructors Constructor Description MethodCallExpr(Expression receiver, String methodName, String ownerClass, List<Expression> arguments, boolean isStatic, SourceType type)Creates a method call with an unknown source location.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddArgument(Expression arg)Appends an argument to the call.intgetArgumentCount()NodeList<Expression>getArguments()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.StringgetDescriptor()SourceLocationgetLocation()Gets the source location of this node.StringgetMethodName()StringgetOwnerClass()StringgetOwnerSimpleName()ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetReceiver()SourceTypegetType()Gets the inferred type of this expression.static MethodCallExprinstanceCall(Expression receiver, String methodName, String ownerClass, List<Expression> arguments, SourceType returnType)Creates an instance method call.booleanisStatic()booleanisSuperCall()voidsetMethodName(String methodName)voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetReceiver(Expression receiver)Replaces the receiver, reparenting the new child.static MethodCallExprstaticCall(String ownerClass, String methodName, List<Expression> arguments, SourceType returnType)Creates a static method call with no receiver.StringtoString()MethodCallExprwithDescriptor(String descriptor)Records the JVM method descriptor recovered from bytecode.MethodCallExprwithMethodName(String methodName)Replaces the method name.MethodCallExprwithReceiver(Expression receiver)Replaces the receiver, reparenting the new child and releasing the former one.MethodCallExprwithSuperCall(boolean superCall)Marks whether this call is an invokespecial dispatch to a superclass method.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
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 thismethodName- the invoked method nameownerClass- the declaring class in internal formatarguments- the call arguments, or null for noneisStatic- true for a static calltype- the return type, or null for voidlocation- 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 thismethodName- the invoked method nameownerClass- the declaring class in internal formatarguments- the call arguments, or null for noneisStatic- true for a static calltype- 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
-
getArguments
public NodeList<Expression> getArguments()
- Returns:
- the arguments
-
isStatic
public boolean isStatic()
- Returns:
- whether static
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
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 formatmethodName- the invoked method namearguments- the call arguments, or null for nonereturnType- 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 thismethodName- the invoked method nameownerClass- the declaring class in internal formatarguments- the call arguments, or null for nonereturnType- 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:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-