Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] parameter evaluation and advice

How can you tell that the code is being evaluated from the byte code? And
what do you mean exactly when you say it is being evaluated?

Something else to consider when developing a Aspect like this. You are
developing an aspect that provides cross-cutting advice to code that would
lend itself perfectly to being an Aspect itself. The ability to determine if
code should be logged or not logged should reside in the Logger class
itself. Ie:

Logger implementation:
public static void log(String s) {
    if Logger.isDebugEnabled()
	log s
}

That being said, your idea would work well for legacy code that contains
System.out.println(String s) as it's logging mechanism.

AR. 


-----Original Message-----
From: Peter Kalmus [mailto:peterlists@xxxxxxxxx]
Sent: November 4, 2003 2:57 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] parameter evaluation and advice


Consider the following advice:

    void around(Logger aLog) :
        call(public * Logger.debug(..))
        && target(aLog)  {
            if (aLog.isDebugEnabled()) {
                proceed(aLog);
            } 
        }

This advice works as expected - it prevents calls to log.debug(myString)
from executing if log is
not debugEnabled.  

However, testing for a side effect on myString or examining byte code
reveals that the parameter
to the debug() method ('myString') is being evaluated, even if log is not
debugEnabled and
proceed() is never called.

I'm not familiar with how AspectJ is implemented, but... is there a way to
prevent parameter
evaluation in this example?  

Thanks,
Peter Kalmus

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top