Reflection support
This commit is contained in:
@@ -39,7 +39,7 @@ import kotlin.reflect.KotlinReflectionInternalError
|
||||
abstract class KDeclarationContainerImpl : ClassBasedDeclarationContainer {
|
||||
// Note: this is stored here on a soft reference to prevent GC from destroying the weak reference to it in the moduleByClassLoader cache
|
||||
val moduleData by ReflectProperties.lazySoft {
|
||||
jClass.getOrCreateModule()
|
||||
jClass.getOrCreateModule(null)
|
||||
}
|
||||
|
||||
abstract val constructorDescriptors: Collection<ConstructorDescriptor>
|
||||
|
||||
@@ -27,9 +27,9 @@ import kotlin.jvm.internal.KotlinPackage
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.KPackage
|
||||
|
||||
class KPackageImpl(override val jClass: Class<*>) : KDeclarationContainerImpl(), KPackage {
|
||||
class KPackageImpl(override val jClass: Class<*>, val moduleName: String) : KDeclarationContainerImpl(), KPackage {
|
||||
val descriptor by ReflectProperties.lazySoft {
|
||||
val moduleData = jClass.getOrCreateModule()
|
||||
val moduleData = jClass.getOrCreateModule(moduleName)
|
||||
val fqName = jClass.classId.getPackageFqName()
|
||||
|
||||
moduleData.module.getPackage(fqName)
|
||||
|
||||
@@ -32,7 +32,12 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
|
||||
@Override
|
||||
public KPackage createKotlinPackage(Class javaClass) {
|
||||
return new KPackageImpl(javaClass);
|
||||
return createKotlinPackage(javaClass, "undefined");
|
||||
}
|
||||
|
||||
@Override
|
||||
public KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
return new KPackageImpl(javaClass, moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,7 @@ private class WeakClassLoaderBox(classLoader: ClassLoader) {
|
||||
ref.get()?.let { it.toString() } ?: "<null>"
|
||||
}
|
||||
|
||||
internal fun Class<*>.getOrCreateModule(): RuntimeModuleData {
|
||||
internal fun Class<*>.getOrCreateModule(moduleName: String?): RuntimeModuleData {
|
||||
val classLoader = this.safeClassLoader
|
||||
val key = WeakClassLoaderBox(classLoader)
|
||||
|
||||
@@ -54,7 +54,7 @@ internal fun Class<*>.getOrCreateModule(): RuntimeModuleData {
|
||||
moduleByClassLoader.remove(key, cached)
|
||||
}
|
||||
|
||||
val module = RuntimeModuleData.create(classLoader)
|
||||
val module = RuntimeModuleData.create(classLoader, moduleName)
|
||||
try {
|
||||
while (true) {
|
||||
val ref = moduleByClassLoader.putIfAbsent(key, WeakReference(module))
|
||||
|
||||
@@ -94,7 +94,7 @@ public val KType.javaType: Type
|
||||
*/
|
||||
public val Class<*>.kotlinPackage: KPackage?
|
||||
get() = if (getSimpleName().endsWith("Package") &&
|
||||
getAnnotation(javaClass<kotlin.jvm.internal.KotlinPackage>()) != null) KPackageImpl(this) else null
|
||||
getAnnotation(javaClass<kotlin.jvm.internal.KotlinPackage>()) != null) KPackageImpl(this, "undefined") else null
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user