public class DefaultReflectionPredicate extends java.lang.Object implements ReflectionPredicate
doNotUseSpecialCase(java.lang.reflect.Method) method).
If a method has the @CheckRep annotation, returns false (the method will be used as a
contract checker, not as a method under test).
| Modifier and Type | Field and Description |
|---|---|
private java.util.Collection<java.lang.String> |
omitFields
The set of fully-qualified field names to omit from generated tests.
|
| Constructor and Description |
|---|
DefaultReflectionPredicate()
Create a reflection predicate.
|
DefaultReflectionPredicate(java.util.Collection<java.lang.String> omitFields)
DefaultReflectionFilter creates a filter object that uses default criteria for inclusion of
reflection objects.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
definesNonBridgeMethod(java.lang.Class<?> c,
java.lang.reflect.Method goalMethod)
Returns true if the class defines the given method, not as a bridge method.
|
private boolean |
discardBridge(java.lang.reflect.Method m)
Determines whether a bridge method should be discarded.
|
private java.lang.String |
doNotUseSpecialCase(java.lang.reflect.Method m)
Indicates methods for which this predicate should return false.
|
private boolean |
isPublic(java.lang.Class<?> c)
Indicates whether the
Class is public. |
private boolean |
isRandoopInstrumentation(java.lang.reflect.Field f)
Indicates that a field is generated by the covered-class instrumentation agent.
|
private boolean |
isRandoopInstrumentation(java.lang.reflect.Method m) |
private boolean |
isVisibilityBridge(java.lang.reflect.Method m)
Determines whether a bridge method is a visibility bridge, which allows access to a
definition of the method in a non-accessible superclass.
|
boolean |
test(java.lang.Class<?> c)
Indicate whether Randoop should use a class.
|
boolean |
test(java.lang.reflect.Constructor<?> c)
Indicate whether Randoop should use a constructor.
|
boolean |
test(java.lang.reflect.Field f)
Determines whether the name of a field is included among the omitted field names.
|
boolean |
test(java.lang.reflect.Method m)
Indicate whether Randoop should use a method.
|
private java.util.Collection<java.lang.String> omitFields
GenInputsAbstract.omit_field.public DefaultReflectionPredicate()
public DefaultReflectionPredicate(java.util.Collection<java.lang.String> omitFields)
omitFields - set of fully-qualified field names to omitpublic boolean test(java.lang.Class<?> c)
ReflectionPredicatetest in interface ReflectionPredicatec - the class to testpublic boolean test(java.lang.reflect.Method m)
Does checks for the several cases, including main methods, bridge methods (see discardBridge(Method), non-bridge synthetic methods, non-accessible methods, or methods with
non-accessible return types.
See the code for the full list.
test in interface ReflectionPredicatem - the method to testprivate boolean isRandoopInstrumentation(java.lang.reflect.Method m)
private boolean discardBridge(java.lang.reflect.Method m)
Bridge methods are synthetic overriding methods that are generated by the compiler to make certain calls type-correct.
Two of the three known cases involve forcing unchecked casts to allow type narrowing of return types (covariant return types) and instantiation of generic type parameters in methods. Both of these are situations that a programmer could view as overriding, but really aren't. These bridge methods do unchecked type conversions from the general type to the more specific type expected by the local method. As a result, if included for testing, Randoop would generate many tests that would confirm that there is an unchecked type conversion. So, we do not want to include these methods.
The third known case involves a public class inheriting a public method defined in a private class of the same package. The bridge method in the public class exposes the method outside of the package, and we *do* want to be able to call this method. (This sort of trick is useful in providing a facade to an API where implementation details are only accessible within the package.)
The only case in which a bridge method should be kept is when it is a visibility bridge.
m - the bridge method to testprivate boolean isVisibilityBridge(java.lang.reflect.Method m)
throws java.lang.Error
The method is a visibility bridge if this class is public and some superclass defines the method as non-public.
m - the bridge method to testm is a visibility bridgejava.lang.Error - if a SecurityException is thrown when accessing superclass methodsprivate boolean definesNonBridgeMethod(java.lang.Class<?> c,
java.lang.reflect.Method goalMethod)
c - the possibly-containing classgoalMethod - the method to search forprivate boolean isPublic(java.lang.Class<?> c)
Class is public.c - the classc is a public classprivate java.lang.String doNotUseSpecialCase(java.lang.reflect.Method m)
m - the method to accept or reject for inclusion in methods under testpublic boolean test(java.lang.reflect.Constructor<?> c)
Use the constructor unless it is specifically omitted, is synthetic with anonymous parameters, or the class is abstract.
test in interface ReflectionPredicatec - the constructor to testpublic boolean test(java.lang.reflect.Field f)
test in interface ReflectionPredicatef - field to testprivate boolean isRandoopInstrumentation(java.lang.reflect.Field f)
Tests whether the field begins with "randoop_".
f - the field