Add more CheckReturnValues for JsonReader.

This encourages skipName over nextName.
This commit is contained in:
Eric Cochran
2018-05-15 17:29:36 -07:00
committed by Eric Cochran
parent b5a50d8281
commit d31f3c2482
3 changed files with 11 additions and 5 deletions

View File

@@ -312,25 +312,25 @@ public abstract class JsonReader implements Closeable {
/** /**
* Returns true if the current array or object has another element. * Returns true if the current array or object has another element.
*/ */
public abstract boolean hasNext() throws IOException; @CheckReturnValue public abstract boolean hasNext() throws IOException;
/** /**
* Returns the type of the next token without consuming it. * Returns the type of the next token without consuming it.
*/ */
public abstract Token peek() throws IOException; @CheckReturnValue public abstract Token peek() throws IOException;
/** /**
* Returns the next token, a {@linkplain Token#NAME property name}, and consumes it. * Returns the next token, a {@linkplain Token#NAME property name}, and consumes it.
* *
* @throws JsonDataException if the next token in the stream is not a property name. * @throws JsonDataException if the next token in the stream is not a property name.
*/ */
public abstract String nextName() throws IOException; @CheckReturnValue public abstract String nextName() throws IOException;
/** /**
* If the next token is a {@linkplain Token#NAME property name} that's in {@code options}, this * If the next token is a {@linkplain Token#NAME property name} that's in {@code options}, this
* consumes it and returns its index. Otherwise this returns -1 and no name is consumed. * consumes it and returns its index. Otherwise this returns -1 and no name is consumed.
*/ */
public abstract int selectName(Options options) throws IOException; @CheckReturnValue public abstract int selectName(Options options) throws IOException;
/** /**
* Skips the next token, consuming it. This method is intended for use when the JSON token stream * Skips the next token, consuming it. This method is intended for use when the JSON token stream
@@ -353,7 +353,7 @@ public abstract class JsonReader implements Closeable {
* If the next token is a {@linkplain Token#STRING string} that's in {@code options}, this * If the next token is a {@linkplain Token#STRING string} that's in {@code options}, this
* consumes it and returns its index. Otherwise this returns -1 and no string is consumed. * consumes it and returns its index. Otherwise this returns -1 and no string is consumed.
*/ */
public abstract int selectString(Options options) throws IOException; @CheckReturnValue public abstract int selectString(Options options) throws IOException;
/** /**
* Returns the {@linkplain Token#BOOLEAN boolean} value of the next token, consuming it. * Returns the {@linkplain Token#BOOLEAN boolean} value of the next token, consuming it.

View File

@@ -35,6 +35,7 @@ public final class JsonReaderPathTest {
return JsonCodecFactory.factories(); return JsonCodecFactory.factories();
} }
@SuppressWarnings("CheckReturnValue")
@Test public void path() throws IOException { @Test public void path() throws IOException {
JsonReader reader = factory.newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}"); JsonReader reader = factory.newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}");
assertThat(reader.getPath()).isEqualTo("$"); assertThat(reader.getPath()).isEqualTo("$");
@@ -114,6 +115,7 @@ public final class JsonReaderPathTest {
assertThat(reader.getPath()).isEqualTo("$"); assertThat(reader.getPath()).isEqualTo("$");
} }
@SuppressWarnings("CheckReturnValue")
@Test public void objectPath() throws IOException { @Test public void objectPath() throws IOException {
JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}"); JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}");
assertThat(reader.getPath()).isEqualTo("$"); assertThat(reader.getPath()).isEqualTo("$");
@@ -154,6 +156,7 @@ public final class JsonReaderPathTest {
assertThat(reader.getPath()).isEqualTo("$"); assertThat(reader.getPath()).isEqualTo("$");
} }
@SuppressWarnings("CheckReturnValue")
@Test public void arrayPath() throws IOException { @Test public void arrayPath() throws IOException {
JsonReader reader = factory.newReader("[1,2]"); JsonReader reader = factory.newReader("[1,2]");
assertThat(reader.getPath()).isEqualTo("$"); assertThat(reader.getPath()).isEqualTo("$");
@@ -212,6 +215,7 @@ public final class JsonReaderPathTest {
assertThat(reader.getPath()).isEqualTo("$.null"); assertThat(reader.getPath()).isEqualTo("$.null");
} }
@SuppressWarnings("CheckReturnValue")
@Test public void skipObjectValues() throws IOException { @Test public void skipObjectValues() throws IOException {
JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}"); JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}");
reader.beginObject(); reader.beginObject();

View File

@@ -393,6 +393,7 @@ public final class JsonUtf8ReaderTest {
} }
} }
@SuppressWarnings("CheckReturnValue")
@Test public void prematurelyClosed() throws IOException { @Test public void prematurelyClosed() throws IOException {
try { try {
JsonReader reader = newReader("{\"a\":[]}"); JsonReader reader = newReader("{\"a\":[]}");
@@ -977,6 +978,7 @@ public final class JsonUtf8ReaderTest {
} }
} }
@SuppressWarnings("CheckReturnValue")
@Test public void failWithPositionDeepPath() throws IOException { @Test public void failWithPositionDeepPath() throws IOException {
JsonReader reader = newReader("[1,{\"a\":[2,3,}"); JsonReader reader = newReader("[1,{\"a\":[2,3,}");
reader.beginArray(); reader.beginArray();