@@ -405,37 +405,55 @@ public boolean hasZeroArgsConstructor(Class<?> clazz) {
405
405
private boolean validateMethods (Class <?> clazz ) {
406
406
Method [] methods = clazz .getMethods ();
407
407
for (Method method : methods ) {
408
- for (Map .Entry <Class <? extends Annotation >, String []> entry : EXPECTED_PARAM_TYPES_MAP
409
- .entrySet ()) {
410
- Class <? extends Annotation > annotationClass = entry .getKey ();
411
- if (method .isAnnotationPresent (annotationClass )) {
412
- String [] expectedParamTypes = entry .getValue ();
413
- if (method .getParameterCount () > 0 ) {
414
- Class <?>[] paramTypes = method .getParameterTypes ();
415
- for (Class <?> type : paramTypes ) {
416
- boolean isExpectedType = false ;
417
- for (String expectedType : expectedParamTypes ) {
418
- if (type .getName ().equals (expectedType )) {
419
- isExpectedType = true ;
420
- break ;
421
- }
422
- }
423
- if (!isExpectedType ) {
424
- LOGGER .error ("Unexpected parameter found: {}" , type .getName ());
425
- return false ;
426
- } else {
427
- LOGGER .trace ("Loaded {}" , clazz .getName ());
428
- }
429
- }
430
- } else if (method .getParameterCount () != 0 ) {
431
- LOGGER .error (
432
- "{} does not have the expected parameter types" , method .getName ()
433
- );
434
- return false ;
435
- }
408
+ if (!validateMethodAnnotations (method )) {
409
+ return false ;
410
+ }
411
+ }
412
+ return true ;
413
+ }
414
+
415
+ private boolean validateMethodAnnotations (Method method ) {
416
+ for (Map .Entry <Class <? extends Annotation >, String []> entry : EXPECTED_PARAM_TYPES_MAP
417
+ .entrySet ()) {
418
+ Class <? extends Annotation > annotationClass = entry .getKey ();
419
+ if (method .isAnnotationPresent (annotationClass )) {
420
+ if (!validateMethodParameters (method , entry .getValue ())) {
421
+ return false ;
436
422
}
437
423
}
438
424
}
439
425
return true ;
440
426
}
427
+
428
+ private boolean validateMethodParameters (Method method , String [] expectedParamTypes ) {
429
+ if (method .getParameterCount () > 0 ) {
430
+ return checkParameterTypes (method , expectedParamTypes );
431
+ } else if (method .getParameterCount () != 0 ) {
432
+ LOGGER .error ("{} does not have the expected parameter types" , method .getName ());
433
+ return false ;
434
+ }
435
+ return true ;
436
+ }
437
+
438
+ private boolean checkParameterTypes (Method method , String [] expectedParamTypes ) {
439
+ Class <?>[] paramTypes = method .getParameterTypes ();
440
+ for (Class <?> type : paramTypes ) {
441
+ if (!isExpectedType (type , expectedParamTypes )) {
442
+ LOGGER .error ("Unexpected parameter found: {}" , type .getName ());
443
+ return false ;
444
+ } else {
445
+ LOGGER .trace ("Loaded {}" , method .getDeclaringClass ().getName ());
446
+ }
447
+ }
448
+ return true ;
449
+ }
450
+
451
+ private boolean isExpectedType (Class <?> type , String [] expectedParamTypes ) {
452
+ for (String expectedType : expectedParamTypes ) {
453
+ if (type .getName ().equals (expectedType )) {
454
+ return true ;
455
+ }
456
+ }
457
+ return false ;
458
+ }
441
459
}
0 commit comments