JVM_IR: remove constructors of nested annotations

This commit is contained in:
pyos
2019-12-19 14:43:09 +01:00
committed by max-kammerer
parent 17d2fda946
commit 59f2aa7add
8 changed files with 43 additions and 11 deletions
@@ -22,19 +22,13 @@ internal val annotationPhase = makeIrFilePhase<JvmBackendContext>(
description = "Remove constructors of annotation classes"
)
/**
* Remove the constructors from annotation classes.
*/
private class AnnotationLowering : FileLoweringPass, IrElementTransformerVoid() {
override fun lower(irFile: IrFile) = irFile.transformChildrenVoid(this)
override fun visitClass(declaration: IrClass): IrStatement {
if (!declaration.isAnnotationClass) return super.visitClass(declaration)
declaration.declarations.removeIf {
it is IrConstructor
override fun visitClass(declaration: IrClass): IrStatement =
declaration.transformPostfix {
if (isAnnotationClass) {
declarations.removeIf { it is IrConstructor }
}
}
return declaration
}
}
@@ -0,0 +1,8 @@
annotation class Foo {
annotation class Bar
}
@Foo.Bar
fun box(): String {
return "OK"
}
@@ -136,6 +136,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/annotations/kt10136.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassPropertyAsParameter.kt")
public void testNestedClassPropertyAsParameter() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt");
@@ -141,6 +141,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/annotations/kt10136.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassPropertyAsParameter.kt")
public void testNestedClassPropertyAsParameter() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt");
@@ -136,6 +136,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/annotations/kt10136.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassPropertyAsParameter.kt")
public void testNestedClassPropertyAsParameter() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt");
@@ -136,6 +136,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/annotations/kt10136.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassPropertyAsParameter.kt")
public void testNestedClassPropertyAsParameter() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt");
@@ -41,6 +41,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassesInAnnotations.kt")
public void testNestedClassesInAnnotations() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt");
@@ -41,6 +41,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
}
@TestMetadata("nestedClassesInAnnotations.kt")
public void testNestedClassesInAnnotations() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt");