Initial stub version of resolve for types
This commit is contained in:
@@ -22,7 +22,7 @@ public class ClassDescriptor extends MemberDescriptorImpl implements MemberDomai
|
||||
public ClassDescriptor(String name) {
|
||||
this(Collections.<Annotation>emptyList(),
|
||||
name, Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<Type>singleton(JetStandardTypes.getAny()));
|
||||
Collections.<Type>singleton(JetStandardClasses.getAnyType()));
|
||||
}
|
||||
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
|
||||
@@ -13,6 +13,8 @@ public class JetStandardClasses {
|
||||
Collections.<Type>emptySet()
|
||||
);
|
||||
|
||||
private static final ClassType ANY_TYPE = new ClassType(ANY);
|
||||
|
||||
private static final ClassDescriptor BYTE = new ClassDescriptor("Byte");
|
||||
private static final ClassDescriptor CHAR = new ClassDescriptor("Char");
|
||||
private static final ClassDescriptor SHORT = new ClassDescriptor("Short");
|
||||
@@ -27,6 +29,10 @@ public class JetStandardClasses {
|
||||
return ANY;
|
||||
}
|
||||
|
||||
public static ClassType getAnyType() {
|
||||
return ANY_TYPE;
|
||||
}
|
||||
|
||||
public static ClassDescriptor getByte() {
|
||||
return BYTE;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -64,7 +68,30 @@ public class JetTypeChecker {
|
||||
}
|
||||
|
||||
public boolean isSubtypeOf(Type subtype, Type supertype) {
|
||||
// subtype.getConstructor().getSupertypes()
|
||||
return false;
|
||||
@Nullable
|
||||
Type closestSupertype = findCorrespondingSupertype(subtype, supertype);
|
||||
if (closestSupertype == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return checkSubtypeForTheSameConstructor(closestSupertype, supertype);
|
||||
}
|
||||
|
||||
// This method returns the supertype of the first parameter that has the same constructor
|
||||
// as the second parameter, applying the substitution of type arguments to it
|
||||
@Nullable
|
||||
private Type findCorrespondingSupertype(Type subtype, Type supertype) {
|
||||
TypeConstructor constructor = subtype.getConstructor();
|
||||
if (constructor.equals(supertype.getConstructor())) {
|
||||
return subtype;
|
||||
}
|
||||
for (Type immediateSupertype : constructor.getSupertypes()) {
|
||||
Type correspondingSupertype = findCorrespondingSupertype(immediateSupertype, supertype);
|
||||
if (correspondingSupertype != null) {
|
||||
return correspondingSupertype;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,21 +23,22 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
if ("Int".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
} else if ("Boolean".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getBoolean();
|
||||
} else if ("Byte".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getByte();
|
||||
} else if ("Char".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getChar();
|
||||
} else if ("Short".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getShort();
|
||||
} else if ("Long".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getLong();
|
||||
} else if ("Float".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getFloat();
|
||||
} else if ("Double".equals(name)) {
|
||||
return JetStandardClasses.getInt();
|
||||
return JetStandardClasses.getDouble();
|
||||
}
|
||||
return null;
|
||||
fail("Type not found: " + name);
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -141,6 +142,11 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
public void visitUserType(JetUserType type) {
|
||||
result[0] = new ClassType(TypeResolver.INSTANCE.resolveClass(BASIC_SCOPE, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement elem) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
});
|
||||
|
||||
return result[0];
|
||||
|
||||
Reference in New Issue
Block a user