Kotlin: don't deduplicate move-conflict per surrounding context (IJ-CR-164999)

(cherry picked from commit aa9180b2e500571b66195ab85d3922fc9bdbb259)

IJ-CR-164999

GitOrigin-RevId: 9070e72f63dc0cdf79b43c1fbc377c9b88381760
This commit is contained in:
Bas Leijdekkers
2025-06-18 16:56:14 +02:00
committed by intellij-monorepo-bot
parent cafc7c15ee
commit 5e3e8bcda5
4 changed files with 3 additions and 5 deletions

View File

@@ -399,7 +399,6 @@ fun checkVisibilityInUsages(
usages: Collection<UsageInfo>
): MultiMap<PsiElement, String> {
val conflicts = MultiMap<PsiElement, String>()
val declarationToContainers = HashMap<KtNamedDeclaration, MutableSet<PsiElement>>()
for (usage in usages) {
val element = usage.element
if (element == null || usage !is MoveRenameUsageInfo || usage is NonCodeUsageInfo) continue
@@ -413,7 +412,6 @@ fun checkVisibilityInUsages(
&& moveTarget.targetElement.parentsWithSelf.filterIsInstance<KtClassOrObject>().all { it.isPublic}
) continue
val container = element.getUsageContext()
if (!declarationToContainers.getOrPut(referencedElement) { HashSet() }.add(container)) continue
val targetContainer = moveTarget.getContainerDescriptor(moveCheckerInfo.context) ?: continue
val referencingDescriptor = when (container) {
is KtDeclaration -> container.resolveToDescriptorIfAny()

View File

@@ -1 +1,2 @@
Method bar() uses class Test which will be inaccessible after move
Method bar() uses class Test which will be inaccessible after move

View File

@@ -1 +1,2 @@
Method bar() uses object Test which will be inaccessible after move
Method bar() uses object Test which will be inaccessible after move

View File

@@ -130,7 +130,6 @@ internal fun checkVisibilityConflictForNonMovedUsages(
targetDir: PsiDirectory,
target: K2MoveTargetDescriptor.Declaration<*>? = null
): MultiMap<PsiElement, String> {
val declarationToContainers = HashMap<KtNamedDeclaration, MutableSet<PsiElement>>()
return usages
.filter { usageInfo -> usageInfo.willNotBeMoved(allDeclarationsToMove) && usageInfo.isVisibleBeforeMove() }
.mapNotNull { usageInfo ->
@@ -151,8 +150,7 @@ internal fun checkVisibilityConflictForNonMovedUsages(
else -> true
}
val reported = declarationToContainers.computeIfAbsent(referencedDeclaration, { HashSet() })
if (reported.add(usageElement.getContainer()) && !isVisible) usageElement.createVisibilityConflict(referencedDeclaration) else null
if (!isVisible) usageElement.createVisibilityConflict(referencedDeclaration) else null
}
}
}