[FIR] Implement UNNECESSARY_SAFE_CALL checker for java warning level types
#KT-63528 Fixed
This commit is contained in:
committed by
Space Team
parent
9c0ac27307
commit
d6bd31b313
-72
@@ -1,72 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: MyNotNull.java
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Nonnull
|
||||
@TypeQualifierNickname
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyNotNull {}
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJsr.java
|
||||
public class AnnotatedWithJsr {
|
||||
@MyNotNull
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(@MyNotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJB.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AnnotatedWithJB {
|
||||
public @NotNull String getString() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
public void consumeString(@NotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: PlainJava.java
|
||||
public class PlainJava {
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
val jsr: AnnotatedWithJsr = AnnotatedWithJsr()
|
||||
val jsrNullable: AnnotatedWithJsr? = null
|
||||
|
||||
val jb: AnnotatedWithJB = AnnotatedWithJB()
|
||||
val jbNullable: AnnotatedWithJB? = null
|
||||
|
||||
val platform: PlainJava = PlainJava()
|
||||
val platformNullable: PlainJava? = null
|
||||
|
||||
fun safeCalls() {
|
||||
val a = jsr.string?.length
|
||||
val b = jsrNullable?.string?.length
|
||||
|
||||
val c = jb.string<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
val d = jbNullable?.string?.length
|
||||
|
||||
val e = platform.string?.length
|
||||
val f = platformNullable?.string?.length
|
||||
}
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
|
||||
+4
-4
@@ -126,7 +126,7 @@ public class A {
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: A.B, c: A.C) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
@@ -136,7 +136,7 @@ fun main(a: A, b: A.B, c: A.C) {
|
||||
a.bar().length
|
||||
a.bar()!!.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
@@ -149,7 +149,7 @@ fun main(a: A, b: A.B, c: A.C) {
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo(null, "")<!>.length
|
||||
|
||||
b.foobar(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
b.foobar("", null)?.length
|
||||
b.foobar("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.bar()<!>.length
|
||||
b.bar()!!.length
|
||||
@@ -162,7 +162,7 @@ fun main(a: A, b: A.B, c: A.C) {
|
||||
b.baz()!!.get(0)?.get(0)
|
||||
|
||||
// c
|
||||
c.foo("", null)?.length
|
||||
c.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
c.foo("", null).length
|
||||
c.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public class A {
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class A {
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: test.A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
|
||||
Reference in New Issue
Block a user