Refactoring: Extract methods

This commit is contained in:
Alexey Sedunov
2014-01-21 19:25:21 +04:00
parent 75f67d5336
commit 598a3214d2
@@ -74,19 +74,20 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
@NotNull @NotNull
protected static NonCodeUsageSearchInfo getSearchInfo( protected static NonCodeUsageSearchInfo getSearchInfo(
@NotNull PsiElement element, @NotNull final Collection<? extends PsiElement> ignoredElements @NotNull PsiElement element, @NotNull Collection<? extends PsiElement> ignoredElements
) { ) {
return new NonCodeUsageSearchInfo( return new NonCodeUsageSearchInfo(getCondition(ignoredElements), element);
new Condition<PsiElement>() { }
@Override
public boolean value(PsiElement usage) { private static Condition<PsiElement> getCondition(final Collection<? extends PsiElement> ignoredElements) {
if (usage instanceof JetFile) return false; return new Condition<PsiElement>() {
return isInside(usage, ignoredElements); @Override
} public boolean value(PsiElement usage) {
}, if (usage instanceof JetFile) return false;
element return isInside(usage, ignoredElements);
); }
};
} }
@NotNull @NotNull
@@ -121,17 +122,13 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
if (property.isLocal()) return searchInfo; if (property.isLocal()) return searchInfo;
Condition<PsiElement> insideDeleted = searchInfo.getInsideDeletedCondition(); Condition<PsiElement> insideDeleted = delegateToJavaProcessorAndCombineConditions(
for (PsiMethod method: LightClassUtil.getLightClassPropertyMethods(property)) { LightClassUtil.getLightClassPropertyMethods(property),
NonCodeUsageSearchInfo accessorSearchInfo = delegateToJavaProcessor(method, allElementsToDelete, result); searchInfo.getInsideDeletedCondition(),
if (accessorSearchInfo == null) continue; allElementsToDelete,
result
insideDeleted = Conditions.or(insideDeleted, accessorSearchInfo.getInsideDeletedCondition()); );
} return new NonCodeUsageSearchInfo(insideDeleted, element);
return insideDeleted != null
? new NonCodeUsageSearchInfo(insideDeleted, element)
: getSearchInfo(element, allElementsToDelete);
} }
if (element instanceof JetTypeParameter) { if (element instanceof JetTypeParameter) {
return findTypeParameterUsages((JetTypeParameter) element, allElementsToDelete, result); return findTypeParameterUsages((JetTypeParameter) element, allElementsToDelete, result);
@@ -150,6 +147,21 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
return getSearchInfo(element, allElementsToDelete); return getSearchInfo(element, allElementsToDelete);
} }
private Condition<PsiElement> delegateToJavaProcessorAndCombineConditions(
Iterable<? extends PsiElement> elements,
Condition<PsiElement> insideDeleted,
PsiElement[] allElementsToDelete,
List<UsageInfo> 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") @SuppressWarnings("MethodOverridesPrivateMethodOfSuperclass")
protected static boolean isInside(@NotNull PsiElement place, @NotNull PsiElement[] ancestors) { protected static boolean isInside(@NotNull PsiElement place, @NotNull PsiElement[] ancestors) {
return isInside(place, Arrays.asList(ancestors)); return isInside(place, Arrays.asList(ancestors));