Search in sources :

Example 1 with TypeListenerBinding

use of com.google.inject.spi.TypeListenerBinding in project guice by google.

the class MembersInjectorStore method createWithListeners.

/** Creates a new members injector and attaches both injection listeners and method aspects. */
private <T> MembersInjectorImpl<T> createWithListeners(TypeLiteral<T> type, Errors errors) throws ErrorsException {
    int numErrorsBefore = errors.size();
    Set<InjectionPoint> injectionPoints;
    try {
        injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
    } catch (ConfigurationException e) {
        errors.merge(e.getErrorMessages());
        injectionPoints = e.getPartialValue();
    }
    ImmutableList<SingleMemberInjector> injectors = getInjectors(injectionPoints, errors);
    errors.throwIfNewErrors(numErrorsBefore);
    EncounterImpl<T> encounter = new EncounterImpl<T>(errors, injector.lookups);
    Set<TypeListener> alreadySeenListeners = Sets.newHashSet();
    for (TypeListenerBinding binding : typeListenerBindings) {
        TypeListener typeListener = binding.getListener();
        if (!alreadySeenListeners.contains(typeListener) && binding.getTypeMatcher().matches(type)) {
            alreadySeenListeners.add(typeListener);
            try {
                typeListener.hear(type, encounter);
            } catch (RuntimeException e) {
                errors.errorNotifyingTypeListener(binding, type, e);
            }
        }
    }
    encounter.invalidate();
    errors.throwIfNewErrors(numErrorsBefore);
    return new MembersInjectorImpl<T>(injector, type, encounter, injectors);
}
Also used : InjectionPoint(com.google.inject.spi.InjectionPoint) InjectionPoint(com.google.inject.spi.InjectionPoint) TypeListenerBinding(com.google.inject.spi.TypeListenerBinding) ConfigurationException(com.google.inject.ConfigurationException) TypeListener(com.google.inject.spi.TypeListener)

Example 2 with TypeListenerBinding

use of com.google.inject.spi.TypeListenerBinding in project roboguice by roboguice.

the class MembersInjectorStore method createWithListeners.

/**
   * Creates a new members injector and attaches both injection listeners and method aspects.
   */
private <T> MembersInjectorImpl<T> createWithListeners(TypeLiteral<T> type, Errors errors) throws ErrorsException {
    int numErrorsBefore = errors.size();
    Set<InjectionPoint> injectionPoints;
    try {
        injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
    } catch (ConfigurationException e) {
        errors.merge(e.getErrorMessages());
        injectionPoints = e.getPartialValue();
    }
    ImmutableList<SingleMemberInjector> injectors = getInjectors(injectionPoints, errors);
    errors.throwIfNewErrors(numErrorsBefore);
    EncounterImpl<T> encounter = new EncounterImpl<T>(errors, injector.lookups);
    Set<TypeListener> alreadySeenListeners = Sets.newHashSet();
    for (TypeListenerBinding binding : typeListenerBindings) {
        TypeListener typeListener = binding.getListener();
        if (!alreadySeenListeners.contains(typeListener) && binding.getTypeMatcher().matches(type)) {
            alreadySeenListeners.add(typeListener);
            try {
                typeListener.hear(type, encounter);
            } catch (RuntimeException e) {
                errors.errorNotifyingTypeListener(binding, type, e);
            }
        }
    }
    encounter.invalidate();
    errors.throwIfNewErrors(numErrorsBefore);
    return new MembersInjectorImpl<T>(injector, type, encounter, injectors);
}
Also used : InjectionPoint(com.google.inject.spi.InjectionPoint) InjectionPoint(com.google.inject.spi.InjectionPoint) TypeListenerBinding(com.google.inject.spi.TypeListenerBinding) ConfigurationException(com.google.inject.ConfigurationException) TypeListener(com.google.inject.spi.TypeListener)

Aggregations

ConfigurationException (com.google.inject.ConfigurationException)2 InjectionPoint (com.google.inject.spi.InjectionPoint)2 TypeListener (com.google.inject.spi.TypeListener)2 TypeListenerBinding (com.google.inject.spi.TypeListenerBinding)2