| Index: pkg/analyzer/lib/src/generated/parser.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
|
| index 409960d38de0834a2641b739f6d149b0d51f8913..411f6a945aef94b069713388d253027542167140 100644
|
| --- a/pkg/analyzer/lib/src/generated/parser.dart
|
| +++ b/pkg/analyzer/lib/src/generated/parser.dart
|
| @@ -8,6 +8,7 @@ import 'dart:collection';
|
| import "dart:math" as math;
|
|
|
| import 'package:analyzer/dart/ast/ast.dart';
|
| +import 'package:analyzer/dart/ast/standard_ast_factory.dart';
|
| import 'package:analyzer/dart/ast/token.dart';
|
| import 'package:analyzer/error/error.dart';
|
| import 'package:analyzer/error/listener.dart';
|
| @@ -393,14 +394,15 @@ class Parser {
|
| } else {
|
| syntheticToken = _createSyntheticToken(TokenType.IDENTIFIER);
|
| }
|
| - return new SimpleIdentifier(syntheticToken, isDeclaration: isDeclaration);
|
| + return astFactory.simpleIdentifier(syntheticToken,
|
| + isDeclaration: isDeclaration);
|
| }
|
|
|
| /**
|
| * Return a synthetic string literal.
|
| */
|
| - SimpleStringLiteral createSyntheticStringLiteral() =>
|
| - new SimpleStringLiteral(_createSyntheticToken(TokenType.STRING), "");
|
| + SimpleStringLiteral createSyntheticStringLiteral() => astFactory
|
| + .simpleStringLiteral(_createSyntheticToken(TokenType.STRING), "");
|
|
|
| /**
|
| * Advance to the next token in the token stream, making it the new current
|
| @@ -599,12 +601,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type.isAdditiveOperator) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseMultiplicativeExpression();
|
| }
|
| while (_currentToken.type.isAdditiveOperator) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseMultiplicativeExpression());
|
| }
|
| return expression;
|
| @@ -631,7 +633,8 @@ class Parser {
|
| if (_matches(TokenType.OPEN_PAREN)) {
|
| arguments = parseArgumentList();
|
| }
|
| - return new Annotation(atSign, name, period, constructorName, arguments);
|
| + return astFactory.annotation(
|
| + atSign, name, period, constructorName, arguments);
|
| }
|
|
|
| /**
|
| @@ -653,7 +656,7 @@ class Parser {
|
| // namedArgument can have an identifier followed by a colon.
|
| //
|
| if (_matchesIdentifier() && _tokenMatches(_peek(), TokenType.COLON)) {
|
| - return new NamedExpression(parseLabel(), parseExpression2());
|
| + return astFactory.namedExpression(parseLabel(), parseExpression2());
|
| } else {
|
| return parseExpression2();
|
| }
|
| @@ -674,7 +677,7 @@ class Parser {
|
| ArgumentList parseArgumentList() {
|
| Token leftParenthesis = getAndAdvance();
|
| if (_matches(TokenType.CLOSE_PAREN)) {
|
| - return new ArgumentList(leftParenthesis, null, getAndAdvance());
|
| + return astFactory.argumentList(leftParenthesis, null, getAndAdvance());
|
| }
|
| //
|
| // Even though unnamed arguments must all appear before any named arguments,
|
| @@ -712,7 +715,8 @@ class Parser {
|
| // If there is, then we're more likely missing a comma and should go back
|
| // to parsing arguments.
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| - return new ArgumentList(leftParenthesis, arguments, rightParenthesis);
|
| + return astFactory.argumentList(
|
| + leftParenthesis, arguments, rightParenthesis);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| }
|
| @@ -738,7 +742,7 @@ class Parser {
|
| }
|
| Token rightParen = _expect(TokenType.CLOSE_PAREN);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new AssertStatement(
|
| + return astFactory.assertStatement(
|
| keyword, leftParen, expression, comma, message, rightParen, semicolon);
|
| }
|
|
|
| @@ -755,7 +759,7 @@ class Parser {
|
| Expression parseAssignableExpression(bool primaryAllowed) {
|
| if (_matchesKeyword(Keyword.SUPER)) {
|
| return parseAssignableSelector(
|
| - new SuperExpression(getAndAdvance()), false,
|
| + astFactory.superExpression(getAndAdvance()), false,
|
| allowConditional: false);
|
| }
|
| return _parseAssignableExpressionNotStartingWithSuper(primaryAllowed);
|
| @@ -786,7 +790,7 @@ class Parser {
|
| try {
|
| Expression index = parseExpression2();
|
| Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
|
| - return new IndexExpression.forTarget(
|
| + return astFactory.indexExpressionForTarget(
|
| prefix, leftBracket, index, rightBracket);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| @@ -800,13 +804,14 @@ class Parser {
|
| [_currentToken.lexeme]);
|
| }
|
| Token operator = getAndAdvance();
|
| - return new PropertyAccess(prefix, operator, parseSimpleIdentifier());
|
| + return astFactory.propertyAccess(
|
| + prefix, operator, parseSimpleIdentifier());
|
| } else if (type == TokenType.INDEX) {
|
| _splitIndex();
|
| Token leftBracket = getAndAdvance();
|
| Expression index = parseSimpleIdentifier();
|
| Token rightBracket = getAndAdvance();
|
| - return new IndexExpression.forTarget(
|
| + return astFactory.indexExpressionForTarget(
|
| prefix, leftBracket, index, rightBracket);
|
| } else {
|
| if (!optional) {
|
| @@ -830,7 +835,7 @@ class Parser {
|
| AwaitExpression parseAwaitExpression() {
|
| Token awaitToken = getAndAdvance();
|
| Expression expression = parseUnaryExpression();
|
| - return new AwaitExpression(awaitToken, expression);
|
| + return astFactory.awaitExpression(awaitToken, expression);
|
| }
|
|
|
| /**
|
| @@ -845,12 +850,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type == TokenType.AMPERSAND) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseShiftExpression();
|
| }
|
| while (_currentToken.type == TokenType.AMPERSAND) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseShiftExpression());
|
| }
|
| return expression;
|
| @@ -868,12 +873,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type == TokenType.BAR) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseBitwiseXorExpression();
|
| }
|
| while (_currentToken.type == TokenType.BAR) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseBitwiseXorExpression());
|
| }
|
| return expression;
|
| @@ -891,12 +896,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type == TokenType.CARET) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseBitwiseAndExpression();
|
| }
|
| while (_currentToken.type == TokenType.CARET) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseBitwiseAndExpression());
|
| }
|
| return expression;
|
| @@ -937,7 +942,7 @@ class Parser {
|
| // there is, then we're more likely missing a semi-colon and should go back
|
| // to parsing statements.
|
| Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
|
| - return new Block(leftBracket, statements, rightBracket);
|
| + return astFactory.block(leftBracket, statements, rightBracket);
|
| }
|
|
|
| /**
|
| @@ -958,7 +963,7 @@ class Parser {
|
| _reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword);
|
| }
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new BreakStatement(breakKeyword, label, semicolon);
|
| + return astFactory.breakStatement(breakKeyword, label, semicolon);
|
| }
|
|
|
| /**
|
| @@ -992,7 +997,7 @@ class Parser {
|
| try {
|
| Expression index = parseExpression2();
|
| Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
|
| - expression = new IndexExpression.forCascade(
|
| + expression = astFactory.indexExpressionForCascade(
|
| period, leftBracket, index, rightBracket);
|
| period = null;
|
| } finally {
|
| @@ -1009,21 +1014,21 @@ class Parser {
|
| do {
|
| TypeArgumentList typeArguments = _parseOptionalTypeArguments();
|
| if (functionName != null) {
|
| - expression = new MethodInvocation(expression, period, functionName,
|
| - typeArguments, parseArgumentList());
|
| + expression = astFactory.methodInvocation(expression, period,
|
| + functionName, typeArguments, parseArgumentList());
|
| period = null;
|
| functionName = null;
|
| } else if (expression == null) {
|
| // It should not be possible to get here.
|
| - expression = new MethodInvocation(expression, period,
|
| + expression = astFactory.methodInvocation(expression, period,
|
| createSyntheticIdentifier(), typeArguments, parseArgumentList());
|
| } else {
|
| - expression = new FunctionExpressionInvocation(
|
| + expression = astFactory.functionExpressionInvocation(
|
| expression, typeArguments, parseArgumentList());
|
| }
|
| } while (_isLikelyArgumentList());
|
| } else if (functionName != null) {
|
| - expression = new PropertyAccess(expression, period, functionName);
|
| + expression = astFactory.propertyAccess(expression, period, functionName);
|
| period = null;
|
| }
|
| assert(expression != null);
|
| @@ -1038,14 +1043,14 @@ class Parser {
|
| TypeArgumentList typeArguments = _parseOptionalTypeArguments();
|
| Expression currentExpression = expression;
|
| if (currentExpression is PropertyAccess) {
|
| - expression = new MethodInvocation(
|
| + expression = astFactory.methodInvocation(
|
| currentExpression.target,
|
| currentExpression.operator,
|
| currentExpression.propertyName,
|
| typeArguments,
|
| parseArgumentList());
|
| } else {
|
| - expression = new FunctionExpressionInvocation(
|
| + expression = astFactory.functionExpressionInvocation(
|
| expression, typeArguments, parseArgumentList());
|
| }
|
| }
|
| @@ -1054,7 +1059,7 @@ class Parser {
|
| if (_currentToken.type.isAssignmentOperator) {
|
| Token operator = getAndAdvance();
|
| _ensureAssignable(expression);
|
| - expression = new AssignmentExpression(
|
| + expression = astFactory.assignmentExpression(
|
| expression, operator, parseExpressionWithoutCascade());
|
| }
|
| return expression;
|
| @@ -1176,7 +1181,7 @@ class Parser {
|
| rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY);
|
| }
|
| - ClassDeclaration classDeclaration = new ClassDeclaration(
|
| + ClassDeclaration classDeclaration = astFactory.classDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| abstractKeyword,
|
| @@ -1207,8 +1212,8 @@ class Parser {
|
| Modifiers modifiers = parseModifiers();
|
| Keyword keyword = _currentToken.keyword;
|
| if (keyword == Keyword.VOID) {
|
| - TypeName returnType =
|
| - new TypeName(new SimpleIdentifier(getAndAdvance()), null);
|
| + TypeName returnType = astFactory.typeName(
|
| + astFactory.simpleIdentifier(getAndAdvance()), null);
|
| keyword = _currentToken.keyword;
|
| Token next = _peek();
|
| bool isFollowedByIdentifier = _tokenMatchesIdentifier(next);
|
| @@ -1327,14 +1332,15 @@ class Parser {
|
| // We appear to have found an incomplete field declaration.
|
| //
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
|
| - VariableDeclaration variable =
|
| - new VariableDeclaration(createSyntheticIdentifier(), null, null);
|
| + VariableDeclaration variable = astFactory.variableDeclaration(
|
| + createSyntheticIdentifier(), null, null);
|
| List<VariableDeclaration> variables = <VariableDeclaration>[variable];
|
| - return new FieldDeclaration(
|
| + return astFactory.fieldDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| null,
|
| - new VariableDeclarationList(null, null, keyword, null, variables),
|
| + astFactory.variableDeclarationList(
|
| + null, null, keyword, null, variables),
|
| _expect(TokenType.SEMICOLON));
|
| }
|
| _reportErrorForToken(
|
| @@ -1347,7 +1353,7 @@ class Parser {
|
| // to loose, so we'll treat it as a method declaration with a missing
|
| // name, parameters and empty body.
|
| //
|
| - return new MethodDeclaration(
|
| + return astFactory.methodDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| null,
|
| @@ -1357,9 +1363,10 @@ class Parser {
|
| null,
|
| createSyntheticIdentifier(isDeclaration: true),
|
| null,
|
| - new FormalParameterList(
|
| + astFactory.formalParameterList(
|
| null, <FormalParameter>[], null, null, null),
|
| - new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)));
|
| + astFactory
|
| + .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)));
|
| }
|
| return null;
|
| } else if (_tokenMatches(next, TokenType.PERIOD) &&
|
| @@ -1387,7 +1394,7 @@ class Parser {
|
| modifiers.externalKeyword,
|
| _validateModifiersForConstructor(modifiers),
|
| modifiers.factoryKeyword,
|
| - new SimpleIdentifier(methodName.token, isDeclaration: false),
|
| + astFactory.simpleIdentifier(methodName.token, isDeclaration: false),
|
| null,
|
| null,
|
| parameters);
|
| @@ -1495,7 +1502,7 @@ class Parser {
|
| modifiers.externalKeyword,
|
| _validateModifiersForConstructor(modifiers),
|
| modifiers.factoryKeyword,
|
| - new SimpleIdentifier(methodName.token, isDeclaration: true),
|
| + astFactory.simpleIdentifier(methodName.token, isDeclaration: true),
|
| null,
|
| null,
|
| parameters);
|
| @@ -1563,9 +1570,9 @@ class Parser {
|
| */
|
| Combinator parseCombinator() {
|
| if (_matchesString(_SHOW)) {
|
| - return new ShowCombinator(getAndAdvance(), parseIdentifierList());
|
| + return astFactory.showCombinator(getAndAdvance(), parseIdentifierList());
|
| } else if (_matchesString(_HIDE)) {
|
| - return new HideCombinator(getAndAdvance(), parseIdentifierList());
|
| + return astFactory.hideCombinator(getAndAdvance(), parseIdentifierList());
|
| }
|
| return null;
|
| }
|
| @@ -1645,7 +1652,8 @@ class Parser {
|
| Token syntheticToken =
|
| new SyntheticStringToken(TokenType.IDENTIFIER, "", sourceOffset);
|
| syntheticToken.setNext(firstToken);
|
| - return new CommentReference(null, new SimpleIdentifier(syntheticToken));
|
| + return astFactory.commentReference(
|
| + null, astFactory.simpleIdentifier(syntheticToken));
|
| }
|
| Token newKeyword = null;
|
| if (_tokenMatchesKeyword(firstToken, Keyword.NEW)) {
|
| @@ -1656,16 +1664,16 @@ class Parser {
|
| if (firstToken.next.type != TokenType.EOF) {
|
| return null;
|
| }
|
| - Identifier identifier = new SimpleIdentifier(firstToken);
|
| - return new CommentReference(null, identifier);
|
| + Identifier identifier = astFactory.simpleIdentifier(firstToken);
|
| + return astFactory.commentReference(null, identifier);
|
| } else if (_tokenMatchesKeyword(firstToken, Keyword.OPERATOR)) {
|
| Token secondToken = firstToken.next;
|
| if (secondToken.isUserDefinableOperator) {
|
| if (secondToken.next.type != TokenType.EOF) {
|
| return null;
|
| }
|
| - Identifier identifier = new SimpleIdentifier(secondToken);
|
| - return new CommentReference(null, identifier);
|
| + Identifier identifier = astFactory.simpleIdentifier(secondToken);
|
| + return astFactory.commentReference(null, identifier);
|
| }
|
| return null;
|
| } else if (_tokenMatchesIdentifier(firstToken)) {
|
| @@ -1675,37 +1683,37 @@ class Parser {
|
| Identifier identifier;
|
| if (_tokenMatches(secondToken, TokenType.PERIOD)) {
|
| if (thirdToken.isUserDefinableOperator) {
|
| - identifier = new PrefixedIdentifier(
|
| - new SimpleIdentifier(firstToken),
|
| + identifier = astFactory.prefixedIdentifier(
|
| + astFactory.simpleIdentifier(firstToken),
|
| secondToken,
|
| - new SimpleIdentifier(thirdToken));
|
| + astFactory.simpleIdentifier(thirdToken));
|
| nextToken = thirdToken.next;
|
| } else if (_tokenMatchesKeyword(thirdToken, Keyword.OPERATOR)) {
|
| Token fourthToken = thirdToken.next;
|
| if (fourthToken.isUserDefinableOperator) {
|
| - identifier = new PrefixedIdentifier(
|
| - new SimpleIdentifier(firstToken),
|
| + identifier = astFactory.prefixedIdentifier(
|
| + astFactory.simpleIdentifier(firstToken),
|
| secondToken,
|
| - new SimpleIdentifier(fourthToken));
|
| + astFactory.simpleIdentifier(fourthToken));
|
| nextToken = fourthToken.next;
|
| } else {
|
| return null;
|
| }
|
| } else if (_tokenMatchesIdentifier(thirdToken)) {
|
| - identifier = new PrefixedIdentifier(
|
| - new SimpleIdentifier(firstToken),
|
| + identifier = astFactory.prefixedIdentifier(
|
| + astFactory.simpleIdentifier(firstToken),
|
| secondToken,
|
| - new SimpleIdentifier(thirdToken));
|
| + astFactory.simpleIdentifier(thirdToken));
|
| nextToken = thirdToken.next;
|
| }
|
| } else {
|
| - identifier = new SimpleIdentifier(firstToken);
|
| + identifier = astFactory.simpleIdentifier(firstToken);
|
| nextToken = firstToken.next;
|
| }
|
| if (nextToken.type != TokenType.EOF) {
|
| return null;
|
| }
|
| - return new CommentReference(newKeyword, identifier);
|
| + return astFactory.commentReference(newKeyword, identifier);
|
| } else {
|
| Keyword keyword = firstToken.keyword;
|
| if (keyword == Keyword.THIS ||
|
| @@ -1795,8 +1803,8 @@ class Parser {
|
| TokenType.IDENTIFIER, '', nameOffset);
|
| }
|
| nameToken.setNext(new SimpleToken(TokenType.EOF, nameToken.end));
|
| - references.add(
|
| - new CommentReference(null, new SimpleIdentifier(nameToken)));
|
| + references.add(astFactory.commentReference(
|
| + null, astFactory.simpleIdentifier(nameToken)));
|
| token.references.add(nameToken);
|
| // next character
|
| rightIndex = leftIndex + 1;
|
| @@ -1840,7 +1848,7 @@ class Parser {
|
| Token firstToken = _currentToken;
|
| ScriptTag scriptTag = null;
|
| if (_matches(TokenType.SCRIPT_TAG)) {
|
| - scriptTag = new ScriptTag(getAndAdvance());
|
| + scriptTag = astFactory.scriptTag(getAndAdvance());
|
| }
|
| //
|
| // Even though all directives must appear before declarations and must occur
|
| @@ -1971,7 +1979,7 @@ class Parser {
|
| // }
|
| }
|
| }
|
| - return new CompilationUnit(
|
| + return astFactory.compilationUnit(
|
| firstToken, scriptTag, directives, declarations, _currentToken);
|
| }
|
|
|
| @@ -2012,8 +2020,8 @@ class Parser {
|
| _validateModifiersForEnum(modifiers);
|
| return parseEnumDeclaration(commentAndMetadata);
|
| } else if (keyword == Keyword.VOID) {
|
| - TypeName returnType =
|
| - new TypeName(new SimpleIdentifier(getAndAdvance()), null);
|
| + TypeName returnType = astFactory.typeName(
|
| + astFactory.simpleIdentifier(getAndAdvance()), null);
|
| keyword = _currentToken.keyword;
|
| next = _peek();
|
| if ((keyword == Keyword.GET || keyword == Keyword.SET) &&
|
| @@ -2052,7 +2060,7 @@ class Parser {
|
| // We appear to have a variable declaration with a type of "void".
|
| //
|
| _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| parseVariableDeclarationListAfterType(null,
|
| @@ -2089,13 +2097,14 @@ class Parser {
|
| // We appear to have found an incomplete top-level variable declaration.
|
| //
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
|
| - VariableDeclaration variable =
|
| - new VariableDeclaration(createSyntheticIdentifier(), null, null);
|
| + VariableDeclaration variable = astFactory.variableDeclaration(
|
| + createSyntheticIdentifier(), null, null);
|
| List<VariableDeclaration> variables = <VariableDeclaration>[variable];
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| - new VariableDeclarationList(null, null, keyword, null, variables),
|
| + astFactory.variableDeclarationList(
|
| + null, null, keyword, null, variables),
|
| _expect(TokenType.SEMICOLON));
|
| }
|
| _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken);
|
| @@ -2119,7 +2128,7 @@ class Parser {
|
| _reportErrorForCurrentToken(
|
| ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
|
| }
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| parseVariableDeclarationListAfterType(
|
| @@ -2142,7 +2151,7 @@ class Parser {
|
| returnType,
|
| getAndAdvance()));
|
| } else if (_matches(TokenType.AT)) {
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| parseVariableDeclarationListAfterType(null,
|
| @@ -2158,13 +2167,14 @@ class Parser {
|
| } else {
|
| semicolon = _createSyntheticToken(TokenType.SEMICOLON);
|
| }
|
| - VariableDeclaration variable =
|
| - new VariableDeclaration(createSyntheticIdentifier(), null, null);
|
| + VariableDeclaration variable = astFactory.variableDeclaration(
|
| + createSyntheticIdentifier(), null, null);
|
| List<VariableDeclaration> variables = <VariableDeclaration>[variable];
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| - new VariableDeclarationList(null, null, null, returnType, variables),
|
| + astFactory.variableDeclarationList(
|
| + null, null, null, returnType, variables),
|
| semicolon);
|
| } else if (next.matchesAny(const <TokenType>[
|
| TokenType.OPEN_PAREN,
|
| @@ -2176,7 +2186,7 @@ class Parser {
|
| return parseFunctionDeclaration(
|
| commentAndMetadata, modifiers.externalKeyword, returnType);
|
| }
|
| - return new TopLevelVariableDeclaration(
|
| + return astFactory.topLevelVariableDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| parseVariableDeclarationListAfterType(
|
| @@ -2200,7 +2210,7 @@ class Parser {
|
| Expression thenExpression = parseExpressionWithoutCascade();
|
| Token colon = _expect(TokenType.COLON);
|
| Expression elseExpression = parseExpressionWithoutCascade();
|
| - return new ConditionalExpression(
|
| + return astFactory.conditionalExpression(
|
| condition, question, thenExpression, colon, elseExpression);
|
| }
|
|
|
| @@ -2234,8 +2244,8 @@ class Parser {
|
| }
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| StringLiteral libraryUri = _parseUri();
|
| - return new Configuration(ifKeyword, leftParenthesis, name, equalToken,
|
| - value, rightParenthesis, libraryUri);
|
| + return astFactory.configuration(ifKeyword, leftParenthesis, name,
|
| + equalToken, value, rightParenthesis, libraryUri);
|
| }
|
|
|
| /**
|
| @@ -2292,8 +2302,12 @@ class Parser {
|
| type != TokenType.FUNCTION) {
|
| equals = _createSyntheticToken(TokenType.EQ);
|
| } else {
|
| - return new ConstructorFieldInitializer(keywordToken, period, fieldName,
|
| - _createSyntheticToken(TokenType.EQ), createSyntheticIdentifier());
|
| + return astFactory.constructorFieldInitializer(
|
| + keywordToken,
|
| + period,
|
| + fieldName,
|
| + _createSyntheticToken(TokenType.EQ),
|
| + createSyntheticIdentifier());
|
| }
|
| }
|
| bool wasInInitializer = _inInitializer;
|
| @@ -2308,9 +2322,9 @@ class Parser {
|
| cascadeSections.add(section);
|
| }
|
| } while (_matches(TokenType.PERIOD_PERIOD));
|
| - expression = new CascadeExpression(expression, cascadeSections);
|
| + expression = astFactory.cascadeExpression(expression, cascadeSections);
|
| }
|
| - return new ConstructorFieldInitializer(
|
| + return astFactory.constructorFieldInitializer(
|
| keywordToken, period, fieldName, equals, expression);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| @@ -2332,7 +2346,7 @@ class Parser {
|
| period = getAndAdvance();
|
| name = parseSimpleIdentifier();
|
| }
|
| - return new ConstructorName(type, period, name);
|
| + return astFactory.constructorName(type, period, name);
|
| }
|
|
|
| /**
|
| @@ -2358,7 +2372,7 @@ class Parser {
|
| ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyword);
|
| }
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new ContinueStatement(continueKeyword, label, semicolon);
|
| + return astFactory.continueStatement(continueKeyword, label, semicolon);
|
| }
|
|
|
| /**
|
| @@ -2411,7 +2425,7 @@ class Parser {
|
| Token firstToken = _currentToken;
|
| ScriptTag scriptTag = null;
|
| if (_matches(TokenType.SCRIPT_TAG)) {
|
| - scriptTag = new ScriptTag(getAndAdvance());
|
| + scriptTag = astFactory.scriptTag(getAndAdvance());
|
| }
|
| List<Directive> directives = <Directive>[];
|
| while (!_matches(TokenType.EOF)) {
|
| @@ -2432,11 +2446,11 @@ class Parser {
|
| while (!_matches(TokenType.EOF)) {
|
| _advance();
|
| }
|
| - return new CompilationUnit(
|
| + return astFactory.compilationUnit(
|
| firstToken, scriptTag, directives, null, _currentToken);
|
| }
|
| }
|
| - return new CompilationUnit(
|
| + return astFactory.compilationUnit(
|
| firstToken, scriptTag, directives, null, _currentToken);
|
| }
|
|
|
| @@ -2454,7 +2468,7 @@ class Parser {
|
| return null;
|
| }
|
| List<CommentReference> references = parseCommentReferences(tokens);
|
| - return Comment.createDocumentationCommentWithReferences(tokens, references);
|
| + return astFactory.documentationComment(tokens, references);
|
| }
|
|
|
| /**
|
| @@ -2505,8 +2519,8 @@ class Parser {
|
| Expression condition = parseExpression2();
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis,
|
| - condition, rightParenthesis, semicolon);
|
| + return astFactory.doStatement(doKeyword, body, whileKeyword,
|
| + leftParenthesis, condition, rightParenthesis, semicolon);
|
| } finally {
|
| _inLoop = wasInLoop;
|
| }
|
| @@ -2525,7 +2539,7 @@ class Parser {
|
| while (_optional(TokenType.PERIOD)) {
|
| components.add(parseSimpleIdentifier());
|
| }
|
| - return new DottedName(components);
|
| + return astFactory.dottedName(components);
|
| }
|
|
|
| /**
|
| @@ -2536,7 +2550,7 @@ class Parser {
|
| * emptyStatement ::=
|
| * ';'
|
| */
|
| - Statement parseEmptyStatement() => new EmptyStatement(getAndAdvance());
|
| + Statement parseEmptyStatement() => astFactory.emptyStatement(getAndAdvance());
|
|
|
| /**
|
| * Parse an enum declaration. The [commentAndMetadata] is the metadata to be
|
| @@ -2577,7 +2591,7 @@ class Parser {
|
| rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_ENUM_BODY);
|
| }
|
| - return new EnumDeclaration(
|
| + return astFactory.enumDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| keyword,
|
| @@ -2599,7 +2613,7 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type.isEqualityOperator) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseRelationalExpression();
|
| }
|
| @@ -2609,7 +2623,7 @@ class Parser {
|
| _reportErrorForNode(
|
| ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression);
|
| }
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseRelationalExpression());
|
| leftEqualityExpression = true;
|
| }
|
| @@ -2631,7 +2645,7 @@ class Parser {
|
| List<Configuration> configurations = _parseConfigurations();
|
| List<Combinator> combinators = parseCombinators();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new ExportDirective(
|
| + return astFactory.exportDirective(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| exportKeyword,
|
| @@ -2684,11 +2698,12 @@ class Parser {
|
| cascadeSections.add(section);
|
| }
|
| } while (_currentToken.type == TokenType.PERIOD_PERIOD);
|
| - return new CascadeExpression(expression, cascadeSections);
|
| + return astFactory.cascadeExpression(expression, cascadeSections);
|
| } else if (type.isAssignmentOperator) {
|
| Token operator = getAndAdvance();
|
| _ensureAssignable(expression);
|
| - return new AssignmentExpression(expression, operator, parseExpression2());
|
| + return astFactory.assignmentExpression(
|
| + expression, operator, parseExpression2());
|
| }
|
| return expression;
|
| }
|
| @@ -2732,7 +2747,7 @@ class Parser {
|
| if (_currentToken.type.isAssignmentOperator) {
|
| Token operator = getAndAdvance();
|
| _ensureAssignable(expression);
|
| - expression = new AssignmentExpression(
|
| + expression = astFactory.assignmentExpression(
|
| expression, operator, parseExpressionWithoutCascade());
|
| }
|
| return expression;
|
| @@ -2751,7 +2766,7 @@ class Parser {
|
| Token keyword = getAndAdvance();
|
| TypeName superclass = parseTypeName(false);
|
| _mustNotBeNullable(superclass, ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS);
|
| - return new ExtendsClause(keyword, superclass);
|
| + return astFactory.extendsClause(keyword, superclass);
|
| }
|
|
|
| /**
|
| @@ -2822,7 +2837,7 @@ class Parser {
|
| ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parameter);
|
| kind = ParameterKind.POSITIONAL;
|
| }
|
| - return new DefaultFormalParameter(
|
| + return astFactory.defaultFormalParameter(
|
| parameter, kind, separator, defaultValue);
|
| } else if (type == TokenType.COLON) {
|
| Token separator = getAndAdvance();
|
| @@ -2836,10 +2851,10 @@ class Parser {
|
| ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter);
|
| kind = ParameterKind.NAMED;
|
| }
|
| - return new DefaultFormalParameter(
|
| + return astFactory.defaultFormalParameter(
|
| parameter, kind, separator, defaultValue);
|
| } else if (kind != ParameterKind.REQUIRED) {
|
| - return new DefaultFormalParameter(parameter, kind, null, null);
|
| + return astFactory.defaultFormalParameter(parameter, kind, null, null);
|
| }
|
| return parameter;
|
| }
|
| @@ -2912,9 +2927,12 @@ class Parser {
|
| (_tokenMatchesKeyword(_peek(), Keyword.IN) ||
|
| _tokenMatches(_peek(), TokenType.COLON))) {
|
| SimpleIdentifier variableName = _parseSimpleIdentifierUnchecked();
|
| - variableList = new VariableDeclarationList(commentAndMetadata.comment,
|
| - commentAndMetadata.metadata, null, null, <VariableDeclaration>[
|
| - new VariableDeclaration(variableName, null, null)
|
| + variableList = astFactory.variableDeclarationList(
|
| + commentAndMetadata.comment,
|
| + commentAndMetadata.metadata,
|
| + null,
|
| + null, <VariableDeclaration>[
|
| + astFactory.variableDeclaration(variableName, null, null)
|
| ]);
|
| } else if (isInitializedVariableDeclaration()) {
|
| variableList =
|
| @@ -2948,12 +2966,12 @@ class Parser {
|
| Token keyword = variableList.keyword;
|
| TypeName type = variableList.type;
|
| if (keyword != null || type != null) {
|
| - loopVariable = new DeclaredIdentifier(
|
| + loopVariable = astFactory.declaredIdentifier(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| keyword,
|
| type,
|
| - new SimpleIdentifier(variable.name.token,
|
| + astFactory.simpleIdentifier(variable.name.token,
|
| isDeclaration: true));
|
| } else {
|
| if (commentAndMetadata.hasMetadata) {
|
| @@ -2969,7 +2987,7 @@ class Parser {
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| Statement body = parseStatement2();
|
| if (loopVariable == null) {
|
| - return new ForEachStatement.withReference(
|
| + return astFactory.forEachStatementWithReference(
|
| awaitKeyword,
|
| forKeyword,
|
| leftParenthesis,
|
| @@ -2979,7 +2997,7 @@ class Parser {
|
| rightParenthesis,
|
| body);
|
| }
|
| - return new ForEachStatement.withDeclaration(
|
| + return astFactory.forEachStatementWithDeclaration(
|
| awaitKeyword,
|
| forKeyword,
|
| leftParenthesis,
|
| @@ -3006,7 +3024,7 @@ class Parser {
|
| }
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| Statement body = parseStatement2();
|
| - return new ForStatement(
|
| + return astFactory.forStatement(
|
| forKeyword,
|
| leftParenthesis,
|
| variableList,
|
| @@ -3053,7 +3071,7 @@ class Parser {
|
| if (!mayBeEmpty) {
|
| _reportErrorForCurrentToken(emptyErrorCode);
|
| }
|
| - return new EmptyFunctionBody(getAndAdvance());
|
| + return astFactory.emptyFunctionBody(getAndAdvance());
|
| }
|
| Token keyword = null;
|
| Token star = null;
|
| @@ -3102,10 +3120,10 @@ class Parser {
|
| semicolon = _expect(TokenType.SEMICOLON);
|
| }
|
| if (!_parseFunctionBodies) {
|
| - return new EmptyFunctionBody(
|
| - _createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| - return new ExpressionFunctionBody(
|
| + return astFactory.expressionFunctionBody(
|
| keyword, functionDefinition, expression, semicolon);
|
| } else if (type == TokenType.OPEN_CURLY_BRACKET) {
|
| if (keyword != null) {
|
| @@ -3116,23 +3134,23 @@ class Parser {
|
| }
|
| if (!_parseFunctionBodies) {
|
| _skipBlock();
|
| - return new EmptyFunctionBody(
|
| - _createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| - return new BlockFunctionBody(keyword, star, parseBlock());
|
| + return astFactory.blockFunctionBody(keyword, star, parseBlock());
|
| } else if (_matchesString(_NATIVE)) {
|
| Token nativeToken = getAndAdvance();
|
| StringLiteral stringLiteral = null;
|
| if (_matches(TokenType.STRING)) {
|
| stringLiteral = _parseStringLiteralUnchecked();
|
| }
|
| - return new NativeFunctionBody(
|
| + return astFactory.nativeFunctionBody(
|
| nativeToken, stringLiteral, _expect(TokenType.SEMICOLON));
|
| } else {
|
| // Invalid function body
|
| _reportErrorForCurrentToken(emptyErrorCode);
|
| - return new EmptyFunctionBody(
|
| - _createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| } finally {
|
| _inAsync = wasInAsync;
|
| @@ -3170,7 +3188,7 @@ class Parser {
|
| keywordToken = getAndAdvance();
|
| }
|
| if (keywordToken != null && _matches(TokenType.OPEN_PAREN)) {
|
| - name = new SimpleIdentifier(keywordToken, isDeclaration: true);
|
| + name = astFactory.simpleIdentifier(keywordToken, isDeclaration: true);
|
| keywordToken = null;
|
| isGetter = false;
|
| } else {
|
| @@ -3185,7 +3203,7 @@ class Parser {
|
| } else {
|
| _reportErrorForCurrentToken(
|
| ParserErrorCode.MISSING_FUNCTION_PARAMETERS);
|
| - parameters = new FormalParameterList(
|
| + parameters = astFactory.formalParameterList(
|
| _createSyntheticToken(TokenType.OPEN_PAREN),
|
| null,
|
| null,
|
| @@ -3201,21 +3219,21 @@ class Parser {
|
| body = parseFunctionBody(
|
| false, ParserErrorCode.MISSING_FUNCTION_BODY, false);
|
| } else {
|
| - body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
|
| + body = astFactory.emptyFunctionBody(_expect(TokenType.SEMICOLON));
|
| }
|
| // if (!isStatement && matches(TokenType.SEMICOLON)) {
|
| // // TODO(brianwilkerson) Improve this error message.
|
| // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme());
|
| // advance();
|
| // }
|
| - return new FunctionDeclaration(
|
| + return astFactory.functionDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| returnType,
|
| keywordToken,
|
| name,
|
| - new FunctionExpression(typeParameters, parameters, body));
|
| + astFactory.functionExpression(typeParameters, parameters, body));
|
| }
|
|
|
| /**
|
| @@ -3245,7 +3263,7 @@ class Parser {
|
| _validateFormalParameterList(parameters);
|
| FunctionBody body =
|
| parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true);
|
| - return new FunctionExpression(typeParameters, parameters, body);
|
| + return astFactory.functionExpression(typeParameters, parameters, body);
|
| }
|
|
|
| /**
|
| @@ -3281,7 +3299,7 @@ class Parser {
|
| if (externalKeyword != null && body is! EmptyFunctionBody) {
|
| _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY);
|
| }
|
| - return new MethodDeclaration(
|
| + return astFactory.methodDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| @@ -3321,7 +3339,7 @@ class Parser {
|
| Expression parseIfNullExpression() {
|
| Expression expression = parseLogicalOrExpression();
|
| while (_currentToken.type == TokenType.QUESTION_QUESTION) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseLogicalOrExpression());
|
| }
|
| return expression;
|
| @@ -3347,7 +3365,7 @@ class Parser {
|
| elseKeyword = getAndAdvance();
|
| elseStatement = parseStatement2();
|
| }
|
| - return new IfStatement(ifKeyword, leftParenthesis, condition,
|
| + return astFactory.ifStatement(ifKeyword, leftParenthesis, condition,
|
| rightParenthesis, thenStatement, elseKeyword, elseStatement);
|
| }
|
|
|
| @@ -3367,7 +3385,7 @@ class Parser {
|
| _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS);
|
| interfaces.add(typeName);
|
| } while (_optional(TokenType.COMMA));
|
| - return new ImplementsClause(keyword, interfaces);
|
| + return astFactory.implementsClause(keyword, interfaces);
|
| }
|
|
|
| /**
|
| @@ -3413,7 +3431,7 @@ class Parser {
|
| }
|
| List<Combinator> combinators = parseCombinators();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new ImportDirective(
|
| + return astFactory.importDirective(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| importKeyword,
|
| @@ -3452,7 +3470,7 @@ class Parser {
|
| TypeName type) {
|
| VariableDeclarationList fieldList =
|
| parseVariableDeclarationListAfterType(null, keyword, type);
|
| - return new FieldDeclaration(
|
| + return astFactory.fieldDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| staticKeyword,
|
| @@ -3471,7 +3489,7 @@ class Parser {
|
| InstanceCreationExpression parseInstanceCreationExpression(Token keyword) {
|
| ConstructorName constructorName = parseConstructorName();
|
| ArgumentList argumentList = _parseArgumentListChecked();
|
| - return new InstanceCreationExpression(
|
| + return astFactory.instanceCreationExpression(
|
| keyword, constructorName, argumentList);
|
| }
|
|
|
| @@ -3488,7 +3506,7 @@ class Parser {
|
| SimpleIdentifier label =
|
| _parseSimpleIdentifierUnchecked(isDeclaration: isDeclaration);
|
| Token colon = getAndAdvance();
|
| - return new Label(label, colon);
|
| + return astFactory.label(label, colon);
|
| }
|
|
|
| /**
|
| @@ -3507,7 +3525,7 @@ class Parser {
|
| LibraryIdentifier libraryName = _parseLibraryName(
|
| ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE, keyword);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new LibraryDirective(commentAndMetadata.comment,
|
| + return astFactory.libraryDirective(commentAndMetadata.comment,
|
| commentAndMetadata.metadata, keyword, libraryName, semicolon);
|
| }
|
|
|
| @@ -3523,7 +3541,7 @@ class Parser {
|
| while (_optional(TokenType.PERIOD)) {
|
| components.add(parseSimpleIdentifier());
|
| }
|
| - return new LibraryIdentifier(components);
|
| + return astFactory.libraryIdentifier(components);
|
| }
|
|
|
| /**
|
| @@ -3541,12 +3559,12 @@ class Parser {
|
| ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) {
|
| if (_matches(TokenType.INDEX)) {
|
| _splitIndex();
|
| - return new ListLiteral(
|
| + return astFactory.listLiteral(
|
| modifier, typeArguments, getAndAdvance(), null, getAndAdvance());
|
| }
|
| Token leftBracket = getAndAdvance();
|
| if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
|
| - return new ListLiteral(
|
| + return astFactory.listLiteral(
|
| modifier, typeArguments, leftBracket, null, getAndAdvance());
|
| }
|
| bool wasInInitializer = _inInitializer;
|
| @@ -3555,13 +3573,13 @@ class Parser {
|
| List<Expression> elements = <Expression>[parseExpression2()];
|
| while (_optional(TokenType.COMMA)) {
|
| if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
|
| - return new ListLiteral(
|
| + return astFactory.listLiteral(
|
| modifier, typeArguments, leftBracket, elements, getAndAdvance());
|
| }
|
| elements.add(parseExpression2());
|
| }
|
| Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
|
| - return new ListLiteral(
|
| + return astFactory.listLiteral(
|
| modifier, typeArguments, leftBracket, elements, rightBracket);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| @@ -3586,7 +3604,7 @@ class Parser {
|
| return parseListLiteral(modifier, typeArguments);
|
| }
|
| _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL);
|
| - return new ListLiteral(
|
| + return astFactory.listLiteral(
|
| modifier,
|
| typeArguments,
|
| _createSyntheticToken(TokenType.OPEN_SQUARE_BRACKET),
|
| @@ -3604,7 +3622,7 @@ class Parser {
|
| Expression parseLogicalAndExpression() {
|
| Expression expression = parseEqualityExpression();
|
| while (_currentToken.type == TokenType.AMPERSAND_AMPERSAND) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseEqualityExpression());
|
| }
|
| return expression;
|
| @@ -3620,7 +3638,7 @@ class Parser {
|
| Expression parseLogicalOrExpression() {
|
| Expression expression = parseLogicalAndExpression();
|
| while (_currentToken.type == TokenType.BAR_BAR) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseLogicalAndExpression());
|
| }
|
| return expression;
|
| @@ -3641,7 +3659,7 @@ class Parser {
|
| MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
|
| Token leftBracket = getAndAdvance();
|
| if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
|
| - return new MapLiteral(
|
| + return astFactory.mapLiteral(
|
| modifier, typeArguments, leftBracket, null, getAndAdvance());
|
| }
|
| bool wasInInitializer = _inInitializer;
|
| @@ -3650,13 +3668,13 @@ class Parser {
|
| List<MapLiteralEntry> entries = <MapLiteralEntry>[parseMapLiteralEntry()];
|
| while (_optional(TokenType.COMMA)) {
|
| if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
|
| - return new MapLiteral(
|
| + return astFactory.mapLiteral(
|
| modifier, typeArguments, leftBracket, entries, getAndAdvance());
|
| }
|
| entries.add(parseMapLiteralEntry());
|
| }
|
| Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
|
| - return new MapLiteral(
|
| + return astFactory.mapLiteral(
|
| modifier, typeArguments, leftBracket, entries, rightBracket);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| @@ -3673,7 +3691,7 @@ class Parser {
|
| Expression key = parseExpression2();
|
| Token separator = _expect(TokenType.COLON);
|
| Expression value = parseExpression2();
|
| - return new MapLiteralEntry(key, separator, value);
|
| + return astFactory.mapLiteralEntry(key, separator, value);
|
| }
|
|
|
| /**
|
| @@ -3773,12 +3791,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type.isMultiplicativeOperator) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseUnaryExpression();
|
| }
|
| while (_currentToken.type.isMultiplicativeOperator) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseUnaryExpression());
|
| }
|
| return expression;
|
| @@ -3823,7 +3841,7 @@ class Parser {
|
| if (_tokenMatches(_peek(), TokenType.STRING)) {
|
| Token afterString = skipStringLiteral(_currentToken.next);
|
| if (afterString != null && afterString.type == TokenType.COLON) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| }
|
| }
|
| @@ -3846,14 +3864,14 @@ class Parser {
|
| } else if (keyword == Keyword.IF) {
|
| return parseIfStatement();
|
| } else if (keyword == Keyword.RETHROW) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseRethrowExpression(), _expect(TokenType.SEMICOLON));
|
| } else if (keyword == Keyword.RETURN) {
|
| return parseReturnStatement();
|
| } else if (keyword == Keyword.SWITCH) {
|
| return parseSwitchStatement();
|
| } else if (keyword == Keyword.THROW) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseThrowExpression(), _expect(TokenType.SEMICOLON));
|
| } else if (keyword == Keyword.TRY) {
|
| return parseTryStatement();
|
| @@ -3863,8 +3881,8 @@ class Parser {
|
| return parseVariableDeclarationStatementAfterMetadata(
|
| commentAndMetadata);
|
| } else if (keyword == Keyword.VOID) {
|
| - TypeName returnType =
|
| - new TypeName(new SimpleIdentifier(getAndAdvance()), null);
|
| + TypeName returnType = astFactory.typeName(
|
| + astFactory.simpleIdentifier(getAndAdvance()), null);
|
| Token next = _currentToken.next;
|
| if (_matchesIdentifier() &&
|
| next.matchesAny(const <TokenType>[
|
| @@ -3902,7 +3920,8 @@ class Parser {
|
| }
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
|
| // TODO(brianwilkerson) Recover from this error.
|
| - return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| } else if (keyword == Keyword.CONST) {
|
| Token next = _currentToken.next;
|
| @@ -3912,7 +3931,7 @@ class Parser {
|
| TokenType.OPEN_SQUARE_BRACKET,
|
| TokenType.INDEX
|
| ])) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| } else if (_tokenMatches(next, TokenType.IDENTIFIER)) {
|
| Token afterType = skipTypeName(next);
|
| @@ -3921,7 +3940,7 @@ class Parser {
|
| (_tokenMatches(afterType, TokenType.PERIOD) &&
|
| _tokenMatches(afterType.next, TokenType.IDENTIFIER) &&
|
| _tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| }
|
| }
|
| @@ -3934,14 +3953,15 @@ class Parser {
|
| keyword == Keyword.NULL ||
|
| keyword == Keyword.SUPER ||
|
| keyword == Keyword.THIS) {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| } else {
|
| //
|
| // We have found an error of some kind. Try to recover.
|
| //
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
|
| - return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| } else if (_inGenerator && _matchesString(_YIELD)) {
|
| return parseYieldStatement();
|
| @@ -3949,7 +3969,7 @@ class Parser {
|
| if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) {
|
| return parseForStatement();
|
| }
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| } else if (_matchesString(_AWAIT) &&
|
| _tokenMatchesKeyword(_peek(), Keyword.FOR)) {
|
| @@ -3968,9 +3988,10 @@ class Parser {
|
| return parseFunctionDeclarationStatement();
|
| } else if (type == TokenType.CLOSE_CURLY_BRACKET) {
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
|
| - return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| + return astFactory
|
| + .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
|
| } else {
|
| - return new ExpressionStatement(
|
| + return astFactory.expressionStatement(
|
| parseExpression2(), _expect(TokenType.SEMICOLON));
|
| }
|
| }
|
| @@ -4016,16 +4037,16 @@ class Parser {
|
| if (enableNnbd && _matches(TokenType.QUESTION)) {
|
| question = getAndAdvance();
|
| }
|
| - return new FunctionTypedFormalParameter(
|
| + return astFactory.functionTypedFormalParameter(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| holder.type,
|
| - new SimpleIdentifier(identifier.token, isDeclaration: true),
|
| + astFactory.simpleIdentifier(identifier.token, isDeclaration: true),
|
| typeParameters,
|
| parameters,
|
| question: question);
|
| } else {
|
| - return new FieldFormalParameter(
|
| + return astFactory.fieldFormalParameter(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| holder.keyword,
|
| @@ -4055,7 +4076,7 @@ class Parser {
|
| // TODO(brianwilkerson) If there are type parameters but no parameters,
|
| // should we create a synthetic empty parameter list here so we can
|
| // capture the type parameters?
|
| - return new FieldFormalParameter(
|
| + return astFactory.fieldFormalParameter(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| holder.keyword,
|
| @@ -4066,12 +4087,12 @@ class Parser {
|
| null,
|
| null);
|
| }
|
| - return new SimpleFormalParameter(
|
| + return astFactory.simpleFormalParameter(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| holder.keyword,
|
| holder.type,
|
| - new SimpleIdentifier(identifier.token, isDeclaration: true));
|
| + astFactory.simpleIdentifier(identifier.token, isDeclaration: true));
|
| }
|
|
|
| /**
|
| @@ -4147,14 +4168,14 @@ class Parser {
|
| ArgumentList argumentList = parseArgumentList();
|
| Expression currentOperand = operand;
|
| if (currentOperand is PropertyAccess) {
|
| - operand = new MethodInvocation(
|
| + operand = astFactory.methodInvocation(
|
| currentOperand.target,
|
| currentOperand.operator,
|
| currentOperand.propertyName,
|
| typeArguments,
|
| argumentList);
|
| } else {
|
| - operand = new FunctionExpressionInvocation(
|
| + operand = astFactory.functionExpressionInvocation(
|
| operand, typeArguments, argumentList);
|
| }
|
| } else {
|
| @@ -4173,7 +4194,7 @@ class Parser {
|
| }
|
| _ensureAssignable(operand);
|
| Token operator = getAndAdvance();
|
| - return new PostfixExpression(operand, operator);
|
| + return astFactory.postfixExpression(operand, operator);
|
| }
|
|
|
| /**
|
| @@ -4236,25 +4257,25 @@ class Parser {
|
| } on FormatException {
|
| // The invalid format should have been reported by the scanner.
|
| }
|
| - return new IntegerLiteral(token, value);
|
| + return astFactory.integerLiteral(token, value);
|
| }
|
| Keyword keyword = _currentToken.keyword;
|
| if (keyword == Keyword.NULL) {
|
| - return new NullLiteral(getAndAdvance());
|
| + return astFactory.nullLiteral(getAndAdvance());
|
| } else if (keyword == Keyword.NEW) {
|
| return parseNewExpression();
|
| } else if (keyword == Keyword.THIS) {
|
| - return new ThisExpression(getAndAdvance());
|
| + return astFactory.thisExpression(getAndAdvance());
|
| } else if (keyword == Keyword.SUPER) {
|
| // TODO(paulberry): verify with Gilad that "super" must be followed by
|
| // unconditionalAssignableSelector in this case.
|
| return parseAssignableSelector(
|
| - new SuperExpression(getAndAdvance()), false,
|
| + astFactory.superExpression(getAndAdvance()), false,
|
| allowConditional: false);
|
| } else if (keyword == Keyword.FALSE) {
|
| - return new BooleanLiteral(getAndAdvance(), false);
|
| + return astFactory.booleanLiteral(getAndAdvance(), false);
|
| } else if (keyword == Keyword.TRUE) {
|
| - return new BooleanLiteral(getAndAdvance(), true);
|
| + return astFactory.booleanLiteral(getAndAdvance(), true);
|
| }
|
| if (type == TokenType.DOUBLE) {
|
| Token token = getAndAdvance();
|
| @@ -4264,7 +4285,7 @@ class Parser {
|
| } on FormatException {
|
| // The invalid format should have been reported by the scanner.
|
| }
|
| - return new DoubleLiteral(token, value);
|
| + return astFactory.doubleLiteral(token, value);
|
| } else if (type == TokenType.HEXADECIMAL) {
|
| Token token = getAndAdvance();
|
| int value = null;
|
| @@ -4273,7 +4294,7 @@ class Parser {
|
| } on FormatException {
|
| // The invalid format should have been reported by the scanner.
|
| }
|
| - return new IntegerLiteral(token, value);
|
| + return astFactory.integerLiteral(token, value);
|
| } else if (keyword == Keyword.CONST) {
|
| return parseConstExpression();
|
| } else if (type == TokenType.OPEN_PAREN) {
|
| @@ -4286,7 +4307,7 @@ class Parser {
|
| try {
|
| Expression expression = parseExpression2();
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| - return new ParenthesizedExpression(
|
| + return astFactory.parenthesizedExpression(
|
| leftParenthesis, expression, rightParenthesis);
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| @@ -4351,7 +4372,7 @@ class Parser {
|
| }
|
| }
|
| ArgumentList argumentList = _parseArgumentListChecked();
|
| - return new RedirectingConstructorInvocation(
|
| + return astFactory.redirectingConstructorInvocation(
|
| keyword, period, constructorName, argumentList);
|
| }
|
|
|
| @@ -4366,27 +4387,28 @@ class Parser {
|
| Expression parseRelationalExpression() {
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type.isRelationalOperator) {
|
| - Expression expression = new SuperExpression(getAndAdvance());
|
| + Expression expression = astFactory.superExpression(getAndAdvance());
|
| Token operator = getAndAdvance();
|
| - return new BinaryExpression(
|
| + return astFactory.binaryExpression(
|
| expression, operator, parseBitwiseOrExpression());
|
| }
|
| Expression expression = parseBitwiseOrExpression();
|
| Keyword keyword = _currentToken.keyword;
|
| if (keyword == Keyword.AS) {
|
| Token asOperator = getAndAdvance();
|
| - return new AsExpression(expression, asOperator, parseTypeName(true));
|
| + return astFactory.asExpression(
|
| + expression, asOperator, parseTypeName(true));
|
| } else if (keyword == Keyword.IS) {
|
| Token isOperator = getAndAdvance();
|
| Token notOperator = null;
|
| if (_matches(TokenType.BANG)) {
|
| notOperator = getAndAdvance();
|
| }
|
| - return new IsExpression(
|
| + return astFactory.isExpression(
|
| expression, isOperator, notOperator, parseTypeName(true));
|
| } else if (_currentToken.type.isRelationalOperator) {
|
| Token operator = getAndAdvance();
|
| - return new BinaryExpression(
|
| + return astFactory.binaryExpression(
|
| expression, operator, parseBitwiseOrExpression());
|
| }
|
| return expression;
|
| @@ -4400,7 +4422,8 @@ class Parser {
|
| * rethrowExpression ::=
|
| * 'rethrow'
|
| */
|
| - Expression parseRethrowExpression() => new RethrowExpression(getAndAdvance());
|
| + Expression parseRethrowExpression() =>
|
| + astFactory.rethrowExpression(getAndAdvance());
|
|
|
| /**
|
| * Parse a return statement. Return the return statement that was parsed.
|
| @@ -4413,11 +4436,11 @@ class Parser {
|
| Statement parseReturnStatement() {
|
| Token returnKeyword = getAndAdvance();
|
| if (_matches(TokenType.SEMICOLON)) {
|
| - return new ReturnStatement(returnKeyword, null, getAndAdvance());
|
| + return astFactory.returnStatement(returnKeyword, null, getAndAdvance());
|
| }
|
| Expression expression = parseExpression2();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new ReturnStatement(returnKeyword, expression, semicolon);
|
| + return astFactory.returnStatement(returnKeyword, expression, semicolon);
|
| }
|
|
|
| /**
|
| @@ -4429,7 +4452,8 @@ class Parser {
|
| */
|
| TypeName parseReturnType() {
|
| if (_currentToken.keyword == Keyword.VOID) {
|
| - return new TypeName(new SimpleIdentifier(getAndAdvance()), null);
|
| + return astFactory.typeName(
|
| + astFactory.simpleIdentifier(getAndAdvance()), null);
|
| } else {
|
| return parseTypeName(false);
|
| }
|
| @@ -4464,7 +4488,7 @@ class Parser {
|
| if (externalKeyword != null && body is! EmptyFunctionBody) {
|
| _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY);
|
| }
|
| - return new MethodDeclaration(
|
| + return astFactory.methodDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| @@ -4489,12 +4513,12 @@ class Parser {
|
| Expression expression;
|
| if (_currentToken.keyword == Keyword.SUPER &&
|
| _currentToken.next.type.isShiftOperator) {
|
| - expression = new SuperExpression(getAndAdvance());
|
| + expression = astFactory.superExpression(getAndAdvance());
|
| } else {
|
| expression = parseAdditiveExpression();
|
| }
|
| while (_currentToken.type.isShiftOperator) {
|
| - expression = new BinaryExpression(
|
| + expression = astFactory.binaryExpression(
|
| expression, getAndAdvance(), parseAdditiveExpression());
|
| }
|
| return expression;
|
| @@ -4544,7 +4568,7 @@ class Parser {
|
| if (labels == null) {
|
| return statement;
|
| }
|
| - return new LabeledStatement(labels, statement);
|
| + return astFactory.labeledStatement(labels, statement);
|
| }
|
|
|
| /**
|
| @@ -4590,7 +4614,7 @@ class Parser {
|
| constructorName = parseSimpleIdentifier();
|
| }
|
| ArgumentList argumentList = _parseArgumentListChecked();
|
| - return new SuperConstructorInvocation(
|
| + return astFactory.superConstructorInvocation(
|
| keyword, period, constructorName, argumentList);
|
| }
|
|
|
| @@ -4635,15 +4659,15 @@ class Parser {
|
| definedLabels.add(label);
|
| }
|
| Token colon = getAndAdvance();
|
| - labels.add(new Label(identifier, colon));
|
| + labels.add(astFactory.label(identifier, colon));
|
| }
|
| Keyword keyword = _currentToken.keyword;
|
| if (keyword == Keyword.CASE) {
|
| Token caseKeyword = getAndAdvance();
|
| Expression caseExpression = parseExpression2();
|
| Token colon = _expect(TokenType.COLON);
|
| - members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon,
|
| - _parseStatementList()));
|
| + members.add(astFactory.switchCase(labels, caseKeyword, caseExpression,
|
| + colon, _parseStatementList()));
|
| if (defaultKeyword != null) {
|
| _reportErrorForToken(
|
| ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE,
|
| @@ -4656,7 +4680,7 @@ class Parser {
|
| }
|
| defaultKeyword = getAndAdvance();
|
| Token colon = _expect(TokenType.COLON);
|
| - members.add(new SwitchDefault(
|
| + members.add(astFactory.switchDefault(
|
| labels, defaultKeyword, colon, _parseStatementList()));
|
| } else {
|
| // We need to advance, otherwise we could end up in an infinite loop,
|
| @@ -4679,7 +4703,7 @@ class Parser {
|
| type = _currentToken.type;
|
| }
|
| Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
|
| - return new SwitchStatement(keyword, leftParenthesis, expression,
|
| + return astFactory.switchStatement(keyword, leftParenthesis, expression,
|
| rightParenthesis, leftBracket, members, rightBracket);
|
| } finally {
|
| _inSwitch = wasInSwitch;
|
| @@ -4716,7 +4740,7 @@ class Parser {
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
|
| components.add(_createSyntheticToken(TokenType.IDENTIFIER));
|
| }
|
| - return new SymbolLiteral(poundSign, components);
|
| + return astFactory.symbolLiteral(poundSign, components);
|
| }
|
|
|
| /**
|
| @@ -4733,10 +4757,10 @@ class Parser {
|
| if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) {
|
| _reportErrorForToken(
|
| ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken);
|
| - return new ThrowExpression(keyword, createSyntheticIdentifier());
|
| + return astFactory.throwExpression(keyword, createSyntheticIdentifier());
|
| }
|
| Expression expression = parseExpression2();
|
| - return new ThrowExpression(keyword, expression);
|
| + return astFactory.throwExpression(keyword, expression);
|
| }
|
|
|
| /**
|
| @@ -4753,10 +4777,10 @@ class Parser {
|
| if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) {
|
| _reportErrorForToken(
|
| ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken);
|
| - return new ThrowExpression(keyword, createSyntheticIdentifier());
|
| + return astFactory.throwExpression(keyword, createSyntheticIdentifier());
|
| }
|
| Expression expression = parseExpressionWithoutCascade();
|
| - return new ThrowExpression(keyword, expression);
|
| + return astFactory.throwExpression(keyword, expression);
|
| }
|
|
|
| /**
|
| @@ -4806,7 +4830,7 @@ class Parser {
|
| rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| }
|
| Block catchBody = _parseBlockChecked();
|
| - catchClauses.add(new CatchClause(
|
| + catchClauses.add(astFactory.catchClause(
|
| onKeyword,
|
| exceptionType,
|
| catchKeyword,
|
| @@ -4824,7 +4848,7 @@ class Parser {
|
| } else if (catchClauses.isEmpty) {
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY);
|
| }
|
| - return new TryStatement(
|
| + return astFactory.tryStatement(
|
| tryKeyword, body, catchClauses, finallyKeyword, finallyClause);
|
| }
|
|
|
| @@ -4896,7 +4920,7 @@ class Parser {
|
| arguments.add(parseTypeName(false));
|
| }
|
| Token rightBracket = _expectGt();
|
| - return new TypeArgumentList(leftBracket, arguments, rightBracket);
|
| + return astFactory.typeArgumentList(leftBracket, arguments, rightBracket);
|
| }
|
|
|
| /**
|
| @@ -4931,10 +4955,10 @@ class Parser {
|
| if (_matchesKeyword(Keyword.EXTENDS)) {
|
| Token keyword = getAndAdvance();
|
| TypeName bound = parseTypeName(false);
|
| - return new TypeParameter(commentAndMetadata.comment,
|
| + return astFactory.typeParameter(commentAndMetadata.comment,
|
| commentAndMetadata.metadata, name, keyword, bound);
|
| }
|
| - return new TypeParameter(commentAndMetadata.comment,
|
| + return astFactory.typeParameter(commentAndMetadata.comment,
|
| commentAndMetadata.metadata, name, null, null);
|
| }
|
|
|
| @@ -4954,7 +4978,8 @@ class Parser {
|
| typeParameters.add(parseTypeParameter());
|
| }
|
| Token rightBracket = _expectGt();
|
| - return new TypeParameterList(leftBracket, typeParameters, rightBracket);
|
| + return astFactory.typeParameterList(
|
| + leftBracket, typeParameters, rightBracket);
|
| }
|
|
|
| /**
|
| @@ -4982,12 +5007,12 @@ class Parser {
|
| // --> "prefixOperator postfixExpression"
|
| // --> "prefixOperator primary selector*"
|
| // --> "prefixOperator 'super' assignableSelector selector*"
|
| - return new PrefixExpression(operator, parseUnaryExpression());
|
| + return astFactory.prefixExpression(operator, parseUnaryExpression());
|
| }
|
| - return new PrefixExpression(
|
| - operator, new SuperExpression(getAndAdvance()));
|
| + return astFactory.prefixExpression(
|
| + operator, astFactory.superExpression(getAndAdvance()));
|
| }
|
| - return new PrefixExpression(operator, parseUnaryExpression());
|
| + return astFactory.prefixExpression(operator, parseUnaryExpression());
|
| } else if (_currentToken.type.isIncrementOperator) {
|
| Token operator = getAndAdvance();
|
| if (_matchesKeyword(Keyword.SUPER)) {
|
| @@ -4995,7 +5020,7 @@ class Parser {
|
| if (nextType == TokenType.OPEN_SQUARE_BRACKET ||
|
| nextType == TokenType.PERIOD) {
|
| // --> "prefixOperator 'super' assignableSelector selector*"
|
| - return new PrefixExpression(operator, parseUnaryExpression());
|
| + return astFactory.prefixExpression(operator, parseUnaryExpression());
|
| }
|
| //
|
| // Even though it is not valid to use an incrementing operator
|
| @@ -5011,18 +5036,18 @@ class Parser {
|
| secondOperator.setNext(_currentToken);
|
| firstOperator.setNext(secondOperator);
|
| operator.previous.setNext(firstOperator);
|
| - return new PrefixExpression(
|
| + return astFactory.prefixExpression(
|
| firstOperator,
|
| - new PrefixExpression(
|
| - secondOperator, new SuperExpression(getAndAdvance())));
|
| + astFactory.prefixExpression(
|
| + secondOperator, astFactory.superExpression(getAndAdvance())));
|
| }
|
| // Invalid operator before 'super'
|
| _reportErrorForCurrentToken(
|
| ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]);
|
| - return new PrefixExpression(
|
| - operator, new SuperExpression(getAndAdvance()));
|
| + return astFactory.prefixExpression(
|
| + operator, astFactory.superExpression(getAndAdvance()));
|
| }
|
| - return new PrefixExpression(
|
| + return astFactory.prefixExpression(
|
| operator, _parseAssignableExpressionNotStartingWithSuper(false));
|
| } else if (type == TokenType.PLUS) {
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
|
| @@ -5057,7 +5082,7 @@ class Parser {
|
| equals = getAndAdvance();
|
| initializer = parseExpression2();
|
| }
|
| - return new VariableDeclaration(name, equals, initializer);
|
| + return astFactory.variableDeclaration(name, equals, initializer);
|
| }
|
|
|
| /**
|
| @@ -5099,7 +5124,7 @@ class Parser {
|
| while (_optional(TokenType.COMMA)) {
|
| variables.add(parseVariableDeclaration());
|
| }
|
| - return new VariableDeclarationList(commentAndMetadata?.comment,
|
| + return astFactory.variableDeclarationList(commentAndMetadata?.comment,
|
| commentAndMetadata?.metadata, keyword, type, variables);
|
| }
|
|
|
| @@ -5124,7 +5149,7 @@ class Parser {
|
| // }
|
| // }
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new VariableDeclarationStatement(variableList, semicolon);
|
| + return astFactory.variableDeclarationStatement(variableList, semicolon);
|
| }
|
|
|
| /**
|
| @@ -5144,7 +5169,7 @@ class Parser {
|
| Expression condition = parseExpression2();
|
| Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
|
| Statement body = parseStatement2();
|
| - return new WhileStatement(
|
| + return astFactory.whileStatement(
|
| keyword, leftParenthesis, condition, rightParenthesis, body);
|
| } finally {
|
| _inLoop = wasInLoop;
|
| @@ -5167,7 +5192,7 @@ class Parser {
|
| _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_WITH);
|
| types.add(typeName);
|
| } while (_optional(TokenType.COMMA));
|
| - return new WithClause(withKeyword, types);
|
| + return astFactory.withClause(withKeyword, types);
|
| }
|
|
|
| /**
|
| @@ -5186,7 +5211,7 @@ class Parser {
|
| }
|
| Expression expression = parseExpression2();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new YieldStatement(yieldToken, star, expression, semicolon);
|
| + return astFactory.yieldStatement(yieldToken, star, expression, semicolon);
|
| }
|
|
|
| /**
|
| @@ -5416,14 +5441,14 @@ class Parser {
|
| * captures the components of the given method declaration).
|
| */
|
| FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) =>
|
| - new FunctionDeclaration(
|
| + astFactory.functionDeclaration(
|
| method.documentationComment,
|
| method.metadata,
|
| method.externalKeyword,
|
| method.returnType,
|
| method.propertyKeyword,
|
| method.name,
|
| - new FunctionExpression(
|
| + astFactory.functionExpression(
|
| method.typeParameters, method.parameters, method.body));
|
|
|
| /**
|
| @@ -5984,8 +6009,8 @@ class Parser {
|
| ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]);
|
| // Recovery: Look to see whether there is a close paren that isn't matched
|
| // to an open paren and if so parse the list of arguments as normal.
|
| - return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null,
|
| - _createSyntheticToken(TokenType.CLOSE_PAREN));
|
| + return astFactory.argumentList(_createSyntheticToken(TokenType.OPEN_PAREN),
|
| + null, _createSyntheticToken(TokenType.CLOSE_PAREN));
|
| }
|
|
|
| /**
|
| @@ -6007,7 +6032,7 @@ class Parser {
|
| message = parseExpression2();
|
| }
|
| Token rightParen = _expect(TokenType.CLOSE_PAREN);
|
| - return new AssertInitializer(
|
| + return astFactory.assertInitializer(
|
| keyword, leftParen, expression, comma, message, rightParen);
|
| }
|
|
|
| @@ -6032,24 +6057,24 @@ class Parser {
|
| ArgumentList argumentList = parseArgumentList();
|
| Expression currentExpression = expression;
|
| if (currentExpression is SimpleIdentifier) {
|
| - expression = new MethodInvocation(
|
| + expression = astFactory.methodInvocation(
|
| null, null, currentExpression, typeArguments, argumentList);
|
| } else if (currentExpression is PrefixedIdentifier) {
|
| - expression = new MethodInvocation(
|
| + expression = astFactory.methodInvocation(
|
| currentExpression.prefix,
|
| currentExpression.period,
|
| currentExpression.identifier,
|
| typeArguments,
|
| argumentList);
|
| } else if (currentExpression is PropertyAccess) {
|
| - expression = new MethodInvocation(
|
| + expression = astFactory.methodInvocation(
|
| currentExpression.target,
|
| currentExpression.operator,
|
| currentExpression.propertyName,
|
| typeArguments,
|
| argumentList);
|
| } else {
|
| - expression = new FunctionExpressionInvocation(
|
| + expression = astFactory.functionExpressionInvocation(
|
| expression, typeArguments, argumentList);
|
| }
|
| if (!primaryAllowed) {
|
| @@ -6061,7 +6086,7 @@ class Parser {
|
| if (identical(selectorExpression, expression)) {
|
| if (!isOptional && (expression is PrefixedIdentifier)) {
|
| PrefixedIdentifier identifier = expression as PrefixedIdentifier;
|
| - expression = new PropertyAccess(
|
| + expression = astFactory.propertyAccess(
|
| identifier.prefix, identifier.period, identifier.identifier);
|
| }
|
| return expression;
|
| @@ -6087,8 +6112,8 @@ class Parser {
|
| ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_CURLY_BRACKET.lexeme]);
|
| // Recovery: Check for an unmatched closing curly bracket and parse
|
| // statements until it is reached.
|
| - return new Block(_createSyntheticToken(TokenType.OPEN_CURLY_BRACKET), null,
|
| - _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET));
|
| + return astFactory.block(_createSyntheticToken(TokenType.OPEN_CURLY_BRACKET),
|
| + null, _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET));
|
| }
|
|
|
| /**
|
| @@ -6180,7 +6205,7 @@ class Parser {
|
| }
|
| semicolon = _createSyntheticToken(TokenType.SEMICOLON);
|
| }
|
| - return new ClassTypeAlias(
|
| + return astFactory.classTypeAlias(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| classKeyword,
|
| @@ -6258,7 +6283,7 @@ class Parser {
|
| if (_matches(TokenType.EQ)) {
|
| separator = getAndAdvance();
|
| redirectedConstructor = parseConstructorName();
|
| - body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
|
| + body = astFactory.emptyFunctionBody(_expect(TokenType.SEMICOLON));
|
| if (factoryKeyword == null) {
|
| _reportErrorForNode(
|
| ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR,
|
| @@ -6292,7 +6317,7 @@ class Parser {
|
| }
|
| }
|
| }
|
| - return new ConstructorDeclaration(
|
| + return astFactory.constructorDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| @@ -6334,7 +6359,7 @@ class Parser {
|
| _reportErrorForNode(ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT,
|
| commentAndMetadata.metadata[0]);
|
| }
|
| - return new EnumConstantDeclaration(
|
| + return astFactory.enumConstantDeclaration(
|
| commentAndMetadata.comment, commentAndMetadata.metadata, name);
|
| }
|
|
|
| @@ -6345,7 +6370,7 @@ class Parser {
|
| FormalParameterList _parseFormalParameterListAfterParen(
|
| Token leftParenthesis) {
|
| if (_matches(TokenType.CLOSE_PAREN)) {
|
| - return new FormalParameterList(
|
| + return astFactory.formalParameterList(
|
| leftParenthesis, null, null, null, getAndAdvance());
|
| }
|
| //
|
| @@ -6495,7 +6520,7 @@ class Parser {
|
| //
|
| leftSquareBracket ??= leftCurlyBracket;
|
| rightSquareBracket ??= rightCurlyBracket;
|
| - return new FormalParameterList(leftParenthesis, parameters,
|
| + return astFactory.formalParameterList(leftParenthesis, parameters,
|
| leftSquareBracket, rightSquareBracket, rightParenthesis);
|
| }
|
|
|
| @@ -6532,7 +6557,7 @@ class Parser {
|
| ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword);
|
| }
|
| }
|
| - return new FunctionDeclarationStatement(declaration);
|
| + return astFactory.functionDeclarationStatement(declaration);
|
| }
|
|
|
| /**
|
| @@ -6560,14 +6585,14 @@ class Parser {
|
| TokenType type = _currentToken.type;
|
| if (type == TokenType.SEMICOLON || type == TokenType.EOF) {
|
| _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS);
|
| - FormalParameterList parameters = new FormalParameterList(
|
| + FormalParameterList parameters = astFactory.formalParameterList(
|
| _createSyntheticToken(TokenType.OPEN_PAREN),
|
| null,
|
| null,
|
| null,
|
| _createSyntheticToken(TokenType.CLOSE_PAREN));
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new FunctionTypeAlias(
|
| + return astFactory.functionTypeAlias(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| keyword,
|
| @@ -6580,7 +6605,7 @@ class Parser {
|
| FormalParameterList parameters = _parseFormalParameterListUnchecked();
|
| _validateFormalParameterList(parameters);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new FunctionTypeAlias(
|
| + return astFactory.functionTypeAlias(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| keyword,
|
| @@ -6594,15 +6619,19 @@ class Parser {
|
| // Recovery: At the very least we should skip to the start of the next
|
| // valid compilation unit member, allowing for the possibility of finding
|
| // the typedef parameters before that point.
|
| - return new FunctionTypeAlias(
|
| + return astFactory.functionTypeAlias(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| keyword,
|
| returnType,
|
| name,
|
| typeParameters,
|
| - new FormalParameterList(_createSyntheticToken(TokenType.OPEN_PAREN),
|
| - null, null, null, _createSyntheticToken(TokenType.CLOSE_PAREN)),
|
| + astFactory.formalParameterList(
|
| + _createSyntheticToken(TokenType.OPEN_PAREN),
|
| + null,
|
| + null,
|
| + null,
|
| + _createSyntheticToken(TokenType.CLOSE_PAREN)),
|
| _createSyntheticToken(TokenType.SEMICOLON));
|
| }
|
| }
|
| @@ -6658,8 +6687,8 @@ class Parser {
|
| } else {
|
| _reportErrorForToken(missingNameError, missingNameToken);
|
| }
|
| - return new LibraryIdentifier(
|
| - <SimpleIdentifier>[createSyntheticIdentifier()]);
|
| + return astFactory
|
| + .libraryIdentifier(<SimpleIdentifier>[createSyntheticIdentifier()]);
|
| }
|
|
|
| /**
|
| @@ -6696,7 +6725,7 @@ class Parser {
|
| _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body);
|
| }
|
| }
|
| - return new MethodDeclaration(
|
| + return astFactory.methodDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| @@ -6737,7 +6766,7 @@ class Parser {
|
| (type == TokenType.OPEN_CURLY_BRACKET || type == TokenType.FUNCTION)) {
|
| _reportErrorForToken(
|
| ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous);
|
| - parameters = new FormalParameterList(
|
| + parameters = astFactory.formalParameterList(
|
| _createSyntheticToken(TokenType.OPEN_PAREN),
|
| null,
|
| null,
|
| @@ -6768,7 +6797,7 @@ class Parser {
|
| NativeClause _parseNativeClause() {
|
| Token keyword = getAndAdvance();
|
| StringLiteral name = parseStringLiteral();
|
| - return new NativeClause(keyword, name);
|
| + return astFactory.nativeClause(keyword, name);
|
| }
|
|
|
| /**
|
| @@ -6795,7 +6824,7 @@ class Parser {
|
| ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]);
|
| }
|
| SimpleIdentifier name =
|
| - new SimpleIdentifier(getAndAdvance(), isDeclaration: true);
|
| + astFactory.simpleIdentifier(getAndAdvance(), isDeclaration: true);
|
| if (_matches(TokenType.EQ)) {
|
| Token previous = _currentToken.previous;
|
| if ((_tokenMatches(previous, TokenType.EQ_EQ) ||
|
| @@ -6813,7 +6842,7 @@ class Parser {
|
| if (externalKeyword != null && body is! EmptyFunctionBody) {
|
| _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY);
|
| }
|
| - return new MethodDeclaration(
|
| + return astFactory.methodDeclaration(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| externalKeyword,
|
| @@ -6838,7 +6867,8 @@ class Parser {
|
| }
|
| Keyword keyword = _currentToken.keyword;
|
| if (keyword == Keyword.VOID) {
|
| - return new TypeName(new SimpleIdentifier(getAndAdvance()), null);
|
| + return astFactory.typeName(
|
| + astFactory.simpleIdentifier(getAndAdvance()), null);
|
| } else if (_matchesIdentifier()) {
|
| Token next = _peek();
|
| if (keyword != Keyword.GET &&
|
| @@ -6892,7 +6922,7 @@ class Parser {
|
| Token partKeyword = getAndAdvance();
|
| StringLiteral partUri = _parseUri();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new PartDirective(commentAndMetadata.comment,
|
| + return astFactory.partDirective(commentAndMetadata.comment,
|
| commentAndMetadata.metadata, partKeyword, partUri, semicolon);
|
| }
|
|
|
| @@ -6913,7 +6943,7 @@ class Parser {
|
| if (enableUriInPartOf && _matches(TokenType.STRING)) {
|
| StringLiteral libraryUri = _parseUri();
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new PartOfDirective(
|
| + return astFactory.partOfDirective(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| partKeyword,
|
| @@ -6925,7 +6955,7 @@ class Parser {
|
| LibraryIdentifier libraryName = _parseLibraryName(
|
| ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, ofKeyword);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new PartOfDirective(
|
| + return astFactory.partOfDirective(
|
| commentAndMetadata.comment,
|
| commentAndMetadata.metadata,
|
| partKeyword,
|
| @@ -6949,7 +6979,7 @@ class Parser {
|
| }
|
| Token period = getAndAdvance();
|
| SimpleIdentifier qualified = parseSimpleIdentifier();
|
| - return new PrefixedIdentifier(qualifier, period, qualified);
|
| + return astFactory.prefixedIdentifier(qualifier, period, qualified);
|
| }
|
|
|
| /**
|
| @@ -6982,7 +7012,8 @@ class Parser {
|
| _reportErrorForCurrentToken(
|
| ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER);
|
| }
|
| - return new SimpleIdentifier(getAndAdvance(), isDeclaration: isDeclaration);
|
| + return astFactory.simpleIdentifier(getAndAdvance(),
|
| + isDeclaration: isDeclaration);
|
| }
|
|
|
| /**
|
| @@ -7021,7 +7052,7 @@ class Parser {
|
| */
|
| StringInterpolation _parseStringInterpolation(Token string) {
|
| List<InterpolationElement> elements = <InterpolationElement>[
|
| - new InterpolationString(
|
| + astFactory.interpolationString(
|
| string, computeStringValue(string.lexeme, true, false))
|
| ];
|
| bool hasMore = true;
|
| @@ -7034,8 +7065,8 @@ class Parser {
|
| try {
|
| Expression expression = parseExpression2();
|
| Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
|
| - elements.add(
|
| - new InterpolationExpression(openToken, expression, rightBracket));
|
| + elements.add(astFactory.interpolationExpression(
|
| + openToken, expression, rightBracket));
|
| } finally {
|
| _inInitializer = wasInInitializer;
|
| }
|
| @@ -7043,24 +7074,25 @@ class Parser {
|
| Token openToken = getAndAdvance();
|
| Expression expression = null;
|
| if (_matchesKeyword(Keyword.THIS)) {
|
| - expression = new ThisExpression(getAndAdvance());
|
| + expression = astFactory.thisExpression(getAndAdvance());
|
| } else {
|
| expression = parseSimpleIdentifier();
|
| }
|
| - elements.add(new InterpolationExpression(openToken, expression, null));
|
| + elements.add(
|
| + astFactory.interpolationExpression(openToken, expression, null));
|
| }
|
| if (_matches(TokenType.STRING)) {
|
| string = getAndAdvance();
|
| isExpression = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION);
|
| hasMore =
|
| isExpression || _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER);
|
| - elements.add(new InterpolationString(
|
| + elements.add(astFactory.interpolationString(
|
| string, computeStringValue(string.lexeme, false, !hasMore)));
|
| } else {
|
| hasMore = false;
|
| }
|
| }
|
| - return new StringInterpolation(elements);
|
| + return astFactory.stringInterpolation(elements);
|
| }
|
|
|
| /**
|
| @@ -7080,11 +7112,13 @@ class Parser {
|
| _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER)) {
|
| strings.add(_parseStringInterpolation(string));
|
| } else {
|
| - strings.add(new SimpleStringLiteral(
|
| + strings.add(astFactory.simpleStringLiteral(
|
| string, computeStringValue(string.lexeme, true, true)));
|
| }
|
| } while (_matches(TokenType.STRING));
|
| - return strings.length == 1 ? strings[0] : new AdjacentStrings(strings);
|
| + return strings.length == 1
|
| + ? strings[0]
|
| + : astFactory.adjacentStrings(strings);
|
| }
|
|
|
| TypeName _parseTypeName(bool inExpression) {
|
| @@ -7093,7 +7127,7 @@ class Parser {
|
| typeName = _parsePrefixedIdentifierUnchecked();
|
| } else if (_matchesKeyword(Keyword.VAR)) {
|
| _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME);
|
| - typeName = new SimpleIdentifier(getAndAdvance());
|
| + typeName = astFactory.simpleIdentifier(getAndAdvance());
|
| } else {
|
| typeName = createSyntheticIdentifier();
|
| _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME);
|
| @@ -7105,7 +7139,7 @@ class Parser {
|
| question = getAndAdvance();
|
| }
|
| }
|
| - return new TypeName(typeName, typeArguments, question: question);
|
| + return astFactory.typeName(typeName, typeArguments, question: question);
|
| }
|
|
|
| /**
|
| @@ -7124,7 +7158,7 @@ class Parser {
|
| // TODO(jmesserly): this feels like a big hammer. Can we restrict it to
|
| // only work inside generic methods?
|
| TypeName typeFromComment = _parseOptionalTypeNameComment();
|
| - return typeFromComment ?? new TypeName(typeName, typeArguments);
|
| + return typeFromComment ?? astFactory.typeName(typeName, typeArguments);
|
| }
|
|
|
| /**
|
| @@ -7181,7 +7215,7 @@ class Parser {
|
| _reportErrorForToken(
|
| ParserErrorCode.NON_STRING_LITERAL_AS_URI, newToken);
|
| _currentToken = endToken.next;
|
| - return new SimpleStringLiteral(newToken, value);
|
| + return astFactory.simpleStringLiteral(newToken, value);
|
| }
|
| }
|
| return parseStringLiteral();
|
| @@ -7204,7 +7238,7 @@ class Parser {
|
| parseVariableDeclarationListAfterType(
|
| commentAndMetadata, keyword, type);
|
| Token semicolon = _expect(TokenType.SEMICOLON);
|
| - return new VariableDeclarationStatement(variableList, semicolon);
|
| + return astFactory.variableDeclarationStatement(variableList, semicolon);
|
| }
|
|
|
| /**
|
|
|