From 796a3812791d3d2ac3d70c63f0d02a04131fe5b4 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Sun, 1 Jan 2012 12:42:20 +0000 Subject: [PATCH] Kill GsonInternalAccess. Clients to this were all broken because nobody was ever assigning INSTANCE. --- .../gson/graph/GraphTypeAdapterFactory.java | 3 +- .../RuntimeTypeAdapterFactory.java | 34 ++-------------- gson/src/main/java/com/google/gson/Gson.java | 1 - .../java/com/google/gson/TreeTypeAdapter.java | 1 - .../com/google/gson/internal/Excluder.java | 2 +- .../gson/internal/GsonInternalAccess.java | 39 ------------------- 6 files changed, 5 insertions(+), 75 deletions(-) delete mode 100644 gson/src/main/java/com/google/gson/internal/GsonInternalAccess.java diff --git a/extras/src/main/java/com/google/gson/graph/GraphTypeAdapterFactory.java b/extras/src/main/java/com/google/gson/graph/GraphTypeAdapterFactory.java index 95a108c9..5aaa9e25 100644 --- a/extras/src/main/java/com/google/gson/graph/GraphTypeAdapterFactory.java +++ b/extras/src/main/java/com/google/gson/graph/GraphTypeAdapterFactory.java @@ -20,7 +20,6 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; -import com.google.gson.internal.GsonInternalAccess; import com.google.gson.internal.bind.JsonTreeReader; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; @@ -59,7 +58,7 @@ public final class GraphTypeAdapterFactory implements TypeAdapterFactory { return null; } - final TypeAdapter typeAdapter = GsonInternalAccess.INSTANCE.getNextAdapter(gson, this, type); + final TypeAdapter typeAdapter = gson.getNextAdapter(this, type); final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); return new TypeAdapter() { @Override public void write(JsonWriter out, T value) throws IOException { diff --git a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java index 03f75041..582c4fd5 100644 --- a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java +++ b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java @@ -18,16 +18,12 @@ package com.google.gson.typeadapters; import com.google.gson.Gson; import com.google.gson.JsonElement; -import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; -import com.google.gson.internal.GsonInternalAccess; import com.google.gson.internal.Streams; -import com.google.gson.internal.bind.JsonTreeWriter; -import com.google.gson.internal.bind.JsonTreeReader; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; @@ -194,8 +190,7 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { final Map, TypeAdapter> subtypeToDelegate = new LinkedHashMap, TypeAdapter>(); for (Map.Entry> entry : labelToSubtype.entrySet()) { - TypeAdapter delegate = GsonInternalAccess.INSTANCE - .getNextAdapter(gson, this, TypeToken.get(entry.getValue())); + TypeAdapter delegate = gson.getNextAdapter(this, TypeToken.get(entry.getValue())); labelToDelegate.put(entry.getKey(), delegate); subtypeToDelegate.put(entry.getValue(), delegate); } @@ -215,18 +210,7 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { throw new JsonParseException("cannot deserialize " + baseType + " subtype named " + label + "; did you forget to register a subtype?"); } - return fromJsonTree(delegate, jsonElement); - } - - // TODO: remove this when TypeAdapter.fromJsonTree() is public - private T fromJsonTree(TypeAdapter delegate, JsonElement jsonTree) { - try { - JsonReader jsonReader = new JsonTreeReader(jsonTree); - jsonReader.setLenient(true); - return delegate.read(jsonReader); - } catch (IOException e) { - throw new JsonIOException(e); - } + return delegate.fromJsonTree(jsonElement); } @Override public void write(JsonWriter out, T value) throws IOException { @@ -238,7 +222,7 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { throw new JsonParseException("cannot serialize " + srcType.getName() + "; did you forget to register a subtype?"); } - JsonObject jsonObject = toJsonTree(delegate, value).getAsJsonObject(); + JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject(); if (jsonObject.has(typeFieldName)) { throw new JsonParseException("cannot serialize " + srcType.getName() + " because it already defines a field named " + typeFieldName); @@ -250,18 +234,6 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { } Streams.write(clone, out); } - - // TODO: remove this when TypeAdapter.toJsonTree() is public - private JsonElement toJsonTree(TypeAdapter delegate, T value) { - try { - JsonTreeWriter jsonWriter = new JsonTreeWriter(); - jsonWriter.setLenient(true); - delegate.write(jsonWriter, value); - return jsonWriter.get(); - } catch (IOException e) { - throw new JsonIOException(e); - } - } }; } } diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java index 4f33b726..ce96198d 100644 --- a/gson/src/main/java/com/google/gson/Gson.java +++ b/gson/src/main/java/com/google/gson/Gson.java @@ -18,7 +18,6 @@ package com.google.gson; import com.google.gson.internal.ConstructorConstructor; import com.google.gson.internal.Excluder; -import com.google.gson.internal.GsonInternalAccess; import com.google.gson.internal.Primitives; import com.google.gson.internal.Streams; import com.google.gson.internal.bind.ArrayTypeAdapter; diff --git a/gson/src/main/java/com/google/gson/TreeTypeAdapter.java b/gson/src/main/java/com/google/gson/TreeTypeAdapter.java index c9929069..05f6f3ee 100644 --- a/gson/src/main/java/com/google/gson/TreeTypeAdapter.java +++ b/gson/src/main/java/com/google/gson/TreeTypeAdapter.java @@ -17,7 +17,6 @@ package com.google.gson; import com.google.gson.internal.$Gson$Preconditions; -import com.google.gson.internal.GsonInternalAccess; import com.google.gson.internal.Streams; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; diff --git a/gson/src/main/java/com/google/gson/internal/Excluder.java b/gson/src/main/java/com/google/gson/internal/Excluder.java index 61c37b77..dce4f1d7 100644 --- a/gson/src/main/java/com/google/gson/internal/Excluder.java +++ b/gson/src/main/java/com/google/gson/internal/Excluder.java @@ -141,7 +141,7 @@ public final class Excluder implements TypeAdapterFactory, Cloneable { TypeAdapter d = delegate; return d != null ? d - : (delegate = GsonInternalAccess.INSTANCE.getNextAdapter(gson, Excluder.this, type)); + : (delegate = gson.getNextAdapter(Excluder.this, type)); } }; } diff --git a/gson/src/main/java/com/google/gson/internal/GsonInternalAccess.java b/gson/src/main/java/com/google/gson/internal/GsonInternalAccess.java deleted file mode 100644 index 2bef899a..00000000 --- a/gson/src/main/java/com/google/gson/internal/GsonInternalAccess.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gson.internal; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -/** - * Internal-only APIs of Gson available only to other classes in Gson. - */ -public abstract class GsonInternalAccess { - public static GsonInternalAccess INSTANCE; - - /** - * Returns a type adapter for {@code} type that isn't {@code skipPast}. This - * can be used for type adapters to compose other, simpler type adapters. - * - * @throws IllegalArgumentException if this GSON cannot serialize and - * deserialize {@code type}. - */ - public abstract TypeAdapter getNextAdapter( - Gson gson, TypeAdapterFactory skipPast, TypeToken type); -}