Convert 'if' with 'is' check to 'as?' with safe call #KT-17054 Fixed

This commit is contained in:
Dmitry Neverov
2017-04-29 06:27:20 +02:00
committed by Mikhail Glukhikh
parent 0361ed8c68
commit fd6d1520c7
13 changed files with 112 additions and 60 deletions
@@ -1,3 +1,5 @@
// IS_APPLICABLE: false
fun maybeFoo(): String? {
return "foo"
}
@@ -1,7 +0,0 @@
fun maybeFoo(): String? {
return "foo"
}
fun main(args: Array<String>) {
maybeFoo()?.length
}
@@ -1,3 +1,5 @@
// IS_APPLICABLE: false
fun maybeFoo(): String? {
return "foo"
}
@@ -1,7 +0,0 @@
fun maybeFoo(): String? {
return "foo"
}
fun main(args: Array<String>) {
maybeFoo()?.length
}
@@ -71,22 +71,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
<problem>
<file>emptyThenBlock.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/emptyThenBlock.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
<problem>
<file>emptyElseBlock.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/emptyElseBlock.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
<problem>
<file>doesNotinlineValueOutsideOfScope.kt</file>
<line>8</line>
@@ -111,4 +95,20 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
<problem>
<file>isCondition.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
<problem>
<file>isNotCondition.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isNotCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
</problem>
</problems>
@@ -0,0 +1 @@
fun foo(arg: Any) = if (arg is String<caret>) arg.length else null
@@ -0,0 +1 @@
fun foo(arg: Any) = (arg as? String)?.length
@@ -0,0 +1 @@
fun foo(arg: Any) = if (arg !is String<caret>) null else arg.length
@@ -0,0 +1 @@
fun foo(arg: Any) = (arg as? String)?.length
@@ -0,0 +1,2 @@
// IS_APPLICABLE: false
fun foo(arg: Any) = if (arg !is String?<caret>) null else arg?.length
@@ -0,0 +1,2 @@
// IS_APPLICABLE: false
fun foo(arg: Any) = if (arg is String?<caret>) arg?.length else null