diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-09-23 11:47:52 +0200 |
---|---|---|
committer | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2020-10-06 15:41:04 +0200 |
commit | be932e200951e5b043f2e04e18b60176ac876156 (patch) | |
tree | a3d78c8ccf719121e062809422e0b6e936f06bcf /plugins | |
parent | 94be25b8854fd6a02adcb1c8798c9afe633b5a20 (diff) | |
download | dokka-be932e200951e5b043f2e04e18b60176ac876156.tar.gz dokka-be932e200951e5b043f2e04e18b60176ac876156.tar.bz2 dokka-be932e200951e5b043f2e04e18b60176ac876156.zip |
Addding separate pages for properties
Diffstat (limited to 'plugins')
8 files changed, 59 insertions, 7 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt index 2600884d..09eb7cc4 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt @@ -26,7 +26,7 @@ open class DefaultExternalLocationProvider( val classLink = (listOfNotNull(packageName) + classNamesChecked.split('.')) .joinToString("/", transform = ::identifierToFilename) - val callableChecked = callable ?: return "$docURL$classLink/index$extension" - return "$docURL$classLink/" + identifierToFilename(callableChecked.name) + extension + val fileName = callable?.let { identifierToFilename(it.name) } ?: "index" + return "$docURL$classLink/$fileName$extension" } } diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index a702766e..e6f92d6b 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -37,7 +37,7 @@ open class DefaultPageCreator( open fun pageForPackage(p: DPackage): PackagePageNode = PackagePageNode( p.name, contentForPackage(p), setOf(p.dri), p, p.classlikes.renameClashingClasslikes().map(::pageForClasslike) + - p.functions.map(::pageForFunction) + p.functions.map(::pageForFunction) + p.properties.mapNotNull(::pageForProperty) ) open fun pageForEnumEntry(e: DEnumEntry): ClasslikePageNode = @@ -55,7 +55,9 @@ open class DefaultPageCreator( constructors.map(::pageForFunction) + c.classlikes.renameClashingClasslikes().map(::pageForClasslike) + c.filteredFunctions.map(::pageForFunction) + + c.properties.mapNotNull(::pageForProperty) + if (c is DEnum) c.entries.map(::pageForEnumEntry) else emptyList() + ) } @@ -74,6 +76,8 @@ open class DefaultPageCreator( open fun pageForFunction(f: DFunction) = MemberPageNode(f.name, contentForFunction(f), setOf(f.dri), f) + open fun pageForProperty(p: DProperty): MemberPageNode? = MemberPageNode(p.name, contentForProperty(p), setOf(p.dri), p) + private val WithScope.filteredFunctions: List<DFunction> get() = functions.mapNotNull { function -> function.takeIf { @@ -476,6 +480,8 @@ open class DefaultPageCreator( protected open fun contentForFunction(f: DFunction) = contentForMember(f) + protected open fun contentForProperty(p: DProperty) = contentForMember(p) + protected open fun contentForMember(d: Documentable) = contentBuilder.contentFor(d) { group(kind = ContentKind.Cover) { cover(d.name.orEmpty()) diff --git a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt index bceb79ae..51817dea 100644 --- a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt +++ b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt @@ -5,6 +5,7 @@ import org.jetbrains.dokka.pages.ModulePageNode import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import kotlin.test.assertEquals class DokkaBasicTests : AbstractCoreTest() { @@ -32,7 +33,7 @@ class DokkaBasicTests : AbstractCoreTest() { ) { pagesGenerationStage = { val root = it as ModulePageNode - assertTrue(root.getClasslikeToMemberMap().filterKeys { it.name == "Test" }.entries.firstOrNull()?.value?.size == 2) + assertEquals(3, root.getClasslikeToMemberMap().filterKeys { it.name == "Test" }.entries.firstOrNull()?.value?.size) } } } diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index 9cd41dcd..3d1495fe 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.dokka.model.DEnum import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -202,7 +203,7 @@ class EnumsTest : AbstractCoreTest() { configuration ) { pagesTransformationStage = { m -> - val entryNode = m.children.first { it.name == "enums" }.children.first { it.name == "Test" }.children.first() as ClasslikePageNode + val entryNode = m.children.first { it.name == "enums" }.children.first { it.name == "Test" }.children.firstIsInstance<ClasslikePageNode>() val signature = (entryNode.content as ContentGroup).dfs { it is ContentGroup && it.dci.toString() == "[enums/Test.E1///PointingToDeclaration/][Cover]" } as ContentGroup signature.assertNode { diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt index 031d8695..ae3281a1 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt @@ -35,7 +35,7 @@ class JavadocPlugin : DokkaPlugin() { dokkaBasePlugin.querySingle { signatureProvider }, context.logger ) - } override dokkaBasePlugin.documentableToPageTranslator + } override kotinAsJavaPlugin.kotlinAsJavaDocumentableToPageTranslator } val documentableSourceSetFilter by extending { diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt index 5f06852e..04a63fca 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt @@ -4,10 +4,11 @@ import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.kotlinAsJava.signatures.JavaSignatureProvider import org.jetbrains.dokka.kotlinAsJava.transformers.KotlinAsJavaDocumentableTransformer +import org.jetbrains.dokka.kotlinAsJava.translators.KotlinAsJavaDocumentableToPageTranslator import org.jetbrains.dokka.plugability.DokkaPlugin class KotlinAsJavaPlugin : DokkaPlugin() { - val kotlinAsJavaDocumentableToPageTranslator by extending { + val kotlinAsJavaDocumentableTransformer by extending { CoreExtensions.documentableTransformer with KotlinAsJavaDocumentableTransformer() } val javaSignatureProvider by extending { @@ -16,4 +17,14 @@ class KotlinAsJavaPlugin : DokkaPlugin() { JavaSignatureProvider(ctx.single(dokkaBasePlugin.commentsToContentConverter), ctx.logger) } override dokkaBasePlugin.kotlinSignatureProvider } + val kotlinAsJavaDocumentableToPageTranslator by extending { + val dokkaBasePlugin = plugin<DokkaBase>() + CoreExtensions.documentableToPageTranslator providing { ctx -> + KotlinAsJavaDocumentableToPageTranslator( + ctx.single(dokkaBasePlugin.commentsToContentConverter), + ctx.single(dokkaBasePlugin.signatureProvider), + ctx.logger + ) + } override dokkaBasePlugin.documentableToPageTranslator + } }
\ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt new file mode 100644 index 00000000..cfb4daa3 --- /dev/null +++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaDocumentableToPageTranslator.kt @@ -0,0 +1,17 @@ +package org.jetbrains.dokka.kotlinAsJava.translators + +import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator +import org.jetbrains.dokka.model.DModule +import org.jetbrains.dokka.pages.ModulePageNode +import org.jetbrains.dokka.utilities.DokkaLogger + +class KotlinAsJavaDocumentableToPageTranslator( + private val commentsToContentConverter: CommentsToContentConverter, + private val signatureProvider: SignatureProvider, + private val logger: DokkaLogger +) : DocumentableToPageTranslator { + override fun invoke(module: DModule): ModulePageNode = + KotlinAsJavaPageCreator(commentsToContentConverter, signatureProvider, logger).pageForModule(module) +}
\ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt new file mode 100644 index 00000000..de998c55 --- /dev/null +++ b/plugins/kotlin-as-java/src/main/kotlin/translators/KotlinAsJavaPageCreator.kt @@ -0,0 +1,16 @@ +package org.jetbrains.dokka.kotlinAsJava.translators + +import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.base.translators.documentables.DefaultPageCreator +import org.jetbrains.dokka.model.DProperty +import org.jetbrains.dokka.pages.MemberPageNode +import org.jetbrains.dokka.utilities.DokkaLogger + +class KotlinAsJavaPageCreator( + commentsToContentConverter: CommentsToContentConverter, + signatureProvider: SignatureProvider, + logger: DokkaLogger +) : DefaultPageCreator(commentsToContentConverter, signatureProvider, logger) { + override fun pageForProperty(p: DProperty): MemberPageNode? = null +}
\ No newline at end of file |