Class ExtractionUtils

java.lang.Object
org.apache.flink.table.types.extraction.ExtractionUtils

@Internal public final class ExtractionUtils extends Object
Utilities for performing reflection tasks.
  • Method Details

    • collectMethods

      public static List<Method> collectMethods(Class<?> function, String methodName)
      Collects methods of the given name.
    • isInvokable

      public static boolean isInvokable(ExtractionUtils.Autoboxing autoboxing, Executable executable, Class<?>... classes)
      Checks whether a method/constructor can be called with the given argument classes. This includes type widening and vararg. null is a wildcard.

      E.g., (int.class, int.class) matches f(Object...), f(int, int), f(Integer, Object) and so forth.

    • createMethodSignatureString

      public static String createMethodSignatureString(String methodName, Class<?>[] parameters, @Nullable Class<?> returnType)
      Creates a method signature string like int eval(Integer, String).
    • validateStructuredClass

      public static void validateStructuredClass(Class<?> clazz)
      Validates the characteristics of a class for a StructuredType such as accessibility.
    • getStructuredField

      public static Field getStructuredField(Class<?> clazz, String fieldName)
      Returns the field of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors.
    • getStructuredFieldGetter

      public static Optional<Method> getStructuredFieldGetter(Class<?> clazz, Field field)
      Checks for a field getter of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors.
    • getStructuredFieldSetter

      public static Optional<Method> getStructuredFieldSetter(Class<?> clazz, Field field)
      Checks for a field setters of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors.
    • hasInvokableConstructor

      public static boolean hasInvokableConstructor(Class<?> clazz, Class<?>... classes)
      Checks for an invokable constructor matching the given arguments.
      See Also:
    • isStructuredFieldDirectlyReadable

      public static boolean isStructuredFieldDirectlyReadable(Field field)
      Checks whether a field is directly readable without a getter.
    • isStructuredFieldDirectlyWritable

      public static boolean isStructuredFieldDirectlyWritable(Field field)
      Checks whether a field is directly writable without a setter or constructor.
    • extractSimpleGeneric

      public static Optional<Class<?>> extractSimpleGeneric(Class<?> baseClass, Class<?> clazz, int pos)
      A minimal version to extract a generic parameter from a given class.

      This method should only be used for very specific use cases, in most cases DataTypeExtractor.extractFromGeneric(DataTypeFactory, Class, int, Type) should be more appropriate.

    • resolveVariableWithClassContext

      public static Type resolveVariableWithClassContext(@Nullable Type contextType, Type type)
      Resolves a variable type while accepting a context for resolution.
    • getClassFromType

      public static Class<?> getClassFromType(Type type)
      Gets the associated class type from a Type parameter.
    • extractAssigningConstructor

      @Nullable public static ExtractionUtils.AssigningConstructor extractAssigningConstructor(Class<?> clazz, List<Field> fields)
      Checks whether the given constructor takes all of the given fields with matching (possibly primitive) type and name. An assigning constructor can define the order of fields.
    • isAssignable

      public static boolean isAssignable(Class<?> cls, Class<?> toClass, ExtractionUtils.Autoboxing autoboxing)
      Checks if one Class can be assigned to a variable of another Class.

      Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

      Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.

      Null may be assigned to any reference type. This method will return true if null is passed in and the toClass is non-primitive.

      Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.

      Parameters:
      cls - the Class to check, may be null
      toClass - the Class to try to assign into, returns false if null
      autoboxing - whether to use implicit autoboxing/unboxing between primitives and wrappers
      autoboxing - checks whether null would end up in a primitive type and forbids it
      Returns:
      true if assignment possible
    • primitiveToWrapper

      public static Class<?> primitiveToWrapper(Class<?> cls)
      Converts the specified primitive Class object to its corresponding wrapper Class object.

      NOTE: From v2.2, this method handles Void.TYPE, returning Void.TYPE.

      Parameters:
      cls - the class to convert, may be null
      Returns:
      the wrapper class for cls or cls if cls is not a primitive. null if null input.
      Since:
      2.1
    • wrapperToPrimitive

      public static Class<?> wrapperToPrimitive(Class<?> cls)
      Converts the specified wrapper class to its corresponding primitive class.

      This method is the counter part of primitiveToWrapper(). If the passed in class is a wrapper class for a primitive type, this primitive type will be returned (e.g. Integer.TYPE for Integer.class). For other classes, or if the parameter is null, the return value is null.

      Parameters:
      cls - the class to convert, may be null
      Returns:
      the corresponding primitive type if cls is a wrapper class, null otherwise
      Since:
      2.4
      See Also:
    • classForName

      public static Class<?> classForName(String name, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException
      Similar to Class.forName(String, boolean, ClassLoader) but resolves primitive names as well.
      Throws:
      ClassNotFoundException