public class ReflectionManager
extends java.lang.Object
For a non-enum class, visits:
For an enum, visits:
values and valueOf.
Note that visitors may have their own predicates, but need not check accessibility.
| Modifier and Type | Field and Description |
|---|---|
(package private) boolean |
logToStdout
If true, output diagnostics to stdout rather than to a log.
|
private AccessibilityPredicate |
predicate
The accessibility predicate for classes and class members.
|
private java.util.ArrayList<ClassVisitor> |
visitors
The visitors to apply.
|
| Constructor and Description |
|---|
ReflectionManager(AccessibilityPredicate predicate)
Creates a manager object that uses the given predicate to determine which classes, methods, and
constructors should be visited.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(ClassVisitor visitor)
Registers a
ClassVisitor for use by the apply(Class) method. |
void |
apply(java.lang.Class<?> c)
Applies the registered
ClassVisitor objects of this object to the given class and its
members that satisfy the given predicate. |
void |
apply(ClassVisitor visitor,
java.lang.Class<?> c)
Applies the given
ClassVisitor visitor to the class object and its members that satisfy
the predicate of this reflection manager. |
private void |
applyTo(ClassVisitor v,
java.lang.Class<?> c)
Apply a visitor to the member class.
|
private void |
applyTo(ClassVisitor v,
java.lang.reflect.Constructor<?> co)
Apply a visitor to a constructor.
|
private void |
applyTo(ClassVisitor v,
java.lang.Enum<?> e)
Apply a visitor to a enum value.
|
private void |
applyTo(ClassVisitor v,
java.lang.reflect.Field f)
Apply a visitor to a field.
|
private void |
applyTo(ClassVisitor v,
java.lang.reflect.Method m)
Apply a visitor to a method.
|
private void |
applyToEnum(ClassVisitor visitor,
java.lang.Class<?> c)
Applies the visitors to the constants and methods of the given enum.
|
private boolean |
isAccessible(java.lang.reflect.Constructor<?> c)
Determines whether a constructor and each of its parameter types are accessible.
|
private boolean |
isAccessible(java.lang.reflect.Method m)
Determines whether a method, its parameter types, and its return type are all accessible.
|
private boolean |
isAccessible(java.lang.reflect.Type type)
Determines whether a
java.lang.reflect.Type is a type accessible by to the generated
tests. |
private void |
logPrintf(java.lang.String fmt,
java.lang.Object... args)
Log a diagnostic message with formatting.
|
private void |
logPrintln(java.lang.String s)
Log a one-line literal diagnostic message.
|
private void |
visitAfter(ClassVisitor v,
java.lang.Class<?> c)
Apply a visitor to a class.
|
private void |
visitBefore(ClassVisitor v,
java.lang.Class<?> c)
Apply a visitor to a class.
|
boolean logToStdout
private AccessibilityPredicate predicate
DO NOT use this field directly (except on classes and fields)! Instead, call the methods
isAccessible() that are defined in this class.
private java.util.ArrayList<ClassVisitor> visitors
public ReflectionManager(AccessibilityPredicate predicate)
predicate - the predicate to indicate whether classes and class members should be visitedpublic void add(ClassVisitor visitor)
ClassVisitor for use by the apply(Class) method.visitor - the ClassVisitor object to addpublic void apply(java.lang.Class<?> c)
ClassVisitor objects of this object to the given class and its
members that satisfy the given predicate. Excludes fields that are shadowed by inheritance that
are otherwise still accessible by reflection. Each visitor is applied to each member at most
once.c - the Class object to be visitedpublic void apply(ClassVisitor visitor, java.lang.Class<?> c)
ClassVisitor visitor to the class object and its members that satisfy
the predicate of this reflection manager.
Sorts class members to ensure a canonical order for visits.
visitor - the ClassVisitor to apply to the classc - the classprivate void applyToEnum(ClassVisitor visitor, java.lang.Class<?> c)
Heuristically exclude methods values and valueOf since their definition is
implicit, and we aren't testing Java enum implementation.
visitor - the ClassVisitorc - the enum class object from which constants and methods are extractedprivate void applyTo(ClassVisitor v, java.lang.reflect.Field f)
v - the ClassVisitorf - the field to be visitedprivate void applyTo(ClassVisitor v, java.lang.Class<?> c)
The ReflectionManager does not apply itself to the member class, since it could
violate assumptions in the visitor. And, so instead allows the visitor to implement that call
if it is necessary.
v - the ClassVisitorc - the member class to be visitedprivate void applyTo(ClassVisitor v, java.lang.reflect.Constructor<?> co)
v - the ClassVisitorco - the constructor to be visitedprivate void applyTo(ClassVisitor v, java.lang.reflect.Method m)
v - the ClassVisitorm - the method to be visitedprivate void applyTo(ClassVisitor v, java.lang.Enum<?> e)
v - the ClassVisitore - the enum value to be visitedprivate void visitBefore(ClassVisitor v, java.lang.Class<?> c)
apply(Class).v - the ClassVisitorc - the class to be visitedprivate void visitAfter(ClassVisitor v, java.lang.Class<?> c)
apply(Class).v - the ClassVisitorc - the class to be visitedprivate boolean isAccessible(java.lang.reflect.Method m)
m - the method to check for accessibilityprivate boolean isAccessible(java.lang.reflect.Constructor<?> c)
c - the constructorprivate boolean isAccessible(java.lang.reflect.Type type)
java.lang.reflect.Type is a type accessible by to the generated
tests.type - the type to checkprivate void logPrintf(java.lang.String fmt,
java.lang.Object... args)
fmt - the format stringargs - the arguments to the format stringprivate void logPrintln(java.lang.String s)
s - the message, a complete line without line terminator