From 75a3a0ac6076cf57c48a440d98e5f9d03c6154a9 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 20 Nov 2023 12:33:10 -0800 Subject: [PATCH] Internal change RELNOTES=N/A PiperOrigin-RevId: 584100389 --- .../binding/MethodSignatureFormatter.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) 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)