Add spacing after the simple name when generating a `@ToPrettyString` representation.
Also fix a property name that was renamed.
RELNOTES=n/a
PiperOrigin-RevId: 361578257
diff --git a/value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ToPrettyStringExtension.java b/value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ToPrettyStringExtension.java
index c0f6f73..968e7b7 100644
--- a/value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ToPrettyStringExtension.java
+++ b/value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ToPrettyStringExtension.java
@@ -102,7 +102,7 @@
.addModifiers(
intersection(toPrettyStringMethod.getModifiers(), INHERITED_VISIBILITY_MODIFIERS));
- method.addCode("return $S", context.autoValueClass().getSimpleName() + "{");
+ method.addCode("return $S", context.autoValueClass().getSimpleName() + " {");
ToPrettyStringImplementation implementation = ToPrettyStringImplementation.create(context);
method.addCode(implementation.toStringCodeBlock.build());
diff --git a/value/src/test/java/com/google/auto/value/extension/toprettystring/ToPrettyStringTest.java b/value/src/test/java/com/google/auto/value/extension/toprettystring/ToPrettyStringTest.java
index 6388966..f519747 100644
--- a/value/src/test/java/com/google/auto/value/extension/toprettystring/ToPrettyStringTest.java
+++ b/value/src/test/java/com/google/auto/value/extension/toprettystring/ToPrettyStringTest.java
@@ -71,7 +71,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "Primitives{"
+ "Primitives {"
+ "\n i = 1,"
+ "\n l = 2,"
+ "\n b = 3,"
@@ -100,7 +100,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrimitiveArray{"
+ "PrimitiveArray {"
+ "\n longs = ["
+ "\n 1,"
+ "\n 2,"
@@ -116,7 +116,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrimitiveArray{" // force newline
+ "PrimitiveArray {" // force newline
+ "\n longs = [],"
+ "\n}");
}
@@ -127,7 +127,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrimitiveArray{" // force newline
+ "PrimitiveArray {" // force newline
+ "\n longs = null,"
+ "\n}");
}
@@ -148,7 +148,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyCollection{"
+ "PrettyCollection {"
+ "\n collection = ["
+ "\n hello,"
+ "\n world,"
@@ -164,7 +164,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyCollection{"
+ "PrettyCollection {"
+ "\n collection = ["
+ "\n hello"
+ "\n world"
@@ -180,7 +180,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyCollection{" // force newline
+ "PrettyCollection {" // force newline
+ "\n collection = [],"
+ "\n}");
}
@@ -191,7 +191,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyCollection{" // force newline
+ "PrettyCollection {" // force newline
+ "\n collection = null,"
+ "\n}");
}
@@ -217,7 +217,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestedCollection{"
+ "NestedCollection {"
+ "\n nestedCollection = ["
+ "\n ["
+ "\n hello,"
@@ -245,7 +245,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestedCollection{"
+ "NestedCollection {"
+ "\n nestedCollection = ["
+ "\n ["
+ "\n hello"
@@ -266,7 +266,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestedCollection{" // force newline
+ "NestedCollection {" // force newline
+ "\n nestedCollection = [],"
+ "\n}");
}
@@ -279,7 +279,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestedCollection{"
+ "NestedCollection {"
+ "\n nestedCollection = ["
+ "\n [],"
+ "\n [],"
@@ -293,7 +293,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestedCollection{" // force newline
+ "NestedCollection {" // force newline
+ "\n nestedCollection = null,"
+ "\n}");
}
@@ -314,7 +314,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "ImmutablePrimitiveArray{"
+ "ImmutablePrimitiveArray {"
+ "\n immutableIntArray = ["
+ "\n 1,"
+ "\n 2,"
@@ -329,7 +329,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "ImmutablePrimitiveArray{" // force newline
+ "ImmutablePrimitiveArray {" // force newline
+ "\n immutableIntArray = [],"
+ "\n}");
}
@@ -341,7 +341,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "ImmutablePrimitiveArray{" // force newline
+ "ImmutablePrimitiveArray {" // force newline
+ "\n immutableIntArray = null,"
+ "\n}");
}
@@ -361,7 +361,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMap{" // force newline
+ "PrettyMap {" // force newline
+ "\n map = {"
+ "\n 1: 2,"
+ "\n },"
@@ -377,7 +377,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMap{"
+ "PrettyMap {"
+ "\n map = {"
+ "\n key1"
+ "\n newline: value1"
@@ -395,7 +395,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMap{" // force newline
+ "PrettyMap {" // force newline
+ "\n map = {},"
+ "\n}");
}
@@ -406,7 +406,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMap{" // force newline
+ "PrettyMap {" // force newline
+ "\n map = null,"
+ "\n}");
}
@@ -439,7 +439,7 @@
MapOfMaps valueType = new AutoValue_ToPrettyStringTest_MapOfMaps(mapOfMaps);
assertThat(valueType.toPrettyString())
.isEqualTo(
- "MapOfMaps{"
+ "MapOfMaps {"
+ "\n mapOfMaps = {"
+ "\n {"
+ "\n k1_k: k1_v,"
@@ -481,7 +481,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "MapOfMaps{"
+ "MapOfMaps {"
+ "\n mapOfMaps = {"
+ "\n {"
+ "\n k_k"
@@ -502,7 +502,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "MapOfMaps{" // force newline
+ "MapOfMaps {" // force newline
+ "\n mapOfMaps = {},"
+ "\n}");
}
@@ -515,7 +515,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "MapOfMaps{" // force newline
+ "MapOfMaps {" // force newline
+ "\n mapOfMaps = {"
+ "\n {}: {},"
+ "\n },"
@@ -528,7 +528,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "MapOfMaps{" // force newline
+ "MapOfMaps {" // force newline
+ "\n mapOfMaps = null,"
+ "\n}");
}
@@ -550,7 +550,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMultimap{" // force newline
+ "PrettyMultimap {" // force newline
+ "\n multimap = {"
+ "\n k: ["
+ "\n v1,"
@@ -570,7 +570,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMultimap{"
+ "PrettyMultimap {"
+ "\n multimap = {"
+ "\n key"
+ "\n newline: ["
@@ -590,7 +590,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMultimap{" // force newline
+ "PrettyMultimap {" // force newline
+ "\n multimap = {},"
+ "\n}");
}
@@ -601,7 +601,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PrettyMultimap{" // force newline
+ "PrettyMultimap {" // force newline
+ "\n multimap = null,"
+ "\n}");
}
@@ -622,7 +622,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "JavaOptional{" // force newline
+ "JavaOptional {" // force newline
+ "\n optional = hello, world,"
+ "\n}");
}
@@ -634,7 +634,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "JavaOptional{" // force newline
+ "JavaOptional {" // force newline
+ "\n optional = <empty>,"
+ "\n}");
}
@@ -647,7 +647,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "JavaOptional{" // force newline
+ "JavaOptional {" // force newline
+ "\n optional = optional"
+ "\n with"
+ "\n newline,"
@@ -661,7 +661,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "JavaOptional{" // force newline
+ "JavaOptional {" // force newline
+ "\n optional = null,"
+ "\n}");
}
@@ -683,7 +683,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "GuavaOptional{" // force newline
+ "GuavaOptional {" // force newline
+ "\n optional = hello, world,"
+ "\n}");
}
@@ -695,7 +695,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "GuavaOptional{" // force newline
+ "GuavaOptional {" // force newline
+ "\n optional = <absent>,"
+ "\n}");
}
@@ -708,7 +708,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "GuavaOptional{" // force newline
+ "GuavaOptional {" // force newline
+ "\n optional = optional"
+ "\n with"
+ "\n newline,"
@@ -722,7 +722,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "GuavaOptional{" // force newline
+ "GuavaOptional {" // force newline
+ "\n optional = null,"
+ "\n}");
}
@@ -755,7 +755,7 @@
new int[][] {{1, 2}, {3, 4, 5}, {}}, "value\nwith\nnewline"))))));
assertThat(valueType.toPrettyString())
.isEqualTo(
- "NestAllTheThings{"
+ "NestAllTheThings {"
+ "\n value = ["
+ "\n {"
+ "\n ["
@@ -799,7 +799,7 @@
assertThat(valueType.customName())
.isEqualTo(
- "WithCustomName{" // force newline
+ "WithCustomName {" // force newline
+ "\n i = 1,"
+ "\n}");
}
@@ -819,7 +819,7 @@
assertThat(valueType.toString())
.isEqualTo(
- "OverridesToString{" // force newline
+ "OverridesToString {" // force newline
+ "\n i = 1,"
+ "\n}");
}
@@ -872,7 +872,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "PropertyHasToPrettyString{"
+ "PropertyHasToPrettyString {"
+ "\n parameterizedWithString = custom"
+ "\n @ToPrettyString"
+ "\n method,"
@@ -915,7 +915,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "CollectionSubtypesWithFixedTypeParameters{"
+ "CollectionSubtypesWithFixedTypeParameters {"
+ "\n list = ["
+ "\n a,"
+ "\n b,"
@@ -946,7 +946,7 @@
assertThat(valueType.toPrettyString())
.isEqualTo(
- "JavaBeans{"
+ "JavaBeans {"
+ "\n int = 4,"
+ "\n boolean = false,"
+ "\n notAJavaIdentifier = not,"
diff --git a/value/userguide/howto.md b/value/userguide/howto.md
index 2948a7c..de5649d 100644
--- a/value/userguide/howto.md
+++ b/value/userguide/howto.md
@@ -701,7 +701,7 @@
Below is a sample rendering of the result of calling `toPrettyString()`.
```
-Song{
+Song {
lyrics = I'm off the deep end, watch as I dive in
I'll never meet the ground
Crash through the surface, where they can't hurt us
@@ -711,7 +711,7 @@
name = "Lady Gaga",
},
Artist {
- nestedProperty = "Bradley Cooper",
+ name = "Bradley Cooper",
}
],
}