mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Merge pull request #9151 from tamasvajk/kotlin-comments-variables-1
Kotlin: Handle variables as comment owners
This commit is contained in:
@@ -110,6 +110,10 @@ open class TrapWriter (protected val loggerBase: LoggerBase, val lm: TrapLabelMa
|
||||
}
|
||||
}
|
||||
|
||||
fun getExistingVariableLabelFor(v: IrVariable): Label<out DbLocalvar>? {
|
||||
return variableLabelMapping.get(v)
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a label for the location described by its arguments.
|
||||
* Typically users will not want to call this directly, but instead
|
||||
|
||||
@@ -6,9 +6,7 @@ import com.github.codeql.utils.versions.Psi2Ir
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtVisitor
|
||||
@@ -98,8 +96,14 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
||||
// Don't attribute comments to the implicit `this` parameter of a function.
|
||||
continue
|
||||
}
|
||||
val label = fileExtractor.getLabel(ownerIr) ?: continue
|
||||
val existingLabel = tw.getExistingLabelFor<DbTop>(label)
|
||||
val label: String
|
||||
val existingLabel = if (ownerIr is IrVariable) {
|
||||
label = "variable ${ownerIr.name.asString()}"
|
||||
tw.getExistingVariableLabelFor(ownerIr)
|
||||
} else {
|
||||
label = fileExtractor.getLabel(ownerIr) ?: continue
|
||||
tw.getExistingLabelFor<DbTop>(label)
|
||||
}
|
||||
if (existingLabel == null) {
|
||||
logger.warn("Couldn't get existing label for $label")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user