[command-completion] IDEA-375693 Command completion. Java. Impossible to rename parameters

- simplify conditions
- more tests

GitOrigin-RevId: 7d9e80bfd3567e8181c445b0ca6256f6fc5c82d2
This commit is contained in:
Mikhail Pyltsin
2025-07-14 15:54:21 +00:00
committed by intellij-monorepo-bot
parent 7561b57236
commit 14789d0e75
2 changed files with 28 additions and 4 deletions
@@ -27,8 +27,7 @@ class JavaRenameActionCommandProvider: AbstractRenameActionCommandProvider() {
//<..> place to call 'rename'
val method = element.parentOfType<PsiMethod>()
if (method != null &&
(method.identifyingElement?.textRange?.startOffset ?: Int.MAX_VALUE) < currentOffset &&
((!method.parameterList.textRange.contains(currentOffset) && (method.body?.lBrace?.textRange?.startOffset ?: 0) >= currentOffset) ||
(method.identifyingElement?.textRange?.endOffset == currentOffset ||
method.parameterList.textRange.endOffset == currentOffset ||
method.body?.rBrace?.textRange?.endOffset == currentOffset)) return method.identifyingElement?.textRange?.endOffset
@@ -443,7 +443,11 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
}
}""".trimIndent())
val elements = myFixture.completeBasic()
assertTrue(elements.any { element -> element.lookupString.contains("Rename", ignoreCase = true) })
val lookupElement = elements
.firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) }
?.`as`(CommandCompletionLookupElement::class.java)
assertNotNull(lookupElement)
assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range)
}
fun testRenameMethod2() {
@@ -456,7 +460,28 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
}.<caret>
}""".trimIndent())
val elements = myFixture.completeBasic()
assertTrue(elements.any { element -> element.lookupString.contains("Rename", ignoreCase = true) })
val lookupElement = elements
.firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) }
?.`as`(CommandCompletionLookupElement::class.java)
assertNotNull(lookupElement)
assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range)
}
fun testRenameMethod3() {
Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable())
myFixture.configureByText(JavaFileType.INSTANCE, """
class A {
void foo.<caret>() {
String y = "1";
System.out.println(y);
}
}""".trimIndent())
val elements = myFixture.completeBasic()
val lookupElement = elements
.firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) }
?.`as`(CommandCompletionLookupElement::class.java)
assertNotNull(lookupElement)
assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range)
}
fun testParameterRename() {