FIR IDE: fix collecting diagnostics multiple times for the same declaration

^KT-45199 fixed
This commit is contained in:
Ilya Kirillov
2021-02-26 17:00:31 +01:00
parent 4acca2fa16
commit 0b921ed9d8
4 changed files with 27 additions and 26 deletions
@@ -58,7 +58,7 @@ abstract class AbstractDiagnosticCollector(
@Suppress("LeakingThis")
private var context = PersistentCheckerContext(this, returnTypeCalculator)
private var currentAction = DiagnosticCollectorDeclarationAction.CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
private var currentAction = DiagnosticCollectorDeclarationAction.CHECK_IN_CURRENT_DECLARATION_AND_LOOKUP_FOR_NESTED
fun initializeComponents(vararg components: AbstractDiagnosticCollectorComponent) {
if (componentsInitialized) {
@@ -72,9 +72,11 @@ abstract class AbstractDiagnosticCollector(
private inner class Visitor : FirDefaultVisitor<Unit, Nothing?>() {
private fun <T : FirElement> T.runComponents() {
components.forEach {
beforeCollecting()
this.accept(it, context)
if (currentAction.checkInCurrentDeclaration) {
components.forEach {
beforeCollecting()
this.accept(it, context)
}
}
}
@@ -220,13 +222,11 @@ abstract class AbstractDiagnosticCollector(
declaration: FirDeclaration,
block: () -> Unit = { declaration.acceptChildren(this, null) }
) {
if (!currentAction.checkNested) return
if (!currentAction.lookupForNestedDeclaration) return
val action = onDeclarationEnter(declaration)
if (action.checkCurrentDeclaration) {
declaration.runComponents()
}
val action = getDeclarationActionOnDeclarationEnter(declaration)
withDiagnosticsAction(action) {
declaration.runComponents()
withDeclaration(declaration) {
block()
}
@@ -258,8 +258,8 @@ abstract class AbstractDiagnosticCollector(
}
}
protected open fun onDeclarationEnter(declaration: FirDeclaration): DiagnosticCollectorDeclarationAction =
DiagnosticCollectorDeclarationAction.CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
protected open fun getDeclarationActionOnDeclarationEnter(declaration: FirDeclaration): DiagnosticCollectorDeclarationAction =
DiagnosticCollectorDeclarationAction.CHECK_IN_CURRENT_DECLARATION_AND_LOOKUP_FOR_NESTED
protected open fun onDeclarationExit(declaration: FirDeclaration) {}
@@ -334,11 +334,11 @@ abstract class AbstractDiagnosticCollector(
}
}
enum class DiagnosticCollectorDeclarationAction(val checkCurrentDeclaration: Boolean, val checkNested: Boolean) {
CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED(checkCurrentDeclaration = true, checkNested = true),
CHECK_CURRENT_DECLARATION_AND_SKIP_NESTED(checkCurrentDeclaration = true, checkNested = false),
SKIP_CURRENT_DECLARATION_AND_CHECK_NESTED(checkCurrentDeclaration = false, checkNested = true),
SKIP(checkCurrentDeclaration = false, checkNested = false),
enum class DiagnosticCollectorDeclarationAction(val checkInCurrentDeclaration: Boolean, val lookupForNestedDeclaration: Boolean) {
CHECK_IN_CURRENT_DECLARATION_AND_LOOKUP_FOR_NESTED(checkInCurrentDeclaration = true, lookupForNestedDeclaration = true),
CHECK_IN_CURRENT_DECLARATION_AND_DO_NOT_LOOKUP_FOR_NESTED(checkInCurrentDeclaration = true, lookupForNestedDeclaration = false),
DO_NOT_CHECK_IN_CURRENT_DECLARATION_AND_LOOKUP_FOR_NESTED(checkInCurrentDeclaration = false, lookupForNestedDeclaration = true),
SKIP(checkInCurrentDeclaration = false, lookupForNestedDeclaration = false),
}
fun AbstractDiagnosticCollector.registerAllComponents() {