aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Model/DocumentationNode.kt2
-rw-r--r--src/Model/DocumentationNodeBuilder.kt72
-rw-r--r--src/main.kt2
-rw-r--r--test/data/functions/genericFunction.kt2
-rw-r--r--test/data/functions/genericFunctionWithConstraints.kt2
-rw-r--r--test/playground.kt8
-rw-r--r--test/src/model/ClassTest.kt27
-rw-r--r--test/src/model/FunctionTest.kt28
-rw-r--r--test/src/model/PropertyTest.kt32
9 files changed, 115 insertions, 60 deletions
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index ad1c3d57..ccfb9b7d 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -64,6 +64,8 @@ public open class DocumentationNode(val descriptor: DeclarationDescriptor,
LowerBound
Exception
+ Modifier
+
Module
}
diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt
index 60f9ca0d..1f553f33 100644
--- a/src/Model/DocumentationNodeBuilder.kt
+++ b/src/Model/DocumentationNodeBuilder.kt
@@ -1,41 +1,59 @@
package org.jetbrains.dokka
import org.jetbrains.jet.lang.resolve.*
-import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.descriptors.impl.*
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
+ fun reference(from: DocumentationNode, to: DocumentationNode, kind: DocumentationReference.Kind) {
+ from.addReferenceTo(to, kind)
+ if (kind == DocumentationReference.Kind.Link)
+ to.addReferenceTo(from, DocumentationReference.Kind.Link)
+ else
+ to.addReferenceTo(from, DocumentationReference.Kind.Owner)
+ }
+
+ fun addModality(descriptor: MemberDescriptor, data: DocumentationNode): DocumentationNode {
+ val modifier = descriptor.getModality().name().toLowerCase()
+ val node = DocumentationNode(descriptor, modifier, DocumentationContent.Empty, DocumentationNode.Kind.Modifier)
+ reference(data, node, DocumentationReference.Kind.Detail)
+ return node
+ }
+
+ fun addVisibility(descriptor: MemberDescriptor, data: DocumentationNode): DocumentationNode {
+ val modifier = descriptor.getVisibility().toString()
+ val node = DocumentationNode(descriptor, modifier, DocumentationContent.Empty, DocumentationNode.Kind.Modifier)
+ reference(data, node, DocumentationReference.Kind.Detail)
+ return node
+ }
+
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Unknown)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Link)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
+ reference(data!!, node, DocumentationReference.Kind.Link)
return node
}
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = DocumentationNode(descriptor!!, descriptor.getName().asString(), DocumentationContent.Empty, DocumentationNode.Kind.Receiver)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Detail)
+ reference(data!!, node, DocumentationReference.Kind.Detail)
val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type)
- node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail)
+ reference(node, typeNode, DocumentationReference.Kind.Detail)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
return node
}
override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Parameter)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Detail)
+ reference(data!!, node, DocumentationReference.Kind.Detail)
val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type)
- node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail)
+ reference(node, typeNode, DocumentationReference.Kind.Detail)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
return node
}
@@ -46,68 +64,72 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
ClassKind.TRAIT -> DocumentationNode.Kind.Interface
else -> DocumentationNode.Kind.Class
})
- data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
+ reference(data!!, node, DocumentationReference.Kind.Member)
+ addModality(descriptor, node)
+ addVisibility(descriptor, node)
return node
}
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Function)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
+ reference(data!!, node, DocumentationReference.Kind.Member)
val typeNode = DocumentationNode(descriptor, descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type)
- node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail)
+ reference(node, typeNode, DocumentationReference.Kind.Detail)
+
+ addModality(descriptor, node)
+ addVisibility(descriptor, node)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
return node
}
override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.TypeParameter)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Detail)
+ reference(data!!, node, DocumentationReference.Kind.Detail)
val builtIns = KotlinBuiltIns.getInstance()
for (constraint in descriptor.getUpperBounds()) {
if (constraint == builtIns.getDefaultBound())
continue
val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNode.Kind.UpperBound)
- node.addReferenceTo(constraintNode, DocumentationReference.Kind.Detail)
+ reference(node, constraintNode, DocumentationReference.Kind.Detail)
}
for (constraint in descriptor.getLowerBounds()) {
if (builtIns.isNothing(constraint))
continue
val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNode.Kind.LowerBound)
- node.addReferenceTo(constraintNode, DocumentationReference.Kind.Detail)
+ reference(node, constraintNode, DocumentationReference.Kind.Detail)
}
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
return node
}
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Property)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
+ reference(data!!, node, DocumentationReference.Kind.Member)
val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type)
- node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail)
+ reference(node, typeNode, DocumentationReference.Kind.Detail)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
+ addModality(descriptor, node)
+ addVisibility(descriptor, node)
return node
}
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Constructor)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
+ reference(data!!, node, DocumentationReference.Kind.Member)
+
+ addVisibility(descriptor, node)
+
return node
}
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNode.Kind.Package)
- data!!.addReferenceTo(node, DocumentationReference.Kind.Member)
- node.addReferenceTo(data, DocumentationReference.Kind.Owner)
+ reference(data!!, node, DocumentationReference.Kind.Member)
return node
}
}
diff --git a/src/main.kt b/src/main.kt
index 6e1ef834..0faa357b 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -41,7 +41,7 @@ public fun main(args: Array<String>) {
context.createDocumentationModule(module, file)
}.reduce {(aggregate, item) -> aggregate.merge(item) }
- ConsoleGenerator(JavaSignatureGenerator()).generate(documentation)
+ ConsoleGenerator(KotlinSignatureGenerator()).generate(documentation)
Disposer.dispose(environment)
} \ No newline at end of file
diff --git a/test/data/functions/genericFunction.kt b/test/data/functions/genericFunction.kt
index 6e07d04b..05a65070 100644
--- a/test/data/functions/genericFunction.kt
+++ b/test/data/functions/genericFunction.kt
@@ -2,4 +2,4 @@
/**
* generic function
*/
-fun <T> generic() {} \ No newline at end of file
+private fun <T> generic() {} \ No newline at end of file
diff --git a/test/data/functions/genericFunctionWithConstraints.kt b/test/data/functions/genericFunctionWithConstraints.kt
index dc7fa3bb..5f22f8c5 100644
--- a/test/data/functions/genericFunctionWithConstraints.kt
+++ b/test/data/functions/genericFunctionWithConstraints.kt
@@ -2,5 +2,5 @@
/**
* generic function
*/
-fun <T : R, R> generic() {
+public fun <T : R, R> generic() {
} \ No newline at end of file
diff --git a/test/playground.kt b/test/playground.kt
index ca503791..b401ac63 100644
--- a/test/playground.kt
+++ b/test/playground.kt
@@ -50,6 +50,9 @@ object Object {
/** one line getter doc */
get() = "Member"
+ val String.valueWithReceiver: Int
+ get() = 1
+
}
class OuterClass {
@@ -60,6 +63,9 @@ class OuterClass {
class NestedClass<T> {
fun nestedClassFunction(item: T) {
}
+
+ fun String.functionWithReceiver(): Int = 1
+
}
inner class InnerClass {
@@ -67,7 +73,7 @@ class OuterClass {
/** doc for R1 type param */
R1,
/** doc for R2 type param */
- R2,
+ R2
>() {
}
}
diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt
index 47eeb2ce..05e156f3 100644
--- a/test/src/model/ClassTest.kt
+++ b/test/src/model/ClassTest.kt
@@ -11,7 +11,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertEquals("<init>", members.single().name)
assertTrue(links.none())
}
@@ -24,7 +24,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertEquals("<init>", members.single().name)
assertTrue(links.none())
}
@@ -37,7 +37,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Object, kind)
assertEquals("Obj", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertTrue(members.none())
assertTrue(links.none())
}
@@ -50,7 +50,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertTrue(links.none())
assertEquals(1, members.count())
@@ -58,8 +58,9 @@ public class ClassTest {
assertEquals("<init>", name)
assertEquals(DocumentationContent.Empty, doc)
assertEquals(DocumentationNode.Kind.Constructor, kind)
- assertEquals(1, details.count())
- with(details.elementAt(0)) {
+ assertEquals(2, details.count())
+ assertEquals("public", details.elementAt(0).name)
+ with(details.elementAt(1)) {
assertEquals("name", name)
assertEquals(DocumentationNode.Kind.Parameter, kind)
assertEquals(DocumentationContent.Empty, doc)
@@ -80,7 +81,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertTrue(links.none())
assertEquals(2, members.count())
@@ -88,7 +89,8 @@ public class ClassTest {
assertEquals("<init>", name)
assertEquals(DocumentationContent.Empty, doc)
assertEquals(DocumentationNode.Kind.Constructor, kind)
- assertTrue(details.none())
+ assertEquals(1, details.count())
+ assertEquals("public", details.elementAt(0).name)
assertTrue(links.none())
assertTrue(members.none())
}
@@ -96,7 +98,7 @@ public class ClassTest {
assertEquals("fn", name)
assertEquals(DocumentationContent.Empty, doc)
assertEquals(DocumentationNode.Kind.Function, kind)
- assertEquals("Unit", details.single().name)
+ assertEquals("Unit", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
assertTrue(members.none())
}
@@ -110,7 +112,7 @@ public class ClassTest {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
assertEquals(DocumentationContent.Empty, doc)
- assertTrue(details.none())
+ assertEquals(2, details.count())
assertTrue(links.none())
assertEquals(2, members.count())
@@ -118,7 +120,8 @@ public class ClassTest {
assertEquals("<init>", name)
assertEquals(DocumentationContent.Empty, doc)
assertEquals(DocumentationNode.Kind.Constructor, kind)
- assertTrue(details.none())
+ assertEquals(1, details.count())
+ assertEquals("public", details.elementAt(0).name)
assertTrue(members.none())
assertTrue(links.none())
}
@@ -126,7 +129,7 @@ public class ClassTest {
assertEquals("name", name)
assertEquals(DocumentationContent.Empty, doc)
assertEquals(DocumentationNode.Kind.Property, kind)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(members.none())
assertTrue(links.none())
}
diff --git a/test/src/model/FunctionTest.kt b/test/src/model/FunctionTest.kt
index e501d3c0..331c59ba 100644
--- a/test/src/model/FunctionTest.kt
+++ b/test/src/model/FunctionTest.kt
@@ -11,7 +11,7 @@ public class FunctionTest {
assertEquals("fn", name)
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals("Function fn", doc.summary)
- assertEquals("Unit", details.single().name)
+ assertEquals("Unit", detail(DocumentationNode.Kind.Type).name)
assertTrue(members.none())
assertTrue(links.none())
}
@@ -26,8 +26,10 @@ public class FunctionTest {
assertEquals("Function with receiver", doc.summary)
assertEquals("Unit", details.elementAt(0).name)
- assertEquals(2, details.count())
- with(details.elementAt(1)) {
+ assertEquals(4, details.count())
+ assertEquals("final", details.elementAt(1).name)
+ assertEquals("internal", details.elementAt(2).name)
+ with(details.elementAt(3)) {
assertEquals("<this>", name)
assertEquals(DocumentationNode.Kind.Receiver, kind)
assertEquals(DocumentationContent.Empty, doc)
@@ -48,9 +50,11 @@ public class FunctionTest {
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals("generic function", doc.summary)
- assertEquals(2, details.count())
+ assertEquals(4, details.count())
assertEquals("Unit", details.elementAt(0).name)
- with(details.elementAt(1)) {
+ assertEquals("final", details.elementAt(1).name)
+ assertEquals("private", details.elementAt(2).name)
+ with(details.elementAt(3)) {
assertEquals("T", name)
assertEquals(DocumentationNode.Kind.TypeParameter, kind)
assertEquals(DocumentationContent.Empty, doc)
@@ -71,9 +75,11 @@ public class FunctionTest {
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals("generic function", doc.summary)
- assertEquals(3, details.count())
+ assertEquals(5, details.count())
assertEquals("Unit", details.elementAt(0).name)
- with(details.elementAt(1)) {
+ assertEquals("final", details.elementAt(1).name)
+ assertEquals("public", details.elementAt(2).name)
+ with(details.elementAt(3)) {
assertEquals("T", name)
assertEquals(DocumentationNode.Kind.TypeParameter, kind)
assertEquals(DocumentationContent.Empty, doc)
@@ -88,7 +94,7 @@ public class FunctionTest {
assertTrue(members.none())
assertTrue(links.none())
}
- with(details.elementAt(2)) {
+ with(details.elementAt(4)) {
assertEquals("R", name)
assertEquals(DocumentationNode.Kind.TypeParameter, kind)
assertEquals(DocumentationContent.Empty, doc)
@@ -112,9 +118,11 @@ Function
Documentation"""
, doc.summary)
- assertEquals(2, details.count())
+ assertEquals(4, details.count())
assertEquals("Unit", details.elementAt(0).name)
- with(details.elementAt(1)) {
+ assertEquals("final", details.elementAt(1).name)
+ assertEquals("internal", details.elementAt(2).name)
+ with(details.elementAt(3)) {
assertEquals("x", name)
assertEquals(DocumentationNode.Kind.Parameter, kind)
assertEquals("parameter", doc.summary)
diff --git a/test/src/model/PropertyTest.kt b/test/src/model/PropertyTest.kt
index 7768af90..07651ce2 100644
--- a/test/src/model/PropertyTest.kt
+++ b/test/src/model/PropertyTest.kt
@@ -11,7 +11,7 @@ public class PropertyTest {
assertEquals("property", name)
assertEquals(DocumentationNode.Kind.Property, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(members.none())
assertTrue(links.none())
}
@@ -24,7 +24,7 @@ public class PropertyTest {
assertEquals("property", name)
assertEquals(DocumentationNode.Kind.Property, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(members.none())
assertTrue(links.none())
}
@@ -37,13 +37,13 @@ public class PropertyTest {
assertEquals("property", name)
assertEquals(DocumentationNode.Kind.Property, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
with(members.single()) {
assertEquals("<get-property>", name)
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
assertTrue(members.none())
}
@@ -57,7 +57,19 @@ public class PropertyTest {
assertEquals("property", name)
assertEquals(DocumentationNode.Kind.Property, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals(3, details.count())
+ with(details.elementAt(0)) {
+ assertEquals(DocumentationNode.Kind.Type, kind)
+ assertEquals("String", name)
+ }
+ with(details.elementAt(1)) {
+ assertEquals(DocumentationNode.Kind.Modifier, kind)
+ assertEquals("final", name)
+ }
+ with(details.elementAt(2)) {
+ assertEquals(DocumentationNode.Kind.Modifier, kind)
+ assertEquals("internal", name)
+ }
assertTrue(links.none())
assertEquals(2, members.count())
@@ -65,7 +77,7 @@ public class PropertyTest {
assertEquals("<get-property>", name)
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
assertTrue(members.none())
}
@@ -73,13 +85,15 @@ public class PropertyTest {
assertEquals("<set-property>", name)
assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals(2, details.count())
+ assertEquals(4, details.count())
assertEquals("Unit", details.elementAt(0).name)
- with(details.elementAt(1)) {
+ assertEquals("final", details.elementAt(1).name)
+ assertEquals("internal", details.elementAt(2).name)
+ with(details.elementAt(3)) {
assertEquals("value", name)
assertEquals(DocumentationNode.Kind.Parameter, kind)
assertEquals(DocumentationContent.Empty, doc)
- assertEquals("String", details.single().name)
+ assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
assertTrue(members.none())
}