Class AbstractType

java.lang.Object
org.postgresql.pljava.adt.spi.AbstractType
All Implemented Interfaces:
Type

public abstract class AbstractType extends Object implements Type
Custom implementations of Java's Type interfaces, with methods for a couple useful manipulations.

The implementations returned from Java reflection methods are internal, with no way to instantiate arbitrary new ones to represent the results of computations with them.

Note: the implementations here do not override equals and hashCode inherited from Object. The JDK internal ones do, but not with documented behaviors, so it didn't seem worthwhile to try to match them. (The API specifies an equals behavior only for ParameterizedType, and no corresponding hashCode even for that, so good luck matching it.) Results from methods in this class can include new objects (instances of these classes) and original ones constructed by Java; don't assume anything sane will happen using equals or hashCode between them. There is a typesEqual static method defined here to do that job.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A class recording the bindings made in a ParameterizedType to the type parameters in a GenericDeclaration<Class>.
    static class 
    A class dedicated to manipulating the types of multidimensional Java arrays, and their instances, that conform to PostgreSQL array constraints (non-'jagged', each dimension's arrays all equal size, no intermediate nulls).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Class<?>
    Returns the erasure of a type.
    static TypeVariable<?>[]
     
     
    static boolean
    isSubtype(Type sub, Type sup)
    Needed: test whether sub is a subtype of sup.
    static Type[]
    refine(Type using, Type... in)
    Refines some Types in by unifying the first of them with using.
    static Type[]
    specialization(Type candidate, Class<?> expected)
    Equivalent to specialization(candidate, expected, null).
    static Type[]
    specialization(Type candidate, Class<?> expected, Type[] rtype)
    Test whether the type candidate is, directly or indirectly, a specialization of generic type expected.
    static Type
    Recursively descend t substituting any occurrence of a type variable found in b, returning a new object, or t unchanged if no substitutions were made.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractType

      public AbstractType()
  • Method Details

    • refine

      public static Type[] refine(Type using, Type... in)
      Refines some Types in by unifying the first of them with using.

      The variadic array of in arguments is returned, modified in place.

      The type using is unified with in[0] and then used to replace in[0], while any variable substitutions made in the unification are repeated in the remaining in elements.

    • isSubtype

      public static boolean isSubtype(Type sub, Type sup)
      Needed: test whether sub is a subtype of sup.

      XXX For the time being, this is nothing but a test of erased subtyping, hastily implemented by requiring that specialization(sub, erase(sup)) does not return null.

      This must sooner or later be replaced with an implementation of the subtyping rules from Java Language Specification 4.10, taking also type parameterization into account.

    • specialization

      public static Type[] specialization(Type candidate, Class<?> expected)
      Equivalent to specialization(candidate, expected, null).
    • specialization

      public static Type[] specialization(Type candidate, Class<?> expected, Type[] rtype)
      Test whether the type candidate is, directly or indirectly, a specialization of generic type expected.

      For example, the Java type T of a particular adapter A that extends Adapter.As<T,?> can be retrieved with specialization(A.class, As.class)[0].

      More generally, this method can retrieve the generic type information from any "super type token", as first proposed by Neal Gafter in 2006, where a super type token is generally an instance of an anonymous subclass that specializes a certain generic type. Although the idea has been often used, the usages have not settled on one agreed name for the generic type. This method will work with any of them, by supplying the expected generic type itself as the second parameter. For example, a super type token foo derived from Gafter's suggested class TypeReference can be unpacked with specialization(foo.getClass(), TypeReference.class).

      Parameters:
      candidate - a type to be checked
      expected - known (normally generic) type to check for
      rtype - array to receive (if non-null) the corresponding (parameterized or raw) type if the result is non-null.
      Returns:
      null if candidate does not extend expected, otherwise the array of type arguments with which it specializes expected
      Throws:
      IllegalArgumentException - if passed a Type that is not a Class or a ParameterizedType
      NullPointerException - if either argument is null
      UnsupportedOperationException - if candidate does extend expected but does not carry the needed parameter bindings (such as when the raw expected Class itself is passed)
    • erase

      public static Class<?> erase(Type t)
      Returns the erasure of a type.

      If t is a Class, it is returned unchanged.

    • substitute

      public static Type substitute(AbstractType.Bindings b, Type t)
      Recursively descend t substituting any occurrence of a type variable found in b, returning a new object, or t unchanged if no substitutions were made.

      Currently throws UnsupportedOperationException if t is a wildcard, as that case shouldn't be needed for the analysis of class/interface inheritance hierarchies that specialization is concerned with.

    • freeVariables

      public static TypeVariable<?>[] freeVariables(Type t)
    • getTypeName

      public String getTypeName()
      Specified by:
      getTypeName in interface Type