Class HelperSequenceCreator

    • Constructor Detail

      • HelperSequenceCreator

        private HelperSequenceCreator()
    • 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 sequences
        collectionType - 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 values
        collectionType - 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 list
        elementsSequence - a tuple-producing sequence; produces the elements of the result
        addSequenceExtender - creates a[i]=e (for an array) or l.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 type
        elementType - the type of the elements
        Returns:
        a Sequence that creates a collection of implementingType
      • 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 values
        elementType - the type of elements for the array
        length - 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 a Sequence for creating an array with parameterized type. Resulting code looks like (ElementType[])new RawElementType[dim0]. Note that the SuppressWarnings annotation is added when the assignment with the cast is output.
        Parameters:
        arrayType - the type of the array
        length - 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 a ClassOrInterfaceType. 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 of java.util.Collection using the JDKTypes.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 the add() method of the given collection type.
        Parameters:
        collectionType - the collection type
        elementType - the element type of the collection
        Returns:
        an operation to add elements to the collection type