EA-26767 - NPE: ExtractMethodProcessor.doRefactoring

This commit is contained in:
anna
2011-06-30 12:39:17 +04:00
parent 68c682ce6b
commit 34151b68df
4 changed files with 24 additions and 1 deletions
@@ -46,6 +46,7 @@ import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
@@ -1047,7 +1048,7 @@ public class ExtractMethodProcessor implements MatchProvider {
LOG.assertTrue(qualifierExpression != null);
qualifierExpression.replace(instanceQualifier);
}
return expr;
return (PsiMethodCallExpression)JavaCodeStyleManager.getInstance(myProject).shortenClassReferences(expr);
}
private void declareNecessaryVariablesInsideBody(PsiCodeBlock body) throws IncorrectOperationException {
@@ -0,0 +1,7 @@
import java.io.IOException;
class Test {
void foo(Exception targetElement) {
PsiPackage aPack = <selection>JavaDirectoryService.getInstance().getPackage((IOException)targetElement)</selection>;
}
}
@@ -0,0 +1,11 @@
import java.io.IOException;
class Test {
void foo(Exception targetElement) {
PsiPackage aPack = newMethod((IOException) targetElement);
}
private PsiPackage newMethod(IOException targetElement) {
return JavaDirectoryService.getInstance().getPackage((IOException)targetElement);
}
}
@@ -489,6 +489,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testInvalidReference() throws Exception {
doTest();
}
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
String expectedError = null;
try {