Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Pointcut that depends on another pointcut(Creating a pointcut that selects method calls)
Pointcut that depends on another pointcut [message #662034] Tue, 29 March 2011 00:54 Go to next message
Scott Ellis is currently offline Scott EllisFriend
Messages: 5
Registered: March 2011
Junior Member
I'm as noob as noob can be. You've been warned.

I've managed by some miracle to create an aspect (.aj) that selects a set of methods that implement the interface of a common base class.

It looks like this:

pointcut checkInAction() :
! within( auditAspect ) &&
(
execution( * baseAction+.doAction( String ) )
);

The aspect is called auditAspect, the base class is baseAction, and the method is doAction with a String parameter (as I'm sure you can see fromthe syntax of the pointcut.

In the same aspect, I want to create another pointcut that selects all method calls originating from these very same methods found by the checkInAction pointcut that return a specify type, and I know the class and method that is being called.

My best guess so far is this:

pointcut myObjectAccess() :
! within( auditAspect ) && cflow( checkInAction() ) &&
call( public myObjectType myFactory.getObject( .. ) );

This is supposed to say: all calls to myFactory.getObject that return myObjectType invoked with the execution flow of the checkInAction pointcut.

Is this the way it should be done? My goal is to debug an entire process that originates in the baseAction class by logging before and after the baseAction is executed--and in the middle of the various implementations, log objects processed during that execution.

Any thoughts on how to fix my approach, or is there another simpler way?

Re: Pointcut that depends on another pointcut [message #662252 is a reply to message #662034] Tue, 29 March 2011 21:14 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
No, this is not quite right.

Your myObjectAccess() pointcut will only match when the call originates from within the original aspect. But it will not match transitive calls that occur outside of the aspect (but within its cflow).

Assume that you have something like this:
// as before
pointcut checkInAction() :
  ! within( auditAspect ) &&
  (  execution( * baseAction+.doAction( String ) ) );

after() : checkInAction() {
  doCheckInAction();
}

void doCheckInAction { ... }

pointcut myObjectAccess() :... ;

after() : myObjectAccess() {
  doMyObjectAccess();
}

void doMyObjectAccess() { ... }



Now, the question is, what goes here: pointcut myObjectAccess() :... ; ?

Notice how both of the advices delegate to methods? This makes it easier to create cflows based on them.

So, your pointcut would look like this:

pointcut myObjectAccess() : cflow(execution(void doCheckInAction()) && !cflow(execution(void doMyObjectAccess());


The second cflow is important so that recursive calls to the pointcut are filtered out. I haven't tried this out, so the syntax may be slightly off, but I think this should generally work.
Re: Pointcut that depends on another pointcut [message #662627 is a reply to message #662252] Thu, 31 March 2011 10:42 Go to previous messageGo to next message
Scott Ellis is currently offline Scott EllisFriend
Messages: 5
Registered: March 2011
Junior Member
Sorry for the delay--thanks for the reply on this. I've had to read it over a few times to understand what you are saying. I'm going to put this into action today and see how it works. I'll post afterwards (and I have a few more questions!)

AspectJ rocks.
Re: Pointcut that depends on another pointcut [message #663133 is a reply to message #662252] Sun, 03 April 2011 23:38 Go to previous message
Scott Ellis is currently offline Scott EllisFriend
Messages: 5
Registered: March 2011
Junior Member
Ok, I've put your advice into action (no pun intended). Your second cflow check was exactly what I needed because I was getting a stack overflow error due to calls to the call I had targeted with the pointcut.

When you say this:

Quote:
Your myObjectAccess() pointcut will only match when the call originates from within the original aspect. But it will not match transitive calls that occur outside of the aspect (but within its cflow).


I understand this to mean that there are calls that my pointcut specify that won't be called unless within the cflow of my pointcut. This is what I was going for, since the call I am targeting is common within the system I am trying to monitor--so I intend to filter out the calls except for when they are in the cflow of the pointcut.

So it looks like AspectJ is my best friend right now. I have another question, but I'll start another thread.

Thanks!
Previous Topic:Advice not behaving properly
Next Topic:Getting the name of a local variable
Goto Forum:
  


Current Time: Mon Dec 18 01:36:13 GMT 2017

Powered by FUDForum. Page generated in 0.01959 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software