diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-07-05 10:04:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-05 10:04:55 +0200 |
commit | 9559158bfeeb274e9ccf1b4563f1b23b42afc493 (patch) | |
tree | 3ece0887623cfe2b7148af23001867a1dd5e6597 /plugins/javadoc/src/main | |
parent | cbd9733d3dd2f52992e98e7cebd072091a572529 (diff) | |
download | dokka-9559158bfeeb274e9ccf1b4563f1b23b42afc493.tar.gz dokka-9559158bfeeb274e9ccf1b4563f1b23b42afc493.tar.bz2 dokka-9559158bfeeb274e9ccf1b4563f1b23b42afc493.zip |
Decompose Kotlin/Java analysis (#3034)
* Extract analysis into separate modules
Diffstat (limited to 'plugins/javadoc/src/main')
8 files changed, 48 insertions, 121 deletions
diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt index 50355c7e..70362ad4 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt @@ -1,15 +1,15 @@ package org.jetbrains.dokka.javadoc -import org.jetbrains.dokka.javadoc.location.JavadocLocationProviderFactory -import org.jetbrains.dokka.javadoc.renderer.KorteJavadocRenderer -import org.jetbrains.dokka.javadoc.signatures.JavadocSignatureProvider import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.PackageListCreator import org.jetbrains.dokka.base.renderers.RootCreator import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.PACKAGE_LIST_NAME import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat +import org.jetbrains.dokka.javadoc.location.JavadocLocationProviderFactory import org.jetbrains.dokka.javadoc.pages.* +import org.jetbrains.dokka.javadoc.renderer.KorteJavadocRenderer +import org.jetbrains.dokka.javadoc.signatures.JavadocSignatureProvider import org.jetbrains.dokka.javadoc.transformers.documentables.JavadocDocumentableJVMSourceSetFilter import org.jetbrains.dokka.javadoc.validity.MultiplatformConfiguredChecker import org.jetbrains.dokka.kotlinAsJava.KotlinAsJavaPlugin @@ -70,7 +70,7 @@ class JavadocPlugin : DokkaPlugin() { } val treeViewInstaller by extending { - javadocPreprocessors with TreeViewInstaller order { after(rootCreator) } + javadocPreprocessors providing ::TreeViewInstaller order { after(rootCreator) } } val allClassessPageInstaller by extending { diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt index 8210b30a..083b5c9a 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt @@ -1,19 +1,14 @@ package org.jetbrains.dokka.javadoc.pages -import com.intellij.psi.PsiClass import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.analysis.DescriptorDocumentableSource -import org.jetbrains.dokka.analysis.PsiDocumentableSource -import org.jetbrains.dokka.analysis.from import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.* -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType +import org.jetbrains.kotlin.analysis.kotlin.internal.InheritanceBuilder +import org.jetbrains.kotlin.analysis.kotlin.internal.InheritanceNode interface JavadocPageNode : ContentPage, WithDocumentables @@ -386,7 +381,8 @@ class TreeViewPage( val classes: List<JavadocClasslikePageNode>?, override val dri: Set<DRI>, override val documentables: List<Documentable> = emptyList(), - val root: PageNode + val root: PageNode, + val inheritanceBuilder: InheritanceBuilder ) : JavadocPageNode { init { assert(packages == null || classes == null) @@ -397,7 +393,6 @@ class TreeViewPage( getDocumentableEntries(node) }.groupBy({ it.first }) { it.second }.map { (l, r) -> l to r.first() }.toMap() - private val descriptorMap = getDescriptorMap() private val inheritanceTuple = generateInheritanceTree() internal val classGraph = inheritanceTuple.first internal val interfaceGraph = inheritanceTuple.second @@ -427,7 +422,8 @@ class TreeViewPage( classes = children.filterIsInstance<JavadocClasslikePageNode>().takeIf { it.isNotEmpty() }, dri = dri, documentables, - root = root + root = root, + inheritanceBuilder ) override fun modified(name: String, children: List<PageNode>): PageNode = @@ -437,7 +433,8 @@ class TreeViewPage( classes = children.filterIsInstance<JavadocClasslikePageNode>().takeIf { it.isNotEmpty() }, dri = dri, documentables, - root = root + root = root, + inheritanceBuilder ) override val embeddedResources: List<String> = emptyList() @@ -484,51 +481,8 @@ class TreeViewPage( fun interfaceTree(node: InheritanceNode) = interfaceTreeRec(node).firstOrNull() // TODO.single() - fun gatherPsiClasses(psi: PsiClass): List<Pair<PsiClass, List<PsiClass>>> = psi.supers.toList().let { l -> - listOf(psi to l) + l.flatMap { gatherPsiClasses(it) } - } - - val psiInheritanceTree = - childrenDocumentables.flatMap { (_, v) -> (v as? WithSources)?.sources?.values.orEmpty() } - .filterIsInstance<PsiDocumentableSource>().mapNotNull { it.psi as? PsiClass } - .flatMap(::gatherPsiClasses) - .flatMap { entry -> entry.second.map { it to entry.first } } - .let { - it + it.map { it.second to null } - } - .groupBy({ it.first }) { it.second } - .map { it.key to it.value.filterNotNull().distinct() } - .map { (k, v) -> - InheritanceNode( - DRI.from(k), - v.map { InheritanceNode(DRI.from(it)) }, - k.supers.filter { it.isInterface }.map { DRI.from(it) }, - k.isInterface - ) - - } - - val descriptorInheritanceTree = descriptorMap.flatMap { (_, v) -> - v.typeConstructor.supertypes - .map { getClassDescriptorForType(it) to v } - } - .let { - it + it.map { it.second to null } - } - .groupBy({ it.first }) { it.second } - .map { it.key to it.value.filterNotNull().distinct() } - .map { (k, v) -> - InheritanceNode( - DRI.from(k), - v.map { InheritanceNode(DRI.from(it)) }, - k.typeConstructor.supertypes.map { getClassDescriptorForType(it) } - .mapNotNull { cd -> cd.takeIf { it.kind == ClassKind.INTERFACE }?.let { DRI.from(it) } }, - isInterface = k.kind == ClassKind.INTERFACE - ) - } - - descriptorInheritanceTree.forEach { addToMap(it, mergeMap) } - psiInheritanceTree.forEach { addToMap(it, mergeMap) } + val inheritanceNodes = inheritanceBuilder.build(childrenDocumentables) + inheritanceNodes.forEach { addToMap(it, mergeMap) } val rootNodes = mergeMap.entries.filter { it.key.classNames in setOf("Any", "Object") //TODO: Probably should be matched by DRI, not just className @@ -539,47 +493,11 @@ class TreeViewPage( return rootNodes.let { Pair(it.mapNotNull(::classTree), it.mapNotNull(::interfaceTree)) } } - private fun generateInterfaceGraph() { - childrenDocumentables.values.filterIsInstance<DInterface>() - } - private fun getDocumentableEntries(node: WithDocumentables): List<Pair<DRI, Documentable>> = node.documentables.map { it.dri to it } + (node as? ContentPage)?.children?.filterIsInstance<WithDocumentables>() ?.flatMap(::getDocumentableEntries).orEmpty() - private fun getDescriptorMap(): Map<DRI, ClassDescriptor> { - val map: MutableMap<DRI, ClassDescriptor> = mutableMapOf() - childrenDocumentables - .mapNotNull { (k, v) -> - v.descriptorForPlatform()?.let { k to it }?.also { (k, v) -> map[k] = v } - }.map { it.second }.forEach { gatherSupertypes(it, map) } - - return map.toMap() - } - - private fun gatherSupertypes(descriptor: ClassDescriptor, map: MutableMap<DRI, ClassDescriptor>) { - map.putIfAbsent(DRI.from(descriptor), descriptor) - descriptor.typeConstructor.supertypes.map { getClassDescriptorForType(it) } - .forEach { gatherSupertypes(it, map) } - } - - private fun Documentable?.descriptorForPlatform(platform: Platform = Platform.jvm) = - (this as? WithSources).descriptorForPlatform(platform) - - private fun WithSources?.descriptorForPlatform(platform: Platform = Platform.jvm) = this?.let { - it.sources.entries.find { it.key.analysisPlatform == platform }?.value?.let { it as? DescriptorDocumentableSource }?.descriptor as? ClassDescriptor - } - - data class InheritanceNode( - val dri: DRI, - val children: List<InheritanceNode> = emptyList(), - val interfaces: List<DRI> = emptyList(), - val isInterface: Boolean = false - ) { - override fun equals(other: Any?): Boolean = other is InheritanceNode && other.dri == dri - override fun hashCode(): Int = dri.hashCode() - } } private fun Documentable.kind(): String? = diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt index e6e0e037..db6845a5 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt @@ -8,7 +8,11 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.BooleanValue import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.pages.PageTransformer +import org.jetbrains.kotlin.analysis.kotlin.internal.InternalKotlinAnalysisPlugin object ResourcesInstaller : PageTransformer { override fun invoke(input: RootPageNode): RootPageNode = input.modified( @@ -21,7 +25,7 @@ object ResourcesInstaller : PageTransformer { ) } -object TreeViewInstaller : PageTransformer { +class TreeViewInstaller(private val context: DokkaContext) : PageTransformer { override fun invoke(input: RootPageNode): RootPageNode = install(input, input) as RootPageNode private fun install(node: PageNode, root: RootPageNode): PageNode = when (node) { @@ -37,7 +41,8 @@ object TreeViewInstaller : PageTransformer { classes = null, dri = node.dri, documentables = node.documentables, - root = root + root = root, + inheritanceBuilder = context.plugin<InternalKotlinAnalysisPlugin>().querySingle { inheritanceBuilder } ) val nodeChildren = node.children.map { childNode -> @@ -56,7 +61,8 @@ object TreeViewInstaller : PageTransformer { classes = node.children.filterIsInstance<JavadocClasslikePageNode>(), dri = node.dri, documentables = node.documentables, - root = root + root = root, + inheritanceBuilder = context.plugin<InternalKotlinAnalysisPlugin>().querySingle { inheritanceBuilder } ) return node.modified(children = node.children + packageTree) as JavadocPackagePageNode @@ -180,4 +186,4 @@ object DeprecatedPageCreator : PageTransformer { ) ) } -}
\ No newline at end of file +} diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index 6a590bc7..f345e32b 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -1,16 +1,17 @@ package org.jetbrains.dokka.javadoc.renderer +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.javadoc.location.JavadocLocationProvider import org.jetbrains.dokka.javadoc.pages.* import org.jetbrains.dokka.javadoc.toNormalized -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.parent import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.ImplementedInterfaces import org.jetbrains.dokka.model.InheritedMember -import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.pages.ContentNode +import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.utilities.formatToEndWithHtml import java.io.File diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt index f50ae124..aecd85f7 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt @@ -1,10 +1,6 @@ package org.jetbrains.dokka.javadoc.renderer import com.soywiz.korte.* -import org.jetbrains.dokka.javadoc.location.JavadocLocationProvider -import org.jetbrains.dokka.javadoc.pages.* -import org.jetbrains.dokka.javadoc.renderer.JavadocContentToHtmlTranslator.Companion.buildLink -import org.jetbrains.dokka.javadoc.toNormalized import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -12,14 +8,21 @@ import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.OutputWriter import org.jetbrains.dokka.javadoc.JavadocPlugin +import org.jetbrains.dokka.javadoc.location.JavadocLocationProvider +import org.jetbrains.dokka.javadoc.pages.* +import org.jetbrains.dokka.javadoc.renderer.JavadocContentToHtmlTranslator.Companion.buildLink +import org.jetbrains.dokka.javadoc.toNormalized import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.pages.PageNode +import org.jetbrains.dokka.pages.RendererSpecificPage +import org.jetbrains.dokka.pages.RenderingStrategy +import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.renderers.Renderer -import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import org.jetbrains.kotlin.analysis.kotlin.internal.InheritanceNode import java.time.LocalDate typealias TemplateMap = Map<String, Any?> @@ -146,9 +149,9 @@ class KorteJavadocRenderer(val context: DokkaContext, resourceDir: String) : }, TeFunction("renderInheritanceGraph") { args -> @Suppress("UNCHECKED_CAST") - val rootNodes = args.first() as List<TreeViewPage.InheritanceNode> + val rootNodes = args.first() as List<InheritanceNode> - fun drawRec(node: TreeViewPage.InheritanceNode): String = + fun drawRec(node: InheritanceNode): String = "<li class=\"circle\">" + node.dri.let { dri -> listOfNotNull( dri.packageName, @@ -170,8 +173,9 @@ class KorteJavadocRenderer(val context: DokkaContext, resourceDir: String) : }, Filter("length") { subject.dynamicLength() }, TeFunction("hasAnyDescription") { args -> - args.first().safeAs<List<HashMap<String, String>>>() - ?.any { it["description"]?.trim()?.isNotEmpty() ?: false } + @Suppress("UNCHECKED_CAST") + val map = args.first() as? List<HashMap<String, String>> + map?.any { it["description"]?.trim()?.isNotEmpty() ?: false } } ).forEach { when (it) { diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt index 6c2fed58..a7a01fc1 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt @@ -1,16 +1,15 @@ package org.jetbrains.dokka.javadoc.renderer -import org.jetbrains.dokka.javadoc.pages.* -import org.jetbrains.dokka.javadoc.renderer.SearchRecord.Companion.allTypes import org.jetbrains.dokka.base.renderers.sourceSets -import org.jetbrains.dokka.base.resolvers.local.resolveOrThrow import org.jetbrains.dokka.base.resolvers.local.LocationProvider +import org.jetbrains.dokka.base.resolvers.local.resolveOrThrow +import org.jetbrains.dokka.javadoc.pages.* +import org.jetbrains.dokka.javadoc.renderer.SearchRecord.Companion.allTypes import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.utilities.formatToEndWithHtml -import java.lang.StringBuilder class SearchScriptsCreator(private val locationProvider: LocationProvider) { diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt index 385e0986..f81b8c5c 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt @@ -1,12 +1,12 @@ package org.jetbrains.dokka.javadoc.signatures -import org.jetbrains.dokka.javadoc.translators.documentables.JavadocPageContentBuilder import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.signatures.JvmSignatureUtils import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.javadoc.translators.documentables.JavadocPageContentBuilder import org.jetbrains.dokka.kotlinAsJava.signatures.JavaSignatureUtils import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.sureClassNames diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/translators/documentables/JavadocPageContentBuilder.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/translators/documentables/JavadocPageContentBuilder.kt index e70f8370..68faba5f 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/translators/documentables/JavadocPageContentBuilder.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/translators/documentables/JavadocPageContentBuilder.kt @@ -1,16 +1,15 @@ package org.jetbrains.dokka.javadoc.translators.documentables -import org.jetbrains.dokka.javadoc.pages.JavadocSignatureContentNode import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.javadoc.pages.JavadocSignatureContentNode import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.utilities.DokkaLogger -import java.lang.IllegalStateException class JavadocPageContentBuilder( commentsConverter: CommentsToContentConverter, @@ -77,4 +76,4 @@ class JavadocPageContentBuilder( supertypes = supertypes ) } -}
\ No newline at end of file +} |