提交 ee1b741e 编写于 作者: M Mikhail Glukhikh

More accurate handling of Elvis in areParenthesesNecessary #KT-15227 Fixed

上级 6d6a16f3
......@@ -503,7 +503,10 @@ public class KtPsiUtil {
if (parentElement instanceof KtLabeledExpression) return false;
// 'x ?: ...' case
if (parentElement instanceof KtBinaryExpression && parentOperation == KtTokens.ELVIS && currentInner == ((KtBinaryExpression) parentElement).getRight()) {
if (parentElement instanceof KtBinaryExpression &&
parentOperation == KtTokens.ELVIS &&
!(innerExpression instanceof KtBinaryExpression) &&
currentInner == ((KtBinaryExpression) parentElement).getRight()) {
return false;
}
......
// See KT-15227
class My(val local: Boolean)
class Your(val my: My?, val parent: Any?)
fun foo(your: Your): Boolean {
val my = your.my
return <caret>if (my != null) my.local else your.parent != null
}
\ No newline at end of file
// See KT-15227
class My(val local: Boolean)
class Your(val my: My?, val parent: Any?)
fun foo(your: Your): Boolean {
val my = your.my
return my?.local ?: (your.parent != null)
}
\ No newline at end of file
......@@ -87,4 +87,12 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>comparisonInElse.kt</file>
<line>8</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/comparisonInElse.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
</problems>
......@@ -1294,6 +1294,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("comparisonInElse.kt")
public void testComparisonInElse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt");
doTest(fileName);
}
@TestMetadata("conditionComparesNullWithNull.kt")
public void testConditionComparesNullWithNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/conditionComparesNullWithNull.kt");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册