Skip to content

Commit e329aa5

Browse files
committed
modify 'AnnotationProcessor' processing annotation data
1 parent 76e5fc1 commit e329aa5

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class AnnotationProcessor {
109109
)
110110

111111
classAnnotationsDescriptors.add(classDescriptor)
112-
println("Class: ${classDescriptor.name}")
112+
println("Class: ${classDescriptor.name}, Annotations: ${classDescriptor.annotations}")
113113
classDescriptor.methods.forEach { method ->
114-
println("Method: ${method.name}, Annotations: ${method.annotations}, Parameters: ${method.parameters}")
114+
println("Method: ${method.name}, Annotations: ${method.annotations},Annotation Parameters: ${method.parameters}")
115115
}
116116
}
117117

@@ -124,17 +124,37 @@ class AnnotationProcessor {
124124
parameters[name] = formatAnnotationValue(value)
125125
}
126126
}
127-
return AnnotationData(annotationNode.desc.removePrefix("L").removeSuffix(";").replace('/', '.'), parameters)
127+
return AnnotationData(formatDescriptor(annotationNode.desc), parameters)
128128
}
129129

130130
private fun formatAnnotationValue(value: Any?): Any? {
131131
return when (value) {
132-
is List<*> -> value.map { formatAnnotationValue(it) }
133-
is Array<*> -> value.map { formatAnnotationValue(it) }
132+
is List<*> -> value.flatMap {
133+
val formattedValue = formatAnnotationValue(it)
134+
if (formattedValue is List<*>) {
135+
formattedValue
136+
} else {
137+
listOf(formattedValue)
138+
}
139+
}
140+
is Array<*> -> value.flatMap {
141+
val formattedValue = formatAnnotationValue(it)
142+
if (formattedValue is List<*>) {
143+
formattedValue
144+
} else {
145+
listOf(formattedValue)
146+
}
147+
}
134148
is TypePath -> value.toString()
135149
is AnnotationNode -> formatAnnotationNode(value)
136-
is Type -> value.className
137-
is String -> value.replace("\"", "\\\"")
150+
is Type -> value.className.replace('/', '.')
151+
is String -> {
152+
if (value.startsWith("L") && value.endsWith(";")) {
153+
formatDescriptor(value)
154+
} else {
155+
value
156+
}
157+
}
138158
is ByteArray -> value.toList()
139159
is CharArray -> value.map { it.toString() }
140160
is ShortArray -> value.toList()
@@ -148,7 +168,7 @@ class AnnotationProcessor {
148168
}
149169

150170
private fun formatAnnotationNode(annotationNode: AnnotationNode): String {
151-
val sb = StringBuilder("@${annotationNode.desc}(")
171+
val sb = StringBuilder("@${formatDescriptor(annotationNode.desc)}(")
152172
annotationNode.values?.let { values ->
153173
for (i in values.indices step 2) {
154174
val name = values[i]
@@ -163,6 +183,10 @@ class AnnotationProcessor {
163183
return sb.toString()
164184
}
165185

186+
private fun formatDescriptor(descriptor: String): String {
187+
return descriptor.removePrefix("L").removeSuffix(";").replace('/', '.')
188+
}
189+
166190
private fun getVisibility(access: Int): Visibility {
167191
return when {
168192
(access and Opcodes.ACC_PUBLIC) != 0 -> Visibility.PUBLIC

0 commit comments

Comments
 (0)