diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 16:28:57 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 16:28:57 +0400 |
commit | 93c92506101fec7f0cff6b63d7e223ae97f20717 (patch) | |
tree | d04c9468d940e8fea71f70cc9a31bcca71a4537b /src/Generation/JavaSignatureGenerator.kt | |
parent | 372ab94571e1ad5885982ea83d4b55286f1d6c23 (diff) | |
download | dokka-93c92506101fec7f0cff6b63d7e223ae97f20717.tar.gz dokka-93c92506101fec7f0cff6b63d7e223ae97f20717.tar.bz2 dokka-93c92506101fec7f0cff6b63d7e223ae97f20717.zip |
Add JavaSignatureGenerator (no properties or ojects yet)
Diffstat (limited to 'src/Generation/JavaSignatureGenerator.kt')
-rw-r--r-- | src/Generation/JavaSignatureGenerator.kt | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/Generation/JavaSignatureGenerator.kt b/src/Generation/JavaSignatureGenerator.kt new file mode 100644 index 00000000..bc9b9a46 --- /dev/null +++ b/src/Generation/JavaSignatureGenerator.kt @@ -0,0 +1,124 @@ +package org.jetbrains.dokka + +import org.jetbrains.dokka.DocumentationNode.* + +class JavaSignatureGenerator : SignatureGenerator { + override fun render(node: DocumentationNode): String { + return when (node.kind) { + Kind.Package -> renderPackage(node) + Kind.Class, + Kind.Interface, + Kind.Object -> renderClass(node) + + Kind.TypeParameter -> renderTypeParameter(node) + Kind.Type, + Kind.UpperBound -> renderType(node) + + Kind.Constructor, + Kind.Function -> renderFunction(node) + Kind.Property -> renderProperty(node) + else -> "${node.kind}: ${node.name}" + } + } + + override fun renderPackage(node: DocumentationNode): String { + return "package ${node.name}" + } + + override fun renderType(node: DocumentationNode): String { + return when (node.name) { + "Unit" -> "void" + "Int" -> "int" + "Long" -> "long" + "Double" -> "double" + "Float" -> "float" + "Char" -> "char" + "Boolean" -> "bool" + // TODO: render arrays + else -> node.name + } + } + + override fun renderTypeParameter(node: DocumentationNode): String { + val constraints = node.details(Kind.UpperBound) + return if (constraints.none()) + node.name + else { + node.name + " extends " + constraints.map { renderType(node) }.join() + } + } + + override fun renderParameter(node: DocumentationNode): String { + return "${renderType(node.detail(Kind.Type))} ${node.name}" + } + + override fun renderTypeParametersForNode(node: DocumentationNode): String { + return StringBuilder { + val typeParameters = node.details(Kind.TypeParameter) + if (typeParameters.any()) { + append("<") + append(typeParameters.map { renderTypeParameter(it) }.join()) + append("> ") + } + }.toString() + } + + override fun renderClass(node: DocumentationNode): String { + return StringBuilder { + when (node.kind) { + Kind.Class -> append("class ") + Kind.Interface -> append("interface ") + Kind.Object -> append("class ") + else -> throw IllegalArgumentException("Node $node is not a class-like object") + } + + append(node.name) + append(renderTypeParametersForNode(node)) + }.toString() + } + + override fun renderFunction(node: DocumentationNode): String { + return StringBuilder { + when (node.kind) { + Kind.Constructor -> { + append(node.owner?.name) + } + Kind.Function -> { + append(renderTypeParametersForNode(node)) + append(renderType(node.detail(Kind.Type))) + append(" ") + append(node.name) + } + else -> throw IllegalArgumentException("Node $node is not a function-like object") + } + + val receiver = node.details(Kind.Receiver).firstOrNull() // TODO: replace with singleOrNull when fixed + append("(") + if (receiver != null) + append((listOf(receiver) + node.details(Kind.Parameter)).map { renderParameter(it) }.join()) + else + append(node.details(Kind.Parameter).map { renderParameter(it) }.join()) + + append(")") + }.toString() + } + + override fun renderProperty(node: DocumentationNode): String { + return StringBuilder { + when (node.kind) { + Kind.Property -> append("val ") + else -> throw IllegalArgumentException("Node $node is not a property") + } + append(renderTypeParametersForNode(node)) + val receiver = node.details(Kind.Receiver).firstOrNull() // TODO: replace with singleOrNull when fixed + if (receiver != null) { + append(renderType(receiver.detail(Kind.Type))) + append(".") + } + + append(node.name) + append(": ") + append(renderType(node.detail(Kind.Type))) + }.toString() + } +}
\ No newline at end of file |