Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] binding parts of the formals

Thanks for replying my previous question. The prob. I'm having is actually 
about the way to define a pointcut. What I want to do is, to simplify, as 
the following:
abstract aspect Test
{
   abstract pointcut Test(int t);
   after(int t):Test(t){ //some code do with t}
}

Now, to map the after advice to a concrete pointcut, I have problems if 
the target method has a different signature. For example, class A has 
method : public void Method(int t, int s). Now, suppose int s is the 
argument I'm interested since I know the semantics of the method. 
Theoretically, I only need to extend the abstract pointcut to pass int s 
into my advice. My advice will automatically get executed. But I don't 
know how to do it. I tried the following:

aspect TTest extends Test
{
  pointcut Test(int s):args(t,s)&&call(public void Target.Method(int,int);
}

I thought the "args" construct can pick out the "int s" in the actual 
target code. But it doesnt' work.

This scheme works if Method has only one argument. Is there a way of 
accomplishing this scheme ? Thanks a bunch.

 Charles Zhang 		
Graduate Student, Middleware Systems Research Group
ECE, U. of Toronto (http://www.eecg.utoronto.ca/~czhang)
" Yawn!!"  

On Sun, 9 Mar 2003, Wes Isberg wrote:

> Use * to signify any single argument, or .. for 0+ arguments.
> 
> From the programming guide...
> 
> -- ... state-based pointcuts
> 
>      args(Type or Id or "..", ...)
> 
>   [...] If it is the "*" wildcard, then any argument will match, 
>   and if it is the special wildcard "..", then any number of 
>   arguments will match, just like in signature patterns. 
>   So the pointcut 
> 
>     args(int, .., String)
> 
>   will pick out all join points where the first argument is an int 
>   and the last is a String. 
> 
> -- ... semantics section:
> 
>    Formal parameter lists can use the wildcard .. 
>    to indicate zero or more arguments, so 
> 
>       execution(void m(..))
> 
>    picks out execution join points for void methods named m, 
>    of any number of arguments
> 
> Wes
> 
> http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/apbs02.html#d0e4935
> 
> 
> Charles Zhang wrote:
> > 
> > I found it is cumbersome to write a pointcut. Say a method has 5
> > arguments. Then I need to define all 5 arguments as the formals of my
> > pointcut if I'm only interested in one of them. Is this just because of my
> > limited understanding?
> > Example: class A{ public void Method(int f, int s, int t, int forth, int
> > fifth) {...}};
> > My after advice only tries to check if forth is bigger than fifth. Can I
> > write:
> > after(int forth, int fifth):args(forth,fifth)&&call(public A.Method(//rest
> > of the signature))?
> > 
> > My knowledge tells me this won't work since the "forth" in advice doesn't
> > correspond to the "forth" in method formals. Or does it?
> > 
> > Reason for asking this is that to be able to bind to a subcontext allows
> > me to write more flexible virtual pointcuts.
> > 
> > Thanks.
> > 
> > Charles Zhang
> > Graduate Student, Middleware Systems Research Group
> > ECE, U. of Toronto (http://www.eecg.utoronto.ca/~czhang)
> > " Yawn!!"
> > 
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top