Class ClassUtils
java.lang.Object
org.springframework.data.repository.util.ClassUtils
Utility class to work with classes.
- Author:
- Oliver Gierke, Mark Paluch, Johannes Englmeier
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertReturnTypeAssignable
(Method method, Class<?>... types) Asserts the givenMethod
's return type to be one of the given types.static int
getNumberOfOccurences
(Method method, Class<?> type) Deprecated.static int
getNumberOfOccurrences
(Method method, Class<?> parameterType) Returns the number of occurrences for the givenparameter type
in the givenMethod
.static boolean
hasParameterOfType
(Method method, Class<?> type) Returns whether the givenMethod
has a parameter of the given type.static boolean
hasProperty
(Class<?> type, String property) Returns whether the given class contains a property with the given name.static void
ifPresent
(String className, ClassLoader classLoader, Consumer<Class<?>> action) static boolean
isGenericRepositoryInterface
(Class<?> interfaze) Returns wthere the given type is theRepository
interface.static boolean
isGenericRepositoryInterface
(String interfaceName) Returns whether the given type name is a repository interface name.static boolean
isOfType
(Object object, Collection<Class<?>> types) Returns whether the given object is of one of the given types.static void
Helper method to extract the original exception that can possibly occur during a reflection call.
-
Method Details
-
hasProperty
Returns whether the given class contains a property with the given name.- Parameters:
type
-property
-- Returns:
-
ifPresent
public static void ifPresent(String className, @Nullable ClassLoader classLoader, Consumer<Class<?>> action) Determine whether theClass
identified by the suppliedclassName
is present * and can be loaded and call theaction
if theClass
could be loaded.- Parameters:
className
- the name of the class to check.classLoader
- the class loader to use.action
- the action callback to notify. (may benull
which indicates the default class loader)- Throws:
IllegalStateException
- if the corresponding class is resolvable but there was a readability mismatch in the inheritance hierarchy of the class (typically a missing dependency declaration in a Jigsaw module definition for a superclass or interface implemented by the class to be checked here)
-
isGenericRepositoryInterface
Returns wthere the given type is theRepository
interface.- Parameters:
interfaze
-- Returns:
-
isGenericRepositoryInterface
Returns whether the given type name is a repository interface name.- Parameters:
interfaceName
-- Returns:
-
getNumberOfOccurences
Deprecated. -
getNumberOfOccurrences
Returns the number of occurrences for the givenparameter type
in the givenMethod
.- Parameters:
method
-Method
to evaluate.parameterType
-Class
of theMethod
parameter type to count.- Returns:
- the number of occurrences for the given
parameter type
in the givenMethod
. - See Also:
-
assertReturnTypeAssignable
Asserts the givenMethod
's return type to be one of the given types. Will unwrap known wrapper types before the assignment check (seeQueryExecutionConverters
).- Parameters:
method
- must not be null.types
- must not be null or empty.
-
isOfType
Returns whether the given object is of one of the given types. Will return false for null.- Parameters:
object
-types
-- Returns:
-
hasParameterOfType
Returns whether the givenMethod
has a parameter of the given type.- Parameters:
method
-type
-- Returns:
-
unwrapReflectionException
Helper method to extract the original exception that can possibly occur during a reflection call.- Parameters:
ex
-- Throws:
Throwable
-
getNumberOfOccurrences(Method, Class)
.