@@ -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 */
@@ -362,10 +429,10 @@ public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDisc
362429 * has been set to begin with)
363430 */
364431 public String getParameterName () {
365- if (this .parameterNameDiscoverer != null ) {
432+ ParameterNameDiscoverer discoverer = this .parameterNameDiscoverer ;
433+ if (discoverer != null ) {
366434 String [] parameterNames = (this .method != null ?
367- this .parameterNameDiscoverer .getParameterNames (this .method ) :
368- this .parameterNameDiscoverer .getParameterNames (this .constructor ));
435+ discoverer .getParameterNames (this .method ) : discoverer .getParameterNames (this .constructor ));
369436 if (parameterNames != null ) {
370437 this .parameterName = parameterNames [this .parameterIndex ];
371438 }
@@ -374,82 +441,17 @@ public String getParameterName() {
374441 return this .parameterName ;
375442 }
376443
377- /**
378- * Increase this parameter's nesting level.
379- * @see #getNestingLevel()
380- */
381- public void increaseNestingLevel () {
382- this .nestingLevel ++;
383- }
384-
385- /**
386- * Decrease this parameter's nesting level.
387- * @see #getNestingLevel()
388- */
389- public void decreaseNestingLevel () {
390- getTypeIndexesPerLevel ().remove (this .nestingLevel );
391- this .nestingLevel --;
392- }
393-
394- /**
395- * Return the nesting level of the target type
396- * (typically 1; e.g. in case of a List of Lists, 1 would indicate the
397- * nested List, whereas 2 would indicate the element of the nested List).
398- */
399- public int getNestingLevel () {
400- return this .nestingLevel ;
401- }
402-
403- /**
404- * Set the type index for the current nesting level.
405- * @param typeIndex the corresponding type index
406- * (or {@code null} for the default type index)
407- * @see #getNestingLevel()
408- */
409- public void setTypeIndexForCurrentLevel (int typeIndex ) {
410- getTypeIndexesPerLevel ().put (this .nestingLevel , typeIndex );
411- }
412-
413- /**
414- * Return the type index for the current nesting level.
415- * @return the corresponding type index, or {@code null}
416- * if none specified (indicating the default type index)
417- * @see #getNestingLevel()
418- */
419- public Integer getTypeIndexForCurrentLevel () {
420- return getTypeIndexForLevel (this .nestingLevel );
421- }
422-
423- /**
424- * Return the type index for the specified nesting level.
425- * @param nestingLevel the nesting level to check
426- * @return the corresponding type index, or {@code null}
427- * if none specified (indicating the default type index)
428- */
429- public Integer getTypeIndexForLevel (int nestingLevel ) {
430- return getTypeIndexesPerLevel ().get (nestingLevel );
431- }
432-
433- /**
434- * Obtain the (lazily constructed) type-indexes-per-level Map.
435- */
436- private Map <Integer , Integer > getTypeIndexesPerLevel () {
437- if (this .typeIndexesPerLevel == null ) {
438- this .typeIndexesPerLevel = new HashMap <Integer , Integer >(4 );
439- }
440- return this .typeIndexesPerLevel ;
441- }
442444
443445 @ Override
444- public boolean equals (Object obj ) {
445- if (this == obj ) {
446+ public boolean equals (Object other ) {
447+ if (this == other ) {
446448 return true ;
447449 }
448- if (obj != null && obj instanceof MethodParameter ) {
449- MethodParameter other = (MethodParameter ) obj ;
450- return (this .parameterIndex == other .parameterIndex && getMember ().equals (other .getMember ()));
450+ if (!(other instanceof MethodParameter )) {
451+ return false ;
451452 }
452- return false ;
453+ MethodParameter otherParam = (MethodParameter ) other ;
454+ return (this .parameterIndex == otherParam .parameterIndex && getMember ().equals (otherParam .getMember ()));
453455 }
454456
455457 @ Override
0 commit comments