aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-03-11 16:55:40 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-11 18:25:01 +0100
commit8e4ffa367b43cdc57c3921fab2182a4209913a51 (patch)
treee4e03996eab0372b642978f0540079efdb6da191 /core/src
parent93b8ae8a552ed88f50e4f17a5906ddeedb77e639 (diff)
downloaddokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.tar.gz
dokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.tar.bz2
dokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.zip
Use Bounds instead of Wrappers to describe types
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/links/DRI.kt2
-rw-r--r--core/src/main/kotlin/model/Documentable.kt11
-rw-r--r--core/src/main/kotlin/model/typeWrappers.kt101
3 files changed, 9 insertions, 105 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index 57ac96e5..cc78ab6f 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -56,6 +56,8 @@ data class DRI(
}
}
+val DriOfUnit = DRI("kotlin", "Unit")
+
fun DRI.withClass(name: String) = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name")
val DRI.parent: DRI
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 176647fa..b697f4e4 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -58,7 +58,7 @@ interface WithVisibility {
}
interface WithType {
- val type: TypeWrapper
+ val type: Bound
}
interface WithAbstraction {
@@ -203,7 +203,7 @@ data class Function(
override val documentation: PlatformDependent<DocumentationNode>,
override val sources: PlatformDependent<DocumentableSource>,
override val visibility: PlatformDependent<Visibility>,
- override val type: TypeWrapper,
+ override val type: Bound,
override val generics: List<TypeParameter>,
override val receiver: Parameter?,
override val modifier: Modifier,
@@ -282,7 +282,7 @@ data class Property(
override val documentation: PlatformDependent<DocumentationNode>,
override val sources: PlatformDependent<DocumentableSource>,
override val visibility: PlatformDependent<Visibility>,
- override val type: TypeWrapper,
+ override val type: Bound,
override val receiver: Parameter?,
val setter: Function?,
val getter: Function?,
@@ -301,7 +301,7 @@ data class Parameter(
override val dri: DRI,
override val name: String?,
override val documentation: PlatformDependent<DocumentationNode>,
- val type: TypeWrapper,
+ val type: Bound,
override val platformData: List<PlatformData>,
override val extra: PropertyContainer<Parameter> = PropertyContainer.empty()
) : Documentable(), WithExtraProperties<Parameter> {
@@ -334,6 +334,9 @@ data class Nullable(val inner: Bound) : Bound()
data class Variance(val kind: Kind, val inner: Bound) : Projection() {
enum class Kind { In, Out }
}
+data class PrimitiveJavaType(val name: String): Bound()
+
+val VoidBound = PrimitiveJavaType("void")
enum class ExtraModifiers {
STATIC, INLINE, INFIX, SUSPEND, REIFIED, CROSSINLINE, NOINLINE,
diff --git a/core/src/main/kotlin/model/typeWrappers.kt b/core/src/main/kotlin/model/typeWrappers.kt
deleted file mode 100644
index b26a3f6d..00000000
--- a/core/src/main/kotlin/model/typeWrappers.kt
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.jetbrains.dokka.model
-
-import com.intellij.psi.PsiArrayType
-import com.intellij.psi.PsiEllipsisType
-import com.intellij.psi.PsiPrimitiveType
-import com.intellij.psi.PsiType
-import com.intellij.psi.impl.source.PsiClassReferenceType
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
-import org.jetbrains.kotlin.types.KotlinType
-
-interface TypeWrapper {
- val constructorFqName: String?
- val constructorNamePathSegments: List<String>
- val arguments: List<TypeWrapper>
- val dri: DRI?
-}
-
-class KotlinTypeWrapper(private val kotlinType: KotlinType) : TypeWrapper {
- private val declarationDescriptor = kotlinType.constructor.declarationDescriptor
- private val fqNameSafe = declarationDescriptor?.fqNameSafe
- override val constructorFqName = fqNameSafe?.asString()
- override val constructorNamePathSegments: List<String> =
- fqNameSafe?.pathSegments()?.map { it.asString() } ?: emptyList()
- override val arguments: List<KotlinTypeWrapper> by lazy {
- kotlinType.arguments.map {
- KotlinTypeWrapper(
- it.type
- )
- }
- }
- override val dri: DRI? by lazy { declarationDescriptor?.let { DRI.from(it) } }
-}
-
-class JavaTypeWrapper : TypeWrapper {
-
- override val constructorFqName: String?
- override val constructorNamePathSegments: List<String>
- override val arguments: List<TypeWrapper>
- override val dri: DRI?
- val isPrimitive: Boolean
-
- constructor(
- constructorNamePathSegments: List<String>,
- arguments: List<TypeWrapper>,
- dri: DRI?,
- isPrimitiveType: Boolean
- ) {
- this.constructorFqName = constructorNamePathSegments.joinToString(".")
- this.constructorNamePathSegments = constructorNamePathSegments
- this.arguments = arguments
- this.dri = dri
- this.isPrimitive = isPrimitiveType
- }
-
- constructor(type: PsiType) {
- if (type is PsiClassReferenceType) {
- val resolved = type.resolve()
- constructorFqName = resolved?.qualifiedName
- constructorNamePathSegments = resolved?.qualifiedName?.split('.') ?: emptyList()
- arguments = type.parameters.mapNotNull {
- if (it is PsiClassReferenceType) JavaTypeWrapper(it) else null
- }
- dri = fromPsi(type)
- this.isPrimitive = false
- } else if (type is PsiEllipsisType) {
- constructorFqName = type.canonicalText
- constructorNamePathSegments = listOf(type.canonicalText) // TODO
- arguments = emptyList()
- dri = DRI("java.lang", "Object") // TODO
- this.isPrimitive = false
- } else if (type is PsiArrayType) {
- constructorFqName = type.canonicalText
- constructorNamePathSegments = listOf(type.canonicalText)
- arguments = emptyList()
- dri = (type as? PsiClassReferenceType)?.let { fromPsi(it) } // TODO
- this.isPrimitive = false
- } else {
- type as PsiPrimitiveType
- constructorFqName = type.name
- constructorNamePathSegments = type.name.split('.')
- arguments = emptyList()
- dri = null
- this.isPrimitive = true
- }
- }
-
- private fun fromPsi(type: PsiClassReferenceType): DRI {
- val className = type.className
- val pkg = type.canonicalText.removeSuffix(className).removeSuffix(".")
- return DRI(packageName = pkg, classNames = className)
- }
-
- override fun toString(): String {
- return constructorFqName.orEmpty()
- }
-
- companion object {
- val VOID = JavaTypeWrapper(listOf("void"), listOf(), null, true)
- }
-}