From 325f4f3a29850e12c074e7e7a50d9e950d46d4ef Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 11:59:13 +0300 Subject: ~ avoid possible parameter name clash with "receiver" --- javadoc/src/main/kotlin/docbase.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'javadoc/src/main') diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt index 4e822fc8..c6b84059 100644 --- a/javadoc/src/main/kotlin/docbase.kt +++ b/javadoc/src/main/kotlin/docbase.kt @@ -247,11 +247,17 @@ class ParameterAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : override fun annotations(): Array? = node.details(DocumentationNode.Kind.Annotation).map { AnnotationDescAdapter(module, it) }.toTypedArray() } -class ReceiverParameterAdapter(module: ModuleNodeAdapter, val receiverType: DocumentationNode) : DocumentationNodeAdapter(module, receiverType), Parameter { +class ReceiverParameterAdapter(module: ModuleNodeAdapter, val receiverType: DocumentationNode, val parent: ExecutableMemberAdapter) : DocumentationNodeAdapter(module, receiverType), Parameter { override fun typeName(): String? = receiverType.name override fun type(): Type? = TypeAdapter(module, receiverType) override fun annotations(): Array = emptyArray() - override fun name(): String = "receiver" + override fun name(): String = tryName("receiver") + + tailRecursive + private fun tryName(name: String): String = when (name) { + in parent.parameters().drop(1).map { it.name() } -> tryName("$$name") + else -> name + } } fun classOf(fqName: String, kind: DocumentationNode.Kind = DocumentationNode.Kind.Class) = DocumentationNode(fqName.substringAfterLast(".", fqName), Content.Empty, kind).let { node -> @@ -290,7 +296,7 @@ open class ExecutableMemberAdapter(module: ModuleNodeAdapter, val node: Document override fun signature(): String = node.details(DocumentationNode.Kind.Parameter).map { JavaLanguageService().renderType(it) }.joinToString(", ", "(", ")") // TODO it should be FQ types override fun parameters(): Array = - ((receiverNode()?.let { receiver -> listOf(ReceiverParameterAdapter(module, receiver)) } ?: emptyList()) + ((receiverNode()?.let { receiver -> listOf(ReceiverParameterAdapter(module, receiver, this)) } ?: emptyList()) + node.details(DocumentationNode.Kind.Parameter).map { ParameterAdapter(module, it) } ).toTypedArray() -- cgit