Package edu.umd.cs.findbugs.ba.jsr305
Class TypeQualifierApplications
java.lang.Object
edu.umd.cs.findbugs.ba.jsr305.TypeQualifierApplications
Figure out where and how type qualifier annotations are applied.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interface
Callback interface to compute effective TypeQualifierAnnotation on an AnnotatedObject or method parameter.(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final boolean
Should exclusive type qualifiers be handled?(package private) static final boolean
(package private) static final boolean
(package private) static final boolean
(package private) static final String
private static ThreadLocal
<TypeQualifierApplications.Data> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static TypeQualifierAnnotation
checkFindBugsDefaultAnnotation
(ClassDescriptor defaultAnnotation, AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) static void
private static TypeQualifierAnnotation
computeEffectiveTypeQualifierAnnotation
(TypeQualifierValue<?> typeQualifierValue, XMethod xmethod, int parameter) private static TypeQualifierAnnotation
computeEffectiveTypeQualifierAnnotation
(TypeQualifierValue<?> typeQualifierValue, AnnotatedObject o) private static TypeQualifierAnnotation
computeExclusiveQualifier
(TypeQualifierValue<?> typeQualifierValue, TypeQualifierApplications.ComputeEffectiveTypeQualifierAnnotation c) static TypeQualifierAnnotation
Resolve a raw AnnotationValue into a TypeQualifierAnnotation.static void
Resolve a raw AnnotationValue into a TypeQualifierAnnotation, storing result in given Set.private static TypeQualifierAnnotation
extractAnnotation
(Collection<AnnotationValue> resolvedTypeQualifiers, TypeQualifierValue<?> typeQualifierValue) private static TypeQualifierAnnotation
findMatchingTypeQualifierAnnotation
(Collection<TypeQualifierAnnotation> typeQualifierAnnotations, TypeQualifierValue<?> typeQualifierValue) Look up a TypeQualifierAnnotation matching given TypeQualifierValue.static Collection
<TypeQualifierAnnotation> getApplicableApplications
(XMethod o, int parameter) Get the Collection of resolved TypeQualifierAnnotations representing directly applied and default (outer scope) type qualifier annotations for given method parameter.static Collection
<TypeQualifierAnnotation> Get the Collection of resolved TypeQualifierAnnotations representing directly applied and default (outer scope) type qualifier annotations for given AnnotatedObject.private static Collection
<TypeQualifierAnnotation> getApplicableScopedApplications
(XMethod o, int parameter) Get the collection of resolved TypeQualifierAnnotations for a given parameter, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)private static Collection
<TypeQualifierAnnotation> Get the collection of resolved TypeQualifierAnnotations for a given AnnotatedObject, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)private static void
getApplicableScopedApplications
(Set<TypeQualifierAnnotation> result, AnnotatedObject o, ElementType e) Populate Set of TypeQualifierAnnotations for given AnnotatedObject, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)private static TypeQualifierAnnotation
getDefaultAnnotation
(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue, ElementType elementType) Look for a default type qualifier annotation.private static TypeQualifierAnnotation
getDefaultTypeQualifierAnnotation
(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue, boolean stopAtClassScope) Get the default (outer scope) annotation applicable to given AnnotatedObject.private static TypeQualifierAnnotation
getDefaultTypeQualifierAnnotationForParameters
(XMethod xmethod, TypeQualifierValue<?> typeQualifierValue, boolean stopAtMethodScope) Get the default (outer-scope) TypeQualifierAnnotation on given method parameter.private static Collection
<AnnotationValue> getDirectAnnotation
(XMethod m, int parameter) Get the direct annotations (if any) on given method parameter.private static Collection
<AnnotationValue> Get the direct annotations (if any) on given AnnotatedObject.static void
getDirectApplications
(Set<TypeQualifierAnnotation> result, XMethod o, int parameter) Populate a Set of TypeQualifierAnnotations representing directly-applied type qualifier annotations on given method parameter.static void
getDirectApplications
(Set<TypeQualifierAnnotation> result, AnnotatedObject o, ElementType e) Populate a Set of TypeQualifierAnnotations representing directly-applied type qualifier annotations on given AnnotatedObject.private static Map
<AnnotatedObject, Collection<AnnotationValue>> private static HashMap
<XMethod, Map<Integer, Collection<AnnotationValue>>> static TypeQualifierAnnotation
getDirectTypeQualifierAnnotation
(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the TypeQualifierAnnotation directly applied to given method parameter.private static TypeQualifierAnnotation
getDirectTypeQualifierAnnotation
(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) Get a directly-applied TypeQualifierAnnotation on given AnnotatedObject.private static Map
<TypeQualifierValue<?>, Map<AnnotatedObject, TypeQualifierAnnotation>> private static Map
<TypeQualifierValue<?>, DualKeyHashMap<XMethod, Integer, TypeQualifierAnnotation>> static TypeQualifierAnnotation
getEffectiveTypeQualifierAnnotation
(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the effective TypeQualifierAnnotation on given method parameter.static TypeQualifierAnnotation
getEffectiveTypeQualifierAnnotation
(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) Get the effective TypeQualifierAnnotation on given AnnotatedObject.static TypeQualifierAnnotation
getInheritedTypeQualifierAnnotation
(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the effective inherited TypeQualifierAnnotation on the given instance method parameter.static TypeQualifierAnnotation
getInheritedTypeQualifierAnnotation
(XMethod o, TypeQualifierValue<?> typeQualifierValue) Get the effective inherited TypeQualifierAnnotation on given instance method.static void
updateAnnotations
(AnnotatedObject object)
-
Field Details
-
DEBUG
static final boolean DEBUG -
DEBUG_METHOD
-
DEBUG_DEFAULT_ANNOTATION
static final boolean DEBUG_DEFAULT_ANNOTATION -
CHECK_EXCLUSIVE
static final boolean CHECK_EXCLUSIVEShould exclusive type qualifiers be handled?- See Also:
-
CHECK_EXHAUSTIVE
static final boolean CHECK_EXHAUSTIVE- See Also:
-
instance
-
-
Constructor Details
-
TypeQualifierApplications
public TypeQualifierApplications()
-
-
Method Details
-
clearInstance
public static void clearInstance() -
getEffectiveParameterAnnotations
private static Map<TypeQualifierValue<?>,DualKeyHashMap<XMethod, getEffectiveParameterAnnotations()Integer, TypeQualifierAnnotation>> -
getEffectiveObjectAnnotations
private static Map<TypeQualifierValue<?>,Map<AnnotatedObject, getEffectiveObjectAnnotations()TypeQualifierAnnotation>> -
getDirectParameterAnnotations
private static HashMap<XMethod,Map<Integer, getDirectParameterAnnotations()Collection<AnnotationValue>>> -
getDirectObjectAnnotations
-
updateAnnotations
-
getDirectAnnotation
Get the direct annotations (if any) on given AnnotatedObject.- Parameters:
m
- an AnnotatedObject- Returns:
- Collection of AnnotationValues representing annotations directly applied to this AnnotatedObject
-
getDirectAnnotation
Get the direct annotations (if any) on given method parameter.- Parameters:
m
- a methodparameter
- a parameter (0 == first parameter)- Returns:
- Collection of AnnotationValues representing annotations directly applied to this parameter
-
getDirectApplications
public static void getDirectApplications(Set<TypeQualifierAnnotation> result, XMethod o, int parameter) Populate a Set of TypeQualifierAnnotations representing directly-applied type qualifier annotations on given method parameter.- Parameters:
result
- Set of TypeQualifierAnnotationso
- a methodparameter
- a parameter (0 == first parameter)
-
getDirectApplications
public static void getDirectApplications(Set<TypeQualifierAnnotation> result, AnnotatedObject o, ElementType e) Populate a Set of TypeQualifierAnnotations representing directly-applied type qualifier annotations on given AnnotatedObject.- Parameters:
result
- Set of TypeQualifierAnnotationso
- an AnnotatedObjecte
- ElementType representing kind of annotated object
-
constructTypeQualifierAnnotation
Resolve a raw AnnotationValue into a TypeQualifierAnnotation.- Parameters:
v
- a raw AnnotationValue- Returns:
- a constructed TypeQualifierAnnotation
-
constructTypeQualifierAnnotation
public static void constructTypeQualifierAnnotation(Set<TypeQualifierAnnotation> set, AnnotationValue v) Resolve a raw AnnotationValue into a TypeQualifierAnnotation, storing result in given Set.- Parameters:
set
- Set of resolved TypeQualifierAnnotationsv
- a raw AnnotationValue
-
getApplicableScopedApplications
private static void getApplicableScopedApplications(Set<TypeQualifierAnnotation> result, AnnotatedObject o, ElementType e) Populate Set of TypeQualifierAnnotations for given AnnotatedObject, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)- Parameters:
result
- Set of TypeQualifierAnnotationso
- an AnnotatedObjecte
- ElementType representing kind of AnnotatedObject
-
getApplicableScopedApplications
private static Collection<TypeQualifierAnnotation> getApplicableScopedApplications(AnnotatedObject o, ElementType e) Get the collection of resolved TypeQualifierAnnotations for a given AnnotatedObject, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)- Parameters:
o
- an AnnotatedObjecte
- ElementType representing kind of AnnotatedObject- Returns:
- Collection of resolved TypeQualifierAnnotations
-
getApplicableScopedApplications
private static Collection<TypeQualifierAnnotation> getApplicableScopedApplications(XMethod o, int parameter) Get the collection of resolved TypeQualifierAnnotations for a given parameter, taking into account annotations applied to outer scopes (e.g., enclosing classes and packages.)- Parameters:
o
- a methodparameter
- a parameter (0 == first parameter)- Returns:
- Collection of resolved TypeQualifierAnnotations
-
getApplicableApplications
Get the Collection of resolved TypeQualifierAnnotations representing directly applied and default (outer scope) type qualifier annotations for given AnnotatedObject.NOTE: does not properly account for inherited annotations on instance methods. It is ok to call this method to find out generally-relevant TypeQualifierAnnotations, but not to find the effective TypeQualifierAnnotation.
- Parameters:
o
- an AnnotatedObject- Returns:
- Collection of TypeQualifierAnnotations applicable to the AnnotatedObject
-
getApplicableApplications
public static Collection<TypeQualifierAnnotation> getApplicableApplications(XMethod o, int parameter) Get the Collection of resolved TypeQualifierAnnotations representing directly applied and default (outer scope) type qualifier annotations for given method parameter.NOTE: does not properly account for inherited annotations on instance method parameters. It is ok to call this method to find out generally-relevant TypeQualifierAnnotations, but not to find the effective TypeQualifierAnnotation.
- Parameters:
o
- a methodparameter
- a parameter (0 == first parameter)- Returns:
- Collection of TypeQualifierAnnotations applicable to the method parameter
-
findMatchingTypeQualifierAnnotation
@CheckForNull private static TypeQualifierAnnotation findMatchingTypeQualifierAnnotation(Collection<TypeQualifierAnnotation> typeQualifierAnnotations, TypeQualifierValue<?> typeQualifierValue) Look up a TypeQualifierAnnotation matching given TypeQualifierValue.- Parameters:
typeQualifierAnnotations
- a Collection of TypeQualifierAnnotationstypeQualifierValue
- a TypeQualifierValue- Returns:
- matching TypeQualifierAnnotation, or null if none
-
getDefaultAnnotation
@CheckForNull private static TypeQualifierAnnotation getDefaultAnnotation(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue, ElementType elementType) Look for a default type qualifier annotation.- Parameters:
o
- an AnnotatedObjecttypeQualifierValue
- a TypeQualifierValueelementType
- type of element for which we're looking for a default annotation- Returns:
- default TypeQualifierAnnotation, or null if none
-
checkFindBugsDefaultAnnotation
@CheckForNull private static TypeQualifierAnnotation checkFindBugsDefaultAnnotation(ClassDescriptor defaultAnnotation, AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) -
extractAnnotation
private static TypeQualifierAnnotation extractAnnotation(Collection<AnnotationValue> resolvedTypeQualifiers, TypeQualifierValue<?> typeQualifierValue) -
getEffectiveTypeQualifierAnnotation
public static TypeQualifierAnnotation getEffectiveTypeQualifierAnnotation(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) Get the effective TypeQualifierAnnotation on given AnnotatedObject. Takes into account inherited and default (outer scope) annotations. Also takes exclusive qualifiers into account.- Parameters:
o
- an AnnotatedObjecttypeQualifierValue
- a TypeQualifierValue specifying kind of annotation we want to look up- Returns:
- the effective TypeQualifierAnnotation, or null if there is no effective TypeQualifierAnnotation on this AnnotatedObject
-
computeEffectiveTypeQualifierAnnotation
private static TypeQualifierAnnotation computeEffectiveTypeQualifierAnnotation(TypeQualifierValue<?> typeQualifierValue, AnnotatedObject o) -
getDirectTypeQualifierAnnotation
private static TypeQualifierAnnotation getDirectTypeQualifierAnnotation(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue) Get a directly-applied TypeQualifierAnnotation on given AnnotatedObject.- Parameters:
o
- an AnnotatedObjecttypeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- directly-applied TypeQualifierAnnotation, or null if there is no such annotation on the AnnotatedObject
-
getInheritedTypeQualifierAnnotation
public static TypeQualifierAnnotation getInheritedTypeQualifierAnnotation(XMethod o, TypeQualifierValue<?> typeQualifierValue) Get the effective inherited TypeQualifierAnnotation on given instance method.- Parameters:
o
- an XMethodtypeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- effective TypeQualifierAnnotation inherited from overridden supertype methods, or null if there is no inherited TypeQualifierAnnotation
-
getDefaultTypeQualifierAnnotation
private static TypeQualifierAnnotation getDefaultTypeQualifierAnnotation(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue, boolean stopAtClassScope) Get the default (outer scope) annotation applicable to given AnnotatedObject.- Parameters:
o
- an AnnotatedObjecttypeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- the applicable default TypeQualifierAnnotation, or null if there is no default TypeQualifierAnnotation
-
getEffectiveTypeQualifierAnnotation
@CheckForNull public static TypeQualifierAnnotation getEffectiveTypeQualifierAnnotation(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the effective TypeQualifierAnnotation on given method parameter. Takes into account inherited and default (outer scope) annotations. Also takes exclusive qualifiers into account.- Parameters:
xmethod
- a methodparameter
- a parameter (0 == first parameter)typeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- effective TypeQualifierAnnotation on the parameter, or null if there is no effective TypeQualifierAnnotation
-
computeEffectiveTypeQualifierAnnotation
private static TypeQualifierAnnotation computeEffectiveTypeQualifierAnnotation(TypeQualifierValue<?> typeQualifierValue, XMethod xmethod, int parameter) -
getDirectTypeQualifierAnnotation
@CheckForNull @CheckReturnValue public static TypeQualifierAnnotation getDirectTypeQualifierAnnotation(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the TypeQualifierAnnotation directly applied to given method parameter.- Parameters:
xmethod
- a methodparameter
- a parameter (0 == first parameter)typeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- TypeQualifierAnnotation directly applied to the parameter, or null if there is no directly applied TypeQualifierAnnotation
-
getInheritedTypeQualifierAnnotation
@CheckForNull public static TypeQualifierAnnotation getInheritedTypeQualifierAnnotation(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) Get the effective inherited TypeQualifierAnnotation on the given instance method parameter.- Parameters:
xmethod
- an instance methodparameter
- a parameter (0 == first parameter)typeQualifierValue
- the kind of TypeQualifierValue we are looking for- Returns:
- effective inherited TypeQualifierAnnotation on the parameter, or null if there is not effective TypeQualifierAnnotation
-
getDefaultTypeQualifierAnnotationForParameters
@CheckForNull private static TypeQualifierAnnotation getDefaultTypeQualifierAnnotationForParameters(XMethod xmethod, TypeQualifierValue<?> typeQualifierValue, boolean stopAtMethodScope) Get the default (outer-scope) TypeQualifierAnnotation on given method parameter.- Parameters:
xmethod
- a methodtypeQualifierValue
- the kind of TypeQualifierValue we are looking forstopAtMethodScope
-- Returns:
- the default (outer scope) TypeQualifierAnnotation on the parameter, or null if there is no default TypeQualifierAnnotation
-
computeExclusiveQualifier
private static TypeQualifierAnnotation computeExclusiveQualifier(TypeQualifierValue<?> typeQualifierValue, TypeQualifierApplications.ComputeEffectiveTypeQualifierAnnotation c)
-