Prepare CLI reporting infrastructure for non-PSI diagnostics
This commit is contained in:
+1
@@ -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>>
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user