Skip to content

Commit 9ab666f

Browse files
committed
refactoring
1 parent 14f8a0a commit 9ab666f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ public JsonToken nextToken() throws IOException
345345
{
346346
_currentIsAlias = false;
347347
_binaryValue = null;
348-
_currentAnchor = null;
349348
if (_closed) {
350349
return null;
351350
}
@@ -363,33 +362,37 @@ public JsonToken nextToken() throws IOException
363362
}
364363
// is null ok? Assume it is, for now, consider to be same as end-of-doc
365364
if (evt == null) {
365+
_currentAnchor = null;
366366
return (_currToken = null);
367367
}
368368
_lastEvent = evt;
369-
370-
/* One complication: field names are only inferred from the
371-
* fact that we are in Object context...
372-
*/
373-
if (_parsingContext.inObject() && _currToken != JsonToken.FIELD_NAME) {
374-
if (!evt.is(Event.ID.Scalar)) {
375-
// end is fine
376-
if (evt.is(Event.ID.MappingEnd)) {
377-
if (!_parsingContext.inObject()) { // sanity check is optional, but let's do it for now
378-
_reportMismatchedEndMarker('}', ']');
369+
370+
// One complication: field names are only inferred from the
371+
// fact that we are in Object context...
372+
if (_parsingContext.inObject()) {
373+
if (_currToken != JsonToken.FIELD_NAME) {
374+
if (!evt.is(Event.ID.Scalar)) {
375+
_currentAnchor = null;
376+
// end is fine
377+
if (evt.is(Event.ID.MappingEnd)) {
378+
if (!_parsingContext.inObject()) { // sanity check is optional, but let's do it for now
379+
_reportMismatchedEndMarker('}', ']');
380+
}
381+
_parsingContext = _parsingContext.getParent();
382+
return (_currToken = JsonToken.END_OBJECT);
379383
}
380-
_parsingContext = _parsingContext.getParent();
381-
return (_currToken = JsonToken.END_OBJECT);
384+
_reportError("Expected a field name (Scalar value in YAML), got this instead: "+evt);
382385
}
383-
_reportError("Expected a field name (Scalar value in YAML), got this instead: "+evt);
386+
ScalarEvent scalar = (ScalarEvent) evt;
387+
String name = scalar.getValue();
388+
_currentFieldName = name;
389+
_parsingContext.setCurrentName(name);
390+
_currentAnchor = scalar.getAnchor();
391+
return (_currToken = JsonToken.FIELD_NAME);
384392
}
385-
ScalarEvent scalar = (ScalarEvent) evt;
386-
String name = scalar.getValue();
387-
_currentFieldName = name;
388-
_parsingContext.setCurrentName(name);
389-
_currentAnchor = scalar.getAnchor();
390-
return (_currToken = JsonToken.FIELD_NAME);
391393
}
392394
// Ugh. Why not expose id, to be able to Switch?
395+
_currentAnchor = null;
393396

394397
// scalar values are probably the commonest:
395398
if (evt.is(Event.ID.Scalar)) {

0 commit comments

Comments
 (0)