[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] pointcut to match inherited methods
|
Hi,
Maybe I don't quite understand the full problem here... but given this code:
class A {
public void m() {
System.out.println("Test A");
}
}
public class B extends A {
}
class C {
public void methodC() {
B b = new B();
b.m(); // Want to catch this inherited method only.
}
}
the pointcut: call(* A.m(..)) will match the line you specified.
There are multiple join point signatures for 'b.m()' and the pointcut
just has to match one of them. The two are 'method-call(void B.m())'
and 'method-call(void A.m())'.
Furthermore if there was this extension:
class D extends A {}
D c = new D();
D.m(); // don't want this one!
and I didn't want that call or if I didn't want calls made directly on
instances of A I would write 'call(* A.m(..)) && target(B)'.
Andy
On 29 April 2010 21:45, Ashank <k_arvind_shankar@xxxxxxxxx> wrote:
>
> Hello Mohan,
>
> You are right about using the 'call' pointcut and my guess is, if 'call' is
> used, one would not need the 'withincode' part. However, as advised in
> AspectJ docs, it is better to have a 'within' pointcut as it will be faster
> and have a smaller footprint than just a 'call' pointcut, especially in
> scenarios like load time weaving.
>
> So I always preferred a combination of 'within' and 'execution' pointcuts to
> match my method calls but I can't seem to use them for inherited methods for
> some reason.
>
> Any ideas/thoughts?
>
> Thanks
> -Arvind
>
>
> Mohan Radhakrishnan wrote:
>>
>> Hi Ashank,
>>
>> Still guessing but based on what I understand this pointcut shows the
>> eclipse marker
>>
>> at this line - > b.m(); // Want to catch this inherited method only.
>>
>> pointcut p() : call(* B.*()) && !withincode(* A+.m());
>>
>> Thanks,
>> Mohan
>>
>> On Thu, Apr 29, 2010 at 6:03 PM, Ashank <k_arvind_shankar@xxxxxxxxx>
>> wrote:
>>>
>>> Hello Mohan,
>>>
>>> Thanks for the reply. I wasn't looking to capture calls to overridden
>>> methods. Going by your example,
>>>
>>> public class A {
>>> public void m(){
>>> System.out.println( "Test A" );
>>> }
>>> }
>>>
>>> public class B extends A {
>>>
>>> }
>>>
>>> class C {
>>> public void methodC() {
>>> B b = new B();
>>> b.m(); // Want to catch this inherited method only.
>>> }
>>> }
>>>
>>> To reiterate, Class B does not override method m. It simply inherits it.
>>> I
>>> wish to catch calls to b.m() where b is an instance of class B. thanks
>>>
>>> -Arvind
>>>
>>>
>>> Mohan Radhakrishnan wrote:
>>>>
>>>> Hi Ashank,
>>>>
>>>> Is this pointcut what you are looking for ?
>>>>
>>>> pointcut p() : execution(* B.m());
>>>>
>>>> public class A {
>>>>
>>>> public void m(){
>>>> System.out.println( "Test A" );
>>>> }
>>>> }
>>>>
>>>> public class B extends A {
>>>>
>>>> public void m(){
>>>> System.out.println( "Test B" );
>>>> }
>>>>
>>>> }
>>>>
>>>> Thanks,
>>>> Mohan
>>>>
>>>> On Thu, Apr 29, 2010 at 3:57 PM, Ashank <k_arvind_shankar@xxxxxxxxx>
>>>> wrote:
>>>>>
>>>>> Hello All,
>>>>>
>>>>> I have a simple question. The same question was asked in this post but
>>>>> it
>>>>> seems to have gone unaddressed as far as my understanding goes.
>>>>> http://old.nabble.com/Weaving-inherited-methods-to15405848.html#a15405848
>>>>>
>>>>> Anyway, the question is, I want a pointcut to match method
>>>>> calls/executions
>>>>> of inherited methods in a subclass. For instance.
>>>>>
>>>>> Class A{
>>>>> public void methodA() {}
>>>>> }
>>>>>
>>>>> Class B extends A() {
>>>>> }
>>>>>
>>>>> Class C() {
>>>>> B b = new B();
>>>>> b.methodA(); // Want to catch this.
>>>>> }
>>>>>
>>>>> As mentioned, I want to match the statement ending with the comment.
>>>>> Please help me out with the pointcut. Thank you very much
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/pointcut-to-match-inherited-methods-tp28398859p28398859.html
>>>>> Sent from the AspectJ - users mailing list archive at Nabble.com.
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/pointcut-to-match-inherited-methods-tp28398859p28399940.html
>>> Sent from the AspectJ - users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> 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
>>
>>
>
> --
> View this message in context: http://old.nabble.com/pointcut-to-match-inherited-methods-tp28398859p28408493.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>