mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
rationalize static method calls after pull up
This commit is contained in:
@@ -93,12 +93,30 @@ public class PullUpHelper extends BaseRefactoringProcessor{
|
||||
|
||||
@NotNull
|
||||
protected UsageInfo[] findUsages() {
|
||||
return new UsageInfo[0];
|
||||
final List<UsageInfo> result = new ArrayList<UsageInfo>();
|
||||
for (MemberInfo memberInfo : myMembersToMove) {
|
||||
final PsiMember member = memberInfo.getMember();
|
||||
if (member.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
for (PsiReference reference : ReferencesSearch.search(member)) {
|
||||
result.add(new UsageInfo(reference));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.isEmpty() ? UsageInfo.EMPTY_ARRAY : result.toArray(new UsageInfo[result.size()]);
|
||||
}
|
||||
|
||||
protected void performRefactoring(UsageInfo[] usages) {
|
||||
moveMembersToBase();
|
||||
moveFieldInitializations();
|
||||
for (UsageInfo usage : usages) {
|
||||
PsiElement element = usage.getElement();
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
PsiExpression qualifierExpression = ((PsiReferenceExpression)element).getQualifierExpression();
|
||||
if (qualifierExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifierExpression).resolve() == mySourceClass) {
|
||||
((PsiReferenceExpression)qualifierExpression).bindToElement(myTargetSuperClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
processMethodsDuplicates();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Foo {}
|
||||
class FooImpl extends Foo {
|
||||
public static void foo(){}
|
||||
<caret>
|
||||
}
|
||||
class U {
|
||||
public static void main(String[] args) {
|
||||
FooImpl.foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
public static void foo(){}
|
||||
}
|
||||
class FooImpl extends Foo {
|
||||
|
||||
}
|
||||
class U {
|
||||
public static void main(String[] args) {
|
||||
Foo.foo();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
doTest(new RefactoringTestUtil.MemberDescriptor("x", PsiField.class),
|
||||
new RefactoringTestUtil.MemberDescriptor("getX", PsiMethod.class),
|
||||
new RefactoringTestUtil.MemberDescriptor("setX", PsiMethod.class));
|
||||
|
||||
}
|
||||
|
||||
public void testPullUpInheritedStaticClasses() throws Exception {
|
||||
@@ -46,7 +45,7 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
public void testPullUpPrivateInnerClassWithPrivateConstructor() throws Exception {
|
||||
doTest(new RefactoringTestUtil.MemberDescriptor("C", PsiClass.class));
|
||||
}
|
||||
|
||||
|
||||
public void testPullUpAndAbstractize() throws Exception {
|
||||
doTest(new RefactoringTestUtil.MemberDescriptor("a", PsiMethod.class),
|
||||
new RefactoringTestUtil.MemberDescriptor("b", PsiMethod.class, true));
|
||||
@@ -102,6 +101,10 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("I", PsiClass.class));
|
||||
}
|
||||
|
||||
public void testUpdateStaticRefs() throws Exception {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
doTest(true, membersToFind);
|
||||
}
|
||||
@@ -121,7 +124,7 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);
|
||||
|
||||
final int[] countMoved = new int[] {0};
|
||||
final int[] countMoved = new int[]{0};
|
||||
final MoveMemberListener listener = new MoveMemberListener() {
|
||||
@Override
|
||||
public void memberMoved(PsiClass aClass, PsiMember member) {
|
||||
@@ -143,5 +146,4 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user