aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 19:23:45 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 19:23:45 +0400
commit484ec26c7d22f4d84b7054b9e243b422acaff3dd (patch)
tree18027117a60c38ba7f8800c8c1abdcde1ae38b19 /src
parent35b64fb01d6b4da4b0dab840a787abc84d1bff06 (diff)
downloaddokka-484ec26c7d22f4d84b7054b9e243b422acaff3dd.tar.gz
dokka-484ec26c7d22f4d84b7054b9e243b422acaff3dd.tar.bz2
dokka-484ec26c7d22f4d84b7054b9e243b422acaff3dd.zip
Add tests for packages, implement simple comment text extraction, build model for functions and parameters.
Diffstat (limited to 'src')
-rw-r--r--src/CommentsAPI.kt17
-rw-r--r--src/DocumentationBuilder.kt25
-rw-r--r--src/DocumentationModel.kt2
3 files changed, 39 insertions, 5 deletions
diff --git a/src/CommentsAPI.kt b/src/CommentsAPI.kt
index 21ba1067..fd281899 100644
--- a/src/CommentsAPI.kt
+++ b/src/CommentsAPI.kt
@@ -1,7 +1,6 @@
package com.jetbrains.dokka
import org.jetbrains.jet.lang.descriptors.*
-import org.jetbrains.jet.lexer.*
import org.jetbrains.jet.lang.resolve.*
import org.jetbrains.jet.kdoc.psi.api.*
import org.jetbrains.jet.lang.psi.JetDeclaration
@@ -12,3 +11,19 @@ fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? {
return psiElement.previousSiblings().takeWhile { it !is JetDeclaration }.firstOrNull { it is KDoc } as KDoc?
}
+
+fun KDoc?.extractText(): String {
+ if (this == null)
+ return ""
+ val text = getText()
+ if (text == null)
+ return ""
+ val lines = text.replace("\r", "").split("\n")
+ return lines.map {
+ it.dropWhile { java.lang.Character.isWhitespace(it) }
+ .dropWhile { it == '/' }
+ .dropWhile { it == '*' }
+ .dropWhile { it == '/' }
+ .dropWhile { java.lang.Character.isWhitespace(it) }
+ }.filter { it.any() }.join("\n")
+} \ No newline at end of file
diff --git a/src/DocumentationBuilder.kt b/src/DocumentationBuilder.kt
index 02db3540..26ed4f80 100644
--- a/src/DocumentationBuilder.kt
+++ b/src/DocumentationBuilder.kt
@@ -10,23 +10,40 @@ fun BindingContext.createDocumentation(file: JetFile): DocumentationModel {
val packageFragment = getPackageFragment(file)
if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment")
- val visitor = DocumentationBuilderVisitor()
+ val visitor = DocumentationBuilderVisitor(this)
visitDescriptor(packageFragment, model, visitor)
return model
}
-class DocumentationBuilderVisitor() : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
+class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = DocumentationNode(descriptor!!.getName().asString(), "doc", DocumentationNodeKind.Function)
+ val doc = context.getDocumentation(descriptor!!).extractText()
+ 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 node = DocumentationNode(descriptor!!.getName().asString(), "doc", DocumentationNodeKind.Function)
+ val doc = context.getDocumentation(descriptor!!).extractText()
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter)
data?.addReferenceTo(node, DocumentationReferenceKind.Detail)
return node
}
+
+
+ override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val doc = context.getDocumentation(descriptor!!).extractText()
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function)
+ data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ return node
+ }
+
+
+ override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = DocumentationNode(descriptor!!.fqName.asString(), "", DocumentationNodeKind.Package)
+ data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ return node
+ }
}
diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt
index b8ef21b0..feddccde 100644
--- a/src/DocumentationModel.kt
+++ b/src/DocumentationModel.kt
@@ -4,6 +4,8 @@ import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetFile
public enum class DocumentationNodeKind {
+ Unknown
+
Package
Class
Function