Package randoop.operation
Class FieldSet
java.lang.Object
randoop.operation.CallableOperation
randoop.operation.FieldSet
- All Implemented Interfaces:
Operation
FieldSetter is an adapter for a
AccessibleField
as a Operation
that acts like a
setter for the field.- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFieldSet
(AccessibleField field) Creates a setterOperation
object for a field of a class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendCode
(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b) Generates code for setting a field.boolean
Sets the value of the field given the inputs.getName()
Returns the name for the operation.int
hashCode()
boolean
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
Parses a description of a field setter in the given string.boolean
satisfies
(ReflectionPredicate reflectionPredicate) Determines whether enclosedField
satisfies the given predicate.toParsableString
(Type declaringType, TypeTuple inputTypes, Type outputType) Returns the string descriptor for field that can be parsed by.toString()
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, getValue, isConstantField, isConstructorCall, isMethodCall, isNonreceivingValue, isUncheckedCast
-
Field Details
-
field
-
-
Constructor Details
-
FieldSet
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 Details
-
execute
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
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
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
-
toString
-
getName
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
equals
-
hashCode
public int hashCode() -
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
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
-