mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Kotlin: Fix comment extraction for anonymous objects
This commit is contained in:
@@ -461,6 +461,14 @@ open class KotlinUsesExtractor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getExistingAnonymousClassLabel(c: IrClass): Label<out DbType>? {
|
||||||
|
if (!c.isAnonymousObject){
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return tw.lm.anonymousTypeMapping[c]?.javaResult?.id
|
||||||
|
}
|
||||||
|
|
||||||
fun fakeKotlinType(): Label<out DbKt_type> {
|
fun fakeKotlinType(): Label<out DbKt_type> {
|
||||||
val fakeKotlinPackageId: Label<DbPackage> = tw.getLabelFor("@\"FakeKotlinPackage\"", {
|
val fakeKotlinPackageId: Label<DbPackage> = tw.getLabelFor("@\"FakeKotlinPackage\"", {
|
||||||
tw.writePackages(it, "fake.kotlin")
|
tw.writePackages(it, "fake.kotlin")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.IrElement
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
|
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
||||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
@@ -126,6 +127,10 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
|||||||
// local functions are not named globally, so we need to get them from the local function label cache
|
// local functions are not named globally, so we need to get them from the local function label cache
|
||||||
label = "local function ${element.name.asString()}"
|
label = "local function ${element.name.asString()}"
|
||||||
fileExtractor.getExistingLocallyVisibleFunctionLabel(element)
|
fileExtractor.getExistingLocallyVisibleFunctionLabel(element)
|
||||||
|
} else if (element is IrClass && element.isAnonymousObject) {
|
||||||
|
// anonymous objects are not named globally, so we need to get them from the cache
|
||||||
|
label = "anonymous class ${element.name.asString()}"
|
||||||
|
fileExtractor.getExistingAnonymousClassLabel(element)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
label = getLabelForNamedElement(element) ?: return null
|
label = getLabelForNamedElement(element) ?: return null
|
||||||
@@ -140,7 +145,12 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
|||||||
|
|
||||||
private fun getLabelForNamedElement(element: IrElement) : String? {
|
private fun getLabelForNamedElement(element: IrElement) : String? {
|
||||||
when (element) {
|
when (element) {
|
||||||
is IrClass -> return fileExtractor.getClassLabel(element, listOf()).classLabel
|
is IrClass ->
|
||||||
|
return if (element.isAnonymousObject) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
fileExtractor.getClassLabel(element, listOf()).classLabel
|
||||||
|
}
|
||||||
is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
|
is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
|
||||||
is IrFunction -> {
|
is IrFunction -> {
|
||||||
return if (element.isLocalFunction()) {
|
return if (element.isLocalFunction()) {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ commentOwners
|
|||||||
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | l |
|
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | l |
|
||||||
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ | comments.kt:82:9:82:24 | localFn |
|
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ | comments.kt:82:9:82:24 | localFn |
|
||||||
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | comments.kt:87:15:92:5 | |
|
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | comments.kt:87:15:92:5 | |
|
||||||
|
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | comments.kt:87:15:92:5 | new X(...) { ... } |
|
||||||
commentNoOwners
|
commentNoOwners
|
||||||
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ |
|
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ |
|
||||||
| comments.kt:24:9:24:25 | // A line comment |
|
| comments.kt:24:9:24:25 | // A line comment |
|
||||||
|
|||||||
Reference in New Issue
Block a user