aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Generation/ConsoleGenerator.kt4
-rw-r--r--src/Generation/JavaSignatureGenerator.kt124
-rw-r--r--src/Generation/KotlinSignatureGenerator.kt4
-rw-r--r--src/Model/DocumentationNode.kt2
-rw-r--r--src/Model/DocumentationNodeBuilder.kt2
-rw-r--r--src/main.kt4
6 files changed, 131 insertions, 9 deletions
diff --git a/src/Generation/ConsoleGenerator.kt b/src/Generation/ConsoleGenerator.kt
index af22a622..4038bdcc 100644
--- a/src/Generation/ConsoleGenerator.kt
+++ b/src/Generation/ConsoleGenerator.kt
@@ -1,8 +1,6 @@
package org.jetbrains.dokka
-public class ConsoleGenerator() {
- val signatureGenerator = KotlinSignatureGenerator()
-
+public class ConsoleGenerator(val signatureGenerator : SignatureGenerator) {
val IndentStep = " "
public fun generate(node: DocumentationNode, indent: String = "") {
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
diff --git a/src/Generation/KotlinSignatureGenerator.kt b/src/Generation/KotlinSignatureGenerator.kt
index ee66d37a..f42b34eb 100644
--- a/src/Generation/KotlinSignatureGenerator.kt
+++ b/src/Generation/KotlinSignatureGenerator.kt
@@ -7,7 +7,7 @@ class KotlinSignatureGenerator : SignatureGenerator {
return when (node.kind) {
Kind.Package -> renderPackage(node)
Kind.Class,
- Kind.Trait,
+ Kind.Interface,
Kind.Object -> renderClass(node)
Kind.TypeParameter -> renderTypeParameter(node)
@@ -57,7 +57,7 @@ class KotlinSignatureGenerator : SignatureGenerator {
return StringBuilder {
when (node.kind) {
Kind.Class -> append("class ")
- Kind.Trait -> append("trait ")
+ Kind.Interface -> append("trait ")
Kind.Object -> append("object ")
else -> throw IllegalArgumentException("Node $node is not a class-like object")
}
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index da0f27e5..ad1c3d57 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -49,7 +49,7 @@ public open class DocumentationNode(val descriptor: DeclarationDescriptor,
Package
Class
- Trait
+ Interface
Object
Constructor
diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt
index 8fa12012..60f9ca0d 100644
--- a/src/Model/DocumentationNodeBuilder.kt
+++ b/src/Model/DocumentationNodeBuilder.kt
@@ -43,7 +43,7 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, when (descriptor.getKind()) {
ClassKind.OBJECT -> DocumentationNode.Kind.Object
- ClassKind.TRAIT -> DocumentationNode.Kind.Trait
+ ClassKind.TRAIT -> DocumentationNode.Kind.Interface
else -> DocumentationNode.Kind.Class
})
data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
diff --git a/src/main.kt b/src/main.kt
index 95cda7af..6e1ef834 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -36,12 +36,12 @@ public fun main(args: Array<String>) {
println()
- val model = environment.processFiles { context, module, file ->
+ val documentation = environment.processFiles { context, module, file ->
println("Processing: ${file.getName()}")
context.createDocumentationModule(module, file)
}.reduce {(aggregate, item) -> aggregate.merge(item) }
- ConsoleGenerator().generate(model)
+ ConsoleGenerator(JavaSignatureGenerator()).generate(documentation)
Disposer.dispose(environment)
} \ No newline at end of file