Introduce Lambda Parameter: Merge actions to allow for atomic undo/redo
This commit is contained in:
+12
-3
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.introduce.introduceParameter
|
package org.jetbrains.kotlin.idea.refactoring.introduce.introduceParameter
|
||||||
|
|
||||||
|
import com.intellij.openapi.command.impl.FinishMarkAction
|
||||||
|
import com.intellij.openapi.command.impl.StartMarkAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.options.ConfigurationException
|
import com.intellij.openapi.options.ConfigurationException
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -29,6 +31,7 @@ import com.intellij.usageView.BaseUsageViewDescriptor
|
|||||||
import com.intellij.usageView.UsageInfo
|
import com.intellij.usageView.UsageInfo
|
||||||
import org.jetbrains.kotlin.idea.JetFileType
|
import org.jetbrains.kotlin.idea.JetFileType
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.isMultiLine
|
import org.jetbrains.kotlin.idea.core.refactoring.isMultiLine
|
||||||
|
import org.jetbrains.kotlin.idea.core.refactoring.runRefactoringWithPostprocessing
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinExtractFunctionDialog
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinExtractFunctionDialog
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinParameterTablePanel
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinParameterTablePanel
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
|
||||||
@@ -89,9 +92,10 @@ public class KotlinIntroduceParameterDialog private constructor(
|
|||||||
private var defaultValueCheckBox: JCheckBox? = null
|
private var defaultValueCheckBox: JCheckBox? = null
|
||||||
private val removeParamsCheckBoxes = LinkedHashMap<JCheckBox, JetParameter>(descriptor.parametersToRemove.size())
|
private val removeParamsCheckBoxes = LinkedHashMap<JCheckBox, JetParameter>(descriptor.parametersToRemove.size())
|
||||||
private var parameterTablePanel: KotlinParameterTablePanel? = null
|
private var parameterTablePanel: KotlinParameterTablePanel? = null
|
||||||
|
private val commandName = if (lambdaExtractionDescriptor != null) INTRODUCE_LAMBDA_PARAMETER else INTRODUCE_PARAMETER
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setTitle(if (lambdaExtractionDescriptor != null) INTRODUCE_LAMBDA_PARAMETER else INTRODUCE_PARAMETER)
|
setTitle(commandName)
|
||||||
init()
|
init()
|
||||||
|
|
||||||
nameField.addDataChangedListener { validateButtons() }
|
nameField.addDataChangedListener { validateButtons() }
|
||||||
@@ -269,6 +273,8 @@ public class KotlinIntroduceParameterDialog private constructor(
|
|||||||
var newArgumentValue = descriptor.newArgumentValue
|
var newArgumentValue = descriptor.newArgumentValue
|
||||||
var newReplacer = descriptor.occurrenceReplacer
|
var newReplacer = descriptor.occurrenceReplacer
|
||||||
|
|
||||||
|
val startMarkAction = StartMarkAction.start(editor, myProject, commandName)
|
||||||
|
|
||||||
lambdaExtractionDescriptor?.let { oldDescriptor ->
|
lambdaExtractionDescriptor?.let { oldDescriptor ->
|
||||||
val newDescriptor = KotlinExtractFunctionDialog.createNewDescriptor(
|
val newDescriptor = KotlinExtractFunctionDialog.createNewDescriptor(
|
||||||
oldDescriptor,
|
oldDescriptor,
|
||||||
@@ -316,12 +322,15 @@ public class KotlinIntroduceParameterDialog private constructor(
|
|||||||
occurrenceReplacer = newReplacer
|
occurrenceReplacer = newReplacer
|
||||||
)
|
)
|
||||||
|
|
||||||
helper.configure(descriptorToRefactor).performRefactoring()
|
val introduceParameter = { helper.configure(descriptorToRefactor).performRefactoring() }
|
||||||
|
introduceParameter.runRefactoringWithPostprocessing(myProject, INTRODUCE_PARAMETER_REFACTORING_ID) {
|
||||||
|
FinishMarkAction.finish(myProject, editor, startMarkAction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createUsageViewDescriptor(usages: Array<out UsageInfo>) = BaseUsageViewDescriptor()
|
override fun createUsageViewDescriptor(usages: Array<out UsageInfo>) = BaseUsageViewDescriptor()
|
||||||
|
|
||||||
override fun getCommandName() = if (lambdaExtractionDescriptor != null) INTRODUCE_LAMBDA_PARAMETER else INTRODUCE_PARAMETER
|
override fun getCommandName() = commandName
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -25,7 +25,12 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.PsiReference
|
import com.intellij.psi.PsiReference
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
import com.intellij.refactoring.BaseRefactoringProcessor
|
||||||
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer
|
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer
|
||||||
|
import com.intellij.refactoring.listeners.RefactoringEventListener
|
||||||
|
import com.intellij.usageView.BaseUsageViewDescriptor
|
||||||
|
import com.intellij.usageView.UsageInfo
|
||||||
|
import com.intellij.usageView.UsageViewDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -143,7 +148,14 @@ fun IntroduceParameterDescriptor.performRefactoring() {
|
|||||||
val project = callable.getProject();
|
val project = callable.getProject();
|
||||||
val changeSignature = { runChangeSignature(project, callableDescriptor, config, callable.analyze(), callable, INTRODUCE_PARAMETER) }
|
val changeSignature = { runChangeSignature(project, callableDescriptor, config, callable.analyze(), callable, INTRODUCE_PARAMETER) }
|
||||||
changeSignature.runRefactoringWithPostprocessing(project, "refactoring.changeSignature") {
|
changeSignature.runRefactoringWithPostprocessing(project, "refactoring.changeSignature") {
|
||||||
occurrencesToReplace.forEach { occurrenceReplacer(it) }
|
try {
|
||||||
|
occurrencesToReplace.forEach { occurrenceReplacer(it) }
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
project.getMessageBus()
|
||||||
|
.syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC)
|
||||||
|
.refactoringDone(INTRODUCE_PARAMETER_REFACTORING_ID, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,5 +422,7 @@ public open class KotlinIntroduceLambdaParameterHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val INTRODUCE_PARAMETER_REFACTORING_ID: String = "kotlin.refactoring.introduceParameter"
|
||||||
|
|
||||||
val INTRODUCE_PARAMETER: String = "Introduce Parameter"
|
val INTRODUCE_PARAMETER: String = "Introduce Parameter"
|
||||||
val INTRODUCE_LAMBDA_PARAMETER: String = "Introduce Lambda Parameter"
|
val INTRODUCE_LAMBDA_PARAMETER: String = "Introduce Lambda Parameter"
|
||||||
|
|||||||
Reference in New Issue
Block a user