Reporting USELESS_ELVIS and UNNECESSARY_NOT_NULL_ASSERTION on Java's @NotNull values

This commit is contained in:
Andrey Breslav
2015-02-05 17:39:36 +03:00
parent 30f5c1b953
commit f36d6ce5b2
11 changed files with 257 additions and 5 deletions
@@ -0,0 +1,45 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// 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 v0 = platformNN <!USELESS_ELVIS!>?:<!> J()
platformNN <!USELESS_ELVIS!>?:<!> J()
platformN ?: J()
platformJ ?: J()
if (platformNN != null) {
<!USELESS_ELVIS!>platformNN<!> ?: J()
}
if (platformN != null) {
<!USELESS_ELVIS!>platformN<!> ?: J()
}
if (platformJ != null) {
<!USELESS_ELVIS!>platformJ<!> ?: J()
}
}
@@ -0,0 +1,3 @@
package
internal fun test(): kotlin.Unit
@@ -0,0 +1,43 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -SENSELESS_COMPARISON -UNUSED_PARAMETER
// 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
if (platformNN != null) {
platformNN<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (platformN != null) {
platformN<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (platformJ != null) {
platformJ<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
platformNN<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
platformN!!
platformJ!!
}
@@ -0,0 +1,3 @@
package
internal fun test(): kotlin.Unit
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: p/J.java
package p;
import org.jetbrains.annotations.*;
public class J {
@NotNull
public static J staticNN;
}
// FILE: k.kt
import p.*
fun test() {
// @NotNull platform type
val platformNN = J.staticNN
foo(platformNN<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
val bar = Bar()
bar(platformNN<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}
fun foo(a: Any) {}
class Bar {
fun invoke(a: Any) {}
}
@@ -0,0 +1,12 @@
package
internal fun foo(/*0*/ a: kotlin.Any): kotlin.Unit
internal fun test(): kotlin.Unit
internal final class Bar {
public constructor Bar()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal final fun invoke(/*0*/ a: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,31 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: p/J.java
package p;
import org.jetbrains.annotations.*;
public class J {
@NotNull
public static J staticNN;
}
// FILE: k.kt
import p.*
fun test() {
// @NotNull platform type
val platformNN = J.staticNN
foo(platformNN <!USELESS_ELVIS!>?:<!> "")
val bar = Bar()
bar(platformNN <!USELESS_ELVIS!>?:<!> "")
}
fun foo(a: Any) {}
class Bar {
fun invoke(a: Any) {}
}
@@ -0,0 +1,12 @@
package
internal fun foo(/*0*/ a: kotlin.Any): kotlin.Unit
internal fun test(): kotlin.Unit
internal final class Bar {
public constructor Bar()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal final fun invoke(/*0*/ a: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}