diff --git a/java/java-tests/testData/refactoring/renameLocal/ConflictInLambdaParameter.java b/java/java-tests/testData/refactoring/renameLocal/ConflictInLambdaParameter.java new file mode 100644 index 000000000000..9a722fa7d39b --- /dev/null +++ b/java/java-tests/testData/refactoring/renameLocal/ConflictInLambdaParameter.java @@ -0,0 +1,10 @@ +class ConfictInLambdaParameter { + public void consume(Consumer c) { + } + + public void bug() { + consume(o -> { // line 1 + consume(o1 -> {}); // line 2 + }); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/RenameLocalTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/RenameLocalTest.java index 778a4f96a6bd..b4588556976f 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/RenameLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/RenameLocalTest.java @@ -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, diff --git a/platform/lang-impl/api-dump.txt b/platform/lang-impl/api-dump.txt index e283a9a500b0..cfe54be55dae 100644 --- a/platform/lang-impl/api-dump.txt +++ b/platform/lang-impl/api-dump.txt @@ -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 diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index 179216782366..82522c709322 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -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 {