Class JandexReflection


  • public class JandexReflection
    extends java.lang.Object
    Utilities that allow moving from the Jandex world to the runtime world using reflection. To maintain stratification, these methods are intentionally not present on the respective Jandex classes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  JandexReflection.GenericArrayTypeImpl
      An implementation of GenericArrayType that is compatible with the JDK's implementation (as in, the equals() and hashCode() methods work as expected).
      private static class  JandexReflection.ParameterizedTypeImpl
      An implementation of ParameterizedType that is compatible with the JDK's implementation (as in, the equals() and hashCode() methods work as expected).
      private static class  JandexReflection.TypeVariableImpl<D extends java.lang.reflect.GenericDeclaration>
      An implementation of TypeVariable that is NOT compatible with the JDK's implementation (as in, the equals() and hashCode() methods do not work as expected).
      private static class  JandexReflection.TypeVariableReferenceImpl<D extends java.lang.reflect.GenericDeclaration>
      A delegating implementation of TypeVariable that is NOT compatible with the JDK's implementation (as in, the equals() and hashCode() methods do not work as expected).
      private static class  JandexReflection.TypeVariables  
      private static class  JandexReflection.WildcardTypeImpl
      An implementation of WildcardType that is compatible with the JDK's implementation (as in, the equals() and hashCode() methods work as expected).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.Class<?> load​(DotName name)  
      static java.lang.Class<?> loadClass​(ClassInfo clazz)
      Loads a class corresponding to given ClassInfo from the thread context classloader.
      static java.lang.Class<?> loadRawType​(Type type)
      Loads a class corresponding to the raw type of given Type from the thread context classloader.
      static java.lang.reflect.Type loadType​(Type type)
      Loads a Reflection Type corresponding to the given Jandex Type.
      private static java.lang.reflect.Type loadType​(Type type, JandexReflection.TypeVariables typeVariables)  
      • Methods inherited from class java.lang.Object

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

      • JandexReflection

        public JandexReflection()
    • Method Detail

      • loadType

        public static java.lang.reflect.Type loadType​(Type type)
        Loads a Reflection Type corresponding to the given Jandex Type. Classes are loaded from the thread context classloader. If there is no TCCL, the classloader that loaded JandexReflection is used. Returns null when type is null.

        The result is equal to the corresponding Type obtained from Reflection and has the same hash code, as long as it doesn't contain any type variables.

        Parameters:
        type - a Jandex Type
        Returns:
        the corresponding Reflection Type
      • loadRawType

        public static java.lang.Class<?> loadRawType​(Type type)
        Loads a class corresponding to the raw type of given Type from the thread context classloader. If there is no TCCL, the classloader that loaded JandexReflection is used. Returns null when type is null.

        Specifically:

        • for the void pseudo-type, returns void.class;
        • for primitive types, returns the corresponding class object (e.g. int.class);
        • for class types, returns the corresponding class object (e.g. String.class);
        • for array types, returns the corresponding class object (e.g. String[][].class);
        • for parameterized types, returns the class object of the generic class (e.g. List.class for List<String>);
        • for wildcard types, returns the class object of the upper bound type (e.g. Number.class for ? extends Number), or Object.class if the wildcard type has no upper bound (e.g. ? super Integer);
        • for type variables, returns the class object of the first bound (e.g. Number.class for T extends Number & Comparable<T>), or Object.class if the type variable has no bounds (e.g. just T);
        • for type variables references, follows the reference to obtain the type variable and then returns the class object of the first bound (e.g. Number.class for T extends Number & Comparable<T>), or Object.class if the type variable has no bounds (e.g. just T);
        • for unresolved type variables, returns Object.class.
        Parameters:
        type - a Jandex Type
        Returns:
        the corresponding Class
      • loadClass

        public static java.lang.Class<?> loadClass​(ClassInfo clazz)
        Loads a class corresponding to given ClassInfo from the thread context classloader. If there is no TCCL, the classloader that loaded JandexReflection is used. Returns null when clazz is null.
        Parameters:
        clazz - a Jandex ClassInfo
        Returns:
        the corresponding Class
      • load

        private static java.lang.Class<?> load​(DotName name)