mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Populate the files table for generic class instances
This is because different instances might see the code in different locations (e.g., the class file exists in more than one jar) or with no location (seen as a .java file passed to kotlinc). While I'm there, improve the order of checks and fix a trivial bug in withFileOfClass
This commit is contained in:
committed by
Ian Lynagh
parent
db9ab22437
commit
239aab67b6
@@ -146,6 +146,9 @@ class KotlinExtractorGlobalState {
|
|||||||
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
|
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
|
||||||
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
|
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
|
||||||
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
|
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
|
||||||
|
// This records source files (typically .class files) that have been extracted already, to save repeatedly extracting
|
||||||
|
// the `files` and `folders` entry for a class file every time we see it.
|
||||||
|
val extractedClassFilePaths = HashSet<String>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -128,21 +128,21 @@ open class KotlinUsesExtractor(
|
|||||||
private fun withFileOfClass(cls: IrClass): KotlinFileExtractor {
|
private fun withFileOfClass(cls: IrClass): KotlinFileExtractor {
|
||||||
val clsFile = cls.fileOrNull
|
val clsFile = cls.fileOrNull
|
||||||
|
|
||||||
if (isExternalDeclaration(cls) || clsFile == null) {
|
if (this is KotlinFileExtractor && this.filePath == clsFile?.path) {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clsFile == null || isExternalDeclaration(cls)) {
|
||||||
val filePath = getIrClassBinaryPath(cls)
|
val filePath = getIrClassBinaryPath(cls)
|
||||||
val newTrapWriter = tw.makeFileTrapWriter(filePath, false)
|
val newTrapWriter = tw.makeFileTrapWriter(filePath, globalExtensionState.extractedClassFilePaths.add(filePath))
|
||||||
val newLoggerTrapWriter = logger.tw.makeFileTrapWriter(filePath, false)
|
val newLoggerTrapWriter = logger.tw.makeFileTrapWriter(filePath, false)
|
||||||
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
|
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
|
||||||
return KotlinFileExtractor(newLogger, newTrapWriter, filePath, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
return KotlinFileExtractor(newLogger, newTrapWriter, filePath, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this is KotlinFileExtractor && this.filePath == clsFile.path) {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, false)
|
val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, false)
|
||||||
val newLoggerTrapWriter = logger.tw.makeSourceFileTrapWriter(clsFile, false)
|
val newLoggerTrapWriter = logger.tw.makeSourceFileTrapWriter(clsFile, false)
|
||||||
val newLogger = FileLogger(logger.loggerBase, newTrapWriter)
|
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
|
||||||
return KotlinFileExtractor(newLogger, newTrapWriter, clsFile.path, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
return KotlinFileExtractor(newLogger, newTrapWriter, clsFile.path, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user