diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.fir.txt b/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.fir.txt new file mode 100644 index 00000000000..27c1034a9f1 --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.fir.txt @@ -0,0 +1,10 @@ +@R|java/lang/annotation/Documented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(#()) @R|java/lang/annotation/Retention|(#()) public abstract annotation class MyNullable : R|java/lang/annotation/Annotation| { +} +public open class NonNullNever : R|java/lang/Object| { + @R|javax/annotation/Nonnull|(#()) public open property field(var): R|ft| + public get(): R|ft| + public set(value: R|ft|): kotlin/Unit + + @R|MyNullable|() public open operator function foo(@R|javax/annotation/Nonnull|(#()) x: R|ft|, @R|MyNullable|() y: R|ft|): R|ft| + +} diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.java b/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.java new file mode 100644 index 00000000000..2626e9abbac --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.java @@ -0,0 +1,33 @@ +// FOREIGN_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.NEVER) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNullable { + +} + +// FILE: NonNullNever.java + +import javax.annotation.*; + import javax.annotation.meta.When; + +public class NonNullNever { + @Nonnull(when = When.NEVER) public String field = null; + + @MyNullable + public String foo(@Nonnull(when = When.NEVER) String x, @MyNullable CharSequence y) { + return ""; + } +} diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/Simple.fir.txt b/compiler/fir/resolve/testData/enhancement/jsr305/Simple.fir.txt new file mode 100644 index 00000000000..af3b5ea1d8b --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/Simple.fir.txt @@ -0,0 +1,10 @@ +public open class Simple : R|java/lang/Object| { + @R|javax/annotation/Nullable|() public open property field(var): R|ft|? + public get(): R|ft|? + public set(value: R|ft|?): kotlin/Unit + + @R|javax/annotation/Nullable|() public open operator function foo(@R|javax/annotation/Nonnull|() x: R|ft|, @R|javax/annotation/CheckForNull|() y: R|ft|?): R|ft|? + + @R|javax/annotation/Nonnull|() public open operator function bar(): R|ft| + +} diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/Simple.java b/compiler/fir/resolve/testData/enhancement/jsr305/Simple.java new file mode 100644 index 00000000000..1c84adcac7a --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/Simple.java @@ -0,0 +1,17 @@ +// FOREIGN_ANNOTATIONS +import javax.annotation.*; + +public class Simple { + @Nullable public String field = null; + + @Nullable + public String foo(@Nonnull String x, @CheckForNull CharSequence y) { + return ""; + } + + @Nonnull + public String bar() { + return ""; + } + +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/Strange.fir.txt b/compiler/fir/resolve/testData/enhancement/jsr305/Strange.fir.txt new file mode 100644 index 00000000000..7a9d5106f22 --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/Strange.fir.txt @@ -0,0 +1,10 @@ +public open class Strange : R|java/lang/Object| { + @R|javax/annotation/Nonnull|(#()) public open property field(var): R|ft| + public get(): R|ft| + public set(value: R|ft|): kotlin/Unit + + @R|javax/annotation/Nonnull|(#()) public open operator function foo(@R|javax/annotation/Nonnull|(#()) x: R|ft|, @R|javax/annotation/Nonnull|(#()) y: R|ft|): R|ft| + + @R|javax/annotation/Nonnull|() public open operator function bar(): R|ft| + +} diff --git a/compiler/fir/resolve/testData/enhancement/jsr305/Strange.java b/compiler/fir/resolve/testData/enhancement/jsr305/Strange.java new file mode 100644 index 00000000000..60eb84b1983 --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/jsr305/Strange.java @@ -0,0 +1,18 @@ +// FOREIGN_ANNOTATIONS +import javax.annotation.*; +import javax.annotation.meta.*; + +public class Strange { + @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 ""; + } + +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/enhancement/note.txt b/compiler/fir/resolve/testData/enhancement/note.txt index fb7bced66ab..13a9f30bf4d 100644 --- a/compiler/fir/resolve/testData/enhancement/note.txt +++ b/compiler/fir/resolve/testData/enhancement/note.txt @@ -1 +1 @@ -FIR enhancement tests use compiler/testData/loadJava/compilerJava \ No newline at end of file +Most FIR enhancement tests use compiler/testData/loadJava/compilerJava \ No newline at end of file diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/AbstractFirTypeEnhancementTest.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/AbstractFirTypeEnhancementTest.kt index 385ce38d369..46fdab53960 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/AbstractFirTypeEnhancementTest.kt +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/AbstractFirTypeEnhancementTest.kt @@ -236,3 +236,5 @@ abstract class AbstractFirTypeEnhancementTest : KtUsefulTestCase() { private const val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/annotations" } } + +abstract class AbstractOwnFirTypeEnhancementTest : AbstractFirTypeEnhancementTest() \ No newline at end of file diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java new file mode 100644 index 00000000000..fa74832b781 --- /dev/null +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java @@ -0,0 +1,59 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.java; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +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/fir/resolve/testData/enhancement") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class OwnFirTypeEnhancementTestGenerated extends AbstractOwnFirTypeEnhancementTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInEnhancement() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/enhancement"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/fir/resolve/testData/enhancement/jsr305") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jsr305 extends AbstractOwnFirTypeEnhancementTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInJsr305() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/enhancement/jsr305"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true); + } + + @TestMetadata("NonNullNever.java") + public void testNonNullNever() throws Exception { + runTest("compiler/fir/resolve/testData/enhancement/jsr305/NonNullNever.java"); + } + + @TestMetadata("Simple.java") + public void testSimple() throws Exception { + runTest("compiler/fir/resolve/testData/enhancement/jsr305/Simple.java"); + } + + @TestMetadata("Strange.java") + public void testStrange() throws Exception { + runTest("compiler/fir/resolve/testData/enhancement/jsr305/Strange.java"); + } + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index 30cc8289b58..2ed177e31bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.AbstractFirResolveTestCase import org.jetbrains.kotlin.fir.AbstractFirResolveTestCaseWithStdlib import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase import org.jetbrains.kotlin.fir.java.AbstractFirTypeEnhancementTest +import org.jetbrains.kotlin.fir.java.AbstractOwnFirTypeEnhancementTest import org.jetbrains.kotlin.generators.tests.generator.testGroup import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME @@ -403,4 +404,11 @@ fun main(args: Array) { model("loadJava/compiledJava", extension = "java") } } + + testGroup("compiler/fir/resolve/tests", "compiler/fir/resolve/testData") { + testClass { + model("enhancement", extension = "java") + } + } + }