From c9b2cda07cae3b8880498847293b23fd7ce8742c Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Thu, 19 Dec 2013 14:11:11 +0400 Subject: [PATCH] Add tests for usage of java annotation with default arguments --- .../annotations/javaAnnotationDefault.java | 18 +++++++++++++++++ .../annotations/javaAnnotationDefault.kt | 20 +++++++++++++++++++ .../BlackBoxWithJavaCodegenTestGenerated.java | 5 +++++ 3 files changed, 43 insertions(+) create mode 100644 compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.java create mode 100644 compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.kt diff --git a/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.java b/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.java new file mode 100644 index 00000000000..0aff2bc869a --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.java @@ -0,0 +1,18 @@ +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@interface JavaAnn { + String value() default "default"; +} + +@Retention(RetentionPolicy.RUNTIME) +@interface JavaAnn2 { + int a() default 1; + byte b() default 1; + short c() default 1; + double d() default 1; + float e() default 1; + long j() default 1; + String f() default "default"; +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.kt b/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.kt new file mode 100644 index 00000000000..9afd86e5b38 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.kt @@ -0,0 +1,20 @@ +JavaAnn class MyClass +JavaAnn2 class MyClass2 + +fun box(): String { + val ann = javaClass().getAnnotation(javaClass()) + if (ann == null) return "fail: cannot find Ann on MyClass}" + if (ann.value() != "default") return "fail: annotation parameter i should be 'default', but was ${ann.value()}" + + val ann2 = javaClass().getAnnotation(javaClass()) + if (ann2 == null) return "fail: cannot find Ann on MyClass}" + if (ann2.a() != 1) return "fail for a: expected = 1, but was ${ann2.a()}" + if (ann2.b() != 1.toByte()) return "fail for b: expected = 1, but was ${ann2.b()}" + if (ann2.c() != 1.toShort()) return "fail for c: expected = 1, but was ${ann2.c()}" + if (ann2.d() != 1.0) return "fail for d: expected = 1, but was ${ann2.d()}" + if (ann2.e() != 1F) return "fail for e: expected = 1, but was ${ann2.e()}" + if (ann2.j() != 1L) return "fail for j: expected = 1, but was ${ann2.j()}" + if (ann2.f() != "default") return "fail for f: expected = default, but was ${ann2.f()}" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 9036a500041..b3a7f372212 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -48,6 +48,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava("compiler/testData/codegen/boxWithJava/annotations/javaAnnotationCall.kt"); } + @TestMetadata("javaAnnotationDefault.kt") + public void testJavaAnnotationDefault() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/annotations/javaAnnotationDefault.kt"); + } + @TestMetadata("javaNegativePropertyAsAnnotationParameter.kt") public void testJavaNegativePropertyAsAnnotationParameter() throws Exception { doTestWithJava("compiler/testData/codegen/boxWithJava/annotations/javaNegativePropertyAsAnnotationParameter.kt");