K2: Fix Java enhancement when jsr305.jar is not in classpath
In that case, when loading Java, we just remember the name of `@Nonnull` argument (javax.annotation.meta.When), and then use it during enhancement ^KT-56656 Fixed
This commit is contained in:
committed by
Space Team
parent
955b8e1490
commit
644391a8e0
-77
@@ -1,77 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: spr/NullableApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
import java.util.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String foo(String x) { return ""; }
|
||||
public @NullableApi String bar(@NullableApi String y) { return ""; }
|
||||
public @NullableApi List<String> baz1() { return null; }
|
||||
public List<@NullableApi String> baz2() { return null; }
|
||||
public @NullableApi List<@NonNullApi String> baz3() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("").length
|
||||
a.foo(null)?.length
|
||||
|
||||
a.bar("").length
|
||||
a.bar(null)?.length
|
||||
|
||||
a.baz1().get(0).length
|
||||
a.baz1()!!.get(0).length
|
||||
a.baz1()!!.get(0)?.length
|
||||
|
||||
a.baz2().get(0).length
|
||||
a.baz2()!!.get(0).length
|
||||
a.baz2()!!.get(0)?.length
|
||||
|
||||
a.baz3().get(0).length
|
||||
a.baz3()!!.get(0).length
|
||||
a.baz3()!!.get(0)?.length
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: spr/NullableApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
import java.util.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String foo(String x) { return ""; }
|
||||
public @NullableApi String bar(@NullableApi String y) { return ""; }
|
||||
public @NullableApi List<String> baz1() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("").length
|
||||
a.foo(null)?.length
|
||||
|
||||
a.bar("").length
|
||||
a.bar(null)?.length
|
||||
|
||||
a.baz1().get(0).length
|
||||
a.baz1()!!.get(0).length
|
||||
a.baz1()!!.get(0)?.length
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: spr/Nullable.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {
|
||||
}
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null).length
|
||||
a.foo(null, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()!!.length
|
||||
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.kt
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -78,15 +78,15 @@ import test.L
|
||||
fun main(a: test.A, l: L<Map<String, Int>, Int?>, l1: L<Map<String, Int>, Int>) {
|
||||
a.foo(l)
|
||||
a.foo(<!ARGUMENT_TYPE_MISMATCH!>l <!UNCHECKED_CAST!>as L<Map<String, Int>, Int><!><!>)
|
||||
a.foo(l <!UNCHECKED_CAST!>as L<Map<String, Int?>, Int?><!>)
|
||||
a.foo(<!ARGUMENT_TYPE_MISMATCH!>l <!UNCHECKED_CAST!>as L<Map<String, Int?>, Int?><!><!>)
|
||||
|
||||
a.bar(l1)
|
||||
a.bar(l1 <!UNCHECKED_CAST!>as L<Map<String, Int>, Int?><!>)
|
||||
a.bar(<!ARGUMENT_TYPE_MISMATCH!>l1 <!UNCHECKED_CAST!>as L<Map<String, Int>, Int?><!><!>)
|
||||
|
||||
a.baz1().t().containsKey("")
|
||||
a.baz1().t().containsKey(null)
|
||||
a.baz1().t().<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>containsKey<!>(null)
|
||||
a.baz1().t().containsValue(1)
|
||||
a.baz1().t().containsValue(null)
|
||||
a.baz1().t().<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>containsValue<!>(null)
|
||||
a.baz1().s().hashCode()
|
||||
|
||||
a.baz1().setT(l.t())
|
||||
@@ -100,8 +100,8 @@ fun main(a: test.A, l: L<Map<String, Int>, Int?>, l1: L<Map<String, Int>, Int>)
|
||||
a.baz2().s().hashCode()
|
||||
|
||||
a.baz3().t().containsKey("")
|
||||
a.baz3().t().containsKey(null)
|
||||
a.baz3().t().<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>containsKey<!>(null)
|
||||
a.baz3().t().containsValue(1)
|
||||
a.baz3().t().containsValue(null)
|
||||
a.baz3().t().<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>containsValue<!>(null)
|
||||
a.baz3().s().hashCode()
|
||||
}
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE, ElementType.METHOD})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: spr/NullableApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
import java.util.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String foo(String x) { return ""; }
|
||||
public @NullableApi String bar(@NullableApi String y) { return ""; }
|
||||
public @NullableApi List<String> baz1() { return null; }
|
||||
public List<@NullableApi String> baz2() { return null; }
|
||||
public @NullableApi List<@NonNullApi String> baz3() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("").length
|
||||
a.foo(null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
a.bar("").length
|
||||
a.bar(null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
a.baz1().get(0).length
|
||||
a.baz1()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0).length
|
||||
a.baz1()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0)?.length
|
||||
|
||||
a.baz2().get(0).length
|
||||
a.baz2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0).length
|
||||
a.baz2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0)?.length
|
||||
|
||||
a.baz3().get(0).length
|
||||
a.baz3()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0).length
|
||||
a.baz3()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.get(0)?.length
|
||||
}
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SKIP_JAVAC
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
|
||||
Reference in New Issue
Block a user