aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CommentsAPI.kt3
-rw-r--r--src/DocumentationBuilder.kt6
-rw-r--r--src/DocumentationBuildingVisitor.kt3
-rw-r--r--test/data/classes/classWithConstructor.kt1
-rw-r--r--test/data/classes/classWithFunction.kt4
-rw-r--r--test/data/classes/emptyClass.kt3
-rw-r--r--test/data/functions/function.kt3
-rw-r--r--test/data/functions/functionWithParams.kt3
-rw-r--r--test/src/ClassTest.kt43
-rw-r--r--test/src/FunctionTest.kt (renamed from test/src/TopLevelFunctionTest.kt)2
10 files changed, 65 insertions, 6 deletions
diff --git a/src/CommentsAPI.kt b/src/CommentsAPI.kt
index fd281899..4d324d9d 100644
--- a/src/CommentsAPI.kt
+++ b/src/CommentsAPI.kt
@@ -7,7 +7,8 @@ import org.jetbrains.jet.lang.psi.JetDeclaration
fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? {
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
- if (psiElement == null) throw IllegalArgumentException("$descriptor doesn't have connection to source code, is it synthetic?")
+ 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?
}
diff --git a/src/DocumentationBuilder.kt b/src/DocumentationBuilder.kt
index 26ed4f80..8b33e2b9 100644
--- a/src/DocumentationBuilder.kt
+++ b/src/DocumentationBuilder.kt
@@ -32,6 +32,12 @@ class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDes
return node
}
+ override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val doc = context.getDocumentation(descriptor!!).extractText()
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Class)
+ data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ return node
+ }
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!).extractText()
diff --git a/src/DocumentationBuildingVisitor.kt b/src/DocumentationBuildingVisitor.kt
index 6486ac90..4289a7f7 100644
--- a/src/DocumentationBuildingVisitor.kt
+++ b/src/DocumentationBuildingVisitor.kt
@@ -64,11 +64,10 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi
public override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
- visitChildren(descriptor.getThisAsReceiverParameter(), node)
visitChildren(descriptor.getConstructors(), node)
visitChildren(descriptor.getTypeConstructor().getParameters(), node)
visitChildren(descriptor.getClassObjectDescriptor(), node)
- visitChildren(descriptor.getDefaultType().getMemberScope().getAllDescriptors(), node)
+ visitChildren(descriptor.getDefaultType().getMemberScope().getOwnDeclaredDescriptors(), node)
return node
}
diff --git a/test/data/classes/classWithConstructor.kt b/test/data/classes/classWithConstructor.kt
new file mode 100644
index 00000000..0751d570
--- /dev/null
+++ b/test/data/classes/classWithConstructor.kt
@@ -0,0 +1 @@
+class Klass(name: String) \ No newline at end of file
diff --git a/test/data/classes/classWithFunction.kt b/test/data/classes/classWithFunction.kt
new file mode 100644
index 00000000..a981cfb6
--- /dev/null
+++ b/test/data/classes/classWithFunction.kt
@@ -0,0 +1,4 @@
+class Klass {
+ fun fn() {
+ }
+}
diff --git a/test/data/classes/emptyClass.kt b/test/data/classes/emptyClass.kt
new file mode 100644
index 00000000..abd20cc8
--- /dev/null
+++ b/test/data/classes/emptyClass.kt
@@ -0,0 +1,3 @@
+class Klass {
+
+} \ No newline at end of file
diff --git a/test/data/functions/function.kt b/test/data/functions/function.kt
index f8c64f94..3ed81dfa 100644
--- a/test/data/functions/function.kt
+++ b/test/data/functions/function.kt
@@ -1,4 +1,5 @@
/**
* Function fn
*/
-fun fn() {} \ No newline at end of file
+fun fn() {
+} \ No newline at end of file
diff --git a/test/data/functions/functionWithParams.kt b/test/data/functions/functionWithParams.kt
index 135ed399..559f4f78 100644
--- a/test/data/functions/functionWithParams.kt
+++ b/test/data/functions/functionWithParams.kt
@@ -3,4 +3,5 @@
* Function
* Documentation
*/
-fun function(x : Int) {} \ No newline at end of file
+fun function(x: Int) {
+} \ No newline at end of file
diff --git a/test/src/ClassTest.kt b/test/src/ClassTest.kt
new file mode 100644
index 00000000..914df53b
--- /dev/null
+++ b/test/src/ClassTest.kt
@@ -0,0 +1,43 @@
+package com.jetbrains.dokka.tests
+
+import org.junit.Test
+import kotlin.test.*
+import com.jetbrains.dokka.*
+
+public class ClassTest {
+ Test fun emptyClass() {
+ verifyModel("test/data/classes/emptyClass.kt") { model ->
+ val item = model.nodes.single().members.single()
+ assertEquals(DocumentationNodeKind.Class, item.kind)
+ assertEquals("Klass", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertEquals("<init>", item.members.single().name)
+ assertTrue(item.links.none())
+ }
+ }
+
+ Test fun classWithConstructor() {
+ verifyModel("test/data/classes/classWithConstructor.kt") { model ->
+ val item = model.nodes.single().members.single()
+ assertEquals(DocumentationNodeKind.Class, item.kind)
+ assertEquals("Klass", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertEquals("<init>", item.members.single().name)
+ assertTrue(item.links.none())
+ }
+ }
+
+ Test fun classWithFunction() {
+ verifyModel("test/data/classes/classWithFunction.kt") { model ->
+ val item = model.nodes.single().members.single()
+ assertEquals(DocumentationNodeKind.Class, item.kind)
+ assertEquals("Klass", item.name)
+ assertEquals("", item.doc)
+ assertTrue(item.details.none())
+ assertEquals("<init>", item.members.single().name)
+ assertTrue(item.links.none())
+ }
+ }
+} \ No newline at end of file
diff --git a/test/src/TopLevelFunctionTest.kt b/test/src/FunctionTest.kt
index 342708f2..e8afe97b 100644
--- a/test/src/TopLevelFunctionTest.kt
+++ b/test/src/FunctionTest.kt
@@ -5,7 +5,7 @@ import kotlin.test.*
import com.jetbrains.dokka.*
-public class TopLevelFunctionTest {
+public class FunctionTest {
Test fun function() {
verifyModel("test/data/functions/function.kt") { model ->
val item = model.nodes.single().members.single()