JodaOrg / joda-beans

Java library to provide an API for beans and properties.
http://www.joda.org/joda-beans/
Apache License 2.0
141 stars 37 forks source link

Allow generation of external Meta-Bean #178

Open andreas-schilling opened 6 years ago

andreas-schilling commented 6 years ago

I wonder if it would be a good idea to optionally allow the generation of external Meta-Beans (just the Meta-Bean in its own class)? This would allow for not having to check in generated code into version control, keep the bean classes more compact and closer to a plain POJO (except the annotations of course and yes, of course they are also sort of plain with all the generated code...) On the flipside one would always have to run the generation step upon a fresh checkout, but I don't think this is much of a drawback (some people might also argue it's the cleaner way).

hackmann commented 6 years ago

Our internal guides say that autogenerated code should not be committed to version control. So I always find it strange when all the autogenerated JodaBeans are committed in full. When I find some time I'll take a look at the maven plugin and see if it's possible to change it to generate the code under target instead of adding to the original file. Similar to how other code generator tools work

andreas-schilling commented 6 years ago

I think it's quite clear that we can implement this sort of thing in the respective generators but I was more trying to understand first whether there are technical reasons for the status quo :-) Thinking some steps ahead: If the generator would allow to plug in extensions that write to different files then anyone could also implement very specific and custom tailored functionality that is based on the metamodel. Of course all of this would also work with stuff going to a single file (the original one), but then code length would get out of hand even more. TL;DR: I think this issue needs the Discussion tag :-)

jodastephen commented 6 years ago

Joda-Beans was intended for a use case where code checked out of a source repo should compile immediately (without any need to run a tool like an annotation processor or maven).

The code isn't that well structured to break out a meta-model for pluggable generators, however that would very much be a good direction to go.

As for the amount of code, the light and minimal bean styles generate less code and may be of interest. Particularly as of the latest release.

andreas-schilling commented 6 years ago

Thanks for jumping in! So there are no hard technical reasons that would not allow the Meta-Beans to be in their own files and/or subpackages, right? Might be an interesting extension then maybe to optionally allow generating them like that.

jodastephen commented 6 years ago

MetaBean is a normal Java interface and can be implemented as such - any way you want.