This is a memo that I gave up trying to create a custom annotation for Lombok.
Summary in 3 lines:
How I tried to make it:
@ 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@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
.@ Value
, the place where the @ Getter
function is called should be deleted.So, first I googled Iroha to make custom annotations with Lombok:
java - Create custom annotation for Lombok - Stack Overflow
Implementing a Custom Lombok Annotation | Baeldung
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
handleFlagUsage (...)
seems to be a snap, read from the configuration file and use @ Value
to check OK / NG, so it is not necessary to copy and paste as a custom annotation.
--deleteAnnotationIfNeccessary (...)
The related items are compatible with the experimental era, so this is also unnecessary for copying as a custom annotation.
--The rest is just calling other handler combinations in order as shown below, so you can copy and paste this and remove only the handleGetter call.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
java - Missing artifact com.sun:tools:jar - Stack Overflow
Oh yeah, it was like this. Then, let's take a look at what happened with java9 ...
Accessing com.sun.tools.javac.util from Java 9 - Stack Overflow
Java Platform, Standard Edition Oracle JDK 9 Migration Guide, Release 9
Declare maven dependency on tools.jar to work on JDK 9 - Stack Overflow
java - Build error: missing artifact com.sun:tools:jar:1.6 - Stack Overflow
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 ...
java - Is it possible to use Lombok annotations as a meta-annotation? - Stack Overflow
Allow usage of annotations as meta-annotations · Issue #557 · rzwitserloot/lombok · GitHub
Feature Request: Allow multiple lombok's annotations to be aggregated into one · Issue #1226 · rzwitserloot/lombok · GitHub
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