From 8d9618348d91eadd860c73287542e6681939baee Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 26 Aug 2015 16:21:47 +0300 Subject: [PATCH] Move .java and .kotlin extension properties to kotlin.jvm Delete the old ones in package kotlin.reflect.jvm because otherwise the code using those functions will become red in a lot less meaningful way (overload resolution ambiguity) than if they're deleted (unresolved import) Based on the work originally done by @dnpetrov #KT-8380 Fixed --- .../IncrementalPackageFragmentProvider.kt | 4 +-- .../checkers/ReflectionAPICallChecker.kt | 3 -- .../annotatedSamFunExpression.kt | 1 - .../annotatedSamLambda/annotatedSamLambda.kt | 1 - .../annotatedLambda/funExpression.kt | 1 - .../annotations/annotatedLambda/lambda.kt | 1 - .../annotations/defaultParameterValues.kt | 1 - .../reflection/classLiterals/arrays.kt | 1 - .../classLiterals/reifiedTypeClassLiteral.kt | 1 - .../reflection/classes/jvmName.kt | 1 - .../reflection/classes/qualifiedName.kt | 1 - .../mappedClassIsEqualToClassLiteral.kt | 2 -- .../methodsFromAny/memberExtensionToString.kt | 1 - .../reflection/noKotlinReflect/javaClass.kt | 33 +++++++++++++++++ .../noKotlinReflect/primitiveJavaClass.kt | 20 +++++++++++ .../noKotlinReflect/reifiedTypeJavaClass.kt | 22 ++++++++++++ .../properties/fakeOverridesInSubclass.kt | 1 - ...getExtensionPropertiesMutableVsReadonly.kt | 1 - .../getPropertiesMutableVsReadonly.kt | 1 - .../memberAndMemberExtensionWithSameName.kt | 1 - .../properties/simpleGetProperties.kt | 1 - .../javaExtensionPropertyIntrinsic.kt | 4 +-- .../annotations/annotationClassMethodCall.kt | 4 +-- .../reified/reifiedNothingSubstitution.kt | 2 +- .../smoke/scriptWithClasspath/script.kts | 2 +- ...lackBoxWithStdlibCodegenTestGenerated.java | 18 ++++++++++ .../src/kotlin/reflect/jvm/_Deprecated.kt | 11 ++++++ .../src/kotlin/reflect/jvm/mapping.kt | 15 -------- .../android/KotlinOutputParserHelper.kt | 4 +-- .../evaluate/KotlinCodeFragmentFactory.kt | 4 +-- .../stdlib/src/kotlin/jvm/JvmClassMapping.kt | 35 +++++++++++++++++++ libraries/stdlib/src/kotlin/util/JLangJVM.kt | 7 ++-- 32 files changed, 155 insertions(+), 50 deletions(-) create mode 100644 compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt create mode 100644 libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt index f75a4b27f17..2b5586bf725 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt @@ -38,8 +38,8 @@ import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil import org.jetbrains.kotlin.storage.NotNullLazyValue import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList -import java.util.HashMap -import kotlin.reflect.jvm.java +import java.util.* +import kotlin.reflect.jvm.* public class IncrementalPackageFragmentProvider( sourceFiles: Collection, diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/calls/checkers/ReflectionAPICallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/calls/checkers/ReflectionAPICallChecker.kt index ad12ca997b4..88587a2a3cd 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/calls/checkers/ReflectionAPICallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/calls/checkers/ReflectionAPICallChecker.kt @@ -16,12 +16,10 @@ package org.jetbrains.kotlin.resolve.jvm.calls.checkers -import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker @@ -30,7 +28,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.NO_REFLECTION_IN_CLASS_PATH import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies import org.jetbrains.kotlin.types.expressions.OperatorConventions -import kotlin.reflect.jvm.java /** * If there's no Kotlin reflection implementation found in the classpath, checks that there are no usages diff --git a/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt b/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt index 582e297caa7..901267de6f0 100644 --- a/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt +++ b/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt @@ -1,5 +1,4 @@ import java.lang.reflect.Method -import kotlin.reflect.jvm.java import kotlin.test.assertEquals annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String) diff --git a/compiler/testData/codegen/boxWithJava/annotatedSamLambda/annotatedSamLambda.kt b/compiler/testData/codegen/boxWithJava/annotatedSamLambda/annotatedSamLambda.kt index b6f53f39310..f6b65be8dd1 100644 --- a/compiler/testData/codegen/boxWithJava/annotatedSamLambda/annotatedSamLambda.kt +++ b/compiler/testData/codegen/boxWithJava/annotatedSamLambda/annotatedSamLambda.kt @@ -1,5 +1,4 @@ import java.lang.reflect.Method -import kotlin.reflect.jvm.java import kotlin.test.assertEquals target(AnnotationTarget.EXPRESSION) diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt index 3bcc483afe4..88b910a9698 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt @@ -1,5 +1,4 @@ import java.lang.reflect.Method -import kotlin.reflect.jvm.java import kotlin.test.assertEquals annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String) diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt index e5de02774ae..17a63ab835d 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt @@ -1,5 +1,4 @@ import java.lang.reflect.Method -import kotlin.reflect.jvm.java import kotlin.test.assertEquals target(AnnotationTarget.EXPRESSION) diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt b/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt index d99408f2f40..f66f5d16f25 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt @@ -1,5 +1,4 @@ import kotlin.reflect.KClass -import kotlin.reflect.jvm.java annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int = 1, diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/arrays.kt b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/arrays.kt index 6dad60a22ee..f1be66a5c7b 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/arrays.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/arrays.kt @@ -1,5 +1,4 @@ import kotlin.test.* -import kotlin.reflect.jvm.* fun box(): String { val any = Array::class diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/reifiedTypeClassLiteral.kt b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/reifiedTypeClassLiteral.kt index 5e8d22cc6d6..cfe75eb11a5 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/reifiedTypeClassLiteral.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/reifiedTypeClassLiteral.kt @@ -1,5 +1,4 @@ import kotlin.test.* -import kotlin.reflect.jvm.java class Klass class Other diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/classes/jvmName.kt b/compiler/testData/codegen/boxWithStdlib/reflection/classes/jvmName.kt index 919900c354e..2da7bd44471 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/classes/jvmName.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/classes/jvmName.kt @@ -1,7 +1,6 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.reflect.jvm.jvmName -import kotlin.reflect.jvm.kotlin class Klass { class Nested diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/classes/qualifiedName.kt b/compiler/testData/codegen/boxWithStdlib/reflection/classes/qualifiedName.kt index 66646bf5ce0..93e4820a909 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/classes/qualifiedName.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/classes/qualifiedName.kt @@ -1,5 +1,4 @@ import kotlin.test.assertEquals -import kotlin.reflect.jvm.kotlin class Klass { class Nested diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/mappedClassIsEqualToClassLiteral.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/mappedClassIsEqualToClassLiteral.kt index 66fbd963da7..084731d3dff 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/mappedClassIsEqualToClassLiteral.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/mappedClassIsEqualToClassLiteral.kt @@ -1,5 +1,3 @@ -import kotlin.reflect.jvm.* - class A fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/memberExtensionToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/memberExtensionToString.kt index dd06767a1bc..eaaea48ea70 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/memberExtensionToString.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/memberExtensionToString.kt @@ -1,4 +1,3 @@ -import kotlin.reflect.jvm.kotlin import kotlin.reflect.* class A { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt new file mode 100644 index 00000000000..e97156d9624 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt @@ -0,0 +1,33 @@ +// NO_KOTLIN_REFLECT + +import kotlin.test.* + +class Klass + +fun box(): String { + val kClass = Klass::class + val jClass = kClass.java + val kjClass = Klass::class.java + val kkClass = jClass.kotlin + val jjClass = kkClass.java + + assertEquals("Klass", jClass.getSimpleName()) + assertEquals("Klass", kjClass.getSimpleName()) + assertEquals("Klass", kkClass.simpleName) + assertEquals(kjClass, jjClass) + + failsWith(Error::class.java) { kClass.simpleName!! } + failsWith(Error::class.java) { kClass.qualifiedName!! } + failsWith(Error::class.java) { kClass.members } + + val jlError = Error::class.java + val kljError = Error::class + val jljError = kljError.java + val jlkError = jlError.kotlin + + assertEquals("Error", jlError.getSimpleName()) + assertEquals("Error", jljError.getSimpleName()) + assertEquals("Error", jlkError.simpleName) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt new file mode 100644 index 00000000000..a21e54b4287 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt @@ -0,0 +1,20 @@ +// NO_KOTLIN_REFLECT + +import kotlin.test.assertEquals + +fun check(name: String, c: Class<*>) { + assertEquals(name, c.simpleName) +} + +fun box(): String { + check("boolean", Boolean::class.java) + check("byte", Byte::class.java) + check("char", Char::class.java) + check("short", Short::class.java) + check("int", Int::class.java) + check("float", Float::class.java) + check("long", Long::class.java) + check("double", Double::class.java) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt new file mode 100644 index 00000000000..0d8d309e4c5 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt @@ -0,0 +1,22 @@ +// NO_KOTLIN_REFLECT + +import kotlin.test.assertEquals + +class Klass + +inline fun simpleName(): String = + T::class.java.getSimpleName() + +inline fun simpleName2(): String { + val kClass = T::class // Intrinsic for T::class.java is not used + return kClass.java.getSimpleName() +} + + +fun box(): String { + assertEquals("Integer", simpleName()) + assertEquals("Integer", simpleName2()) + assertEquals("Klass", simpleName()) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/fakeOverridesInSubclass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/fakeOverridesInSubclass.kt index dc4e816b363..14e19c0318f 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/fakeOverridesInSubclass.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/fakeOverridesInSubclass.kt @@ -1,4 +1,3 @@ -import kotlin.reflect.jvm.* import kotlin.reflect.* import kotlin.test.* diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt index f581d9140a1..dc06a359b10 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt @@ -1,4 +1,3 @@ -import kotlin.reflect.jvm.kotlin import kotlin.reflect.* var storage = "before" diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt index 357294d3914..4b32193bf99 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt @@ -1,4 +1,3 @@ -import kotlin.reflect.jvm.kotlin import kotlin.reflect.* class A(val readonly: String) { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt index bfdb9871187..9e5e7a6e02c 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt @@ -1,4 +1,3 @@ -import kotlin.reflect.jvm.kotlin import kotlin.reflect.* class A { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt index cfded82a949..f4866eebc46 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt @@ -1,5 +1,4 @@ import kotlin.reflect.* -import kotlin.reflect.jvm.kotlin class A(param: String) { val int: Int get() = 42 diff --git a/compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt b/compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt index f61fc0dcc0d..9662621e2df 100644 --- a/compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt +++ b/compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt @@ -1,5 +1,3 @@ -import kotlin.reflect.jvm.java - class Klass fun foo() { @@ -12,5 +10,5 @@ fun foo() { // 2 LDC LKlass;.class // 1 GETSTATIC java/lang/Integer.TYPE : Ljava/lang/Class; -// 1 INVOKESTATIC kotlin/reflect/jvm.*\.getJava +// 1 INVOKESTATIC kotlin/jvm.*\.getJava // 1 LDC Ljava/lang/Integer;.class diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationClassMethodCall.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationClassMethodCall.kt index 4cb16148eb5..5b693198ebd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationClassMethodCall.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationClassMethodCall.kt @@ -15,8 +15,8 @@ fun foo(ann: A) { ann.toString() ann.hashCode() - javaClass().getAnnotation(javaClass()).value() - javaClass().getAnnotation(javaClass()).arg() + MyClass::class.java.getAnnotation(A::class.java).value() + MyClass::class.java.getAnnotation(A::class.java).arg() } fun A.bar() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt index 19e7415e9b9..089f72a5f03 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -DEPRECATED_SYMBOL_WITH_MESSAGE inline fun foo(block: () -> T): String = block().toString() diff --git a/compiler/testData/integration/smoke/scriptWithClasspath/script.kts b/compiler/testData/integration/smoke/scriptWithClasspath/script.kts index 9b1a132c003..89acfad12c6 100644 --- a/compiler/testData/integration/smoke/scriptWithClasspath/script.kts +++ b/compiler/testData/integration/smoke/scriptWithClasspath/script.kts @@ -1,3 +1,3 @@ import javax.inject.Inject -println(javaClass()) +println(Inject::class.java) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 3fdceb57275..b5ba716dc10 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -3513,6 +3513,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("javaClass.kt") + public void testJavaClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("primitiveJavaClass.kt") + public void testPrimitiveJavaClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("propertyGetSetName.kt") public void testPropertyGetSetName() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/propertyGetSetName.kt"); @@ -3525,6 +3537,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode doTestWithStdlib(fileName); } + @TestMetadata("reifiedTypeJavaClass.kt") + public void testReifiedTypeJavaClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("simpleClassLiterals.kt") public void testSimpleClassLiterals() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/simpleClassLiterals.kt"); diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/_Deprecated.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/_Deprecated.kt index 537a3539db8..508077db2c0 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/_Deprecated.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/_Deprecated.kt @@ -45,3 +45,14 @@ public val KClass.declaredExtensionProperties: Collection.accessible: Boolean get() = isAccessible set(value) { isAccessible = value } + + +@deprecated("Use .java instead.", ReplaceWith("java")) +public val KClass.__java: Class + @jvmName("getJava") + get() = this.java + +@deprecated("Use .kotlin instead.", ReplaceWith("kotlin")) +public val Class.__kotlin: KClass + @jvmName("getKotlin") + get() = this.kotlin diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt index 7cff63ad92e..8905edd7da7 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt @@ -17,19 +17,11 @@ package kotlin.reflect.jvm import java.lang.reflect.* -import kotlin.jvm.internal.Intrinsic import kotlin.reflect.* import kotlin.reflect.jvm.internal.* // Kotlin reflection -> Java reflection -/** - * Returns a Java [Class] instance corresponding to the given [KClass] instance. - */ -@Intrinsic("kotlin.KClass.java.property") -public val KClass.java: Class - get() = (this as KClassImpl).jClass - /** * Returns a Java [Class] instance that represents a Kotlin package. * The methods and fields of this class are generated from top level functions and properties in the Kotlin package. @@ -90,13 +82,6 @@ public val KType.javaType: Type // Java reflection -> Kotlin reflection -// TODO: getstatic $kotlinClass or go to foreignKClasses -/** - * Returns a [KClass] instance corresponding to the given Java [Class] instance. - */ -public val Class.kotlin: KClass - get() = KClassImpl(this) - /** * Returns a [KPackage] instance corresponding to the Java [Class] instance. * The given class is generated from top level functions and properties in the Kotlin package. diff --git a/idea/kotlin-android-plugin/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt b/idea/kotlin-android-plugin/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt index 6a07169059e..8bfc213796c 100644 --- a/idea/kotlin-android-plugin/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt +++ b/idea/kotlin-android-plugin/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt @@ -23,9 +23,9 @@ import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.StringUtil import java.io.File import java.lang.reflect.Constructor -import java.util.HashMap +import java.util.* import java.util.regex.Pattern -import kotlin.reflect.jvm.java +import kotlin.reflect.jvm.* import java.lang.reflect.Array as RArray fun parse(line: String, reader: OutputLineReader, messages: MutableList, logger: ILogger): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt index 284a38d1859..5f8b2dca523 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt @@ -65,7 +65,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.utils.addToStdlib.check import java.util.* import java.util.concurrent.atomic.AtomicReference -import kotlin.reflect.jvm.java +import kotlin.reflect.jvm.* class KotlinCodeFragmentFactory: CodeFragmentFactory() { private val LOG = Logger.getInstance(this.javaClass) @@ -338,4 +338,4 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() { return getContextElement(codeFragment.findElementAt(codeFragment.text.length() - 1)) } -} \ No newline at end of file +} diff --git a/libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt b/libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt new file mode 100644 index 00000000000..cd99de48fab --- /dev/null +++ b/libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2015 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 kotlin.jvm + +import kotlin.jvm.internal.ClassBasedDeclarationContainer +import kotlin.jvm.internal.Intrinsic +import kotlin.jvm.internal.Reflection +import kotlin.reflect.KClass + +/** + * Returns a Java [Class] instance corresponding to the given [KClass] instance. + */ +@Intrinsic("kotlin.KClass.java.property") +public val KClass.java: Class + get() = (this as ClassBasedDeclarationContainer).jClass as Class + +/** + * Returns a [KClass] instance corresponding to the given Java [Class] instance. + */ +public val Class.kotlin: KClass + get() = Reflection.createKotlinClass(this) as KClass diff --git a/libraries/stdlib/src/kotlin/util/JLangJVM.kt b/libraries/stdlib/src/kotlin/util/JLangJVM.kt index eee0b5546a7..a0eed70a26d 100644 --- a/libraries/stdlib/src/kotlin/util/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/util/JLangJVM.kt @@ -27,13 +27,16 @@ public annotation(retention = AnnotationRetention.SOURCE) class throws(public va /** * Returns the runtime Java class of this object. */ -@Intrinsic("kotlin.javaClass.property") public val T.javaClass : Class +@Intrinsic("kotlin.javaClass.property") +public val T.javaClass : Class get() = (this as java.lang.Object).getClass() as Class /** * Returns the Java class for the specified type. */ -@Intrinsic("kotlin.javaClass.function") public fun javaClass(): Class = null as Class +@Intrinsic("kotlin.javaClass.function") +@deprecated("Use the class reference and .java extension property instead: MyClass::class.java", ReplaceWith("T::class.java")) +public fun javaClass(): Class = T::class.java /** * Executes the given function [block] while holding the monitor of the given object [lock].