From 1ff50691f11876101b53ba02ba6c344ab688d5df Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Tue, 25 Feb 2020 11:40:02 +0100 Subject: Crude Documentable merger --- core/src/main/kotlin/model/Documentable.kt | 50 +++++++++++++++++------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 689b5c9d..48f00474 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -8,6 +8,7 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.load.kotlin.toSourceElement abstract class Documentable { abstract val name: String? @@ -37,7 +38,8 @@ abstract class Documentable { } data class PlatformDependent( - val map: Map, val expect: T? = null + val map: Map, + val expect: T? = null ) : Map by map { val prevalentValue: T? get() = map.values.distinct().singleOrNull() @@ -89,13 +91,15 @@ interface WithGenerics { val generics: List } +interface WithSupertypes { + val supertypes: PlatformDependent> +} + interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual { val receiver: Parameter? } -abstract class Classlike : Documentable(), WithScope, WithVisibility, WithExpectActual { - abstract val supertypes: PlatformDependent> -} +abstract class Classlike : Documentable(), WithScope, WithVisibility, WithExpectActual data class Module( override val name: String, @@ -144,7 +148,9 @@ data class Class( override val modifier: WithAbstraction.Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithExtraProperties { +) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, + WithExtraProperties { + override val children: List get() = (functions + properties + classlikes + listOfNotNull(companion) + constructors) as List @@ -166,7 +172,7 @@ data class Enum( override val supertypes: PlatformDependent>, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithCompanion, WithConstructors, WithExtraProperties { +) : Classlike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { override val children: List get() = (entries + functions + properties + classlikes + listOfNotNull(companion) + constructors) as List @@ -203,7 +209,7 @@ data class Function( override val modifier: WithAbstraction.Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() - ) : Documentable(), Callable, WithGenerics, WithExtraProperties { +) : Documentable(), Callable, WithGenerics, WithExtraProperties { override val children: List get() = parameters @@ -224,7 +230,7 @@ data class Interface( override val supertypes: PlatformDependent>, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithCompanion, WithGenerics, WithExtraProperties { +) : Classlike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { override val children: List get() = (functions + properties + classlikes + listOfNotNull(companion)) as List @@ -243,7 +249,7 @@ data class Object( override val supertypes: PlatformDependent>, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithExtraProperties { +) : Classlike(), WithSupertypes, WithExtraProperties { override val children: List get() = (functions + properties + classlikes) as List @@ -263,9 +269,7 @@ data class Annotation( override val constructors: List, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithScope, WithVisibility, WithCompanion, WithConstructors, WithExpectActual, - WithExtraProperties { - +) : Classlike(), WithCompanion, WithConstructors, WithExtraProperties { override val children: List get() = (functions + properties + classlikes + constructors + listOfNotNull(companion)) as List @@ -280,7 +284,8 @@ data class Property( override val visibility: PlatformDependent, override val type: TypeWrapper, override val receiver: Parameter?, - val accessors: PlatformDependent, // TODO > extra + val setter: Function?, + val getter: Function, override val modifier: WithAbstraction.Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() @@ -313,7 +318,7 @@ data class TypeParameter( val bounds: List, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -): Documentable(), WithExtraProperties { +) : Documentable(), WithExtraProperties { override val children: List get() = emptyList() @@ -321,10 +326,10 @@ data class TypeParameter( } sealed class Projection { - data class OtherParameter(val name: String): Projection() - object Star: Projection() - data class TypeConstructor(val dri: DRI, val projections: List): Projection() - data class Nullable(val inner: Projection): Projection() + data class OtherParameter(val name: String) : Projection() + object Star : Projection() + data class TypeConstructor(val dri: DRI, val projections: List) : Projection() + data class Nullable(val inner: Projection) : Projection() } private fun String.shorten(maxLength: Int) = lineSequence().first().let { @@ -338,6 +343,9 @@ fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } -sealed class DocumentableSource -class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : DocumentableSource() -class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource() +sealed class DocumentableSource(val path: String) + +class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : + DocumentableSource(descriptor.toSourceElement.containingFile.toString()) + +class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource(psi.containingFile.virtualFile.path) \ No newline at end of file -- cgit