Class TypeExtractor

  • All Implemented Interfaces:
    ClassVisitor

    class TypeExtractor
    extends DefaultClassVisitor
    TypeExtractor is a ClassVisitor that extracts both the class type, and concrete types that are used in a class as either a parameter, a return type, or a field type.
    • Field Detail

      • inputTypes

        private Set<Type> inputTypes
        The set of concrete types.
      • predicate

        private final AccessibilityPredicate predicate
        The accessibility predicate for checking whether a type is accessible in generated tests.
    • Constructor Detail

      • TypeExtractor

        TypeExtractor​(Set<Type> inputTypes,
                      AccessibilityPredicate predicate)
        Creates a visitor that adds discovered concrete types to the given set if they satisfy the accessibility predicate.
        Parameters:
        inputTypes - the set of concrete types
        predicate - the accessibility predicate
    • Method Detail

      • visit

        public void visit​(Constructor<?> c)
        Perform action on a constructor.

        Adds all concrete parameter types from the constructor to the input types set of this object.

        Specified by:
        visit in interface ClassVisitor
        Overrides:
        visit in class DefaultClassVisitor
        Parameters:
        c - the constructor
      • visit

        public void visit​(Method m)
        Perform an action on a method.

        Adds any concrete type among parameter and return types to the input types set of this object. Avoids bridge methods, because may have rawtypes not useful in building tests.

        Specified by:
        visit in interface ClassVisitor
        Overrides:
        visit in class DefaultClassVisitor
        Parameters:
        m - the method
      • visit

        public void visit​(Field f)
        Perform an action on a field.

        Adds a concrete field type to the input types set of this object.

        Specified by:
        visit in interface ClassVisitor
        Overrides:
        visit in class DefaultClassVisitor
        Parameters:
        f - the field
      • addIfConcrete

        private void addIfConcrete​(Type type)
        Determines whether the given general type is not generic, and, if so, adds the concrete type to the input types of this object.
        Parameters:
        type - the general type
      • visitBefore

        public void visitBefore​(Class<?> c)
        Perform an action on a class. Occurs before other visit methods are called.

        Adds the class if it is concrete.

        Specified by:
        visitBefore in interface ClassVisitor
        Overrides:
        visitBefore in class DefaultClassVisitor
        Parameters:
        c - the class to visit