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

Do not render constructor pages and blocks and for annotation classes #2642

Merged
merged 1 commit into from Aug 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -96,7 +96,12 @@ open class DefaultPageCreator(
}
}

val constructors = documentables.flatMap { if (it is WithConstructors) it.constructors else emptyList() }
val constructors =
if (documentables.shouldRenderConstructors()) {
documentables.flatMap { (it as? WithConstructors)?.constructors ?: emptyList() }
} else {
emptyList()
}

val classlikes = documentables.flatMap { it.classlikes }
val functions = documentables.flatMap { it.filteredFunctions }
Expand Down Expand Up @@ -366,7 +371,7 @@ open class DefaultPageCreator(
group(styles = setOf(ContentStyle.TabbedContent), sourceSets = mainSourcesetData + extensions.sourceSets) {
+contentForComments(documentables)
val csWithConstructor = classlikes.filterIsInstance<WithConstructors>()
if (csWithConstructor.isNotEmpty()) {
if (csWithConstructor.isNotEmpty() && documentables.shouldRenderConstructors()) {
val constructorsToDocumented = csWithConstructor.flatMap { it.constructors }
multiBlock(
"Constructors",
Expand Down Expand Up @@ -432,6 +437,11 @@ open class DefaultPageCreator(
}
}

// Annotations might have constructors to substitute reflection invocations
// and for internal/compiler purposes, but they are not expected to be documented
// and instantiated directly under normal circumstances, so constructors should not be rendered.
private fun List<Documentable>.shouldRenderConstructors() = !this.any { it is DAnnotation }

@Suppress("UNCHECKED_CAST")
private inline fun <reified T : TagWrapper> GroupedTags.withTypeUnnamed(): SourceSetDependent<T> =
(this[T::class] as List<Pair<DokkaSourceSet, T>>?)?.toMap().orEmpty()
Expand Down
Expand Up @@ -293,4 +293,49 @@ class ConstructorsSignaturesTest : BaseAbstractTest() {
}
}
}

@Test
fun `should render primary constructor, but not constructors block for annotation class`() {
testInline(
"""
|/src/main/kotlin/test/source.kt
|package test
|
|annotation class MyAnnotation(val param: String) {}
""".trimIndent(),
testConfiguration
) {
pagesTransformationStage = { module ->
val page = module.children.single { it.name == "test" }
.children.single { it.name == "MyAnnotation" } as ContentPage
page.content.assertNode {
group {
header(1) { +"MyAnnotation" }
platformHinted {
group {
+"annotation class "
link { +"MyAnnotation" }
+"("
group {
group {
+"val param: "
group { link { +"String" } }
}
}
+")"
}
}
}
group {
group {
header { +"Properties" }
table {
skipAllNotMatching()
}
}
}
}
}
}
}
}