@@ -152,12 +152,12 @@ public Object loadHostBean(Class beanClass, ActContext<?> ctx) {
152152 return loader .load (null , ctx , false );
153153 }
154154
155- public ParamValueLoader [] methodParamLoaders (Object host , Method method ) {
155+ public ParamValueLoader [] methodParamLoaders (Object host , Method method , ActContext ctx ) {
156156 ParamValueLoader [] loaders = methodRegistry .get (method );
157157 if (null == loaders ) {
158158 $ .Var <Boolean > boolBag = $ .var (Boolean .FALSE );
159159 Class hostClass = null == host ? null : host .getClass ();
160- ParamValueLoader [] newLoaders = findMethodParamLoaders (method , hostClass , boolBag );
160+ ParamValueLoader [] newLoaders = findMethodParamLoaders (method , hostClass , ctx , boolBag );
161161 loaders = methodRegistry .putIfAbsent (method , newLoaders );
162162 if (null == loaders ) {
163163 loaders = newLoaders ;
@@ -174,7 +174,7 @@ public ParamValueLoader[] methodParamLoaders(Object host, Method method) {
174174
175175 public Object [] loadMethodParams (Object host , Method method , ActContext ctx ) {
176176 try {
177- ParamValueLoader [] loaders = methodParamLoaders (host , method );
177+ ParamValueLoader [] loaders = methodParamLoaders (host , method , ctx );
178178 Boolean hasValidationConstraint = methodValidationConstraintLookup .get (method );
179179 int sz = loaders .length ;
180180 Object [] params = new Object [sz ];
@@ -290,7 +290,7 @@ private <T> Map<Field, ParamValueLoader> fieldLoaders(Class<T> beanClass) {
290290 continue ;
291291 }
292292 BeanSpec spec = BeanSpec .of (field , injector );
293- ParamValueLoader loader = paramValueLoaderOf (spec );
293+ ParamValueLoader loader = paramValueLoaderOf (spec , null );
294294 boolean provided = (loader instanceof ProvidedValueLoader );
295295 if (null != loader && !provided ) {
296296 newFieldLoaders .put (field , loader );
@@ -304,7 +304,9 @@ private <T> Map<Field, ParamValueLoader> fieldLoaders(Class<T> beanClass) {
304304 return fieldLoaders ;
305305 }
306306
307- protected ParamValueLoader [] findMethodParamLoaders (Method method , Class host , $ .Var <Boolean > hasValidationConstraint ) {
307+ protected ParamValueLoader [] findMethodParamLoaders (
308+ Method method , Class host ,
309+ ActContext ctx , $ .Var <Boolean > hasValidationConstraint ) {
308310 Type [] types = method .getGenericParameterTypes ();
309311 int sz = types .length ;
310312 if (0 == sz ) {
@@ -328,7 +330,7 @@ protected ParamValueLoader[] findMethodParamLoaders(Method method, Class host, $
328330 if (hasValidationConstraint (spec )) {
329331 hasValidationConstraint .set (true );
330332 }
331- ParamValueLoader loader = paramValueLoaderOf (spec );
333+ ParamValueLoader loader = paramValueLoaderOf (spec , ctx );
332334 if (null == loader ) {
333335 throw new UnexpectedException ("Cannot find param value loader for param: " + spec );
334336 }
@@ -337,16 +339,18 @@ protected ParamValueLoader[] findMethodParamLoaders(Method method, Class host, $
337339 return loaders ;
338340 }
339341
340- private ParamValueLoader paramValueLoaderOf (BeanSpec spec ) {
341- return paramValueLoaderOf (spec , null );
342+ private ParamValueLoader paramValueLoaderOf (BeanSpec spec , ActContext ctx ) {
343+ return paramValueLoaderOf (spec , null , ctx );
342344 }
343345
344- private ParamValueLoader paramValueLoaderOf (BeanSpec spec , String bindName ) {
346+ private ParamValueLoader paramValueLoaderOf (BeanSpec spec , String bindName , ActContext ctx ) {
345347 Class <?> rawType = spec .rawType ();
346348 if (Result .class .isAssignableFrom (rawType )) {
347349 return RESULT_LOADER ;
348350 } else if (Throwable .class .isAssignableFrom (rawType )) {
349351 return new ThrowableLoader ((Class <? extends Throwable >)rawType );
352+ } else if (Annotation .class .isAssignableFrom (rawType )) {
353+ return findHandlerMethodAnnotation ((Class <? extends Annotation >) rawType , ctx );
350354 }
351355 Type type = spec .type ();
352356 Annotation [] annotations = spec .allAnnotations ();
@@ -366,6 +370,60 @@ private ParamValueLoader paramValueLoaderOf(BeanSpec spec, String bindName) {
366370 return loader ;
367371 }
368372
373+ /**
374+ * Returns a `ParamValueLoader` that load annotation from:
375+ * * the handler method
376+ * * the current method (might be a intercepter method)
377+ *
378+ * @param annoType the annotation type
379+ * @param ctx the current {@link ActContext}
380+ * @return a `ParamValueLoader` instance
381+ */
382+ private ParamValueLoader findHandlerMethodAnnotation (final Class <? extends Annotation > annoType , ActContext <?> ctx ) {
383+ if (null == ctx ) {
384+ return ParamValueLoader .NIL ;
385+ }
386+ return new ParamValueLoader () {
387+ @ Override
388+ public Object load (Object bean , ActContext <?> ctx , boolean noDefaultValue ) {
389+ String methodPath = ctx .methodPath ();
390+ Method curMethod = ctx .attribute (ActContext .ATTR_CUR_METHOD );
391+ boolean methodIsCurrent = false ;
392+
393+ Annotation anno = null ;
394+ if (S .notBlank (methodPath )) {
395+ String methodName = S .afterLast (methodPath , "." );
396+ Class <?> hostClass = Act .appClassForName (S .beforeLast (methodPath , "." ));
397+ Method method = null ;
398+ if (S .eq (methodName , curMethod .getName ()) && $ .eq (hostClass , curMethod .getDeclaringClass ())) {
399+ method = curMethod ;
400+ methodIsCurrent = true ;
401+ } else {
402+ for (Method classMethod : hostClass .getMethods ()) {
403+ if (S .eq (methodName , classMethod .getName ())) {
404+ method = classMethod ;
405+ break ;
406+ }
407+ }
408+ }
409+ if (null != method ) {
410+ anno = method .getAnnotation (annoType );
411+ }
412+ }
413+ if (null == anno && !methodIsCurrent ) {
414+ anno = curMethod .getAnnotation (annoType );
415+ }
416+ return anno ;
417+ }
418+
419+ @ Override
420+ public String bindName () {
421+ return null ;
422+ }
423+ };
424+ }
425+
426+
369427 protected abstract ParamValueLoader findContextSpecificLoader (
370428 String bindName ,
371429 Class <?> rawType ,
0 commit comments