Package randoop.operation
Class FieldSet
- java.lang.Object
-
- randoop.operation.CallableOperation
-
- randoop.operation.FieldSet
-
- All Implemented Interfaces:
Operation
public class FieldSet extends CallableOperation
FieldSetter is an adapter for aAccessibleField
as aOperation
that acts like a setter for the field.- See Also:
AccessibleField
-
-
Field Summary
Fields Modifier and Type Field Description private AccessibleField
field
-
Constructor Summary
Constructors Constructor Description FieldSet(AccessibleField field)
Creates a setterOperation
object for a field of a class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
Generates code for setting a field.boolean
equals(Object obj)
ExecutionOutcome
execute(Object[] statementInput)
Sets the value of the field given the inputs.String
getName()
Returns the name for the operation.int
hashCode()
boolean
isMessage()
A FieldSetter is a method call because it acts like a setter.boolean
isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.static TypedOperation
parse(String descr)
Parses a description of a field setter in the given string.boolean
satisfies(ReflectionPredicate reflectionPredicate)
Determines whether enclosedField
satisfies the given predicate.String
toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
Returns the string descriptor for field that can be parsed by.String
toString()
-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, getValue, isConstantField, isConstructorCall, isMethodCall, isNonreceivingValue, isUncheckedCast
-
-
-
-
Field Detail
-
field
private AccessibleField field
-
-
Constructor Detail
-
FieldSet
public FieldSet(AccessibleField field)
Creates a setterOperation
object for a field of a class. Throws an exception if the field is static final.- Parameters:
field
- the field object to be set by setter statements- Throws:
IllegalArgumentException
- if field is static final
-
-
Method Detail
-
execute
public ExecutionOutcome execute(Object[] statementInput)
Sets the value of the field given the inputs. Should the action raise an exception, those are captured and returned as anExecutionOutcome
. Exceptions should only beNullPointerException
, which happens when input is null but field is an instance field.AccessibleField.getValue(Object)
suppresses exceptions that occur because the field is not valid or accessible (specificallyIllegalArgumentException
andIllegalAccessException
).- Specified by:
execute
in classCallableOperation
- Parameters:
statementInput
- the inputs for statement- Returns:
- outcome of access, either void normal execution or captured exception
- Throws:
RandoopBug
- if field access throws bug exceptionSequenceExecutionException
- if field access has type exception
-
appendCode
public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
Generates code for setting a field. Should look likefield = value;
orfield = variable;
- Specified by:
appendCode
in classCallableOperation
- Parameters:
inputVars
- the list of input variables. Last element is value to assign. If an instance field, first is instance, second is value.b
- the StringBuilder to which code is issueddeclaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operation
-
toParsableString
public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
Returns the string descriptor for field that can be parsed by.- 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:
- the parsable string descriptor for this setter
-
parse
public static TypedOperation parse(String descr) throws OperationParseException
Parses a description of a field setter in the given string. A setter description has the form "<set>( field-descriptor )
" where "<set>
" is literally what is expected.- Parameters:
descr
- string containing descriptor of field setter- Returns:
- the field setter for the given string descriptor
- Throws:
OperationParseException
- if descr does not have expected form
-
getName
public String getName()
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
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 interfaceOperation
- Overrides:
isStatic
in classCallableOperation
- Returns:
- true if operation corresponds to static method or field of a class, and false otherwise
-
isMessage
public boolean isMessage()
A FieldSetter is a method call because it acts like a setter.- Specified by:
isMessage
in interfaceOperation
- Overrides:
isMessage
in classCallableOperation
- Returns:
- true if operation is method-like, and false otherwise
-
satisfies
public boolean satisfies(ReflectionPredicate reflectionPredicate)
Determines whether enclosedField
satisfies the given predicate.- Specified by:
satisfies
in interfaceOperation
- Overrides:
satisfies
in classCallableOperation
- Parameters:
reflectionPredicate
- theReflectionPredicate
to be checked- Returns:
- true only if the field used in this setter satisfies predicate.canUse
-
-