Clear reflection caches in black box codegen tests
To prevent tests from altering outcomes of the subsequent tests. Also expose the clearCaches method (in the internal class ReflectionFactoryImpl) so that it can be used in other places in similar circumstances
This commit is contained in:
@@ -105,4 +105,11 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
KDeclarationContainer owner = reference.getOwner();
|
||||
return owner instanceof KDeclarationContainerImpl ? ((KDeclarationContainerImpl) owner) : EmptyContainerForLocal.INSTANCE;
|
||||
}
|
||||
|
||||
// Misc
|
||||
|
||||
public static void clearCaches() {
|
||||
KClassCacheKt.clearKClassCache();
|
||||
ModuleByClassLoaderKt.clearModuleByClassLoaderCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,3 +64,7 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> {
|
||||
K_CLASS_CACHE = K_CLASS_CACHE.plus(name, WeakReference(newKClass))
|
||||
return newKClass
|
||||
}
|
||||
|
||||
internal fun clearKClassCache() {
|
||||
K_CLASS_CACHE = HashPMap.empty()
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ private class WeakClassLoaderBox(classLoader: ClassLoader) {
|
||||
identityHashCode
|
||||
|
||||
override fun toString() =
|
||||
ref.get()?.let { it.toString() } ?: "<null>"
|
||||
ref.get()?.toString() ?: "<null>"
|
||||
}
|
||||
|
||||
internal fun Class<*>.getOrCreateModule(): RuntimeModuleData {
|
||||
@@ -70,3 +70,7 @@ internal fun Class<*>.getOrCreateModule(): RuntimeModuleData {
|
||||
key.temporaryStrongRef = null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun clearModuleByClassLoaderCache() {
|
||||
moduleByClassLoader.clear()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user