mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
fix delegation to abstract method (EA-29618 - NPE: DelegateWithDefaultParamValueIntentionAction.invoke)
This commit is contained in:
@@ -65,11 +65,16 @@ public class DelegateWithDefaultParamValueIntentionAction extends PsiElementBase
|
||||
|
||||
private static PsiMethod generateMethodPrototype(PsiMethod method, PsiParameter param) {
|
||||
final PsiMethod prototype = (PsiMethod)method.copy();
|
||||
final PsiCodeBlock body = prototype.getBody();
|
||||
PsiCodeBlock body = prototype.getBody();
|
||||
if (body != null) {
|
||||
for (PsiStatement psiStatement : body.getStatements()) {
|
||||
psiStatement.delete();
|
||||
}
|
||||
} else {
|
||||
prototype.getModifierList().setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
body =
|
||||
(PsiCodeBlock)prototype
|
||||
.addBefore(JavaPsiFacade.getElementFactory(method.getProject()).createMethodFromText("void foo(){}", prototype).getBody(), null);
|
||||
}
|
||||
final int parameterIndex = method.getParameterList().getParameterIndex(param);
|
||||
prototype.getParameterList().getParameters()[parameterIndex].delete();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Generate delegated method with default parameter value" "true"
|
||||
abstract class Test {
|
||||
int foo(boolean... args) {
|
||||
return foo(<caret>, args);
|
||||
}
|
||||
|
||||
abstract int foo(int ii, boolean... args);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Generate delegated method with default parameter value" "true"
|
||||
abstract class Test {
|
||||
abstract int foo(int i<caret>i, boolean... args);
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
|
||||
@@ -26,7 +27,7 @@ public class DelegateWithDefaultParamValueTest extends LightQuickFixTestCase {
|
||||
protected void doAction(String text, boolean actionShouldBeAvailable, String testFullPath, String testName)
|
||||
throws Exception {
|
||||
try {
|
||||
((TemplateManagerImpl)TemplateManagerImpl.getInstance(getProject())).setTemplateTesting(true);
|
||||
((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true);
|
||||
super.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
|
||||
if (actionShouldBeAvailable) {
|
||||
@@ -35,7 +36,7 @@ public class DelegateWithDefaultParamValueTest extends LightQuickFixTestCase {
|
||||
state.gotoEnd(false);
|
||||
}
|
||||
} finally {
|
||||
((TemplateManagerImpl)TemplateManagerImpl.getInstance(getProject())).setTemplateTesting(false);
|
||||
((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user