diff --git a/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java b/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java new file mode 100644 index 00000000000..ea007b6b68c --- /dev/null +++ b/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java @@ -0,0 +1,61 @@ +/* + * 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.jvm.compiler; + +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") +@RunWith(JUnit3RunnerWithInners.class) +public class LoadJava8TestGenerated extends AbstractLoadJava8Test { + @TestMetadata("compiler/testData/loadJava8/compiledJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CompiledJava extends AbstractLoadJava8Test { + public void testAllFilesPresentInCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), true); + } + + @TestMetadata("TypeAnnotations.java") + public void testTypeAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/TypeAnnotations.java"); + doTestCompiledJava(fileName); + } + } + + @TestMetadata("compiler/testData/loadJava8/sourceJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SourceJava extends AbstractLoadJava8Test { + public void testAllFilesPresentInSourceJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/sourceJava"), Pattern.compile("^(.+)\\.java$"), true); + } + + @TestMetadata("TypeAnnotations.java") + public void testTypeAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/sourceJava/TypeAnnotations.java"); + doTestSourceJava(fileName); + } + } +} diff --git a/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java b/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java new file mode 100644 index 00000000000..4dc5b9bf637 --- /dev/null +++ b/compiler/java8-tests/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java @@ -0,0 +1,43 @@ +/* + * 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.jvm.runtime; + +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/loadJava8/compiledJava") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8RuntimeDescriptorLoaderTest { + public void testAllFilesPresentInCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), true, "sam", "kotlinSignature/propagation"); + } + + @TestMetadata("TypeAnnotations.java") + public void testTypeAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/TypeAnnotations.java"); + doTest(fileName); + } +} diff --git a/compiler/testData/loadJava/sourceJava/TypeAnnotations.java b/compiler/testData/loadJava/sourceJava/TypeAnnotations.java deleted file mode 100644 index 30516b4fbb9..00000000000 --- a/compiler/testData/loadJava/sourceJava/TypeAnnotations.java +++ /dev/null @@ -1,16 +0,0 @@ -package test; - -import java.lang.annotation.*; - -@Target(ElementType.TYPE_USE) -@interface A { - String value() default ""; -} - -interface G {} -interface G2 {} - -public interface TypeAnnotations { - void f(G<@A String> p); - void f(G2<@A String, @A Integer> p); -} \ No newline at end of file diff --git a/compiler/testData/loadJava/sourceJava/TypeAnnotations.txt b/compiler/testData/loadJava/sourceJava/TypeAnnotations.txt deleted file mode 100644 index dd3aecf930a..00000000000 --- a/compiler/testData/loadJava/sourceJava/TypeAnnotations.txt +++ /dev/null @@ -1,6 +0,0 @@ -package test - -public interface TypeAnnotations { - public abstract fun f(/*0*/ p: test.G2<@test.A() kotlin.String!, @test.A() kotlin.Int!>!): kotlin.Unit - public abstract fun f(/*0*/ p: test.G<@test.A() kotlin.String!>!): kotlin.Unit -} diff --git a/compiler/testData/loadJava8/compiledJava/TypeAnnotations.java b/compiler/testData/loadJava8/compiledJava/TypeAnnotations.java new file mode 100644 index 00000000000..c62ead65755 --- /dev/null +++ b/compiler/testData/loadJava8/compiledJava/TypeAnnotations.java @@ -0,0 +1,23 @@ +package test; + +import java.lang.annotation.*; +public class TypeAnnotations { + @Target(ElementType.TYPE_USE) + @interface A { + String value() default ""; + } + + interface G { + } + + interface G2 { + } + + // Currently annotations on type parameters and arguments are not loaded from compiled code because of IDEA-153093 + // Once it will be fixed check if KT-11454 is ready to be resolved + public interface MyClass { + void f(G<@A String> p); + + void f(G2<@A String, @A("abc") Integer> p); + } +} diff --git a/compiler/testData/loadJava8/compiledJava/TypeAnnotations.txt b/compiler/testData/loadJava8/compiledJava/TypeAnnotations.txt new file mode 100644 index 00000000000..9fa9870de7f --- /dev/null +++ b/compiler/testData/loadJava8/compiledJava/TypeAnnotations.txt @@ -0,0 +1,21 @@ +package test + +public open class TypeAnnotations { + public constructor TypeAnnotations() + + @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public/*package*/ final annotation class A : kotlin.Annotation { + public/*package*/ constructor A(/*0*/ value: kotlin.String = ...) + public final val value: kotlin.String + } + + public/*package*/ interface G { + } + + public/*package*/ interface G2 { + } + + public interface MyClass { + public abstract fun f(/*0*/ p0: test.TypeAnnotations.G2!): kotlin.Unit + public abstract fun f(/*0*/ p0: test.TypeAnnotations.G!): kotlin.Unit + } +} diff --git a/compiler/testData/loadJava8/sourceJava/TypeAnnotations.java b/compiler/testData/loadJava8/sourceJava/TypeAnnotations.java new file mode 100644 index 00000000000..cffa9f44312 --- /dev/null +++ b/compiler/testData/loadJava8/sourceJava/TypeAnnotations.java @@ -0,0 +1,21 @@ +package test; + +import java.lang.annotation.*; +public class TypeAnnotations { + @Target(ElementType.TYPE_USE) + @interface A { + String value() default ""; + } + + interface G { + } + + interface G2 { + } + + public interface MyClass { + void f(G<@A String> p); + + void f(G2<@A String, @A("abc") Integer> p); + } +} diff --git a/compiler/testData/loadJava8/sourceJava/TypeAnnotations.txt b/compiler/testData/loadJava8/sourceJava/TypeAnnotations.txt new file mode 100644 index 00000000000..908be591bc4 --- /dev/null +++ b/compiler/testData/loadJava8/sourceJava/TypeAnnotations.txt @@ -0,0 +1,21 @@ +package test + +public open class TypeAnnotations { + public constructor TypeAnnotations() + + @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public/*package*/ final annotation class A : kotlin.Annotation { + public/*package*/ constructor A(/*0*/ value: kotlin.String = ...) + public final val value: kotlin.String + } + + public/*package*/ interface G { + } + + public/*package*/ interface G2 { + } + + public interface MyClass { + public abstract fun f(/*0*/ p: test.TypeAnnotations.G2<@test.TypeAnnotations.A() kotlin.String!, @test.TypeAnnotations.A(value = "abc") kotlin.Int!>!): kotlin.Unit + public abstract fun f(/*0*/ p: test.TypeAnnotations.G<@test.TypeAnnotations.A() kotlin.String!>!): kotlin.Unit + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJava8Test.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJava8Test.java new file mode 100644 index 00000000000..88b2dcbcbf3 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJava8Test.java @@ -0,0 +1,28 @@ +/* + * 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.jvm.compiler; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.test.TestJdkKind; + +public abstract class AbstractLoadJava8Test extends AbstractLoadJavaTest { + @NotNull + @Override + protected TestJdkKind getJdkKind() { + return TestJdkKind.FULL_JDK; + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java index 013fdc67d06..c509801f886 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java @@ -117,7 +117,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { Assert.assertEquals("test", packageFromSource.getName().asString()); PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot( - tmpdir, getTestRootDisposable(), TestJdkKind.MOCK_JDK, configurationKind, true + tmpdir, getTestRootDisposable(), getJdkKind(), configurationKind, true ).first; for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(packageFromBinary.getMemberScope())) { @@ -146,7 +146,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { }); CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests( - ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK); + ConfigurationKind.JDK_ONLY, getJdkKind()); ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath()); JvmContentRootsKt.addJavaSourceRoot(configuration, new File("compiler/testData/loadJava/include")); JvmContentRootsKt.addJavaSourceRoot(configuration, tmpdir); @@ -187,7 +187,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests( getTestRootDisposable(), - compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, getAnnotationsJar(), libraryOut), + compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, getJdkKind(), getAnnotationsJar(), libraryOut), EnvironmentConfigFiles.JVM_CONFIG_FILES); KtFile jetFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject()); @@ -203,6 +203,11 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { ), expectedFile); } + @NotNull + protected TestJdkKind getJdkKind() { + return TestJdkKind.MOCK_JDK; + } + protected void doTestSourceJava(@NotNull String javaFileName) throws Exception { File originalJavaFile = new File(javaFileName); File expectedFile = getTxtFile(javaFileName); @@ -212,7 +217,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { FileUtil.copy(originalJavaFile, new File(testPackageDir, originalJavaFile.getName())); Pair javaPackageAndContext = loadTestPackageAndBindingContextFromJavaRoot( - tmpdir, getTestRootDisposable(), TestJdkKind.MOCK_JDK, ConfigurationKind.JDK_ONLY, false + tmpdir, getTestRootDisposable(), getJdkKind(), ConfigurationKind.JDK_ONLY, false ); checkJavaPackage(expectedFile, javaPackageAndContext.first, javaPackageAndContext.second, @@ -256,7 +261,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { @NotNull ConfigurationKind configurationKind ) throws IOException { compileJavaWithAnnotationsJar(javaFiles, outDir); - return loadTestPackageAndBindingContextFromJavaRoot(outDir, myTestRootDisposable, TestJdkKind.MOCK_JDK, configurationKind, true); + return loadTestPackageAndBindingContextFromJavaRoot(outDir, myTestRootDisposable, getJdkKind(), configurationKind, true); } private static void checkJavaPackage( diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index 5cf506f2ef4..1b4d1d8a9df 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -5111,12 +5111,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestSourceJava(fileName); } - @TestMetadata("TypeAnnotations.java") - public void testTypeAnnotations() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/TypeAnnotations.java"); - doTestSourceJava(fileName); - } - @TestMetadata("WrongNumberOfGenericParameters.java") public void testWrongNumberOfGenericParameters() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/WrongNumberOfGenericParameters.java"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvm8RuntimeDescriptorLoaderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvm8RuntimeDescriptorLoaderTest.kt new file mode 100644 index 00000000000..b892241c71a --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvm8RuntimeDescriptorLoaderTest.kt @@ -0,0 +1,23 @@ +/* + * 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.jvm.runtime + +import org.jetbrains.kotlin.test.TestJdkKind + +abstract class AbstractJvm8RuntimeDescriptorLoaderTest : AbstractJvmRuntimeDescriptorLoaderTest() { + override val defaultJdkKind: TestJdkKind = TestJdkKind.MOCK_JDK +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt index d9501f4c487..0049ba6aa22 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt @@ -72,6 +72,8 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { } } + protected open val defaultJdkKind: TestJdkKind = TestJdkKind.MOCK_JDK + // NOTE: this test does a dirty hack of text substitution to make all annotations defined in source code retain at runtime. // Specifically each @interface in Java sources is extended by @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) // Also type related annotations are removed from Java because they are invisible at runtime @@ -83,7 +85,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { val jdkKind = if (InTextDirectivesUtils.isDirectiveDefined(text, "FULL_JDK")) TestJdkKind.FULL_JDK - else TestJdkKind.MOCK_JDK + else defaultJdkKind compileFile(file, text, jdkKind) diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 9a8cd5f5c7d..072fb84f984 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -113,10 +113,8 @@ import org.jetbrains.kotlin.jps.build.* import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase import org.jetbrains.kotlin.jps.incremental.AbstractProtoComparisonTest import org.jetbrains.kotlin.js.test.semantics.* -import org.jetbrains.kotlin.jvm.compiler.AbstractCompileJavaAgainstKotlinTest -import org.jetbrains.kotlin.jvm.compiler.AbstractLoadJavaTest -import org.jetbrains.kotlin.jvm.compiler.AbstractLoadKotlinWithTypeTableTest -import org.jetbrains.kotlin.jvm.compiler.AbstractWriteSignatureTest +import org.jetbrains.kotlin.jvm.compiler.* +import org.jetbrains.kotlin.jvm.runtime.AbstractJvm8RuntimeDescriptorLoaderTest import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBoxTest import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBytecodeShapeTest @@ -340,12 +338,23 @@ fun main(args: Array) { testClass("BlackBoxWithJava8CodegenTestGenerated") { model("codegen/java8/box") } + testClass("DiagnosticsWithJava8TestGenerated") { model("diagnostics/testsWithJava8") } + testClass() { model("foreignAnnotationsJava8/tests") } + + testClass { + model("loadJava8/compiledJava", extension = "java", testMethod = "doTestCompiledJava") + model("loadJava8/sourceJava", extension = "java", testMethod = "doTestSourceJava") + } + + testClass() { + model("loadJava8/compiledJava", extension = "java", excludeDirs = listOf("sam", "kotlinSignature/propagation")) + } }