aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Model/DocumentationNode.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-10-31 19:10:02 +0100
committerPaweł Marks <pmarks@virtuslab.com>2019-10-31 19:10:02 +0100
commit972ec7adb70a62f825bb67dd05d37ebbcbdfd352 (patch)
tree9114e17c701f6183c123783ce576c260cc0fe819 /core/src/main/kotlin/Model/DocumentationNode.kt
parent6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a (diff)
downloaddokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.tar.gz
dokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.tar.bz2
dokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.zip
Model updated
Diffstat (limited to 'core/src/main/kotlin/Model/DocumentationNode.kt')
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt133
1 files changed, 76 insertions, 57 deletions
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt
index 19ba22a6..5312915b 100644
--- a/core/src/main/kotlin/Model/DocumentationNode.kt
+++ b/core/src/main/kotlin/Model/DocumentationNode.kt
@@ -1,75 +1,94 @@
package org.jetbrains.dokka
-import org.jetbrains.dokka.links.ClassReference
+import org.jetbrains.dokka.links.Callable
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.links.withClass
import org.jetbrains.kotlin.descriptors.*
-class DocumentationNodes {
-
- class Module(name: String, parent: DocumentationNode<*>? = null):
- DocumentationNode<Nothing>(name, parent = parent)
+class Module(val packages: List<Package>) : DocumentationNode<Nothing>(DRI.topLevel, DRI.topLevel) {
+ override val children: List<Package>
+ get() = packages
+}
- class Package(name: String, parent: DocumentationNode<*>):
- DocumentationNode<Nothing>(name, parent = parent)
+class Package(
+ val name: String,
+ override val functions: List<Function>,
+ override val properties: List<Property>,
+ override val classes: List<Class>
+) : ScopeNode<Nothing>(DRI(packageName = name), DRI.topLevel)
- class Class(name: String, descriptor: ClassDescriptor, parent: DocumentationNode<*>? = null) :
- DocumentationNode<ClassDescriptor>(name, descriptor, parent) {
- override val classLike: Boolean = true
- val supertypes = mutableListOf<ClassReference>()
- val isInterface: Boolean
- get() = descriptor?.kind == ClassKind.CLASS
- val isEnum: Boolean
- get() = descriptor?.kind == ClassKind.ENUM_CLASS
- val isEnumEntry: Boolean
- get() = descriptor?.kind == ClassKind.ENUM_ENTRY
- val isAnnotationClass: Boolean
- get() = descriptor?.kind == ClassKind.ANNOTATION_CLASS
- val isObject: Boolean
- get() = descriptor?.kind == ClassKind.OBJECT
- }
-
- class Constructor(name: String, descriptor: ConstructorDescriptor) :
- DocumentationNode<ConstructorDescriptor>(name, descriptor) {
- override val memberLike = true
- }
+class Class(
+ val name: String,
+ override val functions: List<Function>,
+ override val properties: List<Property>,
+ override val classes: List<Class>,
+ override val descriptor: ClassDescriptor,
+ parent: DRI
+) : ScopeNode<ClassDescriptor>(parent.withClass(name), parent)
- class Function(name: String, descriptor: FunctionDescriptor) :
- DocumentationNode<FunctionDescriptor>(name, descriptor) {
- override val memberLike = true
- }
+class Function(
+ val name: String,
+ override val receiver: Parameter?,
+ val parameters: List<Parameter>,
+ override val descriptor: FunctionDescriptor,
+ parent: DRI
+) : CallableNode<FunctionDescriptor>(parent, descriptor) {
+ override val children: List<Parameter>
+ get() = listOfNotNull(receiver) + parameters
+}
- class Property(name: String, descriptor: PropertyDescriptor) :
- DocumentationNode<PropertyDescriptor>(name, descriptor) {
- override val memberLike = true
- }
-/*
- class Field(name: String, descriptor: FieldDescriptor) :
- DocumentationNode<FieldDescriptor>(name, descriptor) {
- override val memberLike = true
- }*/
+class Property(
+ val name: String,
+ override val receiver: Parameter?,
+ override val descriptor: PropertyDescriptor,
+ parent: DRI
+) : CallableNode<PropertyDescriptor>(parent, descriptor) {
+ override val children: List<Parameter>
+ get() = listOfNotNull(receiver)
+}
- class Parameter(name: String, descriptor: ParameterDescriptor?) :
- DocumentationNode<ParameterDescriptor>(name, descriptor)
-/*
- class Annotation(name: String, descriptor: AnnotationDescriptor?) :
- DocumentationNode<AnnotationDescriptor>(name, descriptor)*/
+class Parameter(
+ val name: String,
+ override val descriptor: ParameterDescriptor,
+ parent: DRI,
+ index: Int
+) : DocumentationNode<ParameterDescriptor>(parent, parent.copy(target = index)) {
+ override val children: List<DocumentationNode<*>>
+ get() = emptyList()
}
-abstract class DocumentationNode<T: DeclarationDescriptor>(
- var name: String,
- val descriptor: T? = null,
- val parent: DocumentationNode<*>? = null
+abstract class DocumentationNode<out T : DeclarationDescriptor>(
+ val dri: DRI,
+ val parent: DRI
) {
+ open val descriptor: T? = null
- private val children = mutableListOf<DocumentationNode<*>>()
+ abstract val children: List<DocumentationNode<*>>
- open val classLike = false
+ override fun toString(): String {
+ return "${javaClass.name}($dri)"
+ }
- open val memberLike = false
+ override fun equals(other: Any?) = other is DocumentationNode<*> && this.dri == other.dri
- fun addChild(child: DocumentationNode<*>) =
- children.add(child)
+ override fun hashCode() = dri.hashCode()
+}
- override fun toString(): String {
- return "${javaClass.name}:$name"
- }
+abstract class ScopeNode<out T : ClassOrPackageFragmentDescriptor>(
+ dri: DRI,
+ parent: DRI
+) : DocumentationNode<T>(dri, parent) {
+ abstract val functions: List<Function>
+ abstract val properties: List<Property>
+ abstract val classes: List<Class>
+
+ override val children: List<DocumentationNode<MemberDescriptor>>
+ get() = functions + properties + classes
+}
+
+abstract class CallableNode<out T: CallableDescriptor>(
+ parent: DRI,
+ descriptor: CallableDescriptor
+) : DocumentationNode<T>(parent.copy(callable = Callable.from(descriptor)), parent) {
+ abstract val receiver: Parameter?
} \ No newline at end of file