mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +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
|
// Note not using `parentsWithSelf` as that only works if `d` is an IrDeclarationParent
|
||||||
d.parents.any { (it as? IrAnnotationContainer)?.hasAnnotation(jvmWildcardSuppressionAnnotaton) == true }
|
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.
|
* 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.*
|
||||||
import com.github.codeql.utils.IrVisitorLookup
|
import com.github.codeql.utils.IrVisitorLookup
|
||||||
|
import com.github.codeql.utils.isLocalFunction
|
||||||
import com.github.codeql.utils.versions.Psi2Ir
|
import com.github.codeql.utils.versions.Psi2Ir
|
||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -104,7 +105,11 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
|||||||
val existingLabel = if (ownerIr is IrVariable) {
|
val existingLabel = if (ownerIr is IrVariable) {
|
||||||
label = "variable ${ownerIr.name.asString()}"
|
label = "variable ${ownerIr.name.asString()}"
|
||||||
tw.getExistingVariableLabelFor(ownerIr)
|
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
|
label = getLabel(ownerIr) ?: continue
|
||||||
tw.getExistingLabelFor<DbTop>(label)
|
tw.getExistingLabelFor<DbTop>(label)
|
||||||
}
|
}
|
||||||
@@ -130,7 +135,13 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
|
|||||||
when (element) {
|
when (element) {
|
||||||
is IrClass -> return fileExtractor.getClassLabel(element, listOf()).classLabel
|
is IrClass -> return fileExtractor.getClassLabel(element, listOf()).classLabel
|
||||||
is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
|
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 IrValueParameter -> return fileExtractor.getValueParameterLabel(element, null)
|
||||||
is IrProperty -> return fileExtractor.getPropertyLabel(element)
|
is IrProperty -> return fileExtractor.getPropertyLabel(element)
|
||||||
is IrField -> return fileExtractor.getFieldLabel(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
|
||||||
|
}
|
||||||
@@ -31,11 +31,11 @@ commentOwners
|
|||||||
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | getL |
|
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | getL |
|
||||||
| 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: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 |
|
||||||
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 |
|
||||||
| comments.kt:28:5:30:6 | /*\n A block comment\n */ |
|
| comments.kt:28:5:30:6 | /*\n A block comment\n */ |
|
||||||
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ |
|
|
||||||
commentSections
|
commentSections
|
||||||
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | Kdoc with no owner |
|
| 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 |
|
| 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 |
|
||||||
|
|||||||
Reference in New Issue
Block a user