1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
38
38
* for an advice method from the pointcut expression, returning, and throwing clauses.
39
39
* If an unambiguous interpretation is not available, it returns {@code null}.
40
40
*
41
+ * <h3>Algorithm Summary</h3>
42
+ * <p>If an unambiguous binding can be deduced, then it is.
43
+ * If the advice requirements cannot possibly be satisfied, then {@code null}
44
+ * is returned. By setting the {@link #setRaiseExceptions(boolean) raiseExceptions}
45
+ * property to {@code true}, descriptive exceptions will be thrown instead of
46
+ * returning {@code null} in the case that the parameter names cannot be discovered.
47
+ *
48
+ * <h3>Algorithm Details</h3>
41
49
* <p>This class interprets arguments in the following way:
42
50
* <ol>
43
51
* <li>If the first parameter of the method is of type {@link JoinPoint}
65
73
* zero we proceed to the next stage. If {@code a} > 1 then an
66
74
* {@code AmbiguousBindingException} is raised. If {@code a} == 1,
67
75
* and there are no unbound arguments of type {@code Annotation+},
68
- * then an {@code IllegalArgumentException} is raised. if there is
76
+ * then an {@code IllegalArgumentException} is raised. If there is
69
77
* exactly one such argument, then the corresponding parameter name is
70
78
* assigned the value from the pointcut expression.</li>
71
- * <li>If a returningName has been set, and there are no unbound arguments
79
+ * <li>If a {@code returningName} has been set, and there are no unbound arguments
72
80
* then an {@code IllegalArgumentException} is raised. If there is
73
81
* more than one unbound argument then an
74
82
* {@code AmbiguousBindingException} is raised. If there is exactly
75
83
* one unbound argument then the corresponding parameter name is assigned
76
- * the value < returningName> .</li>
84
+ * the value of the {@code returningName} .</li>
77
85
* <li>If there remain unbound arguments, then the pointcut expression is
78
86
* examined once more for {@code this}, {@code target}, and
79
87
* {@code args} pointcut expressions used in the binding form (binding
99
107
* <p>The behavior on raising an {@code IllegalArgumentException} or
100
108
* {@code AmbiguousBindingException} is configurable to allow this discoverer
101
109
* to be used as part of a chain-of-responsibility. By default the condition will
102
- * be logged and the {@code getParameterNames(.. )} method will simply return
110
+ * be logged and the {@link # getParameterNames(Method )} method will simply return
103
111
* {@code null}. If the {@link #setRaiseExceptions(boolean) raiseExceptions}
104
112
* property is set to {@code true}, the conditions will be thrown as
105
113
* {@code IllegalArgumentException} and {@code AmbiguousBindingException},
106
114
* respectively.
107
115
*
108
- * <p>Was that perfectly clear? ;)
109
- *
110
- * <p>Short version: If an unambiguous binding can be deduced, then it is.
111
- * If the advice requirements cannot possibly be satisfied, then {@code null}
112
- * is returned. By setting the {@link #setRaiseExceptions(boolean) raiseExceptions}
113
- * property to {@code true}, descriptive exceptions will be thrown instead of
114
- * returning {@code null} in the case that the parameter names cannot be discovered.
115
- *
116
116
* @author Adrian Colyer
117
117
* @author Juergen Hoeller
118
118
* @since 2.0
@@ -158,7 +158,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
158
158
159
159
/** The pointcut expression associated with the advice, as a simple String. */
160
160
@ Nullable
161
- private String pointcutExpression ;
161
+ private final String pointcutExpression ;
162
162
163
163
private boolean raiseExceptions ;
164
164
@@ -197,7 +197,7 @@ public void setRaiseExceptions(boolean raiseExceptions) {
197
197
198
198
/**
199
199
* If {@code afterReturning} advice binds the return value, the
200
- * returning variable name must be specified.
200
+ * {@code returning} variable name must be specified.
201
201
* @param returningName the name of the returning variable
202
202
*/
203
203
public void setReturningName (@ Nullable String returningName ) {
@@ -206,18 +206,17 @@ public void setReturningName(@Nullable String returningName) {
206
206
207
207
/**
208
208
* If {@code afterThrowing} advice binds the thrown value, the
209
- * throwing variable name must be specified.
209
+ * {@code throwing} variable name must be specified.
210
210
* @param throwingName the name of the throwing variable
211
211
*/
212
212
public void setThrowingName (@ Nullable String throwingName ) {
213
213
this .throwingName = throwingName ;
214
214
}
215
215
216
-
217
216
/**
218
217
* Deduce the parameter names for an advice method.
219
- * <p>See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
220
- * for this class for details of the algorithm used.
218
+ * <p>See the {@link AspectJAdviceParameterNameDiscoverer class- level javadoc}
219
+ * for this class for details on the algorithm used.
221
220
* @param method the target {@link Method}
222
221
* @return the parameter names
223
222
*/
@@ -316,13 +315,13 @@ public String[] getParameterNames(Constructor<?> ctor) {
316
315
}
317
316
318
317
319
- private void bindParameterName (int index , String name ) {
318
+ private void bindParameterName (int index , @ Nullable String name ) {
320
319
this .parameterNameBindings [index ] = name ;
321
320
this .numberOfRemainingUnboundArguments --;
322
321
}
323
322
324
323
/**
325
- * If the first parameter is of type JoinPoint or ProceedingJoinPoint,bind "thisJoinPoint" as
324
+ * If the first parameter is of type JoinPoint or ProceedingJoinPoint, bind "thisJoinPoint" as
326
325
* parameter name and return true, else return false.
327
326
*/
328
327
private boolean maybeBindThisJoinPoint () {
@@ -367,8 +366,8 @@ private void maybeBindThrowingVariable() {
367
366
}
368
367
369
368
if (throwableIndex == -1 ) {
370
- throw new IllegalStateException ("Binding of throwing parameter '" + this .throwingName
371
- + "' could not be completed as no available arguments are a subtype of Throwable" );
369
+ throw new IllegalStateException ("Binding of throwing parameter '" + this .throwingName +
370
+ "' could not be completed as no available arguments are a subtype of Throwable" );
372
371
}
373
372
else {
374
373
bindParameterName (throwableIndex , this .throwingName );
@@ -400,7 +399,6 @@ private void maybeBindReturningVariable() {
400
399
}
401
400
}
402
401
403
-
404
402
/**
405
403
* Parse the string pointcut expression looking for:
406
404
* @this, @target, @args, @within, @withincode, @annotation.
@@ -465,7 +463,7 @@ else if (numAnnotationSlots == 1) {
465
463
}
466
464
}
467
465
468
- /*
466
+ /**
469
467
* If the token starts meets Java identifier conventions, it's in.
470
468
*/
471
469
@ Nullable
@@ -533,7 +531,6 @@ else if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
533
531
}
534
532
}
535
533
536
-
537
534
if (varNames .size () > 1 ) {
538
535
throw new AmbiguousBindingException ("Found " + varNames .size () +
539
536
" candidate this(), target() or args() variables but only one unbound argument slot" );
@@ -609,7 +606,7 @@ else if (varNames.size() == 1) {
609
606
// else varNames.size must be 0 and we have nothing to bind.
610
607
}
611
608
612
- /*
609
+ /**
613
610
* We've found the start of a binding pointcut at the given index into the
614
611
* token array. Now we need to extract the pointcut body and return it.
615
612
*/
@@ -709,7 +706,7 @@ private boolean alreadyBound(String varName) {
709
706
return false ;
710
707
}
711
708
712
- /*
709
+ /**
713
710
* Return {@code true} if the given argument type is a subclass
714
711
* of the given supertype.
715
712
*/
@@ -737,7 +734,7 @@ private int countNumberOfUnboundPrimitiveArguments() {
737
734
return count ;
738
735
}
739
736
740
- /*
737
+ /**
741
738
* Find the argument index with the given type, and bind the given
742
739
* {@code varName} in that position.
743
740
*/
0 commit comments