@@ -72,12 +72,6 @@ public final class ScmInvokerCodeGenerator {
7272 Object .class ,
7373 new Class <?>[]{Exception .class });
7474
75- static final DeclaredMethod GET_RETURN_TYPE = new DeclaredMethod ("getReturnType" ,
76- new Class []{String .class , Class [].class },
77- new String []{"methodName" , "parameterTypes" },
78- Class .class ,
79- new Class <?>[]{});
80-
8175 private final Class <?> api ;
8276 private final String apiName ;
8377 private final String invokerClassName ;
@@ -448,73 +442,6 @@ void printProxyMethod() {
448442 }
449443 }
450444
451- void printReturnTypeMethod () {
452- println ();
453- println ("@Override" );
454- printf ("public Class<?> getReturnType(String methodName, Class<?>[] parameterTypes)" );
455- try (UncheckedAutoCloseable ignored = printScope ()) {
456- printReturnTypeSwitch ();
457- }
458- }
459-
460- void printReturnTypeSwitch () {
461- printf ("switch (methodName)" );
462- try (UncheckedAutoCloseable ignored = printScope (true , 0 )) {
463- final List <Method > apiMethods = getReturnTypeMethods ();
464-
465- final List <String > methodNames = apiMethods .stream ()
466- .map (Method ::getName )
467- .distinct ()
468- .sorted ()
469- .collect (Collectors .toList ());
470-
471- for (String methodName : methodNames ) {
472- final List <Method > overrides = apiMethods .stream ()
473- .filter (m -> m .getName ().equals (methodName ))
474- .sorted (Comparator .comparing (Method ::getParameterCount ))
475- .collect (Collectors .toList ());
476-
477- printf ("case \" %s\" :" , methodName );
478- try (UncheckedAutoCloseable ignore = printScope (false , 1 )) {
479- for (Method m : overrides ) {
480- printReturnTypeIf (m );
481- }
482- println ("break;" );
483- }
484- println ();
485- }
486-
487- printf ("default:" );
488- try (UncheckedAutoCloseable ignore = printScope (false , 1 )) {
489- println ("break;" );
490- }
491- }
492-
493- println ();
494- println ("throw new IllegalArgumentException(" );
495- println (" \" Method not found: \" + methodName" );
496- println (" + \" with parameterTypes in %s\" );" , apiName );
497- }
498-
499- void printReturnTypeIf (Method method ) {
500- final Class <?>[] paramTypes = method .getParameterTypes ();
501- final String params = classesToString (paramTypes , ".class" );
502-
503- if (paramTypes .length == 0 ) {
504- printf ("if (parameterTypes == null || parameterTypes.length == 0)" );
505- try (UncheckedAutoCloseable ignore = printScope ()) {
506- println ("return %s.class;" , getClassname (method .getReturnType ()));
507- }
508- return ;
509- }
510-
511- println ("if (Arrays.equals(parameterTypes," );
512- printf (true , " new Class<?>[]{%s}))" , params );
513- try (UncheckedAutoCloseable ignore = printScope ()) {
514- println ("return %s.class;" , getClassname (method .getReturnType ()));
515- }
516- }
517-
518445 public String generateClass () {
519446 println ("/** Code generated for {@link %s}. Do not modify. */" , apiName );
520447 printf ("public class %s extends ScmInvoker<%s>" , invokerClassName , apiName );
@@ -523,21 +450,10 @@ public String generateClass() {
523450 printHeaderMethods ();
524451 printProxyMethod ();
525452 printInvokeMethod (INVOKE_LOCAL );
526- printReturnTypeMethod ();
527453 }
528454 return out .toString ();
529455 }
530456
531- List <Method > getReturnTypeMethods () {
532- return Arrays .stream (api .getMethods ())
533- .filter (m -> !Modifier .isStatic (m .getModifiers ()))
534- .filter (m -> m .getAnnotation (Deprecated .class ) == null )
535- .filter (m -> !m .isDefault () || m .getAnnotation (Replicate .class ) != null )
536- .sorted (Comparator .comparing (Method ::getName )
537- .thenComparing (Method ::getParameterCount ))
538- .collect (Collectors .toList ());
539- }
540-
541457 File updateFile (String classString ) throws IOException {
542458 final File java = new File (DIR , invokerClassName + ".java" );
543459 if (!java .isFile ()) {
0 commit comments