private static class Elements.RecordingBinder extends java.lang.Object implements Binder, PrivateBinder
Modifier and Type | Field and Description |
---|---|
private java.util.List<Element> |
elements |
private java.util.Map<Module,Elements.ModuleInfo> |
modules |
private ModuleSource |
moduleSource
The current modules stack
|
private Elements.RecordingBinder |
parent
The binder where exposed bindings will be created
|
private java.util.List<Elements.RecordingBinder> |
privateBinders
All children private binders, so we can scan through them.
|
private PrivateElementsImpl |
privateElements |
private java.util.Set<ModuleAnnotatedMethodScanner> |
scanners |
private java.lang.Object |
source |
private SourceProvider |
sourceProvider |
private Stage |
stage |
Modifier | Constructor and Description |
---|---|
private |
RecordingBinder(Elements.RecordingBinder prototype,
java.lang.Object source,
SourceProvider sourceProvider)
Creates a recording binder that's backed by
prototype . |
private |
RecordingBinder(Elements.RecordingBinder parent,
PrivateElementsImpl privateElements)
Creates a private recording binder.
|
private |
RecordingBinder(Stage stage) |
Modifier and Type | Method and Description |
---|---|
void |
addError(Message message)
Records an error message to be presented to the user at a later time.
|
void |
addError(java.lang.String message,
java.lang.Object... arguments)
Records an error message which will be presented to the user at a later
time.
|
void |
addError(java.lang.Throwable t)
Records an exception, the full details of which will be logged, and the
message of which will be presented to the user at a later
time.
|
<T> AnnotatedBindingBuilder<T> |
bind(java.lang.Class<T> type)
See the EDSL examples at
Binder . |
<T> AnnotatedBindingBuilder<T> |
bind(Key<T> key)
See the EDSL examples at
Binder . |
<T> AnnotatedBindingBuilder<T> |
bind(TypeLiteral<T> typeLiteral)
See the EDSL examples at
Binder . |
AnnotatedConstantBindingBuilder |
bindConstant()
See the EDSL examples at
Binder . |
void |
bindInterceptor(Matcher<? super java.lang.Class<?>> classMatcher,
Matcher<? super java.lang.reflect.Method> methodMatcher,
org.aopalliance.intercept.MethodInterceptor... interceptors)
Binds method interceptor[s] to methods matched by class and method matchers.
|
void |
bindListener(Matcher<? super Binding<?>> bindingMatcher,
ProvisionListener... listeners)
Registers listeners for provisioned objects.
|
void |
bindListener(Matcher<? super TypeLiteral<?>> typeMatcher,
TypeListener listener)
Registers a listener for injectable types.
|
void |
bindScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
Scope scope)
Binds a scope to an annotation.
|
void |
convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
TypeConverter converter)
Binds a type converter.
|
Stage |
currentStage()
Gets the current stage.
|
void |
disableCircularProxies()
Prevents Guice from injecting dependencies that form a cycle, unless broken by a
Provider . |
AnnotatedElementBuilder |
expose(java.lang.Class<?> type)
Makes a binding for
type available to the enclosing environment. |
void |
expose(Key<?> key)
Makes the binding for
key available to the enclosing environment |
AnnotatedElementBuilder |
expose(TypeLiteral<?> type)
Makes a binding for
type available to the enclosing environment. |
private <T> AnnotatedElementBuilder |
exposeInternal(Key<T> key) |
private ElementSource |
getElementSource() |
<T> MembersInjector<T> |
getMembersInjector(java.lang.Class<T> type)
Returns the members injector used to inject dependencies into methods and fields on instances
of the given type
T . |
<T> MembersInjector<T> |
getMembersInjector(TypeLiteral<T> typeLiteral)
Returns the members injector used to inject dependencies into methods and fields on instances
of the given type
T . |
private ModuleSource |
getModuleSource(java.lang.Object module) |
private java.lang.StackTraceElement[] |
getPartialCallStack(java.lang.StackTraceElement[] callStack)
Removes the
moduleSource call stack from the beginning of current call stack. |
<T> Provider<T> |
getProvider(java.lang.Class<T> type)
Returns the provider used to obtain instances for the given injection type.
|
<T> Provider<T> |
getProvider(Dependency<T> dependency)
Returns the provider used to obtain instances for the given injection key.
|
<T> Provider<T> |
getProvider(Key<T> key)
Returns the provider used to obtain instances for the given injection key.
|
void |
install(Module module)
Uses the given module to configure more bindings.
|
PrivateBinder |
newPrivateBinder()
Creates a new private child environment for bindings and other configuration.
|
void |
requestInjection(java.lang.Object instance)
Upon successful creation, the
Injector will inject instance fields
and methods of the given object. |
<T> void |
requestInjection(TypeLiteral<T> type,
T instance)
Upon successful creation, the
Injector will inject instance fields
and methods of the given object. |
void |
requestStaticInjection(java.lang.Class<?>... types)
Upon successful creation, the
Injector will inject static fields
and methods in the given classes. |
void |
requireAtInjectOnConstructors()
Requires that a @
Inject annotation exists on a constructor in order for
Guice to consider it an eligible injectable class. |
void |
requireExactBindingAnnotations()
Requires that Guice finds an exactly matching binding annotation.
|
void |
requireExplicitBindings()
Instructs the Injector that bindings must be listed in a Module in order to
be injected.
|
(package private) void |
scanForAnnotatedMethods()
Applies all scanners to the modules we've installed.
|
void |
scanModulesForAnnotatedMethods(ModuleAnnotatedMethodScanner scanner)
Adds a scanner that will look in all installed modules for annotations the scanner can parse,
and binds them like @Provides methods.
|
Elements.RecordingBinder |
skipSources(java.lang.Class... classesToSkip)
Returns a binder that skips
classesToSkip when identify the
calling code. |
java.lang.String |
toString() |
Elements.RecordingBinder |
withSource(java.lang.Object source)
Returns a binder that uses
source as the reference location for
configuration errors. |
private final Stage stage
private final java.util.Map<Module,Elements.ModuleInfo> modules
private final java.util.List<Element> elements
private final java.lang.Object source
private ModuleSource moduleSource
private final SourceProvider sourceProvider
private final java.util.Set<ModuleAnnotatedMethodScanner> scanners
private final Elements.RecordingBinder parent
private final PrivateElementsImpl privateElements
private final java.util.List<Elements.RecordingBinder> privateBinders
private RecordingBinder(Stage stage)
private RecordingBinder(Elements.RecordingBinder prototype, java.lang.Object source, SourceProvider sourceProvider)
prototype
.private RecordingBinder(Elements.RecordingBinder parent, PrivateElementsImpl privateElements)
public void bindInterceptor(Matcher<? super java.lang.Class<?>> classMatcher, Matcher<? super java.lang.reflect.Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors)
Binder
bindInterceptor
in interface Binder
classMatcher
- matches classes the interceptor should apply to. For
example: only(Runnable.class)
.methodMatcher
- matches methods the interceptor should apply to. For
example: annotatedWith(Transactional.class)
.interceptors
- to bind. The interceptors are called in the order they
are given.public void bindScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, Scope scope)
Binder
public void requestInjection(java.lang.Object instance)
Binder
Injector
will inject instance fields
and methods of the given object.requestInjection
in interface Binder
instance
- for which members will be injectedpublic <T> void requestInjection(TypeLiteral<T> type, T instance)
Binder
Injector
will inject instance fields
and methods of the given object.requestInjection
in interface Binder
type
- of instanceinstance
- for which members will be injectedpublic <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral)
Binder
T
. The returned members injector will not be valid until the main
Injector
has been created. The members injector will throw an IllegalStateException
if you try to use it beforehand.getMembersInjector
in interface Binder
typeLiteral
- type to get members injector forpublic <T> MembersInjector<T> getMembersInjector(java.lang.Class<T> type)
Binder
T
. The returned members injector will not be valid until the main
Injector
has been created. The members injector will throw an IllegalStateException
if you try to use it beforehand.getMembersInjector
in interface Binder
type
- type to get members injector forpublic void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
Binder
bindListener
in interface Binder
typeMatcher
- that matches injectable types the listener should be notified oflistener
- for injectable types matched by typeMatcherpublic void bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listeners)
Binder
Binder.bindListener(com.google.inject.matcher.Matcher<? super com.google.inject.TypeLiteral<?>>, com.google.inject.spi.TypeListener)
.bindListener
in interface Binder
bindingMatcher
- that matches bindings of provisioned objects the listener
should be notified oflisteners
- for provisioned objects matched by bindingMatcherpublic void requestStaticInjection(java.lang.Class<?>... types)
Binder
Injector
will inject static fields
and methods in the given classes.requestStaticInjection
in interface Binder
types
- for which static members will be injectedvoid scanForAnnotatedMethods()
public void install(Module module)
Binder
public Stage currentStage()
Binder
currentStage
in interface Binder
public void addError(java.lang.String message, java.lang.Object... arguments)
Binder
String.format(String, Object[])
to insert the arguments into the
message.public void addError(java.lang.Throwable t)
Binder
public void addError(Message message)
Binder
public <T> AnnotatedBindingBuilder<T> bind(Key<T> key)
Binder
Binder
.public <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
Binder
Binder
.public <T> AnnotatedBindingBuilder<T> bind(java.lang.Class<T> type)
Binder
Binder
.public AnnotatedConstantBindingBuilder bindConstant()
Binder
Binder
.bindConstant
in interface Binder
public <T> Provider<T> getProvider(Key<T> key)
Binder
Injector
has been
created. The provider will throw an IllegalStateException
if you
try to use it beforehand.getProvider
in interface Binder
public <T> Provider<T> getProvider(Dependency<T> dependency)
Binder
Injector
has been created. The provider will throw an IllegalStateException
if you
try to use it beforehand.getProvider
in interface Binder
public <T> Provider<T> getProvider(java.lang.Class<T> type)
Binder
Injector
has been
created. The provider will throw an IllegalStateException
if you
try to use it beforehand.getProvider
in interface Binder
public void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
Binder
convertToTypes
in interface Binder
typeMatcher
- matches types the converter can handleconverter
- converts valuespublic Elements.RecordingBinder withSource(java.lang.Object source)
Binder
source
as the reference location for
configuration errors. This is typically a StackTraceElement
for .java
source but it could any binding source, such as the
path to a .properties
file.withSource
in interface Binder
withSource
in interface PrivateBinder
source
- any object representing the source location and has a
concise toString()
valuepublic Elements.RecordingBinder skipSources(java.lang.Class... classesToSkip)
Binder
classesToSkip
when identify the
calling code. The caller's StackTraceElement
is used to locate
the source of configuration errors.skipSources
in interface Binder
skipSources
in interface PrivateBinder
classesToSkip
- library classes that create bindings on behalf of
their clients.public PrivateBinder newPrivateBinder()
Binder
PrivateModule
for details.newPrivateBinder
in interface Binder
public void disableCircularProxies()
Binder
Provider
. By default, circular dependencies are not disabled.
If a parent injector disables circular dependencies, then all child injectors (and private modules within that injector) also disable circular dependencies. If a parent does not disable circular dependencies, a child injector or private module may optionally declare itself as disabling circular dependencies. If it does, the behavior is limited only to that child or any grandchildren. No siblings of the child will disable circular dependencies.
disableCircularProxies
in interface Binder
public void requireExplicitBindings()
Binder
bind(Foo.class).to(FooImpl.class)
) are allowed, but the
implicit binding (FooImpl
) cannot be directly injected unless
it is also explicitly bound (bind(FooImpl.class)
).
Tools can still retrieve bindings for implicit bindings (bindings created
through a linked binding) if explicit bindings are required, however
Binding.getProvider()
will fail.
By default, explicit bindings are not required.
If a parent injector requires explicit bindings, then all child injectors (and private modules within that injector) also require explicit bindings. If a parent does not require explicit bindings, a child injector or private module may optionally declare itself as requiring explicit bindings. If it does, the behavior is limited only to that child or any grandchildren. No siblings of the child will require explicit bindings.
In the absence of an explicit binding for the target, linked bindings in child injectors create a binding for the target in the parent. Since this behavior can be surprising, it causes an error instead if explicit bindings are required. To avoid this error, add an explicit binding for the target, either in the child or the parent.
requireExplicitBindings
in interface Binder
public void requireAtInjectOnConstructors()
Binder
Inject
annotation exists on a constructor in order for
Guice to consider it an eligible injectable class. By default, Guice will inject classes that
have a no-args constructor if no @Inject
annotation exists on any
constructor.
If the class is bound using LinkedBindingBuilder.toConstructor(java.lang.reflect.Constructor<S>)
, Guice will still inject
that constructor regardless of annotations.
requireAtInjectOnConstructors
in interface Binder
public void requireExactBindingAnnotations()
Binder
@Named Foo
when attempting to inject
@Named("foo") Foo
.requireExactBindingAnnotations
in interface Binder
public void scanModulesForAnnotatedMethods(ModuleAnnotatedMethodScanner scanner)
Binder
scanModulesForAnnotatedMethods
in interface Binder
public void expose(Key<?> key)
PrivateBinder
key
available to the enclosing environmentexpose
in interface PrivateBinder
public AnnotatedElementBuilder expose(java.lang.Class<?> type)
PrivateBinder
type
available to the enclosing environment. Use annotatedWith()
to expose type
with a
binding annotation.expose
in interface PrivateBinder
public AnnotatedElementBuilder expose(TypeLiteral<?> type)
PrivateBinder
type
available to the enclosing environment. Use annotatedWith()
to expose type
with a
binding annotation.expose
in interface PrivateBinder
private <T> AnnotatedElementBuilder exposeInternal(Key<T> key)
private ModuleSource getModuleSource(java.lang.Object module)
private ElementSource getElementSource()
private java.lang.StackTraceElement[] getPartialCallStack(java.lang.StackTraceElement[] callStack)
moduleSource
call stack from the beginning of current call stack. It
also removes the last two elements in order to make install(Module)
the last call
in the call stack.public java.lang.String toString()
toString
in class java.lang.Object