[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Matching all methods on an annotated type?

Hi All,

I've been having some difficulty defining a pointcut that matches all the methods in an annotated type. For example, my understanding of

pointcut test1(Object target, ApplyMethodTiming applyMethodTiming) :
        execution(@ApplyMethodTiming * *(..))
        && @annotation(applyMethodTiming)
        && target(target);

is that it should match all methods that are annotated by @ApplyMethodTiming or are members of a type annotated by @ApplyMethodTiming, but this doesn't appear to be the case. Only those methods annotated with @ApplyMethodTiming are picked out.

I've attached an archive of a maven project containing a few simple tests for this. The only one that works for me is the one that uses reflection to test if the class has the annotation applied to it. I'd rather not do this as it will be quite slow.

The output of the test project is:

00:21:10,377 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - A - Applied to execution(void test.methodTimingTest.ApplyMethodTimingAspectTest.takesNoTime())
00:21:10,382 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - A - Applied to execution(void test.methodTimingTest.TimedObject.takesNoTime())
00:21:10,385 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - R - Applied to execution(void test.methodTimingTest.TimedObject.takesNoTime())
00:21:10,385 FATAL [           main] DOC methodTimingTest.TimedObject - takesNoTime
00:21:10,391 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - A - Applied to execution(void test.methodTimingTest.ApplyMethodTimingAspectTest.worksIfAnnotated())
00:21:10,394 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - 1 - Applied to execution(void test.methodTimingTest.TimedObject.worksIfAnnotated())
00:21:10,394 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - 2 - Applied to execution(void test.methodTimingTest.TimedObject.worksIfAnnotated())
00:21:10,394 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - 3 - Applied to execution(void test.methodTimingTest.TimedObject.worksIfAnnotated())
00:21:10,395 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - A - Applied to execution(void test.methodTimingTest.TimedObject.worksIfAnnotated())
00:21:10,395 FATAL [           main] DOC methodTimingTest.ApplyMethodTimingAspect - R - Applied to execution(void test.methodTimingTest.TimedObject.worksIfAnnotated())
00:21:10,395 FATAL [           main] DOC methodTimingTest.TimedObject - annotated

Where
- A - indicates a match on all methods (execution * *(..))
- R - indicates a match on all methods, then use reflection to determine if the class has the @ApplyMethodTiming aspect
- 1 - indicates a match on execution(@ApplyMethodTiming * *(..)) && @annotation(applyMethodTiming)
- 2 - indicates a match on execution(@ApplyMethodTiming * *(..))
- 3 - indicates a match on execution(* *(..)) && @annotation(applyMethodTiming)

I'm using Apsectj 1.6.5. The strange thing is that I'm sure I seen this working earlier today, but it doesn't appear to want to work now.

Thanks

Steve

Attachment: methodTimingTest.zip
Description: Zip archive