checkers.types
Class TypeHierarchy

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

public class TypeHierarchy
extends Object

Class to test AnnotatedTypeMirrors subtype relationships. The implementation uses the regular traditional java subtyping rules namely, assuming qual(A) := qualifier on A and |A| = type without qualifier:

Subclasses may need to override the methods as specified below, to override this behavior. Please 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
protected  boolean compareArrayComponent(AnnotatedTypeMirror.AnnotatedArrayType rhs, AnnotatedTypeMirror.AnnotatedArrayType lhs)
          Checks that the rhs component type is a subtype of the lhs component type.
protected  boolean compareTypeArg(AnnotatedTypeMirror rhs, AnnotatedTypeMirror lhs)
          Compares two types that are are found within type arguments.
protected  boolean compareTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs, AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
          Only compares the type arguments of rhs and lhs.
 boolean isSubtype(AnnotatedTypeMirror rhs, AnnotatedTypeMirror lhs)
          Checks whether rhs is a subtype of lhs
 
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

compareTypeArg

protected boolean compareTypeArg(AnnotatedTypeMirror rhs,
                                 AnnotatedTypeMirror lhs)
Compares two types that are are found within type arguments. JLS species that for generic types subtype relations, their type arguments need to be equivalent. This method checks that the types, lhs and rhs, are similar, and have the same annotations found in the current type hierarchy. Subclasses may override this behavior to implement special semantics.

Parameters:
rhs - a type argument
lhs - a type argument
Returns:
true if the types have the same annotations

compareTypeArguments

protected boolean compareTypeArguments(AnnotatedTypeMirror.AnnotatedDeclaredType rhs,
                                       AnnotatedTypeMirror.AnnotatedDeclaredType lhs)
Only compares the type arguments of rhs and lhs. It returns true if any of them is not a generic type (e.g. one is erased or not a generic class). JLS specifies that X is a subtype of Y only if A_1 = B_1, ...., A_n = B_n. Subclasses my override this method to override this behavior. As an implementation details, the method uses compareTypeArg to compare each type argument individually.

Parameters:
rhs - a declared type
lhs - a declared type
Returns:
true iff the type arguments of lhs and rhs are similar.

compareArrayComponent

protected boolean compareArrayComponent(AnnotatedTypeMirror.AnnotatedArrayType rhs,
                                        AnnotatedTypeMirror.AnnotatedArrayType lhs)
Checks that the rhs component type is a subtype of the lhs component type. Java specifies that A[] <: B[] if and only if A <: B. However, given this property makes the code unsafe at run-time, subclasses may override this method to override this behavior.

Parameters:
rhs - an array type: right side of an assignment
lhs - an array type: left side of an assignment
Returns:
true iff rhs component type is a subtype of the lhs component type

isSubtype

public final boolean isSubtype(AnnotatedTypeMirror rhs,
                               AnnotatedTypeMirror lhs)
Checks whether rhs is a subtype of lhs

Parameters:
rhs - an annotated type
lhs - an annotated type
Returns:
a true iff rhs a subtype of lhs