aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2014-12-30 17:41:14 +0100
committerDmitry Jemerov <yole@jetbrains.com>2014-12-30 17:41:47 +0100
commit716483c2f20e4af1951342f2acc9a231fcbeab3b (patch)
tree84cd1011021bb6ef38f9567d80805edf17ecc2d7
parent0e70fa4ca021bff09e7d9ce64269a4e698512af5 (diff)
downloaddokka-716483c2f20e4af1951342f2acc9a231fcbeab3b.tar.gz
dokka-716483c2f20e4af1951342f2acc9a231fcbeab3b.tar.bz2
dokka-716483c2f20e4af1951342f2acc9a231fcbeab3b.zip
render annotation classes correctly
-rw-r--r--src/Formats/StructuredFormatService.kt5
-rw-r--r--src/Kotlin/DocumentationBuilder.kt14
-rw-r--r--src/Kotlin/KotlinLanguageService.kt2
-rw-r--r--src/Model/DocumentationNode.kt1
-rw-r--r--test/data/format/annotationClass.kt1
-rw-r--r--test/data/format/annotationClass.md18
-rw-r--r--test/src/format/MarkdownFormatTest.kt6
7 files changed, 44 insertions, 3 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 2d326854..b75f39d1 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -188,7 +188,8 @@ public abstract class StructuredFormatService(val locationService: LocationServi
DocumentationNode.Kind.Class,
DocumentationNode.Kind.Interface,
DocumentationNode.Kind.Enum,
- DocumentationNode.Kind.Object)
+ DocumentationNode.Kind.Object,
+ DocumentationNode.Kind.AnnotationClass)
}, node, to)
appendSection(location, "Constructors", node.members(DocumentationNode.Kind.Constructor), node, to)
appendSection(location, "Properties", node.members(DocumentationNode.Kind.Property), node, to)
@@ -200,7 +201,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi
it.kind !in setOf(
DocumentationNode.Kind.Class,
DocumentationNode.Kind.Interface,
+ DocumentationNode.Kind.Enum,
DocumentationNode.Kind.Object,
+ DocumentationNode.Kind.AnnotationClass,
DocumentationNode.Kind.Constructor,
DocumentationNode.Kind.Property,
DocumentationNode.Kind.Package,
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 0cc17d1f..57f8572f 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -8,6 +8,7 @@ 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
+import org.jetbrains.jet.lang.resolve.DescriptorUtils
public data class DocumentationOptions(val includeNonPublic: Boolean = false)
@@ -75,11 +76,20 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
fun DocumentationNode.appendSupertypes(descriptor: ClassDescriptor) {
val superTypes = descriptor.getTypeConstructor().getSupertypes()
for (superType in superTypes) {
- if (superType.toString() != "Any")
+ if (!ignoreSupertype(superType))
appendType(superType, DocumentationNode.Kind.Supertype)
}
}
+ private fun ignoreSupertype(superType: JetType): Boolean {
+ val superClass = superType.getConstructor()?.getDeclarationDescriptor() as? ClassDescriptor
+ if (superClass != null) {
+ val fqName = DescriptorUtils.getFqNameSafe(superClass).asString()
+ return fqName == "kotlin.Annotation" || fqName == "kotlin.Enum" || fqName == "kotlin.Any"
+ }
+ return false
+ }
+
fun DocumentationNode.appendProjection(projection: TypeProjection, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type) {
val prefix = when (projection.getProjectionKind()) {
Variance.IN_VARIANCE -> "in "
@@ -161,6 +171,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
ClassKind.CLASS_OBJECT -> Kind.Object
ClassKind.TRAIT -> Kind.Interface
ClassKind.ENUM_CLASS -> Kind.Enum
+ ClassKind.ANNOTATION_CLASS -> Kind.AnnotationClass
ClassKind.ENUM_ENTRY -> Kind.EnumItem
else -> Kind.Class
}
@@ -267,7 +278,6 @@ 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
}
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index 1e5edf4d..0538ba74 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -14,6 +14,7 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Interface,
DocumentationNode.Kind.Enum,
DocumentationNode.Kind.EnumItem,
+ DocumentationNode.Kind.AnnotationClass,
DocumentationNode.Kind.Object -> renderClass(node)
DocumentationNode.Kind.TypeParameter -> renderTypeParameter(node)
@@ -181,6 +182,7 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Class -> keyword("class ")
DocumentationNode.Kind.Interface -> keyword("trait ")
DocumentationNode.Kind.Enum -> keyword("enum class ")
+ DocumentationNode.Kind.AnnotationClass -> keyword("annotation class ")
DocumentationNode.Kind.EnumItem -> keyword("enum val ")
DocumentationNode.Kind.Object -> keyword("object ")
else -> throw IllegalArgumentException("Node $node is not a class-like object")
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index 783dea1c..0698a5d0 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -64,6 +64,7 @@ public open class DocumentationNode(val name: String,
Class
Interface
Enum
+ AnnotationClass
EnumItem
Object
diff --git a/test/data/format/annotationClass.kt b/test/data/format/annotationClass.kt
new file mode 100644
index 00000000..89d494fb
--- /dev/null
+++ b/test/data/format/annotationClass.kt
@@ -0,0 +1 @@
+annotation class fancy
diff --git a/test/data/format/annotationClass.md b/test/data/format/annotationClass.md
new file mode 100644
index 00000000..bfaa8581
--- /dev/null
+++ b/test/data/format/annotationClass.md
@@ -0,0 +1,18 @@
+[test](out.md) / [](out.md) / [fancy](out.md)
+
+
+# fancy
+
+
+```
+annotation class fancy
+```
+
+
+
+
+### Constructors
+
+
+| [&lt;init&gt;](out.md) | `public fancy()` |
+
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index 531980de..a1fc7ac1 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -25,4 +25,10 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
+
+ Test fun annotationClass() {
+ verifyOutput("test/data/format/annotationClass.kt", ".md") { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}