From 598a3214d2158bfecb361263e62e2d8266c3e712 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 21 Jan 2014 19:25:21 +0400 Subject: [PATCH] Refactoring: Extract methods --- .../safeDelete/KotlinSafeDeleteProcessor.java | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java index db0e17abc3d..cbb42ed6b79 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java @@ -74,19 +74,20 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor { @NotNull protected static NonCodeUsageSearchInfo getSearchInfo( - @NotNull PsiElement element, @NotNull final Collection ignoredElements + @NotNull PsiElement element, @NotNull Collection ignoredElements ) { - return new NonCodeUsageSearchInfo( - new Condition() { - @Override - public boolean value(PsiElement usage) { - if (usage instanceof JetFile) return false; - return isInside(usage, ignoredElements); - } - }, - element - ); + return new NonCodeUsageSearchInfo(getCondition(ignoredElements), element); + } + + private static Condition getCondition(final Collection ignoredElements) { + return new Condition() { + @Override + public boolean value(PsiElement usage) { + if (usage instanceof JetFile) return false; + return isInside(usage, ignoredElements); + } + }; } @NotNull @@ -121,17 +122,13 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor { if (property.isLocal()) return searchInfo; - Condition insideDeleted = searchInfo.getInsideDeletedCondition(); - for (PsiMethod method: LightClassUtil.getLightClassPropertyMethods(property)) { - NonCodeUsageSearchInfo accessorSearchInfo = delegateToJavaProcessor(method, allElementsToDelete, result); - if (accessorSearchInfo == null) continue; - - insideDeleted = Conditions.or(insideDeleted, accessorSearchInfo.getInsideDeletedCondition()); - } - - return insideDeleted != null - ? new NonCodeUsageSearchInfo(insideDeleted, element) - : getSearchInfo(element, allElementsToDelete); + Condition insideDeleted = delegateToJavaProcessorAndCombineConditions( + LightClassUtil.getLightClassPropertyMethods(property), + searchInfo.getInsideDeletedCondition(), + allElementsToDelete, + result + ); + return new NonCodeUsageSearchInfo(insideDeleted, element); } if (element instanceof JetTypeParameter) { return findTypeParameterUsages((JetTypeParameter) element, allElementsToDelete, result); @@ -150,6 +147,21 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor { return getSearchInfo(element, allElementsToDelete); } + private Condition delegateToJavaProcessorAndCombineConditions( + Iterable elements, + Condition insideDeleted, + PsiElement[] allElementsToDelete, + List result + ) { + for (PsiElement element: elements) { + NonCodeUsageSearchInfo accessorSearchInfo = delegateToJavaProcessor(element, allElementsToDelete, result); + if (accessorSearchInfo == null) continue; + + insideDeleted = Conditions.or(insideDeleted, accessorSearchInfo.getInsideDeletedCondition()); + } + return insideDeleted; + } + @SuppressWarnings("MethodOverridesPrivateMethodOfSuperclass") protected static boolean isInside(@NotNull PsiElement place, @NotNull PsiElement[] ancestors) { return isInside(place, Arrays.asList(ancestors));