Remove OverrideResolver#filterOutOverriding, simplify the only usage

This commit is contained in:
Alexander Udalov
2016-07-20 19:19:41 +03:00
parent 5d04fa3c2f
commit 191f532675
3 changed files with 15 additions and 44 deletions
@@ -123,32 +123,16 @@ public class OverrideResolver {
}; };
} }
private enum Filtering { /**
RETAIN_OVERRIDING, * Given a set of descriptors, returns a set containing all the given descriptors except those which _are overridden_ by at least
RETAIN_OVERRIDDEN * one other descriptor from the original set.
} */
@NotNull @NotNull
@SuppressWarnings("unchecked")
public static <D extends CallableDescriptor> Set<D> filterOutOverridden(@NotNull Set<D> candidateSet) { public static <D extends CallableDescriptor> Set<D> filterOutOverridden(@NotNull Set<D> candidateSet) {
//noinspection unchecked return filterOverrides(candidateSet, Function.ID);
return filterOverrides(candidateSet, Function.ID, Filtering.RETAIN_OVERRIDING);
} }
@NotNull
public static <D> Set<D> filterOutOverriding(@NotNull Set<D> candidateSet) {
//noinspection unchecked
return filterOverrides(candidateSet, Function.ID, Filtering.RETAIN_OVERRIDDEN);
}
@NotNull
public static <D> Set<D> filterOutOverridden(
@NotNull Set<D> candidateSet,
@NotNull Function<? super D, ? extends CallableDescriptor> transform
) {
return filterOverrides(candidateSet, transform, Filtering.RETAIN_OVERRIDING);
}
// In a multi-module project different "copies" of the same class may be present in different libraries, // In a multi-module project different "copies" of the same class may be present in different libraries,
// that's why we use structural equivalence for members (DescriptorEquivalenceForOverrides). // that's why we use structural equivalence for members (DescriptorEquivalenceForOverrides).
// //
@@ -189,10 +173,9 @@ public class OverrideResolver {
} }
@NotNull @NotNull
private static <D> Set<D> filterOverrides( public static <D> Set<D> filterOverrides(
@NotNull Set<D> candidateSet, @NotNull Set<D> candidateSet,
@NotNull Function<? super D, ? extends CallableDescriptor> transform, @NotNull Function<? super D, ? extends CallableDescriptor> transform
@NotNull Filtering filtering
) { ) {
if (candidateSet.size() <= 1) return candidateSet; if (candidateSet.size() <= 1) return candidateSet;
@@ -207,19 +190,8 @@ public class OverrideResolver {
CallableDescriptor me = transform.fun(meD); CallableDescriptor me = transform.fun(meD);
for (D otherD : noDuplicates) { for (D otherD : noDuplicates) {
CallableDescriptor other = transform.fun(otherD); CallableDescriptor other = transform.fun(otherD);
if (me == other) continue; if (me != other && overrides(other, me)) {
if (filtering == Filtering.RETAIN_OVERRIDING) { continue outerLoop;
if (overrides(other, me)) {
continue outerLoop;
}
}
else if (filtering == Filtering.RETAIN_OVERRIDDEN) {
if (overrides(me, other)) {
continue outerLoop;
}
}
else {
throw new AssertionError("Unexpected Filtering object: " + filtering);
} }
} }
candidates.add(meD); candidates.add(meD);
@@ -751,9 +723,8 @@ public class OverrideResolver {
} }
/** /**
* @return overridden real descriptors (not fake overrides). Note that all usages of this method should be followed by calling * @return overridden real descriptors (not fake overrides). Note that most usages of this method should be followed by calling
* {@link #filterOutOverridden(Set)} or {@link #filterOutOverriding(Set)}, because some of the declarations * {@link #filterOutOverridden(Set)}, because some of the declarations can override the other.
* can override the other
* TODO: merge this method with filterOutOverridden * TODO: merge this method with filterOutOverridden
*/ */
@NotNull @NotNull
@@ -193,7 +193,7 @@ public class ResolutionResultsHandler {
candidates = overloadingConflictResolver.findMaximallySpecificVariableAsFunctionCalls(candidates); candidates = overloadingConflictResolver.findMaximallySpecificVariableAsFunctionCalls(candidates);
} }
Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOutOverridden(candidates, MAP_TO_RESULT); Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOverrides(candidates, MAP_TO_RESULT);
if (noOverrides.size() == 1) { if (noOverrides.size() == 1) {
return OverloadResolutionResultsImpl.success(noOverrides.iterator().next()); return OverloadResolutionResultsImpl.success(noOverrides.iterator().next());
} }
@@ -145,11 +145,11 @@ fun <D : CallableMemberDescriptor> D.getDirectlyOverriddenDeclarations(): Collec
return OverrideResolver.filterOutOverridden(result) return OverrideResolver.filterOutOverridden(result)
} }
fun <D : CallableMemberDescriptor> D.getDeepestSuperDeclarations(): Set<D> { fun <D : CallableMemberDescriptor> D.getDeepestSuperDeclarations(): Collection<D> {
val overriddenDeclarations = DescriptorUtils.getAllOverriddenDeclarations(this) val overriddenDeclarations = DescriptorUtils.getAllOverriddenDeclarations(this)
if (overriddenDeclarations.isEmpty()) { if (overriddenDeclarations.isEmpty()) {
return setOf(this) return setOf(this)
} }
return OverrideResolver.filterOutOverriding(overriddenDeclarations) return overriddenDeclarations.filterNot(DescriptorUtils::isOverride)
} }