Package randoop.reflection
Class OperationExtractor
- java.lang.Object
-
- randoop.reflection.DefaultClassVisitor
-
- randoop.reflection.OperationExtractor
-
- All Implemented Interfaces:
ClassVisitor
public class OperationExtractor extends DefaultClassVisitor
OperationExtractor is aClassVisitor
that creates a collection ofTypedOperation
objects for a particularClassOrInterfaceType
through its visit methods as called byReflectionManager.apply(Class)
.- See Also:
ReflectionManager
,ClassVisitor
-
-
Field Summary
Fields Modifier and Type Field Description private AccessibilityPredicate
accessibilityPredicate
The predicate to test accessibility.private ClassOrInterfaceType
classType
The type of the declaring class for the collected operations.private static boolean
debug
Whether to produce debugging output to the Randoop log.private OmitMethodsPredicate
omitPredicate
The predicate to test whether to omit an operation.private Collection<TypedOperation>
operations
The operations collected by the extractor.private SpecificationCollection
operationSpecifications
The specifications (pre/post/throws-conditions).private ReflectionPredicate
reflectionPredicate
The reflection policy for collecting operations.
-
Constructor Summary
Constructors Constructor Description OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates.OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates.OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates and that don't violate the omit method predicate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkSubTypes(TypedClassOperation operation)
Ensures that fieldclassType
of this object is a subtype ofoperation.getDeclaringType()
; throws an exception if not.static List<ClassOrInterfaceType>
classListToTypeList(List<Class<?>> classes)
Converts a list of classes to a list of ClassOrInterfaceType.Collection<TypedOperation>
getOperations()
Returns theTypedOperation
objects collected forclassType
.private TypedClassOperation
instantiateTypes(TypedClassOperation operation)
Updates the operation types in the case thatoperation.getDeclaringType()
is generic, butclassType
is not.static List<TypedOperation>
operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.static List<TypedOperation>
operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.void
visit(Enum<?> e)
Creates aEnumConstant
object for theEnum
.void
visit(Constructor<?> constructor)
Creates aConstructorCall
object for theConstructor
.void
visit(Field field)
Adds theOperation
objects corresponding to getters and setters appropriate to the kind of field.void
visit(Method method)
Creates aMethodCall
object for theMethod
.-
Methods inherited from class randoop.reflection.DefaultClassVisitor
toString, visit, visitAfter, visitBefore
-
-
-
-
Field Detail
-
debug
private static boolean debug
Whether to produce debugging output to the Randoop log.
-
classType
private ClassOrInterfaceType classType
The type of the declaring class for the collected operations.
-
operations
private final Collection<TypedOperation> operations
The operations collected by the extractor. This is the product of applying the visitor.
-
reflectionPredicate
private final ReflectionPredicate reflectionPredicate
The reflection policy for collecting operations.
-
omitPredicate
private OmitMethodsPredicate omitPredicate
The predicate to test whether to omit an operation.
-
accessibilityPredicate
private final AccessibilityPredicate accessibilityPredicate
The predicate to test accessibility.
-
operationSpecifications
private final SpecificationCollection operationSpecifications
The specifications (pre/post/throws-conditions).
-
-
Constructor Detail
-
OperationExtractor
public OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates and that don't violate the omit method predicate.Once created this visitor should only be applied to members of
classType.getRuntimeType()
.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibilityoperationSpecifications
- the specifications (pre/post/throws-conditions)
-
OperationExtractor
public OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateaccessibilityPredicate
- the predicate for test accessibility
-
OperationExtractor
public OperationExtractor(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Creates a visitor object that collects theTypedOperation
objects corresponding to members of the class satisfying the given accessibility and reflection predicates.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibility
-
-
Method Detail
-
operations
public static List<TypedOperation> operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
clazz
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classTypes
- the declaring classes for collected operationsreflectionPredicate
- the reflection predicateaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
clazz
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitPredicate, AccessibilityPredicate accessibilityPredicate)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classTypes
- the declaring classes for collected operationsreflectionPredicate
- the reflection predicateomitPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibility- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(Class<?> clazz, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.- Parameters:
clazz
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitMethodsPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibilityoperationSpecifications
- the specifications (pre/post/throws-conditions)- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(ClassOrInterfaceType classType, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classType
- the declaring class for collected operationsreflectionPredicate
- the reflection predicateomitMethodsPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibilityoperationSpecifications
- the specifications (pre/post/throws-conditions)- Returns:
- the operations in the class that sastisfy the given predicates
-
operations
public static List<TypedOperation> operations(Collection<ClassOrInterfaceType> classTypes, ReflectionPredicate reflectionPredicate, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate, SpecificationCollection operationSpecifications)
Returns the operations in the class that satisfy the given predicates.- Parameters:
classTypes
- the declaring classes for collected operationsreflectionPredicate
- the reflection predicateomitMethodsPredicate
- the list ofPattern
objects for omitting methods, may be nullaccessibilityPredicate
- the predicate for test accessibilityoperationSpecifications
- the specifications (pre/post/throws-conditions)- Returns:
- the operations in the class that sastisfy the given predicates
-
classListToTypeList
public static List<ClassOrInterfaceType> classListToTypeList(List<Class<?>> classes)
Converts a list of classes to a list of ClassOrInterfaceType.- Parameters:
classes
- a list of Class objects- Returns:
- a list of ClassOrInterfaceType objects
-
instantiateTypes
private TypedClassOperation instantiateTypes(TypedClassOperation operation)
Updates the operation types in the case thatoperation.getDeclaringType()
is generic, butclassType
is not. Constructs aSubstitution
that unifies the generic declaring type withclassType
or a superType.- Parameters:
operation
- the operation to instantiate- Returns:
- operation instantiated to match
classType
if the declaring type is generic andclassType
is not; the unmodified operation otherwise - Throws:
RandoopBug
- if there is no substitution that unifies the declaring type withclassType
or a supertype
-
checkSubTypes
private void checkSubTypes(TypedClassOperation operation)
Ensures that fieldclassType
of this object is a subtype ofoperation.getDeclaringType()
; throws an exception if not.- Parameters:
operation
- the operation for which types are to be checked- Throws:
RandoopBug
- if fieldclassType
of this is not a subtype ofoperation.getDeclaringType()
-
visit
public void visit(Constructor<?> constructor)
Creates aConstructorCall
object for theConstructor
.- Specified by:
visit
in interfaceClassVisitor
- Overrides:
visit
in classDefaultClassVisitor
- Parameters:
constructor
- aConstructor
object to be represented as anOperation
-
visit
public void visit(Method method)
Creates aMethodCall
object for theMethod
.The created operation has the declaring class of
method
as the declaring type. An exception is a static method for which the declaring class is not public, in which caseclassType
is used as the declaring class.- Specified by:
visit
in interfaceClassVisitor
- Overrides:
visit
in classDefaultClassVisitor
- Parameters:
method
- aMethod
object to be represented as anOperation
-
visit
public void visit(Field field)
Adds theOperation
objects corresponding to getters and setters appropriate to the kind of field.- Specified by:
visit
in interfaceClassVisitor
- Overrides:
visit
in classDefaultClassVisitor
- Parameters:
field
- aField
object to be represented as anOperation
-
visit
public void visit(Enum<?> e)
Creates aEnumConstant
object for theEnum
.- Specified by:
visit
in interfaceClassVisitor
- Overrides:
visit
in classDefaultClassVisitor
- Parameters:
e
- anEnum
object to be represented as anOperation
-
getOperations
public Collection<TypedOperation> getOperations()
Returns theTypedOperation
objects collected forclassType
.Should be called after all members of the class are visited.
- Returns:
- the collection of operations collected for the class
-
-