From 7df4e6728bbc1b4721b8e68648169b6aefb9f3c8 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 29 Mar 2012 19:57:10 +0400 Subject: [PATCH] 'isSubClass' method moved to DescriptorUtils --- .../jetbrains/jet/codegen/CodegenUtil.java | 25 ------------------ .../jet/codegen/ExpressionCodegen.java | 3 ++- .../jet/lang/resolve/DescriptorUtils.java | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 5e74a9ce847..a9ae66f4cca 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -79,31 +79,6 @@ public class CodegenUtil { return invokeDescriptor; } - public static boolean isSubclass(ClassDescriptor subClass, ClassDescriptor superClass) { - Set allSuperTypes = new THashSet(); - - 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())) { - return true; - } - } - - return false; - } - - public static void addSuperTypes(JetType type, Set set) { - set.add(type); - - for (JetType jetType : type.getConstructor().getSupertypes()) { - addSuperTypes(jetType, set); - } - } - public static boolean isNonLiteralObject(JetClassOrObject myClass) { return myClass instanceof JetObjectDeclaration && !((JetObjectDeclaration) myClass).isObjectLiteral() && !(myClass.getParent() instanceof JetClassObject); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 24ff2bc7c61..f1e91b262c7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.calls.*; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; @@ -1441,7 +1442,7 @@ public class ExpressionCodegen extends JetVisitor { if(cur instanceof CodegenContext.MethodContext && !(cur instanceof CodegenContext.ConstructorContext)) cur = cur.getParentContext(); - if (CodegenUtil.isSubclass(cur.getThisDescriptor(), calleeContainingClass)) { + if (DescriptorUtils.isSubclass(cur.getThisDescriptor(), calleeContainingClass)) { Type type = asmType(calleeContainingClass.getDefaultType()); if(!isObject || (cur.getThisDescriptor() == calleeContainingClass)) { result.put(TYPE_OBJECT, v); 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 f9b61b8d9e1..0d87e0ac48a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -18,6 +18,7 @@ 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.*; @@ -277,4 +278,29 @@ public class DescriptorUtils { throw new IllegalStateException("unknown classifier: " + classifier); } } + + public static boolean isSubclass(ClassDescriptor subClass, ClassDescriptor superClass) { + Set allSuperTypes = new THashSet(); + + 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())) { + return true; + } + } + + return false; + } + + public static void addSuperTypes(JetType type, Set set) { + set.add(type); + + for (JetType jetType : type.getConstructor().getSupertypes()) { + addSuperTypes(jetType, set); + } + } }