Package randoop.operation
Class MethodCall
- java.lang.Object
-
- randoop.operation.CallableOperation
-
- randoop.operation.MethodCall
-
- All Implemented Interfaces:
Operation
public final class MethodCall extends CallableOperation
MethodCall is aOperation
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 enclosedMethod
given values for the inputs.(Class previously called RMethod.)
-
-
Constructor Summary
Constructors Constructor Description MethodCall(Method method)
Creates an object corresponding to a call to the given method.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder sb)
Produces a Java source code representation of this statement and appends it to the given StringBuilder.boolean
equals(Object o)
ExecutionOutcome
execute(Object[] input)
Performs this operation using the array of input values.Method
getMethod()
getMethod returns Method object of this MethodCall.String
getName()
Returns the name for the operation.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(String signature)
Parses a method signature (not a representation of a call; there are no arguments, for example) and returns aMethodCall
object.boolean
satisfies(ReflectionPredicate reflectionPredicate)
Checks whether reflective object contained in anOperation
satisfies the predicate.String
toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
Returns a string representation of this Operation, which can be read by static parse method for class.String
toString()
toString outputs a text representation of the method call.-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getValue, isConstantField, isConstructorCall, isNonreceivingValue, isUncheckedCast
-
-
-
-
Field Detail
-
method
private final Method method
The method that is called by this MethodCall.
-
isStatic
private final boolean isStatic
True if the method is static.
-
-
Constructor Detail
-
MethodCall
public MethodCall(Method method)
Creates an object corresponding to a call to the given method.- Parameters:
method
- the reflective method object
-
-
Method Detail
-
getMethod
public Method getMethod()
getMethod returns Method object of this MethodCall.- Returns:
Method
object called by thisMethodCall
-
toString
public String toString()
toString outputs a text representation of the method call.
-
appendCode
public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder sb)
Produces a Java source code representation of this statement and appends it to the given StringBuilder.Issues the code that corresponds to calling the method with the provided
Variable
objects as arguments.- Specified by:
appendCode
in classCallableOperation
- Parameters:
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
- theStringBuilder
to which code is added
-
execute
public ExecutionOutcome execute(Object[] input)
Performs this operation using the array of input values. Returns the results of execution as an ResultOrException object and can output results to specified PrintStream.- Specified by:
execute
in classCallableOperation
- Parameters:
input
- array containing appropriate inputs to operation- Returns:
- a
NormalExecution
with return value if execution was normal, otherwise aExceptionalExecution
if an exception was thrown
-
isStatic
public boolean isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.- Specified by:
isStatic
in interfaceOperation
- Overrides:
isStatic
in classCallableOperation
- Returns:
- true if this method is static, and false otherwise
-
toParsableString
public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
Returns a string representation of this Operation, which can be read by static parse method for class. For a class C implementing the Operation interface, this method should return a String s such that parsing the string returns an object equivalent to this object, i.e. C.parse(this.s).equals(this).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)
- Specified by:
toParsableString
in classCallableOperation
- Parameters:
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operation- Returns:
- a string representation of this operation
-
parse
public static TypedClassOperation parse(String signature) throws OperationParseException
Parses a method signature (not a representation of a call; there are no arguments, for example) and returns aMethodCall
object. Should satisfyparse(op.toParsableString()).equals(op)
for Operation op.- Parameters:
signature
- a string descriptor- Returns:
- the method call operation for the given string descriptor
- Throws:
OperationParseException
- if s does not match expected descriptor- See Also:
OperationParser.parse(String)
-
isMessage
public boolean isMessage()
Predicate to indicate whether object represents a method-call-like operation (either static or instance). This includes field getters and setters, which are operations that access fields.- Specified by:
isMessage
in interfaceOperation
- Overrides:
isMessage
in classCallableOperation
- Returns:
- true always, since this is a method call
-
isMethodCall
public boolean isMethodCall()
Indicates whether this object represents a method-call operation (either static or instance). This excludes getters and setters.- Specified by:
isMethodCall
in interfaceOperation
- Overrides:
isMethodCall
in classCallableOperation
- Returns:
- true always, since this is a method call
-
getName
public String getName()
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
getReflectionObject
public Method getReflectionObject()
- Overrides:
getReflectionObject
in classCallableOperation
-
satisfies
public boolean satisfies(ReflectionPredicate reflectionPredicate)
Checks whether reflective object contained in anOperation
satisfies the predicate. Since there is no reflective object in anCallableOperation
, returns false.Determines whether enclosed
Method
satisfies the given predicate.- Specified by:
satisfies
in interfaceOperation
- Overrides:
satisfies
in classCallableOperation
- Parameters:
reflectionPredicate
- theReflectionPredicate
to be checked- Returns:
- true only if the method in this object satisfies the canUse(Method) of predicate
-
-