Dynamic{Set,Map} should only include explicitly bound items.

Currently, the Dynamic{Set,Map}Provider includes any binding that
matches the type of the Set or Map, whether it was bound via the
Dynamic{Set,Map} or not. The Dynamic{Set,Map}Provider was updated
to include only bindings with an Annotation.

Change-Id: I124101c982bd52bc3bf27c7bcd70138fd203226a
This commit is contained in:
Colby Ranger
2012-05-16 14:52:14 -07:00
parent 058604b548
commit 63f9016ee1
2 changed files with 9 additions and 2 deletions

View File

@@ -38,7 +38,9 @@ class DynamicMapProvider<T> implements Provider<DynamicMap<T>> {
List<Binding<T>> bindings = injector.findBindingsByType(type);
if (bindings != null) {
for (Binding<T> b : bindings) {
m.put("gerrit", b.getKey(), b.getProvider());
if (b.getKey().getAnnotation() != null) {
m.put("gerrit", b.getKey(), b.getProvider());
}
}
}
return m;

View File

@@ -19,6 +19,7 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.UniqueAnnotations;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,6 +27,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
class DynamicSetProvider<T> implements Provider<DynamicSet<T>> {
private static final Class<?> UNIQUE_ANNOTATION =
UniqueAnnotations.create().getClass();
private final TypeLiteral<T> type;
@Inject
@@ -49,7 +52,9 @@ class DynamicSetProvider<T> implements Provider<DynamicSet<T>> {
}
List<AtomicReference<Provider<T>>> r = newList(cnt);
for (Binding<T> b : bindings) {
r.add(new AtomicReference<Provider<T>>(b.getProvider()));
if (b.getKey().getAnnotation() != null) {
r.add(new AtomicReference<Provider<T>>(b.getProvider()));
}
}
return r;
}