aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CommentsAPI.kt17
-rw-r--r--src/DocumentationBuilder.kt25
-rw-r--r--src/DocumentationModel.kt2
-rw-r--r--test/data/functions/function.kt2
-rw-r--r--test/data/functions/functionWithParams.kt4
-rw-r--r--test/data/packages/dottedNamePackage.kt1
-rw-r--r--test/data/packages/rootPackage.kt0
-rw-r--r--test/data/packages/simpleNamePackage.kt1
-rw-r--r--test/src/PackageTest.kt43
-rw-r--r--test/src/TopLevelFunctionTest.kt8
10 files changed, 94 insertions, 9 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
diff --git a/test/data/functions/function.kt b/test/data/functions/function.kt
index 878b017b..f8c64f94 100644
--- a/test/data/functions/function.kt
+++ b/test/data/functions/function.kt
@@ -1,4 +1,4 @@
/**
- * doc
+ * Function fn
*/
fun fn() {} \ No newline at end of file
diff --git a/test/data/functions/functionWithParams.kt b/test/data/functions/functionWithParams.kt
index 9d3a0ad7..135ed399 100644
--- a/test/data/functions/functionWithParams.kt
+++ b/test/data/functions/functionWithParams.kt
@@ -1,4 +1,6 @@
/**
- * doc
+ * Multiline
+ * Function
+ * Documentation
*/
fun function(x : Int) {} \ No newline at end of file
diff --git a/test/data/packages/dottedNamePackage.kt b/test/data/packages/dottedNamePackage.kt
new file mode 100644
index 00000000..38619310
--- /dev/null
+++ b/test/data/packages/dottedNamePackage.kt
@@ -0,0 +1 @@
+package dot.name \ No newline at end of file
diff --git a/test/data/packages/rootPackage.kt b/test/data/packages/rootPackage.kt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/data/packages/rootPackage.kt
diff --git a/test/data/packages/simpleNamePackage.kt b/test/data/packages/simpleNamePackage.kt
new file mode 100644
index 00000000..2c29f4c7
--- /dev/null
+++ b/test/data/packages/simpleNamePackage.kt
@@ -0,0 +1 @@
+package simple
diff --git a/test/src/PackageTest.kt b/test/src/PackageTest.kt
new file mode 100644
index 00000000..411ea300
--- /dev/null
+++ b/test/src/PackageTest.kt
@@ -0,0 +1,43 @@
+package com.jetbrains.dokka.tests
+
+import org.junit.Test
+import kotlin.test.*
+import com.jetbrains.dokka.*
+
+public class PackageTest {
+ Test fun rootPackage() {
+ verifyFiles("test/data/packages/rootPackage.kt") { model ->
+ val item = model.nodes.single()
+ assertEquals(DocumentationNodeKind.Package, item.kind)
+ assertEquals("", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertTrue(item.members.none())
+ assertTrue(item.links.none())
+ }
+ }
+
+ Test fun simpleNamePackage() {
+ verifyFiles("test/data/packages/simpleNamePackage.kt") { model ->
+ val item = model.nodes.single()
+ assertEquals(DocumentationNodeKind.Package, item.kind)
+ assertEquals("simple", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertTrue(item.members.none())
+ assertTrue(item.links.none())
+ }
+ }
+
+ Test fun dottedNamePackage() {
+ verifyFiles("test/data/packages/dottedNamePackage.kt") { model ->
+ val item = model.nodes.single()
+ assertEquals(DocumentationNodeKind.Package, item.kind)
+ assertEquals("dot.name", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertTrue(item.members.none())
+ assertTrue(item.links.none())
+ }
+ }
+} \ No newline at end of file
diff --git a/test/src/TopLevelFunctionTest.kt b/test/src/TopLevelFunctionTest.kt
index dd88a1a0..02150784 100644
--- a/test/src/TopLevelFunctionTest.kt
+++ b/test/src/TopLevelFunctionTest.kt
@@ -11,7 +11,7 @@ public class TopLevelFunctionTest {
val item = model.nodes.single().members.single()
assertEquals(DocumentationNodeKind.Function, item.kind)
assertEquals("fn", item.name)
- assertEquals("doc", item.doc)
+ assertEquals("Function fn", item.doc)
assertTrue(item.details.none())
assertTrue(item.members.none())
assertTrue(item.links.none())
@@ -23,8 +23,12 @@ public class TopLevelFunctionTest {
val item = model.nodes.single().members.single()
assertEquals(DocumentationNodeKind.Function, item.kind)
assertEquals("function", item.name)
- assertEquals("doc", item.doc)
+ assertEquals("""Multiline
+Function
+Documentation"""
+ , item.doc)
assertEquals("x", item.details.single().name)
+ assertEquals(DocumentationNodeKind.Parameter, item.details.single().kind)
assertTrue(item.members.none())
assertTrue(item.links.none())