Interface TypeReference

All Superinterfaces:
Element

@Beta public interface TypeReference extends Element
Author:
Sven Efftinge
  • Method Details

    • getSimpleName

      String getSimpleName()
      Returns a text representation using the simple names of the involved types. I.e. for 'java.util.List<? extends java.math.BigDecimal>' this method returns 'List<? extends BigDecimal>'
      Returns:
      the simple name of this type reference
    • getName

      String getName()
      returns the text representation using the qualified names of the involved types.
      Returns:
      the qualified name of this type reference
    • getType

      Type getType()
      Returns:
      the referenced type.
    • getActualTypeArguments

      List<TypeReference> getActualTypeArguments()
      Returns:
      the type arguments
    • isWildCard

      boolean isWildCard()
      Returns:
      whether this is a wildcard reference
    • getUpperBound

      TypeReference getUpperBound()
      Returns:
      the upper bounds
    • getLowerBound

      TypeReference getLowerBound()
      Returns:
      the lower bounds
    • isArray

      boolean isArray()
      Returns:
      whether this is an array
    • getArrayComponentType

      TypeReference getArrayComponentType()
      Returns:
      the component type if this tye reference is an array type reference, null otherwise.
    • isAnyType

      boolean isAnyType()
      Returns:
      whether this is the any type, The any type is the subtype of every reference type and its only instance is null.
    • isPrimitive

      boolean isPrimitive()
      Returns:
      whether this is a primitive type (i.e. one of boolean, char, byte, short, int, long, float, double).
    • getWrapperIfPrimitive

      TypeReference getWrapperIfPrimitive()
      Returns:
      the corresponding wrapper TypeReference if this type references is a primitive type. Returns this otherwise.
    • isWrapper

      boolean isWrapper()
      Checks whether this type is one of the wrapper types for the primitive value types.
      Returns:
      wither this is one of the wrapper types for the primitive value types.
    • getPrimitiveIfWrapper

      TypeReference getPrimitiveIfWrapper()
      Returns:
      the corresponding primitive TypeReference if this type references is a wrapper type. Returns this otherwise.
    • isVoid

      boolean isVoid()
      Returns:
      whether this type is 'void' (doesn't include 'java.lang.Void')
    • isAssignableFrom

      boolean isAssignableFrom(TypeReference typeReference)
      Determines if the specified TypeReference parameter can be assigned to this TypeReference. It returns true if so; otherwise it returns false.
      Parameters:
      typeReference -
      Returns:
      returns true is the specified type reference parameter can be assigned to this type reference.
    • isInferred

      boolean isInferred()
      Whether the given type reference is an inferred reference. That is the type is to be computed from some Expression, e.g. a method body or a field initializer. Inferred type references can only be used as handles, and will through an UnsupportedOperationException on every method other than
      Returns:
      whether this type reference is an inferred type reference.
    • getDeclaredSuperTypes

      Iterable<? extends TypeReference> getDeclaredSuperTypes()
      Returns:
      the supertypes (superclass and interfaces) directly implemented/extended by this type
      Since:
      2.7
    • getDeclaredResolvedMethods

      Iterable<? extends ResolvedMethod> getDeclaredResolvedMethods()
      Returns:
      the resolved methods directly declared by this type
      Since:
      2.7
    • getDeclaredResolvedConstructors

      Iterable<? extends ResolvedConstructor> getDeclaredResolvedConstructors()
      Returns:
      the resolved constructors directly declared by this type
      Since:
      2.7
    • getAllResolvedMethods

      Iterable<? extends ResolvedMethod> getAllResolvedMethods()
      Computes all the resolved methods that can be called on this type, either because they were declared directly by the type or by one of its supertypes. For overloaded methods, the one declared closest to this type is used. E.g. when called on the class C in this hierarchy:
       class A {
        def CharSequence foo()
       }
       class B extends A {
        override String foo()
       }
       class C extends B {}
       
       
       B#foo() would be contained, but not A#foo().
      Returns:
      the resolved methods declared in this type and its supertypes.
      Since:
      2.7
    • equals

      boolean equals(Object obj)
      Checks whether this type reference equals the given type reference. For type References where isInferred() is true, the implementation is based on identity of the underlying AST.
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
      whether the given obj is the same instance
      Since:
      2.7
    • hashCode

      int hashCode()
      Value-based for all TypeReferences where isInferred() is false.
      Overrides:
      hashCode in class Object
      Since:
      2.7
    • toString

      String toString()
      A string representation for this type reference. If this reference is resolved, it will return the simple name of this reference. Otherwise a technical information about the inferred type reference.
      Overrides:
      toString in class Object
      Returns:
      a string representation
      Since:
      2.8