Package randoop.operation
Class InitializedArrayCreation
- java.lang.Object
-
- randoop.operation.CallableOperation
-
- randoop.operation.InitializedArrayCreation
-
- All Implemented Interfaces:
Operation
public final class InitializedArrayCreation extends CallableOperation
InitializedArrayCreation is anOperation
representing the construction of a one-dimensional array with a given element type and length. The InitializedArrayCreation operation requires a list of elements in an initializer. For instance,new int[2]
is theInitializedArrayCreation
in the initialization
int[] x = new int[2] { 3, 7 };
with the initializer list as inputs.In terms of the notation used for the
Operation
class, a creation of an array of elements of type e with length n has a signature [ e,...,e] → t, where [e,...,e] is a list of length n, and t is the array type.InitializedArrayCreation objects are immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private Type
elementType
private int
length
-
Constructor Summary
Constructors Constructor Description InitializedArrayCreation(ArrayType arrayType, int length)
Creates an object representing the construction of an array that holds values of the element type and has the given length.
-
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.boolean
equals(Object o)
ExecutionOutcome
execute(Object[] statementInput)
Performs this operation using the array of input values.int
getLength()
Returns the length of created array.String
getName()
Returns the name for the operation.int
hashCode()
static TypedOperation
parse(String str)
Parses an array declaration in a string descriptor 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()
-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, getValue, isConstantField, isConstructorCall, isMessage, isMethodCall, isNonreceivingValue, isStatic, isUncheckedCast, satisfies
-
-
-
-
Field Detail
-
length
private final int length
-
elementType
private final Type elementType
-
-
Constructor Detail
-
InitializedArrayCreation
InitializedArrayCreation(ArrayType arrayType, int length)
Creates an object representing the construction of an array that holds values of the element type and has the given length.- Parameters:
length
- number of objects allowed in the arrayarrayType
- the type of array this operation creates
-
-
Method Detail
-
getLength
public int getLength()
Returns the length of created array.- Returns:
- length of array created by this object
-
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 containing constructed array
-
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.- Specified by:
appendCode
in classCallableOperation
- Parameters:
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operationinputVars
- the list of variables that are inputs to operationb
- theStringBuilder
to which code is added
-
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).Creates string of the form TYPE[NUMELEMS] where TYPE is the type of the array, and NUMELEMS is the number of elements.
Example: int[3]
- 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 descriptor for array creation
-
getName
public String getName()
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
parse
public static TypedOperation parse(String str) throws OperationParseException
Parses an array declaration in a string descriptor in the form generated bytoParsableString(Type, TypeTuple, Type)
.- Parameters:
str
- the string to be parsed for theInitializedArrayCreation
- Returns:
- the array creation for the given string descriptor
- Throws:
OperationParseException
- if string does not have expected form- See Also:
OperationParser.parse(String)
-
-