Package org.pkl.config.java.mapper
Class Reflection
java.lang.Object
org.pkl.config.java.mapper.Reflection
Reflection utilities for implementing
ConverterFactorys. Mostly covers introspection of
parameterized types, which is not covered by the java.util.reflect API.
The heavy lifting under the covers is done by the excellent ge(a)ntyref library.
-
Method Summary
Modifier and TypeMethodDescriptionstatic TypegetArrayElementType(Type type) Returns the (possibly parameterized) element type for the given array type.static Type[]getExactParameterTypes(Executable m, Type declaringType) Returns the exact parameter types of the given method or constructor, taking into account type arguments of the given declaring type.static TypegetExactSubtype(Type type, Class<?> rawSubtype) Returns a parameterization of the given raw subtype, taking into account type arguments of the given supertype.static TypegetExactSupertype(Type type, Class<?> rawSupertype) Returns a parameterization of the given raw supertype, taking into account type arguments of the given subtype.static booleanisMissingTypeArguments(Type type) static TypeReturns the normalized form of the given type.static Class<?> Returns the raw (erased) type for the given parameterized type, type bound for the given wildcard type, or the given type otherwise.static <T> Class<T> toWrapperType(Class<T> type) Returns the wrapper type for the given primitive type.static @Nullable Class<?> tryLoadClass(String qualifiedName) Returns the class with the given fully qualified name, ornullif a class with the given name cannot be found.
-
Method Details
-
tryLoadClass
Returns the class with the given fully qualified name, ornullif a class with the given name cannot be found. -
isMissingTypeArguments
-
normalize
Returns the normalized form of the given type. A normalized type is concrete (no wildcards) and instantiable (not an interface or abstract class). -
toRawType
Returns the raw (erased) type for the given parameterized type, type bound for the given wildcard type, or the given type otherwise. -
toWrapperType
Returns the wrapper type for the given primitive type. If the given type is not a primitive type, returns the given type. -
getArrayElementType
Returns the (possibly parameterized) element type for the given array type. -
getExactSupertype
Returns a parameterization of the given raw supertype, taking into account type arguments of the given subtype. For example,getExactSupertype(listOf(String.class), Collection.class)will returncollectionOf(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
Returns a parameterization of the given raw subtype, taking into account type arguments of the given supertype. For example,getExactSubtype(collectionOf(String.class), List.class)will returnlistOf(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
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.
-