Reporting unnecessary safe calls on Java's @NotNull values

This commit is contained in:
Andrey Breslav
2015-02-04 19:53:43 +03:00
parent 1d4109aec1
commit 30f5c1b953
4 changed files with 62 additions and 1 deletions
@@ -0,0 +1,44 @@
// 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;
public void foo() {}
}
// 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
platformNN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
platformN?.foo()
platformJ?.foo()
if (platformNN != null) {
platformNN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
if (platformN != null) {
platformN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
if (platformJ != null) {
platformJ<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
}
@@ -0,0 +1,3 @@
package
internal fun test(): kotlin.Unit