Class TypeExtractionUtils
- java.lang.Object
-
- org.apache.flink.api.java.typeutils.TypeExtractionUtils
-
@Internal public class TypeExtractionUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeExtractionUtils.LambdaExecutableSimilar to a Java 8 Executable but with a return type.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TypeExtractionUtils.LambdaExecutablecheckAndExtractLambda(Function function)Checks if the given function has been implemented using a Java 8 lambda.static TypeextractTypeArgument(Type t, int index)This method extracts the n-th type argument from the given type.static TypeextractTypeFromLambda(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 MethodgetSingleAbstractMethod(Class<?> baseClass)Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2.static TypegetTypeHierarchy(List<Type> typeHierarchy, Type t, Class<?> stopAtClass)Traverses the type hierarchy of a type up until a certain stop class is found.static booleanhasSuperclass(Class<?> clazz, String superClassName)Returns true if the given class has a superclass of given name.static booleanisClassType(Type t)Checks if a type can be converted to a Class.static booleansameTypeVars(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 voidvalidateLambdaType(Class<?> baseClass, Type t)Checks whether the given type has the generic parameters declared in the class definition.
-
-
-
Method Detail
-
checkAndExtractLambda
public static TypeExtractionUtils.LambdaExecutable checkAndExtractLambda(Function function) throws TypeExtractionException
Checks if the given function has been implemented using a Java 8 lambda. If yes, a LambdaExecutable is returned describing the method/constructor. Otherwise null.- Throws:
TypeExtractionException- lambda extraction is pretty hacky, it might fail for unknown JVM issues.
-
extractTypeFromLambda
public static Type extractTypeFromLambda(Class<?> baseClass, TypeExtractionUtils.LambdaExecutable exec, int[] lambdaTypeArgumentIndices, int paramLen, int baseParametersLen)
Extracts type from given index from lambda. It supports nested types.- Parameters:
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)- Returns:
- extracted type
-
extractTypeArgument
public static Type extractTypeArgument(Type t, int index) throws InvalidTypesException
This method extracts the n-th type argument from the given type. An InvalidTypesException is thrown if the type does not have any type arguments or if the index exceeds the number of type arguments.- Parameters:
t- Type to extract the type arguments fromindex- Index of the type argument to extract- Returns:
- The extracted type argument
- Throws:
InvalidTypesException- if the given type does not have any type arguments or if the index exceeds the number of type arguments.
-
getSingleAbstractMethod
public static Method getSingleAbstractMethod(Class<?> baseClass)
Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2. The Class Object, 9.8 Functional Interfaces, 9.4.3 Interface Method Body) from given class.- Parameters:
baseClass- a class that is a FunctionalInterface to retrieve a SAM from- Returns:
- single abstract method of the given class
- Throws:
InvalidTypesException- if the given class does not implement FunctionalInterface
-
getAllDeclaredMethods
public static List<Method> getAllDeclaredMethods(Class<?> clazz)
Returns all declared methods of a class including methods of superclasses.
-
typeToClass
public static <T> Class<T> typeToClass(Type t)
Convert ParameterizedType or Class to a Class.
-
isClassType
public static boolean isClassType(Type t)
Checks if a type can be converted to a Class. This is true for ParameterizedType and Class.
-
sameTypeVars
public static boolean sameTypeVars(Type t1, Type t2)
Checks whether two types are type variables describing the same.
-
getTypeHierarchy
public 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.- Parameters:
t- type for which a hierarchy need to be created- Returns:
- type of the immediate child of the stop class
-
hasSuperclass
public static boolean hasSuperclass(Class<?> clazz, String superClassName)
Returns true if the given class has a superclass of given name.- Parameters:
clazz- class to be analyzedsuperClassName- class name of the super class
-
getRawClass
public static Class<?> getRawClass(Type t)
Returns the raw class of both parameterized types and generic arrays. Returns java.lang.Object for all other types.
-
-