Kotlin: Fix File locations, and fromSource/hasSourceLocation for Kotlin code

This commit is contained in:
Ian Lynagh
2021-10-21 20:52:15 +01:00
parent b9359bd119
commit 14a10564f3
6 changed files with 10 additions and 5 deletions

View File

@@ -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)

View File

@@ -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