extract method: skip parenthesis as they are skipped by control flow (IDEA-134904)

This commit is contained in:
Anna Kozlova
2015-01-02 12:05:47 +01:00
parent fa99ec2a74
commit 5ecb541855
4 changed files with 25 additions and 2 deletions
@@ -142,8 +142,9 @@ public class ExtractMethodProcessor implements MatchProvider {
String helpId) {
myProject = project;
myEditor = editor;
if (elements.length != 1 || elements.length == 1 && !(elements[0] instanceof PsiBlockStatement)) {
myElements = elements;
if (elements.length != 1 || !(elements[0] instanceof PsiBlockStatement)) {
myElements = elements.length == 1 && elements[0] instanceof PsiParenthesizedExpression
? new PsiElement[] {PsiUtil.skipParenthesizedExprDown((PsiExpression)elements[0])} : elements;
myEnclosingBlockStatement = null;
}
else {
@@ -0,0 +1,7 @@
class Test {
{
int i = 2;
int n = 5;
boolean b = !<selection>(i < n)</selection>;
}
}
@@ -0,0 +1,11 @@
class Test {
{
int i = 2;
int n = 5;
boolean b = !newMethod(i, n);
}
private boolean newMethod(int i, int n) {
return i < n;
}
}
@@ -657,6 +657,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testTheOnlyParenthesisExpressionWhichIsSkippedInControlFlow() throws Exception {
doTest();
}
public void testExpression() throws Exception {
doTest();
}