Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ff6ada

Browse files
committed
Kotlin: Tweak logging
1 parent d6feb58 commit 1ff6ada

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,23 @@ open class KotlinFileExtractor(
3737
): KotlinUsesExtractor(logger, tw, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState) {
3838

3939
inline fun <T> with(kind: String, element: IrElement, f: () -> T): T {
40+
val name = when (element) {
41+
is IrFile -> element.name
42+
is IrDeclarationWithName -> element.name.asString()
43+
else -> "<no name>"
44+
}
4045
val loc = tw.getLocationString(element)
4146
val context = logger.loggerBase.extractorContextStack
42-
context.push(ExtractorContext(kind, element, loc))
47+
context.push(ExtractorContext(kind, element, name, loc))
4348
try {
4449
val depth = context.size
4550
val depthDescription = "${"-".repeat(depth)} (${depth.toString()})"
46-
val name = (element as? IrDeclarationWithName)?.name?.asString() ?: "<no name>"
4751
logger.trace("$depthDescription: Starting a $kind ($name) at $loc")
4852
val result = f()
4953
logger.trace("$depthDescription: Finished a $kind ($name) at $loc")
5054
return result
5155
} catch(exception: Exception) {
52-
throw Exception("While extracting a $kind at $loc", exception)
56+
throw Exception("While extracting a $kind ($name) at $loc", exception)
5357
} finally {
5458
context.pop()
5559
}

java/kotlin-extractor/src/main/kotlin/utils/Logger.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum class Severity(val sev: Int) {
3333
ErrorGlobal(8)
3434
}
3535

36-
data class ExtractorContext(val kind: String, val element: IrElement, val loc: String)
36+
data class ExtractorContext(val kind: String, val element: IrElement, val name: String, val loc: String)
3737

3838
open class LoggerBase(val logCounter: LogCounter) {
3939
val extractorContextStack = Stack<ExtractorContext>()
@@ -106,7 +106,7 @@ open class LoggerBase(val logCounter: LogCounter) {
106106
val iter = extractorContextStack.listIterator(extractorContextStack.size)
107107
while (iter.hasPrevious()) {
108108
val x = iter.previous()
109-
fullMsgBuilder.append(" ...while extracting a ${x.kind} at ${x.loc}\n")
109+
fullMsgBuilder.append(" ...while extracting a ${x.kind} (${x.name}) at ${x.loc}\n")
110110
}
111111
fullMsgBuilder.append(suffix)
112112

0 commit comments

Comments
 (0)