C
Conrad Eaglehill
Hi,
I'm learning AspectJ and running through some example programs, and in
writing aspects, I find that one aspect may relate to another.
For example, I'm creating an application that has a main App class, a
MenuBarAspect aspect, and then a FileMenuAspect aspect, EditMenuAspect
aspect, etc., corresponding to the Menus at the top of the
application. MenuBarAspect defines a JMenuBar variable App.menuBar,
FileMenu defines a JMenu variable App.file, and so on. It compiles and
runs fine. If I remove, say, HelpMenuAspect from the configuration, my
app runs fine, just without a Help menu above, which is perfect.
But if I remove MenuBarAspect from the configuration, it won't compile
because FileMenuAspect, EditMenuAspect, etc., all call the JMenuBar
method add contained within. (so an example line looks like
app.menuBar.add(app.file = new JMenu("File");, but the variable
App.menuBar no longer exists as the aspect that contained the variable
is no longer in the build).
Basically, a solution I envision would be an if statement that
ascertains either the existence of menuBar OR MenuBarAspect in the
build. Then, if I remove MenuBarAspect, the *MenuAspect aspects would
do nothing since they'd fail the if test. Java, as far as I know, has
no such method to do so. A friend mentioned a concept called
refleciton, but I've not really worked with it, though I'm open to it
as a solution. Is there in AspectJ such a way to solve this?
Thanks in advance for the conceptual help,
Conrad Eaglehill
I'm learning AspectJ and running through some example programs, and in
writing aspects, I find that one aspect may relate to another.
For example, I'm creating an application that has a main App class, a
MenuBarAspect aspect, and then a FileMenuAspect aspect, EditMenuAspect
aspect, etc., corresponding to the Menus at the top of the
application. MenuBarAspect defines a JMenuBar variable App.menuBar,
FileMenu defines a JMenu variable App.file, and so on. It compiles and
runs fine. If I remove, say, HelpMenuAspect from the configuration, my
app runs fine, just without a Help menu above, which is perfect.
But if I remove MenuBarAspect from the configuration, it won't compile
because FileMenuAspect, EditMenuAspect, etc., all call the JMenuBar
method add contained within. (so an example line looks like
app.menuBar.add(app.file = new JMenu("File");, but the variable
App.menuBar no longer exists as the aspect that contained the variable
is no longer in the build).
Basically, a solution I envision would be an if statement that
ascertains either the existence of menuBar OR MenuBarAspect in the
build. Then, if I remove MenuBarAspect, the *MenuAspect aspects would
do nothing since they'd fail the if test. Java, as far as I know, has
no such method to do so. A friend mentioned a concept called
refleciton, but I've not really worked with it, though I'm open to it
as a solution. Is there in AspectJ such a way to solve this?
Thanks in advance for the conceptual help,
Conrad Eaglehill