Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] avoid locked method invocation with an annotation

Annotation value matching can be done, yes.  The last section of the
readme for 1.6.0 talks a little about it:
http://www.eclipse.org/aspectj/doc/released/README-160.html

enum TraceLevel { NONE, LEVEL1, LEVEL2, LEVEL3 }

@interface Trace {
  TraceLevel value() default TraceLevel.LEVEL1;
}

aspect X {
  // Advise all methods marked @Trace except those with a tracelevel of none
  before(): execution(@Trace !@Trace(TraceLevel.NONE) * *(..)) {
    System.err.println("tracing "+thisJoinPoint);
  }
}

However, whether support has yet been added for the particular value
type you have in mind, I'm not sure - support is added on a case by
case basis as they come up.  I know I did enum, not sure what else is
in there right now!

And something you didn't ask about, but is interesting: you will also
find that binding the value rather than the annotation itself can
massively increase performance - what do I mean?  Suppose we have an
annotation called 'Marker' with a String value 'message' that we want
to use in our advice.

This will work:

  before(Marker l): execution(@Marker * runTwo(..)) && @annotation(l) {
    String s = l.message();
  }

But this will *fly*:

  before(String s): execution(@Marker * runThree(..)) &&
@annotation(Marker(s)) {
  }


Andy

On 17 February 2010 03:46, Luca Ferrari <fluca1978@xxxxxxxxxxx> wrote:
> On Monday 15 February 2010 05:42:58 pm Andy Clement's cat walking on the
> keyboard wrote:
>> There are older posts on the list about that message, eg.
>> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01058.html
>>
>> You probably can ignore them, or you could be more specific in your
>> call pointcut and specify the annotation:
>>
>> call(public @Lock * AgentProxy+.*(..) )
>>
>
>
> Is there a way to force an annotation's values in the pointcut?
>
> Luca
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top