saker.util Documentation TaskDoc JavaDoc Packages
package saker.util
public class ReflectTypes
Utility class containing functions for handling types in the java.lang.reflect package.
Methods
public static Object
Creates a new empty array instance that is compatible with the argument type.
public static Type
Deannotates the argument type object.
public static Class<?>
Gets the class of a type, and from the value that is treated as an instance of the given type.
public static Collection<ClassLoader>
Gets the classloaders which are associated with the given type.
public static Class<?>
Gets the class representation of the generic array type represented by the argument.
public static Class<?>
Gets the component class of the generic array type represented by the argument.
public static List<extends Type>
getTypeArguments(Type generictype)
Gets a list that contains the actual type parameters of the argument, if it is a parameterized type.
public static Type
getTypeArguments(Type generictype, int index)
Gets the type parameter of the possibly parameterized argument type at the given index.
public static Type
makeArrayType(Type componenttype)
Gets a Type that has the argument type as its component.
public static ParameterizedType
makeParameterizedType(Type type, Type... templateargs)
Creates a new ParameterizedType for the given type, and template arguments.
public static ParameterizedType
makeParameterizedTypeWithOwner(Type owner, Type type, Type... templateargs)
Creates a new ParameterizedType for the given owner, type, and template arguments.
public static WildcardType
Creates a new WildcardType that extends the argument types.
public static WildcardType
Creates a new WildcardType that is a super type of the argument types.
Creates a new empty array instance that is compatible with the argument type.

The raw component type of the generic array type will be retrieved, and a new empty array is created for it. The component type will be resolved accordingly. This method will only be available to create a new array instance if the innermost component type is either a Class, or ParameterizedType. The method cannot create an array for type that have a wildcard or type variable component type.

typeThe generic array type to create the array for.
The created array.
IllegalArgumentExceptionIf the method cannot determine the component type.
NullPointerExceptionIf the argument is null.
public static Type deannotateType(Type type)
Deannotates the argument type object.

If the argument is an instance of AnnotatedType, the AnnotatedType.getType() method will be called on it. This is repeated until the last type is not an annotated type.

typeThe type.
The deannotated type.
public static Class<?> getClassFromType(Object value, Type type)
Gets the class of a type, and from the value that is treated as an instance of the given type.

If the value is not null, the class of the value object is returned.

Else the given type is examined.

If it is an instance of Class, it is returned.

If it is an instance of ParameterizedType, the raw type is returned.

If it is an instance of GenericArrayType, the array type corresponding to it is returned.

In any other cases, null is returned. Wildcards and type variables are not recognized.

valueThe value that is an instance of the given type.
typeThe type to get the class representation of.
The corresponding class, or null if failed to determine.
Gets the classloaders which are associated with the given type.

This method examines the argument type, and gets the classloaders for them.

If the type is a Class, the classloader of that class is added.

If the type is a ParameterizedType, the classloaders for the raw type, and the type arguments are added.

If the type is a GenericArrayType, the classloaders for the component type is added.

If the type is a WildcardType, the classloaders for the upper and lower bounds is added.

If the type is a TypeVariable, the classloaders for the bounds and the generic declaration is added.

In any other case, the type is unrecognized, and no classloaders are added.

typeThe type to get the classloaders for.
A set of classloaders which are associated with the given type.
NullPointerExceptionIf the argument is null.
Gets the class representation of the generic array type represented by the argument.
typeThe generic array type to get the class of.
The class of the generic array.
IllegalArgumentExceptionIf the method cannot determine the component type.
NullPointerExceptionIf the argument is null.
Gets the component class of the generic array type represented by the argument.
typeThe generic array type to get the component class of.
The component class of the argument.
IllegalArgumentExceptionIf the method cannot determine the component type.
NullPointerExceptionIf the argument is null.
public static List<extends Type> getTypeArguments(Type generictype)
Gets a list that contains the actual type parameters of the argument, if it is a parameterized type.

If the argument is not a parameterized type, an empty list is returned.

generictypeThe type to get the type arguments of.
The type arguments.
public static Type getTypeArguments(Type generictype, int index) throws IllegalArgumentException
Gets the type parameter of the possibly parameterized argument type at the given index.

This method will check if the argument is an instanceo of ParameterizedType, and return the actual type argument at the given index.

If the argument is not an instance of ParameterizedType, or the index is out of bounds for the type arguments, Object.class is returned.

generictypeThe generic type.
indexThe index at which to query the type argument.
The found type or Object.class.
IllegalArgumentExceptionIf the index is negative.
public static Type makeArrayType(Type componenttype) throws NullPointerException
Gets a Type that has the argument type as its component.

The returned type is either an instance of GenericArrayType, or a Class.

componenttypeThe component type.
The type that has the argument as component.
NullPointerExceptionIf the argument is null.
public static ParameterizedType makeParameterizedType(Type type, Type... templateargs) throws NullPointerException
Creates a new ParameterizedType for the given type, and template arguments.

The returned ParameterizedType will have the given arguments as its attributes. The result will have null owner type.

The template argument array may or may not be cloned. Any modifications made to it may be reflected on the returned result. Callers shouldn't rely on the array being modifiable after this call returns.

typeThe raw type.
templateargsThe type arguments.
The created parameterized type.
NullPointerExceptionIf the type or template arguments array is null.
public static ParameterizedType makeParameterizedTypeWithOwner(Type owner, Type type, Type... templateargs) throws NullPointerException
Creates a new ParameterizedType for the given owner, type, and template arguments.

The returned ParameterizedType will have the given arguments as its attributes.

The template argument array may or may not be cloned. Any modifications made to it may be reflected on the returned result. Callers shouldn't rely on the array being modifiable after this call returns.

ownerThe owner type. May be null.
typeThe raw type.
templateargsThe type arguments.
The created parameterized type.
NullPointerExceptionIf the type or template arguments array is null.
public static WildcardType makeWildcardTypeExtends(Type... extendtypes) throws NullPointerException
Creates a new WildcardType that extends the argument types.

The extended types argument array may or may not be cloned. Any modifications made to it may be reflected on the returned result. Callers shouldn't rely on the array being modifiable after this call returns.

extendtypesThe types that the wildcard extends.
The created wildcard type.
NullPointerExceptionIf the argument array is null.
public static WildcardType makeWildcardTypeSuper(Type... supertypes) throws NullPointerException
Creates a new WildcardType that is a super type of the argument types.

The super types argument array may or may not be cloned. Any modifications made to it may be reflected on the returned result. Callers shouldn't rely on the array being modifiable after this call returns.

supertypesThe types that the wildcard is super of.
The created wildcard type.
NullPointerExceptionIf the argument array is null.