abstract methods
This commit is contained in:
@@ -54,6 +54,10 @@ public class FunctionCodegen {
|
|||||||
boolean isAbstract = kind == OwnerKind.INTERFACE || bodyExpression == null;
|
boolean isAbstract = kind == OwnerKind.INTERFACE || bodyExpression == null;
|
||||||
if (isAbstract) flags |= Opcodes.ACC_ABSTRACT;
|
if (isAbstract) flags |= Opcodes.ACC_ABSTRACT;
|
||||||
|
|
||||||
|
if (isAbstract && (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DELEGATING_IMPLEMENTATION)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DeclarationDescriptor contextDescriptor = owner instanceof JetClass
|
DeclarationDescriptor contextDescriptor = owner instanceof JetClass
|
||||||
? bindingContext.getClassDescriptor((JetClass) owner)
|
? bindingContext.getClassDescriptor((JetClass) owner)
|
||||||
: bindingContext.getNamespaceDescriptor((JetNamespace) owner);
|
: bindingContext.getNamespaceDescriptor((JetNamespace) owner);
|
||||||
@@ -87,7 +91,7 @@ public class FunctionCodegen {
|
|||||||
iv.invokeinterface(dk.getOwnerClass(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
iv.invokeinterface(dk.getOwnerClass(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||||
iv.areturn(jvmSignature.getReturnType());
|
iv.areturn(jvmSignature.getReturnType());
|
||||||
}
|
}
|
||||||
else {
|
else if (!isAbstract) {
|
||||||
bodyExpression.accept(codegen);
|
bodyExpression.accept(codegen);
|
||||||
generateReturn(mv, bodyExpression, codegen, jvmSignature);
|
generateReturn(mv, bodyExpression, codegen, jvmSignature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.util.List;
|
|||||||
public class ClassGenTest extends CodegenTestCase {
|
public class ClassGenTest extends CodegenTestCase {
|
||||||
public void testPSVMClass() throws Exception {
|
public void testPSVMClass() throws Exception {
|
||||||
loadFile("classes/simpleClass.jet");
|
loadFile("classes/simpleClass.jet");
|
||||||
System.out.println(generateToText());
|
|
||||||
|
|
||||||
final Class aClass = loadClass("SimpleClass", generateClassesInFile());
|
final Class aClass = loadClass("SimpleClass", generateClassesInFile());
|
||||||
final Method[] methods = aClass.getDeclaredMethods();
|
final Method[] methods = aClass.getDeclaredMethods();
|
||||||
@@ -18,7 +17,6 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testArrayListInheritance() throws Exception {
|
public void testArrayListInheritance() throws Exception {
|
||||||
loadFile("classes/inheritingFromArrayList.jet");
|
loadFile("classes/inheritingFromArrayList.jet");
|
||||||
System.out.println(generateToText());
|
|
||||||
|
|
||||||
final Class aClass = loadClass("Foo", generateClassesInFile());
|
final Class aClass = loadClass("Foo", generateClassesInFile());
|
||||||
checkInterface(aClass, List.class);
|
checkInterface(aClass, List.class);
|
||||||
@@ -66,4 +64,15 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
public void testInitializerBlock() throws Exception {
|
public void testInitializerBlock() throws Exception {
|
||||||
blackBoxFile("classes/initializerBlock.jet");
|
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
|
@Nullable
|
||||||
protected static Method findMethodByName(Class aClass, String name) {
|
protected static Method findMethodByName(Class aClass, String name) {
|
||||||
for (Method method : aClass.getMethods()) {
|
for (Method method : aClass.getDeclaredMethods()) {
|
||||||
if (method.getName().equals(name)) {
|
if (method.getName().equals(name)) {
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
final Object instance = aClass.newInstance();
|
final Object instance = aClass.newInstance();
|
||||||
final Method getFoo = findMethodByName(aClass, "getFoo");
|
final Method getFoo = findMethodByName(aClass, "getFoo");
|
||||||
assertEquals(349, getFoo.invoke(instance));
|
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");
|
final Method setter = findMethodByName(aClass, "setter");
|
||||||
setter.invoke(instance);
|
setter.invoke(instance);
|
||||||
assertEquals(610, getFoo.invoke(instance));
|
assertEquals(610, getFoo.invoke(instance));
|
||||||
|
|||||||
Reference in New Issue
Block a user