public abstract class QualifierHierarchy extends Object
All method parameter annotations need to be type qualifiers recognized within this hierarchy.
This assumes that any particular annotated type in a program is annotated with at least one qualifier from the hierarchy.
Constructor and Description |
---|
QualifierHierarchy() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canHaveEmptyAnnotationSet(AnnotatedTypeMirror type)
Returns true if and only if the given type can have empty annotation sets (and thus the
*TypeVariable methods need to be used).
|
AnnotationMirror |
findAnnotationInHierarchy(Collection<? extends AnnotationMirror> annos,
AnnotationMirror top)
Returns the annotation in annos that is in the hierarchy for which annotationMirror is top.
|
AnnotationMirror |
findAnnotationInSameHierarchy(Collection<? extends AnnotationMirror> annos,
AnnotationMirror annotationMirror)
Returns the annotation in annos that is in the same hierarchy as annotationMirror.
|
abstract AnnotationMirror |
getBottomAnnotation(AnnotationMirror start)
Return the bottom for the given qualifier, that is, the qualifier that is a subtype of start
but no further subtypes exist.
|
abstract Set<? extends AnnotationMirror> |
getBottomAnnotations() |
abstract AnnotationMirror |
getPolymorphicAnnotation(AnnotationMirror start) |
abstract AnnotationMirror |
getTopAnnotation(AnnotationMirror start)
Return the top qualifier for the given qualifier, that is, the qualifier that is a supertype
of start but no further supertypes exist.
|
abstract Set<? extends AnnotationMirror> |
getTopAnnotations() |
abstract Set<? extends AnnotationMirror> |
getTypeQualifiers()
Returns all type qualifiers in this type qualifier hierarchy.
|
int |
getWidth()
Returns the width of this hierarchy, i.e.
|
AnnotationMirror |
greatestLowerBound(AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2,
AnnotationMirror a1,
AnnotationMirror a2)
Returns the greatest lower bound for the qualifiers a1 and a2.
|
abstract AnnotationMirror |
greatestLowerBound(AnnotationMirror a1,
AnnotationMirror a2)
Returns the greatest lower bound for the qualifiers a1 and a2.
|
Set<? extends AnnotationMirror> |
greatestLowerBounds(AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2,
Collection<? extends AnnotationMirror> annos1,
Collection<AnnotationMirror> annos2)
Returns the type qualifiers that are the greatest lower bound of the qualifiers in annos1 and
annos2.
|
Set<? extends AnnotationMirror> |
greatestLowerBounds(Collection<? extends AnnotationMirror> annos1,
Collection<? extends AnnotationMirror> annos2)
Returns the greatest lower bound of two types.
|
Set<? extends AnnotationMirror> |
greatestLowerBoundsTypeVariable(Collection<? extends AnnotationMirror> annos1,
Collection<? extends AnnotationMirror> annos2)
Returns the type qualifiers that are the greatest lower bound of the qualifiers in annos1 and
annos2.
|
abstract AnnotationMirror |
greatestLowerBoundTypeVariable(AnnotationMirror a1,
AnnotationMirror a2)
Returns the greatest lower bound for the qualifiers a1 and a2.
|
boolean |
isSubtype(AnnotatedTypeMirror subType,
AnnotatedTypeMirror superType,
AnnotationMirror subAnno,
AnnotationMirror superAnno)
Tests whether
subAnno is a sub-qualifier of superAnno , according to the type
qualifier hierarchy. |
boolean |
isSubtype(AnnotatedTypeMirror subType,
AnnotatedTypeMirror superType,
Collection<? extends AnnotationMirror> subs,
Collection<AnnotationMirror> supers)
Tests whether there is any annotation in
supers that is a super qualifier of some
annotation in subs . |
abstract boolean |
isSubtype(AnnotationMirror rhs,
AnnotationMirror lhs)
Tests whether rhs is equal to or a sub-qualifier of lhs, according to the type qualifier
hierarchy.
|
abstract boolean |
isSubtype(Collection<? extends AnnotationMirror> rhs,
Collection<? extends AnnotationMirror> lhs)
Tests whether there is any annotation in lhs that is a super qualifier of some annotation in
rhs.
|
abstract boolean |
isSubtypeTypeVariable(AnnotationMirror subAnno,
AnnotationMirror superAnno)
Tests whether
subAnno is a sub-qualifier of superAnno , according to the type
qualifier hierarchy. |
abstract boolean |
isSubtypeTypeVariable(Collection<? extends AnnotationMirror> subAnnos,
Collection<? extends AnnotationMirror> superAnnos)
Tests whether there is any annotation in superAnnos that is a super qualifier of some
annotation in subAnnos.
|
boolean |
isValid()
Determine whether the instance is valid.
|
AnnotationMirror |
leastUpperBound(AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2,
AnnotationMirror a1,
AnnotationMirror a2)
Returns the least upper bound for the qualifiers a1 and a2.
|
abstract AnnotationMirror |
leastUpperBound(AnnotationMirror a1,
AnnotationMirror a2)
Returns the least upper bound for the qualifiers a1 and a2.
|
Set<? extends AnnotationMirror> |
leastUpperBounds(AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2,
Collection<? extends AnnotationMirror> annos1,
Collection<AnnotationMirror> annos2)
Returns the type qualifiers that are the least upper bound of the qualifiers in annos1 and
annos2.
|
Set<? extends AnnotationMirror> |
leastUpperBounds(Collection<? extends AnnotationMirror> annos1,
Collection<? extends AnnotationMirror> annos2)
Returns the least upper bound of two types.
|
Set<? extends AnnotationMirror> |
leastUpperBoundsTypeVariable(Collection<? extends AnnotationMirror> annos1,
Collection<? extends AnnotationMirror> annos2)
Returns the type qualifiers that are the least upper bound of the qualifiers in annos1 and
annos2.
|
abstract AnnotationMirror |
leastUpperBoundTypeVariable(AnnotationMirror a1,
AnnotationMirror a2)
Returns the least upper bound for the qualifiers a1 and a2.
|
int |
numberOfIterationsBeforeWidening()
Returns the number of iterations dataflow should perform before
widenedUpperBound(AnnotationMirror, AnnotationMirror) is called or -1 if it should never be
called. |
protected Collection<? extends AnnotationMirror> |
replacePolyAll(Collection<? extends AnnotationMirror> annos)
Returns a new set that is the passed set, but PolyAll has been replaced by a polymorphic
qualifiers, for hierarchies that do not have an annotation in the set.
|
<T> boolean |
updateMappingToMutableSet(Map<T,Set<AnnotationMirror>> map,
T key,
AnnotationMirror newQual)
Update a mapping from some key to a set of AnnotationMirrors.
|
AnnotationMirror |
widenedUpperBound(AnnotationMirror newQualifier,
AnnotationMirror previousQualifier)
If the type hierarchy has an infinite ascending chain, then the dataflow analysis might never
reach a fixed point.
|
public boolean isValid()
public int getWidth()
public abstract Set<? extends AnnotationMirror> getTopAnnotations()
public abstract AnnotationMirror getTopAnnotation(AnnotationMirror start)
public abstract AnnotationMirror getBottomAnnotation(AnnotationMirror start)
public abstract Set<? extends AnnotationMirror> getBottomAnnotations()
public abstract AnnotationMirror getPolymorphicAnnotation(AnnotationMirror start)
start
- any qualifier from the type hierarchypublic abstract Set<? extends AnnotationMirror> getTypeQualifiers()
public abstract boolean isSubtype(AnnotationMirror rhs, AnnotationMirror lhs)
public abstract boolean isSubtype(Collection<? extends AnnotationMirror> rhs, Collection<? extends AnnotationMirror> lhs)
public abstract AnnotationMirror leastUpperBound(AnnotationMirror a1, AnnotationMirror a2)
Examples:
public int numberOfIterationsBeforeWidening()
widenedUpperBound(AnnotationMirror, AnnotationMirror)
is called or -1 if it should never be
called.
Subclasses overriding this method should return some positive number or -1.
widenedUpperBound(AnnotationMirror, AnnotationMirror)
is called or -1 if it should
never be called.public AnnotationMirror widenedUpperBound(AnnotationMirror newQualifier, AnnotationMirror previousQualifier)
numberOfIterationsBeforeWidening()
and
change its return to a positive number.
newQualifier
is newest qualifier dataflow computed for some expression and previousQualifier
is the qualifier dataflow computed on the last iteration.
If the type hierarchy has no infinite ascending chain, returns the least upper bound of the two annotations.
newQualifier
- new qualifier dataflow computed for some expressionpreviousQualifier
- the previous qualifier dataflow computed on the last iterationpublic abstract AnnotationMirror greatestLowerBound(AnnotationMirror a1, AnnotationMirror a2)
The two qualifiers have to be from the same qualifier hierarchy. Otherwise, null will be returned.
a1
- first annotationa2
- second annotationpublic Set<? extends AnnotationMirror> leastUpperBounds(Collection<? extends AnnotationMirror> annos1, Collection<? extends AnnotationMirror> annos2)
Annos1 and annos2 must have the same size, and each annotation in them must be from a different type hierarchy.
This is necessary for determining the type of a conditional expression (?:
), where
the type of the expression is the least upper bound of the true and false clauses.
annos1
- first collection of qualifiersannos2
- second collection of qualifiersprotected Collection<? extends AnnotationMirror> replacePolyAll(Collection<? extends AnnotationMirror> annos)
annos
- set of annotationspublic Set<? extends AnnotationMirror> greatestLowerBounds(Collection<? extends AnnotationMirror> annos1, Collection<? extends AnnotationMirror> annos2)
Annos1 and annos2 must have the same size, and each annotation in them must be from a different type hierarchy.
annos1
- first collection of qualifiersannos2
- second collection of qualifierspublic abstract boolean isSubtypeTypeVariable(AnnotationMirror subAnno, AnnotationMirror superAnno)
subAnno
is a sub-qualifier of superAnno
, according to the type
qualifier hierarchy. This checks only the qualifiers, not the Java type.
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
subAnno
is a sub qualifier of superAnno
public abstract boolean isSubtypeTypeVariable(Collection<? extends AnnotationMirror> subAnnos, Collection<? extends AnnotationMirror> superAnnos)
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
public abstract AnnotationMirror leastUpperBoundTypeVariable(AnnotationMirror a1, AnnotationMirror a2)
Examples:
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
public abstract AnnotationMirror greatestLowerBoundTypeVariable(AnnotationMirror a1, AnnotationMirror a2)
The two qualifiers have to be from the same qualifier hierarchy. Otherwise, null will be returned.
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
a1
- first annotationa2
- second annotationpublic Set<? extends AnnotationMirror> leastUpperBoundsTypeVariable(Collection<? extends AnnotationMirror> annos1, Collection<? extends AnnotationMirror> annos2)
This is necessary for determining the type of a conditional expression (?:
), where
the type of the expression is the least upper bound of the true and false clauses.
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
public Set<? extends AnnotationMirror> greatestLowerBoundsTypeVariable(Collection<? extends AnnotationMirror> annos1, Collection<? extends AnnotationMirror> annos2)
The two qualifiers have to be from the same qualifier hierarchy. Otherwise, null will be returned.
This method works even if the underlying Java type is a type variable. In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful value (namely, no annotation).
annos1
- first collection of qualifiersannos2
- second collection of qualifierspublic static boolean canHaveEmptyAnnotationSet(AnnotatedTypeMirror type)
public boolean isSubtype(AnnotatedTypeMirror subType, AnnotatedTypeMirror superType, AnnotationMirror subAnno, AnnotationMirror superAnno)
subAnno
is a sub-qualifier of superAnno
, according to the type
qualifier hierarchy. This checks only the qualifiers, not the Java type.
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
subAnno
is a sub qualifier of superAnno
public boolean isSubtype(AnnotatedTypeMirror subType, AnnotatedTypeMirror superType, Collection<? extends AnnotationMirror> subs, Collection<AnnotationMirror> supers)
supers
that is a super qualifier of some
annotation in subs
. supers
and subs
contain only the annotations, not
the Java type.
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
supers
is a super of one in subs
public AnnotationMirror leastUpperBound(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror a1, AnnotationMirror a2)
Examples:
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
public AnnotationMirror greatestLowerBound(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror a1, AnnotationMirror a2)
The two qualifiers have to be from the same qualifier hierarchy. Otherwise, null will be returned.
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
a1
- first annotationa2
- second annotationpublic Set<? extends AnnotationMirror> leastUpperBounds(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, Collection<? extends AnnotationMirror> annos1, Collection<AnnotationMirror> annos2)
This is necessary for determining the type of a conditional expression (?:
), where
the type of the expression is the least upper bound of the true and false clauses.
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
public Set<? extends AnnotationMirror> greatestLowerBounds(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, Collection<? extends AnnotationMirror> annos1, Collection<AnnotationMirror> annos2)
The two qualifiers have to be from the same qualifier hierarchy. Otherwise, null will be returned.
This method takes an annotated type to decide if the type variable version of the method should be invoked, or if the normal version is sufficient (which provides more strict checks).
annos1
- first collection of qualifiersannos2
- second collection of qualifierspublic AnnotationMirror findAnnotationInSameHierarchy(Collection<? extends AnnotationMirror> annos, AnnotationMirror annotationMirror)
If the annotation in the hierarchy is PolyAll, then the polymorphic qualifier in the hierarchy is returned instead of PolyAll.
annos
- set of annotations to searchannotationMirror
- annotation that is in the same hierarchy as the returned annotationpublic AnnotationMirror findAnnotationInHierarchy(Collection<? extends AnnotationMirror> annos, AnnotationMirror top)
If the annotation in the hierarchy is PolyAll, then the polymorphic qualifier in the hierarchy is returned instead of PolyAll.
annos
- set of annotations to searchtop
- the top annotation in the hierarchy to which the returned annotation belongspublic <T> boolean updateMappingToMutableSet(Map<T,Set<AnnotationMirror>> map, T key, AnnotationMirror newQual)
map
- the mapping to modifykey
- the key to updatenewQual
- the value to add