From dc50f40ab72c14325da834e4e877f4fc79d1ebec Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Thu, 24 Sep 2026 14:01:56 +0300 Subject: [PATCH] Cover how a long generic field type wraps A field whose parameterized type fits in the line keeps the type whole and moves the name and the initializer to the next line. A type that does not fit breaks right after "<" and puts its arguments one level deeper: on one line when they fit there, one per line when they do not. That is google-java-format's layout, kept as it is. At 120 columns it shows only on a type that is over the limit by itself: in the 15,747 files of the JDK 21 sources, once on a field (LocaleProviderAdapter) and once inside a cast (TCPTransport). The golden pins the three shapes, so that an upstream sync or a change to visitParameterizedType has to say so. --- .../testdata/ojf-long-generic-field-type.input | 7 +++++++ .../testdata/ojf-long-generic-field-type.output | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.input create mode 100644 open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.output diff --git a/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.input b/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.input new file mode 100644 index 000000000..6a0ada6ad --- /dev/null +++ b/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.input @@ -0,0 +1,7 @@ +class LongGenericFieldType { + private final AtomicReference> gridViewConfigurations = new AtomicReference<>(ImmutableTable.of()); + + private final AtomicReference> gridViewConfigurationsWithDefault = new AtomicReference<>(ImmutableTable.of()); + + private final AtomicReference> gridViewConfigurationsWithLongNames = new AtomicReference<>(ImmutableTable.of()); +} diff --git a/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.output b/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.output new file mode 100644 index 000000000..b684e45a3 --- /dev/null +++ b/open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/ojf-long-generic-field-type.output @@ -0,0 +1,16 @@ +class LongGenericFieldType { + private final AtomicReference> + gridViewConfigurations = new AtomicReference<>(ImmutableTable.of()); + + private final AtomicReference< + Table> + gridViewConfigurationsWithDefault = new AtomicReference<>(ImmutableTable.of()); + + private final AtomicReference< + Table< + RealmNameIdentifierValue, + CoreGridViewConfigurationIdentifierValue, + CoreGridViewConfigurationEntryValue, + DefaultValue>> + gridViewConfigurationsWithLongNames = new AtomicReference<>(ImmutableTable.of()); +}