diff options
Diffstat (limited to 'javadoc/src')
-rw-r--r-- | javadoc/src/main/kotlin/docbase.kt | 16 | ||||
-rw-r--r-- | javadoc/src/test/data/obj.kt | 7 | ||||
-rw-r--r-- | javadoc/src/test/data/types.kt | 4 | ||||
-rw-r--r-- | javadoc/src/test/kotlin/JavadocTest.kt | 44 |
4 files changed, 67 insertions, 4 deletions
diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt index e98e28cd..1587db2a 100644 --- a/javadoc/src/main/kotlin/docbase.kt +++ b/javadoc/src/main/kotlin/docbase.kt @@ -93,7 +93,7 @@ private fun DocumentationNode.hasModifier(name: String) = details(DocumentationN class PackageAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), PackageDoc { - private val allClasses = node.members.collectAllTypesRecursively() + private val allClasses = listOf(node).collectAllTypesRecursively() override fun findClass(className: String?): ClassDoc? = allClasses.get(className)?.let { ClassDocumentationNodeAdapter(module, it) } @@ -126,7 +126,7 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) override fun isPackagePrivate(): Boolean = false override fun isStatic(): Boolean = node.hasModifier("static") override fun modifierSpecifier(): Int = Modifier.PUBLIC + if (isStatic) Modifier.STATIC else 0 - override fun qualifiedName(): String? = node.qualifiedName() + override fun qualifiedName(): String? = if (node.kind == DocumentationNode.Kind.Type) node.qualifiedNameFromType() else node.qualifiedName() override fun annotations(): Array<out AnnotationDesc>? = nodeAnnotations(this).toTypedArray() override fun modifiers(): String? = "public ${if (isStatic) "static" else ""}".trim() override fun isProtected(): Boolean = false @@ -134,6 +134,10 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) override fun isFinal(): Boolean = node.hasModifier("final") override fun containingPackage(): PackageDoc? { + if (node.kind == DocumentationNode.Kind.Type) { + return null + } + var owner: DocumentationNode? = node while (owner != null) { if (owner.kind == DocumentationNode.Kind.Package) { @@ -146,6 +150,10 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) } override fun containingClass(): ClassDoc? { + if (node.kind == DocumentationNode.Kind.Type) { + return null + } + var owner = node.owner while (owner != null) { when (owner.kind) { @@ -166,7 +174,7 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) open class TypeAdapter(override val module: ModuleNodeAdapter, override val node: DocumentationNode) : Type, HasDocumentationNode, HasModule { private val javaLanguageService = JavaLanguageService() - override fun qualifiedTypeName(): String = javaLanguageService.getArrayElementType(node)?.qualifiedName() ?: node.qualifiedName() + override fun qualifiedTypeName(): String = javaLanguageService.getArrayElementType(node)?.qualifiedNameFromType() ?: node.qualifiedNameFromType() override fun typeName(): String = javaLanguageService.getArrayElementType(node)?.name ?: node.name override fun simpleTypeName(): String = typeName() // TODO difference typeName() vs simpleTypeName() @@ -178,7 +186,7 @@ open class TypeAdapter(override val module: ModuleNodeAdapter, override val node when (node.kind) { in DocumentationNode.Kind.classLike, DocumentationNode.Kind.ExternalClass, - DocumentationNode.Kind.Exception -> ClassDocumentationNodeAdapter(module, node) + DocumentationNode.Kind.Exception -> module.classNamed(qualifiedTypeName()) ?: ClassDocumentationNodeAdapter(module, node) else -> when { node.links.isNotEmpty() -> TypeAdapter(module, node.links.first()).asClassDoc() diff --git a/javadoc/src/test/data/obj.kt b/javadoc/src/test/data/obj.kt new file mode 100644 index 00000000..1d10a422 --- /dev/null +++ b/javadoc/src/test/data/obj.kt @@ -0,0 +1,7 @@ +package foo + +class O { + companion object { + + } +} diff --git a/javadoc/src/test/data/types.kt b/javadoc/src/test/data/types.kt new file mode 100644 index 00000000..55be6058 --- /dev/null +++ b/javadoc/src/test/data/types.kt @@ -0,0 +1,4 @@ +package foo + +fun foo(x: Int, o: Any): String { +} diff --git a/javadoc/src/test/kotlin/JavadocTest.kt b/javadoc/src/test/kotlin/JavadocTest.kt new file mode 100644 index 00000000..1ac7069b --- /dev/null +++ b/javadoc/src/test/kotlin/JavadocTest.kt @@ -0,0 +1,44 @@ +package org.jetbrains.dokka.javadoc + +import org.jetbrains.dokka.DokkaConsoleLogger +import org.jetbrains.dokka.tests.verifyModel +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +class JavadocTest { + @Test fun testTypes() { + verifyModel("javadoc/src/test/data/types.kt", format = "javadoc", withJdk = true) { model -> + val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "") + val classDoc = doc.classNamed("foo.TypesKt")!! + val method = classDoc.methods().find { it.name() == "foo" }!! + + val type = method.returnType() + assertFalse(type.asClassDoc().isIncluded) + assertEquals("java.lang.String", type.qualifiedTypeName()) + assertEquals("java.lang.String", type.asClassDoc().qualifiedName()) + + val params = method.parameters() + assertTrue(params[0].type().isPrimitive) + assertFalse(params[1].type().asClassDoc().isIncluded) + } + } + + @Test fun testObject() { + verifyModel("javadoc/src/test/data/obj.kt", format = "javadoc") { model -> + val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "") + + val classDoc = doc.classNamed("foo.O") + assertNotNull(classDoc) + + val companionDoc = doc.classNamed("foo.O.Companion") + assertNotNull(companionDoc) + + val pkgDoc = doc.packageNamed("foo")!! + assertEquals(2, pkgDoc.allClasses().size) + } + } + +} |