Use kotlin specific OOCB tracker for light classes inner cache

ClassInnerStuffCache from the platform caches everything with platform
OUT_OF_CODE_BLOCK tracker.
This commit is contained in:
Nikolay Krasko
2019-07-31 14:14:24 +03:00
committed by Nikolay Krasko
parent 78ae1a5745
commit ce3ad8f4da
5 changed files with 264 additions and 3 deletions
@@ -86,6 +86,8 @@ class KotlinCodeBlockModificationListener(
val changeSet = event.getChangeSet(treeAspect) as TreeChangeEvent? ?: return
val ktFile = changeSet.rootElement.psi.containingFile as? KtFile ?: return
incFileModificationCount(ktFile)
val changedElements = changeSet.changedElements
// When a code fragment is reparsed, Intellij doesn't do an AST diff and considers the entire
// contents to be replaced, which is represented in a POM event as an empty list of changed elements
@@ -157,6 +159,12 @@ class KotlinCodeBlockModificationListener(
file.putUserData(FILE_OUT_OF_BLOCK_MODIFICATION_COUNT, count + 1)
}
private fun incFileModificationCount(file: KtFile) {
val tracker = file.getUserData(PER_FILE_MODIFICATION_TRACKER)
?: file.putUserDataIfAbsent(PER_FILE_MODIFICATION_TRACKER, SimpleModificationTracker())
tracker.incModificationCount()
}
fun getInsideCodeBlockModificationScope(element: PsiElement): KtElement? {
val lambda = element.getTopmostParentOfType<KtLambdaExpression>()
if (lambda is KtLambdaExpression) {
@@ -216,6 +224,11 @@ class KotlinCodeBlockModificationListener(
}
}
private val PER_FILE_MODIFICATION_TRACKER = Key<SimpleModificationTracker>("FILE_OUT_OF_BLOCK_MODIFICATION_COUNT")
val KtFile.perFileModificationTracker: ModificationTracker
get() = putUserDataIfAbsent(PER_FILE_MODIFICATION_TRACKER, SimpleModificationTracker())
private val FILE_OUT_OF_BLOCK_MODIFICATION_COUNT = Key<Long>("FILE_OUT_OF_BLOCK_MODIFICATION_COUNT")
val KtFile.outOfBlockModificationCount: Long
@@ -9,11 +9,16 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.util.PsiModificationTracker
import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService
import org.jetbrains.kotlin.psi.KtFile
class KotlinIDEModificationTrackerService(project: Project, psiModificationTracker: PsiModificationTracker) :
KotlinModificationTrackerService() {
override val modificationTracker: ModificationTracker = psiModificationTracker
override val outOfBlockModificationTracker: ModificationTracker =
KotlinCodeBlockModificationListener.getInstance(project).kotlinOutOfCodeBlockTracker
override fun fileModificationTracker(file: KtFile): ModificationTracker =
file.perFileModificationTracker
}