From edd51958c657e0aa226a584b6c7b8d0749641b9f Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Wed, 11 Oct 2023 20:00:09 +0300 Subject: Avoid calling analyze on built-ins (#3200) 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)` --- .../kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt | 2 +- .../symbols/services/SymbolFullClassHierarchyBuilder.kt | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka') diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt index 43435a55..ef795145 100644 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt +++ b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt @@ -93,7 +93,7 @@ public class SymbolsAnalysisPlugin : DokkaPlugin() { plugin().documentableSourceLanguageParser providing { KotlinDocumentableSourceLanguageParser() } } internal val symbolFullClassHierarchyBuilder by extending { - plugin().fullClassHierarchyBuilder providing { SymbolFullClassHierarchyBuilder() } + plugin().fullClassHierarchyBuilder providing ::SymbolFullClassHierarchyBuilder } internal val symbolSyntheticDocumentableDetector by extending { diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/SymbolFullClassHierarchyBuilder.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/SymbolFullClassHierarchyBuilder.kt index 375aee90..0e90bec8 100644 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/SymbolFullClassHierarchyBuilder.kt +++ b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/SymbolFullClassHierarchyBuilder.kt @@ -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().querySingle { kotlinAnalysis } + + override suspend fun build(module: DModule): ClassHierarchy { val map = module.sourceSets.associateWith { ConcurrentHashMap>() } module.packages.forEach { visitDocumentable(it, map) } return map @@ -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) } } } @@ -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) } } -- cgit