Federico Tomassetti
01/31/2024, 3:10 PMprivate 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:
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?Vadim Mishenev
02/14/2024, 3:49 PMDefaultDescriptorToDocumentableTranslator
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:
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.