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:
  • Field Details

    • operation

      private final CallableOperation operation
      The operation to be decorated.
    • inputTypes

      protected final TypeTuple 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 to Operation.
    • outputType

      private final Type outputType
      The output type.
    • execSpec

      private ExecutableSpecification execSpec
      The specification for this operation.
    • compareRankedTypeOperation

      public static final Comparator<TypedOperation.RankedTypeOperation> 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 given Operation.
      Parameters:
      operation - the operation to wrap
      inputTypes - the input types
      outputType - the output types
      execSpec - the specification for the operation
  • Method Details

    • setExecutableSpecification

      public void setExecutableSpecification(ExecutableSpecification execSpec)
      Sets the specification; any previous value is ignored.
      Parameters:
      execSpec - the specification to use for this object
    • getExecutableSpecification

      public ExecutableSpecification getExecutableSpecification()
      Returns the specification.
      Returns:
      the specification to use for this object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public final int compareTo(TypedOperation other)
      Compares this 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).
      Specified by:
      compareTo in interface Comparable<TypedOperation>
      Parameters:
      other - the TypedOperation 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()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Description copied from interface: Operation
      Returns the name for the operation.
      Specified by:
      getName in interface Operation
      Returns:
      the name for this operation
    • getSignatureString

      public String getSignatureString()
      Returns the signature string for this operation.
      Returns:
      a string with the fully-qualified operation name and input type-tuple
    • getInputTypes

      public TypeTuple 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

      public Type getOutputType()
      Returns the output type returned by the operation.
      Returns:
      Type type returned by this operation
    • getOperation

      public CallableOperation 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.
      Specified by:
      isStatic in interface Operation
      Returns:
      true if operation corresponds to static method or field of a class, and false otherwise
    • 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.
      Specified by:
      isMessage in interface Operation
      Returns:
      true if operation is method-like, and false otherwise
    • 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 interface Operation
      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 interface Operation
      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 interface Operation
      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 interface Operation
      Returns:
      true if object is a non-receiving value, and false otherwise
    • getValue

      public Object 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.

      Specified by:
      getValue in interface Operation
      Returns:
      object reference to value
    • satisfies

      public boolean satisfies(ReflectionPredicate reflectionPredicate)
      Description copied from interface: Operation
      Determines whether the reflective object in this Operation satisfies the canUse criteria of the given ReflectionPredicate.
      Specified by:
      satisfies in interface Operation
      Parameters:
      reflectionPredicate - a ReflectionPredicate to be checked
      Returns:
      result of applying reflectionPredicate to object
    • appendCode

      public abstract void appendCode(List<Variable> inputVars, StringBuilder b)
      Appends Java text for this operation to the given StringBuilder, and using the given variables.
      Parameters:
      inputVars - the list of input variables for this operation
      b - the StringBuilder
    • 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.
      Parameters:
      input - array containing appropriate inputs to operation
      Returns:
      results of executing this statement
    • substitute

      public 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.
      Parameters:
      substitution - the substitution
      Returns:
      the operation resulting from applying the substitution to the types of this operation
    • applyCaptureConversion

      public 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.
      Returns:
      the operation result from applying a capture conversion to wildcard types of this operation
    • getTypeParameters

      public List<TypeVariable> 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

      public abstract String 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

      public static TypedClassOperation forConstructor(Constructor<?> constructor)
      Constructs a TypedOperation for a constructor object.
      Parameters:
      constructor - the reflective constructor object
      Returns:
      the typed operation for the constructor
    • forMethod

      public static TypedClassOperation forMethod(Method method)
      Constructs a TypedOperation 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 a 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.
      Parameters:
      method - the method of the anonymous class
      methodParamTypes - the parameter types of the method
      enumClass - 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 a TypedOperation that represents a read access to a field.
      Parameters:
      field - the field
      declaringType - 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 a TypedOperation that represents a write access to a field.
      Parameters:
      field - the field
      declaringType - the declaring type of the field
      Returns:
      an operation to set the value of the given field of the declaring type
    • createNullOrZeroInitializationForType

      public static TypedOperation createNullOrZeroInitializationForType(Type type)
      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

      public static TypedOperation createPrimitiveInitialization(Type type, Object value)
      Creates an operation that initializes a variable to a given primitive value.
      Parameters:
      type - the primitive type
      value - the value for initialization
      Returns:
      the initialization operation
    • createNonreceiverInitialization

      public static TypedOperation createNonreceiverInitialization(NonreceiverTerm term)
      Creates an operation that uses the given NonreceiverTerm for initializing a variable.
      Parameters:
      term - the NonreceiverTerm
      Returns:
      the initialization operation
    • createInitializedArrayCreation

      public static TypedOperation createInitializedArrayCreation(ArrayType arrayType, int size)
      Creates an operation that creates an array of the given type and size.
      Parameters:
      arrayType - the type of the array
      size - the size of the created array
      Returns:
      the array creation operation
    • createArrayCreation

      public static TypedOperation createArrayCreation(ArrayType arrayType)
      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

      public static TypedOperation createCast(Type fromType, Type toType)
      Creates an operation to cast from one type to another.
      Parameters:
      fromType - the input type
      toType - the resulting type
      Returns:
      an operation that casts the input type to the result type
    • createArrayElementAssignment

      public static TypedOperation createArrayElementAssignment(ArrayType arrayType)
      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 interface Operation
      Returns:
      true if the this object is a cast, and false otherwise
    • checkPrestate

      public ExpectedOutcomeTable checkPrestate(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.
      Parameters:
      values - the argument values
      Returns:
      the ExpectedOutcomeTable indicating the results of checking the pre-conditions of the specifications of the operation
    • addNullReceiverIfStatic

      private Object[] addNullReceiverIfStatic(Object[] values)
      Inserts 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.

      Parameters:
      values - the argument array for this operation
      Returns:
      the corresponding operation array for checking a ExecutableBooleanExpression