Skip to content

Commit

Permalink
refactor list creation to route through ConjureCollections
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarcaur committed Nov 14, 2024
1 parent e7a024c commit 1eecccf
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 44 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -259,7 +260,7 @@ private static MethodSpec createConstructor(Collection<EnrichedField> 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.palantir.logsafe.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -37,6 +38,12 @@ private ConjureCollections() {
// cannot instantiate
}

// Simple facade for right now, will be used in a future change
// to preserve some Jackson optimizations
public static <T> List<T> unmodifiableList(List<T> list) {
return Collections.unmodifiableList(list);
}

@SuppressWarnings("unchecked")
public static <T> void addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd) {
Preconditions.checkNotNull(elementsToAdd, "elementsToAdd cannot be null");
Expand Down

0 comments on commit 1eecccf

Please sign in to comment.