Refactoring: "simplify assert not null" is now an inspection
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.SimplifyAssertNotNullInspection
|
||||
@@ -0,0 +1,8 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
// now let's check it for null
|
||||
<caret>assert(v != null /* null */, /* lazy message */ { "Should be not null" }) // 'v' should not be null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0] ?: error(/* null */ /* lazy message */"Should be not null")
|
||||
// now let's check it for null
|
||||
// 'v' should not be null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// FIX: "Replace with '!!' operator"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
// now let's check it for null
|
||||
<caret>assert(v != null /* null */) // 'v' should not be null
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FIX: "Replace with '!!' operator"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
/* null */
|
||||
val v = p[0]!!
|
||||
// now let's check it for null
|
||||
// 'v' should not be null
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null, { val t = 1; "Should be not null: $t" })
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v == null)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
class C {
|
||||
fun error(message: String) { }
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null) { "message" }
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
class C {
|
||||
fun error(message: String) { }
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0] <caret>?: kotlin.error("message")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
class C {
|
||||
fun assert(b: Boolean) { }
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// FIX: "Replace with '!!' operator"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIX: "Replace with '!!' operator"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]!!<caret>
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v1 = p[0]
|
||||
val v2 = p[1]
|
||||
<caret>assert(v1 != null)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
class C(val v: String?) {
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(this.v != null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null, { "Should be not null" })
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0] <caret>?: error("Should be not null")
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0]
|
||||
<caret>assert(v != null) { "Should be not null" }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// FIX: "Replace with '?: error(...)'"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(p: Array<String?>) {
|
||||
val v = p[0] <caret>?: error("Should be not null")
|
||||
}
|
||||
Reference in New Issue
Block a user