Created
July 19, 2024 17:43
-
-
Save IgnatBeresnev/d71a5c16c3b3f0f8f1fc1699ef1292f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun collectSupertypesFromPsiClass( | |
driWithPsiClass: Pair<DRI, PsiClass>, | |
supersMap: MutableMap<DRI, Supertypes> | |
) { | |
val (dri, psiClass) = driWithPsiClass | |
val supertypes = psiClass.superTypes.mapNotNull { it.resolve() } | |
.filterNot { it.qualifiedName == "java.lang.Object" } | |
val supertypesDriWithPsiClass = supertypes.map { DRI.from(it) to it } | |
if (supersMap[dri] == null) { | |
supersMap[dri] = supertypesDriWithPsiClass.map { it.first } | |
supertypesDriWithPsiClass.forEach { collectSupertypesFromPsiClass(it, supersMap) } | |
} | |
} | |
private fun visitDocumentable( | |
documentable: Documentable, | |
hierarchy: SourceSetDependent<MutableMap<DRI, List<DRI>>> | |
) { | |
if (documentable is WithScope) { | |
documentable.classlikes.forEach { visitDocumentable(it, hierarchy) } | |
} | |
if (documentable is DClasslike) { | |
// to build a full class graph, | |
// using supertypes from Documentable is not enough since it keeps only one level of hierarchy | |
documentable.sources.forEach { (sourceSet, source) -> | |
if (source is KtPsiDocumentableSource) { | |
(source.psi as? KtClassOrObject)?.let { psi -> | |
analyze(kotlinAnalysis.getModule(sourceSet)) { | |
val type = psi.getNamedClassOrObjectSymbol()?.buildSelfClassType() ?: return@analyze | |
hierarchy[sourceSet]?.let { collectSupertypesFromKtType(documentable.dri to type, it) } | |
} | |
} | |
} else if (source is PsiDocumentableSource) { | |
val psi = source.psi as PsiClass | |
hierarchy[sourceSet]?.let { collectSupertypesFromPsiClass(documentable.dri to psi, it) } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment