Class ClassUtils

java.lang.Object
com.vaadin.cdi.util.ClassUtils

@Typed public abstract class ClassUtils extends Object
  • Method Details

    • getClassLoader

      public static ClassLoader getClassLoader(Object o)
      Detect the right ClassLoader. The lookup order is determined by:
      1. ContextClassLoader of the current Thread
      2. ClassLoader of the given Object 'o'
      3. ClassLoader of this very ClassUtils class
      Parameters:
      o - if not null it may get used to detect the classloader.
      Returns:
      The ClassLoader which should get used to create new instances
    • isProxyableClass

      public static boolean isProxyableClass(Type type)
      Checks whether the CDI rules for proxyable beans are met. See CDI spec unproxyable bean types
      Parameters:
      type -
      Returns:
      true if all proxy conditions are met, false otherwise
    • tryToLoadClassForName

      public static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType)
      Tries to load a class based on the given name and interface or abstract class.
      Type Parameters:
      T - current type
      Parameters:
      name - name of the concrete class
      targetType - target type (interface or abstract class)
      Returns:
      loaded class or null if it isn't in the classpath
    • tryToLoadClassForName

      public static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType, ClassLoader classLoader)
      Tries to load a class based on the given name and interface or abstract class.
      Type Parameters:
      T - current type
      Parameters:
      name - name of the concrete class
      targetType - target type (interface or abstract class)
      classLoader - The ClassLoader.
      Returns:
      loaded class or null if it isn't in the classpath
    • tryToLoadClassForName

      public static Class tryToLoadClassForName(String name)
      Tries to load a class based on the given name
      Parameters:
      name - name of the class
      Returns:
      loaded class or null if it isn't in the classpath
    • tryToLoadClassForName

      public static Class tryToLoadClassForName(String name, ClassLoader classLoader)
      Tries to load a class based on the given name
      Parameters:
      name - name of the class
      classLoader - The ClassLoader.
      Returns:
      loaded class or null if it isn't in the classpath
    • loadClassForName

      public static Class loadClassForName(String name) throws ClassNotFoundException
      Loads class for the given name
      Parameters:
      name - name of the class
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if the class can't be loaded
    • tryToInstantiateClass

      public static <T> T tryToInstantiateClass(Class<T> targetClass)
      Instantiates a given class via the default constructor
      Type Parameters:
      T - current type
      Parameters:
      targetClass - class which should be instantiated
      Returns:
      created instance or null if the instantiation failed
    • tryToInstantiateClassForName

      public static <T> T tryToInstantiateClassForName(String className, Class<T> targetType)
      Tries to instantiate a class for the given name and type via the default constructor
      Type Parameters:
      T - current type
      Parameters:
      className - name of the class
      targetType - target type
      Returns:
      created instance or null if the instantiation failed
    • tryToInstantiateClassForName

      public static Object tryToInstantiateClassForName(String className)
      Tries to instantiate a class for the given name via the default constructor
      Parameters:
      className - name of the class
      Returns:
      created instance or null if the instantiation failed
    • instantiateClassForName

      public static Object instantiateClassForName(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
      Creates an instance for the given class-name
      Parameters:
      className - name of the class which should be instantiated
      Returns:
      created instance
      Throws:
      ClassNotFoundException - if the instantiation failed
      IllegalAccessException - if the instantiation failed
      InstantiationException - if the instantiation failed
    • getJarVersion

      public static String getJarVersion(Class targetClass)
      Reads the version of the jar which contains the given class
      Parameters:
      targetClass - class within the jar
      Returns:
      version-string which has been found in the manifest or null if there is no version information available
    • getRevision

      public static String getRevision(Class targetClass)
      Reads the VCS revision which was used for creating the jar
      Parameters:
      targetClass - class within the jar
      Returns:
      revision-string which has been found in the manifest or null if there is no information available
    • containsMethod

      public static boolean containsMethod(Class<?> targetClass, Method method)
      Checks if the given class contains a method with the same signature.
      Parameters:
      targetClass - The class to check
      method - The source method
      Returns:
      if it contains a method with the same signature.
    • extractMethod

      public static Method extractMethod(Class<?> clazz, Method sourceMethod)
      Extracts a method with same signature as the source method.
      Parameters:
      clazz - The target class
      sourceMethod - The source method.
      Returns:
      the extracted method or null
    • extractMethod

      public static Method extractMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
      Extract a method with the given name and parameterTypes. Return null if no such visible method exists on the given class.
      Parameters:
      clazz -
      methodName -
      parameterTypes -
      Returns:
    • containsPossiblyGenericMethod

      public static boolean containsPossiblyGenericMethod(Class<?> targetClass, Method method)
      Checks if the given class has a method with the same signature, taking in to account generic types
      Parameters:
      targetClass -
      method -
      Returns:
      if it contains a method with the same signature.
    • extractPossiblyGenericMethod

      public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod)
      Extracts a method matching the source method, allowing generic type parameters to be substituted as long as they are properly castable.
      Parameters:
      clazz - The target class
      sourceMethod - The source method.
      Returns:
      the extracted method or null
    • returns

      public static boolean returns(Method method, Class<?> clazz)