Hello, I am facing an interesting couple of days b...
# dokka
f
Hello, I am facing an interesting couple of days because of Dokka and I hope I can get some help. In a project I am running into an issue which seems caused by the fact that a stripped version of fastutil end up in Dokka, causing NoMethodFound errors at runtime (see https://github.com/Kotlin/dokka/pull/3409). Ok, I then decided to update Dokka, but unfortunately the analysis APIs were removed with no replacement available (https://github.com/Kotlin/dokka/issues/3099). I am using Dokka to extract comments from Kotlin code, as I need to process comments together with other sources to generate some documentation. I am using Dokka in a gradle plugin in this way:
Copy code
private fun buildAST(file: File): AST {
        val sourceSet =
            DokkaSourceSetImpl(
                displayName = "ast",
                sourceSetID = DokkaSourceSetID("ast", "ast"),
                sourceRoots = setOf(file.canonicalFile),
            )
        val dokkaContext =
            DokkaContext.create(
                DokkaConfigurationImpl(sourceSets = listOf(sourceSet)),
                DokkaConsoleLogger(),
                listOf(),
            )
        // here there is my beloved and removed API
        val translator = DefaultDescriptorToDocumentableTranslator(dokkaContext)
        val module = translator.invoke(sourceSet, dokkaContext)
        return AST(module, sourceSet)
    }
I then use the output of the previous method to populate my map:
Copy code
private fun recordDocumentation(ast: AST) {
        ast.module.packages.forEach { pkg ->
            val documentationNode = pkg.documentation[ast.sourceSet]
            documentationNode?.let { commentsByFqn[pkg.packageName] = it }
            pkg.classlikes.forEach { cls ->
                val classDoc = cls.documentation[ast.sourceSet]
                val name = cls.name
                classDoc?.let {
                    name?.let { commentsByFqn[pkg.packageName + "." + name] = classDoc }
                }
                name?.let {
                    cls.properties.forEach { property ->
                        val propertyDoc = property.documentation[ast.sourceSet]
                        propertyDoc?.let {
                            commentsByFqn[keyForProperty(pkg.packageName, name, property.name)] = propertyDoc
                        }
                    }
                }
            }
        }
    }
Do you have any idea of how I could achieve the same result without the analysis APIs?
v
> Ok, I then decided to update Dokka, but unfortunately the analysis APIs were removed with no replacement available
DefaultDescriptorToDocumentableTranslator
is directly unavailable after the refactoring. Although you can use it via an interface of extension point. In this case it is
CoreExtensions.sourceToDocumentableTranslator
https://github.com/Kotlin/dokka/blob/d4d457d357627fd8100e4f0d47868020485996ec/dokk[…]ects/core/src/main/kotlin/org/jetbrains/dokka/CoreExtensions.kt Also, see the developer guide sourceToDocumentableTranslator. In your example the code should be like:
Copy code
val translators = dokkaContext[CoreExtensions.sourceToDocumentableTranslator]
By default, in the configuration provided by Maven or Gradle plugins
CoreExtensions.sourceToDocumentableTranslator
contains two translators: Java and Kotlin. Also, pay the attention that your
DokkaConfigurationImpl .pluginsClasspath
provides no plugins. You need to provide paths at least to the artifacts
analysis-kotlin-api
and
analysis-kotlin-descriptors
(
analysis-kotlin-symbols
). Note: they also can be loaded via
ServiceLoader
without configuring if a runtime classpath contains them. > Do you have any idea of how I could achieve the same result without the analysis APIs? For your purposes the Dokka Analysis API should be used.