Home » Language IDEs » AspectJ » multiple formal parameters?
multiple formal parameters? [message #34081] |
Fri, 16 April 2004 06:16  |
Eclipse User |
|
|
|
I am frustrated - I don't get it!
I want to specify an advice that has TWO parameters and I need access
to BOTH parameters in the advice.
I was able to phrase that as an "anonymous" pointcut (I think that's
the name for something like this):
....
before(IEvent evt, boolean flag): target(evt) && call(*
IEvent.setHandled(boolean)) && args(flag) {
...
}
....
But now I would like to specify this as a NAMED pointcut (1st to make
this more readable and 2nd to reuse the pointcut in more than one
advice):
I defined the pointcut:
....
pointcut eventSetHandled(IEvent evt, boolean flag): target(evt) &&
call(* IEvent.setHandled(boolean)) && args(flag);
And now I want to specify the advice. But how do I phrase this? I
tried:
before(IEvent evt, boolean flag): eventSetHandled(IEvent, boolean)
{ ... }
before(IEvent evt, boolean flag): eventSetHandled(IEvent evt,
boolean flag) { ... }
before(IEvent evt, boolean flag): eventSetHandled(evt, flag) {
.... }
???
None of the above work, i.e. all variants just yield compile errors!
How do I phrase this? What do I need to specify to get hold of more
than a single parameter of a named pointcut??? Or is this not possible
at all?
Alas, all the examples given in the AspectJ manual only show a single
parameter...
Michael
|
|
|
Re: multiple formal parameters? [message #34150 is a reply to message #34081] |
Fri, 16 April 2004 08:13   |
Eclipse User |
|
|
|
Originally posted by: clemas.uk.ibm.com
Hi,
What you want to do is possible. The third variant you quote below works.
i.e. this works for me:
pointcut eventSetHandled(IEvent evt,boolean flag):
target(evt) &&
call(* IEvent.setHandled(boolean)) &&
args(flag);
before(IEvent evt, boolean flag): eventSetHandled(evt,flag) {
System.err.println("In advice! evt="+evt+" flag="+flag);
}
And I'd probably drop the type reference in the call() PCD since you are
using target(). If you want other examples of multiple parameters, take a
look at the Enterprise AOP tutorial presentation downloadable from
http://www.newaspects.com/presentations
Andy.
Michael Moser wrote:
> I am frustrated - I don't get it!
> I want to specify an advice that has TWO parameters and I need access
> to BOTH parameters in the advice.
> I was able to phrase that as an "anonymous" pointcut (I think that's
> the name for something like this):
> ....
> before(IEvent evt, boolean flag): target(evt) && call(*
> IEvent.setHandled(boolean)) && args(flag) {
> ...
> }
> ....
> But now I would like to specify this as a NAMED pointcut (1st to make
> this more readable and 2nd to reuse the pointcut in more than one
> advice):
> I defined the pointcut:
> ....
> pointcut eventSetHandled(IEvent evt, boolean flag): target(evt) &&
> call(* IEvent.setHandled(boolean)) && args(flag);
> And now I want to specify the advice. But how do I phrase this? I
> tried:
> before(IEvent evt, boolean flag): eventSetHandled(IEvent, boolean)
> { ... }
> before(IEvent evt, boolean flag): eventSetHandled(IEvent evt,
> boolean flag) { ... }
> before(IEvent evt, boolean flag): eventSetHandled(evt, flag) {
> .... }
> ???
> None of the above work, i.e. all variants just yield compile errors!
> How do I phrase this? What do I need to specify to get hold of more
> than a single parameter of a named pointcut??? Or is this not possible
> at all?
> Alas, all the examples given in the AspectJ manual only show a single
> parameter...
> Michael
|
|
|
Re: multiple formal parameters? [message #34183 is a reply to message #34150] |
Fri, 16 April 2004 09:09  |
Eclipse User |
|
|
|
Indeed - the third variant works.In fact I got this compiled just
before I saw your append, so I seem to get a first "feeling" for this
somewhat strange syntax. But why it didn't compile before remains
beyond me.
Anyway - thanks a lot! I highly appreciate your help!
And thanks for the link, too! Already on the way to the printer...
Michael
PS.: I'm still puzzled about this exception example - see my other
thread...
"Andy Clement" <clemas@uk.ibm.com> wrote in message
news:c5oili$1ja$1@eclipse.org...
> Hi,
>
> What you want to do is possible. The third variant you quote below
works.
>
> i.e. this works for me:
>
> pointcut eventSetHandled(IEvent evt,boolean flag):
> target(evt) &&
> call(* IEvent.setHandled(boolean)) &&
> args(flag);
>
> before(IEvent evt, boolean flag): eventSetHandled(evt,flag) {
> System.err.println("In advice! evt="+evt+" flag="+flag);
> }
>
>
> And I'd probably drop the type reference in the call() PCD since you
are
> using target(). If you want other examples of multiple parameters,
take a
> look at the Enterprise AOP tutorial presentation downloadable from
>
> http://www.newaspects.com/presentations
>
> Andy.
>
> Michael Moser wrote:
>
> > I am frustrated - I don't get it!
>
> > I want to specify an advice that has TWO parameters and I need
access
> > to BOTH parameters in the advice.
>
> > I was able to phrase that as an "anonymous" pointcut (I think
that's
> > the name for something like this):
> > ....
> > before(IEvent evt, boolean flag): target(evt) && call(*
> > IEvent.setHandled(boolean)) && args(flag) {
> > ...
> > }
> > ....
>
> > But now I would like to specify this as a NAMED pointcut (1st to
make
> > this more readable and 2nd to reuse the pointcut in more than one
> > advice):
>
> > I defined the pointcut:
> > ....
> > pointcut eventSetHandled(IEvent evt, boolean flag): target(evt) &&
> > call(* IEvent.setHandled(boolean)) && args(flag);
>
> > And now I want to specify the advice. But how do I phrase this? I
> > tried:
>
> > before(IEvent evt, boolean flag): eventSetHandled(IEvent,
boolean)
> > { ... }
> > before(IEvent evt, boolean flag): eventSetHandled(IEvent evt,
> > boolean flag) { ... }
> > before(IEvent evt, boolean flag): eventSetHandled(evt, flag) {
> > .... }
> > ???
>
> > None of the above work, i.e. all variants just yield compile
errors!
> > How do I phrase this? What do I need to specify to get hold of
more
> > than a single parameter of a named pointcut??? Or is this not
possible
> > at all?
>
> > Alas, all the examples given in the AspectJ manual only show a
single
> > parameter...
>
> > Michael
>
>
|
|
|
Re: multiple formal parameters? [message #578484 is a reply to message #34081] |
Fri, 16 April 2004 08:13  |
Eclipse User |
|
|
|
Hi,
What you want to do is possible. The third variant you quote below works.
i.e. this works for me:
pointcut eventSetHandled(IEvent evt,boolean flag):
target(evt) &&
call(* IEvent.setHandled(boolean)) &&
args(flag);
before(IEvent evt, boolean flag): eventSetHandled(evt,flag) {
System.err.println("In advice! evt="+evt+" flag="+flag);
}
And I'd probably drop the type reference in the call() PCD since you are
using target(). If you want other examples of multiple parameters, take a
look at the Enterprise AOP tutorial presentation downloadable from
http://www.newaspects.com/presentations
Andy.
Michael Moser wrote:
> I am frustrated - I don't get it!
> I want to specify an advice that has TWO parameters and I need access
> to BOTH parameters in the advice.
> I was able to phrase that as an "anonymous" pointcut (I think that's
> the name for something like this):
> ....
> before(IEvent evt, boolean flag): target(evt) && call(*
> IEvent.setHandled(boolean)) && args(flag) {
> ...
> }
> ....
> But now I would like to specify this as a NAMED pointcut (1st to make
> this more readable and 2nd to reuse the pointcut in more than one
> advice):
> I defined the pointcut:
> ....
> pointcut eventSetHandled(IEvent evt, boolean flag): target(evt) &&
> call(* IEvent.setHandled(boolean)) && args(flag);
> And now I want to specify the advice. But how do I phrase this? I
> tried:
> before(IEvent evt, boolean flag): eventSetHandled(IEvent, boolean)
> { ... }
> before(IEvent evt, boolean flag): eventSetHandled(IEvent evt,
> boolean flag) { ... }
> before(IEvent evt, boolean flag): eventSetHandled(evt, flag) {
> .... }
> ???
> None of the above work, i.e. all variants just yield compile errors!
> How do I phrase this? What do I need to specify to get hold of more
> than a single parameter of a named pointcut??? Or is this not possible
> at all?
> Alas, all the examples given in the AspectJ manual only show a single
> parameter...
> Michael
|
|
|
Re: multiple formal parameters? [message #578506 is a reply to message #34150] |
Fri, 16 April 2004 09:09  |
Eclipse User |
|
|
|
Indeed - the third variant works.In fact I got this compiled just
before I saw your append, so I seem to get a first "feeling" for this
somewhat strange syntax. But why it didn't compile before remains
beyond me.
Anyway - thanks a lot! I highly appreciate your help!
And thanks for the link, too! Already on the way to the printer...
Michael
PS.: I'm still puzzled about this exception example - see my other
thread...
"Andy Clement" <clemas@uk.ibm.com> wrote in message
news:c5oili$1ja$1@eclipse.org...
> Hi,
>
> What you want to do is possible. The third variant you quote below
works.
>
> i.e. this works for me:
>
> pointcut eventSetHandled(IEvent evt,boolean flag):
> target(evt) &&
> call(* IEvent.setHandled(boolean)) &&
> args(flag);
>
> before(IEvent evt, boolean flag): eventSetHandled(evt,flag) {
> System.err.println("In advice! evt="+evt+" flag="+flag);
> }
>
>
> And I'd probably drop the type reference in the call() PCD since you
are
> using target(). If you want other examples of multiple parameters,
take a
> look at the Enterprise AOP tutorial presentation downloadable from
>
> http://www.newaspects.com/presentations
>
> Andy.
>
> Michael Moser wrote:
>
> > I am frustrated - I don't get it!
>
> > I want to specify an advice that has TWO parameters and I need
access
> > to BOTH parameters in the advice.
>
> > I was able to phrase that as an "anonymous" pointcut (I think
that's
> > the name for something like this):
> > ....
> > before(IEvent evt, boolean flag): target(evt) && call(*
> > IEvent.setHandled(boolean)) && args(flag) {
> > ...
> > }
> > ....
>
> > But now I would like to specify this as a NAMED pointcut (1st to
make
> > this more readable and 2nd to reuse the pointcut in more than one
> > advice):
>
> > I defined the pointcut:
> > ....
> > pointcut eventSetHandled(IEvent evt, boolean flag): target(evt) &&
> > call(* IEvent.setHandled(boolean)) && args(flag);
>
> > And now I want to specify the advice. But how do I phrase this? I
> > tried:
>
> > before(IEvent evt, boolean flag): eventSetHandled(IEvent,
boolean)
> > { ... }
> > before(IEvent evt, boolean flag): eventSetHandled(IEvent evt,
> > boolean flag) { ... }
> > before(IEvent evt, boolean flag): eventSetHandled(evt, flag) {
> > .... }
> > ???
>
> > None of the above work, i.e. all variants just yield compile
errors!
> > How do I phrase this? What do I need to specify to get hold of
more
> > than a single parameter of a named pointcut??? Or is this not
possible
> > at all?
>
> > Alas, all the examples given in the AspectJ manual only show a
single
> > parameter...
>
> > Michael
>
>
|
|
|
Goto Forum:
Current Time: Thu May 01 22:24:23 EDT 2025
Powered by FUDForum. Page generated in 0.04194 seconds
|