Class ComponentManager


  • public class ComponentManager
    extends Object
    Stores the component sequences generated during a run of Randoop. "Component sequences" are sequences that Randoop uses to create larger sequences. The collection of sequences is also called Randoop's "pool".

    This class manages different collections of component sequences:

    • General components that can be used as input to any method in any class.
    • Class literals: components representing literal values that apply only to a specific class and should not be used as inputs to other classes.
    • Package literals: analogous to class literals but at the package level.

    SEED SEQUENCES. Seed sequences are the initial sequences provided to the generation process. They include (1) sequences passed via the constructor, (2) class literals, and (3) package literals. The only different treatment of seed sequences is during calls to the clearGeneratedSequences() method, which removes only general, non-seed components from the collection.

    • Field Detail

      • gralComponents

        private SequenceCollection gralComponents
        The principal set of sequences used to create other, larger sequences by the generator. Is never null. Contains both general components and seed sequences. Can be reset by calling clearGeneratedSequences().
      • gralSeeds

        private final Collection<Sequence> gralSeeds
        The sequences that were given pre-generation to the component manager (via its constructor). (Does not include literals, I think?)

        Seeds are all contained in gralComponents. This list is kept to restore seeds if the user calls clearGeneratedSequences().

      • classLiterals

        private ClassLiterals classLiterals
        Components representing literals that should only be used as input to specific classes.

        Null if class literals are not used or none were found. At most one of classLiterals and packageliterals is non-null.

      • packageLiterals

        private @Nullable PackageLiterals packageLiterals
        A set of additional components representing literals that should only be used as input to specific packages.

        Null if package literals are not used or none were found. At most one of classLiterals and packageliterals is non-null.

    • Constructor Detail

      • ComponentManager

        public ComponentManager()
        Create an empty component manager, with an empty seed sequence set.
      • ComponentManager

        public ComponentManager​(Collection<Sequence> generalSeeds)
        Create a component manager, initially populated with the given sequences, which are considered seed sequences.
        Parameters:
        generalSeeds - seed sequences. Can be null, in which case the seed sequences set is considered empty.
    • Method Detail

      • numGeneratedSequences

        public int numGeneratedSequences()
        Returns the number of (non-seed) sequences stored by the manager.
        Returns:
        count of generated sequences in this ComponentManager
      • addClassLevelLiteral

        public void addClassLevelLiteral​(ClassOrInterfaceType type,
                                         Sequence seq)
        Add a sequence representing a literal value that can be used when testing members of the given class.
        Parameters:
        type - the class literal to add for the sequence
        seq - the sequence
      • addPackageLevelLiteral

        public void addPackageLevelLiteral​(Package pkg,
                                           Sequence seq)
        Add a sequence representing a literal value that can be used when testing classes in the given package.
        Parameters:
        pkg - the package to add for the sequence
        seq - the sequence
      • addGeneratedSequence

        public void addGeneratedSequence​(Sequence sequence)
        Add a component sequence.
        Parameters:
        sequence - the sequence
      • clearGeneratedSequences

        void clearGeneratedSequences()
        Removes any components sequences added so far, except for seed sequences, which are preserved.
      • getAllGeneratedSequences

        Set<Sequence> getAllGeneratedSequences()
        Returns the set of all generated sequences.
        Returns:
        the set of all generated sequences
      • getSequencesForType

        SimpleList<Sequence> getSequencesForType​(Type cls)
        Returns all the general component sequences that create values of the given class.
        Parameters:
        cls - the query type
        Returns:
        the sequences that create values of the given type
      • getSequencesForType

        SimpleList<Sequence> getSequencesForType​(TypedOperation operation,
                                                 int i,
                                                 boolean onlyReceivers)
        Returns component sequences that create values of the type required by the i-th input value of a statement that invokes the given operation. Also includes any applicable class- or package-level literals.
        Parameters:
        operation - the statement
        i - the input value index of statement
        onlyReceivers - if true, only return sequences that are appropriate to use as a method call receiver
        Returns:
        the sequences that create values of the given type
      • getAllPrimitiveSequences

        Set<Sequence> getAllPrimitiveSequences()
        Returns all sequences that represent primitive values (e.g. sequences like "Foo var0 = null" or "int var0 = 1"), including general components, class literals and package literals.
        Returns:
        the sequences for primitive values
      • log

        public void log()