Skip to content

Commit

Permalink
Avoid calling analyze on built-ins (#3200)
Browse files Browse the repository at this point in the history
Otherwise, `Caused by: org.jetbrains.kotlin.utils.exceptions.KotlinIllegalArgumentExceptionWithAttachments: Unexpected class org.jetbrains.kotlin.analysis.project.structure.KtBuiltinsModule
                          	at org.jetbrains.kotlin.analysis.low.level.api.fir.util.ExceptionUtilsKt.errorWithFirSpecificEntries(exceptionUtils.kt:50)`
  • Loading branch information
vmishenev authored Oct 11, 2023
1 parent 562a595 commit edd5195
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class SymbolsAnalysisPlugin : DokkaPlugin() {
plugin<InternalKotlinAnalysisPlugin>().documentableSourceLanguageParser providing { KotlinDocumentableSourceLanguageParser() }
}
internal val symbolFullClassHierarchyBuilder by extending {
plugin<InternalKotlinAnalysisPlugin>().fullClassHierarchyBuilder providing { SymbolFullClassHierarchyBuilder() }
plugin<InternalKotlinAnalysisPlugin>().fullClassHierarchyBuilder providing ::SymbolFullClassHierarchyBuilder
}

internal val symbolSyntheticDocumentableDetector by extending {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.dokka.analysis.kotlin.internal.ClassHierarchy
import org.jetbrains.dokka.analysis.kotlin.internal.FullClassHierarchyBuilder
import org.jetbrains.dokka.analysis.kotlin.internal.Supertypes
import org.jetbrains.dokka.analysis.kotlin.symbols.plugin.SymbolsAnalysisPlugin
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.kotlin.psi.KtClassOrObject
import java.util.concurrent.ConcurrentHashMap


internal class SymbolFullClassHierarchyBuilder : FullClassHierarchyBuilder {
override suspend fun build(module: DModule): ClassHierarchy {
internal class SymbolFullClassHierarchyBuilder(val context: DokkaContext) : FullClassHierarchyBuilder {
private val kotlinAnalysis = context.plugin<SymbolsAnalysisPlugin>().querySingle { kotlinAnalysis }

override suspend fun build(module: DModule): ClassHierarchy {
val map = module.sourceSets.associateWith { ConcurrentHashMap<DRI, List<DRI>>() }
module.packages.forEach { visitDocumentable(it, map) }
return map
Expand All @@ -41,7 +47,7 @@ internal class SymbolFullClassHierarchyBuilder : FullClassHierarchyBuilder {

if (supersMap[dri] == null) {
supersMap[dri] = supertypesDriWithKType.map { it.first }
supertypesDriWithKType.forEach{ collectSupertypesFromKtType(it, supersMap) }
supertypesDriWithKType.forEach { collectSupertypesFromKtType(it, supersMap) }
}
}

Expand Down Expand Up @@ -73,7 +79,7 @@ internal class SymbolFullClassHierarchyBuilder : FullClassHierarchyBuilder {
documentable.sources.forEach { (sourceSet, source) ->
if (source is KtPsiDocumentableSource) {
(source.psi as? KtClassOrObject)?.let { psi ->
analyze(psi) {
analyze(kotlinAnalysis[sourceSet].mainModule) {
val type = psi.getNamedClassOrObjectSymbol()?.buildSelfClassType() ?: return@analyze
hierarchy[sourceSet]?.let { collectSupertypesFromKtType(documentable.dri to type, it) }
}
Expand Down

0 comments on commit edd5195

Please sign in to comment.