[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[ews.eclipse.technology.aspectj] Re: AspectJ: around() advice for setName() in derived class
|
Andy Clement wrote:
> The execution() pointcut designator takes a *declared* signature. You
> have no method declared in B called setName(). Change the pointcut to:
>
> pointcut setter (B b): execution(public void setName(*)) &&
> target (b);
Ok, that's better but now, both advices are applied to B. How can I
limit the advice for A to only A without the subclasses?
Regards,
>> Hello,
>>
>> I have two classes:
>>
>> class A {
>> private String name;
>> public void setName (String name) { this.name = name; }
>> }
>>
>> class B extends A;
>>
>> I want to create an advice which allows me to "fix" the name before it
>> is passed into setName() by calling a method validateName() (this is
>> defined in the advice).
>>
>> This works.
>>
>> Now, I want to create a second advice which does the same with a
>> *different* validateName() method for B.
>>
>> I tried
>>
>> pointcut setter (B b): execution(public void B.setName(*)) &&
>> target (b);
>>
>> void around(B obj, String newValue) :
>> setter (obj) && args (newValue) { ... }
>>
>> but the around advice is not applied to anything. What's wrong?
>>
>> Regards,
>>
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.philmann-dark.de/