Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Need advice on how to craft a pointcut ... a real challenge :)

Unfortunately, this is not possible in AspectJ.


On Thu, Feb 19, 2009 at 8:54 AM, Pavlovich, Peter
<Peter.Pavlovich@xxxxxxxxxx> wrote:
>
>
> A)      The process() method must be defined on this class (and each
> subclass) individually (cannot rely on superclass to provide
> implementation).

Can't look for this.  You can't match on the lack of a joinpoint.

>
> B)      Every public attribute (defined directly on the class in question --
> the one implementing the interface) as well as every private attribute with
> a public or protected accessor method (again, defined directly on the class
> implementing the interface) must satisfy one of the following:
>
> i)         The attribute is marked with the "OkToIgnore" annotation.
>
> ii)       The attribute (if public) or the public getter must be
> called/accessed within the scope of the "process()" method defined on this
> class.
>
>
This is not possible either.  I originally wrote the following,
thinking it might work, but it will fail if there is any call to a
shouldn't ignore method outside of the process method.

pointcut shouldntIgnore() : within(MyProcessor+) && call(
(!@OkToIgnore) (public || protected) *.*(..));
pointcut inProcess() : withincode(public void MyProcessor+.process())
&& call(* *.*(..));

declare error : shouldntIgnore() && !inProcess() : "Fail!";

Again, the problem here is that you can't discover the lack of a joinpoint.

>
> If one of (i) or (ii) is not satisfied, then I want to fail compilation or
> log a message or some similar action to be implemented in the advice. The
> action is not that important at this point – my challenge is with defining
> the pointcut.
>
>
>
> Note that the same rules must also apply to subclasses of any class
> implementing the interface -- but these subclasses must define the process()
> method themselves and must "process" their own attributes (the ones defined
> directly on themselves) within that process method.
>
>
>
> Is this even possible? If so, any help on how to define the best pointcut
> for this scenario would be greatly appreciated! I am open to any reasonable
> refactoring that might need to be done to enable this sort of checking as
> well if that would help. I'd prefer not to have to refactor or add extra
> code to the classes if at all possible though.
>
>
>
> I look forward to your help with this challenge!!! Thanks in advance!
>
>
>
> Peter
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top