@@ -6,16 +6,16 @@ import kotlin.contracts.ExperimentalContracts
6
6
import kotlin.contracts.contract
7
7
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember
8
8
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingSymbol
9
+ import org.jetbrains.kotlin.fir.declarations.FirClass
9
10
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
10
- import org.jetbrains.kotlin.fir.declarations.FirFunction
11
+ import org.jetbrains.kotlin.fir.declarations.utils.memberDeclarationNameOrNull
11
12
import org.jetbrains.kotlin.fir.declarations.utils.nameOrSpecialName
12
13
import org.jetbrains.kotlin.fir.packageFqName
13
14
import org.jetbrains.kotlin.fir.resolve.getContainingDeclaration
15
+ import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
14
16
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
15
17
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
16
18
import org.jetbrains.kotlin.fir.symbols.impl.*
17
- import org.jetbrains.kotlin.fir.types.ConeKotlinType
18
- import org.jetbrains.kotlin.fir.types.coneType
19
19
import org.jetbrains.kotlin.name.FqName
20
20
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
21
21
@@ -163,44 +163,37 @@ class GlobalSymbolsCache(testing: Boolean = false) : Iterable<Symbol> {
163
163
}
164
164
165
165
@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 " () "
178
178
}
179
179
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
+ }
186
187
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
+ }
189
192
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} )"
195
195
}
196
196
197
- private fun methodDisambiguator (symbol : FirBasedSymbol <* >): String =
198
- when (symbol) {
199
- is FirCallableSymbol <* > -> disambiguateCallableSymbol(symbol)
200
- is FirClassSymbol <* > -> disambiguateClassSymbol(symbol)
201
- else -> " ()"
202
- }
203
-
204
197
override fun iterator (): Iterator <Symbol > = globals.values.iterator()
205
198
}
206
199
0 commit comments