Annotates an interface for which a dependency-injected
implementation is to be generated. The generated class will
have the name of the type annotated, appended with _Impl. For
example, @Component interface MyComponent {...} will produce an implementation named
MyComponent_Impl.
Component methods
Every type annotated with @Component must contain at least one abstract component
method. Component methods may have any name, but must have no parameters and return a bound type.
A bound type is one of the following:
- an
injectedtype - a
providedtype - the type of one of the parameters of the
factory method Provider<T>, whereTis one of the types described above
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceA builder for a component.static @interfaceA factory for a component. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIftrue, the generated component implementation will contain a staticmockBuildermethod.Class<?>[]A list of classes annotated withModuluswhose bindings are used to generate the component implementation.booleanBy default, themockBuilder(orwithMocks) method is only package-private.
-
Element Details
-
modules
Class<?>[] modulesA list of classes annotated withModuluswhose bindings are used to generate the component implementation.- Default:
{}
-
mockBuilder
boolean mockBuilderIftrue, the generated component implementation will contain a staticmockBuildermethod. However, if this component uses aBuilder, themockBuildermethod will not be generated; see Component.Builder.- Returns:
trueif themockBuildermethod should be generated.
- Default:
false
-
publicMockBuilder
boolean publicMockBuilderBy default, themockBuilder(orwithMocks) method is only package-private. This makes it harder to accidentally invoke from production code.In test code,
mockBuildercan always be invoked, even if it is only package-visible, by placing a forwarding delegate class in the correct package. For example, ifMyComponentis defined in packagecom.my.component, the forwarding delegate class could live insrc/test/java/com/my/componentand look like this:public class MyComponentAccess { public static MyComponent_Impl.MockBuilder mockBuilder() { return MyComponent_Impl.mockBuilder(); } }- Returns:
trueif themockBuilder(orwithMocks) method should have the same visibility as the component.
- Default:
false
-