-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a custom method name prefix #78
Conversation
|
I understand your concern as it is not the way the library is currently configured. Let me explain on this example, why I think a global configuration is a good idea.
I have four different libraries on my little class jaxb, pojobuilder, validation and my own. There are around 80 such classes. I want to keep it a DRY and maintain it all in one place. My dream would be to have a configuration annotation
The Configuration would allow two things.
|
I feel your pain :) Are you aware Pojobuilder now supports meta-annotations (https://github.com/mkarneim/pojobuilder#default-configuration-and-meta-annotations). This allows You can also have a single external class full of static factory methods if that suits you and remove the PB annotation from the pojos themselves:
Back to the code though. I think you have two excellent items here but have conflated them so they serve a single narrow usecase of both at once:
|
I know about meta-annotations and static factory methods I use them both now. But still it can't top this global configuration.
What next? |
I really like the idea of setting processor-level defaults via processor config (how can you have a global annotation, what does it sit on, how do you stop there being >1 etc...) My personal opinion (I'm not the owner of PB) is that you should cancel the PR and submit two enhancements. |
I also think these are two features in one. Right now I am short of time - I will have a closer look at the weekend. |
I am trying to do something like @GeneratePojoBuilder(... withMethodPrefix="myPrefix") How should I set the prefix in PropertyM?
Should it be there at all? this forces getOrCreate to provide the parameter and I don't have the prefix in all cases in the Directive. You can see what I mean here. |
I'd say the name of the You could replace This is going to conflict horribly with PR #79 as we've edited all the same lines of code :) |
I would copy the name pattern to some central place inside the BuilderM and then pass that pattern to the PropertyM whenever I want to generate the actual method name. I have implemented this feature into this branch: https://github.com/mkarneim/pojobuilder/tree/feat-settername If this solution solves the issue "allow a custom method name prefix" for you, I would like to merge it into the master branch and close this issue here. Concerning the other issue about "global configuration" I would suggest that you open another issue so we can discuss it there. Comments? |
tried out the feat-settername branch. It Is perfect |
This contribution allows to provide a custom method name prefix instead of "with"
IMHO "with" is obsolete, as it is clear when using a builder. Also it is too much redundancy.
How to set a custom prefix or remove it.
There are two ways.
The property file should contains the key net.karneim.pojobuilder.methodnameprefix=xx
http://docs.oracle.com/javase/7/docs/technotes/guides/apt/GettingStarted.html
add argument -Anet.karneim.pojobuilder.methodnameprefix=xx to annotation processor.
Maven Example:
Depending on the eclipse and m2e annotation processor setup this setting will be also used by eclipse.