Addition support of Lombok to custom annotation processor

350 views
Skip to first unread message

hohserg

unread,
Oct 4, 2020, 5:22:42 PM10/4/20
to Project Lombok
I'm developing a custom annotation processor(independent on Lombok). My annotation processor is sensitive to field access modifiers and to existence getters/setters. Therefore, I want my annotation processor to support Lombok. Now my annotation processor just sees annotations of Lombok, but do not sees result of Lombok. How to make my annotation processor see the getters/setters which generated by Lombok?
I also managed to make a delombok task in my gradle project: https://gist.github.com/hohserg1/9f7bd9fd138b840f495da4776dcd231b

jhma...@gmail.com

unread,
Oct 5, 2020, 6:22:44 AM10/5/20
to project...@googlegroups.com

Some years ago this seems to be impossible

https://stackoverflow.com/questions/29193806/specifying-order-of-annotation-processors

 

But maybe there are new possibilities …

 

 

Jan

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/a064a06d-ce36-4954-a30e-935f4d209b5en%40googlegroups.com.

hohserg

unread,
Oct 5, 2020, 11:50:36 AM10/5/20
to Project Lombok
Oh, now I've noticed that methods which generated by Lombok is visible from my annotation processor, but modifiers of fields is remain without Lombok transformations.
I created minimal example:
On run command gradle :app:build  getters of @Value-marked class will be visible from annotation processor, but private modifier of field is invisible.

> Task :app:compileJava
C:\Users\hohserg\Documents\GitHub\CustomAnnotationProcessor_with_ Lombok\app\src\main\java\hohserg\apt\example\TestClass.java:7: Note: Found marked element
public class TestClass {
       ^
C:\Users\hohserg\Documents\GitHub\CustomAnnotationProcessor_with_ Lombok\app\src\main\java\hohserg\apt\example\TestClass.java:7: Note: field int some, modifiers[]    Here must be [private, final] because @Value do all fields to private and final
public class TestClass {
       ^
C:\Users\hohserg\Documents\GitHub\CustomAnnotationProcessor_with_ Lombok\app\src\main\java\hohserg\apt\example\TestClass.java:7: Note: method int getSome(), modifiers[public]   Getter which generated by @Value, visible
public class TestClass {
       ^
C:\Users\hohserg\Documents\GitHub\CustomAnnotationProcessor_with_ Lombok\app\src\main\java\hohserg\apt\example\TestClass.java:7: Note: constructor TestClass(int), modifiers[public]   Constructor which generated by @Value, visible
public class TestClass {
       ^
Any ideas, how to add compatibility with Lombok to custom annotation processor?

понедельник, 5 октября 2020 г. в 13:22:44 UTC+3, Jan:

mbrinkma

unread,
Oct 5, 2020, 12:19:06 PM10/5/20
to Project Lombok
Fyi, lombok and the annotation-processor "MapStruct" can coexist (see https://github.com/mapstruct/mapstruct/issues/510  /  https://github.com/rzwitserloot/lombok/issues/973), so this should be possible in this case, too.

hohserg

unread,
Oct 5, 2020, 1:31:02 PM10/5/20
to Project Lombok
Ok, I tried next: https://github.com/mapstruct/mapstruct-examples/blob/master/mapstruct-lombok/build.gradle#L20
In my project: annotationProcessor 'org.projectlombok:lombok:1.18.8', project(':apt')
It have exactly the same result.
Also, if I switch order:  annotationProcessor project(':apt'), 'org.projectlombok:lombok:1.18.8'  that my annotation processor will stop seeing Lombok transformations fully.

MapStruct applies before Lombok in mapstruct-lombok example, it signs that MapStruct should not be sensitive to Lombok, but my annotation processor must be sensitive to Lombok.

понедельник, 5 октября 2020 г. в 19:19:06 UTC+3, mbrinkma:
Reply all
Reply to author
Forward
0 new messages