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 9f230fe2975..799f358119a 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -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) diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt index bd242026e25..71298820e19 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/util/asmUtils.kt @@ -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 diff --git a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index 9e115d389cc..afe5bd1e6de 100644 --- a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -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"); diff --git a/plugins/kapt3/testData/converter/annotations.txt b/plugins/kapt3/testData/converter/annotations.txt index 750b7483a06..dcf0af76847 100644 --- a/plugins/kapt3/testData/converter/annotations.txt +++ b/plugins/kapt3/testData/converter/annotations.txt @@ -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; diff --git a/plugins/kapt3/testData/converter/annotations2.txt b/plugins/kapt3/testData/converter/annotations2.txt index 70ddf050bf0..ebce7a85339 100644 --- a/plugins/kapt3/testData/converter/annotations2.txt +++ b/plugins/kapt3/testData/converter/annotations2.txt @@ -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; diff --git a/plugins/kapt3/testData/converter/jvmStatic.txt b/plugins/kapt3/testData/converter/jvmStatic.txt index c9a476738aa..7c676f2dd80 100644 --- a/plugins/kapt3/testData/converter/jvmStatic.txt +++ b/plugins/kapt3/testData/converter/jvmStatic.txt @@ -25,6 +25,9 @@ public final class JvmStaticTest { public static final class Companion { + private static void one$annotations() { + } + public final int getOne() { return 0; } diff --git a/plugins/kapt3/testData/converter/jvmStaticFieldInParent.txt b/plugins/kapt3/testData/converter/jvmStaticFieldInParent.txt index 0396e053a98..bcd73a4b1aa 100644 --- a/plugins/kapt3/testData/converter/jvmStaticFieldInParent.txt +++ b/plugins/kapt3/testData/converter/jvmStaticFieldInParent.txt @@ -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; } diff --git a/plugins/kapt3/testData/converter/propertyAnnotations.kt b/plugins/kapt3/testData/converter/propertyAnnotations.kt new file mode 100644 index 00000000000..8acf49667ea --- /dev/null +++ b/plugins/kapt3/testData/converter/propertyAnnotations.kt @@ -0,0 +1,6 @@ +annotation class Anno + +class Test { + @property:Anno + 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 new file mode 100644 index 00000000000..852b3477fd3 --- /dev/null +++ b/plugins/kapt3/testData/converter/propertyAnnotations.txt @@ -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(); + } +} diff --git a/plugins/kapt3/testData/converter/topLevel.txt b/plugins/kapt3/testData/converter/topLevel.txt index 53901271040..ae17a91a529 100644 --- a/plugins/kapt3/testData/converter/topLevel.txt +++ b/plugins/kapt3/testData/converter/topLevel.txt @@ -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 java.lang.String getExtensionProperty(@Anno(value = "propRec") T $receiver) { return null;