Interface JTypeMirror

    • Method Detail

      • getTypeSystem

        TypeSystem getTypeSystem()
        Returns the type system that built this type.
      • getTypeAnnotations

        org.pcollections.PSet<SymbolicValue.SymAnnot> getTypeAnnotations()
        Return a list of annotations on this type. Annotations can be written on nearly any type (eg @A Out.@B In<@C T>, @A ? extends @B Up).

        For JTypeVar, this includes both the annotations defined on the type var and those defined at use site. For instance

            <@A T> void accept(@B T t);
        The T type var will have annotation @A in the symbol (AnnotableSymbol.getDeclaredAnnotations()) and in the type var that is in the JMethodSig.getTypeParameters(). In the formal parameter, the type var will have annotations @B @A.
      • isSubtypeOf

        default boolean isSubtypeOf​(@NonNull JTypeMirror other)
        Returns true if this type is the same type or a subtype of the given type. Note that for convenience, this returns true if both types are primitive, and this type is convertible to the other through primitive widening. See TypeOps.Convertibility.bySubtyping().
        NullPointerException - If the argument is null
      • getSuperTypeSet

        default Set<JTypeMirror> getSuperTypeSet()
        Returns the set of (nominal) supertypes of this type. If this is a primitive type, returns the set of other primitives to which this type is convertible by widening conversion (eg for long returns {long, float, double}).

        The returned set always contains this type, so is never empty. Ordering is stable, though unspecified.

        Note that this set contains TypeSystem.OBJECT for interfaces too.

        Note that for types having type annotations, the supertypes do not bear the same annotations. Eg the supertypes of @A String contain Object but not @A Object. The supertypes may be annotated though, eg if a class declares extends @A Foo, the supertypes contain @A Foo.

        UnsupportedOperationException - If this is the null type
      • getErasure

        default JTypeMirror getErasure()
        Returns the erasure of this type. Erasure is defined by JLS§4.6, an adapted definition follows:
        1. The erasure of a parameterized type (§4.5) G<T1,...,Tn> is |G|.
        2. The erasure of a nested type T.C is |T|.C.
        3. The erasure of an array type T[] is |T|[].
        4. The erasure of a type variable (§4.4) is the erasure of its upper bound.
        5. The erasure of an intersection type is the erasure of its leftmost component.
        6. The erasure of every other type is the type itself.

        The JVM representation of a type is in general the symbol of its erasure. So to get a Class instance for the runtime representation of a type, you should do t.getErasure().getSymbol(). The erasure procedure gets rid of types that have no symbol (except if t is a wildcard type, or the TypeSystem.NULL_TYPE)

      • box

        default JTypeMirror box()
        Returns the primitive wrapper type of this type, if this is a primitive type. Otherwise returns this type unchanged.
      • unbox

        default JTypeMirror unbox()
        Returns the unboxed version of this type. Returns this type unchanged if this is not a primitive wrapper type.
      • getAsSuper

        default @Nullable JTypeMirror getAsSuper​(@NonNull JClassSymbol symbol)
        Returns the most specific declared supertype of this type whose erasure is the same as that of the parameter. E.g. for Enum<E>, Comparable, returns Comparable<E>.

        Returns null if that can't be found, meaning that the given type is not a supertype of this type.

      • isReifiable

        default boolean isReifiable()
        Returns true if this type is reifiable. If so, its symbol will not be null (the reverse is not necessarily true).

        Reifiable types are those types that are completely available at run time. See also JLS§4.7

      • isPrimitive

        default boolean isPrimitive()
        Returns true if this type is a primitive type.
      • isPrimitive

        default boolean isPrimitive​(JPrimitiveType.PrimitiveTypeKind kind)
        Returns true if this type is the primitive type of the given kind in its type system.
      • isFloatingPoint

        default boolean isFloatingPoint()
        Returns true if this type is a primitive type of a floating point type.
      • isIntegral

        default boolean isIntegral()
        Returns true if this type is a primitive type of an integral type.
      • isTypeVariable

        default boolean isTypeVariable()
        Returns true if this type is a type variable.
      • isBoxedPrimitive

        default boolean isBoxedPrimitive()
        Returns true if this type is a boxed primitive type. This is a JClassType, whose unbox() method returns a JPrimitiveType.
      • isNumeric

        default boolean isNumeric()
        Returns true if this is a primitive numeric type. The only non-numeric primitive type is TypeSystem.BOOLEAN.
      • isArray

        default boolean isArray()
        Returns true if this is an array type.
      • isGeneric

        default boolean isGeneric()
        Returns true if this type is a generic class type. This means, the symbol declares some type parameters, which is also true for erased types, including raw types.

        For example, List, List<T>, and List<String> are generic, but String is not.

        See Also:
      • isParameterizedType

        default boolean isParameterizedType()
        Returns true if this type is generic, and it it neither raw, nor a generic type declaration.

        E.g. returns true for List<String> or Enum<KeyCode>, but not for List (raw type), List<T> (generic type declaration), or KeyCode (not a generic type).

      • isRaw

        default boolean isRaw()
        Returns true if this is a raw type. This may be
        • A generic class or interface type for which no type arguments were provided
        • An array type whose element type is raw
        • A non-static member type of a raw type

        See Also:
      • isInterface

        default boolean isInterface()
        Returns true if this is an interface type. Annotations are also interface types.
      • streamMethods

        default Stream<JMethodSig> streamMethods​(Predicate<? super JMethodSymbol> prefilter)
        Returns a stream of method signatures declared in and inherited by this type. Method signatures are created on-demand by this method, they're not reused between calls. This stream does not include constructors.

        Note: streams are a bit impractical when it comes to configuring the filter. Possibly a specialized API should be introduced. We need to support the use cases of the symbol table, ie filter by name + accessibility + staticity, and also possibly use cases for rules, like getting a method from a known signature. See also JClassType.getDeclaredMethod(JExecutableSymbol), which looks like this. Unifying this API would be nice.

        prefilter - Filter selecting symbols for which a signature should be created and yielded by the stream
      • getConstructors

        default List<JMethodSig> getConstructors()
        Returns a list of all the declared constructors for this type. Abstract types like type variables and interfaces have no constructors.
      • subst

        JTypeMirror subst​(Function<? super SubstVar,​? extends @NonNull JTypeMirror> subst)
        Description copied from interface: JTypeVisitable
        Replace the type variables occurring in the given type by their image by the given function. Substitutions are not applied recursively (ie, is not applied on the result of a substitution).
        Specified by:
        subst in interface JTypeVisitable
        subst - Substitution function, eg a Substitution
      • withAnnotations

        JTypeMirror withAnnotations​(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
        Returns a type mirror that is equal to this instance but has different type annotations. Note that some types ignore this method and return themselves without changing. Eg the null type cannot be annotated.
        newTypeAnnots - New type annotations (not null)
        A new type, maybe this one
      • equals

        boolean equals​(Object o)
        Returns true if the object is a type equivalent to this one. A few kinds of types use reference identity, like captured type variables, or the null type. A few special types are represented by constants (see TypeSystem). Apart from those, types should always be compared using this method. or TypeOps.isSameType(JTypeMirror, JTypeMirror) (which is null-safe).

        Note that types belonging to different type systems do not test equal. The type system object is global to the analysis though, so this should not ever happen in rules.

        equals in class Object
        Implementation Requirements:
        This method should be implemented with TypeOps.isSameType(JTypeMirror, JTypeMirror), and perform no side-effects on inference variables.
        o -
      • toString

        String toString()
        The toString of type mirrors prints useful debug information, but shouldn't be relied on anywhere, as it may change anytime. Use TypePrettyPrint to display types.
        toString in class Object