Kotlin: Add TrapWriter.writeComment

This commit is contained in:
Ian Lynagh
2021-11-10 14:21:18 +00:00
parent 5cf14e6f39
commit 80e2140ca7
3 changed files with 6 additions and 3 deletions

View File

@@ -132,8 +132,8 @@ fun doFile(invocationTrapFile: String,
if (checkTrapIdentical || !trapFile.exists()) {
val trapTmpFile = File.createTempFile("$filePath.", ".trap.tmp", trapFileDir)
trapTmpFile.bufferedWriter().use { trapFileBW ->
trapFileBW.write("// Generated by invocation ${invocationTrapFile.replace("\n", "\n// ")}\n")
val tw = SourceFileTrapWriter(TrapLabelManager(), trapFileBW, file)
tw.writeComment("Generated by invocation $invocationTrapFile")
val externalClassExtractor = ExternalClassExtractor(logger, file.path, pluginContext)
val fileExtractor = KotlinSourceFileExtractor(logger, tw, file, externalClassExtractor, pluginContext)
fileExtractor.extractFileContents(tw.fileId)

View File

@@ -71,6 +71,9 @@ open class TrapWriter (val lm: TrapLabelManager, val bw: BufferedWriter) {
fun writeTrap(trap: String) {
bw.write(trap)
}
fun writeComment(comment: String) {
writeTrap("// ${comment.replace("\n", "\n// ")}\n")
}
fun flush() {
bw.flush()
}

View File

@@ -53,7 +53,7 @@ open class Logger(val logCounter: LogCounter, open val tw: TrapWriter) {
}
fun info(msg: String) {
val fullMsg = "${timestamp()} $msg"
tw.writeTrap("// " + fullMsg.replace("\n", "\n//") + "\n")
tw.writeComment(fullMsg)
println(fullMsg)
}
fun trace(msg: String) {
@@ -104,7 +104,7 @@ open class Logger(val logCounter: LogCounter, open val tw: TrapWriter) {
for((caller, count) in logCounter.warningCounts) {
if(count >= logCounter.warningLimit) {
val msg = "Total of $count warnings from $caller.\n"
tw.writeTrap("// $msg")
tw.writeComment(msg)
print(msg)
}
}