diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt index 4c18c5e9246..fad0e16d4b3 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.context +import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.expressions.FirGetClassCall import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess @@ -39,6 +41,18 @@ abstract class CheckerContext { allWarningsSuppressed: Boolean, allErrorsSuppressed: Boolean ): PersistentCheckerContext + + fun isDiagnosticSuppressed(diagnostic: FirDiagnostic<*>): Boolean { + val factory = diagnostic.factory + val name = factory.name + val suppressedByAll = when (factory.severity) { + Severity.INFO -> allInfosSuppressed + Severity.WARNING -> allWarningsSuppressed + Severity.ERROR -> allErrorsSuppressed + } + + return suppressedByAll || name in suppressedDiagnostics + } } /** diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt index fde5767a9b2..c131d78ce85 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics.impl -import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic @@ -16,15 +15,8 @@ class DiagnosticReporterWithSuppress : BaseDiagnosticReporter() { override fun report(diagnostic: FirDiagnostic<*>?, context: CheckerContext) { if (diagnostic == null) return - val factory = diagnostic.factory - val name = factory.name - val suppressedByAll = when (factory.severity) { - Severity.INFO -> context.allInfosSuppressed - Severity.WARNING -> context.allWarningsSuppressed - Severity.ERROR -> context.allErrorsSuppressed + if (!context.isDiagnosticSuppressed(diagnostic)) { + _diagnostics += diagnostic } - - if (suppressedByAll || name in context.suppressedDiagnostics) return - _diagnostics += diagnostic } } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt index a9a3c9de0e6..d2291cc2569 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt @@ -54,6 +54,7 @@ internal abstract class AbstractFirIdeDiagnosticsCollector( private inner class Reporter : DiagnosticReporter() { override fun report(diagnostic: FirDiagnostic<*>?, context: CheckerContext) { if (diagnostic !is FirPsiDiagnostic<*>) return + if (context.isDiagnosticSuppressed(diagnostic)) return onDiagnostic(diagnostic) } }