aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt2
-rw-r--r--plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt12
-rw-r--r--plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt42
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt3
-rw-r--r--plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt46
5 files changed, 99 insertions, 6 deletions
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index 06bc550b..c16996a0 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -256,7 +256,7 @@ open class DefaultPageCreator(
"Constructors",
2,
ContentKind.Constructors,
- c.constructors.filter { it.extra[PrimaryConstructorExtra] == null || it.documentation.isNotEmpty() },
+ c.constructors,
c.sourceSets,
needsAnchors = true,
extra = PropertyContainer.empty<ContentNode>() + SimpleAttr.header("Constructors")
diff --git a/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt b/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt
index 92bba3c6..12160db8 100644
--- a/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt
+++ b/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt
@@ -4,6 +4,7 @@ import matchers.content.*
import org.jetbrains.dokka.pages.ContentPage
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.jupiter.api.Test
+import utils.ParamAttributes
import utils.functionSignature
class ConstructorsSignaturesTest : BaseAbstractTest() {
@@ -183,6 +184,17 @@ class ConstructorsSignaturesTest : BaseAbstractTest() {
name = "SomeClass"
)
}
+ group {
+ link { +"SomeClass" }
+ functionSignature(
+ annotations = emptyMap(),
+ visibility = "",
+ modifier = "",
+ keywords = emptySet(),
+ name = "SomeClass",
+ params = listOf("a" to ParamAttributes(emptyMap(), emptySet(), "String")).toTypedArray()
+ )
+ }
}
skipAllNotMatching()
}
diff --git a/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt b/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt
index e17f0800..a6f9af7d 100644
--- a/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt
+++ b/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt
@@ -1,9 +1,7 @@
package transformerBuilders;
import org.jetbrains.dokka.CoreExtensions
-import org.jetbrains.dokka.pages.PageNode
-import org.jetbrains.dokka.pages.RendererSpecificResourcePage
-import org.jetbrains.dokka.pages.RenderingStrategy
+import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -11,6 +9,7 @@ import org.jetbrains.dokka.transformers.pages.pageMapper
import org.jetbrains.dokka.transformers.pages.pageScanner
import org.jetbrains.dokka.transformers.pages.pageStructureTransformer
import org.junit.jupiter.api.Test
+import kotlin.test.assertEquals
class PageTransformerBuilderTest : BaseAbstractTest() {
@@ -133,6 +132,43 @@ class PageTransformerBuilderTest : BaseAbstractTest() {
}
}
+ @Test
+ fun `kotlin constructors tab should exist even though there is primary constructor only`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt
+ |package kotlinAsJavaPlugin
+ |
+ |class Test(val xd: Int)
+ """.trimMargin(),
+ configuration
+ ) {
+ pagesGenerationStage = { root ->
+ val content = root.children
+ .flatMap { it.children<ContentPage>() }
+ .map { it.content }.single().children
+ .filterIsInstance<ContentGroup>()
+ .single { it.dci.kind == ContentKind.Main }.children
+
+ val constructorTabsCount = content.filter { it is ContentHeader }.flatMap {
+ it.children.filter { it is ContentText }
+ }.count {
+ (it as? ContentText)?.text == "Constructors"
+ }
+
+ assertEquals(1, constructorTabsCount)
+ }
+ }
+ }
+
+
private fun <T> Collection<T>.assertCount(n: Int, prefix: String = "") =
assert(count() == n) { "${prefix}Expected $n, got ${count()}" }
diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
index b8e12553..531ff59f 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
@@ -26,8 +26,9 @@ class KotlinAsJavaPlugin : DokkaPlugin() {
signatureProvider providing ::JavaSignatureProvider override kotlinSignatureProvider
}
}
+
val kotlinAsJavaDocumentableToPageTranslator by extending {
CoreExtensions.documentableToPageTranslator providing ::KotlinAsJavaDocumentableToPageTranslator override
plugin<DokkaBase>().documentableToPageTranslator
}
-} \ No newline at end of file
+}
diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
index 655405b9..5fcb22aa 100644
--- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
+++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
@@ -15,6 +15,7 @@ import utils.A
import utils.Span
import utils.TestOutputWriterPlugin
import utils.match
+import kotlin.test.assertEquals
class KotlinAsJavaPluginTest : BaseAbstractTest() {
@@ -87,7 +88,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
.map { it.content }
val children = contentList.flatMap { content ->
- content.mainContents.first().cast<ContentGroup>().children
+ content.mainContents.single { it is ContentGroup }.children
.filterIsInstance<ContentTable>()
.filter { it.children.isNotEmpty() }
}
@@ -437,6 +438,49 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
}
}
}
+
+ @Test
+ fun `should render primary kotlin constructor as a java constructor`() {
+ val writerPlugin = TestOutputWriterPlugin()
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ externalDocumentationLinks = listOf(
+ DokkaConfiguration.ExternalDocumentationLink.jdk(8),
+ stdlibExternalDocumentationLink
+ )
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt
+ |package kotlinAsJavaPlugin
+ |
+ |class Test(val xd: Int)
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(writerPlugin),
+ cleanupOutput = true
+ ) {
+ pagesGenerationStage = { root ->
+ val content = root.children
+ .flatMap { it.children<ContentPage>() }
+ .map { it.content }.single().mainContents
+
+ val text = content.single { it is ContentHeader }.children
+ .single() as ContentText
+
+ assertEquals("Constructors", text.text)
+ }
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test/-test.html").signature().first().match(
+ A("Test"), A("Test"), "(", A("Integer"), "xd)", Span(), ignoreSpanWithTokenStyle = true
+ )
+ }
+ }
+ }
}
private val ContentNode.mainContents: List<ContentNode>