diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/PluginDeclarationProviderFactory.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/PluginDeclarationProviderFactory.kt index d4520f31c46d..08e8dc9b6cb4 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/PluginDeclarationProviderFactory.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/PluginDeclarationProviderFactory.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo import org.jetbrains.kotlin.idea.caches.project.projectSourceModules import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener -import org.jetbrains.kotlin.idea.caches.trackers.KotlinPackageModificationListener import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil import org.jetbrains.kotlin.idea.util.application.getServiceSafe import org.jetbrains.kotlin.name.FqName @@ -86,7 +85,6 @@ class PluginDeclarationProviderFactory( oldPackageExists = $oldPackageExists, SPI.packageExists = $spiPackageExists, OOCB count = ${KotlinCodeBlockModificationListener.getInstance(project).kotlinOutOfCodeBlockTracker.modificationCount} - PT count = ${KotlinPackageModificationListener.getInstance(project).packageTracker.modificationCount} moduleModificationCount = $moduleModificationCount """.trimIndent() diff --git a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinPackageModificationListener.kt b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinPackageModificationListener.kt deleted file mode 100644 index 61c071d573d8..000000000000 --- a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinPackageModificationListener.kt +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.kotlin.idea.caches.trackers - -import com.intellij.ide.plugins.DynamicPluginListener -import com.intellij.ide.plugins.IdeaPluginDescriptor -import com.intellij.lang.ASTNode -import com.intellij.openapi.Disposable -import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.ProjectFileIndex -import com.intellij.openapi.util.ModificationTracker -import com.intellij.openapi.util.SimpleModificationTracker -import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent -import com.intellij.pom.PomManager -import com.intellij.pom.PomModelAspect -import com.intellij.pom.event.PomModelEvent -import com.intellij.pom.event.PomModelListener -import com.intellij.pom.tree.TreeAspect -import com.intellij.pom.tree.events.TreeChangeEvent -import com.intellij.pom.tree.events.impl.ChangeInfoImpl -import com.intellij.psi.PsiElement -import com.intellij.psi.util.findTopmostParentOfType -import com.intellij.vfs.AsyncVfsEventsListener -import com.intellij.vfs.AsyncVfsEventsPostProcessor -import org.jetbrains.kotlin.idea.util.application.getServiceSafe -import org.jetbrains.kotlin.idea.util.isKotlinFileType -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtPackageDirective -import org.jetbrains.kotlin.psi.stubs.elements.KtFileElementType -import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes -import org.jetbrains.kotlin.utils.addToStdlib.safeAs - -/** - * Tracks potential package changes - * - In Kotlin package directives - * - VFS changes line created new file/folder - * - Plugins load/unload - * - * Tested in [org.jetbrains.kotlin.idea.codeInsight.OutOfBlockModificationTestGenerated] - */ -class KotlinPackageModificationListener(project: Project): Disposable { - private val trackerImpl = SimpleModificationTracker() - - val packageTracker: ModificationTracker = trackerImpl - - init { - val messageBusConnection = project.messageBus.connect(this) - - messageBusConnection.subscribe(DynamicPluginListener.TOPIC, object : DynamicPluginListener { - override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) { - incModificationCount() - } - - override fun pluginLoaded(pluginDescriptor: IdeaPluginDescriptor) { - incModificationCount() - } - }) - - val fileIndex = ProjectFileIndex.SERVICE.getInstance(project) - val vfsEventsListener = AsyncVfsEventsListener { events -> - val relatedVfsFileChange = events.any { event -> - event.takeIf { it.isFromRefresh || it is VFileContentChangeEvent }?.file?.let { - it.isKotlinFileType() && fileIndex.isInContent(it) - } ?: false - } - if (relatedVfsFileChange) { - incModificationCount() - } - } - - AsyncVfsEventsPostProcessor.getInstance().addListener(vfsEventsListener, this) - - val treeAspect: TreeAspect = TreeAspect.getInstance(project) - val model = PomManager.getModel(project) - - model.addModelListener( - object : PomModelListener { - override fun isAspectChangeInteresting(aspect: PomModelAspect): Boolean = aspect == treeAspect - - private fun PsiElement.findPackageDirectiveFqName(): FqName? { - return findTopmostParentOfType(false)?.let { - return it.fqName - } - } - - private inline fun ASTNode?.packageDirectiveChange() = - this?.elementType == KtStubElementTypes.PACKAGE_DIRECTIVE - - override fun modelChanged(event: PomModelEvent) { - val changeSet = event.getChangeSet(treeAspect).safeAs() ?: return - - // track only Kotlin - changeSet.rootElement.psi.containingFile.takeIf { it is KtFile } ?: return - - val packageChange = changeSet.changedElements.any { changedElement -> - if (changedElement.packageDirectiveChange()) return@any true - - val changesByElement = changeSet.getChangesByElement(changedElement) - changesByElement.affectedChildren.any child@ { affectedChild -> - if (affectedChild.packageDirectiveChange()) return@child true - val oldChildNode = changesByElement.getChangeByChild(affectedChild).safeAs()?.oldChildNode - // if oldChildNode is null and new child is Kotlin file - it means file was not exist - if (oldChildNode == null && changedElement.elementType == KtFileElementType.INSTANCE || - oldChildNode?.packageDirectiveChange() == true - ) return@child true - - affectedChild.psi.findPackageDirectiveFqName()?.let { return@child true } - oldChildNode?.psi?.findPackageDirectiveFqName() != null - } - } - if (packageChange) { - incModificationCount() - } - } - } - ) - } - - private fun incModificationCount() { - trackerImpl.incModificationCount() - } - - override fun dispose() = Unit - - companion object { - fun getInstance(project: Project): KotlinPackageModificationListener = project.getServiceSafe() - } -} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeInsight/AbstractOutOfBlockModificationTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeInsight/AbstractOutOfBlockModificationTest.kt index e27b6b8bc34f..6223beacea03 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeInsight/AbstractOutOfBlockModificationTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeInsight/AbstractOutOfBlockModificationTest.kt @@ -14,7 +14,6 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import org.jetbrains.kotlin.idea.FrontendInternals import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade -import org.jetbrains.kotlin.idea.caches.trackers.KotlinPackageModificationListener import org.jetbrains.kotlin.idea.caches.trackers.outOfBlockModificationCount import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils @@ -36,7 +35,6 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur } val expectedOutOfBlock = expectedOutOfBlockResult val text = psiFile.text - val expectedPackageTrackerChange = InTextDirectivesUtils.isDirectiveDefined(text, PACKAGE_CHANGE_DIRECTIVE) val isErrorChecksDisabled = InTextDirectivesUtils.isDirectiveDefined(text, DISABLE_ERROR_CHECKS_DIRECTIVE) val isSkipCheckDefined = InTextDirectivesUtils.isDirectiveDefined(text, SKIP_ANALYZE_CHECK_DIRECTIVE) val project = myFixture.project @@ -44,8 +42,6 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur PsiManager.getInstance(project).modificationTracker as PsiModificationTrackerImpl val element = psiFile.findElementAt(myFixture.caretOffset) assertNotNull("Should be valid element", element) - val packageTracker = KotlinPackageModificationListener.getInstance(project).packageTracker - val ptcBeforeType = packageTracker.modificationCount val oobBeforeType = ktFile?.outOfBlockModificationCount val modificationCountBeforeType = tracker.modificationCount @@ -55,7 +51,6 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur myFixture.type(stringToType) PsiDocumentManager.getInstance(project).commitDocument(myFixture.getDocument(myFixture.file)) val oobAfterCount = ktFile?.outOfBlockModificationCount - val ptcAfterType = packageTracker.modificationCount val modificationCountAfterType = tracker.modificationCount assertTrue( "Modification tracker should always be changed after type", @@ -67,11 +62,6 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur + FileUtil.loadFile(testDataFile()), expectedOutOfBlock, oobBeforeType != oobAfterCount ) - assertEquals( - "package modification tracker differs from expected:\n" - + FileUtil.loadFile(testDataFile()), - expectedPackageTrackerChange, ptcBeforeType != ptcAfterType - ) ktFile?.let { if (!isErrorChecksDisabled) { checkForUnexpectedErrors(it) @@ -149,7 +139,6 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur companion object { const val OUT_OF_CODE_BLOCK_DIRECTIVE = "OUT_OF_CODE_BLOCK:" - const val PACKAGE_CHANGE_DIRECTIVE = "PACKAGE_CHANGE" const val DISABLE_ERROR_CHECKS_DIRECTIVE = "DISABLE_ERROR_CHECKS" const val SKIP_ANALYZE_CHECK_DIRECTIVE = "SKIP_ANALYZE_CHECK" const val TYPE_DIRECTIVE = "TYPE:" diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/FunNoType_Block.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/FunNoType_Block.kt index 42e4504ad1de..4839eaac9bba 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/FunNoType_Block.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/FunNoType_Block.kt @@ -1,8 +1,5 @@ // OUT_OF_CODE_BLOCK: TRUE -// It is kind of false positive as `}` breaks entire PSI and all PSI elements are recreated, even (implicit) package directive -// PACKAGE_CHANGE - // ERROR: Function 'test' must have a body // TYPE: \b diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage.kt index e9ece9cfb11b..e2afa0e7f374 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage.kt @@ -1,6 +1,5 @@ // OUT_OF_CODE_BLOCK: TRUE // DISABLE_ERROR_CHECKS -// PACKAGE_CHANGE package foo.b class Some diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage2.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage2.kt index 20cfe568a188..0e7dbc00b9f7 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage2.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage2.kt @@ -1,5 +1,4 @@ // OUT_OF_CODE_BLOCK: TRUE -// PACKAGE_CHANGE // TYPE: '\n' package foo.b diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage3.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage3.kt index cc12ede02ac8..83c7d85fe4fb 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage3.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage3.kt @@ -1,5 +1,4 @@ // OUT_OF_CODE_BLOCK: TRUE -// PACKAGE_CHANGE // TYPE: '\n' package foo.b diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage4.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage4.kt index 6f5ae19c7341..f9371eca66da 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage4.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/InPackage4.kt @@ -1,5 +1,4 @@ // OUT_OF_CODE_BLOCK: TRUE -// PACKAGE_CHANGE // TYPE: '\b\b\b\b\b\b\b\b\b' package a diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/WholeFileChanged.kt b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/WholeFileChanged.kt index ba096fe37bd3..d475c95c2167 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/WholeFileChanged.kt +++ b/plugins/kotlin/idea/tests/testData/codeInsight/outOfBlock/WholeFileChanged.kt @@ -2,10 +2,6 @@ // TYPE: } // SKIP_ANALYZE_CHECK // ERROR: Function declaration must have a name - -// It is kind of false positive as `}` breaks entire PSI and all PSI elements are recreated, even (implicit) package directive -// PACKAGE_CHANGE - fun test() { val someThing: Any? = null diff --git a/plugins/kotlin/plugin/resources/META-INF/caches.xml b/plugins/kotlin/plugin/resources/META-INF/caches.xml index c1c6ec5a5911..3ebcfe2fb52e 100644 --- a/plugins/kotlin/plugin/resources/META-INF/caches.xml +++ b/plugins/kotlin/plugin/resources/META-INF/caches.xml @@ -13,7 +13,6 @@ -