diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java index c95f1602af3..6a051f65848 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java @@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.*; import org.jetbrains.jet.lang.resolve.constants.StringValue; +import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import java.lang.annotation.RetentionPolicy; @@ -224,19 +225,20 @@ public abstract class AnnotationCodegen { } private static RetentionPolicy getRetentionPolicy(ClassifierDescriptor descriptor, JetTypeMapper typeMapper) { - RetentionPolicy rp = RetentionPolicy.RUNTIME; - /* - @todo : when JavaDescriptoResolver provides ennough info for (AnnotationDescriptor annotationDescriptor : descriptor.getAnnotations()) { String internalName = typeMapper.mapType(annotationDescriptor.getType()).getInternalName(); - if("java/lang/annotation/RetentionPolicy".equals(internalName)) { - CompileTimeConstant compileTimeConstant = annotationDescriptor.getValueArguments().get(0); - System.out.println(compileTimeConstant); - break; + if("java/lang/annotation/Retention".equals(internalName)) { + CompileTimeConstant compileTimeConstant = annotationDescriptor.getAllValueArguments().values().iterator().next(); + assert compileTimeConstant instanceof EnumValue : "Retention argument should be Enum value " + compileTimeConstant; + PropertyDescriptor propertyDescriptor = ((EnumValue) compileTimeConstant).getValue(); + assert "java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(propertyDescriptor.getType()).getInternalName()) : + "Retention argument should be of type RetentionPolicy"; + String propertyDescriptorName = propertyDescriptor.getName().asString(); + return RetentionPolicy.valueOf(propertyDescriptorName); } } - */ - return rp; //To change body of created methods use File | Settings | File Templates. + + return RetentionPolicy.CLASS; } abstract AnnotationVisitor visitAnnotation(String descr, boolean visible); diff --git a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt new file mode 100644 index 00000000000..aef672ab0de --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt @@ -0,0 +1,9 @@ +import java.lang.annotation.Retention +import java.lang.annotation.RetentionPolicy + +Ann class MyClass + +Retention(RetentionPolicy.CLASS) +annotation class Ann + +// 1 @LAnn;() \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt new file mode 100644 index 00000000000..649f4d30daf --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt @@ -0,0 +1,9 @@ +import java.lang.annotation.Retention +import java.lang.annotation.RetentionPolicy + +Ann class MyClass + +Retention(RetentionPolicy.RUNTIME) +annotation class Ann + +// 1 @LAnn;() \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt new file mode 100644 index 00000000000..a2248c7740b --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt @@ -0,0 +1,9 @@ +import java.lang.annotation.Retention +import java.lang.annotation.RetentionPolicy + +Ann class MyClass + +Retention(RetentionPolicy.SOURCE) +annotation class Ann + +// 0 @LAnn;() \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java index 945b9461252..8c177828cc9 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java @@ -37,6 +37,21 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/bytecodeText"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("annotationRetentionPolicyClass.kt") + public void testAnnotationRetentionPolicyClass() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt"); + } + + @TestMetadata("annotationRetentionPolicyRuntime.kt") + public void testAnnotationRetentionPolicyRuntime() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt"); + } + + @TestMetadata("annotationRetentionPolicySource.kt") + public void testAnnotationRetentionPolicySource() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt"); + } + @TestMetadata("componentEvaluatesOnlyOnce.kt") public void testComponentEvaluatesOnlyOnce() throws Exception { doTest("compiler/testData/codegen/bytecodeText/componentEvaluatesOnlyOnce.kt");