Top Description Fields Methods
org.glassfish.hk2.api

public Interface ClassAnalyzer

Annotations
@Contract
Imports
java.lang.reflect.Constructor, .Field, .Method, java.util.Set, org.jvnet.hk2.annotations.Contract

When HK2 automatically analyzes a class to find the constructor, fields, initializer methods and postConstruct and preDestroy methods it uses this service to analyze the class. This analyzer is only used for descriptors that are not pre-reified and which are not provided by factories.

HK2 will provide a default implementation of this service (with the name "default"). However, individual descriptors may choose a different class analyzer should they so choose. All user supplied implementations of this service must have a name. Implementations of this service must not be ClassAnalyzers for themselves.

The method ServiceLocator#setDefaultClassAnalyzerName(String) can be used to set the global ClassAnalyzer name that will be the name of the ClassAnalyzer used when the method Descriptor#getClassAnalysisName() returns null

Implementations of ClassAnalyzer will be instantiated as soon as they are added to HK2 in order to avoid deadlocks and circular references. Therefore it is recommended that implementations of ClassAnalyzer make liberal use of jakarta.inject.Provider or IterableProvider when injecting dependent services so that these services are not instantiated when the ClassAnalyzer is created

Author
jwells

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_IMPLEMENTATION_NAME

The name of the default ClassAnalyzer service

Method Summary

Modifier and TypeMethod and Description
public <T> Constructor<T>

Returns:

The non-null constructor to use for creating this service
getConstructor
(Class<T>
the non-null class to analyze
clazz
)

Will return the constructor that it to be used when constructing this service

The default implementation will use the zero-arg constructor if no single constructor with Inject is found.

public <T> Set<Field>

Returns:

A non-null but possibly empty set of initialization fields
getFields
(Class<T>
the non-null class to analyze
clazz
)

Will return the set of initializer fields to be used when initializing this service

The default implementation will return all fields marked with Inject or that have a parameter that is covered by an InjectionResolver

public <T> Set<Method>

Returns:

A non-null but possibly empty set of initialization methods
getInitializerMethods
(Class<T>
the non-null class to analyze
clazz
)

Will return the set of initializer method to be used when initializing this service

The default implementation will return all methods marked with Inject or that have a parameter that is covered by an InjectionResolver and the InjectionResolver#isMethodParameterIndicator() is set to true.

public <T> Method

Returns:

A possibly null method representing the postConstruct method to call
getPostConstructMethod
(Class<T>
the non-null class to analyze
clazz
)

Will return the postConstruct method of the class

The default implementation will return the PostConstruct#postConstruct() method or the method annotated with PostConstruct

public <T> Method

Returns:

A possibly null method representing the preDestroy method to call
getPreDestroyMethod
(Class<T>
the non-null class to analyze
clazz
)

Will return the preDestroy method of the class

The default implementation will return the PreDestroy#preDestroy() method or the method annotated with PreDestroy

Field Detail

DEFAULT_IMPLEMENTATION_NAMEback to summary
public static final String DEFAULT_IMPLEMENTATION_NAME

The name of the default ClassAnalyzer service

Method Detail

getConstructorback to summary
public <T> Constructor<T> getConstructor(Class<T> clazz) throws MultiException, NoSuchMethodException

Will return the constructor that it to be used when constructing this service

The default implementation will use the zero-arg constructor if no single constructor with Inject is found. Also will return any constructor that is covered by an InjectionResolver and the InjectionResolver#isConstructorParameterIndicator() is set to true

Parameters
clazz:Class<T>

the non-null class to analyze

Returns:Constructor<T>

The non-null constructor to use for creating this service

Exceptions
MultiException:
on an error when analyzing the class
NoSuchMethodException:
if there was no available constructor
getFieldsback to summary
public <T> Set<Field> getFields(Class<T> clazz) throws MultiException

Will return the set of initializer fields to be used when initializing this service

The default implementation will return all fields marked with Inject or that have a parameter that is covered by an InjectionResolver

Parameters
clazz:Class<T>

the non-null class to analyze

Returns:Set<Field>

A non-null but possibly empty set of initialization fields

Exceptions
MultiException:
on an error when analyzing the class
getInitializerMethodsback to summary
public <T> Set<Method> getInitializerMethods(Class<T> clazz) throws MultiException

Will return the set of initializer method to be used when initializing this service

The default implementation will return all methods marked with Inject or that have a parameter that is covered by an InjectionResolver and the InjectionResolver#isMethodParameterIndicator() is set to true. Also, any method that has a parameter marked with org.glassfish.hk2.api.messaging.SubscribeTo will NOT be returned, as these methods are instead meant to be called when an event is fired

Parameters
clazz:Class<T>

the non-null class to analyze

Returns:Set<Method>

A non-null but possibly empty set of initialization methods

Exceptions
MultiException:
on an error when analyzing the class
getPostConstructMethodback to summary
public <T> Method getPostConstructMethod(Class<T> clazz) throws MultiException

Will return the postConstruct method of the class

The default implementation will return the PostConstruct#postConstruct() method or the method annotated with PostConstruct

Parameters
clazz:Class<T>

the non-null class to analyze

Returns:Method

A possibly null method representing the postConstruct method to call

Exceptions
MultiException:
on an error when analyzing the class
getPreDestroyMethodback to summary
public <T> Method getPreDestroyMethod(Class<T> clazz) throws MultiException

Will return the preDestroy method of the class

The default implementation will return the PreDestroy#preDestroy() method or the method annotated with PreDestroy

Parameters
clazz:Class<T>

the non-null class to analyze

Returns:Method

A possibly null method representing the preDestroy method to call

Exceptions
MultiException:
on an error when analyzing the class