K2 checkers: separate report committer from other diagnostic components
This commit is contained in:
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.name.StandardClassIds
|
||||
abstract class AbstractDiagnosticCollector(
|
||||
override val session: FirSession,
|
||||
override val scopeSession: ScopeSession = ScopeSession(),
|
||||
protected val createComponents: (DiagnosticReporter) -> List<AbstractDiagnosticCollectorComponent>,
|
||||
protected val createComponents: (DiagnosticReporter) -> DiagnosticCollectorComponents,
|
||||
) : SessionHolder {
|
||||
fun collectDiagnostics(firDeclaration: FirDeclaration, reporter: DiagnosticReporter) {
|
||||
val components = createComponents(reporter)
|
||||
@@ -31,7 +31,7 @@ abstract class AbstractDiagnosticCollector(
|
||||
firDeclaration.accept(visitor, null)
|
||||
}
|
||||
|
||||
protected abstract fun createVisitor(components: List<AbstractDiagnosticCollectorComponent>): CheckerRunningDiagnosticCollectorVisitor
|
||||
protected abstract fun createVisitor(components: DiagnosticCollectorComponents): CheckerRunningDiagnosticCollectorVisitor
|
||||
|
||||
companion object {
|
||||
const val SUPPRESS_ALL_INFOS = "infos"
|
||||
|
||||
+4
-5
@@ -13,19 +13,18 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
|
||||
open class CheckerRunningDiagnosticCollectorVisitor(
|
||||
context: CheckerContext,
|
||||
protected val components: List<AbstractDiagnosticCollectorComponent>
|
||||
protected val components: DiagnosticCollectorComponents
|
||||
) : AbstractDiagnosticCollectorVisitor(context) {
|
||||
|
||||
override fun checkElement(element: FirElement) {
|
||||
components.forEach {
|
||||
components.regularComponents.forEach {
|
||||
element.accept(it, context)
|
||||
}
|
||||
element.accept(components.reportCommitter, context)
|
||||
}
|
||||
|
||||
override fun onDeclarationExit(declaration: FirDeclaration) {
|
||||
if (declaration !is FirFile) return
|
||||
components.forEach {
|
||||
it.endOfFile(declaration)
|
||||
}
|
||||
components.reportCommitter.endOfFile(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.collectors
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.collectors.components.AbstractDiagnosticCollectorComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.collectors.components.ReportCommitterDiagnosticComponent
|
||||
|
||||
class DiagnosticCollectorComponents(
|
||||
val regularComponents: List<AbstractDiagnosticCollectorComponent>,
|
||||
val reportCommitter: ReportCommitterDiagnosticComponent
|
||||
)
|
||||
+2
-2
@@ -15,9 +15,9 @@ import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFull
|
||||
class SimpleDiagnosticsCollector(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
createComponents: (DiagnosticReporter) -> List<AbstractDiagnosticCollectorComponent>,
|
||||
createComponents: (DiagnosticReporter) -> DiagnosticCollectorComponents,
|
||||
) : AbstractDiagnosticCollector(session, scopeSession, createComponents) {
|
||||
override fun createVisitor(components: List<AbstractDiagnosticCollectorComponent>): CheckerRunningDiagnosticCollectorVisitor {
|
||||
override fun createVisitor(components: DiagnosticCollectorComponents): CheckerRunningDiagnosticCollectorVisitor {
|
||||
return CheckerRunningDiagnosticCollectorVisitor(
|
||||
MutableCheckerContext(
|
||||
this,
|
||||
|
||||
-2
@@ -23,6 +23,4 @@ abstract class AbstractDiagnosticCollectorComponent(
|
||||
val source = element.source ?: return
|
||||
reporter.checkAndCommitReportsOn(source, context)
|
||||
}
|
||||
|
||||
open fun endOfFile(file: FirFile) {}
|
||||
}
|
||||
|
||||
+4
-3
@@ -7,17 +7,18 @@ package org.jetbrains.kotlin.fir.analysis.collectors.components
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.collectors.DiagnosticCollectorComponents
|
||||
|
||||
object DiagnosticComponentsFactory {
|
||||
fun createAllDiagnosticComponents(session: FirSession, reporter: DiagnosticReporter): List<AbstractDiagnosticCollectorComponent> {
|
||||
return listOf(
|
||||
fun createAllDiagnosticComponents(session: FirSession, reporter: DiagnosticReporter): DiagnosticCollectorComponents {
|
||||
val regularComponents = listOf(
|
||||
DeclarationCheckersDiagnosticComponent(session, reporter),
|
||||
ExpressionCheckersDiagnosticComponent(session, reporter),
|
||||
TypeCheckersDiagnosticComponent(session, reporter),
|
||||
ErrorNodeDiagnosticCollectorComponent(session, reporter),
|
||||
ControlFlowAnalysisDiagnosticComponent(session, reporter),
|
||||
ReportCommitterDiagnosticComponent(session, reporter)
|
||||
)
|
||||
return DiagnosticCollectorComponents(regularComponents, ReportCommitterDiagnosticComponent(session, reporter))
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ class ReportCommitterDiagnosticComponent(
|
||||
checkAndCommitReportsOn(element, data)
|
||||
}
|
||||
|
||||
override fun endOfFile(file: FirFile) {
|
||||
fun endOfFile(file: FirFile) {
|
||||
checkAndCommitReportsOn(file, null)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user