diff --git a/java/dagger/internal/codegen/binding/MethodSignatureFormatter.java b/java/dagger/internal/codegen/binding/MethodSignatureFormatter.java index a84b128cf1b..d7fea80b790 100644 --- a/java/dagger/internal/codegen/binding/MethodSignatureFormatter.java +++ b/java/dagger/internal/codegen/binding/MethodSignatureFormatter.java @@ -35,6 +35,7 @@ import androidx.room.compiler.processing.XTypeElement; import androidx.room.compiler.processing.XVariableElement; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Streams; import com.squareup.javapoet.ClassName; import dagger.internal.codegen.base.Formatter; import dagger.internal.codegen.xprocessing.XAnnotations; @@ -152,17 +153,24 @@ private static String nameOfType(XType type) { } private static ImmutableList formatedAnnotations(XExecutableElement executableElement) { + Nullability nullability = Nullability.of(executableElement); ImmutableList formattedAnnotations = - executableElement.getAllAnnotations().stream() - // Filter out @NotNull annotations added by KAPT to make error messages consistent - .filter(annotation -> !annotation.getClassName().equals(JET_BRAINS_NOT_NULL)) - .map(MethodSignatureFormatter::formatAnnotation) + Streams.concat( + executableElement.getAllAnnotations().stream() + // Filter out @NotNull annotations added by KAPT to make error messages + // consistent + .filter(annotation -> !annotation.getClassName().equals(JET_BRAINS_NOT_NULL)) + .map(MethodSignatureFormatter::formatAnnotation), + nullability.nullableAnnotations().stream() + // Filter out @NotNull annotations added by KAPT to make error messages + // consistent + .filter(annotation -> !annotation.equals(JET_BRAINS_NOT_NULL)) + .map(annotation -> String.format("@%s", annotation.canonicalName()))) + .distinct() .collect(toImmutableList()); - Nullability nullability = Nullability.of(executableElement); if (nullability.isKotlinTypeNullable() - && nullability.nullableAnnotations().stream() - .noneMatch(JET_BRAINS_NULLABLE::equals) - && getProcessingEnv(executableElement).findTypeElement(JET_BRAINS_NULLABLE) != null) { + && nullability.nullableAnnotations().stream().noneMatch(JET_BRAINS_NULLABLE::equals) + && getProcessingEnv(executableElement).findTypeElement(JET_BRAINS_NULLABLE) != null) { formattedAnnotations = ImmutableList.builder() .addAll(formattedAnnotations)