Changed @Value to no longer imply @Wither. Usually you want only

a few or no withers at all, and adding them is a lot simpler than
removing them. This is a breaking change, but then that's why @Value
was in experimental in the first place.
This commit is contained in:
Reinier Zwitserloot committed 2013-02-18 22:42:39 +01:00
1 parent ed61012f95
commit 06537da4e0
8 files changed
+12 -81

No files matched your search

+2 -1
View File
@@ -2,7 +2,8 @@ Lombok Changelog
----------------
### v0.11.7 (Edgy Guinea Pig)
* FEATURE: Reintroduced `onMethod`, `onConstructor` and `onParam` to `@Getter`, `@Setter`, `@Wither`, and `@XArgsConstructor`. These parameters allow you to add annotations to the methods/constructors that lombok will generate. This is a workaround feature: The stability of the feature on future versions of javac is not guaranteed, and if a better way to implement this feature is found, this feature's current incarnation will be removed without a reasonable period of deprecation. [Documentation on the onX feature](http://projectlombok.org/feature/onX.html)
* CHANGE: {Experimental} The experimental `@Value` feature no longer implies the also experimental `@Wither`. If you like your `@Value` classes to make withers, add `@Wither` to the class right next to `@Value`.
* FEATURE: {Experimental} Reintroduced `onMethod`, `onConstructor` and `onParam` to `@Getter`, `@Setter`, `@Wither`, and `@XArgsConstructor`. These parameters allow you to add annotations to the methods/constructors that lombok will generate. This is a workaround feature: The stability of the feature on future versions of javac is not guaranteed, and if a better way to implement this feature is found, this feature's current incarnation will be removed without a reasonable period of deprecation. [Documentation on the onX feature](http://projectlombok.org/feature/onX.html)
### v0.11.6 (October 30th, 2012)
* FEATURE: Lombok can be disabled entirely for any given compile run by using JVM switch `-Dlombok.disable`. This might be useful for code style checkers and such.
@@ -76,7 +76,6 @@ public class HandleValue extends EclipseAnnotationHandler<Value> {
//and hitting 'find callers'.
new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleWither().generateWitherForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), true, Collections.<Annotation>emptyList(), ast);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 The Project Lombok Authors.
* Copyright (C) 2012-2013 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
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
/**
* Generates a lot of code which fits with a class that is a representation of an immutable entity.
* <p>
* Equivalent to {@code @Getter @Wither @FieldDefaults(makeFinal=true, level=AccessLevel.PRIVATE) @RequiredArgsConstructor @ToString @EqualsAndHashCode}.
* Equivalent to {@code @Getter @FieldDefaults(makeFinal=true, level=AccessLevel.PRIVATE) @RequiredArgsConstructor @ToString @EqualsAndHashCode}.
* <p>
* Complete documentation is found at <a href="http://projectlombok.org/features/experimental/Value.html">the project lombok features page for &#64;Value</a>.
*
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 The Project Lombok Authors.
* Copyright (C) 2012-2013 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
@@ -67,7 +67,6 @@ public class HandleValue extends JavacAnnotationHandler<Value> {
// TODO move this to the end OR move it to the top in eclipse.
new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, true, annotationNode);
new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleWither().generateWitherForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
}
@@ -15,14 +15,6 @@ final class Value1 {
public String getName() {
return this.name;
}
@java.lang.SuppressWarnings("all")
public Value1 withX(final int x) {
return this.x == x ? this : new Value1(x, this.name);
}
@java.lang.SuppressWarnings("all")
public Value1 withName(final String name) {
return this.name == name ? this : new Value1(this.x, name);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -68,14 +60,6 @@ class Value2 {
public String getName() {
return this.name;
}
@java.lang.SuppressWarnings("all")
public Value2 withX(final int x) {
return this.x == x ? this : new Value2(x, this.name);
}
@java.lang.SuppressWarnings("all")
public Value2 withName(final String name) {
return this.name == name ? this : new Value2(this.x, name);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -126,14 +110,6 @@ final class Value3 {
public int getY() {
return this.y;
}
@java.lang.SuppressWarnings("all")
public Value3 withX(final int x) {
return this.x == x ? this : new Value3(x, this.y);
}
@java.lang.SuppressWarnings("all")
public Value3 withY(final int y) {
return this.y == y ? this : new Value3(this.x, y);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
@@ -8,12 +8,6 @@ final @lombok.experimental.Value class Value1 {
public @java.lang.SuppressWarnings("all") String getName() {
return this.name;
}
public @java.lang.SuppressWarnings("all") Value1 withX(final int x) {
return ((this.x == x) ? this : new Value1(x, this.name));
}
public @java.lang.SuppressWarnings("all") Value1 withName(final String name) {
return ((this.name == name) ? this : new Value1(this.x, name));
}
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
@@ -54,12 +48,6 @@ final @lombok.experimental.Value class Value1 {
public @java.lang.SuppressWarnings("all") String getName() {
return this.name;
}
public @java.lang.SuppressWarnings("all") Value2 withX(final int x) {
return ((this.x == x) ? this : new Value2(x, this.name));
}
public @java.lang.SuppressWarnings("all") Value2 withName(final String name) {
return ((this.name == name) ? this : new Value2(this.x, name));
}
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
@@ -105,12 +93,6 @@ final @Value class Value3 {
public @java.lang.SuppressWarnings("all") int getY() {
return this.y;
}
public @java.lang.SuppressWarnings("all") Value3 withX(final int x) {
return ((this.x == x) ? this : new Value3(x, this.y));
}
public @java.lang.SuppressWarnings("all") Value3 withY(final int y) {
return ((this.y == y) ? this : new Value3(this.x, y));
}
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
@@ -30,18 +30,6 @@ public final class ValueExample {
return this.tags;
}
public ValueExample withName(String name) {
return this.name == name ? this : new ValueExample(name, age, score, tags);
}
public ValueExample withScore(double score) {
return this.score == score ? this : new ValueExample(name, age, score, tags);
}
public ValueExample withTags(String[] tags) {
return this.tags == tags ? this : new ValueExample(name, age, score, tags);
}
@java.lang.Override
public boolean equals(Object o) {
if (o == this) return true;
@@ -99,14 +87,6 @@ public final class ValueExample {
return this.value;
}
public Exercise<T> withName(String name) {
return this.name == name ? this : new Exercise<T>(name, value);
}
public Exercise<T> withValue(T value) {
return this.value == value ? this : new Exercise<T>(name, value);
}
@java.lang.Override
public boolean equals(Object o) {
if (o == this) return true;
+7 -13
View File
@@ -15,8 +15,9 @@
<div class="since">
<h3>Since</h3>
<p>
@Value was introduced as experimental feature in lombok v0.11.4.
</p>
<code>@Value</code> was introduced as experimental feature in lombok v0.11.4.
</p><p>
<code>@Value</code> no longer implies <code>@Wither</code> since lombok v0.11.8.
</div>
<div class="experimental">
<h3>Experimental</h3>
@@ -24,19 +25,16 @@
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
<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 setters are not generated. 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>.
In practice, <code>@Value</code> is shorthand for: <code>final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter</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.
@@ -57,13 +55,9 @@
<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>.
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>, and <a href="../GetterSetter.html"><code>@Getter</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.
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(staticConstructor="of")</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>