[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Tutorial PCD call/execution
|
Hi,
Hope my response doesn't come too late.
Here you go:
1. create an eclipse project using the 3 classes/aspects below.
2. Before running, notice that in the main method, the first time method() is called, it is advised, but the second time it is not.
3. Also, notice that AClass.method() is advised.
4. Now run it to make sure it works. You should see that the first time method() is called and both times it is executed it is advised.
public class AClass implements AnInterface {
public void method() {
System.out.println("In AClass.method1()");
}
public static void main(String[] args) {
AClass aClass = new AClass();
aClass.method();
AnInterface anInterface = aClass;
anInterface.method();
}
}
public interface AnInterface {
public void method();
}
public aspect AnAspect {
before() : execution(void AClass.method()) {
System.out.println("Advising execution of AClass.method1()");
}
before() : call(void AClass.method()) {
System.out.println("Advising call of AClass.method2()");
}
}
What's happening?
The best way to think of this is in terms of method signatures. The
first time that method() is called, its signature matches the call
pointcut, whereas the second time it is called, there is no match
(because the signature is of type AnInterface). However, both
executions of method() match the execution pointcut and therefore the
advice is run both times.
For more information, see:
http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html
On Mon, Mar 30, 2009 at 1:19 PM, Ricardo Esteves
<rteves.pt@gmail.com> wrote:
Hello everybody,
I'm doing a tutorial for beginners in AspectJ
(I'm a beginner also). The first tutorial should clarify the difference
between the pointcut designator execution and call.
I'm wondering about which scenario would be better for that. The idea is be simple as possible - Simple is beautiful!
The second tutorial should explain how to catch values. The
tutorials don't need to have written explanation, just a simple
example, with simple description and that's it.
Any suggestions?
Thank you in advance.
Best Regards,
Ricardo Esteves
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users