Skip to content

Commit 097c69f

Browse files
committed
Fix: Correctly store field annotations in FieldAnnotationsDescriptor
1 parent f667861 commit 097c69f

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

plugin/main/src/kotlinx/benchmark/gradle/AnnotationProcessor.kt

+35-15
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,54 @@ class AnnotationProcessor {
6464
?.map { parseAnnotation(it) }
6565
?: emptyList()
6666

67-
val methodDescriptors = classNode.methods
67+
val methodAnnotationsMap: Map<String, List<AnnotationData>> = classNode.methods
6868
.filterNot { it.name == "<init>" }
69+
.filter { methodNode ->
70+
methodNode.name.matches(Regex("^get[A-Z].*\\\$annotations\$")) &&
71+
methodNode.visibleAnnotations?.isNotEmpty() == true
72+
}
73+
.associate { methodNode ->
74+
val fieldName = methodNode.name
75+
.removePrefix("get")
76+
.removeSuffix("\$annotations")
77+
.decapitalize(Locale.ROOT)
78+
79+
val methodAnnotations = methodNode.visibleAnnotations
80+
?.filter { it.desc != "Lkotlin/Metadata;" }
81+
?.map { parseAnnotation(it) }
82+
?: emptyList()
83+
84+
fieldName to methodAnnotations
85+
}
86+
87+
val methodDescriptors = classNode.methods
6988
.filter { methodNode ->
7089
methodNode.visibleAnnotations?.any { it.desc != "Lkotlin/Metadata;" } == true
7190
}
91+
.filterNot { it.name == "<init>" }
92+
.filterNot { it.name.matches(Regex("^get[A-Z].*\\\$annotations\$")) }
7293
.map { methodNode ->
7394
val methodAnnotations = methodNode.visibleAnnotations
7495
?.filter { it.desc != "Lkotlin/Metadata;" }
7596
?.map { parseAnnotation(it) }
7697
?: emptyList()
7798
val parameters = Type.getArgumentTypes(methodNode.desc).map { it.className }
78-
// println("Method: ${methodNode.name}, Annotations: $methodAnnotations, Parameters: $parameters")
79-
// methodAnnotations.forEach { annotation ->
80-
// println("Annotation: ${annotation.name}")
81-
// annotation.parameters.forEach { (key, value) ->
82-
// println(" $key: $value")
83-
// }
84-
// }
8599
MethodAnnotationsDescriptor(
86100
methodNode.name,
87101
getVisibility(methodNode.access),
88102
methodAnnotations,
89-
parameters)
103+
parameters
104+
)
90105
}
91106

92107
val fieldDescriptors = classNode.fields.map { fieldNode ->
93-
val fieldAnnotations = fieldNode.visibleAnnotations
94-
?.filter { it.desc != "Lkotlin/Metadata;" }
95-
?.map { parseAnnotation(it) }
96-
?: emptyList()
97-
FieldAnnotationsDescriptor(fieldNode.name, getFieldVisibility(classNode, fieldNode), fieldAnnotations)
108+
val fieldAnnotations = methodAnnotationsMap.getOrDefault(fieldNode.name, emptyList())
109+
110+
FieldAnnotationsDescriptor(
111+
fieldNode.name,
112+
getFieldVisibility(classNode, fieldNode),
113+
fieldAnnotations
114+
)
98115
}
99116

100117
val packageName = classNode.name.substringBeforeLast('/', "").replace('/', '.')
@@ -112,7 +129,10 @@ class AnnotationProcessor {
112129
classAnnotationsDescriptors.add(classDescriptor)
113130
println("Class: ${classDescriptor.name}, Annotations: ${classDescriptor.annotations}")
114131
classDescriptor.methods.forEach { method ->
115-
println("Method: ${method.name}, Annotations: ${method.annotations},Annotation Parameters: ${method.parameters}")
132+
println("Method: ${method.name}, Annotations: ${method.annotations},Method Parameters: ${method.parameters}")
133+
}
134+
classDescriptor.fields.forEach { field ->
135+
println("Field: ${field.name}, Visibility: ${field.visibility}, Annotations: ${field.annotations}")
116136
}
117137
}
118138

0 commit comments

Comments
 (0)