Skip to content
Permalink
Browse files

Remove code related to the old format of binding injector factories w…

…ith wildcards

RELNOTES:
  - `dagger.android` code can no longer use the `AndroidInjector.Factory<? extends Activity>` format to bind injector factories. See https://google.github.io/dagger/android and the [2.19 release notes](https://github.com/google/dagger/releases/tag/dagger-2.19) for information on how to migrate.
  - Adds an ErrorProne refactoring for migrating from `AndroidSupportInjectionModule` (which now is functionless) to `AndroidInjectionModule`. See [these docs](https://errorprone.info/docs/patching) for how to apply the refactoring to your codebase if you're on `dagger-compiler-2.20`.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220383146
  • Loading branch information
ronshapiro committed Nov 7, 2018
1 parent efd2cc9 commit 221f000e3d608637d5275b5c4650733c7668d450

This file was deleted.

@@ -16,11 +16,6 @@

package dagger.android;

import android.app.Activity;
import android.app.Fragment;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentProvider;
import dagger.Module;
import dagger.internal.Beta;
import dagger.multibindings.Multibinds;
@@ -35,51 +30,10 @@
@Module
public abstract class AndroidInjectionModule {
@Multibinds
abstract Map<Class<?>, AndroidInjector.Factory<?>> allInjectorFactories();
abstract Map<Class<?>, AndroidInjector.Factory<?>> classKeyedInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<?>> allInjectorFactoriesWithStringKeys();

@Multibinds
abstract Map<Class<? extends Activity>, AndroidInjector.Factory<? extends Activity>>
activityInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends Activity>>
activityInjectorFactoriesWithStringKeys();

@Multibinds
abstract Map<Class<? extends Fragment>, AndroidInjector.Factory<? extends Fragment>>
fragmentInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends Fragment>>
fragmentInjectorFactoriesWithStringKeys();

@Multibinds
abstract Map<Class<? extends Service>, AndroidInjector.Factory<? extends Service>>
serviceInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends Service>>
serviceInjectorFactoriesWithStringKeys();

@Multibinds
abstract Map<
Class<? extends BroadcastReceiver>, AndroidInjector.Factory<? extends BroadcastReceiver>>
broadcastReceiverInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends BroadcastReceiver>>
broadcastReceiverInjectorFactoriesWithStringKeys();

@Multibinds
abstract Map<Class<? extends ContentProvider>, AndroidInjector.Factory<? extends ContentProvider>>
contentProviderInjectorFactories();

@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends ContentProvider>>
contentProviderInjectorFactoriesWithStringKeys();
abstract Map<String, AndroidInjector.Factory<?>> stringKeyedInjectorFactories();

private AndroidInjectionModule() {}
}

This file was deleted.

This file was deleted.

@@ -54,15 +54,8 @@
@Inject
DispatchingAndroidInjector(
Map<Class<?>, Provider<AndroidInjector.Factory<?>>> injectorFactoriesWithClassKeys,
Map<String, Provider<AndroidInjector.Factory<?>>> injectorFactoriesWithStringKeys,
Map<Class<? extends T>, Provider<AndroidInjector.Factory<? extends T>>>
boundedInjectorFactoriesWithClassKeys,
Map<String, Provider<AndroidInjector.Factory<? extends T>>>
boundedInjectorFactoriesWithStringKeys) {
this.injectorFactories =
secondaryMerge(
merge(injectorFactoriesWithClassKeys, injectorFactoriesWithStringKeys),
merge(boundedInjectorFactoriesWithClassKeys, boundedInjectorFactoriesWithStringKeys));
Map<String, Provider<AndroidInjector.Factory<?>>> injectorFactoriesWithStringKeys) {
this.injectorFactories = merge(injectorFactoriesWithClassKeys, injectorFactoriesWithStringKeys);
}

/**
@@ -95,26 +88,6 @@
return Collections.unmodifiableMap(safeCast);
}

/**
* Merges the results of {@link #merge(Map, Map)} calls into one map.
*
* <p>An SPI plugin verifies the logical uniqueness of the keysets of these two (merged) maps so
* we're assured there's no overlap.
*/
private static <K, V> Map<K, V> secondaryMerge(Map<K, V> firstMap, Map<K, V> secondMap) {
if (firstMap.isEmpty()) {
return secondMap;
}
if (secondMap.isEmpty()) {
return firstMap;
}

Map<K, V> merged = newLinkedHashMapWithExpectedSize(firstMap.size() + secondMap.size());
merged.putAll(firstMap);
merged.putAll(secondMap);
return merged;
}

/**
* Attempts to perform members-injection on {@code instance}, returning {@code true} if
* successful, {@code false} otherwise.

This file was deleted.

This file was deleted.

@@ -20,7 +20,6 @@
import static com.google.auto.common.AnnotationMirrors.getAnnotationValue;
import static com.google.auto.common.MoreElements.getAnnotationMirror;
import static com.google.auto.common.MoreElements.isAnnotationPresent;
import static dagger.android.processor.AndroidMapKeys.frameworkTypesByMapKey;
import static java.util.stream.Collectors.toList;
import static javax.lang.model.element.Modifier.ABSTRACT;

@@ -33,9 +32,7 @@
import com.squareup.javapoet.TypeName;
import dagger.Module;
import dagger.android.ContributesAndroidInjector;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.processing.Messager;
import javax.inject.Qualifier;
@@ -122,22 +119,11 @@
builder.enclosingModule(ClassName.get(enclosingElement));

TypeMirror injectedType = method.getReturnType();
Optional<? extends Class<? extends Annotation>> maybeMapKeyAnnotation =
frameworkTypesByMapKey(elements)
.entrySet()
.stream()
.filter(entry -> types.isAssignable(injectedType, entry.getValue()))
.map(Map.Entry::getKey)
.findFirst();
if (maybeMapKeyAnnotation.isPresent()) {
if (MoreTypes.asDeclared(injectedType).getTypeArguments().isEmpty()) {
builder.injectedType(ClassName.get(MoreTypes.asTypeElement(injectedType)));
} else {
reporter.reportError(
"@ContributesAndroidInjector methods cannot return parameterized types");
}
if (MoreTypes.asDeclared(injectedType).getTypeArguments().isEmpty()) {
builder.injectedType(ClassName.get(MoreTypes.asTypeElement(injectedType)));
} else {
reporter.reportError(String.format("%s is not a framework type", injectedType));
reporter.reportError(
"@ContributesAndroidInjector methods cannot return parameterized types");
}

AnnotationMirror annotation =

0 comments on commit 221f000

Please sign in to comment.
You can’t perform that action at this time.