KT-14032 related: if expression to elvis now handles also is and !is checks

This commit is contained in:
Mikhail Glukhikh
2016-10-07 21:38:33 +03:00
committed by Mikhail Glukhikh
parent 8188bb1e54
commit 121f0ec810
7 changed files with 92 additions and 22 deletions
@@ -103,4 +103,20 @@
<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>notIsCheck.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/notIsCheck.kt" />
<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>isCheck.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheck.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>
@@ -0,0 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): My {
return if (<caret>arg is My) arg else My(42)
}
@@ -0,0 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): My {
return arg as? My ?: My(42)
}
@@ -0,0 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): My {
return if (<caret>arg !is My) My(42) else arg
}
@@ -0,0 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): My {
return arg as? My ?: My(42)
}