
name.remal.java.lang.ClassLoader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Java & Kotlin tools: common
The newest version!
package name.remal
import name.remal.reflection.ClassLoaderUtils
import name.remal.reflection.ClassLoaderUtils.InstantiatedClassesPropagation
import java.io.File
import java.net.URL
import java.nio.file.Path
fun ClassLoader.getPackageOrNull(packageName: String) = ClassLoaderUtils.getPackageOrNull(this, packageName)
fun ClassLoader.tryLoadClass(className: String, initialize: Boolean = false): Class<*>? = try {
Class.forName(className, initialize, this)
} catch (ignored: LinkageError) {
null
} catch (ignored: ClassNotFoundException) {
null
}
fun ClassLoader.addURL(vararg urls: URL) = ClassLoaderUtils.addURLsToClassLoader(this, *urls)
fun ClassLoader.addURL(vararg files: File) = addURL(*files.map { it.toURI().toURL() }.toTypedArray())
fun ClassLoader.addURL(vararg paths: Path) = addURL(*paths.map { it.toUri().toURL() }.toTypedArray())
fun ClassLoader.forInstantiated(type: Class, implementationType: Class, action: (T) -> R): R = ClassLoaderUtils.forInstantiated(this, type, implementationType, action)
fun ClassLoader.forInstantiated(type: Class, implementationType: Class, propagation: InstantiatedClassesPropagation, action: (T) -> R): R = ClassLoaderUtils.forInstantiated(this, type, implementationType, propagation, action)
fun ClassLoader.forInstantiatedWithPropagatedPackage(type: Class, implementationType: Class, action: (T) -> R): R = ClassLoaderUtils.forInstantiatedWithPropagatedPackage(this, type, implementationType, action)
@JvmName("forInstantiatedVoid")
fun ClassLoader.forInstantiated(type: Class, implementationType: Class, action: (T) -> Unit) = ClassLoaderUtils.forInstantiated(this, type, implementationType, action)
@JvmName("forInstantiatedVoid")
fun ClassLoader.forInstantiated(type: Class, implementationType: Class, propagation: InstantiatedClassesPropagation, action: (T) -> Unit) = ClassLoaderUtils.forInstantiated(this, type, implementationType, propagation, action)
@JvmName("forInstantiatedWithPropagatedPackageVoid")
fun ClassLoader.forInstantiatedWithPropagatedPackage(type: Class, implementationType: Class, action: (T) -> Unit) = ClassLoaderUtils.forInstantiatedWithPropagatedPackage(this, type, implementationType, action)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy