Skip to content

Commit

Permalink
Merge branch 'master' into vmishenev/3352-Process-links-inside-kdoc-s…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
vmishenev authored Jan 18, 2024
2 parents 569866e + 42ce2bd commit ae8f8f8
Show file tree
Hide file tree
Showing 14 changed files with 7,114 additions and 5,646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class SerializationGradleIntegrationTest : AbstractGradleIntegrationTest(), Test
copyAndApplyGitDiff(File("projects", "serialization/serialization.diff"))
}

@OnlyDescriptors // failed due to https://github.com/Kotlin/dokka/issues/3207
@ParameterizedTest(name = "{0}")
@ArgumentsSource(SerializationBuildVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.setProperty
import org.jetbrains.dokka.*
import java.io.File
import java.net.URI
import java.net.URL

/**
Expand Down Expand Up @@ -462,7 +463,7 @@ open class GradleDokkaSourceSetBuilder(
* Convenient override to **append** external documentation links to [externalDocumentationLinks].
*/
fun externalDocumentationLink(url: String, packageListUrl: String? = null) {
externalDocumentationLink(URL(url), packageListUrl = packageListUrl?.let(::URL))
externalDocumentationLink(URI(url).toURL(), packageListUrl = packageListUrl?.let(::URI)?.toURL())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import java.net.URL
*
* ```kotlin
* externalDocumentationLink {
* url.set(URL("https://kotlinlang.org/api/kotlinx.serialization/"))
* url.set(URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL())
* packageListUrl.set(
* rootProject.projectDir.resolve("serialization.package.list").toURL()
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
* )
* }
* ```
Expand All @@ -53,13 +53,13 @@ class GradleExternalDocumentationLinkBuilder(
* Example:
*
* ```kotlin
* java.net.URL("https://kotlinlang.org/api/kotlinx.serialization/")
* java.net.URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL()
* ```
*/
@Internal
val url: Property<URL> = project.objects.property()

@Input // URL is deprecated in gradle inputs
@Input // URL is deprecated in Gradle inputs
internal fun getUrlString() = url.map(URL::toString)

/**
Expand All @@ -69,13 +69,13 @@ class GradleExternalDocumentationLinkBuilder(
* Example:
*
* ```kotlin
* rootProject.projectDir.resolve("serialization.package.list").toURL()
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
* ```
*/
@Internal
val packageListUrl: Property<URL> = project.objects.property()

@Input // URL is deprecated in gradle inputs
@Input // URL is deprecated in Gradle inputs
@Optional
internal fun getPackageListUrlString() = packageListUrl.map(URL::toString)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.net.URL
* ```kotlin
* sourceLink {
* localDirectory.set(projectDir.resolve("src"))
* remoteUrl.set(URL("https://github.com/kotlin/dokka/tree/master/src"))
* remoteUrl.set(URI("https://github.com/kotlin/dokka/tree/master/src").toURL())
* remoteLineSuffix.set("#L")
* }
* ```
Expand Down Expand Up @@ -68,13 +68,13 @@ class GradleSourceLinkBuilder(
* Example:
*
* ```kotlin
* java.net.URL("https://github.com/username/projectname/tree/master/src"))
* java.net.URI("https://github.com/username/projectname/tree/master/src").toURL()
* ```
*/
@Internal
val remoteUrl: Property<URL> = project.objects.property()

@Input // TODO: URL is deprecated in grapdle inputs
@Input // URL is deprecated in Gradle inputs
internal fun getRemoteUrlString() = remoteUrl.map(URL::toString)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.dokka.gradle.utils.externalDocumentationLink_
import org.jetbrains.dokka.gradle.utils.withDependencies_
import org.jetbrains.dokka.toCompactJsonString
import java.io.File
import java.net.URL
import java.net.URI
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -50,8 +50,8 @@ class DokkaConfigurationJsonTest {
reportUndocumented.set(true)

externalDocumentationLink_ {
packageListUrl.set(URL("http://some.url"))
url.set(URL("http://some.other.url"))
packageListUrl.set(URI("http://some.url").toURL())
url.set(URI("http://some.other.url").toURL())
}
perPackageOption {
includeNonPublic.set(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.junit.jupiter.api.io.TempDir
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.net.URL
import java.net.URI
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -51,8 +51,8 @@ class DokkaConfigurationSerializableTest {
reportUndocumented.set(true)

externalDocumentationLink_ {
packageListUrl.set(URL("http://some.url"))
url.set(URL("http://some.other.url"))
packageListUrl.set(URI("http://some.url").toURL())
url.set(URI("http://some.other.url").toURL())
}

perPackageOption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.gradle.kotlin.dsl.closureOf
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.*
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
import java.net.URL
import java.net.URI
import kotlin.test.*

class GradleDokkaSourceSetBuilderTest {
Expand Down Expand Up @@ -222,37 +222,37 @@ class GradleDokkaSourceSetBuilderTest {
GradleSourceLinkBuilder(project).apply {
this.remoteLineSuffix.set("ls1")
this.localDirectory.set(project.file("p1"))
this.remoteUrl.set(URL("https://u1"))
this.remoteUrl.set(URI("https://u1").toURL())
})

sourceSet.sourceLink {
remoteLineSuffix.set("ls2")
localDirectory.set(project.file("p2"))
remoteUrl.set(URL("https://u2"))
remoteUrl.set(URI("https://u2").toURL())
}

sourceSet.sourceLink(project.closureOf<GradleSourceLinkBuilder> {
this.remoteLineSuffix.set("ls3")
this.localDirectory.set(project.file("p3"))
this.remoteUrl.set(URL("https://u3"))
this.remoteUrl.set(URI("https://u3").toURL())
})

assertEquals(
setOf(
SourceLinkDefinitionImpl(
remoteLineSuffix = "ls1",
localDirectory = project.file("p1").absolutePath,
remoteUrl = URL("https://u1")
remoteUrl = URI("https://u1").toURL()
),
SourceLinkDefinitionImpl(
remoteLineSuffix = "ls2",
localDirectory = project.file("p2").absolutePath,
remoteUrl = URL("https://u2")
remoteUrl = URI("https://u2").toURL()
),
SourceLinkDefinitionImpl(
remoteLineSuffix = "ls3",
localDirectory = project.file("p3").absolutePath,
remoteUrl = URL("https://u3")
remoteUrl = URI("https://u3").toURL()
)
),
sourceSet.build().sourceLinks,
Expand Down Expand Up @@ -306,29 +306,29 @@ class GradleDokkaSourceSetBuilderTest {

sourceSet.externalDocumentationLinks.add(
GradleExternalDocumentationLinkBuilder(project).apply {
this.url.set(URL("https://u1"))
this.packageListUrl.set(URL("https://pl1"))
this.url.set(URI("https://u1").toURL())
this.packageListUrl.set(URI("https://pl1").toURL())
}
)

sourceSet.externalDocumentationLink {
url.set(URL("https://u2"))
url.set(URI("https://u2").toURL())
}

sourceSet.externalDocumentationLink(project.closureOf<GradleExternalDocumentationLinkBuilder> {
url.set(URL("https://u3"))
url.set(URI("https://u3").toURL())
})

sourceSet.externalDocumentationLink(url = "https://u4", packageListUrl = "https://pl4")
sourceSet.externalDocumentationLink(url = URL("https://u5"))
sourceSet.externalDocumentationLink(url = URI("https://u5").toURL())

assertEquals(
setOf(
ExternalDocumentationLinkImpl(URL("https://u1"), URL("https://pl1")),
ExternalDocumentationLinkImpl(URL("https://u2"), URL("https://u2/package-list")),
ExternalDocumentationLinkImpl(URL("https://u3"), URL("https://u3/package-list")),
ExternalDocumentationLinkImpl(URL("https://u4"), URL("https://pl4")),
ExternalDocumentationLinkImpl(URL("https://u5"), URL("https://u5/package-list"))
ExternalDocumentationLinkImpl(URI("https://u1").toURL(), URI("https://pl1").toURL()),
ExternalDocumentationLinkImpl(URI("https://u2").toURL(), URI("https://u2/package-list").toURL()),
ExternalDocumentationLinkImpl(URI("https://u3").toURL(), URI("https://u3/package-list").toURL()),
ExternalDocumentationLinkImpl(URI("https://u4").toURL(), URI("https://pl4").toURL()),
ExternalDocumentationLinkImpl(URI("https://u5").toURL(), URI("https://u5/package-list").toURL())
),
sourceSet.build().externalDocumentationLinks,
"Expected all external documentation links being present after build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithTypeParameters
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
import org.jetbrains.kotlin.analysis.api.types.*
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -93,6 +93,28 @@ internal fun KtAnalysisSession.getDRIFromValueParameter(symbol: KtValueParameter
return funDRI.copy(target = PointingToCallableParameters(index))
}

/**
* @return [DRI] to receiver type
*/
internal fun KtAnalysisSession.getDRIFromReceiverParameter(receiverParameterSymbol: KtReceiverParameterSymbol): DRI =
getDRIFromReceiverType(receiverParameterSymbol.type)

private fun KtAnalysisSession.getDRIFromReceiverType(type: KtType): DRI {
return when(type) {
is KtNonErrorClassType -> getDRIFromNonErrorClassType(type)
is KtTypeParameterType -> getDRIFromTypeParameter(type.symbol)
is KtDefinitelyNotNullType -> getDRIFromReceiverType(type.original)
is KtTypeErrorType -> DRI(packageName = "", classNames = "$ERROR_CLASS_NAME $type")
is KtClassErrorType -> DRI(packageName = "", classNames = "$ERROR_CLASS_NAME $type")
is KtDynamicType -> DRI(packageName = "", classNames = "$ERROR_CLASS_NAME $type") // prohibited by a compiler, but it's a possible input

is KtCapturedType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
is KtFlexibleType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
is KtIntegerLiteralType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
is KtIntersectionType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
}
}

internal fun KtAnalysisSession.getDRIFromSymbol(symbol: KtSymbol): DRI =
when (symbol) {
is KtEnumEntrySymbol -> getDRIFromEnumEntry(symbol)
Expand All @@ -103,6 +125,7 @@ internal fun KtAnalysisSession.getDRIFromSymbol(symbol: KtSymbol): DRI =
is KtFunctionLikeSymbol -> getDRIFromFunctionLike(symbol)
is KtClassLikeSymbol -> getDRIFromClassLike(symbol)
is KtPackageSymbol -> getDRIFromPackage(symbol)
is KtReceiverParameterSymbol -> getDRIFromReceiverParameter(symbol)
else -> throw IllegalStateException("Unknown symbol while creating DRI $symbol")
}

Expand Down
Loading

0 comments on commit ae8f8f8

Please sign in to comment.