mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
CommentExtractor: use actual file label instead of hopefully correctly guessing its string form
This commit is contained in:
committed by
Ian Lynagh
parent
bb7e01988a
commit
fdb1668cff
@@ -51,7 +51,7 @@ open class KotlinFileExtractor(
|
||||
tw.writeHasLocation(id, locId)
|
||||
tw.writeCupackage(id, pkgId)
|
||||
file.declarations.map { extractDeclaration(it) }
|
||||
CommentExtractor(this, file).extract()
|
||||
CommentExtractor(this, file, tw.fileId).extract()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ open class KotlinFileExtractor(
|
||||
|
||||
fun getLabel(element: IrElement) : String? {
|
||||
when (element) {
|
||||
is IrFile -> return "@\"${element.path};sourcefile\"" // todo: remove copy-pasted code
|
||||
is IrClass -> return getClassLabel(element, listOf()).classLabel
|
||||
is IrTypeParameter -> return getTypeParameterLabel(element)
|
||||
is IrFunction -> return getFunctionLabel(element, null)
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtVisitor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private val file: IrFile) {
|
||||
class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private val file: IrFile, private val fileLabel: Label<out DbFile>) {
|
||||
private val tw = fileExtractor.tw
|
||||
private val logger = fileExtractor.logger
|
||||
private val ktFile = Psi2Ir().getKtFile(file)
|
||||
@@ -89,14 +89,19 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
||||
file.accept(IrVisitorLookup(ownerPsi, file), owners)
|
||||
|
||||
for (ownerIr in owners) {
|
||||
val label = fileExtractor.getLabel(ownerIr) ?: continue
|
||||
val existingLabel = tw.getExistingLabelFor<DbTop>(label)
|
||||
if (existingLabel == null) {
|
||||
logger.warn(Severity.Warn, "Couldn't get existing label for $label")
|
||||
continue
|
||||
}
|
||||
|
||||
tw.writeKtCommentOwners(commentLabel, existingLabel)
|
||||
val ownerLabel =
|
||||
if (ownerIr == file)
|
||||
fileLabel
|
||||
else {
|
||||
val label = fileExtractor.getLabel(ownerIr) ?: continue
|
||||
val existingLabel = tw.getExistingLabelFor<DbTop>(label)
|
||||
if (existingLabel == null) {
|
||||
logger.warn(Severity.Warn, "Couldn't get existing label for $label")
|
||||
continue
|
||||
}
|
||||
existingLabel
|
||||
}
|
||||
tw.writeKtCommentOwners(commentLabel, ownerLabel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user