mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
push down api prettify after (IDEA-CR-8676)
This commit is contained in:
+5
-7
@@ -90,11 +90,9 @@ public class JavaPushDownDelegate extends PushDownDelegate {
|
||||
|
||||
@Override
|
||||
public void checkTargetClassConflicts(PsiElement targetClass,
|
||||
PushDownData pushDownData,
|
||||
boolean checkStatic,
|
||||
PsiElement context,
|
||||
PushDownData pushDownData,
|
||||
MultiMap<PsiElement, String> conflicts) {
|
||||
new PushDownConflicts((PsiClass)pushDownData.getSourceClass(), (MemberInfo[])pushDownData.getMembersToMove(), conflicts).checkTargetClassConflicts(targetClass, checkStatic, context);
|
||||
new PushDownConflicts((PsiClass)pushDownData.getSourceClass(), (MemberInfo[])pushDownData.getMembersToMove(), conflicts).checkTargetClassConflicts(targetClass, targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +102,7 @@ public class JavaPushDownDelegate extends PushDownDelegate {
|
||||
if (Messages.showOkCancelDialog((aClass.isEnum() ? "Enum " + aClass.getQualifiedName() + " doesn't have constants to inline to. " : "Final class " + aClass.getQualifiedName() + "does not have inheritors. ") +
|
||||
"Pushing members down will result in them being deleted. " +
|
||||
"Would you like to proceed?", conflictDialogTitle, Messages.getWarningIcon()) != Messages.OK) {
|
||||
return NewSubClassData.EMPTY;
|
||||
return NewSubClassData.ABORT_REFACTORING;
|
||||
}
|
||||
} else {
|
||||
String noInheritors = aClass.isInterface() ?
|
||||
@@ -117,11 +115,11 @@ public class JavaPushDownDelegate extends PushDownDelegate {
|
||||
if (classDialog != null) {
|
||||
return new NewSubClassData(classDialog.getTargetDirectory(), classDialog.getClassName());
|
||||
} else {
|
||||
return NewSubClassData.EMPTY;
|
||||
return NewSubClassData.ABORT_REFACTORING;
|
||||
}
|
||||
}
|
||||
else if (answer != Messages.NO) {
|
||||
return NewSubClassData.EMPTY;
|
||||
return NewSubClassData.ABORT_REFACTORING;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -77,7 +77,7 @@ public class PushDownConflicts {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTargetClassConflicts(final PsiElement targetElement, final boolean checkStatic, final PsiElement context) {
|
||||
public void checkTargetClassConflicts(final PsiElement targetElement, final PsiElement context) {
|
||||
if (targetElement instanceof PsiFunctionalExpression) {
|
||||
myConflicts.putValue(targetElement, RefactoringBundle.message("functional.interface.broken"));
|
||||
return;
|
||||
@@ -123,7 +123,6 @@ public class PushDownConflicts {
|
||||
aClass = ((PsiClassType)qualifierType).resolve();
|
||||
}
|
||||
else {
|
||||
if (!checkStatic) continue;
|
||||
if (qualifier instanceof PsiReferenceExpression) {
|
||||
final PsiElement resolved = ((PsiReferenceExpression)qualifier).resolve();
|
||||
if (resolved instanceof PsiClass) {
|
||||
|
||||
+3
-3
@@ -107,7 +107,7 @@ public abstract class AbstractPushDownProcessor extends BaseRefactoringProcessor
|
||||
final UsageInfo[] usagesIn = refUsages.get();
|
||||
if (usagesIn.length == 0) {
|
||||
mySubClassData = myDelegate.preprocessNoInheritorsFound(myPushDownData.getSourceClass(), getCommandName());
|
||||
if (mySubClassData == NewSubClassData.EMPTY) {
|
||||
if (mySubClassData == NewSubClassData.ABORT_REFACTORING) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract class AbstractPushDownProcessor extends BaseRefactoringProcessor
|
||||
@Override
|
||||
public void run() {
|
||||
if (mySubClassData != null) {
|
||||
myDelegate.checkTargetClassConflicts(null, myPushDownData, false, mySubClassData.getContext(), conflicts);
|
||||
myDelegate.checkTargetClassConflicts(null, myPushDownData, conflicts);
|
||||
}
|
||||
else {
|
||||
for (UsageInfo usage : usagesIn) {
|
||||
@@ -126,7 +126,7 @@ public abstract class AbstractPushDownProcessor extends BaseRefactoringProcessor
|
||||
if (element != null) {
|
||||
final PushDownDelegate delegate = PushDownDelegate.findDelegateForTarget(myPushDownData.getSourceClass(), element);
|
||||
if (delegate != null) {
|
||||
delegate.checkTargetClassConflicts(element, myPushDownData, usagesIn.length > 1, element, conflicts);
|
||||
delegate.checkTargetClassConflicts(element, myPushDownData, conflicts);
|
||||
}
|
||||
else {
|
||||
conflicts.putValue(element, "Not supported source/target pair detected");
|
||||
|
||||
@@ -17,10 +17,13 @@ package com.intellij.refactoring.memberPushDown;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
/**
|
||||
* Bean to store new class data if no inheritors were found: {@link PushDownDelegate#preprocessNoInheritorsFound(PsiElement, String)}
|
||||
*/
|
||||
public class NewSubClassData {
|
||||
public static final NewSubClassData EMPTY = new NewSubClassData(null, null);
|
||||
public static final NewSubClassData ABORT_REFACTORING = new NewSubClassData(null, null);
|
||||
|
||||
private PsiElement myContext;
|
||||
private Object myContext;
|
||||
private String myNewClassName;
|
||||
|
||||
public NewSubClassData(PsiElement context, String newClassName) {
|
||||
@@ -28,7 +31,10 @@ public class NewSubClassData {
|
||||
myNewClassName = newClassName;
|
||||
}
|
||||
|
||||
protected PsiElement getContext() {
|
||||
/**
|
||||
* Directory to create new class
|
||||
*/
|
||||
protected Object getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -52,7 +52,7 @@ public abstract class PushDownDelegate {
|
||||
* Implementations are supposed to override this method when overriding default behaviour for the language,
|
||||
* e.g. pushing members from groovy class to java, groovy could provide additional delegate which inherits delegate for java and accepts groovy sources.
|
||||
* Methods to process target class should be updated to cope with source of another language (e.g. calling super on PushDownData translated to java):
|
||||
* {@link #checkTargetClassConflicts(PsiElement, PushDownData, boolean, PsiElement, MultiMap)},
|
||||
* {@link #checkTargetClassConflicts(PsiElement, PushDownData, MultiMap) },
|
||||
* {@link #pushDownToClass(PsiElement, PushDownData)}
|
||||
*/
|
||||
protected abstract boolean isApplicableForSource(@NotNull PsiElement sourceClass);
|
||||
@@ -79,8 +79,6 @@ public abstract class PushDownDelegate {
|
||||
*/
|
||||
protected abstract void checkTargetClassConflicts(PsiElement targetClass,
|
||||
PushDownData pushDownData,
|
||||
boolean checkStatic,
|
||||
PsiElement context,
|
||||
MultiMap<PsiElement, String> conflicts);
|
||||
|
||||
/**
|
||||
@@ -102,7 +100,7 @@ public abstract class PushDownDelegate {
|
||||
* Called if no inheritors were found in {@link #findInheritors(PushDownData)}. Should warn that members would be deleted and
|
||||
* suggest to create new target class if applicable
|
||||
*
|
||||
* @return NewSubClassData.EMPTY if refactoring should be aborted
|
||||
* @return NewSubClassData.ABORT_REFACTORING if refactoring should be aborted
|
||||
* null to proceed without inheritors (members would be deleted from the source class and not added to the target)
|
||||
* new NewSubClassData(context, name) if new inheritor should be created with {@link #createSubClass(PsiElement, NewSubClassData)}
|
||||
*/
|
||||
@@ -111,7 +109,7 @@ public abstract class PushDownDelegate {
|
||||
RefactoringBundle.message("push.down.will.delete.members");
|
||||
final int answer = Messages.showYesNoDialog(message, conflictDialogTitle, Messages.getWarningIcon());
|
||||
if (answer != Messages.YES) {
|
||||
return NewSubClassData.EMPTY;
|
||||
return NewSubClassData.ABORT_REFACTORING;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user