diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-10-29 18:45:33 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-10-29 18:46:41 +0300 |
commit | b9fa0e0741bfdfa76c3929e5343a2b19d96fc1ff (patch) | |
tree | 09a07123c9c6437333f9faad7f4e1c2154aa07f2 | |
parent | 8f32ef92be19c88f1a26d3ce19f77c9e1d053d8d (diff) | |
download | dokka-b9fa0e0741bfdfa76c3929e5343a2b19d96fc1ff.tar.gz dokka-b9fa0e0741bfdfa76c3929e5343a2b19d96fc1ff.tar.bz2 dokka-b9fa0e0741bfdfa76c3929e5343a2b19d96fc1ff.zip |
#361: Fix varargs
Fix #361
-rw-r--r-- | core/src/main/kotlin/javadoc/docbase.kt | 6 | ||||
-rw-r--r-- | core/src/test/kotlin/javadoc/JavadocTest.kt | 18 | ||||
-rw-r--r-- | core/testdata/javadoc/vararg.kt | 3 |
3 files changed, 23 insertions, 4 deletions
diff --git a/core/src/main/kotlin/javadoc/docbase.kt b/core/src/main/kotlin/javadoc/docbase.kt index 2a14c6ff..61b13b46 100644 --- a/core/src/main/kotlin/javadoc/docbase.kt +++ b/core/src/main/kotlin/javadoc/docbase.kt @@ -173,7 +173,7 @@ open class TypeAdapter(override val module: ModuleNodeAdapter, override val node private val javaLanguageService = JavaLanguageService() override fun qualifiedTypeName(): String = javaLanguageService.getArrayElementType(node)?.qualifiedNameFromType() ?: node.qualifiedNameFromType() - override fun typeName(): String = javaLanguageService.getArrayElementType(node)?.simpleName() ?: node.simpleName() + override fun typeName(): String = (javaLanguageService.getArrayElementType(node)?.simpleName() ?: node.simpleName()) + dimension() override fun simpleTypeName(): String = typeName() // TODO difference typeName() vs simpleTypeName() override fun dimension(): String = Collections.nCopies(javaLanguageService.getArrayDimension(node), "[]").joinToString("") @@ -275,7 +275,7 @@ class ParameterizedTypeAdapter(module: ModuleNodeAdapter, node: DocumentationNod } class ParameterAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), Parameter { - override fun typeName(): String? = JavaLanguageService().renderType(node.detail(NodeKind.Type)) + override fun typeName(): String? = type()?.typeName() override fun type(): Type? = TypeAdapter(module, node.detail(NodeKind.Type)) override fun annotations(): Array<out AnnotationDesc> = nodeAnnotations(this).toTypedArray() } @@ -317,7 +317,7 @@ open class ExecutableMemberAdapter(module: ModuleNodeAdapter, node: Documentatio .map { ThrowsTagAdapter(this, ClassDocumentationNodeAdapter(module, classOf(it.subjectName!!, NodeKind.Exception)), it.children) } .toTypedArray() - override fun isVarArgs(): Boolean = node.details(NodeKind.Parameter).any { false } // TODO + override fun isVarArgs(): Boolean = node.details(NodeKind.Parameter).last().hasModifier("vararg") override fun isSynchronized(): Boolean = node.annotations.any { it.name == "synchronized" } diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index 45c45aa4..34b0b7a5 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -64,7 +64,7 @@ class JavadocTest { val member = classDoc.methods().find { it.name() == "main" }!! val paramType = member.parameters()[0].type() assertNull(paramType.asParameterizedType()) - assertEquals("String", paramType.typeName()) + assertEquals("String[]", paramType.typeName()) assertEquals("String", paramType.asClassDoc().name()) } } @@ -161,6 +161,22 @@ class JavadocTest { } } + @Test + fun testVararg() { + verifyJavadoc("testdata/javadoc/vararg.kt") { doc -> + val classDoc = doc.classNamed("VarargKt")!! + val methods = classDoc.methods() + methods.single { it.name() == "vararg" }.let { method -> + assertTrue(method.isVarArgs) + assertEquals("int", method.parameters().last().typeName()) + } + methods.single { it.name() == "varargInMiddle" }.let { method -> + assertFalse(method.isVarArgs) + assertEquals("int[]", method.parameters()[1].typeName()) + } + } + } + private fun verifyJavadoc(name: String, withJdk: Boolean = false, withKotlinRuntime: Boolean = false, diff --git a/core/testdata/javadoc/vararg.kt b/core/testdata/javadoc/vararg.kt new file mode 100644 index 00000000..aa6c26d7 --- /dev/null +++ b/core/testdata/javadoc/vararg.kt @@ -0,0 +1,3 @@ +fun vararg(a: String, vararg b: Int) {} + +fun varargInMiddle(a: String, vararg b: Int, c: Short) {}
\ No newline at end of file |