SenselessComparisonChecker used for @NotNull values from Java

This commit is contained in:
Andrey Breslav
2015-02-05 19:18:10 +03:00
parent d31b9be5fb
commit fcb6055913
10 changed files with 141 additions and 15 deletions
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !DIAGNOSTICS: -UNUSED_VARIABLE -SENSELESS_COMPARISON
// FILE: p/J.java
package p;
@@ -1,3 +1,5 @@
// !DIAGNOSTICS: -SENSELESS_COMPARISON
// FILE: p/J.java
package p;
@@ -0,0 +1,45 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// FILE: p/J.java
package p;
import org.jetbrains.annotations.*;
public class J {
@NotNull
public static J staticNN;
@Nullable
public static J staticN;
public static J staticJ;
}
// FILE: k.kt
import p.*
fun test() {
// @NotNull platform type
val platformNN = J.staticNN
// @Nullable platform type
val platformN = J.staticN
// platform type with no annotation
val platformJ = J.staticJ
val a: Any? = null
if (<!SENSELESS_COMPARISON!>platformNN != null<!>) {}
if (<!SENSELESS_COMPARISON!>null != platformNN<!>) {}
if (<!SENSELESS_COMPARISON!>platformNN == null<!>) {}
if (<!SENSELESS_COMPARISON!>null == platformNN<!>) {}
if (a != null && platformNN != a) {}
if (platformN != null) {}
if (platformN == null) {}
if (a == null && platformN == a) {}
if (platformJ != null) {}
if (platformJ == null) {}
if (a == null && platformJ == a) {}
}
@@ -0,0 +1,3 @@
package
internal fun test(): kotlin.Unit
@@ -0,0 +1,43 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// FILE: p/J.java
package p;
import org.jetbrains.annotations.*;
public class J {
@NotNull
public static J staticNN;
@Nullable
public static J staticN;
public static J staticJ;
}
// FILE: k.kt
import p.*
fun test() {
// @NotNull platform type
val platformNN = J.staticNN
// @Nullable platform type
val platformN = J.staticN
// platform type with no annotation
val platformJ = J.staticJ
val a: Any? = null
if (<!SENSELESS_COMPARISON!>platformNN !== null<!>) {}
if (<!SENSELESS_COMPARISON!>null !== platformNN<!>) {}
if (<!SENSELESS_COMPARISON!>platformNN === null<!>) {}
if (<!SENSELESS_COMPARISON!>null === platformNN<!>) {}
if (platformN !== null) {}
if (platformN === null) {}
if (a === null && platformN === a) {}
if (platformJ !== null) {}
if (platformJ === null) {}
if (a === null && platformJ === a) {}
}
@@ -0,0 +1,3 @@
package
internal fun test(): kotlin.Unit