No one will get this reference (well, Jonathan might), but the best code generator I ever used was the FourGen code generators for screens and reports using Informix 4GL.
These generators had some unique properties that I simply haven't seen anywhere else.
1) They were an organic and first class part of your build. That is, when you worked with this tool, you constantly used and reused it. It wasn't a "wizard" that does a simple "one shot" and you're done.
2) You had full control over the generated code. Specifically, if the code generator did something you didn't like, one of its capabilities was letting you add, change, or simply replace generated code.
On the one hand, you interacted with it at a reasonably high level (basically tying code to events), but on the other you also had an almost "sed(1)" like ability to tweak and change code.
If the high level facilities didn't work, you could simply patch the resulting output 4GL, key that for the generator, and it would reapply your patch at build. The code was also organized in a very granular fashion, baring all to the tool.
For example, when it generated the SQL load a form, this seemingly simple process of building a basic select statement was broken out in to 4 or 5 steps (columns, join, join clauses, filter clause, order by). This fine granularity is part of its power, meaning your individual changes have the smallest impact. I could completely replace the logic to build up the filter part of the SQL, without affecting the tools ability to build up the columns and mappings, etc.
This is a simple, almost crude facility, but it offered key value over many other code generator systems. With other systems, if the code generator did something you didn't like, and you had to hack the resulting code, then the value of the code generator vanishes on a future change. Rerun the generator, lose your changes. The more you changed, the more painful the process of rerunning the generator. With FourGen you were able to capture those snippets and make them part of your build, and rerunning the generator happened, literally, all the time -- it was intrinsic to the build.
The more you hacked, the more you took control away from the code generator and accepted the burden. But this was a gradual process and even with some of the most complicated programs, 9 times out of 10 the code generator continued to provide real added value to the dev process over the lifespan of the project. Rarely did I have to just "throw up my hands", annotate my forms with the "keyword of death" namely "do_not_generate", and accept the entire burden on myself.
While modern systems offer a lot of power with their reflective techniques, there's something to be said about being able to "hack the result" when necessary just to get that specific bit of functionality that the framework authors simply didn't envision or tool for.
Hard to convey the real power here, it's a dead tool for a dead language. But, frankly, I haven't seen anything come close to it in 15 years. Believe me, I've looked, and I still go "why is this so hard"?