mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-262337 refactor this: suggest push members down when there are inheritors only
GitOrigin-RevId: b214655cfcb043081116cbb28c47dccc053a5560
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ac9a14f565
commit
9cdcca333b
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
@@ -54,7 +55,11 @@ public class JavaPushDownHandler implements RefactoringActionHandler, ElementsHa
|
||||
|
||||
@Override
|
||||
public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
|
||||
return !getElements(editor, file, Ref.create(), true).isEmpty();
|
||||
final List<PsiElement> elements = getElements(editor, file, Ref.create(), true);
|
||||
if (elements.isEmpty()) return false;
|
||||
PsiClass psiClass = PsiTreeUtil.getParentOfType(elements.get(0), PsiClass.class, false);
|
||||
if (psiClass == null) return false;
|
||||
return ClassInheritorsSearch.search(psiClass).iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Parent {
|
||||
void test(){}
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
void foo<caret>(){}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Parent<caret> {
|
||||
void test(){}
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
void foo(){}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Parent {
|
||||
void test<caret>(){}
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
void foo(){}
|
||||
}
|
||||
@@ -160,6 +160,18 @@ class RefactorThisTest: LightJavaCodeInsightTestCase() {
|
||||
assertFalse(doActionExists<ConvertToInstanceMethodAction>())
|
||||
}
|
||||
|
||||
fun testPushDownOnMethod() {
|
||||
assertTrue(doActionExists<PushDownAction>())
|
||||
}
|
||||
|
||||
fun testPushDownOnClass() {
|
||||
assertTrue(doActionExists<PushDownAction>())
|
||||
}
|
||||
|
||||
fun testPushDownFiltered() {
|
||||
assertFalse(doActionExists<PushDownAction>())
|
||||
}
|
||||
|
||||
private inline fun <reified A> doActionExists(): Boolean {
|
||||
configureByFile("$BASE_PATH/${getTestName(false)}.java")
|
||||
val actions = findAvailableActions()
|
||||
|
||||
Reference in New Issue
Block a user