Interface Operation
-
- All Known Implementing Classes:
ArrayCreation
,ArrayElementSet
,CallableOperation
,ConstructorCall
,EnumConstant
,FieldGet
,FieldSet
,InitializedArrayCreation
,MethodCall
,NonreceiverTerm
,ReflectionArrayCreation
,TypedClassOperation
,TypedClassOperationWithCast
,TypedOperation
,TypedTermOperation
,UncheckedCast
public interface Operation
Operation represents the constructs that can occur in a statement as part of a test sequence. These include method calls, constructor calls, field accesses, enum constant values, or primitive values. They are used both as symbols in constructing statements as part of tests, and as a computational action in reflective execution of test sequences.The concept of an operation comes from logic and universal algebra, where operations are used to build terms, which represent values. (To dive into the formality, see, e.g., the Term Algebra Wikipedia entry.)
An operation op has a type-signature op: [T1, T2, ..., Tn] → T, where [T1, T2, ..., Tn] is the list of input types, and T is the output type. The input types are represented by an ordered list of
Type
objects, and the output type is a singleType
object.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. If we have a method
int A.m(double d)
, it is represented as an operation m : [A, double] → int. A value, such as an int or enum constant, can be represented as an operation with no input types, and its own type as the output type. So, the number 5 is represented by the operation 5 : [] → int. Non-class values are represented byNonreceiverTerm
objects.When an Operation is used in a statement the actual inputs have to be identified. Execution of the statement will call
CallableOperation.execute(Object[])
with concrete values for each of the inputs.To support text-based serialization, an implementing class C should also provide:
- A public static parse(String) method that returns a new Operation given a string
description. The following property should hold:
C.parse(x.toParsableString()).equals(x)
- Update method OperationParser.parse(String) to parse operations of type C.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getName()
Returns the name for the operation.Object
getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form.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
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 thisOperation
satisfies thecanUse
criteria of the givenReflectionPredicate
.
-
-
-
Method Detail
-
isStatic
boolean isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.- Returns:
- true if operation corresponds to static method or field of a class, and false otherwise
-
isMessage
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.- Returns:
- true if operation is method-like, and false otherwise
-
isMethodCall
boolean isMethodCall()
Indicates whether this object represents a method-call operation (either static or instance). This excludes getters and setters.- Returns:
- true if this operation is a method call, and false otherwise
-
isConstructorCall
boolean isConstructorCall()
Predicate to indicate whether object represents a call to a constructor.- Returns:
- true if operation is a constructor call, and false otherwise
-
isConstantField
boolean isConstantField()
Predicate to indicate whether this object represents a constant field.- Returns:
- true if this operation is a constant field, and false otherwise
-
isNonreceivingValue
boolean isNonreceivingValue()
Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).- Returns:
- true if object is a non-receiving value, and false otherwise
-
isUncheckedCast
boolean isUncheckedCast()
Predicate to indicate whether this object represents an unchecked cast.- Returns:
- true if the this object is a cast, and false otherwise
-
getValue
Object getValue()
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.
- Returns:
- object reference to value
- Throws:
IllegalArgumentException
- if no meaningful definition of "value" for type
-
satisfies
boolean satisfies(ReflectionPredicate reflectionPredicate)
Determines whether the reflective object in thisOperation
satisfies thecanUse
criteria of the givenReflectionPredicate
.- Parameters:
reflectionPredicate
- aReflectionPredicate
to be checked- Returns:
- result of applying reflectionPredicate to object
-
getName
String getName()
Returns the name for the operation.- Returns:
- the name for this operation
-
-