Package com.chemaxon.apidiscovery
Class Discovery
- java.lang.Object
-
- com.chemaxon.apidiscovery.Discovery
-
@Beta @PublicAPI public final class Discovery extends Object
Utility methods for parameter discovery.Please note that this class is marked with
Beta
annotation, so it can be subject of incompatible changes or removal in later releases.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Annotation>
TgetAnnotation(Class<T> a, Object o)
Retrieve an annotation on an object.static <T extends Annotation>
TgetAnnotationForClass(Class<T> annotationClass, Class<?> clazz)
Retrieve annotation for a class.static <T extends Annotation>
com.google.common.base.Optional<T>getAnnotationIfPresent(Class<T> a, Object o)
Retrieve an annotation on an object if present.static Description
getDescriptionAnnotation(Object o)
Retrieve the description annotation on an object.static <T> com.google.common.base.Optional<ParameterBuilder<T>>
initializeBuilderIfExists(T o)
Create initial Builder if possible.static boolean
isParametrized(Object o)
Check if an object is parametrized.static <T> List<CreatorWrapper<T>>
listCreators(Object o, Class<T> targetType)
CreatorWrapper acts as a type-dependent service loader.static <T> List<InstanceWrapper<T>>
listInstances(Class<T> type)
Collect instances of a specific type.static List<ParameterWrapper>
listParameters(Object o)
Retrieve parameters for a mutable parameter object.static <T> com.google.common.base.Optional<InstanceWrapper<T>>
selectInstance(Class<T> type, String shortName)
Look up an instance by its short name.
-
-
-
Method Detail
-
listInstances
@Beta public static <T> List<InstanceWrapper<T>> listInstances(Class<T> type)
Collect instances of a specific type.- Type Parameters:
T
- Type to collect- Parameters:
type
- Type to collect- Returns:
- One or more instances of the specified type. Interfaces are retrieved as services; classes are instantiated with their nullary constructors; enums are enumerated
-
selectInstance
public static <T> com.google.common.base.Optional<InstanceWrapper<T>> selectInstance(Class<T> type, String shortName)
Look up an instance by its short name.- Type Parameters:
T
- Type to collect- Parameters:
type
- Type to collect (bylistInstances(java.lang.Class)
shortName
- Short name of the instance to select- Returns:
- The first matching instance if found
-
isParametrized
@Beta public static boolean isParametrized(Object o)
Check if an object is parametrized.- Parameters:
o
- Object in question- Returns:
- true if o is parametrized
-
listParameters
@Beta public static List<ParameterWrapper> listParameters(Object o)
Retrieve parameters for a mutable parameter object. Parameter set mode is specified byParametrized.parameterSetMode()
on the objectsParametrized
annotation.- Parameters:
o
- Mutable parametrized object annotated withParametrized
- Returns:
- Parameters of o wrapped
- Throws:
IllegalArgumentException
- when o is not annotated withParametrized
or no parameters found
-
getAnnotationForClass
@Beta public static <T extends Annotation> T getAnnotationForClass(Class<T> annotationClass, Class<?> clazz)
Retrieve annotation for a class. Note that enum constants are not handled by this method.- Type Parameters:
T
- Annotation class- Parameters:
annotationClass
- Annotation classclazz
- Target class- Returns:
- Annotation retrieved
- Throws:
IllegalArgumentException
- when noDescription
annotation found
-
getAnnotationIfPresent
@Beta public static <T extends Annotation> com.google.common.base.Optional<T> getAnnotationIfPresent(Class<T> a, Object o)
Retrieve an annotation on an object if present.- Type Parameters:
T
- Annotation class- Parameters:
a
- Annotation classo
- Object to examine- Returns:
- The description annotation if exist
-
getAnnotation
@Beta public static <T extends Annotation> T getAnnotation(Class<T> a, Object o)
Retrieve an annotation on an object.- Type Parameters:
T
- Annotation class- Parameters:
a
- Annotation classo
- Object to examine- Returns:
- The annotation if exists or null; If o is an instance of an enum then enum constant annotation is retrieved
- Throws:
IllegalArgumentException
- when no annotation found
-
getDescriptionAnnotation
@Beta public static Description getDescriptionAnnotation(Object o)
Retrieve the description annotation on an object.- Parameters:
o
- Object to examine- Returns:
- The description annotation if exists or null; If o is an instance of an enum then enum constant annotation is retrieved
- Throws:
IllegalArgumentException
- when noDescription
annotation found
-
listCreators
@Beta public static <T> List<CreatorWrapper<T>> listCreators(Object o, Class<T> targetType)
CreatorWrapper acts as a type-dependent service loader.Note that the order of the returned list is defined by
- Type Parameters:
T
- type to be created- Parameters:
targetType
- type to be createdo
- Instance on which the creators should be called- Returns:
- All distinct creator parameters
-
initializeBuilderIfExists
@Beta public static <T> com.google.common.base.Optional<ParameterBuilder<T>> initializeBuilderIfExists(T o)
Create initial Builder if possible.Builder association is identified by annotation BuilderClass
- Type Parameters:
T
- Parameter object type- Parameters:
o
- An object- Returns:
- An associated builder instance if the parameter object has associated builder.
-
-