[JAVA] A note that I gave up trying to make a custom annotation for Lombok

This is a memo that I gave up trying to create a custom annotation for Lombok.

Summary in 3 lines:

  1. Lombok annotation implementation refers to Java inner class (compiler related).
  2. Since Java9, the method of referencing Java inner classes has changed significantly depending on the build system and IDE, and the difficulty level has become extremely high.
  3. Lombok does not support meta-annotation that aggregates annotations, so there is no way to do it, give up.

How I tried to make it:

  1. @ Value I love it, but I can't reverse-look up the getter created by lombok from Eclipse with Ctrl + Shift + F. It's hard to say. --There is no getter in the source code, so it's natural. ――For the time being, if you display it in the Outline view, you can also see the getter, so if you right-click the getter and select the "References" menu, you can reverse lookup the reference point, but it's awkward. --Reference: https://stackoverflow.com/questions/42644923/eclipse-with-lombok-search-for-getter-and-setter-usages
  2. In the first place, it is @Value for wanting to attach @ToString @EqualsAndHashCode @AllArgsConstructor as an Immutable data structure, and getter is not necessary as a personal preference. The field as a data structure is divided into public final.
  3. Alright, let's make a custom annotation ... Well, the source pack of @ Value, the place where the @ Getter function is called should be deleted.

So, first I googled Iroha to make custom annotations with Lombok:

Yeah, I expected it, but it seems to be annoying and difficult because of Java bytecode manipulation. I wonder if I should stop ... No, I want to make @Value-@Getter in the first place, so what about the source code of @Value?

--Annotation

handleFieldDefaults.generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true);
handleConstructor.generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, SkipIfConstructorExists.YES, annotationNode);
handleConstructor.generateExtraNoArgsConstructor(typeNode, annotationNode);
handleGetter.generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true, List.<JCAnnotation>nil());
handleEqualsAndHashCode.generateEqualsAndHashCodeForType(typeNode, annotationNode);
handleToString.generateToStringForType(typeNode, annotationNode);

It seems that you can copy and paste itself up to this point, but suddenly, "That ... Speaking of which, I'm using the com.sun.tools system ... I'm at a loss.

For the time being, I googled the article when dealing with com.sun.tools with maven until the java8 era.

--Troubleshooting when using Java / Maven3 / tools.jar (<scope> = system, <systemPath>) --Glamenv-Septzen.net

Oh yeah, it was like this. Then, let's take a look at what happened with java9 ...

It's really suspicious to go to the clouds. Or rather, it's already annoying. Dangerous. If you take a quick look at the correspondence on the Eclipse side, it seems that although the contents are slightly different, it is difficult to access the Java inner class:

--Java --About restricted class access | teratail

This is bad. The adjustment of maven / pom.xml seems to be dangerous first, and the combination of it and Eclipse side also raises the complexity.

In the first place, https://github.com/peichhorn/lombok-pg, which is a collection of third-party Lombok custom annotations (which I learned for the first time in this survey), and Lombok itself seems to use Ant for build. Atmosphere that is quite adjusted for Eclipse IDE. (I'm not sure if it's built into the IDE or for developing with the IDE, but it seems to be quite annoying anyway)

I found an article that makes it difficult to maintain Lombok with Java 9 or later.

--Lombok's Java 9 or later support story --Qiita

Well, if custom annotations don't work, can we create a meta-annotation that aggregates existing annotations? I tried to google ...

Apparently it seems difficult and it is not supported.

Considering the above, the only thing I want to do is to make it easy to add the following annotations ... Despite this, the cost to realize it is unusually high.

@AllArgsConstructor
@EqualsAndHashCode
@ToString
(In some cases@With )

Therefore, this time, I will give up creating custom annotations and copy only what I need safely.

Recommended Posts

A note that I gave up trying to make a custom annotation for Lombok
I want to create a generic annotation for a type
A note that I had trouble when trying to use nginx with Remote-Containers of vscode
I want to make a button with a line break with link_to [Note]
I tried to make a Web API that connects to DB with Quarkus
I tried to make a program that searches for the target class from the process that is overloaded with Java
[Note] A list of commands that I checked many times after trying Ruby.
[Android] I want to create a ViewPager that can be used for tutorials
I searched for a lightweight framework that answers the sudden "make it quickly"
I did Java to make (a == 1 && a == 2 && a == 3) always true
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
How to make a lightweight JRE for distribution
[Ruby] I want to make a program that displays today's day of the week!
MockMVC returns 200 even if I make a request to a path that does not exist
A story that I had a hard time trying to build PHP 7.4 on GCE's CentOS 8
I read the readable code, so make a note
I made a method to ask for Premium Friday
I tried to make a login function in Java
I tried to make FizzBuzz that is uselessly flexible
How to make a mod for Slay the Spire
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I was inspired by the article for newcomers, so make a note of it so that you don't forget your original intentions.
I want to make a specific model of ActiveRecord ReadOnly
I want to make a list with kotlin and java!
I just wanted to make a Reactive Property in Java
I want to make a function with kotlin and java!
I tried using Hotwire to make Rails 6.1 scaffold a SPA
I tried to make a client of RESAS-API in Java
I wanted to animate a row when using realm and RecyclerView on Android, but I gave up
How to deal with the type that I thought about writing a Java program for 2 years