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

Skip to content

Commit 62ce28e

Browse files
committed
Kotlin: Populate diagnostic_for
1 parent ac3c635 commit 62ce28e

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class KotlinExtractorExtension(
121121
moduleFragment.files.mapIndexed { index: Int, file: IrFile ->
122122
val fileExtractionProblems = FileExtractionProblems(invocationExtractionProblems)
123123
val fileTrapWriter = tw.makeSourceFileTrapWriter(file, true)
124+
loggerBase.setFileNumber(index)
124125
fileTrapWriter.writeCompilation_compiling_files(compilation, index, fileTrapWriter.fileId)
125126
doFile(fileExtractionProblems, invocationTrapFile, fileTrapWriter, checkTrapIdentical, loggerBase, trapDir, srcDir, file, primitiveTypeMapping, pluginContext, globalExtensionState)
126127
fileTrapWriter.writeCompilation_compiling_files_completed(compilation, index, fileExtractionProblems.extractionResult())

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ class StringLabel<T>(val name: String): Label<T> {
2525
override fun toString(): String = "#$name"
2626
}
2727

28-
/**
29-
* This is not really a label, but just a `*`. Used in the rare cases
30-
* when we only need to refer to something once, to save adding
31-
* unnecessary labels.
32-
*/
33-
class StarLabel<T>: Label<T> {
34-
override fun toString(): String = "*"
35-
}
36-
3728
// TODO: Remove this and all of its uses
3829
fun <T> fakeLabel(): Label<T> {
3930
if (false) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ open class LoggerBase(val logCounter: LogCounter) {
7373
return null
7474
}
7575

76+
private var file_number = -1
77+
private var file_number_diagnostic_number = 0
78+
79+
fun setFileNumber(index: Int) {
80+
file_number = index
81+
file_number_diagnostic_number = 0
82+
}
83+
7684
fun diagnostic(tw: TrapWriter, severity: Severity, msg: String, extraInfo: String?, locationString: String? = null, mkLocationId: () -> Label<DbLocation> = { tw.unknownLocation }) {
7785
val diagnosticLoc = getDiagnosticLocation()
7886
val diagnosticLocStr = if(diagnosticLoc == null) "<unknown location>" else diagnosticLoc
@@ -106,7 +114,9 @@ open class LoggerBase(val logCounter: LogCounter) {
106114
val ts = timestamp()
107115
// We don't actually make the location until after the `return` above
108116
val locationId = mkLocationId()
109-
tw.writeDiagnostics(StarLabel(), "CodeQL Kotlin extractor", severity.sev, "", msg, "$ts $fullMsg", locationId)
117+
val diagLabel = tw.getFreshIdLabel<DbDiagnostic>()
118+
tw.writeDiagnostics(diagLabel, "CodeQL Kotlin extractor", severity.sev, "", msg, "$ts $fullMsg", locationId)
119+
tw.writeDiagnostic_for(diagLabel, StringLabel("compilation"), file_number, file_number_diagnostic_number++)
110120
val locStr = if (locationString == null) "" else "At " + locationString + ": "
111121
val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR"
112122
logStream.write("$ts [$kind] Diagnostic($diagnosticLocStr): $locStr$fullMsg")

0 commit comments

Comments
 (0)