mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
[fleet] java extract - handle duplicates for expressions
GitOrigin-RevId: f22aeeef1f47374a67f6f64ceae97f3fe8480b0f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
46e2dfa159
commit
31ffbe939c
@@ -3,7 +3,6 @@ package com.intellij.refactoring.extractMethod.newImpl
|
||||
|
||||
import com.intellij.codeInsight.Nullability
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.internal.statistic.eventLog.events.EventPair
|
||||
import com.intellij.java.refactoring.JavaRefactoringBundle
|
||||
import com.intellij.openapi.application.ReadAction
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
@@ -31,7 +30,10 @@ import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.replac
|
||||
import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.findAllOptionsToExtract
|
||||
import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.selectOptionWithTargetClass
|
||||
import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.withFilteredAnnotations
|
||||
import com.intellij.refactoring.extractMethod.newImpl.inplace.*
|
||||
import com.intellij.refactoring.extractMethod.newImpl.inplace.ExtractMethodPopupProvider
|
||||
import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils
|
||||
import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceMethodExtractor
|
||||
import com.intellij.refactoring.extractMethod.newImpl.inplace.extractInDialog
|
||||
import com.intellij.refactoring.extractMethod.newImpl.parameterObject.ResultObjectExtractor
|
||||
import com.intellij.refactoring.extractMethod.newImpl.structures.ExtractOptions
|
||||
import com.intellij.refactoring.listeners.RefactoringEventData
|
||||
@@ -82,7 +84,7 @@ class MethodExtractor {
|
||||
)
|
||||
}
|
||||
|
||||
private fun prepareDescriptorsForAllTargetPlaces(editor: Editor, file: PsiFile, range: TextRange): List<ExtractOptions> {
|
||||
fun prepareDescriptorsForAllTargetPlaces(editor: Editor, file: PsiFile, range: TextRange): List<ExtractOptions> {
|
||||
try {
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(file.project, file)) return emptyList()
|
||||
val elements = ExtractSelector().suggestElementsToExtract(file, range)
|
||||
|
||||
@@ -76,7 +76,7 @@ class DuplicatesMethodExtractor(val extractOptions: ExtractOptions, val targetCl
|
||||
return ExtractedElements(replacedCalls, replacedMethod)
|
||||
}
|
||||
|
||||
fun replaceDuplicates(editor: Editor, method: PsiMethod) {
|
||||
fun replaceDuplicates(editor: Editor, method: PsiMethod, beforeDuplicateReplaced: (candidate: List<PsiElement>) -> Unit = {}) {
|
||||
val prepareTimeStart = System.currentTimeMillis()
|
||||
val project = editor.project ?: return
|
||||
val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
|
||||
@@ -156,6 +156,7 @@ class DuplicatesMethodExtractor(val extractOptions: ExtractOptions, val targetCl
|
||||
}
|
||||
|
||||
duplicates.zip(duplicatesExtractOptions).forEach { (duplicate, extractOptions) ->
|
||||
beforeDuplicateReplaced(duplicate.candidate)
|
||||
val callElements = CallBuilder(extractOptions.elements.first()).createCall(replacedMethod, extractOptions)
|
||||
runWriteAction {
|
||||
replacePsiRange(duplicate.candidate, callElements)
|
||||
|
||||
Reference in New Issue
Block a user