Class FieldGet

All Implemented Interfaces:
Operation

public class FieldGet extends CallableOperation
FieldGetter is an adapter that creates a Operation from a AccessibleField and behaves like a getter for the field.
See Also:
  • Field Details

  • Constructor Details

    • FieldGet

      public FieldGet(AccessibleField field)
      FieldGetter sets the public field for the getter statement.
      Parameters:
      field - the AccessibleField object from which to get values
  • Method Details

    • execute

      public ExecutionOutcome execute(Object[] statementInput)
      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 class CallableOperation
      Parameters:
      statementInput - the inputs for statement
      Returns:
      outcome of access
      Throws:
      RandoopBug - if field access throws bug exception
      SequenceExecutionException - 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 class CallableOperation
      Parameters:
      inputVars - the list of variables to be used
      b - the StringBuilder that strings are appended to
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
    • toParsableString

      public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
      Returns string descriptor for field that can be parsed by PublicFieldParser.
      Specified by:
      toParsableString in class CallableOperation
      Parameters:
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
      Returns:
      a string representation of this operation
    • toString

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

      public String getName()
      Description copied from interface: Operation
      Returns the name for the operation.
      Returns:
      the name for this operation
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • parse

      public static TypedOperation parse(String descr) throws OperationParseException
      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 interface Operation
      Overrides:
      isStatic in class CallableOperation
      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 interface Operation
      Overrides:
      isConstantField in class CallableOperation
      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 interface Operation
      Overrides:
      isMessage in class CallableOperation
      Returns:
      true, always
    • satisfies

      public boolean satisfies(ReflectionPredicate reflectionPredicate)
      Determines whether enclosed Field satisfies the given predicate.
      Specified by:
      satisfies in interface Operation
      Overrides:
      satisfies in class CallableOperation
      Parameters:
      reflectionPredicate - the ReflectionPredicate to be checked
      Returns:
      true only if the field used in this getter satisfies predicate.canUse