dropbox / djinni

A tool for generating cross-language type declarations and interface bindings.
Apache License 2.0
2.88k stars 487 forks source link

Suggestion: Code generated based on template files #368

Open paulocoutinhox opened 6 years ago

paulocoutinhox commented 6 years ago

Hi,

I see some people, like me, always needing change some objc file or java file to put some macro, annotation or something like this to support React native or other tools. I see people needing modify record files with more code and etc.

So thinking yesterday about it, i want make a new version with template support. All current code will be based on a template to generate the exact same files. But we can use parameters to change the template to point to a template file.

Searching for template engines, i think that Velocity template is simple and powerful for this requirement: http://www.baeldung.com/apache-velocity

1 - Template for individual functions 2 - Template for final files with the generated code

What Djinni team think about?

artwyman commented 6 years ago

Interesting idea. I think the key will be how much customization you can manage to have while still giving the generator the ability to generate the different code it needs. That could get arbitrarily complicated. It's easy to think how to templatize and customze a single case, but making it work for all cases would be a challenge. Similarly adding a few specific customization points (like extra code to insert at the top of the file, or at the bottom of each generated class) would be straightforward, but getting into small-scale customization like individual arguments would likely be harder.

If you want to try to prototype something, go for it. I'm excited to see what you can come up with.

paulocoutinhox commented 6 years ago

Sure. The idea is leave the developer free to customize function template and file template without need change djinni like other forks in github. If we can change all files and generated functions using a parameter to set a different template from original, i think that djinni can be high customisable.

I will try something and make a pull-request here.

paulocoutinhox commented 6 years ago

I read some Generator classes, but need make a bigger work to use the template file. Today i see that have some part of generated file that is in other small functions than the generator method. The best way is move every code generation to only one function to i understand the logic, generate the template and after apply the same logic inside the template and dont inside the generator method. Today the code is not clear enough.