From 82e3673b77128ec39d09e9e96c61c3de6791557a Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Mon, 24 Feb 2020 12:21:48 +0100 Subject: Amendments to new Documentables model --- core/src/main/kotlin/model/Documentable.kt | 99 ++++++++++++++++-------------- 1 file changed, 54 insertions(+), 45 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 8b059795..3c97feaf 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,8 +1,10 @@ package org.jetbrains.dokka.model +import com.intellij.psi.PsiNamedElement import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.Visibility abstract class Documentable { @@ -33,11 +35,15 @@ abstract class Documentable { data class PlatformDependent(val map: Map) : Map by map { val prevalentValue: T? get() = if (map.all { values.first() == it.value }) values.first() else null + + companion object { + fun empty() = PlatformDependent(mapOf()) + } } interface WithExpectActual { - val expect: Documentable? - val actual: PlatformDependent + val expect: DocumentableSource? + val actual: PlatformDependent } interface WithScope { @@ -81,17 +87,15 @@ interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual val receiver: PlatformDependent } -interface CanBeSupertype - -interface Classlike : WithScope, WithVisibility, WithExpectActual, CanBeSupertype { - val supertypes: PlatformDependent +abstract class Classlike : Documentable(), WithScope, WithVisibility, WithExpectActual { + abstract val supertypes: PlatformDependent> } class Module( override val name: String, override val packages: List, override val documentation: PlatformDependent, - override val original: PlatformDependent + override val original: PlatformDependent = PlatformDependent.empty() ) : Documentable(), WithPackages { override val dri: DRI = DRI.topLevel override val children: List @@ -105,11 +109,11 @@ class Package( override val classlikes: List, override val packages: List, override val documentation: PlatformDependent, - override val original: PlatformDependent + override val original: PlatformDependent = PlatformDependent.empty() ) : Documentable(), WithScope, WithPackages { override val name = dri.packageName.orEmpty() override val children: List - get() = (functions + properties + classlikes + packages) as List + get() = (properties + functions + classlikes + packages) as List } class Class( @@ -119,18 +123,18 @@ class Class( override val functions: List, override val properties: List, override val classlikes: List, - override val expect: Class?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val visibility: PlatformDependent, - override val companion: Object, + override val companion: Object?, override val generics: PlatformDependent, - override val supertypes: PlatformDependent, + override val supertypes: PlatformDependent>, override val documentation: PlatformDependent, - override val original: PlatformDependent, + override val original: PlatformDependent = PlatformDependent.empty(), override val modifier: PlatformDependent -) : Documentable(), Classlike, WithAbstraction, WithCompanion, WithConstructors, WithGenerics { +) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics { override val children: List - get() = (functions + properties + classlikes + companion + constructors) as List + get() = (functions + properties + classlikes + listOfNotNull(companion) + constructors) as List } class Enum( @@ -138,19 +142,19 @@ class Enum( override val name: String, val entries: List, override val documentation: PlatformDependent, - override val expect: Enum?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val functions: List, override val properties: List, override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object, + override val companion: Object?, override val constructors: List, - override val supertypes: PlatformDependent, - override val original: PlatformDependent -) : Documentable(), Classlike, WithCompanion, WithConstructors { + override val supertypes: PlatformDependent>, + override val original: PlatformDependent = PlatformDependent.empty() +) : Classlike(), WithCompanion, WithConstructors { override val children: List - get() = (entries + functions + properties + classlikes + listOf(companion) + constructors) as List + get() = (entries + functions + properties + classlikes + listOfNotNull(companion) + constructors) as List } class EnumEntry( @@ -160,7 +164,7 @@ class EnumEntry( override val functions: List, override val properties: List, override val classlikes: List, - override val original: PlatformDependent + override val original: PlatformDependent = PlatformDependent.empty() ) : Documentable(), WithScope { override val children: List get() = (functions + properties + classlikes) as List @@ -173,13 +177,13 @@ class Function( val returnType: TypeWrapper?, val parameters: List, override val documentation: PlatformDependent, - override val expect: Function?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val visibility: PlatformDependent, override val type: PlatformDependent, override val generics: PlatformDependent, override val receiver: PlatformDependent, - override val original: PlatformDependent, + override val original: PlatformDependent = PlatformDependent.empty(), override val modifier: PlatformDependent ) : Documentable(), Callable, WithGenerics { override val children: List @@ -191,18 +195,18 @@ class Interface( override val dri: DRI, override val documentation: PlatformDependent, override val original: PlatformDependent, - override val expect: Interface?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val functions: List, override val properties: List, override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object, + override val companion: Object?, override val generics: PlatformDependent, - override val supertypes: PlatformDependent -) : Documentable(), Classlike, WithCompanion, WithGenerics { + override val supertypes: PlatformDependent> +) : Classlike(), WithCompanion, WithGenerics { override val children: List - get() = (functions + properties + classlikes + companion) as List + get() = (functions + properties + classlikes + listOfNotNull(companion)) as List } class Object( @@ -210,14 +214,14 @@ class Object( override val dri: DRI, override val documentation: PlatformDependent, override val original: PlatformDependent, - override val expect: Object?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val functions: List, override val properties: List, override val classlikes: List, override val visibility: PlatformDependent, - override val supertypes: PlatformDependent -) : Documentable(), Classlike { + override val supertypes: PlatformDependent> +) : Classlike() { override val children: List get() = (functions + properties + classlikes) as List } @@ -227,30 +231,30 @@ class Annotation( override val dri: DRI, override val documentation: PlatformDependent, override val original: PlatformDependent, - override val expect: Annotation?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val functions: List, override val properties: List, override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object, + override val companion: Object?, override val constructors: List -) : Documentable(), WithScope, WithVisibility, WithCompanion, WithConstructors, WithExpectActual, CanBeSupertype { +) : Documentable(), WithScope, WithVisibility, WithCompanion, WithConstructors, WithExpectActual { override val children: List - get() = (functions + properties + classlikes + constructors + companion) as List + get() = (functions + properties + classlikes + constructors + listOfNotNull(companion)) as List } class Property( override val dri: DRI, override val name: String, override val documentation: PlatformDependent, - override val expect: Property?, - override val actual: PlatformDependent, + override val expect: DocumentableSource?, + override val actual: PlatformDependent, override val visibility: PlatformDependent, override val type: PlatformDependent, override val receiver: PlatformDependent, val accessors: PlatformDependent, // TODO > extra - override val original: PlatformDependent, + override val original: PlatformDependent = PlatformDependent.empty(), override val modifier: PlatformDependent ) : Documentable(), Callable { override val children: List @@ -282,3 +286,8 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = interface Extra object STATIC : Extra +object INHERITED: Extra + +sealed class DocumentableSource +class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor): DocumentableSource() +class PsiDocumentableSource(val psi: PsiNamedElement): DocumentableSource() -- cgit