Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] DISCUSS: Syntax change suggestion

Hi,

Interesting.  When I first read it, I preferred:

before : aMethodIWantToAdvise(String foo, Bar bar) {

rather than

before(String foo, Bar bar) : aMethodIWantToAdvise {

Then I thought about exceptions and how they'd look in the signatures:

after throwing(Exception e): aMethodIWantToAdvise(String foo, Bar bar)
or
after throwing(Exception e) throws IOException:
aMethodIWantToAdvise(String foo, Bar bar)

and that almost tempted me back to the other syntax where the
parameters are only expressed on the advice (since then the order
matches method order: parameters followed by exceptions):

after(String foo, Bar bar) throwing(Exception e): aMethodIWantToAdvise

but there is just something about that pointcut not having arguments
that I don't like.  I think having none suggests to me that any
parameters it has shouldn't be bound in the advice.  Probably because
I am thinking about this kind of syntax where some parts of the
pointcut are discarded:

before(String foo) throwing(Exception e): aMethodIWantToAdvise(foo,*)

Of course, as it is optional syntax, perhaps when using Exception
parameters or clauses the 'traditional' syntax is used, and the more
concise variant is only used for simple declarations.

I think that leaves me voting for:

before : aMethodIWantToAdvise(String foo, Bar bar) {

But I should also probably say that syntax sugar tends to be low on
the priority list whilst there are more serious bugs - hence the new
intertype syntax has dropped down the priority list already due to
just being sugar (and that it requires some serious engineering due to
the need to change that grammar file - always a horrible job!).

I guess I can also see the value in supporting finally with after -
I'd say that was a different enhancement request.  And you are right,
as finally already is a keyword it wouldn't be a nightmare task to
support it :)

I should spend more time on the groovy/aspectj integration as I get a
lot of requests for projects to support all 3 languages
(java/groovy/aspectj) - so whilst we're on a syntax discussion - does
anyone want to scribble out a DSL for AspectJ code style in groovy?
I'm wondering how neat we could get it.  Suppose you wanted to write
your aspect in groovy code.  There is annotation style, of course, but
is there a groovy DSL form that looks like the existing AspectJ code
style (perhaps even covering ITDs and not just advice...)

Andy

On 5 February 2010 16:33, Matthew Adams <matthew@xxxxxxxxxxxxxxx> wrote:
> Hi all,
>
> I wanted to kick a syntax enhancement idea around in the group a little.
>
> Consider the following declaration that creates before advice on any
> method defined on Bar with the name aMethodIWantToAdvise that takes a
> String as its first argument.
>
>    public aspect X {
>        pointcut aMethodIWantToAdvise(String foo, Bar bar) :
>            execution(* aMethodIWantToAdvise(..))
>            && args(foo)
>            && target(bar);
>
>        before(String foo, Bar bar) : aMethodIWantToAdvise(foo, bar) {
>            // ...
>        }
>    }
>
> At first glance, it appears that the syntax declaring the before
> advice could be shortened to the following.  Note that lack of
> argument names following the pointcut name -- there's less
> duplication.
>
>        before(String foo, Bar bar) : aMethodIWantToAdvise {
>            // ...
>        }
>
> I was thinking about suggesting a syntax sugar enhancement to support
> this in the event that the pointcut name and the argument list
> following before (and after & around) are sufficient to uniquely
> identify the pointcut in question.  This makes the advice declaration
> easier to write and it makes it read better, especially in this case,
> where the pointcut name is the same as the method name.
>
> What do you think?
>
> While writing this, it occurred to me that reordering this statement
> would be a nice alternative as well -- consider the ":" to be silent.
>
>        before : aMethodIWantToAdvise(String foo, Bar bar) {
>            // ...
>        }
>
> This syntax is so intuitive that I find it compelling enough to want
> to enter an enhancement request for it.  Check how it makes after
> advice look -- pretend the ":" can be read as "from".
>
>        after throwing : aMethodIWantToAdvise(String foo, Bar bar) {
>            // ...
>        }
>
> or
>
>        after returning : aMethodIWantToAdvise(String foo, Bar bar) {
>            // ...
>        }
>
> Now I'm on a roll.  :)  It's always kind of bugged me that an
> unqualified "after" means "after finally" -- it's a small gotcha for
> newbies.  Since finally is already a Java keyword, why not allow it to
> optionally follow after, just like throwing and returning?
>
>        after finally : aMethodIWantToAdvise(String foo, Bar bar) {
>            // ...
>        }
>
> would be the same as (":" is silent again)
>
>        after : aMethodIWantToAdvise(String foo, Bar bar) {
>            // ...
>        }
>
> The current syntax could still be supported, of course, but I find
> this syntax sugar quite tasty.  You?  I wanted to kick it around a
> little before entering this as an enhancement request for AspectJ 1.7
> (or 2.0?) just to gauge the community's interest.
>
> -matthew
>
> --
> mailto:matthew@xxxxxxxxxxxxxxx
> skype:matthewadams12
> yahoo:matthewadams
> aol:matthewadams12
> google-talk:matthewadams12@xxxxxxxxx
> msn:matthew@xxxxxxxxxxxxxxx
> http://matthewadams.me
> http://www.linkedin.com/in/matthewadams
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top