Package org.fastnate.util
Class ClassUtil
java.lang.Object
org.fastnate.util.ClassUtil
Helper for inspection of classes.
- Author:
- Tobias Liefke
-
Method Summary
Modifier and TypeMethodDescriptionstatic <N extends Number>
NconvertNumber(Number number, Class<N> targetType) Tries to convert the given number to the given type.static <T,I> Class <T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> superClass, int argumentIndex) Resolves the actual binding of a generic type that was specified in a superclass and bound in a subclass.static <T,I> Class <T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> declaringClass, Type attributeType) Resolves the actual binding of a generic type to a specific class by inspecting type variables in the declaring class and the (sub)class of the object.static StringResolves the name of the method that called the caller of this method.static StringgetCallerMethod(Class<?> callerClass) Resolves the name of the method that called the caller of this method.
-
Method Details
-
convertNumber
Tries to convert the given number to the given type.- Parameters:
number- the number that we havetargetType- the type that we need- Returns:
- the number in the given type
- Throws:
IllegalArgumentException- if the target type is not a common number type
-
getActualTypeBinding
public static <T,I> Class<T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> superClass, int argumentIndex) Resolves the actual binding of a generic type that was specified in a superclass and bound in a subclass.- Parameters:
instanceClass- the implementing classsuperClass- the superclass or interface which specifies the generic type variableargumentIndex- the index of the type variable in the superclass definition (0 = the first type variable)- Returns:
- the bound class for the variable in instanceClass
-
getActualTypeBinding
public static <T,I> Class<T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> declaringClass, Type attributeType) Resolves the actual binding of a generic type to a specific class by inspecting type variables in the declaring class and the (sub)class of the object.- Parameters:
instanceClass- the class that implements the object and may contain the binding of the type parametersdeclaringClass- the class that declared the attributeattributeType- the return type, parameter type or field type of the attribute that may contain references to type parameters- Returns:
- the qualified type of the attribute according to the instance class
-
getCallerMethod
Resolves the name of the method that called the caller of this method.- Returns:
- the name of the caller
-
getCallerMethod
Resolves the name of the method that called the caller of this method. Steps up until the caller belongs to the given class- Parameters:
callerClass- the class that the method belongs to- Returns:
- the name of the caller
-