Minor: cleanup and reformat KotlinCodeBlockModificationListener.kt

This commit is contained in:
Nikolay Krasko
2019-05-29 14:56:49 +03:00
parent 2029d16062
commit 2ddcd9f0af
@@ -58,15 +58,13 @@ class KotlinCodeBlockModificationListener(
// All modifications since that count are known to be single-module modifications reflected in
// perModuleModCount map
private var perModuleChangesHighwatermark: Long? = null
private var perModuleChangesHighWatermark: Long? = null
fun getModificationCount(module: Module): Long {
return perModuleModCount[module] ?:
perModuleChangesHighwatermark ?:
modificationTrackerImpl.outOfCodeBlockModificationCount
return perModuleModCount[module] ?: perModuleChangesHighWatermark ?: modificationTrackerImpl.outOfCodeBlockModificationCount
}
fun hasPerModuleModificationCounts() = perModuleChangesHighwatermark != null
fun hasPerModuleModificationCounts() = perModuleChangesHighWatermark != null
init {
val model = PomManager.getModel(project)
@@ -80,7 +78,7 @@ class KotlinCodeBlockModificationListener(
val changeSet = event.getChangeSet(treeAspect) as TreeChangeEvent? ?: return
val file = changeSet.rootElement.psi.containingFile as? KtFile ?: return
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
if (changedElements.any { getInsideCodeBlockModificationScope(it.psi) == null } || changedElements.isEmpty()) {
messageBusConnection.deliverImmediately()
@@ -98,13 +96,12 @@ class KotlinCodeBlockModificationListener(
val newModCount = modificationTrackerImpl.outOfCodeBlockModificationCount
val affectedModule = lastAffectedModule
if (affectedModule != null && newModCount == lastAffectedModuleModCount + 1) {
if (perModuleChangesHighwatermark == null) {
perModuleChangesHighwatermark = lastAffectedModuleModCount
if (perModuleChangesHighWatermark == null) {
perModuleChangesHighWatermark = lastAffectedModuleModCount
}
perModuleModCount[affectedModule] = newModCount
}
else {
perModuleChangesHighwatermark = null
} else {
perModuleChangesHighWatermark = null
perModuleModCount.clear()
}
})
@@ -134,8 +131,7 @@ class KotlinCodeBlockModificationListener(
is KtNamedFunction -> {
if (blockDeclaration.hasBlockBody()) {
return blockDeclaration.bodyExpression?.takeIf { it.isAncestor(element) }
}
else if (blockDeclaration.hasDeclaredReturnType()) {
} else if (blockDeclaration.hasDeclaredReturnType()) {
return blockDeclaration.initializer?.takeIf { it.isAncestor(element) }
}
}
@@ -191,7 +187,8 @@ class KotlinModuleModificationTracker(val module: Module): ModificationTracker {
CachedValueProvider.Result.create(
HashSet<Module>().apply {
ModuleRootManager.getInstance(module).orderEntries().recursively().forEachModule(
CommonProcessors.CollectProcessor(this))
CommonProcessors.CollectProcessor(this)
)
},
ProjectRootModificationTracker.getInstance(module.project)
)