mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline: delete @Override annotations if super method was deleted during inline (IDEA-152175)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.inline;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.history.LocalHistory;
|
||||
import com.intellij.history.LocalHistoryAction;
|
||||
@@ -39,6 +40,7 @@ import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -135,6 +137,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
usages.add(new UsageInfo(reference.getElement()));
|
||||
}
|
||||
|
||||
OverridingMethodsSearch.search(myMethod).forEach(method -> {
|
||||
if (AnnotationUtil.isAnnotated(method, Override.class.getName(), false)) {
|
||||
usages.add(new UsageInfo(method));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (mySearchInComments || mySearchForTextOccurrences) {
|
||||
final NonCodeUsageInfoFactory infoFactory = new NonCodeUsageInfoFactory(myMethod, myMethod.getName()) {
|
||||
@Override
|
||||
@@ -480,6 +489,12 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
imports2Delete.add(PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class));
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
PsiAnnotation annotation = AnnotationUtil.findAnnotation((PsiMethod) element, false, Override.class.getName());
|
||||
if (annotation != null) {
|
||||
annotation.delete();
|
||||
}
|
||||
}
|
||||
else if (JavaLanguage.INSTANCE != element.getLanguage()) {
|
||||
GenericInlineHandler.inlineReference(usage, myMethod, myInliners);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
void f<caret>oo() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
@Override
|
||||
void foo() {}
|
||||
|
||||
void err() {
|
||||
super.foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
void foo() {}
|
||||
|
||||
void err() {
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
doTestInlineThisOnly();
|
||||
}
|
||||
|
||||
public void testDeleteOverrideAnnotations() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestInlineThisOnly() {
|
||||
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(fileName);
|
||||
|
||||
Reference in New Issue
Block a user