mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Merge pull request #543 from square/eric.checkreturn
Add more CheckReturnValues for JsonReader.
This commit is contained in:
@@ -312,25 +312,25 @@ public abstract class JsonReader implements Closeable {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @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
|
||||
* 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
|
||||
@@ -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
|
||||
* 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.
|
||||
|
@@ -35,6 +35,7 @@ public final class JsonReaderPathTest {
|
||||
return JsonCodecFactory.factories();
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void path() throws IOException {
|
||||
JsonReader reader = factory.newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}");
|
||||
assertThat(reader.getPath()).isEqualTo("$");
|
||||
@@ -114,6 +115,7 @@ public final class JsonReaderPathTest {
|
||||
assertThat(reader.getPath()).isEqualTo("$");
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void objectPath() throws IOException {
|
||||
JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}");
|
||||
assertThat(reader.getPath()).isEqualTo("$");
|
||||
@@ -154,6 +156,7 @@ public final class JsonReaderPathTest {
|
||||
assertThat(reader.getPath()).isEqualTo("$");
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void arrayPath() throws IOException {
|
||||
JsonReader reader = factory.newReader("[1,2]");
|
||||
assertThat(reader.getPath()).isEqualTo("$");
|
||||
@@ -212,6 +215,7 @@ public final class JsonReaderPathTest {
|
||||
assertThat(reader.getPath()).isEqualTo("$.null");
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void skipObjectValues() throws IOException {
|
||||
JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}");
|
||||
reader.beginObject();
|
||||
|
@@ -393,6 +393,7 @@ public final class JsonUtf8ReaderTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void prematurelyClosed() throws IOException {
|
||||
try {
|
||||
JsonReader reader = newReader("{\"a\":[]}");
|
||||
@@ -977,6 +978,7 @@ public final class JsonUtf8ReaderTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
@Test public void failWithPositionDeepPath() throws IOException {
|
||||
JsonReader reader = newReader("[1,{\"a\":[2,3,}");
|
||||
reader.beginArray();
|
||||
|
Reference in New Issue
Block a user