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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<#import "../_features.html" as f>
<@f.scaffold title="@Accessors" logline="A more fluent API for getters and setters.">
<@f.history>
<p>
<code>@Accessors</code> was introduced as experimental feature in lombok v0.11.0.
</p><p>
The <em>lombok.config</em> option <code>lombok.accessors.capitalization</code> = [<code>basic</code> | <code>beanspec</code>] was added in lombok v1.18.24.
</p><p>
FUNCTIONAL CHANGE: <code>@Accessors</code> now 'cascades'; any options not set on a field-level <code>@Accessors</code> annotation will get inherited from an
<code>@Accessors</code> annotation on the class (and any options not set on those, from the enclosing class). Finally, anything set in <code>lombok.config</code>
will be used as default. (lombok v1.18.24)
</p><p>
NEW FEATURE: <code>@Accessors(makeFinal = true)</code> will create <code>final</code> getters, setters, and with-ers. There's also
<code>lombok.config</code> key <code>lombok.accessors.makeFinal</code> for the same effect. (lombok v1.18.24)
</@f.history>
<@f.experimental>
<ul>
<li>
We may want to roll these features into a more complete property support concept.
</li><li>
The <code>makeFinal</code> feature is recently released; awaiting community feedback.
</li>
</ul>
Current status: <em>neutral</em> - Some changes are expected. These changes are intended to be backwards compatible, but should start in an experimental feature:
<ul>
<li>Open feature request: More control over naming accessors; for example to address creatively named boolean properties: Turn <code>boolean wasRunning</code> into <code>boolean wasRunning()</code> instead of <code>boolean isWasRunning()</code>, as well as more expansive prefix support. <code>@Accessors</code> will be involved if this feature <a href="https://github.com/projectlombok/lombok/issues/2464">request</a> is addressed.</li>
<li><code>@Accessors</code> currently does not 'cascade' from field <code>@Accessors</code> annotation to the class-level <code>@Accessors</code> annotation, but it does 'cascade' to <code>lombok.config</code>. Changing this is not difficult but backwards incompatible. It's not likely to break much existing code, but this needs to be decided on before the feature can move out of <em>experimental</em> status.</li>
</ul>
</@f.experimental>
<@f.overview>
<p>
The <code>@Accessors</code> annotation is used to configure how lombok generates and looks for getters, setters, and with-ers.
</p><p>
By default, lombok follows the <em>bean specification</em> for getters and setters: The getter for a field named <code>pepper</code> is <code>getPepper</code> for example. However, some might like to break with the <em>bean specification</em> in order to end up with nicer looking APIs. <code>@Accessors</code> lets you do this.
</p><p>
Some programmers like to use a prefix for their fields, i.e. they write <code>fPepper</code> instead of <code>pepper</code>. We <em>strongly</em> discourage doing this, as you can't unit test the validity of your prefixes, and refactor scripts may turn fields into local variables or method names. Furthermore, your tools (such as your editor) can take care of rendering the identifier in a certain way if you want this information to be instantly visible. Nevertheless, you can list the prefixes that your project uses via <code>@Accessors</code> as well.
</p><p>
<code>@Accessors</code> has 4 options:
<ul>
<li>
<code>fluent</code> – A boolean. If <em>true</em>, the getter for <code>pepper</code> is just <code>pepper()</code>, and the setter is <code>pepper(T newValue)</code>. Furthermore, unless specified, <code>chain</code> defaults to <em>true</em>. <br />
Default: <em>false</em>.
</li><li>
<code>chain</code> – A boolean. If <em>true</em>, generated setters return <code>this</code> instead of <code>void</code>.<br />
Default: <em>false</em>, unless <code>fluent=true</code>, then Default: <em>true</em>.
</li><li>
<code>makeFinal</code> – A boolean. If <em>true</em>, generated getters, setters, and with-ers are marked as <code>final</code>.<br />
Default: <em>false</em>.
</li><li>
<code>prefix</code> – A list of strings. If present, fields must be prefixed with any of these prefixes. Each field name is compared to each prefix in the list in turn, and if a match is found, the prefix is stripped out to create the base name for the field. It is legal to include an empty string in the list, which will always match. For characters which are letters, the character following the prefix must not be a lowercase letter, i.e. <code>pepper</code> is not a match even to prefix <code>p</code>, but <code>pEpper</code> would be (and would mean the base name of this field is <code>epper</code>).
</li>
</ul>
<p><p>
The <code>@Accessors</code> annotation is legal on types and fields; getters/setters/with-ers will look at the annotation on the field first, on the type the field is in second (and you have types in types,
each outer type is also checked), and finally for any properties not explicitly set, the appropriate <code>lombok.config</code> setting is used.
</p>
</@f.overview>
<@f.snippets name="experimental/Accessors" />
<@f.confKeys>
<dt>
<code>lombok.accessors.chain</code> = [<code>true</code> | <code>false</code>] (default: false)
</dt><dd>
If set to <code>true</code>, any field/class that either doesn't have an <code>@Accessors</code> annotation, or it does, but that annotation does not have an explicit value for the <code>chain</code> parameter, will act as if <code>@Accessors(chain = true)</code> is present.
</dd><dt>
<code>lombok.accessors.fluent</code> = [<code>true</code> | <code>false</code>] (default: false)
</dt><dd>
If set to <code>true</code>, any field/class that either doesn't have an <code>@Accessors</code> annotation, or it does, but that annotation does not have an explicit value for the <code>fluent</code> parameter, will act as if <code>@Accessors(fluent = true)</code> is present.
</dd><dt>
<code>lombok.accessors.makeFinal</code> = [<code>true</code> | <code>false</code>] (default: false)
</dt><dd>
If set to <code>true</code>, any field/class that either doesn't have an <code>@Accessors</code> annotation, or it does, but that annotation does not have an explicit value for the <code>makeFinal</code> parameter, will act as if <code>@Accessors(makeFinal = true)</code> is present.
</dd><dt>
<code>lombok.accessors.prefix</code> += <em>a field prefix</em> (default: empty list)
</dt><dd>
This is a list property; entries can be added with the <code>+=</code> operator. Inherited prefixes from parent config files can be removed with the <code>-=</code> operator. Any class that either doesn't have an <code>@Accessors</code> annotation, or it does, but that annotation does not have an explicit value for the <code>prefix</code> parameter, will act as if <code>@Accessors(prefix = {<em>prefixes listed in configuration</em>})</code> is present.
</dd><dt>
<code>lombok.accessors.capitalization</code> = [<code>basic</code> | <code>beanspec</code>] (default: basic)
</dt><dd>
Controls how tricky cases like <code>uShaped</code> (one lowercase letter followed by an upper/titlecase letter) are capitalized. <code>basic</code> capitalizes that to <code>getUShaped</code>, and <code>beanspec</code> capitalizes that to <code>getuShaped</code> instead.<br />
Both strategies are commonly used in the java ecosystem, though <code>beanspec</code> is more common.
</dd><dt>
<code>lombok.accessors.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
</dt><dd>
Lombok will flag any usage of <code>@Accessors</code> as a warning or error if configured.
</dd>
</@f.confKeys>
<@f.smallPrint>
<p>
The nearest <code>@Accessors</code> annotation is also used for the various methods in lombok that look for getters, such as <code>@EqualsAndHashCode</code>.
</p><p>
If a prefix list is provided and a field does not start with one of them, that field is skipped entirely by lombok, and a warning will be generated.
</p>
</@f.smallPrint>
</@f.scaffold>
|