diff --git a/compiler/testData/foreignAnnotations/testAnnotations/MyNonnull.java b/compiler/testData/foreignAnnotations/testAnnotations/MyNonnull.java new file mode 100644 index 00000000000..0429da2f377 --- /dev/null +++ b/compiler/testData/foreignAnnotations/testAnnotations/MyNonnull.java @@ -0,0 +1,15 @@ +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.ALWAYS) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNonnull { + +} diff --git a/compiler/testData/foreignAnnotations/testAnnotations/MyNullable.java b/compiler/testData/foreignAnnotations/testAnnotations/MyNullable.java new file mode 100644 index 00000000000..921270b975c --- /dev/null +++ b/compiler/testData/foreignAnnotations/testAnnotations/MyNullable.java @@ -0,0 +1,15 @@ +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNullable { + +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt new file mode 100644 index 00000000000..041b909cdb9 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt @@ -0,0 +1,51 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static Integer staticNN; + @MyNullable + public static Integer staticN; + public static Integer staticJ; +} + +// FILE: k.kt + +fun test() { + var platformNN = J.staticNN + var platformN = J.staticN + var platformJ = J.staticJ + + +platformNN + +platformN + +platformJ + + ++platformNN + ++platformN + ++platformJ + + platformNN++ + platformN++ + platformJ++ + + 1 + platformNN + 1 + platformN + 1 + platformJ + + platformNN + 1 + platformN + 1 + platformJ + 1 + + 1 plus platformNN + 1 plus platformN + 1 plus platformJ + + platformNN plus 1 + platformN plus 1 + platformJ plus 1 + + platformNN += 1 + platformN += 1 + platformJ += 1 +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.txt new file mode 100644 index 00000000000..75d9fc8d51d --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.Int! + @MyNullable public final var staticN: kotlin.Int! + @MyNonnull public final var staticNN: kotlin.Int! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt new file mode 100644 index 00000000000..1d3361208c6 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt @@ -0,0 +1,27 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static Integer[] staticNN; + @MyNullable + public static Integer[] staticN; + public static Integer[] staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + platformNN[0] + platformN[0] + platformJ[0] + + platformNN[0] = 1 + platformN[0] = 1 + platformJ[0] = 1 +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.txt new file mode 100644 index 00000000000..101a12b4f9f --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.Array<(out) kotlin.Int!>! + @MyNullable public final var staticN: kotlin.Array<(out) kotlin.Int!>! + @MyNonnull public final var staticNN: kotlin.Array<(out) kotlin.Int!>! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt new file mode 100644 index 00000000000..26c91535bb9 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt @@ -0,0 +1,26 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +var v: J = J() +var n: J? = J() + +fun test() { + v = J.staticNN + v = J.staticN + v = J.staticJ + + n = J.staticNN + n = J.staticN + n = J.staticJ +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.txt new file mode 100644 index 00000000000..4263b6de9da --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.txt @@ -0,0 +1,17 @@ +package + +public var n: J? +public var v: J +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt new file mode 100644 index 00000000000..9ee6fa645c1 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static Boolean staticNN; + @MyNullable + public static Boolean staticN; + public static Boolean staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + if (platformNN) {} + if (platformN) {} + if (platformJ) {} + + while (platformNN) {} + while (platformN) {} + while (platformJ) {} + + do {} while (platformNN) + do {} while (platformN) + do {} while (platformJ) + + platformNN && false + platformN && false + platformJ && false + + platformNN || false + platformN || false + platformJ || false + + !platformNN + !platformN + !platformJ +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.txt new file mode 100644 index 00000000000..102cb34dc69 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.Boolean! + @MyNullable public final var staticN: kotlin.Boolean! + @MyNonnull public final var staticNN: kotlin.Boolean! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt new file mode 100644 index 00000000000..374049db81c --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; +} + +// FILE: k.kt + +fun test() { + val n = J.staticN + foo(n) + J.staticNN = n + if (n != null) { + foo(n) + J.staticNN = n + } + + val x: J? = null + J.staticNN = x + if (x != null) { + J.staticNN = x + } +} + +fun foo(j: J) {} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.txt new file mode 100644 index 00000000000..bb7557ec32b --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.txt @@ -0,0 +1,15 @@ +package + +public fun foo(/*0*/ j: J): kotlin.Unit +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt new file mode 100644 index 00000000000..37b66ea2d42 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + fun foo(p: J = platformNN, p1: J = platformN, p2: J = platformJ) {} + + fun foo1(p: J? = platformNN, p1: J? = platformN, p2: J? = platformJ) {} +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.txt new file mode 100644 index 00000000000..e4e674e5f95 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt new file mode 100644 index 00000000000..f37c6ed2e3e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt @@ -0,0 +1,23 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + + public interface DP { + String getValue(Object a, Object b); + String setValue(Object a, Object b, Object c); + } + + @MyNonnull + public static DP staticNN; + @MyNullable + public static DP staticN; + public static DP staticJ; +} + +// FILE: k.kt + +var A by J.staticNN +var B by J.staticN +var C by J.staticJ \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.txt new file mode 100644 index 00000000000..e69824b6980 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.txt @@ -0,0 +1,25 @@ +package + +public var A: kotlin.String! +public var B: kotlin.String! +public var C: kotlin.String! + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public interface DP { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract operator fun getValue(/*0*/ a: kotlin.Any!, /*1*/ b: kotlin.Any!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract operator fun setValue(/*0*/ a: kotlin.Any!, /*1*/ b: kotlin.Any!, /*2*/ c: kotlin.Any!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + // Static members + public final var staticJ: J.DP! + @MyNullable public final var staticN: J.DP! + @MyNonnull public final var staticNN: J.DP! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt new file mode 100644 index 00000000000..6d3dbab8f44 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt @@ -0,0 +1,19 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +import java.util.*; + +public class J { + @MyNonnull + public static List staticNN; + @MyNullable + public static List staticN; + public static List staticJ; +} + +// FILE: k.kt + +class A : List by J.staticNN +class B : List by J.staticN +class C : List by J.staticJ \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.txt new file mode 100644 index 00000000000..50bd014ceb1 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.txt @@ -0,0 +1,79 @@ +package + +public final class A : kotlin.collections.List { + public constructor A() + public open override /*1*/ /*delegation*/ val size: kotlin.Int + public open override /*1*/ /*delegation*/ fun contains(/*0*/ element: kotlin.String): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun forEach(/*0*/ p0: java.util.function.Consumer!): kotlin.Unit + public open override /*1*/ /*delegation*/ fun get(/*0*/ index: kotlin.Int): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*delegation*/ fun indexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun isEmpty(): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun iterator(): kotlin.collections.Iterator + public open override /*1*/ /*delegation*/ fun lastIndexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun listIterator(): kotlin.collections.ListIterator + public open override /*1*/ /*delegation*/ fun listIterator(/*0*/ index: kotlin.Int): kotlin.collections.ListIterator + public open override /*1*/ /*fake_override*/ fun parallelStream(): java.util.stream.Stream + public open override /*1*/ /*fake_override*/ fun spliterator(): java.util.Spliterator + public open override /*1*/ /*fake_override*/ fun stream(): java.util.stream.Stream + public open override /*1*/ /*delegation*/ fun subList(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.collections.List + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class B : kotlin.collections.List { + public constructor B() + public open override /*1*/ /*delegation*/ val size: kotlin.Int + public open override /*1*/ /*delegation*/ fun contains(/*0*/ element: kotlin.String): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun forEach(/*0*/ p0: java.util.function.Consumer!): kotlin.Unit + public open override /*1*/ /*delegation*/ fun get(/*0*/ index: kotlin.Int): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*delegation*/ fun indexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun isEmpty(): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun iterator(): kotlin.collections.Iterator + public open override /*1*/ /*delegation*/ fun lastIndexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun listIterator(): kotlin.collections.ListIterator + public open override /*1*/ /*delegation*/ fun listIterator(/*0*/ index: kotlin.Int): kotlin.collections.ListIterator + public open override /*1*/ /*fake_override*/ fun parallelStream(): java.util.stream.Stream + public open override /*1*/ /*fake_override*/ fun spliterator(): java.util.Spliterator + public open override /*1*/ /*fake_override*/ fun stream(): java.util.stream.Stream + public open override /*1*/ /*delegation*/ fun subList(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.collections.List + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class C : kotlin.collections.List { + public constructor C() + public open override /*1*/ /*delegation*/ val size: kotlin.Int + public open override /*1*/ /*delegation*/ fun contains(/*0*/ element: kotlin.String): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun forEach(/*0*/ p0: java.util.function.Consumer!): kotlin.Unit + public open override /*1*/ /*delegation*/ fun get(/*0*/ index: kotlin.Int): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*delegation*/ fun indexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun isEmpty(): kotlin.Boolean + public open override /*1*/ /*delegation*/ fun iterator(): kotlin.collections.Iterator + public open override /*1*/ /*delegation*/ fun lastIndexOf(/*0*/ element: kotlin.String): kotlin.Int + public open override /*1*/ /*delegation*/ fun listIterator(): kotlin.collections.ListIterator + public open override /*1*/ /*delegation*/ fun listIterator(/*0*/ index: kotlin.Int): kotlin.collections.ListIterator + public open override /*1*/ /*fake_override*/ fun parallelStream(): java.util.stream.Stream + public open override /*1*/ /*fake_override*/ fun spliterator(): java.util.Spliterator + public open override /*1*/ /*fake_override*/ fun stream(): java.util.stream.Stream + public open override /*1*/ /*delegation*/ fun subList(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.collections.List + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.collections.(Mutable)List! + @MyNullable public final var staticN: kotlin.collections.(Mutable)List! + @MyNonnull public final var staticNN: kotlin.collections.(Mutable)List! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt new file mode 100644 index 00000000000..50bdaf91f28 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + platformNN.foo() + platformN.foo() + platformJ.foo() + + with(platformNN) { + foo() + } + with(platformN) { + foo() + } + with(platformJ) { + foo() + } + + platformNN.bar() + platformN.bar() + platformJ.bar() +} + +fun J.foo() {} +fun J?.bar() {} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.txt new file mode 100644 index 00000000000..910ab685036 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.txt @@ -0,0 +1,17 @@ +package + +public fun test(): kotlin.Unit +public fun J?.bar(): kotlin.Unit +public fun J.foo(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt new file mode 100644 index 00000000000..1ab42f14d16 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; + + public void foo() {} +} + +// FILE: k.kt + +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.foo() + platformN.foo() + platformJ.foo() + + with(platformNN) { + foo() + } + with(platformN) { + foo() + } + with(platformJ) { + foo() + } +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.txt new file mode 100644 index 00000000000..a6693ca109d --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.txt @@ -0,0 +1,16 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt new file mode 100644 index 00000000000..f1bb7fd09a4 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + checkSubtype(platformNN) + checkSubtype(platformN) + checkSubtype(platformJ) + + checkSubtype(platformNN) + checkSubtype(platformN) + checkSubtype(platformJ) +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.txt new file mode 100644 index 00000000000..e4e674e5f95 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt new file mode 100644 index 00000000000..21ca16afebe --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt @@ -0,0 +1,26 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +import java.util.*; + +public class J { + @MyNonnull + public static List staticNN; + @MyNullable + public static List staticN; + public static List staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + for (x in platformNN) {} + for (x in platformN) {} + for (x in platformJ) {} +} + diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.txt new file mode 100644 index 00000000000..f457f18ac40 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.collections.(Mutable)List! + @MyNullable public final var staticN: kotlin.collections.(Mutable)List! + @MyNonnull public final var staticNN: kotlin.collections.(Mutable)List! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt new file mode 100644 index 00000000000..00c4f82f7cf --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + foo(J.staticNN) + foo(J.staticN) + foo(J.staticJ) + + bar(J.staticNN) + bar(J.staticN) + bar(J.staticJ) +} + +fun foo(j: J) {} +fun bar(j: J?) {} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.txt new file mode 100644 index 00000000000..5eb01e5c6a9 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.txt @@ -0,0 +1,17 @@ +package + +public fun bar(/*0*/ j: J?): kotlin.Unit +public fun foo(/*0*/ j: J): kotlin.Unit +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt new file mode 100644 index 00000000000..914ab0171b4 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt @@ -0,0 +1,23 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + public interface Invoke { + void invoke(); + } + + @MyNonnull + public static Invoke staticNN; + @MyNullable + public static Invoke staticN; + public static Invoke staticJ; +} + +// FILE: k.kt + +fun test() { + J.staticNN() + J.staticN() + J.staticJ() +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.txt new file mode 100644 index 00000000000..fc52e4db20e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.txt @@ -0,0 +1,22 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public interface Invoke { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract operator fun invoke(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + // Static members + public final var staticJ: J.Invoke! + @MyNullable public final var staticN: J.Invoke! + @MyNonnull public final var staticNN: J.Invoke! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt new file mode 100644 index 00000000000..35bc895674e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// KT-6829 False warning on map to @Nullable + +// FILE: J.java + +public class J { + + @MyNullable + public String method() { return ""; } +} + +// FILE: k.kt + +fun foo(collection: Collection) { + val mapped = collection.map { it.method() } + mapped[0].length +} + +public fun Iterable.map(transform: (T) -> R): List { + null!! +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.txt new file mode 100644 index 00000000000..5b75e68f044 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.txt @@ -0,0 +1,12 @@ +package + +public fun foo(/*0*/ collection: kotlin.collections.Collection): kotlin.Unit +public fun kotlin.collections.Iterable.map(/*0*/ transform: (T) -> R): kotlin.collections.List + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @MyNullable public open fun method(): kotlin.String! + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt new file mode 100644 index 00000000000..c643824a033 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + public interface Multi { + String component1(); + String component2(); + } + + @MyNonnull + public static Multi staticNN; + @MyNullable + public static Multi staticN; + public static Multi staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + val (a1, b1) = platformNN + val (a2, b2) = platformN + val (a3, b3) = platformJ +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.txt new file mode 100644 index 00000000000..f692e3b21a7 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.txt @@ -0,0 +1,23 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public interface Multi { + public abstract operator fun component1(): kotlin.String! + public abstract operator fun component2(): kotlin.String! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + // Static members + public final var staticJ: J.Multi! + @MyNullable public final var staticN: J.Multi! + @MyNonnull public final var staticNN: J.Multi! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt new file mode 100644 index 00000000000..2003f670f16 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt @@ -0,0 +1,90 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + + +public class J { + @MyNonnull + public static J staticNN; + @MyNullable + public static J staticN; + public static J staticJ; + + public static void staticSet(@MyNonnull J nn, @MyNullable J n, J j) {} + + public J(@MyNonnull J nn, @MyNullable J n, J j) {} + public J() {} + + @MyNonnull + public J nn; + @MyNullable + public J n; + public J j; + + public void set(@MyNonnull J nn, @MyNullable J n, J j) {} +} + +// FILE: k.kt + +fun test(n: J?, nn: J) { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + J.staticNN = n + J.staticNN = platformN + J.staticNN = nn + J.staticNN = platformNN + J.staticNN = platformJ + + J.staticN = n + J.staticN = platformN + J.staticN = nn + J.staticN = platformNN + J.staticN = platformJ + + J.staticJ = n + J.staticJ = platformN + J.staticJ = nn + J.staticJ = platformNN + J.staticJ = platformJ + + J.staticSet(nn, nn, nn) + J.staticSet(platformNN, platformNN, platformNN) + J.staticSet(n, n, n) + J.staticSet(platformN, platformN, platformN) + J.staticSet(platformJ, platformJ, platformJ) + + J().nn = n + J().nn = platformN + J().nn = nn + J().nn = platformNN + J().nn = platformJ + + J().n = n + J().n = platformN + J().n = nn + J().n = platformNN + J().n = platformJ + + J().j = n + J().j = platformN + J().j = nn + J().j = platformNN + J().j = platformJ + + J().set(nn, nn, nn) + J().set(platformNN, platformNN, platformNN) + J().set(n, n, n) + J().set(platformN, platformN, platformN) + J().set(platformJ, platformJ, platformJ) + + J(nn, nn, nn) + J(platformNN, platformNN, platformNN) + J(n, n, n) + J(platformN, platformN, platformN) + J(platformJ, platformJ, platformJ) +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.txt new file mode 100644 index 00000000000..268d3d61192 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.txt @@ -0,0 +1,21 @@ +package + +public fun test(/*0*/ n: J?, /*1*/ nn: J): kotlin.Unit + +public open class J { + public constructor J() + public constructor J(/*0*/ @MyNonnull nn: J!, /*1*/ @MyNullable n: J!, /*2*/ j: J!) + public final var j: J! + @MyNullable public final var n: J! + @MyNonnull public final var nn: J! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open operator fun set(/*0*/ @MyNonnull nn: J!, /*1*/ @MyNullable n: J!, /*2*/ j: J!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: J! + @MyNullable public final var staticN: J! + @MyNonnull public final var staticNN: J! + public open fun staticSet(/*0*/ @MyNonnull nn: J!, /*1*/ @MyNullable n: J!, /*2*/ j: J!): kotlin.Unit +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt new file mode 100644 index 00000000000..6de9449f8e0 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt @@ -0,0 +1,28 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static int[] staticNN; + @MyNullable + public static int[] staticN; + public static int[] staticJ; +} + +// FILE: k.kt + +fun test() { + val platformNN = J.staticNN + val platformN = J.staticN + val platformJ = J.staticJ + + platformNN[0] + platformN[0] + platformJ[0] + + platformNN[0] = 1 + platformN[0] = 1 + platformJ[0] = 1 +} + diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.txt new file mode 100644 index 00000000000..b4f47f8496d --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.txt @@ -0,0 +1,15 @@ +package + +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: kotlin.IntArray! + @MyNullable public final var staticN: kotlin.IntArray! + @MyNonnull public final var staticNN: kotlin.IntArray! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt new file mode 100644 index 00000000000..cc60fb811b1 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt @@ -0,0 +1,25 @@ +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNonnull + public static Exception staticNN; + @MyNullable + public static Exception staticN; + public static Exception staticJ; +} + +// FILE: k.kt + +fun test() { + throw J.staticNN +} + +fun test1() { + throw J.staticN +} + +fun test2() { + throw J.staticJ +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.txt new file mode 100644 index 00000000000..16131e5bab8 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.txt @@ -0,0 +1,17 @@ +package + +public fun test(): kotlin.Unit +public fun test1(): kotlin.Unit +public fun test2(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticJ: java.lang.Exception! + @MyNullable public final var staticN: java.lang.Exception! + @MyNonnull public final var staticNN: java.lang.Exception! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt new file mode 100644 index 00000000000..8faa1bfb467 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: J.java + +public class J { + @MyNullable + public static J staticN; +} + +// FILE: JJ.java + +public class JJ { + public static JJ staticNN; +} + +// FILE: JJJ.java + +public class JJJ { + @MyNonnull + public static JJJ staticNNN; +} + +// FILE: k.kt + +fun test() { + val a = J.staticN ?: null + foo(a) + val b = JJ.staticNN ?: null + foo(b) + val c = JJJ.staticNNN ?: null + foo(c) +} + +fun foo(a: Any?) { +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.txt new file mode 100644 index 00000000000..0636901a35e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.txt @@ -0,0 +1,34 @@ +package + +public fun foo(/*0*/ a: kotlin.Any?): kotlin.Unit +public fun test(): kotlin.Unit + +public open class J { + public constructor J() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @MyNullable public final var staticN: J! +} + +public open class JJ { + public constructor JJ() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final var staticNN: JJ! +} + +public open class JJJ { + public constructor JJJ() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @MyNonnull public final var staticNNN: JJJ! +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt new file mode 100644 index 00000000000..a59375b2c0f --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: A.java +public class A { + public void foo(@MyNonnull T t) { + } + + public @MyNullable String bar() { + return null; + } + + public @MyNullable T bam() { + return null; + } + + @MyNullable + public X baz() { + return null; + } + +} +// FILE: main.kt + +class X(t: T?) { + + init { + val a = A() + a.foo(t) + + val x: T = a.bam() + val y: T = a.baz() + } +} + +fun test() { + val a = A() + a.foo(null) + + val b: String = a.bar() +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.txt new file mode 100644 index 00000000000..1818db10302 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.txt @@ -0,0 +1,21 @@ +package + +public fun test(): kotlin.Unit + +public open class A { + public constructor A() + @MyNullable public open fun bam(): T! + @MyNullable public open fun bar(): kotlin.String! + @MyNullable public open fun baz(): X! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ @MyNonnull t: T!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class X { + public constructor X(/*0*/ t: T?) + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt new file mode 100644 index 00000000000..5d40b90f9be --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt @@ -0,0 +1,69 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: MyNullable.java +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNullable { + +} + +// FILE: MyNonnull.java +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.ALWAYS) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNonnull { + +} + +// FILE: A.java + +import javax.annotation.*; + +public class A { + @MyNullable public String field = null; + + @MyNullable + public String foo(@MyNonnull String x, @MyNullable CharSequence y) { + return ""; + } + + @MyNonnull + public String bar() { + return ""; + } + +} + +// 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 +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.txt new file mode 100644 index 00000000000..ebc84337f3d --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.txt @@ -0,0 +1,27 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +public open class A { + public constructor A() + @MyNullable public final var field: kotlin.String! + @MyNonnull public open fun bar(): kotlin.String! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @MyNullable public open fun foo(/*0*/ @MyNonnull x: kotlin.String!, /*1*/ @MyNullable y: kotlin.CharSequence!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.MustBeDocumented @javax.annotation.meta.TypeQualifierNickname @javax.annotation.Nonnull(when = When.ALWAYS) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) public final annotation class MyNonnull : kotlin.Annotation { + public constructor MyNonnull() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.MustBeDocumented @javax.annotation.meta.TypeQualifierNickname @javax.annotation.Nonnull(when = When.MAYBE) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) public final annotation class MyNullable : kotlin.Annotation { + public constructor MyNullable() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt new file mode 100644 index 00000000000..c3cc81520f1 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: A.java + +import javax.annotation.*; + +public class A { + @Nullable public String field = null; + + @Nullable + public String foo(@Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } + +} + +// 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 +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.txt new file mode 100644 index 00000000000..77aaa765fbf --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.txt @@ -0,0 +1,13 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +public open class A { + public constructor A() + @javax.annotation.Nullable public final var field: kotlin.String? + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @javax.annotation.Nullable public open fun foo(/*0*/ @javax.annotation.Nonnull x: kotlin.String, /*1*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt new file mode 100644 index 00000000000..23065ff7876 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: A.java + +import javax.annotation.*; +import javax.annotation.meta.*; + +public class A { + @Nonnull(when=When.UNKNOWN) public String field = null; + + @Nonnull(when=When.MAYBE) + public String foo(@Nonnull(when=When.ALWAYS) String x, @Nonnull(when=When.NEVER) CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } + +} + +// 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 +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.txt new file mode 100644 index 00000000000..25bdaa38663 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.txt @@ -0,0 +1,13 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +public open class A { + public constructor A() + @javax.annotation.Nonnull(when = When.UNKNOWN) public final var field: kotlin.String! + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @javax.annotation.Nonnull(when = When.MAYBE) public open fun foo(/*0*/ @javax.annotation.Nonnull(when = When.ALWAYS) x: kotlin.String, /*1*/ @javax.annotation.Nonnull(when = When.NEVER) y: kotlin.CharSequence!): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt new file mode 100644 index 00000000000..a8c2968b543 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt @@ -0,0 +1,59 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: FieldsAreNullable.java +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.CheckForNull; +import javax.annotation.meta.TypeQualifierDefault; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@CheckForNull +@TypeQualifierDefault({ElementType.FIELD}) +public @interface FieldsAreNullable { +} + +// FILE: A.java + +import javax.annotation.*; + +@FieldsAreNullable +public class A { + public String field = null; + @Nonnull + public String nonNullField = ""; + + public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } +} + +// FILE: main.kt + +fun main(a: A) { + // foo is platform + a.foo("", "", null)?.length + a.foo("", "", null).length + a.foo(null, null, "").length + + a.bar().length + a.bar()!!.length + + a.field?.length + a.field.length + a.field = null + + a.nonNullField?.length + a.nonNullField.length + a.nonNullField = null +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.txt new file mode 100644 index 00000000000..d3b23b584f4 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.txt @@ -0,0 +1,21 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +@FieldsAreNullable public open class A { + public constructor A() + public final var field: kotlin.String! + @javax.annotation.Nonnull public final var nonNullField: kotlin.String + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ q: kotlin.String!, /*1*/ @javax.annotation.Nonnull x: kotlin.String, /*2*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.CheckForNull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.FIELD}) public final annotation class FieldsAreNullable : kotlin.Annotation { + public constructor FieldsAreNullable() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt new file mode 100644 index 00000000000..a35ab08afe4 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt @@ -0,0 +1,159 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: NonNullApi.java + +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.METHOD, ElementType.PARAMETER, ElementType.FIELD}) +public @interface NonNullApi { +} + +// FILE: NullableApi.java + +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.CheckForNull; +import javax.annotation.meta.TypeQualifierDefault; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@CheckForNull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) +public @interface NullableApi { +} + +// FILE: A.java + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import javax.annotation.Nonnull; + +@NonNullApi +public class A { + public String foo1(String x) { return ""; } + public String foo2(String x) { return ""; } + public String foo3(String x) { return ""; } + + + @Nullable + public String bar1(@Nullable String x) { return ""; } + @Nullable + public String bar2(@Nullable String x) { return ""; } + + public String baz(@Nonnull String x) { return ""; } +} + +// FILE: AInt.java + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import javax.annotation.Nonnull; + +@NonNullApi +public interface AInt { + public CharSequence foo1(String x); + public CharSequence foo2(String x); + public CharSequence foo3(String x); + + + @Nullable + public CharSequence bar1(@Nullable String x); + @Nullable + public CharSequence bar2(@Nullable String x); + + public CharSequence baz(@Nonnull String x); +} + + +// FILE: B.java + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import javax.annotation.Nonnull; + +@NullableApi +public class B extends A implements AInt { + // conflicts + public String foo1(String x) { return ""; } + + // no conflicts + @Nonnull + public String foo2(@Nonnull String x) { return ""; } + + // fake override for foo3 shouldn't have any conflicts + + // no conflicts + public String bar1(String x) { return ""; } + + // conflicts + public String baz(String x) { return ""; } +} + +// FILE: C.java + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import javax.annotation.Nonnull; + +@NonNullApi +public class C extends A implements AInt { + // no conflicts + public String foo1(String x) { return ""; } + + // no conflicts + public String foo2(@Nonnull String x) { return ""; } + + // fake override for foo3 shouldn't have any conflicts + + // no conflicts, covariant override + public String bar1(String x) { return ""; } + // no conflicts + @Nullable + public String bar2(@Nullable String x) { return ""; } + + // no conflicts + public String baz(String x) { return ""; } +} + +// FILE: main.kt + +fun main(a: A, b: B, c: C) { + a.foo1(null).length + a.foo2(null).length + a.foo3(null).length + a.bar1(null).length + a.bar2(null).length + a.baz(null).length + + b.foo1(null).length + b.foo1(null)?.length + b.foo2(null).length + b.foo3(null).length + b.bar1(null).length + b.bar2(null).length + b.baz(null).length + b.baz(null)?.length + + c.foo1(null).length + c.foo2(null).length + c.foo3(null).length + c.bar1(null).length + c.bar1(null)?.length + c.bar2(null).length + c.baz(null).length +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.txt new file mode 100644 index 00000000000..c716a65cc45 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.txt @@ -0,0 +1,68 @@ +package + +public fun main(/*0*/ a: A, /*1*/ b: B, /*2*/ c: C): kotlin.Unit + +@NonNullApi public open class A { + public constructor A() + @javax.annotation.Nullable public open fun bar1(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.String? + @javax.annotation.Nullable public open fun bar2(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.String? + public open fun baz(/*0*/ @javax.annotation.Nonnull x: kotlin.String): kotlin.String! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo1(/*0*/ x: kotlin.String!): kotlin.String! + public open fun foo2(/*0*/ x: kotlin.String!): kotlin.String! + public open fun foo3(/*0*/ x: kotlin.String!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@NonNullApi public interface AInt { + @javax.annotation.Nullable public abstract fun bar1(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.CharSequence? + @javax.annotation.Nullable public abstract fun bar2(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.CharSequence? + public abstract fun baz(/*0*/ @javax.annotation.Nonnull x: kotlin.String): kotlin.CharSequence! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo1(/*0*/ x: kotlin.String!): kotlin.CharSequence! + public abstract fun foo2(/*0*/ x: kotlin.String!): kotlin.CharSequence! + public abstract fun foo3(/*0*/ x: kotlin.String!): kotlin.CharSequence! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@NullableApi public open class B : A, AInt { + public constructor B() + public open override /*2*/ fun bar1(/*0*/ x: kotlin.String?): kotlin.String? + @javax.annotation.Nullable public open override /*2*/ /*fake_override*/ fun bar2(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.String? + public open override /*2*/ fun baz(/*0*/ x: kotlin.String): kotlin.String! + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ fun foo1(/*0*/ x: kotlin.String!): kotlin.String! + @javax.annotation.Nonnull public open override /*2*/ fun foo2(/*0*/ @javax.annotation.Nonnull x: kotlin.String): kotlin.String + public open override /*2*/ /*fake_override*/ fun foo3(/*0*/ x: kotlin.String!): kotlin.String! + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +@NonNullApi public open class C : A, AInt { + public constructor C() + public open override /*2*/ fun bar1(/*0*/ x: kotlin.String?): kotlin.String? + @javax.annotation.Nullable public open override /*2*/ fun bar2(/*0*/ @javax.annotation.Nullable x: kotlin.String?): kotlin.String? + public open override /*2*/ fun baz(/*0*/ x: kotlin.String): kotlin.String! + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ fun foo1(/*0*/ x: kotlin.String!): kotlin.String! + public open override /*2*/ fun foo2(/*0*/ @javax.annotation.Nonnull x: kotlin.String): kotlin.String! + public open override /*2*/ /*fake_override*/ fun foo3(/*0*/ x: kotlin.String!): kotlin.String! + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.FILE}) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.Nonnull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) public final annotation class NonNullApi : kotlin.Annotation { + public constructor NonNullApi() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.FILE}) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.CheckForNull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) public final annotation class NullableApi : kotlin.Annotation { + public constructor NullableApi() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt new file mode 100644 index 00000000000..2ffba618cda --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt @@ -0,0 +1,185 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: NonNullApi.java + +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; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Nonnull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) +public @interface NonNullApi { +} + +// FILE: NullableApi.java + +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.CheckForNull; +import javax.annotation.meta.TypeQualifierDefault; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@CheckForNull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) +public @interface NullableApi { +} + +// FILE: FieldsAreNullable.java +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.CheckForNull; +import javax.annotation.meta.TypeQualifierDefault; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@CheckForNull +@TypeQualifierDefault({ElementType.FIELD}) +public @interface FieldsAreNullable { +} + +// FILE: A.java + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import javax.annotation.Nonnull; + +@NonNullApi +public class A { + public String field = null; + + public String foo(String x, @CheckForNull CharSequence y) { + return ""; + } + + @NullableApi + public String foobar(String x, @Nonnull CharSequence y) { + return ""; + } + + public String bar() { + return ""; + } + + @Nullable + public java.util.List baz() { + return null; + } + + @NullableApi + public class B { + public String field = null; + + public String foo(String x, @Nonnull CharSequence y) { + return ""; + } + + @NonNullApi + public String foobar(String x, @Nullable CharSequence y) { + return ""; + } + + public String bar() { + return ""; + } + + @Nullable + public java.util.List baz() { + return null; + } + } + + @FieldsAreNullable + public class C { + public String field = null; + + public String foo(String x, @Nullable CharSequence y) { + return ""; + } + + @NullableApi + public String foobar(String x, @Nullable CharSequence y) { + return ""; + } + + public String bar() { + return ""; + } + + @Nullable + public java.util.List baz() { + return null; + } + } +} + +// FILE: main.kt + +fun main(a: A, b: A.B, c: A.C) { + a.foo("", null)?.length + a.foo("", null).length + a.foo(null, "").length + + a.foobar(null, "").length + a.foobar("", null)?.length + + a.bar().length + a.bar()!!.length + + a.field?.length + a.field.length + + a.baz().get(0) + a.baz()!!.get(0).get(0) + a.baz()!!.get(0)?.get(0) + + // b + b.foo("", null)?.length + b.foo("", null).length + b.foo(null, "").length + + b.foobar(null, "").length + b.foobar("", null)?.length + + b.bar().length + b.bar()!!.length + + b.field?.length + b.field.length + + b.baz().get(0) + b.baz()!!.get(0).get(0) + b.baz()!!.get(0)?.get(0) + + // c + c.foo("", null)?.length + c.foo("", null).length + c.foo(null, "").length + + c.foobar(null, "").length + c.foobar("", null)?.length + + c.bar().length + c.bar()!!.length + + c.field?.length + c.field.length + + c.baz().get(0) + c.baz()!!.get(0).get(0) + c.baz()!!.get(0)?.get(0) +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.txt new file mode 100644 index 00000000000..c126a698511 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.txt @@ -0,0 +1,60 @@ +package + +public fun main(/*0*/ a: A, /*1*/ b: A.B, /*2*/ c: A.C): kotlin.Unit + +@NonNullApi public open class A { + public constructor A() + public final var field: kotlin.String! + public open fun bar(): kotlin.String! + @javax.annotation.Nullable public open fun baz(): kotlin.collections.(Mutable)List? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String! + @NullableApi public open fun foobar(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.Nonnull y: kotlin.CharSequence): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + @NullableApi public open inner class B { + public constructor B() + public final var field: kotlin.String! + public open fun bar(): kotlin.String! + @javax.annotation.Nullable public open fun baz(): kotlin.collections.(Mutable)List? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.Nonnull y: kotlin.CharSequence): kotlin.String! + @NonNullApi public open fun foobar(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.Nullable y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + @FieldsAreNullable public open inner class C { + public constructor C() + public final var field: kotlin.String! + public open fun bar(): kotlin.String! + @javax.annotation.Nullable public open fun baz(): kotlin.collections.(Mutable)List? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.Nullable y: kotlin.CharSequence?): kotlin.String! + @NullableApi public open fun foobar(/*0*/ x: kotlin.String!, /*1*/ @javax.annotation.Nullable y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +@kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.CheckForNull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.FIELD}) public final annotation class FieldsAreNullable : kotlin.Annotation { + public constructor FieldsAreNullable() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.Nonnull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) public final annotation class NonNullApi : kotlin.Annotation { + public constructor NonNullApi() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.CheckForNull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) public final annotation class NullableApi : kotlin.Annotation { + public constructor NullableApi() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt new file mode 100644 index 00000000000..759c1c721ce --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: A.java + +import javax.annotation.*; + +@ParametersAreNonnullByDefault +public class A { + @Nullable public String field = null; + + public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } +} + +// FILE: main.kt + +fun main(a: A) { + // foo is platform + a.foo("", "", null)?.length + a.foo("", "", null).length + a.foo(null, null, "").length + + a.bar().length + a.bar()!!.length + + a.field?.length + a.field.length +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.txt new file mode 100644 index 00000000000..35cc6bf1c4f --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.txt @@ -0,0 +1,13 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +@javax.annotation.ParametersAreNonnullByDefault public open class A { + public constructor A() + @javax.annotation.Nullable public final var field: kotlin.String? + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ q: kotlin.String!, /*1*/ @javax.annotation.Nonnull x: kotlin.String, /*2*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt new file mode 100644 index 00000000000..1febc29c7ca --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt @@ -0,0 +1,74 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// RENDER_PACKAGE: test +// RENDER_PACKAGE: test2 +// WARNING_FOR_JSR305_ANNOTATIONS + +// FILE: test/package-info.java + +@javax.annotation.ParametersAreNonnullByDefault() +package test; + +// FILE: test/A.java + +package test; + +import javax.annotation.*; + +public class A { + @Nullable public String field = null; + + public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } +} + +// FILE: test2/A2.java + +package test2; + +import javax.annotation.*; + +public class A2 { + @Nullable public String field = null; + + public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } +} + +// FILE: main.kt + +import test.A +import test2.A2 + +fun main(a: A, a2: A2) { + a.foo("", "", null)?.length + a.foo("", "", null).length + a.foo(null, null, "").length + + a.bar().length + a.bar()!!.length + + a.field?.length + a.field.length + + a2.foo("", "", null)?.length + a2.foo("", "", null).length + a2.foo(null, null, "").length + + a2.bar().length + a2.bar()!!.length + + a2.field?.length + a2.field.length +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.txt new file mode 100644 index 00000000000..0b3f977be5e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.txt @@ -0,0 +1,27 @@ +package test + +public open class A { + public constructor A() + @javax.annotation.Nullable public final var field: kotlin.String? + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ q: kotlin.String!, /*1*/ @javax.annotation.Nonnull x: kotlin.String, /*2*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +package test2 + +public open class A2 { + public constructor A2() + @javax.annotation.Nullable public final var field: kotlin.String? + @javax.annotation.Nonnull public open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ q: kotlin.String!, /*1*/ @javax.annotation.Nonnull x: kotlin.String, /*2*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +package + +public fun main(/*0*/ a: test.A, /*1*/ a2: test2.A2): kotlin.Unit diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt new file mode 100644 index 00000000000..15b11bd142e --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt @@ -0,0 +1,83 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WARNING_FOR_JSR305_ANNOTATIONS + +// 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.METHOD, ElementType.PARAMETER}) +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 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().get(0) + a.baz()!!.get(0).get(0) + a.baz()!!.get(0)?.get(0) +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.txt new file mode 100644 index 00000000000..1bd2b3b06b7 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.txt @@ -0,0 +1,14 @@ +package + +public fun main(/*0*/ a: A): kotlin.Unit + +@spr.NonNullApi public open class A { + public constructor A() + public final var field: kotlin.String! + public open fun bar(): kotlin.String! + @spr.Nullable public open fun baz(): kotlin.collections.(Mutable)List! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ x: kotlin.String!, /*1*/ @spr.Nullable y: kotlin.CharSequence!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt new file mode 100644 index 00000000000..15e8b11ee82 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt @@ -0,0 +1,90 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// RENDER_PACKAGE: test +// WARNING_FOR_JSR305_ANNOTATIONS + +// 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.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Nonnull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) +public @interface NonNullApi { +} + +// FILE: test/package-info.java + +@spr.NonNullApi() +package test; + +// FILE: test/A.java + +package test; + +import spr.*; + +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 baz() { + return null; + } +} + +// FILE: main.kt + +fun main(a: test.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().get(0) + a.baz()!!.get(0).get(0) + a.baz()!!.get(0)?.get(0) +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.txt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.txt new file mode 100644 index 00000000000..4b24cd33f76 --- /dev/null +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.txt @@ -0,0 +1,16 @@ +package test + +public open class A { + public constructor A() + public final var field: kotlin.String! + public open fun bar(): kotlin.String! + @spr.Nullable public open fun baz(): kotlin.collections.(Mutable)List! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ x: kotlin.String!, /*1*/ @spr.Nullable y: kotlin.CharSequence!): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +package + +public fun main(/*0*/ a: test.A): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathTestGenerated.java index c144ccf6a78..bb97586a289 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathTestGenerated.java @@ -90,6 +90,219 @@ public class ForeignAnnotationsNoAnnotationInClasspathTestGenerated extends Abst doTest(fileName); } + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jsr305NullabilityWarnings extends AbstractForeignAnnotationsNoAnnotationInClasspathTest { + public void testAllFilesPresentInJsr305NullabilityWarnings() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jsr305NullabilityGenerics.kt") + public void testJsr305NullabilityGenerics() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305NullabilityNicknames.kt") + public void testJsr305NullabilityNicknames() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Simple.kt") + public void testJsr305Simple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Strange.kt") + public void testJsr305Strange() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FromPlatformTypes extends AbstractForeignAnnotationsNoAnnotationInClasspathTest { + public void testAllFilesPresentInFromPlatformTypes() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("arithmetic.kt") + public void testArithmetic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt"); + doTest(fileName); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt"); + doTest(fileName); + } + + @TestMetadata("assignToVar.kt") + public void testAssignToVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt"); + doTest(fileName); + } + + @TestMetadata("conditions.kt") + public void testConditions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt"); + doTest(fileName); + } + + @TestMetadata("dataFlowInfo.kt") + public void testDataFlowInfo() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt"); + doTest(fileName); + } + + @TestMetadata("defaultParameters.kt") + public void testDefaultParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt"); + doTest(fileName); + } + + @TestMetadata("delegatedProperties.kt") + public void testDelegatedProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt"); + doTest(fileName); + } + + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceExtension.kt") + public void testDerefenceExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceMember.kt") + public void testDerefenceMember() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt"); + doTest(fileName); + } + + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt"); + doTest(fileName); + } + + @TestMetadata("for.kt") + public void testFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt"); + doTest(fileName); + } + + @TestMetadata("functionArguments.kt") + public void testFunctionArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt"); + doTest(fileName); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt"); + doTest(fileName); + } + + @TestMetadata("kt6829.kt") + public void testKt6829() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt"); + doTest(fileName); + } + + @TestMetadata("multiDeclaration.kt") + public void testMultiDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt"); + doTest(fileName); + } + + @TestMetadata("passToJava.kt") + public void testPassToJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveArray.kt") + public void testPrimitiveArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt"); + doTest(fileName); + } + + @TestMetadata("throw.kt") + public void testThrow() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt"); + doTest(fileName); + } + + @TestMetadata("uselessElvisRightIsNull.kt") + public void testUselessElvisRightIsNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeQualifierDefault extends AbstractForeignAnnotationsNoAnnotationInClasspathTest { + public void testAllFilesPresentInTypeQualifierDefault() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("fieldsAreNullable.kt") + public void testFieldsAreNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt"); + doTest(fileName); + } + + @TestMetadata("nullabilityFromOverridden.kt") + public void testNullabilityFromOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt"); + doTest(fileName); + } + + @TestMetadata("overridingDefaultQualifier.kt") + public void testOverridingDefaultQualifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefault.kt") + public void testParametersAreNonnullByDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefaultPackage.kt") + public void testParametersAreNonnullByDefaultPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt"); + doTest(fileName); + } + + @TestMetadata("springNullable.kt") + public void testSpringNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt"); + doTest(fileName); + } + + @TestMetadata("springNullablePackage.kt") + public void testSpringNullablePackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt"); + doTest(fileName); + } + } + } + @TestMetadata("compiler/testData/foreignAnnotations/tests/typeQualifierDefault") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGenerated.java index 8318e2ac838..e6ba4337564 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGenerated.java @@ -90,6 +90,219 @@ public class ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGe doTest(fileName); } + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jsr305NullabilityWarnings extends AbstractForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTest { + public void testAllFilesPresentInJsr305NullabilityWarnings() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jsr305NullabilityGenerics.kt") + public void testJsr305NullabilityGenerics() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305NullabilityNicknames.kt") + public void testJsr305NullabilityNicknames() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Simple.kt") + public void testJsr305Simple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Strange.kt") + public void testJsr305Strange() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FromPlatformTypes extends AbstractForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTest { + public void testAllFilesPresentInFromPlatformTypes() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("arithmetic.kt") + public void testArithmetic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt"); + doTest(fileName); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt"); + doTest(fileName); + } + + @TestMetadata("assignToVar.kt") + public void testAssignToVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt"); + doTest(fileName); + } + + @TestMetadata("conditions.kt") + public void testConditions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt"); + doTest(fileName); + } + + @TestMetadata("dataFlowInfo.kt") + public void testDataFlowInfo() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt"); + doTest(fileName); + } + + @TestMetadata("defaultParameters.kt") + public void testDefaultParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt"); + doTest(fileName); + } + + @TestMetadata("delegatedProperties.kt") + public void testDelegatedProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt"); + doTest(fileName); + } + + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceExtension.kt") + public void testDerefenceExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceMember.kt") + public void testDerefenceMember() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt"); + doTest(fileName); + } + + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt"); + doTest(fileName); + } + + @TestMetadata("for.kt") + public void testFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt"); + doTest(fileName); + } + + @TestMetadata("functionArguments.kt") + public void testFunctionArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt"); + doTest(fileName); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt"); + doTest(fileName); + } + + @TestMetadata("kt6829.kt") + public void testKt6829() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt"); + doTest(fileName); + } + + @TestMetadata("multiDeclaration.kt") + public void testMultiDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt"); + doTest(fileName); + } + + @TestMetadata("passToJava.kt") + public void testPassToJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveArray.kt") + public void testPrimitiveArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt"); + doTest(fileName); + } + + @TestMetadata("throw.kt") + public void testThrow() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt"); + doTest(fileName); + } + + @TestMetadata("uselessElvisRightIsNull.kt") + public void testUselessElvisRightIsNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeQualifierDefault extends AbstractForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTest { + public void testAllFilesPresentInTypeQualifierDefault() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("fieldsAreNullable.kt") + public void testFieldsAreNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt"); + doTest(fileName); + } + + @TestMetadata("nullabilityFromOverridden.kt") + public void testNullabilityFromOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt"); + doTest(fileName); + } + + @TestMetadata("overridingDefaultQualifier.kt") + public void testOverridingDefaultQualifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefault.kt") + public void testParametersAreNonnullByDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefaultPackage.kt") + public void testParametersAreNonnullByDefaultPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt"); + doTest(fileName); + } + + @TestMetadata("springNullable.kt") + public void testSpringNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt"); + doTest(fileName); + } + + @TestMetadata("springNullablePackage.kt") + public void testSpringNullablePackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt"); + doTest(fileName); + } + } + } + @TestMetadata("compiler/testData/foreignAnnotations/tests/typeQualifierDefault") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java index a4f8c0a06c6..1b4c099e395 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java @@ -90,6 +90,219 @@ public class ForeignAnnotationsTestGenerated extends AbstractForeignAnnotationsT doTest(fileName); } + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jsr305NullabilityWarnings extends AbstractForeignAnnotationsTest { + public void testAllFilesPresentInJsr305NullabilityWarnings() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jsr305NullabilityGenerics.kt") + public void testJsr305NullabilityGenerics() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityGenerics.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305NullabilityNicknames.kt") + public void testJsr305NullabilityNicknames() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305NullabilityNicknames.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Simple.kt") + public void testJsr305Simple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Simple.kt"); + doTest(fileName); + } + + @TestMetadata("jsr305Strange.kt") + public void testJsr305Strange() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/jsr305Strange.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FromPlatformTypes extends AbstractForeignAnnotationsTest { + public void testAllFilesPresentInFromPlatformTypes() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("arithmetic.kt") + public void testArithmetic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/arithmetic.kt"); + doTest(fileName); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/array.kt"); + doTest(fileName); + } + + @TestMetadata("assignToVar.kt") + public void testAssignToVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/assignToVar.kt"); + doTest(fileName); + } + + @TestMetadata("conditions.kt") + public void testConditions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/conditions.kt"); + doTest(fileName); + } + + @TestMetadata("dataFlowInfo.kt") + public void testDataFlowInfo() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/dataFlowInfo.kt"); + doTest(fileName); + } + + @TestMetadata("defaultParameters.kt") + public void testDefaultParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/defaultParameters.kt"); + doTest(fileName); + } + + @TestMetadata("delegatedProperties.kt") + public void testDelegatedProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegatedProperties.kt"); + doTest(fileName); + } + + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/delegation.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceExtension.kt") + public void testDerefenceExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceExtension.kt"); + doTest(fileName); + } + + @TestMetadata("derefenceMember.kt") + public void testDerefenceMember() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/derefenceMember.kt"); + doTest(fileName); + } + + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/expectedType.kt"); + doTest(fileName); + } + + @TestMetadata("for.kt") + public void testFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/for.kt"); + doTest(fileName); + } + + @TestMetadata("functionArguments.kt") + public void testFunctionArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/functionArguments.kt"); + doTest(fileName); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/invoke.kt"); + doTest(fileName); + } + + @TestMetadata("kt6829.kt") + public void testKt6829() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/kt6829.kt"); + doTest(fileName); + } + + @TestMetadata("multiDeclaration.kt") + public void testMultiDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/multiDeclaration.kt"); + doTest(fileName); + } + + @TestMetadata("passToJava.kt") + public void testPassToJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/passToJava.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveArray.kt") + public void testPrimitiveArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/primitiveArray.kt"); + doTest(fileName); + } + + @TestMetadata("throw.kt") + public void testThrow() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/throw.kt"); + doTest(fileName); + } + + @TestMetadata("uselessElvisRightIsNull.kt") + public void testUselessElvisRightIsNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/fromPlatformTypes/uselessElvisRightIsNull.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeQualifierDefault extends AbstractForeignAnnotationsTest { + public void testAllFilesPresentInTypeQualifierDefault() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("fieldsAreNullable.kt") + public void testFieldsAreNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt"); + doTest(fileName); + } + + @TestMetadata("nullabilityFromOverridden.kt") + public void testNullabilityFromOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt"); + doTest(fileName); + } + + @TestMetadata("overridingDefaultQualifier.kt") + public void testOverridingDefaultQualifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefault.kt") + public void testParametersAreNonnullByDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefault.kt"); + doTest(fileName); + } + + @TestMetadata("parametersAreNonnullByDefaultPackage.kt") + public void testParametersAreNonnullByDefaultPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/parametersAreNonnullByDefaultPackage.kt"); + doTest(fileName); + } + + @TestMetadata("springNullable.kt") + public void testSpringNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullable.kt"); + doTest(fileName); + } + + @TestMetadata("springNullablePackage.kt") + public void testSpringNullablePackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/typeQualifierDefault/springNullablePackage.kt"); + doTest(fileName); + } + } + } + @TestMetadata("compiler/testData/foreignAnnotations/tests/typeQualifierDefault") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)