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
|
<#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>
</@f.history>
<@f.experimental>
<ul>
<li>
We may want to roll these features into a more complete property support concept.
</li><li>
New feature – community feedback requested.
</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: naming behaviour for properties that start with a lowercase letter followed by an uppercase letter. Half of specs, tools and lombok users prefer that a field named <code>uLimit</code> into <code>getULimit</code> (including lombok) and the other half turn prefer <code>getuLimit</code>. <code>@Accessors</code> may be involved in any update that addresses this <a href="https://github.com/rzwitserloot/lombok/issues/2693">request</a>.</li>
<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/rzwitserloot/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 and setters.
</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> therefore has 3 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>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; the annotation that applies is the one on the field if present, otherwise the one on the class. When a <code>@Accessors</code> annotation on a field is present, any <code>@Accessors</code> annotation also present on the class the field is in, is entirely ignored, <em>even for properties not configured on the field <code>@Accessors</code></em>. This in contrast to any <code>lombok.config</code> configuration keys which serve as fall-back default if any explicit <code>@Accessors</code> annotation doesn't specify.
</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 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 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.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.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>
|