Package com.google.inject.internal
Class EncounterImpl<T>
- java.lang.Object
-
- com.google.inject.internal.EncounterImpl<T>
-
- All Implemented Interfaces:
TypeEncounter<T>
final class EncounterImpl<T> extends java.lang.Object implements TypeEncounter<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<MethodAspect>
aspects
private Errors
errors
private java.util.List<InjectionListener<? super T>>
injectionListeners
private Lookups
lookups
private java.util.List<MembersInjector<? super T>>
membersInjectors
private boolean
valid
-
Constructor Summary
Constructors Constructor Description EncounterImpl(Errors errors, Lookups lookups)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 for typeI
which will be presented to the user at a later time.void
addError(java.lang.Throwable t)
Records an exception for typeI
, the full details of which will be logged, and the message of which will be presented to the user at a later time.void
bindInterceptor(Matcher<? super java.lang.reflect.Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors)
Binds method interceptor[s] to methods matched in typeI
and its supertypes.(package private) com.google.common.collect.ImmutableList<MethodAspect>
getAspects()
(package private) com.google.common.collect.ImmutableSet<InjectionListener<? super T>>
getInjectionListeners()
<T> MembersInjector<T>
getMembersInjector(TypeLiteral<T> typeLiteral)
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.<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 typeT
.(package private) com.google.common.collect.ImmutableSet<MembersInjector<? super T>>
getMembersInjectors()
<T> Provider<T>
getProvider(Key<T> key)
Returns the provider used to obtain instances for the given injection key.<T> Provider<T>
getProvider(java.lang.Class<T> type)
Returns the provider used to obtain instances for the given injection type.(package private) void
invalidate()
void
register(MembersInjector<? super T> membersInjector)
Registers a members injector for typeI
.void
register(InjectionListener<? super T> injectionListener)
Registers an injection listener for typeI
.
-
-
-
Field Detail
-
errors
private final Errors errors
-
lookups
private final Lookups lookups
-
membersInjectors
private java.util.List<MembersInjector<? super T>> membersInjectors
-
injectionListeners
private java.util.List<InjectionListener<? super T>> injectionListeners
-
aspects
private java.util.List<MethodAspect> aspects
-
valid
private boolean valid
-
-
Method Detail
-
invalidate
void invalidate()
-
getAspects
com.google.common.collect.ImmutableList<MethodAspect> getAspects()
-
bindInterceptor
public void bindInterceptor(Matcher<? super java.lang.reflect.Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors)
Description copied from interface:TypeEncounter
Binds method interceptor[s] to methods matched in typeI
and its supertypes. A method is eligible for interception if:- Guice created the instance the method is on
- Neither the enclosing type nor the method is final
- And the method is package-private or more accessible
- Specified by:
bindInterceptor
in interfaceTypeEncounter<T>
- Parameters:
methodMatcher
- matches methods the interceptor should apply to. For example:annotatedWith(Transactional.class)
.interceptors
- to bind
-
getMembersInjectors
com.google.common.collect.ImmutableSet<MembersInjector<? super T>> getMembersInjectors()
-
getInjectionListeners
com.google.common.collect.ImmutableSet<InjectionListener<? super T>> getInjectionListeners()
-
register
public void register(MembersInjector<? super T> membersInjector)
Description copied from interface:TypeEncounter
Registers a members injector for typeI
. Guice will use the members injector after its performed its own injections on an instance ofI
.- Specified by:
register
in interfaceTypeEncounter<T>
-
register
public void register(InjectionListener<? super T> injectionListener)
Description copied from interface:TypeEncounter
Registers an injection listener for typeI
. Guice will notify the listener after all injections have been performed on an instance ofI
.- Specified by:
register
in interfaceTypeEncounter<T>
-
addError
public void addError(java.lang.String message, java.lang.Object... arguments)
Description copied from interface:TypeEncounter
Records an error message for typeI
which will be presented to the user at a later time. Unlike throwing an exception, this enable us to continue configuring the Injector and discover more errors. UsesString.format(String, Object[])
to insert the arguments into the message.- Specified by:
addError
in interfaceTypeEncounter<T>
-
addError
public void addError(java.lang.Throwable t)
Description copied from interface:TypeEncounter
Records an exception for typeI
, the full details of which will be logged, and the message of which will be presented to the user at a later time. If your type listener calls something that you worry may fail, you should catch the exception and pass it to this method.- Specified by:
addError
in interfaceTypeEncounter<T>
-
addError
public void addError(Message message)
Description copied from interface:TypeEncounter
Records an error message to be presented to the user at a later time.- Specified by:
addError
in interfaceTypeEncounter<T>
-
getProvider
public <T> Provider<T> getProvider(Key<T> key)
Description copied from interface:TypeEncounter
Returns the provider used to obtain instances for the given injection key. The returned provider will not be valid until the injector has been created. The provider will throw anIllegalStateException
if you try to use it beforehand.- Specified by:
getProvider
in interfaceTypeEncounter<T>
-
getProvider
public <T> Provider<T> getProvider(java.lang.Class<T> type)
Description copied from interface:TypeEncounter
Returns the provider used to obtain instances for the given injection type. The returned provider will not be valid until the injector has been created. The provider will throw anIllegalStateException
if you try to use it beforehand.- Specified by:
getProvider
in interfaceTypeEncounter<T>
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral)
Description copied from interface:TypeEncounter
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
. The returned members injector will not be valid until the main injector has been created. The members injector will throw anIllegalStateException
if you try to use it beforehand.- Specified by:
getMembersInjector
in interfaceTypeEncounter<T>
- Parameters:
typeLiteral
- type to get members injector for
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(java.lang.Class<T> type)
Description copied from interface:TypeEncounter
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
. The returned members injector will not be valid until the main injector has been created. The members injector will throw anIllegalStateException
if you try to use it beforehand.- Specified by:
getMembersInjector
in interfaceTypeEncounter<T>
- Parameters:
type
- type to get members injector for
-
-