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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// '(x operator y)' case
|
if (innerExpression instanceof KtBinaryExpression) {
|
||||||
if (innerExpression instanceof KtBinaryExpression &&
|
// '(x operator return [...]) operator ...' case
|
||||||
innerOperation != KtTokens.ELVIS &&
|
if (parentElement instanceof KtBinaryExpression) {
|
||||||
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
|
KtBinaryExpression innerBinary = (KtBinaryExpression) innerExpression;
|
||||||
return true;
|
if (innerBinary.getRight() instanceof KtReturnExpression) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// '(x operator y)' case
|
||||||
|
if (innerOperation != KtTokens.ELVIS &&
|
||||||
|
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int innerPriority = getPriority(innerExpression);
|
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);
|
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")
|
@TestMetadata("necessaryParentheses1.kt")
|
||||||
public void testNecessaryParentheses1() throws Exception {
|
public void testNecessaryParentheses1() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/necessaryParentheses1.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/necessaryParentheses1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user