Class Classes

java.lang.Object
org.linkki.util.reflection.Classes

public class Classes extends Object
Utility for handling Classes.
  • Method Details

    • getType

      public static <T> Class<? extends T> getType(Supplier<Class<? extends T>> typeSupplier, Class<? extends T> aptFallback)
      Wraps the call to the given type supplier with a try-catch-block to catch MirroredTypeException. Returns the fallback type in case of a MirroredTypeException.

      This method must be used for all type access in annotations and aspects which may be loaded by annotation processor. While processing the annotation the referenced type may not be compiled yet. In this case a MirroredTypeException is thrown. The annotation processor should proceed with the fallback type.

      Parameters:
      typeSupplier - the supplier that accesses the type
      aptFallback - the fallback which is returned in case of a MirroredTypeException
      Returns:
      The type returned by the supplier or the fallback in case of a MirroredTypeException
    • getTypeName

      public static String getTypeName(Supplier<? extends Class<?>> classSupplier)
      Returns the name of the class which is provided by the given supplier. This method can be safely used in an annotation processors.
      Parameters:
      classSupplier - A supplier that gives the class for which the type name is requested
      Returns:
      The qualified name of the class which is returned by the given supplier
    • instantiate

      public static <T> T instantiate(Supplier<Class<? extends T>> classSupplier, Class<? extends T> aptFallback)
      Instantiates the class which is returned by the given supplier by calling the no-arguments constructor. This method can be safely used in an annotation processors.
      Type Parameters:
      T - the class
      Parameters:
      classSupplier - The supplier which gives access to the class
      Returns:
      an instance of the class
      Throws:
      IllegalArgumentException - if the class has no accessible no-arguments constructor or if calling it fails for any reason
    • instantiate

      public static <T> T instantiate(Class<T> clazz)
      Instantiates the given class with its no-arguments constructor.
      Type Parameters:
      T - the class
      Parameters:
      clazz - the class
      Returns:
      an instance of the class
      Throws:
      IllegalArgumentException - if the class has no accessible no-arguments constructor or if calling it fails for any reason