diff options
6 files changed, 90 insertions, 25 deletions
diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt index df0c12c2..e3105918 100644 --- a/core/src/main/kotlin/pages/PageBuilder.kt +++ b/core/src/main/kotlin/pages/PageBuilder.kt @@ -62,7 +62,7 @@ open class DefaultPageBuilder( } } - fun contentForClasslike(c: Classlike): ContentGroup = when (c) { + open fun contentForClasslike(c: Classlike): ContentGroup = when (c) { is Class -> contentForClass(c) is Enum -> contentForEnum(c) else -> throw IllegalStateException("$c should not be present here") @@ -91,7 +91,7 @@ open class DefaultPageBuilder( text(it.briefDocTagString) } - block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) { + this.block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) { link(it.name, it.dri) signature(it) text(it.briefDocTagString) diff --git a/core/src/main/kotlin/pages/PageContentBuilder.kt b/core/src/main/kotlin/pages/PageContentBuilder.kt index bc01b03e..ed0a0fea 100644 --- a/core/src/main/kotlin/pages/PageContentBuilder.kt +++ b/core/src/main/kotlin/pages/PageContentBuilder.kt @@ -17,7 +17,7 @@ open class DefaultPageContentBuilder( private val styles: Set<Style> = emptySet(), private val extras: Set<Extra> = emptySet() ) : PageContentBuilder { - private val contents = mutableListOf<ContentNode>() + protected val contents = mutableListOf<ContentNode>() protected fun createText(text: String, kind: Kind = ContentKind.Symbol) = ContentText(text, DCI(dri, kind), platformData, styles, extras) diff --git a/core/src/main/kotlin/transformers/psi/DefaultPsiToDocumentationTranslator.kt b/core/src/main/kotlin/transformers/psi/DefaultPsiToDocumentationTranslator.kt index 2078faa7..144f319f 100644 --- a/core/src/main/kotlin/transformers/psi/DefaultPsiToDocumentationTranslator.kt +++ b/core/src/main/kotlin/transformers/psi/DefaultPsiToDocumentationTranslator.kt @@ -13,6 +13,8 @@ import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.idea.caches.project.getPlatformModuleInfo +import org.jetbrains.kotlin.platform.TargetPlatform object DefaultPsiToDocumentationTranslator : PsiToDocumentationTranslator { @@ -71,18 +73,20 @@ object DefaultPsiToDocumentationTranslator : PsiToDocumentationTranslator { link(superClass, node, RefKind.Inheritor) } }*/ + val inherited = emptyList<DRI>() //listOf(psi.superClass) + psi.interfaces // TODO DRIs of inherited + val actual = getComment(psi).map { ClassPlatformInfo(it, inherited) } return Class( - dri, - name.orEmpty(), - kind, - constructors.map { parseFunction(it, dri, true) }, - methods.mapNotNull { if (!it.isConstructor) parseFunction(it, dri) else null }, - fields.mapNotNull { parseField(it, dri) }, - innerClasses.map { parseClass(it, dri) }, - null, - emptyList(), - mutableSetOf(), + dri = dri, + name = name.orEmpty(), + kind = kind, + constructors = constructors.map { parseFunction(it, dri, true) }, + functions = methods.mapNotNull { if (!it.isConstructor) parseFunction(it, dri) else null }, + properties = fields.mapNotNull { parseField(it, dri) }, + classlikes = innerClasses.map { parseClass(it, dri) }, + expected = null, + actual = actual, + extra = mutableSetOf(), visibility = mapOf(platformData to psi.getVisibility()) ) } diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageBuilder.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageBuilder.kt index 67a3ee86..8f026477 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageBuilder.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageBuilder.kt @@ -3,11 +3,11 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.kotlinAsJava.conversions.asJava import org.jetbrains.dokka.kotlinAsJava.conversions.asStatic import org.jetbrains.dokka.kotlinAsJava.conversions.withClass +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Function import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.doc.TagWrapper +import org.jetbrains.dokka.model.Function import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.transformers.descriptors.KotlinClassKindTypes import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -21,8 +21,14 @@ fun <T : Documentable> List<T>.groupedByLocation(): Map<String, List<T>> = location!!.let { it.split("/").last().split(".").first() + "Kt" } }) { it.second } +fun PlatformInfo.toClassPlatformInfo(inherited: List<DRI> = emptyList()) = + ClassPlatformInfo(this, emptyList()) + class KotlinAsJavaPageBuilder(rootContentGroup: RootContentBuilder) : DefaultPageBuilder(rootContentGroup) { + override fun pageForModule(m: Module): ModulePageNode = + ModulePageNode(m.name.ifEmpty { "root" }, contentForModule(m), m, m.packages.map { pageForPackage(it) }) + data class FunsAndProps(val key: String, val funs: List<Function>, val props: List<Property>) override fun pageForPackage(p: Package): PackagePageNode { @@ -36,6 +42,8 @@ class KotlinAsJavaPageBuilder(rootContentGroup: RootContentBuilder) : DefaultPag val classes = (p.classlikes + zipped.map { (key, funs, props) -> val dri = p.dri.withClass(key) + val actual = + (funs.flatMap { it.actual } + props.flatMap { it.actual }).distinct().map { it.toClassPlatformInfo() } Class( dri = dri, name = key, @@ -44,7 +52,7 @@ class KotlinAsJavaPageBuilder(rootContentGroup: RootContentBuilder) : DefaultPag functions = funs.map { it.withClass(key, dri).asStatic() }, properties = props.map { it.withClass(key, dri) }, classlikes = emptyList(), - actual = emptyList(), + actual = actual, expected = null, visibility = p.platformData.map { it to Visibilities.PUBLIC }.toMap() ) @@ -64,5 +72,9 @@ class KotlinAsJavaPageBuilder(rootContentGroup: RootContentBuilder) : DefaultPag } } - private fun TagWrapper.toHeaderString() = this.javaClass.toGenericString().split('.').last() + override fun contentForClasslike(c: Classlike): ContentGroup = when (c) { + is Class -> contentForClass(c) + is Enum -> contentForEnum(c) + else -> throw IllegalStateException("$c should not be present here") + } }
\ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt index 65925fb2..05896d11 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt @@ -1,10 +1,7 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.Function -import org.jetbrains.dokka.model.TypeWrapper -import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.transformers.psi.JavaTypeWrapper import org.jetbrains.dokka.utilities.DokkaLogger @@ -18,10 +15,10 @@ class KotlinAsJavaPageContentBuilder( private val styles: Set<Style> = emptySet(), private val extras: Set<Extra> = emptySet() ) : DefaultPageContentBuilder(dri, platformData, kind, commentsConverter, logger, styles, extras) { - private val contents = mutableListOf<ContentNode>() override fun signature(f: Function) = signature(f) { + // DokkaConsoleLogger.info("KotlinAsJavaSignature") val returnType = f.returnType if (!f.isConstructor) { if (returnType != null && @@ -51,6 +48,13 @@ class KotlinAsJavaPageContentBuilder( text(")") } + override fun group( + dri: Set<DRI>, + platformData: Set<PlatformData>, + kind: Kind, + block: PageContentBuilderFunction + ): ContentGroup = group(dri, platformData, kind, commentsConverter, logger, block) + companion object { fun group( dri: Set<DRI>, diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index c0833293..6186283f 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -1,6 +1,5 @@ package kotlinAsJavaPlugin -import junit.framework.Assert.fail import org.jetbrains.dokka.pages.ContentGroup import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.ContentTable @@ -10,6 +9,8 @@ import testApi.testRunner.AbstractCoreTest class KotlinAsJavaPluginTest : AbstractCoreTest() { + fun fail(msg: String) = assert(false) { msg } + @Test fun topLevelTest() { val configuration = dokkaConfiguration { @@ -37,7 +38,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { cleanupOutput = true ) { pagesGenerationStage = { root -> - val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage )?.content ?: run { + val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage)?.content ?: run { fail("Either children or content is null") } @@ -92,7 +93,51 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { } } - private fun <T> Collection<T>.assertCount(n: Int) = - assert(count() == n) { "Expected $n, got ${count()}" } + @Test + fun kotlinAndJavaTest() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |fun testF(i: Int) = i + |/src/main/kotlin/kotlinAsJavaPlugin/TestJ.java + |package kotlinAsJavaPlugin + | + |class TestJ { + | int testF(int i) { return i; } + |} + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val classes = root.children.first().children.associateBy { it.name } + classes.values.assertCount(2, "Class count: ") + + classes["TestKt"].let { + it?.children.orEmpty().assertCount(1, "(Kotlin) TestKt members: ") + it!!.children.first() + .let { assert(it.name == "testF") { "(Kotlin) Expected method name: testF, got: ${it.name}" } } + } + + classes["TestJ"].let { + it?.children.orEmpty().assertCount(1, "(Java) TestJ members: ") + it!!.children.first() + .let { assert(it.name == "testF") { "(Java) Expected method name: testF, got: ${it.name}" } } + } + } + } + } + + private fun <T> Collection<T>.assertCount(n: Int, prefix: String = "") = + assert(count() == n) { "${prefix}Expected $n, got ${count()}" } }
\ No newline at end of file |