Hi all,
One of the features missing from the
java language is a pre-processor to handle conditional compilation. Many
people will point out that this was only really needed in C++ to handle
different platforms and that its possible to imitate #ifdef kind of constructs using static variables, which is
how the guys at Philips reduce their preprocessing directives for their Koala
component technology.
ie.
private final static boolean DEBUG = true;
..
if(DEBUG)
{ ... some
functionality
} whereby setting DEBUG as a static
variable would cause the compiler to include the code or not.
I've been wondering if it is possible to do the
same thing in AspectJ on advice, whereby the compiler would know that the
branches could not be reached so would not include them.
I put together a simple aspect as shown
below
aspect X
{ private final static
boolean CHECK = false; pointcut
something() : call (public void
SomeClass.printMsg(String)); pointcut check() :
if(CHECK); before() :something()
&& check()
{ //.. some
functionality
} }
but found after checking the bytecode that the
compiler converted the advice into a method even though it would never get
executed.
Is there a reason for this?
Cheers
Neil
|