aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Model/DocumentationNode.kt
blob: 19ba22a6a555a2c50ef966e8e43044dcb90b5757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.jetbrains.dokka

import org.jetbrains.dokka.links.ClassReference
import org.jetbrains.kotlin.descriptors.*

class DocumentationNodes {

    class Module(name: String, parent: DocumentationNode<*>? = null):
        DocumentationNode<Nothing>(name, parent = parent)

    class Package(name: String, parent: DocumentationNode<*>):
        DocumentationNode<Nothing>(name, parent = parent)

    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 Function(name: String, descriptor: FunctionDescriptor) :
        DocumentationNode<FunctionDescriptor>(name, descriptor) {
        override val memberLike = true
    }

    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 Parameter(name: String, descriptor: ParameterDescriptor?) :
        DocumentationNode<ParameterDescriptor>(name, descriptor)
/*
    class Annotation(name: String, descriptor: AnnotationDescriptor?) :
        DocumentationNode<AnnotationDescriptor>(name, descriptor)*/
}

abstract class DocumentationNode<T: DeclarationDescriptor>(
    var name: String,
    val descriptor: T? = null,
    val parent: DocumentationNode<*>? = null
) {

    private val children = mutableListOf<DocumentationNode<*>>()

    open val classLike = false

    open val memberLike = false

    fun addChild(child: DocumentationNode<*>) =
        children.add(child)

    override fun toString(): String {
        return "${javaClass.name}:$name"
    }
}