public abstract class TypedOperation extends java.lang.Object implements Operation, java.lang.Comparable<TypedOperation>
Operation
objects. An operation has zero or more input types, and one
output type that may be void
.TypedClassOperation
,
TypedTermOperation
Modifier and Type | Class and Description |
---|---|
static class |
TypedOperation.RankedTypeOperation
RankedTypedOperation is a wrapper around a TypedOperation and a number.
|
Modifier and Type | Field and Description |
---|---|
static java.util.Comparator<TypedOperation.RankedTypeOperation> |
compareRankedTypeOperation
Comparator used for sorting by ranking.
|
private @Nullable ExecutableSpecification |
execSpec
The specification for this operation.
|
protected TypeTuple |
inputTypes
The type tuple of input types.
|
private CallableOperation |
operation
The operation to be decorated.
|
private Type |
outputType
The output type.
|
Constructor and Description |
---|
TypedOperation(CallableOperation operation,
TypeTuple inputTypes,
Type outputType,
@Nullable ExecutableSpecification execSpec)
Create typed operation for the given
Operation . |
Modifier and Type | Method and Description |
---|---|
private java.lang.Object[] |
addNullReceiverIfStatic(java.lang.Object[] values)
Inserts
null as first argument when this operation is static. |
abstract void |
appendCode(java.util.List<Variable> inputVars,
java.lang.StringBuilder b)
Appends Java text for this operation to the given
StringBuilder , and using the given
variables. |
abstract TypedOperation |
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.
|
ExpectedOutcomeTable |
checkPrestate(java.lang.Object[] values)
Tests the specification for this operation against the argument values and returns the
ExpectedOutcomeTable indicating the results of checking the pre-conditions of the
specifications of the operation. |
int |
compareTo(TypedOperation other)
Compares this
TypedOperation 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(java.lang.reflect.Field field,
ClassOrInterfaceType declaringType)
Creates a
TypedOperation 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 |
createNonreceiverInitialization(NonreceiverTerm term)
Creates an operation that uses the given
NonreceiverTerm for initializing a variable. |
static TypedOperation |
createNullOrZeroInitializationForType(Type type)
Creates an operation that initializes a variable to the zero value for the given type.
|
static TypedOperation |
createPrimitiveInitialization(Type type,
java.lang.Object value)
Creates an operation that initializes a variable to a given primitive value.
|
static TypedClassOperation |
createSetterForField(java.lang.reflect.Field field,
ClassOrInterfaceType declaringType)
Creates a
TypedOperation that represents a write access to a field. |
boolean |
equals(@Nullable java.lang.Object obj) |
ExecutionOutcome |
execute(java.lang.Object[] input)
Performs this operation using the array of input values.
|
static TypedClassOperation |
forConstructor(java.lang.reflect.Constructor<?> constructor)
Constructs a
TypedOperation for a constructor object. |
static TypedClassOperation |
forMethod(java.lang.reflect.Method method)
Constructs a
TypedOperation for a method object. |
private static @Nullable TypedClassOperation |
getAnonEnumOperation(java.lang.reflect.Method method,
java.util.List<Type> methodParamTypes,
java.lang.Class<?> enumClass)
Constructs a
TypedOperation for an enum from a method object that is a member of an
anonymous class for an enum constant. |
ExecutableSpecification |
getExecutableSpecification()
Returns the specification.
|
TypeTuple |
getInputTypes()
Returns the tuple of input types for this operation.
|
java.lang.String |
getName()
Returns the name for the operation.
|
CallableOperation |
getOperation()
Get the enclosed operation in this typed operation.
|
Type |
getOutputType()
Returns the output type returned by the operation.
|
java.lang.String |
getSignatureString()
Returns the signature string for this operation.
|
java.util.List<TypeVariable> |
getTypeParameters()
Returns an empty list representing the type parameters of this.
|
java.lang.Object |
getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some
form.
|
int |
hashCode() |
abstract boolean |
hasWildcardTypes()
Indicates whether this operation has a type that is a wildcard type.
|
boolean |
isConstantField()
Predicate to indicate whether this object represents a constant field.
|
boolean |
isConstructorCall()
Predicate to indicate whether object represents a call to a constructor.
|
boolean |
isGeneric()
Indicate whether this operation is generic.
|
boolean |
isGeneric(boolean ignoreWildcards)
Indicate whether this operation is generic.
|
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 |
isNonreceivingValue()
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 |
isUncheckedCast()
Predicate to indicate whether this object represents an unchecked cast.
|
boolean |
satisfies(ReflectionPredicate reflectionPredicate)
Determines whether the reflective object in this
Operation satisfies the canUse
criteria of the given ReflectionPredicate . |
void |
setExecutableSpecification(ExecutableSpecification execSpec)
Sets the specification; any previous value is ignored.
|
private static OperationSpecification |
specificationFromAnnotations(java.lang.reflect.Method method,
@ClassGetName java.lang.String className)
Creates a specification for the given method based on @NonNull annotations for parameter and
return types.
|
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 java.lang.String |
toParsableString()
Constructs a string representation of this operation that can be parsed by parse methods of the
implementing types.
|
java.lang.String |
toString() |
private final CallableOperation operation
protected final TypeTuple inputTypes
Operation
.private final Type outputType
private @Nullable ExecutableSpecification execSpec
public static final java.util.Comparator<TypedOperation.RankedTypeOperation> compareRankedTypeOperation
TypedOperation(CallableOperation operation, TypeTuple inputTypes, Type outputType, @Nullable ExecutableSpecification execSpec)
Operation
.operation
- the operation to wrapinputTypes
- the input typesoutputType
- the output typesexecSpec
- the specification for the operationprivate static OperationSpecification specificationFromAnnotations(java.lang.reflect.Method method, @ClassGetName java.lang.String className)
method
- the method to extract the specification fromclassName
- the name of the class that declares the methodpublic void setExecutableSpecification(ExecutableSpecification execSpec)
execSpec
- the specification to use for this objectpublic ExecutableSpecification getExecutableSpecification()
public boolean equals(@Nullable java.lang.Object obj)
equals
in class java.lang.Object
public final int compareTo(TypedOperation other)
TypedOperation
to another. Orders operations by type (any TypedTermOperation
object precedes a TypedClassOperation
) then lexicographically
(alphabetically comparing class names, then operation names, then input type names, and finally
output type names).compareTo
in interface java.lang.Comparable<TypedOperation>
other
- the TypedOperation
to compare with this operationop
, 0 if the operations
are identical, and some value > 0 if this operation succeeds op
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getName()
Operation
public java.lang.String getSignatureString()
public TypeTuple getInputTypes()
public Type getOutputType()
Type
type returned by this operationpublic CallableOperation getOperation()
public abstract boolean hasWildcardTypes()
public final boolean isGeneric()
public boolean isGeneric(boolean ignoreWildcards)
ignoreWildcards
- if true, ignore wildcards; that is, treat wildcards as not making the
operation genericpublic boolean isStatic()
Operation
public boolean isMessage()
Operation
public boolean isMethodCall()
Operation
isMethodCall
in interface Operation
public boolean isConstantField()
Operation
isConstantField
in interface Operation
public boolean isConstructorCall()
Operation
isConstructorCall
in interface Operation
public boolean isNonreceivingValue()
Operation
isNonreceivingValue
in interface Operation
public java.lang.Object getValue()
Operation
This is a hack to allow randoop.main.GenBranchDir to do mutation.
public boolean satisfies(ReflectionPredicate reflectionPredicate)
Operation
Operation
satisfies the canUse
criteria of the given ReflectionPredicate
.satisfies
in interface Operation
reflectionPredicate
- a ReflectionPredicate
to be checkedpublic abstract void appendCode(java.util.List<Variable> inputVars, java.lang.StringBuilder b)
StringBuilder
, and using the given
variables.inputVars
- the list of input variables for this operationb
- the StringBuilder
public ExecutionOutcome execute(java.lang.Object[] input)
input
- array containing appropriate inputs to operationpublic abstract TypedOperation substitute(Substitution substitution)
substitution
- the substitutionpublic abstract TypedOperation applyCaptureConversion()
public java.util.List<TypeVariable> getTypeParameters()
public abstract java.lang.String toParsableString()
public static TypedClassOperation forConstructor(java.lang.reflect.Constructor<?> constructor)
TypedOperation
for a constructor object.constructor
- the reflective constructor objectpublic static TypedClassOperation forMethod(java.lang.reflect.Method method)
TypedOperation
for a method object.method
- the reflective method objectprivate static @Nullable TypedClassOperation getAnonEnumOperation(java.lang.reflect.Method method, java.util.List<Type> methodParamTypes, java.lang.Class<?> enumClass)
TypedOperation
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.method
- the method of the anonymous classmethodParamTypes
- the parameter types of the methodenumClass
- the declaring classenumClass
public static TypedClassOperation createGetterForField(java.lang.reflect.Field field, ClassOrInterfaceType declaringType)
TypedOperation
that represents a read access to a field.field
- the fielddeclaringType
- the declaring type for the fieldpublic static TypedClassOperation createSetterForField(java.lang.reflect.Field field, ClassOrInterfaceType declaringType)
TypedOperation
that represents a write access to a field.field
- the fielddeclaringType
- the declaring type of the fieldpublic static TypedOperation createNullOrZeroInitializationForType(Type type)
type
- the type of the initializationpublic static TypedOperation createPrimitiveInitialization(Type type, java.lang.Object value)
type
- the primitive typevalue
- the value for initializationpublic static TypedOperation createNonreceiverInitialization(NonreceiverTerm term)
NonreceiverTerm
for initializing a variable.term
- the NonreceiverTerm
public static TypedOperation createInitializedArrayCreation(ArrayType arrayType, int size)
arrayType
- the type of the arraysize
- the size of the created arraypublic static TypedOperation createArrayCreation(ArrayType arrayType)
arrayType
- the desired array typepublic static TypedOperation createCast(Type fromType, Type toType)
fromType
- the input typetoType
- the resulting typepublic static TypedOperation createArrayElementAssignment(ArrayType arrayType)
arrayType
- the type of the arraypublic boolean isUncheckedCast()
Operation
isUncheckedCast
in interface Operation
public ExpectedOutcomeTable checkPrestate(java.lang.Object[] values)
ExpectedOutcomeTable
indicating the results of checking the pre-conditions of the
specifications of the operation.values
- the argument valuesExpectedOutcomeTable
indicating the results of checking the pre-conditions
of the specifications of the operationprivate java.lang.Object[] addNullReceiverIfStatic(java.lang.Object[] values)
null
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.
values
- the argument array for this operationExecutableBooleanExpression