bling bling

Prefix internal classes with $ to prevent them from interfering with IDE's auto import functionality.
This commit is contained in:
Jesse Wilson 2011-03-29 21:24:26 +00:00
parent 5e74dabad9
commit 4efb133b4a
39 changed files with 238 additions and 245 deletions

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@ -53,8 +53,8 @@ final class CamelCaseSeparatorNamingPolicy extends RecursiveFieldNamingPolicy {
* is null or empty.
*/
public CamelCaseSeparatorNamingPolicy(String separatorString) {
Preconditions.checkNotNull(separatorString);
Preconditions.checkArgument(!"".equals(separatorString));
$Preconditions.checkNotNull(separatorString);
$Preconditions.checkArgument(!"".equals(separatorString));
this.separatorString = separatorString;
}

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Cache;
import com.google.gson.internal.LruCache;
import com.google.gson.internal.$Cache;
import com.google.gson.internal.$LruCache;
import java.lang.reflect.Constructor;
@ -30,14 +30,14 @@ class DefaultConstructorAllocator {
private static final Constructor<Null> NULL_CONSTRUCTOR = createNullConstructor();
// Package private for testing purposes.
final Cache<Class<?>, Constructor<?>> constructorCache;
final $Cache<Class<?>, Constructor<?>> constructorCache;
public DefaultConstructorAllocator() {
this(200);
}
public DefaultConstructorAllocator(int cacheSize) {
constructorCache = new LruCache<Class<?>, Constructor<?>>(cacheSize);
constructorCache = new $LruCache<Class<?>, Constructor<?>>(cacheSize);
}
private static final Constructor<Null> createNullConstructor() {

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -615,8 +615,8 @@ final class DefaultTypeAdapters {
JsonArray array = new JsonArray();
Type childGenericType = null;
if (typeOfSrc instanceof ParameterizedType) {
Class<?> rawTypeOfSrc = Types.getRawType(typeOfSrc);
childGenericType = Types.getCollectionElementType(typeOfSrc, rawTypeOfSrc);
Class<?> rawTypeOfSrc = $Types.getRawType(typeOfSrc);
childGenericType = $Types.getCollectionElementType(typeOfSrc, rawTypeOfSrc);
}
for (Object child : src) {
if (child == null) {
@ -639,7 +639,7 @@ final class DefaultTypeAdapters {
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
// This handles cases where users are using their own subclass of Collection.
Collection collection = constructCollectionType(typeOfT, context);
Type childType = Types.getCollectionElementType(typeOfT, Types.getRawType(typeOfT));
Type childType = $Types.getCollectionElementType(typeOfT, $Types.getRawType(typeOfT));
for (JsonElement childElement : json.getAsJsonArray()) {
if (childElement == null || childElement.isJsonNull()) {
collection.add(null);
@ -1027,7 +1027,7 @@ final class DefaultTypeAdapters {
}
public T createInstance(Type type) {
Class<?> rawType = Types.getRawType(type);
Class<?> rawType = $Types.getRawType(type);
try {
T specificInstance = (T) allocator.newInstance(rawType);
return (specificInstance == null)

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.io.IOException;
@ -50,7 +50,7 @@ class DelegatingJsonElementVisitor implements JsonElementVisitor {
private final JsonElementVisitor delegate;
protected DelegatingJsonElementVisitor(JsonElementVisitor delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
this.delegate = $Preconditions.checkNotNull(delegate);
}
public void endArray(JsonArray array) throws IOException {
@ -69,37 +69,37 @@ class DelegatingJsonElementVisitor implements JsonElementVisitor {
delegate.startObject(object);
}
public void visitArrayMember(JsonArray parent, JsonPrimitive member,
public void visitArrayMember(JsonArray parent, JsonPrimitive member,
boolean isFirst) throws IOException {
delegate.visitArrayMember(parent, member, isFirst);
}
public void visitArrayMember(JsonArray parent, JsonArray member,
public void visitArrayMember(JsonArray parent, JsonArray member,
boolean isFirst) throws IOException {
delegate.visitArrayMember(parent, member, isFirst);
}
public void visitArrayMember(JsonArray parent, JsonObject member,
public void visitArrayMember(JsonArray parent, JsonObject member,
boolean isFirst) throws IOException {
delegate.visitArrayMember(parent, member, isFirst);
}
public void visitObjectMember(JsonObject parent, String memberName, JsonPrimitive member,
public void visitObjectMember(JsonObject parent, String memberName, JsonPrimitive member,
boolean isFirst) throws IOException {
delegate.visitObjectMember(parent, memberName, member, isFirst);
}
public void visitObjectMember(JsonObject parent, String memberName, JsonArray member,
public void visitObjectMember(JsonObject parent, String memberName, JsonArray member,
boolean isFirst) throws IOException {
delegate.visitObjectMember(parent, memberName, member, isFirst);
}
public void visitObjectMember(JsonObject parent, String memberName, JsonObject member,
public void visitObjectMember(JsonObject parent, String memberName, JsonObject member,
boolean isFirst) throws IOException {
delegate.visitObjectMember(parent, memberName, member, isFirst);
}
public void visitNullObjectMember(JsonObject parent, String memberName,
public void visitNullObjectMember(JsonObject parent, String memberName,
boolean isFirst) throws IOException {
delegate.visitNullObjectMember(parent, memberName, isFirst);
}

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.util.Collection;
@ -30,7 +30,7 @@ final class DisjunctionExclusionStrategy implements ExclusionStrategy {
private final Collection<ExclusionStrategy> strategies;
DisjunctionExclusionStrategy(Collection<ExclusionStrategy> strategies) {
this.strategies = Preconditions.checkNotNull(strategies);
this.strategies = $Preconditions.checkNotNull(strategies);
}
public boolean shouldSkipField(FieldAttributes f) {

View File

@ -16,10 +16,10 @@
package com.google.gson;
import com.google.gson.internal.Cache;
import com.google.gson.internal.LruCache;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Cache;
import com.google.gson.internal.$LruCache;
import com.google.gson.internal.$Pair;
import com.google.gson.internal.$Preconditions;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
@ -42,8 +42,8 @@ public final class FieldAttributes {
private static final String MAX_CACHE_PROPERTY_NAME =
"com.google.gson.annotation_cache_size_hint";
private static final Cache<Pair<Class<?>, String>, Collection<Annotation>> ANNOTATION_CACHE =
new LruCache<Pair<Class<?>,String>, Collection<Annotation>>(getMaxCacheSize());
private static final $Cache<$Pair<Class<?>, String>, Collection<Annotation>> ANNOTATION_CACHE =
new $LruCache<$Pair<Class<?>,String>, Collection<Annotation>>(getMaxCacheSize());
private final Class<?> declaringClazz;
private final Field field;
@ -62,7 +62,7 @@ public final class FieldAttributes {
* @param f the field to pull attributes from
*/
FieldAttributes(final Class<?> declaringClazz, final Field f) {
this.declaringClazz = Preconditions.checkNotNull(declaringClazz);
this.declaringClazz = $Preconditions.checkNotNull(declaringClazz);
this.name = f.getName();
this.declaredType = f.getType();
this.isSynthetic = f.isSynthetic();
@ -157,7 +157,7 @@ public final class FieldAttributes {
*/
public Collection<Annotation> getAnnotations() {
if (annotations == null) {
Pair<Class<?>, String> key = new Pair<Class<?>, String>(declaringClazz, name);
$Pair<Class<?>, String> key = new $Pair<Class<?>, String>(declaringClazz, name);
annotations = ANNOTATION_CACHE.getElement(key);
if (annotations == null) {
annotations = Collections.unmodifiableCollection(

View File

@ -16,12 +16,12 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
/**
* Adapts the old "deprecated" FieldNamingStrategy to the new {@link FieldNamingStrategy2}
* type.
*
* type.
*
* @author Inderjeet Singh
* @author Joel Leitch
*/
@ -30,7 +30,7 @@ final class FieldNamingStrategy2Adapter implements FieldNamingStrategy2 {
private final FieldNamingStrategy adaptee;
public FieldNamingStrategy2Adapter(FieldNamingStrategy adaptee) {
this.adaptee = Preconditions.checkNotNull(adaptee);
this.adaptee = $Preconditions.checkNotNull(adaptee);
}
public String translateName(FieldAttributes f) {

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.$Primitives;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
@ -388,7 +388,7 @@ public final class Gson {
*/
public <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException {
Object object = fromJson(json, (Type) classOfT);
return Primitives.wrap(classOfT).cast(object);
return $Primitives.wrap(classOfT).cast(object);
}
/**
@ -441,7 +441,7 @@ public final class Gson {
JsonReader jsonReader = new JsonReader(json);
Object object = fromJson(jsonReader, classOfT);
assertFullConsumption(object, jsonReader);
return Primitives.wrap(classOfT).cast(object);
return $Primitives.wrap(classOfT).cast(object);
}
/**
@ -520,7 +520,7 @@ public final class Gson {
*/
public <T> T fromJson(JsonElement json, Class<T> classOfT) throws JsonSyntaxException {
Object object = fromJson(json, (Type) classOfT);
return Primitives.wrap(classOfT).cast(object);
return $Primitives.wrap(classOfT).cast(object);
}
/**
@ -547,7 +547,7 @@ public final class Gson {
return null;
}
JsonDeserializationContext context = new JsonDeserializationContextDefault(
new ObjectNavigator(deserializationExclusionStrategy), fieldNamingPolicy,
new ObjectNavigator(deserializationExclusionStrategy), fieldNamingPolicy,
deserializers, objectConstructor);
T target = (T) context.deserialize(json, typeOfT);
return target;

View File

@ -16,6 +16,7 @@
package com.google.gson;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.Arrays;
@ -27,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import com.google.gson.DefaultTypeAdapters.DefaultDateTypeAdapter;
import com.google.gson.internal.Preconditions;
/**
* <p>Use this builder to construct a {@link Gson} instance when you need to set configuration
@ -186,7 +186,7 @@ public final class GsonBuilder {
this.serializeNulls = true;
return this;
}
/**
* Enabling this feature will only change the serialized form if the map key is
* a complex type (i.e. non-primitive) in its <strong>serialized</strong> JSON
@ -197,9 +197,9 @@ public final class GsonBuilder {
* <h3>Maps as JSON objects</h3>
* For this case, assume that a type adapter is registered to serialize and
* deserialize some {@code Point} class, which contains an x and y coordinate,
* to/from the JSON Primitive string value {@code "(x,y)"}. The Java map would
* to/from the JSON Primitive string value {@code "(x,y)"}. The Java map would
* then be serialized as a {@link JsonObject}.
*
*
* <p>Below is an example:
* <pre> {@code
* Gson gson = new GsonBuilder()
@ -224,10 +224,10 @@ public final class GsonBuilder {
* {@code Point} class, but rather the default Gson serialization is applied.
* In this case, some {@code new Point(2,3)} would serialize as {@code
* {"x":2,"y":5}}.
*
*
* <p>Given the assumption above, a {@code Map<Point, String>} will be
* serialize as an array of arrays (can be viewed as an entry set of pairs).
*
*
* <p>Below is an example of serializing complex types as JSON arrays:
* <pre> {@code
* Gson gson = new GsonBuilder()
@ -239,7 +239,7 @@ public final class GsonBuilder {
* original.put(new Point(8, 8), "b");
* System.out.println(gson.toJson(original, type));
* }
*
*
* The JSON output would look as follows:
* <pre> {@code
* [
@ -259,7 +259,7 @@ public final class GsonBuilder {
* ]
* ]
* }</pre>
*
*
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/
@ -350,7 +350,7 @@ public final class GsonBuilder {
deserializeExclusionStrategies.addAll(strategyList);
return this;
}
/**
* Configures Gson to apply a set of exclusion strategies during either serialization or
* deserialization. Each of the {@code strategies} will be applied as a disjunction rule.
@ -365,8 +365,8 @@ public final class GsonBuilder {
* @since 1.7
*/
public GsonBuilder setExclusionStrategies(Mode mode, ExclusionStrategy... strategies) {
Set<ExclusionStrategy> strategySet =
(Preconditions.checkNotNull(mode) == Mode.SERIALIZE)
Set<ExclusionStrategy> strategySet =
($Preconditions.checkNotNull(mode) == Mode.SERIALIZE)
? serializeExclusionStrategies : deserializeExclusionStrategies;
strategySet.addAll(Arrays.asList(strategies));
return this;
@ -470,8 +470,8 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
if (typeAdapter instanceof InstanceCreator<?>) {
registerInstanceCreator(type, (InstanceCreator<?>) typeAdapter);
}
@ -549,8 +549,8 @@ public final class GsonBuilder {
* @since 1.7
*/
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
if (typeAdapter instanceof InstanceCreator<?>) {
registerInstanceCreatorForTypeHierarchy(baseType, (InstanceCreator<?>) typeAdapter);
}
@ -626,7 +626,7 @@ public final class GsonBuilder {
serializationStrategies.add(innerClassExclusionStrategy);
}
if (ignoreVersionsAfter != VersionConstants.IGNORE_VERSIONS) {
VersionExclusionStrategy versionExclusionStrategy =
VersionExclusionStrategy versionExclusionStrategy =
new VersionExclusionStrategy(ignoreVersionsAfter);
deserializationStrategies.add(versionExclusionStrategy);
serializationStrategies.add(versionExclusionStrategy);

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
@ -42,22 +42,22 @@ final class JsonArrayDeserializationVisitor<T> extends JsonDeserializationVisito
@SuppressWarnings("unchecked")
protected T constructTarget() {
if (!json.isJsonArray()) {
throw new JsonParseException("Expecting array found: " + json);
throw new JsonParseException("Expecting array found: " + json);
}
JsonArray jsonArray = json.getAsJsonArray();
if (Types.isArray(targetType)) {
if ($Types.isArray(targetType)) {
// We know that we are getting back an array of the required type, so
// this typecasting is safe.
return (T) objectConstructor.constructArray(Types.getArrayComponentType(targetType),
return (T) objectConstructor.constructArray($Types.getArrayComponentType(targetType),
jsonArray.size());
}
// is a collection
return (T) objectConstructor.construct(Types.getRawType(targetType));
return (T) objectConstructor.construct($Types.getRawType(targetType));
}
public void visitArray(Object array, Type arrayType) {
if (!json.isJsonArray()) {
throw new JsonParseException("Expecting array found: " + json);
throw new JsonParseException("Expecting array found: " + json);
}
JsonArray jsonArray = json.getAsJsonArray();
for (int i = 0; i < jsonArray.size(); i++) {
@ -67,12 +67,12 @@ final class JsonArrayDeserializationVisitor<T> extends JsonDeserializationVisito
if (jsonChild == null || jsonChild.isJsonNull()) {
child = null;
} else if (jsonChild instanceof JsonObject) {
child = visitChildAsObject(Types.getArrayComponentType(arrayType), jsonChild);
child = visitChildAsObject($Types.getArrayComponentType(arrayType), jsonChild);
} else if (jsonChild instanceof JsonArray) {
child = visitChildAsArray(Types.getArrayComponentType(arrayType),
child = visitChildAsArray($Types.getArrayComponentType(arrayType),
jsonChild.getAsJsonArray());
} else if (jsonChild instanceof JsonPrimitive) {
child = visitChildAsObject(Types.getArrayComponentType(arrayType),
child = visitChildAsObject($Types.getArrayComponentType(arrayType),
jsonChild.getAsJsonPrimitive());
} else {
throw new IllegalStateException();
@ -95,12 +95,12 @@ final class JsonArrayDeserializationVisitor<T> extends JsonDeserializationVisito
}
public void visitObjectField(FieldAttributes f, Type typeOfF, Object obj) {
throw new JsonParseException("Expecting array but found object field " + f.getName() + ": "
throw new JsonParseException("Expecting array but found object field " + f.getName() + ": "
+ obj);
}
public boolean visitFieldUsingCustomHandler(FieldAttributes f, Type actualTypeOfField, Object parent) {
throw new JsonParseException("Expecting array but found field " + f.getName() + ": "
throw new JsonParseException("Expecting array but found field " + f.getName() + ": "
+ parent);
}

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Pair;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.Type;
@ -51,7 +51,7 @@ abstract class JsonDeserializationVisitor<T> implements ObjectNavigator.Visitor
this.fieldNamingPolicy = fieldNamingPolicy;
this.objectConstructor = objectConstructor;
this.deserializers = deserializers;
this.json = Preconditions.checkNotNull(json);
this.json = $Preconditions.checkNotNull(json);
this.context = context;
this.constructed = false;
}
@ -74,18 +74,18 @@ abstract class JsonDeserializationVisitor<T> implements ObjectNavigator.Visitor
@SuppressWarnings("unchecked")
public final boolean visitUsingCustomHandler(ObjectTypePair objTypePair) {
Pair<JsonDeserializer<?>, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers);
$Pair<JsonDeserializer<?>, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers);
if (pair == null) {
return false;
}
}
Object value = invokeCustomDeserializer(json, pair);
target = (T) value;
constructed = true;
return true;
}
protected Object invokeCustomDeserializer(JsonElement element,
Pair<JsonDeserializer<?>, ObjectTypePair> pair) {
protected Object invokeCustomDeserializer(JsonElement element,
$Pair<JsonDeserializer<?>, ObjectTypePair> pair) {
if (element == null || element.isJsonNull()) {
return null;
}

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.Type;
@ -42,7 +42,7 @@ class JsonDeserializerExceptionWrapper<T> implements JsonDeserializer<T> {
* @throws IllegalArgumentException if {@code delegate} is {@code null}.
*/
JsonDeserializerExceptionWrapper(JsonDeserializer<T> delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
this.delegate = $Preconditions.checkNotNull(delegate);
}
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
@ -64,7 +64,7 @@ class JsonDeserializerExceptionWrapper<T> implements JsonDeserializer<T> {
throw new JsonParseException(errorMsg.toString(), e);
}
}
@Override
public String toString() {
return delegate.toString();

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -33,11 +33,11 @@ import java.util.regex.Pattern;
*/
class JsonFieldNameValidator {
private static final String COMMON_PATTERN = "[a-zA-Z][a-zA-Z0-9\\ \\$_\\-]*$";
private static final Pattern JSON_FIELD_NAME_PATTERN =
Pattern.compile("(^" + COMMON_PATTERN + ")|(^[\\$_]" + COMMON_PATTERN + ")");
/**
* Performs validation on the JSON field name to ensure it is a valid field name.
*
@ -46,8 +46,8 @@ class JsonFieldNameValidator {
* @throws IllegalArgumentException if the field name is an invalid JSON field name
*/
public String validate(String fieldName) {
Preconditions.checkNotNull(fieldName);
Preconditions.checkArgument(!"".equals(fieldName.trim()));
$Preconditions.checkNotNull(fieldName);
$Preconditions.checkArgument(!"".equals(fieldName.trim()));
Matcher matcher = JSON_FIELD_NAME_PATTERN.matcher(fieldName);
if (!matcher.matches()) {

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.io.IOException;
import java.util.LinkedHashMap;
@ -57,7 +57,7 @@ public final class JsonObject extends JsonElement {
if (value == null) {
value = JsonNull.createJsonNull();
}
members.put(Preconditions.checkNotNull(property), value);
members.put($Preconditions.checkNotNull(property), value);
}
/**

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.$Pair;
import com.google.gson.internal.$Primitives;
import java.lang.reflect.Type;
@ -56,7 +56,7 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
public void visitObjectField(FieldAttributes f, Type typeOfF, Object obj) {
try {
if (!json.isJsonObject()) {
throw new JsonParseException("Expecting object found: " + json);
throw new JsonParseException("Expecting object found: " + json);
}
JsonObject jsonObject = json.getAsJsonObject();
String fName = getFieldName(f);
@ -75,7 +75,7 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
public void visitArrayField(FieldAttributes f, Type typeOfF, Object obj) {
try {
if (!json.isJsonObject()) {
throw new JsonParseException("Expecting object found: " + json);
throw new JsonParseException("Expecting object found: " + json);
}
JsonObject jsonObject = json.getAsJsonObject();
String fName = getFieldName(f);
@ -99,10 +99,10 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
try {
String fName = getFieldName(f);
if (!json.isJsonObject()) {
throw new JsonParseException("Expecting object found: " + json);
throw new JsonParseException("Expecting object found: " + json);
}
JsonElement child = json.getAsJsonObject().get(fName);
boolean isPrimitive = Primitives.isPrimitive(declaredTypeOfField);
boolean isPrimitive = $Primitives.isPrimitive(declaredTypeOfField);
if (child == null) { // Child will be null if the field wasn't present in Json
return true;
} else if (child.isJsonNull()) {
@ -112,10 +112,10 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
return true;
}
ObjectTypePair objTypePair = new ObjectTypePair(null, declaredTypeOfField, false);
Pair<JsonDeserializer<?>, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers);
$Pair<JsonDeserializer<?>, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers);
if (pair == null) {
return false;
}
}
Object value = invokeCustomDeserializer(child, pair);
if (value != null || !isPrimitive) {
f.set(parent, value);

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.io.IOException;
import java.math.BigDecimal;
@ -94,8 +94,8 @@ public final class JsonPrimitive extends JsonElement {
char c = ((Character) primitive).charValue();
this.value = String.valueOf(c);
} else {
Preconditions.checkArgument(primitive instanceof Number
|| isPrimitiveOrString(primitive));
$Preconditions.checkArgument(primitive instanceof Number
|| isPrimitiveOrString(primitive));
this.value = primitive;
}
}

View File

@ -16,9 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Pair;
import com.google.gson.internal.$Types;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
@ -77,7 +77,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
public void visitArray(Object array, Type arrayType) {
assignToRoot(new JsonArray());
int length = Array.getLength(array);
Type componentType = Types.getArrayComponentType(arrayType);
Type componentType = $Types.getArrayComponentType(arrayType);
for (int i = 0; i < length; ++i) {
Object child = Array.get(array, i);
// we should not get more specific component type yet since it is possible
@ -174,7 +174,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
*/
@SuppressWarnings("unchecked")
private JsonElement findAndInvokeCustomSerializer(ObjectTypePair objTypePair) {
Pair<JsonSerializer<?>,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers);
$Pair<JsonSerializer<?>,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers);
if (pair == null) {
return null;
}
@ -193,7 +193,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
public boolean visitFieldUsingCustomHandler(
FieldAttributes f, Type declaredTypeOfField, Object parent) {
try {
Preconditions.checkState(root.isJsonObject());
$Preconditions.checkState(root.isJsonObject());
Object obj = f.get(parent);
if (obj == null) {
if (serializeNulls) {
@ -216,7 +216,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
}
private void assignToRoot(JsonElement newRoot) {
root = Preconditions.checkNotNull(newRoot);
root = $Preconditions.checkNotNull(newRoot);
}
private boolean isFieldNull(FieldAttributes f, Object obj) {

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -37,8 +37,8 @@ final class MapTypeAdapter implements JsonSerializer<Map<?, ?>>,
JsonObject map = new JsonObject();
Type childGenericType = null;
if (typeOfSrc instanceof ParameterizedType) {
Class<?> rawTypeOfSrc = Types.getRawType(typeOfSrc);
childGenericType = Types.getMapKeyAndValueTypes(typeOfSrc, rawTypeOfSrc)[1];
Class<?> rawTypeOfSrc = $Types.getRawType(typeOfSrc);
childGenericType = $Types.getMapKeyAndValueTypes(typeOfSrc, rawTypeOfSrc)[1];
}
for (Map.Entry entry : (Set<Map.Entry>) src.entrySet()) {
@ -62,7 +62,7 @@ final class MapTypeAdapter implements JsonSerializer<Map<?, ?>>,
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
// This handles cases where users are using their own subclass of Map.
Map<Object, Object> map = constructMapType(typeOfT, context);
Type[] keyAndValueTypes = Types.getMapKeyAndValueTypes(typeOfT, Types.getRawType(typeOfT));
Type[] keyAndValueTypes = $Types.getMapKeyAndValueTypes(typeOfT, $Types.getRawType(typeOfT));
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
Object key = context.deserialize(new JsonPrimitive(entry.getKey()), keyAndValueTypes[0]);
Object value = context.deserialize(entry.getValue(), keyAndValueTypes[1]);

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.UnsafeAllocator;
import com.google.gson.internal.$Types;
import com.google.gson.internal.$UnsafeAllocator;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
@ -33,7 +33,7 @@ import java.lang.reflect.Type;
* @author Joel Leitch
*/
final class MappedObjectConstructor implements ObjectConstructor {
private static final UnsafeAllocator unsafeAllocator = UnsafeAllocator.create();
private static final $UnsafeAllocator unsafeAllocator = $UnsafeAllocator.create();
private static final DefaultConstructorAllocator defaultConstructorAllocator =
new DefaultConstructorAllocator(500);
@ -54,13 +54,13 @@ final class MappedObjectConstructor implements ObjectConstructor {
}
public Object constructArray(Type type, int length) {
return Array.newInstance(Types.getRawType(type), length);
return Array.newInstance($Types.getRawType(type), length);
}
@SuppressWarnings({"unchecked", "cast"})
private <T> T constructWithAllocators(Type typeOfT) {
try {
Class<T> clazz = (Class<T>) Types.getRawType(typeOfT);
Class<T> clazz = (Class<T>) $Types.getRawType(typeOfT);
T obj = defaultConstructorAllocator.newInstance(clazz);
return (obj == null)
? unsafeAllocator.newInstance(clazz)

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.util.Stack;
@ -37,7 +37,7 @@ final class MemoryRefStack {
* @return the object that was added
*/
public ObjectTypePair push(ObjectTypePair obj) {
Preconditions.checkNotNull(obj);
$Preconditions.checkNotNull(obj);
return stack.push(obj);
}

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@ -65,7 +65,7 @@ final class ModifyFirstLetterNamingPolicy extends RecursiveFieldNamingPolicy {
* @throws IllegalArgumentException if {@code modifier} is null
*/
ModifyFirstLetterNamingPolicy(LetterModifier modifier) {
this.letterModifier = Preconditions.checkNotNull(modifier);
this.letterModifier = $Preconditions.checkNotNull(modifier);
}
@Override

View File

@ -16,15 +16,15 @@
package com.google.gson;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import com.google.gson.internal.$Primitives;
import java.lang.reflect.Type;
/**
* Provides ability to apply a visitor to an object and all of its fields
* recursively.
*
*
* @author Inderjeet Singh
* @author Joel Leitch
*/
@ -58,7 +58,7 @@ final class ObjectNavigator {
/**
* This is called to visit an object using a custom handler
*
*
* @return true if a custom handler exists, false otherwise
*/
public boolean visitUsingCustomHandler(ObjectTypePair objTypePair);
@ -71,7 +71,7 @@ final class ObjectNavigator {
Object parent);
void visitPrimitive(Object primitive);
/**
* Retrieve the current target
*/
@ -96,7 +96,7 @@ final class ObjectNavigator {
* @param objTypePair The object,type (fully genericized) being navigated
*/
public void accept(ObjectTypePair objTypePair, Visitor visitor) {
if (exclusionStrategy.shouldSkipClass(Types.getRawType(objTypePair.type))) {
if (exclusionStrategy.shouldSkipClass($Types.getRawType(objTypePair.type))) {
return;
}
boolean visitedWithCustomHandler = visitor.visitUsingCustomHandler(objTypePair);
@ -109,7 +109,7 @@ final class ObjectNavigator {
objTypePair.setObject(objectToVisit);
visitor.start(objTypePair);
try {
if (Types.isArray(objTypePair.type)) {
if ($Types.isArray(objTypePair.type)) {
visitor.visitArray(objectToVisit, objTypePair.type);
} else if (objTypePair.type == Object.class && isPrimitiveOrString(objectToVisit)) {
// TODO(Joel): this is only used for deserialization of "primitives"
@ -129,6 +129,6 @@ final class ObjectNavigator {
private static boolean isPrimitiveOrString(Object objectToVisit) {
Class<?> realClazz = objectToVisit.getClass();
return realClazz == Object.class || realClazz == String.class
|| Primitives.unwrap(realClazz).isPrimitive();
|| $Primitives.unwrap(realClazz).isPrimitive();
}
}

View File

@ -15,7 +15,7 @@
*/
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.$Pair;
import java.lang.reflect.Type;
@ -52,23 +52,23 @@ final class ObjectTypePair {
return String.format("preserveType: %b, type: %s, obj: %s", preserveType, type, obj);
}
<HANDLER> Pair<HANDLER, ObjectTypePair> getMatchingHandler(
<HANDLER> $Pair<HANDLER, ObjectTypePair> getMatchingHandler(
ParameterizedTypeHandlerMap<HANDLER> handlers) {
HANDLER handler = null;
if (!preserveType && obj != null) {
// First try looking up the handler for the actual type
ObjectTypePair moreSpecificType = toMoreSpecificType();
ObjectTypePair moreSpecificType = toMoreSpecificType();
handler = handlers.getHandlerFor(moreSpecificType.type);
if (handler != null) {
return new Pair<HANDLER, ObjectTypePair>(handler, moreSpecificType);
return new $Pair<HANDLER, ObjectTypePair>(handler, moreSpecificType);
}
}
// Try the specified type
handler = handlers.getHandlerFor(type);
return handler == null ? null : new Pair<HANDLER, ObjectTypePair>(handler, this);
return handler == null ? null : new $Pair<HANDLER, ObjectTypePair>(handler, this);
}
ObjectTypePair toMoreSpecificType() {
ObjectTypePair toMoreSpecificType() {
if (preserveType || obj == null) {
return this;
}
@ -79,7 +79,7 @@ final class ObjectTypePair {
return new ObjectTypePair(obj, actualType, preserveType);
}
Type getMoreSpecificType() {
Type getMoreSpecificType() {
if (preserveType || obj == null) {
return type;
}
@ -88,7 +88,7 @@ final class ObjectTypePair {
// This takes care of situations where the field was declared as an Object, but the
// actual value contains something more specific. See Issue 54.
// TODO (inder): This solution will not work if the field is of a generic type, but
// TODO (inder): This solution will not work if the field is of a generic type, but
// the actual object is of a raw type (which is a sub-class of the generic type).
static Type getActualTypeIfMoreSpecific(Type type, Class<?> actualClass) {
if (type instanceof Class<?>) {
@ -98,7 +98,7 @@ final class ObjectTypePair {
}
if (type == Object.class) {
type = actualClass;
}
}
}
return type;
}

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Pair;
import com.google.gson.internal.$Types;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -30,25 +30,25 @@ import java.util.logging.Logger;
/**
* A map that provides ability to associate handlers for a specific type or all
* of its sub-types
*
*
* @author Inderjeet Singh
* @author Joel Leitch
*
*
* @param <T> The handler that will be looked up by type
*/
final class ParameterizedTypeHandlerMap<T> {
private static final Logger logger =
Logger.getLogger(ParameterizedTypeHandlerMap.class.getName());
private final Map<Type, T> map = new HashMap<Type, T>();
private final List<Pair<Class<?>, T>> typeHierarchyList = new ArrayList<Pair<Class<?>, T>>();
private final List<$Pair<Class<?>, T>> typeHierarchyList = new ArrayList<$Pair<Class<?>, T>>();
private boolean modifiable = true;
public synchronized void registerForTypeHierarchy(Class<?> typeOfT, T value) {
Pair<Class<?>, T> pair = new Pair<Class<?>, T>(typeOfT, value);
$Pair<Class<?>, T> pair = new $Pair<Class<?>, T>(typeOfT, value);
registerForTypeHierarchy(pair);
}
public synchronized void registerForTypeHierarchy(Pair<Class<?>, T> pair) {
public synchronized void registerForTypeHierarchy($Pair<Class<?>, T> pair) {
if (!modifiable) {
throw new IllegalStateException("Attempted to modify an unmodifiable map.");
}
@ -70,7 +70,7 @@ final class ParameterizedTypeHandlerMap<T> {
private int getIndexOfAnOverriddenHandler(Class<?> type) {
for (int i = typeHierarchyList.size()-1; i >= 0; --i) {
Pair<Class<?>, T> entry = typeHierarchyList.get(i);
$Pair<Class<?>, T> entry = typeHierarchyList.get(i);
if (type.isAssignableFrom(entry.first)) {
return i;
}
@ -100,7 +100,7 @@ final class ParameterizedTypeHandlerMap<T> {
// Quite important to traverse the typeHierarchyList from stack bottom first since
// we want to register the handlers in the same order to preserve priority order
for (int i = other.typeHierarchyList.size()-1; i >= 0; --i) {
Pair<Class<?>, T> entry = other.typeHierarchyList.get(i);
$Pair<Class<?>, T> entry = other.typeHierarchyList.get(i);
int index = getIndexOfSpecificHandlerForTypeHierarchy(entry.first);
if (index < 0) {
registerForTypeHierarchy(entry);
@ -118,7 +118,7 @@ final class ParameterizedTypeHandlerMap<T> {
// Quite important to traverse the typeHierarchyList from stack bottom first since
// we want to register the handlers in the same order to preserve priority order
for (int i = other.typeHierarchyList.size()-1; i >= 0; --i) {
Pair<Class<?>, T> entry = other.typeHierarchyList.get(i);
$Pair<Class<?>, T> entry = other.typeHierarchyList.get(i);
registerForTypeHierarchy(entry);
}
}
@ -139,7 +139,7 @@ final class ParameterizedTypeHandlerMap<T> {
public synchronized T getHandlerFor(Type type) {
T handler = map.get(type);
if (handler == null) {
Class<?> rawClass = Types.getRawType(type);
Class<?> rawClass = $Types.getRawType(type);
if (rawClass != type) {
handler = getHandlerFor(rawClass);
}
@ -152,7 +152,7 @@ final class ParameterizedTypeHandlerMap<T> {
}
private T getHandlerForTypeHierarchy(Class<?> type) {
for (Pair<Class<?>, T> entry : typeHierarchyList) {
for ($Pair<Class<?>, T> entry : typeHierarchyList) {
if (entry.first.isAssignableFrom(type)) {
return entry.second;
}
@ -186,7 +186,7 @@ final class ParameterizedTypeHandlerMap<T> {
public String toString() {
StringBuilder sb = new StringBuilder("{mapForTypeHierarchy:{");
boolean first = true;
for (Pair<Class<?>, T> entry : typeHierarchyList) {
for ($Pair<Class<?>, T> entry : typeHierarchyList) {
if (first) {
first = false;
} else {
@ -211,6 +211,6 @@ final class ParameterizedTypeHandlerMap<T> {
}
private String typeToString(Type type) {
return Types.getRawType(type).getSimpleName();
return $Types.getRawType(type).getSimpleName();
}
}

View File

@ -16,9 +16,9 @@
package com.google.gson;
import com.google.gson.ObjectNavigator.Visitor;
import com.google.gson.internal.LruCache;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.Types;
import com.google.gson.internal.$LruCache;
import com.google.gson.internal.$Types;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
@ -28,16 +28,16 @@ import java.util.List;
/**
* Visits each of the fields of the specified class using reflection
*
*
* @author Inderjeet Singh
* @author Joel Leitch
* @author Jesse Wilson
*/
final class ReflectingFieldNavigator {
private static final LruCache<Type, List<Class<?>>> classCache =
new LruCache<Type, List<Class<?>>>(500);
private static final LruCache<Class<?>, Field[]> fieldsCache =
new LruCache<Class<?>, Field[]>(500);
private static final $LruCache<Type, List<Class<?>>> classCache =
new $LruCache<Type, List<Class<?>>>(500);
private static final $LruCache<Class<?>, Field[]> fieldsCache =
new $LruCache<Class<?>, Field[]>(500);
private final ExclusionStrategy exclusionStrategy;
@ -46,7 +46,7 @@ final class ReflectingFieldNavigator {
* object.
*/
ReflectingFieldNavigator(ExclusionStrategy exclusionStrategy) {
this.exclusionStrategy = Preconditions.checkNotNull(exclusionStrategy);
this.exclusionStrategy = $Preconditions.checkNotNull(exclusionStrategy);
}
/**
@ -60,13 +60,13 @@ final class ReflectingFieldNavigator {
}
/**
* Returns a list of classes corresponding to the inheritance of specified type
* Returns a list of classes corresponding to the inheritance of specified type
*/
private List<Class<?>> getInheritanceHierarchy(Type type) {
List<Class<?>> classes = classCache.get(type);
if (classes == null) {
classes = new ArrayList<Class<?>>();
Class<?> topLevelClass = Types.getRawType(type);
Class<?> topLevelClass = $Types.getRawType(type);
for (Class<?> curr = topLevelClass; curr != null && !curr.equals(Object.class); curr =
curr.getSuperclass()) {
if (!curr.isSynthetic()) {
@ -91,7 +91,7 @@ final class ReflectingFieldNavigator {
boolean visitedWithCustomHandler =
visitor.visitFieldUsingCustomHandler(fieldAttributes, declaredTypeOfField, obj);
if (!visitedWithCustomHandler) {
if (Types.isArray(declaredTypeOfField)) {
if ($Types.isArray(declaredTypeOfField)) {
visitor.visitArrayField(fieldAttributes, declaredTypeOfField, obj);
} else {
visitor.visitObjectField(fieldAttributes, declaredTypeOfField, obj);
@ -120,11 +120,11 @@ final class ReflectingFieldNavigator {
* @return the type information for the field
*/
public static Type getTypeInfoForField(Field f, Type typeDefiningF) {
Class<?> rawType = Types.getRawType(typeDefiningF);
Class<?> rawType = $Types.getRawType(typeDefiningF);
if (!f.getDeclaringClass().isAssignableFrom(rawType)) {
// this field is unrelated to the type; the user probably omitted type information
return f.getGenericType();
}
return Types.resolve(typeDefiningF, rawType, f.getGenericType());
return $Types.resolve(typeDefiningF, rawType, f.getGenericType());
}
}

View File

@ -18,7 +18,7 @@ package com.google.gson;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.$Preconditions;
/**
* This strategy will exclude any files and/or class that are passed the
@ -30,7 +30,7 @@ final class VersionExclusionStrategy implements ExclusionStrategy {
private final double version;
VersionExclusionStrategy(double version) {
Preconditions.checkArgument(version >= 0.0D);
$Preconditions.checkArgument(version >= 0.0D);
this.version = version;
}

View File

@ -18,11 +18,11 @@ package com.google.gson.internal;
/**
* Defines generic cache interface.
*
*
* @author Inderjeet Singh
* @author Joel Leitch
*/
public interface Cache<K, V> {
public interface $Cache<K, V> {
/**
* Adds the new value object into the cache for the given key. If the key already
@ -40,10 +40,10 @@ public interface Cache<K, V> {
* @return the cached value for the given {@code key}
*/
V getElement(K key);
/**
* Removes the value from the cache for the given key.
*
*
* @param key the key identifying the value to remove
* @return the value for the given {@code key}
*/

View File

@ -21,19 +21,19 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* An implementation of the {@link Cache} interface that evict objects from the cache using an
* An implementation of the {@link $Cache} interface that evict objects from the cache using an
* LRU (least recently used) algorithm. Object start getting evicted from the cache once the
* {@code maxCapacity} is reached.
*
*
* @author Inderjeet Singh
* @author Joel Leitch
*/
public final class LruCache<K, V> extends LinkedHashMap<K, V> implements Cache<K, V> {
public final class $LruCache<K, V> extends LinkedHashMap<K, V> implements $Cache<K, V> {
private static final long serialVersionUID = 1L;
private final int maxCapacity;
public LruCache(int maxCapacity) {
public $LruCache(int maxCapacity) {
super(maxCapacity, 0.7F, true);
this.maxCapacity = maxCapacity;
}

View File

@ -25,11 +25,11 @@ package com.google.gson.internal;
* @param <FIRST>
* @param <SECOND>
*/
public final class Pair<FIRST, SECOND> {
public final class $Pair<FIRST, SECOND> {
public final FIRST first;
public final SECOND second;
public Pair(FIRST first, SECOND second) {
public $Pair(FIRST first, SECOND second) {
this.first = first;
this.second = second;
}
@ -42,11 +42,11 @@ public final class Pair<FIRST, SECOND> {
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair<?, ?>)) {
if (!(o instanceof $Pair<?, ?>)) {
return false;
}
Pair<?, ?> that = (Pair<?, ?>) o;
$Pair<?, ?> that = ($Pair<?, ?>) o;
return equal(this.first, that.first) && equal(this.second, that.second);
}

View File

@ -29,7 +29,7 @@ package com.google.gson.internal;
* @author Inderjeet Singh
* @author Joel Leitch
*/
public final class Preconditions {
public final class $Preconditions {
public static <T> T checkNotNull(T obj) {
if (obj == null) {
throw new NullPointerException();
@ -42,7 +42,7 @@ public final class Preconditions {
throw new IllegalArgumentException();
}
}
public static void checkState(boolean condition) {
if (!condition) {
throw new IllegalStateException();

View File

@ -28,8 +28,8 @@ import java.util.Map;
*
* @author Kevin Bourrillion
*/
public final class Primitives {
private Primitives() {}
public final class $Primitives {
private $Primitives() {}
/** A map from primitive types to their corresponding wrapper types. */
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
@ -38,7 +38,7 @@ public final class Primitives {
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
// Sad that we can't use a BiMap. :(
static {
Map<Class<?>, Class<?>> primToWrap = new HashMap<Class<?>, Class<?>>(16);
Map<Class<?>, Class<?>> wrapToPrim = new HashMap<Class<?>, Class<?>>(16);
@ -78,7 +78,7 @@ public final class Primitives {
*/
public static boolean isWrapperType(Class<?> type) {
return WRAPPER_TO_PRIMITIVE_TYPE.containsKey(
Preconditions.checkNotNull(type));
$Preconditions.checkNotNull(type));
}
/**
@ -94,7 +94,7 @@ public final class Primitives {
// cast is safe: long.class and Long.class are both of type Class<Long>
@SuppressWarnings("unchecked")
Class<T> wrapped = (Class<T>) PRIMITIVE_TO_WRAPPER_TYPE.get(
Preconditions.checkNotNull(type));
$Preconditions.checkNotNull(type));
return (wrapped == null) ? type : wrapped;
}
@ -111,7 +111,7 @@ public final class Primitives {
// cast is safe: long.class and Long.class are both of type Class<Long>
@SuppressWarnings("unchecked")
Class<T> unwrapped = (Class<T>) WRAPPER_TO_PRIMITIVE_TYPE.get(
Preconditions.checkNotNull(type));
$Preconditions.checkNotNull(type));
return (unwrapped == null) ? type : unwrapped;
}
}
}

View File

@ -16,8 +16,8 @@
package com.google.gson.internal;
import static com.google.gson.internal.Preconditions.checkArgument;
import static com.google.gson.internal.Preconditions.checkNotNull;
import static com.google.gson.internal.$Preconditions.checkArgument;
import static com.google.gson.internal.$Preconditions.checkNotNull;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
@ -38,10 +38,10 @@ import java.util.Properties;
* @author Bob Lee
* @author Jesse Wilson
*/
public final class Types {
public final class $Types {
static final Type[] EMPTY_TYPE_ARRAY = new Type[] {};
private Types() {}
private $Types() {}
/**
* Returns a new parameterized type, applying {@code typeArguments} to
@ -269,7 +269,7 @@ public final class Types {
static Type getSupertype(Type context, Class<?> contextRawType, Class<?> supertype) {
checkArgument(supertype.isAssignableFrom(contextRawType));
return resolve(context, contextRawType,
Types.getGenericSupertype(context, contextRawType, supertype));
$Types.getGenericSupertype(context, contextRawType, supertype));
}
/**
@ -473,7 +473,7 @@ public final class Types {
@Override public boolean equals(Object other) {
return other instanceof ParameterizedType
&& Types.equals(this, (ParameterizedType) other);
&& $Types.equals(this, (ParameterizedType) other);
}
@Override public int hashCode() {
@ -513,7 +513,7 @@ public final class Types {
@Override public boolean equals(Object o) {
return o instanceof GenericArrayType
&& Types.equals(this, (GenericArrayType) o);
&& $Types.equals(this, (GenericArrayType) o);
}
@Override public int hashCode() {
@ -565,7 +565,7 @@ public final class Types {
@Override public boolean equals(Object other) {
return other instanceof WildcardType
&& Types.equals(this, (WildcardType) other);
&& $Types.equals(this, (WildcardType) other);
}
@Override public int hashCode() {

View File

@ -27,10 +27,10 @@ import java.lang.reflect.Method;
* @author Joel Leitch
* @author Jesse Wilson
*/
public abstract class UnsafeAllocator {
public abstract class $UnsafeAllocator {
public abstract <T> T newInstance(Class<T> c) throws Exception;
public static UnsafeAllocator create() {
public static $UnsafeAllocator create() {
// try JVM
// public class Unsafe {
// public Object allocateInstance(Class<?> type);
@ -41,7 +41,7 @@ public abstract class UnsafeAllocator {
f.setAccessible(true);
final Object unsafe = f.get(null);
final Method allocateInstance = unsafeClass.getMethod("allocateInstance", Class.class);
return new UnsafeAllocator() {
return new $UnsafeAllocator() {
@Override
@SuppressWarnings("unchecked")
public <T> T newInstance(Class<T> c) throws Exception {
@ -60,7 +60,7 @@ public abstract class UnsafeAllocator {
final Method newInstance = ObjectInputStream.class
.getDeclaredMethod("newInstance", Class.class, Class.class);
newInstance.setAccessible(true);
return new UnsafeAllocator() {
return new $UnsafeAllocator() {
@Override
@SuppressWarnings("unchecked")
public <T> T newInstance(Class<T> c) throws Exception {
@ -83,7 +83,7 @@ public abstract class UnsafeAllocator {
final Method newInstance = ObjectStreamClass.class
.getDeclaredMethod("newInstance", Class.class, int.class);
newInstance.setAccessible(true);
return new UnsafeAllocator() {
return new $UnsafeAllocator() {
@Override
@SuppressWarnings("unchecked")
public <T> T newInstance(Class<T> c) throws Exception {
@ -94,7 +94,7 @@ public abstract class UnsafeAllocator {
}
// give up
return new UnsafeAllocator() {
return new $UnsafeAllocator() {
@Override
public <T> T newInstance(Class<T> c) {
throw new UnsupportedOperationException("Cannot allocate " + c);

View File

@ -16,11 +16,9 @@
package com.google.gson.reflect;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import com.google.gson.internal.$Preconditions;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@ -41,9 +39,6 @@ import java.util.Map;
*
* <p>This syntax cannot be used to create type literals that have wildcard
* parameters, such as {@code Class<?>} or {@code List<? extends CharSequence>}.
* Such type tokens must be constructed programatically, either by {@link
* Method#getGenericReturnType extracting types from members} or by using the
* {@link Types} factory class.
*
* @author Bob Lee
* @author Sven Mawson
@ -66,7 +61,7 @@ public class TypeToken<T> {
@SuppressWarnings("unchecked")
protected TypeToken() {
this.type = getSuperclassTypeParameter(getClass());
this.rawType = (Class<? super T>) Types.getRawType(type);
this.rawType = (Class<? super T>) $Types.getRawType(type);
this.hashCode = type.hashCode();
}
@ -75,13 +70,13 @@ public class TypeToken<T> {
*/
@SuppressWarnings("unchecked")
TypeToken(Type type) {
this.type = Types.canonicalize(Preconditions.checkNotNull(type));
this.rawType = (Class<? super T>) Types.getRawType(this.type);
this.type = $Types.canonicalize($Preconditions.checkNotNull(type));
this.rawType = (Class<? super T>) $Types.getRawType(this.type);
this.hashCode = this.type.hashCode();
}
/**
* Returns the type from super class's type parameter in {@link Types#canonicalize(java.lang.reflect.Type)
* Returns the type from super class's type parameter in {@link $Types#canonicalize
* canonical form}.
*/
@SuppressWarnings("unchecked")
@ -91,7 +86,7 @@ public class TypeToken<T> {
throw new RuntimeException("Missing type parameter.");
}
ParameterizedType parameterized = (ParameterizedType) superclass;
return Types.canonicalize(parameterized.getActualTypeArguments()[0]);
return $Types.canonicalize(parameterized.getActualTypeArguments()[0]);
}
/**
@ -136,12 +131,12 @@ public class TypeToken<T> {
}
if (type instanceof Class<?>) {
return rawType.isAssignableFrom(Types.getRawType(from));
return rawType.isAssignableFrom($Types.getRawType(from));
} else if (type instanceof ParameterizedType) {
return isAssignableFrom(from, (ParameterizedType) type,
new HashMap<String, Type>());
} else if (type instanceof GenericArrayType) {
return rawType.isAssignableFrom(Types.getRawType(from))
return rawType.isAssignableFrom($Types.getRawType(from))
&& isAssignableFrom(from, (GenericArrayType) type);
} else {
throw buildUnexpectedTypeError(
@ -201,7 +196,7 @@ public class TypeToken<T> {
}
// First figure out the class and any type information.
Class<?> clazz = Types.getRawType(from);
Class<?> clazz = $Types.getRawType(from);
ParameterizedType ptype = null;
if (from instanceof ParameterizedType) {
ptype = (ParameterizedType) from;
@ -290,11 +285,11 @@ public class TypeToken<T> {
@Override public final boolean equals(Object o) {
return o instanceof TypeToken<?>
&& Types.equals(type, ((TypeToken<?>) o).type);
&& $Types.equals(type, ((TypeToken<?>) o).type);
}
@Override public final String toString() {
return Types.typeToString(type);
return $Types.typeToString(type);
}
/**

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import com.google.gson.reflect.TypeToken;
import junit.framework.TestCase;
@ -26,7 +26,7 @@ import java.lang.reflect.Type;
import java.util.List;
/**
* Unit tests for the {@code GenericArrayType}s created by the {@link Types} class.
* Unit tests for the {@code GenericArrayType}s created by the {@link $Types} class.
*
* @author Inderjeet Singh
* @author Joel Leitch
@ -37,13 +37,13 @@ public class GenericArrayTypeTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
ourType = Types.arrayOf(Types.newParameterizedTypeWithOwner(null, List.class, String.class));
ourType = $Types.arrayOf($Types.newParameterizedTypeWithOwner(null, List.class, String.class));
}
public void testOurTypeFunctionality() throws Exception {
Type parameterizedType = new TypeToken<List<String>>() {}.getType();
Type genericArrayType = new TypeToken<List<String>[]>() {}.getType();
assertEquals(parameterizedType, ourType.getGenericComponentType());
assertEquals(genericArrayType, ourType);
assertEquals(genericArrayType.hashCode(), ourType.hashCode());

View File

@ -16,13 +16,13 @@
package com.google.gson;
import com.google.gson.internal.Cache;
import com.google.gson.internal.LruCache;
import com.google.gson.internal.$Cache;
import com.google.gson.internal.$LruCache;
import junit.framework.TestCase;
/**
* Unit test for the {@link LruCache} class.
* Unit test for the {@link $LruCache} class.
*
* @author Inderjeet Singh
* @author Joel Leitch
@ -30,33 +30,33 @@ import junit.framework.TestCase;
public class LruCacheTest extends TestCase {
public void testCacheHitAndMiss() throws Exception {
Cache<String, Integer> cache = new LruCache<String, Integer>(3);
$Cache<String, Integer> cache = new $LruCache<String, Integer>(3);
String key = "key1";
assertNull(cache.getElement(key));
cache.addElement(key, 1);
assertEquals(1, cache.getElement(key).intValue());
String key2 = "key2";
cache.addElement(key2, 2);
assertEquals(1, cache.getElement(key).intValue());
assertEquals(2, cache.getElement(key2).intValue());
}
public void testCacheKeyOverwrite() throws Exception {
Cache<String, Integer> cache = new LruCache<String, Integer>(3);
$Cache<String, Integer> cache = new $LruCache<String, Integer>(3);
String key = "key1";
assertNull(cache.getElement(key));
cache.addElement(key, 1);
assertEquals(1, cache.getElement(key).intValue());
cache.addElement(key, 5);
assertEquals(5, cache.getElement(key).intValue());
}
public void testCacheEviction() throws Exception {
Cache<String, Integer> cache = new LruCache<String, Integer>(5);
$Cache<String, Integer> cache = new $LruCache<String, Integer>(5);
cache.addElement("key1", 1);
cache.addElement("key2", 2);

View File

@ -16,7 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Types;
import com.google.gson.reflect.TypeToken;
import junit.framework.TestCase;
@ -26,7 +26,7 @@ import java.lang.reflect.Type;
import java.util.List;
/**
* Unit tests for {@code ParamterizedType}s created by the {@link Types} class.
* Unit tests for {@code ParamterizedType}s created by the {@link $Types} class.
*
* @author Inderjeet Singh
* @author Joel Leitch
@ -37,7 +37,7 @@ public class ParameterizedTypeTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
ourType = Types.newParameterizedTypeWithOwner(null, List.class, String.class);
ourType = $Types.newParameterizedTypeWithOwner(null, List.class, String.class);
}
public void testOurTypeFunctionality() throws Exception {

View File

@ -16,8 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Types;
import com.google.gson.internal.$Primitives;
import com.google.gson.internal.$Types;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -51,7 +51,7 @@ public class ParamterizedTypeFixtures {
private String getExpectedJson(Object obj) {
Class<?> clazz = obj.getClass();
if (Primitives.isWrapperType(Primitives.wrap(clazz))) {
if ($Primitives.isWrapperType($Primitives.wrap(clazz))) {
return obj.toString();
} else if (obj.getClass().equals(String.class)) {
return "\"" + obj.toString() + "\"";
@ -127,7 +127,7 @@ public class ParamterizedTypeFixtures {
@SuppressWarnings("unchecked")
public static<T> String getExpectedJson(MyParameterizedType<T> obj) {
Class<T> clazz = (Class<T>) obj.value.getClass();
boolean addQuotes = !clazz.isArray() && !Primitives.unwrap(clazz).isPrimitive();
boolean addQuotes = !clazz.isArray() && !$Primitives.unwrap(clazz).isPrimitive();
StringBuilder sb = new StringBuilder("{\"");
sb.append(obj.value.getClass().getSimpleName()).append("\":");
if (addQuotes) {
@ -153,10 +153,10 @@ public class ParamterizedTypeFixtures {
public MyParameterizedType<T> deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
Class<?> rawType = Types.getRawType(genericClass);
Class<?> rawType = $Types.getRawType(genericClass);
String className = rawType.getSimpleName();
T value = (T) json.getAsJsonObject().get(className).getAsObject();
if (Primitives.isPrimitive(genericClass)) {
if ($Primitives.isPrimitive(genericClass)) {
PrimitiveTypeAdapter typeAdapter = new PrimitiveTypeAdapter();
value = (T) typeAdapter.adaptType(value, rawType);
}

View File

@ -16,25 +16,23 @@
package com.google.gson;
import com.google.gson.internal.$Primitives;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.google.gson.JsonParseException;
import com.google.gson.internal.Primitives;
/**
* Handles type conversion from some object to some primitive (or primitive
* wrapper instance).
*
*
* @author Joel Leitch
*/
final class PrimitiveTypeAdapter {
@SuppressWarnings("unchecked")
public <T> T adaptType(Object from, Class<T> to) {
Class<?> aClass = Primitives.wrap(to);
if (Primitives.isWrapperType(aClass)) {
Class<?> aClass = $Primitives.wrap(to);
if ($Primitives.isWrapperType(aClass)) {
if (aClass == Character.class) {
String value = from.toString();
if (value.length() == 1) {