From 48ec227aafcdff7f90dc5d439e0fd3f94b3d4615 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Wed, 10 Feb 2021 10:59:46 +0300 Subject: [PATCH] [KAPT] Suppress resolve error in annotation procssing #KT-33223 --- .../kotlin/kapt3/base/javac/KaptJavaLog.kt | 1 + .../KaptToolIntegrationTestGenerated.java | 5 +++ .../Test.kt | 28 ++++++++++++++ .../build.txt | 37 +++++++++++++++++++ .../converter/errorLocationMapping.kt | 10 +---- .../testData/converter/invalidFieldName.kt | 4 +- .../testData/converter/kt24272.kt | 3 +- 7 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/Test.kt create mode 100644 plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/build.txt diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt index b43e68d34f1..748a571fb49 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt @@ -210,6 +210,7 @@ class KaptJavaLog( "compiler.err.already.defined", "compiler.err.annotation.type.not.applicable", "compiler.err.doesnt.exist", + "compiler.err.cant.resolve.location", "compiler.err.duplicate.annotation.missing.container", "compiler.err.not.def.access.package.cant.access", "compiler.err.package.not.visible", diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java index 44c26562292..b14aae95ffd 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java +++ b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java @@ -49,6 +49,11 @@ public class KaptToolIntegrationTestGenerated extends AbstractKaptToolIntegratio runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGeneration/"); } + @TestMetadata("kotlinFileGenerationCorrectErrorTypes") + public void testKotlinFileGenerationCorrectErrorTypes() throws Exception { + runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/"); + } + @TestMetadata("kotlinFileGenerationDefaultOutput") public void testKotlinFileGenerationDefaultOutput() throws Exception { runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationDefaultOutput/"); diff --git a/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/Test.kt b/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/Test.kt new file mode 100644 index 00000000000..a8643f0be03 --- /dev/null +++ b/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/Test.kt @@ -0,0 +1,28 @@ +package test + +import apt.Anno +import generated.Test as TestGenerated +import generated.Property + +@Anno +class Test { + + @field:Anno + val property: String = "" + + @Anno + fun function() { + + } + +} + +interface Usage { + fun test(): TestGenerated + fun test1(): generated.Function + fun test2(): Property +} + +fun main() { + println("Generated class: " + TestGenerated::class.java.name) +} diff --git a/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/build.txt b/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/build.txt new file mode 100644 index 00000000000..3feb71f53fe --- /dev/null +++ b/plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/build.txt @@ -0,0 +1,37 @@ +# copy +../kotlinFileGeneration/ap +ap + +# mkdir +output/ap +output/stubs +output/classes +output/sources +output/kotlin-sources + +# kotlinc +-cp %KOTLIN_STDLIB% +-d output/ap +ap/Processor.kt + +# copy +../kotlinFileGeneration/ap/META-INF/services/javax.annotation.processing.Processor +output/ap/META-INF/services/javax.annotation.processing.Processor + +# kapt +-Kapt-stubs=output/stubs +-Kapt-classes=output/classes +-Kapt-sources=output/sources +-Kapt-classpath=output/ap +-Kapt-option:kapt.kotlin.generated=output/kotlin-sources +-Kapt-correct-error-types=true +-d output/classes +-cp output/ap:%KOTLIN_STDLIB% +Test.kt + +# java +-cp output/classes:output/ap:%KOTLIN_STDLIB% +test.TestKt + +# after +Generated class: generated.Test diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt index fdefd42d9ba..3e914d7114f 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt @@ -28,13 +28,5 @@ class ErrorInDeclarations { annotation class Anno(val a: KClass) // EXPECTED_ERROR(kotlin:11:1) cannot find symbol -// EXPECTED_ERROR(kotlin:12:1) cannot find symbol -// EXPECTED_ERROR(kotlin:16:5) cannot find symbol -// EXPECTED_ERROR(kotlin:17:5) cannot find symbol -// EXPECTED_ERROR(kotlin:20:5) cannot find symbol -// EXPECTED_ERROR(kotlin:22:5) cannot find symbol -// EXPECTED_ERROR(kotlin:25:5) cannot find symbol // EXPECTED_ERROR(kotlin:6:1) cannot find symbol -// EXPECTED_ERROR(kotlin:9:34) cannot find symbol -// EXPECTED_ERROR(kotlin:9:50) cannot find symbol -// EXPECTED_ERROR(kotlin:9:62) cannot find symbol \ No newline at end of file +// EXPECTED_ERROR(kotlin:12:1) cannot find symbol diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/invalidFieldName.kt b/plugins/kapt3/kapt3-compiler/testData/converter/invalidFieldName.kt index 8d632996be4..00144698f89 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/invalidFieldName.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/invalidFieldName.kt @@ -5,5 +5,5 @@ enum class Color { @Anno(Color.`WHI-TE`) annotation class Anno(val color: Color) -// EXPECTED_ERROR(kotlin:5:1) cannot find symbol -// EXPECTED_ERROR(other:-1:-1) 'WHI-TE' is an invalid Java enum value name \ No newline at end of file +// EXPECTED_ERROR(kotlin:5:1) an enum annotation value must be an enum constant +// EXPECTED_ERROR(other:-1:-1) 'WHI-TE' is an invalid Java enum value name diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/kt24272.kt b/plugins/kapt3/kapt3-compiler/testData/converter/kt24272.kt index 3106eb438a2..0e3c4995bab 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/kt24272.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/kt24272.kt @@ -10,5 +10,4 @@ class Foo(private val string: String) { } } -// EXPECTED_ERROR(kotlin:9:9) cannot find symbol -// EXPECTED_ERROR(other:-1:-1) Can't generate a stub for 'Foo$Bar$Bar'. \ No newline at end of file +// EXPECTED_ERROR(other:-1:-1) Can't generate a stub for 'Foo$Bar$Bar'.