Merge pull request #10520 from tamasvajk/kotlin-fix-anonymous-object-comment

Kotlin: Fix comment extraction for anonymous objects
This commit is contained in:
Tamás Vajk
2022-09-27 12:42:05 +02:00
committed by GitHub
4 changed files with 34 additions and 2 deletions

View File

@@ -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> {
val fakeKotlinPackageId: Label<DbPackage> = tw.getLabelFor("@\"FakeKotlinPackage\"", {
tw.writePackages(it, "fake.kotlin")

View File

@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
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.kdoc.psi.api.KDoc
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
label = "local function ${element.name.asString()}"
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 {
label = getLabelForNamedElement(element) ?: return null
@@ -140,7 +145,12 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
private fun getLabelForNamedElement(element: IrElement) : String? {
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 IrFunction -> {
return if (element.isLocalFunction()) {