@@ -70,8 +70,6 @@ import org.jetbrains.kotlin.utils.toReadOnlyList
70
70
import java.util.*
71
71
import com.intellij.debugger.engine.DebuggerUtils as JDebuggerUtils
72
72
73
- class PositionedElement (val className : String? , val element : PsiElement ? )
74
-
75
73
public class KotlinPositionManager (private val myDebugProcess : DebugProcess ) : MultiRequestPositionManager, PositionManagerEx() {
76
74
77
75
private val myTypeMappers = WeakHashMap <String , CachedValue <JetTypeMapper >>()
@@ -177,8 +175,8 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
177
175
continue
178
176
}
179
177
180
- val internalClassName = getInternalClassNameForElement(literal.firstChild, typeMapper, file, isInLibrary).className
181
- if (internalClassName == currentLocationClassName) {
178
+ val internalClassNames = getInternalClassNameForElement(literal.firstChild, typeMapper, file, isInLibrary)
179
+ if (internalClassNames.any { it == currentLocationClassName } ) {
182
180
return literal
183
181
}
184
182
}
@@ -233,7 +231,7 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
233
231
234
232
if (! ProjectRootsUtil .isInProjectOrLibSource(psiFile)) return result
235
233
236
- val names = classNameForPositionAndInlinedOnes (sourcePosition)
234
+ val names = classNamesForPositionAndInlinedOnes (sourcePosition)
237
235
for (name in names) {
238
236
result.addAll(myDebugProcess.virtualMachineProxy.classesByName(name))
239
237
}
@@ -252,48 +250,44 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
252
250
throw NoDataException .INSTANCE
253
251
}
254
252
255
- private fun classNameForPositionAndInlinedOnes (sourcePosition : SourcePosition ): List <String > {
253
+ private fun classNamesForPositionAndInlinedOnes (sourcePosition : SourcePosition ): List <String > {
256
254
val result = hashSetOf<String >()
257
- val name = classNameForPosition(sourcePosition)
258
- if (name != null ) {
259
- result.add(name)
260
- }
261
- val list = findInlinedCalls(sourcePosition.elementAt, sourcePosition.file)
262
- result.addAll(list)
255
+ val names = classNamesForPosition(sourcePosition)
256
+ result.addAll(names)
263
257
264
258
val lambdas = findLambdas(sourcePosition)
265
259
result.addAll(lambdas)
266
260
267
261
return result.toReadOnlyList();
268
262
}
269
263
270
- private fun findLambdas (sourcePosition : SourcePosition ): List <String > {
264
+ private fun findLambdas (sourcePosition : SourcePosition ): Collection <String > {
271
265
return runReadAction {
272
266
val lambdas = getLambdasAtLineIfAny(sourcePosition)
273
267
val file = sourcePosition.file.containingFile as KtFile
274
268
val isInLibrary = LibraryUtil .findLibraryEntry(file.virtualFile, file.project) != null
275
- lambdas.mapNotNull {
269
+ lambdas.flatMap {
276
270
val typeMapper = if (! isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(it, file)
277
- getInternalClassNameForElement(it, typeMapper, file, isInLibrary).className
271
+ getInternalClassNameForElement(it, typeMapper, file, isInLibrary)
278
272
}
279
273
}
280
274
}
281
275
282
- public fun classNameForPosition (sourcePosition : SourcePosition ): String? {
283
- val psiElement = runReadAction { sourcePosition.elementAt } ? : return null
284
- return classNameForPosition (psiElement)
276
+ public fun classNamesForPosition (sourcePosition : SourcePosition ): Collection < String > {
277
+ val psiElement = runReadAction { sourcePosition.elementAt } ? : return emptyList()
278
+ return classNamesForPosition (psiElement)
285
279
}
286
280
287
- private fun classNameForPosition (element : PsiElement ): String? {
281
+ private fun classNamesForPosition (element : PsiElement ): Collection < String > {
288
282
return runReadAction {
289
283
if (DumbService .getInstance(element.project).isDumb) {
290
- null
284
+ emptySet()
291
285
}
292
286
else {
293
287
val file = element.containingFile as KtFile
294
288
val isInLibrary = LibraryUtil .findLibraryEntry(file.virtualFile, file.project) != null
295
289
val typeMapper = if (! isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(element, file)
296
- getInternalClassNameForElement(element, typeMapper, file, isInLibrary).className
290
+ getInternalClassNameForElement(element, typeMapper, file, isInLibrary)
297
291
}
298
292
}
299
293
}
@@ -335,19 +329,15 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
335
329
336
330
@Deprecated(" Since Idea 14.0.3 use createPrepareRequests fun" )
337
331
override fun createPrepareRequest (classPrepareRequestor : ClassPrepareRequestor , sourcePosition : SourcePosition ): ClassPrepareRequest ? {
338
- if (sourcePosition.file !is KtFile ) {
339
- throw NoDataException .INSTANCE
340
- }
341
- val className = classNameForPosition(sourcePosition) ? : return null
342
- return myDebugProcess.requestsManager.createClassPrepareRequest(classPrepareRequestor, className.replace(' /' , ' .' ))
332
+ return createPrepareRequests(classPrepareRequestor, sourcePosition).firstOrNull()
343
333
}
344
334
345
335
override fun createPrepareRequests (requestor : ClassPrepareRequestor , position : SourcePosition ): List <ClassPrepareRequest > {
346
336
if (position.file !is KtFile ) {
347
337
throw NoDataException .INSTANCE
348
338
}
349
339
350
- return classNameForPositionAndInlinedOnes (position).mapNotNull {
340
+ return classNamesForPositionAndInlinedOnes (position).mapNotNull {
351
341
className -> myDebugProcess.requestsManager.createClassPrepareRequest(requestor, className.replace(' /' , ' .' ))
352
342
}
353
343
}
@@ -360,32 +350,32 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
360
350
myTypeMappers.put(key, value)
361
351
}
362
352
363
- private fun getInternalClassNameForElement (notPositionedElement : PsiElement ? , typeMapper : JetTypeMapper , file : KtFile , isInLibrary : Boolean ): PositionedElement {
353
+ private fun getInternalClassNameForElement (notPositionedElement : PsiElement ? , typeMapper : JetTypeMapper , file : KtFile , isInLibrary : Boolean ): Collection < String > {
364
354
val element = getElementToCalculateClassName(notPositionedElement)
365
355
when {
366
- element is KtClassOrObject -> return PositionedElement ( getJvmInternalNameForImpl(typeMapper, element), element )
356
+ element is KtClassOrObject -> return getJvmInternalNameForImpl(typeMapper, element).toCollection( )
367
357
element is KtFunctionLiteral -> {
368
358
if (isInlinedLambda(element, typeMapper.bindingContext)) {
369
359
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
370
360
}
371
361
else {
372
362
val asmType = CodegenBinding .asmTypeForAnonymousClass(typeMapper.bindingContext, element)
373
- return PositionedElement ( asmType.internalName, element )
363
+ return asmType.internalName.toCollection( )
374
364
}
375
365
}
376
366
element is KtAnonymousInitializer -> {
377
367
val parent = getElementToCalculateClassName(element.parent)
378
368
// Class-object initializer
379
369
if (parent is KtObjectDeclaration && parent.isCompanion()) {
380
- return PositionedElement ( getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary).className, parent )
370
+ return getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary)
381
371
}
382
372
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
383
373
}
384
374
element is KtProperty && (! element.isTopLevel || ! isInLibrary) -> {
385
375
if (isInPropertyAccessor(notPositionedElement)) {
386
376
val classOrObject = PsiTreeUtil .getParentOfType(element, KtClassOrObject ::class .java)
387
377
if (classOrObject != null ) {
388
- return PositionedElement ( getJvmInternalNameForImpl(typeMapper, classOrObject), element )
378
+ return getJvmInternalNameForImpl(typeMapper, classOrObject).toCollection( )
389
379
}
390
380
}
391
381
@@ -394,25 +384,31 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
394
384
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
395
385
}
396
386
397
- return PositionedElement ( getJvmInternalNameForPropertyOwner(typeMapper, descriptor), element )
387
+ return getJvmInternalNameForPropertyOwner(typeMapper, descriptor).toCollection( )
398
388
}
399
389
element is KtNamedFunction -> {
400
390
if (isInlinedLambda(element, typeMapper.bindingContext)) {
401
391
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
402
392
}
403
393
394
+ val inlinedCalls = findInlinedCalls(element, typeMapper.bindingContext)
404
395
val parent = getElementToCalculateClassName(element.parent)
405
- if (parent is KtClassOrObject ) {
406
- return PositionedElement ( getJvmInternalNameForImpl(typeMapper, parent), element )
396
+ val parentInternalName = if (parent is KtClassOrObject ) {
397
+ getJvmInternalNameForImpl(typeMapper, parent)
407
398
}
408
399
else if (parent != null ) {
409
400
val asmType = CodegenBinding .asmTypeForAnonymousClass(typeMapper.bindingContext, element)
410
- return PositionedElement (asmType.internalName, element)
401
+ asmType.internalName
402
+ }
403
+ else {
404
+ NoResolveFileClassesProvider .getFileClassInternalName(file)
411
405
}
406
+
407
+ return (inlinedCalls + parentInternalName.toCollection()).toSet()
412
408
}
413
409
}
414
410
415
- return PositionedElement ( NoResolveFileClassesProvider .getFileClassInternalName(file), element )
411
+ return NoResolveFileClassesProvider .getFileClassInternalName(file).toCollection( )
416
412
}
417
413
418
414
private val TYPES_TO_CALCULATE_CLASSNAME : Array <Class <out KtElement >> =
@@ -468,29 +464,18 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
468
464
private fun createKeyForTypeMapper (file : KtFile ) = NoResolveFileClassesProvider .getFileClassInternalName(file)
469
465
470
466
471
- private fun findInlinedCalls (element : PsiElement ? , jetFile : PsiFile ? ): List <String > {
472
- if (element == null || jetFile !is KtFile ) {
473
- return emptyList()
474
- }
475
-
467
+ private fun findInlinedCalls (function : KtNamedFunction , context : BindingContext ): Collection <String > {
476
468
return runReadAction {
477
- val result = arrayListOf<String >()
478
- val isInLibrary = LibraryUtil .findLibraryEntry(jetFile.virtualFile, jetFile.project) != null
479
- val typeMapper = if (! isInLibrary) prepareTypeMapper(jetFile) else createTypeMapperForLibraryFile(element, jetFile)
480
- val psiElement = getInternalClassNameForElement(element, typeMapper, jetFile, isInLibrary).element;
481
-
482
- if (psiElement is KtNamedFunction &&
483
- InlineUtil .isInline(typeMapper.bindingContext.get(BindingContext .DECLARATION_TO_DESCRIPTOR , psiElement))
484
- ) {
485
- ReferencesSearch .search(psiElement).forEach {
469
+ val result = hashSetOf<String >()
470
+
471
+ if (InlineUtil .isInline(context.get(BindingContext .DECLARATION_TO_DESCRIPTOR , function))) {
472
+ ReferencesSearch .search(function).forEach {
486
473
if (! it.isImportUsage()) {
487
474
val usage = it.element
488
475
if (usage is KtElement ) {
489
476
// TODO recursive search
490
- val name = classNameForPosition(usage)
491
- if (name != null ) {
492
- result.add(name)
493
- }
477
+ val names = classNamesForPosition(usage)
478
+ result.addAll(names)
494
479
}
495
480
}
496
481
true
@@ -502,6 +487,8 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
502
487
503
488
private fun ReferenceType.containsKotlinStrata () = availableStrata().contains(" Kotlin" )
504
489
490
+ private fun String?.toCollection () = if (this == null ) emptySet() else setOf (this )
491
+
505
492
companion object {
506
493
public fun createTypeMapper (file : KtFile ): JetTypeMapper {
507
494
val project = file.project
0 commit comments