From 1ff064d98db2cef32c3e93210d125be89af02e1b Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 29 Jul 2020 15:46:47 +0300 Subject: [PATCH] Make Kotlin OOCBM updater for modules internal again Replace direct API access with dedicated service. --- ...onAnchorAwareLibraryModificationTracker.kt | 9 ++++---- ...tlinCodeBlockModificationListenerCompat.kt | 3 +-- ...ModuleOutOfCodeBlockModificationTracker.kt | 6 ++---- ...esolutionAnchorModificationCountService.kt | 21 +++++++++++++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/ResolutionAnchorModificationCountService.kt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/ResolutionAnchorAwareLibraryModificationTracker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/ResolutionAnchorAwareLibraryModificationTracker.kt index 21c6c0add9b..0eb150e3af4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/ResolutionAnchorAwareLibraryModificationTracker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/ResolutionAnchorAwareLibraryModificationTracker.kt @@ -7,14 +7,15 @@ package org.jetbrains.kotlin.idea.caches.project import com.intellij.openapi.util.ModificationTracker import org.jetbrains.kotlin.idea.caches.resolve.ResolutionAnchorCacheService -import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener +import org.jetbrains.kotlin.idea.caches.trackers.ResolutionAnchorModificationCountService class ResolutionAnchorAwareLibraryModificationTracker( private val libraryInfo: LibraryInfo, ) : ModificationTracker { override fun getModificationCount(): Long { - val anchorDependencies = ResolutionAnchorCacheService.getInstance(libraryInfo.project).getDependencyResolutionAnchors(libraryInfo) - val updaterForModules = KotlinCodeBlockModificationListener.getInstance(libraryInfo.project).perModuleOutOfCodeBlockTrackerUpdater - return anchorDependencies.maxOfOrNull { updaterForModules.getModificationCount(it.module) } ?: 0 + val anchorDependencyModules = ResolutionAnchorCacheService.getInstance(libraryInfo.project) + .getDependencyResolutionAnchors(libraryInfo) + .map { it.module } + return ResolutionAnchorModificationCountService.getLatestModificationCount(anchorDependencyModules) } } diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt index 364aadf02a7..9c6521beb74 100644 --- a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt @@ -50,8 +50,7 @@ abstract class KotlinCodeBlockModificationListenerCompat(protected val project: lateinit var kotlinOutOfCodeBlockTracker: ModificationTracker - // TODO: close back exposed API - val perModuleOutOfCodeBlockTrackerUpdater = KotlinModuleOutOfCodeBlockModificationTracker.Updater(project) + internal val perModuleOutOfCodeBlockTrackerUpdater = KotlinModuleOutOfCodeBlockModificationTracker.Updater(project) protected fun init( treeAspect: TreeAspect, diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinModuleOutOfCodeBlockModificationTracker.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinModuleOutOfCodeBlockModificationTracker.kt index 2e5d56055e4..d9be08a0a32 100644 --- a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinModuleOutOfCodeBlockModificationTracker.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinModuleOutOfCodeBlockModificationTracker.kt @@ -68,8 +68,7 @@ class KotlinModuleOutOfCodeBlockModificationTracker private constructor(private } } - // TODO: close back exposed API - class Updater(project: Project) { + internal class Updater(project: Project) { private val kotlinOfOfCodeBlockTracker by lazy { KotlinCodeBlockModificationListener.getInstance(project).kotlinOutOfCodeBlockTracker } @@ -84,8 +83,7 @@ class KotlinModuleOutOfCodeBlockModificationTracker private constructor(private // perModuleModCount map private var perModuleChangesHighWatermark: Long? = null - // TODO: close back exposed API - fun getModificationCount(module: Module): Long { + internal fun getModificationCount(module: Module): Long { return perModuleModCount[module] ?: perModuleChangesHighWatermark ?: kotlinOfOfCodeBlockTracker.modificationCount } diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/ResolutionAnchorModificationCountService.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/ResolutionAnchorModificationCountService.kt new file mode 100644 index 00000000000..bd7288d3a7e --- /dev/null +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/ResolutionAnchorModificationCountService.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2020 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.openapi.module.Module +import com.intellij.openapi.util.ModificationTracker + +object ResolutionAnchorModificationCountService { + fun getLatestModificationCount(anchorModules: Collection): Long { + if (anchorModules.isEmpty()) + return ModificationTracker.NEVER_CHANGED.modificationCount + + val modificationCountUpdater = + KotlinCodeBlockModificationListener.getInstance(anchorModules.first().project).perModuleOutOfCodeBlockTrackerUpdater + return anchorModules.maxOfOrNull { modificationCountUpdater.getModificationCount(it) } + ?: ModificationTracker.NEVER_CHANGED.modificationCount + } +}