Skip to content

Commit

Permalink
Use guice
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 16, 2024
1 parent 10f2165 commit e0c3f55
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -150,24 +152,16 @@ public <Q> Supplier<Q> getCompiledBinding(Dependency<Q> dep) {
com.google.inject.Injector injector = guiceInjectorProvider.get();
if (key.getRawType() == List.class) {
Key<Object> elementType = key.getTypeParameter(0);
PlexusContainer container = injector.getInstance(PlexusContainer.class);
return () -> {
try {
var plexus = container.lookupList(elementType.getRawType());
// PlexusContainer container = injector.getInstance(PlexusContainer.class);
// var plexus = container.lookupList(elementType.getRawType());
var guice = injector.findBindingsByType(TypeLiteral.get(elementType.getRawType()));
Set<Binding<Object>> di = getBindings(elementType);
if (plexus.size() != guice.size()) {
System.err.println("Suspicious difference: Plexus: " + plexus.size() + " Guice: "
+ guice.size() + " for " + key);
}
if (di == null) {
return (Q) plexus;
}
if (!plexus.isEmpty() && !di.isEmpty() && plexus.size() == di.size()) {
System.err.println("Suspicious same size: Plexus: " + plexus.size() + " DI: " + guice.size()
+ " for " + key);
}
List<Binding<Object>> bindings = new ArrayList<>(di);
List<Binding<Object>> bindings = new ArrayList<>();
Optional.ofNullable(di).stream()
.flatMap(Collection::stream)
.forEach(bindings::add);
guice.stream()
.filter(b -> !(b instanceof ProviderInstanceBinding<?> pib
&& pib.getUserSuppliedProvider() instanceof BridgeProvider<?>))
Expand Down

0 comments on commit e0c3f55

Please sign in to comment.