/** * Returns an {@link AnnotationMirror} for the annotation of type {@code annotationClass} on * {@code element}, or {@link Optional#empty()} if no such annotation exists. This method is a * safer alternative to calling {@link Element#getAnnotation} as it avoids any interaction with * annotation proxies. */ static Optional<AnnotationMirror> getAnnotationMirror( Element element, Class<? extends Annotation> annotationClass) { return Optional.ofNullable(MoreElements.getAnnotationMirror(element, annotationClass).orNull()); }
/** * 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); } }
getAnnotationMirror(method, ContributesAndroidInjector.class).get(); for (TypeMirror module : getAnnotationValue(annotation, "modules").accept(new AllTypesVisitor(), null)) {