getAllOverriddenDescriptors() moved to DescriptorUtils

This commit is contained in:
Andrey Breslav
2014-10-11 01:49:11 +04:00
parent f7ccfafd1c
commit 4a132599fd
9 changed files with 55 additions and 58 deletions
@@ -298,30 +298,12 @@ public class OverrideResolver {
// As other code relies on no equal descriptors passed here, we guard against f == g, but this may not be necessary
if (!f.equals(g) && DescriptorEquivalenceForOverrides.INSTANCE$.areEquivalent(f.getOriginal(), g.getOriginal())) return true;
CallableDescriptor originalG = g.getOriginal();
for (D overriddenFunction : getAllOverriddenDescriptors(f)) {
for (D overriddenFunction : DescriptorUtils.getAllOverriddenDescriptors(f)) {
if (DescriptorEquivalenceForOverrides.INSTANCE$.areEquivalent(originalG, overriddenFunction.getOriginal())) return true;
}
return false;
}
@NotNull
@SuppressWarnings("unchecked")
public static <D extends CallableDescriptor> Set<D> getAllOverriddenDescriptors(@NotNull D f) {
Set<D> result = new LinkedHashSet<D>();
collectAllOverriddenDescriptors((D) f.getOriginal(), result);
return result;
}
private static <D extends CallableDescriptor> void collectAllOverriddenDescriptors(@NotNull D current, @NotNull Set<D> result) {
if (result.contains(current)) return;
for (CallableDescriptor callableDescriptor : current.getOriginal().getOverriddenDescriptors()) {
@SuppressWarnings("unchecked")
D descriptor = (D) callableDescriptor;
collectAllOverriddenDescriptors(descriptor, result);
result.add(descriptor);
}
}
private static <T extends DeclarationDescriptor> MultiMap<Name, T> groupDescriptorsByName(Collection<T> properties) {
MultiMap<Name, T> r = new LinkedMultiMap<Name, T>();
for (T property : properties) {
@@ -999,31 +981,10 @@ public class OverrideResolver {
return filterOutOverridden(result);
}
@NotNull
public static <D extends CallableMemberDescriptor> Set<D> getAllOverriddenDeclarations(@NotNull D memberDescriptor) {
Set<D> result = Sets.newHashSet();
for (CallableMemberDescriptor overriddenDeclaration : memberDescriptor.getOverriddenDescriptors()) {
CallableMemberDescriptor.Kind kind = overriddenDeclaration.getKind();
if (kind == DECLARATION) {
//noinspection unchecked
result.add((D) overriddenDeclaration);
}
else if (kind == DELEGATION || kind == FAKE_OVERRIDE || kind == SYNTHESIZED) {
//do nothing
}
else {
throw new AssertionError("Unexpected callable kind " + kind);
}
//noinspection unchecked
result.addAll(getAllOverriddenDeclarations((D) overriddenDeclaration));
}
return result;
}
@NotNull
@ReadOnly
public static <D extends CallableMemberDescriptor> Set<D> getDeepestSuperDeclarations(@NotNull D functionDescriptor) {
Set<D> overriddenDeclarations = getAllOverriddenDeclarations(functionDescriptor);
Set<D> overriddenDeclarations = DescriptorUtils.getAllOverriddenDeclarations(functionDescriptor);
if (overriddenDeclarations.isEmpty()) {
return Collections.singleton(functionDescriptor);
}