From 16e648e3338878eaa10a1553fef4bf1a65a1ee8c Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 7 Dec 2016 19:39:40 +0300 Subject: [PATCH] More sensible implementation of caching quickfix data between multiple fixes --- .../KotlinIntentionActionFactoryWithDelegate.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinIntentionActionFactoryWithDelegate.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinIntentionActionFactoryWithDelegate.kt index 0cd63de8f83..ce40352d173 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinIntentionActionFactoryWithDelegate.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinIntentionActionFactoryWithDelegate.kt @@ -68,7 +68,7 @@ abstract class KotlinIntentionActionFactoryWithDelegate // Cache data so that it can be shared between quick fixes bound to the same element & diagnostic // Cache null values - var cachedData: Ref? = null + val cachedData: Ref = Ref.create(extractFixData(originalElement, diagnostic)) val actions: List = try { createFixes(originalElementPointer, diagnostic) factory@ { val element = originalElementPointer.element ?: return@factory null @@ -80,14 +80,12 @@ abstract class KotlinIntentionActionFactoryWithDelegate .diagnostics .forElement(diagnosticElement) .firstOrNull { DefaultErrorMessages.render(it) == diagnosticMessage } ?: return@factory null - if (cachedData == null) { - cachedData = Ref(extractFixData(element, currentDiagnostic)) - } - cachedData!!.get() + + cachedData.get() ?: extractFixData(element, currentDiagnostic) }.filter { it.isAvailable(project, null, file) } } 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