Interface TypeHierarchy
- All Known Implementing Classes:
DefaultTypeHierarchy
,KeyForAnnotatedTypeFactory.KeyForTypeHierarchy
public interface TypeHierarchy
Compares AnnotatedTypeMirrors for subtype relationships. See also
QualifierHierarchy
.-
Method Summary
Modifier and TypeMethodDescriptionboolean
isSubtype
(AnnotatedTypeMirror subtype, AnnotatedTypeMirror supertype) Returns true ifsubtype
is a subtype of or convertible tosupertype
for all hierarchies present.
-
Method Details
-
isSubtype
Returns true ifsubtype
is a subtype of or convertible tosupertype
for all hierarchies present. If the underlying Java type ofsubtype
is not a subtype of or convertible to the underlying Java type ofsupertype
, then the behavior of this method is undefined.Ideally, types that require conversions would be converted before isSubtype is called, but instead, isSubtype performs some of these conversions.
JLS 5.1 specifies 13 categories of conversions.
3 categories are converted in isSubtype:
- Boxing conversions: isSubtype calls
AnnotatedTypes.asSuper(AnnotatedTypeFactory, AnnotatedTypeMirror, AnnotatedTypeMirror)
which callsAnnotatedTypeFactory.getBoxedType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)
- Unboxing conversions: isSubtype calls
AnnotatedTypes.asSuper(AnnotatedTypeFactory, AnnotatedTypeMirror, AnnotatedTypeMirror)
which callsAnnotatedTypeFactory.getUnboxedType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)
- String conversions: Any type to String. isSubtype calls
AnnotatedTypes.asSuper(org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.type.AnnotatedTypeMirror, T)
which callsAnnotatedTypeFactory.getStringType(AnnotatedTypeMirror)
- Unchecked conversions: Generic type to raw type. Raw types are instantiated with bounds in AnnotatedTypeFactory#fromTypeTree before is subtype is called
- Capture conversions: Wildcards are captured in
AnnotatedTypeFactory.applyCaptureConversion(AnnotatedTypeMirror)
- Identity conversions: type to same type
- Widening primitive conversions: primitive to primitive (no loss of information, byte to short for example)
- Narrowing primitive conversions: primitive to primitive (possibly loss of information, short to byte for example)
- Widening and Narrowing Primitive Conversion: byte to char
- Widening reference conversions: Upcast
- Narrowing reference conversions: Downcast
- Value set conversions: floating-point value from one value set to another without changing its type.
- Parameters:
subtype
- possible subtypesupertype
- possible supertype- Returns:
- true if
subtype
is a subtype ofsupertype
for all hierarchies present
- Boxing conversions: isSubtype calls
-