3 ms·
JavaPoet is a relatively nice library for generating Java sources: https://github.com/square/javapoet https://github.com/square/javapoet
by wtetzner 9y ago
JavaPoet is a relatively nice library for generating Java sources: https://github.com/square/javapoet https://github.com/square/javapoet
- specialist 9y agoThanks. I tried JavaPoet, once apon a time. I'm just a simple bear. I can't keep all the details straight. One strategy I use to cope is round tripping, as a way to confirm I get the expected results. My current approach to code generation: painstakingly hand craft the desired source code output. Then turn that into a template (progressive refinement). Then compare (diff) generated output to manual. Iterate. Many times that means adjusting target to make it easier to generate. Using bytecodes (class file) as the target output adds complexity and more steps. I've been reversing bytecodes for a long time, manually using javap, the decompilers (which are now quite good), and using ASMs code generator plugin for Eclipse (super clever). But it's too fussy, compared to the Java source code strategy.