aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Analysis/CommentsAPI.kt21
-rw-r--r--src/Generation/ConsoleGenerator.kt27
-rw-r--r--src/Model/DocumentationBuilder.kt12
-rw-r--r--src/main.kt23
4 files changed, 66 insertions, 17 deletions
diff --git a/src/Analysis/CommentsAPI.kt b/src/Analysis/CommentsAPI.kt
index a32ee734..03b1911c 100644
--- a/src/Analysis/CommentsAPI.kt
+++ b/src/Analysis/CommentsAPI.kt
@@ -5,12 +5,21 @@ import org.jetbrains.jet.lang.resolve.*
import org.jetbrains.jet.kdoc.psi.api.*
import org.jetbrains.jet.lang.psi.*
-fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? {
+fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): String {
+ return getDocumentationElements(descriptor).map { it.extractText() }.join("\n")
+}
+
+fun BindingContext.getDocumentationElements(descriptor: DeclarationDescriptor): List<KDoc> {
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
if (psiElement == null)
throw IllegalArgumentException("$descriptor doesn't have connection to source code, is it synthetic?")
- return psiElement.previousSiblings().takeWhile { it !is JetDeclaration }.firstOrNull { it is KDoc } as KDoc?
+ return psiElement.previousSiblings() // go backwards
+ .takeWhile { it !is JetDeclaration } // till previous declaration
+ .filter { it is KDoc } // get KDocs
+ .map { it as KDoc } // cast
+ .toList()
+ .reverse() // make reversed list
}
fun KDoc?.extractText(): String {
@@ -21,10 +30,14 @@ fun KDoc?.extractText(): String {
return ""
val lines = text.replace("\r", "").split("\n")
return lines.map {
- it.dropWhile { java.lang.Character.isWhitespace(it) }
+ val comment = it.trim()
.dropWhile { it == '/' }
.dropWhile { it == '*' }
.dropWhile { it == '/' }
- .dropWhile { java.lang.Character.isWhitespace(it) }
+ .trim()
+ if (comment.endsWith("*/"))
+ comment.substring(0, comment.length - 2).trim()
+ else
+ comment
}.filter { it.any() }.join("\n")
} \ No newline at end of file
diff --git a/src/Generation/ConsoleGenerator.kt b/src/Generation/ConsoleGenerator.kt
new file mode 100644
index 00000000..e46cac31
--- /dev/null
+++ b/src/Generation/ConsoleGenerator.kt
@@ -0,0 +1,27 @@
+package org.jetbrains.dokka
+
+public class ConsoleGenerator() {
+ val IndentStep = " "
+
+ public fun generate(node: DocumentationNode, indent: String = "") {
+ generateHeader(node, indent)
+ generateDetails(node, indent)
+ generateMembers(node, indent)
+ }
+
+ public fun generateHeader(node: DocumentationNode, indent: String = "") {
+ println("$indent${node.kind}: ${node.name}")
+ println("$indent\"${node.doc.replace("\n", "\n$indent")}\"")
+ println()
+ }
+
+ public fun generateDetails(node: DocumentationNode, indent: String = "") {
+ for (child in node.details)
+ generate(child, indent + IndentStep)
+ }
+
+ public fun generateMembers(node: DocumentationNode, indent: String = "") {
+ for (child in node.members)
+ generate(child, indent + IndentStep)
+ }
+} \ No newline at end of file
diff --git a/src/Model/DocumentationBuilder.kt b/src/Model/DocumentationBuilder.kt
index 77f74eb2..08298926 100644
--- a/src/Model/DocumentationBuilder.kt
+++ b/src/Model/DocumentationBuilder.kt
@@ -19,21 +19,21 @@ fun BindingContext.createDocumentation(file: JetFile): DocumentationModel {
class DocumentationBuilderVisitor(val context: BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown)
data?.addReferenceTo(node, DocumentationReferenceKind.Member)
return node
}
override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter)
data?.addReferenceTo(node, DocumentationReferenceKind.Detail)
return node
}
override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc,
when (descriptor.getKind()) {
ClassKind.OBJECT -> DocumentationNodeKind.Object
@@ -45,21 +45,21 @@ class DocumentationBuilderVisitor(val context: BindingContext) : DeclarationDesc
}
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function)
data?.addReferenceTo(node, DocumentationReferenceKind.Member)
return node
}
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property)
data?.addReferenceTo(node, DocumentationReferenceKind.Member)
return node
}
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val doc = context.getDocumentation(descriptor!!).extractText()
+ val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor)
data?.addReferenceTo(node, DocumentationReferenceKind.Member)
return node
diff --git a/src/main.kt b/src/main.kt
index e385da3f..79a8bfcb 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -3,15 +3,23 @@ package org.jetbrains.dokka
import com.sampullara.cli.*
import com.intellij.openapi.util.*
import org.jetbrains.jet.cli.common.messages.*
-import org.jetbrains.jet.utils.*
-import org.jetbrains.jet.lang.resolve.BindingContext
-import org.jetbrains.jet.lang.psi.JetFile
-import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
+import org.jetbrains.jet.cli.common.arguments.*
+
+class DokkaArguments {
+ Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
+ ValueDescription("<path>")
+ public var src: String? = null
+
+ Argument(value = "output", description = "Output directory path for .md files")
+ ValueDescription("<path>")
+ public var outputDir: String? = null
+}
public fun main(args: Array<String>) {
- val compilerArguments = K2JVMCompilerArguments()
- val sources: List<String> = Args.parse(compilerArguments, args) ?: listOf()
+ val arguments = DokkaArguments()
+ val sourceFiles = Args.parse(arguments, args)
+ val sources: List<String> = sourceFiles ?: listOf()
val environment = AnalysisEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) {
/*
@@ -32,6 +40,7 @@ public fun main(args: Array<String>) {
context.createDocumentation(file)
}.fold(DocumentationModel()) {(aggregate, item) -> aggregate.merge(item) }
- println(model)
+ ConsoleGenerator().generate(model)
+
Disposer.dispose(environment)
} \ No newline at end of file