Skip to main content

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

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


Back to the top