Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Lombok annotations as a meta-annotation?

I want to define my own annotation for transfer objects and include there some Lombok annotations as meta-annotations:

@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Data @NoArgsConstructor @AllArgsConstructor public @interface TransferObject { } 

The intent is to annotate all my transfer objects with @TransferObject and "inherit" all of the above. In practice it doesn't work, classes annotated with @TransferObject are not processed by Lombok.

Is there some way to get this working? If not, it it theoretically possible to enhance Lombok to look for meta-annotations?

Note: I'm on Java 8.

UPDATE: It looks like there's a feature request for this on github.

like image 346
Bogdan Calmac Avatar asked Nov 04 '15 02:11

Bogdan Calmac


People also ask

Are annotations metadata?

The rows or tuples are the data, and the columns would be the metadata; they define what each value is for any given row. Annotations are code snippits you put in at the java class or method level that further define data about the given code, but without changing any of the actual coded logic.

What are Lombok annotations?

What is Lombok. Project Lombok (from now on, Lombok) is an annotation-based Java library that allows you to reduce boilerplate code. Lombok offers various annotations aimed at replacing Java code that is well known for being boilerplate, repetitive, or tedious to write.

What is the use of @interface annotation?

Notice the @interface keyword. This signals to the Java compiler that this is a Java annotation definition. Notice that each element is defined similarly to a method definition in an interface. It has a data type and a name.


1 Answers

Short answer is NOT (for current version 1.18.4 - Oct 30, 2018)

According to the thread here:

This feature would require resolution in a very early stage of processing. Currently that is not possible. Possibly, since we now have the lombok configuration system, we might come up with a different solution.

Actually, they have several requests of the similar functionality on Lombok's GitHub page - non of them is implemented.

Please consider upvoting this feature or this one.

like image 170
Yurii Bondarenko Avatar answered Sep 16 '22 12:09

Yurii Bondarenko