@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.isImportUsage
46
46
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
47
47
import org.jetbrains.kotlin.idea.util.application.runReadAction
48
48
import org.jetbrains.kotlin.load.java.JvmAbi
49
+ import org.jetbrains.kotlin.name.Name
49
50
import org.jetbrains.kotlin.psi.*
50
51
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
51
52
import org.jetbrains.kotlin.psi.psiUtil.parents
@@ -187,7 +188,7 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
187
188
private fun inlineCallClassPatterns (typeMapper : KotlinTypeMapper , element : KtElement ): List <String > {
188
189
val context = typeMapper.bindingContext
189
190
190
- val ( inlineCall, ktAnonymousClassElementProducer) = runReadAction {
191
+ val inlineCall = runReadAction {
191
192
element.parents.map {
192
193
val ktCallExpression: KtCallExpression = when (it) {
193
194
is KtFunctionLiteral -> {
@@ -210,31 +211,26 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
210
211
ktCallExpression to (it as KtElement )
211
212
}.lastOrNull {
212
213
it != null && isInlineCall(context, it.component1())
213
- }
214
+ }?.first
214
215
} ? : return emptyList()
215
216
216
217
val lexicalScope = context[BindingContext .LEXICAL_SCOPE , inlineCall] ? : return emptyList()
218
+ val baseClassName = classNamesForPosition(inlineCall, false ).firstOrNull() ? : return emptyList()
217
219
218
220
val resolvedCall = runReadAction { inlineCall.getResolvedCall(context) } ? : return emptyList()
219
221
val inlineFunctionName = resolvedCall.resultingDescriptor.name
220
222
221
- val originalInternalClassName = CodegenBinding .asmTypeForAnonymousClass(
222
- typeMapper.bindingContext, ktAnonymousClassElementProducer).internalName
223
-
224
223
val ownerDescriptor = lexicalScope.ownerDescriptor
225
-
226
- val className = if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext)) {
227
- originalInternalClassName.replaceAfterLast(" $" , DO_RESUME_METHOD_NAME )
224
+ val ownerDescriptorName = if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext)) {
225
+ Name .identifier(DO_RESUME_METHOD_NAME )
228
226
}
229
227
else {
230
- originalInternalClassName.funPrefix()
228
+ ownerDescriptor.name
231
229
}
232
230
231
+ val ownerJvmName = if (ownerDescriptorName.isSpecial) InlineCodegenUtil .SPECIAL_TRANSFORMATION_NAME else ownerDescriptorName.asString()
233
232
val mangledInternalClassName =
234
- className +
235
- (if (ownerDescriptor.name.isSpecial) " $" + InlineCodegenUtil .SPECIAL_TRANSFORMATION_NAME else " " ) +
236
- InlineCodegenUtil .INLINE_CALL_TRANSFORMATION_SUFFIX + " $" +
237
- inlineFunctionName
233
+ baseClassName + " $" + ownerJvmName + InlineCodegenUtil .INLINE_CALL_TRANSFORMATION_SUFFIX + " $" + inlineFunctionName
238
234
239
235
return listOf (" $mangledInternalClassName *" )
240
236
}
@@ -254,7 +250,7 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
254
250
KtSecondaryConstructor ::class .java)
255
251
256
252
private fun getElementToCalculateClassName (notPositionedElement : PsiElement ? ): KtElement ? {
257
- if (notPositionedElement?.javaClass as Class <* > in TYPES_TO_CALCULATE_CLASSNAME ) return notPositionedElement as KtElement
253
+ if (notPositionedElement?.let { it:: class .java } as Class <* > in TYPES_TO_CALCULATE_CLASSNAME ) return notPositionedElement as KtElement
258
254
259
255
return readAction { PsiTreeUtil .getParentOfType(notPositionedElement, * TYPES_TO_CALCULATE_CLASSNAME ) }
260
256
}
@@ -411,17 +407,6 @@ private fun isInlineCall(context: BindingContext, expr: KtCallExpression): Boole
411
407
412
408
private inline fun <reified T : PsiElement > PsiElement.typedParent (): T ? = getStrictParentOfType()
413
409
414
- private fun String.funPrefix (): String {
415
- if (lastIndexOf(" $" ) < 0 ) return this
416
-
417
- val trimmed = trimEnd { it == ' $' || it.isDigit() } // Can accidentally trim end of function name if it ends with a number
418
- val nextDollarIndex = indexOf(' $' , startIndex = trimmed.length - 1 )
419
-
420
- if (nextDollarIndex < 0 ) return this
421
-
422
- return this .substring(0 , nextDollarIndex)
423
- }
424
-
425
410
private fun String.substringIndex (): String {
426
411
if (lastIndexOf(" $" ) < 0 ) return this
427
412
0 commit comments