Feature request: combine several lombok's annotations into a customized ones

1,348 views
Skip to first unread message

Alexandre Saudate

unread,
Jan 12, 2018, 5:56:58 PM1/12/18
to Project Lombok
It would be nice if we could combine several of lombok's annotations into a single, customized one, that brings together several of lombok's features. For example


Before:


@Data
@Wither
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(accessLevel=AccessLevel.PRIVATE, makeFinal=true)
public class MyPOJO {
    //...
}



After:

@POJO
public class MyPOJO {
    //...
}


And the definition of the POJO annotation :


@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
@Data
@Wither
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(accessLevel=AccessLevel.PRIVATE, makeFinal=true)
public @interface POJO {
}


This way, I can ensure that several classes in my project follows the same standards. 




Marco Servetto

unread,
Jan 12, 2018, 6:02:41 PM1/12/18
to project...@googlegroups.com
Yes, this obviously a good idea and has been proposed many times, but
it seams like is problematic
for some Java annotation processing specific issues....
> --
> You received this message because you are subscribed to the Google Groups
> "Project Lombok" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to project-lombo...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reinier Zwitserloot

unread,
Mar 19, 2018, 5:28:02 AM3/19/18
to Project Lombok
Yes, this is an oft-requested feature. We are not opposed to it at all but it's just really tricky to make; @Getter and company run BEFORE your compiler has produced a list of methods and such (because.. it would have made a list of methods without that getter if it had gotten that far into it!), which also means we have no idea what @POJO means when we hit this file. We can wait until later when we do know what it means, but then the compiler has already generated the list.

So, we have 2 options (and either are already far more complicated than @Data, @Getter, @Value and company are now):

1) Try to retroactively fit the generated methods into the data structures tracking method names and the like. This is especially in javac extremely difficult because it's immutable tree structures all the way down.

2) Tell the compiler to ditch the work its done so far and start over. This is actually a thing you can (easily) do, because annotation processors require this as a general rule, but, the downside is, it's slow. That means using this feature will increase your compile turnaround times noticably.

Add the above difficulties on top of the fact that this feature would be complicated regardless, and you see why it's not been added yet, I hope :P
Reply all
Reply to author
Forward
0 new messages