checkers.types
Class TypeHierarchy

java.lang.Object
  extended by checkers.types.TypeHierarchy

public class TypeHierarchy
extends Object

Class to test 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:

  1. A <: B iff |A| <: |B| && qual(A) <: qual(B)
  2. A[] <: B[] iff A <: B and qual(A[]) <: qual(B[])
  3. A<A1, ..., An> <: B<B1, ..., Bn> if A <: B && A1 = B1 && ... && An = Bn
Subclasses may override this behavior.

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.


Constructor Summary
TypeHierarchy(QualifierHierarchy qualifierHierarchy)
          Constructs an instance of TypeHierarchy for the type system whose qualifiers represented in qualifierHierarchy.
 
Method Summary
 boolean isSubtype(AnnotatedTypeMirror rhs, AnnotatedTypeMirror lhs)
          Entry point for subtype checking: Checks whether rhs is a subtype of lhs.
protected  boolean isSubtypeAsArrayComponent(AnnotatedTypeMirror rhs, AnnotatedTypeMirror lhs)
          Checks that rhs is a subtype of lhs, as an array component type.
protected  boolean isSubtypeAsTypeArgument(AnnotatedTypeMirror rhs, AnnotatedTypeMirror lhs)
          Checks that rhs is a subtype of lhs, as actual type arguments.
protected  boolean isSubtypeTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs, AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
          Checks that rhs and lhs are subtypes with respect to type arguments only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeHierarchy

public TypeHierarchy(QualifierHierarchy qualifierHierarchy)
Constructs an instance of TypeHierarchy for the type system whose qualifiers represented in qualifierHierarchy.

Parameters:
qualifierHierarchy -
Method Detail

isSubtype

public final boolean isSubtype(AnnotatedTypeMirror rhs,
                               AnnotatedTypeMirror lhs)
Entry point for subtype checking: Checks whether rhs is a subtype of lhs.

Returns:
a true iff rhs a subtype of lhs

isSubtypeTypeArguments

protected boolean isSubtypeTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs,
                                         AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
Checks that rhs and lhs are subtypes with respect to type arguments only. Returns true if any of the provided types is not a parameterized type. A parameterized type, rhs, is a subtype of another, lhs, only if their actual type parameters are invariant.

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.

Returns:
true iff the type arguments of lhs and rhs are invariant.

isSubtypeAsTypeArgument

protected boolean isSubtypeAsTypeArgument(AnnotatedTypeMirror rhs,
                                          AnnotatedTypeMirror lhs)
Checks that rhs is a subtype of lhs, as actual type arguments. In JLS terms, rhs needs to be invariant of lhs.

Returns:
true if the types have the same annotations

isSubtypeAsArrayComponent

protected boolean isSubtypeAsArrayComponent(AnnotatedTypeMirror rhs,
                                            AnnotatedTypeMirror lhs)
Checks that rhs is a subtype of lhs, as an array component type. (Unfortunately) Java specifies array components are co-variant while maintaining subtype relations.

This property of arrays makes the code unsafe at run-time. Subclasses may override this method to enforce a stricter relationship.

Returns:
true iff rhs is a subtype of lhs