Convert IfThenToElvisIntention to inspection & decrease severity to INFO
#KT-16067 Fixed
This commit is contained in:
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun test(): String? {
|
||||
var foo = maybeFoo()
|
||||
val bar = if (foo == null<caret>)
|
||||
"hello"
|
||||
else
|
||||
foo
|
||||
return foo
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun test(): String? {
|
||||
var foo = maybeFoo()
|
||||
val bar = foo ?: "hello"
|
||||
return foo
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = null
|
||||
val bar = "bar"
|
||||
|
||||
if (foo != null<caret>) {
|
||||
doSomething ("Hello")
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo = null
|
||||
val a = "a"
|
||||
val b = "b"
|
||||
|
||||
if (foo != null<caret>) {
|
||||
a
|
||||
}
|
||||
else {
|
||||
b
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// 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
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// 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)
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
if (null == <caret>null) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
operator fun <T> T.compareTo(a: T): Int = 0
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = null
|
||||
val bar = "bar"
|
||||
if (foo > null<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// ERROR: Type mismatch: inferred type is Int but Boolean was expected
|
||||
// ERROR: Type mismatch: inferred type is Int but Boolean was expected
|
||||
// ERROR: Operator call corresponds to a dot-qualified call 'foo.times(10)' which is not allowed on a nullable receiver 'foo'.
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo: Int? = 4
|
||||
val bar = 3
|
||||
if (foo * 10<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
|
||||
data class IntPair(val first: Int?, val second: Int?)
|
||||
|
||||
fun f(pair: IntPair): Int {
|
||||
val (x, y) = pair
|
||||
return if (x != <caret>null) x else 5
|
||||
}
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
|
||||
data class IntPair(val first: Int?, val second: Int?)
|
||||
|
||||
fun f(pair: IntPair): Int {
|
||||
val (x, y) = pair
|
||||
return x ?: 5
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
doSomething(foo)
|
||||
val bar = "bar"
|
||||
if (foo != null<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
doSomething(foo)
|
||||
val bar = "bar"
|
||||
foo ?: bar
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
val x = maybeFoo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (x !=<caret> null) {
|
||||
x
|
||||
} else {
|
||||
"abc"
|
||||
}
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
val x = maybeFoo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
x ?: "abc"
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo = "foo"
|
||||
val bar = "foo"
|
||||
if (<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = null
|
||||
if (foo != null<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
val bar = "bar"
|
||||
if (foo == null<caret>) {
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class Foo {
|
||||
fun Foo.bar(): Int = 1
|
||||
}
|
||||
|
||||
fun Foo.test(foo: Foo?): Int = <caret>if (foo == null) { 0 } else { foo.bar() }
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
class Foo {
|
||||
fun Foo.bar(): Int = 1
|
||||
}
|
||||
|
||||
fun Foo.test(foo: Foo?): Int = foo?.bar() ?: 0
|
||||
@@ -1,14 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
if (foo != null<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
if (foo != null<caret>)
|
||||
foo
|
||||
else
|
||||
bar
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
val x = if (foo == null<caret>) {
|
||||
bar
|
||||
}
|
||||
else {
|
||||
foo
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
val x = maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
val x = "baz" + if (foo == null<caret>) bar else foo
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
val x = "baz" + (maybeFoo() ?: bar)
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun foo(arg: Any): Int {
|
||||
// 1
|
||||
return <caret>if (arg is Int) arg
|
||||
// 2
|
||||
else 10
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
fun foo(arg: Any): Int {
|
||||
// 1
|
||||
return arg as? Int
|
||||
// 2
|
||||
?: 10
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() = <caret>if (this == null) true else isEmpty()
|
||||
@@ -1,2 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() = this?.isEmpty() ?: true
|
||||
@@ -1,90 +0,0 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>willNotInlineClassProperty.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/src/willNotInlineClassProperty.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>ifAsExpression.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/src/ifAsExpression.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>ifAsPartOfExpression.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/src/ifAsPartOfExpression.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>doesNotInlineVariableInMultiDeclaration.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/src/doesNotInlineVariableInMultiDeclaration.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>nullCheckWithSelector.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="nullCheckWithSelector.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>nullCheckWithSelectorCall.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="nullCheckWithSelectorCall.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>nullCheckWithSelectorCallChain.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="nullCheckWithSelectorCallChain.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>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>
|
||||
<problem>
|
||||
<file>implicitReceiver.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/implicitReceiver.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>applicableForLocalStableVar.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/applicableForLocalStableVar.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>extensionFunctionInClass.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/extensionFunctionInClass.kt" />
|
||||
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
|
||||
<description>Replace 'if' expression with elvis expression</description>
|
||||
</problem>
|
||||
</problems>
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisInspection
|
||||
// WITH_RUNTIME
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My {
|
||||
return if (<caret>arg is My) arg else My(42)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My {
|
||||
return arg as? My ?: My(42)
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun foo(x: CharSequence?) {
|
||||
val y = if (x is String?) {
|
||||
x
|
||||
}
|
||||
else {
|
||||
(x as CharSequence).toString()
|
||||
}<caret>
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
interface A
|
||||
interface B
|
||||
|
||||
fun prepare(x: A) = x
|
||||
fun use(x: A) {}
|
||||
|
||||
fun test(x: A) {
|
||||
val xx = <caret>if (x is B) x else prepare(x)
|
||||
use(xx)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int {
|
||||
return if (<caret>arg is My) arg.x else 42
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int {
|
||||
return (arg as? My)?.x ?: 42
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int {
|
||||
return if (<caret>arg is My) arg.x.hashCode() else 42
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): Int {
|
||||
return (arg as? My)?.x?.hashCode() ?: 42
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
interface Taggable {
|
||||
val tag: String
|
||||
}
|
||||
|
||||
fun Any.log() {
|
||||
val tag = <caret>if (this is Taggable) {
|
||||
tag
|
||||
}
|
||||
else {
|
||||
this::class.java.simpleName
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
interface Taggable {
|
||||
val tag: String
|
||||
}
|
||||
|
||||
fun Any.log() {
|
||||
val tag = (this as? Taggable)?.tag ?: this::class.java.simpleName
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
if (foo == null<caret>)
|
||||
bar
|
||||
else
|
||||
foo
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
val bar = "bar"
|
||||
if (foo != null<caret>)
|
||||
foo
|
||||
else
|
||||
bar
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
if (foo == null<caret>) {
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
val bar = "bar"
|
||||
if (foo != null<caret>)
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
val bar = "bar"
|
||||
if<caret> {
|
||||
foo
|
||||
} else bar
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo = "foo"
|
||||
val bar = "bar"
|
||||
if (foo == bar<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//IS_APPLICABLE: false
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (maybeFoo() == null<caret>)
|
||||
maybeFoo()
|
||||
else
|
||||
"bar"
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun capture(block: () -> Unit): Unit = Unit
|
||||
|
||||
fun test(): String? {
|
||||
var foo = maybeFoo()
|
||||
|
||||
capture {
|
||||
foo = null
|
||||
}
|
||||
|
||||
val bar = if (foo == null<caret>)
|
||||
42
|
||||
else
|
||||
foo
|
||||
|
||||
return foo
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun main(args: Array<String>) {
|
||||
val t: String? = "abc"
|
||||
if (t != null<caret>) t else throw KotlinNullPointerException()
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun main(args: Array<String>) {
|
||||
val t: String? = "abc"
|
||||
if (t == null<caret>) throw NullPointerException() else t
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My {
|
||||
return if (<caret>arg !is My) My(42) else arg
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: Any?): My {
|
||||
return arg as? My ?: My(42)
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
if (foo == null<caret>) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
foo
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: My?): Int {
|
||||
return if (<caret>arg != null) arg.x else 42
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
class My(val x: Int)
|
||||
|
||||
fun foo(arg: My?): Int {
|
||||
return arg?.x ?: 42
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = if (<caret>nullableString != null) {
|
||||
nullableString.toUpperCase()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = nullableString?.toUpperCase() ?: ""
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = if (<caret>nullableString != null) {
|
||||
nullableString.toUpperCase().toLowerCase()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val nullableString: String? = "abc"
|
||||
|
||||
val foo = nullableString?.toUpperCase()?.toLowerCase() ?: ""
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
class Something {
|
||||
fun nullable(): Int? = null
|
||||
}
|
||||
fun Something?.nullable(value: Int): Int? =
|
||||
<caret>if (this == null) value else nullable()
|
||||
@@ -1,7 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun foo(p: String?): String? {
|
||||
return <caret>if (p != null) p.bar() else "a"
|
||||
}
|
||||
|
||||
fun String.bar(): String? = null
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun <T> doSomething(a: T) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = null
|
||||
val bar = "bar"
|
||||
|
||||
if (foo != null<caret>) {
|
||||
foo
|
||||
}
|
||||
else {
|
||||
doSomething("Hello")
|
||||
bar
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String?) {
|
||||
val x = <caret>if (s != null) {
|
||||
bar(s)
|
||||
}
|
||||
else {
|
||||
13
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -1,7 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String?) {
|
||||
val x = s?.let { bar(it) } ?: 13
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -1,12 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(it: String?) {
|
||||
val x = <caret>if (it != null) {
|
||||
bar(it)
|
||||
}
|
||||
else {
|
||||
13
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(it: String?) {
|
||||
val x = it?.let { it1 -> bar(it1) } ?: 13
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -1,15 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: String?): String {
|
||||
return <caret>if (param1 != null) {
|
||||
doAThing(param1)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: String?): String {
|
||||
return param1?.let { doAThing(it) } ?: ""
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: Any?): String {
|
||||
return <caret>if (param1 is String) {
|
||||
doAThing(param1)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: Any?): String {
|
||||
return (param1 as? String)?.let { doAThing(it) } ?: ""
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
val foo = maybeFoo()
|
||||
if (null == foo<caret>)
|
||||
bar
|
||||
else
|
||||
foo
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bar = "bar"
|
||||
maybeFoo() ?: bar
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun bar(): String = "bar"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (null != foo<caret>)
|
||||
foo
|
||||
else
|
||||
bar()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun maybeFoo(): String? {
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fun bar(): String = "bar"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo() ?: bar()
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun main(args: Array<String>) {
|
||||
val foo = null
|
||||
if (foo == null<caret>) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun main(args: Array<String>) {
|
||||
val t: String? = "abc"
|
||||
if (t != null<caret>) t else throw NullPointerException("'t' must not be null")
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun main(args: Array<String>) {
|
||||
"abc" ?: throw NullPointerException("'t' must not be null")
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
open class Some {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
object Obj : Some()
|
||||
|
||||
fun foo(arg: Any?) {
|
||||
<caret>if (arg is Some) {
|
||||
arg.bar()
|
||||
}
|
||||
else {
|
||||
Obj.bar()
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
class F(a: Int?) {
|
||||
val b = a
|
||||
val c = if (b !=<caret> null) b else 2
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
F(1).c
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
class F(a: Int?) {
|
||||
val b = a
|
||||
val c = b ?: 2
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
F(1).c
|
||||
}
|
||||
Reference in New Issue
Block a user