aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt8
-rw-r--r--core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt4
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt18
-rw-r--r--core/src/main/kotlin/Kotlin/KotlinLanguageService.kt1
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt4
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt22
-rw-r--r--core/testdata/format/annotationClass.package.md11
-rw-r--r--core/testdata/format/deprecated.package.html2
-rw-r--r--core/testdata/format/exceptionClass.kt1
-rw-r--r--core/testdata/format/exceptionClass.md14
-rw-r--r--core/testdata/format/exceptionClass.package.md11
-rw-r--r--core/testdata/format/overloads.html2
12 files changed, 83 insertions, 15 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)
}
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index e2339707..5ec2b637 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -26,9 +26,13 @@ public class MarkdownFormatTest {
}
@Test fun annotationClass() {
- verifyOutput("testdata/format/annotationClass.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("annotationClass", withKotlinRuntime = true)
+ verifyMarkdownPackage("annotationClass", withKotlinRuntime = true)
+ }
+
+ @Test fun exceptionClass() {
+ verifyMarkdownNode("exceptionClass", withKotlinRuntime = true)
+ verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true)
}
@Test fun annotationParams() {
@@ -215,4 +219,16 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
}
}
+
+ private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members)
+ }
+ }
+
+ private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyOutput("testdata/format/$fileName.kt", ".md", withKotlinRuntime = withKotlinRuntime) { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}
diff --git a/core/testdata/format/annotationClass.package.md b/core/testdata/format/annotationClass.package.md
new file mode 100644
index 00000000..f7c8405d
--- /dev/null
+++ b/core/testdata/format/annotationClass.package.md
@@ -0,0 +1,11 @@
+[test](test/index)
+
+
+## Package &lt;root&gt;
+
+
+### Annotations
+
+
+| [fancy](test/fancy/index) | `annotation class fancy` |
+
diff --git a/core/testdata/format/deprecated.package.html b/core/testdata/format/deprecated.package.html
index dd80471c..7658b435 100644
--- a/core/testdata/format/deprecated.package.html
+++ b/core/testdata/format/deprecated.package.html
@@ -5,7 +5,7 @@
<BODY>
<a href="test/index">test</a><br/>
<br/>
-<h2>Package </h2>
+<h2>Package &lt;root&gt;</h2>
<h3>Types</h3>
<table>
<tbody>
diff --git a/core/testdata/format/exceptionClass.kt b/core/testdata/format/exceptionClass.kt
new file mode 100644
index 00000000..d005bd89
--- /dev/null
+++ b/core/testdata/format/exceptionClass.kt
@@ -0,0 +1 @@
+class MyException : Exception
diff --git a/core/testdata/format/exceptionClass.md b/core/testdata/format/exceptionClass.md
new file mode 100644
index 00000000..97160d1c
--- /dev/null
+++ b/core/testdata/format/exceptionClass.md
@@ -0,0 +1,14 @@
+[test](test/index) / [MyException](test/-my-exception/index)
+
+
+# MyException
+
+`class MyException&nbsp;:&nbsp;Exception`
+
+
+
+### Constructors
+
+
+| [&lt;init&gt;](test/-my-exception/-init-) | `MyException()` |
+
diff --git a/core/testdata/format/exceptionClass.package.md b/core/testdata/format/exceptionClass.package.md
new file mode 100644
index 00000000..608aa8ed
--- /dev/null
+++ b/core/testdata/format/exceptionClass.package.md
@@ -0,0 +1,11 @@
+[test](test/index)
+
+
+## Package &lt;root&gt;
+
+
+### Exceptions
+
+
+| [MyException](test/-my-exception/index) | `class MyException&nbsp;:&nbsp;Exception` |
+
diff --git a/core/testdata/format/overloads.html b/core/testdata/format/overloads.html
index 752f3989..896d79a9 100644
--- a/core/testdata/format/overloads.html
+++ b/core/testdata/format/overloads.html
@@ -5,7 +5,7 @@
<BODY>
<a href="test/index">test</a><br/>
<br/>
-<h2>Package </h2>
+<h2>Package &lt;root&gt;</h2>
<h3>Functions</h3>
<table>
<tbody>