Package randoop.generation
Class HelperSequenceCreator
- java.lang.Object
-
- randoop.generation.HelperSequenceCreator
-
class HelperSequenceCreator extends Object
Contains static methods that create Sequences.The only two methods that are currently externally used are
createArraySequence(randoop.generation.ComponentManager, randoop.types.Type)
andcreateCollection(randoop.generation.ComponentManager, randoop.types.InstantiatedType)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
HelperSequenceCreator.SequenceExtender
-
Constructor Summary
Constructors Modifier Constructor Description private
HelperSequenceCreator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Sequence
buildAddSequence(Sequence creationSequence, TupleSequence elementsSequence, HelperSequenceCreator.SequenceExtender addSequenceExtender)
Returns a sequence that creates a list or array.private static Sequence
createAnArray(TupleSequence elementsSequence, Type elementType, int length)
Creates a sequence that builds an array of the given element type using sequences from the given list of candidates.(package private) static SimpleList<Sequence>
createArraySequence(ComponentManager components, Type collectionType)
Returns a sequence that creates an object of type compatible with the given class.(package private) static Sequence
createCollection(ComponentManager componentManager, InstantiatedType collectionType)
Generates a sequence that creates a Collection.private static Sequence
createCollectionCreationSequence(InstantiatedType implementingType, ReferenceType elementType)
Creates the creation sequence for a collection with the given type and element type.private static Sequence
createGenericArrayCreationSequence(ArrayType arrayType, int length)
Creates aSequence
for creating an array with parameterized type.private static TypedOperation
getAddOperation(ParameterizedType collectionType, ReferenceType elementType)
Create a method call operation for theadd()
method of the given collection type.private static TypedOperation
getCollectionAddAllOperation(ReferenceType elementType)
Create the operation to callCollections.addAll(Collection, Object[])
that allows initialization of aCollection
object.private static Constructor<?>
getDefaultConstructor(ClassOrInterfaceType creationType)
Gets the default constructor for aClassOrInterfaceType
.private static ReferenceType
getElementType(InstantiatedType collectionType)
Returns the element type of the given collection type.private static TypedOperation
getEnumSetCreation(ParameterizedType creationType)
Create the operation needed to create an empty EnumSet of the given type.private static InstantiatedType
getImplementingTypeForCollection(InstantiatedType elementType)
Constructs an implementing type for an abstract subtype ofjava.util.Collection
using theJDKTypes.getImplementingTypeForCollection(ParameterizedType)
method.
-
-
-
Method Detail
-
createArraySequence
static SimpleList<Sequence> createArraySequence(ComponentManager components, Type collectionType)
Returns a sequence that creates an object of type compatible with the given class. Wraps the object in a list, and returns the list.CURRENTLY, will return a sequence (i.e. a non-empty list) only if
collectionType
is an array.- Parameters:
components
- the component manager with existing sequencescollectionType
- the query type- Returns:
- the singleton list containing the compatible sequence
-
getElementType
private static ReferenceType getElementType(InstantiatedType collectionType)
Returns the element type of the given collection type.- Parameters:
collectionType
- the collection type- Returns:
- the ReferenceType with the given collection type
-
createCollection
static Sequence createCollection(ComponentManager componentManager, InstantiatedType collectionType)
Generates a sequence that creates a Collection.- Parameters:
componentManager
- the component manager for selecting valuescollectionType
- the type for collection- Returns:
- a sequence that creates a collection of type
collectionType
-
buildAddSequence
private static Sequence buildAddSequence(Sequence creationSequence, TupleSequence elementsSequence, HelperSequenceCreator.SequenceExtender addSequenceExtender)
Returns a sequence that creates a list or array. The resulting sequence consists of the two given sequences, augmented by N invocations of addSequenceExtender, where N is the size of elementsSequence.outputIndices.- Parameters:
creationSequence
- creates an empty array or listelementsSequence
- a tuple-producing sequence; produces the elements of the resultaddSequenceExtender
- createsa[i]=e
(for an array) orl.add(e)
(for a list)- Returns:
- a sequence that creates an array or list that contains all the elements produced by elementsSequence
-
createCollectionCreationSequence
private static Sequence createCollectionCreationSequence(InstantiatedType implementingType, ReferenceType elementType)
Creates the creation sequence for a collection with the given type and element type.- Parameters:
implementingType
- the collection typeelementType
- the type of the elements- Returns:
- a
Sequence
that creates a collection ofimplementingType
-
createAnArray
private static Sequence createAnArray(TupleSequence elementsSequence, Type elementType, int length)
Creates a sequence that builds an array of the given element type using sequences from the given list of candidates.- Parameters:
elementsSequence
- the sequence creating element valueselementType
- the type of elements for the arraylength
- the length of the array- Returns:
- a sequence that creates an array with the given element type
-
createGenericArrayCreationSequence
private static Sequence createGenericArrayCreationSequence(ArrayType arrayType, int length)
Creates aSequence
for creating an array with parameterized type. Resulting code looks like(ElementType[])new RawElementType[dim0]
. Note that theSuppressWarnings
annotation is added when the assignment with the cast is output.- Parameters:
arrayType
- the type of the arraylength
- the length of the array to be created- Returns:
- the sequence to create an array with the given element type and length
-
getDefaultConstructor
private static Constructor<?> getDefaultConstructor(ClassOrInterfaceType creationType)
Gets the default constructor for aClassOrInterfaceType
. Returns null if the type has none.- Parameters:
creationType
- the class type- Returns:
- the reflection object for the default constructor of the given type; null, if there is none
-
getImplementingTypeForCollection
private static InstantiatedType getImplementingTypeForCollection(InstantiatedType elementType)
Constructs an implementing type for an abstract subtype ofjava.util.Collection
using theJDKTypes.getImplementingTypeForCollection(ParameterizedType)
method. Otherwise, returns the given type.Note: this should ensure that the type has some mechanism for constructing an object
- Parameters:
elementType
- the type- Returns:
- a non-abstract subtype of the given type, or the original type
-
getEnumSetCreation
private static TypedOperation getEnumSetCreation(ParameterizedType creationType)
Create the operation needed to create an empty EnumSet of the given type.- Parameters:
creationType
- the EnumSet type- Returns:
- the empty EnumSet with the given type
-
getAddOperation
private static TypedOperation getAddOperation(ParameterizedType collectionType, ReferenceType elementType)
Create a method call operation for theadd()
method of the given collection type.- Parameters:
collectionType
- the collection typeelementType
- the element type of the collection- Returns:
- an operation to add elements to the collection type
-
getCollectionAddAllOperation
private static TypedOperation getCollectionAddAllOperation(ReferenceType elementType)
Create the operation to callCollections.addAll(Collection, Object[])
that allows initialization of aCollection
object.- Parameters:
elementType
- the element type of the collection- Returns:
- the operation to initialize a collection from an array
-
-