abstract methods

This commit is contained in:
Dmitry Jemerov
2011-05-30 15:26:34 +04:00
parent 867e2f4938
commit 5c9a807c57
4 changed files with 19 additions and 5 deletions
@@ -54,6 +54,10 @@ public class FunctionCodegen {
boolean isAbstract = kind == OwnerKind.INTERFACE || bodyExpression == null;
if (isAbstract) flags |= Opcodes.ACC_ABSTRACT;
if (isAbstract && (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DELEGATING_IMPLEMENTATION)) {
return;
}
DeclarationDescriptor contextDescriptor = owner instanceof JetClass
? bindingContext.getClassDescriptor((JetClass) owner)
: bindingContext.getNamespaceDescriptor((JetNamespace) owner);
@@ -87,7 +91,7 @@ public class FunctionCodegen {
iv.invokeinterface(dk.getOwnerClass(), jvmSignature.getName(), jvmSignature.getDescriptor());
iv.areturn(jvmSignature.getReturnType());
}
else {
else if (!isAbstract) {
bodyExpression.accept(codegen);
generateReturn(mv, bodyExpression, codegen, jvmSignature);
}
@@ -9,7 +9,6 @@ import java.util.List;
public class ClassGenTest extends CodegenTestCase {
public void testPSVMClass() throws Exception {
loadFile("classes/simpleClass.jet");
System.out.println(generateToText());
final Class aClass = loadClass("SimpleClass", generateClassesInFile());
final Method[] methods = aClass.getDeclaredMethods();
@@ -18,7 +17,6 @@ public class ClassGenTest extends CodegenTestCase {
public void testArrayListInheritance() throws Exception {
loadFile("classes/inheritingFromArrayList.jet");
System.out.println(generateToText());
final Class aClass = loadClass("Foo", generateClassesInFile());
checkInterface(aClass, List.class);
@@ -66,4 +64,15 @@ public class ClassGenTest extends CodegenTestCase {
public void testInitializerBlock() throws Exception {
blackBoxFile("classes/initializerBlock.jet");
}
public void testAbstractMethod() throws Exception {
loadText("class Foo { abstract fun x(): String; fun y(): Int = 0 }");
final Codegens codegens = generateClassesInFile();
final Class aClass = loadClass("Foo", codegens);
assertNotNull(aClass.getMethod("x"));
final Class implClass = loadClass("Foo$$Impl", codegens);
assertNull(findMethodByName(implClass, "x"));
assertNotNull(findMethodByName(implClass, "y"));
}
}
@@ -180,7 +180,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
@Nullable
protected static Method findMethodByName(Class aClass, String name) {
for (Method method : aClass.getMethods()) {
for (Method method : aClass.getDeclaredMethods()) {
if (method.getName().equals(name)) {
return method;
}
@@ -97,7 +97,8 @@ public class PropertyGenTest extends CodegenTestCase {
final Object instance = aClass.newInstance();
final Method getFoo = findMethodByName(aClass, "getFoo");
assertEquals(349, getFoo.invoke(instance));
assertNull(findMethodByName(aClass, "setFoo"));
final Method setFoo = findMethodByName(aClass, "setFoo");
assertTrue((setFoo.getModifiers() & Modifier.PRIVATE) != 0);
final Method setter = findMethodByName(aClass, "setter");
setter.invoke(instance);
assertEquals(610, getFoo.invoke(instance));