@@ -47,22 +47,22 @@ public class MethodParameter {
4747
4848 private final int parameterIndex ;
4949
50- private Class <?> containingClass ;
50+ private int nestingLevel = 1 ;
5151
52- private Class <?> parameterType ;
52+ /** Map from Integer level to Integer type index */
53+ Map <Integer , Integer > typeIndexesPerLevel ;
5354
54- private Type genericParameterType ;
55+ private volatile Class <?> containingClass ;
5556
56- private Annotation [] parameterAnnotations ;
57+ private volatile Class <?> parameterType ;
5758
58- private ParameterNameDiscoverer parameterNameDiscoverer ;
59+ private volatile Type genericParameterType ;
5960
60- private String parameterName ;
61+ private volatile Annotation [] parameterAnnotations ;
6162
62- private int nestingLevel = 1 ;
63+ private volatile ParameterNameDiscoverer parameterNameDiscoverer ;
6364
64- /** Map from Integer level to Integer type index */
65- Map <Integer , Integer > typeIndexesPerLevel ;
65+ private volatile String parameterName ;
6666
6767
6868 /**
@@ -203,6 +203,73 @@ public int getParameterIndex() {
203203 return this .parameterIndex ;
204204 }
205205
206+ /**
207+ * Increase this parameter's nesting level.
208+ * @see #getNestingLevel()
209+ */
210+ public void increaseNestingLevel () {
211+ this .nestingLevel ++;
212+ }
213+
214+ /**
215+ * Decrease this parameter's nesting level.
216+ * @see #getNestingLevel()
217+ */
218+ public void decreaseNestingLevel () {
219+ getTypeIndexesPerLevel ().remove (this .nestingLevel );
220+ this .nestingLevel --;
221+ }
222+
223+ /**
224+ * Return the nesting level of the target type
225+ * (typically 1; e.g. in case of a List of Lists, 1 would indicate the
226+ * nested List, whereas 2 would indicate the element of the nested List).
227+ */
228+ public int getNestingLevel () {
229+ return this .nestingLevel ;
230+ }
231+
232+ /**
233+ * Set the type index for the current nesting level.
234+ * @param typeIndex the corresponding type index
235+ * (or {@code null} for the default type index)
236+ * @see #getNestingLevel()
237+ */
238+ public void setTypeIndexForCurrentLevel (int typeIndex ) {
239+ getTypeIndexesPerLevel ().put (this .nestingLevel , typeIndex );
240+ }
241+
242+ /**
243+ * Return the type index for the current nesting level.
244+ * @return the corresponding type index, or {@code null}
245+ * if none specified (indicating the default type index)
246+ * @see #getNestingLevel()
247+ */
248+ public Integer getTypeIndexForCurrentLevel () {
249+ return getTypeIndexForLevel (this .nestingLevel );
250+ }
251+
252+ /**
253+ * Return the type index for the specified nesting level.
254+ * @param nestingLevel the nesting level to check
255+ * @return the corresponding type index, or {@code null}
256+ * if none specified (indicating the default type index)
257+ */
258+ public Integer getTypeIndexForLevel (int nestingLevel ) {
259+ return getTypeIndexesPerLevel ().get (nestingLevel );
260+ }
261+
262+ /**
263+ * Obtain the (lazily constructed) type-indexes-per-level Map.
264+ */
265+ private Map <Integer , Integer > getTypeIndexesPerLevel () {
266+ if (this .typeIndexesPerLevel == null ) {
267+ this .typeIndexesPerLevel = new HashMap <Integer , Integer >(4 );
268+ }
269+ return this .typeIndexesPerLevel ;
270+ }
271+
272+
206273 /**
207274 * Set a containing class to resolve the parameter type against.
208275 */
@@ -364,10 +431,10 @@ public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDisc
364431 * has been set to begin with)
365432 */
366433 public String getParameterName () {
367- if (this .parameterNameDiscoverer != null ) {
434+ ParameterNameDiscoverer discoverer = this .parameterNameDiscoverer ;
435+ if (discoverer != null ) {
368436 String [] parameterNames = (this .method != null ?
369- this .parameterNameDiscoverer .getParameterNames (this .method ) :
370- this .parameterNameDiscoverer .getParameterNames (this .constructor ));
437+ discoverer .getParameterNames (this .method ) : discoverer .getParameterNames (this .constructor ));
371438 if (parameterNames != null ) {
372439 this .parameterName = parameterNames [this .parameterIndex ];
373440 }
@@ -376,82 +443,17 @@ public String getParameterName() {
376443 return this .parameterName ;
377444 }
378445
379- /**
380- * Increase this parameter's nesting level.
381- * @see #getNestingLevel()
382- */
383- public void increaseNestingLevel () {
384- this .nestingLevel ++;
385- }
386-
387- /**
388- * Decrease this parameter's nesting level.
389- * @see #getNestingLevel()
390- */
391- public void decreaseNestingLevel () {
392- getTypeIndexesPerLevel ().remove (this .nestingLevel );
393- this .nestingLevel --;
394- }
395-
396- /**
397- * Return the nesting level of the target type
398- * (typically 1; e.g. in case of a List of Lists, 1 would indicate the
399- * nested List, whereas 2 would indicate the element of the nested List).
400- */
401- public int getNestingLevel () {
402- return this .nestingLevel ;
403- }
404-
405- /**
406- * Set the type index for the current nesting level.
407- * @param typeIndex the corresponding type index
408- * (or {@code null} for the default type index)
409- * @see #getNestingLevel()
410- */
411- public void setTypeIndexForCurrentLevel (int typeIndex ) {
412- getTypeIndexesPerLevel ().put (this .nestingLevel , typeIndex );
413- }
414-
415- /**
416- * Return the type index for the current nesting level.
417- * @return the corresponding type index, or {@code null}
418- * if none specified (indicating the default type index)
419- * @see #getNestingLevel()
420- */
421- public Integer getTypeIndexForCurrentLevel () {
422- return getTypeIndexForLevel (this .nestingLevel );
423- }
424-
425- /**
426- * Return the type index for the specified nesting level.
427- * @param nestingLevel the nesting level to check
428- * @return the corresponding type index, or {@code null}
429- * if none specified (indicating the default type index)
430- */
431- public Integer getTypeIndexForLevel (int nestingLevel ) {
432- return getTypeIndexesPerLevel ().get (nestingLevel );
433- }
434-
435- /**
436- * Obtain the (lazily constructed) type-indexes-per-level Map.
437- */
438- private Map <Integer , Integer > getTypeIndexesPerLevel () {
439- if (this .typeIndexesPerLevel == null ) {
440- this .typeIndexesPerLevel = new HashMap <Integer , Integer >(4 );
441- }
442- return this .typeIndexesPerLevel ;
443- }
444446
445447 @ Override
446- public boolean equals (Object obj ) {
447- if (this == obj ) {
448+ public boolean equals (Object other ) {
449+ if (this == other ) {
448450 return true ;
449451 }
450- if (obj != null && obj instanceof MethodParameter ) {
451- MethodParameter other = (MethodParameter ) obj ;
452- return (this .parameterIndex == other .parameterIndex && getMember ().equals (other .getMember ()));
452+ if (!(other instanceof MethodParameter )) {
453+ return false ;
453454 }
454- return false ;
455+ MethodParameter otherParam = (MethodParameter ) other ;
456+ return (this .parameterIndex == otherParam .parameterIndex && getMember ().equals (otherParam .getMember ()));
455457 }
456458
457459 @ Override
0 commit comments