[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Newbie question - How to capture/reset final/private/protected variables
|
Hi,
I am trying to use Aspectj to enable/turn on set of debug flags that
might possibly be non-public (private/protected) while some of them are also
final. I was able to capture the static initializations; But I dont how to
set the final variables nor able to access/reset the private variables.
pointcut setClassLevelFlags() : staticinitialization( *.*) &&
!cflow(adviceexecution()) && within(test1.*);
before() : setClassLevelFlags() {
System.out.println("\tGoing to set the class level variables ...
");
}
after() : setClassLevelFlags() {
//test1.Test1 tt = (Test1) thisJoinPoint.getTarget();
System.out.println("\t\tAfter setting the class level variable
inside staticInitializationBlock");
try {
Object tt = thisJoinPoint.getTarget(); ====> This does not work as
the object is not there
====> this works if an already constructed class...
Class cc = tt.getClass();
Field ff = cc.getField("classLevelDebug");
System.out.println("\t\tAfter setting the classLevelDebug variable
inside staticInitializationBlock, the classLevelDebug is ... " +
ff.getBoolean(tt));
ff.setBoolean(tt, true);
System.out.println("\t\tAfter resetting the classLevelDebug variable
, the classLevelDebug is ... " + ff.getBoolean(tt));
//tt.classLevelDebug = true;
//System.out.println("\t\tAfter resetting the debug variable inside
staticInitializationBlock, the debug is ... " + classLevelDebug);
} catch(Exception e) { System.out.println("Exception thrown on
accessing .. classLevelDebug field");
e.printStackTrace(); }
}
The test code has something like following with either package or private
scope:
public class Test1 {
String aa = "dummy";
boolean debug = false;
static boolean classLevelDebug = false;
...
}
Thanks in advance,
Sabha