Kapt3: Add property annotation holder methods to Java stubs (KT-13767)
This commit is contained in:
committed by
Yan Zhulanow
parent
e3db014c27
commit
5061bab794
+6
-1
@@ -218,9 +218,14 @@ class ClassFileToSourceStubConverter(
|
||||
}
|
||||
|
||||
private fun convertMethod(method: MethodNode, containingClass: ClassNode, packageFqName: String): JCMethodDecl? {
|
||||
if (isSynthetic(method.access)) return null
|
||||
val descriptor = kaptContext.origins[method]?.descriptor as? CallableDescriptor ?: return null
|
||||
|
||||
val isAnnotationHolderForProperty = descriptor is PropertyDescriptor && isSynthetic(method.access)
|
||||
&& isPrivate(method.access) && isStatic(method.access)
|
||||
&& method.name.endsWith("\$annotations")
|
||||
|
||||
if (isSynthetic(method.access) && !isAnnotationHolderForProperty) return null
|
||||
|
||||
val isOverridden = descriptor.overriddenDescriptors.isNotEmpty()
|
||||
val visibleAnnotations = if (isOverridden) {
|
||||
(method.visibleAnnotations ?: emptyList()) + AnnotationNode(Type.getType(Override::class.java).descriptor)
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
internal fun isEnum(access: Int) = (access and Opcodes.ACC_ENUM) != 0
|
||||
internal fun isPublic(access: Int) = (access and Opcodes.ACC_PUBLIC) != 0
|
||||
internal fun isSynthetic(access: Int) = (access and Opcodes.ACC_SYNTHETIC) != 0
|
||||
internal fun isPrivate(access: Int) = (access and Opcodes.ACC_PRIVATE) != 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
|
||||
|
||||
+6
@@ -180,6 +180,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAnnotations.kt")
|
||||
public void testPropertyAnnotations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/propertyAnnotations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("severalPackageParts.kt")
|
||||
public void testSeveralPackageParts() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/severalPackageParts.kt");
|
||||
|
||||
@@ -71,6 +71,10 @@ public final class TestAnno2 {
|
||||
java.lang.String param) {
|
||||
}
|
||||
|
||||
@Anno3(value = "property")
|
||||
private static void b$annotations() {
|
||||
}
|
||||
|
||||
@Anno3(value = "getter")
|
||||
public final java.lang.String getB() {
|
||||
return null;
|
||||
|
||||
@@ -17,8 +17,16 @@ public abstract class Test {
|
||||
@Anno(value = "abstract-method")
|
||||
public abstract java.lang.String abstractMethod();
|
||||
|
||||
@Anno(value = "abstract-val")
|
||||
private static void abstractVal$annotations() {
|
||||
}
|
||||
|
||||
public abstract java.lang.String getAbstractVal();
|
||||
|
||||
@Anno(value = "v-property")
|
||||
private static void v$annotations() {
|
||||
}
|
||||
|
||||
@Anno(value = "v-get")
|
||||
public final java.lang.String getV() {
|
||||
return null;
|
||||
@@ -71,6 +79,10 @@ public final class AnnotationsTest {
|
||||
java.lang.String $receiver) {
|
||||
}
|
||||
|
||||
@Anno(value = "top-level-val")
|
||||
private static void topLevelVal$annotations(int p0) {
|
||||
}
|
||||
|
||||
public static final java.lang.String getTopLevelVal(@Anno(value = "top-level-val-receiver")
|
||||
int $receiver) {
|
||||
return null;
|
||||
|
||||
@@ -25,6 +25,9 @@ public final class JvmStaticTest {
|
||||
|
||||
public static final class Companion {
|
||||
|
||||
private static void one$annotations() {
|
||||
}
|
||||
|
||||
public final int getOne() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public final class Test {
|
||||
|
||||
public static final class A {
|
||||
|
||||
private static void test$annotations() {
|
||||
}
|
||||
|
||||
public final java.lang.String getTest() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
annotation class Anno
|
||||
|
||||
class Test {
|
||||
@property:Anno
|
||||
val prop = "A"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public abstract @interface Anno {
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
public final class Test {
|
||||
private final java.lang.String prop = "A";
|
||||
|
||||
@Anno()
|
||||
private static void prop$annotations() {
|
||||
}
|
||||
|
||||
public final java.lang.String getProp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Test() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,10 @@ public final class TopLevelKt {
|
||||
java.lang.String b) {
|
||||
}
|
||||
|
||||
@Anno(value = "extpr")
|
||||
private static void extensionProperty$annotations(java.lang.Object p0) {
|
||||
}
|
||||
|
||||
public static final <T extends java.lang.Object>java.lang.String getExtensionProperty(@Anno(value = "propRec")
|
||||
T $receiver) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user