Class TypeExtractionUtils


  • @Internal
    public class TypeExtractionUtils
    extends Object
    • Method Detail

      • checkAndExtractLambda

        public static TypeExtractionUtils.LambdaExecutable checkAndExtractLambda​(org.apache.flink.api.common.functions.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 implements
        exec - lambda function to extract the type from
        lambdaTypeArgumentIndices - position of type to extract in type hierarchy
        paramLen - 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 from
        index - 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 analyzed
        superClassName - 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.
      • validateLambdaType

        public static void validateLambdaType​(Class<?> baseClass,
                                              Type t)
        Checks whether the given type has the generic parameters declared in the class definition.
        Parameters:
        t - type to be validated