[command-completion] IDEA-359174 command completion

- plural 'getter' and 'setter'

GitOrigin-RevId: 72baab4184338cd2e49d156358e6df8dd7b1bcf6
This commit is contained in:
Mikhail Pyltsin
2025-02-21 12:05:41 +00:00
committed by intellij-monorepo-bot
parent 41137e55e2
commit e4963f56d8
4 changed files with 62 additions and 17 deletions
@@ -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<String, Pair<String, String>>(
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<CompletionCommand> {
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
}
}
@@ -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
+14 -1
View File
@@ -185,8 +185,21 @@ c:com.intellij.codeInsight.actions.VcsFacade
- com.intellij.openapi.project.DumbAware
- <init>():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
- <init>(com.intellij.codeInsight.actions.CodeInsightAction,java.lang.String,java.lang.String):V
- b:<init>(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
- <init>():V
@@ -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<CompletionCommand> {
override fun getCommands(context: CommandCompletionProviderContext): List<CompletionCommand> {
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)
}
}
}
}