diff options
-rw-r--r-- | core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Languages/JavaLanguageService.kt | 21 | ||||
-rw-r--r-- | core/src/main/kotlin/Model/DocumentationNode.kt | 7 | ||||
-rw-r--r-- | core/src/main/kotlin/javadoc/docbase.kt | 2 | ||||
-rw-r--r-- | core/src/test/kotlin/javadoc/JavadocTest.kt | 12 | ||||
-rw-r--r-- | core/testdata/javadoc/bytearr.kt | 7 |
6 files changed, 42 insertions, 9 deletions
diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 5da41f29..39ad79a6 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -22,7 +22,7 @@ private fun mapTypeName(psiType: PsiType): String = when (psiType) { is PsiPrimitiveType -> psiType.canonicalText is PsiClassType -> psiType.resolve()?.qualifiedName ?: psiType.className is PsiEllipsisType -> mapTypeName(psiType.componentType) - is PsiArrayType -> "Array" + is PsiArrayType -> "kotlin.Array" else -> psiType.canonicalText } diff --git a/core/src/main/kotlin/Languages/JavaLanguageService.kt b/core/src/main/kotlin/Languages/JavaLanguageService.kt index d6f9ade5..f3b567d3 100644 --- a/core/src/main/kotlin/Languages/JavaLanguageService.kt +++ b/core/src/main/kotlin/Languages/JavaLanguageService.kt @@ -43,15 +43,24 @@ class JavaLanguageService : LanguageService { } } - fun getArrayElementType(node: DocumentationNode): DocumentationNode? = when (node.name) { - "Array" -> node.details(NodeKind.Type).singleOrNull()?.let { et -> getArrayElementType(et) ?: et } ?: DocumentationNode("Object", node.content, NodeKind.ExternalClass) - "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> DocumentationNode(node.name.removeSuffix("Array").toLowerCase(), node.content, NodeKind.Type) + fun getArrayElementType(node: DocumentationNode): DocumentationNode? = when (node.qualifiedName()) { + "kotlin.Array" -> + node.details(NodeKind.Type).singleOrNull()?.let { et -> getArrayElementType(et) ?: et } ?: DocumentationNode("Object", node.content, NodeKind.ExternalClass) + + "kotlin.IntArray", "kotlin.LongArray", "kotlin.ShortArray", "kotlin.ByteArray", + "kotlin.CharArray", "kotlin.DoubleArray", "kotlin.FloatArray", "kotlin.BooleanArray" -> + DocumentationNode(node.name.removeSuffix("Array").toLowerCase(), node.content, NodeKind.Type) + else -> null } - fun getArrayDimension(node: DocumentationNode): Int = when (node.name) { - "Array" -> 1 + (node.details(NodeKind.Type).singleOrNull()?.let { getArrayDimension(it) } ?: 0) - "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> 1 + fun getArrayDimension(node: DocumentationNode): Int = when (node.qualifiedName()) { + "kotlin.Array" -> + 1 + (node.details(NodeKind.Type).singleOrNull()?.let { getArrayDimension(it) } ?: 0) + + "kotlin.IntArray", "kotlin.LongArray", "kotlin.ShortArray", "kotlin.ByteArray", + "kotlin.CharArray", "kotlin.DoubleArray", "kotlin.FloatArray", "kotlin.BooleanArray" -> + 1 else -> 0 } diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index afa513d1..33543aff 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -168,4 +168,9 @@ fun DocumentationNode.appendTextNode(text: String, append(DocumentationNode(text, Content.Empty, kind), refKind) } -fun DocumentationNode.qualifiedName() = path.drop(1).map { it.name }.filter { it.length > 0 }.joinToString(".") +fun DocumentationNode.qualifiedName(): String { + if (kind == NodeKind.Type) { + return qualifiedNameFromType() + } + return path.drop(1).map { it.name }.filter { it.length > 0 }.joinToString(".") +} diff --git a/core/src/main/kotlin/javadoc/docbase.kt b/core/src/main/kotlin/javadoc/docbase.kt index 4298316f..795ba84a 100644 --- a/core/src/main/kotlin/javadoc/docbase.kt +++ b/core/src/main/kotlin/javadoc/docbase.kt @@ -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? = if (node.kind == NodeKind.Type) node.qualifiedNameFromType() else node.qualifiedName() + override fun qualifiedName(): String? = 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 diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index b848aaa1..54654a2c 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -47,4 +47,16 @@ class JavadocTest { assertEquals(classDoc, member!!.containingClass()) } } + + @Test fun testByteArray() { + verifyModel("testdata/javadoc/bytearr.kt", format = "javadoc", withKotlinRuntime = true) { model -> + val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "") + + val classDoc = doc.classNamed("foo.ByteArray")!! + assertNotNull(classDoc.asClassDoc()) + + val member = classDoc.methods().find { it.name() == "foo" }!! + assertEquals("[]", member.returnType().dimension()) + } + } } diff --git a/core/testdata/javadoc/bytearr.kt b/core/testdata/javadoc/bytearr.kt new file mode 100644 index 00000000..84be1a70 --- /dev/null +++ b/core/testdata/javadoc/bytearr.kt @@ -0,0 +1,7 @@ +package foo + +class ByteArray { + fun foo(): IntArray { + return intArrayOf() + } +}
\ No newline at end of file |