Coverage Summary for Class: ExtensionKt (dev.suresh.lang)

Class Method, % Branch, % Line, % Instruction, %
ExtensionKt 0% (0/4) 0% (0/2) 0% (0/9) 0% (0/58)
ExtensionKt$methodName$1 0% (0/1) 0% (0/2) 0% (0/1) 0% (0/13)
ExtensionKt$sam$i$java_util_function_Function$0
Total 0% (0/5) 0% (0/4) 0% (0/10) 0% (0/71)


 package dev.suresh.lang
 
 import java.net.URL
 import kotlin.jvm.optionals.getOrNull
 
 /** Returns the method name contains this call-site */
 inline val methodName
   get() = StackWalker.getInstance().walk { it.findFirst().getOrNull()?.methodName }
 
 /** Read the [Class] as [ByteArray] */
 fun <T : Class<*>> T.toBytes(): ByteArray? {
   val classAsPath = "${name.replace('.', '/')}.class"
   return classLoader.getResourceAsStream(classAsPath)?.readBytes()
 }
 
 /**
  * Returns the actual class [URL]
  *
  * ```
  * val url = LogManager::class.java.resourcePath
  * ```
  */
 val <T : Class<*>> T.resourcePath: URL?
   get() = getResource("$simpleName.class")
 
 /** Run the lambda in the context of the receiver classloader. */
 fun ClassLoader.using(run: () -> Unit) {
   val cl = Thread.currentThread().contextClassLoader
   try {
     Thread.currentThread().contextClassLoader = this
     run()
   } finally {
     Thread.currentThread().contextClassLoader = cl
   }
 }