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)
BinderbindInterceptor in interface BinderclassMatcher - 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)
Binderpublic void requestInjection(java.lang.Object instance)
BinderInjector will inject instance fields
and methods of the given object.requestInjection in interface Binderinstance - for which members will be injectedpublic <T> void requestInjection(TypeLiteral<T> type, T instance)
BinderInjector will inject instance fields
and methods of the given object.requestInjection in interface Bindertype - of instanceinstance - for which members will be injectedpublic <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral)
BinderT. 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 BindertypeLiteral - type to get members injector forpublic <T> MembersInjector<T> getMembersInjector(java.lang.Class<T> type)
BinderT. 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 Bindertype - type to get members injector forpublic void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
BinderbindListener in interface BindertypeMatcher - that matches injectable types the listener should be notified oflistener - for injectable types matched by typeMatcherpublic void bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listeners)
BinderBinder.bindListener(com.google.inject.matcher.Matcher<? super com.google.inject.TypeLiteral<?>>, com.google.inject.spi.TypeListener).bindListener in interface BinderbindingMatcher - that matches bindings of provisioned objects the listener
should be notified oflisteners - for provisioned objects matched by bindingMatcherpublic void requestStaticInjection(java.lang.Class<?>... types)
BinderInjector will inject static fields
and methods in the given classes.requestStaticInjection in interface Bindertypes - for which static members will be injectedvoid scanForAnnotatedMethods()
public void install(Module module)
Binderpublic Stage currentStage()
BindercurrentStage in interface Binderpublic void addError(java.lang.String message,
java.lang.Object... arguments)
BinderString.format(String, Object[]) to insert the arguments into the
message.public void addError(java.lang.Throwable t)
Binderpublic void addError(Message message)
Binderpublic <T> AnnotatedBindingBuilder<T> bind(Key<T> key)
BinderBinder.public <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
BinderBinder.public <T> AnnotatedBindingBuilder<T> bind(java.lang.Class<T> type)
BinderBinder.public AnnotatedConstantBindingBuilder bindConstant()
BinderBinder.bindConstant in interface Binderpublic <T> Provider<T> getProvider(Key<T> key)
BinderInjector has been
created. The provider will throw an IllegalStateException if you
try to use it beforehand.getProvider in interface Binderpublic <T> Provider<T> getProvider(Dependency<T> dependency)
BinderInjector
has been created. The provider will throw an IllegalStateException if you
try to use it beforehand.getProvider in interface Binderpublic <T> Provider<T> getProvider(java.lang.Class<T> type)
BinderInjector has been
created. The provider will throw an IllegalStateException if you
try to use it beforehand.getProvider in interface Binderpublic void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
BinderconvertToTypes in interface BindertypeMatcher - matches types the converter can handleconverter - converts valuespublic Elements.RecordingBinder withSource(java.lang.Object source)
Bindersource 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 BinderwithSource in interface PrivateBindersource - any object representing the source location and has a
concise toString() valuepublic Elements.RecordingBinder skipSources(java.lang.Class... classesToSkip)
BinderclassesToSkip when identify the
calling code. The caller's StackTraceElement is used to locate
the source of configuration errors.skipSources in interface BinderskipSources in interface PrivateBinderclassesToSkip - library classes that create bindings on behalf of
their clients.public PrivateBinder newPrivateBinder()
BinderPrivateModule for details.newPrivateBinder in interface Binderpublic void disableCircularProxies()
BinderProvider. 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 Binderpublic void requireExplicitBindings()
Binderbind(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 Binderpublic void requireAtInjectOnConstructors()
BinderInject 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 Binderpublic void requireExactBindingAnnotations()
Binder@Named Foo when attempting to inject
@Named("foo") Foo.requireExactBindingAnnotations in interface Binderpublic void scanModulesForAnnotatedMethods(ModuleAnnotatedMethodScanner scanner)
BinderscanModulesForAnnotatedMethods in interface Binderpublic void expose(Key<?> key)
PrivateBinderkey available to the enclosing environmentexpose in interface PrivateBinderpublic AnnotatedElementBuilder expose(java.lang.Class<?> type)
PrivateBindertype available to the enclosing environment. Use annotatedWith() to expose type with a
binding annotation.expose in interface PrivateBinderpublic AnnotatedElementBuilder expose(TypeLiteral<?> type)
PrivateBindertype available to the enclosing environment. Use annotatedWith() to expose type with a
binding annotation.expose in interface PrivateBinderprivate <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