3232import act .controller .Controller ;
3333import act .controller .annotation .Port ;
3434import act .controller .annotation .TemplateContext ;
35- import act .controller .annotation .UrlContext ;
3635import act .controller .meta .*;
3736import act .handler .builtin .controller .RequestHandlerProxy ;
3837import act .route .RouteSource ;
@@ -129,21 +128,22 @@ public void visit(int version, int access, String name, String signature, String
129128 @ Override
130129 public AnnotationVisitor visitAnnotation (String desc , boolean visible ) {
131130 AnnotationVisitor av = super .visitAnnotation (desc , visible );
132- if (Type .getType (Controller .class ).getDescriptor ().equals (desc )) {
131+ Class <? extends Annotation > c = AsmType .classForDesc (desc );
132+ if (Controller .class == c ) {
133133 classInfo .isController (true );
134134 return new ControllerAnnotationVisitor (av );
135- } else if (Type . getType ( UrlContext . class ). getDescriptor (). equals ( desc )) {
135+ } else if (ControllerClassMetaInfo . isUrlContextAnnotation ( c )) {
136136 classInfo .isController (true );
137- return new UrlContextAnnotationVisitor (av );
138- } else if (Type . getType ( TemplateContext .class ). getDescriptor (). equals ( desc ) ) {
137+ return new ClassUrlContextAnnotationVisitor (av , ControllerClassMetaInfo . isUrlContextAnnotationSupportInheritance ( c ) );
138+ } else if (TemplateContext .class == c ) {
139139 classInfo .isController (true );
140140 return new TemplateContextAnnotationVisitor (av );
141- } else if (Type . getType ( Port .class ). getDescriptor (). equals ( desc ) ) {
141+ } else if (Port .class == c ) {
142142 return new PortAnnotationVisitor (av );
143- } else if (Type . getType ( With .class ). getDescriptor (). equals ( desc ) ) {
143+ } else if (With .class == c ) {
144144 classInfo .isController (true );
145145 return new ClassWithAnnotationVisitor (av );
146- } else if (Type . getType ( WsEndpoint .class ). getDescriptor (). equals ( desc ) ) {
146+ } else if (WsEndpoint .class == c ) {
147147 classInfo .isController (true );
148148 return new WsEndpointAnnotationVisitor (av );
149149 }
@@ -262,15 +262,21 @@ public void visitEnd() {
262262 }
263263 }
264264
265- private class UrlContextAnnotationVisitor extends AnnotationVisitor {
266- UrlContextAnnotationVisitor (AnnotationVisitor av ) {
265+ private class ClassUrlContextAnnotationVisitor extends AnnotationVisitor {
266+ private final boolean supportInheritance ;
267+ ClassUrlContextAnnotationVisitor (AnnotationVisitor av , boolean supportInheritance ) {
267268 super (ASM5 , av );
269+ this .supportInheritance = supportInheritance ;
268270 }
269271
270272 @ Override
271273 public void visit (String name , Object value ) {
272274 if ("value" .equals (name )) {
273- classInfo .urlContext (value .toString ());
275+ String pathComponent = value .toString ();
276+ if (!supportInheritance && !pathComponent .startsWith ("/" )) {
277+ pathComponent = "/" + pathComponent ;
278+ }
279+ classInfo .urlContext (pathComponent );
274280 }
275281 super .visit (name , value );
276282 }
@@ -324,6 +330,7 @@ private class ActionMethodVisitor extends MethodVisitor implements Opcodes {
324330 private boolean disableJsonCircularRefDetect ;
325331 private HandlerMethodMetaInfo methodInfo ;
326332 private PropertySpec .MetaInfo propSpec ;
333+ List <String > paths = C .newList ();
327334 private Map <Integer , List <ParamAnnoInfoTrait >> paramAnnoInfoList = C .newMap ();
328335 private Map <Integer , List <GeneralAnnoInfo >> genericParamAnnoInfoList = C .newMap ();
329336 private BitSet contextInfo = new BitSet ();
@@ -351,8 +358,7 @@ private class ActionMethodVisitor extends MethodVisitor implements Opcodes {
351358 public AnnotationVisitor visitAnnotation (String desc , boolean visible ) {
352359 AnnotationVisitor av = super .visitAnnotation (desc , visible );
353360 Type type = Type .getType (desc );
354- String className = type .getClassName ();
355- Class <? extends Annotation > c = $ .classForName (className );
361+ Class <? extends Annotation > c = AsmType .classForType (type );
356362 if (Virtual .class .getName ().equals (c .getName ())) {
357363 isVirtual .set (true );
358364 return av ;
@@ -375,7 +381,9 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
375381 methodInfo .propertySpec (propSpec );
376382 }
377383 methodInfo .disableJsonCircularRefDetect (disableJsonCircularRefDetect );
378- return new ActionAnnotationVisitor (av , ControllerClassMetaInfo .lookupHttpMethod (c ), ControllerClassMetaInfo .isActionUtilAnnotation (c ), isStatic );
384+ return new ActionAnnotationVisitor (av , ControllerClassMetaInfo .lookupHttpMethod (c ), ControllerClassMetaInfo .isActionUtilAnnotation (c ), isStatic , ControllerClassMetaInfo .noDefPath (c ));
385+ } else if (ControllerClassMetaInfo .isUrlContextAnnotation (c )) {
386+ return new MethodUrlContextAnnotationVisitor (av , ControllerClassMetaInfo .isUrlContextAnnotationSupportAbsolutePath (c ));
379387 } else if (ControllerClassMetaInfo .isInterceptorAnnotation (c )) {
380388 checkMethodName (methodName );
381389 markRequireScan ();
@@ -682,20 +690,42 @@ public void visitEnd() {
682690 }
683691 }
684692
693+ private class MethodUrlContextAnnotationVisitor extends AnnotationVisitor {
694+ private final boolean supportAbsolutePath ;
695+ MethodUrlContextAnnotationVisitor (AnnotationVisitor av , boolean supportAbsolutePath ) {
696+ super (ASM5 , av );
697+ this .supportAbsolutePath = supportAbsolutePath ;
698+ }
699+
700+ @ Override
701+ public void visit (String name , Object value ) {
702+ if ("value" .equals (name )) {
703+ String pathComponent = value .toString ();
704+ if (!supportAbsolutePath && pathComponent .startsWith ("/" )) {
705+ pathComponent = pathComponent .substring (1 );
706+ }
707+ paths .add (pathComponent );
708+ }
709+ super .visit (name , value );
710+ }
711+ }
712+
713+
685714 private class ActionAnnotationVisitor extends AnnotationVisitor implements Opcodes {
686715
687716 List <H .Method > httpMethods = C .newList ();
688- List <String > paths = C .newList ();
689717 boolean isUtil ;
690718 boolean isStatic ;
719+ boolean noDefPath ;
691720
692- public ActionAnnotationVisitor (AnnotationVisitor av , H .Method method , boolean isUtil , boolean staticMethod ) {
721+ public ActionAnnotationVisitor (AnnotationVisitor av , H .Method method , boolean isUtil , boolean staticMethod , boolean noDefPath ) {
693722 super (ASM5 , av );
694723 if (null != method ) {
695724 httpMethods .add (method );
696725 }
697726 this .isUtil = isUtil ;
698727 this .isStatic = staticMethod ;
728+ this .noDefPath = noDefPath ;
699729 }
700730
701731 @ Override
@@ -737,7 +767,7 @@ public void visitEnd() {
737767 httpMethods .addAll (H .Method .actionMethods ());
738768 }
739769 final List <Router > routers = routers ();
740- if (paths .isEmpty ()) {
770+ if (! noDefPath && paths .isEmpty ()) {
741771 paths .add ("" );
742772 }
743773
0 commit comments