public final class MethodCall extends CallableOperation
Operation
that represents a call to a method. It is a wrapper for a
reflective Method object, and caches values of computed reflective calls.
An an Operation
, a call to a non-static method
T mname (T1,...,Tn)
of class C can be represented formally as an operation
mname: [C, T1,...,Tn] → T.
If this method is static, then we could write the operation as
C.mname: [T1,...,Tn] → T
(a class instance not being needed as an input).
The execution of a MethodCall
executes the enclosed Method
given values for
the inputs.
(Class previously called RMethod.)
Modifier and Type | Field and Description |
---|---|
private boolean |
isStatic
True if the method is static.
|
private java.lang.reflect.Method |
method
The method that is called by this MethodCall.
|
Constructor and Description |
---|
MethodCall(java.lang.reflect.Method method)
Creates an object corresponding to a call to the given method.
|
Modifier and Type | Method and Description |
---|---|
void |
appendCode(Type declaringType,
TypeTuple inputTypes,
Type outputType,
java.util.List<Variable> inputVars,
java.lang.StringBuilder sb)
Produces a Java source code representation of this statement and appends it to the given
StringBuilder.
|
boolean |
equals(@Nullable java.lang.Object o) |
ExecutionOutcome |
execute(java.lang.Object[] input)
Performs this operation using the array of input values.
|
java.lang.reflect.Method |
getMethod()
getMethod returns Method object of this MethodCall.
|
java.lang.String |
getName()
Returns the name for the operation.
|
java.lang.reflect.Method |
getReflectionObject() |
int |
hashCode() |
boolean |
isMessage()
Predicate to indicate whether object represents a method-call-like operation (either static or
instance).
|
boolean |
isMethodCall()
Indicates whether this object represents a method-call operation (either static or instance).
|
boolean |
isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.
|
static TypedClassOperation |
parse(java.lang.String signature)
Parses a method signature (not a representation of a call; there are no arguments, for
example) and returns a
MethodCall object. |
boolean |
satisfies(ReflectionPredicate reflectionPredicate)
Checks whether reflective object contained in an
Operation satisfies the predicate. |
java.lang.String |
toParsableString(Type declaringType,
TypeTuple inputTypes,
Type outputType)
Returns a string representation of this Operation (not an invocation of this Operation), which
can be read by the static parse method for the class in which the method is defined.
|
java.lang.String |
toString()
toString outputs a text representation of the method, but not of a method call.
|
getArgumentString, getValue, isConstantField, isConstructorCall, isNonreceivingValue, isUncheckedCast
private final java.lang.reflect.Method method
private final boolean isStatic
public MethodCall(java.lang.reflect.Method method)
method
- the reflective method objectpublic java.lang.reflect.Method getMethod()
Method
object called by this MethodCall
public java.lang.String toString()
toString
in class java.lang.Object
public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, java.util.List<Variable> inputVars, java.lang.StringBuilder sb)
Issues the code that corresponds to calling the method with the provided Variable
objects as arguments.
appendCode
in class CallableOperation
inputVars
- is the list of actual arguments to be printeddeclaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operationsb
- the StringBuilder
to which code is addedpublic boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public ExecutionOutcome execute(java.lang.Object[] input)
execute
in class CallableOperation
input
- array containing appropriate inputs to operationNormalExecution
with return value if execution was normal, otherwise a ExceptionalExecution
if an exception was thrownpublic boolean isStatic()
isStatic
in interface Operation
isStatic
in class CallableOperation
public java.lang.String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
The descriptor for a method is a string representing the method signature.
Examples: java.util.ArrayList.get(int) java.util.ArrayList.add(int,java.lang.Object)
toParsableString
in class CallableOperation
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operationpublic static TypedClassOperation parse(java.lang.String signature) throws OperationParseException
MethodCall
object. Should satisfy parse(op.toParsableString()).equals(op)
for Operation op.signature
- a string descriptorOperationParseException
- if s does not match expected descriptorOperationParser.parse(String)
public boolean isMessage()
isMessage
in interface Operation
isMessage
in class CallableOperation
public boolean isMethodCall()
isMethodCall
in interface Operation
isMethodCall
in class CallableOperation
public java.lang.String getName()
Operation
public java.lang.reflect.Method getReflectionObject()
getReflectionObject
in class CallableOperation
public boolean satisfies(ReflectionPredicate reflectionPredicate)
Operation
satisfies the predicate.
Since there is no reflective object in an CallableOperation
, returns false.
Determines whether enclosed Method
satisfies the given predicate.
satisfies
in interface Operation
satisfies
in class CallableOperation
reflectionPredicate
- the ReflectionPredicate
to be checked