Kotlin: When verbose, make with log when it starts and finishes doing something

This commit is contained in:
Ian Lynagh
2022-03-07 11:03:56 +00:00
parent 8b56302644
commit 9c2df20117

View File

@@ -42,10 +42,15 @@ open class KotlinFileExtractor(
): KotlinUsesExtractor(logger, tw, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState) {
inline fun <T> with(kind: String, element: IrElement, f: () -> T): T {
val loc = tw.getLocationString(element)
try {
return f()
val name = (element as? IrDeclarationWithName)?.name?.asString() ?: "<no name>"
logger.trace("Starting a $kind ($name) at $loc")
val result = f()
logger.trace("Finished a $kind ($name) at $loc")
return result
} catch(exception: Exception) {
throw Exception("While extracting a $kind at ${tw.getLocationString(element)}", exception)
throw Exception("While extracting a $kind at $loc", exception)
}
}