diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-24 09:14:37 +0200 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-06-25 19:50:22 +0200 |
commit | 08f40e2a13006882e8f8425f111b8527e7bbcb0f (patch) | |
tree | 1052c35c75fccaa044a73b33e5f0b5adae4c0f57 /plugins/base/src/main/kotlin/transformers/pages | |
parent | cf2e842da89f0effa6bdb5eb942b250c94360b5c (diff) | |
download | dokka-08f40e2a13006882e8f8425f111b8527e7bbcb0f.tar.gz dokka-08f40e2a13006882e8f8425f111b8527e7bbcb0f.tar.bz2 dokka-08f40e2a13006882e8f8425f111b8527e7bbcb0f.zip |
Remove kotlin source analysis from :core to :kotlin-analysis (thanks to Afzal Najam)
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages')
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt | 41 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt | 4 |
2 files changed, 29 insertions, 16 deletions
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 57655a9d..0d133a65 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -1,11 +1,11 @@ package org.jetbrains.dokka.base.transformers.pages.samples import com.intellij.psi.PsiElement -import org.jetbrains.dokka.DokkaGenerator -import org.jetbrains.dokka.EnvironmentAndFacade import org.jetbrains.dokka.Platform import org.jetbrains.dokka.analysis.AnalysisEnvironment +import org.jetbrains.dokka.analysis.DokkaMessageCollector import org.jetbrains.dokka.analysis.DokkaResolutionFacade +import org.jetbrains.dokka.analysis.EnvironmentAndFacade import org.jetbrains.dokka.base.renderers.platforms import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.SourceSetData @@ -41,7 +41,7 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { } private fun setUpAnalysis(context: DokkaContext) = context.configuration.passesConfigurations.map { - context.sourceSet(it) to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run { + context.sourceSet(it) to AnalysisEnvironment(DokkaMessageCollector(context.logger), it.analysisPlatform).run { if (analysisPlatform == Platform.jvm) { addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } @@ -57,11 +57,16 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { } }.toMap() - 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") } + 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 val body = processBody(psiElement) val node = contentCode(contentPage.platforms(), contentPage.dri, body, "kotlin") @@ -70,10 +75,14 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { } private fun ContentNode.dfs(fqName: String, node: ContentCode): ContentNode { - return when(this) { + return when (this) { is ContentHeader -> copy(children.map { it.dfs(fqName, node) }) is ContentDivergentGroup -> copy(children.map { it.dfs(fqName, node) } as List<ContentDivergentInstance>) - is ContentDivergentInstance -> copy(before.let { it?.dfs(fqName, node) }, divergent.let { it.dfs(fqName, node) }, after.let { it?.dfs(fqName, node) }) + is ContentDivergentInstance -> copy( + before.let { it?.dfs(fqName, node) }, + divergent.dfs(fqName, node), + after.let { it?.dfs(fqName, node) } + ) is ContentCode -> copy(children.map { it.dfs(fqName, node) }) is ContentDRILink -> copy(children.map { it.dfs(fqName, node) }) is ContentResolvedLink -> copy(children.map { it.dfs(fqName, node) }) @@ -90,10 +99,14 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { private fun fqNameToPsiElement(resolutionFacade: DokkaResolutionFacade, functionName: String): PsiElement? { val packageName = functionName.takeWhile { it != '.' } - val descriptor = resolutionFacade.resolveSession.getPackageFragment(FqName(packageName)) ?: - return null.also { context.logger.warn("Cannot find descriptor for package $packageName") } - val symbol = resolveKDocSampleLink(BindingContext.EMPTY, resolutionFacade, descriptor, functionName.split(".")).firstOrNull() ?: - return null.also { context.logger.warn("Unresolved function $functionName in @sample") } + val descriptor = resolutionFacade.resolveSession.getPackageFragment(FqName(packageName)) + ?: return null.also { context.logger.warn("Cannot find descriptor for package $packageName") } + val symbol = resolveKDocSampleLink( + BindingContext.EMPTY, + resolutionFacade, + descriptor, + functionName.split(".") + ).firstOrNull() ?: return null.also { context.logger.warn("Unresolved function $functionName in @sample") } return DescriptorToSourceUtils.descriptorToDeclaration(symbol) } 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 8113d277..7603c80b 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -3,11 +3,11 @@ package org.jetbrains.dokka.base.transformers.pages.sourcelinks import com.intellij.psi.PsiElement import com.intellij.psi.PsiDocumentManager import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.analysis.DescriptorDocumentableSource +import org.jetbrains.dokka.analysis.PsiDocumentableSource 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.pages.* import org.jetbrains.dokka.plugability.DokkaContext |