From f53f92cdd641a137ab14c0933f0fdccf7e3771cc Mon Sep 17 00:00:00 2001 From: Alexey Belkov Date: Thu, 7 Dec 2023 15:52:41 +0400 Subject: [PATCH] K2: Add KtDiagnosticRenderers.CLASS_ID to render ClassId FQNs with dots KT-MR-13391 --- ...cCompilerTestFirTestdataTestGenerated.java | 6 +++ ...osticCompilerFirTestDataTestGenerated.java | 6 +++ .../ClassIdDiagnosticRendering.fir.txt | 47 +++++++++++++++++++ .../ClassIdDiagnosticRendering.kt | 33 +++++++++++++ .../FirLightTreeDiagnosticsTestGenerated.java | 6 +++ .../FirPsiDiagnosticTestGenerated.java | 6 +++ .../diagnostics/FirErrorsDefaultMessages.kt | 15 +++--- .../diagnostics/KtDiagnosticRenderers.kt | 5 ++ 8 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java index 459553cff85..4412818498e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java @@ -5290,6 +5290,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); } + @Test + @TestMetadata("ClassIdDiagnosticRendering.kt") + public void testClassIdDiagnosticRendering() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java index 8a9755eea1a..dbc6fec71b9 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java @@ -5290,6 +5290,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); } + @Test + @TestMetadata("ClassIdDiagnosticRendering.kt") + public void testClassIdDiagnosticRendering() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.fir.txt new file mode 100644 index 00000000000..b47c3a1bf6d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.fir.txt @@ -0,0 +1,47 @@ +FILE: ClassIdDiagnosticRendering.kt + package a.b.c + + @R|kotlin/RequiresOptIn|() public final annotation class Marker : R|kotlin/Annotation| { + public constructor(): R|a/b/c/Marker| { + super() + } + + } + @R|a/b/c/Marker|() public final class Some : R|kotlin/Any| { + public constructor(): R|a/b/c/Some| { + super() + } + + } + public final fun main(): R|kotlin/Unit| { + R|a/b/c/Some.Some|() + } + public final annotation class DummyAnnotation : R|kotlin/Annotation| { + public constructor(): R|a/b/c/DummyAnnotation| { + super() + } + + } + @R|kotlin/SubclassOptInRequired|(markerClass = (Q|a/b/c/DummyAnnotation|)) public open class IncorrectSubclassOptInArgumentMarker : R|kotlin/Any| { + public constructor(): R|a/b/c/IncorrectSubclassOptInArgumentMarker| { + super() + } + + } + internal abstract fun interface StableInterface : R|kotlin/Any| { + @R|a/b/c/Marker|() public abstract fun experimentalMethod(): R|kotlin/Unit| + + } + public final fun testOverrides(): R|kotlin/Unit| { + object : R|a/b/c/StableInterface| { + private constructor(): R|a/b/c/| { + super() + } + + public open override fun experimentalMethod(): R|kotlin/Unit| { + } + + } + + } + public final actual typealias TypealiasToKotlinPkg = R|kotlin/Deprecated| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt new file mode 100644 index 00000000000..4960279efdb --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt @@ -0,0 +1,33 @@ +// WITH_EXTENDED_CHECKERS + +package a.b.c + +import kotlin.jvm.functions.Function0 + +@RequiresOptIn +annotation class Marker + +@Marker +class Some + +fun main() { + Some() +} + +annotation class DummyAnnotation + +@SubclassOptInRequired(DummyAnnotation::class) +open class IncorrectSubclassOptInArgumentMarker + +internal fun interface StableInterface { + @Marker + fun experimentalMethod() +} + +fun testOverrides() { + object : StableInterface { + override fun experimentalMethod() {} + } +} + +actual typealias TypealiasToKotlinPkg = kotlin.Deprecated \ No newline at end of file diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java index 3ed37566ac6..1c9ed80257f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java @@ -5290,6 +5290,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); } + @Test + @TestMetadata("ClassIdDiagnosticRendering.kt") + public void testClassIdDiagnosticRendering() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java index 24584362566..886347a71ad 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java @@ -5290,6 +5290,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); } + @Test + @TestMetadata("ClassIdDiagnosticRendering.kt") + public void testClassIdDiagnosticRendering() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/ClassIdDiagnosticRendering.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index 57848f1cbb8..8c49776779d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap +import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.CLASS_ID import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.COLLECTION import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.EMPTY import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.FUNCTION_PARAMETERS @@ -890,7 +891,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { map.put(SINGLETON_IN_SUPERTYPE, "Cannot extend an object.") map.put(NULLABLE_SUPERTYPE, "Supertypes cannot be nullable.") map.put(REDUNDANT_NULLABLE, "Redundant '?'.") - map.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class is not recommended for use in Kotlin. Use ''{0}'' instead.", TO_STRING) + map.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class is not recommended for use in Kotlin. Use ''{0}'' instead.", CLASS_ID) map.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class can appear in a supertype list.") map.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice.") map.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum classes cannot extend classes.") @@ -1049,11 +1050,11 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { ) // OptIn - map.put(OPT_IN_USAGE, "{1}", TO_STRING, STRING) - map.put(OPT_IN_USAGE_ERROR, "{1}", TO_STRING, STRING) + map.put(OPT_IN_USAGE, "{1}", CLASS_ID, STRING) + map.put(OPT_IN_USAGE_ERROR, "{1}", CLASS_ID, STRING) - map.put(OPT_IN_OVERRIDE, "{1}", TO_STRING, STRING) - map.put(OPT_IN_OVERRIDE_ERROR, "{1}", TO_STRING, STRING) + map.put(OPT_IN_OVERRIDE, "{1}", CLASS_ID, STRING) + map.put(OPT_IN_OVERRIDE_ERROR, "{1}", CLASS_ID, STRING) map.put(OPT_IN_IS_NOT_ENABLED, "This annotation should be used with the compiler argument '-opt-in=kotlin.RequiresOptIn'.") map.put(OPT_IN_CAN_ONLY_BE_USED_AS_ANNOTATION, "This class can only be used as an annotation.") @@ -1065,7 +1066,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { map.put( OPT_IN_ARGUMENT_IS_NOT_MARKER, "Annotation ''{0}'' is not an opt-in requirement marker; therefore, its usage in @OptIn is ignored.", - TO_STRING + CLASS_ID ) map.put( OPT_IN_MARKER_WITH_WRONG_TARGET, @@ -2072,7 +2073,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { map.put( ACTUAL_TYPEALIAS_TO_SPECIAL_ANNOTATION, "''actual typealias'' to annotation which affects code compilation can lead to incorrect behavior. Instead, use ''{0}'' annotation directly.", - TO_STRING + CLASS_ID ) map.put( ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT, diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/KtDiagnosticRenderers.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/KtDiagnosticRenderers.kt index 8ba72bd0fe5..e3c01097794 100644 --- a/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/KtDiagnosticRenderers.kt +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/KtDiagnosticRenderers.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.diagnostics import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.diagnostics.rendering.ContextIndependentParameterRenderer import org.jetbrains.kotlin.diagnostics.rendering.Renderer +import org.jetbrains.kotlin.name.ClassId object KtDiagnosticRenderers { val NULLABLE_STRING = Renderer { it ?: "null" } @@ -33,6 +34,10 @@ object KtDiagnosticRenderers { val FUNCTION_PARAMETERS = Renderer { hasValueParameters: Boolean -> if (hasValueParameters) "..." else "" } + val CLASS_ID = Renderer { classId: ClassId -> + classId.asFqNameString() + } + @Suppress("FunctionName") fun COLLECTION(renderer: ContextIndependentParameterRenderer): ContextIndependentParameterRenderer> { return Renderer { list ->