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 anOperation
.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.
-
-
Constructor Summary
Constructors Constructor Description NonreceiverTerm(Type type, Object value)
Constructs a NonreceiverTerm.
-
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)
Produces a Java source code representation of this statement and appends it to the given StringBuilder.(package private) static NonreceiverTerm
createNullOrZeroTerm(Type type)
Returns a NonreceiverTerm holding the zero/false value for the specified class c.boolean
equals(Object o)
Indicates whether this object is equal to o.ExecutionOutcome
execute(Object[] statementInput)
Performs this operation using the array of input values.String
getName()
Returns the name for the operation.Type
getType()
Return the type.Object
getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form.int
hashCode()
Returns a hash code value for this NonreceiverTerm.static boolean
isNonreceiverType(Class<?> c)
Determines whether the givenClass<?>
is the type of a non-receiver term.boolean
isNonreceivingValue()
Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).static TypedOperation
parse(String s)
Parse a non-receiver value in a string in the form generated bytoParsableString(Type, TypeTuple, Type)
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.String
toString()
Returns string representation of this NonreceiverTerm.-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, isConstantField, isConstructorCall, isMessage, isMethodCall, isStatic, isUncheckedCast, satisfies
-
-
-
-
Method Detail
-
isNonreceiverType
public static boolean isNonreceiverType(Class<?> c)
Determines whether the givenClass<?>
is the type of a non-receiver term.- Parameters:
c
- theClass<?>
object- Returns:
- true iff the type is primitive, boxed primitive,
String
, orClass
-
equals
public boolean equals(Object o)
Indicates whether this object is equal to o.
-
hashCode
public int hashCode()
Returns a hash code value for this NonreceiverTerm.
-
toString
public String toString()
Returns string representation of this NonreceiverTerm.
-
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 classCallableOperation
- 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 classCallableOperation
- Parameters:
inputVars
- ignoredb
-StringBuilder
to which string representation is appendeddeclaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- 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 interfaceOperation
- Overrides:
getValue
in classCallableOperation
- 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.- Returns 'a' for characters.
- Returns null for
JavaTypes.CLASS_TYPE
. - Returns "" (empty string) for
JavaTypes.STRING_TYPE
.
- 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 classCallableOperation
- Parameters:
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- 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 bytoParsableString(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 interfaceOperation
- Overrides:
isNonreceivingValue
in classCallableOperation
- Returns:
- true, since all of objects are non-receivers
-
-