mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExtractMethodProcessor: fix NPE extracting method from empty parenthesis: EA-214509
GitOrigin-RevId: 5fc2d19d08efca879d6e8174d0a8500eb7803dc5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4c321d86bc
commit
b36a94855a
+7
-2
@@ -143,8 +143,13 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
myProject = project;
|
||||
myEditor = editor;
|
||||
if (elements.length != 1 || !(elements[0] instanceof PsiBlockStatement)) {
|
||||
myElements = elements.length == 1 && elements[0] instanceof PsiParenthesizedExpression
|
||||
? new PsiElement[] {PsiUtil.skipParenthesizedExprDown((PsiExpression)elements[0])} : elements;
|
||||
if (elements.length == 1 && elements[0] instanceof PsiParenthesizedExpression) {
|
||||
PsiExpression expression = PsiUtil.skipParenthesizedExprDown((PsiExpression)elements[0]);
|
||||
myElements = expression != null ? new PsiElement[]{expression} : elements;
|
||||
}
|
||||
else {
|
||||
myElements = elements;
|
||||
}
|
||||
myEnclosingBlockStatement = null;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class C {
|
||||
void foo() {
|
||||
int x = <selection>()</selection>;
|
||||
}
|
||||
}
|
||||
@@ -1170,6 +1170,15 @@ public class ExtractMethodTest extends LightJavaCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEmptyParenthesis() throws Exception {
|
||||
try {
|
||||
doTest();
|
||||
fail("Should not work for empty parenthesis");
|
||||
}
|
||||
catch (PrepareFailedException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testQualifyWhenConflictingNamePresent() throws Exception {
|
||||
final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
settings.ELSE_ON_NEW_LINE = true;
|
||||
|
||||
Reference in New Issue
Block a user