Add filterOutOverriding to OverridingUtil
This commit is contained in:
committed by
Pavel V. Talanov
parent
82feef23c3
commit
97532f68c6
@@ -46,15 +46,34 @@ public class OverridingUtil {
|
|||||||
private OverridingUtil() {
|
private OverridingUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static enum Filtering {
|
||||||
|
RETAIN_OVERRIDING,
|
||||||
|
RETAIN_OVERRIDDEN
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <D extends CallableDescriptor> Set<D> filterOutOverridden(@NotNull Set<D> candidateSet) {
|
public static <D extends CallableDescriptor> Set<D> filterOutOverridden(@NotNull Set<D> candidateSet) {
|
||||||
return filterOutOverridden(candidateSet, Function.ID);
|
return filterOverrides(candidateSet, Function.ID, Filtering.RETAIN_OVERRIDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <D> Set<D> filterOutOverriding(@NotNull Set<D> candidateSet) {
|
||||||
|
return filterOverrides(candidateSet, Function.ID, Filtering.RETAIN_OVERRIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <D> Set<D> filterOutOverridden(
|
public static <D> Set<D> filterOutOverridden(
|
||||||
@NotNull Set<D> candidateSet,
|
@NotNull Set<D> candidateSet,
|
||||||
@NotNull Function<? super D, ? extends CallableDescriptor> transform
|
@NotNull Function<? super D, ? extends CallableDescriptor> transform
|
||||||
|
) {
|
||||||
|
return filterOverrides(candidateSet, transform, Filtering.RETAIN_OVERRIDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static <D> Set<D> filterOverrides(
|
||||||
|
@NotNull Set<D> candidateSet,
|
||||||
|
@NotNull Function<? super D, ? extends CallableDescriptor> transform,
|
||||||
|
@NotNull Filtering filtering
|
||||||
) {
|
) {
|
||||||
Set<D> candidates = Sets.newLinkedHashSet();
|
Set<D> candidates = Sets.newLinkedHashSet();
|
||||||
outerLoop:
|
outerLoop:
|
||||||
@@ -63,8 +82,18 @@ public class OverridingUtil {
|
|||||||
for (D otherD : candidateSet) {
|
for (D otherD : candidateSet) {
|
||||||
CallableDescriptor other = transform.fun(otherD);
|
CallableDescriptor other = transform.fun(otherD);
|
||||||
if (me == other) continue;
|
if (me == other) continue;
|
||||||
if (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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (D otherD : candidates) {
|
for (D otherD : candidates) {
|
||||||
|
|||||||
Reference in New Issue
Block a user