From 3bae350829ecf0f90823de32dc9fd564d0852ce2 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 2 Apr 2012 13:15:38 +0400 Subject: [PATCH] 'isSubclass' method refactoring: not collecting all supertypes --- .../jet/lang/resolve/DescriptorUtils.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 0d87e0ac48a..1523fd2bb76 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve; 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 class DescriptorUtils { } } - public static boolean isSubclass(ClassDescriptor subClass, ClassDescriptor superClass) { - Set allSuperTypes = new THashSet(); + public static boolean isSubclass(@NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) { + DeclarationDescriptor superOriginal = superClass.getOriginal(); + return hasEqualSuperType(subClass.getDefaultType(), superOriginal); + } - addSuperTypes(subClass.getDefaultType(), allSuperTypes); - - final DeclarationDescriptor superOriginal = superClass.getOriginal(); - - 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) { + DeclarationDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); + if (descriptor != null && superOriginal.equals(descriptor.getOriginal())) { + return true; + } + for (JetType superType : type.getConstructor().getSupertypes()) { + if (hasEqualSuperType(superType, superOriginal)) { return true; } } - return false; }