/** * A valid @Binds method could bind an {@link AndroidInjector.Factory} for one type, while giving * it a map key of a different type. The return type and parameter type would pass typical @Binds * validation, but the map lookup in {@link dagger.android.DispatchingAndroidInjector} would * retrieve the wrong injector factory. * * <pre>{@code * {@literal @Binds} * {@literal @IntoMap} * {@literal @ClassKey(GreenActivity.class)} * abstract AndroidInjector.Factory<?> bindBlueActivity( * BlueActivityComponent.Builder builder); * }</pre> */ private void validateMapKeyMatchesBindsParameter( Class<? extends Annotation> annotation, ExecutableElement method) { TypeMirror parameterType = getOnlyElement(method.getParameters()).asType(); AnnotationMirror annotationMirror = getAnnotationMirror(method, annotation).get(); TypeMirror mapKeyType = elements.getTypeElement(injectedTypeFromMapKey(annotationMirror).get()).asType(); if (!types.isAssignable(parameterType, injectorFactoryOf(mapKeyType))) { messager.printMessage( Kind.ERROR, String.format("%s does not implement AndroidInjector<%s>", parameterType, mapKeyType), method, annotationMirror); } }
for (Binding injectorFactory : injectorFactories) { AnnotationMirror mapKey = mapKey(injectorFactory).get(); Optional<String> injectedType = injectedTypeFromMapKey(mapKey); if (injectedType.isPresent()) { mapKeyIndex.put(injectedType.get(), injectorFactory);
getOnlyElement(getAnnotatedAnnotations(method, MapKey.class)); TypeElement mapKeyValueElement = elements.getTypeElement(injectedTypeFromMapKey(mapKeyAnnotation).get()); messager.printMessage( Kind.ERROR,