Package org.jdbi.v3.core.internal
Class JdbiClassUtils
java.lang.Object
org.jdbi.v3.core.internal.JdbiClassUtils
Helper class for various internal reflection operations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T>createInstanceIfPossible(CheckedCallable<T> creator) Creates a new instance from aCheckedCallableinstance if possible.static booleanReturns true if a specific class can be loaded.static MethodmethodLookup(Class<?> klass, String methodName, Class<?>... parameterTypes) Lookup a specific method name related to a class.safeMethodLookup(Class<?> klass, String methodName, Class<?>... parameterTypes) Lookup a specific method name related to a class.static Object[]safeVarargs(Object... args) Safely move arguments passed from from a varargs call to a call that expects an array of objects.superTypes(Class<?> type) Returns all supertypes to a given type.
-
Field Details
-
NO_ARGS
-
-
Constructor Details
-
JdbiClassUtils
private JdbiClassUtils()
-
-
Method Details
-
isPresent
Returns true if a specific class can be loaded.- Parameters:
klass- The class- Returns:
- True if it can be loaded, false otherwise
-
methodLookup
Lookup a specific method name related to a class. This helper triesClass.getMethod(String, Class[])first, then falls back toClass.getDeclaredMethod(String, Class[]).- Parameters:
klass- A classmethodName- A method nameparameterTypes- All parameter types for the method- Returns:
- A
Methodobject - Throws:
IllegalStateException- If the method could not be found
-
safeMethodLookup
public static Optional<Method> safeMethodLookup(Class<?> klass, String methodName, Class<?>... parameterTypes) Lookup a specific method name related to a class. This helper triesClass.getMethod(String, Class[])first, then falls back toClass.getDeclaredMethod(String, Class[]).- Parameters:
klass- A classmethodName- A method nameparameterTypes- All parameter types for the method- Returns:
- A
Methodobject wrapped in anOptionalif the method could be found,Optional.empty()otherwise
-
createInstanceIfPossible
Creates a new instance from aCheckedCallableinstance if possible.- Type Parameters:
T- The type of the new instance- Parameters:
creator- ACheckedCallableinstance which returns a new instance or throws any of the exceptions out ofClass.getConstructor(Class[])orConstructor.newInstance(Object...)- Returns:
- A new instance wrapped in an
OptionalorOptional.empty()if aReflectiveOperationExceptionorSecurityExceptionoccured
-
superTypes
Returns all supertypes to a given type. -
safeVarargs
Safely move arguments passed from from a varargs call to a call that expects an array of objects.- Parameters:
args- A list of objects. May be null or empty- Returns:
- Returns an Array of objects. If the input was null, returns an empty array, otherwise all arguments as an array
-