Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Suggestion: Code generated based on template files #368

Open
paulocoutinhox opened this issue May 18, 2018 · 3 comments
Open

Suggestion: Code generated based on template files #368

paulocoutinhox opened this issue May 18, 2018 · 3 comments

Comments

@paulocoutinhox
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants