Java: fix inline renaming of lambda parameters with conflict (IDEA-377645)

GitOrigin-RevId: ddaf13469dc000dbeaab4fe1f25d1687d87237a5
This commit is contained in:
Bas Leijdekkers
2025-09-06 11:30:07 +00:00
committed by intellij-monorepo-bot
parent b3fa4de450
commit 62575dc2aa
4 changed files with 25 additions and 1 deletions
@@ -0,0 +1,10 @@
class ConfictInLambdaParameter {
public void consume(Consumer<Object> c) {
}
public void bug() {
consume(o -> { // line 1
consume(o1<caret> -> {}); // line 2
});
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -116,6 +116,12 @@ public class RenameLocalTest extends LightRefactoringTestCase {
"Variable 's' Already Exists",
() -> doTestInplaceRename("s"));
}
public void testConflictInLambdaParameter() {
assertThrows(BaseRefactoringProcessor.ConflictsInTestsException.class,
"Variable 'o' Already Exists",
() -> doTestInplaceRename("o"));
}
public void testConflictWithFutureVar() {
assertThrows(BaseRefactoringProcessor.ConflictsInTestsException.class,
+2
View File
@@ -999,6 +999,8 @@ com.intellij.refactoring.introduce.IntroduceTarget
- a:render():java.lang.String
com.intellij.refactoring.move.MoveCallback
- a:refactoringCompleted():V
c:com.intellij.refactoring.rename.inplace.VariableInplaceRenamer
- p:checkLocalScope():com.intellij.psi.PsiElement
com.intellij.refactoring.safeDelete.SafeDeleteDialog$Callback
- a:run(com.intellij.refactoring.safeDelete.SafeDeleteDialog):V
com.intellij.refactoring.safeDelete.SafeDeleteProcessorDelegate
@@ -394,6 +394,12 @@ public class VariableInplaceRenamer extends InplaceRefactoring {
myEditor.getCaretModel().moveToOffset(myOrigOffset);
}
@Override
protected @Nullable PsiElement checkLocalScope() {
PsiElement scope = super.checkLocalScope();
return scope != null && !(scope instanceof PsiFileSystemItem) ? scope.getParent() : scope;
}
private @Nullable RangeHighlighter highlightConflictingElement(PsiElement conflictingElement) {
if (conflictingElement != null) {
try {