Class VariableBounds
java.lang.Object
org.checkerframework.framework.util.typeinference8.types.VariableBounds
Data structure to stores the bounds of a variable.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionBounds on this variable.final ConstraintSet
Constraints implied by complementary pairs of bounds found during incorporation.boolean
Whether this variable has a throws bounds.Qualifier bounds on this variable.Saved bounds used in the event the first attempt at resolution fails.Saved qualifier bounds used in the event the first attempt at resolution fails. -
Constructor Summary
ConstructorDescriptionVariableBounds
(Variable variable, Java8InferenceContext context) Creates bounds forvariable
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addBound
(VariableBounds.BoundKind kind, AbstractType otherType) AddsotherType
as bound against this variable.void
addConstraintsFromComplementaryBounds
(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> s) Adds constraints from complementary bounds.void
Add constraints created via incorporation of the bound.void
addConstraintsFromComplementaryQualifierBounds
(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers) Add constraints created via incorporation of the bound.void
addQualifierBound
(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers) Addsqualifiers
as a qualifier bound against this variable.boolean
Apply instantiations to all bounds and constraints of this variable.Return all lower bounds that are proper types.Returns all upper bounds that proper types.Returns the instantiation of this variable.Collection<? extends Variable>
Return all variables mentioned in a bound against this variable.Returns the constraints generated when incorporating a capture bound.boolean
Return true if this has an instantiation.boolean
Does this bound set contain two bounds of the formsS1 <: var
andS2 <: var
, where S1 and S2 have supertypes that are two different parameterizations of the same generic class or interface?boolean
Returns true if any bound mentions a primitive wrapper type.boolean
Returns true if there exists an equal or lower bound against a type, S, such that S is not a subtype ofG<...>
, but S is a subtype of the raw type|G<...>|
, whereG
a generic class or interface for which the parameter of this method,t
, is a parameterization.boolean
Return true if this has a throws bound.boolean
Returns true if any lower or equal bound is a parameterized type with at least one wildcard as a type argument.boolean
Returns whether this variable only has bounds against proper types.void
restore()
Restore the bounds to the state previously saved.void
save()
Save the current bounds in case the first attempt at resolution fails.void
setHasThrowsBound
(boolean b) Set has throws boundReturns all upper bounds.
-
Field Details
-
bounds
Bounds on this variable. Stored as a map from kind of bound (upper, lower, equal) to a set ofAbstractType
s. -
qualifierBounds
Qualifier bounds on this variable. Stored as a map from kind of bound (upper, lower, equal) to a set ofAnnotationMirror
s. A qualifier bound is a bound on the primary annotation of this variable. -
constraints
Constraints implied by complementary pairs of bounds found during incorporation. -
hasThrowsBound
public boolean hasThrowsBoundWhether this variable has a throws bounds. -
savedBounds
Saved bounds used in the event the first attempt at resolution fails. -
savedQualifierBounds
Saved qualifier bounds used in the event the first attempt at resolution fails.
-
-
Constructor Details
-
VariableBounds
Creates bounds forvariable
.- Parameters:
variable
- a variablecontext
- the context
-
-
Method Details
-
save
public void save()Save the current bounds in case the first attempt at resolution fails. -
restore
public void restore()Restore the bounds to the state previously saved. This method is called if the first attempt at resolution fails. -
hasThrowsBound
public boolean hasThrowsBound()Return true if this has a throws bound.- Returns:
- true if this has a throws bound
-
setHasThrowsBound
public void setHasThrowsBound(boolean b) Set has throws bound- Parameters:
b
- has thrown bound
-
addBound
AddsotherType
as bound against this variable.- Parameters:
kind
- the kind of boundotherType
- the bound type- Returns:
- if a new bound was added
-
addQualifierBound
public void addQualifierBound(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers) Addsqualifiers
as a qualifier bound against this variable.- Parameters:
kind
- the kind of boundqualifiers
- the qualifiers
-
addConstraintsFromComplementaryQualifierBounds
public void addConstraintsFromComplementaryQualifierBounds(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> qualifiers) Add constraints created via incorporation of the bound. See JLS 18.3.1.- Parameters:
kind
- the kind of boundqualifiers
- the qualifiers
-
addConstraintsFromComplementaryBounds
Add constraints created via incorporation of the bound. See JLS 18.3.1.- Parameters:
kind
- the kind of bounds
- the type of the bound
-
addConstraintsFromComplementaryBounds
public void addConstraintsFromComplementaryBounds(VariableBounds.BoundKind kind, Set<? extends AbstractQualifier> s) Adds constraints from complementary bounds.- Parameters:
kind
- kind of bounds
- qualifiers
-
onlyProperBounds
public boolean onlyProperBounds()Returns whether this variable only has bounds against proper types.- Returns:
- whether this variable only has bounds against proper types.
-
findProperLowerBounds
Return all lower bounds that are proper types.- Returns:
- all lower bounds that are proper types
-
findProperUpperBounds
Returns all upper bounds that proper types.- Returns:
- all upper bounds that are proper types
-
upperBounds
Returns all upper bounds.- Returns:
- all upper bounds
-
applyInstantiationsToBounds
public boolean applyInstantiationsToBounds()Apply instantiations to all bounds and constraints of this variable.- Returns:
- whether any of the bounds changed
-
getVariablesMentionedInBounds
Return all variables mentioned in a bound against this variable.- Returns:
- all variables mentioned in a bound against this variable
-
getInstantiation
Returns the instantiation of this variable.- Returns:
- the instantiation of this variable
-
hasInstantiation
public boolean hasInstantiation()Return true if this has an instantiation.- Returns:
- true if this has an instantiation
-
hasPrimitiveWrapperBound
public boolean hasPrimitiveWrapperBound()Returns true if any bound mentions a primitive wrapper type.- Returns:
- true if any bound mentions a primitive wrapper type
-
hasWildcardParameterizedLowerOrEqualBound
public boolean hasWildcardParameterizedLowerOrEqualBound()Returns true if any lower or equal bound is a parameterized type with at least one wildcard as a type argument.- Returns:
- true if any lower or equal bound is a parameterized type with at least one wildcard for a type argument
-
hasLowerBoundDifferentParam
public boolean hasLowerBoundDifferentParam()Does this bound set contain two bounds of the formsS1 <: var
andS2 <: var
, where S1 and S2 have supertypes that are two different parameterizations of the same generic class or interface?- Returns:
- whether this bound set contain two bounds of the forms
S1 <: var
andS2 <: var
, where S1 and S2 have supertypes that are two different parameterizations of the same generic class or interface
-
hasRawTypeLowerOrEqualBound
Returns true if there exists an equal or lower bound against a type, S, such that S is not a subtype ofG<...>
, but S is a subtype of the raw type|G<...>|
, whereG
a generic class or interface for which the parameter of this method,t
, is a parameterization.- Parameters:
t
- a parameterization of a generic class or interface,G
- Returns:
- true if there exists an equal or lower bound against a type, S, such that S is not a
subtype of
G<...>
, but S is a subtype of the raw type|G<...>|
, whereG
a generic class or interface for which the parameter of this method,t
, is a parameterization.
-
getWildcardConstraints
Returns the constraints generated when incorporating a capture bound. See JLS 18.3.2.- Parameters:
Ai
- the captured type argumentBi
- the bound of the type variable- Returns:
- constraints generated when incorporating a capture bound
-