Class FeatureUtil
- java.lang.Object
-
- com.google.common.collect.testing.features.FeatureUtil
-
public class FeatureUtil extends java.lang.ObjectUtilities for collecting and validating tester requirements from annotations.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.reflect.AnnotatedElement,java.util.List<java.lang.annotation.Annotation>>annotationCacheA cache of annotated objects (typically a Class or Method) to its set of annotations.private static java.util.Map<java.lang.Class<?>,TesterRequirements>classTesterRequirementsCacheprivate static java.util.Map<java.lang.reflect.Method,TesterRequirements>methodTesterRequirementsCache
-
Constructor Summary
Constructors Constructor Description FeatureUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<Feature<?>>addImpliedFeatures(java.util.Set<Feature<?>> features)Given a set of features, add to it all the features directly or indirectly implied by any of them, and return it.static TesterRequirementsbuildDeclaredTesterRequirements(java.lang.reflect.AnnotatedElement classOrMethod)Construct the set of requirements specified by annotations directly on a tester class or method.private static TesterRequirementsbuildTesterRequirements(java.lang.annotation.Annotation testerAnnotation)Find all the constraints explicitly or implicitly specified by a single tester annotation.(package private) static TesterRequirementsbuildTesterRequirements(java.lang.Class<?> testerClass)Construct the full set of requirements for a tester class.(package private) static TesterRequirementsbuildTesterRequirements(java.lang.reflect.Method testerMethod)Construct the full set of requirements for a tester method.private static voidcheckConflict(java.lang.String earlierRequirement, java.util.Set<Feature<?>> earlierFeatures, java.lang.String newRequirement, java.util.Set<Feature<?>> newFeatures, java.lang.Object source)static java.lang.Iterable<java.lang.annotation.Annotation>getTesterAnnotations(java.lang.reflect.AnnotatedElement classOrMethod)Find all the tester annotations declared on a tester class or method.static TesterRequirementsgetTesterRequirements(java.lang.Class<?> testerClass)Get the full set of requirements for a tester class.static TesterRequirementsgetTesterRequirements(java.lang.reflect.Method testerMethod)Get the full set of requirements for a tester class.static java.util.Set<Feature<?>>impliedFeatures(java.util.Set<Feature<?>> features)Given a set of features, return a new set of all features directly or indirectly implied by any of them.private static TesterRequirementsincorporateRequirements(TesterRequirements requirements, TesterRequirements moreRequirements, java.lang.Object source)Incorporate additional requirements into an existing requirements object.static <T> java.util.Set<T>intersection(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2)Construct a newSetthat is the intersection of the given sets.
-
-
-
Field Detail
-
annotationCache
private static java.util.Map<java.lang.reflect.AnnotatedElement,java.util.List<java.lang.annotation.Annotation>> annotationCache
A cache of annotated objects (typically a Class or Method) to its set of annotations.
-
classTesterRequirementsCache
private static final java.util.Map<java.lang.Class<?>,TesterRequirements> classTesterRequirementsCache
-
methodTesterRequirementsCache
private static final java.util.Map<java.lang.reflect.Method,TesterRequirements> methodTesterRequirementsCache
-
-
Method Detail
-
addImpliedFeatures
public static java.util.Set<Feature<?>> addImpliedFeatures(java.util.Set<Feature<?>> features)
Given a set of features, add to it all the features directly or indirectly implied by any of them, and return it.- Parameters:
features- the set of features to expand- Returns:
- the same set of features, expanded with all implied features
-
impliedFeatures
public static java.util.Set<Feature<?>> impliedFeatures(java.util.Set<Feature<?>> features)
Given a set of features, return a new set of all features directly or indirectly implied by any of them.- Parameters:
features- the set of features whose implications to find- Returns:
- the implied set of features
-
getTesterRequirements
public static TesterRequirements getTesterRequirements(java.lang.Class<?> testerClass) throws ConflictingRequirementsException
Get the full set of requirements for a tester class.- Parameters:
testerClass- a tester class- Returns:
- all the constraints implicitly or explicitly required by the class or any of its superclasses.
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
getTesterRequirements
public static TesterRequirements getTesterRequirements(java.lang.reflect.Method testerMethod) throws ConflictingRequirementsException
Get the full set of requirements for a tester class.- Parameters:
testerMethod- a test method of a tester class- Returns:
- all the constraints implicitly or explicitly required by the method, its declaring class, or any of its superclasses.
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
buildTesterRequirements
static TesterRequirements buildTesterRequirements(java.lang.Class<?> testerClass) throws ConflictingRequirementsException
Construct the full set of requirements for a tester class.- Parameters:
testerClass- a tester class- Returns:
- all the constraints implicitly or explicitly required by the class or any of its superclasses.
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
buildTesterRequirements
static TesterRequirements buildTesterRequirements(java.lang.reflect.Method testerMethod) throws ConflictingRequirementsException
Construct the full set of requirements for a tester method.- Parameters:
testerMethod- a test method of a tester class- Returns:
- all the constraints implicitly or explicitly required by the method, its declaring class, or any of its superclasses.
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
buildTesterRequirements
private static TesterRequirements buildTesterRequirements(java.lang.annotation.Annotation testerAnnotation) throws ConflictingRequirementsException
Find all the constraints explicitly or implicitly specified by a single tester annotation.- Parameters:
testerAnnotation- a tester annotation- Returns:
- the requirements specified by the annotation
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
buildDeclaredTesterRequirements
public static TesterRequirements buildDeclaredTesterRequirements(java.lang.reflect.AnnotatedElement classOrMethod) throws ConflictingRequirementsException
Construct the set of requirements specified by annotations directly on a tester class or method.- Parameters:
classOrMethod- a tester class or a test method thereof- Returns:
- all the constraints implicitly or explicitly required by annotations on the class or method.
- Throws:
ConflictingRequirementsException- if the requirements are mutually inconsistent.
-
getTesterAnnotations
public static java.lang.Iterable<java.lang.annotation.Annotation> getTesterAnnotations(java.lang.reflect.AnnotatedElement classOrMethod)
Find all the tester annotations declared on a tester class or method.- Parameters:
classOrMethod- a class or method whose tester annotations to find- Returns:
- an iterable sequence of tester annotations on the class
-
incorporateRequirements
private static TesterRequirements incorporateRequirements(TesterRequirements requirements, TesterRequirements moreRequirements, java.lang.Object source) throws ConflictingRequirementsException
Incorporate additional requirements into an existing requirements object.- Parameters:
requirements- the existing requirements objectmoreRequirements- more requirements to incorporatesource- the source of the additional requirements (used only for error reporting)- Returns:
- the existing requirements object, modified to include the additional requirements
- Throws:
ConflictingRequirementsException- if the additional requirements are inconsistent with the existing requirements
-
checkConflict
private static void checkConflict(java.lang.String earlierRequirement, java.util.Set<Feature<?>> earlierFeatures, java.lang.String newRequirement, java.util.Set<Feature<?>> newFeatures, java.lang.Object source) throws ConflictingRequirementsException- Throws:
ConflictingRequirementsException
-
intersection
public static <T> java.util.Set<T> intersection(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2)Construct a newSetthat is the intersection of the given sets.
-
-