mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
pull up: preserve/remove override from pulled method according to super classes structure
This commit is contained in:
@@ -204,15 +204,15 @@ public class PullUpHelper extends BaseRefactoringProcessor{
|
||||
for (MemberInfo info : myMembersToMove) {
|
||||
if (info.getMember() instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)info.getMember();
|
||||
PsiMethod methodCopy = (PsiMethod)method.copy();
|
||||
if (method.findDeepestSuperMethods().length == 0) {
|
||||
deleteOverrideAnnotationIfFound(methodCopy);
|
||||
}
|
||||
final boolean isOriginalMethodAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
|
||||
if (myIsTargetInterface || info.isToAbstract()) {
|
||||
PsiMethod methodCopy = (PsiMethod)method.copy();
|
||||
ChangeContextUtil.clearContextInfo(method);
|
||||
RefactoringUtil.abstractizeMethod(myTargetSuperClass, methodCopy);
|
||||
RefactoringUtil.replaceMovedMemberTypeParameters(methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
|
||||
if (method.findDeepestSuperMethods().length == 0 || (myTargetSuperClass.isInterface() && !PsiUtil.isLanguageLevel6OrHigher(mySourceClass))) {
|
||||
deleteOverrideAnnotationIfFound(methodCopy);
|
||||
}
|
||||
|
||||
myJavaDocPolicy.processCopiedJavaDoc(methodCopy.getDocComment(), method.getDocComment(), isOriginalMethodAbstract);
|
||||
|
||||
@@ -240,14 +240,14 @@ public class PullUpHelper extends BaseRefactoringProcessor{
|
||||
if (isOriginalMethodAbstract) {
|
||||
PsiUtil.setModifierProperty(myTargetSuperClass, PsiModifier.ABSTRACT, true);
|
||||
}
|
||||
RefactoringUtil.replaceMovedMemberTypeParameters(method, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
|
||||
fixReferencesToStatic(method, movedMembers);
|
||||
final PsiMethod superClassMethod = myTargetSuperClass.findMethodBySignature(method, false);
|
||||
RefactoringUtil.replaceMovedMemberTypeParameters(methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
|
||||
fixReferencesToStatic(methodCopy, movedMembers);
|
||||
final PsiMethod superClassMethod = myTargetSuperClass.findMethodBySignature(methodCopy, false);
|
||||
if (superClassMethod != null && superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
superClassMethod.replace(method);
|
||||
superClassMethod.replace(methodCopy);
|
||||
}
|
||||
else {
|
||||
final PsiMember movedElement = (PsiMember)myTargetSuperClass.add(method);
|
||||
final PsiMember movedElement = (PsiMember)myTargetSuperClass.add(methodCopy);
|
||||
myMembersAfterMove.add(movedElement);
|
||||
}
|
||||
method.delete();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
public class Test {
|
||||
abstract class Base extends IntImpl {
|
||||
@Override
|
||||
public abstract String<caret> foo();
|
||||
}
|
||||
|
||||
class IntImpl extends Int {}
|
||||
|
||||
class Int {
|
||||
public abstract String foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public class Test {
|
||||
abstract class Base extends IntImpl {
|
||||
}
|
||||
|
||||
abstract class IntImpl extends Int {
|
||||
@Override
|
||||
public abstract String foo();
|
||||
}
|
||||
|
||||
class Int {
|
||||
public abstract String foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Test {
|
||||
abstract class Base extends Int {
|
||||
@Override
|
||||
public abstract String<caret> foo();
|
||||
}
|
||||
|
||||
class Int {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Test {
|
||||
abstract class Base extends Int {
|
||||
}
|
||||
|
||||
abstract class Int {
|
||||
public abstract String foo();
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,14 @@ public class PullUpTest extends LightCodeInsightTestCase {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testRemoveOverrideFromPulledMethod() throws Exception {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testPreserveOverrideInPulledMethod() throws Exception {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
doTest(true, membersToFind);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user