@@ -8,29 +8,37 @@ data class AnnotationData(
8
8
val parameters : Map <String , Any ?>
9
9
)
10
10
11
+ data class ClassAnnotations (
12
+ val classAnnotations : Map <String , AnnotationData >,
13
+ val methodAnnotations : Map <String , Map <String , AnnotationData >>,
14
+ val fieldAnnotations : Map <String , Map <String , AnnotationData >>
15
+ )
16
+
11
17
class AnnotationProcessor {
12
18
13
- private val classAnnotations = mutableMapOf<String , MutableMap < String , AnnotationData > >()
19
+ private val classAnnotationsMap = mutableMapOf<String , ClassAnnotations >()
14
20
15
21
fun processClassFile (classFile : File ) {
16
22
val classReader = ClassReader (classFile.readBytes())
17
23
val classNode = ClassNode ()
18
24
classReader.accept(classNode, 0 )
19
25
20
- val annotations = mutableMapOf<String , AnnotationData >()
26
+ val classAnnotations = mutableMapOf<String , AnnotationData >()
27
+ val methodAnnotations = mutableMapOf<String , MutableMap <String , AnnotationData >>()
28
+ val fieldAnnotations = mutableMapOf<String , MutableMap <String , AnnotationData >>()
21
29
22
30
classNode.visibleAnnotations?.forEach { annotationNode ->
23
31
if (annotationNode.desc != " Lkotlin/Metadata;" ) {
24
32
val annotationData = parseAnnotation(annotationNode)
25
- annotations [annotationNode.desc] = annotationData
33
+ classAnnotations [annotationNode.desc] = annotationData
26
34
}
27
35
}
28
36
29
37
classNode.methods?.forEach { methodNode ->
30
38
methodNode.visibleAnnotations?.forEach { annotationNode ->
31
39
if (annotationNode.desc != " Lkotlin/Metadata;" ) {
32
40
val annotationData = parseAnnotation(annotationNode)
33
- annotations [annotationNode.desc] = annotationData
41
+ methodAnnotations.getOrPut(methodNode.name) { mutableMapOf () } [annotationNode.desc] = annotationData
34
42
}
35
43
}
36
44
}
@@ -39,12 +47,12 @@ class AnnotationProcessor {
39
47
fieldNode.visibleAnnotations?.forEach { annotationNode ->
40
48
if (annotationNode.desc != " Lkotlin/Metadata;" ) {
41
49
val annotationData = parseAnnotation(annotationNode)
42
- annotations [annotationNode.desc] = annotationData
50
+ fieldAnnotations.getOrPut(fieldNode.name) { mutableMapOf () } [annotationNode.desc] = annotationData
43
51
}
44
52
}
45
53
}
46
54
47
- classAnnotations [classNode.name] = annotations
55
+ classAnnotationsMap [classNode.name] = ClassAnnotations (classAnnotations, methodAnnotations, fieldAnnotations)
48
56
}
49
57
50
58
private fun parseAnnotation (annotationNode : AnnotationNode ): AnnotationData {
@@ -95,7 +103,7 @@ class AnnotationProcessor {
95
103
return sb.toString()
96
104
}
97
105
98
- fun getClassAnnotations (): Map <String , Map < String , AnnotationData > > {
99
- return classAnnotations
106
+ fun getClassAnnotations (): Map <String , ClassAnnotations > {
107
+ return classAnnotationsMap
100
108
}
101
109
}
0 commit comments