From 7f0930975d0d6b8f321fe057ec1823ae4ad08eeb Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Thu, 9 Jan 2025 06:25:01 +0100 Subject: [PATCH] [kotlin] Add k1 invalidateCaches #KTIJ-5644 GitOrigin-RevId: ba69c563cf00f2a00511948ed2a7d167fcb3506a --- .../kotlin/formatter/AbstractFormatterTest.kt | 8 ++------ .../idea/inspections/AbstractInspectionTest.kt | 10 ++-------- .../jetbrains/kotlin/test/util/invalidateUtil.kt | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/test/util/invalidateUtil.kt diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractFormatterTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractFormatterTest.kt index a674180241a6f..67ac2affb0eac 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractFormatterTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractFormatterTest.kt @@ -8,8 +8,6 @@ import com.intellij.testFramework.common.runAll import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils -import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener -import org.jetbrains.kotlin.idea.caches.trackers.KotlinModuleOutOfCodeBlockModificationTracker import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinTestUtils @@ -17,16 +15,14 @@ import org.jetbrains.kotlin.idea.test.configureCodeStyleAndRun import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.scripting.definitions.ScriptConfigurationsProvider +import org.jetbrains.kotlin.test.util.invalidateCaches import java.io.File abstract class AbstractFormatterTest : KotlinLightCodeInsightFixtureTestCase() { override fun tearDown() { runAll( - { runInEdtAndWait { - KotlinCodeBlockModificationListener.getInstance(project).incModificationCount() - KotlinModuleOutOfCodeBlockModificationTracker.incrementModificationCountForAllModules(project) - } }, + { runInEdtAndWait { project.invalidateCaches() } }, { super.tearDown() }, ) } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractInspectionTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractInspectionTest.kt index 121043abb4557..27bfaa1fd2f46 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractInspectionTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractInspectionTest.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.codeInspection.ex.EntryPointsManagerBase import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.fileTypes.FileTypeManager -import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiFile import com.intellij.testFramework.TestLoggerFactory @@ -14,11 +13,10 @@ import org.jdom.Document import org.jdom.input.SAXBuilder import org.jetbrains.kotlin.formatter.FormatSettingsUtil import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils -import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener -import org.jetbrains.kotlin.idea.caches.trackers.KotlinModuleOutOfCodeBlockModificationTracker import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout import org.jetbrains.kotlin.idea.test.* import org.jetbrains.kotlin.idea.util.application.executeWriteCommand +import org.jetbrains.kotlin.test.util.invalidateCaches import org.jetbrains.plugins.groovy.GroovyFileType import org.junit.runner.Description import java.io.File @@ -49,11 +47,7 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase() { EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.remove(ENTRY_POINT_ANNOTATION) }, { - runInEdtAndWait { - KotlinCodeBlockModificationListener.getInstance(project).incModificationCount() - KotlinModuleOutOfCodeBlockModificationTracker.incrementModificationCountForAllModules(project) - ProjectRootManager.getInstance(project).incModificationCount() - } + runInEdtAndWait { project.invalidateCaches() } }, { super.tearDown() } ) diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/test/util/invalidateUtil.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/test/util/invalidateUtil.kt new file mode 100644 index 0000000000000..874e990647b28 --- /dev/null +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/test/util/invalidateUtil.kt @@ -0,0 +1,15 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.test.util + +import com.intellij.openapi.application.runWriteAction +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener +import org.jetbrains.kotlin.idea.caches.trackers.KotlinModuleOutOfCodeBlockModificationTracker + +fun Project.invalidateCaches() { + runWriteAction { + // see Fe10KotlinGlobalModificationService + KotlinCodeBlockModificationListener.getInstance(this).incModificationCount() + KotlinModuleOutOfCodeBlockModificationTracker.incrementModificationCountForAllModules(this) + } +} \ No newline at end of file