diff --git a/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt b/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt index ee73af820f8..603c4b0433b 100644 --- a/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt +++ b/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt @@ -25,8 +25,10 @@ fun box(): String { // Java class without nested classes assertEquals(emptyList(), nestedNames(Error::class)) + // Java interface with nested classes + assertEquals(listOf("Entry"), nestedNames(java.util.Map::class)) // Java class with nested classes - assertEquals(listOf("State", "UncaughtExceptionHandler"), nestedNames(Thread::class)) + assertEquals(listOf("SimpleEntry", "SimpleImmutableEntry"), nestedNames(java.util.AbstractMap::class)) // Built-ins assertEquals(emptyList(), nestedNames(Array::class)) diff --git a/compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt b/compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt index d1ae9ba0f8d..a124113eef4 100644 --- a/compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt +++ b/compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt @@ -1,10 +1,12 @@ // TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS, NATIVE +// IGNORE_BACKEND: JS, NATIVE, JVM // WITH_REFLECT // FULL_JDK // See KT-11258 Incorrect resolution sequence for Java field +//SHOULD BE enabled after KT-16616 fix + import java.util.* fun box(): String { diff --git a/compiler/testData/codegen/box/regressions/kt6485.kt b/compiler/testData/codegen/box/regressions/kt6485.kt index 01977c6cf72..563ed276949 100644 --- a/compiler/testData/codegen/box/regressions/kt6485.kt +++ b/compiler/testData/codegen/box/regressions/kt6485.kt @@ -16,10 +16,10 @@ open class TypeLiteral { inline fun typeLiteral(): TypeLiteral = object : TypeLiteral() {} fun box(): String { - assertEquals("class java.lang.String", typeLiteral().type.toString()) + assertEquals("java.lang.String", (typeLiteral().type as Class<*>).canonicalName) assertEquals("java.util.List", typeLiteral>().type.toString()) - assertEquals("java.lang.String[]", typeLiteral>().type.toString()) - assertEquals("java.lang.Integer[]", typeLiteral>().type.toString()) - assertEquals("java.lang.String[][]", typeLiteral>>().type.toString()) + assertEquals("java.lang.String[]", (typeLiteral>().type as Class<*>).canonicalName) + assertEquals("java.lang.Integer[]", (typeLiteral>().type as Class<*>).canonicalName) + assertEquals("java.lang.String[][]", (typeLiteral>>().type as Class<*>).canonicalName) return "OK" -} +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt b/compiler/testData/codegen/java6/box/builtinStubMethods/immutableRemove.kt similarity index 100% rename from compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt rename to compiler/testData/codegen/java6/box/builtinStubMethods/immutableRemove.kt diff --git a/compiler/testData/codegen/box/reflection/parameters/javaParametersHaveNoNames.kt b/compiler/testData/codegen/java6/box/reflection/parameters/javaParametersHaveNoNames.kt similarity index 100% rename from compiler/testData/codegen/box/reflection/parameters/javaParametersHaveNoNames.kt rename to compiler/testData/codegen/java6/box/reflection/parameters/javaParametersHaveNoNames.kt diff --git a/compiler/testData/codegen/java6/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt b/compiler/testData/codegen/java6/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt new file mode 100644 index 00000000000..e10c57f7343 --- /dev/null +++ b/compiler/testData/codegen/java6/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt @@ -0,0 +1,26 @@ +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS, NATIVE + +// WITH_REFLECT +// FULL_JDK +// See KT-11258 Incorrect resolution sequence for Java field + +//SHOULD BE deleted after KT-16616 fix +import java.util.* + +fun box(): String { + listOf( + ArrayList::class, + LinkedList::class, + AbstractList::class, + HashSet::class, + TreeSet::class, + HashMap::class, + TreeMap::class, + AbstractMap::class, + AbstractMap.SimpleEntry::class + ).map { + it.members.map(Any::toString) + } + return "OK" +} diff --git a/compiler/testData/codegen/java8/box/builtinStubMethods/immutableRemove.kt b/compiler/testData/codegen/java8/box/builtinStubMethods/immutableRemove.kt new file mode 100644 index 00000000000..2710f121246 --- /dev/null +++ b/compiler/testData/codegen/java8/box/builtinStubMethods/immutableRemove.kt @@ -0,0 +1,53 @@ +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS, NATIVE + +// FULL_JDK +// WITH_RUNTIME +interface ImmutableCollection : Collection { + fun add(element: @UnsafeVariance E): ImmutableCollection + fun addAll(elements: Collection<@UnsafeVariance E>): ImmutableCollection + fun remove(element: @UnsafeVariance E): ImmutableCollection +} + +class ImmutableCollectionmpl : ImmutableCollection { + override val size: Int + get() = throw UnsupportedOperationException() + + override fun contains(element: E): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun containsAll(elements: Collection): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun isEmpty(): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun iterator(): Iterator { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun add(element: E): ImmutableCollection = this + override fun addAll(elements: Collection): ImmutableCollection = this + override fun remove(element: E): ImmutableCollection = this +} + +fun box(): String { + val c = ImmutableCollectionmpl() + if (c.remove("") !== c) return "fail 1" + if (c.add("") !== c) return "fail 2" + if (c.addAll(java.util.ArrayList()) !== c) return "fail 3" + + val method = c.javaClass.methods.single { it.name == "remove" && it.returnType == Boolean::class.javaPrimitiveType } + + try { + method.invoke(c, "") + return "fail 4" + } catch (e: java.lang.reflect.InvocationTargetException) { + if (e.cause!!.message != "Operation is not supported for read-only collection") return "fail 5: ${e.cause!!.message}" + } + + return "OK" +} diff --git a/compiler/testData/codegen/java8/box/reflection/parameters/javaParametersHaveDefaultNames.kt b/compiler/testData/codegen/java8/box/reflection/parameters/javaParametersHaveDefaultNames.kt new file mode 100644 index 00000000000..a16962fbf65 --- /dev/null +++ b/compiler/testData/codegen/java8/box/reflection/parameters/javaParametersHaveDefaultNames.kt @@ -0,0 +1,22 @@ +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS, NATIVE + +// WITH_REFLECT +// FILE: J.java + +public class J { + void foo(String s, int i) {} + + static void bar(J j) {} +} + +// FILE: K.kt + +import kotlin.test.assertEquals + +fun box(): String { + assertEquals(listOf(null, "arg0", "arg1"), J::foo.parameters.map { it.name }) + assertEquals(listOf("arg0"), J::bar.parameters.map { it.name }) + + return "OK" +} diff --git a/compiler/testData/codegen/light-analysis/builtinStubMethods/immutableRemove.txt b/compiler/testData/codegen/light-analysis/builtinStubMethods/immutableRemove.txt deleted file mode 100644 index c831236546d..00000000000 --- a/compiler/testData/codegen/light-analysis/builtinStubMethods/immutableRemove.txt +++ /dev/null @@ -1,33 +0,0 @@ -@kotlin.Metadata -public interface ImmutableCollection { - public abstract @org.jetbrains.annotations.NotNull method add(p0: java.lang.Object): ImmutableCollection - public abstract @org.jetbrains.annotations.NotNull method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): ImmutableCollection - public abstract @org.jetbrains.annotations.NotNull method remove(p0: java.lang.Object): ImmutableCollection -} - -@kotlin.Metadata -public final class ImmutableCollectionmpl { - public method (): void - public @org.jetbrains.annotations.NotNull method add(p0: java.lang.Object): ImmutableCollection - public method add(p0: java.lang.Object): boolean - public @org.jetbrains.annotations.NotNull method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): ImmutableCollection - public method addAll(p0: java.util.Collection): boolean - public method clear(): void - public method contains(p0: java.lang.Object): boolean - public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean - public method getSize(): int - public method isEmpty(): boolean - public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator - public @org.jetbrains.annotations.NotNull method remove(p0: java.lang.Object): ImmutableCollection - public method remove(p0: java.lang.Object): boolean - public method removeAll(p0: java.util.Collection): boolean - public method retainAll(p0: java.util.Collection): boolean - public final method size(): int - public method toArray(): java.lang.Object[] - public method toArray(p0: java.lang.Object[]): java.lang.Object[] -} - -@kotlin.Metadata -public final class ImmutableRemoveKt { - public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String -} diff --git a/compiler/testData/codegen/light-analysis/reflection/parameters/javaParametersHaveNoNames.txt b/compiler/testData/codegen/light-analysis/reflection/parameters/javaParametersHaveNoNames.txt deleted file mode 100644 index 53ba8e014b0..00000000000 --- a/compiler/testData/codegen/light-analysis/reflection/parameters/javaParametersHaveNoNames.txt +++ /dev/null @@ -1,4 +0,0 @@ -@kotlin.Metadata -public final class KKt { - public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String -} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c803c8c2a0c..dd8d1673fc5 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1379,12 +1379,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } - @TestMetadata("immutableRemove.kt") - public void testImmutableRemove() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt"); - doTest(fileName); - } - @TestMetadata("implementationInTrait.kt") public void testImplementationInTrait() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/implementationInTrait.kt"); @@ -14932,12 +14926,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } - @TestMetadata("javaParametersHaveNoNames.kt") - public void testJavaParametersHaveNoNames() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/javaParametersHaveNoNames.kt"); - doTest(fileName); - } - @TestMetadata("kinds.kt") public void testKinds() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/kinds.kt"); @@ -15283,7 +15271,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes @TestMetadata("getMembersOfStandardJavaClasses.kt") public void testGetMembersOfStandardJavaClasses() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt"); - doTest(fileName); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java index 4c500f433e6..0e78439bc92 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java @@ -138,6 +138,21 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg doTest(fileName); } + @TestMetadata("compiler/testData/codegen/java8/box/builtinStubMethods") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class BuiltinStubMethods extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInBuiltinStubMethods() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/builtinStubMethods"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("immutableRemove.kt") + public void testImmutableRemove() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/builtinStubMethods/immutableRemove.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/java8/box/delegationBy") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -592,5 +607,20 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/reflection/synthesizedParameterNames.kt"); doTest(fileName); } + + @TestMetadata("compiler/testData/codegen/java8/box/reflection/parameters") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Parameters extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInParameters() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/reflection/parameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("javaParametersHaveDefaultNames.kt") + public void testJavaParametersHaveDefaultNames() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/reflection/parameters/javaParametersHaveDefaultNames.kt"); + doTest(fileName); + } + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index d5d5aba1662..e38c7a545bb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1379,12 +1379,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("immutableRemove.kt") - public void testImmutableRemove() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt"); - doTest(fileName); - } - @TestMetadata("implementationInTrait.kt") public void testImplementationInTrait() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/implementationInTrait.kt"); @@ -14932,12 +14926,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("javaParametersHaveNoNames.kt") - public void testJavaParametersHaveNoNames() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/javaParametersHaveNoNames.kt"); - doTest(fileName); - } - @TestMetadata("kinds.kt") public void testKinds() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/kinds.kt"); @@ -15283,7 +15271,13 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @TestMetadata("getMembersOfStandardJavaClasses.kt") public void testGetMembersOfStandardJavaClasses() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt"); - doTest(fileName); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c0b56fbefb7..37fa7fa0690 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1613,18 +1613,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } - @TestMetadata("immutableRemove.kt") - public void testImmutableRemove() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); - } - @TestMetadata("implementationInTrait.kt") public void testImplementationInTrait() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/implementationInTrait.kt"); @@ -18150,18 +18138,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } - @TestMetadata("javaParametersHaveNoNames.kt") - public void testJavaParametersHaveNoNames() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/javaParametersHaveNoNames.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); - } - @TestMetadata("kinds.kt") public void testKinds() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/parameters/kinds.kt");