mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
push down: preserve @Override if keep abstract was selected (IDEA-155600)
This commit is contained in:
+10
-15
@@ -229,28 +229,20 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
}
|
||||
|
||||
if (memberInfo.isToAbstract()) {
|
||||
if (sourceClass.isInterface()) {
|
||||
if (oldMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
|
||||
PsiUtil.setModifierProperty(oldMethod, PsiModifier.DEFAULT, false);
|
||||
RefactoringUtil.makeMethodAbstract(sourceClass, oldMethod);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (newMember.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
PsiUtil.setModifierProperty(newMember, PsiModifier.PROTECTED, true);
|
||||
}
|
||||
if (newMember.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
PsiUtil.setModifierProperty(newMember, PsiModifier.PROTECTED, true);
|
||||
}
|
||||
|
||||
pushDownData.getCommentPolicy().processNewJavaDoc(((PsiMethod)newMember).getDocComment());
|
||||
}
|
||||
if (memberInfo.isToAbstract()) {
|
||||
OverrideImplementUtil.annotateOnOverrideImplement((PsiMethod)newMember, targetClass, (PsiMethod)memberInfo.getMember());
|
||||
}
|
||||
}
|
||||
else { //abstract method: remove @Override
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(methodBySignature, "java.lang.Override");
|
||||
if (annotation != null && !leaveOverrideAnnotation(sourceClass, substitutor, method)) {
|
||||
annotation.delete();
|
||||
if (!memberInfo.isToAbstract()) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(methodBySignature, "java.lang.Override");
|
||||
if (annotation != null && !leaveOverrideAnnotation(sourceClass, substitutor, method)) {
|
||||
annotation.delete();
|
||||
}
|
||||
}
|
||||
final PsiDocComment oldDocComment = method.getDocComment();
|
||||
if (oldDocComment != null) {
|
||||
@@ -318,6 +310,9 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
PsiUtil.setModifierProperty(method, PsiModifier.PROTECTED, true);
|
||||
}
|
||||
if (method.hasModifierProperty(PsiModifier.DEFAULT)) {
|
||||
PsiUtil.setModifierProperty(method, PsiModifier.DEFAULT, false);
|
||||
}
|
||||
RefactoringUtil.makeMethodAbstract((PsiClass)pushDownData.getSourceClass(), method);
|
||||
pushDownData.getCommentPolicy().processOldJavaDoc(method.getDocComment());
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface Test {
|
||||
/**
|
||||
* some javadoc
|
||||
*/
|
||||
default void foo() {
|
||||
System.out.println("I");
|
||||
}
|
||||
}
|
||||
|
||||
class C implements Test {
|
||||
/**
|
||||
* another javadoc
|
||||
*/
|
||||
@Override
|
||||
public void foo() {
|
||||
System.out.println("C");
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
interface Test {
|
||||
/**
|
||||
* some javadoc
|
||||
*/
|
||||
void foo();
|
||||
}
|
||||
|
||||
class C implements Test {
|
||||
/**
|
||||
* another javadoc
|
||||
*/
|
||||
@Override
|
||||
public void foo() {
|
||||
System.out.println("C");
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,10 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
doTestImplements(true);
|
||||
}
|
||||
|
||||
public void testPreserveOverrideAnnotationAfterConflict() throws Exception {
|
||||
doTestImplements(true, true);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
@@ -135,7 +139,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
new DocCommentPolicy(DocCommentPolicy.ASIS)) {
|
||||
@Override
|
||||
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
|
||||
if (failure ? conflicts.isEmpty() : !conflicts.isEmpty()) {
|
||||
if (failure == conflicts.isEmpty()) {
|
||||
fail(failure ? "Conflict was not detected" : "False conflict was detected");
|
||||
}
|
||||
return true;
|
||||
@@ -150,6 +154,10 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
private void doTestImplements(boolean toAbstract) {
|
||||
doTestImplements(toAbstract, false);
|
||||
}
|
||||
|
||||
private void doTestImplements(boolean toAbstract, boolean failure) {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
@@ -166,6 +174,9 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
new DocCommentPolicy(DocCommentPolicy.ASIS)) {
|
||||
@Override
|
||||
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
|
||||
if (failure == conflicts.isEmpty()) {
|
||||
fail(failure ? "Conflict was not detected" : "False conflict was detected");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}.run();
|
||||
|
||||
Reference in New Issue
Block a user