Saturday 15 August 2015

reflection - How-to programatically access private members trough privileged Aspect in AspectJ? -


I was wondering if I was adding a method to take these initiatives to AspectJ. Check for each object of the class ruby ​​object () This method is considered as a string spitting like # (fullclassname, var1 = val1, var2 = val2, ...)

, so far it is good Is it .getClass (). GetFields () I want all visible fields and this. GetClass () Meet with the Modifier.isPrivate (field.getModifiers ()) (). I give a list of all the private sector ..

The problem here is that I am not able to retrieve the value of private areas as I do with a visual I think that This is normal because the reflecting API I am using is not part of the epitouch, so they do not know that I am running a so-called privileged aspect here.

Since I am in privileged mode, I

Thank you for your help

 

Code> Reflects the public privileged aspect {Private Static Hashmop & lt; Classroom & lt;? Object & gt ;, Arreelist & rt; RubyObject & gt; & Gt; Oostor = new Hashmap & lt; Classroom & lt;? Object & gt ;, Arreelist & rt; RubyObject & gt; & Gt; (); Personal Boolean RubyObject.hasBeenImported = false; Parents Announcement: ca.concordia * Implements Ruby object; // format string # & lt; Classname, var1 = val, var2 = val, ... & gt; // Unfortunately, private data is not received because the privileged aspect may not be with the field. Object (object) public string ruby ​​object Inspect () {string result = "# & lt;" + This.getClass () GetName (); (Field area: this.getClass (). GetFields ()) {try {result = =, "+ field.getName () +" = "+ field.get (this);} hold (exception e) {result = "," + Field.getName () + "= (???)";} // should never be;} (Field field: this.getClass (). GetDeclaredFields ()) {If (Modifier.isPrivate (field .getModifiers ()) Results + = "," + field.getName () + "= (private)";} result = = "& gt;"; return result;}

I had only one problem, and it seems that it is as simple as changing

  Result + = "," + field.getName () + "= (private)";  

to

  field.setAccessible (true) ); Result + = "," + field.getName () + "=" + field.get (this);  

Hope this will help someone!


No comments:

Post a Comment