Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Accessing value of annotation on method parameter

Hi Luke,

This is enhancement
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259416 - currently you
cannot do it directly in the syntax, you need to dig them out of the
thisJoinPoint object.

MethodSignature ms =
(MethodSignature)thisJoinPointStaticPart.getSignature();
System.out.println(ms.getMethod().getParameterAnnotations()[0][0]);

when it is supported, likely syntax is:

before(SomeAnno anno): execution(* someMethod(..)) && @args(anno (*)) {}

cheers,
Andy

On 15 November 2011 04:26, LukeAspectJ <lukas.abels.vehns@xxxxxxxxxxxxxx> wrote:
> Hi!
>
> I have the following problem:
> I want to access the value of an annotation that is annotating a parameter
> of a method in my advice function. Is it possible to somehow make the
> annotation available to the advice in my pointcut?
>
> For example:
>
> public class A {
>    public String annotatedValue;
> }
>
> @Target({PARAMETER, FIELD})
> @Retention(RUNTIME)
> @Documented
> public @interface QSChild {
>    String value() default "";
> }
>
> public class BeanFactoryA {
>   public BeanObject generateBeanObject(@QSChild("testvalue") A objectA) {
> ... }
>   ...
> }
>
> In my aspect, i want to intercept the call to any generateBeanObject method
> and somehow get the value of the @QSChild annotation.
>
> public aspect BeanFactoryAspect {
>    pointcut beanFactoryMethod(@QSChild param) : call(* *(@QSChild (*))) &&
> //now make the annotation available
>
>    before(@QSChild param) : beanFactoryMethod(param) {
>        // do something with the value of the annotation
>    }
> }
>
>
> Any help is appreciated,
> Luke
>
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/Accessing-value-of-annotation-on-method-parameter-tp4042771p4042771.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top