aboutsummaryrefslogtreecommitdiff
path: root/core/src
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
parent6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a (diff)
downloaddokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.tar.gz
dokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.tar.bz2
dokka-972ec7adb70a62f825bb67dd05d37ebbcbdfd352.zip
Model updated
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt133
-rw-r--r--core/src/main/kotlin/links/DRI.kt69
-rw-r--r--core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt1
3 files changed, 130 insertions, 73 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
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index 35eb6497..7ab25444 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -1,22 +1,28 @@
package org.jetbrains.dokka.links
+import org.jetbrains.kotlin.descriptors.CallableDescriptor
+import org.jetbrains.kotlin.types.KotlinType
import java.text.ParseException
/**
* [DRI] stands for DokkaResourceIdentifier
*/
-data class DRI(val packageName: String? = null,
- val classNames: String? = null,
- val callable: Callable? = null,
- val target: Int? = null,
- val extra: String? = null) {
-
- constructor(packageName: String? = null,
- classNames: String? = null,
- callableName: String? = null,
- signature: String? = null,
- target: Int? = null,
- extra: String? = null) : this(packageName, classNames, Callable.from(callableName, signature), target, extra)
+data class DRI(
+ val packageName: String? = null,
+ val classNames: String? = null,
+ val callable: Callable? = null,
+ val target: Int? = null,
+ val extra: String? = null
+) {
+
+ constructor(
+ packageName: String? = null,
+ classNames: String? = null,
+ callableName: String? = null,
+ signature: String? = null,
+ target: Int? = null,
+ extra: String? = null
+ ) : this(packageName, classNames, Callable.from(callableName, signature), target, extra)
override fun toString(): String =
"${packageName.orEmpty()}/${classNames.orEmpty()}/${callable?.name.orEmpty()}/${callable?.signature().orEmpty()}/${target?.toString().orEmpty()}/${extra.orEmpty()}"
@@ -29,7 +35,11 @@ data class DRI(val packageName: String? = null,
DRI(
packageName,
classNames,
- try { Callable.from(callableName, callableSignature) } catch(e: ParseException) { null },
+ try {
+ Callable.from(callableName, callableSignature)
+ } catch (e: ParseException) {
+ null
+ },
target?.toInt(),
ext
)
@@ -37,11 +47,25 @@ data class DRI(val packageName: String? = null,
} catch (e: Throwable) {
throw ParseException(s, 0)
}
+
+ val topLevel = DRI()
}
}
+fun DRI.withClass(name: String) = copy(classNames = classNames.orEmpty() + ".$name")
+
+val DRI.parent: DRI
+ get() = when {
+ extra != null -> copy(extra = null)
+ target != null -> copy(target = null)
+ callable != null -> copy(callable = null)
+ classNames != null -> copy(classNames = classNames.substringBeforeLast('.').takeIf { it.isNotBlank() })
+ else -> DRI.topLevel
+ }
+
data class Callable(val name: String, val receiver: String, val returnType: String, val params: List<String>) {
- fun signature() = "$receiver.$returnType.${params.joinToString(".")}"
+ fun signature() = "$receiver#$returnType#${params.joinToString("#")}"
+
companion object {
fun from(name: String?, signature: String?): Callable = try {
signature.toString()
@@ -63,10 +87,25 @@ data class Callable(val name: String, val receiver: String, val returnType: Stri
} catch (e: Throwable) {
throw ParseException(s, 0)
}
+
+ fun from(descriptor: CallableDescriptor) = with(descriptor) {
+ Callable(
+ name.asString(),
+ extensionReceiverParameter?.value?.type?.constructorName.orEmpty(),
+ returnType?.constructorName.orEmpty(),
+ valueParameters.map { it.type.constructorName.orEmpty() }
+ )
+ }
}
}
-data class ClassReference(val dri: DRI, val subs: MutableList<ClassReference> = mutableListOf())
+data class ClassReference(val dri: DRI, val subs: MutableList<ClassReference> = mutableListOf()) {
+ private val subsText = subs.takeIf { it.isNotEmpty() }?.toString().orEmpty()
+ override fun toString() = "$dri$subsText"
+}
private operator fun <T> List<T>.component6(): T = get(5)
+private val KotlinType.constructorName
+ get() = constructor.declarationDescriptor?.name?.asString()
+
diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
index 13e9b0d0..fd2e6797 100644
--- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
+++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.transformers
import org.jetbrains.dokka.DocumentationNode
-import org.jetbrains.dokka.DocumentationNodes
import org.jetbrains.dokka.pages.ContentNode
import org.jetbrains.dokka.pages.ContentSymbol
import org.jetbrains.dokka.pages.ModulePageNode