Class DefaultReflectionPredicate
- java.lang.Object
-
- randoop.reflection.DefaultReflectionPredicate
-
- All Implemented Interfaces:
ReflectionPredicate
public class DefaultReflectionPredicate extends Object implements ReflectionPredicate
Default implementations of methods that indicate what is "under test": whether a class, method, constructor, or field should be used in Randoop's exploration. Returns true for public members, with some exceptions (seedoNotUseSpecialCase(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).
-
-
Field Summary
Fields Modifier and Type Field Description private Collection<String>
omitFields
The set of fully-qualified field names to omit from generated tests.
-
Constructor Summary
Constructors Constructor Description DefaultReflectionPredicate()
Create a reflection predicate.DefaultReflectionPredicate(Collection<String> omitFields)
DefaultReflectionFilter creates a filter object that uses default criteria for inclusion of reflection objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
definesNonBridgeMethod(Class<?> c, Method goalMethod)
Returns true if the class defines the given method, not as a bridge method.private boolean
discardBridge(Method m)
Determines whether a bridge method should be discarded.private String
doNotUseSpecialCase(Method m)
Indicates methods for which this predicate should return false.private boolean
isPublic(Class<?> c)
Indicates whether theClass
is public.private boolean
isRandoopInstrumentation(Field f)
Indicates that a field is generated by the covered-class instrumentation agent.private boolean
isRandoopInstrumentation(Method m)
private boolean
isVisibilityBridge(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(Class<?> c)
Indicate whether Randoop should use a class.boolean
test(Constructor<?> c)
Indicate whether Randoop should use a constructor.boolean
test(Field f)
Determines whether the name of a field is included among the omitted field names.boolean
test(Method m)
Indicate whether Randoop should use a method.
-
-
-
Field Detail
-
omitFields
private Collection<String> omitFields
The set of fully-qualified field names to omit from generated tests. SeeGenInputsAbstract.omit_field
.
-
-
Constructor Detail
-
DefaultReflectionPredicate
public DefaultReflectionPredicate()
Create a reflection predicate.
-
DefaultReflectionPredicate
public DefaultReflectionPredicate(Collection<String> omitFields)
DefaultReflectionFilter creates a filter object that uses default criteria for inclusion of reflection objects.- Parameters:
omitFields
- set of fully-qualified field names to omit
-
-
Method Detail
-
test
public boolean test(Class<?> c)
Description copied from interface:ReflectionPredicate
Indicate whether Randoop should use a class.- Specified by:
test
in interfaceReflectionPredicate
- Parameters:
c
- the class to test- Returns:
- true if the class meets the predicate criteria, false otherwise
-
test
public boolean test(Method m)
Indicate whether Randoop should use a method.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.
- Specified by:
test
in interfaceReflectionPredicate
- Parameters:
m
- the method to test- Returns:
- true if the method meets the predicate criteria, false otherwise
-
isRandoopInstrumentation
private boolean isRandoopInstrumentation(Method m)
-
discardBridge
private boolean discardBridge(Method m)
Determines whether a bridge method should be discarded.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.
- Parameters:
m
- the bridge method to test- Returns:
- true if the bridge method should be discarded, false otherwise
-
isVisibilityBridge
private boolean isVisibilityBridge(Method m) throws Error
Determines whether a bridge method is a visibility bridge, which allows access to a definition of the method in a non-accessible superclass.The method is a visibility bridge if this class is public and some superclass defines the method as non-public.
- Parameters:
m
- the bridge method to test- Returns:
- true iff
m
is a visibility bridge - Throws:
Error
- if aSecurityException
is thrown when accessing superclass methods
-
definesNonBridgeMethod
private boolean definesNonBridgeMethod(Class<?> c, Method goalMethod)
Returns true if the class defines the given method, not as a bridge method. Returns false if the class does not define the given method, or if the class defines the method as a bridge method. Ignores inheritance of methods.- Parameters:
c
- the possibly-containing classgoalMethod
- the method to search for- Returns:
- true if the class defines the method
-
isPublic
private boolean isPublic(Class<?> c)
Indicates whether theClass
is public.- Parameters:
c
- the class- Returns:
- true if
c
is a public class
-
doNotUseSpecialCase
private String doNotUseSpecialCase(Method m)
Indicates methods for which this predicate should return false. See inline comments for details. This is a main place that Randoop controls which methods are methods under test.- Parameters:
m
- the method to accept or reject for inclusion in methods under test- Returns:
- a non-null string giving a reason the method should be skipped, or null to not skip it
-
test
public boolean test(Constructor<?> c)
Indicate whether Randoop should use a constructor.Use the constructor unless it is specifically omitted, is synthetic with anonymous parameters, or the class is abstract.
- Specified by:
test
in interfaceReflectionPredicate
- Parameters:
c
- the constructor to test- Returns:
- true if the constructor meets the predicate criteria, false otherwise
-
test
public boolean test(Field f)
Determines whether the name of a field is included among the omitted field names.- Specified by:
test
in interfaceReflectionPredicate
- Parameters:
f
- field to test- Returns:
- true if field name does not occur in omitFields pattern, and false if it does
-
isRandoopInstrumentation
private boolean isRandoopInstrumentation(Field f)
Indicates that a field is generated by the covered-class instrumentation agent.Tests whether the field begins with
"randoop_"
.- Parameters:
f
- the field- Returns:
- true if the field name
-
-