diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index a789dd6978c..310464bb781 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -939,6 +939,11 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati var annotations = visibleAnnotations?.fold(JavacList.nil(), ::convertAndAdd) ?: JavacList.nil() annotations = invisibleAnnotations?.fold(annotations, ::convertAndAdd) ?: annotations + if (isDeprecated(access)) { + val type = treeMaker.Type(Type.getType(java.lang.Deprecated::class.java)) + annotations = annotations.append(treeMaker.Annotation(type, JavacList.nil())) + } + val flags = when (kind) { ElementKind.ENUM -> access and CLASS_MODIFIERS and Opcodes.ACC_ABSTRACT.inv().toLong() ElementKind.CLASS -> access and CLASS_MODIFIERS diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt index 55f38c1d377..92f16278ee0 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt @@ -29,6 +29,10 @@ internal fun isSynthetic(access: Int) = (access and Opcodes.ACC_SYNTHETIC) != 0 internal fun isFinal(access: Int) = (access and Opcodes.ACC_FINAL) != 0 internal fun isStatic(access: Int) = (access and Opcodes.ACC_STATIC) != 0 internal fun isAbstract(access: Int) = (access and Opcodes.ACC_ABSTRACT) != 0 + +private const val LONG_DEPRECATED = Opcodes.ACC_DEPRECATED.toLong() +internal fun isDeprecated(access: Long) = (access and LONG_DEPRECATED) != 0L + internal fun ClassNode.isEnum() = (access and Opcodes.ACC_ENUM) != 0 internal fun ClassNode.isAnnotation() = (access and Opcodes.ACC_ANNOTATION) != 0 internal fun MethodNode.isVarargs() = (access and Opcodes.ACC_VARARGS) != 0 diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index ec5cef9625a..cb3065de0de 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -88,6 +88,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi runTest("plugins/kapt3/kapt3-compiler/testData/converter/defaultImpls.kt"); } + @TestMetadata("deprecated.kt") + public void testDeprecated() throws Exception { + runTest("plugins/kapt3/kapt3-compiler/testData/converter/deprecated.kt"); + } + @TestMetadata("enumImports.kt") public void testEnumImports() throws Exception { runTest("plugins/kapt3/kapt3-compiler/testData/converter/enumImports.kt"); diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotations.txt b/plugins/kapt3/kapt3-compiler/testData/converter/annotations.txt index a4998fe463d..fd496b9f7a4 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/annotations.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotations.txt @@ -110,6 +110,7 @@ public final class TestAnno2 { } @Anno3(value = "property") + @java.lang.Deprecated() public static void b$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotations2.txt b/plugins/kapt3/kapt3-compiler/testData/converter/annotations2.txt index 1238848a7e1..6bc227730b8 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/annotations2.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotations2.txt @@ -30,6 +30,7 @@ public final class AnnotationsTest { } @Anno(value = "top-level-val") + @java.lang.Deprecated() public static void topLevelVal$annotations(int p0) { } @@ -82,6 +83,7 @@ public abstract class Test { public abstract java.lang.String abstractMethod(); @Anno(value = "abstract-val") + @java.lang.Deprecated() public static void abstractVal$annotations() { } @@ -89,6 +91,7 @@ public abstract class Test { public abstract java.lang.String getAbstractVal(); @Anno(value = "v-property") + @java.lang.Deprecated() public static void v$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotationsWithTargets.txt b/plugins/kapt3/kapt3-compiler/testData/converter/annotationsWithTargets.txt index 6b4773110b8..d81fe24bd02 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/annotationsWithTargets.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotationsWithTargets.txt @@ -18,6 +18,7 @@ public final class Bar { @Anno() @PropertyAnno() + @java.lang.Deprecated() public static void a$annotations() { } @@ -43,6 +44,7 @@ public final class Baz { public final java.lang.String a = ""; @Anno() + @java.lang.Deprecated() public static void a$annotations() { } @@ -75,6 +77,7 @@ public final class Foo { private final java.lang.String a = null; @PropertyAnno() + @java.lang.Deprecated() public static void a$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/comments.txt b/plugins/kapt3/kapt3-compiler/testData/converter/comments.txt index 8bc8f5daeee..69f17b612bd 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/comments.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/comments.txt @@ -87,6 +87,7 @@ public final class Test { * prop2. */ @Anno() + @java.lang.Deprecated() public static void prop2$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.kt b/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.kt new file mode 100644 index 00000000000..473fe202d42 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.kt @@ -0,0 +1,18 @@ +package deprecated + +@Deprecated("Deprecated annotation") +annotation class Anno + +@Deprecated("Deprecated class") +@Anno +class Foo { + @Deprecated("Deprecated function") + fun foo(a: Int) {} + + @Deprecated("Deprecated property") + val prop = 0 + + var foo: Int + @Deprecated("Deprecated getter") get() = 0 + @Deprecated("Deprecated setter") set(value) {} +} \ No newline at end of file diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.txt b/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.txt new file mode 100644 index 00000000000..0702cbc0454 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/deprecated.txt @@ -0,0 +1,49 @@ +package deprecated; + +import java.lang.System; + +@kotlin.Metadata() +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) +@java.lang.Deprecated() +public abstract @interface Anno { +} + +//////////////////// + +package deprecated; + +import java.lang.System; + +@kotlin.Metadata() +@Anno() +@java.lang.Deprecated() +public final class Foo { + @java.lang.Deprecated() + private final int prop = 0; + + @java.lang.Deprecated() + public final void foo(int a) { + } + + @java.lang.Deprecated() + public static void prop$annotations() { + } + + @java.lang.Deprecated() + public final int getProp() { + return 0; + } + + @java.lang.Deprecated() + public final int getFoo() { + return 0; + } + + @java.lang.Deprecated() + public final void setFoo(int value) { + } + + public Foo() { + super(); + } +} diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/jvmStatic.txt b/plugins/kapt3/kapt3-compiler/testData/converter/jvmStatic.txt index 3990759e580..77d469a548f 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/jvmStatic.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/jvmStatic.txt @@ -20,6 +20,7 @@ public final class JvmStaticTest { @kotlin.Metadata() public static final class Companion { + @java.lang.Deprecated() public static void one$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/jvmStaticFieldInParent.txt b/plugins/kapt3/kapt3-compiler/testData/converter/jvmStaticFieldInParent.txt index 07e90091af6..13f8c5b9ee4 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/jvmStaticFieldInParent.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/jvmStaticFieldInParent.txt @@ -18,6 +18,7 @@ public final class Test { @kotlin.Metadata() public static final class A { + @java.lang.Deprecated() public static void test$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/kt18791.txt b/plugins/kapt3/kapt3-compiler/testData/converter/kt18791.txt index a0b74f61b25..01c878bb1ac 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/kt18791.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/kt18791.txt @@ -136,6 +136,7 @@ public final class MyActivity { private final int propF = 0; @Bind(id = lib.R.id.textView) + @java.lang.Deprecated() public static void a$annotations() { } @@ -144,6 +145,7 @@ public final class MyActivity { } @Bind(id = lib.R.id.textView) + @java.lang.Deprecated() public static void b$annotations() { } @@ -152,6 +154,7 @@ public final class MyActivity { } @Bind(id = app.R.layout.mainActivity) + @java.lang.Deprecated() public static void c$annotations() { } @@ -160,6 +163,7 @@ public final class MyActivity { } @Bind(id = app.R.layout.mainActivity) + @java.lang.Deprecated() public static void d$annotations() { } @@ -169,6 +173,7 @@ public final class MyActivity { @Anno(a1 = app.B.a1, a2 = app.B.a2, a3 = app.B.a3, a4 = app.B.a4, a5 = app.B.a5, a6 = app.B.a6, a7 = app.B.a7, a8 = app.B.a8, a9 = "A") @Bind(id = app.R2.layout.mainActivity) + @java.lang.Deprecated() public static void e$annotations() { } @@ -177,6 +182,7 @@ public final class MyActivity { } @Bind(id = app.B.id.textView) + @java.lang.Deprecated() public static void f$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/propertyAnnotations.txt b/plugins/kapt3/kapt3-compiler/testData/converter/propertyAnnotations.txt index ea84001dfe8..fdb5c0d09c7 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/propertyAnnotations.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/propertyAnnotations.txt @@ -29,6 +29,7 @@ public final class Test { @Anno2() @Anno() + @java.lang.Deprecated() public static void prop$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.txt b/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.txt index 2779b066bb0..e103b5af245 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.txt @@ -189,6 +189,7 @@ public final class Test { @lib.Anno(value = "3", construct = {"C"}) @lib.Anno(value = "2", construct = {"A", "B"}) @lib.Anno(value = "1") + @java.lang.Deprecated() public static void value$annotations() { } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/topLevel.txt b/plugins/kapt3/kapt3-compiler/testData/converter/topLevel.txt index 8d44c6c4de7..1a27a4085b7 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/topLevel.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/topLevel.txt @@ -53,6 +53,7 @@ public final class TopLevelKt { } @Anno(value = "extpr") + @java.lang.Deprecated() public static void extensionProperty$annotations(java.lang.Object p0) { }