diff --git a/compiler/java8-tests/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java b/compiler/java8-tests/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java new file mode 100644 index 0000000000000000000000000000000000000000..3348e7edc365e6feb73f9d016e25c60288f104e7 --- /dev/null +++ b/compiler/java8-tests/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.checkers; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/foreignAnnotationsJava8/tests") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class ForeignJava8AnnotationsTestGenerated extends AbstractForeignJava8AnnotationsTest { + public void testAllFilesPresentInTests() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("checkerFramework.kt") + public void testCheckerFramework() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.kt"); + doTest(fileName); + } + + @TestMetadata("eclipse.kt") + public void testEclipse() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotationsJava8/tests/eclipse.kt"); + doTest(fileName); + } +} diff --git a/compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/NonNull.java b/compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/NonNull.java similarity index 88% rename from compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/NonNull.java rename to compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/NonNull.java index f25979be369f64ee93d07ee44e058a0ca435d489..bfc7aeb5fb2d999b6dc1d7ec9315500688d97956 100644 --- a/compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/NonNull.java +++ b/compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/NonNull.java @@ -35,7 +35,6 @@ import java.lang.annotation.Target; */ @Documented @Retention(RetentionPolicy.RUNTIME) -// TODO: originally it's target was: TYPE_USE, TYPE_PARAMETER -@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE }) +@Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) public @interface NonNull { } \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/Nullable.java b/compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/Nullable.java similarity index 82% rename from compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/Nullable.java rename to compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/Nullable.java index b60746d8f99474a8e62e40946a63cb9016de3df5..8eab1a1139664ef68171813edb239d02624950ba 100644 --- a/compiler/testData/foreignAnnotations/annotations/org/checkerframework/checker/nullness/qual/Nullable.java +++ b/compiler/testData/foreignAnnotationsJava8/annotations/org/checkerframework/checker/nullness/qual/Nullable.java @@ -22,7 +22,6 @@ import java.lang.annotation.Target; */ @Documented @Retention(RetentionPolicy.RUNTIME) -// TODO: originally it's target was: TYPE_USE, TYPE_PARAMETER -@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE }) +@Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) public @interface Nullable { } \ No newline at end of file diff --git a/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/NonNull.java b/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/NonNull.java new file mode 100644 index 0000000000000000000000000000000000000000..7722bf89c6fb26ec0267ad982060a6588226ddfa --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/NonNull.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Stephan Herrmann and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * IBM Corporation - bug fixes + *******************************************************************************/ +package org.eclipse.jdt.annotation; + +import static java.lang.annotation.ElementType.TYPE_USE; + +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; + +/** + * Qualifier for a reference type in a {@link ElementType#TYPE_USE TYPE_USE} position: + * The type that has this annotation is intended to not include the value null. + *

+ * If annotation based null analysis is enabled using this annotation has two consequences: + *

+ *
    + *
  1. Dereferencing an expression of this type is safe, i.e., no NullPointerException can occur at runtime.
  2. + *
  3. An attempt to bind a null value to an entity (field, local variable, method parameter or method return value) + * of this type is a compile time error.
  4. + *
+ * For the second case, diagnostics issued by the compiler should distinguish three situations: + *
    + *
  1. Nullness of the value can be statically determined, the entity is definitely bound from either of: + *
  2. + *
  3. Nullness cannot definitely be determined, because different code branches yield different results.
  4. + *
  5. Nullness cannot be determined, because other program elements are involved for which + * null annotations are lacking.
  6. + *
+ *

+ * Note: Since org.eclipse.jdt.annotation 2.0.0, the + * @Target is {TYPE_USE}. For the old API, see + * + * @NonNull in 1.1.0. + *

+ * @since 1.0 + */ +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ TYPE_USE }) +public @interface NonNull { + // marker annotation with no members +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/Nullable.java b/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/Nullable.java new file mode 100644 index 0000000000000000000000000000000000000000..70e479f349e99c8d5449f7d869ea156f90d9eb44 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/annotations/org/eclipse/jdt/annotation/Nullable.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Stephan Herrmann and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * IBM Corporation - bug fixes + *******************************************************************************/ +package org.eclipse.jdt.annotation; + +import static java.lang.annotation.ElementType.TYPE_USE; + +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; + +/** + * Qualifier for a reference type in a {@link ElementType#TYPE_USE TYPE_USE} position: + * The type that has this annotation explicitly includes the value null. + *

+ * If annotation based null analysis is enabled using this annotation has two consequences: + *

+ *
    + *
  1. Binding a null value to an entity (field, local variable, method parameter or method return value) + * of this type is legal.
  2. + *
  3. Dereferencing an expression of this type is unsafe, i.e., a NullPointerException can occur at runtime.
  4. + *
+ *

+ * Note: Since org.eclipse.jdt.annotation 2.0.0, the + * @Target is {TYPE_USE}. For the old API, see + * + * @Nullable in 1.1.0. + *

+ * @since 1.0 + */ +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ TYPE_USE }) +public @interface Nullable { + // marker annotation with no members +} \ No newline at end of file diff --git a/compiler/testData/foreignAnnotations/tests/checkerFramework.kt b/compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.kt similarity index 100% rename from compiler/testData/foreignAnnotations/tests/checkerFramework.kt rename to compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.kt diff --git a/compiler/testData/foreignAnnotations/tests/checkerFramework.txt b/compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.txt similarity index 100% rename from compiler/testData/foreignAnnotations/tests/checkerFramework.txt rename to compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.txt diff --git a/compiler/testData/foreignAnnotationsJava8/tests/eclipse.kt b/compiler/testData/foreignAnnotationsJava8/tests/eclipse.kt new file mode 100644 index 0000000000000000000000000000000000000000..86c6c7bae3395b45fb898a07d8d1875d64fe154c --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/eclipse.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// FILE: A.java + +import org.eclipse.jdt.annotation.*; + +public class A { + @Nullable public String field = null; + + @Nullable + public String foo(@NonNull String x, @Nullable CharSequence y) { + return ""; + } + + @NonNull + public String bar() { + return ""; + } + + @Nullable + public T baz(@NonNull T x) { return x; } +} + +// FILE: main.kt + +fun main(a: A, a1: 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("").length + a.baz("")?.length + a.baz(null).length + + a1.baz("")!!.length + a1.baz(null)!!.length +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/eclipse.txt b/compiler/testData/foreignAnnotationsJava8/tests/eclipse.txt new file mode 100644 index 0000000000000000000000000000000000000000..99fe9e5cd5a1436d27f1bfe6d9cdff10b815309e --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/eclipse.txt @@ -0,0 +1,14 @@ +package + +public fun main(/*0*/ a: A, /*1*/ a1: A): kotlin.Unit + +public open class A { + public constructor A() + @org.eclipse.jdt.annotation.Nullable() public final var field: kotlin.String? + @org.eclipse.jdt.annotation.NonNull() public open fun bar(): kotlin.String + @org.eclipse.jdt.annotation.Nullable() public open fun baz(/*0*/ @org.eclipse.jdt.annotation.NonNull() x: T): T? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @org.eclipse.jdt.annotation.Nullable() public open fun foo(/*0*/ @org.eclipse.jdt.annotation.NonNull() x: kotlin.String, /*1*/ @org.eclipse.jdt.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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsTest.kt b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsTest.kt index 941fa2a583289867c34cded8d54e586478b9c82a..46050fb6890bb6f1ca656d9229793b83497baada 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsTest.kt @@ -22,8 +22,11 @@ import java.io.File abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() { override fun getExtraClasspath(): List { return listOf(MockLibraryUtil.compileLibraryToJar( - "compiler/testData/foreignAnnotations/annotations", + annotationsPath, "foreign-annotations", /* addSources = */false, /* allowKotlinPackage = */ false )) } + + open protected val annotationsPath: String + get() = "compiler/testData/foreignAnnotations/annotations" } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignJava8AnnotationsTest.kt b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignJava8AnnotationsTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..5cd516a0f3979d3895f5f0a8ed52fddcf23d5dda --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractForeignJava8AnnotationsTest.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.checkers + +abstract class AbstractForeignJava8AnnotationsTest : AbstractForeignAnnotationsTest() { + override val annotationsPath: String + get() = "compiler/testData/foreignAnnotationsJava8/annotations" +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java index a1f7b046101a0284347021da2119f11c87e42150..7f7fb9cd53e8b2c33b1afa40a38b456885c9a8a8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsTestGenerated.java @@ -47,12 +47,6 @@ public class ForeignAnnotationsTestGenerated extends AbstractForeignAnnotationsT doTest(fileName); } - @TestMetadata("checkerFramework.kt") - public void testCheckerFramework() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/checkerFramework.kt"); - doTest(fileName); - } - @TestMetadata("eclipse.kt") public void testEclipse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/eclipse.kt"); diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 4e950891dcc6596877eac2f07004fb0976646c64..9a8cd5f5c7d9eb02880485d839a91eb387df9343 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -343,6 +343,9 @@ fun main(args: Array) { testClass("DiagnosticsWithJava8TestGenerated") { model("diagnostics/testsWithJava8") } + testClass() { + model("foreignAnnotationsJava8/tests") + } }