Hi Arne, You could of course use reflection to do this, but I suspect you are seeking a higher performance solution. If that's true, it's not possible to do this kind of code generation with AspectJ: it doesn't give you a way to iterate over members like this. I implemented something quite similar using Javassist (http://www.csg.is.titech.ac.jp/~chiba/javassist/) recently (it's about 10 lines of code), which would be fairly easy to integrate in with AspectJ advice - you might be able to use a pertypewithin aspect to do so (or just have an ITD to hold an accessor object). If you do something like this, you'd want to create something like interface MyExternalizable extends Externalizable and have your ITD be on MyExternalizable, to avoid the complexities of weaving into the Java runtime (which adding an ITD to Externalizable would imply).
Another tool that could help with this kind of task is Spoon (http://spoon.gforge.inria.fr/), although I believe that would require you to change your tool chain. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arne Hormann Sent: Friday, February 16, 2007 10:22 AM To: [email protected] Subject: [aspectj-users] Nonreflective field access in default implementations of interface methods Hi! I'm new to AspectJ and I'm pretty much stuck right now (please help me! ;-P). This is my example scenario: My program is sluggishly slow. After some profiling, I see it spends most of its time serializing and deserializing objects. I want do do some benchmarks with different serialization approaches and want to do so only once, so I change all my serializable classes and replace the "implements Serializable" with a type annotation @Persistable. Now I can try several policies using aspects. First approach: use Externalizable instead of Serializable. I want to do something like this (as I don't know how this should look, I borrowed some syntax from JSP): aspect PersistViaExternalizable { declare parents: (@Persistable *) implements Externalizable; public void Externalizable.readExternal(ObjectInput in) { <% for (Field f : IMPLEMENTING_CLASS.getFields()) { %><%= f.getName() %> = (<%= f.getType() %>) in.readObject(); <% } %> } public void Externalizable.writeExternal(ObjectOutput out) { <% for (Field f : INSTRUMENTED_CLASS.fields) { %>out.writeObject(<%= f.getName() %>); <% } %> } } I read lot's of documentation and didn't find any example or mention of anything remotely this, so I'd really like to hear how this could be done. I know the example is oversimplified (e.g. no support for primitive types), but as the fields and their types/supertypes are statically known this _should_ be possible. Can this be done in AspectJ? How? Any help is greatly appreciated! Regards, Arne Hormann _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
