Create an "internals" package for classes that we do not want to share, but is needed across multiple pacakges.

As well, move non-Gson specific classes, such as Preconditions, to this new "internals" package.
This commit is contained in:
Joel Leitch 2011-03-21 22:30:35 +00:00
parent 657688ca79
commit 861e047a62
42 changed files with 104 additions and 38 deletions

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collection;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Types;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.io.IOException;
/**

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.util.Collection;
/**

View File

@ -16,6 +16,11 @@
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 java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
/**
* Adapts the old "deprecated" FieldNamingStrategy to the new {@link FieldNamingStrategy2}
* type.

View File

@ -16,6 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Primitives;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

View File

@ -27,6 +27,7 @@ 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

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Types;
import java.lang.reflect.Array;
import java.lang.reflect.Type;

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Preconditions;
import java.lang.reflect.Type;
/**

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.lang.reflect.Type;
/**

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Primitives;
import java.lang.reflect.Type;
/**

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

View File

@ -16,6 +16,7 @@
package com.google.gson;
import java.lang.reflect.Type;
/**

View File

@ -16,6 +16,10 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.Types;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
@ -168,7 +172,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
/**
* objTypePair.getObject() must not be null
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings("unchecked")
private JsonElement findAndInvokeCustomSerializer(ObjectTypePair objTypePair) {
Pair<JsonSerializer<?>,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers);
if (pair == null) {

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Types;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.internal.UnsafeAllocator;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.util.Stack;
/**

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collection;

View File

@ -16,6 +16,10 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Types;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Type;

View File

@ -16,6 +16,8 @@
package com.google.gson;
import com.google.gson.internal.Preconditions;
/**
* A factory class used to simplify {@link ObjectNavigator} creation.
* This object holds on to a reference of the {@link ExclusionStrategy}

View File

@ -15,6 +15,8 @@
*/
package com.google.gson;
import com.google.gson.internal.Pair;
import java.lang.reflect.Type;
/**

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Pair;
import com.google.gson.internal.Types;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -18,6 +18,7 @@ package com.google.gson;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;
import com.google.gson.internal.Preconditions;
/**
* This strategy will exclude any files and/or class that are passed the

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
/**
* Defines generic cache interface.
@ -22,7 +22,7 @@ package com.google.gson;
* @author Inderjeet Singh
* @author Joel Leitch
*/
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

View File

@ -14,7 +14,8 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
import java.util.LinkedHashMap;
import java.util.Map;
@ -27,12 +28,12 @@ import java.util.Map;
* @author Inderjeet Singh
* @author Joel Leitch
*/
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;
LruCache(int maxCapacity) {
public LruCache(int maxCapacity) {
super(maxCapacity, 0.7F, true);
this.maxCapacity = maxCapacity;
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
/**
* A simple object that holds onto a pair of object references, first and second.
@ -25,12 +25,11 @@ package com.google.gson;
* @param <FIRST>
* @param <SECOND>
*/
final class Pair<FIRST, SECOND> {
public final class Pair<FIRST, SECOND> {
public final FIRST first;
public final SECOND second;
final FIRST first;
final SECOND second;
Pair(FIRST first, SECOND second) {
public Pair(FIRST first, SECOND second) {
this.first = first;
this.second = second;
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
/**
* A simple utility class used to check method Preconditions.
@ -29,7 +29,7 @@ package com.google.gson;
* @author Inderjeet Singh
* @author Joel Leitch
*/
final class Preconditions {
public final class Preconditions {
public static <T> T checkNotNull(T obj) {
if (obj == null) {
throw new NullPointerException();

View File

@ -14,7 +14,8 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
import java.lang.reflect.Type;
import java.util.Collections;
@ -27,14 +28,14 @@ import java.util.Map;
*
* @author Kevin Bourrillion
*/
final class Primitives {
public final class Primitives {
private Primitives() {}
/** A map from primitive types to their corresponding wrapper types. */
public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
/** A map from wrapper types to their corresponding primitive types. */
public static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
// Sad that we can't use a BiMap. :(

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
import java.io.Serializable;
import java.lang.reflect.Array;
@ -274,7 +274,7 @@ public final class Types {
* Returns true if this type is an array.
*/
@SuppressWarnings("unchecked")
static boolean isArray(Type type) {
public static boolean isArray(Type type) {
return type instanceof GenericArrayType
|| (type instanceof Class && ((Class<?>) type).isArray());
}
@ -283,7 +283,7 @@ public final class Types {
* Returns the component type of this array type.
* @throws ClassCastException if this type is not an array.
*/
static Type getArrayComponentType(Type array) {
public static Type getArrayComponentType(Type array) {
return array instanceof GenericArrayType
? ((GenericArrayType) array).getGenericComponentType()
: ((Class<?>) array).getComponentType();
@ -293,7 +293,7 @@ public final class Types {
* Returns the element type of this collection type.
* @throws IllegalArgumentException if this type is not a collection.
*/
static Type getCollectionElementType(Type context, Class<?> contextRawType) {
public static Type getCollectionElementType(Type context, Class<?> contextRawType) {
Type collectionType = getSupertype(context, contextRawType, Collection.class);
return ((ParameterizedType) collectionType).getActualTypeArguments()[0];
}
@ -302,7 +302,7 @@ public final class Types {
* Returns a two element array containing this map's key and value types in
* positions 0 and 1 respectively.
*/
static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) {
public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) {
/*
* Work around a problem with the declaration of java.util.Properties. That
* class should extend Hashtable<String, String>, but it's declared to
@ -318,7 +318,7 @@ public final class Types {
}
@SuppressWarnings("unchecked")
static Type resolve(Type context, Class<?> contextRawType, Type toResolve) {
public static Type resolve(Type context, Class<?> contextRawType, Type toResolve) {
// this implementation is made a little more complicated in an attempt to avoid object-creation
while (true) {
if (toResolve instanceof TypeVariable) {
@ -390,7 +390,7 @@ public final class Types {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings("unchecked")
static Type resolveTypeVariable(Type context, Class<?> contextRawType, TypeVariable unknown) {
Class<?> declaredByRaw = declaringClassOf(unknown);

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.gson;
package com.google.gson.internal;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
@ -27,7 +27,7 @@ import java.lang.reflect.Method;
* @author Joel Leitch
* @author Jesse Wilson
*/
abstract class UnsafeAllocator {
public abstract class UnsafeAllocator {
public abstract <T> T newInstance(Class<T> c) throws Exception;
public static UnsafeAllocator create() {

View File

@ -16,7 +16,8 @@
package com.google.gson.reflect;
import com.google.gson.Types;
import com.google.gson.internal.Types;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
@ -35,11 +36,11 @@ import java.util.Map;
* create an empty anonymous inner class:
*
* <p>
* {@code TypeLiteral<List<String>> list = new TypeToken<List<String>>() {};}
* {@code TypeToken<List<String>> list = new TypeToken<List<String>>() {};}
*
* <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 literals must be constructed programatically, either by {@link
* Such type tokens must be constructed programatically, either by {@link
* Method#getGenericReturnType extracting types from members} or by using the
* {@link Types} factory class.
*

View File

@ -16,6 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.reflect.TypeToken;
import junit.framework.TestCase;

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Cache;
import com.google.gson.internal.LruCache;
import junit.framework.TestCase;
/**

View File

@ -16,7 +16,6 @@
package com.google.gson;
import com.google.gson.MemoryRefStack;
import junit.framework.TestCase;

View File

@ -16,6 +16,7 @@
package com.google.gson;
import com.google.gson.internal.Types;
import com.google.gson.reflect.TypeToken;
import junit.framework.TestCase;

View File

@ -16,6 +16,9 @@
package com.google.gson;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Types;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;

View File

@ -21,7 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.google.gson.JsonParseException;
import com.google.gson.Primitives;
import com.google.gson.internal.Primitives;
/**
* Handles type conversion from some object to some primitive (or primitive

View File

@ -19,8 +19,6 @@ package com.google.gson.functional;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonElement;
import com.google.gson.common.TestTypes.BagOfPrimitives;
import com.google.gson.reflect.TypeToken;
import junit.framework.TestCase;

View File

@ -133,10 +133,10 @@ public final class TypeHierarchyAdapterTest extends TestCase {
public void testRegisterSubTypeFirstNotAllowed() {
try {
Gson gson = new GsonBuilder()
.registerTypeHierarchyAdapter(Manager.class, new ManagerAdapter())
.registerTypeHierarchyAdapter(Employee.class, new EmployeeAdapter())
.create();
new GsonBuilder()
.registerTypeHierarchyAdapter(Manager.class, new ManagerAdapter())
.registerTypeHierarchyAdapter(Employee.class, new EmployeeAdapter())
.create();
fail();
} catch (IllegalArgumentException expected) {
}