getAllOverriddenDescriptors() moved to DescriptorUtils
This commit is contained in:
@@ -34,11 +34,9 @@ import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.*;
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
public class DescriptorUtils {
|
||||
@@ -410,4 +408,43 @@ public class DescriptorUtils {
|
||||
public static boolean classCanHaveOpenMembers(@NotNull ClassDescriptor classDescriptor) {
|
||||
return classDescriptor.getModality() != Modality.FINAL || classDescriptor.getKind() == ClassKind.ENUM_CLASS;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends CallableMemberDescriptor> Set<D> getAllOverriddenDeclarations(@NotNull D memberDescriptor) {
|
||||
Set<D> result = new HashSet<D>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user