'isSubClass' method moved to DescriptorUtils

This commit is contained in:
Svetlana Isakova
2012-03-29 19:57:10 +04:00
parent 2650e9f6b0
commit 7df4e6728b
3 changed files with 28 additions and 26 deletions
@@ -79,31 +79,6 @@ public class CodegenUtil {
return invokeDescriptor;
}
public static boolean isSubclass(ClassDescriptor subClass, ClassDescriptor superClass) {
Set<JetType> allSuperTypes = new THashSet<JetType>();
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<JetType> 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);
@@ -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<StackValue, StackValue> {
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);
@@ -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<JetType> allSuperTypes = new THashSet<JetType>();
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<JetType> set) {
set.add(type);
for (JetType jetType : type.getConstructor().getSupertypes()) {
addSuperTypes(jetType, set);
}
}
}