Skip to content

Commit e94c691

Browse files
committed
AbstractAspectJAdvisorFactory uses AnnotationUtils.getValue
1 parent c69fdfa commit e94c691

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected enum AspectJAnnotationType {
169169
*/
170170
protected static class AspectJAnnotation<A extends Annotation> {
171171

172-
private static final String[] EXPRESSION_PROPERTIES = new String[] {"value", "pointcut"};
172+
private static final String[] EXPRESSION_ATTRIBUTES = new String[] {"pointcut", "value"};
173173

174174
private static Map<Class<?>, AspectJAnnotationType> annotationTypeMap =
175175
new HashMap<Class<?>, AspectJAnnotationType>(8);
@@ -198,36 +198,29 @@ public AspectJAnnotation(A annotation) {
198198
// but need to invoke them reflectively as there isn't a common interface.
199199
try {
200200
this.pointcutExpression = resolveExpression(annotation);
201-
this.argumentNames = (String) annotation.getClass().getMethod("argNames").invoke(annotation);
201+
this.argumentNames = (String) AnnotationUtils.getValue(annotation, "argNames");
202202
}
203203
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);
205205
}
206206
}
207207

208208
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;
213212
}
214-
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
213+
throw new IllegalStateException("Unknown annotation type: " + annotation);
215214
}
216215

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;
228221
}
229222
}
230-
return expression;
223+
throw new IllegalStateException("Failed to resolve expression: " + annotation);
231224
}
232225

233226
public AspectJAnnotationType getAnnotationType() {

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,9 @@ public static Object getValue(Annotation annotation, String attributeName) {
13701370
ReflectionUtils.makeAccessible(method);
13711371
return method.invoke(annotation);
13721372
}
1373+
catch (NoSuchMethodException ex) {
1374+
return null;
1375+
}
13731376
catch (InvocationTargetException ex) {
13741377
rethrowAnnotationConfigurationException(ex.getTargetException());
13751378
throw new IllegalStateException(

0 commit comments

Comments
 (0)