From da987548c08a2919389f691f6b24e2b2d0f1df7c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 3 Dec 2021 12:08:46 +0100 Subject: [PATCH] [java] [rename] correctly handle method reference rename (IDEA-283662) GitOrigin-RevId: c869ac621c25373fa08e742439f6022fa6052efc --- .../java/PsiMethodReferenceExpressionImpl.java | 17 +++-------------- .../renameLocal/ClassNameUsedInMethodRefs.java | 8 +++++++- .../ClassNameUsedInMethodRefs_after.java | 8 +++++++- .../renameLocal/MethodNameUsedInMethodRefs.java | 15 +++++++++++++++ .../MethodNameUsedInMethodRefs_after.java | 15 +++++++++++++++ .../java/refactoring/RenameLocalTest.java | 6 +++++- 6 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs.java create mode 100644 java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs_after.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java index 25e695f0bc88..b3dde064910a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java @@ -1,10 +1,9 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.source.tree.java; import com.intellij.icons.AllIcons; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.CheckUtil; @@ -14,7 +13,6 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.source.JavaStubPsiElement; import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; -import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.scope.ElementClassFilter; import com.intellij.psi.scope.PsiConflictResolver; @@ -319,20 +317,11 @@ public class PsiMethodReferenceExpressionImpl extends JavaStubPsiElementar { + static final class Bar { private Bar() { } } @@ -15,3 +15,9 @@ public class FooBar { foo(Bar::new); } } + +class FooBarBaz { + public static void main(String[] args) throws Exception { + foo(FooBar.Bar::new); + } +} diff --git a/java/java-tests/testData/refactoring/renameLocal/ClassNameUsedInMethodRefs_after.java b/java/java-tests/testData/refactoring/renameLocal/ClassNameUsedInMethodRefs_after.java index 6ec908b222f8..d0b20734315b 100644 --- a/java/java-tests/testData/refactoring/renameLocal/ClassNameUsedInMethodRefs_after.java +++ b/java/java-tests/testData/refactoring/renameLocal/ClassNameUsedInMethodRefs_after.java @@ -1,5 +1,5 @@ public class FooBar { - private static final class Bar1 { + static final class Bar1 { private Bar1() { } } @@ -15,3 +15,9 @@ public class FooBar { foo(Bar1::new); } } + +class FooBarBaz { + public static void main(String[] args) throws Exception { + foo(FooBar.Bar1::new); + } +} diff --git a/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs.java b/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs.java new file mode 100644 index 000000000000..fb66f0dbeadc --- /dev/null +++ b/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs.java @@ -0,0 +1,15 @@ +public class FooBar { + + static void foo() {} + + + public static void main(String[] args) throws Exception { + Runnable runnable = FooBar::foo; + } +} + +class FooBarBaz { + public static void main(String[] args) throws Exception { + Runnable runnable = FooBar::foo; + } +} diff --git a/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs_after.java b/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs_after.java new file mode 100644 index 000000000000..f74fbfa5814a --- /dev/null +++ b/java/java-tests/testData/refactoring/renameLocal/MethodNameUsedInMethodRefs_after.java @@ -0,0 +1,15 @@ +public class FooBar { + + static void bar1() {} + + + public static void main(String[] args) throws Exception { + Runnable runnable = FooBar::bar1; + } +} + +class FooBarBaz { + public static void main(String[] args) throws Exception { + Runnable runnable = FooBar::bar1; + } +} 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 a1f08018fd6e..ef5be4398fcd 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-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.refactoring; import com.intellij.JavaTestUtil; @@ -67,6 +67,10 @@ public class RenameLocalTest extends LightRefactoringTestCase { doTest("Bar1"); } + public void testMethodNameUsedInMethodRefs() { + doTest("bar1"); + } + public void testRenameParamUniqueName() { configureByFile(); final HashSet result = new HashSet<>();