Class ClassUtil

java.lang.Object
org.fastnate.util.ClassUtil

public final class ClassUtil extends Object
Helper for inspection of classes.
Author:
Tobias Liefke
  • Method Details

    • convertNumber

      public static <N extends Number> N convertNumber(Number number, Class<N> targetType)
      Tries to convert the given number to the given type.
      Parameters:
      number - the number that we have
      targetType - 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 class
      superClass - the superclass or interface which specifies the generic type variable
      argumentIndex - 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 parameters
      declaringClass - the class that declared the attribute
      attributeType - 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

      public static String getCallerMethod()
      Resolves the name of the method that called the caller of this method.
      Returns:
      the name of the caller
    • getCallerMethod

      public static String getCallerMethod(Class<?> callerClass)
      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