Support secondary constructors in JVM backend

There is a lot of changes about closures calculating and generating.

1. As classes can have more than one constructor each of them should
have closure arguments.

2. Captured variables set is the same for all of them.

3. Within constructors bodies/delegating calls closure parameters
should be accessed through method arguments because fields may be
not initialized yet.
This commit is contained in:
Denis Zharkov
2015-02-24 19:47:16 +03:00
parent 6779e95767
commit e65382e6ec
35 changed files with 1290 additions and 39 deletions
@@ -143,6 +143,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/constructor/genericConstructor.kt");
doTestAgainstJava(fileName);
}
@TestMetadata("secondaryConstructor.kt")
public void testSecondaryConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/constructor/secondaryConstructor.kt");
doTestAgainstJava(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxAgainstJava/delegation")
@@ -70,6 +70,7 @@ import java.util.regex.Pattern;
BlackBoxCodegenTestGenerated.Regressions.class,
BlackBoxCodegenTestGenerated.SafeCall.class,
BlackBoxCodegenTestGenerated.SamConstructors.class,
BlackBoxCodegenTestGenerated.SecondaryConstructors.class,
BlackBoxCodegenTestGenerated.StaticFields.class,
BlackBoxCodegenTestGenerated.Strings.class,
BlackBoxCodegenTestGenerated.Super.class,
@@ -1715,6 +1716,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("subclosuresWithinInitializers.kt")
public void testSubclosuresWithinInitializers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/subclosuresWithinInitializers.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/codegen/box/closures/captureOuterProperty")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6270,6 +6277,111 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/secondaryConstructors")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SecondaryConstructors extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInSecondaryConstructors() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/secondaryConstructors"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("basicNoPrimaryManySinks.kt")
public void testBasicNoPrimaryManySinks() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/basicNoPrimaryManySinks.kt");
doTest(fileName);
}
@TestMetadata("basicNoPrimaryOneSink.kt")
public void testBasicNoPrimaryOneSink() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/basicNoPrimaryOneSink.kt");
doTest(fileName);
}
@TestMetadata("basicPrimary.kt")
public void testBasicPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/basicPrimary.kt");
doTest(fileName);
}
@TestMetadata("dataClasses.kt")
public void testDataClasses() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/dataClasses.kt");
doTest(fileName);
}
@TestMetadata("defaultArgs.kt")
public void testDefaultArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/defaultArgs.kt");
doTest(fileName);
}
@TestMetadata("enums.kt")
public void testEnums() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/enums.kt");
doTest(fileName);
}
@TestMetadata("generics.kt")
public void testGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/generics.kt");
doTest(fileName);
}
@TestMetadata("innerClasses.kt")
public void testInnerClasses() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/innerClasses.kt");
doTest(fileName);
}
@TestMetadata("innerClassesInheritance.kt")
public void testInnerClassesInheritance() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/innerClassesInheritance.kt");
doTest(fileName);
}
@TestMetadata("localClasses.kt")
public void testLocalClasses() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/localClasses.kt");
doTest(fileName);
}
@TestMetadata("superCallPrimary.kt")
public void testSuperCallPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/superCallPrimary.kt");
doTest(fileName);
}
@TestMetadata("superCallSecondary.kt")
public void testSuperCallSecondary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/superCallSecondary.kt");
doTest(fileName);
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/varargs.kt");
doTest(fileName);
}
@TestMetadata("withNonLocalReturn.kt")
public void testWithNonLocalReturn() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/withNonLocalReturn.kt");
doTest(fileName);
}
@TestMetadata("withReturn.kt")
public void testWithReturn() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/withReturn.kt");
doTest(fileName);
}
@TestMetadata("withReturnUnit.kt")
public void testWithReturnUnit() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/withReturnUnit.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/staticFields")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -36,6 +36,7 @@ import java.util.regex.Pattern;
BlackBoxWithJavaCodegenTestGenerated.PlatformStatic.class,
BlackBoxWithJavaCodegenTestGenerated.Properties.class,
BlackBoxWithJavaCodegenTestGenerated.Reflection.class,
BlackBoxWithJavaCodegenTestGenerated.SecondaryConstructors.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@@ -181,4 +182,40 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
}
@TestMetadata("compiler/testData/codegen/boxWithJava/secondaryConstructors")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({
})
@RunWith(JUnit3RunnerWithInners.class)
public static class SecondaryConstructors extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInSecondaryConstructors() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava/secondaryConstructors"), Pattern.compile("^([^\\.]+)$"), true);
}
@TestMetadata("withGenerics")
public void testWithGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/secondaryConstructors/withGenerics/");
doTestWithJava(fileName);
}
@TestMetadata("withPrimary")
public void testWithPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/secondaryConstructors/withPrimary/");
doTestWithJava(fileName);
}
@TestMetadata("withVarargs")
public void testWithVarargs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/secondaryConstructors/withVarargs/");
doTestWithJava(fileName);
}
@TestMetadata("withoutPrimary")
public void testWithoutPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/secondaryConstructors/withoutPrimary/");
doTestWithJava(fileName);
}
}
}