Class ExtractionUtils
- java.lang.Object
-
- org.apache.flink.table.types.extraction.ExtractionUtils
-
@Internal public final class ExtractionUtils extends Object
Utilities for performing reflection tasks.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtractionUtils.AssigningConstructorResult of the extraction inextractAssigningConstructor(Class, List).static classExtractionUtils.AutoboxingChecks the relation between primitive and boxed types.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckStateDataType(DataType dataType)Checks whether the given data type can be used as a state entry forProcessTableFunction.static Class<?>classForName(String name, boolean initialize, ClassLoader classLoader)Similar toClass.forName(String, boolean, ClassLoader)but resolves primitive names as well.static List<Method>collectMethods(Class<?> function, String methodName)Collects methods of the given name.static StringcreateMethodSignatureString(String methodName, Class<?>[] parameters, Class<?> returnType)Creates a method signature string likeint eval(Integer, String).static ExtractionUtils.AssigningConstructorextractAssigningConstructor(Class<?> clazz, List<Field> fields)Checks whether the given constructor takes all of the given fields with matching (possibly primitive) type and name.static Optional<Class<?>>extractSimpleGeneric(Class<?> baseClass, Class<?> clazz, int pos)A minimal version to extract a generic parameter from a given class.static Class<?>getClassFromType(Type type)Gets the associated class type from a Type parameter.static FieldgetStructuredField(Class<?> clazz, String fieldName)Returns the field of a structured type.static Optional<Method>getStructuredFieldGetter(Class<?> clazz, Field field)Checks for a field getter of a structured type.static Optional<Method>getStructuredFieldSetter(Class<?> clazz, Field field)Checks for a field setters of a structured type.static booleanhasInvokableConstructor(Class<?> clazz, Class<?>... classes)Checks for an invokable constructor matching the given arguments.static booleanisAssignable(Class<?> cls, Class<?> toClass, ExtractionUtils.Autoboxing autoboxing)Checks if oneClasscan be assigned to a variable of anotherClass.static booleanisInvokable(ExtractionUtils.Autoboxing autoboxing, Executable executable, Class<?>... classes)Checks whether a method/constructor can be called with the given argument classes.static booleanisStructuredFieldDirectlyReadable(Field field)Checks whether a field is directly readable without a getter.static booleanisStructuredFieldDirectlyWritable(Field field)Checks whether a field is directly writable without a setter or constructor.static Class<?>primitiveToWrapper(Class<?> cls)Converts the specified primitive Class object to its corresponding wrapper Class object.static TyperesolveVariableWithClassContext(Type contextType, Type type)Resolves a variable type while accepting a context for resolution.static voidvalidateStructuredClass(Class<?> clazz)Validates the characteristics of a class for aStructuredTypesuch as accessibility.static Class<?>wrapperToPrimitive(Class<?> cls)Converts the specified wrapper class to its corresponding primitive class.
-
-
-
Method Detail
-
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.nullis a wildcard.E.g.,
(int.class, int.class)matchesf(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 likeint eval(Integer, String).
-
validateStructuredClass
public static void validateStructuredClass(Class<?> clazz)
Validates the characteristics of a class for aStructuredTypesuch 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.
-
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.
-
checkStateDataType
public static void checkStateDataType(DataType dataType)
Checks whether the given data type can be used as a state entry forProcessTableFunction.
-
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 oneClasscan be assigned to a variable of anotherClass.Unlike the
Class.isAssignableFrom(java.lang.Class)method, this method takes into account widenings of primitive classes andnulls.Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.
Nullmay be assigned to any reference type. This method will returntrueifnullis passed in and the toClass is non-primitive.Specifically, this method tests whether the type represented by the specified
Classparameter can be converted to the type represented by thisClassobject 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 nulltoClass- the Class to try to assign into, returns false if nullautoboxing- whether to use implicit autoboxing/unboxing between primitives and wrappersautoboxing- checks whether null would end up in a primitive type and forbids it- Returns:
trueif 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, returningVoid.TYPE.- Parameters:
cls- the class to convert, may be null- Returns:
- the wrapper class for
clsorclsifclsis not a primitive.nullif 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.TYPEforInteger.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
clsis a wrapper class, null otherwise - Since:
- 2.4
- See Also:
primitiveToWrapper(Class)
-
classForName
public static Class<?> classForName(String name, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException
Similar toClass.forName(String, boolean, ClassLoader)but resolves primitive names as well.- Throws:
ClassNotFoundException
-
-