All Downloads are FREE. Search and download functionalities are using the official Maven repository.

framework.src.org.checkerframework.framework.type.TypeHierarchy Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0
Show newest version
package org.checkerframework.framework.type;

import org.checkerframework.framework.util.AnnotatedTypes;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.util.Types;

/**
 * Compares AnnotatedTypeMirrors for subtype relationships.
 * See also QualifierHierarchy
 */
public interface TypeHierarchy {

    /**
     * Returns true if {@code subtype} is a subtype of or convertible to {@code supertype}
     * for all hierarchies present.  If the underlying Java type of {@code subtype} is not a subtype of
     * or convertible to the underlying Java type of {@code supertype}, 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. *

* 4 categories are converted in isSubtype: * *

    *
  • Boxing conversions: isSubtype calls {@link AnnotatedTypes#asSuper(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, AnnotatedTypeMirror)} * which calls {@link AnnotatedTypeFactory#getBoxedType} *
  • Unboxing conversions: isSubtype calls {@link AnnotatedTypes#asSuper(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, AnnotatedTypeMirror)} * which calls {@link AnnotatedTypeFactory#getUnboxedType} *
  • Capture conversions: Wildcards are treated as though they were converted to type variables *
  • String conversions: Any type to String. Special case in {@link DefaultTypeHierarchy#visitDeclared_Declared}. *
* * 1 happens elsewhere: *
    *
  • Unchecked conversions: Generic type to raw type. Raw types are instantiated with bounds in * AnnotatedTypeFactory#fromTypeTree before is subtype is called *
* * 7 are not explicitly converted and are treated as though the types are actually subtypes. *
    *
  • 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 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. *
* * @param subtype possible subtype * @param supertype possible supertype * @return true if {@code subtype} is a subtype of {@code supertype} for all hierarchies present. */ boolean isSubtype(AnnotatedTypeMirror subtype, AnnotatedTypeMirror supertype); /** * The same as {@link #isSubtype(AnnotatedTypeMirror, AnnotatedTypeMirror)}, but only for the hierarchy of which * {@code top} is the top. * * @param subtype possible subtype * @param supertype possible supertype * @param top the qualifier at the top of the hierarchy for which the subtype check should be preformed. * @return Returns true if {@code subtype} is a subtype of {@code supertype} in the qualifier hierarchy * whose top is {@code top} */ boolean isSubtype(AnnotatedTypeMirror subtype, AnnotatedTypeMirror supertype, AnnotationMirror top); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy