diff --git a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java index 40452cbc88ec..212ec20dfe31 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java @@ -192,12 +192,12 @@ public class JavaPushDownDelegate extends PushDownDelegate refsToRebind = new ArrayList<>(); final PsiModifierList list = member.getModifierList(); LOG.assertTrue(list != null); - if (list.hasModifierProperty(PsiModifier.STATIC)) { + if (list.hasModifierProperty(PsiModifier.STATIC) && !PsiUtil.isLocalOrAnonymousClass(targetClass)) { for (final PsiReference reference : ReferencesSearch.search(member)) { final PsiElement element = reference.getElement(); if (element instanceof PsiReferenceExpression) { final PsiExpression qualifierExpression = ((PsiReferenceExpression)element).getQualifierExpression(); - if (qualifierExpression instanceof PsiReferenceExpression && !(((PsiReferenceExpression)qualifierExpression).resolve() instanceof PsiClass)) { + if (qualifierExpression instanceof PsiReferenceExpression && !(((PsiReferenceExpression)qualifierExpression).resolve() instanceof PsiClass) || qualifierExpression == null) { continue; } } diff --git a/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate.java b/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate.java new file mode 100644 index 000000000000..e13df082c52b --- /dev/null +++ b/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate.java @@ -0,0 +1,19 @@ +class Foo { + public static void foo() { + + } + + void m() { + class FooExt extends Foo { + { + foo(); + } + } + + class FooExt1 extends Foo { + { + foo(); + } + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate_after.java b/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate_after.java new file mode 100644 index 000000000000..90987512221b --- /dev/null +++ b/java/java-tests/testData/refactoring/pushDown/StaticToLocalWithReferenceUpdate_after.java @@ -0,0 +1,24 @@ +class Foo { + + void m() { + class FooExt extends Foo { + { + foo(); + } + + public static void foo() { + + } + } + + class FooExt1 extends Foo { + { + foo(); + } + + public static void foo() { + + } + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java index fc8a9790eada..c9b2a1c79ff1 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java @@ -27,6 +27,7 @@ import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -127,6 +128,16 @@ public class PushDownTest extends LightRefactoringTestCase { }); } + public void testStaticToLocalWithReferenceUpdate() { + doTest(conflicts -> { + assertSameElements(conflicts.values(), + Arrays.asList("Method m() uses method foo(), which is pushed down", + "Method m() uses method foo(), which is pushed down", + "Static method foo() can't be pushed to non-static class FooExt1", + "Static method foo() can't be pushed to non-static class FooExt")); + }); + } + private void doTest() { doTest(false); }