Kapt: Restore constant identifiers for field annotations (KT-27334)
The old behavior broke after the refactoring of annotations with use-site targets.
This commit is contained in:
+8
-2
@@ -570,9 +570,15 @@ class ClassFileToSourceStubConverter(
|
||||
val origin = kaptContext.origins[field]
|
||||
val descriptor = origin?.descriptor
|
||||
|
||||
val fieldAnnotations = when (descriptor) {
|
||||
is PropertyDescriptor -> descriptor.backingField?.annotations
|
||||
else -> descriptor?.annotations
|
||||
} ?: Annotations.EMPTY
|
||||
|
||||
val modifiers = convertModifiers(
|
||||
field.access, ElementKind.FIELD, packageFqName,
|
||||
field.visibleAnnotations, field.invisibleAnnotations, descriptor?.annotations ?: Annotations.EMPTY)
|
||||
field.access, ElementKind.FIELD, packageFqName,
|
||||
field.visibleAnnotations, field.invisibleAnnotations, fieldAnnotations
|
||||
)
|
||||
|
||||
val name = field.name
|
||||
if (!isValidIdentifier(name)) return null
|
||||
|
||||
+5
@@ -59,6 +59,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/annotations3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("annotationsWithTargets.kt")
|
||||
public void testAnnotationsWithTargets() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/annotationsWithTargets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("comments.kt")
|
||||
public void testComments() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/comments.kt");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class FieldAnno
|
||||
|
||||
@Target(AnnotationTarget.PROPERTY)
|
||||
annotation class PropertyAnno
|
||||
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
annotation class ParameterAnno
|
||||
|
||||
annotation class Anno
|
||||
|
||||
class Foo(@FieldAnno @PropertyAnno @ParameterAnno @Anno val a: String)
|
||||
|
||||
class Bar {
|
||||
@FieldAnno @PropertyAnno @Anno
|
||||
val a: String = ""
|
||||
}
|
||||
|
||||
class Baz {
|
||||
@FieldAnno @Anno
|
||||
@JvmField
|
||||
val a: String = ""
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
public abstract @interface Anno {
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Bar {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
@FieldAnno()
|
||||
private final java.lang.String a = "";
|
||||
|
||||
@Anno()
|
||||
@PropertyAnno()
|
||||
public static void a$annotations() {
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String getA() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bar() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.FIELD})
|
||||
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.FIELD})
|
||||
public abstract @interface FieldAnno {
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Foo {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
@FieldAnno()
|
||||
private final java.lang.String a = null;
|
||||
|
||||
@PropertyAnno()
|
||||
public static void a$annotations() {
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String getA() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Foo(@org.jetbrains.annotations.NotNull()
|
||||
@Anno()
|
||||
@ParameterAnno()
|
||||
java.lang.String a) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.PARAMETER})
|
||||
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.VALUE_PARAMETER})
|
||||
public abstract @interface ParameterAnno {
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
@java.lang.annotation.Target(value = {})
|
||||
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.PROPERTY})
|
||||
public abstract @interface PropertyAnno {
|
||||
}
|
||||
@@ -52,6 +52,9 @@ import lib.R.id.textView
|
||||
|
||||
annotation class Bind(val id: Int)
|
||||
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class BindField(val id: Int)
|
||||
|
||||
annotation class Anno(
|
||||
val a1: Boolean,
|
||||
val a2: Byte,
|
||||
@@ -64,6 +67,31 @@ annotation class Anno(
|
||||
val a9: String)
|
||||
|
||||
class MyActivity {
|
||||
@Bind(LibR.id.textView)
|
||||
@BindField(LibR.id.textView)
|
||||
val a = 0
|
||||
|
||||
@Bind(lib.R.id.textView)
|
||||
@BindField(lib.R.id.textView)
|
||||
val b = 0
|
||||
|
||||
@Bind(app.R.layout.mainActivity)
|
||||
@BindField(app.R.layout.mainActivity)
|
||||
val c = 0
|
||||
|
||||
@Bind(R.layout.mainActivity)
|
||||
@BindField(R.layout.mainActivity)
|
||||
val d = 0
|
||||
|
||||
@Bind(R2.layout.mainActivity)
|
||||
@BindField(R2.layout.mainActivity)
|
||||
@Anno(a1 = B.a1, a2 = B.a2, a3 = B.a3, a4 = B.a4, a5 = B.a5, a6 = B.a6, a7 = B.a7, a8 = B.a8, a9 = B.a9)
|
||||
val e = 0
|
||||
|
||||
@Bind(B.id.textView)
|
||||
@BindField(B.id.textView)
|
||||
val f = 0
|
||||
|
||||
@Bind(LibR.id.textView)
|
||||
fun foo() {}
|
||||
|
||||
|
||||
@@ -72,8 +72,84 @@ package app;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.FIELD})
|
||||
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.FIELD})
|
||||
public abstract @interface BindField {
|
||||
|
||||
public abstract int id();
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
package app;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class MyActivity {
|
||||
@BindField(id = lib.R.id.textView)
|
||||
private final int a = 0;
|
||||
@BindField(id = lib.R.id.textView)
|
||||
private final int b = 0;
|
||||
@BindField(id = app.R.layout.mainActivity)
|
||||
private final int c = 0;
|
||||
@BindField(id = app.R.layout.mainActivity)
|
||||
private final int d = 0;
|
||||
@BindField(id = app.R2.layout.mainActivity)
|
||||
private final int e = 0;
|
||||
@BindField(id = app.B.id.textView)
|
||||
private final int f = 0;
|
||||
|
||||
@Bind(id = lib.R.id.textView)
|
||||
public static void a$annotations() {
|
||||
}
|
||||
|
||||
public final int getA() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bind(id = lib.R.id.textView)
|
||||
public static void b$annotations() {
|
||||
}
|
||||
|
||||
public final int getB() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bind(id = app.R.layout.mainActivity)
|
||||
public static void c$annotations() {
|
||||
}
|
||||
|
||||
public final int getC() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bind(id = app.R.layout.mainActivity)
|
||||
public static void d$annotations() {
|
||||
}
|
||||
|
||||
public final int getD() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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)
|
||||
public static void e$annotations() {
|
||||
}
|
||||
|
||||
public final int getE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bind(id = app.B.id.textView)
|
||||
public static void f$annotations() {
|
||||
}
|
||||
|
||||
public final int getF() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bind(id = lib.R.id.textView)
|
||||
public final void foo() {
|
||||
|
||||
Reference in New Issue
Block a user