Modifier and Type | Class and Description |
---|---|
static class |
TypeExtractionUtils.LambdaExecutable
Similar to a Java 8 Executable but with a return type.
|
Modifier and Type | Method and Description |
---|---|
static TypeExtractionUtils.LambdaExecutable |
checkAndExtractLambda(Function function)
Checks if the given function has been implemented using a Java 8 lambda.
|
static Type |
extractTypeArgument(Type t,
int index)
This method extracts the n-th type argument from the given type.
|
static Type |
extractTypeFromLambda(Class<?> baseClass,
TypeExtractionUtils.LambdaExecutable exec,
int[] lambdaTypeArgumentIndices,
int paramLen,
int baseParametersLen)
Extracts type from given index from lambda.
|
static List<Method> |
getAllDeclaredMethods(Class<?> clazz)
Returns all declared methods of a class including methods of superclasses.
|
static Class<?> |
getRawClass(Type t)
Returns the raw class of both parameterized types and generic arrays.
|
static Method |
getSingleAbstractMethod(Class<?> baseClass)
Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2.
|
static Type |
getTypeHierarchy(List<Type> typeHierarchy,
Type t,
Class<?> stopAtClass)
Traverses the type hierarchy of a type up until a certain stop class is found.
|
static boolean |
hasSuperclass(Class<?> clazz,
String superClassName)
Returns true if the given class has a superclass of given name.
|
static boolean |
isClassType(Type t)
Checks if a type can be converted to a Class.
|
static boolean |
sameTypeVars(Type t1,
Type t2)
Checks whether two types are type variables describing the same.
|
static <T> Class<T> |
typeToClass(Type t)
Convert ParameterizedType or Class to a Class.
|
static void |
validateLambdaType(Class<?> baseClass,
Type t)
Checks whether the given type has the generic parameters declared in the class definition.
|
public static TypeExtractionUtils.LambdaExecutable checkAndExtractLambda(Function function) throws TypeExtractionException
TypeExtractionException
- lambda extraction is pretty hacky, it might fail for unknown
JVM issues.public static Type extractTypeFromLambda(Class<?> baseClass, TypeExtractionUtils.LambdaExecutable exec, int[] lambdaTypeArgumentIndices, int paramLen, int baseParametersLen)
baseClass
- SAM function that the lambda implementsexec
- lambda function to extract the type fromlambdaTypeArgumentIndices
- position of type to extract in type hierarchyparamLen
- count of total parameters of the lambda (including closure parameters)baseParametersLen
- count of lambda interface parameters (without closure parameters)public static Type extractTypeArgument(Type t, int index) throws InvalidTypesException
t
- Type to extract the type arguments fromindex
- Index of the type argument to extractInvalidTypesException
- if the given type does not have any type arguments or if the
index exceeds the number of type arguments.public static Method getSingleAbstractMethod(Class<?> baseClass)
baseClass
- a class that is a FunctionalInterface to retrieve a SAM fromInvalidTypesException
- if the given class does not implement FunctionalInterfacepublic static List<Method> getAllDeclaredMethods(Class<?> clazz)
public static <T> Class<T> typeToClass(Type t)
public static boolean isClassType(Type t)
public static boolean sameTypeVars(Type t1, Type t2)
public static Type getTypeHierarchy(List<Type> typeHierarchy, Type t, Class<?> stopAtClass)
t
- type for which a hierarchy need to be createdpublic static boolean hasSuperclass(Class<?> clazz, String superClassName)
clazz
- class to be analyzedsuperClassName
- class name of the super classpublic static Class<?> getRawClass(Type t)
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.