aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2014-12-30 16:34:08 +0100
committerDmitry Jemerov <yole@jetbrains.com>2014-12-30 16:37:19 +0100
commitef51f7e2466e28db0943d528b6b489aefd098c0d (patch)
treefed7da99ea57a6cd5443d2fb40ae90c38431d800
parent5f47bc17630ef1457b36054dc8b19011d9d14132 (diff)
downloaddokka-ef51f7e2466e28db0943d528b6b489aefd098c0d.tar.gz
dokka-ef51f7e2466e28db0943d528b6b489aefd098c0d.tar.bz2
dokka-ef51f7e2466e28db0943d528b6b489aefd098c0d.zip
annotations work in progress
-rw-r--r--src/Kotlin/DocumentationBuilder.kt20
-rw-r--r--src/Model/DocumentationNode.kt4
-rw-r--r--src/Model/DocumentationReference.kt1
-rw-r--r--test/data/classes/annotatedClass.kt1
-rw-r--r--test/data/format/annotations.kt4
-rw-r--r--test/data/format/annotations.md0
-rw-r--r--test/data/functions/annotatedFunction.kt2
-rw-r--r--test/data/functions/functionWithAnnotatedParam.kt2
-rw-r--r--test/data/properties/annotatedProperty.kt1
-rw-r--r--test/src/format/MarkdownFormatTest.kt6
-rw-r--r--test/src/model/ClassTest.kt14
-rw-r--r--test/src/model/FunctionTest.kt30
-rw-r--r--test/src/model/PropertyTest.kt13
13 files changed, 97 insertions, 1 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index aeea4a55..0cc17d1f 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -6,6 +6,8 @@ import org.jetbrains.jet.lang.types.*
import org.jetbrains.jet.lang.types.lang.*
import org.jetbrains.jet.lang.resolve.name.*
import org.jetbrains.jet.lang.resolve.lazy.*
+import org.jetbrains.jet.lang.descriptors.annotations.Annotated
+import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
public data class DocumentationOptions(val includeNonPublic: Boolean = false)
@@ -104,6 +106,12 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
node.appendProjection(typeArgument)
}
+ fun DocumentationNode.appendAnnotations(annotated: Annotated) {
+ annotated.getAnnotations().forEach {
+ append(it.build(), DocumentationReference.Kind.Annotation)
+ }
+ }
+
fun DocumentationNode.appendChild(descriptor: DeclarationDescriptor, kind: DocumentationReference.Kind) {
// do not include generated code
if (descriptor is CallableMemberDescriptor && descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION)
@@ -168,6 +176,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
node.appendChildren(classObjectDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
DocumentationReference.Kind.Member)
}
+ node.appendAnnotations(this)
register(this, node)
return node
}
@@ -189,6 +198,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
node.appendChildren(getValueParameters(), DocumentationReference.Kind.Detail)
node.appendType(getReturnType())
+ node.appendAnnotations(this)
register(this, node)
return node
@@ -210,6 +220,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
node.appendChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
node.appendType(getReturnType())
+ node.appendAnnotations(this)
getGetter()?.let {
if (!it.isDefault())
node.appendChild(it, DocumentationReference.Kind.Member)
@@ -226,6 +237,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
fun ValueParameterDescriptor.build(): DocumentationNode {
val node = DocumentationNode(this, Kind.Parameter)
node.appendType(getType())
+ node.appendAnnotations(this)
register(this, node)
return node
}
@@ -255,6 +267,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
val constraintNode = DocumentationNode(constraint.toString(), Content.Empty, DocumentationNode.Kind.LowerBound)
node.append(constraintNode, DocumentationReference.Kind.Detail)
}
+ node.appendAnnotations(this)
return node
}
@@ -264,6 +277,13 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return node
}
+ fun AnnotationDescriptor.build(): DocumentationNode {
+ val annotationClass = getType().getConstructor().getDeclarationDescriptor()
+ val node = DocumentationNode(annotationClass.getName().asString(), Content.Empty, DocumentationNode.Kind.Annotation)
+ // TODO handle parameters
+ return node
+ }
+
/**
* Generates cross-references for documentation such as extensions for a type, inheritors, etc
*
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index 86d2ee04..783dea1c 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -30,6 +30,8 @@ public open class DocumentationNode(val name: String,
get() = references(DocumentationReference.Kind.Inheritor).map { it.to }
public val links: List<DocumentationNode>
get() = references(DocumentationReference.Kind.Link).map { it.to }
+ public val annotations: List<DocumentationNode>
+ get() = references(DocumentationReference.Kind.Annotation).map { it.to }
// TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice
public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReference.Kind) {
@@ -85,6 +87,8 @@ public open class DocumentationNode(val name: String,
Modifier
Module
+
+ Annotation
}
}
diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt
index 1849fe08..9fb366cb 100644
--- a/src/Model/DocumentationReference.kt
+++ b/src/Model/DocumentationReference.kt
@@ -9,6 +9,7 @@ public data class DocumentationReference(val from: DocumentationNode, val to: Do
Extension
Inheritor
Override
+ Annotation
}
}
diff --git a/test/data/classes/annotatedClass.kt b/test/data/classes/annotatedClass.kt
new file mode 100644
index 00000000..62c6f0ec
--- /dev/null
+++ b/test/data/classes/annotatedClass.kt
@@ -0,0 +1 @@
+data class Foo() {}
diff --git a/test/data/format/annotations.kt b/test/data/format/annotations.kt
new file mode 100644
index 00000000..445ec969
--- /dev/null
+++ b/test/data/format/annotations.kt
@@ -0,0 +1,4 @@
+data class Foo {
+ inline fun bar() {
+ }
+}
diff --git a/test/data/format/annotations.md b/test/data/format/annotations.md
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/data/format/annotations.md
diff --git a/test/data/functions/annotatedFunction.kt b/test/data/functions/annotatedFunction.kt
new file mode 100644
index 00000000..11c19672
--- /dev/null
+++ b/test/data/functions/annotatedFunction.kt
@@ -0,0 +1,2 @@
+inline fun f() {
+}
diff --git a/test/data/functions/functionWithAnnotatedParam.kt b/test/data/functions/functionWithAnnotatedParam.kt
new file mode 100644
index 00000000..8922f765
--- /dev/null
+++ b/test/data/functions/functionWithAnnotatedParam.kt
@@ -0,0 +1,2 @@
+fun function([noinline] notInlined: () -> Unit) {
+}
diff --git a/test/data/properties/annotatedProperty.kt b/test/data/properties/annotatedProperty.kt
new file mode 100644
index 00000000..f70c28b4
--- /dev/null
+++ b/test/data/properties/annotatedProperty.kt
@@ -0,0 +1 @@
+inline val property = "test" \ No newline at end of file
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index 5cdfb8b5..e9852964 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -19,4 +19,10 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
+
+ Test fun annotations() {
+ verifyOutput("test/data/format/annotations.kt") { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}
diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt
index b95a31dc..b9be30bf 100644
--- a/test/src/model/ClassTest.kt
+++ b/test/src/model/ClassTest.kt
@@ -167,3 +167,17 @@ public class ClassTest {
}
}
}
+
+ Test fun annotatedClass() {
+ verifyModel("test/data/classes/annotatedClass.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(1, annotations.count())
+ with(annotations[0]) {
+ assertEquals("data", name)
+ assertEquals(Content.Empty, content)
+ assertEquals(DocumentationNode.Kind.Annotation, kind)
+ }
+ }
+ }
+ }
+}
diff --git a/test/src/model/FunctionTest.kt b/test/src/model/FunctionTest.kt
index 2a4ad0a5..d3d7843a 100644
--- a/test/src/model/FunctionTest.kt
+++ b/test/src/model/FunctionTest.kt
@@ -135,4 +135,32 @@ Documentation""", content.description.toTestString())
}
}
}
-} \ No newline at end of file
+
+ Test fun annotatedFunction() {
+ verifyModel("test/data/functions/annotatedFunction.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(1, annotations.count())
+ with(annotations[0]) {
+ assertEquals("inline", name)
+ assertEquals(Content.Empty, content)
+ assertEquals(DocumentationNode.Kind.Annotation, kind)
+ }
+ }
+ }
+ }
+
+ Test fun functionWithAnnotatedParam() {
+ verifyModel("test/data/functions/functionWithAnnotatedParam.kt") { model ->
+ with(model.members.single().members.single()) {
+ with(details.elementAt(2)) {
+ assertEquals(1, annotations.count())
+ with(annotations[0]) {
+ assertEquals("noinline", name)
+ assertEquals(Content.Empty, content)
+ assertEquals(DocumentationNode.Kind.Annotation, kind)
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/test/src/model/PropertyTest.kt b/test/src/model/PropertyTest.kt
index 103da170..0bf9714d 100644
--- a/test/src/model/PropertyTest.kt
+++ b/test/src/model/PropertyTest.kt
@@ -99,4 +99,17 @@ public class PropertyTest {
}
}
}
+
+ Test fun annotatedProperty() {
+ verifyModel("test/data/properties/annotatedProperty.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(1, annotations.count())
+ with(annotations[0]) {
+ assertEquals("inline", name)
+ assertEquals(Content.Empty, content)
+ assertEquals(DocumentationNode.Kind.Annotation, kind)
+ }
+ }
+ }
+ }
}