From 95187cd035767a17908f7969fc51a21763c275db Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 30 Jan 2014 18:50:21 +0400 Subject: [PATCH] Avoid usage duplication for declarations with multiple light elements --- .../safeDelete/KotlinSafeDeleteProcessor.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.kt index a82689fda38..3367617eece 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.kt @@ -67,7 +67,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() { return NonCodeUsageSearchInfo(getIgnoranceCondition(), element) } - fun findUsagesByJavaProcessor(element: PsiElement): NonCodeUsageSearchInfo? { + fun findUsagesByJavaProcessor(element: PsiElement, forceReferencedElementUnwrapping: Boolean): NonCodeUsageSearchInfo? { val javaUsages = ArrayList() val searchInfo = super.findUsages(element, allElementsToDelete, javaUsages) @@ -92,7 +92,9 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() { else { usageElement.getParentByType(javaClass())?.let { importDirective -> SafeDeleteImportDirectiveUsageInfo(importDirective, element.unwrapped as JetDeclaration) - } ?: usageInfo + } ?: if (forceReferencedElementUnwrapping) { + SafeDeleteReferenceJavaDeleteUsageInfo(usageElement, element.unwrapped, usageInfo.isSafeDelete()) + } else usageInfo } } @@ -105,7 +107,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() { fun findUsagesByJavaProcessor(elements: Iterator, insideDeleted: Condition): Condition = elements - .map { element -> findUsagesByJavaProcessor(element)?.getInsideDeletedCondition() } + .map { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() } .filterNotNull() .fold(insideDeleted) {(condition1, condition2) -> Conditions.or(condition1, condition2) } @@ -161,19 +163,19 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() { val searchInfo = when (element) { is JetClassOrObject -> - element.toLightClass()?.let { klass -> findUsagesByJavaProcessor(klass) } + element.toLightClass()?.let { klass -> findUsagesByJavaProcessor(klass, false) } is JetNamedFunction -> { if (element.isLocal()) { findKotlinDeclarationUsages(element) } else { - element.getRepresentativeLightMethod()?.let { method -> findUsagesByJavaProcessor(method) } + element.getRepresentativeLightMethod()?.let { method -> findUsagesByJavaProcessor(method, false) } } } is PsiMethod -> - findUsagesByJavaProcessor(element) + findUsagesByJavaProcessor(element, false) is JetProperty -> { if (element.isLocal()) {