diff options
Diffstat (limited to 'core/src/main/kotlin/Model')
-rw-r--r-- | core/src/main/kotlin/Model/DocumentationNode.kt | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index 1871e21c..48bad7eb 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -2,13 +2,14 @@ package org.jetbrains.dokka.Model import org.jetbrains.dokka.links.DRI import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag class Module(val packages: List<Package>) : DocumentationNode<Nothing>() { - override val dri: DRI - get() = DRI.topLevel + override val docTag: KDocTag? = null - override val children: List<Package> - get() = packages + override val dri: DRI = DRI.topLevel + + override val children: List<Package> = packages } class Package( @@ -18,6 +19,8 @@ class Package( override val classes: List<Class> ) : ScopeNode<Nothing>() { val name = dri.packageName.orEmpty() + + override val docTag: KDocTag? = null } class Class( @@ -26,6 +29,7 @@ class Class( override val functions: List<Function>, override val properties: List<Property>, override val classes: List<Class>, + override val docTag: KDocTag?, override val descriptor: ClassDescriptor ) : ScopeNode<ClassDescriptor>() @@ -34,6 +38,7 @@ class Function( val name: String, override val receiver: Parameter?, val parameters: List<Parameter>, + override val docTag: KDocTag?, override val descriptor: FunctionDescriptor ) : CallableNode<FunctionDescriptor>() { override val children: List<Parameter> @@ -44,6 +49,7 @@ class Property( override val dri: DRI, val name: String, override val receiver: Parameter?, + override val docTag: KDocTag?, override val descriptor: PropertyDescriptor ) : CallableNode<PropertyDescriptor>() { override val children: List<Parameter> @@ -53,6 +59,7 @@ class Property( class Parameter( override val dri: DRI, val name: String?, + override val docTag: KDocTag?, override val descriptor: ParameterDescriptor ) : DocumentationNode<ParameterDescriptor>() { override val children: List<DocumentationNode<*>> @@ -62,17 +69,25 @@ class Parameter( abstract class DocumentationNode<out T : DeclarationDescriptor> { open val descriptor: T? = null + abstract val docTag: KDocTag? // TODO: replace in the future with more robust doc-comment model + abstract val dri: DRI abstract val children: List<DocumentationNode<*>> override fun toString(): String { - return "${javaClass.simpleName}($dri)" + return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]"}.orEmpty() } override fun equals(other: Any?) = other is DocumentationNode<*> && this.dri == other.dri override fun hashCode() = dri.hashCode() + + val rawDocstring: String + get() = docTag?.getContent().orEmpty() + + val briefDocstring: String + get() = rawDocstring.shorten(40) } abstract class ScopeNode<out T : ClassOrPackageFragmentDescriptor> : DocumentationNode<T>() { @@ -86,4 +101,8 @@ abstract class ScopeNode<out T : ClassOrPackageFragmentDescriptor> : Documentati abstract class CallableNode<out T : CallableDescriptor> : DocumentationNode<T>() { abstract val receiver: Parameter? +} + +private fun String.shorten(maxLength: Int) = lineSequence().first().let { + if (it.length != length || it.length > maxLength) it.take(maxLength - 3) + "..." else it }
\ No newline at end of file |