mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Kotlin: Fix File locations, and fromSource/hasSourceLocation for Kotlin code
This commit is contained in:
@@ -166,8 +166,10 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
|
||||
}
|
||||
|
||||
fun extractFileContents(id: Label<DbFile>) {
|
||||
val locId = tw.getWholeFileLocation()
|
||||
val pkg = file.fqName.asString()
|
||||
val pkgId = extractPackage(pkg)
|
||||
tw.writeHasLocation(id, locId)
|
||||
tw.writeCupackage(id, pkgId)
|
||||
file.declarations.map { extractDeclaration(it) }
|
||||
CommentExtractor(this).extract()
|
||||
@@ -198,7 +200,7 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
|
||||
val qualClassName = if (pkg.isEmpty()) jvmName else "$pkg.$jvmName"
|
||||
val label = "@\"class;$qualClassName\""
|
||||
val id: Label<DbClass> = tw.getLabelFor(label)
|
||||
val locId = tw.getLocation(-1, -1) // TODO: This should be the whole file
|
||||
val locId = tw.getWholeFileLocation()
|
||||
val pkgId = extractPackage(pkg)
|
||||
tw.writeClasses(id, jvmName, pkgId, id)
|
||||
tw.writeHasLocation(id, locId)
|
||||
|
||||
@@ -77,6 +77,9 @@ class FileTrapWriter (
|
||||
fun getLocation(e: IrElement): Label<DbLocation> {
|
||||
return getLocation(e.startOffset, e.endOffset)
|
||||
}
|
||||
fun getWholeFileLocation(): Label<DbLocation> {
|
||||
return getLocation(fileId, 0, 0, 0, 0)
|
||||
}
|
||||
fun getLocation(startOffset: Int, endOffset: Int): Label<DbLocation> {
|
||||
// If the compiler doesn't have a location, then start and end are both -1
|
||||
val unknownLoc = startOffset == -1 && endOffset == -1
|
||||
|
||||
Reference in New Issue
Block a user