Accessing context from advices in AspectJ

Alan Cyment <[email protected]>
Newsgroups gmane.comp.programming.aspect.general
Message-ID <[email protected]>
Hi everyone out there! I'm currently working on an analysis of how context is accessed by advice in AspectJ (i.e. how advice code interacts with active objects either through pointcuts parameters or by using the thisJoinPoint object).  
 
The example I'm working on is the classic Point & Line case: a simplified drawing application that uses a Display object and that offers the user the chance to define both Points and Lines. In the original example, the only existing advice does not need to interact with the Points and Lines, so I decided to change the scenario a little bit: instead of updating the whole screen, we wish to (in Windows terms) invalidate the smallest region that contains the shapes that have changed their position.

This new requirement forces the advice code to retrieve from the shapes the region they take up on the screen. The following is the cleanest solution I could find in AspectJ:

public aspect UpdateSignaling {

    pointcut changePoint(Point P): 
        ((execution(void Point.set*(int))) || 
        (execution(void Point.moveBy(int,int))))
        && target(P);
        
    pointcut changeLine(Line L) :    
        (execution(void Line.moveBy(int,int)))
        && target(L);
    
    after(Point P) returning: changePoint(P){
        Display.update(P.getX(),P.getY(),P.getX(),P.getY());}

    after(Line L) returning: changeLine(L) {
        Display.update(L.getP1().getX(),L.getP1().getY(),
                                        L.getP2().getX(),L.getP2().getY());}

 }

Do you think there's a way of avoiding the need for two advices? And for advices to actually have to know a shape's inner structure?

Cheers,
Alan



_______________________________________________
discuss mailing list    -    [email protected]

To unsubscribe and change options, go to:
http://aosd.net/mailman/listinfo/discuss_aosd.net

Check out the AOSD.net Wiki: http://aosd.net/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.