From 1819194a4cd128d5542d2de7f580c0396af696c0 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 31 Jan 2017 19:47:52 +0300 Subject: [PATCH] Kapt3: Allow annotations with Kotlin-only targets, such as PROPERTY (KT-15697) --- .../org/jetbrains/kotlin/kapt3/javac/KaptJavaLog.kt | 3 ++- .../kapt3/stubs/ClassFileToSourceStubConverter.kt | 1 - plugins/kapt3/testData/converter/annotations.txt | 3 +++ plugins/kapt3/testData/converter/annotations2.txt | 1 + plugins/kapt3/testData/converter/enums.txt | 1 + .../kapt3/testData/converter/propertyAnnotations.kt | 5 ++++- .../kapt3/testData/converter/propertyAnnotations.txt | 11 +++++++++++ plugins/kapt3/testData/converter/topLevel.txt | 1 + .../kapt3/testData/kotlinRunner/NestedClasses.it.txt | 1 + 9 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptJavaLog.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptJavaLog.kt index 08c070c1ec7..69020844626 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptJavaLog.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptJavaLog.kt @@ -45,7 +45,8 @@ class KaptJavaLog( "compiler.err.name.clash.same.erasure.no.override", "compiler.err.name.clash.same.erasure.no.override.1", "compiler.err.name.clash.same.erasure.no.hide", - "compiler.err.already.defined") + "compiler.err.already.defined", + "compiler.err.annotation.type.not.applicable") internal fun preRegister(context: Context, messageCollector: MessageCollector) { context.put(Log.logKey, Context.Factory { diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 8b78b3b7695..cdcd6ef5edd 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -66,7 +66,6 @@ class ClassFileToSourceStubConverter( "java.lang.Deprecated", "kotlin.Deprecated", // Deprecated annotations "java.lang.Synthetic", "synthetic.kotlin.jvm.GeneratedByJvmOverloads", // kapt3-related annotation for marking JvmOverloads-generated methods - "java.lang.annotation.", // Java annotations "kotlin.jvm.", "kotlin.Metadata" // Kotlin annotations from runtime ) diff --git a/plugins/kapt3/testData/converter/annotations.txt b/plugins/kapt3/testData/converter/annotations.txt index 0c8a16b5a99..0378cfab95a 100644 --- a/plugins/kapt3/testData/converter/annotations.txt +++ b/plugins/kapt3/testData/converter/annotations.txt @@ -1,9 +1,11 @@ +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno1 { } //////////////////// +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno2 { public abstract int i() default 5; @@ -28,6 +30,7 @@ public abstract @interface Anno2 { //////////////////// +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno3 { public abstract java.lang.String value(); diff --git a/plugins/kapt3/testData/converter/annotations2.txt b/plugins/kapt3/testData/converter/annotations2.txt index 7beb9999ce6..0657003ca3d 100644 --- a/plugins/kapt3/testData/converter/annotations2.txt +++ b/plugins/kapt3/testData/converter/annotations2.txt @@ -1,5 +1,6 @@ package test; +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) @Anno(value = "anno-class") public abstract @interface Anno { diff --git a/plugins/kapt3/testData/converter/enums.txt b/plugins/kapt3/testData/converter/enums.txt index 023a701e58b..90d717190d5 100644 --- a/plugins/kapt3/testData/converter/enums.txt +++ b/plugins/kapt3/testData/converter/enums.txt @@ -1,3 +1,4 @@ +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno1 { public abstract java.lang.String value(); diff --git a/plugins/kapt3/testData/converter/propertyAnnotations.kt b/plugins/kapt3/testData/converter/propertyAnnotations.kt index 8acf49667ea..323cb8c686d 100644 --- a/plugins/kapt3/testData/converter/propertyAnnotations.kt +++ b/plugins/kapt3/testData/converter/propertyAnnotations.kt @@ -1,6 +1,9 @@ annotation class Anno +@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) +annotation class Anno2 + class Test { - @property:Anno + @property:[Anno Anno2] val prop = "A" } \ No newline at end of file diff --git a/plugins/kapt3/testData/converter/propertyAnnotations.txt b/plugins/kapt3/testData/converter/propertyAnnotations.txt index 1bc4379f93b..fceca61a71e 100644 --- a/plugins/kapt3/testData/converter/propertyAnnotations.txt +++ b/plugins/kapt3/testData/converter/propertyAnnotations.txt @@ -1,13 +1,24 @@ +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno { } //////////////////// +@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE}) +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) +@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.PROPERTY, kotlin.annotation.AnnotationTarget.CLASS}) +public abstract @interface Anno2 { +} + +//////////////////// + + public final class Test { @org.jetbrains.annotations.NotNull() private final java.lang.String prop = "A"; + @Anno2() @Anno() private static void prop$annotations() { } diff --git a/plugins/kapt3/testData/converter/topLevel.txt b/plugins/kapt3/testData/converter/topLevel.txt index afe3fef0ed5..4247153acf9 100644 --- a/plugins/kapt3/testData/converter/topLevel.txt +++ b/plugins/kapt3/testData/converter/topLevel.txt @@ -1,5 +1,6 @@ package test.another; +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface Anno { public abstract java.lang.String value(); diff --git a/plugins/kapt3/testData/kotlinRunner/NestedClasses.it.txt b/plugins/kapt3/testData/kotlinRunner/NestedClasses.it.txt index 8a851d08da6..eabee2ccd7f 100644 --- a/plugins/kapt3/testData/kotlinRunner/NestedClasses.it.txt +++ b/plugins/kapt3/testData/kotlinRunner/NestedClasses.it.txt @@ -1,5 +1,6 @@ package test; +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) public abstract @interface MyAnnotation { }