diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-01-15 15:39:07 +0100 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-01-15 18:22:40 +0100 |
commit | aca9ac636f97a1eab75eae648a7e5b5c6305b5c7 (patch) | |
tree | 1c29b01ee044443bc47cb1fd06323f9531c530be /core | |
parent | c1cff90ea678622c2d489fe9fe752160bed724f8 (diff) | |
download | dokka-aca9ac636f97a1eab75eae648a7e5b5c6305b5c7.tar.gz dokka-aca9ac636f97a1eab75eae648a7e5b5c6305b5c7.tar.bz2 dokka-aca9ac636f97a1eab75eae648a7e5b5c6305b5c7.zip |
Information about generics and nullability is no longer lost
also removed obsolete and commented tests
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/links/DRI.kt | 111 | ||||
-rw-r--r-- | core/src/test/kotlin/dri/DRITest.kt | 74 |
2 files changed, 39 insertions, 146 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt index 2ece58e5..0fe2900b 100644 --- a/core/src/main/kotlin/links/DRI.kt +++ b/core/src/main/kotlin/links/DRI.kt @@ -69,15 +69,12 @@ data class Callable( } sealed class TypeReference { + abstract val isNullable: Boolean companion object { fun from(d: ReceiverParameterDescriptor): TypeReference? = - when (val value = d.value) { - is ExtensionReceiver -> Bound( - fullyQualifiedName = value.type.constructorName.orEmpty(), - params = value.type.arguments.map { from(it) }, - isNullable = value.type.isMarkedNullable - ) + when (d.value) { + is ExtensionReceiver -> from(d.type) else -> run { println("Unknown value type for $d") null @@ -87,83 +84,53 @@ sealed class TypeReference { fun from(d: ValueParameterDescriptor): TypeReference? = from(d.type) - private fun from(tp: TypeParameterDescriptor, r: KotlinType?): Param = - Param(tp.upperBounds.map { from(it, r) }) - - - private fun from(t: KotlinType, r: KotlinType? = null): TypeReference = - if(t == r) - Self - else - when (val d = t.constructor.declarationDescriptor) { - is TypeParameterDescriptor -> from(d, r ?: t) - else -> Bound(t.constructorName.orEmpty(), t.arguments.map { from(it, r ?: t) }, t.isMarkedNullable) - } + private fun from(t: KotlinType, self: KotlinType? = null): TypeReference = + if (t == self) + if (t.isMarkedNullable) NullableSelfType else SelfType + else when (val d = t.constructor.declarationDescriptor) { + is TypeParameterDescriptor -> TypeParam( + d.upperBounds.map { from(it, self ?: t) }, + t.isMarkedNullable + ) + else -> TypeConstructor( + t.constructorName.orEmpty(), + t.arguments.map { from(it, self) }, + t.isMarkedNullable + ) + } private fun from(t: TypeProjection, r: KotlinType? = null): TypeReference = if (t.isStarProjection) { - starProjection + TypeConstructor("kotlin.Any", emptyList(), isNullable = true) } else { from(t.type, r) } - - private val starProjection = Param(listOf(Bound("*", emptyList(), true))) } } -data class Param(val bounds: List<TypeReference>) : TypeReference() -data class Bound(val fullyQualifiedName: String, val params: List<TypeReference>, val isNullable: Boolean) : TypeReference() { - override fun toString() = fullyQualifiedName + if (params.isNotEmpty()) { - "[${params.joinToString(",")}]" //TODO params can be Param or Self, handle naming - } else { - "" - } + +data class TypeParam(val bounds: List<TypeReference>, override val isNullable: Boolean) : TypeReference() + +data class TypeConstructor( + val fullyQualifiedName: String, + val params: List<TypeReference>, + override val isNullable: Boolean +) : TypeReference() { + override fun toString() = fullyQualifiedName + + (if (params.isNotEmpty()) "[${params.joinToString(",")}]" else "") + + if (isNullable) "?" else "" +} + +object SelfType : TypeReference() { + override val isNullable = false + override fun toString() = "^" +} + +object NullableSelfType : TypeReference() { + override val isNullable = true + override fun toString() = "^?" } -object Self : TypeReference() - - -//data class TypeReference(val classNames: String, val typeBounds: List<TypeReference> = emptyList()) { -// override fun toString() = classNames + if (typeBounds.isNotEmpty()) { -// "[${typeBounds.joinToString(",")}]" -// } else { -// "" -// } -// -// companion object { -// fun from(d: ReceiverParameterDescriptor): TypeReference? = -// when (val value = d.value) { -// is ExtensionReceiver -> TypeReference( -// classNames = value.type.constructorName.orEmpty(), -// typeBounds = value.type.arguments.map { from(it) } -// ) -// else -> run { -// println("Unknown value type for $d") -// null -// } -// } -// -// fun from(d: ValueParameterDescriptor): TypeReference? = from(d.type) -// -// private fun from(tp: TypeParameterDescriptor): TypeReference = -// TypeReference("", tp.upperBounds.map { from(it) }) -// -// private fun from(t: KotlinType): TypeReference = -// when (val d = t.constructor.declarationDescriptor) { -// is TypeParameterDescriptor -> from(d) -// else -> TypeReference(t.constructorName.orEmpty(), t.arguments.map { from(it) }) -// } -// -// private fun from(t: TypeProjection): TypeReference = -// if (t.isStarProjection) { -// starProjection -// } else { -// from(t.type) -// } -// -// val starProjection = TypeReference("*") -// } -//} private operator fun <T> List<T>.component6(): T = get(5) diff --git a/core/src/test/kotlin/dri/DRITest.kt b/core/src/test/kotlin/dri/DRITest.kt deleted file mode 100644 index 911e49bf..00000000 --- a/core/src/test/kotlin/dri/DRITest.kt +++ /dev/null @@ -1,74 +0,0 @@ -package org.jetbrains.dokka.tests.dri - -import org.jetbrains.dokka.links.Callable -import org.jetbrains.dokka.links.TypeReference -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.resolvers.toJavadocLocation -import org.junit.Test -import kotlin.test.assertEquals - -class DRITest { -// @Test -// fun onlyClassNames() { -// val expected = DRI(classNames = "className1.className2") -// val actual = DRI.from("/className1.className2////") -// assertEquals(expected, actual) -// } - -// @Test -// fun fullDRI() { -// val expected = DRI("org.dokka", "className1.className2", Callable("<init>", "", listOf("Int")), 2, "something") -// val actual = DRI.from("org.dokka/className1.className2/<init>/..Int/2/something") -// assertEquals(expected, actual) -// } - -// @Test -// fun onlyExtra() { -// val expected = DRI(null, null, null, null, "extra") -// val actual = DRI.from("/////extra") -// assertEquals(expected, actual) -// } -// -// @Test -// fun javadoc8Location() { -// val dri = DRI("org.jetbrains.dokka", "DRITest", "javadocLocation", ".void.") -// assertEquals("org/jetbrains/dokka/DRITest.html#javadocLocation--", dri.toJavadocLocation(8)) -// } -// -// @Test -// fun parseDRI() { -// val toParse = -// "example//baz/example.Foo[kotlin.Comparable[*],[kotlin.collections.List[example.ReBarBar],kotlin.Comparable[*]]]#[kotlin.collections.List[example.ReBarBar],kotlin.Comparable[*]]//" -// val dri = DRI( -// "example", -// "", -// Callable( -// "baz", -// TypeReference( -// "example.Foo", listOf( -// TypeReference("kotlin.Comparable", listOf(TypeReference.starProjection)), -// TypeReference( -// "", listOf( -// TypeReference("kotlin.collections.List", listOf(TypeReference("example.ReBarBar"))), -// TypeReference("kotlin.Comparable", listOf(TypeReference.starProjection)) -// ) -// ) -// ) -// ), -// listOf( -// TypeReference( -// "", -// listOf( -// TypeReference("kotlin.collections.List", listOf(TypeReference("example.ReBarBar"))), -// TypeReference("kotlin.Comparable", listOf(TypeReference.starProjection)) -// ) -// -// ) -// ) -// ) -// ) -// assertEquals(dri.toString(), DRI.from(toParse).toString()) -// } -} - - |