Add "Redundant 'requireNotNull' or 'checkNotNull' call" inspection

#KT-29113 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-04 16:40:55 +09:00
committed by Mikhail Glukhikh
parent c234683770
commit fa1f3871c0
16 changed files with 212 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RedundantRequireNotNullCallInspection
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test(s: String) {
println(1)
kotlin.<caret>checkNotNull(s)
println(2)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(s: String) {
println(1)
println(2)
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test(s: String) {
println(1)
<caret>requireNotNull(s)
println(2)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(s: String) {
println(1)
println(2)
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun test(s: String?) {
if (s != null) {
println(1)
requireNotNull<caret>(s) { "" }
println(2)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test(s: String?) {
if (s != null) {
println(1)
println(2)
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test(s: String?) {
requireNotNull(s)
<caret>requireNotNull(s)
println(1)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(s: String?) {
requireNotNull(s)
println(1)
}
@@ -0,0 +1,5 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(s: String?) {
<caret>requireNotNull(s)
}
@@ -0,0 +1,11 @@
// PROBLEM: none
// WITH_RUNTIME
class Test {
var s: String? = null
fun test() {
if (s != null) {
<caret>requireNotNull(s)
}
}
}
@@ -0,0 +1,5 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(b: Boolean) {
<caret>require(b)
}