Package org.linkki.util
Class Classes
- java.lang.Object
-
- org.linkki.util.Classes
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 catchMirroredTypeException.static StringgetTypeName(Supplier<? extends Class<?>> classSupplier)Returns the name of the class which is provided by the given supplier.static <T> Tinstantiate(Class<T> clazz)Instantiates the given class with its no-arguments constructor.static <T> Tinstantiate(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.
-
-
-
Method Detail
-
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 catchMirroredTypeException. Returns the fallback type in case of aMirroredTypeException.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
MirroredTypeExceptionis thrown. The annotation processor should proceed with the fallback type.- Parameters:
typeSupplier- the supplier that accesses the typeaptFallback- the fallback which is returned in case of aMirroredTypeException- 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
-
-