@@ -6,16 +6,16 @@ import kotlin.contracts.ExperimentalContracts
66import kotlin.contracts.contract
77import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember
88import org.jetbrains.kotlin.fir.analysis.checkers.getContainingSymbol
9+ import org.jetbrains.kotlin.fir.declarations.FirClass
910import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
10- import org.jetbrains.kotlin.fir.declarations.FirFunction
11+ import org.jetbrains.kotlin.fir.declarations.utils.memberDeclarationNameOrNull
1112import org.jetbrains.kotlin.fir.declarations.utils.nameOrSpecialName
1213import org.jetbrains.kotlin.fir.packageFqName
1314import org.jetbrains.kotlin.fir.resolve.getContainingDeclaration
15+ import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
1416import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
1517import org.jetbrains.kotlin.fir.symbols.SymbolInternals
1618import org.jetbrains.kotlin.fir.symbols.impl.*
17- import org.jetbrains.kotlin.fir.types.ConeKotlinType
18- import org.jetbrains.kotlin.fir.types.coneType
1919import org.jetbrains.kotlin.name.FqName
2020import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
2121
@@ -163,44 +163,37 @@ class GlobalSymbolsCache(testing: Boolean = false) : Iterable<Symbol> {
163163 }
164164
165165 @OptIn(SymbolInternals ::class )
166- fun disambiguateCallableSymbol ( callableSymbol : FirCallableSymbol <* >): String {
167- val callableId = callableSymbol.callableId
168- val callableName = callableId.callableName.asString()
169- val fqName = callableId.packageName.asString()
170-
171- // Get the FIR element associated with the callable symbol
172- val firFunction = callableSymbol .fir as ? FirFunction ? : return " $fqName . $callableName "
173-
174- // Get parameter types from the function's value parameters
175- val parameterTypes =
176- firFunction.valueParameters.joinToString(separator = " , " ) {
177- it.returnTypeRef.coneType.render()
166+ private fun methodDisambiguator ( symbol : FirFunctionSymbol <* >): String {
167+ val session = symbol.moduleData.session
168+
169+ val siblings =
170+ when ( val containingSymbol = symbol.getContainingSymbol(session)) {
171+ is FirClassSymbol ->
172+ (containingSymbol .fir as FirClass ).declarations.map { it.symbol }
173+ is FirFileSymbol -> containingSymbol.fir.declarations.map { it.symbol }
174+ null ->
175+ symbol.moduleData.session.symbolProvider.getTopLevelCallableSymbols(
176+ symbol.packageFqName(), symbol.name)
177+ else -> return " () "
178178 }
179179
180- // Get the return type (for functions and properties)
181- val returnType = firFunction.returnTypeRef.coneType.render()
182-
183- // Create a string representing the fully qualified name + signature
184- return " $fqName .$callableName ($parameterTypes ): $returnType "
185- }
180+ var count = 0
181+ var found = false
182+ for (decl in siblings) {
183+ if (decl == symbol) {
184+ found = true
185+ break
186+ }
186187
187- // Extension function to render a ConeKotlinType to a string
188- private fun ConeKotlinType?.render (): String = this ?.toString() ? : " Unit"
188+ if (decl.memberDeclarationNameOrNull?.equals(symbol.name) == true ) {
189+ count++
190+ }
191+ }
189192
190- private fun disambiguateClassSymbol (classSymbol : FirClassSymbol <* >): String {
191- val classId = classSymbol.classId
192- val fqName = classId.asString()
193- // You can also add additional details like visibility or modifiers if needed
194- return " class $fqName "
193+ if (count == 0 || ! found) return " ()"
194+ return " (+${count} )"
195195 }
196196
197- private fun methodDisambiguator (symbol : FirBasedSymbol <* >): String =
198- when (symbol) {
199- is FirCallableSymbol <* > -> disambiguateCallableSymbol(symbol)
200- is FirClassSymbol <* > -> disambiguateClassSymbol(symbol)
201- else -> " ()"
202- }
203-
204197 override fun iterator (): Iterator <Symbol > = globals.values.iterator()
205198}
206199
0 commit comments