Add "suffix" configuration option to @Setter/@Getter (like "prefix" option)

662 views
Skip to first unread message

Klaro

unread,
May 15, 2017, 5:07:32 PM5/15/17
to Project Lombok
Hi!

For those who use prefixes (like "m_") for field variables, @Setter and @Getter can already be configured with the "lombok.accessors.prefix" option to strip these prefixes.

Consequently, there should be a way to configure suffixes the same way. I recommend (and wish!) to have a "lombok.accessors.suffix" configuration option. This should not be a big change since Lombok can already handle prefixes.

I might be the only person on the world using a name suffix for fields, but this new option would help me to keep my naming convention. ;-)

What do you think?

---

Furthermore, I suggest to lift the above configuration options into the annotation itself (e.g. with new annotation parameters "prefixesToStrip" and "suffixesToStrip"). Thus I could avoid to use a configuration file, which reduces the footprint of Lombok in projects.

Code could look like this:

public class MyClass {
@Setter(prefixesToStrip = { "m_" }, suffixesToStrip = { "$" })
@Getter(prefixesToStrip = { "m_" }, suffixesToStrip = { "$" })
private String m_myMember$;


Using these new suggested parameters could especially be useful if using @Getter/@Setter on class level.
 
@Setter(prefixesToStrip = { "m_" }, suffixesToStrip = { "$" })
@Getter(prefixesToStrip = { "m_" }, suffixesToStrip = { "$" })
 public class MyClass {
private String m_myMember1$;
private String m_myMember2$;
private String m_myMember3$; 


What do you think?

Roel Spilker

unread,
May 15, 2017, 5:14:45 PM5/15/17
to Project Lombok
I don't see the added benefits outweigh the additional maintenance costs. I've never encountered such naming convention before, where it doesn't contain information that you would like to be available in the getters/setters/etc. as well.

Regarding your suggestion to add the prefixes to the getter/setter annotation, it already exists in @Accessors. See https://projectlombok.org/features/experimental/Accessors.html

Klaro

unread,
May 28, 2017, 12:29:54 PM5/28/17
to Project Lombok
Correct: a prefix option already exists in @Accessors. But consequently, a suffix option should be available - this is missing.

Even eclipse allows to configure prefixes and suffixes for fields (see Window -> Preferences -> Java -> Code Style).

Reinier Zwitserloot

unread,
Jul 10, 2017, 3:41:54 PM7/10/17
to Project Lombok
I'm pretty sure you're the only one in the world who does that.

If I put in a big pile all the crazy conventions, then the consequence is that @Setter and co end up having about 70 different parameters, all for obscure naming conventions.

I'm pretty sure we can all agree that there are only 3 options:

1. Lombok ships with only configurations for very common styles.

2. Lombok ships with 70 different options for all styles under the sun.

3. Lombok ships with only configurations for very common styles... and your pet exotic style.

#1 is better than #2, and #3... well, I also want a pony and a unicorn, but I'm not getting that either.

Not something we're going to be adding, unfortunately.
Reply all
Reply to author
Forward
0 new messages