diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt index fa120ca58ed..082e7efcd65 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt @@ -46,7 +46,9 @@ object FirDiagnosticRenderers { modifierRenderer = FirPartialModifierRenderer(), valueParameterRenderer = FirValueParameterRendererNoDefaultValue(), declarationRenderer = FirDeclarationRenderer("local "), + annotationRenderer = FirAnnotationRendererForReadability(), lineBreakAfterContextReceivers = false, + renderFieldAnnotationSeparately = false, ).renderElementAsString(symbol.fir, trim = true) is FirTypeParameterSymbol -> symbol.name.asString() else -> "???" diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirAnnotationRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirAnnotationRenderer.kt index a303cb8e632..707214398d5 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirAnnotationRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirAnnotationRenderer.kt @@ -32,7 +32,7 @@ open class FirAnnotationRenderer { internal fun renderAnnotation(annotation: FirAnnotation, explicitAnnotationUseSiteTarget: AnnotationUseSiteTarget? = null) { printer.print("@") (explicitAnnotationUseSiteTarget ?: annotation.useSiteTarget)?.let { - printer.print(it.name) + renderUseSiteTarget(it) printer.print(":") } @@ -56,4 +56,14 @@ open class FirAnnotationRenderer { printer.print(" ") } } + + open protected fun renderUseSiteTarget(it: AnnotationUseSiteTarget) { + printer.print(it.name) + } } + +class FirAnnotationRendererForReadability : FirAnnotationRenderer() { + override fun renderUseSiteTarget(it: AnnotationUseSiteTarget) { + printer.print(it.renderName) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt index e1b61b98361..2674f95c3a0 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt @@ -47,6 +47,7 @@ class FirRenderer( override val resolvedNamedReferenceRenderer: FirResolvedNamedReferenceRenderer = FirResolvedNamedReferenceRendererWithLabel(), override val resolvedQualifierRenderer: FirResolvedQualifierRenderer = FirResolvedQualifierRendererWithLabel(), private val lineBreakAfterContextReceivers: Boolean = true, + private val renderFieldAnnotationSeparately: Boolean = true, override val getClassCallRenderer: FirGetClassCallRenderer = FirGetClassCallRendererForDebugging(), ) : FirRendererComponents { @@ -258,7 +259,9 @@ class FirRenderer( if (callableDeclaration is FirProperty) { val backingField = callableDeclaration.backingField if (backingField?.annotations?.isNotEmpty() == true) { - print("field:") + if (renderFieldAnnotationSeparately) { + print("field:") + } annotationRenderer?.render(backingField) } } diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt index 73c840d07f3..9919679f4ae 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt @@ -1,9 +1,13 @@ -/deprecatedError.kt:10:13: error: using 'C' is an error. alas +/deprecatedError.kt:14:13: error: using 'C' is an error. alas fun test(c: C) { ^ -/deprecatedError.kt:11:5: error: using 'foo(String): Unit' is an error. alas +/deprecatedError.kt:15:5: error: using 'foo(String): Unit' is an error. alas foo("") ^ -/deprecatedError.kt:12:5: error: using 'C' is an error. alas +/deprecatedError.kt:16:5: error: using 'C' is an error. alas C() ^ +/deprecatedError.kt:17:5: error: using 'bar: Int' is an error. alas + bar + ^ + diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt index 04eb853da78..c58b0bdeea5 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt @@ -1,5 +1,7 @@ -/deprecatedError.kt:(237,238): error: '@Deprecated(...) class C : Any' is deprecated. alas. +/deprecatedError.kt:(319,320): error: '@Deprecated(...) class C : Any' is deprecated. alas. -/deprecatedError.kt:(246,249): error: '@Deprecated(...) fun foo(s: @Foo() String): Unit' is deprecated. alas. +/deprecatedError.kt:(328,331): error: '@Deprecated(...) fun foo(s: @Foo() String): Unit' is deprecated. alas. -/deprecatedError.kt:(258,259): error: 'constructor(): C' is deprecated. alas. +/deprecatedError.kt:(340,341): error: 'constructor(): C' is deprecated. alas. + +/deprecatedError.kt:(348,351): error: '@Deprecated(...) @field:Foo() val bar: Int' is deprecated. alas. diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt index 4569ef0b8e4..64aee76c864 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt @@ -7,10 +7,15 @@ fun foo(s: @Foo String) {} @Deprecated("alas", level = DeprecationLevel.ERROR) class C +@field:Foo +@Deprecated("alas", level = DeprecationLevel.ERROR) +val bar: Int = 42 + fun test(c: C) { foo("") C() + bar } -@Target(AnnotationTarget.TYPE) +@Target(AnnotationTarget.TYPE, AnnotationTarget.FIELD) annotation class Foo \ No newline at end of file