com.google.inject.internal.ProcessedBindingData Maven / Gradle / Ivy
package com.google.inject.internal;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Keeps track of creation listeners & uninitialized bindings,
* so they can be processed after bindings are recorded.
*/
class ProcessedBindingData {
private final List creationListeners = Lists.newArrayList();
private final List uninitializedBindings = Lists.newArrayList();
private final List delayedUninitializedBindings = Lists.newArrayList();
void addCreationListener(CreationListener listener) {
creationListeners.add(listener);
}
void addUninitializedBinding(Runnable runnable) {
uninitializedBindings.add(runnable);
}
void addDelayedUninitializedBinding(Runnable runnable) {
delayedUninitializedBindings.add(runnable);
}
void initializeBindings() {
for (Runnable initializer : uninitializedBindings) {
initializer.run();
}
}
void runCreationListeners(Errors errors) {
for (CreationListener creationListener : creationListeners) {
creationListener.notify(errors);
}
}
/**
* Initialized bindings that need to be delayed until after all injection points and other
* bindings are processed. The main current usecase for this is resolving Optional dependencies
* for OptionalBinder bindings.
*/
void initializeDelayedBindings() {
for (Runnable initializer : delayedUninitializedBindings) {
initializer.run();
}
}
}