mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
push down: conflict if move static to local (IDEA-182514)
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringConflictsUtil;
|
||||
@@ -203,6 +204,12 @@ public class PushDownConflicts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (movedMember.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
PsiUtil.getEnclosingStaticElement(targetClass, null) == null &&
|
||||
!(targetClass.getParent() instanceof PsiFile)) {
|
||||
myConflicts.putValue(movedMember, "Static " + RefactoringUIUtil.getDescription(movedMember, false) + " can't be pushed to non-static " + RefactoringUIUtil.getDescription(targetClass, false));
|
||||
}
|
||||
}
|
||||
|
||||
private class UsedMovedMembersConflictsCollector extends ClassMemberReferencesVisitor {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
public static void f<caret>oo() {
|
||||
|
||||
}
|
||||
|
||||
void m() {
|
||||
class FooExt extends Foo { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
public static void f<caret>oo() {
|
||||
|
||||
}
|
||||
|
||||
void m() {
|
||||
class FooExt extends Foo { }
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,12 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testStaticToLocal() {
|
||||
doTest(conflicts -> {
|
||||
assertSameElements(conflicts.values(), Collections.singletonList("Static method <b><code>foo()</code></b> can't be pushed to non-static class <b><code>FooExt</code></b>"));
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user