diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2016-01-04 21:29:24 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2016-01-04 21:29:24 +0100 |
commit | efd848a7d5f5f241de4696d34a500d76f51b3cbc (patch) | |
tree | e45bfeef1786c9226efbfa353a2c0ab12b8b8dad /core/src/main/kotlin | |
parent | e0d00cba3613d092b6fa6af961378584c7c77b75 (diff) | |
download | dokka-efd848a7d5f5f241de4696d34a500d76f51b3cbc.tar.gz dokka-efd848a7d5f5f241de4696d34a500d76f51b3cbc.tar.bz2 dokka-efd848a7d5f5f241de4696d34a500d76f51b3cbc.zip |
separate groups for annotations and exceptions in the members list
Diffstat (limited to 'core/src/main/kotlin')
5 files changed, 25 insertions, 10 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index e1ca7a62..faa0b1ef 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -187,7 +187,8 @@ abstract class StructuredFormatService(locationService: LocationService, val singleNode = nodes.singleOrNull() if (singleNode != null && singleNode.isModuleOrPackage()) { if (singleNode.kind == NodeKind.Package) { - appendHeader(to, "Package " + formatText(singleNode.name), 2) + val packageName = if (singleNode.name.isEmpty()) "<root>" else singleNode.name + appendHeader(to, "Package " + formatText(packageName), 2) } to.append(formatText(location, singleNode.content)) } else { @@ -275,7 +276,9 @@ abstract class StructuredFormatService(locationService: LocationService, } appendSection("Packages", node.members(NodeKind.Package)) - appendSection("Types", node.members.filter { it.kind in NodeKind.classLike }) + appendSection("Types", node.members.filter { it.kind in NodeKind.classLike && it.kind != NodeKind.AnnotationClass && it.kind != NodeKind.Exception }) + appendSection("Annotations", node.members(NodeKind.AnnotationClass)) + appendSection("Exceptions", node.members(NodeKind.Exception)) appendSection("Extensions for External Classes", node.members(NodeKind.ExternalClass)) appendSection("Enum Values", node.members(NodeKind.EnumItem)) appendSection("Constructors", node.members(NodeKind.Constructor)) @@ -292,6 +295,7 @@ abstract class StructuredFormatService(locationService: LocationService, NodeKind.Enum, NodeKind.Object, NodeKind.AnnotationClass, + NodeKind.Exception, NodeKind.Constructor, NodeKind.Property, NodeKind.Package, diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index c16e66c6..67bf1f08 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.intellij.psi.* +import com.intellij.psi.util.InheritanceUtil fun getSignature(element: PsiElement?) = when(element) { is PsiClass -> element.qualifiedName @@ -141,6 +142,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { isInterface -> NodeKind.Interface isEnum -> NodeKind.Enum isAnnotationType -> NodeKind.AnnotationClass + isException() -> NodeKind.Exception else -> NodeKind.Class } val node = nodeForElement(this, kind) @@ -159,6 +161,8 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { return node } + fun PsiClass.isException() = InheritanceUtil.isInheritor(this, "java.lang.Throwable") + fun ignoreSupertype(psiType: PsiClassType): Boolean = psiType.isClass("java.lang.Enum") || psiType.isClass("java.lang.Object") diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 5deb6177..e3de493a 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.isDocumentedAnnotation import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver @@ -31,6 +32,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection +import org.jetbrains.kotlin.types.typeUtil.supertypes data class DocumentationOptions(val outputDir: String, val outputFormat: String, @@ -283,12 +285,13 @@ class DocumentationBuilder } fun ClassDescriptor.build(): DocumentationNode { - val kind = when (kind) { - ClassKind.OBJECT -> NodeKind.Object - ClassKind.INTERFACE -> NodeKind.Interface - ClassKind.ENUM_CLASS -> NodeKind.Enum - ClassKind.ANNOTATION_CLASS -> NodeKind.AnnotationClass - ClassKind.ENUM_ENTRY -> NodeKind.EnumItem + val kind = when { + kind == ClassKind.OBJECT -> NodeKind.Object + kind == ClassKind.INTERFACE -> NodeKind.Interface + kind == ClassKind.ENUM_CLASS -> NodeKind.Enum + kind == ClassKind.ANNOTATION_CLASS -> NodeKind.AnnotationClass + kind == ClassKind.ENUM_ENTRY -> NodeKind.EnumItem + isSubclassOfThrowable() -> NodeKind.Exception else -> NodeKind.Class } val node = nodeForDescriptor(this, kind) @@ -317,6 +320,9 @@ class DocumentationBuilder return node } + fun ClassDescriptor.isSubclassOfThrowable(): Boolean = + defaultType.supertypes().any { it.constructor.declarationDescriptor == builtIns.throwable } + fun ConstructorDescriptor.build(): DocumentationNode { val node = nodeForDescriptor(this, NodeKind.Constructor) node.appendInPageChildren(valueParameters, RefKind.Detail) diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt index 80f91646..9c9c9fc7 100644 --- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt +++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt @@ -294,6 +294,7 @@ class KotlinLanguageService : LanguageService { when (node.kind) { NodeKind.Class, NodeKind.AnnotationClass, + NodeKind.Exception, NodeKind.Enum -> keyword("class ") NodeKind.Interface -> keyword("interface ") NodeKind.EnumItem -> keyword("enum val ") diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index ba3edc24..121a5764 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -10,6 +10,7 @@ enum class NodeKind { Interface, Enum, AnnotationClass, + Exception, EnumItem, Object, @@ -28,7 +29,6 @@ enum class NodeKind { Supertype, UpperBound, LowerBound, - Exception, Modifier, NullabilityModifier, @@ -50,7 +50,7 @@ enum class NodeKind { OverloadGroupNote; companion object { - val classLike = setOf(Class, Interface, Enum, AnnotationClass, Object) + val classLike = setOf(Class, Interface, Enum, AnnotationClass, Exception, Object) } } |