Move jvm annotations and class mapping intrinsics to runtime.jvm module to kotlin.jvm package.
Make annotationClass to be a property. Deprecate with error javaClass property on KClass<T>
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : 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)")
|
||||
}
|
||||
|
||||
@@ -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 <T : Any> KClass<T>.java: Class<T>
|
||||
@JvmName("getJavaClass")
|
||||
get() = (this as ClassBasedDeclarationContainer).jClass as Class<T>
|
||||
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public val <T : Any> Class<T>.kotlin: KClass<T>
|
||||
@JvmName("getKotlinClass")
|
||||
get() = Reflection.createKotlinClass(this) as KClass<T>
|
||||
|
||||
|
||||
/**
|
||||
* Returns the runtime Java class of this object.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Intrinsic("kotlin.javaClass.property")
|
||||
public val <T: Any> T.javaClass : Class<T>
|
||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||
|
||||
@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 <T: Any> KClass<T>.javaClass: Class<KClass<T>>
|
||||
@JvmName("getRuntimeClassOfKClassInstance")
|
||||
get() = (this as java.lang.Object).getClass() as Class<KClass<T>>
|
||||
|
||||
/**
|
||||
* Checks if array can contain element of type [T].
|
||||
*/
|
||||
@Intrinsic("kotlin.jvm.isArrayOf")
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||
public fun <reified T : Any> 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 : Annotation> T.annotationClass: KClass<out T>
|
||||
get() = (this as java.lang.annotation.Annotation).annotationType().kotlin as KClass<out T>
|
||||
-4
@@ -87,10 +87,6 @@ public annotation class JvmSynthetic
|
||||
public annotation class Throws(public vararg val exceptionClasses: KClass<out Throwable>)
|
||||
|
||||
|
||||
@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.
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
<target name="document">
|
||||
<delete dir="doc/stdlib"/>
|
||||
<mkdir dir="doc/stdlib"/>
|
||||
<dokka src="stdlib/src:../core/builtins:../core/reflection.jvm"
|
||||
<dokka src="stdlib/src:../core/builtins:../core/reflection.jvm:../core/runtime.jvm/src/kotlin/jvm/annotations:../core/runtime.jvm/src/kotlin/jvm/JvmClassMapping.kt"
|
||||
samples="stdlib/test" outputDir="doc" moduleName="stdlib" skipDeprecated="true" outputFormat="kotlin-website"
|
||||
include="stdlib/src/Module.md">
|
||||
<sourcelink path=".." url="http://github.com/JetBrains/kotlin/blob/master" linesuffix="#L"/>
|
||||
|
||||
+6
-13
@@ -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 <T : Any> KClass<T>.java: Class<T>
|
||||
get() = (this as ClassBasedDeclarationContainer).jClass as Class<T>
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T: Any> KClass<T>.getJava(): Class<T> = this.java
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T : Any> Class<T>.getKotlin(): KClass<T> = Reflection.createKotlinClass(this) as KClass<T>
|
||||
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
|
||||
*/
|
||||
public val <T : Any> Class<T>.kotlin: KClass<T>
|
||||
get() = Reflection.createKotlinClass(this) as KClass<T>
|
||||
+3
-10
@@ -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 <reified T : Any> 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)
|
||||
@@ -32,6 +32,7 @@ public annotation class throws(public vararg val exceptionClasses: KClass<out Th
|
||||
* Returns the runtime Java class of this object.
|
||||
*/
|
||||
@Intrinsic("kotlin.javaClass.property")
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public val <T: Any> T.javaClass : Class<T>
|
||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||
|
||||
@@ -47,8 +48,8 @@ public fun <reified T: Any> javaClass(): Class<T> = T::class.java
|
||||
/**
|
||||
* Returns the annotation type of this annotation.
|
||||
*/
|
||||
public fun <T : Annotation> T.annotationType() : Class<out T> =
|
||||
(this as java.lang.annotation.Annotation).annotationType() as Class<out T>
|
||||
@Deprecated("Use annotationClass.java instead", ReplaceWith("annotationClass.java"))
|
||||
public fun <T : Annotation> T.annotationType() : Class<out T> = annotationClass.java
|
||||
|
||||
/**
|
||||
* Invokes the underlying method represented by this [Method] object, on the specified [instance] with the specified parameters.
|
||||
|
||||
Reference in New Issue
Block a user