square/javapoet ? reverse-engineered prompt

Reverse engineered prompt

Build me a Java library that lets developers generate clean .java source files without hand writing boilerplate strings everywhere. I want an easy fluent API where someone can describe a class, interface, method, constructor, field, parameter, annotation, package name, imports, and modifiers, then turn that into nicely formatted Java source.

It should feel like building a Java file piece by piece. A user should be able to create a HelloWorld class with a main method, add statements, add control flow like if, else, for loops, try and catch, then either print the generated source, get it as a string, or write it to disk.

Please support simple placeholders for generated code, including literals, strings with escaping, and Java types so imports are handled cleanly. Keep the API immutable where it makes sense and use builders so it is pleasant to chain calls. Add tests and a few examples that show the generated code clearly.

Are you gonna build this?

make sure you review the code using coderabbit

Try freeSponsored — opens CodeRabbit in a new tab