Open zeldigas opened 1 year ago
I suppose the reason is because copyable, nullable and non-null annotations are mostly hardcoded: https://github.com/projectlombok/lombok/blob/1473389f397579a224d57b496f6387f3b8cbb6a9/src/core/lombok/core/handlers/HandlerUtil.java#L130. :(
This also applies to annotations added to the configuration explicitly like
lombok.copyableannotations += org.intellij.lang.annotations.Language
The generated constructor does not have this annotation present; source:
compiled output:
A contribution of a simple test case (it's just a matter of writing self-contained java files along with what you think lombok should do with em and putting them into the right dirs (test/transform/resource/before
and test/transform/resource/after-javac
and/or test/transform/resource/after-ecj
).
Sorry @rzwitserloot , I don't think I quite understand what you're asking of me to contribute or what's unclear, would you please elaborate?
I was expecting lombok to copy field annotations to the respective constructor parameters, not only for Nullability annotations but favorably also for copyable annotations.
Lombok has a copy system and there are a ton of places where annotations may or may not be copied. This isn't exactly a high traffic bug report and we have various tests about copying annotations that all pass.
So, exactly, which annotations are and aren't being copied?
You have posted a sample project - it sounds like all you'd really have to do is take the output of java -jar lombok.jar delombok TheOneFromSpringThatDoesWork.java
, 'fix' the annotations to your custom ones, and contribute a PR that just has TheOneThatDoesNotWorkWithYourCustomAnnos.java
in test/transform/resources/before
, and the output of delombok from the spring example, adapted to be like what you'd have expected from your custom take to the after-delombok
dir (which you do not currently get, hence, failing the test case). You can stick lombok.config
primitives in a comment in the before
source file (check other files that do this, just scan for .java
files in before that start with a comment, various ones do this).
Describe the bug In my project and libs I use custom nullability annotations that are almost one-to-one copies of spring ones, the purpose is to avoid depending on spring-core. I wanted to configure lombok to add them from fields to constructors and methods (getters/setters) for Value/Data annotated classes, but for some reason annotations are not added.
At the same time, when lombok is configured to use
spring
orcheckerframework
annotations they are added correctly.In other words, sample class
Produce different results depending on
Nullable
annotation.For spring with (
lombok.addLombokGeneratedAnnotation=true, lombok.addNullAnnotations=spring
)For custom (
lombok.addLombokGeneratedAnnotation=true, lombok.addNullAnnotations=CUSTOM:com.example.annotations.NonNull:com.example.annotations.Nullable
)To Reproduce I've prepared a sample project that shows the problem: https://github.com/zeldigas/lombok-custom-nullable-problem. In
spring
module you can find usage of spring annotations and incustom
- custom ones that are defined in this module as well (for simplicity)Expected behavior Both modules in sample project are working the same way.
Version info (please complete the following information):
1.18.24