mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Kotlin: Give context to diagnostics
We now get e.g.
[2022-03-09 13:59:04 K] [ERROR] Diagnostic(com.github.codeql.KotlinUsesExtractor.useSimpleType(KotlinUsesExtractor.kt:505)): Type alias ignored for <root>.Test<kotlin.String>{ <root>.Alias1<kotlin.String> }
...while extracting a function at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
...while extracting a function if real at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
...while extracting a declaration at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
...while extracting a file at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:1:1:8:0
This commit is contained in:
@@ -40,9 +40,10 @@ open class KotlinFileExtractor(
|
||||
|
||||
inline fun <T> with(kind: String, element: IrElement, f: () -> T): T {
|
||||
val loc = tw.getLocationString(element)
|
||||
globalExtensionState.context.push(ExtractorContext(kind, element))
|
||||
val context = logger.loggerBase.extractorContextStack
|
||||
context.push(ExtractorContext(kind, element, loc))
|
||||
try {
|
||||
val depth = globalExtensionState.context.size
|
||||
val depth = context.size
|
||||
val depthDescription = "${"-".repeat(depth)} (${depth.toString()})"
|
||||
val name = (element as? IrDeclarationWithName)?.name?.asString() ?: "<no name>"
|
||||
logger.trace("$depthDescription: Starting a $kind ($name) at $loc")
|
||||
@@ -52,7 +53,7 @@ open class KotlinFileExtractor(
|
||||
} catch(exception: Exception) {
|
||||
throw Exception("While extracting a $kind at $loc", exception)
|
||||
} finally {
|
||||
globalExtensionState.context.pop()
|
||||
context.pop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user