From 8d5e69b06cb9e6a33f4d65a099d02d6a96b35c61 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 1 Aug 2017 16:06:45 +0300 Subject: [PATCH] Inline variable: do not show dialog / preview from J2K #KT-19332 Fixed --- .../org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt | 2 +- .../idea/refactoring/inline/KotlinInlineValDialog.kt | 5 +++-- .../idea/refactoring/inline/KotlinInlineValHandler.kt | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt index d7277a2aa86..e96b8741feb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt +++ b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt @@ -280,7 +280,7 @@ object J2KPostProcessingRegistrar { if (!UnnecessaryVariableInspection.isActiveFor(element)) return null return { - KotlinInlineValHandler().inlineElement(element.project, element.findExistingEditor(), element) + KotlinInlineValHandler(withPrompt = false).inlineElement(element.project, element.findExistingEditor(), element) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValDialog.kt index a3e8b0cf1a3..b4465e6118b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValDialog.kt @@ -30,7 +30,8 @@ class KotlinInlineValDialog( private val property: KtProperty, private val reference: KtSimpleNameReference?, private val replacementStrategy: UsageReplacementStrategy, - private val assignmentToDelete: KtBinaryExpression? + private val assignmentToDelete: KtBinaryExpression?, + withPreview: Boolean = true ) : InlineOptionsDialog(property.project, true, property) { private var occurrenceCount = initOccurrencesNumber(property) @@ -42,7 +43,7 @@ class KotlinInlineValDialog( init { myInvokedOnReference = reference != null title = refactoringName - setPreviewResults(shouldBeShown()) + setPreviewResults(withPreview && shouldBeShown()) if (forSimpleLocal()) { setDoNotAskOption(object : DialogWrapper.DoNotAskOption { override fun isToBeShown() = EditorSettingsExternalizable.getInstance().isShowInlineLocalDialog diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt index 4dac95a8585..91238627483 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt @@ -47,7 +47,9 @@ import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis -class KotlinInlineValHandler : InlineActionHandler() { +class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHandler() { + + constructor(): this(withPrompt = true) override fun isEnabledForLanguage(l: Language) = l == KotlinLanguage.INSTANCE @@ -185,9 +187,9 @@ class KotlinInlineValHandler : InlineActionHandler() { val reference = editor?.let { TargetElementUtil.findReference(it, it.caretModel.offset) } as? KtSimpleNameReference - val dialog = KotlinInlineValDialog(declaration, reference, replacementStrategy, assignmentToDelete) + val dialog = KotlinInlineValDialog(declaration, reference, replacementStrategy, assignmentToDelete, withPreview = withPrompt) - if (!ApplicationManager.getApplication().isUnitTestMode && dialog.shouldBeShown()) { + if (withPrompt && !ApplicationManager.getApplication().isUnitTestMode && dialog.shouldBeShown()) { dialog.show() if (!dialog.isOK && hasHighlightings) { val statusBar = WindowManager.getInstance().getStatusBar(declaration.project)