diff options
| author | Błażej Kardyś <bkardys@virtuslab.com> | 2019-10-31 11:44:03 +0100 |
|---|---|---|
| committer | Błażej Kardyś <bkardys@virtuslab.com> | 2019-10-31 11:44:03 +0100 |
| commit | c33e8e16a0e446b78496cbcd878ba76ea51c0940 (patch) | |
| tree | 7362b668c5ee48255e46a7efcb8db3f2525d1e8f | |
| parent | 14a290009098b777521b1dedb551047fb66ba73b (diff) | |
| download | dokka-c33e8e16a0e446b78496cbcd878ba76ea51c0940.tar.gz dokka-c33e8e16a0e446b78496cbcd878ba76ea51c0940.tar.bz2 dokka-c33e8e16a0e446b78496cbcd878ba76ea51c0940.zip | |
Temp changes
| -rw-r--r-- | .idea/compiler.xml | 10 | ||||
| -rw-r--r-- | core/src/main/kotlin/Generation/DocumentationMerger.kt | 235 | ||||
| -rw-r--r-- | core/src/main/kotlin/Generation/DokkaGenerator.kt | 71 | ||||
| -rw-r--r-- | core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 81 | ||||
| -rw-r--r-- | core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 75 | ||||
| -rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 914 | ||||
| -rw-r--r-- | core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt | 3 | ||||
| -rw-r--r-- | core/src/main/kotlin/Model/DocumentationNode.kt | 339 | ||||
| -rw-r--r-- | core/src/main/kotlin/Model/DocumentationReference.kt | 115 | ||||
| -rw-r--r-- | core/src/main/kotlin/Utilities/DokkaModules.kt | 3 | ||||
| -rw-r--r-- | core/src/main/kotlin/links/DRI.kt | 2 |
11 files changed, 307 insertions, 1541 deletions
diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 71547e0e..d3328b68 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -52,6 +52,8 @@ <module name="dokka.runners.maven-plugin.test" target="1.8" /> <module name="fatjar_main" target="1.8" /> <module name="fatjar_test" target="1.8" /> + <module name="gradle-integration-tests.org.jetbrains.dokka.gradle-integration-tests.main" target="1.8" /> + <module name="gradle-integration-tests.org.jetbrains.dokka.gradle-integration-tests.test" target="1.8" /> <module name="gradle-integration-tests_main" target="1.8" /> <module name="gradle-integration-tests_test" target="1.8" /> <module name="gradle-plugin_main" target="1.8" /> @@ -70,6 +72,8 @@ <module name="org.jetbrains.dokka.cli.test" target="1.8" /> <module name="org.jetbrains.dokka.core.main" target="1.8" /> <module name="org.jetbrains.dokka.core.test" target="1.8" /> + <module name="org.jetbrains.dokka.coreDependencies.main" target="1.8" /> + <module name="org.jetbrains.dokka.coreDependencies.test" target="1.8" /> <module name="org.jetbrains.dokka.fatjar.main" target="1.8" /> <module name="org.jetbrains.dokka.fatjar.test" target="1.8" /> <module name="org.jetbrains.dokka.gradle-integration-tests.main" target="1.8" /> @@ -78,8 +82,14 @@ <module name="org.jetbrains.dokka.gradle-plugin.test" target="1.8" /> <module name="org.jetbrains.dokka.integration.main" target="1.8" /> <module name="org.jetbrains.dokka.integration.test" target="1.8" /> + <module name="org.jetbrains.dokka.javadoc8.main" target="1.8" /> + <module name="org.jetbrains.dokka.javadoc8.test" target="1.8" /> <module name="org.jetbrains.dokka.maven-plugin.main" target="1.8" /> <module name="org.jetbrains.dokka.maven-plugin.test" target="1.8" /> + <module name="org.jetbrains.dokka.plugins.main" target="1.8" /> + <module name="org.jetbrains.dokka.plugins.test" target="1.8" /> + <module name="org.jetbrains.dokka.testApi.main" target="1.8" /> + <module name="org.jetbrains.dokka.testApi.test" target="1.8" /> </bytecodeTargetLevel> </component> </project>
\ No newline at end of file diff --git a/core/src/main/kotlin/Generation/DocumentationMerger.kt b/core/src/main/kotlin/Generation/DocumentationMerger.kt deleted file mode 100644 index 53dc23a9..00000000 --- a/core/src/main/kotlin/Generation/DocumentationMerger.kt +++ /dev/null @@ -1,235 +0,0 @@ -package org.jetbrains.dokka.Generation - -import org.jetbrains.dokka.* - -class DocumentationMerger( - private val documentationModules: List<DocumentationModule>, - val logger: DokkaLogger -) { - private val producedNodeRefGraph: NodeReferenceGraph = NodeReferenceGraph() - private val signatureMap: Map<DocumentationNode, String> - private val oldToNewNodeMap: MutableMap<DocumentationNode, DocumentationNode> = mutableMapOf() - - init { - if (documentationModules.groupBy { it.name }.size > 1) { - throw IllegalArgumentException("Modules should have similar names: ${documentationModules.joinToString(", ") {it.name}}") - } - - signatureMap = documentationModules - .flatMap { it.nodeRefGraph.nodeMapView.entries } - .associate { (k, v) -> v to k } - - - documentationModules.map { it.nodeRefGraph } - .flatMap { it.references } - .forEach { producedNodeRefGraph.addReference(it) } - } - - private fun mergePackageReferences( - from: DocumentationNode, - packages: List<DocumentationReference> - ): List<DocumentationReference> { - val packagesByName = packages - .map { it.to } - .groupBy { it.name } - - val resultReferences = mutableListOf<DocumentationReference>() - for ((name, listOfPackages) in packagesByName) { - try { - val producedPackage = mergePackagesWithEqualNames(name, from, listOfPackages) - updatePendingReferences() - - resultReferences.add( - DocumentationReference(from, producedPackage, RefKind.Member) - ) - } catch (t: Throwable) { - val entries = listOfPackages.joinToString(",") { "references:${it.allReferences().size}" } - throw Error("Failed to merge package $name from $from with entries $entries. ${t.message}", t) - } - } - - return resultReferences - } - - private fun mergePackagesWithEqualNames( - name: String, - from: DocumentationNode, - packages: List<DocumentationNode> - ): DocumentationNode { - val mergedPackage = DocumentationNode(name, Content.Empty, NodeKind.Package) - - for (contentToAppend in packages.map { it.content }.distinct()) { - mergedPackage.updateContent { - for (otherChild in contentToAppend.children) { - children.add(otherChild) - } - } - } - - for (node in packages) { - oldToNewNodeMap[node] = mergedPackage - } - - val references = packages.flatMap { it.allReferences() } - val mergedReferences = mergeReferences(mergedPackage, references) - for (ref in mergedReferences) { - if (ref.kind == RefKind.Owner) { - continue - } - mergedPackage.addReference(ref) - } - - from.append(mergedPackage, RefKind.Member) - - return mergedPackage - } - - private fun mergeMemberGroupBy(it: DocumentationNode): String { - val signature = signatureMap[it] - - if (signature != null) { - return signature - } - - logger.error("Failed to find signature for $it in \n${it.allReferences().joinToString { "\n ${it.kind} ${it.to}" }}") - return "<ERROR>" - } - - private fun mergeMemberReferences( - from: DocumentationNode, - refs: List<DocumentationReference> - ): List<DocumentationReference> { - val membersBySignature: Map<String, List<DocumentationNode>> = refs.map { it.to } - .groupBy(this::mergeMemberGroupBy) - - val mergedMembers: MutableList<DocumentationReference> = mutableListOf() - for ((signature, members) in membersBySignature) { - val newNode = mergeMembersWithEqualSignature(signature, members) - - producedNodeRefGraph.register(signature, newNode) - updatePendingReferences() - from.append(newNode, RefKind.Member) - - mergedMembers.add(DocumentationReference(from, newNode, RefKind.Member)) - } - - return mergedMembers - } - - private fun mergeMembersWithEqualSignature( - signature: String, - nodes: List<DocumentationNode> - ): DocumentationNode { - require(nodes.isNotEmpty()) - - val singleNode = nodes.singleOrNull() - if (singleNode != null) { - singleNode.dropReferences { it.kind == RefKind.Owner } - return singleNode - } - - // Specialization processing - // Given (Common, JVM, JRE6, JS) and (JVM, JRE6) and (JVM, JRE7) - // Sorted: (JVM, JRE6), (JVM, JRE7), (Common, JVM, JRE6, JS) - // Should output: (JVM, JRE6), (JVM, JRE7), (Common, JS) - // Should not remove first platform - val nodesSortedByPlatformCount = nodes.sortedBy { it.platforms.size } - val allPlatforms = mutableSetOf<String>() - nodesSortedByPlatformCount.forEach { node -> - node.platforms - .filterNot { allPlatforms.add(it) } - .filter { it != node.platforms.first() } - .forEach { platform -> - node.dropReferences { it.kind == RefKind.Platform && it.to.name == platform } - } - } - - // TODO: Quick and dirty fox for merging extensions for external classes. Fix this probably in StructuredFormatService - // TODO: while refactoring documentation model - - val groupNode = if(nodes.first().kind == NodeKind.ExternalClass){ - DocumentationNode(nodes.first().name, Content.Empty, NodeKind.ExternalClass) - } else { - DocumentationNode(nodes.first().name, Content.Empty, NodeKind.GroupNode) - } - groupNode.appendTextNode(signature, NodeKind.Signature, RefKind.Detail) - - for (node in nodes) { - node.dropReferences { it.kind == RefKind.Owner } - groupNode.append(node, RefKind.Origin) - node.append(groupNode, RefKind.TopLevelPage) - - oldToNewNodeMap[node] = groupNode - } - - if (groupNode.kind == NodeKind.ExternalClass){ - val refs = nodes.flatMap { it.allReferences() }.filter { it.kind != RefKind.Owner && it.kind != RefKind.TopLevelPage } - refs.forEach { - if (it.kind != RefKind.Link) { - it.to.dropReferences { ref -> ref.kind == RefKind.Owner } - it.to.append(groupNode, RefKind.Owner) - } - groupNode.append(it.to, it.kind) - } - } - - // if nodes are classes, nested members should be also merged and - // inserted at the same level with class - if (nodes.all { it.kind in NodeKind.classLike }) { - val members = nodes.flatMap { it.allReferences() }.filter { it.kind == RefKind.Member } - val mergedMembers = mergeMemberReferences(groupNode, members) - - for (ref in mergedMembers) { - if (ref.kind == RefKind.Owner) { - continue - } - - groupNode.append(ref.to, RefKind.Member) - } - } - - return groupNode - } - - - private fun mergeReferences( - from: DocumentationNode, - refs: List<DocumentationReference> - ): List<DocumentationReference> { - val (refsToPackages, otherRefs) = refs.partition { it.to.kind == NodeKind.Package } - val mergedPackages = mergePackageReferences(from, refsToPackages) - - val (refsToMembers, refsNotToMembers) = otherRefs.partition { it.kind == RefKind.Member } - val mergedMembers = mergeMemberReferences(from, refsToMembers) - - return mergedPackages + mergedMembers + refsNotToMembers - } - - fun merge(): DocumentationModule { - val mergedDocumentationModule = DocumentationModule( - name = documentationModules.first().name, - content = documentationModules.first().content, - nodeRefGraph = producedNodeRefGraph - ) - - val refs = documentationModules.flatMap { - it.allReferences() - } - mergeReferences(mergedDocumentationModule, refs) - - return mergedDocumentationModule - } - - private fun updatePendingReferences() { - for (ref in producedNodeRefGraph.references) { - ref.lazyNodeFrom.update() - ref.lazyNodeTo.update() - } - } - - private fun NodeResolver.update() { - if (this is NodeResolver.Exact && exactNode in oldToNewNodeMap) { - exactNode = oldToNewNodeMap[exactNode]!! - } - } -}
\ No newline at end of file diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 90d7cfcc..51d70fbd 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -7,9 +7,7 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager -import org.jetbrains.dokka.Generation.DocumentationMerger import org.jetbrains.dokka.Utilities.DokkaAnalysisModule -import org.jetbrains.dokka.Utilities.DokkaOutputModule import org.jetbrains.dokka.Utilities.DokkaRunModule import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation @@ -24,12 +22,13 @@ import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer import org.jetbrains.kotlin.resolve.TopDownAnalysisMode import org.jetbrains.kotlin.utils.PathUtil import java.io.File -import kotlin.system.measureTimeMillis -class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, - val logger: DokkaLogger) { +class DokkaGenerator( + val dokkaConfiguration: DokkaConfiguration, + val logger: DokkaLogger +) { - private val documentationModules: MutableList<DocumentationModule> = mutableListOf() + private val documentationModules: MutableList<DocumentationNodes.Module> = mutableListOf() private val globalInjector = Guice.createInjector(DokkaRunModule(dokkaConfiguration)) @@ -37,26 +36,15 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, for (pass in passesConfigurations) { - val documentationModule = DocumentationModule(pass.moduleName) + val documentationModule = DocumentationNodes.Module(pass.moduleName) appendSourceModule(pass, documentationModule) documentationModules.add(documentationModule) } - - val totalDocumentationModule = DocumentationMerger(documentationModules, logger).merge() - totalDocumentationModule.prepareForGeneration(dokkaConfiguration) - - val timeBuild = measureTimeMillis { - logger.info("Generating pages... ") - val outputInjector = globalInjector.createChildInjector(DokkaOutputModule(dokkaConfiguration, logger)) - val instance = outputInjector.getInstance(Generator::class.java) - instance.buildAll(totalDocumentationModule) - } - logger.info("done in ${timeBuild / 1000} secs") } private fun appendSourceModule( passConfiguration: DokkaConfiguration.PassConfiguration, - documentationModule: DocumentationModule + documentationModule: DocumentationNodes.Module ) = with(passConfiguration) { val sourcePaths = passConfiguration.sourceRoots.map { it.path } @@ -84,9 +72,15 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, } val injector = globalInjector.createChildInjector( - DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentationModule.nodeRefGraph, passConfiguration, logger)) + DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, passConfiguration, logger) + ) - buildDocumentationModule(injector, documentationModule, { isNotSample(it, passConfiguration.samples) }, includes) + buildDocumentationModule( + injector, + documentationModule, + { isNotSample(it, passConfiguration.samples) }, + includes + ) val timeAnalyse = System.currentTimeMillis() - startAnalyse logger.info("done in ${timeAnalyse / 1000} secs") @@ -118,7 +112,7 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, return environment } - private fun isNotSample(file: PsiFile, samples: List<String>): Boolean { + private fun isNotSample(file: PsiFile, samples: List<String>): Boolean { val sourceFile = File(file.virtualFile!!.path) return samples.none { sample -> val canonicalSample = File(sample).canonicalPath @@ -145,10 +139,12 @@ class DokkaMessageCollector(val logger: DokkaLogger) : MessageCollector { override fun hasErrors() = seenErrors } -fun buildDocumentationModule(injector: Injector, - documentationModule: DocumentationModule, - filesToDocumentFilter: (PsiFile) -> Boolean = { file -> true }, - includes: List<String> = listOf()) { +fun buildDocumentationModule( + injector: Injector, + documentationModule: DocumentationNodes.Module, + filesToDocumentFilter: (PsiFile) -> Boolean = { file -> true }, + includes: List<String> = listOf() +) { val coreEnvironment = injector.getInstance(KotlinCoreEnvironment::class.java) val fragmentFiles = coreEnvironment.getSourceFiles().filter(filesToDocumentFilter) @@ -158,25 +154,20 @@ fun buildDocumentationModule(injector: Injector, analyzer.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, fragmentFiles) val fragments = fragmentFiles.mapNotNull { resolutionFacade.resolveSession.getPackageFragment(it.packageFqName) } - .distinct() + .distinct() val packageDocs = injector.getInstance(PackageDocs::class.java) for (include in includes) { packageDocs.parse(include, fragments) } - if (documentationModule.content.isEmpty()) { - documentationModule.updateContent { - for (node in packageDocs.moduleContent.children) { - append(node) - } - } - } parseJavaPackageDocs(packageDocs, coreEnvironment) with(injector.getInstance(DocumentationBuilder::class.java)) { - documentationModule.appendFragments(fragments, packageDocs.packageContent, - injector.getInstance(PackageDocumentationBuilder::class.java)) + documentationModule.appendFragments( + fragments, + injector.getInstance(PackageDocumentationBuilder::class.java) + ) propagateExtensionFunctionsToSubclasses(fragments, resolutionFacade) } @@ -189,8 +180,8 @@ fun buildDocumentationModule(injector: Injector, fun parseJavaPackageDocs(packageDocs: PackageDocs, coreEnvironment: KotlinCoreEnvironment) { val contentRoots = coreEnvironment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS) - ?.filterIsInstance<JavaSourceRoot>() - ?.map { it.file } + ?.filterIsInstance<JavaSourceRoot>() + ?.map { it.file } ?: listOf() contentRoots.forEach { root -> root.walkTopDown().filter { it.name == "overview.html" }.forEach { @@ -202,8 +193,8 @@ fun parseJavaPackageDocs(packageDocs: PackageDocs, coreEnvironment: KotlinCoreEn fun KotlinCoreEnvironment.getJavaSourceFiles(): List<PsiJavaFile> { val sourceRoots = configuration.get(CLIConfigurationKeys.CONTENT_ROOTS) - ?.filterIsInstance<JavaSourceRoot>() - ?.map { it.file } + ?.filterIsInstance<JavaSourceRoot>() + ?.map { it.file } ?: listOf() val result = arrayListOf<PsiJavaFile>() diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 3b368329..d3fc7048 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtModifierListOwner fun getSignature(element: PsiElement?) = when(element) { @@ -55,30 +54,33 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { private val passConfiguration: DokkaConfiguration.PassConfiguration private val refGraph: NodeReferenceGraph private val docParser: JavaDocumentationParser + private val documentationBuilder: DocumentationBuilder @Inject constructor( - passConfiguration: DokkaConfiguration.PassConfiguration, + documentationBuilder: DocumentationBuilder, refGraph: NodeReferenceGraph, logger: DokkaLogger, signatureProvider: ElementSignatureProvider, externalDocumentationLinkResolver: ExternalDocumentationLinkResolver ) { - this.passConfiguration = passConfiguration + this.passConfiguration = documentationBuilder.passConfiguration + this.documentationBuilder = documentationBuilder this.refGraph = refGraph this.docParser = JavadocParser(refGraph, logger, signatureProvider, externalDocumentationLinkResolver) } - constructor(passConfiguration: DokkaConfiguration.PassConfiguration, refGraph: NodeReferenceGraph, docParser: JavaDocumentationParser) { - this.passConfiguration = passConfiguration + constructor(documentationBuilder: DocumentationBuilder, refGraph: NodeReferenceGraph, docParser: JavaDocumentationParser) { + this.passConfiguration = documentationBuilder.passConfiguration this.refGraph = refGraph this.docParser = docParser + this.documentationBuilder = documentationBuilder } override fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map<String, Content>) { if (skipFile(file) || file.classes.all { skipElement(it) }) { return } - val packageNode = findOrCreatePackageNode(module, file.packageName, emptyMap(), refGraph) + val packageNode = documentationBuilder.findOrCreatePackageNode(module, file.packageName, emptyMap(), refGraph) appendClasses(packageNode, file.classes) } @@ -108,7 +110,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } fun nodeForElement(element: PsiNamedElement, - kind: NodeKind, + kind: DocumentationNodes, name: String = element.name ?: "<anonymous>", register: Boolean = false): DocumentationNode { val (docComment, deprecatedContent) = docParser.parseDocumentation(element) @@ -125,14 +127,6 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } } } - if (deprecatedContent != null) { - val deprecationNode = DocumentationNode("", deprecatedContent, NodeKind.Modifier) - node.append(deprecationNode, RefKind.Deprecation) - } - if (element is PsiDocCommentOwner && element.isDeprecated && node.deprecation == null) { - val deprecationNode = DocumentationNode("", Content.of(ContentText("Deprecated")), NodeKind.Modifier) - node.append(deprecationNode, RefKind.Deprecation) - } return node } @@ -182,15 +176,15 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { fun PsiClass.build(): DocumentationNode { val kind = when { - isAnnotationType -> NodeKind.AnnotationClass - isInterface -> NodeKind.Interface - isEnum -> NodeKind.Enum - isException() -> NodeKind.Exception - else -> NodeKind.Class + isAnnotationType -> DocumentationNodes.AnnotationClass + isInterface -> DocumentationNodes.Interface + isEnum -> DocumentationNodes.Enum + isException() -> DocumentationNodes.Exception + else -> DocumentationNodes.Class } val node = nodeForElement(this, kind, register = isAnnotationType) superTypes.filter { !ignoreSupertype(it) }.forEach { - node.appendType(it, NodeKind.Supertype) + node.appendType(it, DocumentationNodes.Supertype) val superClass = it.resolve() if (superClass != null) { link(superClass, node, RefKind.Inheritor) @@ -239,13 +233,13 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { "\"" + StringUtil.escapeStringCharacters(value) + "\"" else -> value.toString() } - append(DocumentationNode(text, Content.Empty, NodeKind.Value), RefKind.Detail) + append(DocumentationNode(text, Content.Empty, DocumentationNodes.Value), RefKind.Detail) } } - private fun PsiField.nodeKind(): NodeKind = when { - this is PsiEnumConstant -> NodeKind.EnumItem - else -> NodeKind.Field + private fun PsiField.nodeKind(): DocumentationNodes = when { + this is PsiEnumConstant -> DocumentationNodes.EnumItem + else -> DocumentationNodes.Field } fun PsiMethod.build(): DocumentationNode { @@ -261,24 +255,21 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { return node } - private fun PsiMethod.nodeKind(): NodeKind = when { - isConstructor -> NodeKind.Constructor - else -> NodeKind.Function + private fun PsiMethod.nodeKind(): DocumentationNodes = when { + isConstructor -> DocumentationNodes.Constructor + else -> DocumentationNodes.Function } fun PsiParameter.build(): DocumentationNode { - val node = nodeForElement(this, NodeKind.Parameter) + val node = nodeForElement(this, DocumentationNodes.Parameter::class) node.appendType(type) - if (type is PsiEllipsisType) { - node.appendTextNode("vararg", NodeKind.Modifier, RefKind.Detail) - } return node } fun PsiTypeParameter.build(): DocumentationNode { - val node = nodeForElement(this, NodeKind.TypeParameter) - extendsListTypes.forEach { node.appendType(it, NodeKind.UpperBound) } - implementsListTypes.forEach { node.appendType(it, NodeKind.UpperBound) } + val node = nodeForElement(this, DocumentationNodes.TypeParameter) + extendsListTypes.forEach { node.appendType(it, DocumentationNodes.UpperBound) } + implementsListTypes.forEach { node.appendType(it, DocumentationNodes.UpperBound) } return node } @@ -287,27 +278,27 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { PsiModifier.MODIFIERS.forEach { if (modifierList.hasExplicitModifier(it)) { - appendTextNode(it, NodeKind.Modifier) + appendTextNode(it, DocumentationNodes.Modifier) } } } - fun DocumentationNode.appendType(psiType: PsiType?, kind: NodeKind = NodeKind.Type) { + fun DocumentationNode.appendType(psiType: PsiType?, kind: DocumentationNodes = DocumentationNodes.Type) { if (psiType == null) { return } append(psiType.build(kind), RefKind.Detail) } - fun PsiType.build(kind: NodeKind = NodeKind.Type): DocumentationNode { + fun PsiType.build(kind: DocumentationNodes = DocumentationNodes.Type): DocumentationNode { val name = mapTypeName(this) val node = DocumentationNode(name, Content.Empty, kind) if (this is PsiClassType) { - node.appendDetails(parameters) { build(NodeKind.Type) } + node.appendDetails(parameters) { build(DocumentationNodes.Type) } link(node, resolve()) } if (this is PsiArrayType && this !is PsiEllipsisType) { - node.append(componentType.build(NodeKind.Type), RefKind.Detail) + node.append(componentType.build(DocumentationNodes.Type), RefKind.Detail) } return node } @@ -316,7 +307,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { val existing = refGraph.lookup(getSignature(psiClass)!!) if (existing != null) return existing val new = psiClass.build() - val packageNode = findOrCreatePackageNode(null, (psiClass.containingFile as PsiJavaFile).packageName, emptyMap(), refGraph) + val packageNode = documentation. findOrCreatePackageNode(null, (psiClass.containingFile as PsiJavaFile).packageName, emptyMap(), refGraph) packageNode.append(new, RefKind.Member) return new } @@ -327,20 +318,20 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { is KtLightAbstractAnnotation -> clsDelegate else -> this } - val node = DocumentationNode(qualifiedName?.substringAfterLast(".") ?: "<?>", Content.Empty, NodeKind.Annotation) + val node = DocumentationNodes.Annotation(qualifiedName?.substringAfterLast(".") ?: "<?>") val psiClass = original.nameReferenceElement?.resolve() as? PsiClass if (psiClass != null && psiClass.isAnnotationType) { node.append(lookupOrBuildClass(psiClass), RefKind.Link) } parameterList.attributes.forEach { - val parameter = DocumentationNode(it.name ?: "value", Content.Empty, NodeKind.Parameter) + val parameter = DocumentationNodes.Parameter(it.name ?: "value", this.extractDescriptor()) val value = it.value if (value != null) { val valueText = (value as? PsiLiteralExpression)?.value as? String ?: value.text - val valueNode = DocumentationNode(valueText, Content.Empty, NodeKind.Value) + val valueNode = DocumentationNode(valueText, Content.Empty, DocumentationNodes.Value) parameter.append(valueNode, RefKind.Detail) } - node.append(parameter, RefKind.Detail) + node.append(parameter, RefKind.Detail)m } return node } diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index ce20aeec..7c9f2d15 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -30,20 +30,28 @@ import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.source.PsiSourceElement class DescriptorDocumentationParser - @Inject constructor(val options: DokkaConfiguration.PassConfiguration, - val logger: DokkaLogger, - val linkResolver: DeclarationLinkResolver, - val resolutionFacade: DokkaResolutionFacade, - val refGraph: NodeReferenceGraph, - val sampleService: SampleProcessingService, - val signatureProvider: KotlinElementSignatureProvider, - val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver -) -{ - fun parseDocumentation(descriptor: DeclarationDescriptor, inline: Boolean = false, isDefaultNoArgConstructor: Boolean = false): Content = - parseDocumentationAndDetails(descriptor, inline, isDefaultNoArgConstructor).first +@Inject constructor( + val options: DokkaConfiguration.PassConfiguration, + val logger: DokkaLogger, + val linkResolver: DeclarationLinkResolver, + val resolutionFacade: DokkaResolutionFacade, + val refGraph: NodeReferenceGraph, + val sampleService: SampleProcessingService, + val signatureProvider: KotlinElementSignatureProvider, + val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver +) { + fun parseDocumentation( + descriptor: DeclarationDescriptor, + inline: Boolean = false, + isDefaultNoArgConstructor: Boolean = false + ): Content = + parseDocumentationAndDetails(descriptor, inline, isDefaultNoArgConstructor).first - fun parseDocumentationAndDetails(descriptor: DeclarationDescriptor, inline: Boolean = false, isDefaultNoArgConstructor: Boolean = false): Pair<Content, (DocumentationNode) -> Unit> { + fun parseDocumentationAndDetails( + descriptor: DeclarationDescriptor, + inline: Boolean = false, + isDefaultNoArgConstructor: Boolean = false + ): Pair<Content, (DocumentationNode) -> Unit> { if (descriptor is JavaClassDescriptor || descriptor is JavaCallableMemberDescriptor) { return parseJavadoc(descriptor) } @@ -51,8 +59,8 @@ class DescriptorDocumentationParser val kdoc = descriptor.findKDoc() ?: findStdlibKDoc(descriptor) if (kdoc == null) { if (options.effectivePackageOptions(descriptor.fqNameSafe).reportUndocumented && !descriptor.isDeprecated() && - descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor && - descriptor !is PropertyAccessorDescriptor && !descriptor.isSuppressWarning()) { + descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor && + descriptor !is PropertyAccessorDescriptor && !descriptor.isSuppressWarning()) { logger.warn("No documentation for ${descriptor.signatureWithSourceLocation()}") } return Content.Empty to { node -> } @@ -62,7 +70,7 @@ class DescriptorDocumentationParser (PsiTreeUtil.getParentOfType(kdoc, KDoc::class.java)?.context as? KtDeclaration) ?.takeIf { it != descriptor.original.sourcePsi() } ?.resolveToDescriptorIfAny() - ?: descriptor + ?: descriptor var kdocText = if (isDefaultNoArgConstructor) { getConstructorTagContent(descriptor) ?: kdoc.getContent() @@ -74,7 +82,11 @@ class DescriptorDocumentationParser } val tree = parseMarkdown(kdocText) val linkMap = LinkMap.buildLinkMap(tree.node, kdocText) - val content = buildContent(tree, LinkResolver(linkMap) { href -> linkResolver.resolveContentLink(contextDescriptor, href) }, inline) + val content = buildContent( + tree, + LinkResolver(linkMap) { href -> linkResolver.resolveContentLink(contextDescriptor, href) }, + inline + ) if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { @@ -87,7 +99,10 @@ class DescriptorDocumentationParser val section = content.addSection(javadocSectionDisplayName(it.name), it.getSubjectName()) val sectionContent = it.getContent() val markdownNode = parseMarkdown(sectionContent) - buildInlineContentTo(markdownNode, section, LinkResolver(linkMap) { href -> linkResolver.resolveContentLink(contextDescriptor, href) }) + buildInlineContentTo( + markdownNode, + section, + LinkResolver(linkMap) { href -> linkResolver.resolveContentLink(contextDescriptor, href) }) } } } @@ -102,7 +117,7 @@ class DescriptorDocumentationParser } - private fun DeclarationDescriptor.isSuppressWarning() : Boolean { + private fun DeclarationDescriptor.isSuppressWarning(): Boolean { val suppressAnnotation = annotations.findAnnotation(FqName(Suppress::class.qualifiedName!!)) return if (suppressAnnotation != null) { @Suppress("UNCHECKED_CAST") @@ -126,11 +141,12 @@ class DescriptorDocumentationParser } if (DescriptorUtils.getFqName(deepestDescriptor.containingDeclaration).asString() == "kotlin.Any") { val anyClassDescriptors = resolutionFacade.resolveSession.getTopLevelClassifierDescriptors( - FqName.fromSegments(listOf("kotlin", "Any")), NoLookupLocation.FROM_IDE) + FqName.fromSegments(listOf("kotlin", "Any")), NoLookupLocation.FROM_IDE + ) anyClassDescriptors.forEach { val anyMethod = (it as ClassDescriptor).getMemberScope(listOf()) - .getDescriptorsFiltered(DescriptorKindFilter.FUNCTIONS) { it == descriptor.name } - .single() + .getDescriptorsFiltered(DescriptorKindFilter.FUNCTIONS) { it == descriptor.name } + .single() val kdoc = anyMethod.findKDoc() if (kdoc != null) { return kdoc @@ -145,17 +161,12 @@ class DescriptorDocumentationParser val psi = ((descriptor as? DeclarationDescriptorWithSource)?.source as? PsiSourceElement)?.psi if (psi is PsiDocCommentOwner) { |
