Prepare CLI reporting infrastructure for non-PSI diagnostics

This commit is contained in:
Ilya Chernikov
2021-10-04 12:22:03 +02:00
parent 5446168770
commit 1ce4075112
10 changed files with 182 additions and 28 deletions
@@ -10,4 +10,5 @@ import org.jetbrains.kotlin.diagnostics.KtDiagnostic
abstract class BaseDiagnosticReporter : DiagnosticReporter() {
abstract val diagnostics: List<KtDiagnostic>
abstract val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
}
@@ -13,10 +13,10 @@ import org.jetbrains.kotlin.diagnostics.KtDiagnostic
class DeduplicatingDiagnosticReporter(private val inner: DiagnosticReporter) : DiagnosticReporter() {
private val reported = mutableSetOf<Pair<AbstractKtSourceElement, AbstractKtDiagnosticFactory>>()
private val reported = mutableSetOf<Triple<String?, AbstractKtSourceElement, AbstractKtDiagnosticFactory>>()
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) {
if (diagnostic != null && reported.add(Pair(diagnostic.element, diagnostic.factory))) {
if (diagnostic != null && reported.add(Triple(context.containingFilePath, diagnostic.element, diagnostic.factory))) {
inner.report(diagnostic, context)
}
}
@@ -9,14 +9,16 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticContext
import org.jetbrains.kotlin.diagnostics.KtDiagnostic
class DiagnosticReporterWithSuppress : BaseDiagnosticReporter() {
private val _diagnostics: MutableList<KtDiagnostic> = mutableListOf()
private val _diagnosticsByFilePath: MutableMap<String?, MutableList<KtDiagnostic>> = mutableMapOf()
override val diagnostics: List<KtDiagnostic>
get() = _diagnostics
get() = _diagnosticsByFilePath.flatMap { it.value }
override val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
get() = _diagnosticsByFilePath
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) {
if (diagnostic == null) return
if (!context.isDiagnosticSuppressed(diagnostic)) {
_diagnostics += diagnostic
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.add(diagnostic)
}
}
}
@@ -9,12 +9,14 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticContext
import org.jetbrains.kotlin.diagnostics.KtDiagnostic
class SimpleDiagnosticReporter : BaseDiagnosticReporter() {
private val _diagnostics: MutableList<KtDiagnostic> = mutableListOf()
private val _diagnosticsByFilePath: MutableMap<String?, MutableList<KtDiagnostic>> = mutableMapOf()
override val diagnostics: List<KtDiagnostic>
get() = _diagnostics
get() = _diagnosticsByFilePath.flatMap { it.value }
override val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
get() = _diagnosticsByFilePath
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) {
if (diagnostic == null) return
_diagnostics += diagnostic
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.add(diagnostic)
}
}