@@ -169,7 +169,7 @@ protected enum AspectJAnnotationType {
169
169
*/
170
170
protected static class AspectJAnnotation <A extends Annotation > {
171
171
172
- private static final String [] EXPRESSION_PROPERTIES = new String [] {"value " , "pointcut " };
172
+ private static final String [] EXPRESSION_ATTRIBUTES = new String [] {"pointcut " , "value " };
173
173
174
174
private static Map <Class <?>, AspectJAnnotationType > annotationTypeMap =
175
175
new HashMap <Class <?>, AspectJAnnotationType >(8 );
@@ -198,36 +198,29 @@ public AspectJAnnotation(A annotation) {
198
198
// but need to invoke them reflectively as there isn't a common interface.
199
199
try {
200
200
this .pointcutExpression = resolveExpression (annotation );
201
- this .argumentNames = (String ) annotation . getClass (). getMethod ( "argNames" ). invoke ( annotation );
201
+ this .argumentNames = (String ) AnnotationUtils . getValue ( annotation , "argNames" );
202
202
}
203
203
catch (Exception ex ) {
204
- throw new IllegalArgumentException (annotation + " cannot be an AspectJ annotation" , ex );
204
+ throw new IllegalArgumentException (annotation + " is not a valid AspectJ annotation" , ex );
205
205
}
206
206
}
207
207
208
208
private AspectJAnnotationType determineAnnotationType (A annotation ) {
209
- for (Class <?> type : annotationTypeMap .keySet ()) {
210
- if (type .isInstance (annotation )) {
211
- return annotationTypeMap .get (type );
212
- }
209
+ AspectJAnnotationType type = annotationTypeMap .get (annotation .annotationType ());
210
+ if (type != null ) {
211
+ return type ;
213
212
}
214
- throw new IllegalStateException ("Unknown annotation type: " + annotation . toString () );
213
+ throw new IllegalStateException ("Unknown annotation type: " + annotation );
215
214
}
216
215
217
- private String resolveExpression (A annotation ) throws Exception {
218
- String expression = null ;
219
- for (String methodName : EXPRESSION_PROPERTIES ) {
220
- try {
221
- Method method = annotation .getClass ().getDeclaredMethod (methodName );
222
- String candidate = (String ) method .invoke (annotation );
223
- if (StringUtils .hasText (candidate )) {
224
- expression = candidate ;
225
- }
226
- }
227
- catch (NoSuchMethodException ex ) {
216
+ private String resolveExpression (A annotation ) {
217
+ for (String attributeName : EXPRESSION_ATTRIBUTES ) {
218
+ String candidate = (String ) AnnotationUtils .getValue (annotation , attributeName );
219
+ if (StringUtils .hasText (candidate )) {
220
+ return candidate ;
228
221
}
229
222
}
230
- return expression ;
223
+ throw new IllegalStateException ( "Failed to resolve expression: " + annotation ) ;
231
224
}
232
225
233
226
public AspectJAnnotationType getAnnotationType () {
0 commit comments