[FIR] Make FirAnalyzerFacade returns diagnostics grouped by fir file

This commit is contained in:
Dmitriy Novozhilov
2020-11-03 16:01:42 +03:00
parent dabc259ae8
commit ed0e5adce7
2 changed files with 5 additions and 5 deletions
@@ -339,7 +339,7 @@ object KotlinToJVMBytecodeCompiler {
val firAnalyzerFacade = FirAnalyzerFacade(session, moduleConfiguration.languageVersionSettings, ktFiles)
firAnalyzerFacade.runResolution()
val firDiagnostics = firAnalyzerFacade.runCheckers()
val firDiagnostics = firAnalyzerFacade.runCheckers().values.flatten()
AnalyzerWithCompilerReport.reportDiagnostics(
SimpleDiagnostics(
firDiagnostics.map { it.toRegularDiagnostic() }
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.KtFile
class FirAnalyzerFacade(val session: FirSession, val languageVersionSettings: LanguageVersionSettings, val ktFiles: List<KtFile>) {
private var firFiles: List<FirFile>? = null
private var scopeSession: ScopeSession? = null
private var collectedDiagnostics: List<FirDiagnostic<*>>? = null
private var collectedDiagnostics: Map<FirFile, List<FirDiagnostic<*>>>? = null
private fun buildRawFir() {
if (firFiles != null) return
@@ -52,13 +52,13 @@ class FirAnalyzerFacade(val session: FirSession, val languageVersionSettings: La
}
@OptIn(ExperimentalStdlibApi::class)
fun runCheckers(): List<FirDiagnostic<*>> {
fun runCheckers(): Map<FirFile, List<FirDiagnostic<*>>> {
if (scopeSession == null) runResolution()
if (collectedDiagnostics != null) return collectedDiagnostics!!
val collector = FirDiagnosticsCollector.create(session)
collectedDiagnostics = buildList {
collectedDiagnostics = buildMap {
for (file in firFiles!!) {
addAll(collector.collectDiagnostics(file))
put(file, collector.collectDiagnostics(file))
}
}
return collectedDiagnostics!!