diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/commands/impl/JavaGenerateCommandCompletion.kt b/java/java-impl/src/com/intellij/codeInsight/completion/commands/impl/JavaGenerateCommandCompletion.kt index 07206f77f564..eee2c2afdcbb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/commands/impl/JavaGenerateCommandCompletion.kt +++ b/java/java-impl/src/com/intellij/codeInsight/completion/commands/impl/JavaGenerateCommandCompletion.kt @@ -1,12 +1,23 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInsight.completion.commands.impl +import com.intellij.codeInsight.CodeInsightBundle +import com.intellij.codeInsight.completion.command.CommandCompletionProviderContext +import com.intellij.codeInsight.completion.command.CompletionCommand import com.intellij.codeInsight.completion.command.commands.AbstractGenerateCommandProvider +import com.intellij.idea.ActionsBundle +import com.intellij.java.JavaBundle import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.intellij.psi.PsiIdentifier internal class JavaGenerateCommandCompletion : AbstractGenerateCommandProvider() { + private val renaming = mapOf>( + Pair(ActionsBundle.message("action.GenerateGetter.text"), Pair("Getters", JavaBundle.message("command.completion.getters.text"))), + Pair(ActionsBundle.message("action.GenerateSetter.text"), Pair("Setters", JavaBundle.message("command.completion.setters.text"))), + Pair(ActionsBundle.message("action.GenerateGetterAndSetter.text"), Pair("Getters and Setters", JavaBundle.message("command.completion.getters.and.setters.text"))) + ) + override fun generationIsAvailable(element: PsiElement, offset: Int): Boolean { val parent = element.parent if (parent !is PsiClass) return false @@ -14,4 +25,18 @@ internal class JavaGenerateCommandCompletion : AbstractGenerateCommandProvider() !(element is PsiIdentifier && parent.nameIdentifier == element)) return false return true } + + override fun getCommands(context: CommandCompletionProviderContext): List { + val commands = super.getCommands(context) + for (command in commands) { + if (command is GenerateCompletionCommand) { + val newName = renaming[command.action.templateText] + if (newName != null) { + command.customName = "Generate \'${newName.first}\'" + command.customI18nName = CodeInsightBundle.message("command.completion.generate.text", newName.second) + } + } + } + return commands + } } \ No newline at end of file diff --git a/java/openapi/resources/messages/JavaBundle.properties b/java/openapi/resources/messages/JavaBundle.properties index 89c437374057..3f81378ac54a 100644 --- a/java/openapi/resources/messages/JavaBundle.properties +++ b/java/openapi/resources/messages/JavaBundle.properties @@ -1958,6 +1958,9 @@ tooltip.variable.used=Variable ''{0}'' is used command.completion.inline.text=Inline command.completion.delete.element.text=Delete element +command.completion.getters.text=Getters +command.completion.setters.text=Setters +command.completion.getters.and.setters.text=Getters and Setters advanced.setting.java.show.irrelevant.templates.in.source.roots=Show irrelevant New File templates in Java source roots java.test.use.wall.time=Use Wall Time diff --git a/platform/lang-impl/api-dump-experimental.txt b/platform/lang-impl/api-dump-experimental.txt index f554d9f3fec8..4448e896d11e 100644 --- a/platform/lang-impl/api-dump-experimental.txt +++ b/platform/lang-impl/api-dump-experimental.txt @@ -185,8 +185,21 @@ c:com.intellij.codeInsight.actions.VcsFacade - com.intellij.openapi.project.DumbAware - ():V - a:generationIsAvailable(com.intellij.psi.PsiElement,I):Z -- f:getCommands(com.intellij.codeInsight.completion.command.CommandCompletionProviderContext):java.util.List +- getCommands(com.intellij.codeInsight.completion.command.CommandCompletionProviderContext):java.util.List - pf:isOnlySpaceInLine(com.intellij.openapi.editor.Document,I):Z +*pf:com.intellij.codeInsight.completion.command.commands.AbstractGenerateCommandProvider$GenerateCompletionCommand +- com.intellij.codeInsight.completion.command.CompletionCommand +- (com.intellij.codeInsight.actions.CodeInsightAction,java.lang.String,java.lang.String):V +- b:(com.intellij.codeInsight.actions.CodeInsightAction,java.lang.String,java.lang.String,I,kotlin.jvm.internal.DefaultConstructorMarker):V +- execute(I,com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor):V +- f:getAction():com.intellij.codeInsight.actions.CodeInsightAction +- f:getCustomI18nName():java.lang.String +- f:getCustomName():java.lang.String +- getI18nName():java.lang.String +- getIcon():javax.swing.Icon +- getName():java.lang.String +- f:setCustomI18nName(java.lang.String):V +- f:setCustomName(java.lang.String):V *a:com.intellij.codeInsight.completion.command.commands.AbstractGoToDeclarationCompletionCommand - com.intellij.codeInsight.completion.command.commands.AbstractActionCompletionCommand - ():V diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/commands/AbstractGenerateCommandProvider.kt b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/commands/AbstractGenerateCommandProvider.kt index f35256ae2e23..4ea9df4da836 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/commands/AbstractGenerateCommandProvider.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/commands/AbstractGenerateCommandProvider.kt @@ -24,7 +24,7 @@ import javax.swing.Icon * in a code completion system. */ abstract class AbstractGenerateCommandProvider : CommandProvider, DumbAware { - final override fun getCommands(context: CommandCompletionProviderContext): List { + override fun getCommands(context: CommandCompletionProviderContext): List { val psiFile = context.psiFile val project = context.project val offset = context.offset @@ -73,23 +73,27 @@ abstract class AbstractGenerateCommandProvider : CommandProvider, DumbAware { * @return `true` if generation actions are available for the specified element; `false` otherwise. */ abstract fun generationIsAvailable(element: PsiElement, offset: Int): Boolean -} -internal class GenerateCompletionCommand(private val action: CodeInsightAction) : CompletionCommand() { - override val name: String - get() = "Generate \'" + action.templateText + "\'" - override val i18nName: @Nls String - get() = CodeInsightBundle.message("command.completion.generate.text", action.templateText) - override val icon: Icon? - get() = null + protected class GenerateCompletionCommand( + val action: CodeInsightAction, + var customName: String? = null, + var customI18nName: @Nls String? = null, + ) : CompletionCommand() { + override val name: String + get() = customName ?: ("Generate \'" + action.templateText + "\'") + override val i18nName: @Nls String + get() = customI18nName ?: (CodeInsightBundle.message("command.completion.generate.text", action.templateText)) + override val icon: Icon? + get() = null - override fun execute(offset: Int, psiFile: PsiFile, editor: Editor?) { - if (editor == null) return - val dataContext = DataManager.getInstance().getDataContext(editor.getComponent()) - val presentation: Presentation = action.templatePresentation.clone() - val event = AnActionEvent.createEvent(action, dataContext, presentation, ActionPlaces.UNKNOWN, ActionUiKind.NONE, null) - if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) { - ActionUtil.performActionDumbAwareWithCallbacks(action, event) + override fun execute(offset: Int, psiFile: PsiFile, editor: Editor?) { + if (editor == null) return + val dataContext = DataManager.getInstance().getDataContext(editor.getComponent()) + val presentation: Presentation = action.templatePresentation.clone() + val event = AnActionEvent.createEvent(action, dataContext, presentation, ActionPlaces.UNKNOWN, ActionUiKind.NONE, null) + if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) { + ActionUtil.performActionDumbAwareWithCallbacks(action, event) + } } } } \ No newline at end of file