Make Kotlin OOCBM updater for modules internal again

Replace direct API access with dedicated service.
This commit is contained in:
Pavel Kirpichenkov
2020-07-29 15:46:47 +03:00
parent 9d6bdc6fc4
commit 1ff064d98d
4 changed files with 29 additions and 10 deletions
@@ -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)
}
}
@@ -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,
@@ -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
}
@@ -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<Module>): 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
}
}