1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<#import "../_features.html" as f>
<@f.scaffold title="@FieldDefaults" logline="New default field modifiers for the 21st century.">
<@f.history>
<p>
@FieldDefaults was introduced as experimental feature in lombok v0.11.4.
</p>
</@f.history>
<@f.experimental>
<ul>
<li>
Would be nice if you could stick this on the package-info.java package to set the default for all classes in that package.
</li><li>
[UPDATE 2022-02-04] Currently simply having a <code>lombok.config</code> entry of <code>lombok.fieldDefaults.defaultPrivate = true</code> (or, analogously, <code>defaultFinal</code>) is enough to modify <em>every</em> source file that is affected by that configuration, even if said source file has absolutely no trace whatsoever of lombok anything inside it. We're not quite sure if this is a good idea. Our current point of view is that this is too much magic, and there is an alternative plan: meta-annotations. Until at least the meta-annotations idea has been explored and discarded, this feature will not be leaving <em>experimental</em> in its current state. Most likely, if it ever does, the <code>lombok.FieldDefaults</code> annotation will be <em>required</em>, though, you may set it via the to be built meta-annotation.
</li>
</ul>
Current status: <em>neutral</em> - Currently we feel this feature may not move out of experimental status without changes.
</@f.experimental>
<@f.overview>
<p>
The <code>@FieldDefaults</code> annotation can add an access modifier (<code>public</code>, <code>private</code>, or <code>protected</code>) to each field in the annotated class or enum. It can also add <code>final</code> to each field in the annotated class or enum.
</p><p>
To add <code>final</code> to each (instance) field, use <code>@FieldDefaults(makeFinal=true)</code>. Any non-final field which must remain nonfinal can be annotated with <code>@NonFinal</code> (also in the <code>lombok.experimental</code> package).
</p><p>
To add an access modifier to each (instance) field, use <code>@FieldDefaults(level=AccessLevel.PRIVATE)</code>. Any field that does not already have an access modifier (i.e. any field that looks like package private access) is changed to have the appropriate access modifier. Any package private field which must remain package private can be annotated with <code>@PackagePrivate</code> (also in the <code>lombok.experimental</code> package).
</p>
</@f.overview>
<@f.snippets name="experimental/FieldDefaults" />
<@f.confKeys>
<dt>
<code>lombok.fieldDefaults.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
</dt><dd>
Lombok will flag any usage of <code>@FieldDefaults</code> as a warning or error if configured.
</dd><dt>
<code>lombok.fieldDefaults.defaultPrivate</code> = [<code>true</code> | <code>false</code>] (default: false)
</dt><dd>
(Since 1.16.8) If set to <code>true</code>, <em>every</em> field in <em>every</em> class or enum anywhere in the sources being compiled will be marked as <code>private</code> unless it has an explicit access modifier or the <code>@PackagePrivate</code> annotation, or an explicit <code>@FieldDefaults</code> annotation is present to override this config key.
</dd><dt>
<code>lombok.fieldDefaults.defaultFinal</code> = [<code>true</code> | <code>false</code>] (default: false)
</dt><dd>
(Since 1.16.8) If set to <code>true</code>, <em>every</em> field in <em>every</em> class or enum anywhere in the sources being compiled will be marked as <code>final</code> unless it has the <code>@NonFinal</code> annotation, or an explicit <code>@FieldDefaults</code> annotation is present to override this config key.
</dd>
</@f.confKeys>
<@f.smallPrint>
<p>
Like other lombok handlers that touch fields, any field whose name starts with a dollar (<code>$</code>) symbol is skipped entirely. Such a field will not be modified at all.
</p>
</@f.smallPrint>
</@f.scaffold>
|