projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.92k stars 2.4k forks source link

[FEATURE] @FieldNameConstants.Include must be added in a enum for all fields #3756

Open Gaboxondo opened 1 month ago

Gaboxondo commented 1 month ago

Right now, for using Enums within annotation like the Spring boot cache ones, you can't unless you declare the enum field. This right now can be done with the combination of @FieldNameConstnats and @FieldNameConstants.Include

example of usage of this annotation in an Enum

@CacheEvict(value = Colors.Fields.Red)

and there are also a lot of cases for using enums within some other annotations

The problem is that in a Enum you cannot use just one annotation at the class level for creating the fields to ALL the enum values. You have to annotate the class with the @FieldNameConstnats and each param with @FieldNameConstants.Include.

@FieldNameConstants
public class CacheNames {
  @FieldNameConstants.INCLUDE
  ColorsCache,
  @FieldNameConstants.INCLUDE
  TShirstCache,
  @FieldNameConstants.INCLUDE
  CountriesCache;
}

it will be easier to be able to do something like this:

@FieldNameConstants
public class Colors {
  ColorsCache,
  TShirstCache,
  CountriesCache;
}

and just use the exclusion when needed.

This will benefit all people developers of java that are using this type of annotations with enums. In the previous example the enum only had 3 fields but imagine an enum with 20 having to add all of this field-by-field annotation.

Thanks a lot

uapcent commented 1 month ago

That would definitely help me with my current project. I had to add the annotations too many times, i was surprised there wasn't a cleaner way.