45
45
*/
46
46
abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
47
47
48
- protected final Log logger = LogFactory . getLog ( this . getClass ()) ;
48
+ protected final MetadataReaderLog logger ;
49
49
50
50
protected final AnnotationAttributes attributes ;
51
51
52
52
protected final ClassLoader classLoader ;
53
53
54
54
55
- public AbstractRecursiveAnnotationVisitor (ClassLoader classLoader , AnnotationAttributes attributes ) {
55
+ public AbstractRecursiveAnnotationVisitor (ClassLoader classLoader ,
56
+ AnnotationAttributes attributes , MetadataReaderLog logger ) {
56
57
super (SpringAsmInfo .ASM_VERSION );
57
58
this .classLoader = classLoader ;
58
59
this .attributes = attributes ;
60
+ this .logger = (logger == null ? new MetadataReaderLogAdapter () : logger );
59
61
}
60
62
61
63
@@ -67,11 +69,13 @@ public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDes
67
69
String annotationType = Type .getType (asmTypeDescriptor ).getClassName ();
68
70
AnnotationAttributes nestedAttributes = new AnnotationAttributes ();
69
71
this .attributes .put (attributeName , nestedAttributes );
70
- return new RecursiveAnnotationAttributesVisitor (annotationType , nestedAttributes , this .classLoader );
72
+ return new RecursiveAnnotationAttributesVisitor (annotationType , nestedAttributes ,
73
+ this .classLoader , this .logger );
71
74
}
72
75
73
76
public AnnotationVisitor visitArray (String attributeName ) {
74
- return new RecursiveAnnotationArrayVisitor (attributeName , this .attributes , this .classLoader );
77
+ return new RecursiveAnnotationArrayVisitor (attributeName , this .attributes ,
78
+ this .classLoader , this .logger );
75
79
}
76
80
77
81
public void visitEnum (String attributeName , String asmTypeDescriptor , String attributeValue ) {
@@ -84,10 +88,10 @@ public void visitEnum(String attributeName, String asmTypeDescriptor, String att
84
88
}
85
89
}
86
90
catch (ClassNotFoundException ex ) {
87
- this .logger .debug ("Failed to classload enum type while reading annotation metadata" , ex );
91
+ this .logger .log ("Failed to classload enum type while reading annotation metadata" , ex );
88
92
}
89
93
catch (IllegalAccessException ex ) {
90
- this .logger .warn ("Could not access enum value while reading annotation metadata" , ex );
94
+ this .logger .log ("Could not access enum value while reading annotation metadata" , ex );
91
95
}
92
96
this .attributes .put (attributeName , valueToUse );
93
97
}
@@ -106,9 +110,10 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
106
110
private final List <AnnotationAttributes > allNestedAttributes = new ArrayList <AnnotationAttributes >();
107
111
108
112
109
- public RecursiveAnnotationArrayVisitor (
110
- String attributeName , AnnotationAttributes attributes , ClassLoader classLoader ) {
111
- super (classLoader , attributes );
113
+ public RecursiveAnnotationArrayVisitor (String attributeName ,
114
+ AnnotationAttributes attributes , ClassLoader classLoader ,
115
+ MetadataReaderLog logger ) {
116
+ super (classLoader , attributes , logger );
112
117
this .attributeName = attributeName ;
113
118
}
114
119
@@ -132,7 +137,8 @@ public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDes
132
137
String annotationType = Type .getType (asmTypeDescriptor ).getClassName ();
133
138
AnnotationAttributes nestedAttributes = new AnnotationAttributes ();
134
139
this .allNestedAttributes .add (nestedAttributes );
135
- return new RecursiveAnnotationAttributesVisitor (annotationType , nestedAttributes , this .classLoader );
140
+ return new RecursiveAnnotationAttributesVisitor (annotationType , nestedAttributes ,
141
+ this .classLoader , this .logger );
136
142
}
137
143
138
144
public void visitEnd () {
@@ -154,9 +160,10 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
154
160
private final String annotationType ;
155
161
156
162
157
- public RecursiveAnnotationAttributesVisitor (
158
- String annotationType , AnnotationAttributes attributes , ClassLoader classLoader ) {
159
- super (classLoader , attributes );
163
+ public RecursiveAnnotationAttributesVisitor (String annotationType ,
164
+ AnnotationAttributes attributes , ClassLoader classLoader ,
165
+ MetadataReaderLog logger ) {
166
+ super (classLoader , attributes , logger );
160
167
this .annotationType = annotationType ;
161
168
}
162
169
@@ -167,7 +174,7 @@ public final void visitEnd() {
167
174
this .doVisitEnd (annotationClass );
168
175
}
169
176
catch (ClassNotFoundException ex ) {
170
- this .logger .debug ("Failed to classload type while reading annotation " +
177
+ this .logger .log ("Failed to classload type while reading annotation " +
171
178
"metadata. This is a non-fatal error, but certain annotation " +
172
179
"metadata may be unavailable." , ex );
173
180
}
@@ -226,11 +233,11 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
226
233
private final Map <String , Set <String >> metaAnnotationMap ;
227
234
228
235
229
- public AnnotationAttributesReadingVisitor (
230
- String annotationType , MultiValueMap <String , AnnotationAttributes > attributesMap ,
231
- Map <String , Set <String >> metaAnnotationMap , ClassLoader classLoader ) {
232
-
233
- super (annotationType , new AnnotationAttributes (), classLoader );
236
+ public AnnotationAttributesReadingVisitor (String annotationType ,
237
+ MultiValueMap <String , AnnotationAttributes > attributesMap ,
238
+ Map <String , Set <String >> metaAnnotationMap , ClassLoader classLoader ,
239
+ MetadataReaderLog logger ) {
240
+ super (annotationType , new AnnotationAttributes (), classLoader , logger );
234
241
this .annotationType = annotationType ;
235
242
this .attributesMap = attributesMap ;
236
243
this .metaAnnotationMap = metaAnnotationMap ;
@@ -267,3 +274,14 @@ private void recusivelyCollectMetaAnnotations(Set<String> visited, Annotation an
267
274
}
268
275
}
269
276
}
277
+
278
+
279
+ class MetadataReaderLogAdapter implements MetadataReaderLog {
280
+
281
+ private Log logger = LogFactory .getLog (AnnotationAttributesReadingVisitor .class );
282
+
283
+ @ Override
284
+ public void log (String message , Throwable t ) {
285
+ logger .debug (message , t );
286
+ }
287
+ }
0 commit comments