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

Skip to content

Commit 26a0925

Browse files
committed
Kotlin: Add comments saying what generated TRAP files
1 parent 35ad8f3 commit 26a0925

4 files changed

Lines changed: 25 additions & 12 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.ArrayList
99
import java.util.HashSet
1010
import java.util.zip.GZIPOutputStream
1111

12-
class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String, val primitiveTypeMapping: PrimitiveTypeMapping, val pluginContext: IrPluginContext) {
12+
class ExternalClassExtractor(val logger: FileLogger, val invocationTrapFile: String, val sourceFilePath: String, val primitiveTypeMapping: PrimitiveTypeMapping, val pluginContext: IrPluginContext) {
1313

1414
val externalClassesDone = HashSet<IrClass>()
1515
val externalClassWorkList = ArrayList<IrClass>()
@@ -33,10 +33,17 @@ class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String,
3333
logger.info("Skipping extracting class ${irClass.name}")
3434
} else {
3535
GZIPOutputStream(manager.getFile().outputStream()).bufferedWriter().use { trapFileBW ->
36+
// We want our comments to be the first thing in the file,
37+
// so start off with a mere TrapWriter
38+
val tw = TrapWriter(TrapLabelManager(), trapFileBW)
39+
tw.writeComment("Generated by the CodeQL Kotlin extractor for external dependencies")
40+
tw.writeComment("Part of invocation $invocationTrapFile")
41+
// Now elevate to a SourceFileTrapWriter, and populate the
42+
// file information
3643
val binaryPath = getIrClassBinaryPath(irClass)
37-
val tw =
38-
FileTrapWriter(TrapLabelManager(), trapFileBW, binaryPath, true)
39-
val fileExtractor = KotlinFileExtractor(logger, tw, manager, this, primitiveTypeMapping, pluginContext)
44+
val ftw = tw.makeFileTrapWriter(binaryPath, true)
45+
46+
val fileExtractor = KotlinFileExtractor(logger, ftw, manager, this, primitiveTypeMapping, pluginContext)
4047
fileExtractor.extractClassSource(irClass)
4148
}
4249
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,17 @@ fun doFile(invocationTrapFile: String,
112112
if (checkTrapIdentical || !trapFile.exists()) {
113113
val trapTmpFile = File.createTempFile("$filePath.", ".trap.tmp", trapFileDir)
114114
trapTmpFile.bufferedWriter().use { trapFileBW ->
115-
val tw = SourceFileTrapWriter(TrapLabelManager(), trapFileBW, file, true)
116-
tw.writeComment("Generated by invocation $invocationTrapFile")
117-
val externalClassExtractor = ExternalClassExtractor(logger, file.path, primitiveTypeMapping, pluginContext)
118-
val fileExtractor = KotlinSourceFileExtractor(logger, tw, file, externalClassExtractor, primitiveTypeMapping, pluginContext)
119-
fileExtractor.extractFileContents(tw.fileId)
115+
// We want our comments to be the first thing in the file,
116+
// so start off with a mere TrapWriter
117+
val tw = TrapWriter(TrapLabelManager(), trapFileBW)
118+
tw.writeComment("Generated by the CodeQL Kotlin extractor for kotlin source code")
119+
tw.writeComment("Part of invocation $invocationTrapFile")
120+
// Now elevate to a SourceFileTrapWriter, and populate the
121+
// file information
122+
val sftw = tw.makeSourceFileTrapWriter(file, true)
123+
val externalClassExtractor = ExternalClassExtractor(logger, invocationTrapFile, file.path, primitiveTypeMapping, pluginContext)
124+
val fileExtractor = KotlinSourceFileExtractor(logger, sftw, file, externalClassExtractor, primitiveTypeMapping, pluginContext)
125+
fileExtractor.extractFileContents(sftw.fileId)
120126
externalClassExtractor.extractExternalClasses()
121127
}
122128
if (checkTrapIdentical && trapFile.exists()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ open class KotlinUsesExtractor(
7373
val clsFile = cls.fileOrNull
7474

7575
if (isExternalDeclaration(cls) || clsFile == null) {
76-
val newTrapWriter = tw.makeFileTrapWriter(getIrClassBinaryPath(cls))
76+
val newTrapWriter = tw.makeFileTrapWriter(getIrClassBinaryPath(cls), false)
7777
val newLogger = FileLogger(logger.logCounter, newTrapWriter)
7878
return KotlinFileExtractor(newLogger, newTrapWriter, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext)
7979
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ open class TrapWriter (protected val lm: TrapLabelManager, private val bw: Buffe
159159
* Gets a FileTrapWriter like this one (using the same label manager,
160160
* writer etc), but using the given `filePath` for locations.
161161
*/
162-
fun makeFileTrapWriter(filePath: String) =
163-
FileTrapWriter(lm, bw, filePath, false)
162+
fun makeFileTrapWriter(filePath: String, populateFileTables: Boolean) =
163+
FileTrapWriter(lm, bw, filePath, populateFileTables)
164164

165165
/**
166166
* Gets a FileTrapWriter like this one (using the same label manager,

0 commit comments

Comments
 (0)