Class CFAbstractValue<V extends CFAbstractValue<V>>
- java.lang.Object
-
- org.checkerframework.framework.flow.CFAbstractValue<V>
-
- Type Parameters:
V- the values that this CFAbstractValue wraps
- All Implemented Interfaces:
AbstractValue<V>
- Direct Known Subclasses:
AccumulationValue,CFValue,KeyForValue,NullnessNoInitValue
public abstract class CFAbstractValue<V extends CFAbstractValue<V>> extends java.lang.Object implements AbstractValue<V>
An implementation of an abstract value used by the Checker Framework org.checkerframework.dataflow analysis.A value holds a set of annotations and a type mirror. The set of annotations represents the primary annotation on a type; therefore, the set of annotations must have an annotation for each hierarchy unless the type mirror is a type variable or a wildcard that extends a type variable. Both type variables and wildcards may be missing a primary annotation. For this set of annotations, there is an additional constraint that only wildcards that extend type variables can be missing annotations.
In order to compute
leastUpperBound(CFAbstractValue)andmostSpecific(CFAbstractValue, CFAbstractValue), the case where one value has an annotation in a hierarchy and the other does not must be handled. For type variables, theAnnotatedTypeMirror.AnnotatedTypeVariablefor the declaration of the type variable is used. TheAnnotatedTypeMirror.AnnotatedTypeVariableis computed using the type mirror. For wildcards, it is not always possible to get theAnnotatedTypeMirror.AnnotatedWildcardTypefor the type mirror. However, a CFAbstractValue's type mirror is only a wildcard if the type of some expression is a wildcard. The type of an expression is only a wildcard because the Checker Framework does not implement capture conversion. For these uses of uncaptured wildcards, only the primary annotation on the upper bound is ever used. So, the set of annotations represents the primary annotation on the wildcard's upper bound. If that upper bound is a type variable, then the set of annotations could be missing an annotation in a hierarchy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classCFAbstractValue.AnnotationSetCombinerCombines two sets of AnnotationMirrors by hierarchy.protected classCFAbstractValue.ValueGlbComputes the GLB of two sets of annotations.protected classCFAbstractValue.ValueLubComputes the least upper bound or, ifshouldWidenis true, an upper bounds of two sets of annotations.
-
Field Summary
Fields Modifier and Type Field Description protected CFAbstractAnalysis<V,?,?>analysisThe analysis class this value belongs to.protected AnnotationMirrorSetannotationsThe annotations in this abstract value.protected javax.lang.model.type.TypeMirrorunderlyingTypeThe underlying (Java) type in this abstract value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCFAbstractValue(CFAbstractAnalysis<V,?,?> analysis, AnnotationMirrorSet annotations, javax.lang.model.type.TypeMirror underlyingType)Creates a new CFAbstractValue.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanBeMissingAnnotations()Returns whether or not the set of annotations can be missing an annotation for any hierarchy.booleanequals(@Nullable java.lang.Object obj)AnnotationMirrorSetgetAnnotations()Returns a set of annotations.javax.lang.model.type.TypeMirrorgetUnderlyingType()VgreatestLowerBound(@Nullable V other)Compute the greatest lower bound of two values.inthashCode()VleastUpperBound(@Nullable V other)Compute the least upper bound of two values.VmostSpecific(@Nullable V other, @Nullable V backup)Returns the more specific of two valuesthisandother.java.lang.StringtoString()Returns the string representation.java.lang.StringtoStringFullyQualified()Returns the string representation, using fully-qualified names.java.lang.StringtoStringSimple()Returns the string representation, using simple (not fully-qualified) names.static booleanvalidateSet(AnnotationMirrorSet annos, javax.lang.model.type.TypeMirror typeMirror, AnnotatedTypeFactory atypeFactory)Returns true if the set has an annotation from every hierarchy (or if it doesn't need to); returns false if the set is missing an annotation from some hierarchy.VwidenUpperBound(@Nullable V previous)Compute an upper bound of two values that is wider than the least upper bound of the two values.
-
-
-
Field Detail
-
analysis
protected final CFAbstractAnalysis<V extends CFAbstractValue<V>,?,?> analysis
The analysis class this value belongs to.
-
underlyingType
protected final javax.lang.model.type.TypeMirror underlyingType
The underlying (Java) type in this abstract value.
-
annotations
protected final AnnotationMirrorSet annotations
The annotations in this abstract value.
-
-
Constructor Detail
-
CFAbstractValue
protected CFAbstractValue(CFAbstractAnalysis<V,?,?> analysis, AnnotationMirrorSet annotations, javax.lang.model.type.TypeMirror underlyingType)
Creates a new CFAbstractValue.- Parameters:
analysis- the analysis class this value belongs toannotations- the annotations in this abstract valueunderlyingType- the underlying (Java) type in this abstract value
-
-
Method Detail
-
validateSet
public static boolean validateSet(AnnotationMirrorSet annos, javax.lang.model.type.TypeMirror typeMirror, AnnotatedTypeFactory atypeFactory)
Returns true if the set has an annotation from every hierarchy (or if it doesn't need to); returns false if the set is missing an annotation from some hierarchy.- Parameters:
annos- set of annotationstypeMirror- where the annotations are writtenatypeFactory- the type factory- Returns:
- true if no annotations are missing
-
canBeMissingAnnotations
public boolean canBeMissingAnnotations()
Returns whether or not the set of annotations can be missing an annotation for any hierarchy.- Returns:
- whether or not the set of annotations can be missing an annotation
-
getAnnotations
@Pure public AnnotationMirrorSet getAnnotations()
Returns a set of annotations. IfcanBeMissingAnnotations()returns true, then the set of annotations may not have an annotation for every hierarchy.To get the single annotation in a particular hierarchy, use
QualifierHierarchy.findAnnotationInHierarchy(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, javax.lang.model.element.AnnotationMirror).- Returns:
- a set of annotations
-
getUnderlyingType
@Pure public javax.lang.model.type.TypeMirror getUnderlyingType()
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
@Pure public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toStringFullyQualified
@SideEffectFree public java.lang.String toStringFullyQualified()
Returns the string representation, using fully-qualified names.- Returns:
- the string representation, using fully-qualified names
-
toStringSimple
@SideEffectFree public java.lang.String toStringSimple()
Returns the string representation, using simple (not fully-qualified) names.- Returns:
- the string representation, using simple (not fully-qualified) names
-
toString
@SideEffectFree public java.lang.String toString()
Returns the string representation.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation
-
mostSpecific
public V mostSpecific(@Nullable V other, @Nullable V backup)
Returns the more specific of two valuesthisandother. If they do not contain information for all hierarchies, then it is possible that information from boththisandotherare taken.If neither of the two is more specific for one of the hierarchies (i.e., if the two are incomparable as determined by
QualifierHierarchy.isSubtypeShallow(AnnotationMirror, TypeMirror, AnnotationMirror, TypeMirror), then the respective value frombackupis used.- Parameters:
other- the other value to obtain information frombackup- the value to use ifthisandotherare incomparable- Returns:
- the more specific of two values
thisandother
-
leastUpperBound
public V leastUpperBound(@Nullable V other)
Description copied from interface:AbstractValueCompute the least upper bound of two values.Important: This method must fulfill the following contract:
- Does not change
this. - Does not change
other. - Returns a fresh object which is not aliased yet.
- Returns an object of the same (dynamic) type as
this, even if the signature is more permissive. - Is commutative.
- Specified by:
leastUpperBoundin interfaceAbstractValue<V extends CFAbstractValue<V>>
- Does not change
-
widenUpperBound
public V widenUpperBound(@Nullable V previous)
Compute an upper bound of two values that is wider than the least upper bound of the two values. Used to jump to a higher abstraction to allow faster termination of the fixed point computations inAnalysis.A particular analysis might not require widening and should implement this method by calling leastUpperBound.
Important: This method must fulfill the following contract:
- Does not change
this. - Does not change
previous. - Returns a fresh object which is not aliased yet.
- Returns an object of the same (dynamic) type as
this, even if the signature is more permissive. - Is commutative.
- Parameters:
previous- must be the previous value- Returns:
- an upper bound of two values that is wider than the least upper bound of the two values
- Does not change
-
greatestLowerBound
public V greatestLowerBound(@Nullable V other)
Compute the greatest lower bound of two values.Important: This method must fulfill the following contract:
- Does not change
this. - Does not change
other. - Returns a fresh object which is not aliased yet.
- Returns an object of the same (dynamic) type as
this, even if the signature is more permissive. - Is commutative.
- Parameters:
other- another value- Returns:
- the greatest lower bound of two values
- Does not change
-
-