pull up: ensure varargs as last parameter (IDEA-193132)

This commit is contained in:
Anna Kozlova
2018-06-01 20:04:05 +03:00
parent e8be01101d
commit ce8366714f
4 changed files with 31 additions and 0 deletions
@@ -408,6 +408,8 @@ public class JavaPullUpHelper implements PullUpHelper<MemberInfo> {
Initializer i2 = fieldsToInitializers.get(field2);
if(i1.movedFieldsUsed.contains(field2)) return 1;
if(i2.movedFieldsUsed.contains(field1)) return -1;
if (i1.usedParameters.stream().anyMatch(p -> p.isVarArgs())) return 1;
if (i2.usedParameters.stream().anyMatch(p -> p.isVarArgs())) return -1;
return 0;
});
@@ -0,0 +1,10 @@
class Super {}
class Test extends Super{
String[] f2;
String f<caret>1;
public Test(String f1, String... f2) {
this.f2 = f2;
this.f1 = f1;
}
}
@@ -0,0 +1,15 @@
class Super {
String[] f2;
String f1;
Super(String f1, String... f2) {
this.f1 = f1;
this.f2 = f2;
}
}
class Test extends Super{
public Test(String f1, String... f2) {
super(f1, f2);
}
}
@@ -185,6 +185,10 @@ public class PullUpTest extends LightRefactoringTestCase {
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
}
public void testOrderVarargsParameterLast() {
doTest(false, new RefactoringTestUtil.MemberDescriptor("f2", PsiField.class), new RefactoringTestUtil.MemberDescriptor("f1", PsiField.class));
}
public void testOuterClassRefsNoConflictIfAsAbstract() {
doTest(false, new RefactoringTestUtil.MemberDescriptor("bar", PsiMethod.class, true));
}