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:
Chris Smowton
2022-03-24 15:07:09 +00:00
committed by Ian Lynagh
parent db9ab22437
commit 239aab67b6
2 changed files with 10 additions and 7 deletions

View File

@@ -146,6 +146,9 @@ class KotlinExtractorGlobalState {
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
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>()
}
/*

View File

@@ -128,21 +128,21 @@ open class KotlinUsesExtractor(
private fun withFileOfClass(cls: IrClass): KotlinFileExtractor {
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 newTrapWriter = tw.makeFileTrapWriter(filePath, false)
val newTrapWriter = tw.makeFileTrapWriter(filePath, globalExtensionState.extractedClassFilePaths.add(filePath))
val newLoggerTrapWriter = logger.tw.makeFileTrapWriter(filePath, false)
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
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 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)
}