Volodymyr Kushnir
unread,Apr 27, 2025, 2:25:23 PMApr 27Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Project Lombok
Instead of reviewing tons of requests for custom annotations which are quite similar to what Lombok already have, - it would be great to introduce annotation which will be a marker that current annotation has Lombok annotations inside.
This will increase amount of ways Lombok annotations can be re-used and decrease amount of annotations Lombok need, - because you can compose annotations in the way you need (even if such combination is pretty weird from Lombok team perspective).
It even can replace existing @Data and @Value annotations since there will be a lot of options which might better suit your needs. Existing @UtilityClass may be replaced with custom annotation which applies @NoArgsConstructor(access = AccessLevel.PRIVATE) and so on...
How it can be used: basically in the server side application you have only few categories of DTO's or other components, so you will be able create few annotations and re-use them again and again.
Example of how coupling works for JSR303 (there is no marker annotation):
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Documented
@NotNull
@Size(min = 3, max = 30)
@Constraint(validatedBy = {})
public @interface Name
{
// content is not important
}
Example of how annotations in Jackson marked with marker annotation:
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonMerge
{
// content is not important
}
As an example it will be easy to achieve having annotation which will be quite similar to existing @Data but without required arg constructor and having for example protected setters:
@Target({TBD})
@Retention(RetentionPolicy.RUNTIME)
@Getter
@Setter(value = AccessLevel.PROTECTED)
@ToString
@EqualsAndHashCodde
@LombokAnnotationInside // lombok marker to be added to let lombok know it should handle it as container of other lombok annotations
public @interface YourCustomDtoAnnotation
{
// content is not important
}
Using custom annotation will prevent from situations when annotations like @Data are used and then tuned with other annotations to achieve expected results.
Using custom annotation also have benefits for the end-user cause it may contain extra information within (not sure this has value for Lombok itself, but potentially it may contain some extra fields to configure or tune code generation)
Impact on the annotation processor logic.
Now Lombok finds usage of supported annotations and apply corresponding handlers.
This most likely will not change, but in addition to that it will also look for the annotations marked as container annotation. For found annotations it will check which Lombok annotations are added and will re-use existing annotation handlers. Probably it will need its own handler to extract information from custom annotation and delegate calls to other handlers.
Its hard to predict how existing Lombok annotation handlers will change, but new annotation handler definitely will need to pass information about annotated target.
Let me know what do you think about this!
Thanks,
Volodymyr