diff options
Diffstat (limited to 'plugins')
5 files changed, 139 insertions, 47 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 67e9407f..dfb0d3f7 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -82,39 +82,18 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } - private fun actualTypealiasedSignature(c: DClasslike, sourceSet: DokkaSourceSet, aliasedType: Bound): ContentGroup { - @Suppress("UNCHECKED_CAST") - val deprecationStyles = (c as? WithExtraProperties<out Documentable>) - ?.stylesIfDeprecated(sourceSet) - ?: emptySet() - - return contentBuilder.contentFor( - c, - ContentKind.Symbol, - setOf(TextStyle.Monospace), - sourceSets = setOf(sourceSet) - ) { - keyword("actual ") - keyword("typealias ") - link(c.name.orEmpty(), c.dri, styles = mainStyles + deprecationStyles) - operator(" = ") - signatureForProjection(aliasedType) - } - } - private fun classlikeSignature(c: DClasslike): List<ContentNode> { @Suppress("UNCHECKED_CAST") - val typeAliasUnderlyingType = (c as? WithExtraProperties<DClasslike>) + val typeAlias = (c as? WithExtraProperties<DClasslike>) ?.extra ?.get(ActualTypealias) - ?.underlyingType + ?.typeAlias return c.sourceSets.map { sourceSetData -> - val sourceSetType = typeAliasUnderlyingType?.get(sourceSetData) - if (sourceSetType == null) { - regularSignature(c, sourceSetData) + if (typeAlias != null && sourceSetData in typeAlias.sourceSets) { + regularSignature(typeAlias, sourceSetData) } else { - actualTypealiasedSignature(c, sourceSetData, sourceSetType) + regularSignature(c, sourceSetData) } } } @@ -361,27 +340,33 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(t: DTypeAlias) = t.sourceSets.map { - contentBuilder.contentFor(t, sourceSets = setOf(it)) { - t.underlyingType.entries.groupBy({ it.value }, { it.key }).map { (type, platforms) -> - +contentBuilder.contentFor( - t, - ContentKind.Symbol, - setOf(TextStyle.Monospace), - sourceSets = platforms.toSet() - ) { - annotationsBlock(t) - t.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") } - processExtraModifiers(t) - keyword("typealias ") - group(styles = mainStyles + t.stylesIfDeprecated(it)) { - signatureForProjection(t.type) - } - operator(" = ") - signatureForTypealiasTarget(t, type) - } + regularSignature(t, it) + } + + private fun regularSignature( + t: DTypeAlias, + sourceSet: DokkaSourceSet + ) = contentBuilder.contentFor(t, sourceSets = setOf(sourceSet)) { + t.underlyingType.entries.groupBy({ it.value }, { it.key }).map { (type, platforms) -> + +contentBuilder.contentFor( + t, + ContentKind.Symbol, + setOf(TextStyle.Monospace), + sourceSets = platforms.toSet() + ) { + annotationsBlock(t) + t.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") } + if (t.expectPresentInSet != null) keyword("actual ") + processExtraModifiers(t) + keyword("typealias ") + group(styles = mainStyles + t.stylesIfDeprecated(sourceSet)) { + signatureForProjection(t.type) } + operator(" = ") + signatureForTypealiasTarget(t, type) } } + } private fun signature(t: DTypeParameter) = t.sourceSets.map { diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt index e895db60..22fc6e9a 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt @@ -6,6 +6,13 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer +/** + * Since we can not merge [DClasslike] with [DTypeAlias.underlyingType] and [DTypeAlias.extra], + * we have this transformer to add [ActualTypealias] extra in expect [DClasslike] + * + * The transformer should be applied after merging all documentables + */ +// TODO assign actual [DTypeAlias.expectPresentInSet] an expect source set, currently, [DTypeAlias.expectPresentInSet] always = null class ActualTypealiasAdder : DocumentableTransformer { override fun invoke(original: DModule, context: DokkaContext) = original.generateTypealiasesMap().let { aliases -> @@ -66,30 +73,36 @@ class ActualTypealiasAdder : DocumentableTransformer { elements.map { element -> if (element.expectPresentInSet != null) { typealiases[element.dri]?.let { ta -> - val merged = element.withNewExtras(element.extra + ActualTypealias(ta.underlyingType)).let { + val actualTypealiasExtra = ActualTypealias(ta.copy(expectPresentInSet = element.expectPresentInSet)) + val merged = element.withNewExtras(element.extra + actualTypealiasExtra).let { when (it) { is DClass -> it.copy( documentation = element.documentation + ta.documentation, + sources = element.sources + ta.sources, sourceSets = element.sourceSets + ta.sourceSets ) is DEnum -> it.copy( documentation = element.documentation + ta.documentation, + sources = element.sources + ta.sources, sourceSets = element.sourceSets + ta.sourceSets ) is DInterface -> it.copy( documentation = element.documentation + ta.documentation, + sources = element.sources + ta.sources, sourceSets = element.sourceSets + ta.sourceSets ) is DObject -> it.copy( documentation = element.documentation + ta.documentation, + sources = element.sources + ta.sources, sourceSets = element.sourceSets + ta.sourceSets ) is DAnnotation -> it.copy( documentation = element.documentation + ta.documentation, + sources = element.sources + ta.sources, sourceSets = element.sourceSets + ta.sourceSets ) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 41ab2039..ce4776e7 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -818,6 +818,7 @@ private class DokkaDescriptorVisitor( documentation = resolveDescriptorData(), sourceSets = setOf(sourceSet), generics = generics.await(), + sources = descriptor.createSources(), extra = PropertyContainer.withAll( descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), info.exceptionInSupertypesOrNull(), diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index d271be2e..38ae2be3 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -8,7 +8,6 @@ import org.jetbrains.dokka.model.dfs import org.junit.jupiter.api.Test import utils.* import kotlin.test.assertEquals - class SignatureTest : BaseAbstractTest() { private val configuration = dokkaConfiguration { sourceSets { @@ -36,7 +35,8 @@ class SignatureTest : BaseAbstractTest() { name = "jvm" dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") - classpath = listOf(commonStdlibPath!!) + classpath = listOf( + commonStdlibPath ?: throw IllegalStateException("Common stdlib is not found"),) externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) } } @@ -549,6 +549,39 @@ class SignatureTest : BaseAbstractTest() { } } } + @Test + fun `actual typealias should have generic parameters and fully qualified name of the expansion type`() { + val writerPlugin = TestOutputWriterPlugin() + + testInline( + """ + |/src/main/kotlin/common/Test.kt + |package example + | + |expect class Array<T> + | + |/src/main/kotlin/jvm/Test.kt + |package example + | + |actual typealias Array<T> = kotlin.Array<T> + """.trimMargin(), + mppConfiguration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val signatures = writerPlugin.writer.renderedContent("test/example/-array/index.html").signature().toList() + + signatures[0].match( + "expect class ", A("Array"), "<", A("T"), ">", + ignoreSpanWithTokenStyle = true + ) + signatures[1].match( + "actual typealias ", A("Array"), "<", A("T"), "> = ", A("kotlin.Array"), "<", A("T"), ">", + ignoreSpanWithTokenStyle = true + ) + } + } + } @Test fun `type with an actual typealias`() { diff --git a/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt index 81b4db69..11996186 100644 --- a/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt @@ -1,5 +1,6 @@ package transformers +import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.SourceLinkDefinitionImpl import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.junit.jupiter.api.Test @@ -64,4 +65,63 @@ class SourceLinkTransformerTest : BaseAbstractTest() { } } } + + @Test + fun `source link should be for actual typealias`() { + val mppConfiguration = dokkaConfiguration { + moduleName = "test" + sourceSets { + sourceSet { + name = "common" + sourceRoots = listOf("src/main/kotlin/common/Test.kt") + classpath = listOf(commonStdlibPath!!) + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + } + sourceSet { + name = "jvm" + dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) + sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") + classpath = listOf(commonStdlibPath!!) + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + sourceLinks = listOf( + SourceLinkDefinitionImpl( + localDirectory = "src/main/kotlin", + remoteUrl = URL("https://github.com/user/repo/tree/master/src/main/kotlin"), + remoteLineSuffix = "#L" + ) + ) + } + } + } + + val writerPlugin = TestOutputWriterPlugin() + + testInline( + """ + |/src/main/kotlin/common/Test.kt + |package example + | + |expect class Foo + | + |/src/main/kotlin/jvm/Test.kt + |package example + | + |class Bar + |actual typealias Foo = Bar + | + """.trimMargin(), + mppConfiguration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val page = writerPlugin.writer.renderedContent("test/example/-foo/index.html") + val sourceLink = page.getSourceLink() + + assertEquals( + "https://github.com/user/repo/tree/master/src/main/kotlin/jvm/Test.kt#L4", + sourceLink + ) + } + } + } }
\ No newline at end of file |