MCPcopy
hub / github.com/google/gson / quickPeek

Method quickPeek

src/main/java/com/google/gson/stream/JsonReader.java:354–396  ·  view source on GitHub ↗

Ensures that a token is ready. After this call either token or value will be non-null. To ensure token has a definitive value, use #peek()

()

Source from the content-addressed store, hash-verified

352 * value, use {@link #peek()}
353 */
354 private JsonToken quickPeek() throws IOException {
355 if (hasToken) {
356 return token;
357 }
358
359 switch (peekStack()) {
360 case EMPTY_DOCUMENT:
361 if (lenient) {
362 consumeNonExecutePrefix();
363 }
364 replaceTop(JsonScope.NONEMPTY_DOCUMENT);
365 JsonToken firstToken = nextValue();
366 if (!lenient && firstToken != JsonToken.BEGIN_ARRAY && firstToken != JsonToken.BEGIN_OBJECT) {
367 syntaxError("Expected JSON document to start with '[' or '{'");
368 }
369 return firstToken;
370 case EMPTY_ARRAY:
371 return nextInArray(true);
372 case NONEMPTY_ARRAY:
373 return nextInArray(false);
374 case EMPTY_OBJECT:
375 return nextInObject(true);
376 case DANGLING_NAME:
377 return objectValue();
378 case NONEMPTY_OBJECT:
379 return nextInObject(false);
380 case NONEMPTY_DOCUMENT:
381 try {
382 JsonToken token = nextValue();
383 if (lenient) {
384 return token;
385 }
386 throw syntaxError("Expected EOF");
387 } catch (EOFException e) {
388 hasToken = true; // TODO: avoid throwing here?
389 return token = JsonToken.END_DOCUMENT;
390 }
391 case CLOSED:
392 throw new IllegalStateException("JsonReader is closed");
393 default:
394 throw new AssertionError();
395 }
396 }
397
398 /**
399 * Consumes the non-execute prefix if it exists.

Callers 10

expectMethod · 0.95
hasNextMethod · 0.95
peekMethod · 0.95
advanceMethod · 0.95
nextNameMethod · 0.95
nextBooleanMethod · 0.95
nextNullMethod · 0.95
nextDoubleMethod · 0.95
nextLongMethod · 0.95
nextIntMethod · 0.95

Calls 8

peekStackMethod · 0.95
replaceTopMethod · 0.95
nextValueMethod · 0.95
syntaxErrorMethod · 0.95
nextInArrayMethod · 0.95
nextInObjectMethod · 0.95
objectValueMethod · 0.95

Tested by

no test coverage detected