Patrick BRUNETON wrote:
> In a plugin I have written for my company, I did something like this.
> It's possible to inject/modify code but not always easy because the code
> model is mostly in "write once" mode.
> For example I do this :
>
> private void augmenterGetSetObjetBD(JDefinedClass classeObjetBD)
> {
> for (JMethod m : classeObjetBD.methods())
> {
> if (m.name().startsWith("set"))
> {
> m.body().directStatement("setChanged();");
> }
> ...
>
> For some more complex modifications (e.g. changing return type, modify
> annotations, modify method names, etc.) I had to use reflection on
> com.sun.codemodel classes.
Yeah, I know what you mean.
I think we can do what you are doing better, by allowing your plugin to
tell FieldRenderer and ask it to do something like:
1. inject this code after the property is changed
2. inject this code before the property is read
etc. Those are the "hooks" that I mean. In this way you can inject your
code in much safer fashion.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com