Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

'isSubclass' method refactoring: not collecting all supertypes

  • Loading branch information...
commit 3bae350829ecf0f90823de32dc9fd564d0852ce2 1 parent 9d75256
@svtk svtk authored
View
22 compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java
@@ -18,7 +18,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -279,20 +278,21 @@ public static boolean isObject(@NotNull ClassifierDescriptor classifier) {
}
}
- public static boolean isSubclass(ClassDescriptor subClass, ClassDescriptor superClass) {
- Set<JetType> allSuperTypes = new THashSet<JetType>();
-
- addSuperTypes(subClass.getDefaultType(), allSuperTypes);
-
- final DeclarationDescriptor superOriginal = superClass.getOriginal();
+ public static boolean isSubclass(@NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) {
+ DeclarationDescriptor superOriginal = superClass.getOriginal();
@abreslav Owner
abreslav added a note

What's the point in this variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return hasEqualSuperType(subClass.getDefaultType(), superOriginal);
+ }
- for (JetType superType : allSuperTypes) {
- final DeclarationDescriptor descriptor = superType.getConstructor().getDeclarationDescriptor();
- if (descriptor != null && superOriginal.equals(descriptor.getOriginal())) {
+ private static boolean hasEqualSuperType(@NotNull JetType type, @NotNull DeclarationDescriptor superOriginal) {
@abreslav Owner
abreslav added a note

This name is misleading: it does not look for an equal supertype. It checks if the given descriptor is a superCLASS for the given type.

@svtk Collaborator
svtk added a note

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ DeclarationDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
+ if (descriptor != null && superOriginal.equals(descriptor.getOriginal())) {
@abreslav Owner
abreslav added a note

Did you mean anything special by saying equals() here? We use identity-equals for descriptors, AFAIR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return true;
+ }
+ for (JetType superType : type.getConstructor().getSupertypes()) {
+ if (hasEqualSuperType(superType, superOriginal)) {
return true;
}
}
-
return false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.