From 609d69620239517dacb0197d2192b5a653bd8a06 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 3 Jul 2015 12:11:08 +0300 Subject: [PATCH] Annotations have now retention of "RUNTIME" by default. Java retention is generated as given by kotlin annotation. Annotation rendering changed. Annotation arguments with default values are rendered as ... if renderDefaultAnnotationArguments is true. Tests: java retention does not taken into account by Descriptor comparator. Java retentinon changed to kotlin retention in some tests + one new test with java retention added. More accurate tests for intentions in byte code (visibility controlled). --- .../kotlin/codegen/AnnotationCodegen.java | 46 ++++++++++++++++++- ...vaNegativePropertyAsAnnotationParameter.kt | 6 +-- .../javaPropertyAsAnnotationParameter.kt | 6 +-- .../javaPropertyWithIntInitializer.kt | 6 +-- .../annotatedSamFunExpression.kt | 4 +- .../annotationsWithKClass/array/array.kt | 4 +- .../annotationsWithKClass/basic/basic.kt | 4 +- .../annotationsWithKClass/vararg/vararg.kt | 4 +- .../annotations/simpleClassObject.kt | 5 +- .../annotations/annotatedEnumEntry.kt | 8 +--- .../annotatedLambda/funExpression.kt | 4 +- .../annotations/annotationsOnDefault.kt | 4 +- .../annotations/defaultParameterValues.kt | 5 +- .../annotations/delegatedPropertySetter.kt | 5 +- ...otlinPropertyFromClassObjectAsParameter.kt | 6 +-- .../kotlinTopLevelPropertyAsParameter.kt | 6 +-- .../nestedClassPropertyAsParameter.kt | 6 +-- .../annotations/parameterWithPrimitiveType.kt | 6 +-- ...rtyWithPropertyInInitializerAsParameter.kt | 6 +-- .../varargInAnnotationParameter.kt | 6 +-- .../codegen/boxWithStdlib/evaluate/char.kt | 6 +-- .../codegen/boxWithStdlib/evaluate/divide.kt | 6 +-- .../boxWithStdlib/evaluate/infixCallBinary.kt | 6 +-- .../boxWithStdlib/evaluate/intrincics.kt | 6 +-- .../boxWithStdlib/evaluate/maxValue.kt | 6 +-- .../boxWithStdlib/evaluate/maxValueByte.kt | 6 +-- .../boxWithStdlib/evaluate/maxValueInt.kt | 6 +-- .../boxWithStdlib/evaluate/miltiply.kt | 6 +-- .../codegen/boxWithStdlib/evaluate/minus.kt | 6 +-- .../codegen/boxWithStdlib/evaluate/mod.kt | 6 +-- .../boxWithStdlib/evaluate/paranthesized.kt | 6 +-- .../codegen/boxWithStdlib/evaluate/plus.kt | 6 +-- .../evaluate/simpleCallBinary.kt | 6 +-- .../boxWithStdlib/evaluate/unaryMinus.kt | 6 +-- .../boxWithStdlib/evaluate/unaryPlus.kt | 6 +-- .../reflection/kClassInAnnotation/array.kt | 4 +- .../reflection/kClassInAnnotation/basic.kt | 4 +- .../reflection/kClassInAnnotation/vararg.kt | 4 +- .../boxWithStdlib/regressions/kt1932.kt | 4 +- .../annotationJavaRetentionPolicyRuntime.kt | 9 ++++ .../annotationRetentionPolicyClass.kt | 10 ++-- .../annotationRetentionPolicyRuntime.kt | 9 ++-- .../annotationRetentionPolicySource.kt | 6 +-- .../properties/syntheticMethod/inClass.kt | 4 +- .../properties/syntheticMethod/inTrait.kt | 4 +- .../properties/syntheticMethod/topLevel.kt | 4 +- .../AnnotationInTrait.A.kt | 5 +- .../InlinedConstants.A.kt | 6 +-- .../KotlinPropertyAsAnnotationParameter.B.kt | 5 +- .../JavaAnnotationConstructors.txt | 4 +- .../annotations/TargetedAnnotation.kt | 6 +++ .../annotations/TargetedAnnotation.txt | 5 ++ .../annotations/classes/DataClass.kt | 3 ++ .../annotations/classes/DataClass.txt | 9 ++++ .../annotations/classes/Retention.kt | 4 +- .../annotations/classes/Retention.txt | 2 +- .../codegen/BytecodeTextTestGenerated.java | 6 +++ .../AbstractCompileJavaAgainstKotlinTest.java | 3 ++ .../jvm/compiler/LoadJavaTestGenerated.java | 12 +++++ .../AbstractJvmRuntimeDescriptorLoaderTest.kt | 21 +++------ ...mRuntimeDescriptorLoaderTestGenerated.java | 12 +++++ .../util/RecursiveDescriptorComparator.java | 14 ++++-- .../kotlin/renderer/DescriptorRenderer.kt | 1 + .../kotlin/renderer/DescriptorRendererImpl.kt | 13 +++++- .../renderer/DescriptorRendererOptionsImpl.kt | 1 + .../stubs/ResolveByStubTestGenerated.java | 12 +++++ libraries/stdlib/test/AnnotationsTest.kt | 5 +- .../annotationInSameFile/annotations.txt | 8 ++-- 68 files changed, 214 insertions(+), 242 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/annotationJavaRetentionPolicyRuntime.kt create mode 100644 compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt create mode 100644 compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.txt create mode 100644 compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt create mode 100644 compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java index e8a775f7884..a5c3f95a6e3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java @@ -119,6 +119,12 @@ public abstract class AnnotationCodegen { generateNullabilityAnnotation(descriptor.getReturnType(), annotationDescriptorsAlreadyPresent); } } + if (annotated instanceof ClassDescriptor) { + ClassDescriptor classDescriptor = (ClassDescriptor) annotated; + if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) { + generateRetentionAnnotation(classDescriptor, annotationDescriptorsAlreadyPresent); + } + } } private static boolean isInvisibleFromTheOutside(@Nullable DeclarationDescriptor descriptor) { @@ -160,6 +166,15 @@ public abstract class AnnotationCodegen { generateAnnotationIfNotPresent(annotationDescriptorsAlreadyPresent, annotationClass); } + private void generateRetentionAnnotation(@NotNull ClassDescriptor classDescriptor, @NotNull Set annotationDescriptorsAlreadyPresent) { + RetentionPolicy policy = getRetentionPolicy(classDescriptor); + String descriptor = Type.getType(Retention.class).getDescriptor(); + if (!annotationDescriptorsAlreadyPresent.add(descriptor)) return; + AnnotationVisitor visitor = visitAnnotation(descriptor, true); + visitor.visitEnum("value", Type.getType(RetentionPolicy.class).getDescriptor(), policy.name()); + visitor.visitEnd(); + } + private void generateAnnotationIfNotPresent(Set annotationDescriptorsAlreadyPresent, Class annotationClass) { String descriptor = Type.getType(annotationClass).getDescriptor(); if (!annotationDescriptorsAlreadyPresent.contains(descriptor)) { @@ -318,8 +333,37 @@ public abstract class AnnotationCodegen { value.accept(argumentVisitor, null); } + private enum KotlinRetention { + SOURCE(RetentionPolicy.SOURCE), + BINARY(RetentionPolicy.CLASS), + RUNTIME(RetentionPolicy.RUNTIME); + + final RetentionPolicy mapped; + + KotlinRetention(RetentionPolicy mapped) { + this.mapped = mapped; + } + } + @NotNull private RetentionPolicy getRetentionPolicy(@NotNull Annotated descriptor) { + AnnotationDescriptor kotlinAnnotation = descriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.annotation); + if (kotlinAnnotation != null) { + for (Map.Entry> argument: kotlinAnnotation.getAllValueArguments().entrySet()) { + if ("retention".equals(argument.getKey().getName().asString()) && argument.getValue() instanceof EnumValue) { + ClassDescriptor enumEntry = ((EnumValue) argument.getValue()).getValue(); + JetType classObjectType = getClassObjectType(enumEntry); + if (classObjectType != null) { + if ("kotlin/annotation/AnnotationRetention".equals(typeMapper.mapType(classObjectType).getInternalName())) { + String entryName = enumEntry.getName().asString(); + for (KotlinRetention retention: KotlinRetention.values()) { + if (retention.name().equals(entryName)) return retention.mapped; + } + } + } + } + } + } AnnotationDescriptor retentionAnnotation = descriptor.getAnnotations().findAnnotation(new FqName(Retention.class.getName())); if (retentionAnnotation != null) { Collection> valueArguments = retentionAnnotation.getAllValueArguments().values(); @@ -337,7 +381,7 @@ public abstract class AnnotationCodegen { } } - return RetentionPolicy.CLASS; + return RetentionPolicy.RUNTIME; } @NotNull diff --git a/compiler/testData/codegen/boxAgainstJava/annotations/javaNegativePropertyAsAnnotationParameter.kt b/compiler/testData/codegen/boxAgainstJava/annotations/javaNegativePropertyAsAnnotationParameter.kt index b3cf2d96acf..0146526a3a7 100644 --- a/compiler/testData/codegen/boxAgainstJava/annotations/javaNegativePropertyAsAnnotationParameter.kt +++ b/compiler/testData/codegen/boxAgainstJava/annotations/javaNegativePropertyAsAnnotationParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b) class MyClass fun box(): String { @@ -15,8 +12,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyAsAnnotationParameter.kt b/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyAsAnnotationParameter.kt index 60170c36cba..aa6d75c3acb 100644 --- a/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyAsAnnotationParameter.kt +++ b/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyAsAnnotationParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b, Foo.bool, Foo.c, Foo.str) class MyClass fun box(): String { @@ -18,8 +15,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyWithIntInitializer.kt b/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyWithIntInitializer.kt index 67875adf7f6..4e621be9447 100644 --- a/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyWithIntInitializer.kt +++ b/compiler/testData/codegen/boxAgainstJava/annotations/javaPropertyWithIntInitializer.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b, Foo.c) class MyClass fun box(): String { @@ -16,8 +13,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt b/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt index 798e6a86839..582e297caa7 100644 --- a/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt +++ b/compiler/testData/codegen/boxWithJava/annotatedSamFunExpression/annotatedSamFunExpression.kt @@ -1,10 +1,8 @@ -import java.lang.annotation.* import java.lang.reflect.Method import kotlin.reflect.jvm.java import kotlin.test.assertEquals -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val x: String) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String) fun testMethod(method: Method, name: String) { assertEquals("OK", method.getAnnotation(javaClass()).x, "On method of test named `$name`") diff --git a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/array/array.kt b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/array/array.kt index 0f8718e1bc0..f4f88aa7c14 100644 --- a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/array/array.kt +++ b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/array/array.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val args: Array>) fun box(): String { diff --git a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/basic/basic.kt b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/basic/basic.kt index b0c937dff79..c346d5ec59c 100644 --- a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/basic/basic.kt +++ b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/basic/basic.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val arg: KClass<*>) fun box(): String { diff --git a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/vararg/vararg.kt b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/vararg/vararg.kt index d22a733d399..cf39dfd67ca 100644 --- a/compiler/testData/codegen/boxWithJava/annotationsWithKClass/vararg/vararg.kt +++ b/compiler/testData/codegen/boxWithJava/annotationsWithKClass/vararg/vararg.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(vararg val args: KClass<*>) fun box(): String { diff --git a/compiler/testData/codegen/boxWithJava/platformStatic/annotations/simpleClassObject.kt b/compiler/testData/codegen/boxWithJava/platformStatic/annotations/simpleClassObject.kt index a57849fb795..296cd8224cb 100644 --- a/compiler/testData/codegen/boxWithJava/platformStatic/annotations/simpleClassObject.kt +++ b/compiler/testData/codegen/boxWithJava/platformStatic/annotations/simpleClassObject.kt @@ -1,9 +1,6 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy import kotlin.platform.platformStatic -Retention(RetentionPolicy.RUNTIME) -annotation class testAnnotation +annotation(retention = AnnotationRetention.RUNTIME) class testAnnotation class A { diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedEnumEntry.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedEnumEntry.kt index 95143c59e78..ead0b2e2156 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedEnumEntry.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedEnumEntry.kt @@ -1,12 +1,8 @@ // KT-5665 -import java.lang.annotation.* +annotation(retention = AnnotationRetention.RUNTIME) class First -Retention(RetentionPolicy.RUNTIME) -annotation class First - -Retention(RetentionPolicy.RUNTIME) -annotation class Second(val value: String) +annotation(retention = AnnotationRetention.RUNTIME) class Second(val value: String) enum class E { @First diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt index e1a35abe22b..3bcc483afe4 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/funExpression.kt @@ -1,10 +1,8 @@ -import java.lang.annotation.* import java.lang.reflect.Method import kotlin.reflect.jvm.java import kotlin.test.assertEquals -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val x: String) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String) fun foo0(block: () -> Unit) = block.javaClass fun foo1(block: (String) -> Unit) = block.javaClass diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotationsOnDefault.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotationsOnDefault.kt index 3ae2dd93f86..6179a2439ea 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotationsOnDefault.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotationsOnDefault.kt @@ -1,8 +1,6 @@ -import java.lang.annotation.* import kotlin.test.assertEquals -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val x: Int) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: Int) class A { Ann(1) fun foo(x: Int, y: Int = 2, z: Int) {} diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt b/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt index 304e1fcce29..d99408f2f40 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/defaultParameterValues.kt @@ -1,10 +1,7 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy import kotlin.reflect.KClass import kotlin.reflect.jvm.java -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int = 1, val s: String = "a", val a: Ann2 = Ann2(), diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/delegatedPropertySetter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/delegatedPropertySetter.kt index 24e7376a8a3..34356bf7a12 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/delegatedPropertySetter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/delegatedPropertySetter.kt @@ -1,7 +1,4 @@ -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) -annotation class First +annotation(retention = AnnotationRetention.RUNTIME) class First class MyClass() { public var x: String by Delegate() diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/kotlinPropertyFromClassObjectAsParameter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/kotlinPropertyFromClassObjectAsParameter.kt index ec16c008089..835385e0b5e 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/kotlinPropertyFromClassObjectAsParameter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/kotlinPropertyFromClassObjectAsParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b, Foo.bool, Foo.c, Foo.str) class MyClass fun box(): String { @@ -18,8 +15,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/kotlinTopLevelPropertyAsParameter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/kotlinTopLevelPropertyAsParameter.kt index 8356c404d74..eaaafbf3f6e 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/kotlinTopLevelPropertyAsParameter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/kotlinTopLevelPropertyAsParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(i, s, f, d, l, b, bool, c, str) class MyClass fun box(): String { @@ -18,8 +15,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/nestedClassPropertyAsParameter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/nestedClassPropertyAsParameter.kt index 48a935e5c2f..d7dd3805275 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/nestedClassPropertyAsParameter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/nestedClassPropertyAsParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(A.B.i) class MyClass fun box(): String { @@ -10,8 +7,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val i: Int) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val i: Int) class A { class B { diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/parameterWithPrimitiveType.kt b/compiler/testData/codegen/boxWithStdlib/annotations/parameterWithPrimitiveType.kt index 3b7914376da..6469958ea93 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/parameterWithPrimitiveType.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/parameterWithPrimitiveType.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val b: Byte, val s: Short, val i: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/propertyWithPropertyInInitializerAsParameter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/propertyWithPropertyInInitializerAsParameter.kt index 97afafad53c..268155c7a59 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/propertyWithPropertyInInitializerAsParameter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/propertyWithPropertyInInitializerAsParameter.kt @@ -1,6 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann(i) class MyClass fun box(): String { @@ -10,8 +7,7 @@ fun box(): String { return "OK" } -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val i: Int) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val i: Int) val i2: Int = 1 val i: Int = i2 diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/varargInAnnotationParameter.kt b/compiler/testData/codegen/boxWithStdlib/annotations/varargInAnnotationParameter.kt index bcb6d456c13..ed2fe14f038 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/varargInAnnotationParameter.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/varargInAnnotationParameter.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(vararg val p: Int) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(vararg val p: Int) Ann() class MyClass1 Ann(1) class MyClass2 diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/char.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/char.kt index 22674ee4f60..6fe0644ffe4 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/char.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/char.kt @@ -1,10 +1,6 @@ package test -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val c1: Int) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val c1: Int) Ann('a' - 'a') class MyClass diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/divide.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/divide.kt index ca891eb6eac..1273569707b 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/divide.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/divide.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val b: Byte, val s: Short, val i: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/infixCallBinary.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/infixCallBinary.kt index 3ecdbb17b1f..52666d81d24 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/infixCallBinary.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/infixCallBinary.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Int, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/intrincics.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/intrincics.kt index f63fdef4400..07cbc06acb8 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/intrincics.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/intrincics.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Short, val p3: Byte, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValue.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValue.kt index 1cb3dcb089c..7ec02fad346 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValue.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValue.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Int, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueByte.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueByte.kt index c927a96f218..11e6517a39e 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueByte.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueByte.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Byte, val p4: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueInt.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueInt.kt index 8317171ba77..2b81c8bac02 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueInt.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/maxValueInt.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Int, val p4: Long, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/miltiply.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/miltiply.kt index aca9bf3c2de..5125caa4557 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/miltiply.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/miltiply.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/minus.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/minus.kt index 626c85df9b7..baeeab6de9f 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/minus.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/minus.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/mod.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/mod.kt index 5042c163602..64ba6b944ea 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/mod.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/mod.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/paranthesized.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/paranthesized.kt index 62629fe5b1f..f9815c6940b 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/paranthesized.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/paranthesized.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/plus.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/plus.kt index c84910aa5cb..bfa000dfe76 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/plus.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/plus.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/simpleCallBinary.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/simpleCallBinary.kt index 84999de929f..2be9ecb8298 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/simpleCallBinary.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/simpleCallBinary.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Int, val p2: Int, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/unaryMinus.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/unaryMinus.kt index 68d4077cedc..a40663c2e87 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/unaryMinus.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/unaryMinus.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/evaluate/unaryPlus.kt b/compiler/testData/codegen/boxWithStdlib/evaluate/unaryPlus.kt index a75bc397886..b330439042e 100644 --- a/compiler/testData/codegen/boxWithStdlib/evaluate/unaryPlus.kt +++ b/compiler/testData/codegen/boxWithStdlib/evaluate/unaryPlus.kt @@ -1,8 +1,4 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val p1: Byte, val p2: Short, val p3: Int, diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/array.kt b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/array.kt index baf6024ecf4..05fc8d82bed 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/array.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/array.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val args: Array>) class O diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/basic.kt b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/basic.kt index eb42b6d11b8..16039ba0f60 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/basic.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/basic.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val arg: KClass<*>) class OK diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/vararg.kt b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/vararg.kt index 5033ea07085..41d79e7c693 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/vararg.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/kClassInAnnotation/vararg.kt @@ -1,8 +1,6 @@ import kotlin.reflect.KClass -import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -annotation +annotation(retention = AnnotationRetention.RUNTIME) class Ann(vararg val args: KClass<*>) class O diff --git a/compiler/testData/codegen/boxWithStdlib/regressions/kt1932.kt b/compiler/testData/codegen/boxWithStdlib/regressions/kt1932.kt index b8040c69354..b5d58877650 100644 --- a/compiler/testData/codegen/boxWithStdlib/regressions/kt1932.kt +++ b/compiler/testData/codegen/boxWithStdlib/regressions/kt1932.kt @@ -1,8 +1,6 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy import java.lang.annotation.Annotation -Retention(RetentionPolicy.RUNTIME) annotation class foo(val name : String) +annotation(retention = AnnotationRetention.RUNTIME) class foo(val name : String) class Test() { foo("OK") fun hello(input : String) { diff --git a/compiler/testData/codegen/bytecodeText/annotationJavaRetentionPolicyRuntime.kt b/compiler/testData/codegen/bytecodeText/annotationJavaRetentionPolicyRuntime.kt new file mode 100644 index 00000000000..649f4d30daf --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/annotationJavaRetentionPolicyRuntime.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/annotationRetentionPolicyClass.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt index aef672ab0de..6e2e89a7c8d 100644 --- a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt @@ -1,9 +1,7 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann class MyClass -Retention(RetentionPolicy.CLASS) -annotation class Ann +annotation(retention = AnnotationRetention.BINARY) class Ann + +// 1 @LAnn;() +// 1 invisible -// 1 @LAnn;() \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt index 649f4d30daf..08c29cd3766 100644 --- a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicyRuntime.kt @@ -1,9 +1,6 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann class MyClass -Retention(RetentionPolicy.RUNTIME) -annotation class Ann +annotation(retention = AnnotationRetention.RUNTIME) class Ann -// 1 @LAnn;() \ No newline at end of file +// 1 @LAnn;() +// 0 invisible diff --git a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt index a2248c7740b..7260c31a09b 100644 --- a/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt +++ b/compiler/testData/codegen/bytecodeText/annotationRetentionPolicySource.kt @@ -1,9 +1,5 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - Ann class MyClass -Retention(RetentionPolicy.SOURCE) -annotation class Ann +annotation(retention = AnnotationRetention.SOURCE) class Ann // 0 @LAnn;() \ No newline at end of file diff --git a/compiler/testData/codegen/properties/syntheticMethod/inClass.kt b/compiler/testData/codegen/properties/syntheticMethod/inClass.kt index f17c4afc14c..c050fdabadc 100644 --- a/compiler/testData/codegen/properties/syntheticMethod/inClass.kt +++ b/compiler/testData/codegen/properties/syntheticMethod/inClass.kt @@ -1,6 +1,4 @@ -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) annotation class SomeAnnotation(val value: String) +annotation(retention = AnnotationRetention.RUNTIME) class SomeAnnotation(val value: String) class A { @SomeAnnotation("OK") val property: Int diff --git a/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt b/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt index fecb7aed395..20006213ee7 100644 --- a/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt +++ b/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt @@ -1,6 +1,4 @@ -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) annotation class SomeAnnotation(val value: String) +annotation(retention = AnnotationRetention.RUNTIME) class SomeAnnotation(val value: String) interface T { @SomeAnnotation("OK") val property: Int diff --git a/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt b/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt index 9bd6284ea32..c5948fc87dd 100644 --- a/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt +++ b/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt @@ -1,6 +1,4 @@ -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) annotation class SomeAnnotation(val value: String) +annotation(retention = AnnotationRetention.RUNTIME) class SomeAnnotation(val value: String) @SomeAnnotation("OK") val property: Int get() = 42 diff --git a/compiler/testData/compileKotlinAgainstKotlin/AnnotationInTrait.A.kt b/compiler/testData/compileKotlinAgainstKotlin/AnnotationInTrait.A.kt index a04ee6dda50..199cf2d375f 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/AnnotationInTrait.A.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/AnnotationInTrait.A.kt @@ -1,9 +1,6 @@ package a -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) -annotation class Ann +annotation(retention = AnnotationRetention.RUNTIME) class Ann interface Tr { Ann diff --git a/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.A.kt b/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.A.kt index 35e5e84c913..dc9584be3c9 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.A.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.A.kt @@ -1,8 +1,5 @@ package constants -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - public val b: Byte = 100 public val s: Short = 20000 public val i: Int = 2000000 @@ -14,5 +11,4 @@ public val c: Char = '\u03c0' // pi symbol public val str: String = ":)" -@Retention(RetentionPolicy.RUNTIME) -public annotation class AnnotationClass(public val value: String) \ No newline at end of file +public annotation(retention = AnnotationRetention.RUNTIME) class AnnotationClass(public val value: String) \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt b/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt index 32e6000ec7a..86274b17551 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt @@ -1,5 +1,3 @@ -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy import a.* Ann(i, s, f, d, l, b, bool, c, str) @@ -8,8 +6,7 @@ class MyClass1 Ann(i2, s2, f2, d2, l2, b2, bool2, c2, str2) class MyClass2 -Retention(RetentionPolicy.RUNTIME) -annotation class Ann( +annotation(retention = AnnotationRetention.RUNTIME) class Ann( val i: Int, val s: Short, val f: Float, diff --git a/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt b/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt index d7458d0cc85..397822550f8 100644 --- a/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt +++ b/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt @@ -1,13 +1,13 @@ package -kotlin.annotation.annotation() java.lang.annotation.Retention(value = RetentionPolicy.CLASS) internal final annotation class my : kotlin.Annotation { +kotlin.annotation.annotation() internal final annotation class my : kotlin.Annotation { public constructor my() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -kotlin.annotation.annotation() java.lang.annotation.Retention(value = RetentionPolicy.RUNTIME) java.lang.annotation.Target(value = {ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) internal final annotation class my1 : kotlin.Annotation { +kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) internal final annotation class my1 : kotlin.Annotation { public constructor my1() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt b/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt new file mode 100644 index 00000000000..5127231dbc9 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt @@ -0,0 +1,6 @@ +// ALLOW_AST_ACCESS + +package test + +target(AnnotationTarget.CLASSIFIER) +public annotation class TargetedAnnotation diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.txt b/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.txt new file mode 100644 index 00000000000..5d67f42b301 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.txt @@ -0,0 +1,5 @@ +package test + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() public final annotation class TargetedAnnotation : kotlin.Annotation { + /*primary*/ public constructor TargetedAnnotation() +} diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt new file mode 100644 index 00000000000..423299db385 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt @@ -0,0 +1,3 @@ +package test + +data class My(val x: Int) diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.txt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.txt new file mode 100644 index 00000000000..89946f14107 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.txt @@ -0,0 +1,9 @@ +package test + +kotlin.data() internal final class My { + /*primary*/ public constructor My(/*0*/ x: kotlin.Int) + internal final val x: kotlin.Int + internal final fun (): kotlin.Int + internal final /*synthesized*/ fun component1(): kotlin.Int + public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ...): test.My +} diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.kt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.kt index 6f1ded2bbd0..bd9b66be01f 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.kt @@ -2,6 +2,4 @@ //SKIP_IN_RUNTIME_TEST package test -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) annotation class Anno +annotation(retention = AnnotationRetention.RUNTIME) class Anno diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.txt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.txt index 5b62bb55b8f..95dc30c54f9 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.txt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/Retention.txt @@ -1,5 +1,5 @@ package test -java.lang.annotation.Retention(value = RetentionPolicy.RUNTIME) kotlin.annotation.annotation() internal final annotation class Anno : kotlin.Annotation { +kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) internal final annotation class Anno : kotlin.Annotation { /*primary*/ public constructor Anno() } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index ac3f1ea6b05..d7b551fb128 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -47,6 +47,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("annotationJavaRetentionPolicyRuntime.kt") + public void testAnnotationJavaRetentionPolicyRuntime() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/annotationJavaRetentionPolicyRuntime.kt"); + doTest(fileName); + } + @TestMetadata("annotationRetentionPolicyClass.kt") public void testAnnotationRetentionPolicyClass() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/annotationRetentionPolicyClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java index eccfaa7ed35..cd23c5db5e7 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.descriptors.PackageViewDescriptor; +import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.psi.JetFile; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.renderer.DescriptorRendererOptions; @@ -35,6 +36,7 @@ import org.junit.Assert; import java.io.File; import java.io.IOException; +import java.lang.annotation.Retention; import java.util.Collections; import static org.jetbrains.kotlin.test.JetTestUtils.*; @@ -53,6 +55,7 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT options.setWithDefinedIn(false); options.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE); options.setVerbose(true); + options.setExcludedAnnotationClasses(Collections.singleton(new FqName(Retention.class.getName()))); return Unit.INSTANCE$; } } diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index 8787889e66f..1e88eca050c 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -1942,6 +1942,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledKotlin(fileName); } + @TestMetadata("TargetedAnnotation.kt") + public void testTargetedAnnotation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt"); + doTestCompiledKotlin(fileName); + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classMembers") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -2031,6 +2037,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledKotlin(fileName); } + @TestMetadata("DataClass.kt") + public void testDataClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt"); + doTestCompiledKotlin(fileName); + } + @TestMetadata("Deprecated.kt") public void testDeprecated() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt index 116a8affaee..9c7c0e8612d 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuratio import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.utils.sure import java.io.File +import java.lang.annotation.Retention import java.net.URLClassLoader import java.util.regex.Pattern @@ -52,21 +53,18 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi private val renderer = DescriptorRenderer.withOptions { withDefinedIn = false excludedAnnotationClasses = (listOf( - ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME, - // TODO: add these annotations when they are retained at runtime - "kotlin.deprecated", - "kotlin.data", - "kotlin.inline" - ).map { FqName(it) } + JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES).toSet() + FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME) + ) + JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES).toSet() overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE includePropertyConstant = false verbose = true + renderDefaultAnnotationArguments = true } } // NOTE: this test does a dirty hack of text substitution to make all annotations defined in source code retain at runtime. - // Specifically each "annotation class" in Kotlin sources is replaced by "Retention(RUNTIME) annotation class", and the same in Java + // Specifically each @interface in Java sources is extended by @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) // Also type related annotations are removed from Java because they are invisible at runtime protected fun doTest(fileName: String) { val file = File(fileName) @@ -123,7 +121,7 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi val environment = JetTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea( myTestRootDisposable, ConfigurationKind.ALL, jdkKind ) - val jetFile = JetTestUtils.createFile(file.getPath(), addRuntimeRetentionToKotlinSource(text), environment.project) + val jetFile = JetTestUtils.createFile(file.getPath(), text, environment.project) GenerationUtils.compileFileGetClassFileFactoryForTest(jetFile).writeAllTo(tmpdir) } } @@ -166,13 +164,6 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi return SyntheticPackageViewForTest(module, packageScopes, classes) } - private fun addRuntimeRetentionToKotlinSource(text: String): String { - return text.replace( - "annotation class", - "@[java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)] annotation class" - ) - } - private fun adaptJavaSource(text: String): String { val typeAnnotations = arrayOf("NotNull", "Nullable", "ReadOnly", "Mutable") return typeAnnotations.fold(text) { text, annotation -> text.replace("@$annotation", "") }.replace( diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index 9e1c62d4995..cf574eae3eb 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -81,6 +81,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD doTest(fileName); } + @TestMetadata("TargetedAnnotation.kt") + public void testTargetedAnnotation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classMembers") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -170,6 +176,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD doTest(fileName); } + @TestMetadata("DataClass.kt") + public void testDataClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt"); + doTest(fileName); + } + @TestMetadata("Deprecated.kt") public void testDeprecated() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java b/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java index 6fe0cfe2c58..b43c957a1b4 100644 --- a/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java +++ b/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java @@ -40,20 +40,26 @@ import org.jetbrains.kotlin.utils.Printer; import org.junit.Assert; import java.io.File; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.lang.annotation.Retention; +import java.util.*; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry; import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden; public class RecursiveDescriptorComparator { + + private static final Set excludedAnnotations = new HashSet(); + static { + excludedAnnotations.add(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)); + excludedAnnotations.add(new FqName(Retention.class.getName())); + } + private static final DescriptorRenderer DEFAULT_RENDERER = DescriptorRenderer.Companion.withOptions( new Function1() { @Override public Unit invoke(DescriptorRendererOptions options) { options.setWithDefinedIn(false); - options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME))); + options.setExcludedAnnotationClasses(excludedAnnotations); options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE); options.setIncludePropertyConstant(true); options.setNameShortness(NameShortness.FULLY_QUALIFIED); diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt index 01a38387c11..89fe98bdfab 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt @@ -176,6 +176,7 @@ public interface DescriptorRendererOptions { public var flexibleTypesForCode: Boolean public var secondaryConstructorsAsPrimary: Boolean public var renderAccessors: Boolean + public var renderDefaultAnnotationArguments: Boolean } public enum class RenderingFormat { diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 0c0d18d43b3..dd48739459f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -366,13 +366,22 @@ internal class DescriptorRendererImpl( } private fun renderAndSortAnnotationArguments(descriptor: AnnotationDescriptor): List { - return descriptor.getAllValueArguments().entrySet() + val allValueArguments = descriptor.getAllValueArguments() + val classDescriptor = if (renderDefaultAnnotationArguments) TypeUtils.getClassDescriptor(descriptor.getType()) else null + val parameterDescriptorsWithDefaultValue = classDescriptor?.getUnsubstitutedPrimaryConstructor()?.getValueParameters()?.filter { + it.declaresDefaultValue() + } ?: emptyList() + val defaultList = parameterDescriptorsWithDefaultValue.filter { !allValueArguments.containsKey(it) }.map { + "${it.getName().asString()} = ..." + }.sort() + val argumentList = allValueArguments.entrySet() .map { entry -> val name = entry.key.getName().asString() - val value = renderConstant(entry.value) + val value = if (!parameterDescriptorsWithDefaultValue.contains(entry.key)) renderConstant(entry.value) else "..." "$name = $value" } .sort() + return (defaultList + argumentList).sort() } private fun renderConstant(value: CompileTimeConstant<*>): String { diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt index 51c0b33739d..29613c13b51 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt @@ -85,6 +85,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions { override var receiverAfterName by property(false) override var renderCompanionObjectName by property(false) override var renderAccessors by property(false) + override var renderDefaultAnnotationArguments by property(false) override var excludedAnnotationClasses by property(emptySet()) diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java index 6d52f481654..295e8ef3c35 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java @@ -79,6 +79,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest { doTest(fileName); } + @TestMetadata("TargetedAnnotation.kt") + public void testTargetedAnnotation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/TargetedAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classMembers") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -168,6 +174,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest { doTest(fileName); } + @TestMetadata("DataClass.kt") + public void testDataClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/DataClass.kt"); + doTest(fileName); + } + @TestMetadata("Deprecated.kt") public void testDeprecated() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt"); diff --git a/libraries/stdlib/test/AnnotationsTest.kt b/libraries/stdlib/test/AnnotationsTest.kt index 40c45c3b3e6..cb6967f9cc4 100644 --- a/libraries/stdlib/test/AnnotationsTest.kt +++ b/libraries/stdlib/test/AnnotationsTest.kt @@ -3,11 +3,8 @@ package test.annotations import kotlin.* import kotlin.test.assertTrue import org.junit.Test as test -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) -annotation class MyAnno +annotation(retention = AnnotationRetention.RUNTIME) class MyAnno MyAnno Deprecated diff --git a/plugins/annotation-collector/testData/collectToFile/annotationInSameFile/annotations.txt b/plugins/annotation-collector/testData/collectToFile/annotationInSameFile/annotations.txt index e111145ea84..45399e7808f 100644 --- a/plugins/annotation-collector/testData/collectToFile/annotationInSameFile/annotations.txt +++ b/plugins/annotation-collector/testData/collectToFile/annotationInSameFile/annotations.txt @@ -1,6 +1,8 @@ a kotlin.annotation.annotation 0 p org.test 0 c 0 0/SomeAnnotation -a org.test.SomeAnnotation 1 -c 1 0/SomeClass -m 1 0/SomeClass annotatedFunction +a java.lang.annotation.Retention 1 +c 1 0/SomeAnnotation +a org.test.SomeAnnotation 2 +c 2 0/SomeClass +m 2 0/SomeClass annotatedFunction