diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/DokkaDescriptorVisitor.kt | 22 | ||||
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 16 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/transformers/XmlAttributesTransformer.kt | 80 |
3 files changed, 113 insertions, 5 deletions
diff --git a/core/src/main/kotlin/DokkaDescriptorVisitor.kt b/core/src/main/kotlin/DokkaDescriptorVisitor.kt index 34b45f23..0265eacb 100644 --- a/core/src/main/kotlin/DokkaDescriptorVisitor.kt +++ b/core/src/main/kotlin/DokkaDescriptorVisitor.kt @@ -42,9 +42,7 @@ class DokkaDescriptorVisitor( override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRI): Class { val dri = parent.withClass(descriptor.name.asString()) val scope = descriptor.getMemberScope(emptyList()) - val kdoc = descriptor.findKDoc()?.let { - parseMarkdown(it.text) - } + return Class( dri, descriptor.name.asString(), @@ -53,7 +51,8 @@ class DokkaDescriptorVisitor( scope.properties(dri), scope.classes(dri), descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), - listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()), + getXMLDRIs(listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData())).toMutableSet() ) } @@ -141,4 +140,19 @@ class DokkaDescriptorVisitor( }?.toMap() ?: emptyMap() return Descriptor(this, doc, links, listOf(platformData)) } + + private fun getXMLDRIs(descriptors: List<Descriptor<*>>) = + descriptors.mapNotNull { it.docTag?.children?.findLast { it.text.contains("@attr") }?.text }.flatMap { ref -> + val matchResult = "@attr\\s+ref\\s+(.+)".toRegex().matchEntire(ref) + val toFind = matchResult?.groups?.last()?.value.orEmpty() + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + descriptors.first().descriptor, + null, + toFind.split('.') + ).map { DefaultExtra("@attr ref", DRI.from(it).toString()) } + } } + +data class DefaultExtra(val key: String, val value: String) : Extra diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 355b232a..7529c53a 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -7,6 +7,7 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.MarkdownToContentConverter import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.pages.transformers.XmlAttributesTransformer import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.HtmlRenderer import org.jetbrains.dokka.resolvers.DefaultLocationProvider @@ -50,7 +51,10 @@ class DokkaGenerator( .distinct() .mapNotNull { facade.resolveSession.getPackageFragment(it) } .map { - DokkaDescriptorVisitor(PlatformData(pass.analysisPlatform, pass.targets), facade).visitPackageFragmentDescriptor( + DokkaDescriptorVisitor( + PlatformData(pass.analysisPlatform, pass.targets), + facade + ).visitPackageFragmentDescriptor( it, DRI.topLevel ) @@ -71,6 +75,16 @@ class DokkaGenerator( DefaultLocationProvider(it, configuration, ".${configuration.format}") ).render(it) } + .let { + XmlAttributesTransformer(it) + } + }.also { + // it.genericPretty().also(::nierzigoj) + HtmlRenderer( + FileWriter(configuration.outputDir, ""), + DefaultLocationProvider(it, configuration, ".${configuration.format}") + ).render(it) + } } private class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector { diff --git a/core/src/main/kotlin/pages/transformers/XmlAttributesTransformer.kt b/core/src/main/kotlin/pages/transformers/XmlAttributesTransformer.kt new file mode 100644 index 00000000..7a74cb65 --- /dev/null +++ b/core/src/main/kotlin/pages/transformers/XmlAttributesTransformer.kt @@ -0,0 +1,80 @@ +package org.jetbrains.dokka.pages.transformers + +import org.jetbrains.dokka.DefaultExtra +import org.jetbrains.dokka.Model.DocumentationNode +import org.jetbrains.dokka.Model.dfs +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.renderers.platforms + +object XmlAttributesTransformer : PageNodeTransformer { + enum class XMLKind : Kind { + Main, XmlList + } + + override fun invoke(original: ModulePageNode): ModulePageNode { + original.findAll { it is ClassPageNode }.forEach { node -> + val refs = node.documentationNode?.extra?.filterIsInstance<DefaultExtra>()?.filter { it.key == "@attr ref"}.orEmpty() + val elementsToAdd = mutableListOf<DocumentationNode<*>>() + + refs.forEach { ref -> + val toFind = DRI.from(ref.value) + original.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } + } + + val refTable = ContentGroup( + listOf( + ContentHeader( + listOf( + ContentText( + "XML Attributes", + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + 2, + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ), + ContentTable( + emptyList(), + elementsToAdd.map { + ContentGroup( + listOf( + ContentDRILink( + listOf( + ContentText( + it.descriptors.first().name.toString(), + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + it.dri, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ), + ContentText( + it.briefDocstring, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + }, + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + + val content = node.content as ContentGroup + val children = (node.content as ContentGroup).children + node.content = content.copy(children = children + refTable) + } + return original + } +} |