org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderer.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.diagnostics
import org.jetbrains.kotlin.diagnostics.rendering.*
import org.jetbrains.kotlin.fir.FirSourceElement
interface FirDiagnosticRenderer> : DiagnosticRenderer {
override fun render(diagnostic: D): String
}
class SimpleFirDiagnosticRenderer(private val message: String) : FirDiagnosticRenderer> {
override fun render(diagnostic: FirSimpleDiagnostic): String {
return message
}
}
sealed class AbstractFirDiagnosticWithParametersRenderer>(
protected val message: String
) : FirDiagnosticRenderer, AbstractDiagnosticWithParametersRenderer(message)
class FirDiagnosticWithParameters1Renderer(
message: String,
private val rendererForA: DiagnosticParameterRenderer?,
) : AbstractFirDiagnosticWithParametersRenderer>(message) {
override fun renderParameters(diagnostic: FirDiagnosticWithParameters1): Array {
val context = RenderingContext.of(diagnostic.a)
return arrayOf(renderParameter(diagnostic.a, rendererForA, context))
}
}
class FirDiagnosticWithParameters2Renderer(
message: String,
private val rendererForA: DiagnosticParameterRenderer?,
private val rendererForB: DiagnosticParameterRenderer?,
) : AbstractFirDiagnosticWithParametersRenderer>(message) {
override fun renderParameters(diagnostic: FirDiagnosticWithParameters2): Array {
val context = RenderingContext.of(diagnostic.a, diagnostic.b)
return arrayOf(
renderParameter(diagnostic.a, rendererForA, context),
renderParameter(diagnostic.b, rendererForB, context),
)
}
}
class FirDiagnosticWithParameters3Renderer(
message: String,
private val rendererForA: DiagnosticParameterRenderer?,
private val rendererForB: DiagnosticParameterRenderer?,
private val rendererForC: DiagnosticParameterRenderer?,
) : AbstractFirDiagnosticWithParametersRenderer>(message) {
override fun renderParameters(diagnostic: FirDiagnosticWithParameters3): Array {
val context = RenderingContext.of(diagnostic.a, diagnostic.b, diagnostic.c)
return arrayOf(
renderParameter(diagnostic.a, rendererForA, context),
renderParameter(diagnostic.b, rendererForB, context),
renderParameter(diagnostic.c, rendererForC, context),
)
}
}