superclass stuff improvements

This commit is contained in:
Dmitry Jemerov
2011-05-30 16:26:12 +04:00
parent d0f284fd5f
commit 4fdfcdc541
3 changed files with 27 additions and 16 deletions
@@ -1,7 +1,5 @@
package org.jetbrains.jet.codegen;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -47,19 +45,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (delegationSpecifiers.isEmpty()) return "java/lang/Object";
JetDelegationSpecifier first = delegationSpecifiers.get(0);
if (first instanceof JetDelegatorToSuperClass) {
JetType superType = bindingContext.resolveTypeReference(first.getTypeReference());
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
PsiElement superPsi = bindingContext.getDeclarationPsiElement(superClassDescriptor);
if (superPsi instanceof PsiClass) {
PsiClass psiClass = (PsiClass) superPsi;
String fqn = psiClass.getQualifiedName();
if (!psiClass.isInterface()) {
return fqn.replace('.', '/');
}
}
}
else if (first instanceof JetDelegatorToSuperCall) {
if (first instanceof JetDelegatorToSuperClass || first instanceof JetDelegatorToSuperCall) {
JetType superType = bindingContext.resolveTypeReference(first.getTypeReference());
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
return typeMapper.jvmName(superClassDescriptor, kind);
@@ -104,7 +90,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
List<JetDelegationSpecifier> specifiers = myClass.getDelegationSpecifiers();
if (specifiers.isEmpty() || !(specifiers.get(0) instanceof JetDelegatorToSuperCall)) {
String superClass = getSuperClass();
// TODO correct calculation of super class
String superClass = "java/lang/Object";
if (!specifiers.isEmpty()) {
final JetType superType = bindingContext.resolveTypeReference(specifiers.get(0).getTypeReference());
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
if (superClassDescriptor.hasConstructors()) {
superClass = getSuperClass();
}
}
iv.load(0, Type.getType("L" + superClass + ";"));
iv.invokespecial(superClass, "<init>", /* TODO super constructor descriptor */"()V");
}
@@ -0,0 +1,13 @@
class Foo {
fun xyzzy(): String = "xyzzy"
}
class Bar(): Foo {
fun test(): String = xyzzy()
}
fun box() {
val bar = new Bar()
val f = bar.test()
return if (f == "xyzzy") "OK" else "fail"
}
@@ -75,4 +75,8 @@ public class ClassGenTest extends CodegenTestCase {
assertNull(findMethodByName(implClass, "x"));
assertNotNull(findMethodByName(implClass, "y"));
}
public void testInheritedMethod() throws Exception {
blackBoxFile("classes/inheritedMethod.jet");
}
}