diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaClassOnCompanionChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaClassOnCompanionChecker.kt index 01d3f9d9d1a..6dc3dcdb75d 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaClassOnCompanionChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaClassOnCompanionChecker.kt @@ -34,7 +34,7 @@ public class JavaClassOnCompanionChecker : CallChecker { if (descriptor !is PropertyDescriptor || descriptor.name.asString() != "javaClass") return val container = descriptor.containingDeclaration - if (container !is PackageFragmentDescriptor || container.fqName.asString() != "kotlin") return + if (container !is PackageFragmentDescriptor || container.fqName.asString() != "kotlin.jvm") return val actualType = descriptor.type diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt index d59a08e0092..714854859dd 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt @@ -134,7 +134,7 @@ internal class KClassImpl(override val jClass: Class) : KDeclaration val packageName = classId.packageFqName.asString() val className = classId.relativeClassName.asString().replace('.', '$') // All pseudo-classes like String.Companion must be accessible from the current class loader - javaClass.safeClassLoader.tryLoadClass("$packageName.$className") + (this as Any).javaClass.safeClassLoader.tryLoadClass("$packageName.$className") } else -> throw KotlinReflectionInternalError("Unsupported class: $nestedClass (source = $source)") } diff --git a/core/runtime.jvm/src/kotlin/jvm/JvmClassMapping.kt b/core/runtime.jvm/src/kotlin/jvm/JvmClassMapping.kt new file mode 100644 index 00000000000..89828ecabf4 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/jvm/JvmClassMapping.kt @@ -0,0 +1,70 @@ +/* + * 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. + */ +@file:kotlin.jvm.JvmName("JvmClassMappingKt") +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + +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. + */ +@Suppress("UNCHECKED_CAST") +@Intrinsic("kotlin.KClass.java.property") +public val KClass.java: Class + @JvmName("getJavaClass") + get() = (this as ClassBasedDeclarationContainer).jClass as Class + +/** + * Returns a [KClass] instance corresponding to the given Java [Class] instance. + */ +@Suppress("UNCHECKED_CAST") +public val Class.kotlin: KClass + @JvmName("getKotlinClass") + get() = Reflection.createKotlinClass(this) as KClass + + +/** + * Returns the runtime Java class of this object. + */ +@Suppress("UNCHECKED_CAST") +@Intrinsic("kotlin.javaClass.property") +public val T.javaClass : Class + get() = (this as java.lang.Object).getClass() as Class + +@Deprecated("Use 'java' property to get Java class corresponding to this Kotlin class or cast this instance to Any if you really want to get the runtime Java class of this implementation of KClass.", ReplaceWith("(this as Any).javaClass"), level = DeprecationLevel.ERROR) +public val KClass.javaClass: Class> + @JvmName("getRuntimeClassOfKClassInstance") + get() = (this as java.lang.Object).getClass() as Class> + +/** + * Checks if array can contain element of type [T]. + */ +@Intrinsic("kotlin.jvm.isArrayOf") +@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") +public fun Array<*>.isArrayOf(): Boolean = + T::class.java.isAssignableFrom(this.javaClass.componentType) + +/** + * Returns a [KClass] instance corresponding to the annotation type of this annotation. + */ +@Suppress("UNCHECKED_CAST") +public val T.annotationClass: KClass + get() = (this as java.lang.annotation.Annotation).annotationType().kotlin as KClass diff --git a/libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt b/core/runtime.jvm/src/kotlin/jvm/annotations/JvmFlagAnnotations.kt similarity index 100% rename from libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt rename to core/runtime.jvm/src/kotlin/jvm/annotations/JvmFlagAnnotations.kt diff --git a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt b/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt similarity index 94% rename from libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt rename to core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt index 163d44a81d8..fc5646e1234 100644 --- a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt +++ b/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt @@ -87,10 +87,6 @@ public annotation class JvmSynthetic public annotation class Throws(public vararg val exceptionClasses: KClass) -@Target(AnnotationTarget.FILE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) -internal annotation class JvmVersion(public val minimum: Int = 6, public val maximum: Int = 100) - /** * Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field. */ diff --git a/libraries/build-docs.xml b/libraries/build-docs.xml index 844fa1a71bd..091f01e6aa2 100644 --- a/libraries/build-docs.xml +++ b/libraries/build-docs.xml @@ -14,7 +14,7 @@ - diff --git a/libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt b/libraries/stdlib/src/kotlin/jvm/ClassMapping.kt similarity index 57% rename from libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt rename to libraries/stdlib/src/kotlin/jvm/ClassMapping.kt index 103024855a7..7686333aed4 100644 --- a/libraries/stdlib/src/kotlin/jvm/JvmClassMapping.kt +++ b/libraries/stdlib/src/kotlin/jvm/ClassMapping.kt @@ -14,23 +14,16 @@ * limitations under the License. */ @file:kotlin.jvm.JvmName("ClassMapping") +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") 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 +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public fun KClass.getJava(): Class = this.java + +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public fun Class.getKotlin(): KClass = Reflection.createKotlinClass(this) as KClass -/** - * 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/jvm/IsArrayOf.kt b/libraries/stdlib/src/kotlin/jvm/JvmVersion.kt similarity index 66% rename from libraries/stdlib/src/kotlin/jvm/IsArrayOf.kt rename to libraries/stdlib/src/kotlin/jvm/JvmVersion.kt index 21cad54cae9..a8198e5ec66 100644 --- a/libraries/stdlib/src/kotlin/jvm/IsArrayOf.kt +++ b/libraries/stdlib/src/kotlin/jvm/JvmVersion.kt @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package kotlin.jvm -import kotlin.jvm.internal.Intrinsic - -/** - * Checks if array can contain element of type [T]. - */ -@Intrinsic("kotlin.jvm.isArrayOf") -@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") -public fun Array<*>.isArrayOf(): Boolean = - T::class.java.isAssignableFrom(this.javaClass.componentType) +@Target(AnnotationTarget.FILE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +internal annotation class JvmVersion(public val minimum: Int = 6, public val maximum: Int = 100) diff --git a/libraries/stdlib/src/kotlin/util/JLangJVM.kt b/libraries/stdlib/src/kotlin/util/JLangJVM.kt index 66f0c7e4202..4269439999c 100644 --- a/libraries/stdlib/src/kotlin/util/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/util/JLangJVM.kt @@ -32,6 +32,7 @@ public annotation class throws(public vararg val exceptionClasses: KClass T.javaClass : Class get() = (this as java.lang.Object).getClass() as Class @@ -47,8 +48,8 @@ public fun javaClass(): Class = T::class.java /** * Returns the annotation type of this annotation. */ -public fun T.annotationType() : Class = - (this as java.lang.annotation.Annotation).annotationType() as Class +@Deprecated("Use annotationClass.java instead", ReplaceWith("annotationClass.java")) +public fun T.annotationType() : Class = annotationClass.java /** * Invokes the underlying method represented by this [Method] object, on the specified [instance] with the specified parameters.