Class ExtractionUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of the extraction inextractAssigningConstructor(Class, List).static enumChecks the relation between primitive and boxed types. -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>classForName(String name, boolean initialize, ClassLoader classLoader) Similar toClass.forName(String, boolean, ClassLoader)but resolves primitive names as well.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).extractAssigningConstructor(Class<?> clazz, List<Field> fields) Checks whether the given constructor takes all of the given fields with matching (possibly primitive) type and name.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.getStructuredFieldGetter(Class<?> clazz, Field field) Checks for a field getter of a structured type.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 booleanChecks whether a field is directly readable without a getter.static booleanChecks 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 Details
-
collectMethods
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
Validates the characteristics of a class for aStructuredTypesuch as accessibility. -
getStructuredField
Returns the field of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors. -
getStructuredFieldGetter
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
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
Checks for an invokable constructor matching the given arguments. -
isStructuredFieldDirectlyReadable
Checks whether a field is directly readable without a getter. -
isStructuredFieldDirectlyWritable
Checks whether a field is directly writable without a setter or constructor. -
extractSimpleGeneric
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
Resolves a variable type while accepting a context for resolution. -
getClassFromType
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 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
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
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:
-
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
-