From 972ec7adb70a62f825bb67dd05d37ebbcbdfd352 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Thu, 31 Oct 2019 19:10:02 +0100 Subject: Model updated --- core/src/main/kotlin/Model/DocumentationNode.kt | 133 ++++++++++++++---------- 1 file changed, 76 insertions(+), 57 deletions(-) (limited to 'core/src/main/kotlin/Model/DocumentationNode.kt') 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(name, parent = parent) +class Module(val packages: List) : DocumentationNode(DRI.topLevel, DRI.topLevel) { + override val children: List + get() = packages +} - class Package(name: String, parent: DocumentationNode<*>): - DocumentationNode(name, parent = parent) +class Package( + val name: String, + override val functions: List, + override val properties: List, + override val classes: List +) : ScopeNode(DRI(packageName = name), DRI.topLevel) - class Class(name: String, descriptor: ClassDescriptor, parent: DocumentationNode<*>? = null) : - DocumentationNode(name, descriptor, parent) { - override val classLike: Boolean = true - val supertypes = mutableListOf() - 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(name, descriptor) { - override val memberLike = true - } +class Class( + val name: String, + override val functions: List, + override val properties: List, + override val classes: List, + override val descriptor: ClassDescriptor, + parent: DRI +) : ScopeNode(parent.withClass(name), parent) - class Function(name: String, descriptor: FunctionDescriptor) : - DocumentationNode(name, descriptor) { - override val memberLike = true - } +class Function( + val name: String, + override val receiver: Parameter?, + val parameters: List, + override val descriptor: FunctionDescriptor, + parent: DRI +) : CallableNode(parent, descriptor) { + override val children: List + get() = listOfNotNull(receiver) + parameters +} - class Property(name: String, descriptor: PropertyDescriptor) : - DocumentationNode(name, descriptor) { - override val memberLike = true - } -/* - class Field(name: String, descriptor: FieldDescriptor) : - DocumentationNode(name, descriptor) { - override val memberLike = true - }*/ +class Property( + val name: String, + override val receiver: Parameter?, + override val descriptor: PropertyDescriptor, + parent: DRI +) : CallableNode(parent, descriptor) { + override val children: List + get() = listOfNotNull(receiver) +} - class Parameter(name: String, descriptor: ParameterDescriptor?) : - DocumentationNode(name, descriptor) -/* - class Annotation(name: String, descriptor: AnnotationDescriptor?) : - DocumentationNode(name, descriptor)*/ +class Parameter( + val name: String, + override val descriptor: ParameterDescriptor, + parent: DRI, + index: Int +) : DocumentationNode(parent, parent.copy(target = index)) { + override val children: List> + get() = emptyList() } -abstract class DocumentationNode( - var name: String, - val descriptor: T? = null, - val parent: DocumentationNode<*>? = null +abstract class DocumentationNode( + val dri: DRI, + val parent: DRI ) { + open val descriptor: T? = null - private val children = mutableListOf>() + abstract val children: List> - 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( + dri: DRI, + parent: DRI +) : DocumentationNode(dri, parent) { + abstract val functions: List + abstract val properties: List + abstract val classes: List + + override val children: List> + get() = functions + properties + classes +} + +abstract class CallableNode( + parent: DRI, + descriptor: CallableDescriptor +) : DocumentationNode(parent.copy(callable = Callable.from(descriptor)), parent) { + abstract val receiver: Parameter? } \ No newline at end of file -- cgit