Re: [abc-users] Parameters for aspects

From: Eric Bodden <eric.bodden_at_mail.mcgill.ca>
Date: Thu, 13 Sep 2007 20:52:35 -0400

I am not sure whether I understand correctly what you are trying to achieve.

First of all: Why not just use abstract pointcuts? That's the normal
way to parameterize an aspect and it solves the problem you are
stating.

Secondly, what should be passed to the aspect? Is "methods" an array
of methods or a pointcut that may match methods? If it's the former,
an array can be created in multiple ways and in particular, its
contents are not yet available at compile time. So this is impossible.
In the second case (pointcut), there actually is no pointcut matching
methods in AspectJ. There only is a call-pointcut matching method
calls and an execution pointcut matching method executions. So maybe
"methods" should be a method pattern.

Assume "methods" is a method pattern then you could modify your aspect
to "inline" this pattern into execution pointcuts as you showed. For
that to work, you would have to...

1.) Define a custom AST node for Aspects, storing the additional
method pattern(s).
2.) Define custom AST nodes for execution-pointcuts that can hold a "name".
3.) Change the parser to accept the new syntax and create those nodes.
4.) Create a compiler pass (a visitor) that inlines the nodes:
a) When entering an aspect declaration, push all method patterns on the stack.
b) When seeing an execution pointcut with a "name", resolve that name
via the method patterns on the stack.

Hope that helps,
Eric

On 13/09/2007, Khalid Al-Jasser <k.al-jasser_at_pgrad.unimelb.edu.au> wrote:
> Hi,
>
> I am trying to write an extension that allows me to add parameters in
> aspects.
> for example:
> ----------------------------------------------------------
>
> public aspect SynchAspect(Method [] methods) {
>
> //lock declaration
>
> before(): exection (methods){
> synchronized(this){
> >> synchronization logic
> >> aquiring the lock
> }
> }//end before
>
> after(): execution (methods){
> synchronized(this){
> >> synchronization logic
> >> releasing the lock
> }
> }//end after
> }
> ------------------------------------------------------------
> in the example above, instead of hardcoding the pointcut that includes the
> methods, I
> would like to supply these methods as parameters to the aspect.
> After that, in the before and after advice, I need to "literally" replace
> the $methods$ with the actual passed methods.
> In other words, I need to manipulate the aspect code before compiling it.
>
> I am currently stuck as I don't know any way to manipulate the signature of
> the execution pointcut.
> Any ideas!! can you help please?
> regards,
> Khalid Aljasser
> The University of Melbourne
>
>
>
>

-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada
Received on Fri Sep 14 2007 - 01:52:40 BST

This archive was generated by hypermail 2.2.0 : Sun Sep 30 2007 - 23:50:11 BST