Make parentheses necessary for '(x op return y) op z' #KT-16808 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
426a54c3ab
commit
e8b95b971d
@@ -530,11 +530,19 @@ public class KtPsiUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
// '(x operator y)' case
|
||||
if (innerExpression instanceof KtBinaryExpression &&
|
||||
innerOperation != KtTokens.ELVIS &&
|
||||
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
|
||||
return true;
|
||||
if (innerExpression instanceof KtBinaryExpression) {
|
||||
// '(x operator return [...]) operator ...' case
|
||||
if (parentElement instanceof KtBinaryExpression) {
|
||||
KtBinaryExpression innerBinary = (KtBinaryExpression) innerExpression;
|
||||
if (innerBinary.getRight() instanceof KtReturnExpression) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// '(x operator y)' case
|
||||
if (innerOperation != KtTokens.ELVIS &&
|
||||
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int innerPriority = getPriority(innerExpression);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun foo(): Boolean {
|
||||
return <caret>("" ?: return false) in listOf("")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun foo() {
|
||||
bar(<caret>("" ?: return) in listOf(""))
|
||||
}
|
||||
|
||||
fun bar(arg: Boolean) {}
|
||||
@@ -13412,6 +13412,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("elvisRhs.kt")
|
||||
public void testElvisRhs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/elvisRhs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("elvisRhsEmptyReturn.kt")
|
||||
public void testElvisRhsEmptyReturn() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/elvisRhsEmptyReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("necessaryParentheses1.kt")
|
||||
public void testNecessaryParentheses1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/necessaryParentheses1.kt");
|
||||
|
||||
Reference in New Issue
Block a user