From 74269fcdf91558fa2edcf06af460e37bdf9178d6 Mon Sep 17 00:00:00 2001 From: Brandon Marc-Aurele Date: Thu, 14 Nov 2024 13:14:06 -0500 Subject: [PATCH] refactor list creation to route through ConjureCollections --- .../palantir/product/CollectionsTestObject.java | 2 +- .../palantir/product/CovariantListExample.java | 5 ++--- .../com/palantir/product/ExternalLongExample.java | 3 +-- .../java/com/palantir/product/ListExample.java | 15 +++++++-------- .../com/palantir/product/ManyFieldExample.java | 2 +- .../product/MultipleFieldsOnlyFinalStage.java | 4 ++-- .../palantir/product/SafeExternalLongExample.java | 2 +- .../com/palantir/product/SafeLongExample.java | 3 +-- .../com/palantir/product/StrictFourFields.java | 2 +- .../StrictMultipleDeprecatedAndUnsafeFields.java | 2 +- .../product/StrictOneCollectionField.java | 3 +-- .../com/palantir/product/StrictThreeFields.java | 3 +-- .../palantir/product/CovariantListExample.java | 5 ++--- .../com/palantir/product/ExternalLongExample.java | 3 +-- .../prefix/com/palantir/product/ListExample.java | 15 +++++++-------- .../com/palantir/product/ManyFieldExample.java | 2 +- .../palantir/product/SafeExternalLongExample.java | 2 +- .../com/palantir/product/SafeLongExample.java | 3 +-- .../conjure/java/types/BeanGenerator.java | 3 ++- 19 files changed, 35 insertions(+), 44 deletions(-) diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/CollectionsTestObject.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/CollectionsTestObject.java index a2b70e293..4f65c071d 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/CollectionsTestObject.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/CollectionsTestObject.java @@ -50,7 +50,7 @@ private CollectionsTestObject( CollectionsTestAliasSet aset, CollectionsTestAliasMap amap) { validateFields(items, itemsMap, optionalItem, itemsSet, alist, aset, amap); - this.items = Collections.unmodifiableList(items); + this.items = ConjureCollections.unmodifiableList(items); this.itemsMap = Collections.unmodifiableMap(itemsMap); this.optionalItem = optionalItem; this.itemsSet = Collections.unmodifiableSet(itemsSet); diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/CovariantListExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/CovariantListExample.java index d0037dfe5..60ac3e9a0 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/CovariantListExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/CovariantListExample.java @@ -10,7 +10,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -28,8 +27,8 @@ public final class CovariantListExample { private CovariantListExample(List items, List externalItems) { validateFields(items, externalItems); - this.items = Collections.unmodifiableList(items); - this.externalItems = Collections.unmodifiableList(externalItems); + this.items = ConjureCollections.unmodifiableList(items); + this.externalItems = ConjureCollections.unmodifiableList(externalItems); } @JsonProperty("items") diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/ExternalLongExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/ExternalLongExample.java index 6a219fd2d..561025f71 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/ExternalLongExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/ExternalLongExample.java @@ -11,7 +11,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -34,7 +33,7 @@ private ExternalLongExample(long externalLong, Optional optionalExternalLo validateFields(optionalExternalLong, listExternalLong); this.externalLong = externalLong; this.optionalExternalLong = optionalExternalLong; - this.listExternalLong = Collections.unmodifiableList(listExternalLong); + this.listExternalLong = ConjureCollections.unmodifiableList(listExternalLong); } @JsonProperty("externalLong") diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/ListExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/ListExample.java index 885402021..8e739e799 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/ListExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/ListExample.java @@ -11,7 +11,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; @@ -47,13 +46,13 @@ private ListExample( List> nestedItems) { validateFields( items, primitiveItems, doubleItems, booleanItems, optionalItems, aliasOptionalItems, nestedItems); - this.items = Collections.unmodifiableList(items); - this.primitiveItems = Collections.unmodifiableList(primitiveItems); - this.doubleItems = Collections.unmodifiableList(doubleItems); - this.booleanItems = Collections.unmodifiableList(booleanItems); - this.optionalItems = Collections.unmodifiableList(optionalItems); - this.aliasOptionalItems = Collections.unmodifiableList(aliasOptionalItems); - this.nestedItems = Collections.unmodifiableList(nestedItems); + this.items = ConjureCollections.unmodifiableList(items); + this.primitiveItems = ConjureCollections.unmodifiableList(primitiveItems); + this.doubleItems = ConjureCollections.unmodifiableList(doubleItems); + this.booleanItems = ConjureCollections.unmodifiableList(booleanItems); + this.optionalItems = ConjureCollections.unmodifiableList(optionalItems); + this.aliasOptionalItems = ConjureCollections.unmodifiableList(aliasOptionalItems); + this.nestedItems = ConjureCollections.unmodifiableList(nestedItems); } @JsonProperty("items") diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/ManyFieldExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/ManyFieldExample.java index 7386d9a38..860ef06f9 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/ManyFieldExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/ManyFieldExample.java @@ -56,7 +56,7 @@ private ManyFieldExample( this.integer = integer; this.doubleValue = doubleValue; this.optionalItem = optionalItem; - this.items = Collections.unmodifiableList(items); + this.items = ConjureCollections.unmodifiableList(items); this.set = Collections.unmodifiableSet(set); this.map = Collections.unmodifiableMap(map); this.alias = alias; diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/MultipleFieldsOnlyFinalStage.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/MultipleFieldsOnlyFinalStage.java index 8b6984d98..44217c2bb 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/MultipleFieldsOnlyFinalStage.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/MultipleFieldsOnlyFinalStage.java @@ -53,11 +53,11 @@ private MultipleFieldsOnlyFinalStage( Optional optionalItemOld, Set itemsSetOld) { validateFields(items, itemsMap, optionalItem, itemsSet, itemsOld, itemsMapOld, optionalItemOld, itemsSetOld); - this.items = Collections.unmodifiableList(items); + this.items = ConjureCollections.unmodifiableList(items); this.itemsMap = Collections.unmodifiableMap(itemsMap); this.optionalItem = optionalItem; this.itemsSet = Collections.unmodifiableSet(itemsSet); - this.itemsOld = Collections.unmodifiableList(itemsOld); + this.itemsOld = ConjureCollections.unmodifiableList(itemsOld); this.itemsMapOld = Collections.unmodifiableMap(itemsMapOld); this.optionalItemOld = optionalItemOld; this.itemsSetOld = Collections.unmodifiableSet(itemsSetOld); diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeExternalLongExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeExternalLongExample.java index ee64acbd5..ea5ec2019 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeExternalLongExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeExternalLongExample.java @@ -43,7 +43,7 @@ private SafeExternalLongExample( validateFields(optionalSafeExternalLong, safeExternalLongList, safeExternalLongSet); this.safeExternalLongValue = safeExternalLongValue; this.optionalSafeExternalLong = optionalSafeExternalLong; - this.safeExternalLongList = Collections.unmodifiableList(safeExternalLongList); + this.safeExternalLongList = ConjureCollections.unmodifiableList(safeExternalLongList); this.safeExternalLongSet = Collections.unmodifiableSet(safeExternalLongSet); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongExample.java index ba755c61a..227e74a05 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongExample.java @@ -11,7 +11,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -29,7 +28,7 @@ public final class SafeLongExample { private SafeLongExample(SafeLong safeLongValue, List safeLongList) { validateFields(safeLongValue, safeLongList); this.safeLongValue = safeLongValue; - this.safeLongList = Collections.unmodifiableList(safeLongList); + this.safeLongList = ConjureCollections.unmodifiableList(safeLongList); } @JsonProperty("safeLongValue") diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictFourFields.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictFourFields.java index 8a20c77a3..609669d9b 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictFourFields.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictFourFields.java @@ -44,7 +44,7 @@ private StrictFourFields( Optional optionalItem, Map mappedRids) { validateFields(myList, bearerTokenValue, optionalItem, mappedRids); - this.myList = Collections.unmodifiableList(myList); + this.myList = ConjureCollections.unmodifiableList(myList); this.bearerTokenValue = bearerTokenValue; this.optionalItem = optionalItem; this.mappedRids = Collections.unmodifiableMap(mappedRids); diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictMultipleDeprecatedAndUnsafeFields.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictMultipleDeprecatedAndUnsafeFields.java index 1035a2096..842d79234 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictMultipleDeprecatedAndUnsafeFields.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictMultipleDeprecatedAndUnsafeFields.java @@ -55,7 +55,7 @@ private StrictMultipleDeprecatedAndUnsafeFields( Map mappedRids, StrictFourFields strictFourFieldsObject) { validateFields(myList, bearerTokenValue, safeLongValue, optionalItem, mappedRids, strictFourFieldsObject); - this.myList = Collections.unmodifiableList(myList); + this.myList = ConjureCollections.unmodifiableList(myList); this.bearerTokenValue = bearerTokenValue; this.safeLongValue = safeLongValue; this.myInteger = myInteger; diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictOneCollectionField.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictOneCollectionField.java index 49ff3d3da..dd74d7b72 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictOneCollectionField.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictOneCollectionField.java @@ -11,7 +11,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -26,7 +25,7 @@ public final class StrictOneCollectionField { private StrictOneCollectionField(List myList) { validateFields(myList); - this.myList = Collections.unmodifiableList(myList); + this.myList = ConjureCollections.unmodifiableList(myList); } @JsonProperty("myList") diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictThreeFields.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictThreeFields.java index 4ae6c4551..80e89cfe0 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictThreeFields.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/StrictThreeFields.java @@ -14,7 +14,6 @@ import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import com.palantir.tokens.auth.BearerToken; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; @@ -35,7 +34,7 @@ public final class StrictThreeFields { private StrictThreeFields(List myList, BearerToken bearerTokenValue, Optional optionalItem) { validateFields(myList, bearerTokenValue, optionalItem); - this.myList = Collections.unmodifiableList(myList); + this.myList = ConjureCollections.unmodifiableList(myList); this.bearerTokenValue = bearerTokenValue; this.optionalItem = optionalItem; } diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/CovariantListExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/CovariantListExample.java index 8eff4d61e..e59c78b13 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/CovariantListExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/CovariantListExample.java @@ -11,7 +11,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -29,8 +28,8 @@ public final class CovariantListExample { private CovariantListExample(List items, List externalItems) { validateFields(items, externalItems); - this.items = Collections.unmodifiableList(items); - this.externalItems = Collections.unmodifiableList(externalItems); + this.items = ConjureCollections.unmodifiableList(items); + this.externalItems = ConjureCollections.unmodifiableList(externalItems); } @JsonProperty("items") diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ExternalLongExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ExternalLongExample.java index d5e45b8f5..0cb67d326 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ExternalLongExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ExternalLongExample.java @@ -12,7 +12,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -35,7 +34,7 @@ private ExternalLongExample(long externalLong, Optional optionalExternalLo validateFields(optionalExternalLong, listExternalLong); this.externalLong = externalLong; this.optionalExternalLong = optionalExternalLong; - this.listExternalLong = Collections.unmodifiableList(listExternalLong); + this.listExternalLong = ConjureCollections.unmodifiableList(listExternalLong); } @JsonProperty("externalLong") diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ListExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ListExample.java index 21a972e86..4bf20286d 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ListExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ListExample.java @@ -12,7 +12,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; @@ -48,13 +47,13 @@ private ListExample( List> nestedItems) { validateFields( items, primitiveItems, doubleItems, booleanItems, optionalItems, aliasOptionalItems, nestedItems); - this.items = Collections.unmodifiableList(items); - this.primitiveItems = Collections.unmodifiableList(primitiveItems); - this.doubleItems = Collections.unmodifiableList(doubleItems); - this.booleanItems = Collections.unmodifiableList(booleanItems); - this.optionalItems = Collections.unmodifiableList(optionalItems); - this.aliasOptionalItems = Collections.unmodifiableList(aliasOptionalItems); - this.nestedItems = Collections.unmodifiableList(nestedItems); + this.items = ConjureCollections.unmodifiableList(items); + this.primitiveItems = ConjureCollections.unmodifiableList(primitiveItems); + this.doubleItems = ConjureCollections.unmodifiableList(doubleItems); + this.booleanItems = ConjureCollections.unmodifiableList(booleanItems); + this.optionalItems = ConjureCollections.unmodifiableList(optionalItems); + this.aliasOptionalItems = ConjureCollections.unmodifiableList(aliasOptionalItems); + this.nestedItems = ConjureCollections.unmodifiableList(nestedItems); } @JsonProperty("items") diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ManyFieldExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ManyFieldExample.java index 0f421ecbf..dafbd08c8 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ManyFieldExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/ManyFieldExample.java @@ -57,7 +57,7 @@ private ManyFieldExample( this.integer = integer; this.doubleValue = doubleValue; this.optionalItem = optionalItem; - this.items = Collections.unmodifiableList(items); + this.items = ConjureCollections.unmodifiableList(items); this.set = Collections.unmodifiableSet(set); this.map = Collections.unmodifiableMap(map); this.alias = alias; diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeExternalLongExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeExternalLongExample.java index e03834858..81ae838be 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeExternalLongExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeExternalLongExample.java @@ -44,7 +44,7 @@ private SafeExternalLongExample( validateFields(optionalSafeExternalLong, safeExternalLongList, safeExternalLongSet); this.safeExternalLongValue = safeExternalLongValue; this.optionalSafeExternalLong = optionalSafeExternalLong; - this.safeExternalLongList = Collections.unmodifiableList(safeExternalLongList); + this.safeExternalLongList = ConjureCollections.unmodifiableList(safeExternalLongList); this.safeExternalLongSet = Collections.unmodifiableSet(safeExternalLongSet); } diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeLongExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeLongExample.java index f444d7d4c..9868e5ff1 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeLongExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeLongExample.java @@ -12,7 +12,6 @@ import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -30,7 +29,7 @@ public final class SafeLongExample { private SafeLongExample(SafeLong safeLongValue, List safeLongList) { validateFields(safeLongValue, safeLongList); this.safeLongValue = safeLongValue; - this.safeLongList = Collections.unmodifiableList(safeLongList); + this.safeLongList = ConjureCollections.unmodifiableList(safeLongList); } @JsonProperty("safeLongValue") diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/BeanGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/BeanGenerator.java index ea7caa700..8267d8ef9 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/BeanGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/BeanGenerator.java @@ -26,6 +26,7 @@ import com.palantir.conjure.CaseConverter; import com.palantir.conjure.java.ConjureAnnotations; import com.palantir.conjure.java.Options; +import com.palantir.conjure.java.lib.internal.ConjureCollections; import com.palantir.conjure.java.util.JavaNameSanitizer; import com.palantir.conjure.java.util.Javadoc; import com.palantir.conjure.java.util.Packages; @@ -259,7 +260,7 @@ private static MethodSpec createConstructor(Collection fields, Co // is private and necessarily called from the builder, which does its own defensive copying. if (field.conjureDef().getType().accept(TypeVisitor.IS_LIST)) { // TODO(melliot): contribute a fix to JavaPoet that parses $T correctly for a JavaPoet FieldSpec - body.addStatement("this.$1N = $2T.unmodifiableList($1N)", spec, Collections.class); + body.addStatement("this.$1N = $2T.unmodifiableList($1N)", spec, ConjureCollections.class); } else if (field.conjureDef().getType().accept(TypeVisitor.IS_SET)) { body.addStatement("this.$1N = $2T.unmodifiableSet($1N)", spec, Collections.class); } else if (field.conjureDef().getType().accept(TypeVisitor.IS_MAP)) {