Bug 266381 - Support the let() pointcut
Summary: Support the let() pointcut
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-26 16:48 EST by Ramnivas Laddad CLA
Modified: 2009-05-19 19:33 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ramnivas Laddad CLA 2009-02-26 16:48:23 EST
(I thought we had an issue related to this, but couldn't find one).

I come across many situations, where the let() pointcut (http://abc.comlab.ox.ac.uk/documents/abc-2006-1.pdf) would have helped a lot in creating a simpler design.

A common situation under which I encounter the need for the let() pointcut is where I want the base aspect to make no decisions regarding the join point selection criterion. Subaspects then are free to use an annotation-based or name-based pointcut. However, defining the pointcut in the base aspect is challenging. The let() pointcut will let me do a better job.

abstract aspect AbstractSecurity {
    abstract pointcut secured(String role);

    before(String role) : secured(role) {
       ...
    }
}

aspect AnnotationDrivenSecurity extends AbstractSecurity {
       pointcut secured(String role) 
           : execution(@Secured * *(..)) && @annotation(Secured(role));
}

aspect MappingBasedSecurity extends AbstractSecurity {
    Map<String, String> roleMapping; // injected dependency

    pointcut secured(String role)
           : execution(@Secured * *(..))
             && let(role, roleMapping.get(thisJoinPointStaticPart.getSignature());

    /* or more likely something like:
    pointcut secured(String role) : execution(@Secured * *(..)) && let(role, getRole(thisJoinPoint));

    String getRole(JoinPoint jp) {
       ...
    }
    */
}

This way the abstract aspect declares what it absolutely needs and no more. Currently, I end up using the template design pattern, where the base aspect calls a method such as getRole(JoinPoint). For the mapping based subaspect, this is fine. However, for the annotation-based approach, this means using reflection on the thisJoinPoint object.
Comment 1 Ramnivas Laddad CLA 2009-02-26 20:34:36 EST
See bug #266415 for additional examples