diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java index 017811164..b44e24672 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java @@ -58,7 +58,7 @@ protected final void check() { @JsonCreator public static ConjurePackage of(String name) { - return ImmutableConjurePackage.builder().name(name).build(); + return ImmutableConjurePackage.builder().name(Names.intern(name)).build(); } public static ConjurePackage of(Iterable components) { diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java index 973f27202..2e4b70400 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java @@ -62,6 +62,6 @@ protected final void check() { @JsonCreator public static ErrorCode of(String name) { - return ImmutableErrorCode.builder().name(name).build(); + return ImmutableErrorCode.builder().name(Names.intern(name)).build(); } } diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java index e9d332384..112bfe56b 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java @@ -49,6 +49,6 @@ protected final void check() { @JsonCreator public static ErrorNamespace of(String name) { - return ImmutableErrorNamespace.builder().name(name).build(); + return ImmutableErrorNamespace.builder().name(Names.intern(name)).build(); } } diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java index 3a2200885..cb7317142 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java @@ -81,7 +81,7 @@ protected CaseConverter.Case nameCase() { @JsonCreator public static FieldName of(String name) { - return ImmutableFieldName.builder().name(name).build(); + return ImmutableFieldName.builder().name(Names.intern(name)).build(); } /** Converts this {@link FieldName} to a {@link FieldName} with the given case. */ diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Names.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Names.java new file mode 100644 index 000000000..fbe06a3bf --- /dev/null +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Names.java @@ -0,0 +1,31 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.conjure.parser.types.names; + +import com.google.common.collect.Interner; +import com.google.common.collect.Interners; +import javax.annotation.Nullable; + +final class Names { + private static final Interner internedNames = Interners.newWeakInterner(); + + private Names() {} + + static String intern(@Nullable String name) { + return (name == null) ? null : internedNames.intern(name); + } +} diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java index 2b6651be6..6d9b73982 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java @@ -47,6 +47,6 @@ protected final void check() { @JsonCreator public static Namespace of(String name) { - return ImmutableNamespace.builder().name(name).build(); + return ImmutableNamespace.builder().name(Names.intern(name)).build(); } } diff --git a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java index 4c9ba3416..abe40f13d 100644 --- a/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java +++ b/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java @@ -56,6 +56,6 @@ protected final void check() { @JsonCreator public static TypeName of(String name) { - return ImmutableTypeName.builder().name(name).build(); + return ImmutableTypeName.builder().name(Names.intern(name)).build(); } }