More sensible implementation of caching quickfix data between multiple fixes

This commit is contained in:
Dmitry Jemerov
2016-12-07 19:39:40 +03:00
parent a3aa2ca81e
commit 16e648e333
@@ -68,7 +68,7 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : KtElement, D : Any>
// Cache data so that it can be shared between quick fixes bound to the same element & diagnostic // Cache data so that it can be shared between quick fixes bound to the same element & diagnostic
// Cache null values // Cache null values
var cachedData: Ref<D>? = null val cachedData: Ref<D> = Ref.create(extractFixData(originalElement, diagnostic))
val actions: List<QuickFixWithDelegateFactory> = try { val actions: List<QuickFixWithDelegateFactory> = try {
createFixes(originalElementPointer, diagnostic) factory@ { createFixes(originalElementPointer, diagnostic) factory@ {
val element = originalElementPointer.element ?: return@factory null val element = originalElementPointer.element ?: return@factory null
@@ -80,14 +80,12 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : KtElement, D : Any>
.diagnostics .diagnostics
.forElement(diagnosticElement) .forElement(diagnosticElement)
.firstOrNull { DefaultErrorMessages.render(it) == diagnosticMessage } ?: return@factory null .firstOrNull { DefaultErrorMessages.render(it) == diagnosticMessage } ?: return@factory null
if (cachedData == null) {
cachedData = Ref(extractFixData(element, currentDiagnostic)) cachedData.get() ?: extractFixData(element, currentDiagnostic)
}
cachedData!!.get()
}.filter { it.isAvailable(project, null, file) } }.filter { it.isAvailable(project, null, file) }
} }
finally { finally {
cachedData = null // Do not keep cache after all actions are initialized cachedData.set(null) // Do not keep cache after all actions are initialized
} }
return actions return actions