From 50e711d24b517bc93c37d89f258c9dafaa038ad1 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Mon, 20 Jan 2020 14:55:42 +0100 Subject: kotlin-as-java plugin --- core/src/main/kotlin/model/Documentable.kt | 52 ++++-- core/src/main/kotlin/pages/PageBuilder.kt | 12 +- core/src/main/kotlin/pages/PageContentBuilder.kt | 12 +- .../DefaultDescriptorToDocumentationTranslator.kt | 192 +++++++++++++++------ .../DefaultDocumentationNodeMerger.kt | 13 +- .../psi/DefaultPsiToDocumentationTranslator.kt | 46 ++++- 6 files changed, 232 insertions(+), 95 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 86ba24b7..1744e27f 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -4,7 +4,9 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.transformers.descriptors.KotlinClassKindTypes -import org.jetbrains.dokka.transformers.descriptors.KotlinTypeWrapper +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility class Module(override val name: String, val packages: List) : Documentable() { override val dri: DRI = DRI.topLevel @@ -32,7 +34,8 @@ class Class( override val classlikes: List, override val expected: ClassPlatformInfo?, override val actual: List, - override val extra: MutableSet = mutableSetOf() + override val extra: MutableSet = mutableSetOf(), + override val visibility: Map ) : Classlike( name = name, dri = dri, @@ -43,7 +46,7 @@ class Class( expected = expected, actual = actual, extra = extra -) +), WithVisibility class Enum( override val dri: DRI, @@ -55,8 +58,9 @@ class Enum( override val classlikes: List = emptyList(), override val expected: ClassPlatformInfo? = null, override val actual: List, - override val extra: MutableSet = mutableSetOf() -) : Classlike(dri = dri, name = name, kind = KotlinClassKindTypes.ENUM_CLASS, actual = actual) { + override val extra: MutableSet = mutableSetOf(), + override val visibility: Map +) : Classlike(dri = dri, name = name, kind = KotlinClassKindTypes.ENUM_CLASS, actual = actual), WithVisibility { constructor(c: Classlike, entries: List, ctors: List) : this( dri = c.dri, name = c.name, @@ -67,7 +71,8 @@ class Enum( classlikes = c.classlikes, expected = c.expected, actual = c.actual, - extra = c.extra + extra = c.extra, + visibility = c.visibility ) override val children: List @@ -79,7 +84,8 @@ class EnumEntry( override val name: String, override val expected: ClassPlatformInfo? = null, override val actual: List, - override val extra: MutableSet = mutableSetOf() + override val extra: MutableSet = mutableSetOf(), + override val visibility: Map ) : Classlike( dri = dri, name = name, @@ -93,7 +99,8 @@ class EnumEntry( name = c.name, actual = c.actual, expected = c.expected, - extra = c.extra + extra = c.extra, + visibility = c.visibility ) override val children: List @@ -109,8 +116,9 @@ class Function( val parameters: List, override val expected: PlatformInfo?, override val actual: List, - override val extra: MutableSet = mutableSetOf() -) : CallableNode() { + override val extra: MutableSet = mutableSetOf(), + override val visibility: Map +) : CallableNode(), WithVisibility { override val children: List get() = listOfNotNull(receiver) + parameters } @@ -121,8 +129,10 @@ class Property( override val receiver: Parameter?, override val expected: PlatformInfo?, override val actual: List, - override val extra: MutableSet = mutableSetOf() -) : CallableNode() { + override val extra: MutableSet = mutableSetOf(), + val accessors: List, + override val visibility: Map +) : CallableNode(), WithVisibility { override val children: List get() = listOfNotNull(receiver) } @@ -208,7 +218,7 @@ abstract class Classlike( override val expected: ClassPlatformInfo? = null, override val actual: List, override val extra: MutableSet = mutableSetOf() -) : ScopeNode() { +) : ScopeNode(), WithVisibility { val inherited by lazy { platformInfo.mapNotNull { (it as? ClassPlatformInfo)?.inherited }.flatten() } } @@ -217,8 +227,12 @@ abstract class ScopeNode : Documentable() { abstract val properties: List abstract val classlikes: List - override val children: List - get() = functions + properties + classlikes + override val children: List // It is written so awkwardly because of type inference being lost here + get() = mutableListOf().apply { + addAll(functions) + addAll(properties) + addAll(classlikes) + } } abstract class CallableNode : Documentable() { @@ -235,6 +249,7 @@ interface TypeWrapper { val arguments: List val dri: DRI? } + interface ClassKind fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = @@ -244,4 +259,9 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } -interface Extra \ No newline at end of file +interface Extra +object STATIC : Extra + +interface WithVisibility { + val visibility: Map +} \ No newline at end of file diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt index 7fe07ae4..df0c12c2 100644 --- a/core/src/main/kotlin/pages/PageBuilder.kt +++ b/core/src/main/kotlin/pages/PageBuilder.kt @@ -5,7 +5,7 @@ import org.jetbrains.dokka.model.Enum import org.jetbrains.dokka.model.Function import org.jetbrains.dokka.model.doc.TagWrapper -class DefaultPageBuilder( +open class DefaultPageBuilder( override val rootContentGroup: RootContentBuilder ) : PageBuilder { @@ -37,10 +37,10 @@ class DefaultPageBuilder( else -> throw IllegalStateException("$m should not be present here") } - private fun group(node: Documentable, content: PageContentBuilderFunction) = + protected open fun group(node: Documentable, content: PageContentBuilderFunction) = rootContentGroup(node, ContentKind.Main, content) - private fun contentForModule(m: Module) = group(m) { + protected open fun contentForModule(m: Module) = group(m) { header(1) { text("root") } block("Packages", 2, ContentKind.Packages, m.packages, m.platformData) { link(it.name, it.dri) @@ -49,7 +49,7 @@ class DefaultPageBuilder( text("Link to allpage here") } - private fun contentForPackage(p: Package) = group(p) { + protected open fun contentForPackage(p: Package) = group(p) { header(1) { text("Package ${p.name}") } block("Types", 2, ContentKind.Properties, p.classlikes, p.platformData) { link(it.name, it.dri) @@ -62,13 +62,13 @@ class DefaultPageBuilder( } } - private fun contentForClasslike(c: Classlike): ContentGroup = when (c) { + fun contentForClasslike(c: Classlike): ContentGroup = when (c) { is Class -> contentForClass(c) is Enum -> contentForEnum(c) else -> throw IllegalStateException("$c should not be present here") } - private fun contentForClass(c: Class) = group(c) { + protected fun contentForClass(c: Class) = group(c) { header(1) { text(c.name) } c.inherited.takeIf { it.isNotEmpty() }?.let { diff --git a/core/src/main/kotlin/pages/PageContentBuilder.kt b/core/src/main/kotlin/pages/PageContentBuilder.kt index d5ffe27a..bc01b03e 100644 --- a/core/src/main/kotlin/pages/PageContentBuilder.kt +++ b/core/src/main/kotlin/pages/PageContentBuilder.kt @@ -8,21 +8,21 @@ import org.jetbrains.dokka.model.TypeWrapper import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.utilities.DokkaLogger -class DefaultPageContentBuilder( +open class DefaultPageContentBuilder( private val dri: Set, private val platformData: Set, private val kind: Kind, private val commentsConverter: CommentsToContentConverter, - val logger: DokkaLogger, + open val logger: DokkaLogger, private val styles: Set