mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
Documentation for new @Accessors feature as well as the API (the annotation in experimental package).
This commit is contained in:
1 parent
6ca2a91d6b
commit
ceeabe5103
4 files changed
+206
No files matched your search
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package lombok.experimental;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* A container for settings for the generation of getters and setters.
|
||||
* Using this annotation does nothing by itself; an annotation that makes lombok generate getters and setters,
|
||||
* such as {@link lombok.Setter} or {@link lombok.Data} is also required.
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Accessors {
|
||||
/**
|
||||
* If true, accessors will be named after the field and not include a <code>get</code> or <code>set</code>
|
||||
* prefix. If true and <code>chain</code> is omitted, <code>chain</code> defaults to <code>true</code>.
|
||||
* <strong>default: false</strong>
|
||||
*/
|
||||
boolean fluent() default false;
|
||||
|
||||
/**
|
||||
* If true, setters return <code>this</code> instead of <code>void</code>.
|
||||
* <strong>default: false</strong>, unless <code>fluent=true</code>, then <strong>default: true</code>
|
||||
*/
|
||||
boolean chain() default false;
|
||||
|
||||
/**
|
||||
* If present, only fields with any of the stated prefixes are given the getter/setter treatment.
|
||||
* Note that a prefix only counts if the next character is NOT a lowercase character. If multiple fields
|
||||
* all turn into the same name when the prefix is stripped, an error will be generated.
|
||||
*/
|
||||
String[] prefix() default {};
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" type="text/css" href="../../logi/reset.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../features.css" />
|
||||
<link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
|
||||
<meta name="description" content="Spice up your java" />
|
||||
<title>EXPERIMENTAL - @Accessors</title>
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="header"><a href="../../index.html">Project Lombok</a></div>
|
||||
<h1>@Accessors</h1>
|
||||
<div class="byline">A more fluent API for getters and setters.</div>
|
||||
<div class="since">
|
||||
<h3>Since</h3>
|
||||
<p>
|
||||
@Accessors was introduced as experimental feature in lombok v0.10.10.
|
||||
</p>
|
||||
</div>
|
||||
<div class="experimental">
|
||||
<h3>Experimental</h3>
|
||||
<p>
|
||||
Experimental because:
|
||||
<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>positive</em> - Currently we feel this feature may move out of experimental status with no or minor changes soon.
|
||||
</div>
|
||||
<div class="overview">
|
||||
<h3>Overview</h3>
|
||||
<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>
|
||||
</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 that field's type is ignored.
|
||||
</p>
|
||||
</div>
|
||||
<div class="snippets">
|
||||
<div class="pre">
|
||||
<h3>With Lombok</h3>
|
||||
<div class="snippet">@HTML_PRE@</div>
|
||||
</div>
|
||||
<div class="sep"></div>
|
||||
<div class="post">
|
||||
<h3>Vanilla Java</h3>
|
||||
<div class="snippet">@HTML_POST@</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="clear: left;"></div>
|
||||
<div class="overview">
|
||||
<h3>Small print</h3><div class="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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<a href="index.html">Back to experimental features</a> | <span class="disabled">Previous feature</span> | <span class="disabled">Next feature</span><br />
|
||||
<a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2012 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
var pageTracker = _gat._getTracker("UA-9884254-1");
|
||||
pageTracker._trackPageview();
|
||||
} catch(err) {}
|
||||
</script>
|
||||
</body></html>
|
||||
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" type="text/css" href="../../logi/reset.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../features.css" />
|
||||
<link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
|
||||
<meta name="description" content="Spice up your java" />
|
||||
<title>Lombok feature overview</title>
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="header"><a href="../../index.html">Project Lombok</a></div>
|
||||
<h1>Lombok experimental features</h1>
|
||||
<div class="index overview">
|
||||
Experimental features are available in your normal lombok installation, but are not as robustly supported as lombok's main features.
|
||||
In particular, experimental features:<ul>
|
||||
<li>Are not tested as well as the core features.</li>
|
||||
<li>Do not get bugs fixed as quickly as core features.</li>
|
||||
<li>May have APIs that will change, possibly drastically if we find a different, better way to solve the same problem.</li>
|
||||
<li>May disappear entirely if the feature is too difficult to support or does bust enough boilerplate.</li>
|
||||
</ul>
|
||||
Features that receive positive community feedback and which seem to produce clean, flexible code will eventually become accepted
|
||||
as a core feature and move out of the experimental package.
|
||||
<dl>
|
||||
<dt><a href="Accessors.html"><code>@Accessors</code></a></dt>
|
||||
<dd>A more fluent API for getters and setters.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2012 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
var pageTracker = _gat._getTracker("UA-9884254-1");
|
||||
pageTracker._trackPageview();
|
||||
} catch(err) {}
|
||||
</script>
|
||||
</body></html>
|
||||
@@ -38,6 +38,8 @@
|
||||
<dd>Finally! Hassle-free final local variables.</dd>
|
||||
<dt><a href="Delegate.html"><code>@Delegate</code></a></dt>
|
||||
<dd>Don't lose your composition.</dd>
|
||||
<dt><a href="experimental/index.html">experimental features</a></dt>
|
||||
<dd>Here be dragons: Extra features which aren't quite ready for prime time yet.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="pointer">
|
||||
|
||||
Reference in new issue
Block a user