Package randoop.operation
Class MethodCall
java.lang.Object
randoop.operation.CallableOperation
randoop.operation.MethodCall
- All Implemented Interfaces:
Operation
MethodCall is a
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.)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMethodCall
(Method method) MethodCall creates an object corresponding to the given reflective method. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Performs this operation using the array of input values.getMethod returns Method object of this MethodCall.getName()
Returns the name for the operation.int
hashCode()
boolean
Predicate to indicate whether object represents a method-call-like operation (either static or instance).boolean
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
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.toParsableString
(Type declaringType, TypeTuple inputTypes, Type outputType) Returns a string representation of this Operation, which can be read by static parse method for class.toString()
toString outputs a text representation of the method call.Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getValue, isConstantField, isConstructorCall, isNonreceivingValue, isUncheckedCast
-
Field Details
-
method
-
isStatic
private final boolean isStatic
-
-
Constructor Details
-
MethodCall
MethodCall creates an object corresponding to the given reflective method.- Parameters:
method
- the reflective method object
-
-
Method Details
-
getMethod
getMethod returns Method object of this MethodCall.- Returns:
Method
object called by thisMethodCall
-
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
-
equals
-
hashCode
public int hashCode() -
execute
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
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
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:
-
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
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
getReflectionObject
- Overrides:
getReflectionObject
in classCallableOperation
-
satisfies
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
-