Cleanup 191 patchset logic (KTI-267)

This commit is contained in:
Yunir Salimzyanov
2020-06-04 19:42:45 +03:00
parent 820353ee0e
commit dce19b0ace
35 changed files with 1004 additions and 1230 deletions
@@ -9,7 +9,6 @@ package org.jetbrains.kotlin.idea.caches.trackers
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SimpleModificationTracker
import com.intellij.pom.tree.TreeAspect
import com.intellij.psi.impl.PsiTreeChangeEventImpl
import org.jetbrains.kotlin.idea.KotlinLanguage
/**
@@ -21,61 +20,32 @@ class KotlinCodeBlockModificationListener(
treeAspect: TreeAspect
) : KotlinCodeBlockModificationListenerCompat(project) {
@Suppress("UnstableApiUsage")
private val isLanguageTrackerEnabled = modificationTrackerImpl.isEnableLanguageTrackerCompat
// FIX ME WHEN BUNCH 191 REMOVED
// When there're we no per-language trackers we had to increment global tracker first and process result afterward
private val customIncrement = if (isLanguageTrackerEnabled) 0 else 1
init {
init(
treeAspect,
incOCBCounter = { ktFile ->
if (isLanguageTrackerEnabled) {
kotlinOutOfCodeBlockTrackerImpl.incModificationCount()
perModuleOutOfCodeBlockTrackerUpdater.onKotlinPhysicalFileOutOfBlockChange(ktFile, true)
} else {
perModuleOutOfCodeBlockTrackerUpdater.onKotlinPhysicalFileOutOfBlockChange(ktFile, false)
// Increment counter and process changes in PsiModificationTracker.Listener
modificationTrackerImpl.incCounter()
}
kotlinOutOfCodeBlockTrackerImpl.incModificationCount()
perModuleOutOfCodeBlockTrackerUpdater.onKotlinPhysicalFileOutOfBlockChange(ktFile, true)
},
kotlinOutOfCodeBlockTrackerProducer = {
if (isLanguageTrackerEnabled) {
SimpleModificationTracker()
} else {
object : SimpleModificationTracker() {
override fun getModificationCount(): Long {
@Suppress("DEPRECATION")
return modificationTrackerImpl.outOfCodeBlockModificationCount
}
}
}
SimpleModificationTracker()
},
psiModificationTrackerListener = {
@Suppress("UnstableApiUsage")
if (isLanguageTrackerEnabled) {
val kotlinTrackerInternalIDECount =
modificationTrackerImpl.forLanguage(KotlinLanguage.INSTANCE).modificationCount
if (kotlinModificationTracker == kotlinTrackerInternalIDECount) {
// Some update that we are not sure is from Kotlin language, as Kotlin language tracker wasn't changed
kotlinOutOfCodeBlockTrackerImpl.incModificationCount()
} else {
kotlinModificationTracker = kotlinTrackerInternalIDECount
}
val kotlinTrackerInternalIDECount =
modificationTrackerImpl.forLanguage(KotlinLanguage.INSTANCE).modificationCount
if (kotlinModificationTracker == kotlinTrackerInternalIDECount) {
// Some update that we are not sure is from Kotlin language, as Kotlin language tracker wasn't changed
kotlinOutOfCodeBlockTrackerImpl.incModificationCount()
} else {
kotlinModificationTracker = kotlinTrackerInternalIDECount
}
perModuleOutOfCodeBlockTrackerUpdater.onPsiModificationTrackerUpdate(customIncrement)
perModuleOutOfCodeBlockTrackerUpdater.onPsiModificationTrackerUpdate()
}
)
}
override fun treeChanged(event: PsiTreeChangeEventImpl) {
assert(isLanguageTrackerEnabled)
super.treeChanged(event)
}
companion object {
fun getInstance(project: Project): KotlinCodeBlockModificationListener =
project.getComponent(KotlinCodeBlockModificationListener::class.java)
@@ -1,13 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.caches.trackers
import com.intellij.psi.impl.PsiModificationTrackerImpl
// FIX ME WHEN BUNCH 191 REMOVED
@Suppress("unused")
val PsiModificationTrackerImpl.isEnableLanguageTrackerCompat
get() = true
@@ -38,22 +38,6 @@ abstract class AbstractKotlinInspection : LocalInspectionTool() {
val problemDescriptor = manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes)
registerProblem(problemDescriptor)
}
// FIX ME WHEN BUNCH 191 REMOVED
// a workaround for IDEA-211491
override fun getProblemElement(psiElement: PsiElement): PsiNamedElement? {
val parent = psiElement.parents().firstOrNull { parent ->
when (parent) {
is KtPropertyAccessor -> true
is KtNamedDeclaration -> parent !is KtValVarKeywordOwner || parent.valOrVarKeyword != null
else -> false
}
}
if (parent is KtPropertyAccessor) {
return parent.property
}
return super.getProblemElement(psiElement)
}
}
@Suppress("unused")