Skip to content

Commit 45e5e14

Browse files
Rename $Gson$Preconditions and $Gson$Types. (#2838)
There might have been good reasons to use these weird names back in the day, but they cause problems and there doesn't seem to be a compelling reason to avoid the more obvious names `GsonPreconditions` and `GsonTypes`.
1 parent c6d4425 commit 45e5e14

17 files changed

+73
-81
lines changed

gson/src/main/java/com/google/gson/GsonBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import com.google.errorprone.annotations.InlineMe;
3333
import com.google.gson.annotations.Since;
3434
import com.google.gson.annotations.Until;
35-
import com.google.gson.internal.$Gson$Preconditions;
3635
import com.google.gson.internal.Excluder;
36+
import com.google.gson.internal.GsonPreconditions;
3737
import com.google.gson.internal.bind.DefaultDateTypeAdapter;
3838
import com.google.gson.internal.bind.TreeTypeAdapter;
3939
import com.google.gson.internal.bind.TypeAdapters;
@@ -704,7 +704,7 @@ private static int checkDateFormatStyle(int style) {
704704
@CanIgnoreReturnValue
705705
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
706706
Objects.requireNonNull(type);
707-
$Gson$Preconditions.checkArgument(
707+
GsonPreconditions.checkArgument(
708708
typeAdapter instanceof JsonSerializer<?>
709709
|| typeAdapter instanceof JsonDeserializer<?>
710710
|| typeAdapter instanceof InstanceCreator<?>
@@ -778,7 +778,7 @@ public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
778778
@CanIgnoreReturnValue
779779
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
780780
Objects.requireNonNull(baseType);
781-
$Gson$Preconditions.checkArgument(
781+
GsonPreconditions.checkArgument(
782782
typeAdapter instanceof JsonSerializer<?>
783783
|| typeAdapter instanceof JsonDeserializer<?>
784784
|| typeAdapter instanceof TypeAdapter<?>);

gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private static boolean hasStringKeyType(Type mapType) {
367367
if (typeArguments.length == 0) {
368368
return false;
369369
}
370-
return $Gson$Types.getRawType(typeArguments[0]) == String.class;
370+
return GsonTypes.getRawType(typeArguments[0]) == String.class;
371371
}
372372

373373
private static ObjectConstructor<? extends Map<? extends Object, Object>> newMapConstructor(

gson/src/main/java/com/google/gson/internal/$Gson$Preconditions.java renamed to gson/src/main/java/com/google/gson/internal/GsonPreconditions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* @author Joel Leitch
3333
*/
3434
@SuppressWarnings("MemberName") // legacy class name
35-
public final class $Gson$Preconditions {
36-
private $Gson$Preconditions() {
35+
public final class GsonPreconditions {
36+
private GsonPreconditions() {
3737
throw new UnsupportedOperationException();
3838
}
3939

gson/src/main/java/com/google/gson/internal/$Gson$Types.java renamed to gson/src/main/java/com/google/gson/internal/GsonTypes.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.gson.internal;
1818

19-
import static com.google.gson.internal.$Gson$Preconditions.checkArgument;
19+
import static com.google.gson.internal.GsonPreconditions.checkArgument;
2020
import static java.util.Objects.requireNonNull;
2121

2222
import java.io.Serializable;
@@ -43,10 +43,10 @@
4343
* @author Jesse Wilson
4444
*/
4545
@SuppressWarnings("MemberName") // legacy class name
46-
public final class $Gson$Types {
46+
public final class GsonTypes {
4747
static final Type[] EMPTY_TYPE_ARRAY = new Type[] {};
4848

49-
private $Gson$Types() {
49+
private GsonTypes() {
5050
throw new UnsupportedOperationException();
5151
}
5252

@@ -288,9 +288,7 @@ private static Type getSupertype(Type context, Class<?> contextRawType, Class<?>
288288
}
289289
checkArgument(supertype.isAssignableFrom(contextRawType));
290290
return resolve(
291-
context,
292-
contextRawType,
293-
$Gson$Types.getGenericSupertype(context, contextRawType, supertype));
291+
context, contextRawType, GsonTypes.getGenericSupertype(context, contextRawType, supertype));
294292
}
295293

296294
/**
@@ -555,7 +553,7 @@ public Type getOwnerType() {
555553
@Override
556554
public boolean equals(Object other) {
557555
return other instanceof ParameterizedType
558-
&& $Gson$Types.equals(this, (ParameterizedType) other);
556+
&& GsonTypes.equals(this, (ParameterizedType) other);
559557
}
560558

561559
private static int hashCodeOrZero(Object o) {
@@ -604,7 +602,7 @@ public Type getGenericComponentType() {
604602

605603
@Override
606604
public boolean equals(Object o) {
607-
return o instanceof GenericArrayType && $Gson$Types.equals(this, (GenericArrayType) o);
605+
return o instanceof GenericArrayType && GsonTypes.equals(this, (GenericArrayType) o);
608606
}
609607

610608
@Override
@@ -664,7 +662,7 @@ public Type[] getLowerBounds() {
664662

665663
@Override
666664
public boolean equals(Object other) {
667-
return other instanceof WildcardType && $Gson$Types.equals(this, (WildcardType) other);
665+
return other instanceof WildcardType && GsonTypes.equals(this, (WildcardType) other);
668666
}
669667

670668
@Override

gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.google.gson.Gson;
2020
import com.google.gson.TypeAdapter;
2121
import com.google.gson.TypeAdapterFactory;
22-
import com.google.gson.internal.$Gson$Types;
22+
import com.google.gson.internal.GsonTypes;
2323
import com.google.gson.reflect.TypeToken;
2424
import com.google.gson.stream.JsonReader;
2525
import com.google.gson.stream.JsonToken;
@@ -42,13 +42,12 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
4242
return null;
4343
}
4444

45-
Type componentType = $Gson$Types.getArrayComponentType(type);
45+
Type componentType = GsonTypes.getArrayComponentType(type);
4646
TypeAdapter<?> componentTypeAdapter = gson.getAdapter(TypeToken.get(componentType));
4747

4848
@SuppressWarnings({"unchecked", "rawtypes"})
4949
TypeAdapter<T> arrayAdapter =
50-
new ArrayTypeAdapter(
51-
gson, componentTypeAdapter, $Gson$Types.getRawType(componentType));
50+
new ArrayTypeAdapter(gson, componentTypeAdapter, GsonTypes.getRawType(componentType));
5251
return arrayAdapter;
5352
}
5453
};

gson/src/main/java/com/google/gson/internal/bind/CollectionTypeAdapterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.google.gson.Gson;
2020
import com.google.gson.TypeAdapter;
2121
import com.google.gson.TypeAdapterFactory;
22-
import com.google.gson.internal.$Gson$Types;
2322
import com.google.gson.internal.ConstructorConstructor;
23+
import com.google.gson.internal.GsonTypes;
2424
import com.google.gson.internal.ObjectConstructor;
2525
import com.google.gson.reflect.TypeToken;
2626
import com.google.gson.stream.JsonReader;
@@ -47,7 +47,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
4747
return null;
4848
}
4949

50-
Type elementType = $Gson$Types.getCollectionElementType(type, rawType);
50+
Type elementType = GsonTypes.getCollectionElementType(type, rawType);
5151
TypeAdapter<?> elementTypeAdapter = gson.getAdapter(TypeToken.get(elementType));
5252
TypeAdapter<?> wrappedTypeAdapter =
5353
new TypeAdapterRuntimeTypeWrapper<>(gson, elementTypeAdapter, elementType);

gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.google.gson.JsonSyntaxException;
2323
import com.google.gson.TypeAdapter;
2424
import com.google.gson.TypeAdapterFactory;
25-
import com.google.gson.internal.$Gson$Types;
2625
import com.google.gson.internal.ConstructorConstructor;
26+
import com.google.gson.internal.GsonTypes;
2727
import com.google.gson.internal.JsonReaderInternalAccess;
2828
import com.google.gson.internal.ObjectConstructor;
2929
import com.google.gson.internal.Streams;
@@ -131,7 +131,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
131131
return null;
132132
}
133133

134-
Type[] keyAndValueTypes = $Gson$Types.getMapKeyAndValueTypes(type, rawType);
134+
Type[] keyAndValueTypes = GsonTypes.getMapKeyAndValueTypes(type, rawType);
135135
Type keyType = keyAndValueTypes[0];
136136
Type valueType = keyAndValueTypes[1];
137137
TypeAdapter<?> keyAdapter = getKeyAdapter(gson, keyType);

gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import com.google.gson.TypeAdapterFactory;
2828
import com.google.gson.annotations.JsonAdapter;
2929
import com.google.gson.annotations.SerializedName;
30-
import com.google.gson.internal.$Gson$Types;
3130
import com.google.gson.internal.ConstructorConstructor;
3231
import com.google.gson.internal.Excluder;
32+
import com.google.gson.internal.GsonTypes;
3333
import com.google.gson.internal.ObjectConstructor;
3434
import com.google.gson.internal.Primitives;
3535
import com.google.gson.internal.ReflectionAccessFilterHelper;
@@ -387,7 +387,7 @@ private FieldsData getBoundFields(
387387
ReflectionHelper.makeAccessible(field);
388388
}
389389

390-
Type fieldType = $Gson$Types.resolve(type.getType(), raw, field.getGenericType());
390+
Type fieldType = GsonTypes.resolve(type.getType(), raw, field.getGenericType());
391391
List<String> fieldNames = getFieldNames(field);
392392
String serializedName = fieldNames.get(0);
393393
BoundField boundField =
@@ -417,7 +417,7 @@ private FieldsData getBoundFields(
417417
}
418418
}
419419
}
420-
type = TypeToken.get($Gson$Types.resolve(type.getType(), raw, raw.getGenericSuperclass()));
420+
type = TypeToken.get(GsonTypes.resolve(type.getType(), raw, raw.getGenericSuperclass()));
421421
raw = type.getRawType();
422422
}
423423
return new FieldsData(deserializedFields, new ArrayList<>(serializedFields.values()));

gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.gson.JsonSerializer;
2626
import com.google.gson.TypeAdapter;
2727
import com.google.gson.TypeAdapterFactory;
28-
import com.google.gson.internal.$Gson$Preconditions;
28+
import com.google.gson.internal.GsonPreconditions;
2929
import com.google.gson.internal.Streams;
3030
import com.google.gson.reflect.TypeToken;
3131
import com.google.gson.stream.JsonReader;
@@ -162,7 +162,7 @@ private static final class SingleTypeFactory implements TypeAdapterFactory {
162162
serializer = typeAdapter instanceof JsonSerializer ? (JsonSerializer<?>) typeAdapter : null;
163163
deserializer =
164164
typeAdapter instanceof JsonDeserializer ? (JsonDeserializer<?>) typeAdapter : null;
165-
$Gson$Preconditions.checkArgument(serializer != null || deserializer != null);
165+
GsonPreconditions.checkArgument(serializer != null || deserializer != null);
166166
this.exactType = exactType;
167167
this.matchRawType = matchRawType;
168168
this.hierarchyType = hierarchyType;

gson/src/main/java/com/google/gson/reflect/TypeToken.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.gson.reflect;
1818

19-
import com.google.gson.internal.$Gson$Types;
19+
import com.google.gson.internal.GsonTypes;
2020
import com.google.gson.internal.TroubleshootingGuide;
2121
import java.lang.reflect.GenericArrayType;
2222
import java.lang.reflect.ParameterizedType;
@@ -72,15 +72,15 @@ public class TypeToken<T> {
7272
@SuppressWarnings("unchecked")
7373
protected TypeToken() {
7474
this.type = getTypeTokenTypeArgument();
75-
this.rawType = (Class<? super T>) $Gson$Types.getRawType(type);
75+
this.rawType = (Class<? super T>) GsonTypes.getRawType(type);
7676
this.hashCode = type.hashCode();
7777
}
7878

7979
/** Unsafe. Constructs a type literal manually. */
8080
@SuppressWarnings("unchecked")
8181
private TypeToken(Type type) {
82-
this.type = $Gson$Types.canonicalize(Objects.requireNonNull(type));
83-
this.rawType = (Class<? super T>) $Gson$Types.getRawType(this.type);
82+
this.type = GsonTypes.canonicalize(Objects.requireNonNull(type));
83+
this.rawType = (Class<? super T>) GsonTypes.getRawType(this.type);
8484
this.hashCode = this.type.hashCode();
8585
}
8686

@@ -90,14 +90,14 @@ private static boolean isCapturingTypeVariablesForbidden() {
9090

9191
/**
9292
* Verifies that {@code this} is an instance of a direct subclass of TypeToken and returns the
93-
* type argument for {@code T} in {@link $Gson$Types#canonicalize canonical form}.
93+
* type argument for {@code T} in {@link GsonTypes#canonicalize canonical form}.
9494
*/
9595
private Type getTypeTokenTypeArgument() {
9696
Type superclass = getClass().getGenericSuperclass();
9797
if (superclass instanceof ParameterizedType) {
9898
ParameterizedType parameterized = (ParameterizedType) superclass;
9999
if (parameterized.getRawType() == TypeToken.class) {
100-
Type typeArgument = $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
100+
Type typeArgument = GsonTypes.canonicalize(parameterized.getActualTypeArguments()[0]);
101101

102102
if (isCapturingTypeVariablesForbidden()) {
103103
verifyNoTypeVariable(typeArgument);
@@ -193,11 +193,11 @@ public boolean isAssignableFrom(Type from) {
193193
}
194194

195195
if (type instanceof Class<?>) {
196-
return rawType.isAssignableFrom($Gson$Types.getRawType(from));
196+
return rawType.isAssignableFrom(GsonTypes.getRawType(from));
197197
} else if (type instanceof ParameterizedType) {
198198
return isAssignableFrom(from, (ParameterizedType) type, new HashMap<String, Type>());
199199
} else if (type instanceof GenericArrayType) {
200-
return rawType.isAssignableFrom($Gson$Types.getRawType(from))
200+
return rawType.isAssignableFrom(GsonTypes.getRawType(from))
201201
&& isAssignableFrom(from, (GenericArrayType) type);
202202
} else {
203203
throw buildUnsupportedTypeException(
@@ -253,7 +253,7 @@ private static boolean isAssignableFrom(
253253
}
254254

255255
// First figure out the class and any type information.
256-
Class<?> clazz = $Gson$Types.getRawType(from);
256+
Class<?> clazz = GsonTypes.getRawType(from);
257257
ParameterizedType ptype = null;
258258
if (from instanceof ParameterizedType) {
259259
ptype = (ParameterizedType) from;
@@ -343,12 +343,12 @@ public final int hashCode() {
343343

344344
@Override
345345
public final boolean equals(Object o) {
346-
return o instanceof TypeToken<?> && $Gson$Types.equals(type, ((TypeToken<?>) o).type);
346+
return o instanceof TypeToken<?> && GsonTypes.equals(type, ((TypeToken<?>) o).type);
347347
}
348348

349349
@Override
350350
public final String toString() {
351-
return $Gson$Types.typeToString(type);
351+
return GsonTypes.typeToString(type);
352352
}
353353

354354
/** Gets type literal for the given {@code Type} instance. */
@@ -412,7 +412,7 @@ public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments)
412412
}
413413

414414
// Check for this here to avoid misleading exception thrown by ParameterizedTypeImpl
415-
if ($Gson$Types.requiresOwnerType(rawType)) {
415+
if (GsonTypes.requiresOwnerType(rawType)) {
416416
throw new IllegalArgumentException(
417417
"Raw type "
418418
+ rawClass.getName()
@@ -422,11 +422,11 @@ public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments)
422422
for (int i = 0; i < expectedArgsCount; i++) {
423423
Type typeArgument =
424424
Objects.requireNonNull(typeArguments[i], "Type argument must not be null");
425-
Class<?> rawTypeArgument = $Gson$Types.getRawType(typeArgument);
425+
Class<?> rawTypeArgument = GsonTypes.getRawType(typeArgument);
426426
TypeVariable<?> typeVariable = typeVariables[i];
427427

428428
for (Type bound : typeVariable.getBounds()) {
429-
Class<?> rawBound = $Gson$Types.getRawType(bound);
429+
Class<?> rawBound = GsonTypes.getRawType(bound);
430430

431431
if (!rawBound.isAssignableFrom(rawTypeArgument)) {
432432
throw new IllegalArgumentException(
@@ -440,14 +440,13 @@ public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments)
440440
}
441441
}
442442

443-
return new TypeToken<>(
444-
$Gson$Types.newParameterizedTypeWithOwner(null, rawClass, typeArguments));
443+
return new TypeToken<>(GsonTypes.newParameterizedTypeWithOwner(null, rawClass, typeArguments));
445444
}
446445

447446
/**
448447
* Gets type literal for the array type whose elements are all instances of {@code componentType}.
449448
*/
450449
public static TypeToken<?> getArray(Type componentType) {
451-
return new TypeToken<>($Gson$Types.arrayOf(componentType));
450+
return new TypeToken<>(GsonTypes.arrayOf(componentType));
452451
}
453452
}

gson/src/test/java/com/google/gson/GenericArrayTypeTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.gson.internal.$Gson$Types;
21+
import com.google.gson.internal.GsonTypes;
2222
import com.google.gson.reflect.TypeToken;
2323
import java.lang.reflect.GenericArrayType;
2424
import java.lang.reflect.Type;
@@ -27,7 +27,7 @@
2727
import org.junit.Test;
2828

2929
/**
30-
* Unit tests for the {@code GenericArrayType}s created by the {@link $Gson$Types} class.
30+
* Unit tests for the {@code GenericArrayType}s created by the {@link GsonTypes} class.
3131
*
3232
* @author Inderjeet Singh
3333
* @author Joel Leitch
@@ -38,8 +38,7 @@ public class GenericArrayTypeTest {
3838
@Before
3939
public void setUp() throws Exception {
4040
ourType =
41-
$Gson$Types.arrayOf(
42-
$Gson$Types.newParameterizedTypeWithOwner(null, List.class, String.class));
41+
GsonTypes.arrayOf(GsonTypes.newParameterizedTypeWithOwner(null, List.class, String.class));
4342
}
4443

4544
@Test

gson/src/test/java/com/google/gson/ParameterizedTypeFixtures.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.gson;
1818

19-
import com.google.gson.internal.$Gson$Types;
19+
import com.google.gson.internal.GsonTypes;
2020
import com.google.gson.internal.Primitives;
2121
import java.lang.reflect.Method;
2222
import java.lang.reflect.ParameterizedType;
@@ -139,7 +139,7 @@ public MyParameterizedType<T> deserialize(
139139
JsonElement json, Type typeOfT, JsonDeserializationContext context)
140140
throws JsonParseException {
141141
Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
142-
Class<?> rawType = $Gson$Types.getRawType(genericClass);
142+
Class<?> rawType = GsonTypes.getRawType(genericClass);
143143
String className = rawType.getSimpleName();
144144
JsonElement jsonElement = json.getAsJsonObject().get(className);
145145

0 commit comments

Comments
 (0)