diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/annotation.txt b/compiler/testData/compileJavaAgainstKotlin/targets/annotation.txt index c67a9aad096..6349b9ea3ed 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/annotation.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/annotation.txt @@ -4,6 +4,6 @@ test.meta() public/*package*/ final class MyAnn : kotlin.Annotation { public/*package*/ constructor MyAnn() } -kotlin.annotation.target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.ANNOTATION_TYPE}) internal final class meta : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) kotlin.annotation.annotation() internal final class meta : kotlin.Annotation { public constructor meta() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/classifier.txt b/compiler/testData/compileJavaAgainstKotlin/targets/classifier.txt index e78c36e3bfa..f19f7e8a330 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/classifier.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/classifier.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.TYPE}) internal final class classifier : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() internal final class classifier : kotlin.Annotation { public constructor classifier() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/constructor.txt b/compiler/testData/compileJavaAgainstKotlin/targets/constructor.txt index ce1e8b0164d..084487bdda8 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/constructor.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/constructor.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.CONSTRUCTOR}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.CONSTRUCTOR}) internal final class constructor : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CONSTRUCTOR}) kotlin.annotation.annotation() internal final class constructor : kotlin.Annotation { public constructor constructor() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/empty.txt b/compiler/testData/compileJavaAgainstKotlin/targets/empty.txt index 0dd05225d23..d2e4b24462c 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/empty.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/empty.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {}) internal final class empty : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {}) kotlin.annotation.annotation() internal final class empty : kotlin.Annotation { public constructor empty() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/field.txt b/compiler/testData/compileJavaAgainstKotlin/targets/field.txt index 65c95f1a64a..c85e2edcd7f 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/field.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/field.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.FIELD}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.FIELD}) internal final class field : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.FIELD}) kotlin.annotation.annotation() internal final class field : kotlin.Annotation { public constructor field() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/function.txt b/compiler/testData/compileJavaAgainstKotlin/targets/function.txt index 89291920462..8e421090589 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/function.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/function.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class function : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() internal final class function : kotlin.Annotation { public constructor function() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/getter.txt b/compiler/testData/compileJavaAgainstKotlin/targets/getter.txt index 2cb31f08715..39bf0f57ecb 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/getter.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/getter.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_GETTER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class getter : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_GETTER}) kotlin.annotation.annotation() internal final class getter : kotlin.Annotation { public constructor getter() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/local.txt b/compiler/testData/compileJavaAgainstKotlin/targets/local.txt index 7731a09f388..2a1332759af 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/local.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/local.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.LOCAL_VARIABLE}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.LOCAL_VARIABLE}) internal final class local : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.LOCAL_VARIABLE}) kotlin.annotation.annotation() internal final class local : kotlin.Annotation { public constructor local() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/multiple.txt b/compiler/testData/compileJavaAgainstKotlin/targets/multiple.txt index 2a3a8c4e794..e8113fd2d4f 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/multiple.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/multiple.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.TYPE, ElementType.METHOD}) internal final class multiple : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() internal final class multiple : kotlin.Annotation { public constructor multiple() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/package-info.txt b/compiler/testData/compileJavaAgainstKotlin/targets/package-info.txt index e1012210dd7..facfd4f2029 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/package-info.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/package-info.txt @@ -3,6 +3,6 @@ package test test.pck() public/*package*/ interface `package-info` { } -kotlin.annotation.target(allowedTargets = {AnnotationTarget.PACKAGE}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.PACKAGE}) internal final class pck : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PACKAGE}) kotlin.annotation.annotation() internal final class pck : kotlin.Annotation { public constructor pck() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/parameter.txt b/compiler/testData/compileJavaAgainstKotlin/targets/parameter.txt index b96cb99dc91..8773097824a 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/parameter.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/parameter.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.PARAMETER}) internal final class parameter : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation() internal final class parameter : kotlin.Annotation { public constructor parameter() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/property.txt b/compiler/testData/compileJavaAgainstKotlin/targets/property.txt index 636e36d33b1..fdc224d14ea 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/property.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/property.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {}) internal final class property : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY}) kotlin.annotation.annotation() internal final class property : kotlin.Annotation { public constructor property() } diff --git a/compiler/testData/compileJavaAgainstKotlin/targets/setter.txt b/compiler/testData/compileJavaAgainstKotlin/targets/setter.txt index a9afdf028d3..a60787c4175 100644 --- a/compiler/testData/compileJavaAgainstKotlin/targets/setter.txt +++ b/compiler/testData/compileJavaAgainstKotlin/targets/setter.txt @@ -1,5 +1,5 @@ package test -kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_SETTER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class setter : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_SETTER}) kotlin.annotation.annotation() internal final class setter : kotlin.Annotation { public constructor setter() } diff --git a/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt b/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.txt index 873cccd65d5..d98b84fb357 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() internal final class my : kotlin.Annotation { +java.lang.annotation.Retention(value = RetentionPolicy.CLASS) kotlin.annotation.annotation() internal final 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() internal final class my1 : kotlin.Annotation { +java.lang.annotation.Retention(value = RetentionPolicy.RUNTIME) java.lang.annotation.Target(value = {ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) kotlin.annotation.annotation() internal final 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/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java b/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java index 7d4d4802e98..bd085a6686d 100644 --- a/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java +++ b/compiler/tests/org/jetbrains/kotlin/test/util/RecursiveDescriptorComparator.java @@ -49,19 +49,12 @@ import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisit 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())); - excludedAnnotations.add(new FqName(Target.class.getName())); - } - private static final DescriptorRenderer DEFAULT_RENDERER = DescriptorRenderer.Companion.withOptions( new Function1() { @Override public Unit invoke(DescriptorRendererOptions options) { options.setWithDefinedIn(false); - options.setExcludedAnnotationClasses(excludedAnnotations); + options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME))); options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE); options.setIncludePropertyConstant(true); options.setNameShortness(NameShortness.FULLY_QUALIFIED); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java index 05a5a6eae81..fccd277c6ac 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java @@ -41,6 +41,9 @@ public final class JvmAnnotationNames { public static final Name TARGET_ANNOTATION_MEMBER_NAME = Name.identifier("allowedTargets"); public static final Name RETENTION_ANNOTATION_PARAMETER_NAME = Name.identifier("retention"); + public static final FqName TARGET_ANNOTATION = new FqName("java.lang.annotation.Target"); + public static final FqName RETENTION_ANNOTATION = new FqName("java.lang.annotation.Retention"); + public static final FqName JETBRAINS_NOT_NULL_ANNOTATION = new FqName("org.jetbrains.annotations.NotNull"); public static final FqName JETBRAINS_NULLABLE_ANNOTATION = new FqName("org.jetbrains.annotations.Nullable"); public static final FqName JETBRAINS_MUTABLE_ANNOTATION = new FqName("org.jetbrains.annotations.Mutable"); @@ -118,6 +121,7 @@ public final class JvmAnnotationNames { private static final Set SPECIAL_ANNOTATIONS = new HashSet(); private static final Set NULLABILITY_ANNOTATIONS = new HashSet(); + private static final Set SPECIAL_META_ANNOTATIONS = new HashSet(); static { for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SIGNATURE)) { SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); @@ -127,13 +131,16 @@ public final class JvmAnnotationNames { for (FqName fqName : Arrays.asList(JETBRAINS_NOT_NULL_ANNOTATION, JETBRAINS_NULLABLE_ANNOTATION)) { NULLABILITY_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); } + for (FqName fqName : Arrays.asList(TARGET_ANNOTATION, RETENTION_ANNOTATION)) { + SPECIAL_META_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); + } } public static boolean isSpecialAnnotation(@NotNull ClassId classId, boolean javaSpecificAnnotationsAreSpecial) { JvmClassName className = JvmClassName.byClassId(classId); - return (javaSpecificAnnotationsAreSpecial && NULLABILITY_ANNOTATIONS.contains(className)) - || SPECIAL_ANNOTATIONS.contains(className) - || className.getInternalName().startsWith("jet/runtime/typeinfo/"); + return (javaSpecificAnnotationsAreSpecial + && (NULLABILITY_ANNOTATIONS.contains(className) || SPECIAL_META_ANNOTATIONS.contains(className)) + ) || SPECIAL_ANNOTATIONS.contains(className) || className.getInternalName().startsWith("jet/runtime/typeinfo/"); } private JvmAnnotationNames() {