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
Fix incorrect handling of static members used within @see
tag
#2627
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentCon | |
import org.jetbrains.dokka.base.transformers.pages.tags.CustomTagContentProvider | ||
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder.DocumentableContentBuilder | ||
import org.jetbrains.dokka.links.DRI | ||
import org.jetbrains.dokka.links.PointingToDeclaration | ||
import org.jetbrains.dokka.model.* | ||
import org.jetbrains.dokka.model.doc.* | ||
import org.jetbrains.dokka.model.properties.PropertyContainer | ||
|
@@ -590,26 +591,31 @@ open class DefaultPageCreator( | |
availablePlatforms.forEach { platform -> | ||
val possibleFallbacks = sourceSets.getPossibleFallbackSourcesets(platform) | ||
seeAlsoTags.forEach { (_, see) -> | ||
(see[platform] ?: see.fallback(possibleFallbacks))?.let { | ||
(see[platform] ?: see.fallback(possibleFallbacks))?.let { seeTag -> | ||
row( | ||
sourceSets = setOf(platform), | ||
kind = ContentKind.Comment, | ||
styles = this@group.mainStyles, | ||
) { | ||
it.address?.let { dri -> | ||
seeTag.address?.let { dri -> | ||
// only declaration links are expected to be fully qualified | ||
val linkText = dri.takeIf { it.target is PointingToDeclaration } | ||
?.let { seeTag.name.removePrefix("${it.packageName}.") } | ||
?: seeTag.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out, |
||
|
||
link( | ||
dri.classNames ?: it.name, | ||
dri, | ||
text = linkText, | ||
address = dri, | ||
kind = ContentKind.Comment, | ||
styles = mainStyles + ContentStyle.RowTitle | ||
) | ||
} ?: text( | ||
it.name, | ||
text = seeTag.name, | ||
kind = ContentKind.Comment, | ||
styles = mainStyles + ContentStyle.RowTitle | ||
) | ||
if (it.isNotEmpty()) { | ||
comment(it.root) | ||
if (seeTag.isNotEmpty()) { | ||
comment(seeTag.root) | ||
} | ||
} | ||
} | ||
|
@@ -639,7 +645,8 @@ open class DefaultPageCreator( | |
row(sourceSets = setOf(sourceset)) { | ||
group(styles = mainStyles + ContentStyle.RowTitle) { | ||
throws.exceptionAddress?.let { | ||
link(text = it.classNames ?: entry.key, address = it) | ||
val className = it.takeIf { it.target is PointingToDeclaration }?.classNames | ||
link(text = className ?: entry.key, address = it) | ||
} ?: text(entry.key) | ||
} | ||
if (throws.isNotEmpty()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,76 +517,73 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { | |
} | ||
|
||
@Test | ||
fun `undocumented see also from java`(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved two tests to |
||
fun `should prefix static function and property links with class name`() { | ||
testInline( | ||
""" | ||
|/src/main/java/example/Source.java | ||
|package example; | ||
|/src/main/kotlin/com/example/package/CollectionExtensions.kt | ||
|package com.example.util | ||
| | ||
|public interface Source { | ||
| String getProperty(String k, String v); | ||
| | ||
| /** | ||
| * @see #getProperty(String, String) | ||
| */ | ||
| String getProperty(String k); | ||
|object CollectionExtensions { | ||
| val property = "Hi" | ||
| fun emptyList() {} | ||
|} | ||
""".trimIndent(), testConfiguration | ||
) { | ||
documentablesTransformationStage = { module -> | ||
val functionWithSeeTag = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.find { it.name == "getProperty" && it.parameters.count() == 1 } | ||
val seeTag = functionWithSeeTag?.docs()?.firstIsInstanceOrNull<See>() | ||
val expectedLinkDestinationDRI = DRI( | ||
packageName = "example", | ||
classNames = "Source", | ||
callable = Callable( | ||
name = "getProperty", | ||
params = listOf(JavaClassReference("java.lang.String"), JavaClassReference("java.lang.String")) | ||
) | ||
) | ||
|
||
kotlin.test.assertNotNull(seeTag) | ||
assertEquals("getProperty(String, String)", seeTag.name) | ||
assertEquals(expectedLinkDestinationDRI, seeTag.address) | ||
assertEquals(emptyList(), seeTag.children) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `documented see also from java`(){ | ||
testInline( | ||
""" | ||
|/src/main/java/example/Source.java | ||
|package example; | ||
| | ||
|public interface Source { | ||
| String getProperty(String k, String v); | ||
|/src/main/kotlin/com/example/foo.kt | ||
|package com.example | ||
| | ||
| /** | ||
| * @see #getProperty(String, String) this is a reference to a method that is present on the same class. | ||
| */ | ||
| String getProperty(String k); | ||
|} | ||
""".trimIndent(), testConfiguration | ||
|import com.example.util.CollectionExtensions.property | ||
|import com.example.util.CollectionExtensions.emptyList | ||
| | ||
|/** | ||
| * @see [property] static property | ||
| * @see [emptyList] static emptyList | ||
| */ | ||
|fun function() {} | ||
""".trimIndent(), | ||
testConfiguration | ||
) { | ||
documentablesTransformationStage = { module -> | ||
val functionWithSeeTag = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.find { it.name == "getProperty" && it.parameters.size == 1 } | ||
val seeTag = functionWithSeeTag?.docs()?.firstIsInstanceOrNull<See>() | ||
val expectedLinkDestinationDRI = DRI( | ||
packageName = "example", | ||
classNames = "Source", | ||
callable = Callable( | ||
name = "getProperty", | ||
params = listOf(JavaClassReference("java.lang.String"), JavaClassReference("java.lang.String")) | ||
) | ||
) | ||
pagesTransformationStage = { module -> | ||
val page = module.children.single { it.name == "com.example" } | ||
.children.single { it.name == "function" } as ContentPage | ||
|
||
kotlin.test.assertNotNull(seeTag) | ||
assertEquals("getProperty(String, String)", seeTag.name) | ||
assertEquals(expectedLinkDestinationDRI, seeTag.address) | ||
assertEquals("this is a reference to a method that is present on the same class.", seeTag.children.first().text().trim()) | ||
assertEquals(1, seeTag.children.size) | ||
page.content.assertNode { | ||
group { | ||
header(1) { +"function" } | ||
} | ||
divergentGroup { | ||
divergentInstance { | ||
divergent { | ||
bareSignature( | ||
annotations = emptyMap(), | ||
visibility = "", | ||
modifier = "", | ||
keywords = emptySet(), | ||
name = "function", | ||
returnType = null, | ||
) | ||
} | ||
after { | ||
header(4) { +"See also" } | ||
group { | ||
table { | ||
group { | ||
link { +"CollectionExtensions.property" } | ||
group { | ||
group { +"static property" } | ||
} | ||
} | ||
group { | ||
link { +"CollectionExtensions.emptyList" } | ||
group { | ||
group { +"static emptyList" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall problem is basically here.
For
com.example.Object.function()
it would returncom.example.Object
, so if you have multiple@see
tags that point to multiple different functions from the sameobject
- there would be name collisions, and some members would be discarded bygroupBy
further down the road.This function is overall very wrong, and it would take a lot of effort to make it right