diff options
-rw-r--r-- | .idea/jarRepositories.xml | 80 | ||||
-rw-r--r-- | core/src/main/kotlin/links/DRI.kt | 111 | ||||
-rw-r--r-- | core/src/test/kotlin/dri/DRITest.kt | 74 |
3 files changed, 119 insertions, 146 deletions
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..8e7bd752 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RemoteRepositoriesConfiguration"> + <remote-repository> + <option name="id" value="central" /> + <option name="name" value="Maven Central repository" /> + <option name="url" value="https://repo1.maven.org/maven2" /> + </remote-repository> + <remote-repository> + <option name="id" value="jboss.community" /> + <option name="name" value="JBoss Community repository" /> + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven8" /> + <option name="name" value="maven8" /> + <option name="url" value="https://www.jetbrains.com/intellij-repository/snapshots" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven5" /> + <option name="name" value="maven5" /> + <option name="url" value="https://kotlin.bintray.com/kotlinx" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenRepo" /> + <option name="name" value="MavenRepo" /> + <option name="url" value="https://repo.maven.apache.org/maven2/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven4" /> + <option name="name" value="maven4" /> + <option name="url" value="https://teamcity.jetbrains.com/guestAuth/repository/download/Kotlin_dev_CompilerAllPlugins/1.3.20-dev-564/maven" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven7" /> + <option name="name" value="maven7" /> + <option name="url" value="https://dl.bintray.com/orangy/maven" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven" /> + <option name="name" value="maven" /> + <option name="url" value="https://dl.bintray.com/jetbrains/markdown" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenLocal" /> + <option name="name" value="MavenLocal" /> + <option name="url" value="file:$MAVEN_REPOSITORY$/" /> + </remote-repository> + <remote-repository> + <option name="id" value="BintrayJCenter" /> + <option name="name" value="BintrayJCenter" /> + <option name="url" value="https://jcenter.bintray.com/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven9" /> + <option name="name" value="maven9" /> + <option name="url" value="https://www.jetbrains.com/intellij-repository/releases" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven2" /> + <option name="name" value="maven2" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlin-eap" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven3" /> + <option name="name" value="maven3" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlin-dev" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven6" /> + <option name="name" value="maven6" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlinx" /> + </remote-repository> + <remote-repository> + <option name="id" value="Google" /> + <option name="name" value="Google" /> + <option name="url" value="https://dl.google.com/dl/android/maven2/" /> + </remote-repository> + </component> +</project>
\ No newline at end of file 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()) -// } -} - - |