Bug 149260 - Allow declare precedence to override default advice precedence based on inheritance
Summary: Allow declare precedence to override default advice precedence based on inher...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-29 20:50 EDT by Ron Bodkin CLA
Modified: 2013-06-24 11:05 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 Ron Bodkin CLA 2006-06-29 20:50:27 EDT
I would like to be able to control the precedence of advice from an abstract base aspect in a concrete derived aspect, i.e., to change so that the concrete aspect's advice can run with lower precedence. Unfortunately, declare precedence only defines precedence with respect to concrete aspects (*). So you can't order advice to make this example program print AB:

abstract aspect Base {
    abstract protected pointcut run();
    after() returning : run() {
        System.out.print("A");
    }
}
    
public aspect Derived extends Base {
    declare precedence: Base, (!Base && Base+); // no-op!

    public static void main(String argz[]) {
    }
    protected pointcut run() : execution(* main(..));
    after() returning : run() {
        System.out.print("B");
    }
}

My work-around is to use a static inner aspect that has the advice. This works for singleton aspects but is trickier for perXXX aspects.

The real use case I have for this is to allow capturing additional data in a concrete monitoring subaspect's after advice before the abstract base aspect's after advice runs... In my case I don't want to use a template method because the common base aspect advice typically advises case1()||case2()||case3() and I want to run different after advice on case1(), case2(), and case3() before the common base aspect's generic advice, after binding additional context data (often this or args). Because I need to advise additional data, I can't extract a method in the base aspect and advise that.

(*) My memory was rusty so I had to reread the programmer's guide. It would also be helpful if it produced a warning if you try to use declare precedence with an abstract aspect as a specific type.
Comment 1 Andrew Clement CLA 2013-06-24 11:05:19 EDT
unsetting the target field which is currently set for something already released