Package org.pkl.config.java.mapper
Class Reflection
- java.lang.Object
-
- org.pkl.config.java.mapper.Reflection
-
public final class Reflection extends java.lang.ObjectReflection utilities for implementingConverterFactorys. Mostly covers introspection of parameterized types, which is not covered by thejava.util.reflectAPI.The heavy lifting under the covers is done by the excellent ge(a)ntyref library.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.TypegetArrayElementType(java.lang.reflect.Type type)Returns the (possibly parameterized) element type for the given array type.static java.lang.reflect.Type[]getExactParameterTypes(java.lang.reflect.Executable m, java.lang.reflect.Type declaringType)Returns the exact parameter types of the given method or constructor, taking into account type arguments of the given declaring type.static java.lang.reflect.TypegetExactSubtype(java.lang.reflect.Type type, java.lang.Class<?> rawSubtype)Returns a parameterization of the given raw subtype, taking into account type arguments of the given supertype.static java.lang.reflect.TypegetExactSupertype(java.lang.reflect.Type type, java.lang.Class<?> rawSupertype)Returns a parameterization of the given raw supertype, taking into account type arguments of the given subtype.static booleanisMissingTypeArguments(java.lang.reflect.Type type)static java.lang.reflect.Typenormalize(java.lang.reflect.Type type)Returns the normalized form of the given type.static java.lang.Class<?>toRawType(java.lang.reflect.Type type)Returns the raw (erased) type for the given parameterized type, type bound for the given wildcard type, or the given type otherwise.static <T> java.lang.Class<T>toWrapperType(java.lang.Class<T> type)Returns the wrapper type for the given primitive type.static @Nullable java.lang.Class<?>tryLoadClass(java.lang.String qualifiedName)Returns the class with the given fully qualified name, ornullif a class with the given name cannot be found.
-
-
-
Method Detail
-
tryLoadClass
public static @Nullable java.lang.Class<?> tryLoadClass(java.lang.String qualifiedName)
Returns the class with the given fully qualified name, ornullif a class with the given name cannot be found.
-
isMissingTypeArguments
public static boolean isMissingTypeArguments(java.lang.reflect.Type type)
-
normalize
public static java.lang.reflect.Type normalize(java.lang.reflect.Type type)
Returns the normalized form of the given type. A normalized type is concrete (no wildcards) and instantiable (not an interface or abstract class).
-
toRawType
public static java.lang.Class<?> toRawType(java.lang.reflect.Type type)
Returns the raw (erased) type for the given parameterized type, type bound for the given wildcard type, or the given type otherwise.
-
toWrapperType
public static <T> java.lang.Class<T> toWrapperType(java.lang.Class<T> type)
Returns the wrapper type for the given primitive type. If the given type is not a primitive type, returns the given type.
-
getArrayElementType
public static java.lang.reflect.Type getArrayElementType(java.lang.reflect.Type type)
Returns the (possibly parameterized) element type for the given array type.
-
getExactSupertype
public static java.lang.reflect.Type getExactSupertype(java.lang.reflect.Type type, java.lang.Class<?> rawSupertype)Returns a parameterization of the given raw supertype, taking into account type arguments of the given subtype. For example, @{code getExactSupertype(listOf(String.class), Collection.class)} will return @{code collectionOf(String.class)}. If the given subtype is not a parameterized type, returns the given raw supertype. If the given types have no inheritance relationship, returnsnull.
-
getExactSubtype
public static java.lang.reflect.Type getExactSubtype(java.lang.reflect.Type type, java.lang.Class<?> rawSubtype)Returns a parameterization of the given raw subtype, taking into account type arguments of the given supertype. For example, @{code getExactSubtype(collectionOf(String.class), List.class)} will return @{code listOf(String.class)}. If the given supertype is not a parameterized type, returns the given raw subtype. If the given types have no inheritance relationship, returnsnull.
-
getExactParameterTypes
public static java.lang.reflect.Type[] getExactParameterTypes(java.lang.reflect.Executable m, java.lang.reflect.Type declaringType)Returns the exact parameter types of the given method or constructor, taking into account type arguments of the given declaring type. For example,getExactParameterTypes(List.class.getDeclaredMethod("get"), listOf(optionalOf(String.class)will returnoptionalOf(String.class). ThrowsIllegalArgumentExceptionif the given method or constructor is not declared by the given type.
-
-