Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to access annotation values

You can also write this (avoiding the need for reflection) :

void around(NeedPermissionGroup npg):
   execution(* hello.World.*()) && @annotation(npg)  {

               // ** How can I access annotation value for id (defined in World as 1)
               // AMC: now you can just write "npg.id()"

               proceed(npg);


       }

On 02/01/06, bednarz-hannover@xxxxxx <bednarz-hannover@xxxxxx> wrote:
Hi Eduardo,

thank you very much. This was exactly my problem. I knew only how to get annotations from classes and not from methods. Your suggestion is working perfectly.

My best,

Andreas Bednarz

aspectj-users@xxxxxxxxxxx schrieb am 02.01.06 02:34:06:
>
> Hi Andreas,
>
> You should write something like this:
>
> void around(): execution(@NeedPermissionGroup * hello.World.*())  {
>     MethodSignature signature = (MethodSignature) thisJoinPoint.getSignature();
>     NeedPermissionGroup ann =
> signature.getMethod().getAnnotation(NeedPermissionGroup.class);
>
>     System.out.println(ann.id());
>
>     proceed();
> }
>
> []'s
> Eduardo
>
> 2006/1/1, bednarz-hannover@xxxxxx < bednarz-hannover@xxxxxx>:
> > Hello Alex,
> >
> > how would you access the id value in the following classes:
> >
> > -- NeedPermissionGroup.java --
> >
> > package hello;
> >
> > @Retention(RetentionPolicy.RUNTIME)
> > @Target({ElementType.METHOD,ElementType.TYPE})
> > public @interface NeedPermissionGroup {
> >         int id()                        default -1;
> > }
> >
> > -- World.java --
> >
> > package hello;
> > public class World {
> >
> >         @NeedPermissionGroup(id=1)
> >         private void output1() {
> >                 System.out.println("output1");
> >         }
> >
> > }
> >
> >
> > My aspect is at this time, is this enough? What should I insert at marked position  ?
> >
> > public aspect WorldAspect {
> >
> >
> >         void around(): execution(@NeedPermissionGroup * hello.World.*())  {
> >
> >                 // ** How can I access annotation value for id (defined in World as 1)
> >                 proceed();
> >
> >         }
> >
> >
> > Thank you,
> >
> > Andreas
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

--
mfG

Bednarz, Hannover
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



--
-- Adrian
adrian.colyer@xxxxxxxxx

Back to the top