mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
enable delegate for interfaces in 1.8
This commit is contained in:
+2
-1
@@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.changeClassSignature.ChangeClassSignatureDialog;
|
||||
@@ -89,7 +90,7 @@ public class JavaChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final PsiReferenceExpression refExpr = editor != null ? TargetElementUtil.findReferenceExpression(editor) : null;
|
||||
final boolean allowDelegation = containingClass != null && !containingClass.isInterface();
|
||||
final boolean allowDelegation = containingClass != null && (!containingClass.isInterface() || PsiUtil.isLanguageLevel8OrHigher(containingClass));
|
||||
final DialogWrapper dialog = new JavaChangeSignatureDialog(project, method, allowDelegation, refExpr == null ? method : refExpr);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
+4
-1
@@ -639,7 +639,10 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
private static void generateDelegate(JavaChangeInfo changeInfo) throws IncorrectOperationException {
|
||||
final PsiMethod delegate = (PsiMethod)changeInfo.getMethod().copy();
|
||||
final PsiClass targetClass = changeInfo.getMethod().getContainingClass();
|
||||
LOG.assertTrue(!targetClass.isInterface());
|
||||
LOG.assertTrue(targetClass != null);
|
||||
if (targetClass.isInterface() && delegate.getBody() == null) {
|
||||
delegate.getModifierList().setModifierProperty(PsiModifier.DEFAULT, true);
|
||||
}
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(targetClass.getProject());
|
||||
ChangeSignatureProcessor.makeEmptyBody(factory, delegate);
|
||||
final PsiCallExpression callExpression = ChangeSignatureProcessor.addDelegatingCallTemplate(delegate, changeInfo.getNewName());
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface SAM {
|
||||
void <caret>foo();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
interface SAM {
|
||||
default void foo() {
|
||||
foo(false);
|
||||
}
|
||||
|
||||
void foo(boolean b);
|
||||
}
|
||||
+4
@@ -38,6 +38,10 @@ public class ChangeSignatureTouchLambdaTest extends ChangeSignatureBaseTest {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testDelegateInInterface() throws Exception {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "false")}, new ThrownExceptionInfo[0], true);
|
||||
}
|
||||
|
||||
private void doTestConflict() {
|
||||
try {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
|
||||
Reference in New Issue
Block a user