diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-13 00:11:02 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-08-13 00:11:02 +0200 |
commit | 8850798a04e7f44925ed16b3450623b02f5b6295 (patch) | |
tree | 7e40b1f95e1ad082ee135bf3ae9b1de4e946d2d4 /website/features/experimental | |
parent | 42f5a55d69850603d951a65929f48a3b462b54ea (diff) | |
download | lombok-8850798a04e7f44925ed16b3450623b02f5b6295.tar.gz lombok-8850798a04e7f44925ed16b3450623b02f5b6295.tar.bz2 lombok-8850798a04e7f44925ed16b3450623b02f5b6295.zip |
Documentation for @Value, @FieldDefaults, @Wither
Diffstat (limited to 'website/features/experimental')
-rw-r--r-- | website/features/experimental/ExtensionMethod.html | 2 | ||||
-rw-r--r-- | website/features/experimental/FieldDefaults.html | 84 | ||||
-rw-r--r-- | website/features/experimental/Value.html | 87 | ||||
-rw-r--r-- | website/features/experimental/Wither.html | 100 | ||||
-rw-r--r-- | website/features/experimental/index.html | 6 |
5 files changed, 278 insertions, 1 deletions
diff --git a/website/features/experimental/ExtensionMethod.html b/website/features/experimental/ExtensionMethod.html index 773904bb..0025d795 100644 --- a/website/features/experimental/ExtensionMethod.html +++ b/website/features/experimental/ExtensionMethod.html @@ -90,7 +90,7 @@ System.out.println(x.or("Hello, World!"));</pre> </div> </div> <div class="footer"> - <a href="index.html">Back to experimental features</a> | <a href="Accessors.html">Previous feature (@Accessors)</a> | <span class="disabled">Next feature</a><br /> + <a href="index.html">Back to experimental features</a> | <a href="Accessors.html">Previous feature (@Accessors)</a> | <a href="FieldDefaults.html">Next feature (@FieldDefaults)</a><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> diff --git a/website/features/experimental/FieldDefaults.html b/website/features/experimental/FieldDefaults.html new file mode 100644 index 00000000..94c23a27 --- /dev/null +++ b/website/features/experimental/FieldDefaults.html @@ -0,0 +1,84 @@ +<!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 - @FieldDefaults</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>@FieldDefaults</h1> + <div class="byline">New default field modifiers for the 21st century.</div> + <div class="since"> + <h3>Since</h3> + <p> + @FieldDefaults was introduced as experimental feature in lombok v0.11.4. + </p> + </div> + <div class="experimental"> + <h3>Experimental</h3> + <p> + Experimental because: + <ul> + <li>New feature; unsure if this busts enough boilerplate</li> + <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>Part of the work on @Value, which is experimental</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>@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><p> + To add <code>final</code> to each 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 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> + </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> + 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> + </div> + </div> + <div class="footer"> + <a href="index.html">Back to experimental features</a> | <a href="ExtensionMethod.html">Previous feature (@ExtensionMethod)</a> | <a href="Wither.html">Next feature (@Wither)</a><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> diff --git a/website/features/experimental/Value.html b/website/features/experimental/Value.html new file mode 100644 index 00000000..464f0966 --- /dev/null +++ b/website/features/experimental/Value.html @@ -0,0 +1,87 @@ +<!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 - @ExtensionMethod</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>@Value</h1> + <div class="byline">Immutable classes made very easy.</div> + <div class="since"> + <h3>Since</h3> + <p> + @Value was introduced as experimental feature in lombok v0.11.4. + </p> + </div> + <div class="experimental"> + <h3>Experimental</h3> + <p> + Experimental because: + <ul> + <li>Various choices still have to be vetted as being the correct 'least surprise' choice: Should the class be made final by default, etc.</li> + <li>Dependent on @Wither which is experimental.</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> + <code>@Value</code> is the immutable variant of <a href="../Data.html"><code>@Data</code></a>; all fields are made <code>private</code> and <code>final</code> by default, and instead of setters, each field gets a so-called 'wither', + which is a method that produces a clone with each field having the same value, except for the field you want a new value for. The class itself is also made <code>final</code> by default, because immutability is not something that can + be forced onto a subclass. Like <code>@Data</code>, useful <code>toString()</code>, <code>equals()</code> and <code>hashCode()</code> methods are also generated, each field gets a getter method, and a constructor that covers every + argument (except <code>final</code> fields that are initialized in the field declaration) is also generated. + </p><p> + In practice, <code>@Value</code> is shorthand for: <code>final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter @Wither</code>. + </p><p> + It is possible to override the final-by-default and private-by-default behaviour using either an explicit access level on a field, or by using the <code>@NonFinal</code> or <code>@PackagePrivate</code> annotations.<br /> + It is possible to override any default behaviour for any of the 'parts' that make up <code>@Value</code> by explicitly using that annotation. + </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> + Look for the documentation on the 'parts' of <code>@Value</code>: <a href="../ToString.html"><code>@ToString</code></a>, <a href="../EqualsAndHashCode.html"><code>@EqualsAndHashCode</code></a>, + <a href="../Constructor.html"><code>@AllArgsConstructor</code></a>, <a href="FieldDefaults.html"><code>@FieldDefaults</code></a>, <a href="../GetterSetter.html"><code>@Getter</code></a>, + <a href="Wither.html"><code>@Wither</code></a>. + </p><p> + For classes with generics, it's useful to have a static method which serves as a constructor, because inference of generic parameters via static methods works in java6 and avoids having to use the diamond operator. + While you can force this by applying an explicit <code>@AllArgsConstructor</code> annotation, there's also the <code>@Value(staticConstructor="of")</code> feature, which will make the generated all-arguments constructor + private, and generates a public static method named <code>of</code> which is a wrapper around this private constructor. + </p> + </div> + </div> + <div class="footer"> + <a href="index.html">Back to experimental features</a> | <a href="Wither.html">Previous feature (@Wither)</a> | <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> diff --git a/website/features/experimental/Wither.html b/website/features/experimental/Wither.html new file mode 100644 index 00000000..34d6d0d9 --- /dev/null +++ b/website/features/experimental/Wither.html @@ -0,0 +1,100 @@ +<!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 - @ExtensionMethod</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>@Wither</h1> + <div class="byline">Immutable 'setters' - methods that create a clone but with one changed field.</div> + <div class="since"> + <h3>Since</h3> + <p> + @Wither was introduced as experimental feature in lombok v0.11.4. + </p> + </div> + <div class="experimental"> + <h3>Experimental</h3> + <p> + Experimental because: + <ul> + <li>Still not sure that <code>@Wither</code> is an appropriate name for this feature.</li> + <li>Should there be an option to supply a way of cloning the input somehow?</li> + <li>Should the way that the clone is created by configurable?</li> + <li>Should we replace @Wither entirely with a builder class?</li> + </ul> + Current status: <em>neutral</em> - More feedback requires on the items in the above list before promotion to the main package is warranted. + </div> + <div class="overview"> + <h3>Overview</h3> + <p> + The next best alternative to a setter for an immutable property is to construct a clone of the object, but with a new value for this one field. + A method to generate this clone is precisely what <code>@Wither</code> generates: a <code>withFieldName(newValue)</code> method which produces a clone + except for the new value for the associated field. + </p><p> + For example, if you create <code>public class Point { private final int x, y; }</code>, setters make no sense because the fields + are final. <code>@Wither</code> can generate a <code>withX(int newXValue)</code> method for you which will return a new point with the supplied + value for <code>x</code> and the same value for <code>y</code>. + </p><p> + Like <a href="../GetterSetter.html"><code>@Setter</code></a>, you can specify an access level in case you want the generated wither to be something other than <code>public</code>:<br /> + <code>@Wither(level = AccessLevel.PROTECTED)</code>. Also like <a href="../GetterSetter.html"><code>@Setter</code></a>, you can also put a <code>@Wither</code> annotation on a type, which means + a 'wither' is generated for each field (even non-final fields). + </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> + Withers cannot be generated for static fields because that makes no sense. + </p><p> + When applying <code>@Wither</code> to a type, static fields and fields whose name start with a $ are skipped. + </p><p> + For generating the method names, the first character of the field, if it is a lowercase character, is title-cased, otherwise, it is left unmodified. + Then, <code>with</code> is prefixed. + </p><p> + No method is generated if any method already exists with the same name (case insensitive) and same parameter count. For example, <code>withX(int x)</code> + will not be generated if there's already a method <code>withX(String... x)</code> even though it is technically possible to make the method. This caveat + exists to prevent confusion. If the generation of a method is skipped for this reason, a warning is emitted instead. Varargs count as 0 to N parameters. + </p><p> + For <code>boolean</code> fields that start with <code>is</code> immediately followed by a title-case letter, nothing is prefixed to generate the wither name. + </p><p> + Any annotations named <code>@NonNull</code> (case insensitive) on the field are interpreted as: This field must not ever hold + <em>null</em>. Therefore, these annotations result in an explicit null check in the generated wither. Also, these + annotations (as well as any annotation named <code>@Nullable</code> or <code>@CheckForNull</code>) are copied to wither parameter. + </p> + </div> + </div> + <div class="footer"> + <a href="index.html">Back to experimental features</a> | <a href="FieldDefaults.html">Previous feature (@FieldDefaults)</a> | <a href="Value.html">Next feature (@Value)</a><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> diff --git a/website/features/experimental/index.html b/website/features/experimental/index.html index 9b25d710..6f180065 100644 --- a/website/features/experimental/index.html +++ b/website/features/experimental/index.html @@ -26,6 +26,12 @@ <dd>A more fluent API for getters and setters.</dd> <dt><a href="ExtensionMethod.html"><Code>@ExtensionMethod</code></a></dt> <dd>Annoying API? Fix it yourself: Add new methods to existing types!</dd> + <dt><a href="FieldDefaults.html"><Code>@FieldDefaults</code></a></dt> + <dd>New default field modifiers for the 21st century.</dd> + <dt><a href="Wither.html"><Code>@Wither</code></a></dt> + <dd>Immutable 'setters' - methods that create a clone but with one changed field.</dd> + <dt><a href="Value.html"><Code>@Value</code></a></dt> + <dd>Immutable classes made very easy.</dd> </dl> </div> <div class="footer"> |