[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Calling super from around advice
|
Hi,
you can dig the parent name out by using reflection on thisJoinPoint.
This aspect should do what you are looking for:
public aspect Test {
String around(): execution(public String A+.getName()) && !within(A) {
String text = thisJoinPoint.getThis().getClass().getSuperclass().getName() ;
System.out.println(text);
return proceed();
}
}
You can shorten the chain of calls by using the this pointcut.
I hope this helps.
Walter
On Fri, 6 Oct 2017, Karl Sanders wrote:
Thanks for your reply.
So, there's no way to change the pointcut definition or something else
to make my example work?
I'm trying to intercept calls to a method in derived classes and then
call the parent's base method.
Regards,
Karl
On Fri, Oct 6, 2017 at 7:11 PM, Henrique Rebêlo <hemr@xxxxxxxxxxx> wrote:
Hi Sanders,
This is just because the super you're calling is from the aspect's
supertype, which is the type object in this case...
Em sex, 6 de out de 2017 às 13:37, Karl Sanders <karlsanders75@xxxxxxxxx>
escreveu:
Hi,
I have this example code:
public class A {
public String getName() { return "A"; }
}
public class B extends A {
@Override
public String getName() { return "B";}
}
public aspect Test {
String around(): execution(public String A+.getName())
&& !within(A) {
String text = "advice";
// text = super.getName();
System.out.println(text);
return proceed();
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new B().getName());
}
}
If I run the main method I get this output:
advice
B
Now I hoped that by removing the comment from the line inside
the advice I would get:
A
B
But the code simply doesn't compile, with this message:
The method getName() is undefined for the type Object
I found this message:
https://dev.eclipse.org/mhonarc/lists/aspectj-users/msg12163.html
and it seems quite clearly to explain what's the issue with my example.
Since some time has passed I would like to ask if it's still not possible
to call the base method using super.
Regards,
Karl
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
...............................................................................................................................
Henrique Rebelo
http://www.cin.ufpe.br/~hemr
Centro de Informática
Universidade Federal de Pernambuco , Brazil
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--