mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Kotlin: Consistently use addClassLabel, and have it handle external classes
This commit is contained in:
@@ -33,8 +33,9 @@ class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String,
|
||||
logger.info("Skipping extracting class ${irClass.name}")
|
||||
} else {
|
||||
GZIPOutputStream(manager.getFile().outputStream()).bufferedWriter().use { trapFileBW ->
|
||||
val binaryPath = getIrClassBinaryPath(irClass)
|
||||
val tw =
|
||||
FileTrapWriter(TrapLabelManager(), trapFileBW, getIrClassBinaryPath(irClass), true)
|
||||
FileTrapWriter(TrapLabelManager(), trapFileBW, binaryPath, true)
|
||||
val fileExtractor = KotlinFileExtractor(logger, tw, manager, this, primitiveTypeMapping, pluginContext)
|
||||
fileExtractor.extractClassSource(irClass)
|
||||
}
|
||||
|
||||
@@ -95,23 +95,14 @@ open class KotlinUsesExtractor(
|
||||
|
||||
val extractClass = substituteClass ?: c
|
||||
|
||||
val classId = getClassLabel(extractClass, typeArgs)
|
||||
val classLabel : Label<out DbClassorinterface> = tw.getLabelFor(classId.classLabel, {
|
||||
// If this is a generic type instantiation then it has no
|
||||
// source entity, so we need to extract it here
|
||||
if (typeArgs.isNotEmpty()) {
|
||||
this.withSourceFileOfClass(extractClass).extractClassInstance(extractClass, typeArgs)
|
||||
}
|
||||
|
||||
substituteClass?.let { extractClassLaterIfExternal(it) }
|
||||
})
|
||||
val classTypeResult = addClassLabel(extractClass, typeArgs)
|
||||
// Extract both the Kotlin and equivalent Java classes, so that we have database entries
|
||||
// for both even if all internal references to the Kotlin type are substituted.
|
||||
// TODO: Should we do this inside the label initialisation? That would require all
|
||||
// initialisers of the label to do it.
|
||||
extractClassLaterIfExternal(c)
|
||||
if(c != extractClass) {
|
||||
extractClassLaterIfExternal(c)
|
||||
}
|
||||
|
||||
return UseClassInstanceResult(TypeResult(classLabel, extractClass.fqNameWhenAvailable?.asString(), classId.shortName), extractClass)
|
||||
return UseClassInstanceResult(classTypeResult, extractClass)
|
||||
}
|
||||
|
||||
fun isExternalDeclaration(d: IrDeclaration): Boolean {
|
||||
@@ -143,8 +134,17 @@ open class KotlinUsesExtractor(
|
||||
|
||||
fun addClassLabel(c: IrClass, typeArgs: List<IrTypeArgument>): TypeResult<DbClassorinterface> {
|
||||
val classLabelResult = getClassLabel(c, typeArgs)
|
||||
val classLabel : Label<out DbClassorinterface> = tw.getLabelFor(classLabelResult.classLabel, {
|
||||
// If this is a generic type instantiation then it has no
|
||||
// source entity, so we need to extract it here
|
||||
if (typeArgs.isNotEmpty()) {
|
||||
this.withSourceFileOfClass(c).extractClassInstance(c, typeArgs)
|
||||
}
|
||||
|
||||
extractClassLaterIfExternal(c)
|
||||
})
|
||||
return TypeResult(
|
||||
tw.getLabelFor(classLabelResult.classLabel),
|
||||
classLabel,
|
||||
c.fqNameWhenAvailable?.asString(),
|
||||
classLabelResult.shortName)
|
||||
}
|
||||
@@ -293,7 +293,6 @@ open class KotlinUsesExtractor(
|
||||
})
|
||||
TypeResult(label, primitiveName, primitiveName)
|
||||
} else {
|
||||
extractClassLaterIfExternal(javaClass)
|
||||
addClassLabel(javaClass, listOf())
|
||||
}
|
||||
val kotlinClassId = useClassInstance(kotlinClass, listOf()).typeResult.id
|
||||
@@ -522,7 +521,6 @@ class X {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun getClassLabel(c: IrClass, typeArgs: List<IrTypeArgument>): ClassLabelResults {
|
||||
if (c.isAnonymousObject) {
|
||||
logger.warn(Severity.ErrorSevere, "Label generation should not be requested for an anonymous class")
|
||||
@@ -541,8 +539,8 @@ class X {
|
||||
}
|
||||
|
||||
// For source classes, the label doesn't include and type arguments
|
||||
val classId = getClassLabel(c, listOf())
|
||||
return tw.getLabelFor(classId.classLabel)
|
||||
val classTypeResult = addClassLabel(c, listOf())
|
||||
return classTypeResult.id
|
||||
}
|
||||
|
||||
fun getTypeParameterLabel(param: IrTypeParameter): String {
|
||||
|
||||
Reference in New Issue
Block a user