mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02: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
|
||||
|
||||
@@ -7,6 +7,7 @@ comments
|
||||
| comments.kt:28:5:30:6 | /*\n A block comment\n */ | /*\n A block comment\n */ |
|
||||
| comments.kt:35:5:35:34 | /** Medium is in the middle */ | /** Medium is in the middle */ |
|
||||
| comments.kt:37:5:37:23 | /** This is high */ | /** This is high */ |
|
||||
| comments.kt:42:5:44:6 | /**\n * A variable.\n */ | /**\n * A variable.\n */ |
|
||||
commentOwners
|
||||
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:31:1 | Group |
|
||||
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:31:1 | Group |
|
||||
@@ -16,6 +17,7 @@ commentOwners
|
||||
| comments.kt:19:5:22:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | comments.kt:23:5:26:5 | add |
|
||||
| comments.kt:35:5:35:34 | /** Medium is in the middle */ | comments.kt:36:5:36:14 | Medium |
|
||||
| comments.kt:37:5:37:23 | /** This is high */ | comments.kt:38:5:38:11 | High |
|
||||
| comments.kt:42:5:44:6 | /**\n * A variable.\n */ | comments.kt:45:5:45:13 | int a |
|
||||
commentSections
|
||||
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | Kdoc with no owner |
|
||||
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
|
||||
@@ -25,8 +27,10 @@ commentSections
|
||||
| comments.kt:19:5:22:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | Adds a [member] to this group.\n |
|
||||
| comments.kt:35:5:35:34 | /** Medium is in the middle */ | Medium is in the middle |
|
||||
| comments.kt:37:5:37:23 | /** This is high */ | This is high |
|
||||
| comments.kt:42:5:44:6 | /**\n * A variable.\n */ | A variable. |
|
||||
commentSectionContents
|
||||
| A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
|
||||
| A variable. | A variable. |
|
||||
| Adds a [member] to this group.\n | Adds a [member] to this group.\n |
|
||||
| Creates an empty group. | Creates an empty group. |
|
||||
| Kdoc with no owner | Kdoc with no owner |
|
||||
|
||||
@@ -37,3 +37,10 @@ enum class Severity(val sev: Int) {
|
||||
/** This is high */
|
||||
High(3)
|
||||
}
|
||||
|
||||
fun fn1() {
|
||||
/**
|
||||
* A variable.
|
||||
*/
|
||||
val a = 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user