Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 530658894
  • Loading branch information
sameb authored and Guice Team committed May 9, 2023
1 parent 40a5bcf commit be0141c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
40 changes: 22 additions & 18 deletions core/src/com/google/inject/internal/RealMapBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,12 @@ public void configure(Binder binder) {
// The map this exposes is internally an ImmutableMap, so it's OK to massage
// the guice Provider to jakarta Provider in the value (since Guice provider
// implements jakarta Provider).
@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, jakarta.inject.Provider<V>>> jakartaProviderMapProvider =
(Provider) providerMapProvider;
binder.bind(bindingSelection.getJakartaProviderMapKey()).toProvider(jakartaProviderMapProvider);
@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, jakarta.inject.Provider<V>>> jakartaProviderMapProvider =
(Provider) providerMapProvider;
binder
.bind(bindingSelection.getJakartaProviderMapKey())
.toProvider(jakartaProviderMapProvider);

RealMapProvider<K, V> mapProvider = new RealMapProvider<>(bindingSelection);
// Bind Map<K, V> to the provider w/ extension support.
Expand All @@ -317,10 +319,10 @@ public void configure(Binder binder) {

// The Map.Entries are all ProviderMapEntry instances which do not allow setValue, so it is
// safe to massage the return type like this
@SuppressWarnings({"unchecked", "rawtypes"})
Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> jakartaEntrySetProviderKey =
(Key) bindingSelection.getEntrySetBinder().getSetKey();
binder.bind(bindingSelection.getEntrySetJakartaProviderKey()).to(jakartaEntrySetProviderKey);
@SuppressWarnings({"unchecked", "rawtypes"})
Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> jakartaEntrySetProviderKey =
(Key) bindingSelection.getEntrySetBinder().getSetKey();
binder.bind(bindingSelection.getEntrySetJakartaProviderKey()).to(jakartaEntrySetProviderKey);
}

@Override
Expand Down Expand Up @@ -1050,23 +1052,25 @@ public void configure(Binder binder) {
// The collection this exposes is internally an ImmutableMap, so it's OK to massage
// the guice Provider to jakarta Provider in the value (since the guice Provider implements
// jakarta Provider).
@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, Set<jakarta.inject.Provider<V>>>> jakartaProvider =
(Provider) multimapProvider;
binder.bind(bindingSelection.getJakartaProviderSetMultimapKey()).toProvider(jakartaProvider);
@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, Set<jakarta.inject.Provider<V>>>> jakartaProvider =
(Provider) multimapProvider;
binder
.bind(bindingSelection.getJakartaProviderSetMultimapKey())
.toProvider(jakartaProvider);

@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, Collection<Provider<V>>>> collectionProvider = (Provider) multimapProvider;
binder
.bind(bindingSelection.getProviderCollectionMultimapKey())
.toProvider(collectionProvider);

@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, Collection<jakarta.inject.Provider<V>>>> collectionJakartaProvider =
(Provider) multimapProvider;
binder
.bind(bindingSelection.getJakartaProviderCollectionMultimapKey())
.toProvider(collectionJakartaProvider);
@SuppressWarnings({"unchecked", "rawtypes"})
Provider<Map<K, Collection<jakarta.inject.Provider<V>>>> collectionJakartaProvider =
(Provider) multimapProvider;
binder
.bind(bindingSelection.getJakartaProviderCollectionMultimapKey())
.toProvider(collectionJakartaProvider);

// Binds a Map<K, Set<V>>
@SuppressWarnings({"unchecked", "rawtypes"})
Expand Down
10 changes: 6 additions & 4 deletions core/src/com/google/inject/internal/RealMultibinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ public void configure(Binder binder) {
// The collection this exposes is internally an ImmutableList, so it's OK to massage
// the guice Provider to jakarta Provider in the value (since the guice Provider implements
// jakarta Provider).
@SuppressWarnings("unchecked")
Provider<Collection<jakarta.inject.Provider<T>>> jakartaProvider =
(Provider) collectionOfProvidersProvider;
binder.bind(bindingSelection.getCollectionOfJakartaProvidersKey()).toProvider(jakartaProvider);
@SuppressWarnings("unchecked")
Provider<Collection<jakarta.inject.Provider<T>>> jakartaProvider =
(Provider) collectionOfProvidersProvider;
binder
.bind(bindingSelection.getCollectionOfJakartaProvidersKey())
.toProvider(jakartaProvider);
}

public void permitDuplicates() {
Expand Down
30 changes: 15 additions & 15 deletions core/src/com/google/inject/internal/RealOptionalBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,21 @@ public void configure(Binder binder) {
// Provider is assignable to jakarta.inject.Provider and the provider that the factory contains
// cannot be modified so we can use some rawtypes hackery to share the same implementation.
// cgcb.Optional<jakarta.inject.Provider<T>>
@SuppressWarnings("unchecked")
InternalProviderInstanceBindingImpl.Factory<Optional<jakarta.inject.Provider<T>>>
optionalJakartaProviderFactory =
(InternalProviderInstanceBindingImpl.Factory) optionalProviderFactory;
binder
.bind(key.ofType(optionalOfJakartaProvider(typeLiteral)))
.toProvider(optionalJakartaProviderFactory);
// ju.Optional<jakarta.inject.Provider<T>>
@SuppressWarnings("unchecked")
InternalProviderInstanceBindingImpl.Factory<java.util.Optional<jakarta.inject.Provider<T>>>
javaOptionalJakartaProviderFactory =
(InternalProviderInstanceBindingImpl.Factory) javaOptionalProviderFactory;
binder
.bind(key.ofType(javaOptionalOfJakartaProvider(typeLiteral)))
.toProvider(javaOptionalJakartaProviderFactory);
@SuppressWarnings("unchecked")
InternalProviderInstanceBindingImpl.Factory<Optional<jakarta.inject.Provider<T>>>
optionalJakartaProviderFactory =
(InternalProviderInstanceBindingImpl.Factory) optionalProviderFactory;
binder
.bind(key.ofType(optionalOfJakartaProvider(typeLiteral)))
.toProvider(optionalJakartaProviderFactory);
// ju.Optional<jakarta.inject.Provider<T>>
@SuppressWarnings("unchecked")
InternalProviderInstanceBindingImpl.Factory<java.util.Optional<jakarta.inject.Provider<T>>>
javaOptionalJakartaProviderFactory =
(InternalProviderInstanceBindingImpl.Factory) javaOptionalProviderFactory;
binder
.bind(key.ofType(javaOptionalOfJakartaProvider(typeLiteral)))
.toProvider(javaOptionalJakartaProviderFactory);

// cgcb.Optional<T>
Key<Optional<T>> optionalKey = key.ofType(optionalOf(typeLiteral));
Expand Down

0 comments on commit be0141c

Please sign in to comment.