Skip to content

Commit 2c4bf22

Browse files
eamonnmcmanuscgruber
authored andcommitted
Update the README.md for AutoValue to reflect the change in primitive array semantics, whereby they are no longer cloned on access.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=100406005
1 parent a3e2db0 commit 2c4bf22

File tree

6 files changed

+3
-157
lines changed

6 files changed

+3
-157
lines changed

value/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ If you have multiple creation methods, have them all call through
551551
to the same point, so there is still one call to the generated file,
552552
and one place to insert preconditions, etc.
553553

554-
**Avoid mutable field types**, especially if you make your
554+
**Avoid mutable field types**, such as arrays, especially if you make your
555555
accessor methods `public`. The generated accessors won't copy the
556556
field value on its way out, so you'd be exposing your internal
557557
state. This doesn't mean your factory method can't *accept*
@@ -568,14 +568,6 @@ mutable types as input parameters. Example:
568568
}
569569
```
570570

571-
Primitive arrays are arguably an exception to this, as in this
572-
case only AutoValue does return a copy of the internal array
573-
from the generated accessor. It does not automatically copy the
574-
data on its way in, however, so your static factory method should
575-
pass `array.clone()` in to the generated constructor instead of
576-
the input `array` itself. If you are using builders, arrays will
577-
be cloned in the generated builder.
578-
579571
Finally, if you choose to provide an explicit `equals`, `hashCode`
580572
or `toString` implementation, please make it **`final`**, so readers
581573
don't have to wonder whether AutoValue is overriding it.

value/src/it/functional/invoker.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.

value/src/it/functional/pom.xml

Lines changed: 0 additions & 98 deletions
This file was deleted.

value/src/main/java/com/google/auto/value/AutoValue.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,6 @@
1818
import java.lang.annotation.RetentionPolicy;
1919
import java.lang.annotation.Target;
2020

21-
/**
22-
* Specifies that <a href="https://github.com/google/auto/tree/master/value">AutoValue</a> should
23-
* generate an implementation class for the annotated abstract class, implementing the standard
24-
* {@link Object} methods like {@link Object#equals equals} to have conventional value semantics. A
25-
* simple example: <pre>
26-
*
27-
* &#64;AutoValue
28-
* abstract class Person {
29-
* static Person create(String name, int id) {
30-
* return new AutoValue_Person(name, id);
31-
* }
32-
*
33-
* abstract String name();
34-
* abstract int id();
35-
* }</pre>
36-
*
37-
* @see <a href="https://github.com/google/auto/tree/master/value">AutoValue User's Guide</a>
38-
*
39-
*
40-
* @author Éamonn McManus
41-
* @author Kevin Bourrillion
42-
*/
4321
@Retention(RetentionPolicy.SOURCE)
4422
@Target(ElementType.TYPE)
4523
public @interface AutoValue {

value/src/main/java/com/google/auto/value/processor/AutoValueProcessor.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ public static class Property {
198198
private final ExecutableElement method;
199199
private final String type;
200200
private final ImmutableList<String> annotations;
201-
private final String nullableAnnotation;
202201

203202
Property(
204203
String name,
@@ -211,18 +210,6 @@ public static class Property {
211210
this.method = method;
212211
this.type = type;
213212
this.annotations = buildAnnotations(typeSimplifier);
214-
this.nullableAnnotation = buildNullableAnnotation(typeSimplifier);
215-
}
216-
217-
private String buildNullableAnnotation(TypeSimplifier typeSimplifier) {
218-
for (AnnotationMirror annotationMirror : method.getAnnotationMirrors()) {
219-
String name = annotationMirror.getAnnotationType().asElement().getSimpleName().toString();
220-
if (name.equals("Nullable")) {
221-
AnnotationOutput annotationOutput = new AnnotationOutput(typeSimplifier);
222-
return annotationOutput.sourceFormForAnnotation(annotationMirror);
223-
}
224-
}
225-
return null;
226213
}
227214

228215
private ImmutableList<String> buildAnnotations(TypeSimplifier typeSimplifier) {

value/src/test/java/com/google/auto/value/processor/PropertyAnnotationsTest.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private JavaFileObject expectedCode(List<String> imports, List<String> annotatio
123123
"@Generated(\"" + AutoValueProcessor.class.getName() + "\")",
124124
"final class AutoValue_Baz extends Baz {",
125125
" private final int buh;",
126+
"",
126127
" AutoValue_Baz(" + nullable + "int buh) {",
127128
" this.buh = buh;",
128129
" }",
@@ -165,12 +166,10 @@ private JavaFileObject expectedCode(List<String> imports, List<String> annotatio
165166
return JavaFileObjects.forSourceLines("foo.bar.AutoValue_Baz", lines);
166167
}
167168

168-
169169
private void assertGeneratedMatches(
170170
List<String> imports,
171171
List<String> annotations,
172-
List<String> expectedAnnotations,
173-
String expectedConstructorParamAnnotation) {
172+
List<String> expectedAnnotations) {
174173

175174
JavaFileObject javaFileObject = sourceCode(imports, annotations);
176175
JavaFileObject expectedOutput = expectedCode(imports, expectedAnnotations);
@@ -180,14 +179,6 @@ private void assertGeneratedMatches(
180179
.processedWith(new AutoValueProcessor())
181180
.compilesWithoutError()
182181
.and().generatesSources(expectedOutput);
183-
184-
}
185-
186-
private void assertGeneratedMatches(
187-
List<String> imports,
188-
List<String> annotations,
189-
List<String> expectedAnnotations) {
190-
assertGeneratedMatches(imports, annotations, expectedAnnotations, null);
191182
}
192183

193184
public void testSimpleAnnotation() {

0 commit comments

Comments
 (0)