public class TypeHierarchy extends @NonNull Object
AnnotatedTypeMirror
subtype relationships.
This implementation uses the regular Java subtyping rules.
More specifically, let
<: be the subtyping relationship,
qual(A) = qualifier on A
, and
|A| = type without qualifier
:
Note that the array subtyping rules depends on a runtime check to guarantee the soundness of the type system. It is unsafe for static check purposes.
Modifier and Type | Field and Description |
---|---|
protected BaseTypeChecker |
checker
The type checker to use.
|
protected Set<@Nullable Element> |
visited
Prevent infinite loops in cases of recursive type bound
|
Constructor and Description |
---|
TypeHierarchy(BaseTypeChecker checker,
QualifierHierarchy qualifierHierarchy)
Constructs an instance of
TypeHierarchy for the type system
whose qualifiers represented in qualifierHierarchy. |
Modifier and Type | Method and Description |
---|---|
protected @Mutable AnnotatedTypeMirror |
handlePolyAll(@Mutable AnnotatedTypeMirror in)
Replace @PolyAll qualifiers by @PolyXXX qualifiers for each type
system, for which no concrete qualifier is given.
|
boolean |
isSubtype(@Mutable AnnotatedTypeMirror rhs,
@Mutable AnnotatedTypeMirror lhs)
Entry point for subtype checking:
Checks whether rhs is a subtype of lhs.
|
protected boolean |
isSubtypeAsArrayComponent(@Mutable AnnotatedTypeMirror rhs,
@Mutable AnnotatedTypeMirror lhs)
Checks that rhs is a subtype of lhs, as an array component type.
|
protected boolean |
isSubtypeAsTypeArgument(@Mutable AnnotatedTypeMirror rhs,
@Mutable AnnotatedTypeMirror lhs)
Checks that rhs is a subtype of lhs, as actual type arguments.
|
protected boolean |
isSubtypeImpl(@Mutable AnnotatedTypeMirror rhs,
@Mutable AnnotatedTypeMirror lhs)
Checks if the rhs is a subtype of the lhs.
|
protected boolean |
isSubtypeTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs,
AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
Checks that rhs and lhs are subtypes with respect to type arguments only.
|
protected final Set<@Nullable Element> visited
protected final BaseTypeChecker checker
public TypeHierarchy(BaseTypeChecker checker, QualifierHierarchy qualifierHierarchy)
TypeHierarchy
for the type system
whose qualifiers represented in qualifierHierarchy.checker
- The type checker to usequalifierHierarchy
- The qualifier hierarchy to usepublic boolean isSubtype(@Mutable AnnotatedTypeMirror rhs, @Mutable AnnotatedTypeMirror lhs)
protected @Mutable AnnotatedTypeMirror handlePolyAll(@Mutable AnnotatedTypeMirror in)
protected final boolean isSubtypeImpl(@Mutable AnnotatedTypeMirror rhs, @Mutable AnnotatedTypeMirror lhs)
protected boolean isSubtypeTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs, AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
As an implementation detail, this method uses
isSubtypeAsTypeArgument(AnnotatedTypeMirror, AnnotatedTypeMirror)
to compare each type argument individually. Subclasses may override
either methods to allow type argument to change covariantly.
protected boolean isSubtypeAsTypeArgument(@Mutable AnnotatedTypeMirror rhs, @Mutable AnnotatedTypeMirror lhs)
protected boolean isSubtypeAsArrayComponent(@Mutable AnnotatedTypeMirror rhs, @Mutable AnnotatedTypeMirror lhs)
This property of arrays makes the code unsafe at run-time. Subclasses may override this method to enforce a stricter relationship.