mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Kotlin: fix doc comment extraction for local functions
This commit is contained in:
@@ -1121,10 +1121,6 @@ open class KotlinUsesExtractor(
|
||||
// Note not using `parentsWithSelf` as that only works if `d` is an IrDeclarationParent
|
||||
d.parents.any { (it as? IrAnnotationContainer)?.hasAnnotation(jvmWildcardSuppressionAnnotaton) == true }
|
||||
|
||||
protected fun IrFunction.isLocalFunction(): Boolean {
|
||||
return this.visibility == DescriptorVisibilities.LOCAL
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold labels for generated classes around local functions, lambdas, function references, and property references.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.github.codeql.comments
|
||||
|
||||
import com.github.codeql.*
|
||||
import com.github.codeql.utils.IrVisitorLookup
|
||||
import com.github.codeql.utils.isLocalFunction
|
||||
import com.github.codeql.utils.versions.Psi2Ir
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -104,7 +105,11 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
||||
val existingLabel = if (ownerIr is IrVariable) {
|
||||
label = "variable ${ownerIr.name.asString()}"
|
||||
tw.getExistingVariableLabelFor(ownerIr)
|
||||
} else {
|
||||
} else if (ownerIr is IrFunction && ownerIr.isLocalFunction()) {
|
||||
label = "local function ${ownerIr.name.asString()}"
|
||||
fileExtractor.getLocallyVisibleFunctionLabels(ownerIr).function
|
||||
}
|
||||
else {
|
||||
label = getLabel(ownerIr) ?: continue
|
||||
tw.getExistingLabelFor<DbTop>(label)
|
||||
}
|
||||
@@ -130,7 +135,13 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
||||
when (element) {
|
||||
is IrClass -> return fileExtractor.getClassLabel(element, listOf()).classLabel
|
||||
is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
|
||||
is IrFunction -> return fileExtractor.getFunctionLabel(element, null)
|
||||
is IrFunction -> {
|
||||
return if (element.isLocalFunction()) {
|
||||
null
|
||||
} else {
|
||||
fileExtractor.getFunctionLabel(element, null)
|
||||
}
|
||||
}
|
||||
is IrValueParameter -> return fileExtractor.getValueParameterLabel(element, null)
|
||||
is IrProperty -> return fileExtractor.getPropertyLabel(element)
|
||||
is IrField -> return fileExtractor.getFieldLabel(element)
|
||||
|
||||
8
java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt
Normal file
8
java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.github.codeql.utils
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
|
||||
fun IrFunction.isLocalFunction(): Boolean {
|
||||
return this.visibility == DescriptorVisibilities.LOCAL
|
||||
}
|
||||
Reference in New Issue
Block a user