Package randoop.operation
Class FieldGet
java.lang.Object
randoop.operation.CallableOperation
randoop.operation.FieldGet
- All Implemented Interfaces:
Operation
FieldGetter is an adapter that creates a
Operation
from a AccessibleField
and
behaves like a getter for the field.- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFieldGet
(AccessibleField field) FieldGetter sets the public field for the getter statement. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendCode
(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b) Adds the text for an initialization of a variable from a field to the StringBuilder.boolean
Performs computation of getting value of field or capturing thrown exceptions.getName()
Returns the name for the operation.int
hashCode()
boolean
Predicate to indicate whether this object represents a constant field.boolean
Predicate to indicate whether object represents a method-call-like operation (either static or instance).boolean
isStatic()
Predicate to indicate whether object represents a static operation on the declaring class.static TypedOperation
Parses a getter for a field from a string.boolean
satisfies
(ReflectionPredicate reflectionPredicate) Determines whether enclosedField
satisfies the given predicate.toParsableString
(Type declaringType, TypeTuple inputTypes, Type outputType) Returns string descriptor for field that can be parsed by PublicFieldParser.toString()
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, getValue, isConstructorCall, isMethodCall, isNonreceivingValue, isUncheckedCast
-
Field Details
-
field
-
-
Constructor Details
-
FieldGet
FieldGetter sets the public field for the getter statement.- Parameters:
field
- theAccessibleField
object from which to get values
-
-
Method Details
-
execute
Performs computation of getting value of field or capturing thrown exceptions. Exceptions should only be NullPointerException, which happens when input is null but field is an instance field.AccessibleField.getValue(Object)
suppresses exceptions that occur because field is not valid or accessible.- Specified by:
execute
in classCallableOperation
- Parameters:
statementInput
- the inputs for statement- Returns:
- outcome of access
- Throws:
RandoopBug
- if field access throws bug exceptionSequenceExecutionException
- if field access has a type exception
-
appendCode
public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b) Adds the text for an initialization of a variable from a field to the StringBuilder.- Specified by:
appendCode
in classCallableOperation
- Parameters:
inputVars
- the list of variables to be usedb
- the StringBuilder that strings are appended todeclaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operation
-
toParsableString
Returns string descriptor for field that can be parsed by PublicFieldParser.- 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:
- a string representation of this operation
-
toString
-
getName
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
equals
-
hashCode
public int hashCode() -
parse
Parses a getter for a field from a string. A getter description has the form "<get>( field-descriptor )
" where "<get>
" is literal ("<
" and ">
" included), and field-descriptor is as recognized by- Parameters:
descr
- the string containing descriptor of getter for a field- Returns:
- the getter operation for the given string descriptor
- Throws:
OperationParseException
- if any error in descriptor string
-
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
-
isConstantField
public boolean isConstantField()Description copied from interface:Operation
Predicate to indicate whether this object represents a constant field.- Specified by:
isConstantField
in interfaceOperation
- Overrides:
isConstantField
in classCallableOperation
- Returns:
- true if this operation is a constant field, and false otherwise
-
isMessage
public 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.- Specified by:
isMessage
in interfaceOperation
- Overrides:
isMessage
in classCallableOperation
- Returns:
- true, always
-
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 getter satisfies predicate.canUse
-