diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-05-05 17:45:12 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-05-14 13:30:33 +0200 |
commit | 3f2a790190da4f40ea6d8a976aa1929b2a1b002b (patch) | |
tree | 752ee84451954e9ea5e6d4133e18e41aaee2f7b1 /plugins/base/src/main/kotlin/transformers/pages | |
parent | a440f0cb8756019131a2c15389e747aea3c585e7 (diff) | |
download | dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.gz dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.bz2 dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.zip |
Changing approach from platform-driven to source-set-driven
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages')
5 files changed, 45 insertions, 41 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt index 778e0498..cb74441e 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.transformers.pages.comments +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.* @@ -8,7 +9,7 @@ interface CommentsToContentConverter { fun buildContent( docTag: DocTag, dci: DCI, - platforms: Set<PlatformData>, + platforms: Set<SourceSetData>, styles: Set<Style> = emptySet(), extras: PropertyContainer<ContentNode> = PropertyContainer.empty() ): List<ContentNode> diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt index 4e65bae9..85391549 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.transformers.pages.comments +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.* @@ -8,19 +9,19 @@ object DocTagToContentConverter : CommentsToContentConverter { override fun buildContent( docTag: DocTag, dci: DCI, - platforms: Set<PlatformData>, + sourceSets: Set<SourceSetData>, styles: Set<Style>, extra: PropertyContainer<ContentNode> ): List<ContentNode> { fun buildChildren(docTag: DocTag, newStyles: Set<Style> = emptySet(), newExtras: SimpleAttr? = null) = docTag.children.flatMap { - buildContent(it, dci, platforms, styles + newStyles, newExtras?.let { extra + it } ?: extra) + buildContent(it, dci, sourceSets, styles + newStyles, newExtras?.let { extra + it } ?: extra) } fun buildTableRows(rows: List<DocTag>, newStyle: Style): List<ContentGroup> = rows.flatMap { - buildContent(it, dci, platforms, styles + newStyle, extra) as List<ContentGroup> + buildContent(it, dci, sourceSets, styles + newStyle, extra) as List<ContentGroup> } fun buildHeader(level: Int) = @@ -29,7 +30,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildChildren(docTag), level, dci, - platforms, + sourceSets, styles ) ) @@ -40,7 +41,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildChildren(docTag), ordered, dci, - platforms, + sourceSets, styles, ((PropertyContainer.empty<ContentNode>()) + SimpleAttr("start", start.toString())) ) @@ -48,7 +49,7 @@ object DocTagToContentConverter : CommentsToContentConverter { fun buildNewLine() = listOf( ContentBreakLine( - platforms + sourceSets ) ) @@ -71,7 +72,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildChildren(docTag), docTag.params.get("href")!!, dci, - platforms, + sourceSets, styles ) ) @@ -83,7 +84,7 @@ object DocTagToContentConverter : CommentsToContentConverter { setOf(docTag.dri), ContentKind.Symbol ), - platforms, + sourceSets, styles ) ) @@ -92,7 +93,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildChildren(docTag), "", dci, - platforms, + sourceSets, styles ) ) @@ -101,7 +102,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildChildren(docTag), "", dci, - platforms, + sourceSets, styles ) ) @@ -110,7 +111,7 @@ object DocTagToContentConverter : CommentsToContentConverter { address = docTag.params["href"]!!, altText = docTag.params["alt"], dci = dci, - platforms = platforms, + sourceSets = sourceSets, style = styles, extra = extra ) @@ -119,7 +120,7 @@ object DocTagToContentConverter : CommentsToContentConverter { ContentText( "", dci, - platforms, + sourceSets, setOf() ) ) @@ -127,7 +128,7 @@ object DocTagToContentConverter : CommentsToContentConverter { ContentText( docTag.body, dci, - platforms, + sourceSets, styles ) ) @@ -137,7 +138,7 @@ object DocTagToContentConverter : CommentsToContentConverter { buildTableRows(docTag.children.filterIsInstance<Th>(), CommentTable), buildTableRows(docTag.children.filterIsInstance<Tr>(), CommentTable), dci, - platforms, + sourceSets, styles + CommentTable ) ) @@ -145,10 +146,10 @@ object DocTagToContentConverter : CommentsToContentConverter { is Tr -> listOf( ContentGroup( docTag.children.map { - ContentGroup(buildChildren(it), dci, platforms, styles, extra) + ContentGroup(buildChildren(it), dci, sourceSets, styles, extra) }, dci, - platforms, + sourceSets, styles ) ) diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt index fb904f47..31e79555 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt @@ -32,6 +32,6 @@ object SameMethodNamePageMergerStrategy : PageMergerStrategy { } fun asGroup(dci: DCI, nodes: List<ContentNode>): ContentGroup = - nodes.first().let { ContentGroup(nodes, dci, it.platforms, it.style, it.extra) } + nodes.first().let { ContentGroup(nodes, dci, it.sourceSets, it.style, it.extra) } }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index 78fc4d33..9b04af40 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -8,8 +8,10 @@ import org.jetbrains.dokka.analysis.AnalysisEnvironment import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.base.renderers.platforms import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.doc.Sample import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.dokka.model.sourceSet import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -31,16 +33,16 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { val analysis = setUpAnalysis(context) return input.transformContentPagesTree { page -> - page.documentable?.documentation?.allEntries?.fold(page) { acc, entry -> - entry.second.children.filterIsInstance<Sample>().fold(acc) { acc, sample -> - acc.modified(content = acc.content.addSample(page, entry.first, sample.name, analysis)) + page.documentable?.documentation?.entries?.fold(page) { acc, entry -> + entry.value.children.filterIsInstance<Sample>().fold(acc) { acc, sample -> + acc.modified(content = acc.content.addSample(page, entry.key, sample.name, analysis)) } } ?: page } } private fun setUpAnalysis(context: DokkaContext) = context.configuration.passesConfigurations.map { - it.platformData to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run { + context.sourceSet(it) to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run { if (analysisPlatform == Platform.jvm) { addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } @@ -56,12 +58,9 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { } }.toMap() - private fun ContentNode.addSample(contentPage: ContentPage, platform: PlatformData?, fqName: String, analysis: Map<PlatformData, EnvironmentAndFacade>): ContentNode { - val facade = if(platform == null) { - analysis.entries.find { it.key.platformType.name == "common" }?.value - } else { - analysis[platform] - }?.facade ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform?.name ?: "expect"}") } + private fun ContentNode.addSample(contentPage: ContentPage, platform: SourceSetData, fqName: String, analysis: Map<SourceSetData, EnvironmentAndFacade>): ContentNode { + val facade = analysis[platform]?.facade ?: + return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleName}")} val psiElement = fqNameToPsiElement(facade, fqName) ?: return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") } val imports = processImports(psiElement) // TODO: Process somehow imports. Maybe just attach them at the top of each body @@ -96,13 +95,13 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { return DescriptorToSourceUtils.descriptorToDeclaration(symbol) } - private fun contentCode(platforms: List<PlatformData>, dri: Set<DRI>, content: String, language: String) = + private fun contentCode(sourceSets: List<SourceSetData>, dri: Set<DRI>, content: String, language: String) = ContentCode( children = listOf( ContentText( text = content, dci = DCI(dri, ContentKind.BriefComment), - platforms = platforms.toSet(), + sourceSets = sourceSets.toSet(), style = emptySet(), extra = PropertyContainer.empty() ) @@ -110,7 +109,7 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { language = language, extra = PropertyContainer.empty(), dci = DCI(dri, ContentKind.Source), - platforms = platforms.toSet(), + sourceSets = sourceSets.toSet(), style = emptySet() ) }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt index fa73e757..876326d1 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -5,9 +5,12 @@ import com.intellij.psi.PsiDocumentManager import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.DescriptorDocumentableSource +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.DocumentableSource import org.jetbrains.dokka.model.PsiDocumentableSource import org.jetbrains.dokka.model.WithExpectActual +import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.dokka.model.sourceSet import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -30,11 +33,11 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent } private fun getSourceLinks() = context.configuration.passesConfigurations - .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, it.platformData) } } + .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, context.sourceSetCache.getSourceSet(it)) } } private fun resolveSources(documentable: WithExpectActual) = documentable.sources .mapNotNull { entry -> - getSourceLinks().find { entry.value.path.contains(it.path) && it.platformData == entry.key }?.let { + getSourceLinks().find { entry.value.path.contains(it.path) && it.sourceSetData == entry.key }?.let { Pair( entry.key, entry.value.toLink(it) @@ -42,7 +45,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent } } - private fun ContentPage.addSourcesContent(sources: List<Pair<PlatformData, String>>) = builder + private fun ContentPage.addSourcesContent(sources: List<Pair<SourceSetData, String>>) = builder .buildSourcesContent(this, sources) .let { this.modified( @@ -52,10 +55,10 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent private fun PageContentBuilder.buildSourcesContent( node: ContentPage, - sources: List<Pair<PlatformData, String>> + sources: List<Pair<SourceSetData, String>> ) = contentFor( node.dri.first(), - node.documentable!!.platformData.toSet() + node.documentable!!.sourceSets.toSet() ) { header(2) { text("Sources") } +ContentTable( @@ -66,7 +69,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent } }, DCI(node.dri, ContentKind.Source), - node.documentable!!.platformData.toSet(), + node.documentable!!.sourceSets.toSet(), style = emptySet() ) } @@ -94,7 +97,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent else -> ContentGroup( children = listOf(this, table), extra = this.extra, - platforms = this.platforms, + sourceSets = this.sourceSets, dci = this.dci, style = this.style ) @@ -107,8 +110,8 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent } } -data class SourceLink(val path: String, val url: String, val lineSuffix: String?, val platformData: PlatformData) { - constructor(sourceLinkDefinition: DokkaConfiguration.SourceLinkDefinition, platformData: PlatformData) : this( - sourceLinkDefinition.path, sourceLinkDefinition.url, sourceLinkDefinition.lineSuffix, platformData +data class SourceLink(val path: String, val url: String, val lineSuffix: String?, val sourceSetData: SourceSetData) { + constructor(sourceLinkDefinition: DokkaConfiguration.SourceLinkDefinition, sourceSetData: SourceSetData) : this( + sourceLinkDefinition.path, sourceLinkDefinition.url, sourceLinkDefinition.lineSuffix, sourceSetData ) }
\ No newline at end of file |