From b62126328f0778abe21d3334f5a713086cb3d15e Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Wed, 26 Feb 2020 15:51:07 +0100 Subject: Adding psi parsing for new model --- core/src/main/kotlin/model/Documentable.kt | 16 +++++++++------- core/src/main/kotlin/model/documentableProperties.kt | 14 ++++++++++++++ .../main/kotlin/model/properties/PropertyContainer.kt | 13 ++++++------- core/src/main/kotlin/model/properties/properties.kt | 6 +++--- core/src/main/kotlin/model/typeWrappers.kt | 4 ++++ 5 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 core/src/main/kotlin/model/documentableProperties.kt (limited to 'core/src') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 48f00474..73a5f9d3 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -3,6 +3,8 @@ 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.model.properties.ExtraProperty +import org.jetbrains.dokka.model.properties.MergeStrategy import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.PlatformData @@ -72,10 +74,10 @@ interface WithType { } interface WithAbstraction { - val modifier: Modifier + val modifier: Modifier? enum class Modifier { - Abstract, Open, Final + Abstract, Open, Final, Static } } @@ -145,7 +147,7 @@ data class Class( override val generics: List, override val supertypes: PlatformDependent>, override val documentation: PlatformDependent, - override val modifier: WithAbstraction.Modifier, + override val modifier: WithAbstraction.Modifier?, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, @@ -206,7 +208,7 @@ data class Function( override val type: TypeWrapper, override val generics: List, override val receiver: Parameter?, - override val modifier: WithAbstraction.Modifier, + override val modifier: WithAbstraction.Modifier?, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { @@ -285,8 +287,8 @@ data class Property( override val type: TypeWrapper, override val receiver: Parameter?, val setter: Function?, - val getter: Function, - override val modifier: WithAbstraction.Modifier, + val getter: Function?, + override val modifier: WithAbstraction.Modifier?, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties { @@ -348,4 +350,4 @@ 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 +class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource(psi.containingFile.virtualFile.path) diff --git a/core/src/main/kotlin/model/documentableProperties.kt b/core/src/main/kotlin/model/documentableProperties.kt new file mode 100644 index 00000000..38a06451 --- /dev/null +++ b/core/src/main/kotlin/model/documentableProperties.kt @@ -0,0 +1,14 @@ +package org.jetbrains.dokka.model + +import org.jetbrains.dokka.model.properties.ExtraProperty +import org.jetbrains.dokka.model.properties.MergeStrategy + +data class InheritedFunction(val isInherited: Boolean): ExtraProperty { + object InheritedFunctionKey: ExtraProperty.Key { + override fun mergeStrategyFor(left: Boolean, right: Boolean) = MergeStrategy.Fail { + throw IllegalArgumentException("Function inheritance should be consistent!") + } + } + override val key: ExtraProperty.Key = + InheritedFunctionKey +} \ No newline at end of file diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt index 50216278..d30c6844 100644 --- a/core/src/main/kotlin/model/properties/PropertyContainer.kt +++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt @@ -1,16 +1,15 @@ package org.jetbrains.dokka.model.properties -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull class PropertyContainer internal constructor( - @PublishedApi internal val map: Map, Property> + @PublishedApi internal val map: Map, ExtraProperty> ) { - operator fun plus(prop: Property): PropertyContainer = + operator fun plus(prop: ExtraProperty): PropertyContainer = PropertyContainer(map + (prop.key to prop)) // TODO: Add logic for caching calculated properties - inline operator fun get(key: Property.Key): T? = when (val prop = map[key]) { + inline operator fun get(key: ExtraProperty.Key): T? = when (val prop = map[key]) { is T? -> prop else -> throw ClassCastException("Property for $key stored under not matching key type.") } @@ -27,7 +26,7 @@ interface WithExtraProperties { } fun C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties { - val aggregatedExtras: List>> = + val aggregatedExtras: List>> = (left.extra.map.values + right.extra.map.values) .groupBy { it.key } .values @@ -37,12 +36,12 @@ fun C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperti @Suppress("UNCHECKED_CAST") val strategies: List> = toMerge.map { (l, r) -> - (l.key as Property.Key>).mergeStrategyFor(l, r) + (l.key as ExtraProperty.Key>).mergeStrategyFor(l, r) } strategies.firstIsInstanceOrNull()?.error?.invoke() - val replaces: List> = strategies.filterIsInstance>().map { it.newProperty } + val replaces: List> = strategies.filterIsInstance>().map { it.newProperty } val needingFullMerge: List<(preMerged: C, left: C, right: C) -> C> = strategies.filterIsInstance>().map { it.merger } diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt index 4ca44926..83f8d63d 100644 --- a/core/src/main/kotlin/model/properties/properties.kt +++ b/core/src/main/kotlin/model/properties/properties.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka.model.properties -interface Property { +interface ExtraProperty { interface Key { fun mergeStrategyFor(left: T, right: T): MergeStrategy = MergeStrategy.Fail { throw NotImplementedError("Property merging for $this is not implemented") @@ -9,12 +9,12 @@ interface Property { val key: Key } -interface CalculatedProperty: Property.Key { +interface CalculatedProperty: ExtraProperty.Key { fun calculate(subject: C): T } sealed class MergeStrategy { - class Replace(val newProperty: Property): MergeStrategy() + class Replace(val newProperty: ExtraProperty): MergeStrategy() object Remove: MergeStrategy() class Full(val merger: (preMerged: C, left: C, right: C) -> C): MergeStrategy() class Fail(val error: () -> Nothing): MergeStrategy() diff --git a/core/src/main/kotlin/model/typeWrappers.kt b/core/src/main/kotlin/model/typeWrappers.kt index 5719c6d3..b26a3f6d 100644 --- a/core/src/main/kotlin/model/typeWrappers.kt +++ b/core/src/main/kotlin/model/typeWrappers.kt @@ -94,4 +94,8 @@ class JavaTypeWrapper : TypeWrapper { override fun toString(): String { return constructorFqName.orEmpty() } + + companion object { + val VOID = JavaTypeWrapper(listOf("void"), listOf(), null, true) + } } -- cgit