2222
2323import java .lang .annotation .Annotation ;
2424import java .lang .reflect .Method ;
25+ import java .lang .reflect .Parameter ;
2526
2627import static com .google .common .base .Preconditions .checkState ;
2728
3132 */
3233public class IntrospectorSupport {
3334
34- protected static <T extends Annotation > T getParameterAnnotation (Method method , int parameterIndex , Class <T > annotationClass ) {
35- for (Annotation annotation : method . getParameterAnnotations ()[ parameterIndex ] ) {
35+ protected static <T extends Annotation > T getParameterAnnotation (Parameter parameter , Class <T > annotationClass ) {
36+ for (Annotation annotation : parameter . getAnnotations () ) {
3637 if (annotation .annotationType () == annotationClass ) {
3738 @ SuppressWarnings ("unchecked" ) T annotation1 = (T ) annotation ;
3839 return annotation1 ;
@@ -42,8 +43,8 @@ protected static <T extends Annotation> T getParameterAnnotation(Method method,
4243 return null ;
4344 }
4445
45- protected static <T extends Annotation > boolean hasParameterAnnotation (Method method , int parameterIndex , Class <T > annotationClass ) {
46- return getParameterAnnotation (method , parameterIndex , annotationClass ) != null ;
46+ protected static <T extends Annotation > boolean hasParameterAnnotation (Parameter parameter , Class <T > annotationClass ) {
47+ return getParameterAnnotation (parameter , annotationClass ) != null ;
4748 }
4849
4950 protected static String getMethodSignature (Method method ) {
@@ -57,13 +58,14 @@ protected static String getMethodSignature(final Method method, final String nor
5758 signature .append (name ).append ("(" );
5859
5960 boolean first = true ;
60- Class <?> [] parameterTypes = method .getParameterTypes ();
61+ final Parameter [] parameters = method .getParameters ();
6162
62- for (int i =0 ; i < parameterTypes .length ; i ++) {
63- Class <?> parameterType = parameterTypes [i ];
63+ for (int i =0 ; i < parameters .length ; ++i ) {
64+ final Parameter parameter = parameters [i ];
65+ final Class <?> parameterType = parameter .getType ();
6466
6567 // skip BlockChain parameters
66- if (hasParameterAnnotation (method , i , BlockChain .class )) {
68+ if (hasParameterAnnotation (parameter , BlockChain .class )) {
6769 continue ;
6870 }
6971
@@ -76,7 +78,7 @@ protected static String getMethodSignature(final Method method, final String nor
7678 final String typeName ;
7779
7880 // varargs
79- if (i == parameterTypes . length - 1 && method .isVarArgs ()) {
81+ if (parameter .isVarArgs ()) {
8082 checkState (parameterType .isArray ());
8183 typeName = parameterType .getComponentType ().getName ()+"..." ;
8284 }
@@ -95,9 +97,8 @@ else if (parameterType.isArray()) {
9597 Class <?>[] generics = ResolvableType .forMethodParameter (MethodParameter .forMethodOrConstructor (method , i )).resolveGenerics ();
9698 signature .append (makeTypeWithGenerics (typeName , generics ));
9799
98- // parameter name
99- // TODO improve in JDK8 (#218)
100- signature .append (" p" ).append (i );
100+ // parameter name (or argX by default)
101+ signature .append (" " ).append (parameter .getName ());
101102 }
102103
103104 signature .append (")" );
0 commit comments