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

[K1] Fix KDoc and Javadoc link to a package #3490

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -18,6 +18,11 @@ internal val PsiElement.parentsWithSelf: Sequence<PsiElement>

@InternalDokkaApi
public fun DRI.Companion.from(psi: PsiElement): DRI = psi.parentsWithSelf.run {
if (psi is PsiPackage) {
return@run DRI(
packageName = psi.qualifiedName,
)
}
val psiMethod = firstIsInstanceOrNull<PsiMethod>()
val psiField = firstIsInstanceOrNull<PsiField>()
val classes = filterIsInstance<PsiClass>().filterNot { it is PsiTypeParameter }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull

internal fun DRI.Companion.from(descriptor: DeclarationDescriptor) = descriptor.parentsWithSelf.run {
if (descriptor is PackageViewDescriptor) {
return@run DRI(
packageName = descriptor.fqName.asString()
)
}
val parameter = firstIsInstanceOrNull<ValueParameterDescriptor>()
val callable = parameter?.containingDeclaration ?: firstIsInstanceOrNull<CallableDescriptor>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ class LinkTest : BaseAbstractTest() {
}

@Test
@OnlySymbols("#3455 - KDoc links to a package are unresolved ")
fun `fully qualified link should lead to package`() {
// for the test case, there is the only one link candidate in K1 and K2
val configuration = dokkaConfiguration {
Expand Down Expand Up @@ -696,7 +695,6 @@ class LinkTest : BaseAbstractTest() {
}

@Test
@OnlySymbols("#3455 - KDoc links to a package are unresolved ")
fun `short link should lead to package rather than function`() {
val configuration = dokkaConfiguration {
sourceSets {
Expand Down
22 changes: 22 additions & 0 deletions dokka-subprojects/plugin-base/src/test/kotlin/model/JavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo
import org.jetbrains.dokka.links.*
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.Param
import org.jetbrains.dokka.model.doc.See
import org.jetbrains.dokka.model.doc.Text
import utils.AbstractModelTest
import utils.assertContains
Expand Down Expand Up @@ -488,4 +489,25 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
}
}

@Test
fun `should have a link to a package in see doctag`() {
inlineModelTest(
"""
|/**
| * @see java
| */
|public class Foo {
|}
""", configuration = configuration
) {
with((this / "java" / "Foo").cast<DClass>()) {
val doc = this.documentation.values.single()
val expectedDRI = DRI(
packageName = "java", classNames = null,
target = PointingToDeclaration,
)
assertEquals(expectedDRI, (doc.dfs { it is See } as See).address)
}
}
}
}
Loading