diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt index 44c5d1704151..cd8752e5bc85 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt @@ -7,30 +7,21 @@ import com.intellij.codeInsight.hint.HintManager import com.intellij.codeInsight.hints.presentation.PresentationRenderer import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.codeInsight.template.impl.TemplateState -import com.intellij.icons.AllIcons import com.intellij.ide.ui.IdeUiService -import com.intellij.internal.statistic.collectors.fus.ui.GotItUsageCollector -import com.intellij.internal.statistic.collectors.fus.ui.GotItUsageCollectorGroup import com.intellij.internal.statistic.eventLog.events.FusInputEvent import com.intellij.java.codeserver.core.JavaPsiVariableUtil import com.intellij.java.refactoring.JavaRefactoringBundle import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.application.EDT import com.intellij.openapi.diff.DiffColors import com.intellij.openapi.editor.* import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.TextAttributesKey -import com.intellij.openapi.editor.event.DocumentEvent -import com.intellij.openapi.editor.event.DocumentListener -import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.editor.markup.RangeHighlighter import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.OpenFileDescriptor -import com.intellij.openapi.keymap.KeymapUtil import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.popup.Balloon import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.TextRange import com.intellij.openapi.vfs.VirtualFile @@ -40,15 +31,12 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtil import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.rename.inplace.TemplateInlayUtil -import com.intellij.ui.GotItTooltip import com.intellij.util.SmartList import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.jetbrains.annotations.Nls -import java.awt.Point import java.awt.event.KeyEvent import java.awt.event.MouseEvent -import java.util.concurrent.CompletableFuture object InplaceExtractUtils { @@ -156,65 +144,6 @@ object InplaceExtractUtils { } } - fun createChangeBasedDisposable(editor: Editor): Disposable { - val disposable = Disposer.newDisposable() - EditorUtil.disposeWithEditor(editor, disposable) - val changeListener = object: DocumentListener { - override fun documentChanged(event: DocumentEvent) { - Disposer.dispose(disposable) - } - } - editor.document.addDocumentListener(changeListener, disposable) - return disposable - } - - fun createNavigationGotIt(parent: Disposable): GotItTooltip? { - val gotoKeyboardShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_GOTO_DECLARATION) - val gotoMouseShortcut = KeymapUtil.getFirstMouseShortcutText(IdeActions.ACTION_GOTO_DECLARATION) - if (gotoKeyboardShortcut.isEmpty() || gotoMouseShortcut.isEmpty()) return null - val header = JavaRefactoringBundle.message("extract.method.gotit.navigation.header") - val message = JavaRefactoringBundle.message("extract.method.gotit.navigation.message", gotoMouseShortcut, gotoKeyboardShortcut) - return GotItTooltip("extract.method.gotit.navigate", message, parent).withHeader(header) - } - - fun createChangeSignatureGotIt(parent: Disposable): GotItTooltip? { - val moveLeftShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.MOVE_ELEMENT_LEFT) - val moveRightShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.MOVE_ELEMENT_RIGHT) - if (moveLeftShortcut.isEmpty() || moveRightShortcut.isEmpty()) return null - val contextActionShortcut = KeymapUtil.getFirstKeyboardShortcutText("ShowIntentionActions") - val header = JavaRefactoringBundle.message("extract.method.gotit.signature.header") - val message = JavaRefactoringBundle.message("extract.method.gotit.signature.message", contextActionShortcut, moveLeftShortcut, moveRightShortcut) - return GotItTooltip("extract.method.signature.change", message, parent) - .withIcon(AllIcons.Gutter.SuggestedRefactoringBulbDisabled) - .withHeader(header) - } - - fun GotItTooltip.showInEditor(editor: Editor, range: TextRange): CompletableFuture { - val offset = minOf(range.startOffset + 3, range.endOffset) - fun getPosition(): Point = editor.offsetToXY(offset) - fun isVisible(): Boolean = editor.scrollingModel.visibleArea.contains(getPosition()) - fun updateBalloon(balloon: Balloon) { - if (isVisible()) { - balloon.revalidate() - } else { - balloon.hide(true) - GotItUsageCollector.instance.logClose(id, GotItUsageCollectorGroup.CloseType.AncestorRemoved) - } - } - withPosition(Balloon.Position.above) - - val balloonFuture = CompletableFuture() - if (isVisible()) { - setOnBalloonCreated { balloon -> - editor.scrollingModel.addVisibleAreaListener({ updateBalloon(balloon) }, balloon) - balloonFuture.complete(balloon) - } - show(editor.contentComponent, pointProvider = { _, _-> getPosition() }) - } - - return balloonFuture - } - fun logStatisticsOnShow(editor: Editor, mouseEvent: MouseEvent? = null){ val showEvent = mouseEvent ?: KeyEvent(editor.component, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_TAB, KeyEvent.VK_TAB.toChar()) diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt index 63464768faf5..09106a9c64aa 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt @@ -8,9 +8,6 @@ import com.intellij.openapi.application.EDT import com.intellij.openapi.application.readAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.asTextRange -import com.intellij.openapi.editor.event.CaretEvent -import com.intellij.openapi.editor.event.CaretListener -import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Key import com.intellij.openapi.util.TextRange @@ -21,20 +18,12 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.refactoring.JavaRefactoringSettings import com.intellij.refactoring.extractMethod.ExtractMethodDialog import com.intellij.refactoring.extractMethod.ExtractMethodHandler -import com.intellij.refactoring.extractMethod.newImpl.CodeFragmentAnalyzer -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodService -import com.intellij.refactoring.extractMethod.newImpl.MethodExtractor +import com.intellij.refactoring.extractMethod.newImpl.* import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.addInlaySettingsElement import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.checkReferenceIdentifier -import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.createChangeBasedDisposable -import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.createChangeSignatureGotIt import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.createGreedyRangeMarker -import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.createNavigationGotIt import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.createPreview import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.findElementAt -import com.intellij.refactoring.extractMethod.newImpl.inplace.InplaceExtractUtils.showInEditor import com.intellij.refactoring.rename.inplace.InplaceRefactoring import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -111,7 +100,6 @@ internal class InplaceMethodExtractor( val methodName = editor.document.getText(range) val extractedMethod = findElementAt(file, methodIdentifierRange) ?: return@onSuccess InplaceExtractMethodCollector.executed.log(defaultExtractor.extractOptions.methodName != methodName) - installGotItTooltips(editor, callIdentifierRange.asTextRange, methodIdentifierRange.asTextRange) MethodExtractor.sendRefactoringDoneEvent(extractedMethod) runWithModalProgressBlocking(project, ExtractMethodHandler.getRefactoringName()) { extractor.replaceDuplicates(editor, extractedMethod) @@ -127,25 +115,6 @@ internal class InplaceMethodExtractor( } } - private fun installGotItTooltips(editor: Editor, navigationGotItRange: TextRange?, changeSignatureGotItRange: TextRange?){ - if (navigationGotItRange == null || changeSignatureGotItRange == null) { - return - } - val parentDisposable = Disposer.newDisposable().also { EditorUtil.disposeWithEditor(editor, it) } - val previousBalloonFuture = createNavigationGotIt(parentDisposable)?.showInEditor(editor, navigationGotItRange) - val disposable = createChangeBasedDisposable(editor) - val caretListener = object: CaretListener { - override fun caretPositionChanged(event: CaretEvent) { - if (editor.logicalPositionToOffset(event.newPosition) in changeSignatureGotItRange) { - previousBalloonFuture?.thenAccept { balloon -> balloon.hide(true) } - createChangeSignatureGotIt(parentDisposable)?.showInEditor(editor, changeSignatureGotItRange) - Disposer.dispose(disposable) - } - } - } - editor.caretModel.addCaretListener(caretListener, disposable) - } - private fun afterTemplateStart(templateState: TemplateState) { setActiveExtractor(editor, this) addInlaySettingsElement(templateState, popupProvider)?.also { inlay -> diff --git a/java/openapi/resources/messages/JavaRefactoringBundle.properties b/java/openapi/resources/messages/JavaRefactoringBundle.properties index d81b97d16a1a..6a09bc36a82a 100644 --- a/java/openapi/resources/messages/JavaRefactoringBundle.properties +++ b/java/openapi/resources/messages/JavaRefactoringBundle.properties @@ -806,10 +806,6 @@ dialog.message.field.doesnt.have.initializer=Field {0} doesn''t have an initiali dialog.message.replace.duplicates.works.with.constants.only=Replace Duplicates works with constants only dialog.message.caret.should.be.inside.method.or.constant=Caret should be positioned inside a method or constant inline.object.command.name=Inline Object -extract.method.gotit.signature.header=Change the method signature -extract.method.gotit.signature.message=

1. Edit the signature

2. Update usages: click the icon in the gutter or press {0}

To reorder parameters, use {1} or {2}.

-extract.method.gotit.navigation.header=Looking to change the method signature? -extract.method.gotit.navigation.message=Go to the method declaration to do it:
{0} the method name or press {1}. introduce.variable.no.matching.occurrences=No matching occurrences inline.super.no.inheritors.warning.message=Cannot inline class without inheritors inline.superclass.foreign.language.conflict.message=Cannot inline to {0}