Class NonreceiverTerm

java.lang.Object
randoop.operation.CallableOperation
randoop.operation.NonreceiverTerm
All Implemented Interfaces:
Operation

public final class NonreceiverTerm extends CallableOperation
Represents a value that either cannot (primitive or null values), or we don't care to have (String, Class) be a receiver for a method call as an Operation.

As an Operation, a value v of type T is formally represented by an operation v : [] → T, with no input types, and the type of the value as the output type. This kind of operation is a ground term — it requires no inputs.

The execution of this Operation simply returns the value.

  • Field Details

    • type

      private final Type type
      The Type of this non-receiver term.
    • value

      private final Object value
      The value of this non-receiver term. Must be null, a String, a boxed primitive, or a Class.
  • Constructor Details

    • NonreceiverTerm

      public NonreceiverTerm(Type type, Object value)
      Constructs a NonreceiverTerm with type t and value o.
      Parameters:
      type - the type of the term
      value - the value of the term
  • Method Details

    • isNonreceiverType

      public static boolean isNonreceiverType(Class<?> c)
      Determines whether the given Class<?> is the type of a non-receiver term.
      Parameters:
      c - the Class<?> object
      Returns:
      true iff the type is primitive, boxed primitive, String, or Class
    • equals

      public boolean equals(Object o)
      Indicates whether this object is equal to o.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code value for this NonreceiverTerm.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns string representation of this NonreceiverTerm.
      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
    • execute

      public ExecutionOutcome execute(Object[] statementInput)
      Performs this operation using the array of input values. Returns the results of execution as an ResultOrException object and can output results to specified PrintStream.
      Specified by:
      execute in class CallableOperation
      Parameters:
      statementInput - array containing appropriate inputs to operation
      Returns:
      NormalExecution object enclosing value of this non-receiver term
    • appendCode

      public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
      Produces a Java source code representation of this statement and appends it to the given StringBuilder.

      For NonreceiverTerm, simply adds a code representation of the value to the string builder. Note: this does not explicitly box primitive values.

      Specified by:
      appendCode in class CallableOperation
      Parameters:
      inputVars - ignored
      b - StringBuilder to which string representation is appended
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
    • getValue

      public 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.

      Specified by:
      getValue in interface Operation
      Overrides:
      getValue in class CallableOperation
      Returns:
      value of this NonreceiverTerm
    • getType

      public Type getType()
      Return the type.
      Returns:
      the type
    • createNullOrZeroTerm

      static NonreceiverTerm createNullOrZeroTerm(Type type)
      Returns a NonreceiverTerm holding the zero/false value for the specified class c.
      Parameters:
      type - the type of value desired
      Returns:
      a NonreceiverTerm with a canonical representative of the given type
    • toParsableString

      public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
      Returns a string representation of this Operation, which can be read by static parse method for class. For a class C implementing the Operation interface, this method should return a String s such that parsing the string returns an object equivalent to this object, i.e. C.parse(this.s).equals(this).

      Returns a string representing this primitive declaration. The string is of the form:
      TYPE:VALUE
      Where TYPE is the type of the primitive declaration, and VALUE is its value. If VALUE is "null" then the value is null (not the String "null"). If TYPE is "char" then (char)Integer.parseInt(VALUE, 16) yields the character value.

      Examples:

       String:null                  represents: String x = null
       java.lang.String:""          represents: String x = "";
       String:""                    represents: String x = "";
       String:" "                   represents: String x = " ";
       String:"\""                  represents: String x = "\"";
       String:"\n"                  represents: String x = "\n";
       String:"☺"              represents: String x = "☺";
       java.lang.Object:null        represents: Object x = null;
       [[Ljava.lang.Object;:null    represents: Object[][] = null;
       int:0                        represents: int x = 0;
       boolean:false                represents: boolean x = false;
       char:20                      represents: char x = ' ';
       
      Note that a string type can be given as both "String" or "java.lang.String".
      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:
      string representation of primitive, String or null value
    • parse

      public static TypedOperation parse(String s) throws OperationParseException
      Parse a non-receiver value in a string in the form generated by toParsableString(Type, TypeTuple, Type)
      Parameters:
      s - a string representing a value of a non-receiver type
      Returns:
      the non-receiver term for the given string descriptor
      Throws:
      OperationParseException - if string does not represent valid object
    • isNonreceivingValue

      public boolean isNonreceivingValue()
      Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).
      Specified by:
      isNonreceivingValue in interface Operation
      Overrides:
      isNonreceivingValue in class CallableOperation
      Returns:
      true, since all of objects are non-receivers