[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Accessing private fields
|
Hello everybody!
I'm trying to access private fields by reflection to get a class's
contents, it doesn't work unless i had the code directly into the class
that i want to inspect
In this aspect, I had the function showClassContent() to the class
ExampleMain that I want to inspect :
public aspect TraceMyClasses {
public void ExampleMain.showClassContent() {
Field[] fieldTab = this.getClass().getDeclaredFields();
for(int i=0;i<fieldTab.length-1;i++) {
String fieldName = fieldTab[i].getName();
String fieldValue;
try {
fieldValue=fieldTab[i].get(this).toString();
} catch (IllegalAccessException e) {
fieldValue="Unable to access";
}
}
void around (ExampleMain myClass, Object arg): execution(void *.*(..))
&& this(myClass) && args(arg) {
try { proceed(myClass,arg); }
catch (Exception e) {
myClass.showClassContent();
}
}
}
But I can't get the value of private fields.. How can I do ?
Thanks in advance
Alain