[FIR] Inherit FIR with parameter renderer from the old parameter renderer
This commit is contained in:
+4
-13
@@ -7,13 +7,12 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.*
|
import org.jetbrains.kotlin.diagnostics.rendering.*
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import java.text.MessageFormat
|
|
||||||
|
|
||||||
sealed class FirDiagnosticRenderer<D : FirDiagnostic<*>> : DiagnosticRenderer<D> {
|
interface FirDiagnosticRenderer<D : FirDiagnostic<*>> : DiagnosticRenderer<D> {
|
||||||
abstract override fun render(diagnostic: D): String
|
override fun render(diagnostic: D): String
|
||||||
}
|
}
|
||||||
|
|
||||||
class SimpleFirDiagnosticRenderer<E : FirSourceElement>(private val message: String) : FirDiagnosticRenderer<FirSimpleDiagnostic<E>>() {
|
class SimpleFirDiagnosticRenderer<E : FirSourceElement>(private val message: String) : FirDiagnosticRenderer<FirSimpleDiagnostic<E>> {
|
||||||
override fun render(diagnostic: FirSimpleDiagnostic<E>): String {
|
override fun render(diagnostic: FirSimpleDiagnostic<E>): String {
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
@@ -21,15 +20,7 @@ class SimpleFirDiagnosticRenderer<E : FirSourceElement>(private val message: Str
|
|||||||
|
|
||||||
sealed class AbstractFirDiagnosticWithParametersRenderer<D : FirDiagnostic<*>>(
|
sealed class AbstractFirDiagnosticWithParametersRenderer<D : FirDiagnostic<*>>(
|
||||||
protected val message: String
|
protected val message: String
|
||||||
) : FirDiagnosticRenderer<D>() {
|
) : FirDiagnosticRenderer<D>, AbstractDiagnosticWithParametersRenderer<D>(message)
|
||||||
private val messageFormat = MessageFormat(message)
|
|
||||||
|
|
||||||
override fun render(diagnostic: D): String {
|
|
||||||
return messageFormat.format(renderParameters(diagnostic))
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun renderParameters(diagnostic: D): Array<out Any>
|
|
||||||
}
|
|
||||||
|
|
||||||
class FirDiagnosticWithParameters1Renderer<E : FirSourceElement, A : Any>(
|
class FirDiagnosticWithParameters1Renderer<E : FirSourceElement, A : Any>(
|
||||||
message: String,
|
message: String,
|
||||||
|
|||||||
+2
-2
@@ -23,8 +23,8 @@ import java.text.MessageFormat
|
|||||||
abstract class AbstractDiagnosticWithParametersRenderer<D : Diagnostic> protected constructor(message: String) : DiagnosticRenderer<D> {
|
abstract class AbstractDiagnosticWithParametersRenderer<D : Diagnostic> protected constructor(message: String) : DiagnosticRenderer<D> {
|
||||||
private val messageFormat = MessageFormat(message)
|
private val messageFormat = MessageFormat(message)
|
||||||
|
|
||||||
override fun render(obj: D): String {
|
override fun render(diagnostic: D): String {
|
||||||
return messageFormat.format(renderParameters(obj))
|
return messageFormat.format(renderParameters(diagnostic))
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun renderParameters(diagnostic: D): Array<out Any>
|
abstract fun renderParameters(diagnostic: D): Array<out Any>
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
|||||||
argument: () -> String,
|
argument: () -> String,
|
||||||
): FirDiagnosticWithParameters1<FirSourceElement, String>? {
|
): FirDiagnosticWithParameters1<FirSourceElement, String>? {
|
||||||
val sourceElement = element.source ?: return null
|
val sourceElement = element.source ?: return null
|
||||||
|
if (sourceElement.kind != FirRealSourceElementKind) return null
|
||||||
val name = name ?: return null
|
val name = name ?: return null
|
||||||
if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(name) != true) return null
|
if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(name) != true) return null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user