Class NonreceiverTerm
- All Implemented Interfaces:
Operation
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 Summary
-
Constructor Summary
ConstructorDescriptionNonreceiverTerm
(Type type, Object value) Constructs a NonreceiverTerm with type t and value o. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Indicates whether this object is equal to o.Performs this operation using the array of input values.getName()
Returns the name for the operation.getType()
Return the type.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
Predicate to indicate whether this object represents a value of a non-receiving type (includes numbers, strings, and null).static TypedOperation
Parse a non-receiver value in a string in the form generated bytoParsableString(Type, TypeTuple, Type)
toParsableString
(Type declaringType, TypeTuple inputTypes, Type outputType) Returns a string representation of this Operation, which can be read by static parse method for class.toString()
Returns string representation of this NonreceiverTerm.Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, isConstantField, isConstructorCall, isMessage, isMethodCall, isStatic, isUncheckedCast, satisfies
-
Field Details
-
type
TheType
of this non-receiver term. -
value
The value of this non-receiver term. Must be null, a String, a boxed primitive, or a Class.
-
-
Constructor Details
-
NonreceiverTerm
Constructs a NonreceiverTerm with type t and value o.- Parameters:
type
- the type of the termvalue
- the value of the term
-
-
Method Details
-
isNonreceiverType
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
Indicates whether this object is equal to o. -
hashCode
public int hashCode()Returns a hash code value for this NonreceiverTerm. -
toString
Returns string representation of this NonreceiverTerm. -
getName
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
execute
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
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
Return the type.- Returns:
- the type
-
createNullOrZeroTerm
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
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
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
-