Refactoring of IfThen: ToDoubleBang / ToElvis / ToSafeAccess
Some common actions were extracted to IfThenUtils.kt Use consistent logic in all three intentions Also fixes potential PSI consistency problems in conversions dot->safe calls
This commit is contained in:
+24
@@ -111,4 +111,28 @@
|
||||
<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>nullCheckWithSelectorCallChain.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/nullCheckWithSelectorCallChain.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>isCheckWithSelectorChain.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/isCheckWithSelectorChain.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>isCheckSimple.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/isCheckSimple.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,5 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My? {
|
||||
return if (<caret>arg is My) arg else null
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My? {
|
||||
return arg as? My
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int? {
|
||||
return if (<caret>arg is My) arg.x.hashCode() else null
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int? {
|
||||
return (arg as? My)?.x?.hashCode()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun foo(arg: Any?): Any? {
|
||||
return if (<caret>arg != null) arg else null
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = if (<caret>nullableString != null) {
|
||||
nullableString.toUpperCase().toLowerCase()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = nullableString?.toUpperCase()?.toLowerCase()
|
||||
Reference in New Issue
Block a user