[extract method] remove redundant initial name parameter

GitOrigin-RevId: de1e6344e4a403af1e31db08bdb619912a619b2b
This commit is contained in:
Alexandr Suhinin
2024-07-24 15:13:01 +03:00
committed by intellij-monorepo-bot
parent e2a5109b5f
commit 32ae65de50
2 changed files with 8 additions and 10 deletions

View File

@@ -125,8 +125,7 @@ class MethodExtractor {
val suggestedNames = guessedNames.takeIf { it.size > 1 }.orEmpty()
executeRefactoringCommand(project) {
val extractor = DuplicatesMethodExtractor.create(options.targetClass, options.elements, methodName, options.isStatic)
require(extractor.targetClass == options.targetClass)
val inplaceExtractor = InplaceMethodExtractor(editor, range, popupSettings, extractor, methodName)
val inplaceExtractor = InplaceMethodExtractor(editor, range, popupSettings, extractor)
inplaceExtractor.extractAndRunTemplate(LinkedHashSet(suggestedNames))
}
}

View File

@@ -42,8 +42,7 @@ import com.intellij.refactoring.rename.inplace.InplaceRefactoring
internal class InplaceMethodExtractor(private val editor: Editor,
private val range: TextRange,
private val popupProvider: ExtractMethodPopupProvider,
private val baseExtractor: DuplicatesMethodExtractor,
private val initialMethodName: String) {
private val defaultExtractor: DuplicatesMethodExtractor) {
companion object {
private val INPLACE_METHOD_EXTRACTOR = Key<InplaceMethodExtractor>("InplaceMethodExtractor")
@@ -59,7 +58,7 @@ internal class InplaceMethodExtractor(private val editor: Editor,
private val extractor: DuplicatesMethodExtractor = createExtractor()
private val file: PsiFile = baseExtractor.targetClass.containingFile
private val file: PsiFile = defaultExtractor.targetClass.containingFile
private val editorState = EditorState(file.project, editor)
@@ -72,13 +71,13 @@ internal class InplaceMethodExtractor(private val editor: Editor,
private val project = file.project
private fun createExtractor(): DuplicatesMethodExtractor {
val elements = ExtractSelector().suggestElementsToExtract(baseExtractor.targetClass.containingFile, range)
var options = baseExtractor.extractOptions
val elements = ExtractSelector().suggestElementsToExtract(defaultExtractor.targetClass.containingFile, range)
var options = defaultExtractor.extractOptions
if (popupProvider.makeStatic == true) {
val analyzer = CodeFragmentAnalyzer(options.elements)
options = ExtractMethodPipeline.withForcedStatic(analyzer, options) ?: throw IllegalStateException()
}
return DuplicatesMethodExtractor(options, baseExtractor.targetClass, elements)
return DuplicatesMethodExtractor(options, defaultExtractor.targetClass, elements)
}
fun extractAndRunTemplate(suggestedNames: LinkedHashSet<String>) {
@@ -122,7 +121,7 @@ internal class InplaceMethodExtractor(private val editor: Editor,
val range = callIdentifierRange?.asTextRange ?: return@onSuccess
val methodName = editor.document.getText(range)
val extractedMethod = findElementAt<PsiMethod>(file, methodIdentifierRange) ?: return@onSuccess
InplaceExtractMethodCollector.executed.log(initialMethodName != methodName)
InplaceExtractMethodCollector.executed.log(defaultExtractor.extractOptions.methodName != methodName)
installGotItTooltips(editor, callIdentifierRange?.asTextRange, methodIdentifierRange?.asTextRange)
MethodExtractor.sendRefactoringDoneEvent(extractedMethod)
extractor.replaceDuplicates(editor, extractedMethod)
@@ -199,7 +198,7 @@ internal class InplaceMethodExtractor(private val editor: Editor,
val methodName = if (identifierRange != null) editor.document.getText(identifierRange) else null
TemplateManagerImpl.getTemplateState(editor)?.gotoEnd(true)
WriteCommandAction.writeCommandAction(project).withName(ExtractMethodHandler.getRefactoringName()).run<Throwable> {
val inplaceExtractor = InplaceMethodExtractor(editor, range, popupProvider, baseExtractor, initialMethodName)
val inplaceExtractor = InplaceMethodExtractor(editor, range, popupProvider, defaultExtractor)
inplaceExtractor.extractAndRunTemplate(linkedSetOf())
if (methodName != null) {
inplaceExtractor.setMethodName(methodName)