@@ -500,13 +500,8 @@ class Parser {
500500 reportRecoverableError (next, fasta.messageTopLevelOperator);
501501 // Insert a synthetic identifier
502502 // and continue parsing as a top level function.
503- rewriter.insertToken (
504- next,
505- new SyntheticStringToken (
506- TokenType .IDENTIFIER ,
507- '#synthetic_function_${next .charOffset }' ,
508- next.next.charOffset,
509- 0 ));
503+ rewriter.insertSyntheticIdentifier (
504+ next, '#synthetic_function_${next .charOffset }' );
510505 return parseTopLevelMemberImpl (next);
511506 }
512507 // Ignore any preceding modifiers and just report the unexpected token
@@ -1109,9 +1104,7 @@ class Parser {
11091104 // Recovery: Report an error and insert synthetic `with` clause.
11101105 reportRecoverableError (
11111106 withKeyword, fasta.templateExpectedButGot.withArguments ('with' ));
1112- withKeyword =
1113- new SyntheticKeywordToken (Keyword .WITH , withKeyword.charOffset);
1114- rewriter.insertToken (token, withKeyword);
1107+ withKeyword = rewriter.insertSyntheticKeyword (token, Keyword .WITH );
11151108 if (! isValidTypeReference (withKeyword.next)) {
11161109 rewriter.insertSyntheticIdentifier (withKeyword);
11171110 }
@@ -2223,13 +2216,8 @@ class Parser {
22232216 token = next;
22242217 next = token.next;
22252218 if (optional ('(' , next.next)) {
2226- rewriter.insertToken (
2227- next,
2228- new SyntheticStringToken (
2229- TokenType .IDENTIFIER ,
2230- '#synthetic_identifier_${next .charOffset }' ,
2231- next.charOffset,
2232- 0 ));
2219+ rewriter.insertSyntheticIdentifier (
2220+ next, '#synthetic_identifier_${next .charOffset }' );
22332221 }
22342222 }
22352223 }
@@ -2496,8 +2484,7 @@ class Parser {
24962484 // expecting one of `,` or `;` or `{`
24972485 reportRecoverableError (
24982486 token, fasta.templateExpectedAfterButGot.withArguments (',' ));
2499- next = rewriter.insertToken (
2500- token, new SyntheticToken (TokenType .COMMA , token.next.charOffset));
2487+ next = rewriter.insertSyntheticToken (token, TokenType .COMMA );
25012488 }
25022489 }
25032490 mayParseFunctionExpressions = old;
@@ -2559,8 +2546,7 @@ class Parser {
25592546 // `this.<fieldname>=` is expected.
25602547 reportRecoverableError (
25612548 next, fasta.templateExpectedButGot.withArguments ('.' ));
2562- rewriter.insertToken (
2563- token, new SyntheticToken (TokenType .PERIOD , next.offset));
2549+ rewriter.insertSyntheticToken (token, TokenType .PERIOD );
25642550 token = rewriter.insertSyntheticIdentifier (token.next);
25652551 next = token.next;
25662552 }
@@ -2574,8 +2560,7 @@ class Parser {
25742560 // then fall through to insert the LHS and `=` of the assignment,
25752561 // otherwise insert an `=` and synthetic identifier.
25762562 if (! next2.isOperator && ! optional ('.' , next2)) {
2577- token = rewriter.insertToken (
2578- next, new SyntheticToken (TokenType .EQ , next2.offset));
2563+ token = rewriter.insertSyntheticToken (next, TokenType .EQ );
25792564 token = insertSyntheticIdentifier (token, IdentifierContext .expression,
25802565 message: fasta.messageMissingAssignmentInInitializer,
25812566 messageOnToken: next);
@@ -2586,8 +2571,7 @@ class Parser {
25862571 token = insertSyntheticIdentifier (
25872572 token, IdentifierContext .fieldInitializer,
25882573 message: fasta.messageExpectedAnInitializer, messageOnToken: token);
2589- token = rewriter.insertToken (
2590- token, new SyntheticToken (TokenType .EQ , token.offset));
2574+ token = rewriter.insertSyntheticToken (token, TokenType .EQ );
25912575 token = rewriter.insertSyntheticIdentifier (token);
25922576 return parseInitializerExpressionRest (beforeExpression);
25932577 }
@@ -2600,7 +2584,7 @@ class Parser {
26002584 token = insertSyntheticIdentifier (
26012585 beforeExpression, IdentifierContext .fieldInitializer,
26022586 message: fasta.messageMissingAssignmentInInitializer);
2603- rewriter.insertToken (token, new SyntheticToken ( TokenType .EQ , token.offset) );
2587+ rewriter.insertSyntheticToken (token, TokenType .EQ );
26042588 return parseInitializerExpressionRest (beforeExpression);
26052589 }
26062590
@@ -2745,9 +2729,7 @@ class Parser {
27452729 // for users to understand and fix the error.
27462730 reportRecoverableError (findPreviousNonZeroLengthToken (token),
27472731 fasta.templateExpectedAfterButGot.withArguments (';' ));
2748-
2749- return rewriter.insertToken (
2750- token, new SyntheticToken (TokenType .SEMICOLON , next.charOffset));
2732+ return rewriter.insertSyntheticToken (token, TokenType .SEMICOLON );
27512733 }
27522734
27532735 /// Report an error at the token after [token] that has the given [message] .
@@ -4523,7 +4505,6 @@ class Parser {
45234505 token = typeParamOrArg.parseArguments (start, this );
45244506 if (optional ('{' , next)) {
45254507 if (typeParamOrArg.typeArgumentCount > 2 ) {
4526- // TODO(danrubel): remove code in listeners which report this error
45274508 listener.handleRecoverableError (
45284509 fasta.messageSetOrMapLiteralTooManyTypeArguments,
45294510 start.next,
@@ -5364,34 +5345,27 @@ class Parser {
53645345 // Recovery
53655346 reportRecoverableError (
53665347 leftParenthesis, fasta.templateExpectedButGot.withArguments ('(' ));
5367- int offset = leftParenthesis.offset;
53685348
5369- BeginToken openParen = forToken
5370- .setNext (new SyntheticBeginToken (TokenType .OPEN_PAREN , offset));
5349+ BeginToken openParen = rewriter.insertToken (
5350+ forToken,
5351+ new SyntheticBeginToken (
5352+ TokenType .OPEN_PAREN , leftParenthesis.offset));
53715353
5372- Token loopPart ;
5354+ Token token ;
53735355 if (awaitToken != null ) {
5374- loopPart = openParen.setNext (
5375- new SyntheticStringToken (TokenType .IDENTIFIER , '' , offset));
5376- loopPart =
5377- loopPart.setNext (new SyntheticKeywordToken (Keyword .IN , offset));
5378- loopPart = loopPart.setNext (
5379- new SyntheticStringToken (TokenType .IDENTIFIER , '' , offset));
5356+ token = rewriter.insertSyntheticIdentifier (openParen);
5357+ token = rewriter.insertSyntheticKeyword (token, Keyword .IN );
5358+ token = rewriter.insertSyntheticIdentifier (token);
53805359 } else {
5381- loopPart =
5382- openParen.setNext (new SyntheticToken (TokenType .SEMICOLON , offset));
5383- loopPart =
5384- loopPart.setNext (new SyntheticToken (TokenType .SEMICOLON , offset));
5360+ token = rewriter.insertSyntheticToken (openParen, TokenType .SEMICOLON );
5361+ token = rewriter.insertSyntheticToken (token, TokenType .SEMICOLON );
53855362 }
53865363
5387- Token closeParen =
5388- loopPart.setNext (new SyntheticToken (TokenType .CLOSE_PAREN , offset));
5389- openParen.endGroup = closeParen;
5390- Token identifier = closeParen
5391- .setNext (new SyntheticStringToken (TokenType .IDENTIFIER , '' , offset));
5392- Token semicolon =
5393- identifier.setNext (new SyntheticToken (TokenType .SEMICOLON , offset));
5394- semicolon.setNext (leftParenthesis);
5364+ openParen.endGroup = token = rewriter.insertToken (token,
5365+ new SyntheticToken (TokenType .CLOSE_PAREN , leftParenthesis.offset));
5366+
5367+ token = rewriter.insertSyntheticIdentifier (token);
5368+ rewriter.insertSyntheticToken (token, TokenType .SEMICOLON );
53955369
53965370 leftParenthesis = openParen;
53975371 }
@@ -5400,7 +5374,7 @@ class Parser {
54005374 // parses the metadata, modifiers, and type of a local variable
54015375 // declaration if it exists. This enables capturing [beforeIdentifier]
54025376 // for later error reporting.
5403- return parseExpressionStatementOrDeclaration (forToken.next , true );
5377+ return parseExpressionStatementOrDeclaration (leftParenthesis , true );
54045378 }
54055379
54065380 /// Parse the remainder of the local variable declaration
@@ -5586,8 +5560,7 @@ class Parser {
55865560 if (! optional ('while' , whileToken)) {
55875561 reportRecoverableError (
55885562 whileToken, fasta.templateExpectedButGot.withArguments ('while' ));
5589- whileToken = rewriter.insertToken (token,
5590- new SyntheticKeywordToken (Keyword .WHILE , whileToken.charOffset));
5563+ whileToken = rewriter.insertSyntheticKeyword (token, Keyword .WHILE );
55915564 }
55925565 token = ensureParenthesizedCondition (whileToken);
55935566 token = ensureSemicolon (token);
@@ -5813,8 +5786,8 @@ class Parser {
58135786 rewriter.moveSynthetic (exceptionName, openParens.endGroup);
58145787 comma = null ;
58155788 } else {
5816- comma = rewriter. insertToken (exceptionName,
5817- new SyntheticToken ( TokenType . COMMA , comma.charOffset) );
5789+ comma =
5790+ rewriter. insertSyntheticToken (exceptionName, TokenType . COMMA );
58185791 }
58195792 }
58205793 if (comma != null ) {
@@ -6168,8 +6141,7 @@ class Parser {
61686141 next = next.next;
61696142 } else {
61706143 reportRecoverableError (next, fasta.messageMissingOperatorKeyword);
6171- rewriter.insertToken (
6172- beforeName, new SyntheticToken (Keyword .OPERATOR , next.offset));
6144+ rewriter.insertSyntheticKeyword (beforeName, Keyword .OPERATOR );
61736145 }
61746146
61756147 assert ((next.isOperator && next.endGroup == null ) ||
@@ -6265,9 +6237,7 @@ class Parser {
62656237 Token recoverFromStackOverflow (Token token) {
62666238 Token next = token.next;
62676239 reportRecoverableError (next, fasta.messageStackOverflow);
6268-
6269- next = new SyntheticToken (TokenType .SEMICOLON , token.offset);
6270- rewriter.insertToken (token, next);
6240+ next = rewriter.insertSyntheticToken (token, TokenType .SEMICOLON );
62716241 listener.handleEmptyStatement (next);
62726242
62736243 while (notEofOrValue ('}' , next)) {
0 commit comments