Kapt: Support @Deprecated annotations (KT-30368)

This commit is contained in:
Yan Zhulanow
2019-04-25 23:27:34 +03:00
parent 1309c0c67a
commit 9edd4554a9
15 changed files with 100 additions and 0 deletions
@@ -939,6 +939,11 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
var annotations = visibleAnnotations?.fold(JavacList.nil<JCAnnotation>(), ::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
@@ -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
@@ -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");
@@ -110,6 +110,7 @@ public final class TestAnno2 {
}
@Anno3(value = "property")
@java.lang.Deprecated()
public static void b$annotations() {
}
@@ -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() {
}
@@ -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() {
}
@@ -87,6 +87,7 @@ public final class Test {
* prop2.
*/
@Anno()
@java.lang.Deprecated()
public static void prop2$annotations() {
}
@@ -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) {}
}
@@ -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();
}
}
@@ -20,6 +20,7 @@ public final class JvmStaticTest {
@kotlin.Metadata()
public static final class Companion {
@java.lang.Deprecated()
public static void one$annotations() {
}
@@ -18,6 +18,7 @@ public final class Test {
@kotlin.Metadata()
public static final class A {
@java.lang.Deprecated()
public static void test$annotations() {
}
@@ -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() {
}
@@ -29,6 +29,7 @@ public final class Test {
@Anno2()
@Anno()
@java.lang.Deprecated()
public static void prop$annotations() {
}
@@ -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() {
}
@@ -53,6 +53,7 @@ public final class TopLevelKt {
}
@Anno(value = "extpr")
@java.lang.Deprecated()
public static void extensionProperty$annotations(java.lang.Object p0) {
}