diff --git a/WORKSPACE b/WORKSPACE index e84385e77f7..8ff11319441 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -210,6 +210,13 @@ KOTLIN_VERSION = "2.0.21" KSP_VERSION = KOTLIN_VERSION + "-1.0.28" +# XProcessing testing uses the embeddable Kotlin version. Ideally, this would be +# the same as KOTLIN_VERSION, but XProcessing testing requires 2.1.0 and Bazel +# doesn't support 2.1.0 yet. See https://github.com/bazelbuild/rules_kotlin/issues/1176. +EMBEDDABLE_KOTLIN_VERSION = "2.1.0" + +EMBEDDABLE_KSP_VERSION = EMBEDDABLE_KOTLIN_VERSION + "-1.0.28" + MAVEN_VERSION = "3.3.3" maven_install( @@ -251,7 +258,6 @@ maven_install( "com.google.devtools.ksp:symbol-processing:%s" % KSP_VERSION, "com.google.devtools.ksp:symbol-processing-api:%s" % KSP_VERSION, "com.google.devtools.ksp:symbol-processing-common-deps:%s" % KSP_VERSION, - "com.google.devtools.ksp:symbol-processing-aa-embeddable:%s" % KSP_VERSION, "com.google.errorprone:error_prone_annotation:%s" % ERROR_PRONE_VERSION, "com.google.errorprone:error_prone_annotations:%s" % ERROR_PRONE_VERSION, "com.google.errorprone:error_prone_check_api:%s" % ERROR_PRONE_VERSION, @@ -294,9 +300,6 @@ maven_install( "org.eclipse.sisu:org.eclipse.sisu.plexus:%s" % ECLIPSE_SISU_VERSION, "org.eclipse.sisu:org.eclipse.sisu.inject:%s" % ECLIPSE_SISU_VERSION, "org.hamcrest:hamcrest-core:1.3", - "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:%s" % KOTLIN_VERSION, - "org.jetbrains.kotlin:kotlin-compiler-embeddable:%s" % KOTLIN_VERSION, - "org.jetbrains.kotlin:kotlin-daemon-embeddable:%s" % KOTLIN_VERSION, "org.jetbrains.kotlin:kotlin-metadata-jvm:%s" % KOTLIN_VERSION, "org.jetbrains.kotlin:kotlin-stdlib:%s" % KOTLIN_VERSION, "org.jspecify:jspecify:1.0.0", @@ -314,3 +317,20 @@ maven_install( "https://maven.google.com", ], ) + +maven_install( + name = "kotlin_embeddable", + artifacts = [ + "com.google.devtools.ksp:symbol-processing:%s" % EMBEDDABLE_KSP_VERSION, + "com.google.devtools.ksp:symbol-processing-aa-embeddable:%s" % EMBEDDABLE_KSP_VERSION, + "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:%s" % EMBEDDABLE_KOTLIN_VERSION, + "org.jetbrains.kotlin:kotlin-compiler-embeddable:%s" % EMBEDDABLE_KOTLIN_VERSION, + "org.jetbrains.kotlin:kotlin-daemon-embeddable:%s" % EMBEDDABLE_KOTLIN_VERSION, + "org.jetbrains.kotlin:kotlin-metadata-jvm:%s" % EMBEDDABLE_KOTLIN_VERSION, + "org.jetbrains.kotlin:kotlin-stdlib:%s" % EMBEDDABLE_KOTLIN_VERSION, + ], + repositories = [ + "https://repo1.maven.org/maven2", + "https://maven.google.com", + ], +) diff --git a/java/dagger/internal/codegen/xprocessing/BUILD b/java/dagger/internal/codegen/xprocessing/BUILD index f03b2f935a3..f2345d66003 100644 --- a/java/dagger/internal/codegen/xprocessing/BUILD +++ b/java/dagger/internal/codegen/xprocessing/BUILD @@ -63,12 +63,12 @@ java_library( testonly = 1, exports = [ ":xprocessing-testing-lib", - "@maven//:com_google_devtools_ksp_symbol_processing", - "@maven//:com_google_devtools_ksp_symbol_processing_aa_embeddable", - "@maven//:com_google_devtools_ksp_symbol_processing_common_deps", - "@maven//:org_jetbrains_kotlin_kotlin_annotation_processing_embeddable", - "@maven//:org_jetbrains_kotlin_kotlin_compiler_embeddable", - "@maven//:org_jetbrains_kotlin_kotlin_daemon_embeddable", + "@kotlin_embeddable//:com_google_devtools_ksp_symbol_processing", + "@kotlin_embeddable//:com_google_devtools_ksp_symbol_processing_aa_embeddable", + "@kotlin_embeddable//:com_google_devtools_ksp_symbol_processing_common_deps", + "@kotlin_embeddable//:org_jetbrains_kotlin_kotlin_annotation_processing_embeddable", + "@kotlin_embeddable//:org_jetbrains_kotlin_kotlin_compiler_embeddable", + "@kotlin_embeddable//:org_jetbrains_kotlin_kotlin_daemon_embeddable", ], ) diff --git a/java/dagger/internal/codegen/xprocessing/xprocessing-testing.jar b/java/dagger/internal/codegen/xprocessing/xprocessing-testing.jar index f7f02031862..99ba3797173 100644 Binary files a/java/dagger/internal/codegen/xprocessing/xprocessing-testing.jar and b/java/dagger/internal/codegen/xprocessing/xprocessing-testing.jar differ diff --git a/java/dagger/internal/codegen/xprocessing/xprocessing.jar b/java/dagger/internal/codegen/xprocessing/xprocessing.jar index 31833cc5bad..584b96d85d9 100644 Binary files a/java/dagger/internal/codegen/xprocessing/xprocessing.jar and b/java/dagger/internal/codegen/xprocessing/xprocessing.jar differ diff --git a/javatests/dagger/hilt/processor/internal/generatesrootinput/BUILD b/javatests/dagger/hilt/processor/internal/generatesrootinput/BUILD index c697141e4a8..99c2ad1443b 100644 --- a/javatests/dagger/hilt/processor/internal/generatesrootinput/BUILD +++ b/javatests/dagger/hilt/processor/internal/generatesrootinput/BUILD @@ -32,6 +32,7 @@ compiler_test( "//java/dagger/hilt/android/testing/compile", "//java/dagger/hilt/processor/internal:base_processor", "//java/dagger/hilt/processor/internal/generatesrootinput:generates_root_inputs", + "//java/dagger/internal/codegen/extension", "//java/dagger/internal/codegen/xprocessing", "//java/dagger/internal/codegen/xprocessing:xprocessing-testing", "//third_party/java/javapoet", diff --git a/javatests/dagger/hilt/processor/internal/generatesrootinput/GeneratesRootInputProcessorTest.java b/javatests/dagger/hilt/processor/internal/generatesrootinput/GeneratesRootInputProcessorTest.java index 195b5fee300..12636e46821 100644 --- a/javatests/dagger/hilt/processor/internal/generatesrootinput/GeneratesRootInputProcessorTest.java +++ b/javatests/dagger/hilt/processor/internal/generatesrootinput/GeneratesRootInputProcessorTest.java @@ -17,13 +17,12 @@ package dagger.hilt.processor.internal.generatesrootinput; import static com.google.common.truth.Truth.assertThat; +import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList; -import androidx.room.compiler.processing.XElement; import androidx.room.compiler.processing.XFiler.Mode; import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.XRoundEnv; import androidx.room.compiler.processing.util.Source; -import com.google.common.truth.Correspondence; import com.squareup.javapoet.ClassName; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.TypeSpec; @@ -43,7 +42,7 @@ public final class GeneratesRootInputProcessorTest { private static final int GENERATED_CLASSES = 5; private static final ClassName TEST_ANNOTATION = ClassName.get("test", "TestAnnotation"); - private final List elementsToWaitFor = new ArrayList<>(); + private final List elementsToWaitFor = new ArrayList<>(); private int generatedClasses = 0; public final class TestAnnotationStep extends BaseProcessingStep { @@ -57,7 +56,10 @@ public TestAnnotationStep(XProcessingEnv env) { @Override public void postProcess(XProcessingEnv processingEnv, XRoundEnv round) { if (generatedClasses > 0) { - elementsToWaitFor.addAll(generatesRootInputs.getElementsToWaitFor(round)); + elementsToWaitFor.addAll( + generatesRootInputs.getElementsToWaitFor(round).stream() + .map(element -> XElements.asTypeElement(element).getQualifiedName()) + .collect(toImmutableList())); } if (generatedClasses < GENERATED_CLASSES) { TypeSpec typeSpec = @@ -84,10 +86,6 @@ public void succeeds_ComponentProcessorWaitsForAnnotationsWithGeneratesRootInput subject -> { subject.hasErrorCount(0); assertThat(elementsToWaitFor) - .comparingElementsUsing( - Correspondence.transforming( - element -> XElements.asTypeElement(element).getQualifiedName(), - "has qualified name of")) .containsExactly("foo.Foo0", "foo.Foo1", "foo.Foo2", "foo.Foo3", "foo.Foo4") .inOrder(); elementsToWaitFor.clear(); diff --git a/javatests/dagger/internal/codegen/BindsMethodValidationTest.java b/javatests/dagger/internal/codegen/BindsMethodValidationTest.java index 5383e5def31..7653d7d5214 100644 --- a/javatests/dagger/internal/codegen/BindsMethodValidationTest.java +++ b/javatests/dagger/internal/codegen/BindsMethodValidationTest.java @@ -20,7 +20,6 @@ import static dagger.internal.codegen.DaggerModuleMethodSubject.Factory.assertThatModuleMethod; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.util.Source; import com.google.common.collect.ImmutableList; import dagger.Module; @@ -253,27 +252,21 @@ public void bindsMissingTypeInParameterHierarchy() { subject.hasErrorCount(2); break; } - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC; subject.hasErrorContaining( - String.format( - "ModuleProcessingStep was unable to process 'test.TestModule' because '%s' " - + "could not be resolved.", - isJavac ? "MissingType" : "error.NonExistentClass")); + "ModuleProcessingStep was unable to process 'test.TestModule' because " + + "'MissingType' could not be resolved."); subject.hasErrorContaining( - String.format( - "BindingMethodProcessingStep was unable to process" - + " 'bindObject(test.Child)' because '%1$s' could not " - + "be resolved." - + "\n " - + "\n Dependency trace:" - + "\n => element (INTERFACE): test.TestModule" - + "\n => element (METHOD): bindObject(test.Child)" - + "\n => element (PARAMETER): child" - + "\n => type (DECLARED parameter): test.Child" - + "\n => type (DECLARED supertype): test.Parent" - + "\n => type (ERROR supertype): %1$s", - isJavac ? "MissingType" : "error.NonExistentClass")); + "BindingMethodProcessingStep was unable to process " + + "'bindObject(test.Child)' because 'MissingType' could " + + "not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (INTERFACE): test.TestModule" + + "\n => element (METHOD): bindObject(test.Child)" + + "\n => element (PARAMETER): child" + + "\n => type (DECLARED parameter): test.Child" + + "\n => type (DECLARED supertype): test.Parent" + + "\n => type (ERROR supertype): MissingType"); }); } @@ -319,26 +312,19 @@ public void bindsMissingTypeInReturnTypeHierarchy() { subject.hasErrorCount(2); break; } - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC; subject.hasErrorContaining( - String.format( - "ModuleProcessingStep was unable to process 'test.TestModule' because '%s' " - + "could not be resolved.", - isJavac ? "MissingType" : "error.NonExistentClass")); + "ModuleProcessingStep was unable to process 'test.TestModule' because " + + "'MissingType' could not be resolved."); subject.hasErrorContaining( - String.format( - "BindingMethodProcessingStep was unable to process " - + "'bindChild(java.lang.String)' because '%1$s' could not be" - + " resolved." - + "\n " - + "\n Dependency trace:" - + "\n => element (INTERFACE): test.TestModule" - + "\n => element (METHOD): bindChild(java.lang.String)" - + "\n => type (DECLARED return type): test.Child" - + "\n => type (DECLARED supertype): test.Parent" - + "\n => type (ERROR supertype): %1$s", - isJavac ? "MissingType" : "error.NonExistentClass")); + "BindingMethodProcessingStep was unable to process 'bindChild(java.lang.String)' " + + "because 'MissingType' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (INTERFACE): test.TestModule" + + "\n => element (METHOD): bindChild(java.lang.String)" + + "\n => type (DECLARED return type): test.Child" + + "\n => type (DECLARED supertype): test.Parent" + + "\n => type (ERROR supertype): MissingType"); }); } diff --git a/javatests/dagger/internal/codegen/DaggerSuperficialValidationTest.java b/javatests/dagger/internal/codegen/DaggerSuperficialValidationTest.java index dffe7014a78..2dbbe74bb55 100644 --- a/javatests/dagger/internal/codegen/DaggerSuperficialValidationTest.java +++ b/javatests/dagger/internal/codegen/DaggerSuperficialValidationTest.java @@ -86,18 +86,14 @@ public void missingReturnType() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => element (METHOD): blah()", - " => type (ERROR return type): %1$s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => element (METHOD): blah()", + " => type (ERROR return type): MissingType")); }); } @@ -132,8 +128,7 @@ public void missingGenericReturnType() { ? isKAPT(processingEnv) ? "MissingType" : "MissingType" : ""; } else { - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - errorType = "error.NonExistentClass"; + errorType = "MissingType"; } assertThat(exception) .hasMessageThat() @@ -179,8 +174,7 @@ public void missingReturnTypeTypeParameter() { // JDK 24 improves error type information. errorType = Runtime.version().feature() >= 24 ? "MissingType" : ""; } else { - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - errorType = "error.NonExistentClass"; + errorType = sourceKind == SourceKind.KOTLIN ? "MissingType<*>" : "MissingType"; } assertThat(exception) .hasMessageThat() @@ -220,18 +214,14 @@ public void missingTypeParameter() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => element (TYPE_PARAMETER): T", - " => type (ERROR bound type): %s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => element (TYPE_PARAMETER): T", + " => type (ERROR bound type): MissingType")); }); } @@ -258,19 +248,15 @@ public void missingParameterType() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => element (METHOD): foo(%1$s)", - " => element (PARAMETER): param", - " => type (ERROR parameter type): %1$s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => element (METHOD): foo(MissingType)", + " => element (PARAMETER): param", + " => type (ERROR parameter type): MissingType")); }); } @@ -295,18 +281,14 @@ public void missingAnnotation() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => annotation type: MissingAnnotation", - " => type (ERROR annotation type): %s"), - isJavac ? "MissingAnnotation" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => annotation type: MissingAnnotation", + " => type (ERROR annotation type): MissingAnnotation")); }); } @@ -385,20 +367,16 @@ public void missingWildcardBound() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => element (METHOD): extendsTest()", - " => type (DECLARED return type): test.TestClass.Foo", - " => type (WILDCARD type argument): ? extends %1$s", - " => type (ERROR extends bound type): %1$s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => element (METHOD): extendsTest()", + " => type (DECLARED return type): test.TestClass.Foo", + " => type (WILDCARD type argument): ? extends MissingType", + " => type (ERROR extends bound type): MissingType")); }); } @@ -425,18 +403,14 @@ public void missingIntersection() { assertThrows( ValidationException.KnownErrorType.class, () -> superficialValidation.validateElement(testClassElement)); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.TestClass", - " => element (TYPE_PARAMETER): T", - " => type (ERROR bound type): %s"), - isJavac ? "Missing" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.TestClass", + " => element (TYPE_PARAMETER): T", + " => type (ERROR bound type): Missing")); }); } @@ -481,15 +455,15 @@ public void invalidAnnotationValue() { "Validation trace:", " => element (CLASS): test.Outer.TestClass", " => annotation type: test.Outer.TestAnnotation", - " => annotation: @test.Outer.TestAnnotation(classes={<%1$s>})", - " => annotation value (TYPE_ARRAY): classes={<%1$s>}", - " => annotation value (TYPE): classes=<%1$s>"), - isJavac ? "error" : "ERROR TYPE: MissingType"); + " => annotation: @test.Outer.TestAnnotation(classes={%1$s})", + " => annotation value (TYPE_ARRAY): classes={%1$s}", + " => annotation value (TYPE): classes=%1$s"), + isJavac ? "" : "MissingType"); if (!isJavac) { expectedMessage = NEW_LINES.join( expectedMessage, - " => type (ERROR annotation value type): error.NonExistentClass"); + " => type (ERROR annotation value type): MissingType"); } assertThat(exception).hasMessageThat().contains(expectedMessage); }); @@ -546,15 +520,15 @@ public void invalidAnnotationValueOnParameter() { " => element (CONSTRUCTOR): TestClass(java.lang.String)", " => element (PARAMETER): strParam", " => annotation type: test.Outer.TestAnnotation", - " => annotation: @test.Outer.TestAnnotation(classes={<%1$s>})", - " => annotation value (TYPE_ARRAY): classes={<%1$s>}", - " => annotation value (TYPE): classes=<%1$s>"), - isJavac ? "error" : "ERROR TYPE: MissingType"); + " => annotation: @test.Outer.TestAnnotation(classes={%1$s})", + " => annotation value (TYPE_ARRAY): classes={%1$s}", + " => annotation value (TYPE): classes=%1$s"), + isJavac ? "" : "MissingType"); if (!isJavac) { expectedMessage = NEW_LINES.join( expectedMessage, - " => type (ERROR annotation value type): error.NonExistentClass"); + " => type (ERROR annotation value type): MissingType"); } assertThat(exception).hasMessageThat().contains(expectedMessage); }); @@ -603,7 +577,7 @@ public void invalidSuperclassInTypeHierarchy() { " => type (DECLARED return type): test.Outer.Child", " => type (DECLARED supertype): test.Outer.Parent", " => type (ERROR supertype): %s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + isJavac ? "MissingType" : "MissingType")); }); } @@ -644,20 +618,16 @@ public void invalidSuperclassTypeParameterInTypeHierarchy() { () -> superficialValidation.validateTypeHierarchyOf( "return type", getChildMethod, getChildMethod.getReturnType())); - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC; assertThat(exception) .hasMessageThat() .contains( - String.format( - NEW_LINES.join( - "Validation trace:", - " => element (CLASS): test.Outer", - " => element (METHOD): getChild()", - " => type (DECLARED return type): test.Outer.Child", - " => type (DECLARED supertype): test.Outer.Parent<%1$s>", - " => type (ERROR type argument): %1$s"), - isJavac ? "MissingType" : "error.NonExistentClass")); + NEW_LINES.join( + "Validation trace:", + " => element (CLASS): test.Outer", + " => element (METHOD): getChild()", + " => type (DECLARED return type): test.Outer.Child", + " => type (DECLARED supertype): test.Outer.Parent", + " => type (ERROR type argument): MissingType")); }); } diff --git a/javatests/dagger/internal/codegen/UnresolvableDependencyTest.java b/javatests/dagger/internal/codegen/UnresolvableDependencyTest.java index 296dae496aa..8609bc2b844 100644 --- a/javatests/dagger/internal/codegen/UnresolvableDependencyTest.java +++ b/javatests/dagger/internal/codegen/UnresolvableDependencyTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; -import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.util.Source; import com.google.common.collect.ImmutableMap; import dagger.testing.compile.CompilerTests; @@ -86,24 +85,24 @@ public void referencesUnresolvableDependency() { subject.hasErrorCount(2); break; } - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC; - String trace = "\n " - + "\n Dependency trace:" - + "\n => element (CLASS): test.Bar" - + "\n => element (CONSTRUCTOR): Bar(%1$s)" - + "\n => type (EXECUTABLE constructor): (%1$s)void" - + "\n => type (ERROR parameter type): %1$s"; subject.hasErrorContaining( - String.format( - "InjectProcessingStep was unable to process 'Bar(%1$s)' because '%1$s' could " - + "not be resolved." + trace, - isJavac ? "UnresolvableDependency" : "error.NonExistentClass")); + "InjectProcessingStep was unable to process 'Bar(UnresolvableDependency)' " + + "because 'UnresolvableDependency' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => element (CONSTRUCTOR): Bar(UnresolvableDependency)" + + "\n => type (EXECUTABLE constructor): (UnresolvableDependency)void" + + "\n => type (ERROR parameter type): UnresolvableDependency"); subject.hasErrorContaining( - String.format( - "ComponentProcessingStep was unable to process 'test.FooComponent' because " - + "'%1$s' could not be resolved." + trace, - isJavac ? "UnresolvableDependency" : "error.NonExistentClass")); + "ComponentProcessingStep was unable to process 'test.FooComponent' because " + + "'UnresolvableDependency' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => element (CONSTRUCTOR): Bar(UnresolvableDependency)" + + "\n => type (EXECUTABLE constructor): (UnresolvableDependency)void" + + "\n => type (ERROR parameter type): UnresolvableDependency"); // Check that the stacktrace is not included in the error message by default. assertThat(subject.getCompilationResult().rawOutput()) @@ -181,23 +180,22 @@ public void referencesUnresolvableAnnotationOnType() { subject.hasErrorCount(2); break; } - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC; - String trace = "\n " - + "\n Dependency trace:" - + "\n => element (CLASS): test.Bar" - + "\n => annotation: @UnresolvableAnnotation" - + "\n => type (ERROR annotation type): %1$s"; subject.hasErrorContaining( - String.format( - "InjectProcessingStep was unable to process 'Bar(java.lang.String)' because " - + "'%1$s' could not be resolved." + trace, - isJavac ? "UnresolvableAnnotation" : "error.NonExistentClass")); + "InjectProcessingStep was unable to process 'Bar(java.lang.String)' because " + + "'UnresolvableAnnotation' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => annotation: @UnresolvableAnnotation" + + "\n => type (ERROR annotation type): UnresolvableAnnotation"); subject.hasErrorContaining( - String.format( - "ComponentProcessingStep was unable to process 'test.FooComponent' because " - + "'%1$s' could not be resolved." + trace, - isJavac ? "UnresolvableAnnotation" : "error.NonExistentClass")); + "ComponentProcessingStep was unable to process 'test.FooComponent' because " + + "'UnresolvableAnnotation' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => annotation: @UnresolvableAnnotation" + + "\n => type (ERROR annotation type): UnresolvableAnnotation"); }); } @@ -254,25 +252,26 @@ public void referencesUnresolvableAnnotationOnTypeOnParameter() { subject.hasErrorCount(2); break; } - // TODO(b/248552462): Javac and KSP should match once this bug is fixed. - boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC; - String trace = "\n " - + "\n Dependency trace:" - + "\n => element (CLASS): test.Bar" - + "\n => element (CONSTRUCTOR): Bar(java.lang.String)" - + "\n => element (PARAMETER): dep" - + "\n => annotation: @UnresolvableAnnotation" - + "\n => type (ERROR annotation type): %1$s"; subject.hasErrorContaining( - String.format( - "InjectProcessingStep was unable to process 'Bar(java.lang.String)' because " - + "'%1$s' could not be resolved." + trace, - isJavac ? "UnresolvableAnnotation" : "error.NonExistentClass")); + "InjectProcessingStep was unable to process 'Bar(java.lang.String)' because " + + "'UnresolvableAnnotation' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => element (CONSTRUCTOR): Bar(java.lang.String)" + + "\n => element (PARAMETER): dep" + + "\n => annotation: @UnresolvableAnnotation" + + "\n => type (ERROR annotation type): UnresolvableAnnotation"); subject.hasErrorContaining( - String.format( - "ComponentProcessingStep was unable to process 'test.FooComponent' because " - + "'%1$s' could not be resolved." + trace, - isJavac ? "UnresolvableAnnotation" : "error.NonExistentClass")); + "ComponentProcessingStep was unable to process 'test.FooComponent' because " + + "'UnresolvableAnnotation' could not be resolved." + + "\n " + + "\n Dependency trace:" + + "\n => element (CLASS): test.Bar" + + "\n => element (CONSTRUCTOR): Bar(java.lang.String)" + + "\n => element (PARAMETER): dep" + + "\n => annotation: @UnresolvableAnnotation" + + "\n => type (ERROR annotation type): UnresolvableAnnotation"); }); } }