fix delegation to abstract method (EA-29618 - NPE: DelegateWithDefaultParamValueIntentionAction.invoke)

This commit is contained in:
anna
2011-09-08 20:27:42 +02:00
parent 7ff91a3d92
commit 32e09dafb3
4 changed files with 21 additions and 3 deletions

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -0,0 +1,4 @@
// "Generate delegated method with default parameter value" "true"
abstract class Test {
abstract int foo(int i<caret>i, boolean... args);
}

View File

@@ -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);
}
}