Generate synthetic methods for annotated properties in TImpl classes

Traits themselves can't have these methods, since it'd be a weird public method
in an interface

 #KT-4072 Fixed
This commit is contained in:
Alexander Udalov
2013-10-15 22:25:24 +04:00
parent 5539a29439
commit 08bc67b925
5 changed files with 83 additions and 25 deletions
@@ -45,7 +45,7 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
public void testInClass() {
loadFile();
assertClassHasAnnotatedSyntheticMethod(generateClass("A"));
assertAnnotatedSyntheticMethodExistence(true, generateClass("A"));
}
public void testTopLevel() {
@@ -55,14 +55,24 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
if (fileName.startsWith(packageClassName) && !fileName.equals(packageClassName + ".class")) {
// This should be package$src class
Class<?> a = generateClass(fileName.substring(0, fileName.length() - ".class".length()));
assertClassHasAnnotatedSyntheticMethod(a);
assertAnnotatedSyntheticMethodExistence(true, a);
}
}
}
private static void assertClassHasAnnotatedSyntheticMethod(@NotNull Class<?> a) {
for (Method method : a.getDeclaredMethods()) {
public void testInTrait() throws ClassNotFoundException {
loadFile();
GeneratedClassLoader loader = generateAndCreateClassLoader();
assertAnnotatedSyntheticMethodExistence(false, loader.loadClass("T"));
assertAnnotatedSyntheticMethodExistence(true, loader.loadClass("T" + JvmAbi.TRAIT_IMPL_SUFFIX));
}
private static void assertAnnotatedSyntheticMethodExistence(boolean expected, @NotNull Class<?> clazz) {
for (Method method : clazz.getDeclaredMethods()) {
if (TEST_SYNTHETIC_METHOD_NAME.equals(method.getName())) {
if (!expected) {
fail("Synthetic method for annotated property found, but not expected: " + method);
}
assertTrue(method.isSynthetic());
int modifiers = method.getModifiers();
assertTrue(Modifier.isFinal(modifiers));
@@ -75,6 +85,8 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
return;
}
}
fail("Synthetic method for annotated property not found: " + TEST_SYNTHETIC_METHOD_NAME);
if (expected) {
fail("Synthetic method for annotated property expected, but not found: " + TEST_SYNTHETIC_METHOD_NAME);
}
}
}