JVM: Rewrite companion object accessor generation

Old version handled only private companions correctly.
Some situations require multiple companion object accessors
(including accessors for protected companion objects from supertypes)
to be generated in the corresponding class.
This commit is contained in:
Dmitry Petrov
2020-01-11 00:56:04 +03:00
parent 04a6f4d92b
commit 6ad159bb01
23 changed files with 1009 additions and 101 deletions
@@ -17642,6 +17642,79 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/protectedCompanionObjectAccessedFromNestedClass.kt");
}
@TestMetadata("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class MultipleCompanionsWithAccessors extends AbstractBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@TestMetadata("accessFromInlineLambda.kt")
public void testAccessFromInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/accessFromInlineLambda.kt");
}
public void testAllFilesPresentInMultipleCompanionsWithAccessors() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("anonymousObjectInPropertyInitializer.kt")
public void testAnonymousObjectInPropertyInitializer() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/anonymousObjectInPropertyInitializer.kt");
}
@TestMetadata("fromAnonymousObjectInNestedClass.kt")
public void testFromAnonymousObjectInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/fromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("fromInitBlock.kt")
public void testFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/fromInitBlock.kt");
}
@TestMetadata("fromInitBlockOfNestedClass.kt")
public void testFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/fromInitBlockOfNestedClass.kt");
}
@TestMetadata("fromInlineLambdaInNestedClass.kt")
public void testFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/fromInlineLambdaInNestedClass.kt");
}
@TestMetadata("inheritedProtectedCompanionAndOwnPrivateCompanion.kt")
public void testInheritedProtectedCompanionAndOwnPrivateCompanion() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/inheritedProtectedCompanionAndOwnPrivateCompanion.kt");
}
@TestMetadata("inheritedProtectedCompanionsReferencedByName.kt")
public void testInheritedProtectedCompanionsReferencedByName() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/inheritedProtectedCompanionsReferencedByName.kt");
}
@TestMetadata("lambdaInPropertyInitializer.kt")
public void testLambdaInPropertyInitializer() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/lambdaInPropertyInitializer.kt");
}
@TestMetadata("twoInheritedProtectedCompanions.kt")
public void testTwoInheritedProtectedCompanions() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/twoInheritedProtectedCompanions.kt");
}
@TestMetadata("withCompanionObjectBase.kt")
public void testWithCompanionObjectBase() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/withCompanionObjectBase.kt");
}
@TestMetadata("withMultipleNestedCompanionObjectBases.kt")
public void testWithMultipleNestedCompanionObjectBases() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/multipleCompanionsWithAccessors/withMultipleNestedCompanionObjectBases.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/objects/companionObjectAccess/primitiveCompanion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)