My first question even if all this is possible and practical, is it worth all the hassle?

My hunch tells me that right now, at best it's seldom used and at worst exotic.

And then about limitations. It's like projecting 3D onto 2D and then trying to get 3D back out of that 2D. It's not just challenging, but some information is lost.

These information can be recorded somewhere (like metadata for generated code), however if we used features like protected regions it'll make it even more challenging. (some heuristics would help though)

Then about loops and conditionals.

The Solution?

The way I think about it right now is that reverse code generation would be like a submodule inside a greater code generation task. Kinda like protected regions. So the reverse generator does not work globally, but only in specific parts of the project. And for those parts, we know that there are no loops or conditionals or complex constructs. UPCASE and down_case transformations etc. may still be practical.

The key lies in the prototype application. The prototype needs to serve a double role:

It is directly executable/buildable as a project in the target platform environment

It can be extracted to form generator templates

So we have to annotate the prototype app in some way. The annotations can be external (like Hibernate/JPA Persistence XML mappings) or internal (like JPA Java annotations, JAX-RS, etc.).

For internal annotations, there seems to be no other way than using the comment capability in the target language, just like protected regions. If the target language doesn't support comments, then the only possible approach is external annotations.