Minor: cleanup and reformat KotlinCodeBlockModificationListener.kt
This commit is contained in:
+11
-14
@@ -58,15 +58,13 @@ class KotlinCodeBlockModificationListener(
|
|||||||
|
|
||||||
// All modifications since that count are known to be single-module modifications reflected in
|
// All modifications since that count are known to be single-module modifications reflected in
|
||||||
// perModuleModCount map
|
// perModuleModCount map
|
||||||
private var perModuleChangesHighwatermark: Long? = null
|
private var perModuleChangesHighWatermark: Long? = null
|
||||||
|
|
||||||
fun getModificationCount(module: Module): Long {
|
fun getModificationCount(module: Module): Long {
|
||||||
return perModuleModCount[module] ?:
|
return perModuleModCount[module] ?: perModuleChangesHighWatermark ?: modificationTrackerImpl.outOfCodeBlockModificationCount
|
||||||
perModuleChangesHighwatermark ?:
|
|
||||||
modificationTrackerImpl.outOfCodeBlockModificationCount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasPerModuleModificationCounts() = perModuleChangesHighwatermark != null
|
fun hasPerModuleModificationCounts() = perModuleChangesHighWatermark != null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val model = PomManager.getModel(project)
|
val model = PomManager.getModel(project)
|
||||||
@@ -80,7 +78,7 @@ class KotlinCodeBlockModificationListener(
|
|||||||
val changeSet = event.getChangeSet(treeAspect) as TreeChangeEvent? ?: return
|
val changeSet = event.getChangeSet(treeAspect) as TreeChangeEvent? ?: return
|
||||||
val file = changeSet.rootElement.psi.containingFile as? KtFile ?: return
|
val file = changeSet.rootElement.psi.containingFile as? KtFile ?: return
|
||||||
val changedElements = changeSet.changedElements
|
val changedElements = changeSet.changedElements
|
||||||
// When a code fragment is reparsed, IntelliJ doesn't do an AST diff and considers the entire
|
// 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
|
// contents to be replaced, which is represented in a POM event as an empty list of changed elements
|
||||||
if (changedElements.any { getInsideCodeBlockModificationScope(it.psi) == null } || changedElements.isEmpty()) {
|
if (changedElements.any { getInsideCodeBlockModificationScope(it.psi) == null } || changedElements.isEmpty()) {
|
||||||
messageBusConnection.deliverImmediately()
|
messageBusConnection.deliverImmediately()
|
||||||
@@ -98,13 +96,12 @@ class KotlinCodeBlockModificationListener(
|
|||||||
val newModCount = modificationTrackerImpl.outOfCodeBlockModificationCount
|
val newModCount = modificationTrackerImpl.outOfCodeBlockModificationCount
|
||||||
val affectedModule = lastAffectedModule
|
val affectedModule = lastAffectedModule
|
||||||
if (affectedModule != null && newModCount == lastAffectedModuleModCount + 1) {
|
if (affectedModule != null && newModCount == lastAffectedModuleModCount + 1) {
|
||||||
if (perModuleChangesHighwatermark == null) {
|
if (perModuleChangesHighWatermark == null) {
|
||||||
perModuleChangesHighwatermark = lastAffectedModuleModCount
|
perModuleChangesHighWatermark = lastAffectedModuleModCount
|
||||||
}
|
}
|
||||||
perModuleModCount[affectedModule] = newModCount
|
perModuleModCount[affectedModule] = newModCount
|
||||||
}
|
} else {
|
||||||
else {
|
perModuleChangesHighWatermark = null
|
||||||
perModuleChangesHighwatermark = null
|
|
||||||
perModuleModCount.clear()
|
perModuleModCount.clear()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -134,8 +131,7 @@ class KotlinCodeBlockModificationListener(
|
|||||||
is KtNamedFunction -> {
|
is KtNamedFunction -> {
|
||||||
if (blockDeclaration.hasBlockBody()) {
|
if (blockDeclaration.hasBlockBody()) {
|
||||||
return blockDeclaration.bodyExpression?.takeIf { it.isAncestor(element) }
|
return blockDeclaration.bodyExpression?.takeIf { it.isAncestor(element) }
|
||||||
}
|
} else if (blockDeclaration.hasDeclaredReturnType()) {
|
||||||
else if (blockDeclaration.hasDeclaredReturnType()) {
|
|
||||||
return blockDeclaration.initializer?.takeIf { it.isAncestor(element) }
|
return blockDeclaration.initializer?.takeIf { it.isAncestor(element) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,7 +187,8 @@ class KotlinModuleModificationTracker(val module: Module): ModificationTracker {
|
|||||||
CachedValueProvider.Result.create(
|
CachedValueProvider.Result.create(
|
||||||
HashSet<Module>().apply {
|
HashSet<Module>().apply {
|
||||||
ModuleRootManager.getInstance(module).orderEntries().recursively().forEachModule(
|
ModuleRootManager.getInstance(module).orderEntries().recursively().forEachModule(
|
||||||
CommonProcessors.CollectProcessor(this))
|
CommonProcessors.CollectProcessor(this)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
ProjectRootModificationTracker.getInstance(module.project)
|
ProjectRootModificationTracker.getInstance(module.project)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user