handle getters/setters without body; generate initializers for class-level properties
This commit is contained in:
@@ -3,6 +3,7 @@ package org.jetbrains.jet.codegen;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.lang.JetFileType;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -97,16 +98,21 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected Method generateFunction(String name) {
|
||||
Class aClass = generateNamespaceClass();
|
||||
return findMethodByName(aClass, name);
|
||||
final Method method = findMethodByName(aClass, name);
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("couldn't find method " + name);
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static Method findMethodByName(Class aClass, String name) {
|
||||
for (Method method : aClass.getMethods()) {
|
||||
if (method.getName().equals(name)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("couldn't find method " + name);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void assertIsCurrentTime(long returnValue) {
|
||||
|
||||
@@ -73,4 +73,13 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
String value = (String) method.invoke(null, "IDEA");
|
||||
assertEquals(value, "IntelliJ IDEA");
|
||||
}
|
||||
|
||||
public void testAccessorsWithoutBody() throws Exception {
|
||||
loadText("class AccessorsWithoutBody { public var foo: Int = 349\n get\n private set } ");
|
||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "AccessorsWithoutBody");
|
||||
final Object instance = aClass.newInstance();
|
||||
final Method getFoo = findMethodByName(aClass, "getFoo");
|
||||
assertEquals(349, getFoo.invoke(instance));
|
||||
assertNull(findMethodByName(aClass, "setFoo"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user