Creating an alias annotation around Lombok annotations

1,118 views
Skip to first unread message

medge

unread,
Oct 15, 2014, 6:03:34 PM10/15/14
to project...@googlegroups.com
(Didn't know what to search for, so apologies if this is a duplicate question)

Fair warning: I am fairly new to annotation construction. Using them is fine, making them is new to me
 
What I essentially want to do is wrap lombok annotations within a custom annotation that would act solely as an alias to said lombok annotations. This is basically the concept Spring Boot uses with annotations like @Controller which is an alias for @Component (among others) 

For example: 

@MyModel public class Model {}

Would be equivalent to:

@Data @NoArgsConstructor public class Model {}

Is this possible? As a note: I am using Java 8 currently and tried a "dummy attempt" of:

@Data @NoArgsConstructor public @interface MyModel {}

But that threw errors.

Thanks!

Leon Blakey

unread,
Oct 16, 2014, 1:21:23 PM10/16/14
to project...@googlegroups.com
I'm pretty sure that requires resolution which is very complicated

However an alternative, but slightly more cryptic, option is to use the new config file. Then its a relatively simpler @org.myproject.MyCustomAnnotation=@ToString(callSuper=true), @NoArgsConstructor

Obviously the syntax could use some work but that's still a lot easier than trying to make resolution work

--
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.

medge

unread,
Oct 16, 2014, 2:21:48 PM10/16/14
to project...@googlegroups.com
So to clarify: after a quick look through [http://projectlombok.org/features/configuration.html], I created a file called lombok.config in my project's root directory with the following content:

config.stopBubbling = true
@MyModel = @ToString(callSuper=true), @Data, @NoArgsConstructor

However, an attempt to run this fails.

The test model looks like:

@MyModel

public class Test {

private String t;

private String u;

}

But something like new Test().setU("s"); fails

Am I missing something?

Reinier Zwitserloot

unread,
Oct 29, 2014, 9:38:01 AM10/29/14
to project...@googlegroups.com
Leon's post was a suggestion of how it _could_ work. It doesn't actually work yet, but Roel and I will discuss it.

medge

unread,
Oct 29, 2014, 9:47:05 AM10/29/14
to project...@googlegroups.com
Cheers, thanks for the update :)

AnyaCranmer

unread,
Nov 4, 2015, 5:35:38 PM11/4/15
to Project Lombok
I also have a proposal for a wrapper annotation around existing lombok annotations. Similar to @Data but including Constructor annotations and Builder.
Would you consider an creating an annotation that wraps these annotations?:

@AllArgsConstructor
@Builder
@Data
@NoArgsConstructor
@Value


thanks!
Reply all
Reply to author
Forward
0 new messages