Skip to content
Browse files

'isSubclass' method refactoring: not collecting all supertypes

  • Loading branch information...
1 parent 9d75256 commit 3bae350829ecf0f90823de32dc9fd564d0852ce2 @svtk svtk committed Apr 2, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java
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
JetBrains member
abreslav added a note Apr 9, 2012

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
JetBrains member
abreslav added a note Apr 9, 2012

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
JetBrains member
svtk added a note Apr 17, 2012

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
JetBrains member
abreslav added a note Apr 9, 2012

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;
}

0 comments on commit 3bae350

Please sign in to comment.
Something went wrong with that request. Please try again.