Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gson/src/main/java/com/google/gson/GsonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import com.google.errorprone.annotations.InlineMe;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;
import com.google.gson.internal.$Gson$Preconditions;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.GsonPreconditions;
import com.google.gson.internal.bind.DefaultDateTypeAdapter;
import com.google.gson.internal.bind.TreeTypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
Expand Down Expand Up @@ -704,7 +704,7 @@ private static int checkDateFormatStyle(int style) {
@CanIgnoreReturnValue
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
Objects.requireNonNull(type);
$Gson$Preconditions.checkArgument(
GsonPreconditions.checkArgument(
typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?>
|| typeAdapter instanceof InstanceCreator<?>
Expand Down Expand Up @@ -778,7 +778,7 @@ public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
@CanIgnoreReturnValue
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
Objects.requireNonNull(baseType);
$Gson$Preconditions.checkArgument(
GsonPreconditions.checkArgument(
typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?>
|| typeAdapter instanceof TypeAdapter<?>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private static boolean hasStringKeyType(Type mapType) {
if (typeArguments.length == 0) {
return false;
}
return $Gson$Types.getRawType(typeArguments[0]) == String.class;
return GsonTypes.getRawType(typeArguments[0]) == String.class;
}

private static ObjectConstructor<? extends Map<? extends Object, Object>> newMapConstructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
* @author Joel Leitch
*/
@SuppressWarnings("MemberName") // legacy class name
public final class $Gson$Preconditions {
private $Gson$Preconditions() {
public final class GsonPreconditions {
private GsonPreconditions() {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.gson.internal;

import static com.google.gson.internal.$Gson$Preconditions.checkArgument;
import static com.google.gson.internal.GsonPreconditions.checkArgument;
import static java.util.Objects.requireNonNull;

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

private $Gson$Types() {
private GsonTypes() {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -288,9 +288,7 @@ private static Type getSupertype(Type context, Class<?> contextRawType, Class<?>
}
checkArgument(supertype.isAssignableFrom(contextRawType));
return resolve(
context,
contextRawType,
$Gson$Types.getGenericSupertype(context, contextRawType, supertype));
context, contextRawType, GsonTypes.getGenericSupertype(context, contextRawType, supertype));
}

/**
Expand Down Expand Up @@ -555,7 +553,7 @@ public Type getOwnerType() {
@Override
public boolean equals(Object other) {
return other instanceof ParameterizedType
&& $Gson$Types.equals(this, (ParameterizedType) other);
&& GsonTypes.equals(this, (ParameterizedType) other);
}

private static int hashCodeOrZero(Object o) {
Expand Down Expand Up @@ -604,7 +602,7 @@ public Type getGenericComponentType() {

@Override
public boolean equals(Object o) {
return o instanceof GenericArrayType && $Gson$Types.equals(this, (GenericArrayType) o);
return o instanceof GenericArrayType && GsonTypes.equals(this, (GenericArrayType) o);
}

@Override
Expand Down Expand Up @@ -664,7 +662,7 @@ public Type[] getLowerBounds() {

@Override
public boolean equals(Object other) {
return other instanceof WildcardType && $Gson$Types.equals(this, (WildcardType) other);
return other instanceof WildcardType && GsonTypes.equals(this, (WildcardType) other);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.GsonTypes;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
Expand All @@ -42,13 +42,12 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
return null;
}

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

@SuppressWarnings({"unchecked", "rawtypes"})
TypeAdapter<T> arrayAdapter =
new ArrayTypeAdapter(
gson, componentTypeAdapter, $Gson$Types.getRawType(componentType));
new ArrayTypeAdapter(gson, componentTypeAdapter, GsonTypes.getRawType(componentType));
return arrayAdapter;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.GsonTypes;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
Expand All @@ -47,7 +47,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
return null;
}

Type elementType = $Gson$Types.getCollectionElementType(type, rawType);
Type elementType = GsonTypes.getCollectionElementType(type, rawType);
TypeAdapter<?> elementTypeAdapter = gson.getAdapter(TypeToken.get(elementType));
TypeAdapter<?> wrappedTypeAdapter =
new TypeAdapterRuntimeTypeWrapper<>(gson, elementTypeAdapter, elementType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.GsonTypes;
import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.internal.Streams;
Expand Down Expand Up @@ -131,7 +131,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
return null;
}

Type[] keyAndValueTypes = $Gson$Types.getMapKeyAndValueTypes(type, rawType);
Type[] keyAndValueTypes = GsonTypes.getMapKeyAndValueTypes(type, rawType);
Type keyType = keyAndValueTypes[0];
Type valueType = keyAndValueTypes[1];
TypeAdapter<?> keyAdapter = getKeyAdapter(gson, keyType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.GsonTypes;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.ReflectionAccessFilterHelper;
Expand Down Expand Up @@ -387,7 +387,7 @@ private FieldsData getBoundFields(
ReflectionHelper.makeAccessible(field);
}

Type fieldType = $Gson$Types.resolve(type.getType(), raw, field.getGenericType());
Type fieldType = GsonTypes.resolve(type.getType(), raw, field.getGenericType());
List<String> fieldNames = getFieldNames(field);
String serializedName = fieldNames.get(0);
BoundField boundField =
Expand Down Expand Up @@ -417,7 +417,7 @@ private FieldsData getBoundFields(
}
}
}
type = TypeToken.get($Gson$Types.resolve(type.getType(), raw, raw.getGenericSuperclass()));
type = TypeToken.get(GsonTypes.resolve(type.getType(), raw, raw.getGenericSuperclass()));
raw = type.getRawType();
}
return new FieldsData(deserializedFields, new ArrayList<>(serializedFields.values()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Preconditions;
import com.google.gson.internal.GsonPreconditions;
import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
Expand Down Expand Up @@ -162,7 +162,7 @@ private static final class SingleTypeFactory implements TypeAdapterFactory {
serializer = typeAdapter instanceof JsonSerializer ? (JsonSerializer<?>) typeAdapter : null;
deserializer =
typeAdapter instanceof JsonDeserializer ? (JsonDeserializer<?>) typeAdapter : null;
$Gson$Preconditions.checkArgument(serializer != null || deserializer != null);
GsonPreconditions.checkArgument(serializer != null || deserializer != null);
this.exactType = exactType;
this.matchRawType = matchRawType;
this.hierarchyType = hierarchyType;
Expand Down
33 changes: 16 additions & 17 deletions gson/src/main/java/com/google/gson/reflect/TypeToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.gson.reflect;

import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.GsonTypes;
import com.google.gson.internal.TroubleshootingGuide;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -72,15 +72,15 @@ public class TypeToken<T> {
@SuppressWarnings("unchecked")
protected TypeToken() {
this.type = getTypeTokenTypeArgument();
this.rawType = (Class<? super T>) $Gson$Types.getRawType(type);
this.rawType = (Class<? super T>) GsonTypes.getRawType(type);
this.hashCode = type.hashCode();
}

/** Unsafe. Constructs a type literal manually. */
@SuppressWarnings("unchecked")
private TypeToken(Type type) {
this.type = $Gson$Types.canonicalize(Objects.requireNonNull(type));
this.rawType = (Class<? super T>) $Gson$Types.getRawType(this.type);
this.type = GsonTypes.canonicalize(Objects.requireNonNull(type));
this.rawType = (Class<? super T>) GsonTypes.getRawType(this.type);
this.hashCode = this.type.hashCode();
}

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

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

if (isCapturingTypeVariablesForbidden()) {
verifyNoTypeVariable(typeArgument);
Expand Down Expand Up @@ -193,11 +193,11 @@ public boolean isAssignableFrom(Type from) {
}

if (type instanceof Class<?>) {
return rawType.isAssignableFrom($Gson$Types.getRawType(from));
return rawType.isAssignableFrom(GsonTypes.getRawType(from));
} else if (type instanceof ParameterizedType) {
return isAssignableFrom(from, (ParameterizedType) type, new HashMap<String, Type>());
} else if (type instanceof GenericArrayType) {
return rawType.isAssignableFrom($Gson$Types.getRawType(from))
return rawType.isAssignableFrom(GsonTypes.getRawType(from))
&& isAssignableFrom(from, (GenericArrayType) type);
} else {
throw buildUnsupportedTypeException(
Expand Down Expand Up @@ -253,7 +253,7 @@ private static boolean isAssignableFrom(
}

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

@Override
public final boolean equals(Object o) {
return o instanceof TypeToken<?> && $Gson$Types.equals(type, ((TypeToken<?>) o).type);
return o instanceof TypeToken<?> && GsonTypes.equals(type, ((TypeToken<?>) o).type);
}

@Override
public final String toString() {
return $Gson$Types.typeToString(type);
return GsonTypes.typeToString(type);
}

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

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

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

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

return new TypeToken<>(
$Gson$Types.newParameterizedTypeWithOwner(null, rawClass, typeArguments));
return new TypeToken<>(GsonTypes.newParameterizedTypeWithOwner(null, rawClass, typeArguments));
}

/**
* Gets type literal for the array type whose elements are all instances of {@code componentType}.
*/
public static TypeToken<?> getArray(Type componentType) {
return new TypeToken<>($Gson$Types.arrayOf(componentType));
return new TypeToken<>(GsonTypes.arrayOf(componentType));
}
}
7 changes: 3 additions & 4 deletions gson/src/test/java/com/google/gson/GenericArrayTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.GsonTypes;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;
Expand All @@ -27,7 +27,7 @@
import org.junit.Test;

/**
* Unit tests for the {@code GenericArrayType}s created by the {@link $Gson$Types} class.
* Unit tests for the {@code GenericArrayType}s created by the {@link GsonTypes} class.
*
* @author Inderjeet Singh
* @author Joel Leitch
Expand All @@ -38,8 +38,7 @@ public class GenericArrayTypeTest {
@Before
public void setUp() throws Exception {
ourType =
$Gson$Types.arrayOf(
$Gson$Types.newParameterizedTypeWithOwner(null, List.class, String.class));
GsonTypes.arrayOf(GsonTypes.newParameterizedTypeWithOwner(null, List.class, String.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.gson;

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

Expand Down
Loading