Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut for overriden or implemented methods

This isn't possible to do in AspectJ because modifier patterns (and annotations are treated as modifiers) are always matched on the *subject* of the join point (for execution, the actual method that executes, for call, the method that is the static target of the call) and are not matched against any of the inherited signatures. I made my best effort at explaining these rules as simply as possible in chapter 1 of the AspectJ 5 Developer's Notebook: http:// www.eclipse.org/aspectj/doc/released/adk15notebook/jpsigs.html.

Having said that it is not possible, I have also seen a number of use cases where I wanted to express join point matching criteria based on annotations on super interfaces or methods (even though such annotations are not inherited according to the JLS). To support this we'd need to introduce something like @superannotation(TypeName) which would match like @annotation, but also consider annotations on supers. This leads down the unpleasant road of needing @superthis and @supertarget too, cluttering the pointcut language. If an elegant solution could be found, I would consider this a candidate for AspectJ 6.

Regards, Adrian.


On 30 Sep 2006, at 10:10, Monal Daxini wrote:

I do not want to declare annotation on a type based on methods.  I am
looking at finding all methods that override or implement a
method-having-MyAnnotation.
hasmethod does not help in my case because the implemented and
overriden methods do not inherit the annotation. What I need are
"implementsMethod" pointcut and "overridesMethod" pointcut -- Is there
anything similar available or is it possible to achieve something
similar?

Thank you
Monal

On 9/29/06, Eric Bodden <eric.bodden@xxxxxxxxxxxxxx> wrote:
Hi.

I think you can use "declare annotation" with a hasmethod-pointcut in
order to declare an annotation on all types that have a method with
@MyAnnotation. This annotation on the type can then be inherited.

(see here for hasmethod:
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg06671.html)


Eric


> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-
> bounces@xxxxxxxxxxx] On Behalf Of Monal Daxini
> Sent: Friday, September 29, 2006 4:33 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: [aspectj-users] pointcut for overriden or implemented methods
>
> Hi,
>
> Is it possible to write a pointcut with the following requirements:
>
> Match all methods in classes that override or implement methods with > @MyAnnotation defined in the super class or the interface. So in the
> following example the pointcut should match both methds in the
> WorkPlace class.
>
> @Retention(RetentionPolicy.RUNTIME)
> @Inherited
> public @interface MyAnnotation {
> }
>
> public interface Work {
>      @MyAnnotation
>       public void doSomething();
> }
>
> public abstract class AbstractPlace {
>      @MyAnnotation
>       public void getPlace();
> }
>
> public class WorkPlace extends AbstractPlace implements Work {
>     public void doSomething() {
>         ...
>     }
>
>     public void getPlace() {
>         ...
>     }
> }
>
> Note: the annotation on the method are not inherited.
>
> Thank you
> Monal
> _______________________________________________
> 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

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



Back to the top