@@ -299,22 +299,51 @@ private Map<TypeElement, MvcRouter> buildRouteRegistry(
299299
300300 // Generate unique method name by router
301301 for (var router : registry .values ()) {
302- // Initialize with supports/create method from MvcFactory (avoid name collision)
303- var names = new HashSet <>();
304- for (var route : router .getRoutes ()) {
305- if (!names .add (route .getMethodName ())) {
302+ // Split routes by their target generated classes to avoid false collisions
303+ var restAndTrpcRoutes = router .getRoutes ().stream ().filter (r -> !r .isJsonRpc ()).toList ();
304+
305+ var rpcRoutes = router .getRoutes ().stream ().filter (MvcRoute ::isJsonRpc ).toList ();
306+
307+ resolveGeneratedNames (restAndTrpcRoutes );
308+ resolveGeneratedNames (rpcRoutes );
309+ }
310+ return registry ;
311+ }
312+
313+ private void resolveGeneratedNames (List <MvcRoute > routes ) {
314+ // Group by the actual target method name in the generated class
315+ var grouped =
316+ routes .stream ()
317+ .collect (
318+ Collectors .groupingBy (
319+ route -> {
320+ String baseName = route .getMethodName ();
321+ return route .isTrpc ()
322+ ? "trpc"
323+ + Character .toUpperCase (baseName .charAt (0 ))
324+ + baseName .substring (1 )
325+ : baseName ;
326+ }));
327+
328+ for (var overloads : grouped .values ()) {
329+ if (overloads .size () == 1 ) {
330+ // No conflict in this specific output file, use the clean original name
331+ overloads .get (0 ).setGeneratedName (overloads .get (0 ).getMethodName ());
332+ } else {
333+ // Conflict detected: generate names based on parameter types
334+ for (var route : overloads ) {
306335 var paramsString =
307336 route .getRawParameterTypes (true ).stream ()
308337 .map (it -> it .substring (Math .max (0 , it .lastIndexOf ("." ) + 1 )))
309338 .map (it -> Character .toUpperCase (it .charAt (0 )) + it .substring (1 ))
310339 .collect (Collectors .joining ());
340+
341+ // A 0-arg method gets exactly the base name.
342+ // Methods with args get the base name + their parameter types.
311343 route .setGeneratedName (route .getMethodName () + paramsString );
312- } else {
313- route .setGeneratedName (route .getMethodName ());
314344 }
315345 }
316346 }
317- return registry ;
318347 }
319348
320349 /**
0 commit comments