Lombok: @Accessors() generate fluent accessors by default if lombok.accessors.fluent is true

Created on 26 Jun 2018  Â·  5Comments  Â·  Source: projectlombok/lombok

@Accessors() doesn't respect the default value of its fluent parameter when it conflicts with lombok.accessors.fluent.

This means that if your project's default is to use fluent accessors, but you want to use get/set for e.g. legacy public code, you need to specify @Accessors(fluent = false) even tho you'll get a warning that it's redundant with the default value.

All 5 comments

The standard meaning of annotations is that omitting an argument is equivalent to using it's default value. This is necessary as there's no way of distinguishing these two cases via annotation processing or reflection.

However, this is pretty impractical and Lombok tries to be smarter about it. I guess, empty @Accessors is a no-op, rather than an equivalent of @Accessors(fluent=false, chain=false, prefix={}) and that's a good thing (at least in general, as it allows to override a single setting without specifying all others).

The question is where the warning comes from. I can see none in my Eclipse. Can you switch it off?

Yes, I don't think it's a bug, just that it's a bit confusing when adding the annotation.

I'm using Android Studio 3.1, based on some IntelliJ IDEA build from a few months ago, and it's really good at graying out whatever is unnecessary/redundant. In this case it's flagging fluent = false, since the annotation's code indeed shows that false is the default value for fluent.

I only opened the issue because it might possible to fix Lombok so that the default values are indeed default at compile time, e.g. by not hard-coding false but using some static property instead? I haven't looked into it…

Meanwhile, this makes IntelliJ 🌸happy 🌸:

@SuppressWarnings("DefaultAnnotationParam")
@Accessors(fluent = false)
@Value
class Foo {
  ...
}

I only opened the issue because it might possible to fix Lombok so that the default values are indeed default at compile time, e.g. by not hard-coding false but using some static property instead? I haven't looked into it…

I'm rather sure, it's impossible. Annotations are very rigid and they have to work from the class file alone. The default must be a compile-time constant or even a literal (I don't know).

Lombok does some useful magic allowing to "partially override" an annotation. Idea produces a useful warning here. It's just that this warning doesn't apply, because of the magic.

I guess, Lombok can't fix it. Maybe the Lombok-Idea-plugin can. For sure, Idea could automatically exempt all lombok.** annotations.

@Maaartinus: Created mplushnikov/lombok-intellij-plugin#495

Was this page helpful?
0 / 5 - 0 ratings