4444import javax .inject .Provider ;
4545import java .io .FileNotFoundException ;
4646import java .lang .reflect .AnnotatedElement ;
47+ import java .lang .reflect .Method ;
4748import java .lang .reflect .Modifier ;
4849import java .nio .file .Path ;
4950import java .nio .file .Paths ;
@@ -71,17 +72,12 @@ private static class Stack {
7172 private String pattern ;
7273 private Executor executor ;
7374 private List <Route .Decorator > filters = new ArrayList <>();
74- private List <Renderer > renderers = new ArrayList <>();
7575 private List <Route .After > afters = new ArrayList <>();
7676
7777 public Stack (String pattern ) {
7878 this .pattern = pattern ;
7979 }
8080
81- public void then (Renderer renderer ) {
82- renderers .add (renderer );
83- }
84-
8581 public void then (Route .Decorator filter ) {
8682 filters .add (filter );
8783 }
@@ -98,13 +94,8 @@ public Stream<Route.After> toAfter() {
9894 return afters .stream ();
9995 }
10096
101- public Stream <Renderer > toRenderer () {
102- return renderers .stream ();
103- }
104-
10597 public void clear () {
10698 this .filters .clear ();
107- this .renderers .clear ();
10899 this .afters .clear ();
109100 executor = null ;
110101 }
@@ -133,7 +124,6 @@ public Stack executor(Executor executor) {
133124 }
134125 };
135126
136-
137127 private ErrorHandler err ;
138128
139129 private Map <String , StatusCode > errorCodes ;
@@ -593,19 +583,21 @@ private void mvc(String prefix, Class type, Provider provider) {
593583 }
594584
595585 private void find (String prefix , Class type , Throwing .Consumer <MvcMethod > consumer ) {
596- String classPath = prefix == null ? path (type ) : prefix + "/" + path (type );
597586 MvcMetadata mvcMetadata = new MvcMetadata (source );
598587 mvcMetadata .parse (type );
599588 List <MvcMethod > routes = new ArrayList <>();
600589 Stream .of (type .getDeclaredMethods ())
601590 .forEach (method -> {
602591 if (Modifier .isPublic (method .getModifiers ())) {
603592 mvcAnnotations .httpMethod (method ).forEach (httpMethod -> {
604- MvcMethod mvc = mvcMetadata .get (method );
605- mvc .setPattern (classPath + "/" + path (method ));
606- mvc .setMethod (method );
607- mvc .setHttpMethod (httpMethod );
608- routes .add (mvc );
593+ String [] paths = pathPrefix (prefix , path (method ));
594+ for (String path : paths ) {
595+ MvcMethod mvc = mvcMetadata .create (method );
596+ mvc .setPattern (path );
597+ mvc .setMethod (method );
598+ mvc .setHttpMethod (httpMethod );
599+ routes .add (mvc );
600+ }
609601 });
610602 }
611603 });
@@ -614,9 +606,38 @@ private void find(String prefix, Class type, Throwing.Consumer<MvcMethod> consum
614606 mvcMetadata .destroy ();
615607 }
616608
617- private String path (AnnotatedElement type ) {
618- String path = mvcAnnotations .pathPattern (type );
619- return path == null ? "" : path ;
609+ private String [] pathPrefix (String prefix , String [] path ) {
610+ if (prefix == null ) {
611+ return path ;
612+ }
613+ String [] result = new String [path .length ];
614+ for (int i = 0 ; i < path .length ; i ++) {
615+ result [i ] = prefix + "/" + path [i ];
616+ }
617+ return result ;
618+ }
619+
620+ private String [] path (Method m ) {
621+ String [] path = mvcAnnotations .pathPattern (m );
622+ String [] root = mvcAnnotations .pathPattern (m .getDeclaringClass ());
623+ if (root == null ) {
624+ if (path == null ) {
625+ return new String [] {"/" };
626+ }
627+ return path ;
628+ }
629+ if (path == null ) {
630+ return root ;
631+ }
632+ String [] result = new String [root .length * path .length ];
633+ int k = 0 ;
634+ for (String base : root ) {
635+ for (String element : path ) {
636+ result [k ] = base + "/" + element ;
637+ k += 1 ;
638+ }
639+ }
640+ return result ;
620641 }
621642
622643 private void checkMvcAnnotations () {
0 commit comments