Add inspection to simplify successive null checks #KT-14799 Fixed

This commit is contained in:
Dimach
2017-06-21 15:02:06 +03:00
committed by Mikhail Glukhikh
parent fc12f37105
commit 7407083624
17 changed files with 307 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.NullChecksToSafeCallInspection
@@ -0,0 +1,10 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a<caret> != null && a.a != null && a.a.a != null && a.a.a.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,10 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a?.a?.a?.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,7 @@
class My {
fun foo(): String? = null
}
fun test(my: My?) {
if (<caret>my != null && my.foo() != null) {}
}
@@ -0,0 +1,7 @@
class My {
fun foo(): String? = null
}
fun test(my: My?) {
if (my?.foo() != null) {}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
class KotlinType
class KotlinTypeInfo(val type: KotlinType?) {
fun foo(other: KotlinTypeInfo) {
if (<caret>type != null && other.type != null) {
}
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
// Controversial case, better to do nothing here
if (a<caret> != null && a.a?.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,10 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a<caret> == null || a.a == null || a.a.a == null || a.a.a.a == null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,10 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a?.a?.a?.a == null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,11 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a?.a<caret> != null && a.a.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,11 @@
fun main(args: Array<String>) {
val a: Testtt? = Testtt()
if (a?.a?.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,12 @@
// PROBLEM: none
var a: Testtt? = Testtt()
fun main(args: Array<String>) {
if (a<caret> != null && a?.a != null) {
}
}
class Testtt {
val a: Testtt? = null
}
@@ -0,0 +1,12 @@
// PROBLEM: none
val a: Testtt? = Testtt()
fun main(args: Array<String>) {
if (a<caret> != null && a.a != null) {
}
}
class Testtt
val Testtt?.a: Testtt? get() = null