Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Tutorial PCD call/execution

Thank you a lot for your reply! It was very useful!

Now  I would like to create a scenario where we want to capture a specific value. This scenario could be divided in different ones where the value could be a primitive value, an object, an argument (if it's the first, the 3rd or the last) , etc. The idea is to create just one simple class with some methods and show with different aspects the idea of "capture the value".

Any idea about how I can do that?

The goal is to show this example to aspectJ beginners as an simple tutorial.

Just simple examples about how to do that, will be apreciated! :)

Thank you very much in advance.
Best Regads,

Ricardo Esteves


On Thu, Apr 2, 2009 at 6:26 AM, Andrew Eisenberg <andrew@xxxxxxxxxxxx> wrote:
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



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top