[FIR] Render diagnostics parameters instead of full text in debug messages (closer to old tests)

This commit is contained in:
Ivan Kochurkin
2021-05-20 18:28:50 +03:00
committed by TeamCityServer
parent 6de97e17fe
commit ef53f0e0b3
6 changed files with 23 additions and 6 deletions
@@ -9,12 +9,18 @@ import org.jetbrains.kotlin.diagnostics.rendering.*
interface FirDiagnosticRenderer<D : FirDiagnostic<*>> : DiagnosticRenderer<D> {
override fun render(diagnostic: D): String
override fun renderParameters(diagnostic: D): Array<out Any?>
}
class SimpleFirDiagnosticRenderer(private val message: String) : FirDiagnosticRenderer<FirSimpleDiagnostic<*>> {
override fun render(diagnostic: FirSimpleDiagnostic<*>): String {
return message
}
override fun renderParameters(diagnostic: FirSimpleDiagnostic<*>): Array<out Any?> {
return arrayOf()
}
}
sealed class AbstractFirDiagnosticWithParametersRenderer<D : FirDiagnostic<*>>(
@@ -9,4 +9,6 @@ import org.jetbrains.kotlin.diagnostics.UnboundDiagnostic
interface DiagnosticRenderer<in D : UnboundDiagnostic> {
fun render(diagnostic: D): String
fun renderParameters(diagnostic: D): Array<out Any?>
}
@@ -31,4 +31,10 @@ public class SimpleDiagnosticRenderer implements DiagnosticRenderer<Diagnostic>
public String render(@NotNull Diagnostic diagnostic) {
return message;
}
@NotNull
@Override
public Object[] renderParameters(@NotNull Diagnostic diagnostic) {
return new Object[0];
}
}
@@ -27,11 +27,11 @@ abstract class AbstractDiagnosticWithParametersRenderer<in D : UnboundDiagnostic
return messageFormat.format(renderParameters(diagnostic))
}
abstract fun renderParameters(diagnostic: D): Array<out Any?>
override fun renderParameters(diagnostic: D): Array<out Any?> {
return arrayOf()
}
}
class DiagnosticWithParameters1Renderer<A>(
message: String,
private val rendererForA: DiagnosticParameterRenderer<A>?
@@ -83,7 +83,7 @@ class DiagnosticWithParameters4Renderer<A : Any, B : Any, C : Any, D : Any>(
private val rendererForD: DiagnosticParameterRenderer<D>?,
) : AbstractDiagnosticWithParametersRenderer<DiagnosticWithParameters4<*, A, B, C, D>>(message) {
override fun renderParameters(diagnostic: DiagnosticWithParameters4<*, A, B, C, D>): Array<out Any> {
override fun renderParameters(diagnostic: DiagnosticWithParameters4<*, A, B, C, D>): Array<out Any?> {
val context = RenderingContext.of(diagnostic.a, diagnostic.b, diagnostic.c, diagnostic.d)
return arrayOf(
renderParameter(diagnostic.a, rendererForA, context),
@@ -6,7 +6,7 @@ class A() {
field = <!ASSIGNMENT_TYPE_MISMATCH!>value<!>
}
val y: Int
get(): <!WRONG_GETTER_RETURN_TYPE("Getter return type must be equal to the type of the property, i.e. 'kotlin/Int'")!>String<!> = "s"
get(): <!WRONG_GETTER_RETURN_TYPE("kotlin/Int; kotlin/String")!>String<!> = "s"
val z: Int
get() {
return "s"
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.frontend.fir.handlers
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.fir.analysis.diagnostics.AbstractFirDiagnosticWithParametersRenderer
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDefaultErrorMessages
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderer
@@ -67,7 +68,9 @@ class FirDiagnosticCodeMetaRenderConfiguration(
@Suppress("UNCHECKED_CAST")
val renderer = FirDefaultErrorMessages.getRendererForDiagnostic(diagnostic) as FirDiagnosticRenderer<FirDiagnostic<*>>
params.add(renderer.render(diagnostic))
if (renderer is AbstractFirDiagnosticWithParametersRenderer<*>) {
renderer.renderParameters(diagnostic).mapTo(params, Any?::toString)
}
if (renderSeverity)
params.add("severity='${diagnostic.severity}'")