extract if: keep necessary parenthesis (IDEA-219639)

GitOrigin-RevId: 9582978807c159f8302a1781a5f3388fb0130ad9
This commit is contained in:
Anna Kozlova
2019-08-06 11:10:12 +02:00
committed by intellij-monorepo-bot
parent bf3eefc4b0
commit 774401fb2f
3 changed files with 21 additions and 1 deletions

View File

@@ -110,7 +110,8 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
if (token != null && sb.length() != 0) {
sb.append(token.getText()).append(" ");
}
sb.append(tracker.text(ObjectUtils.notNull(PsiUtil.skipParenthesizedExprDown(e), e)));
tracker.markUnchanged(ObjectUtils.notNull(PsiUtil.skipParenthesizedExprDown(e), e));
sb.append(e.getText());
}
return factory.createExpressionFromText(sb.toString(), expression);
}

View File

@@ -0,0 +1,10 @@
// "Extract if (b)" "true"
class MyTest {
void foo(boolean a, boolean b, boolean c, boolean d) {
if (b)
if (a && (c || d)) {
}
}
}

View File

@@ -0,0 +1,9 @@
// "Extract if (b)" "true"
class MyTest {
void foo(boolean a, boolean b, boolean c, boolean d) {
if (a && <caret>b && (c || d)) {
}
}
}