Skip to content

Commit

Permalink
Publicize promoteNameToValue of JsonReader
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuwenbo committed May 24, 2023
1 parent ed8ca46 commit b0a6b9e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ JsonElement nextJsonElement() throws IOException {
return getClass().getSimpleName() + locationString();
}

public void promoteNameToValue() throws IOException {
@Override public void promoteNameToValue() throws IOException {
expect(JsonToken.NAME);
Iterator<?> i = (Iterator<?>) peekStack();
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) i.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -181,7 +180,7 @@ public Adapter(Gson context, Type keyType, TypeAdapter<K> keyTypeAdapter,
} else {
in.beginObject();
while (in.hasNext()) {
JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in);
in.promoteNameToValue();
K key = keyTypeAdapter.read(in);
V value = valueTypeAdapter.read(in);
V replaced = map.put(key, value);
Expand Down
42 changes: 19 additions & 23 deletions gson/src/main/java/com/google/gson/stream/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.gson.stream;

import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.internal.TroubleshootingGuide;
import com.google.gson.internal.bind.JsonTreeReader;
import java.io.Closeable;
Expand Down Expand Up @@ -1690,27 +1689,24 @@ private void consumeNonExecutePrefix() throws IOException {
pos += 5;
}

static {
JsonReaderInternalAccess.INSTANCE = new JsonReaderInternalAccess() {
@Override public void promoteNameToValue(JsonReader reader) throws IOException {
if (reader instanceof JsonTreeReader) {
((JsonTreeReader)reader).promoteNameToValue();
return;
}
int p = reader.peeked;
if (p == PEEKED_NONE) {
p = reader.doPeek();
}
if (p == PEEKED_DOUBLE_QUOTED_NAME) {
reader.peeked = PEEKED_DOUBLE_QUOTED;
} else if (p == PEEKED_SINGLE_QUOTED_NAME) {
reader.peeked = PEEKED_SINGLE_QUOTED;
} else if (p == PEEKED_UNQUOTED_NAME) {
reader.peeked = PEEKED_UNQUOTED;
} else {
throw reader.unexpectedTokenError("a name");
}
}
};
/**
* Changes the type of the current property name token to a string value.
*
* @since $next-version$
*/
public void promoteNameToValue() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
if (p == PEEKED_DOUBLE_QUOTED_NAME) {
peeked = PEEKED_DOUBLE_QUOTED;
} else if (p == PEEKED_SINGLE_QUOTED_NAME) {
peeked = PEEKED_SINGLE_QUOTED;
} else if (p == PEEKED_UNQUOTED_NAME) {
peeked = PEEKED_UNQUOTED;
} else {
throw unexpectedTokenError("a name");
}
}
}

0 comments on commit b0a6b9e

Please sign in to comment.