From b437fbe924264ebb43d09146bebd6b0c5d5ba914 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 12 Jul 2011 17:39:04 +0400 Subject: [PATCH] rename method: qualify refs inside anonymous classes if necessary (IDEA-71830 ) --- .../rename/RenameJavaMethodProcessor.java | 2 +- .../rename2HideFromAnonymous/after/p/Foo.java | 33 +++++++++++++++++++ .../before/p/Foo.java | 33 +++++++++++++++++++ .../refactoring/RenameMethodMultiTest.java | 4 +++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/after/p/Foo.java create mode 100644 java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/before/p/Foo.java diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java index e4a1ff9711c7..d6aa95349f79 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java @@ -130,7 +130,7 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor { qualifyMember(element, newName, outerClass, isStatic); break; } - outerClass = outerClass.getContainingClass(); + outerClass = PsiTreeUtil.getParentOfType(outerClass, PsiClass.class); } } } diff --git a/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/after/p/Foo.java b/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/after/p/Foo.java new file mode 100644 index 000000000000..1250f80dfc55 --- /dev/null +++ b/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/after/p/Foo.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package p; + +class Foo { + public Bar createBar() { + return new Bar() { + public void bazz(int i) { + Foo.this.bazz(i); + } + }; + } + + private void bazz(int i) { + } + + public interface Bar { + void bazz(int i); + } +} diff --git a/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/before/p/Foo.java b/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/before/p/Foo.java new file mode 100644 index 000000000000..4e9acc82b1bf --- /dev/null +++ b/java/java-tests/testData/refactoring/renameMethod/multi/rename2HideFromAnonymous/before/p/Foo.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package p; + +class Foo { + public Bar createBar() { + return new Bar() { + public void bazz(int i) { + buzz(i); + } + }; + } + + private void buzz(int i) { + } + + public interface Bar { + void bazz(int i); + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java index 82b3324cc559..f2b52e19e34c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java @@ -57,6 +57,10 @@ public class RenameMethodMultiTest extends MultiFileTestCase { fail("Conflicts were not found"); } + public void testRename2HideFromAnonymous() throws Exception { + doTest("p.Foo", "void buzz(int i)", "bazz"); + } + public void testAlignedMultilineParameters() throws Exception { getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true; getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;