Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K2] Fix missed KDoc for members without sources #3708

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -96,10 +96,8 @@ internal fun KaSession.findKDoc(symbol: KaSymbol): KDocContent? {
}

// for generated function (e.g. `copy`) [KtSymbol.psi] is undefined (although actually returns a class psi), see test `data class kdocs over generated methods`
if (symbol.origin != KaSymbolOrigin.SOURCE) return null


val ktElement = symbol.psi as? KtElement
// for DELEGATED/INTERSECTION_OVERRIDE/SUBSTITUTION_OVERRIDE members, it continues search in overridden symbols
val ktElement = if (symbol.origin == KaSymbolOrigin.SOURCE) symbol.psi as? KtElement else null
ktElement?.findKDoc()?.let {
return it
}
Original file line number Diff line number Diff line change
@@ -5,8 +5,11 @@
package model

import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.analysis.kotlin.markdown.MARKDOWN_ELEMENT_FILE_NAME
import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.CustomDocTag
import org.jetbrains.dokka.model.doc.Description
import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.model.doc.Text
import utils.AbstractModelTest
@@ -608,4 +611,76 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt",
}
}
}

@Test
fun `substitution override (fake override) should have KDoc`() {
inlineModelTest(
"""
|open class Job<T> {
| /** some doc */
| open fun do1(p: T) = p
| /** some doc */
| var p: T? = null
|}
|class GoodJob : Job<Int>()
"""
) {
with((this / "inheritors" / "GoodJob" / "do1").cast<DFunction>()) {
name equals "do1"
documentation.values.single().children.first() equals Description(
CustomDocTag(
children = listOf(
P(
children = listOf(Text(body = "some doc"))
)
), name = MARKDOWN_ELEMENT_FILE_NAME
)
)
}
with((this / "inheritors" / "GoodJob" / "p").cast<DProperty>()) {
name equals "p"
documentation.values.single().children.first() equals Description(
CustomDocTag(
children = listOf(
P(
children = listOf(Text(body = "some doc"))
)
), name = MARKDOWN_ELEMENT_FILE_NAME
)
)
}
}
}

@Test
fun `members implemented by delegation should inherit KDoc`() {
inlineModelTest(
"""
|interface CookieJar {
| /**
| * Saves cookies
| */
| fun saveFromResponse(url: String)
|}
|
|class JavaNetCookieJar private constructor(
| delegate: CookieJarImpl,
|) : CookieJar by delegate
""".trimMargin()
) {
with((this / "inheritors" / "JavaNetCookieJar"/ "saveFromResponse").cast<DFunction>()) {
name equals "saveFromResponse"
documentation.values.single().children.first() equals Description(
CustomDocTag(
children = listOf(
P(
children = listOf(Text(body = "Saves cookies"))
)
), name = MARKDOWN_ELEMENT_FILE_NAME
)
)
}
}
}

}
Loading