Package randoop.operation
Class TypedOperation
java.lang.Object
randoop.operation.TypedOperation
- All Implemented Interfaces:
Comparable<TypedOperation>
,Operation
- Direct Known Subclasses:
TypedClassOperation
,TypedTermOperation
public abstract class TypedOperation
extends Object
implements Operation, Comparable<TypedOperation>
Type decorator of
Operation
objects. An operation has zero or more input types, and one
output type that may be void
.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
RankedTypedOperation is a wrapper around a TypedOperation and a number. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator<TypedOperation.RankedTypeOperation>
Comparator used for sorting by ranking.private ExecutableSpecification
The specification for this operation.protected final TypeTuple
The type tuple of input types.private final CallableOperation
The operation to be decorated.private final Type
The output type. -
Constructor Summary
ConstructorDescriptionTypedOperation
(CallableOperation operation, TypeTuple inputTypes, Type outputType, @Nullable ExecutableSpecification execSpec) Create typed operation for the givenOperation
. -
Method Summary
Modifier and TypeMethodDescriptionprivate Object[]
addNullReceiverIfStatic
(Object[] values) Insertsnull
as first argument when this operation is static.abstract void
appendCode
(List<Variable> inputVars, StringBuilder b) Appends Java text for this operation to the givenStringBuilder
, and using the given variables.abstract TypedOperation
Applies a capture conversion to the wildcard types of this operation, and returns a new operation with new type variables for the wildcard types.checkPrestate
(Object[] values) Tests the specification for this operation against the argument values and returns theExpectedOutcomeTable
indicating the results of checking the pre-conditions of the specifications of the operation.final int
compareTo
(TypedOperation other) Compares thisTypedOperation
to another.static TypedOperation
createArrayCreation
(ArrayType arrayType) Creates a simple array creation operation for the given type.static TypedOperation
createArrayElementAssignment
(ArrayType arrayType) Creates an operation to assign a value to an array element.static TypedOperation
createCast
(Type fromType, Type toType) Creates an operation to cast from one type to another.static TypedClassOperation
createGetterForField
(Field field, ClassOrInterfaceType declaringType) Creates aTypedOperation
that represents a read access to a field.static TypedOperation
createInitializedArrayCreation
(ArrayType arrayType, int size) Creates an operation that creates an array of the given type and size.static TypedOperation
Creates an operation that uses the givenNonreceiverTerm
for initializing a variable.static TypedOperation
Creates an operation that initializes a variable to the zero value for the given type.static TypedOperation
createPrimitiveInitialization
(Type type, Object value) Creates an operation that initializes a variable to a given primitive value.static TypedClassOperation
createSetterForField
(Field field, ClassOrInterfaceType declaringType) Creates aTypedOperation
that represents a write access to a field.boolean
Performs this operation using the array of input values.static TypedClassOperation
forConstructor
(Constructor<?> constructor) Constructs aTypedOperation
for a constructor object.static TypedClassOperation
Constructs aTypedOperation
for a method object.private static TypedClassOperation
getAnonEnumOperation
(Method method, List<Type> methodParamTypes, Class<?> enumClass) Constructs aTypedOperation
for an enum from a method object that is a member of an anonymous class for an enum constant.Returns the specification.Returns the tuple of input types for this operation.getName()
Returns the name for the operation.Get the enclosed operation in this typed operation.Returns the output type returned by the operation.Returns the signature string for this operation.Returns an empty list representing the type parameters of this.getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form.int
hashCode()
abstract boolean
Indicates whether this operation has a type that is a wildcard type.boolean
Predicate to indicate whether this object represents a constant field.boolean
Predicate to indicate whether object represents a call to a constructor.final boolean
Indicate whether this operation is generic.boolean
isGeneric
(boolean ignoreWildcards) Indicate whether this operation is generic.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
Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).boolean
isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.boolean
Predicate to indicate whether this object represents an unchecked cast.boolean
satisfies
(ReflectionPredicate reflectionPredicate) Determines whether the reflective object in thisOperation
satisfies thecanUse
criteria of the givenReflectionPredicate
.void
Sets the specification; any previous value is ignored.abstract TypedOperation
substitute
(Substitution substitution) Applies the given substitution to the generic types in this operation, and returns a new operation with the instantiated types.abstract String
Constructs a string representation of this operation that can be parsed by parse methods of the implementing types.toString()
-
Field Details
-
operation
The operation to be decorated. -
inputTypes
The type tuple of input types. For a non-static method call or an instance field access, the first input type is always that of the receiver, that is, the declaring class of the method or the field. Refer toOperation
. -
outputType
The output type. -
execSpec
The specification for this operation. -
compareRankedTypeOperation
Comparator used for sorting by ranking.
-
-
Constructor Details
-
TypedOperation
TypedOperation(CallableOperation operation, TypeTuple inputTypes, Type outputType, @Nullable ExecutableSpecification execSpec) Create typed operation for the givenOperation
.- Parameters:
operation
- the operation to wrapinputTypes
- the input typesoutputType
- the output typesexecSpec
- the specification for the operation
-
-
Method Details
-
setExecutableSpecification
Sets the specification; any previous value is ignored.- Parameters:
execSpec
- the specification to use for this object
-
getExecutableSpecification
Returns the specification.- Returns:
- the specification to use for this object
-
equals
-
compareTo
Compares thisTypedOperation
to another. Orders operations by type (anyTypedTermOperation
object precedes aTypedClassOperation
) then lexicographically (alphabetically comparing class names, then operation names, then input type names, and finally output type names).- Specified by:
compareTo
in interfaceComparable<TypedOperation>
- Parameters:
other
- theTypedOperation
to compare with this operation- Returns:
- value < 0 if this operation precedes
op
, 0 if the operations are identical, and > 0 if this operation succeeds op
-
hashCode
public int hashCode() -
toString
-
getName
Description copied from interface:Operation
Returns the name for the operation. -
getSignatureString
Returns the signature string for this operation.- Returns:
- a string with the fully-qualified operation name and input type-tuple
-
getInputTypes
Returns the tuple of input types for this operation. For a non-static method call or an instance field access, the first input type is always the declaring class of the method or field.- Returns:
- tuple of concrete input types
-
getOutputType
Returns the output type returned by the operation.- Returns:
Type
type returned by this operation
-
getOperation
Get the enclosed operation in this typed operation.- Returns:
- the enclosed operation
-
hasWildcardTypes
public abstract boolean hasWildcardTypes()Indicates whether this operation has a type that is a wildcard type.- Returns:
- true if at least one input or output type has a wildcard, false otherwise
-
isGeneric
public final boolean isGeneric()Indicate whether this operation is generic. An operation is generic if any of its input and output types are generic.- Returns:
- true if the operation is generic, false if not
-
isGeneric
public boolean isGeneric(boolean ignoreWildcards) Indicate whether this operation is generic. An operation is generic if any of its input and output types are generic.- Parameters:
ignoreWildcards
- if true, ignore wildcards; that is, treat wildcards as not making the operation generic- Returns:
- true if the operation is generic, false if not
-
isStatic
public boolean isStatic()Description copied from interface:Operation
Predicate to indicate whether object represents a static operation on the declaring class. -
isMessage
public boolean isMessage()Description copied from interface:Operation
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. -
isMethodCall
public boolean isMethodCall()Description copied from interface:Operation
Indicates whether this object represents a method-call operation (either static or instance). This excludes getters and setters.- Specified by:
isMethodCall
in interfaceOperation
- Returns:
- true if this operation is a method call, and false otherwise
-
isConstantField
public boolean isConstantField()Description copied from interface:Operation
Predicate to indicate whether this object represents a constant field.- Specified by:
isConstantField
in interfaceOperation
- Returns:
- true if this operation is a constant field, and false otherwise
-
isConstructorCall
public boolean isConstructorCall()Description copied from interface:Operation
Predicate to indicate whether object represents a call to a constructor.- Specified by:
isConstructorCall
in interfaceOperation
- Returns:
- true if operation is a constructor call, and false otherwise
-
isNonreceivingValue
public boolean isNonreceivingValue()Description copied from interface:Operation
Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).- Specified by:
isNonreceivingValue
in interfaceOperation
- Returns:
- true if object is a non-receiving value, and false otherwise
-
getValue
Description copied from interface:Operation
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form. Only null if value is null, otherwise throws an exception if there is not a reasonable meaning of value for type of operation.This is a hack to allow randoop.main.GenBranchDir to do mutation.
-
satisfies
Description copied from interface:Operation
Determines whether the reflective object in thisOperation
satisfies thecanUse
criteria of the givenReflectionPredicate
.- Specified by:
satisfies
in interfaceOperation
- Parameters:
reflectionPredicate
- aReflectionPredicate
to be checked- Returns:
- result of applying reflectionPredicate to object
-
appendCode
Appends Java text for this operation to the givenStringBuilder
, and using the given variables.- Parameters:
inputVars
- the list of input variables for this operationb
- theStringBuilder
-
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.- Parameters:
input
- array containing appropriate inputs to operation- Returns:
- results of executing this statement
-
substitute
Applies the given substitution to the generic types in this operation, and returns a new operation with the instantiated types.- Parameters:
substitution
- the substitution- Returns:
- the operation resulting from applying the substitution to the types of this operation
-
applyCaptureConversion
Applies a capture conversion to the wildcard types of this operation, and returns a new operation with new type variables for the wildcard types.- Returns:
- the operation result from applying a capture conversion to wildcard types of this operation
-
getTypeParameters
Returns an empty list representing the type parameters of this. Clients will mutate the list.- Returns:
- an empty list representing the type parameters of this
-
toParsableString
Constructs a string representation of this operation that can be parsed by parse methods of the implementing types.- Returns:
- a string representation of this operation
-
forConstructor
Constructs aTypedOperation
for a constructor object.- Parameters:
constructor
- the reflective constructor object- Returns:
- the typed operation for the constructor
-
forMethod
Constructs aTypedOperation
for a method object.- Parameters:
method
- the reflective method object- Returns:
- the typed operation for the given method
-
getAnonEnumOperation
private static TypedClassOperation getAnonEnumOperation(Method method, List<Type> methodParamTypes, Class<?> enumClass) Constructs aTypedOperation
for an enum from a method object that is a member of an anonymous class for an enum constant. Will return null if no matching method is found in the enum.- Parameters:
method
- the method of the anonymous classmethodParamTypes
- the parameter types of the methodenumClass
- the declaring class- Returns:
- the typed operation for the given method, null if no matching method is found in
enumClass
-
createGetterForField
public static TypedClassOperation createGetterForField(Field field, ClassOrInterfaceType declaringType) Creates aTypedOperation
that represents a read access to a field.- Parameters:
field
- the fielddeclaringType
- the declaring type for the field- Returns:
- an operation to access the given field of the declaring type
-
createSetterForField
public static TypedClassOperation createSetterForField(Field field, ClassOrInterfaceType declaringType) Creates aTypedOperation
that represents a write access to a field.- Parameters:
field
- the fielddeclaringType
- the declaring type of the field- Returns:
- an operation to set the value of the given field of the declaring type
-
createNullOrZeroInitializationForType
Creates an operation that initializes a variable to the zero value for the given type.- Parameters:
type
- the type of the initialization- Returns:
- the initialization operation
-
createPrimitiveInitialization
Creates an operation that initializes a variable to a given primitive value.- Parameters:
type
- the primitive typevalue
- the value for initialization- Returns:
- the initialization operation
-
createNonreceiverInitialization
Creates an operation that uses the givenNonreceiverTerm
for initializing a variable.- Parameters:
term
- theNonreceiverTerm
- Returns:
- the initialization operation
-
createInitializedArrayCreation
Creates an operation that creates an array of the given type and size.- Parameters:
arrayType
- the type of the arraysize
- the size of the created array- Returns:
- the array creation operation
-
createArrayCreation
Creates a simple array creation operation for the given type.- Parameters:
arrayType
- the desired array type- Returns:
- an operation to create an array of the given type
-
createCast
Creates an operation to cast from one type to another.- Parameters:
fromType
- the input typetoType
- the resulting type- Returns:
- an operation that casts the input type to the result type
-
createArrayElementAssignment
Creates an operation to assign a value to an array element.- Parameters:
arrayType
- the type of the array- Returns:
- an operation that
-
isUncheckedCast
public boolean isUncheckedCast()Description copied from interface:Operation
Predicate to indicate whether this object represents an unchecked cast.- Specified by:
isUncheckedCast
in interfaceOperation
- Returns:
- true if the this object is a cast, and false otherwise
-
checkPrestate
Tests the specification for this operation against the argument values and returns theExpectedOutcomeTable
indicating the results of checking the pre-conditions of the specifications of the operation.- Parameters:
values
- the argument values- Returns:
- the
ExpectedOutcomeTable
indicating the results of checking the pre-conditions of the specifications of the operation
-
addNullReceiverIfStatic
Insertsnull
as first argument when this operation is static.This is necessary because the argument array for checking an
Operation
is always assumed to have a "receiver" argument, which is null (and ignored) for a static method.- Parameters:
values
- the argument array for this operation- Returns:
- the corresponding operation array for checking a
ExecutableBooleanExpression
-