Lombok: Improve @FieldNameConstants functionality

Created on 29 May 2018  路  2Comments  路  Source: projectlombok/lombok

@FieldNameConstants is realy great, but it generates names like this:
private Date date; becames public static final String DATE = "date";,
which causes generated names to mix with other static fields.
Moreover it is not alway clear if "DATE" is field name, or some date for example.

My suggestion is to prepend FIELD_ prefix to all generated names, so: private String date; will become public static final String FIELD_DATE = "date";

That way generated names are nicely groupped and we immediatelly know what it represent.

Most helpful comment

IMO adding this:

    public String prefix() default "";
    public String suffix() default "";

Into the annotation and then handling that stuff will do. Perhaps the default for prefix could be "FIELD_".

All 2 comments

IMO adding this:

    public String prefix() default "";
    public String suffix() default "";

Into the annotation and then handling that stuff will do. Perhaps the default for prefix could be "FIELD_".

Yup. Added in commit b8e85f5dc7044e9a4bd43c41786bdda2a38f50ac and will be in 1.18.0 to be released soon. It's a bit more involved; you can config prefix and suffix via both the annotation itself and lombok.config

Was this page helpful?
0 / 5 - 0 ratings