diff --git a/gson/src/main/java/com/google/gson/CamelCaseSeparatorNamingPolicy.java b/gson/src/main/java/com/google/gson/CamelCaseSeparatorNamingPolicy.java index 23b4f00e..fd114a91 100644 --- a/gson/src/main/java/com/google/gson/CamelCaseSeparatorNamingPolicy.java +++ b/gson/src/main/java/com/google/gson/CamelCaseSeparatorNamingPolicy.java @@ -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; } diff --git a/gson/src/main/java/com/google/gson/DefaultConstructorAllocator.java b/gson/src/main/java/com/google/gson/DefaultConstructorAllocator.java index 2774c389..dacb4d19 100644 --- a/gson/src/main/java/com/google/gson/DefaultConstructorAllocator.java +++ b/gson/src/main/java/com/google/gson/DefaultConstructorAllocator.java @@ -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_CONSTRUCTOR = createNullConstructor(); // Package private for testing purposes. - final Cache, Constructor> constructorCache; + final $Cache, Constructor> constructorCache; public DefaultConstructorAllocator() { this(200); } public DefaultConstructorAllocator(int cacheSize) { - constructorCache = new LruCache, Constructor>(cacheSize); + constructorCache = new $LruCache, Constructor>(cacheSize); } private static final Constructor createNullConstructor() { diff --git a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java index 02649363..703e4802 100644 --- a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java +++ b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java @@ -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) diff --git a/gson/src/main/java/com/google/gson/DelegatingJsonElementVisitor.java b/gson/src/main/java/com/google/gson/DelegatingJsonElementVisitor.java index fd9bf057..34b21ec0 100644 --- a/gson/src/main/java/com/google/gson/DelegatingJsonElementVisitor.java +++ b/gson/src/main/java/com/google/gson/DelegatingJsonElementVisitor.java @@ -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); } diff --git a/gson/src/main/java/com/google/gson/DisjunctionExclusionStrategy.java b/gson/src/main/java/com/google/gson/DisjunctionExclusionStrategy.java index d2058c2c..d4edb9d8 100644 --- a/gson/src/main/java/com/google/gson/DisjunctionExclusionStrategy.java +++ b/gson/src/main/java/com/google/gson/DisjunctionExclusionStrategy.java @@ -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 strategies; DisjunctionExclusionStrategy(Collection strategies) { - this.strategies = Preconditions.checkNotNull(strategies); + this.strategies = $Preconditions.checkNotNull(strategies); } public boolean shouldSkipField(FieldAttributes f) { diff --git a/gson/src/main/java/com/google/gson/FieldAttributes.java b/gson/src/main/java/com/google/gson/FieldAttributes.java index 2bd6be5d..b5839c01 100644 --- a/gson/src/main/java/com/google/gson/FieldAttributes.java +++ b/gson/src/main/java/com/google/gson/FieldAttributes.java @@ -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, String>, Collection> ANNOTATION_CACHE = - new LruCache,String>, Collection>(getMaxCacheSize()); + private static final $Cache<$Pair, String>, Collection> ANNOTATION_CACHE = + new $LruCache<$Pair,String>, Collection>(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 getAnnotations() { if (annotations == null) { - Pair, String> key = new Pair, String>(declaringClazz, name); + $Pair, String> key = new $Pair, String>(declaringClazz, name); annotations = ANNOTATION_CACHE.getElement(key); if (annotations == null) { annotations = Collections.unmodifiableCollection( diff --git a/gson/src/main/java/com/google/gson/FieldNamingStrategy2Adapter.java b/gson/src/main/java/com/google/gson/FieldNamingStrategy2Adapter.java index 3568a2b2..15f939c4 100644 --- a/gson/src/main/java/com/google/gson/FieldNamingStrategy2Adapter.java +++ b/gson/src/main/java/com/google/gson/FieldNamingStrategy2Adapter.java @@ -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) { diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java index 7fdb7d66..8f6e56d5 100644 --- a/gson/src/main/java/com/google/gson/Gson.java +++ b/gson/src/main/java/com/google/gson/Gson.java @@ -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 fromJson(String json, Class 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 fromJson(JsonElement json, Class 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; diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index 53ea4688..d754ff10 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -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; /** *

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 serialized JSON @@ -197,9 +197,9 @@ public final class GsonBuilder { *

Maps as JSON objects

* 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}. - * + * *

Below is an example: *

  {@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}}.
-   * 
+   *
    * 

Given the assumption above, a {@code Map} will be * serialize as an array of arrays (can be viewed as an entry set of pairs). - * + * *

Below is an example of serializing complex types as JSON arrays: *

 {@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:
    * 
   {@code
    *   [
@@ -259,7 +259,7 @@ public final class GsonBuilder {
    *     ]
    *   ]
    * }
- * + * * @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 strategySet = - (Preconditions.checkNotNull(mode) == Mode.SERIALIZE) + Set 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); diff --git a/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java b/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java index 8c4d7219..9eb08fd6 100644 --- a/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java @@ -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 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 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 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); } diff --git a/gson/src/main/java/com/google/gson/JsonDeserializationVisitor.java b/gson/src/main/java/com/google/gson/JsonDeserializationVisitor.java index 53b20d3a..2cb5ef2c 100644 --- a/gson/src/main/java/com/google/gson/JsonDeserializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonDeserializationVisitor.java @@ -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 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 implements ObjectNavigator.Visitor @SuppressWarnings("unchecked") public final boolean visitUsingCustomHandler(ObjectTypePair objTypePair) { - Pair, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers); + $Pair, 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, ObjectTypePair> pair) { + protected Object invokeCustomDeserializer(JsonElement element, + $Pair, ObjectTypePair> pair) { if (element == null || element.isJsonNull()) { return null; } diff --git a/gson/src/main/java/com/google/gson/JsonDeserializerExceptionWrapper.java b/gson/src/main/java/com/google/gson/JsonDeserializerExceptionWrapper.java index 41ef4e88..8ed07c7f 100644 --- a/gson/src/main/java/com/google/gson/JsonDeserializerExceptionWrapper.java +++ b/gson/src/main/java/com/google/gson/JsonDeserializerExceptionWrapper.java @@ -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 implements JsonDeserializer { * @throws IllegalArgumentException if {@code delegate} is {@code null}. */ JsonDeserializerExceptionWrapper(JsonDeserializer 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 implements JsonDeserializer { throw new JsonParseException(errorMsg.toString(), e); } } - + @Override public String toString() { return delegate.toString(); diff --git a/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java b/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java index 2bee43ca..c18042a3 100644 --- a/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java +++ b/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java @@ -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()) { diff --git a/gson/src/main/java/com/google/gson/JsonObject.java b/gson/src/main/java/com/google/gson/JsonObject.java index ede0ab9b..fcdab9e7 100644 --- a/gson/src/main/java/com/google/gson/JsonObject.java +++ b/gson/src/main/java/com/google/gson/JsonObject.java @@ -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); } /** diff --git a/gson/src/main/java/com/google/gson/JsonObjectDeserializationVisitor.java b/gson/src/main/java/com/google/gson/JsonObjectDeserializationVisitor.java index de7bb21d..716c3890 100644 --- a/gson/src/main/java/com/google/gson/JsonObjectDeserializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonObjectDeserializationVisitor.java @@ -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 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 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 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 extends JsonDeserializationVisit return true; } ObjectTypePair objTypePair = new ObjectTypePair(null, declaredTypeOfField, false); - Pair, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers); + $Pair, ObjectTypePair> pair = objTypePair.getMatchingHandler(deserializers); if (pair == null) { return false; - } + } Object value = invokeCustomDeserializer(child, pair); if (value != null || !isPrimitive) { f.set(parent, value); diff --git a/gson/src/main/java/com/google/gson/JsonPrimitive.java b/gson/src/main/java/com/google/gson/JsonPrimitive.java index ce58122a..05406cd0 100644 --- a/gson/src/main/java/com/google/gson/JsonPrimitive.java +++ b/gson/src/main/java/com/google/gson/JsonPrimitive.java @@ -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; } } diff --git a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java index 2dda6fec..17996ead 100644 --- a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java @@ -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,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers); + $Pair,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) { diff --git a/gson/src/main/java/com/google/gson/MapTypeAdapter.java b/gson/src/main/java/com/google/gson/MapTypeAdapter.java index a497a5e2..782557bd 100644 --- a/gson/src/main/java/com/google/gson/MapTypeAdapter.java +++ b/gson/src/main/java/com/google/gson/MapTypeAdapter.java @@ -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>, 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) src.entrySet()) { @@ -62,7 +62,7 @@ final class MapTypeAdapter implements JsonSerializer>, // 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 map = constructMapType(typeOfT, context); - Type[] keyAndValueTypes = Types.getMapKeyAndValueTypes(typeOfT, Types.getRawType(typeOfT)); + Type[] keyAndValueTypes = $Types.getMapKeyAndValueTypes(typeOfT, $Types.getRawType(typeOfT)); for (Map.Entry entry : json.getAsJsonObject().entrySet()) { Object key = context.deserialize(new JsonPrimitive(entry.getKey()), keyAndValueTypes[0]); Object value = context.deserialize(entry.getValue(), keyAndValueTypes[1]); diff --git a/gson/src/main/java/com/google/gson/MappedObjectConstructor.java b/gson/src/main/java/com/google/gson/MappedObjectConstructor.java index 26eedd51..1d3e2813 100644 --- a/gson/src/main/java/com/google/gson/MappedObjectConstructor.java +++ b/gson/src/main/java/com/google/gson/MappedObjectConstructor.java @@ -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 constructWithAllocators(Type typeOfT) { try { - Class clazz = (Class) Types.getRawType(typeOfT); + Class clazz = (Class) $Types.getRawType(typeOfT); T obj = defaultConstructorAllocator.newInstance(clazz); return (obj == null) ? unsafeAllocator.newInstance(clazz) diff --git a/gson/src/main/java/com/google/gson/MemoryRefStack.java b/gson/src/main/java/com/google/gson/MemoryRefStack.java index db519aa0..d2c7a604 100644 --- a/gson/src/main/java/com/google/gson/MemoryRefStack.java +++ b/gson/src/main/java/com/google/gson/MemoryRefStack.java @@ -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); } diff --git a/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java b/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java index c19220be..a8a152a5 100644 --- a/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java +++ b/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java @@ -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 diff --git a/gson/src/main/java/com/google/gson/ObjectNavigator.java b/gson/src/main/java/com/google/gson/ObjectNavigator.java index fc2bb7f4..21549cf0 100644 --- a/gson/src/main/java/com/google/gson/ObjectNavigator.java +++ b/gson/src/main/java/com/google/gson/ObjectNavigator.java @@ -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(); } } diff --git a/gson/src/main/java/com/google/gson/ObjectTypePair.java b/gson/src/main/java/com/google/gson/ObjectTypePair.java index afc60060..36f50b60 100644 --- a/gson/src/main/java/com/google/gson/ObjectTypePair.java +++ b/gson/src/main/java/com/google/gson/ObjectTypePair.java @@ -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); } - Pair getMatchingHandler( + $Pair getMatchingHandler( ParameterizedTypeHandlerMap 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, moreSpecificType); + return new $Pair(handler, moreSpecificType); } } // Try the specified type handler = handlers.getHandlerFor(type); - return handler == null ? null : new Pair(handler, this); + return handler == null ? null : new $Pair(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; } diff --git a/gson/src/main/java/com/google/gson/ParameterizedTypeHandlerMap.java b/gson/src/main/java/com/google/gson/ParameterizedTypeHandlerMap.java index 2410e303..ff3fd4a2 100644 --- a/gson/src/main/java/com/google/gson/ParameterizedTypeHandlerMap.java +++ b/gson/src/main/java/com/google/gson/ParameterizedTypeHandlerMap.java @@ -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 The handler that will be looked up by type */ final class ParameterizedTypeHandlerMap { private static final Logger logger = Logger.getLogger(ParameterizedTypeHandlerMap.class.getName()); private final Map map = new HashMap(); - private final List, T>> typeHierarchyList = new ArrayList, T>>(); + private final List<$Pair, T>> typeHierarchyList = new ArrayList<$Pair, T>>(); private boolean modifiable = true; public synchronized void registerForTypeHierarchy(Class typeOfT, T value) { - Pair, T> pair = new Pair, T>(typeOfT, value); + $Pair, T> pair = new $Pair, T>(typeOfT, value); registerForTypeHierarchy(pair); } - public synchronized void registerForTypeHierarchy(Pair, T> pair) { + public synchronized void registerForTypeHierarchy($Pair, T> pair) { if (!modifiable) { throw new IllegalStateException("Attempted to modify an unmodifiable map."); } @@ -70,7 +70,7 @@ final class ParameterizedTypeHandlerMap { private int getIndexOfAnOverriddenHandler(Class type) { for (int i = typeHierarchyList.size()-1; i >= 0; --i) { - Pair, T> entry = typeHierarchyList.get(i); + $Pair, T> entry = typeHierarchyList.get(i); if (type.isAssignableFrom(entry.first)) { return i; } @@ -100,7 +100,7 @@ final class ParameterizedTypeHandlerMap { // 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, T> entry = other.typeHierarchyList.get(i); + $Pair, T> entry = other.typeHierarchyList.get(i); int index = getIndexOfSpecificHandlerForTypeHierarchy(entry.first); if (index < 0) { registerForTypeHierarchy(entry); @@ -118,7 +118,7 @@ final class ParameterizedTypeHandlerMap { // 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, T> entry = other.typeHierarchyList.get(i); + $Pair, T> entry = other.typeHierarchyList.get(i); registerForTypeHierarchy(entry); } } @@ -139,7 +139,7 @@ final class ParameterizedTypeHandlerMap { 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 { } private T getHandlerForTypeHierarchy(Class type) { - for (Pair, T> entry : typeHierarchyList) { + for ($Pair, T> entry : typeHierarchyList) { if (entry.first.isAssignableFrom(type)) { return entry.second; } @@ -186,7 +186,7 @@ final class ParameterizedTypeHandlerMap { public String toString() { StringBuilder sb = new StringBuilder("{mapForTypeHierarchy:{"); boolean first = true; - for (Pair, T> entry : typeHierarchyList) { + for ($Pair, T> entry : typeHierarchyList) { if (first) { first = false; } else { @@ -211,6 +211,6 @@ final class ParameterizedTypeHandlerMap { } private String typeToString(Type type) { - return Types.getRawType(type).getSimpleName(); + return $Types.getRawType(type).getSimpleName(); } } diff --git a/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java b/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java index bf4f79e6..1a538a7e 100644 --- a/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java +++ b/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java @@ -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>> classCache = - new LruCache>>(500); - private static final LruCache, Field[]> fieldsCache = - new LruCache, Field[]>(500); + private static final $LruCache>> classCache = + new $LruCache>>(500); + private static final $LruCache, Field[]> fieldsCache = + new $LruCache, 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> getInheritanceHierarchy(Type type) { List> classes = classCache.get(type); if (classes == null) { classes = new ArrayList>(); - 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()); } } diff --git a/gson/src/main/java/com/google/gson/VersionExclusionStrategy.java b/gson/src/main/java/com/google/gson/VersionExclusionStrategy.java index d62f21b0..ecbf7f3b 100644 --- a/gson/src/main/java/com/google/gson/VersionExclusionStrategy.java +++ b/gson/src/main/java/com/google/gson/VersionExclusionStrategy.java @@ -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; } diff --git a/gson/src/main/java/com/google/gson/internal/Cache.java b/gson/src/main/java/com/google/gson/internal/$Cache.java similarity index 97% rename from gson/src/main/java/com/google/gson/internal/Cache.java rename to gson/src/main/java/com/google/gson/internal/$Cache.java index e1b35ca7..4fce2de3 100644 --- a/gson/src/main/java/com/google/gson/internal/Cache.java +++ b/gson/src/main/java/com/google/gson/internal/$Cache.java @@ -18,11 +18,11 @@ package com.google.gson.internal; /** * Defines generic cache interface. - * + * * @author Inderjeet Singh * @author Joel Leitch */ -public interface Cache { +public interface $Cache { /** * Adds the new value object into the cache for the given key. If the key already @@ -40,10 +40,10 @@ public interface Cache { * @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} */ diff --git a/gson/src/main/java/com/google/gson/internal/LruCache.java b/gson/src/main/java/com/google/gson/internal/$LruCache.java similarity index 85% rename from gson/src/main/java/com/google/gson/internal/LruCache.java rename to gson/src/main/java/com/google/gson/internal/$LruCache.java index 76be0a68..7892bc72 100644 --- a/gson/src/main/java/com/google/gson/internal/LruCache.java +++ b/gson/src/main/java/com/google/gson/internal/$LruCache.java @@ -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 extends LinkedHashMap implements Cache { +public final class $LruCache extends LinkedHashMap implements $Cache { 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; } diff --git a/gson/src/main/java/com/google/gson/internal/Pair.java b/gson/src/main/java/com/google/gson/internal/$Pair.java similarity index 89% rename from gson/src/main/java/com/google/gson/internal/Pair.java rename to gson/src/main/java/com/google/gson/internal/$Pair.java index 205ae295..56c5b069 100644 --- a/gson/src/main/java/com/google/gson/internal/Pair.java +++ b/gson/src/main/java/com/google/gson/internal/$Pair.java @@ -25,11 +25,11 @@ package com.google.gson.internal; * @param * @param */ -public final class Pair { +public final class $Pair { 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 { @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); } diff --git a/gson/src/main/java/com/google/gson/internal/Preconditions.java b/gson/src/main/java/com/google/gson/internal/$Preconditions.java similarity index 93% rename from gson/src/main/java/com/google/gson/internal/Preconditions.java rename to gson/src/main/java/com/google/gson/internal/$Preconditions.java index 83dbaa0a..0487221a 100644 --- a/gson/src/main/java/com/google/gson/internal/Preconditions.java +++ b/gson/src/main/java/com/google/gson/internal/$Preconditions.java @@ -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 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(); diff --git a/gson/src/main/java/com/google/gson/internal/Primitives.java b/gson/src/main/java/com/google/gson/internal/$Primitives.java similarity index 95% rename from gson/src/main/java/com/google/gson/internal/Primitives.java rename to gson/src/main/java/com/google/gson/internal/$Primitives.java index 6c4165d8..0b3ef1aa 100644 --- a/gson/src/main/java/com/google/gson/internal/Primitives.java +++ b/gson/src/main/java/com/google/gson/internal/$Primitives.java @@ -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> PRIMITIVE_TO_WRAPPER_TYPE; @@ -38,7 +38,7 @@ public final class Primitives { private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPE; // Sad that we can't use a BiMap. :( - + static { Map, Class> primToWrap = new HashMap, Class>(16); Map, Class> wrapToPrim = new HashMap, 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 @SuppressWarnings("unchecked") Class wrapped = (Class) 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 @SuppressWarnings("unchecked") Class unwrapped = (Class) WRAPPER_TO_PRIMITIVE_TYPE.get( - Preconditions.checkNotNull(type)); + $Preconditions.checkNotNull(type)); return (unwrapped == null) ? type : unwrapped; - } + } } diff --git a/gson/src/main/java/com/google/gson/internal/Types.java b/gson/src/main/java/com/google/gson/internal/$Types.java similarity index 97% rename from gson/src/main/java/com/google/gson/internal/Types.java rename to gson/src/main/java/com/google/gson/internal/$Types.java index 9aa90ad9..fd6999f5 100644 --- a/gson/src/main/java/com/google/gson/internal/Types.java +++ b/gson/src/main/java/com/google/gson/internal/$Types.java @@ -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() { diff --git a/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java b/gson/src/main/java/com/google/gson/internal/$UnsafeAllocator.java similarity index 93% rename from gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java rename to gson/src/main/java/com/google/gson/internal/$UnsafeAllocator.java index ec6c355e..c33024ca 100644 --- a/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java +++ b/gson/src/main/java/com/google/gson/internal/$UnsafeAllocator.java @@ -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 newInstance(Class 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 newInstance(Class 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 newInstance(Class 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 newInstance(Class c) throws Exception { @@ -94,7 +94,7 @@ public abstract class UnsafeAllocator { } // give up - return new UnsafeAllocator() { + return new $UnsafeAllocator() { @Override public T newInstance(Class c) { throw new UnsupportedOperationException("Cannot allocate " + c); diff --git a/gson/src/main/java/com/google/gson/reflect/TypeToken.java b/gson/src/main/java/com/google/gson/reflect/TypeToken.java index 886cc158..1b2f5890 100644 --- a/gson/src/main/java/com/google/gson/reflect/TypeToken.java +++ b/gson/src/main/java/com/google/gson/reflect/TypeToken.java @@ -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; * *

This syntax cannot be used to create type literals that have wildcard * parameters, such as {@code Class} or {@code List}. - * 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 { @SuppressWarnings("unchecked") protected TypeToken() { this.type = getSuperclassTypeParameter(getClass()); - this.rawType = (Class) Types.getRawType(type); + this.rawType = (Class) $Types.getRawType(type); this.hashCode = type.hashCode(); } @@ -75,13 +70,13 @@ public class TypeToken { */ @SuppressWarnings("unchecked") TypeToken(Type type) { - this.type = Types.canonicalize(Preconditions.checkNotNull(type)); - this.rawType = (Class) Types.getRawType(this.type); + this.type = $Types.canonicalize($Preconditions.checkNotNull(type)); + this.rawType = (Class) $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 { 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 { } 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()); } 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 { } // 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 { @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); } /** diff --git a/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java b/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java index 71b8eea7..242421db 100644 --- a/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java +++ b/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java @@ -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>() {}.getType(); Type genericArrayType = new TypeToken[]>() {}.getType(); - + assertEquals(parameterizedType, ourType.getGenericComponentType()); assertEquals(genericArrayType, ourType); assertEquals(genericArrayType.hashCode(), ourType.hashCode()); diff --git a/gson/src/test/java/com/google/gson/LruCacheTest.java b/gson/src/test/java/com/google/gson/LruCacheTest.java index c9d01ee3..4bcd2500 100644 --- a/gson/src/test/java/com/google/gson/LruCacheTest.java +++ b/gson/src/test/java/com/google/gson/LruCacheTest.java @@ -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 cache = new LruCache(3); - + $Cache cache = new $LruCache(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 cache = new LruCache(3); - + $Cache cache = new $LruCache(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 cache = new LruCache(5); + $Cache cache = new $LruCache(5); cache.addElement("key1", 1); cache.addElement("key2", 2); diff --git a/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java b/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java index aca57eca..b18eabff 100644 --- a/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java +++ b/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java @@ -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 { diff --git a/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java b/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java index 45f8d474..e687fc14 100644 --- a/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java +++ b/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java @@ -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 String getExpectedJson(MyParameterizedType obj) { Class clazz = (Class) 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 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); } diff --git a/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java b/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java index 2a71746f..5e453c28 100644 --- a/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java +++ b/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java @@ -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 adaptType(Object from, Class 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) {