Generate foreign annotation test data for FIR
This commit is contained in:
+77
@@ -0,0 +1,77 @@
|
||||
// !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
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// !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
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// !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)
|
||||
}
|
||||
Vendored
+107
@@ -0,0 +1,107 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// RENDER_PACKAGE: test
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
// WITH_RUNTIME
|
||||
// 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.TYPE_USE})
|
||||
@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.PACKAGE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.TYPE_USE})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: test/package-info.java
|
||||
@spr.NonNullApi()
|
||||
package test;
|
||||
|
||||
// FILE: test/L.java
|
||||
package test;
|
||||
|
||||
public class L<T extends java.util.Map<String, S>, S> {
|
||||
public T t() { return null; }
|
||||
public S s() { return null; }
|
||||
|
||||
public void setT(@spr.Nullable T t) {}
|
||||
public void setS(S s) {}
|
||||
}
|
||||
|
||||
// FILE: test/A.java
|
||||
package test;
|
||||
|
||||
import spr.*;
|
||||
import java.util.*;
|
||||
|
||||
public class A {
|
||||
public void foo(L<Map<String, Integer>, @Nullable Integer> l) {}
|
||||
public void bar(L<?, Integer> l) {}
|
||||
public L<Map<String, Integer>, @Nullable Integer> baz1() { return null; }
|
||||
public L<?, Integer> baz2() { return null; }
|
||||
public L<? extends Map<String, Integer>, Integer> baz3() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
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(l as L<Map<String, Int>, Int>)
|
||||
a.foo(l as L<Map<String, Int?>, Int?>)
|
||||
|
||||
a.bar(l1)
|
||||
a.bar(l1 as L<Map<String, Int>, Int?>)
|
||||
|
||||
a.baz1().t().containsKey("")
|
||||
a.baz1().t().containsKey(null)
|
||||
a.baz1().t().containsValue(1)
|
||||
a.baz1().t().containsValue(null)
|
||||
a.baz1().s().hashCode()
|
||||
|
||||
a.baz1().setT(l.t())
|
||||
a.baz1().setT(<!ARGUMENT_TYPE_MISMATCH!>l.t() as L<Map<String, Int>, Int><!>)
|
||||
a.baz1().setT(null)
|
||||
|
||||
a.baz2().t().containsKey("")
|
||||
a.baz2().t().containsKey(null)
|
||||
a.baz2().t().containsValue(1)
|
||||
a.baz2().t().containsValue(null)
|
||||
a.baz2().s().hashCode()
|
||||
|
||||
a.baz3().t().containsKey("")
|
||||
a.baz3().t().containsKey(null)
|
||||
a.baz3().t().containsValue(1)
|
||||
a.baz3().t().containsValue(null)
|
||||
a.baz3().s().hashCode()
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
// !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
|
||||
}
|
||||
Reference in New Issue
Block a user