Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 186153005: New analzyer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use meaningful name instead of '_' in predicate. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 AstNode visitAssignmentExpression(AssignmentExpression node) { 219 AstNode visitAssignmentExpression(AssignmentExpression node) {
220 if (identical(_oldNode, node.leftHandSide)) { 220 if (identical(_oldNode, node.leftHandSide)) {
221 // TODO(brianwilkerson) If the assignment is part of a cascade section, th en we don't have a 221 // TODO(brianwilkerson) If the assignment is part of a cascade section, th en we don't have a
222 // single parse method that will work. Otherwise, we can parse a condition al expression, but 222 // single parse method that will work. Otherwise, we can parse a condition al expression, but
223 // need to ensure that the resulting expression is assignable. 223 // need to ensure that the resulting expression is assignable.
224 // return parser.parseConditionalExpression(); 224 // return parser.parseConditionalExpression();
225 throw new InsufficientContextException(); 225 throw new InsufficientContextException();
226 } else if (identical(_oldNode, node.rightHandSide)) { 226 } else if (identical(_oldNode, node.rightHandSide)) {
227 if (isCascadeAllowed(node)) { 227 if (isCascadeAllowedInAssignment(node)) {
228 return _parser.parseExpression2(); 228 return _parser.parseExpression2();
229 } 229 }
230 return _parser.parseExpressionWithoutCascade(); 230 return _parser.parseExpressionWithoutCascade();
231 } 231 }
232 return notAChild(node); 232 return notAChild(node);
233 } 233 }
234 234
235 AstNode visitBinaryExpression(BinaryExpression node) { 235 AstNode visitBinaryExpression(BinaryExpression node) {
236 if (identical(_oldNode, node.leftOperand)) { 236 if (identical(_oldNode, node.leftOperand)) {
237 throw new InsufficientContextException(); 237 throw new InsufficientContextException();
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 952 }
953 return notAChild(node); 953 return notAChild(node);
954 } 954 }
955 955
956 AstNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node); 956 AstNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node);
957 957
958 AstNode visitThisExpression(ThisExpression node) => notAChild(node); 958 AstNode visitThisExpression(ThisExpression node) => notAChild(node);
959 959
960 AstNode visitThrowExpression(ThrowExpression node) { 960 AstNode visitThrowExpression(ThrowExpression node) {
961 if (identical(_oldNode, node.expression)) { 961 if (identical(_oldNode, node.expression)) {
962 if (isCascadeAllowed2(node)) { 962 if (isCascadeAllowedInThrow(node)) {
963 return _parser.parseExpression2(); 963 return _parser.parseExpression2();
964 } 964 }
965 return _parser.parseExpressionWithoutCascade(); 965 return _parser.parseExpressionWithoutCascade();
966 } 966 }
967 return notAChild(node); 967 return notAChild(node);
968 } 968 }
969 969
970 AstNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 970 AstNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
971 if (identical(_oldNode, node.documentationComment)) { 971 if (identical(_oldNode, node.documentationComment)) {
972 throw new InsufficientContextException(); 972 throw new InsufficientContextException();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 return notAChild(node); 1072 return notAChild(node);
1073 } 1073 }
1074 1074
1075 /** 1075 /**
1076 * Return `true` if the given assignment expression can have a cascade express ion on the 1076 * Return `true` if the given assignment expression can have a cascade express ion on the
1077 * right-hand side. 1077 * right-hand side.
1078 * 1078 *
1079 * @param node the assignment expression being tested 1079 * @param node the assignment expression being tested
1080 * @return `true` if the right-hand side can be a cascade expression 1080 * @return `true` if the right-hand side can be a cascade expression
1081 */ 1081 */
1082 bool isCascadeAllowed(AssignmentExpression node) { 1082 bool isCascadeAllowedInAssignment(AssignmentExpression node) {
1083 // TODO(brianwilkerson) Implement this method. 1083 // TODO(brianwilkerson) Implement this method.
1084 throw new InsufficientContextException(); 1084 throw new InsufficientContextException();
1085 } 1085 }
1086 1086
1087 /** 1087 /**
1088 * Return `true` if the given throw expression can have a cascade expression. 1088 * Return `true` if the given throw expression can have a cascade expression.
1089 * 1089 *
1090 * @param node the throw expression being tested 1090 * @param node the throw expression being tested
1091 * @return `true` if the expression can be a cascade expression 1091 * @return `true` if the expression can be a cascade expression
1092 */ 1092 */
1093 bool isCascadeAllowed2(ThrowExpression node) { 1093 bool isCascadeAllowedInThrow(ThrowExpression node) {
1094 // TODO(brianwilkerson) Implement this method. 1094 // TODO(brianwilkerson) Implement this method.
1095 throw new InsufficientContextException(); 1095 throw new InsufficientContextException();
1096 } 1096 }
1097 1097
1098 /** 1098 /**
1099 * Throw an exception indicating that the visited node was not the parent of t he node to be 1099 * Throw an exception indicating that the visited node was not the parent of t he node to be
1100 * replaced. 1100 * replaced.
1101 * 1101 *
1102 * @param visitedNode the visited node that should have been the parent of the node to be replaced 1102 * @param visitedNode the visited node that should have been the parent of the node to be replaced
1103 */ 1103 */
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 * Parse a sequence of statements, starting with the given token. 1437 * Parse a sequence of statements, starting with the given token.
1438 * 1438 *
1439 * @param token the first token of the sequence of statement 1439 * @param token the first token of the sequence of statement
1440 * @return the statements that were parsed, or `null` if the tokens do not rep resent a 1440 * @return the statements that were parsed, or `null` if the tokens do not rep resent a
1441 * recognizable sequence of statements 1441 * recognizable sequence of statements
1442 */ 1442 */
1443 List<Statement> parseStatements(Token token) { 1443 List<Statement> parseStatements(Token token) {
1444 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseStatements"); 1444 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseStatements");
1445 try { 1445 try {
1446 _currentToken = token; 1446 _currentToken = token;
1447 return parseStatements2(); 1447 return parseStatementList();
1448 } finally { 1448 } finally {
1449 instrumentation.log(); 1449 instrumentation.log();
1450 } 1450 }
1451 } 1451 }
1452 1452
1453 /** 1453 /**
1454 * Set whether parser is to parse function bodies. 1454 * Set whether parser is to parse function bodies.
1455 * 1455 *
1456 * @param parseFunctionBodies `true` if parser is to parse function bodies 1456 * @param parseFunctionBodies `true` if parser is to parse function bodies
1457 */ 1457 */
1458 void set parseFunctionBodies(bool parseFunctionBodies) { 1458 void set parseFunctionBodies(bool parseFunctionBodies) {
1459 this._parseFunctionBodies = parseFunctionBodies; 1459 this._parseFunctionBodies = parseFunctionBodies;
1460 } 1460 }
1461 1461
1462 /** 1462 /**
1463 * Parse an annotation. 1463 * Parse an annotation.
1464 * 1464 *
1465 * <pre> 1465 * <pre>
1466 * annotation ::= 1466 * annotation ::=
1467 * '@' qualified ('.' identifier)? arguments? 1467 * '@' qualified ('.' identifier)? arguments?
1468 * </pre> 1468 * </pre>
1469 * 1469 *
1470 * @return the annotation that was parsed 1470 * @return the annotation that was parsed
1471 */ 1471 */
1472 Annotation parseAnnotation() { 1472 Annotation parseAnnotation() {
1473 Token atSign = expect2(TokenType.AT); 1473 Token atSign = expect(TokenType.AT);
1474 Identifier name = parsePrefixedIdentifier(); 1474 Identifier name = parsePrefixedIdentifier();
1475 Token period = null; 1475 Token period = null;
1476 SimpleIdentifier constructorName = null; 1476 SimpleIdentifier constructorName = null;
1477 if (matches5(TokenType.PERIOD)) { 1477 if (matches(TokenType.PERIOD)) {
1478 period = andAdvance; 1478 period = andAdvance;
1479 constructorName = parseSimpleIdentifier(); 1479 constructorName = parseSimpleIdentifier();
1480 } 1480 }
1481 ArgumentList arguments = null; 1481 ArgumentList arguments = null;
1482 if (matches5(TokenType.OPEN_PAREN)) { 1482 if (matches(TokenType.OPEN_PAREN)) {
1483 arguments = parseArgumentList(); 1483 arguments = parseArgumentList();
1484 } 1484 }
1485 return new Annotation(atSign, name, period, constructorName, arguments); 1485 return new Annotation(atSign, name, period, constructorName, arguments);
1486 } 1486 }
1487 1487
1488 /** 1488 /**
1489 * Parse an argument. 1489 * Parse an argument.
1490 * 1490 *
1491 * <pre> 1491 * <pre>
1492 * argument ::= 1492 * argument ::=
1493 * namedArgument 1493 * namedArgument
1494 * | expression 1494 * | expression
1495 * 1495 *
1496 * namedArgument ::= 1496 * namedArgument ::=
1497 * label expression 1497 * label expression
1498 * </pre> 1498 * </pre>
1499 * 1499 *
1500 * @return the argument that was parsed 1500 * @return the argument that was parsed
1501 */ 1501 */
1502 Expression parseArgument() { 1502 Expression parseArgument() {
1503 // 1503 //
1504 // Both namedArgument and expression can start with an identifier, but only namedArgument can 1504 // Both namedArgument and expression can start with an identifier, but only namedArgument can
1505 // have an identifier followed by a colon. 1505 // have an identifier followed by a colon.
1506 // 1506 //
1507 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 1507 if (matchesIdentifier() && tokenMatches(peek(), TokenType.COLON)) {
1508 return new NamedExpression(parseLabel(), parseExpression2()); 1508 return new NamedExpression(parseLabel(), parseExpression2());
1509 } else { 1509 } else {
1510 return parseExpression2(); 1510 return parseExpression2();
1511 } 1511 }
1512 } 1512 }
1513 1513
1514 /** 1514 /**
1515 * Parse a list of arguments. 1515 * Parse a list of arguments.
1516 * 1516 *
1517 * <pre> 1517 * <pre>
1518 * arguments ::= 1518 * arguments ::=
1519 * '(' argumentList? ')' 1519 * '(' argumentList? ')'
1520 * 1520 *
1521 * argumentList ::= 1521 * argumentList ::=
1522 * namedArgument (',' namedArgument)* 1522 * namedArgument (',' namedArgument)*
1523 * | expressionList (',' namedArgument)* 1523 * | expressionList (',' namedArgument)*
1524 * </pre> 1524 * </pre>
1525 * 1525 *
1526 * @return the argument list that was parsed 1526 * @return the argument list that was parsed
1527 */ 1527 */
1528 ArgumentList parseArgumentList() { 1528 ArgumentList parseArgumentList() {
1529 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 1529 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
1530 List<Expression> arguments = new List<Expression>(); 1530 List<Expression> arguments = new List<Expression>();
1531 if (matches5(TokenType.CLOSE_PAREN)) { 1531 if (matches(TokenType.CLOSE_PAREN)) {
1532 return new ArgumentList(leftParenthesis, arguments, andAdvance); 1532 return new ArgumentList(leftParenthesis, arguments, andAdvance);
1533 } 1533 }
1534 // 1534 //
1535 // Even though unnamed arguments must all appear before any named arguments, we allow them to 1535 // Even though unnamed arguments must all appear before any named arguments, we allow them to
1536 // appear in any order so that we can recover faster. 1536 // appear in any order so that we can recover faster.
1537 // 1537 //
1538 Expression argument = parseArgument(); 1538 Expression argument = parseArgument();
1539 arguments.add(argument); 1539 arguments.add(argument);
1540 bool foundNamedArgument = argument is NamedExpression; 1540 bool foundNamedArgument = argument is NamedExpression;
1541 bool generatedError = false; 1541 bool generatedError = false;
1542 while (optional(TokenType.COMMA)) { 1542 while (optional(TokenType.COMMA)) {
1543 argument = parseArgument(); 1543 argument = parseArgument();
1544 arguments.add(argument); 1544 arguments.add(argument);
1545 if (foundNamedArgument) { 1545 if (foundNamedArgument) {
1546 if (!generatedError && argument is! NamedExpression) { 1546 if (!generatedError && argument is! NamedExpression) {
1547 // Report the error, once, but allow the arguments to be in any order in the AST. 1547 // Report the error, once, but allow the arguments to be in any order in the AST.
1548 reportError13(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); 1548 reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGU MENT, []);
1549 generatedError = true; 1549 generatedError = true;
1550 } 1550 }
1551 } else if (argument is NamedExpression) { 1551 } else if (argument is NamedExpression) {
1552 foundNamedArgument = true; 1552 foundNamedArgument = true;
1553 } 1553 }
1554 } 1554 }
1555 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whethe r there is a 1555 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whethe r there is a
1556 // matching right parenthesis. If there is, then we're more likely missing a comma and should 1556 // matching right parenthesis. If there is, then we're more likely missing a comma and should
1557 // go back to parsing arguments. 1557 // go back to parsing arguments.
1558 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 1558 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
1559 return new ArgumentList(leftParenthesis, arguments, rightParenthesis); 1559 return new ArgumentList(leftParenthesis, arguments, rightParenthesis);
1560 } 1560 }
1561 1561
1562 /** 1562 /**
1563 * Parse a bitwise or expression. 1563 * Parse a bitwise or expression.
1564 * 1564 *
1565 * <pre> 1565 * <pre>
1566 * bitwiseOrExpression ::= 1566 * bitwiseOrExpression ::=
1567 * bitwiseXorExpression ('|' bitwiseXorExpression)* 1567 * bitwiseXorExpression ('|' bitwiseXorExpression)*
1568 * | 'super' ('|' bitwiseXorExpression)+ 1568 * | 'super' ('|' bitwiseXorExpression)+
1569 * </pre> 1569 * </pre>
1570 * 1570 *
1571 * @return the bitwise or expression that was parsed 1571 * @return the bitwise or expression that was parsed
1572 */ 1572 */
1573 Expression parseBitwiseOrExpression() { 1573 Expression parseBitwiseOrExpression() {
1574 Expression expression; 1574 Expression expression;
1575 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) { 1575 if (matchesKeyword(Keyword.SUPER) && tokenMatches(peek(), TokenType.BAR)) {
1576 expression = new SuperExpression(andAdvance); 1576 expression = new SuperExpression(andAdvance);
1577 } else { 1577 } else {
1578 expression = parseBitwiseXorExpression(); 1578 expression = parseBitwiseXorExpression();
1579 } 1579 }
1580 while (matches5(TokenType.BAR)) { 1580 while (matches(TokenType.BAR)) {
1581 Token operator = andAdvance; 1581 Token operator = andAdvance;
1582 expression = new BinaryExpression(expression, operator, parseBitwiseXorExp ression()); 1582 expression = new BinaryExpression(expression, operator, parseBitwiseXorExp ression());
1583 } 1583 }
1584 return expression; 1584 return expression;
1585 } 1585 }
1586 1586
1587 /** 1587 /**
1588 * Parse a block. 1588 * Parse a block.
1589 * 1589 *
1590 * <pre> 1590 * <pre>
1591 * block ::= 1591 * block ::=
1592 * '{' statements '}' 1592 * '{' statements '}'
1593 * </pre> 1593 * </pre>
1594 * 1594 *
1595 * @return the block that was parsed 1595 * @return the block that was parsed
1596 */ 1596 */
1597 Block parseBlock() { 1597 Block parseBlock() {
1598 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 1598 Token leftBracket = expect(TokenType.OPEN_CURLY_BRACKET);
1599 List<Statement> statements = new List<Statement>(); 1599 List<Statement> statements = new List<Statement>();
1600 Token statementStart = _currentToken; 1600 Token statementStart = _currentToken;
1601 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) { 1601 while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACKET)) {
1602 Statement statement = parseStatement2(); 1602 Statement statement = parseStatement2();
1603 if (statement != null) { 1603 if (statement != null) {
1604 statements.add(statement); 1604 statements.add(statement);
1605 } 1605 }
1606 if (identical(_currentToken, statementStart)) { 1606 if (identical(_currentToken, statementStart)) {
1607 // Ensure that we are making progress and report an error if we're not. 1607 // Ensure that we are making progress and report an error if we're not.
1608 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1608 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
1609 advance(); 1609 advance();
1610 } 1610 }
1611 statementStart = _currentToken; 1611 statementStart = _currentToken;
1612 } 1612 }
1613 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 1613 Token rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
1614 return new Block(leftBracket, statements, rightBracket); 1614 return new Block(leftBracket, statements, rightBracket);
1615 } 1615 }
1616 1616
1617 /** 1617 /**
1618 * Parse a class member. 1618 * Parse a class member.
1619 * 1619 *
1620 * <pre> 1620 * <pre>
1621 * classMemberDefinition ::= 1621 * classMemberDefinition ::=
1622 * declaration ';' 1622 * declaration ';'
1623 * | methodSignature functionBody 1623 * | methodSignature functionBody
1624 * </pre> 1624 * </pre>
1625 * 1625 *
1626 * @param className the name of the class containing the member being parsed 1626 * @param className the name of the class containing the member being parsed
1627 * @return the class member that was parsed, or `null` if what was found was n ot a valid 1627 * @return the class member that was parsed, or `null` if what was found was n ot a valid
1628 * class member 1628 * class member
1629 */ 1629 */
1630 ClassMember parseClassMember(String className) { 1630 ClassMember parseClassMember(String className) {
1631 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1631 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
1632 Modifiers modifiers = parseModifiers(); 1632 Modifiers modifiers = parseModifiers();
1633 if (matches(Keyword.VOID)) { 1633 if (matchesKeyword(Keyword.VOID)) {
1634 TypeName returnType = parseReturnType(); 1634 TypeName returnType = parseReturnType();
1635 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1635 if (matchesKeyword(Keyword.GET) && tokenMatchesIdentifier(peek())) {
1636 validateModifiersForGetterOrSetterOrMethod(modifiers); 1636 validateModifiersForGetterOrSetterOrMethod(modifiers);
1637 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifi ers.staticKeyword, returnType); 1637 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifi ers.staticKeyword, returnType);
1638 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1638 } else if (matchesKeyword(Keyword.SET) && tokenMatchesIdentifier(peek())) {
1639 validateModifiersForGetterOrSetterOrMethod(modifiers); 1639 validateModifiersForGetterOrSetterOrMethod(modifiers);
1640 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifi ers.staticKeyword, returnType); 1640 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifi ers.staticKeyword, returnType);
1641 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 1641 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
1642 validateModifiersForOperator(modifiers); 1642 validateModifiersForOperator(modifiers);
1643 return parseOperator(commentAndMetadata, modifiers.externalKeyword, retu rnType); 1643 return parseOperator(commentAndMetadata, modifiers.externalKeyword, retu rnType);
1644 } else if (matchesIdentifier() && matchesAny(peek(), [ 1644 } else if (matchesIdentifier() && matchesAny(peek(), [
1645 TokenType.OPEN_PAREN, 1645 TokenType.OPEN_PAREN,
1646 TokenType.OPEN_CURLY_BRACKET, 1646 TokenType.OPEN_CURLY_BRACKET,
1647 TokenType.FUNCTION])) { 1647 TokenType.FUNCTION])) {
1648 validateModifiersForGetterOrSetterOrMethod(modifiers); 1648 validateModifiersForGetterOrSetterOrMethod(modifiers);
1649 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw ord, modifiers.staticKeyword, returnType); 1649 return parseMethodDeclarationAfterReturnType(commentAndMetadata, modifie rs.externalKeyword, modifiers.staticKeyword, returnType);
1650 } else { 1650 } else {
1651 // 1651 //
1652 // We have found an error of some kind. Try to recover. 1652 // We have found an error of some kind. Try to recover.
1653 // 1653 //
1654 if (matchesIdentifier()) { 1654 if (matchesIdentifier()) {
1655 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 1655 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
1656 // 1656 //
1657 // We appear to have a variable declaration with a type of "void". 1657 // We appear to have a variable declaration with a type of "void".
1658 // 1658 //
1659 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []); 1659 reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []);
1660 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType); 1660 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType);
1661 } 1661 }
1662 } 1662 }
1663 if (isOperator(_currentToken)) { 1663 if (isOperator(_currentToken)) {
1664 // 1664 //
1665 // We appear to have found an operator declaration without the 'operat or' keyword. 1665 // We appear to have found an operator declaration without the 'operat or' keyword.
1666 // 1666 //
1667 validateModifiersForOperator(modifiers); 1667 validateModifiersForOperator(modifiers);
1668 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType); 1668 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType);
1669 } 1669 }
1670 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 1670 reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
1671 return null; 1671 return null;
1672 } 1672 }
1673 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1673 } else if (matchesKeyword(Keyword.GET) && tokenMatchesIdentifier(peek())) {
1674 validateModifiersForGetterOrSetterOrMethod(modifiers); 1674 validateModifiersForGetterOrSetterOrMethod(modifiers);
1675 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1675 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1676 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1676 } else if (matchesKeyword(Keyword.SET) && tokenMatchesIdentifier(peek())) {
1677 validateModifiersForGetterOrSetterOrMethod(modifiers); 1677 validateModifiersForGetterOrSetterOrMethod(modifiers);
1678 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1678 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1679 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 1679 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
1680 validateModifiersForOperator(modifiers); 1680 validateModifiersForOperator(modifiers);
1681 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null); 1681 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null);
1682 } else if (!matchesIdentifier()) { 1682 } else if (!matchesIdentifier()) {
1683 if (isOperator(_currentToken)) { 1683 if (isOperator(_currentToken)) {
1684 // 1684 //
1685 // We appear to have found an operator declaration without the 'operator ' keyword. 1685 // We appear to have found an operator declaration without the 'operator ' keyword.
1686 // 1686 //
1687 validateModifiersForOperator(modifiers); 1687 validateModifiersForOperator(modifiers);
1688 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null ); 1688 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null );
1689 } 1689 }
1690 reportError14(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1690 reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1691 if (commentAndMetadata.comment != null || !commentAndMetadata.metadata.isE mpty) { 1691 if (commentAndMetadata.comment != null || !commentAndMetadata.metadata.isE mpty) {
1692 // 1692 //
1693 // We appear to have found an incomplete declaration at the end of the c lass. At this point 1693 // We appear to have found an incomplete declaration at the end of the c lass. At this point
1694 // it consists of a metadata, which we don't want to loose, so we'll tre at it as a method 1694 // it consists of a metadata, which we don't want to loose, so we'll tre at it as a method
1695 // declaration with a missing name, parameters and empty body. 1695 // declaration with a missing name, parameters and empty body.
1696 // 1696 //
1697 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetad ata.metadata, null, null, null, null, null, createSyntheticIdentifier(), new For malParameterList(null, new List<FormalParameter>(), null, null, null), new Empty FunctionBody(createSyntheticToken2(TokenType.SEMICOLON))); 1697 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetad ata.metadata, null, null, null, null, null, createSyntheticIdentifier(), new For malParameterList(null, new List<FormalParameter>(), null, null, null), new Empty FunctionBody(createSyntheticToken(TokenType.SEMICOLON)));
1698 } 1698 }
1699 return null; 1699 return null;
1700 } else if (matches4(peek(), TokenType.PERIOD) && matchesIdentifier2(peek2(2) ) && matches4(peek2(3), TokenType.OPEN_PAREN)) { 1700 } else if (tokenMatches(peek(), TokenType.PERIOD) && tokenMatchesIdentifier( peek2(2)) && tokenMatches(peek2(3), TokenType.OPEN_PAREN)) {
1701 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList()); 1701 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList());
1702 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1702 } else if (tokenMatches(peek(), TokenType.OPEN_PAREN)) {
1703 SimpleIdentifier methodName = parseSimpleIdentifier(); 1703 SimpleIdentifier methodName = parseSimpleIdentifier();
1704 FormalParameterList parameters = parseFormalParameterList(); 1704 FormalParameterList parameters = parseFormalParameterList();
1705 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) { 1705 if (matches(TokenType.COLON) || modifiers.factoryKeyword != null || method Name.name == className) {
1706 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters); 1706 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters);
1707 } 1707 }
1708 validateModifiersForGetterOrSetterOrMethod(modifiers); 1708 validateModifiersForGetterOrSetterOrMethod(modifiers);
1709 validateFormalParameterList(parameters); 1709 validateFormalParameterList(parameters);
1710 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, null, methodName, parameters); 1710 return parseMethodDeclarationAfterParameters(commentAndMetadata, modifiers .externalKeyword, modifiers.staticKeyword, null, methodName, parameters);
1711 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 1711 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
1712 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 1712 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
1713 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 1713 reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TY PE, []);
1714 } 1714 }
1715 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null); 1715 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null);
1716 } 1716 }
1717 TypeName type = parseTypeName(); 1717 TypeName type = parseTypeName();
1718 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1718 if (matchesKeyword(Keyword.GET) && tokenMatchesIdentifier(peek())) {
1719 validateModifiersForGetterOrSetterOrMethod(modifiers); 1719 validateModifiersForGetterOrSetterOrMethod(modifiers);
1720 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type); 1720 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type);
1721 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1721 } else if (matchesKeyword(Keyword.SET) && tokenMatchesIdentifier(peek())) {
1722 validateModifiersForGetterOrSetterOrMethod(modifiers); 1722 validateModifiersForGetterOrSetterOrMethod(modifiers);
1723 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type); 1723 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type);
1724 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 1724 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
1725 validateModifiersForOperator(modifiers); 1725 validateModifiersForOperator(modifiers);
1726 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type); 1726 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type);
1727 } else if (!matchesIdentifier()) { 1727 } else if (!matchesIdentifier()) {
1728 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 1728 if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
1729 // 1729 //
1730 // We appear to have found an incomplete declaration at the end of the c lass. At this point 1730 // We appear to have found an incomplete declaration at the end of the c lass. At this point
1731 // it consists of a type name, so we'll treat it as a field declaration with a missing 1731 // it consists of a type name, so we'll treat it as a field declaration with a missing
1732 // field name and semicolon. 1732 // field name and semicolon.
1733 // 1733 //
1734 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type); 1734 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type);
1735 } 1735 }
1736 if (isOperator(_currentToken)) { 1736 if (isOperator(_currentToken)) {
1737 // 1737 //
1738 // We appear to have found an operator declaration without the 'operator ' keyword. 1738 // We appear to have found an operator declaration without the 'operator ' keyword.
1739 // 1739 //
1740 validateModifiersForOperator(modifiers); 1740 validateModifiersForOperator(modifiers);
1741 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type ); 1741 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type );
1742 } 1742 }
1743 // 1743 //
1744 // We appear to have found an incomplete declaration before another declar ation. 1744 // We appear to have found an incomplete declaration before another declar ation.
1745 // At this point it consists of a type name, so we'll treat it as a field declaration 1745 // At this point it consists of a type name, so we'll treat it as a field declaration
1746 // with a missing field name and semicolon. 1746 // with a missing field name and semicolon.
1747 // 1747 //
1748 reportError14(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1748 reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1749 try { 1749 try {
1750 lockErrorListener(); 1750 lockErrorListener();
1751 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type); 1751 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type);
1752 } finally { 1752 } finally {
1753 unlockErrorListener(); 1753 unlockErrorListener();
1754 } 1754 }
1755 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1755 } else if (tokenMatches(peek(), TokenType.OPEN_PAREN)) {
1756 SimpleIdentifier methodName = parseSimpleIdentifier(); 1756 SimpleIdentifier methodName = parseSimpleIdentifier();
1757 FormalParameterList parameters = parseFormalParameterList(); 1757 FormalParameterList parameters = parseFormalParameterList();
1758 if (methodName.name == className) { 1758 if (methodName.name == className) {
1759 reportError12(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []); 1759 reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, [ ]);
1760 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters); 1760 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters);
1761 } 1761 }
1762 validateModifiersForGetterOrSetterOrMethod(modifiers); 1762 validateModifiersForGetterOrSetterOrMethod(modifiers);
1763 validateFormalParameterList(parameters); 1763 validateFormalParameterList(parameters);
1764 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, type, methodName, parameters); 1764 return parseMethodDeclarationAfterParameters(commentAndMetadata, modifiers .externalKeyword, modifiers.staticKeyword, type, methodName, parameters);
1765 } 1765 }
1766 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type); 1766 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type);
1767 } 1767 }
1768 1768
1769 /** 1769 /**
1770 * Parse a compilation unit. 1770 * Parse a compilation unit.
1771 * 1771 *
1772 * Specified: 1772 * Specified:
1773 * 1773 *
1774 * <pre> 1774 * <pre>
1775 * compilationUnit ::= 1775 * compilationUnit ::=
1776 * scriptTag? directive* topLevelDeclaration* 1776 * scriptTag? directive* topLevelDeclaration*
1777 * </pre> 1777 * </pre>
1778 * Actual: 1778 * Actual:
1779 * 1779 *
1780 * <pre> 1780 * <pre>
1781 * compilationUnit ::= 1781 * compilationUnit ::=
1782 * scriptTag? topLevelElement* 1782 * scriptTag? topLevelElement*
1783 * 1783 *
1784 * topLevelElement ::= 1784 * topLevelElement ::=
1785 * directive 1785 * directive
1786 * | topLevelDeclaration 1786 * | topLevelDeclaration
1787 * </pre> 1787 * </pre>
1788 * 1788 *
1789 * @return the compilation unit that was parsed 1789 * @return the compilation unit that was parsed
1790 */ 1790 */
1791 CompilationUnit parseCompilationUnit2() { 1791 CompilationUnit parseCompilationUnit2() {
1792 Token firstToken = _currentToken; 1792 Token firstToken = _currentToken;
1793 ScriptTag scriptTag = null; 1793 ScriptTag scriptTag = null;
1794 if (matches5(TokenType.SCRIPT_TAG)) { 1794 if (matches(TokenType.SCRIPT_TAG)) {
1795 scriptTag = new ScriptTag(andAdvance); 1795 scriptTag = new ScriptTag(andAdvance);
1796 } 1796 }
1797 // 1797 //
1798 // Even though all directives must appear before declarations and must occur in a given order, 1798 // Even though all directives must appear before declarations and must occur in a given order,
1799 // we allow directives and declarations to occur in any order so that we can recover better. 1799 // we allow directives and declarations to occur in any order so that we can recover better.
1800 // 1800 //
1801 bool libraryDirectiveFound = false; 1801 bool libraryDirectiveFound = false;
1802 bool partOfDirectiveFound = false; 1802 bool partOfDirectiveFound = false;
1803 bool partDirectiveFound = false; 1803 bool partDirectiveFound = false;
1804 bool directiveFoundAfterDeclaration = false; 1804 bool directiveFoundAfterDeclaration = false;
1805 List<Directive> directives = new List<Directive>(); 1805 List<Directive> directives = new List<Directive>();
1806 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 1806 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
1807 Token memberStart = _currentToken; 1807 Token memberStart = _currentToken;
1808 while (!matches5(TokenType.EOF)) { 1808 while (!matches(TokenType.EOF)) {
1809 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1809 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
1810 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword .LIBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !m atches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) { 1810 if ((matchesKeyword(Keyword.IMPORT) || matchesKeyword(Keyword.EXPORT) || m atchesKeyword(Keyword.LIBRARY) || matchesKeyword(Keyword.PART)) && !tokenMatches (peek(), TokenType.PERIOD) && !tokenMatches(peek(), TokenType.LT) && !tokenMatch es(peek(), TokenType.OPEN_PAREN)) {
1811 Directive directive = parseDirective(commentAndMetadata); 1811 Directive directive = parseDirective(commentAndMetadata);
1812 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { 1812 if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
1813 reportError13(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []); 1813 reportErrorForCurrentToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION , []);
1814 directiveFoundAfterDeclaration = true; 1814 directiveFoundAfterDeclaration = true;
1815 } 1815 }
1816 if (directive is LibraryDirective) { 1816 if (directive is LibraryDirective) {
1817 if (libraryDirectiveFound) { 1817 if (libraryDirectiveFound) {
1818 reportError13(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []); 1818 reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIV ES, []);
1819 } else { 1819 } else {
1820 if (directives.length > 0) { 1820 if (directives.length > 0) {
1821 reportError14(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directi ve.libraryToken, []); 1821 reportErrorForToken(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, d irective.libraryToken, []);
1822 } 1822 }
1823 libraryDirectiveFound = true; 1823 libraryDirectiveFound = true;
1824 } 1824 }
1825 } else if (directive is PartDirective) { 1825 } else if (directive is PartDirective) {
1826 partDirectiveFound = true; 1826 partDirectiveFound = true;
1827 } else if (partDirectiveFound) { 1827 } else if (partDirectiveFound) {
1828 if (directive is ExportDirective) { 1828 if (directive is ExportDirective) {
1829 reportError14(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1829 reportErrorForToken(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRE CTIVE, directive.keyword, []);
1830 } else if (directive is ImportDirective) { 1830 } else if (directive is ImportDirective) {
1831 reportError14(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1831 reportErrorForToken(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRE CTIVE, directive.keyword, []);
1832 } 1832 }
1833 } 1833 }
1834 if (directive is PartOfDirective) { 1834 if (directive is PartOfDirective) {
1835 if (partOfDirectiveFound) { 1835 if (partOfDirectiveFound) {
1836 reportError13(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []); 1836 reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIV ES, []);
1837 } else { 1837 } else {
1838 int directiveCount = directives.length; 1838 int directiveCount = directives.length;
1839 for (int i = 0; i < directiveCount; i++) { 1839 for (int i = 0; i < directiveCount; i++) {
1840 reportError14(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, direc tives[i].keyword, []); 1840 reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directives[i].keyword, []);
1841 } 1841 }
1842 partOfDirectiveFound = true; 1842 partOfDirectiveFound = true;
1843 } 1843 }
1844 } else { 1844 } else {
1845 if (partOfDirectiveFound) { 1845 if (partOfDirectiveFound) {
1846 reportError14(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directi ve.keyword, []); 1846 reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, d irective.keyword, []);
1847 } 1847 }
1848 } 1848 }
1849 directives.add(directive); 1849 directives.add(directive);
1850 } else if (matches5(TokenType.SEMICOLON)) { 1850 } else if (matches(TokenType.SEMICOLON)) {
1851 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1851 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
1852 advance(); 1852 advance();
1853 } else { 1853 } else {
1854 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data); 1854 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data);
1855 if (member != null) { 1855 if (member != null) {
1856 declarations.add(member); 1856 declarations.add(member);
1857 } 1857 }
1858 } 1858 }
1859 if (identical(_currentToken, memberStart)) { 1859 if (identical(_currentToken, memberStart)) {
1860 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1860 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
1861 advance(); 1861 advance();
1862 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) { 1862 while (!matches(TokenType.EOF) && !couldBeStartOfCompilationUnitMember() ) {
1863 advance(); 1863 advance();
1864 } 1864 }
1865 } 1865 }
1866 memberStart = _currentToken; 1866 memberStart = _currentToken;
1867 } 1867 }
1868 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken); 1868 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken);
1869 } 1869 }
1870 1870
1871 /** 1871 /**
1872 * Parse a conditional expression. 1872 * Parse a conditional expression.
1873 * 1873 *
1874 * <pre> 1874 * <pre>
1875 * conditionalExpression ::= 1875 * conditionalExpression ::=
1876 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)? 1876 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)?
1877 * </pre> 1877 * </pre>
1878 * 1878 *
1879 * @return the conditional expression that was parsed 1879 * @return the conditional expression that was parsed
1880 */ 1880 */
1881 Expression parseConditionalExpression() { 1881 Expression parseConditionalExpression() {
1882 Expression condition = parseLogicalOrExpression(); 1882 Expression condition = parseLogicalOrExpression();
1883 if (!matches5(TokenType.QUESTION)) { 1883 if (!matches(TokenType.QUESTION)) {
1884 return condition; 1884 return condition;
1885 } 1885 }
1886 Token question = andAdvance; 1886 Token question = andAdvance;
1887 Expression thenExpression = parseExpressionWithoutCascade(); 1887 Expression thenExpression = parseExpressionWithoutCascade();
1888 Token colon = expect2(TokenType.COLON); 1888 Token colon = expect(TokenType.COLON);
1889 Expression elseExpression = parseExpressionWithoutCascade(); 1889 Expression elseExpression = parseExpressionWithoutCascade();
1890 return new ConditionalExpression(condition, question, thenExpression, colon, elseExpression); 1890 return new ConditionalExpression(condition, question, thenExpression, colon, elseExpression);
1891 } 1891 }
1892 1892
1893 /** 1893 /**
1894 * Parse the name of a constructor. 1894 * Parse the name of a constructor.
1895 * 1895 *
1896 * <pre> 1896 * <pre>
1897 * constructorName: 1897 * constructorName:
1898 * type ('.' identifier)? 1898 * type ('.' identifier)?
1899 * </pre> 1899 * </pre>
1900 * 1900 *
1901 * @return the constructor name that was parsed 1901 * @return the constructor name that was parsed
1902 */ 1902 */
1903 ConstructorName parseConstructorName() { 1903 ConstructorName parseConstructorName() {
1904 TypeName type = parseTypeName(); 1904 TypeName type = parseTypeName();
1905 Token period = null; 1905 Token period = null;
1906 SimpleIdentifier name = null; 1906 SimpleIdentifier name = null;
1907 if (matches5(TokenType.PERIOD)) { 1907 if (matches(TokenType.PERIOD)) {
1908 period = andAdvance; 1908 period = andAdvance;
1909 name = parseSimpleIdentifier(); 1909 name = parseSimpleIdentifier();
1910 } 1910 }
1911 return new ConstructorName(type, period, name); 1911 return new ConstructorName(type, period, name);
1912 } 1912 }
1913 1913
1914 /** 1914 /**
1915 * Parse an expression that does not contain any cascades. 1915 * Parse an expression that does not contain any cascades.
1916 * 1916 *
1917 * <pre> 1917 * <pre>
1918 * expression ::= 1918 * expression ::=
1919 * assignableExpression assignmentOperator expression 1919 * assignableExpression assignmentOperator expression
1920 * | conditionalExpression cascadeSection* 1920 * | conditionalExpression cascadeSection*
1921 * | throwExpression 1921 * | throwExpression
1922 * </pre> 1922 * </pre>
1923 * 1923 *
1924 * @return the expression that was parsed 1924 * @return the expression that was parsed
1925 */ 1925 */
1926 Expression parseExpression2() { 1926 Expression parseExpression2() {
1927 if (matches(Keyword.THROW)) { 1927 if (matchesKeyword(Keyword.THROW)) {
1928 return parseThrowExpression(); 1928 return parseThrowExpression();
1929 } else if (matches(Keyword.RETHROW)) { 1929 } else if (matchesKeyword(Keyword.RETHROW)) {
1930 return parseRethrowExpression(); 1930 return parseRethrowExpression();
1931 } 1931 }
1932 // 1932 //
1933 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional 1933 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional
1934 // expression and then determine whether it is followed by an assignmentOper ator, checking for 1934 // expression and then determine whether it is followed by an assignmentOper ator, checking for
1935 // conformance to the restricted grammar after making that determination. 1935 // conformance to the restricted grammar after making that determination.
1936 // 1936 //
1937 Expression expression = parseConditionalExpression(); 1937 Expression expression = parseConditionalExpression();
1938 TokenType tokenType = _currentToken.type; 1938 TokenType tokenType = _currentToken.type;
1939 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1939 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
(...skipping 20 matching lines...) Expand all
1960 * <pre> 1960 * <pre>
1961 * expressionWithoutCascade ::= 1961 * expressionWithoutCascade ::=
1962 * assignableExpression assignmentOperator expressionWithoutCascade 1962 * assignableExpression assignmentOperator expressionWithoutCascade
1963 * | conditionalExpression 1963 * | conditionalExpression
1964 * | throwExpressionWithoutCascade 1964 * | throwExpressionWithoutCascade
1965 * </pre> 1965 * </pre>
1966 * 1966 *
1967 * @return the expression that was parsed 1967 * @return the expression that was parsed
1968 */ 1968 */
1969 Expression parseExpressionWithoutCascade() { 1969 Expression parseExpressionWithoutCascade() {
1970 if (matches(Keyword.THROW)) { 1970 if (matchesKeyword(Keyword.THROW)) {
1971 return parseThrowExpressionWithoutCascade(); 1971 return parseThrowExpressionWithoutCascade();
1972 } else if (matches(Keyword.RETHROW)) { 1972 } else if (matchesKeyword(Keyword.RETHROW)) {
1973 return parseRethrowExpression(); 1973 return parseRethrowExpression();
1974 } 1974 }
1975 // 1975 //
1976 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional 1976 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional
1977 // expression and then determine whether it is followed by an assignmentOper ator, checking for 1977 // expression and then determine whether it is followed by an assignmentOper ator, checking for
1978 // conformance to the restricted grammar after making that determination. 1978 // conformance to the restricted grammar after making that determination.
1979 // 1979 //
1980 Expression expression = parseConditionalExpression(); 1980 Expression expression = parseConditionalExpression();
1981 if (_currentToken.type.isAssignmentOperator) { 1981 if (_currentToken.type.isAssignmentOperator) {
1982 Token operator = andAdvance; 1982 Token operator = andAdvance;
1983 ensureAssignable(expression); 1983 ensureAssignable(expression);
1984 expression = new AssignmentExpression(expression, operator, parseExpressio nWithoutCascade()); 1984 expression = new AssignmentExpression(expression, operator, parseExpressio nWithoutCascade());
1985 } 1985 }
1986 return expression; 1986 return expression;
1987 } 1987 }
1988 1988
1989 /** 1989 /**
1990 * Parse a class extends clause. 1990 * Parse a class extends clause.
1991 * 1991 *
1992 * <pre> 1992 * <pre>
1993 * classExtendsClause ::= 1993 * classExtendsClause ::=
1994 * 'extends' type 1994 * 'extends' type
1995 * </pre> 1995 * </pre>
1996 * 1996 *
1997 * @return the class extends clause that was parsed 1997 * @return the class extends clause that was parsed
1998 */ 1998 */
1999 ExtendsClause parseExtendsClause() { 1999 ExtendsClause parseExtendsClause() {
2000 Token keyword = expect(Keyword.EXTENDS); 2000 Token keyword = expectKeyword(Keyword.EXTENDS);
2001 TypeName superclass = parseTypeName(); 2001 TypeName superclass = parseTypeName();
2002 return new ExtendsClause(keyword, superclass); 2002 return new ExtendsClause(keyword, superclass);
2003 } 2003 }
2004 2004
2005 /** 2005 /**
2006 * Parse a list of formal parameters. 2006 * Parse a list of formal parameters.
2007 * 2007 *
2008 * <pre> 2008 * <pre>
2009 * formalParameterList ::= 2009 * formalParameterList ::=
2010 * '(' ')' 2010 * '(' ')'
(...skipping 10 matching lines...) Expand all
2021 * optionalPositionalFormalParameters ::= 2021 * optionalPositionalFormalParameters ::=
2022 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']' 2022 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']'
2023 * 2023 *
2024 * namedFormalParameters ::= 2024 * namedFormalParameters ::=
2025 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' 2025 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}'
2026 * </pre> 2026 * </pre>
2027 * 2027 *
2028 * @return the formal parameters that were parsed 2028 * @return the formal parameters that were parsed
2029 */ 2029 */
2030 FormalParameterList parseFormalParameterList() { 2030 FormalParameterList parseFormalParameterList() {
2031 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 2031 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
2032 if (matches5(TokenType.CLOSE_PAREN)) { 2032 if (matches(TokenType.CLOSE_PAREN)) {
2033 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce); 2033 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce);
2034 } 2034 }
2035 // 2035 //
2036 // Even though it is invalid to have default parameters outside of brackets, required parameters 2036 // Even though it is invalid to have default parameters outside of brackets, required parameters
2037 // inside of brackets, or multiple groups of default and named parameters, w e allow all of these 2037 // inside of brackets, or multiple groups of default and named parameters, w e allow all of these
2038 // cases so that we can recover better. 2038 // cases so that we can recover better.
2039 // 2039 //
2040 List<FormalParameter> parameters = new List<FormalParameter>(); 2040 List<FormalParameter> parameters = new List<FormalParameter>();
2041 List<FormalParameter> normalParameters = new List<FormalParameter>(); 2041 List<FormalParameter> normalParameters = new List<FormalParameter>();
2042 List<FormalParameter> positionalParameters = new List<FormalParameter>(); 2042 List<FormalParameter> positionalParameters = new List<FormalParameter>();
2043 List<FormalParameter> namedParameters = new List<FormalParameter>(); 2043 List<FormalParameter> namedParameters = new List<FormalParameter>();
2044 List<FormalParameter> currentParameters = normalParameters; 2044 List<FormalParameter> currentParameters = normalParameters;
2045 Token leftSquareBracket = null; 2045 Token leftSquareBracket = null;
2046 Token rightSquareBracket = null; 2046 Token rightSquareBracket = null;
2047 Token leftCurlyBracket = null; 2047 Token leftCurlyBracket = null;
2048 Token rightCurlyBracket = null; 2048 Token rightCurlyBracket = null;
2049 ParameterKind kind = ParameterKind.REQUIRED; 2049 ParameterKind kind = ParameterKind.REQUIRED;
2050 bool firstParameter = true; 2050 bool firstParameter = true;
2051 bool reportedMuliplePositionalGroups = false; 2051 bool reportedMuliplePositionalGroups = false;
2052 bool reportedMulipleNamedGroups = false; 2052 bool reportedMulipleNamedGroups = false;
2053 bool reportedMixedGroups = false; 2053 bool reportedMixedGroups = false;
2054 bool wasOptionalParameter = false; 2054 bool wasOptionalParameter = false;
2055 Token initialToken = null; 2055 Token initialToken = null;
2056 do { 2056 do {
2057 if (firstParameter) { 2057 if (firstParameter) {
2058 firstParameter = false; 2058 firstParameter = false;
2059 } else if (!optional(TokenType.COMMA)) { 2059 } else if (!optional(TokenType.COMMA)) {
2060 // TODO(brianwilkerson) The token is wrong, we need to recover from this case. 2060 // TODO(brianwilkerson) The token is wrong, we need to recover from this case.
2061 if (getEndToken(leftParenthesis) != null) { 2061 if (getEndToken(leftParenthesis) != null) {
2062 reportError13(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme] ); 2062 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [TokenType. COMMA.lexeme]);
2063 } else { 2063 } else {
2064 reportError14(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentTok en.previous, []); 2064 reportErrorForToken(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _curr entToken.previous, []);
2065 break; 2065 break;
2066 } 2066 }
2067 } 2067 }
2068 initialToken = _currentToken; 2068 initialToken = _currentToken;
2069 // 2069 //
2070 // Handle the beginning of parameter groups. 2070 // Handle the beginning of parameter groups.
2071 // 2071 //
2072 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 2072 if (matches(TokenType.OPEN_SQUARE_BRACKET)) {
2073 wasOptionalParameter = true; 2073 wasOptionalParameter = true;
2074 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 2074 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
2075 reportError13(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [] ); 2075 reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMET ER_GROUPS, []);
2076 reportedMuliplePositionalGroups = true; 2076 reportedMuliplePositionalGroups = true;
2077 } 2077 }
2078 if (leftCurlyBracket != null && !reportedMixedGroups) { 2078 if (leftCurlyBracket != null && !reportedMixedGroups) {
2079 reportError13(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2079 reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS, []) ;
2080 reportedMixedGroups = true; 2080 reportedMixedGroups = true;
2081 } 2081 }
2082 leftSquareBracket = andAdvance; 2082 leftSquareBracket = andAdvance;
2083 currentParameters = positionalParameters; 2083 currentParameters = positionalParameters;
2084 kind = ParameterKind.POSITIONAL; 2084 kind = ParameterKind.POSITIONAL;
2085 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2085 } else if (matches(TokenType.OPEN_CURLY_BRACKET)) {
2086 wasOptionalParameter = true; 2086 wasOptionalParameter = true;
2087 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { 2087 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) {
2088 reportError13(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []); 2088 reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GR OUPS, []);
2089 reportedMulipleNamedGroups = true; 2089 reportedMulipleNamedGroups = true;
2090 } 2090 }
2091 if (leftSquareBracket != null && !reportedMixedGroups) { 2091 if (leftSquareBracket != null && !reportedMixedGroups) {
2092 reportError13(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2092 reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS, []) ;
2093 reportedMixedGroups = true; 2093 reportedMixedGroups = true;
2094 } 2094 }
2095 leftCurlyBracket = andAdvance; 2095 leftCurlyBracket = andAdvance;
2096 currentParameters = namedParameters; 2096 currentParameters = namedParameters;
2097 kind = ParameterKind.NAMED; 2097 kind = ParameterKind.NAMED;
2098 } 2098 }
2099 // 2099 //
2100 // Parse and record the parameter. 2100 // Parse and record the parameter.
2101 // 2101 //
2102 FormalParameter parameter = parseFormalParameter(kind); 2102 FormalParameter parameter = parseFormalParameter(kind);
2103 parameters.add(parameter); 2103 parameters.add(parameter);
2104 currentParameters.add(parameter); 2104 currentParameters.add(parameter);
2105 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) { 2105 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) {
2106 reportError12(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, paramet er, []); 2106 reportErrorForNode(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, pa rameter, []);
2107 } 2107 }
2108 // 2108 //
2109 // Handle the end of parameter groups. 2109 // Handle the end of parameter groups.
2110 // 2110 //
2111 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters. 2111 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters.
2112 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 2112 if (matches(TokenType.CLOSE_SQUARE_BRACKET)) {
2113 rightSquareBracket = andAdvance; 2113 rightSquareBracket = andAdvance;
2114 currentParameters = normalParameters; 2114 currentParameters = normalParameters;
2115 if (leftSquareBracket == null) { 2115 if (leftSquareBracket == null) {
2116 if (leftCurlyBracket != null) { 2116 if (leftCurlyBracket != null) {
2117 reportError13(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); 2117 reportErrorForCurrentToken(ParserErrorCode.WRONG_TERMINATOR_FOR_PARA METER_GROUP, ["}"]);
2118 rightCurlyBracket = rightSquareBracket; 2118 rightCurlyBracket = rightSquareBracket;
2119 rightSquareBracket = null; 2119 rightSquareBracket = null;
2120 } else { 2120 } else {
2121 reportError13(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["["]); 2121 reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR _PARAMETER_GROUP, ["["]);
2122 } 2122 }
2123 } 2123 }
2124 kind = ParameterKind.REQUIRED; 2124 kind = ParameterKind.REQUIRED;
2125 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 2125 } else if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
2126 rightCurlyBracket = andAdvance; 2126 rightCurlyBracket = andAdvance;
2127 currentParameters = normalParameters; 2127 currentParameters = normalParameters;
2128 if (leftCurlyBracket == null) { 2128 if (leftCurlyBracket == null) {
2129 if (leftSquareBracket != null) { 2129 if (leftSquareBracket != null) {
2130 reportError13(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]); 2130 reportErrorForCurrentToken(ParserErrorCode.WRONG_TERMINATOR_FOR_PARA METER_GROUP, ["]"]);
2131 rightSquareBracket = rightCurlyBracket; 2131 rightSquareBracket = rightCurlyBracket;
2132 rightCurlyBracket = null; 2132 rightCurlyBracket = null;
2133 } else { 2133 } else {
2134 reportError13(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["{"]); 2134 reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR _PARAMETER_GROUP, ["{"]);
2135 } 2135 }
2136 } 2136 }
2137 kind = ParameterKind.REQUIRED; 2137 kind = ParameterKind.REQUIRED;
2138 } 2138 }
2139 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken); 2139 } while (!matches(TokenType.CLOSE_PAREN) && initialToken != _currentToken);
2140 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2140 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
2141 // 2141 //
2142 // Check that the groups were closed correctly. 2142 // Check that the groups were closed correctly.
2143 // 2143 //
2144 if (leftSquareBracket != null && rightSquareBracket == null) { 2144 if (leftSquareBracket != null && rightSquareBracket == null) {
2145 reportError13(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]" ]); 2145 reportErrorForCurrentToken(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETE R_GROUP, ["]"]);
2146 } 2146 }
2147 if (leftCurlyBracket != null && rightCurlyBracket == null) { 2147 if (leftCurlyBracket != null && rightCurlyBracket == null) {
2148 reportError13(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]); 2148 reportErrorForCurrentToken(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETE R_GROUP, ["}"]);
2149 } 2149 }
2150 // 2150 //
2151 // Build the parameter list. 2151 // Build the parameter list.
2152 // 2152 //
2153 if (leftSquareBracket == null) { 2153 if (leftSquareBracket == null) {
2154 leftSquareBracket = leftCurlyBracket; 2154 leftSquareBracket = leftCurlyBracket;
2155 } 2155 }
2156 if (rightSquareBracket == null) { 2156 if (rightSquareBracket == null) {
2157 rightSquareBracket = rightCurlyBracket; 2157 rightSquareBracket = rightCurlyBracket;
2158 } 2158 }
(...skipping 21 matching lines...) Expand all
2180 * Parse an implements clause. 2180 * Parse an implements clause.
2181 * 2181 *
2182 * <pre> 2182 * <pre>
2183 * implementsClause ::= 2183 * implementsClause ::=
2184 * 'implements' type (',' type)* 2184 * 'implements' type (',' type)*
2185 * </pre> 2185 * </pre>
2186 * 2186 *
2187 * @return the implements clause that was parsed 2187 * @return the implements clause that was parsed
2188 */ 2188 */
2189 ImplementsClause parseImplementsClause() { 2189 ImplementsClause parseImplementsClause() {
2190 Token keyword = expect(Keyword.IMPLEMENTS); 2190 Token keyword = expectKeyword(Keyword.IMPLEMENTS);
2191 List<TypeName> interfaces = new List<TypeName>(); 2191 List<TypeName> interfaces = new List<TypeName>();
2192 interfaces.add(parseTypeName()); 2192 interfaces.add(parseTypeName());
2193 while (optional(TokenType.COMMA)) { 2193 while (optional(TokenType.COMMA)) {
2194 interfaces.add(parseTypeName()); 2194 interfaces.add(parseTypeName());
2195 } 2195 }
2196 return new ImplementsClause(keyword, interfaces); 2196 return new ImplementsClause(keyword, interfaces);
2197 } 2197 }
2198 2198
2199 /** 2199 /**
2200 * Parse a label. 2200 * Parse a label.
2201 * 2201 *
2202 * <pre> 2202 * <pre>
2203 * label ::= 2203 * label ::=
2204 * identifier ':' 2204 * identifier ':'
2205 * </pre> 2205 * </pre>
2206 * 2206 *
2207 * @return the label that was parsed 2207 * @return the label that was parsed
2208 */ 2208 */
2209 Label parseLabel() { 2209 Label parseLabel() {
2210 SimpleIdentifier label = parseSimpleIdentifier(); 2210 SimpleIdentifier label = parseSimpleIdentifier();
2211 Token colon = expect2(TokenType.COLON); 2211 Token colon = expect(TokenType.COLON);
2212 return new Label(label, colon); 2212 return new Label(label, colon);
2213 } 2213 }
2214 2214
2215 /** 2215 /**
2216 * Parse a library identifier. 2216 * Parse a library identifier.
2217 * 2217 *
2218 * <pre> 2218 * <pre>
2219 * libraryIdentifier ::= 2219 * libraryIdentifier ::=
2220 * identifier ('.' identifier)* 2220 * identifier ('.' identifier)*
2221 * </pre> 2221 * </pre>
2222 * 2222 *
2223 * @return the library identifier that was parsed 2223 * @return the library identifier that was parsed
2224 */ 2224 */
2225 LibraryIdentifier parseLibraryIdentifier() { 2225 LibraryIdentifier parseLibraryIdentifier() {
2226 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 2226 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
2227 components.add(parseSimpleIdentifier()); 2227 components.add(parseSimpleIdentifier());
2228 while (matches5(TokenType.PERIOD)) { 2228 while (matches(TokenType.PERIOD)) {
2229 advance(); 2229 advance();
2230 components.add(parseSimpleIdentifier()); 2230 components.add(parseSimpleIdentifier());
2231 } 2231 }
2232 return new LibraryIdentifier(components); 2232 return new LibraryIdentifier(components);
2233 } 2233 }
2234 2234
2235 /** 2235 /**
2236 * Parse a logical or expression. 2236 * Parse a logical or expression.
2237 * 2237 *
2238 * <pre> 2238 * <pre>
2239 * logicalOrExpression ::= 2239 * logicalOrExpression ::=
2240 * logicalAndExpression ('||' logicalAndExpression)* 2240 * logicalAndExpression ('||' logicalAndExpression)*
2241 * </pre> 2241 * </pre>
2242 * 2242 *
2243 * @return the logical or expression that was parsed 2243 * @return the logical or expression that was parsed
2244 */ 2244 */
2245 Expression parseLogicalOrExpression() { 2245 Expression parseLogicalOrExpression() {
2246 Expression expression = parseLogicalAndExpression(); 2246 Expression expression = parseLogicalAndExpression();
2247 while (matches5(TokenType.BAR_BAR)) { 2247 while (matches(TokenType.BAR_BAR)) {
2248 Token operator = andAdvance; 2248 Token operator = andAdvance;
2249 expression = new BinaryExpression(expression, operator, parseLogicalAndExp ression()); 2249 expression = new BinaryExpression(expression, operator, parseLogicalAndExp ression());
2250 } 2250 }
2251 return expression; 2251 return expression;
2252 } 2252 }
2253 2253
2254 /** 2254 /**
2255 * Parse a map literal entry. 2255 * Parse a map literal entry.
2256 * 2256 *
2257 * <pre> 2257 * <pre>
2258 * mapLiteralEntry ::= 2258 * mapLiteralEntry ::=
2259 * expression ':' expression 2259 * expression ':' expression
2260 * </pre> 2260 * </pre>
2261 * 2261 *
2262 * @return the map literal entry that was parsed 2262 * @return the map literal entry that was parsed
2263 */ 2263 */
2264 MapLiteralEntry parseMapLiteralEntry() { 2264 MapLiteralEntry parseMapLiteralEntry() {
2265 Expression key = parseExpression2(); 2265 Expression key = parseExpression2();
2266 Token separator = expect2(TokenType.COLON); 2266 Token separator = expect(TokenType.COLON);
2267 Expression value = parseExpression2(); 2267 Expression value = parseExpression2();
2268 return new MapLiteralEntry(key, separator, value); 2268 return new MapLiteralEntry(key, separator, value);
2269 } 2269 }
2270 2270
2271 /** 2271 /**
2272 * Parse a normal formal parameter. 2272 * Parse a normal formal parameter.
2273 * 2273 *
2274 * <pre> 2274 * <pre>
2275 * normalFormalParameter ::= 2275 * normalFormalParameter ::=
2276 * functionSignature 2276 * functionSignature
(...skipping 11 matching lines...) Expand all
2288 * | metadata identifier 2288 * | metadata identifier
2289 * </pre> 2289 * </pre>
2290 * 2290 *
2291 * @return the normal formal parameter that was parsed 2291 * @return the normal formal parameter that was parsed
2292 */ 2292 */
2293 NormalFormalParameter parseNormalFormalParameter() { 2293 NormalFormalParameter parseNormalFormalParameter() {
2294 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 2294 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
2295 FinalConstVarOrType holder = parseFinalConstVarOrType(true); 2295 FinalConstVarOrType holder = parseFinalConstVarOrType(true);
2296 Token thisKeyword = null; 2296 Token thisKeyword = null;
2297 Token period = null; 2297 Token period = null;
2298 if (matches(Keyword.THIS)) { 2298 if (matchesKeyword(Keyword.THIS)) {
2299 thisKeyword = andAdvance; 2299 thisKeyword = andAdvance;
2300 period = expect2(TokenType.PERIOD); 2300 period = expect(TokenType.PERIOD);
2301 } 2301 }
2302 SimpleIdentifier identifier = parseSimpleIdentifier(); 2302 SimpleIdentifier identifier = parseSimpleIdentifier();
2303 if (matches5(TokenType.OPEN_PAREN)) { 2303 if (matches(TokenType.OPEN_PAREN)) {
2304 FormalParameterList parameters = parseFormalParameterList(); 2304 FormalParameterList parameters = parseFormalParameterList();
2305 if (thisKeyword == null) { 2305 if (thisKeyword == null) {
2306 if (holder.keyword != null) { 2306 if (holder.keyword != null) {
2307 reportError14(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []); 2307 reportErrorForToken(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, hold er.keyword, []);
2308 } 2308 }
2309 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters); 2309 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters);
2310 } else { 2310 } else {
2311 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters); 2311 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters);
2312 } 2312 }
2313 } 2313 }
2314 TypeName type = holder.type; 2314 TypeName type = holder.type;
2315 if (type != null) { 2315 if (type != null) {
2316 if (matches3(type.name.beginToken, Keyword.VOID)) { 2316 if (tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) {
2317 reportError14(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []); 2317 reportErrorForToken(ParserErrorCode.VOID_PARAMETER, type.name.beginToken , []);
2318 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) { 2318 } else if (holder.keyword != null && tokenMatchesKeyword(holder.keyword, K eyword.VAR)) {
2319 reportError14(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []); 2319 reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []);
2320 } 2320 }
2321 } 2321 }
2322 if (thisKeyword != null) { 2322 if (thisKeyword != null) {
2323 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l); 2323 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l);
2324 } 2324 }
2325 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier); 2325 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier);
2326 } 2326 }
2327 2327
2328 /** 2328 /**
2329 * Parse a prefixed identifier. 2329 * Parse a prefixed identifier.
2330 * 2330 *
2331 * <pre> 2331 * <pre>
2332 * prefixedIdentifier ::= 2332 * prefixedIdentifier ::=
2333 * identifier ('.' identifier)? 2333 * identifier ('.' identifier)?
2334 * </pre> 2334 * </pre>
2335 * 2335 *
2336 * @return the prefixed identifier that was parsed 2336 * @return the prefixed identifier that was parsed
2337 */ 2337 */
2338 Identifier parsePrefixedIdentifier() { 2338 Identifier parsePrefixedIdentifier() {
2339 SimpleIdentifier qualifier = parseSimpleIdentifier(); 2339 SimpleIdentifier qualifier = parseSimpleIdentifier();
2340 if (!matches5(TokenType.PERIOD)) { 2340 if (!matches(TokenType.PERIOD)) {
2341 return qualifier; 2341 return qualifier;
2342 } 2342 }
2343 Token period = andAdvance; 2343 Token period = andAdvance;
2344 SimpleIdentifier qualified = parseSimpleIdentifier(); 2344 SimpleIdentifier qualified = parseSimpleIdentifier();
2345 return new PrefixedIdentifier(qualifier, period, qualified); 2345 return new PrefixedIdentifier(qualifier, period, qualified);
2346 } 2346 }
2347 2347
2348 /** 2348 /**
2349 * Parse a return type. 2349 * Parse a return type.
2350 * 2350 *
2351 * <pre> 2351 * <pre>
2352 * returnType ::= 2352 * returnType ::=
2353 * 'void' 2353 * 'void'
2354 * | type 2354 * | type
2355 * </pre> 2355 * </pre>
2356 * 2356 *
2357 * @return the return type that was parsed 2357 * @return the return type that was parsed
2358 */ 2358 */
2359 TypeName parseReturnType() { 2359 TypeName parseReturnType() {
2360 if (matches(Keyword.VOID)) { 2360 if (matchesKeyword(Keyword.VOID)) {
2361 return new TypeName(new SimpleIdentifier(andAdvance), null); 2361 return new TypeName(new SimpleIdentifier(andAdvance), null);
2362 } else { 2362 } else {
2363 return parseTypeName(); 2363 return parseTypeName();
2364 } 2364 }
2365 } 2365 }
2366 2366
2367 /** 2367 /**
2368 * Parse a simple identifier. 2368 * Parse a simple identifier.
2369 * 2369 *
2370 * <pre> 2370 * <pre>
2371 * identifier ::= 2371 * identifier ::=
2372 * IDENTIFIER 2372 * IDENTIFIER
2373 * </pre> 2373 * </pre>
2374 * 2374 *
2375 * @return the simple identifier that was parsed 2375 * @return the simple identifier that was parsed
2376 */ 2376 */
2377 SimpleIdentifier parseSimpleIdentifier() { 2377 SimpleIdentifier parseSimpleIdentifier() {
2378 if (matchesIdentifier()) { 2378 if (matchesIdentifier()) {
2379 return new SimpleIdentifier(andAdvance); 2379 return new SimpleIdentifier(andAdvance);
2380 } 2380 }
2381 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []); 2381 reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []);
2382 return createSyntheticIdentifier(); 2382 return createSyntheticIdentifier();
2383 } 2383 }
2384 2384
2385 /** 2385 /**
2386 * Parse a statement. 2386 * Parse a statement.
2387 * 2387 *
2388 * <pre> 2388 * <pre>
2389 * statement ::= 2389 * statement ::=
2390 * label* nonLabeledStatement 2390 * label* nonLabeledStatement
2391 * </pre> 2391 * </pre>
2392 * 2392 *
2393 * @return the statement that was parsed 2393 * @return the statement that was parsed
2394 */ 2394 */
2395 Statement parseStatement2() { 2395 Statement parseStatement2() {
2396 List<Label> labels = new List<Label>(); 2396 List<Label> labels = new List<Label>();
2397 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 2397 while (matchesIdentifier() && tokenMatches(peek(), TokenType.COLON)) {
2398 labels.add(parseLabel()); 2398 labels.add(parseLabel());
2399 } 2399 }
2400 Statement statement = parseNonLabeledStatement(); 2400 Statement statement = parseNonLabeledStatement();
2401 if (labels.isEmpty) { 2401 if (labels.isEmpty) {
2402 return statement; 2402 return statement;
2403 } 2403 }
2404 return new LabeledStatement(labels, statement); 2404 return new LabeledStatement(labels, statement);
2405 } 2405 }
2406 2406
2407 /** 2407 /**
2408 * Parse a string literal. 2408 * Parse a string literal.
2409 * 2409 *
2410 * <pre> 2410 * <pre>
2411 * stringLiteral ::= 2411 * stringLiteral ::=
2412 * MULTI_LINE_STRING+ 2412 * MULTI_LINE_STRING+
2413 * | SINGLE_LINE_STRING+ 2413 * | SINGLE_LINE_STRING+
2414 * </pre> 2414 * </pre>
2415 * 2415 *
2416 * @return the string literal that was parsed 2416 * @return the string literal that was parsed
2417 */ 2417 */
2418 StringLiteral parseStringLiteral() { 2418 StringLiteral parseStringLiteral() {
2419 List<StringLiteral> strings = new List<StringLiteral>(); 2419 List<StringLiteral> strings = new List<StringLiteral>();
2420 while (matches5(TokenType.STRING)) { 2420 while (matches(TokenType.STRING)) {
2421 Token string = andAdvance; 2421 Token string = andAdvance;
2422 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) { 2422 if (matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches(TokenTyp e.STRING_INTERPOLATION_IDENTIFIER)) {
2423 strings.add(parseStringInterpolation(string)); 2423 strings.add(parseStringInterpolation(string));
2424 } else { 2424 } else {
2425 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true))); 2425 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true)));
2426 } 2426 }
2427 } 2427 }
2428 if (strings.length < 1) { 2428 if (strings.length < 1) {
2429 reportError13(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 2429 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_STRING_LITERAL, []);
2430 return createSyntheticStringLiteral(); 2430 return createSyntheticStringLiteral();
2431 } else if (strings.length == 1) { 2431 } else if (strings.length == 1) {
2432 return strings[0]; 2432 return strings[0];
2433 } else { 2433 } else {
2434 return new AdjacentStrings(strings); 2434 return new AdjacentStrings(strings);
2435 } 2435 }
2436 } 2436 }
2437 2437
2438 /** 2438 /**
2439 * Parse a list of type arguments. 2439 * Parse a list of type arguments.
2440 * 2440 *
2441 * <pre> 2441 * <pre>
2442 * typeArguments ::= 2442 * typeArguments ::=
2443 * '<' typeList '>' 2443 * '<' typeList '>'
2444 * 2444 *
2445 * typeList ::= 2445 * typeList ::=
2446 * type (',' type)* 2446 * type (',' type)*
2447 * </pre> 2447 * </pre>
2448 * 2448 *
2449 * @return the type argument list that was parsed 2449 * @return the type argument list that was parsed
2450 */ 2450 */
2451 TypeArgumentList parseTypeArgumentList() { 2451 TypeArgumentList parseTypeArgumentList() {
2452 Token leftBracket = expect2(TokenType.LT); 2452 Token leftBracket = expect(TokenType.LT);
2453 List<TypeName> arguments = new List<TypeName>(); 2453 List<TypeName> arguments = new List<TypeName>();
2454 arguments.add(parseTypeName()); 2454 arguments.add(parseTypeName());
2455 while (optional(TokenType.COMMA)) { 2455 while (optional(TokenType.COMMA)) {
2456 arguments.add(parseTypeName()); 2456 arguments.add(parseTypeName());
2457 } 2457 }
2458 Token rightBracket = expect2(TokenType.GT); 2458 Token rightBracket = expect(TokenType.GT);
2459 return new TypeArgumentList(leftBracket, arguments, rightBracket); 2459 return new TypeArgumentList(leftBracket, arguments, rightBracket);
2460 } 2460 }
2461 2461
2462 /** 2462 /**
2463 * Parse a type name. 2463 * Parse a type name.
2464 * 2464 *
2465 * <pre> 2465 * <pre>
2466 * type ::= 2466 * type ::=
2467 * qualified typeArguments? 2467 * qualified typeArguments?
2468 * </pre> 2468 * </pre>
2469 * 2469 *
2470 * @return the type name that was parsed 2470 * @return the type name that was parsed
2471 */ 2471 */
2472 TypeName parseTypeName() { 2472 TypeName parseTypeName() {
2473 Identifier typeName; 2473 Identifier typeName;
2474 if (matches(Keyword.VAR)) { 2474 if (matchesKeyword(Keyword.VAR)) {
2475 reportError13(ParserErrorCode.VAR_AS_TYPE_NAME, []); 2475 reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME, []);
2476 typeName = new SimpleIdentifier(andAdvance); 2476 typeName = new SimpleIdentifier(andAdvance);
2477 } else if (matchesIdentifier()) { 2477 } else if (matchesIdentifier()) {
2478 typeName = parsePrefixedIdentifier(); 2478 typeName = parsePrefixedIdentifier();
2479 } else { 2479 } else {
2480 typeName = createSyntheticIdentifier(); 2480 typeName = createSyntheticIdentifier();
2481 reportError13(ParserErrorCode.EXPECTED_TYPE_NAME, []); 2481 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME, []);
2482 } 2482 }
2483 TypeArgumentList typeArguments = null; 2483 TypeArgumentList typeArguments = null;
2484 if (matches5(TokenType.LT)) { 2484 if (matches(TokenType.LT)) {
2485 typeArguments = parseTypeArgumentList(); 2485 typeArguments = parseTypeArgumentList();
2486 } 2486 }
2487 return new TypeName(typeName, typeArguments); 2487 return new TypeName(typeName, typeArguments);
2488 } 2488 }
2489 2489
2490 /** 2490 /**
2491 * Parse a type parameter. 2491 * Parse a type parameter.
2492 * 2492 *
2493 * <pre> 2493 * <pre>
2494 * typeParameter ::= 2494 * typeParameter ::=
2495 * metadata name ('extends' bound)? 2495 * metadata name ('extends' bound)?
2496 * </pre> 2496 * </pre>
2497 * 2497 *
2498 * @return the type parameter that was parsed 2498 * @return the type parameter that was parsed
2499 */ 2499 */
2500 TypeParameter parseTypeParameter() { 2500 TypeParameter parseTypeParameter() {
2501 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 2501 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
2502 SimpleIdentifier name = parseSimpleIdentifier(); 2502 SimpleIdentifier name = parseSimpleIdentifier();
2503 if (matches(Keyword.EXTENDS)) { 2503 if (matchesKeyword(Keyword.EXTENDS)) {
2504 Token keyword = andAdvance; 2504 Token keyword = andAdvance;
2505 TypeName bound = parseTypeName(); 2505 TypeName bound = parseTypeName();
2506 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.me tadata, name, keyword, bound); 2506 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.me tadata, name, keyword, bound);
2507 } 2507 }
2508 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.meta data, name, null, null); 2508 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.meta data, name, null, null);
2509 } 2509 }
2510 2510
2511 /** 2511 /**
2512 * Parse a list of type parameters. 2512 * Parse a list of type parameters.
2513 * 2513 *
2514 * <pre> 2514 * <pre>
2515 * typeParameterList ::= 2515 * typeParameterList ::=
2516 * '<' typeParameter (',' typeParameter)* '>' 2516 * '<' typeParameter (',' typeParameter)* '>'
2517 * </pre> 2517 * </pre>
2518 * 2518 *
2519 * @return the list of type parameters that were parsed 2519 * @return the list of type parameters that were parsed
2520 */ 2520 */
2521 TypeParameterList parseTypeParameterList() { 2521 TypeParameterList parseTypeParameterList() {
2522 Token leftBracket = expect2(TokenType.LT); 2522 Token leftBracket = expect(TokenType.LT);
2523 List<TypeParameter> typeParameters = new List<TypeParameter>(); 2523 List<TypeParameter> typeParameters = new List<TypeParameter>();
2524 typeParameters.add(parseTypeParameter()); 2524 typeParameters.add(parseTypeParameter());
2525 while (optional(TokenType.COMMA)) { 2525 while (optional(TokenType.COMMA)) {
2526 typeParameters.add(parseTypeParameter()); 2526 typeParameters.add(parseTypeParameter());
2527 } 2527 }
2528 Token rightBracket = expect2(TokenType.GT); 2528 Token rightBracket = expect(TokenType.GT);
2529 return new TypeParameterList(leftBracket, typeParameters, rightBracket); 2529 return new TypeParameterList(leftBracket, typeParameters, rightBracket);
2530 } 2530 }
2531 2531
2532 /** 2532 /**
2533 * Parse a with clause. 2533 * Parse a with clause.
2534 * 2534 *
2535 * <pre> 2535 * <pre>
2536 * withClause ::= 2536 * withClause ::=
2537 * 'with' typeName (',' typeName)* 2537 * 'with' typeName (',' typeName)*
2538 * </pre> 2538 * </pre>
2539 * 2539 *
2540 * @return the with clause that was parsed 2540 * @return the with clause that was parsed
2541 */ 2541 */
2542 WithClause parseWithClause() { 2542 WithClause parseWithClause() {
2543 Token with2 = expect(Keyword.WITH); 2543 Token with2 = expectKeyword(Keyword.WITH);
2544 List<TypeName> types = new List<TypeName>(); 2544 List<TypeName> types = new List<TypeName>();
2545 types.add(parseTypeName()); 2545 types.add(parseTypeName());
2546 while (optional(TokenType.COMMA)) { 2546 while (optional(TokenType.COMMA)) {
2547 types.add(parseTypeName()); 2547 types.add(parseTypeName());
2548 } 2548 }
2549 return new WithClause(with2, types); 2549 return new WithClause(with2, types);
2550 } 2550 }
2551 2551
2552 void set currentToken(Token currentToken) { 2552 void set currentToken(Token currentToken) {
2553 this._currentToken = currentToken; 2553 this._currentToken = currentToken;
(...skipping 12 matching lines...) Expand all
2566 * value is invalid. 2566 * value is invalid.
2567 * 2567 *
2568 * @param builder the builder to which the scalar value is to be appended 2568 * @param builder the builder to which the scalar value is to be appended
2569 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value 2569 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value
2570 * @param scalarValue the value to be appended 2570 * @param scalarValue the value to be appended
2571 * @param startIndex the index of the first character representing the scalar value 2571 * @param startIndex the index of the first character representing the scalar value
2572 * @param endIndex the index of the last character representing the scalar val ue 2572 * @param endIndex the index of the last character representing the scalar val ue
2573 */ 2573 */
2574 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s calarValue, int startIndex, int endIndex) { 2574 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s calarValue, int startIndex, int endIndex) {
2575 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) { 2575 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) {
2576 reportError13(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); 2576 reportErrorForCurrentToken(ParserErrorCode.INVALID_CODE_POINT, [escapeSequ ence]);
2577 return; 2577 return;
2578 } 2578 }
2579 if (scalarValue < Character.MAX_VALUE) { 2579 if (scalarValue < Character.MAX_VALUE) {
2580 builder.appendChar(scalarValue); 2580 builder.appendChar(scalarValue);
2581 } else { 2581 } else {
2582 builder.append(Character.toChars(scalarValue)); 2582 builder.append(Character.toChars(scalarValue));
2583 } 2583 }
2584 } 2584 }
2585 2585
2586 /** 2586 /**
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 FunctionDeclaration convertToFunctionDeclaration(MethodDeclaration method) => new FunctionDeclaration(method.documentationComment, method.metadata, method.ext ernalKeyword, method.returnType, method.propertyKeyword, method.name, new Functi onExpression(method.parameters, method.body)); 2640 FunctionDeclaration convertToFunctionDeclaration(MethodDeclaration method) => new FunctionDeclaration(method.documentationComment, method.metadata, method.ext ernalKeyword, method.returnType, method.propertyKeyword, method.name, new Functi onExpression(method.parameters, method.body));
2641 2641
2642 /** 2642 /**
2643 * Return `true` if the current token could be the start of a compilation unit member. This 2643 * Return `true` if the current token could be the start of a compilation unit member. This
2644 * method is used for recovery purposes to decide when to stop skipping tokens after finding an 2644 * method is used for recovery purposes to decide when to stop skipping tokens after finding an
2645 * error while parsing a compilation unit member. 2645 * error while parsing a compilation unit member.
2646 * 2646 *
2647 * @return `true` if the current token could be the start of a compilation uni t member 2647 * @return `true` if the current token could be the start of a compilation uni t member
2648 */ 2648 */
2649 bool couldBeStartOfCompilationUnitMember() { 2649 bool couldBeStartOfCompilationUnitMember() {
2650 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword.L IBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !mat ches4(peek(), TokenType.LT)) { 2650 if ((matchesKeyword(Keyword.IMPORT) || matchesKeyword(Keyword.EXPORT) || mat chesKeyword(Keyword.LIBRARY) || matchesKeyword(Keyword.PART)) && !tokenMatches(p eek(), TokenType.PERIOD) && !tokenMatches(peek(), TokenType.LT)) {
2651 // This looks like the start of a directive 2651 // This looks like the start of a directive
2652 return true; 2652 return true;
2653 } else if (matches(Keyword.CLASS)) { 2653 } else if (matchesKeyword(Keyword.CLASS)) {
2654 // This looks like the start of a class definition 2654 // This looks like the start of a class definition
2655 return true; 2655 return true;
2656 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) & & !matches4(peek(), TokenType.LT)) { 2656 } else if (matchesKeyword(Keyword.TYPEDEF) && !tokenMatches(peek(), TokenTyp e.PERIOD) && !tokenMatches(peek(), TokenType.LT)) {
2657 // This looks like the start of a typedef 2657 // This looks like the start of a typedef
2658 return true; 2658 return true;
2659 } else if (matches(Keyword.VOID) || ((matches(Keyword.GET) || matches(Keywor d.SET)) && matchesIdentifier2(peek())) || (matches(Keyword.OPERATOR) && isOperat or(peek()))) { 2659 } else if (matchesKeyword(Keyword.VOID) || ((matchesKeyword(Keyword.GET) || matchesKeyword(Keyword.SET)) && tokenMatchesIdentifier(peek())) || (matchesKeywo rd(Keyword.OPERATOR) && isOperator(peek()))) {
2660 // This looks like the start of a function 2660 // This looks like the start of a function
2661 return true; 2661 return true;
2662 } else if (matchesIdentifier()) { 2662 } else if (matchesIdentifier()) {
2663 if (matches4(peek(), TokenType.OPEN_PAREN)) { 2663 if (tokenMatches(peek(), TokenType.OPEN_PAREN)) {
2664 // This looks like the start of a function 2664 // This looks like the start of a function
2665 return true; 2665 return true;
2666 } 2666 }
2667 Token token = skipReturnType(_currentToken); 2667 Token token = skipReturnType(_currentToken);
2668 if (token == null) { 2668 if (token == null) {
2669 return false; 2669 return false;
2670 } 2670 }
2671 if (matches(Keyword.GET) || matches(Keyword.SET) || (matches(Keyword.OPERA TOR) && isOperator(peek())) || matchesIdentifier()) { 2671 if (matchesKeyword(Keyword.GET) || matchesKeyword(Keyword.SET) || (matches Keyword(Keyword.OPERATOR) && isOperator(peek())) || matchesIdentifier()) {
2672 return true; 2672 return true;
2673 } 2673 }
2674 } 2674 }
2675 return false; 2675 return false;
2676 } 2676 }
2677 2677
2678 /** 2678 /**
2679 * Create a synthetic identifier. 2679 * Create a synthetic identifier.
2680 * 2680 *
2681 * @return the synthetic identifier that was created 2681 * @return the synthetic identifier that was created
2682 */ 2682 */
2683 SimpleIdentifier createSyntheticIdentifier() { 2683 SimpleIdentifier createSyntheticIdentifier() {
2684 Token syntheticToken; 2684 Token syntheticToken;
2685 if (identical(_currentToken.type, TokenType.KEYWORD)) { 2685 if (identical(_currentToken.type, TokenType.KEYWORD)) {
2686 // Consider current keyword token as an identifier. 2686 // Consider current keyword token as an identifier.
2687 // It is not always true, e.g. "^is T" where "^" is place the place for sy nthetic identifier. 2687 // It is not always true, e.g. "^is T" where "^" is place the place for sy nthetic identifier.
2688 // By creating SyntheticStringToken we can distinguish a real identifier f rom synthetic. 2688 // By creating SyntheticStringToken we can distinguish a real identifier f rom synthetic.
2689 // In the code completion behavior will depend on a cursor position - befo re or on "is". 2689 // In the code completion behavior will depend on a cursor position - befo re or on "is".
2690 syntheticToken = injectToken(new SyntheticStringToken(TokenType.IDENTIFIER , _currentToken.lexeme, _currentToken.offset)); 2690 syntheticToken = injectToken(new SyntheticStringToken(TokenType.IDENTIFIER , _currentToken.lexeme, _currentToken.offset));
2691 } else { 2691 } else {
2692 syntheticToken = createSyntheticToken2(TokenType.IDENTIFIER); 2692 syntheticToken = createSyntheticToken(TokenType.IDENTIFIER);
2693 } 2693 }
2694 return new SimpleIdentifier(syntheticToken); 2694 return new SimpleIdentifier(syntheticToken);
2695 } 2695 }
2696 2696
2697 /** 2697 /**
2698 * Create a synthetic token representing the given keyword.
2699 *
2700 * @return the synthetic token that was created
2701 */
2702 Token createSyntheticKeyword(Keyword keyword) => injectToken(new Parser_Synthe ticKeywordToken(keyword, _currentToken.offset));
2703
2704 /**
2698 * Create a synthetic string literal. 2705 * Create a synthetic string literal.
2699 * 2706 *
2700 * @return the synthetic string literal that was created 2707 * @return the synthetic string literal that was created
2701 */ 2708 */
2702 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral( createSyntheticToken2(TokenType.STRING), ""); 2709 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral( createSyntheticToken(TokenType.STRING), "");
2703
2704 /**
2705 * Create a synthetic token representing the given keyword.
2706 *
2707 * @return the synthetic token that was created
2708 */
2709 Token createSyntheticToken(Keyword keyword) => injectToken(new Parser_Syntheti cKeywordToken(keyword, _currentToken.offset));
2710 2710
2711 /** 2711 /**
2712 * Create a synthetic token with the given type. 2712 * Create a synthetic token with the given type.
2713 * 2713 *
2714 * @return the synthetic token that was created 2714 * @return the synthetic token that was created
2715 */ 2715 */
2716 Token createSyntheticToken2(TokenType type) => injectToken(new StringToken(typ e, "", _currentToken.offset)); 2716 Token createSyntheticToken(TokenType type) => injectToken(new StringToken(type , "", _currentToken.offset));
2717 2717
2718 /** 2718 /**
2719 * Check that the given expression is assignable and report an error if it isn 't. 2719 * Check that the given expression is assignable and report an error if it isn 't.
2720 * 2720 *
2721 * <pre> 2721 * <pre>
2722 * assignableExpression ::= 2722 * assignableExpression ::=
2723 * primary (arguments* assignableSelector)+ 2723 * primary (arguments* assignableSelector)+
2724 * | 'super' assignableSelector 2724 * | 'super' assignableSelector
2725 * | identifier 2725 * | identifier
2726 * 2726 *
2727 * assignableSelector ::= 2727 * assignableSelector ::=
2728 * '[' expression ']' 2728 * '[' expression ']'
2729 * | '.' identifier 2729 * | '.' identifier
2730 * </pre> 2730 * </pre>
2731 * 2731 *
2732 * @param expression the expression being checked 2732 * @param expression the expression being checked
2733 */ 2733 */
2734 void ensureAssignable(Expression expression) { 2734 void ensureAssignable(Expression expression) {
2735 if (expression != null && !expression.isAssignable) { 2735 if (expression != null && !expression.isAssignable) {
2736 reportError13(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); 2736 reportErrorForCurrentToken(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIG NABLE, []);
2737 } 2737 }
2738 } 2738 }
2739 2739
2740 /** 2740 /**
2741 * If the current token has the expected type, return it after advancing to th e next token.
2742 * Otherwise report an error and return the current token without advancing.
2743 *
2744 * @param type the type of token that is expected
2745 * @return the token that matched the given type
2746 */
2747 Token expect(TokenType type) {
2748 if (matches(type)) {
2749 return andAdvance;
2750 }
2751 // Remove uses of this method in favor of matches?
2752 // Pass in the error code to use to report the error?
2753 if (identical(type, TokenType.SEMICOLON)) {
2754 reportErrorForToken(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous , [type.lexeme]);
2755 } else {
2756 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]);
2757 }
2758 return _currentToken;
2759 }
2760
2761 /**
2741 * If the current token is a keyword matching the given string, return it afte r advancing to the 2762 * If the current token is a keyword matching the given string, return it afte r advancing to the
2742 * next token. Otherwise report an error and return the current token without advancing. 2763 * next token. Otherwise report an error and return the current token without advancing.
2743 * 2764 *
2744 * @param keyword the keyword that is expected 2765 * @param keyword the keyword that is expected
2745 * @return the token that matched the given type 2766 * @return the token that matched the given type
2746 */ 2767 */
2747 Token expect(Keyword keyword) { 2768 Token expectKeyword(Keyword keyword) {
2748 if (matches(keyword)) { 2769 if (matchesKeyword(keyword)) {
2749 return andAdvance; 2770 return andAdvance;
2750 } 2771 }
2751 // Remove uses of this method in favor of matches? 2772 // Remove uses of this method in favor of matches?
2752 // Pass in the error code to use to report the error? 2773 // Pass in the error code to use to report the error?
2753 reportError13(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]); 2774 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]) ;
2754 return _currentToken; 2775 return _currentToken;
2755 } 2776 }
2756 2777
2757 /**
2758 * If the current token has the expected type, return it after advancing to th e next token.
2759 * Otherwise report an error and return the current token without advancing.
2760 *
2761 * @param type the type of token that is expected
2762 * @return the token that matched the given type
2763 */
2764 Token expect2(TokenType type) {
2765 if (matches5(type)) {
2766 return andAdvance;
2767 }
2768 // Remove uses of this method in favor of matches?
2769 // Pass in the error code to use to report the error?
2770 if (identical(type, TokenType.SEMICOLON)) {
2771 reportError14(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [typ e.lexeme]);
2772 } else {
2773 reportError13(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]);
2774 }
2775 return _currentToken;
2776 }
2777
2778 /** 2778 /**
2779 * If [currentToken] is a semicolon, returns it; otherwise reports error and c reates a 2779 * If [currentToken] is a semicolon, returns it; otherwise reports error and c reates a
2780 * synthetic one. 2780 * synthetic one.
2781 * 2781 *
2782 * TODO(scheglov) consider pushing this into [expect] 2782 * TODO(scheglov) consider pushing this into [expect]
2783 */ 2783 */
2784 Token expectSemicolon() { 2784 Token expectSemicolon() {
2785 if (matches5(TokenType.SEMICOLON)) { 2785 if (matches(TokenType.SEMICOLON)) {
2786 return andAdvance; 2786 return andAdvance;
2787 } else { 2787 } else {
2788 reportError14(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [";" ]); 2788 reportErrorForToken(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous , [";"]);
2789 return createSyntheticToken2(TokenType.SEMICOLON); 2789 return createSyntheticToken(TokenType.SEMICOLON);
2790 } 2790 }
2791 } 2791 }
2792 2792
2793 /** 2793 /**
2794 * Search the given list of ranges for a range that contains the given index. Return the range 2794 * Search the given list of ranges for a range that contains the given index. Return the range
2795 * that was found, or `null` if none of the ranges contain the index. 2795 * that was found, or `null` if none of the ranges contain the index.
2796 * 2796 *
2797 * @param ranges the ranges to be searched 2797 * @param ranges the ranges to be searched
2798 * @param index the index contained in the returned range 2798 * @param index the index contained in the returned range
2799 * @return the range that was found 2799 * @return the range that was found
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 * type. 2894 * type.
2895 * 2895 *
2896 * @return `true` if we can successfully parse the rest of a type alias if we first parse a 2896 * @return `true` if we can successfully parse the rest of a type alias if we first parse a
2897 * return type. 2897 * return type.
2898 */ 2898 */
2899 bool hasReturnTypeInTypeAlias() { 2899 bool hasReturnTypeInTypeAlias() {
2900 Token next = skipReturnType(_currentToken); 2900 Token next = skipReturnType(_currentToken);
2901 if (next == null) { 2901 if (next == null) {
2902 return false; 2902 return false;
2903 } 2903 }
2904 return matchesIdentifier2(next); 2904 return tokenMatchesIdentifier(next);
2905 } 2905 }
2906 2906
2907 /** 2907 /**
2908 * Inject the given token into the token stream immediately before the current token. 2908 * Inject the given token into the token stream immediately before the current token.
2909 * 2909 *
2910 * @param token the token to be added to the token stream 2910 * @param token the token to be added to the token stream
2911 * @return the token that was just added to the token stream 2911 * @return the token that was just added to the token stream
2912 */ 2912 */
2913 Token injectToken(Token token) { 2913 Token injectToken(Token token) {
2914 Token previous = _currentToken.previous; 2914 Token previous = _currentToken.previous;
2915 token.setNext(_currentToken); 2915 token.setNext(_currentToken);
2916 previous.setNext(token); 2916 previous.setNext(token);
2917 return token; 2917 return token;
2918 } 2918 }
2919 2919
2920 /** 2920 /**
2921 * Return `true` if the current token appears to be the beginning of a functio n declaration. 2921 * Return `true` if the current token appears to be the beginning of a functio n declaration.
2922 * 2922 *
2923 * @return `true` if the current token appears to be the beginning of a functi on declaration 2923 * @return `true` if the current token appears to be the beginning of a functi on declaration
2924 */ 2924 */
2925 bool isFunctionDeclaration() { 2925 bool isFunctionDeclaration() {
2926 if (matches(Keyword.VOID)) { 2926 if (matchesKeyword(Keyword.VOID)) {
2927 return true; 2927 return true;
2928 } 2928 }
2929 Token afterReturnType = skipTypeName(_currentToken); 2929 Token afterReturnType = skipTypeName(_currentToken);
2930 if (afterReturnType == null) { 2930 if (afterReturnType == null) {
2931 // There was no return type, but it is optional, so go back to where we st arted. 2931 // There was no return type, but it is optional, so go back to where we st arted.
2932 afterReturnType = _currentToken; 2932 afterReturnType = _currentToken;
2933 } 2933 }
2934 Token afterIdentifier = skipSimpleIdentifier(afterReturnType); 2934 Token afterIdentifier = skipSimpleIdentifier(afterReturnType);
2935 if (afterIdentifier == null) { 2935 if (afterIdentifier == null) {
2936 // It's possible that we parsed the function name as if it were a type nam e, so see whether 2936 // It's possible that we parsed the function name as if it were a type nam e, so see whether
2937 // it makes sense if we assume that there is no type. 2937 // it makes sense if we assume that there is no type.
2938 afterIdentifier = skipSimpleIdentifier(_currentToken); 2938 afterIdentifier = skipSimpleIdentifier(_currentToken);
2939 } 2939 }
2940 if (afterIdentifier == null) { 2940 if (afterIdentifier == null) {
2941 return false; 2941 return false;
2942 } 2942 }
2943 if (isFunctionExpression(afterIdentifier)) { 2943 if (isFunctionExpression(afterIdentifier)) {
2944 return true; 2944 return true;
2945 } 2945 }
2946 // It's possible that we have found a getter. While this isn't valid at this point we test for 2946 // It's possible that we have found a getter. While this isn't valid at this point we test for
2947 // it in order to recover better. 2947 // it in order to recover better.
2948 if (matches(Keyword.GET)) { 2948 if (matchesKeyword(Keyword.GET)) {
2949 Token afterName = skipSimpleIdentifier(_currentToken.next); 2949 Token afterName = skipSimpleIdentifier(_currentToken.next);
2950 if (afterName == null) { 2950 if (afterName == null) {
2951 return false; 2951 return false;
2952 } 2952 }
2953 return matches4(afterName, TokenType.FUNCTION) || matches4(afterName, Toke nType.OPEN_CURLY_BRACKET); 2953 return tokenMatches(afterName, TokenType.FUNCTION) || tokenMatches(afterNa me, TokenType.OPEN_CURLY_BRACKET);
2954 } 2954 }
2955 return false; 2955 return false;
2956 } 2956 }
2957 2957
2958 /** 2958 /**
2959 * Return `true` if the given token appears to be the beginning of a function expression. 2959 * Return `true` if the given token appears to be the beginning of a function expression.
2960 * 2960 *
2961 * @param startToken the token that might be the start of a function expressio n 2961 * @param startToken the token that might be the start of a function expressio n
2962 * @return `true` if the given token appears to be the beginning of a function expression 2962 * @return `true` if the given token appears to be the beginning of a function expression
2963 */ 2963 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 * qualified typeArguments? 2999 * qualified typeArguments?
3000 * 3000 *
3001 * initializedIdentifier ::= 3001 * initializedIdentifier ::=
3002 * identifier ('=' expression)? 3002 * identifier ('=' expression)?
3003 * </pre> 3003 * </pre>
3004 * 3004 *
3005 * @return `true` if the current token is the first token in an initialized va riable 3005 * @return `true` if the current token is the first token in an initialized va riable
3006 * declaration 3006 * declaration
3007 */ 3007 */
3008 bool isInitializedVariableDeclaration() { 3008 bool isInitializedVariableDeclaration() {
3009 if (matches(Keyword.FINAL) || matches(Keyword.VAR)) { 3009 if (matchesKeyword(Keyword.FINAL) || matchesKeyword(Keyword.VAR)) {
3010 // An expression cannot start with a keyword other than 'const', 'rethrow' , or 'throw'. 3010 // An expression cannot start with a keyword other than 'const', 'rethrow' , or 'throw'.
3011 return true; 3011 return true;
3012 } 3012 }
3013 if (matches(Keyword.CONST)) { 3013 if (matchesKeyword(Keyword.CONST)) {
3014 // Look to see whether we might be at the start of a list or map literal, otherwise this 3014 // Look to see whether we might be at the start of a list or map literal, otherwise this
3015 // should be the start of a variable declaration. 3015 // should be the start of a variable declaration.
3016 return !matchesAny(peek(), [ 3016 return !matchesAny(peek(), [
3017 TokenType.LT, 3017 TokenType.LT,
3018 TokenType.OPEN_CURLY_BRACKET, 3018 TokenType.OPEN_CURLY_BRACKET,
3019 TokenType.OPEN_SQUARE_BRACKET, 3019 TokenType.OPEN_SQUARE_BRACKET,
3020 TokenType.INDEX]); 3020 TokenType.INDEX]);
3021 } 3021 }
3022 // We know that we have an identifier, and need to see whether it might be a type name. 3022 // We know that we have an identifier, and need to see whether it might be a type name.
3023 Token token = skipTypeName(_currentToken); 3023 Token token = skipTypeName(_currentToken);
3024 if (token == null) { 3024 if (token == null) {
3025 // There was no type name, so this can't be a declaration. 3025 // There was no type name, so this can't be a declaration.
3026 return false; 3026 return false;
3027 } 3027 }
3028 token = skipSimpleIdentifier(token); 3028 token = skipSimpleIdentifier(token);
3029 if (token == null) { 3029 if (token == null) {
3030 return false; 3030 return false;
3031 } 3031 }
3032 TokenType type = token.type; 3032 TokenType type = token.type;
3033 return identical(type, TokenType.EQ) || identical(type, TokenType.COMMA) || identical(type, TokenType.SEMICOLON) || matches3(token, Keyword.IN); 3033 return identical(type, TokenType.EQ) || identical(type, TokenType.COMMA) || identical(type, TokenType.SEMICOLON) || tokenMatchesKeyword(token, Keyword.IN);
3034 } 3034 }
3035 3035
3036 /** 3036 /**
3037 * Given that we have just found bracketed text within a comment, look to see whether that text is 3037 * Given that we have just found bracketed text within a comment, look to see whether that text is
3038 * (a) followed by a parenthesized link address, (b) followed by a colon, or ( c) followed by 3038 * (a) followed by a parenthesized link address, (b) followed by a colon, or ( c) followed by
3039 * optional whitespace and another square bracket. 3039 * optional whitespace and another square bracket.
3040 * 3040 *
3041 * This method uses the syntax described by the <a 3041 * This method uses the syntax described by the <a
3042 * href="http://daringfireball.net/projects/markdown/syntax">markdown</a> proj ect. 3042 * href="http://daringfireball.net/projects/markdown/syntax">markdown</a> proj ect.
3043 * 3043 *
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 // Token "=" means that it is actually field initializer. 3079 // Token "=" means that it is actually field initializer.
3080 if (identical(startToken.type, TokenType.EQ)) { 3080 if (identical(startToken.type, TokenType.EQ)) {
3081 return false; 3081 return false;
3082 } 3082 }
3083 // Consume all operator tokens. 3083 // Consume all operator tokens.
3084 Token token = startToken.next; 3084 Token token = startToken.next;
3085 while (token.isOperator) { 3085 while (token.isOperator) {
3086 token = token.next; 3086 token = token.next;
3087 } 3087 }
3088 // Formal parameter list is expect now. 3088 // Formal parameter list is expect now.
3089 return matches4(token, TokenType.OPEN_PAREN); 3089 return tokenMatches(token, TokenType.OPEN_PAREN);
3090 } 3090 }
3091 3091
3092 /** 3092 /**
3093 * Return `true` if the current token appears to be the beginning of a switch member. 3093 * Return `true` if the current token appears to be the beginning of a switch member.
3094 * 3094 *
3095 * @return `true` if the current token appears to be the beginning of a switch member 3095 * @return `true` if the current token appears to be the beginning of a switch member
3096 */ 3096 */
3097 bool isSwitchMember() { 3097 bool isSwitchMember() {
3098 Token token = _currentToken; 3098 Token token = _currentToken;
3099 while (matches4(token, TokenType.IDENTIFIER) && matches4(token.next, TokenTy pe.COLON)) { 3099 while (tokenMatches(token, TokenType.IDENTIFIER) && tokenMatches(token.next, TokenType.COLON)) {
3100 token = token.next.next; 3100 token = token.next.next;
3101 } 3101 }
3102 if (identical(token.type, TokenType.KEYWORD)) { 3102 if (identical(token.type, TokenType.KEYWORD)) {
3103 Keyword keyword = (token as KeywordToken).keyword; 3103 Keyword keyword = (token as KeywordToken).keyword;
3104 return identical(keyword, Keyword.CASE) || identical(keyword, Keyword.DEFA ULT); 3104 return identical(keyword, Keyword.CASE) || identical(keyword, Keyword.DEFA ULT);
3105 } 3105 }
3106 return false; 3106 return false;
3107 } 3107 }
3108 3108
3109 /** 3109 /**
3110 * Return `true` if the given token appears to be the first token of a type na me that is 3110 * Return `true` if the given token appears to be the first token of a type na me that is
3111 * followed by a variable or field formal parameter. 3111 * followed by a variable or field formal parameter.
3112 * 3112 *
3113 * @param startToken the first token of the sequence being checked 3113 * @param startToken the first token of the sequence being checked
3114 * @return `true` if there is a type name and variable starting at the given t oken 3114 * @return `true` if there is a type name and variable starting at the given t oken
3115 */ 3115 */
3116 bool isTypedIdentifier(Token startToken) { 3116 bool isTypedIdentifier(Token startToken) {
3117 Token token = skipReturnType(startToken); 3117 Token token = skipReturnType(startToken);
3118 if (token == null) { 3118 if (token == null) {
3119 return false; 3119 return false;
3120 } else if (matchesIdentifier2(token)) { 3120 } else if (tokenMatchesIdentifier(token)) {
3121 return true; 3121 return true;
3122 } else if (matches3(token, Keyword.THIS) && matches4(token.next, TokenType.P ERIOD) && matchesIdentifier2(token.next.next)) { 3122 } else if (tokenMatchesKeyword(token, Keyword.THIS) && tokenMatches(token.ne xt, TokenType.PERIOD) && tokenMatchesIdentifier(token.next.next)) {
3123 return true; 3123 return true;
3124 } 3124 }
3125 return false; 3125 return false;
3126 } 3126 }
3127 3127
3128 /** 3128 /**
3129 * Compare the given tokens to find the token that appears first in the source being parsed. That 3129 * Compare the given tokens to find the token that appears first in the source being parsed. That
3130 * is, return the left-most of all of the tokens. The arguments are allowed to be `null`. 3130 * is, return the left-most of all of the tokens. The arguments are allowed to be `null`.
3131 * Return the token with the smallest offset, or `null` if there are no argume nts or if all 3131 * Return the token with the smallest offset, or `null` if there are no argume nts or if all
3132 * of the arguments are `null`. 3132 * of the arguments are `null`.
(...skipping 18 matching lines...) Expand all
3151 3151
3152 /** 3152 /**
3153 * Increments the error reporting lock level. If level is more than `0`, then 3153 * Increments the error reporting lock level. If level is more than `0`, then
3154 * [reportError] wont report any error. 3154 * [reportError] wont report any error.
3155 */ 3155 */
3156 void lockErrorListener() { 3156 void lockErrorListener() {
3157 _errorListenerLock++; 3157 _errorListenerLock++;
3158 } 3158 }
3159 3159
3160 /** 3160 /**
3161 * Return `true` if the current token matches the given keyword.
3162 *
3163 * @param keyword the keyword that can optionally appear in the current locati on
3164 * @return `true` if the current token matches the given keyword
3165 */
3166 bool matches(Keyword keyword) => matches3(_currentToken, keyword);
3167
3168 /**
3169 * Return `true` if the current token matches the given identifier.
3170 *
3171 * @param identifier the identifier that can optionally appear in the current location
3172 * @return `true` if the current token matches the given identifier
3173 */
3174 bool matches2(String identifier) => identical(_currentToken.type, TokenType.ID ENTIFIER) && _currentToken.lexeme == identifier;
3175
3176 /**
3177 * Return `true` if the given token matches the given keyword.
3178 *
3179 * @param token the token being tested
3180 * @param keyword the keyword that is being tested for
3181 * @return `true` if the given token matches the given keyword
3182 */
3183 bool matches3(Token token, Keyword keyword) => identical(token.type, TokenType .KEYWORD) && identical((token as KeywordToken).keyword, keyword);
3184
3185 /**
3186 * Return `true` if the given token has the given type.
3187 *
3188 * @param token the token being tested
3189 * @param type the type of token that is being tested for
3190 * @return `true` if the given token has the given type
3191 */
3192 bool matches4(Token token, TokenType type) => identical(token.type, type);
3193
3194 /**
3195 * Return `true` if the current token has the given type. Note that this metho d, unlike 3161 * Return `true` if the current token has the given type. Note that this metho d, unlike
3196 * other variants, will modify the token stream if possible to match a wider r ange of tokens. In 3162 * other variants, will modify the token stream if possible to match a wider r ange of tokens. In
3197 * particular, if we are attempting to match a '>' and the next token is eithe r a '>>' or '>>>', 3163 * particular, if we are attempting to match a '>' and the next token is eithe r a '>>' or '>>>',
3198 * the token stream will be re-written and `true` will be returned. 3164 * the token stream will be re-written and `true` will be returned.
3199 * 3165 *
3200 * @param type the type of token that can optionally appear in the current loc ation 3166 * @param type the type of token that can optionally appear in the current loc ation
3201 * @return `true` if the current token has the given type 3167 * @return `true` if the current token has the given type
3202 */ 3168 */
3203 bool matches5(TokenType type) { 3169 bool matches(TokenType type) {
3204 TokenType currentType = _currentToken.type; 3170 TokenType currentType = _currentToken.type;
3205 if (currentType != type) { 3171 if (currentType != type) {
3206 if (identical(type, TokenType.GT)) { 3172 if (identical(type, TokenType.GT)) {
3207 if (identical(currentType, TokenType.GT_GT)) { 3173 if (identical(currentType, TokenType.GT_GT)) {
3208 int offset = _currentToken.offset; 3174 int offset = _currentToken.offset;
3209 Token first = new Token(TokenType.GT, offset); 3175 Token first = new Token(TokenType.GT, offset);
3210 Token second = new Token(TokenType.GT, offset + 1); 3176 Token second = new Token(TokenType.GT, offset + 1);
3211 second.setNext(_currentToken.next); 3177 second.setNext(_currentToken.next);
3212 first.setNext(second); 3178 first.setNext(second);
3213 _currentToken.previous.setNext(first); 3179 _currentToken.previous.setNext(first);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 } 3222 }
3257 return false; 3223 return false;
3258 } 3224 }
3259 3225
3260 /** 3226 /**
3261 * Return `true` if the current token is a valid identifier. Valid identifiers include 3227 * Return `true` if the current token is a valid identifier. Valid identifiers include
3262 * built-in identifiers (pseudo-keywords). 3228 * built-in identifiers (pseudo-keywords).
3263 * 3229 *
3264 * @return `true` if the current token is a valid identifier 3230 * @return `true` if the current token is a valid identifier
3265 */ 3231 */
3266 bool matchesIdentifier() => matchesIdentifier2(_currentToken); 3232 bool matchesIdentifier() => tokenMatchesIdentifier(_currentToken);
3267 3233
3268 /** 3234 /**
3269 * Return `true` if the given token is a valid identifier. Valid identifiers i nclude 3235 * Return `true` if the current token matches the given keyword.
3270 * built-in identifiers (pseudo-keywords).
3271 * 3236 *
3272 * @return `true` if the given token is a valid identifier 3237 * @param keyword the keyword that can optionally appear in the current locati on
3238 * @return `true` if the current token matches the given keyword
3273 */ 3239 */
3274 bool matchesIdentifier2(Token token) => matches4(token, TokenType.IDENTIFIER) || (matches4(token, TokenType.KEYWORD) && (token as KeywordToken).keyword.isPseu doKeyword); 3240 bool matchesKeyword(Keyword keyword) => tokenMatchesKeyword(_currentToken, key word);
3241
3242 /**
3243 * Return `true` if the current token matches the given identifier.
3244 *
3245 * @param identifier the identifier that can optionally appear in the current location
3246 * @return `true` if the current token matches the given identifier
3247 */
3248 bool matchesString(String identifier) => identical(_currentToken.type, TokenTy pe.IDENTIFIER) && _currentToken.lexeme == identifier;
3275 3249
3276 /** 3250 /**
3277 * If the current token has the given type, then advance to the next token and return `true` 3251 * If the current token has the given type, then advance to the next token and return `true`
3278 * . Otherwise, return `false` without advancing. 3252 * . Otherwise, return `false` without advancing.
3279 * 3253 *
3280 * @param type the type of token that can optionally appear in the current loc ation 3254 * @param type the type of token that can optionally appear in the current loc ation
3281 * @return `true` if the current token has the given type 3255 * @return `true` if the current token has the given type
3282 */ 3256 */
3283 bool optional(TokenType type) { 3257 bool optional(TokenType type) {
3284 if (matches5(type)) { 3258 if (matches(type)) {
3285 advance(); 3259 advance();
3286 return true; 3260 return true;
3287 } 3261 }
3288 return false; 3262 return false;
3289 } 3263 }
3290 3264
3291 /** 3265 /**
3292 * Parse an additive expression. 3266 * Parse an additive expression.
3293 * 3267 *
3294 * <pre> 3268 * <pre>
3295 * additiveExpression ::= 3269 * additiveExpression ::=
3296 * multiplicativeExpression (additiveOperator multiplicativeExpression)* 3270 * multiplicativeExpression (additiveOperator multiplicativeExpression)*
3297 * | 'super' (additiveOperator multiplicativeExpression)+ 3271 * | 'super' (additiveOperator multiplicativeExpression)+
3298 * </pre> 3272 * </pre>
3299 * 3273 *
3300 * @return the additive expression that was parsed 3274 * @return the additive expression that was parsed
3301 */ 3275 */
3302 Expression parseAdditiveExpression() { 3276 Expression parseAdditiveExpression() {
3303 Expression expression; 3277 Expression expression;
3304 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator) { 3278 if (matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isAdditiveOpera tor) {
3305 expression = new SuperExpression(andAdvance); 3279 expression = new SuperExpression(andAdvance);
3306 } else { 3280 } else {
3307 expression = parseMultiplicativeExpression(); 3281 expression = parseMultiplicativeExpression();
3308 } 3282 }
3309 while (_currentToken.type.isAdditiveOperator) { 3283 while (_currentToken.type.isAdditiveOperator) {
3310 Token operator = andAdvance; 3284 Token operator = andAdvance;
3311 expression = new BinaryExpression(expression, operator, parseMultiplicativ eExpression()); 3285 expression = new BinaryExpression(expression, operator, parseMultiplicativ eExpression());
3312 } 3286 }
3313 return expression; 3287 return expression;
3314 } 3288 }
3315 3289
3316 /** 3290 /**
3317 * Parse an argument definition test. 3291 * Parse an argument definition test.
3318 * 3292 *
3319 * <pre> 3293 * <pre>
3320 * argumentDefinitionTest ::= 3294 * argumentDefinitionTest ::=
3321 * '?' identifier 3295 * '?' identifier
3322 * </pre> 3296 * </pre>
3323 * 3297 *
3324 * @return the argument definition test that was parsed 3298 * @return the argument definition test that was parsed
3325 */ 3299 */
3326 ArgumentDefinitionTest parseArgumentDefinitionTest() { 3300 ArgumentDefinitionTest parseArgumentDefinitionTest() {
3327 Token question = expect2(TokenType.QUESTION); 3301 Token question = expect(TokenType.QUESTION);
3328 SimpleIdentifier identifier = parseSimpleIdentifier(); 3302 SimpleIdentifier identifier = parseSimpleIdentifier();
3329 reportError14(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []); 3303 reportErrorForToken(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, que stion, []);
3330 return new ArgumentDefinitionTest(question, identifier); 3304 return new ArgumentDefinitionTest(question, identifier);
3331 } 3305 }
3332 3306
3333 /** 3307 /**
3334 * Parse an assert statement. 3308 * Parse an assert statement.
3335 * 3309 *
3336 * <pre> 3310 * <pre>
3337 * assertStatement ::= 3311 * assertStatement ::=
3338 * 'assert' '(' conditionalExpression ')' ';' 3312 * 'assert' '(' conditionalExpression ')' ';'
3339 * </pre> 3313 * </pre>
3340 * 3314 *
3341 * @return the assert statement 3315 * @return the assert statement
3342 */ 3316 */
3343 AssertStatement parseAssertStatement() { 3317 AssertStatement parseAssertStatement() {
3344 Token keyword = expect(Keyword.ASSERT); 3318 Token keyword = expectKeyword(Keyword.ASSERT);
3345 Token leftParen = expect2(TokenType.OPEN_PAREN); 3319 Token leftParen = expect(TokenType.OPEN_PAREN);
3346 Expression expression = parseExpression2(); 3320 Expression expression = parseExpression2();
3347 if (expression is AssignmentExpression) { 3321 if (expression is AssignmentExpression) {
3348 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []); 3322 reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expres sion, []);
3349 } else if (expression is CascadeExpression) { 3323 } else if (expression is CascadeExpression) {
3350 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, [] ); 3324 reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expressio n, []);
3351 } else if (expression is ThrowExpression) { 3325 } else if (expression is ThrowExpression) {
3352 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []); 3326 reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []);
3353 } else if (expression is RethrowExpression) { 3327 } else if (expression is RethrowExpression) {
3354 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, [] ); 3328 reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expressio n, []);
3355 } 3329 }
3356 Token rightParen = expect2(TokenType.CLOSE_PAREN); 3330 Token rightParen = expect(TokenType.CLOSE_PAREN);
3357 Token semicolon = expect2(TokenType.SEMICOLON); 3331 Token semicolon = expect(TokenType.SEMICOLON);
3358 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon); 3332 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon);
3359 } 3333 }
3360 3334
3361 /** 3335 /**
3362 * Parse an assignable expression. 3336 * Parse an assignable expression.
3363 * 3337 *
3364 * <pre> 3338 * <pre>
3365 * assignableExpression ::= 3339 * assignableExpression ::=
3366 * primary (arguments* assignableSelector)+ 3340 * primary (arguments* assignableSelector)+
3367 * | 'super' assignableSelector 3341 * | 'super' assignableSelector
3368 * | identifier 3342 * | identifier
3369 * </pre> 3343 * </pre>
3370 * 3344 *
3371 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any 3345 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any
3372 * assignable selector 3346 * assignable selector
3373 * @return the assignable expression that was parsed 3347 * @return the assignable expression that was parsed
3374 */ 3348 */
3375 Expression parseAssignableExpression(bool primaryAllowed) { 3349 Expression parseAssignableExpression(bool primaryAllowed) {
3376 if (matches(Keyword.SUPER)) { 3350 if (matchesKeyword(Keyword.SUPER)) {
3377 return parseAssignableSelector(new SuperExpression(andAdvance), false); 3351 return parseAssignableSelector(new SuperExpression(andAdvance), false);
3378 } 3352 }
3379 // 3353 //
3380 // A primary expression can start with an identifier. We resolve the ambigui ty by determining 3354 // A primary expression can start with an identifier. We resolve the ambigui ty by determining
3381 // whether the primary consists of anything other than an identifier and/or is followed by an 3355 // whether the primary consists of anything other than an identifier and/or is followed by an
3382 // assignableSelector. 3356 // assignableSelector.
3383 // 3357 //
3384 Expression expression = parsePrimaryExpression(); 3358 Expression expression = parsePrimaryExpression();
3385 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 3359 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
3386 while (true) { 3360 while (true) {
3387 while (matches5(TokenType.OPEN_PAREN)) { 3361 while (matches(TokenType.OPEN_PAREN)) {
3388 ArgumentList argumentList = parseArgumentList(); 3362 ArgumentList argumentList = parseArgumentList();
3389 if (expression is SimpleIdentifier) { 3363 if (expression is SimpleIdentifier) {
3390 expression = new MethodInvocation(null, null, expression as SimpleIden tifier, argumentList); 3364 expression = new MethodInvocation(null, null, expression as SimpleIden tifier, argumentList);
3391 } else if (expression is PrefixedIdentifier) { 3365 } else if (expression is PrefixedIdentifier) {
3392 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 3366 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
3393 expression = new MethodInvocation(identifier.prefix, identifier.period , identifier.identifier, argumentList); 3367 expression = new MethodInvocation(identifier.prefix, identifier.period , identifier.identifier, argumentList);
3394 } else if (expression is PropertyAccess) { 3368 } else if (expression is PropertyAccess) {
3395 PropertyAccess access = expression as PropertyAccess; 3369 PropertyAccess access = expression as PropertyAccess;
3396 expression = new MethodInvocation(access.target, access.operator, acce ss.propertyName, argumentList); 3370 expression = new MethodInvocation(access.target, access.operator, acce ss.propertyName, argumentList);
3397 } else { 3371 } else {
(...skipping 23 matching lines...) Expand all
3421 * assignableSelector ::= 3395 * assignableSelector ::=
3422 * '[' expression ']' 3396 * '[' expression ']'
3423 * | '.' identifier 3397 * | '.' identifier
3424 * </pre> 3398 * </pre>
3425 * 3399 *
3426 * @param prefix the expression preceding the selector 3400 * @param prefix the expression preceding the selector
3427 * @param optional `true` if the selector is optional 3401 * @param optional `true` if the selector is optional
3428 * @return the assignable selector that was parsed 3402 * @return the assignable selector that was parsed
3429 */ 3403 */
3430 Expression parseAssignableSelector(Expression prefix, bool optional) { 3404 Expression parseAssignableSelector(Expression prefix, bool optional) {
3431 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 3405 if (matches(TokenType.OPEN_SQUARE_BRACKET)) {
3432 Token leftBracket = andAdvance; 3406 Token leftBracket = andAdvance;
3433 Expression index = parseExpression2(); 3407 Expression index = parseExpression2();
3434 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3408 Token rightBracket = expect(TokenType.CLOSE_SQUARE_BRACKET);
3435 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket); 3409 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket);
3436 } else if (matches5(TokenType.PERIOD)) { 3410 } else if (matches(TokenType.PERIOD)) {
3437 Token period = andAdvance; 3411 Token period = andAdvance;
3438 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 3412 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
3439 } else { 3413 } else {
3440 if (!optional) { 3414 if (!optional) {
3441 // Report the missing selector. 3415 // Report the missing selector.
3442 reportError13(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3416 reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
3443 } 3417 }
3444 return prefix; 3418 return prefix;
3445 } 3419 }
3446 } 3420 }
3447 3421
3448 /** 3422 /**
3449 * Parse a bitwise and expression. 3423 * Parse a bitwise and expression.
3450 * 3424 *
3451 * <pre> 3425 * <pre>
3452 * bitwiseAndExpression ::= 3426 * bitwiseAndExpression ::=
3453 * shiftExpression ('&' shiftExpression)* 3427 * shiftExpression ('&' shiftExpression)*
3454 * | 'super' ('&' shiftExpression)+ 3428 * | 'super' ('&' shiftExpression)+
3455 * </pre> 3429 * </pre>
3456 * 3430 *
3457 * @return the bitwise and expression that was parsed 3431 * @return the bitwise and expression that was parsed
3458 */ 3432 */
3459 Expression parseBitwiseAndExpression() { 3433 Expression parseBitwiseAndExpression() {
3460 Expression expression; 3434 Expression expression;
3461 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) { 3435 if (matchesKeyword(Keyword.SUPER) && tokenMatches(peek(), TokenType.AMPERSAN D)) {
3462 expression = new SuperExpression(andAdvance); 3436 expression = new SuperExpression(andAdvance);
3463 } else { 3437 } else {
3464 expression = parseShiftExpression(); 3438 expression = parseShiftExpression();
3465 } 3439 }
3466 while (matches5(TokenType.AMPERSAND)) { 3440 while (matches(TokenType.AMPERSAND)) {
3467 Token operator = andAdvance; 3441 Token operator = andAdvance;
3468 expression = new BinaryExpression(expression, operator, parseShiftExpressi on()); 3442 expression = new BinaryExpression(expression, operator, parseShiftExpressi on());
3469 } 3443 }
3470 return expression; 3444 return expression;
3471 } 3445 }
3472 3446
3473 /** 3447 /**
3474 * Parse a bitwise exclusive-or expression. 3448 * Parse a bitwise exclusive-or expression.
3475 * 3449 *
3476 * <pre> 3450 * <pre>
3477 * bitwiseXorExpression ::= 3451 * bitwiseXorExpression ::=
3478 * bitwiseAndExpression ('^' bitwiseAndExpression)* 3452 * bitwiseAndExpression ('^' bitwiseAndExpression)*
3479 * | 'super' ('^' bitwiseAndExpression)+ 3453 * | 'super' ('^' bitwiseAndExpression)+
3480 * </pre> 3454 * </pre>
3481 * 3455 *
3482 * @return the bitwise exclusive-or expression that was parsed 3456 * @return the bitwise exclusive-or expression that was parsed
3483 */ 3457 */
3484 Expression parseBitwiseXorExpression() { 3458 Expression parseBitwiseXorExpression() {
3485 Expression expression; 3459 Expression expression;
3486 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) { 3460 if (matchesKeyword(Keyword.SUPER) && tokenMatches(peek(), TokenType.CARET)) {
3487 expression = new SuperExpression(andAdvance); 3461 expression = new SuperExpression(andAdvance);
3488 } else { 3462 } else {
3489 expression = parseBitwiseAndExpression(); 3463 expression = parseBitwiseAndExpression();
3490 } 3464 }
3491 while (matches5(TokenType.CARET)) { 3465 while (matches(TokenType.CARET)) {
3492 Token operator = andAdvance; 3466 Token operator = andAdvance;
3493 expression = new BinaryExpression(expression, operator, parseBitwiseAndExp ression()); 3467 expression = new BinaryExpression(expression, operator, parseBitwiseAndExp ression());
3494 } 3468 }
3495 return expression; 3469 return expression;
3496 } 3470 }
3497 3471
3498 /** 3472 /**
3499 * Parse a break statement. 3473 * Parse a break statement.
3500 * 3474 *
3501 * <pre> 3475 * <pre>
3502 * breakStatement ::= 3476 * breakStatement ::=
3503 * 'break' identifier? ';' 3477 * 'break' identifier? ';'
3504 * </pre> 3478 * </pre>
3505 * 3479 *
3506 * @return the break statement that was parsed 3480 * @return the break statement that was parsed
3507 */ 3481 */
3508 Statement parseBreakStatement() { 3482 Statement parseBreakStatement() {
3509 Token breakKeyword = expect(Keyword.BREAK); 3483 Token breakKeyword = expectKeyword(Keyword.BREAK);
3510 SimpleIdentifier label = null; 3484 SimpleIdentifier label = null;
3511 if (matchesIdentifier()) { 3485 if (matchesIdentifier()) {
3512 label = parseSimpleIdentifier(); 3486 label = parseSimpleIdentifier();
3513 } 3487 }
3514 if (!_inLoop && !_inSwitch && label == null) { 3488 if (!_inLoop && !_inSwitch && label == null) {
3515 reportError14(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 3489 reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, [ ]);
3516 } 3490 }
3517 Token semicolon = expect2(TokenType.SEMICOLON); 3491 Token semicolon = expect(TokenType.SEMICOLON);
3518 return new BreakStatement(breakKeyword, label, semicolon); 3492 return new BreakStatement(breakKeyword, label, semicolon);
3519 } 3493 }
3520 3494
3521 /** 3495 /**
3522 * Parse a cascade section. 3496 * Parse a cascade section.
3523 * 3497 *
3524 * <pre> 3498 * <pre>
3525 * cascadeSection ::= 3499 * cascadeSection ::=
3526 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* casc adeAssignment? 3500 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* casc adeAssignment?
3527 * 3501 *
3528 * cascadeSelector ::= 3502 * cascadeSelector ::=
3529 * '[' expression ']' 3503 * '[' expression ']'
3530 * | identifier 3504 * | identifier
3531 * 3505 *
3532 * cascadeAssignment ::= 3506 * cascadeAssignment ::=
3533 * assignmentOperator expressionWithoutCascade 3507 * assignmentOperator expressionWithoutCascade
3534 * </pre> 3508 * </pre>
3535 * 3509 *
3536 * @return the expression representing the cascaded method invocation 3510 * @return the expression representing the cascaded method invocation
3537 */ 3511 */
3538 Expression parseCascadeSection() { 3512 Expression parseCascadeSection() {
3539 Token period = expect2(TokenType.PERIOD_PERIOD); 3513 Token period = expect(TokenType.PERIOD_PERIOD);
3540 Expression expression = null; 3514 Expression expression = null;
3541 SimpleIdentifier functionName = null; 3515 SimpleIdentifier functionName = null;
3542 if (matchesIdentifier()) { 3516 if (matchesIdentifier()) {
3543 functionName = parseSimpleIdentifier(); 3517 functionName = parseSimpleIdentifier();
3544 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { 3518 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) {
3545 Token leftBracket = andAdvance; 3519 Token leftBracket = andAdvance;
3546 Expression index = parseExpression2(); 3520 Expression index = parseExpression2();
3547 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3521 Token rightBracket = expect(TokenType.CLOSE_SQUARE_BRACKET);
3548 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket); 3522 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket);
3549 period = null; 3523 period = null;
3550 } else { 3524 } else {
3551 reportError14(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]); 3525 reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_c urrentToken.lexeme]);
3552 functionName = createSyntheticIdentifier(); 3526 functionName = createSyntheticIdentifier();
3553 } 3527 }
3554 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3528 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3555 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3529 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3556 if (functionName != null) { 3530 if (functionName != null) {
3557 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList()); 3531 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList());
3558 period = null; 3532 period = null;
3559 functionName = null; 3533 functionName = null;
3560 } else if (expression == null) { 3534 } else if (expression == null) {
3561 // It should not be possible to get here. 3535 // It should not be possible to get here.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3601 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause wit hClause?)? implementsClause? '{' classMembers '}' | 3575 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause wit hClause?)? implementsClause? '{' classMembers '}' |
3602 * metadata 'abstract'? 'class' mixinApplicationClass 3576 * metadata 'abstract'? 'class' mixinApplicationClass
3603 * </pre> 3577 * </pre>
3604 * 3578 *
3605 * @param commentAndMetadata the metadata to be associated with the member 3579 * @param commentAndMetadata the metadata to be associated with the member
3606 * @param abstractKeyword the token for the keyword 'abstract', or `null` if t he keyword was 3580 * @param abstractKeyword the token for the keyword 'abstract', or `null` if t he keyword was
3607 * not given 3581 * not given
3608 * @return the class declaration that was parsed 3582 * @return the class declaration that was parsed
3609 */ 3583 */
3610 CompilationUnitMember parseClassDeclaration(CommentAndMetadata commentAndMetad ata, Token abstractKeyword) { 3584 CompilationUnitMember parseClassDeclaration(CommentAndMetadata commentAndMetad ata, Token abstractKeyword) {
3611 Token keyword = expect(Keyword.CLASS); 3585 Token keyword = expectKeyword(Keyword.CLASS);
3612 if (matchesIdentifier()) { 3586 if (matchesIdentifier()) {
3613 Token next = peek(); 3587 Token next = peek();
3614 if (matches4(next, TokenType.LT)) { 3588 if (tokenMatches(next, TokenType.LT)) {
3615 next = skipTypeParameterList(next); 3589 next = skipTypeParameterList(next);
3616 if (next != null && matches4(next, TokenType.EQ)) { 3590 if (next != null && tokenMatches(next, TokenType.EQ)) {
3617 return parseClassTypeAlias(commentAndMetadata, abstractKeyword, keywor d); 3591 return parseClassTypeAlias(commentAndMetadata, abstractKeyword, keywor d);
3618 } 3592 }
3619 } else if (matches4(next, TokenType.EQ)) { 3593 } else if (tokenMatches(next, TokenType.EQ)) {
3620 return parseClassTypeAlias(commentAndMetadata, abstractKeyword, keyword) ; 3594 return parseClassTypeAlias(commentAndMetadata, abstractKeyword, keyword) ;
3621 } 3595 }
3622 } 3596 }
3623 SimpleIdentifier name = parseSimpleIdentifier(); 3597 SimpleIdentifier name = parseSimpleIdentifier();
3624 String className = name.name; 3598 String className = name.name;
3625 TypeParameterList typeParameters = null; 3599 TypeParameterList typeParameters = null;
3626 if (matches5(TokenType.LT)) { 3600 if (matches(TokenType.LT)) {
3627 typeParameters = parseTypeParameterList(); 3601 typeParameters = parseTypeParameterList();
3628 } 3602 }
3629 // 3603 //
3630 // Parse the clauses. The parser accepts clauses in any order, but will gene rate errors if they 3604 // Parse the clauses. The parser accepts clauses in any order, but will gene rate errors if they
3631 // are not in the order required by the specification. 3605 // are not in the order required by the specification.
3632 // 3606 //
3633 ExtendsClause extendsClause = null; 3607 ExtendsClause extendsClause = null;
3634 WithClause withClause = null; 3608 WithClause withClause = null;
3635 ImplementsClause implementsClause = null; 3609 ImplementsClause implementsClause = null;
3636 bool foundClause = true; 3610 bool foundClause = true;
3637 while (foundClause) { 3611 while (foundClause) {
3638 if (matches(Keyword.EXTENDS)) { 3612 if (matchesKeyword(Keyword.EXTENDS)) {
3639 if (extendsClause == null) { 3613 if (extendsClause == null) {
3640 extendsClause = parseExtendsClause(); 3614 extendsClause = parseExtendsClause();
3641 if (withClause != null) { 3615 if (withClause != null) {
3642 reportError14(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKe yword, []); 3616 reportErrorForToken(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause. withKeyword, []);
3643 } else if (implementsClause != null) { 3617 } else if (implementsClause != null) {
3644 reportError14(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsC lause.keyword, []); 3618 reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, imple mentsClause.keyword, []);
3645 } 3619 }
3646 } else { 3620 } else {
3647 reportError14(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause. keyword, []); 3621 reportErrorForToken(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsC lause.keyword, []);
3648 parseExtendsClause(); 3622 parseExtendsClause();
3649 } 3623 }
3650 } else if (matches(Keyword.WITH)) { 3624 } else if (matchesKeyword(Keyword.WITH)) {
3651 if (withClause == null) { 3625 if (withClause == null) {
3652 withClause = parseWithClause(); 3626 withClause = parseWithClause();
3653 if (implementsClause != null) { 3627 if (implementsClause != null) {
3654 reportError14(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClau se.keyword, []); 3628 reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implemen tsClause.keyword, []);
3655 } 3629 }
3656 } else { 3630 } else {
3657 reportError14(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKe yword, []); 3631 reportErrorForToken(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause. withKeyword, []);
3658 parseWithClause(); 3632 parseWithClause();
3659 } 3633 }
3660 } else if (matches(Keyword.IMPLEMENTS)) { 3634 } else if (matchesKeyword(Keyword.IMPLEMENTS)) {
3661 if (implementsClause == null) { 3635 if (implementsClause == null) {
3662 implementsClause = parseImplementsClause(); 3636 implementsClause = parseImplementsClause();
3663 } else { 3637 } else {
3664 reportError14(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsC lause.keyword, []); 3638 reportErrorForToken(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, imple mentsClause.keyword, []);
3665 parseImplementsClause(); 3639 parseImplementsClause();
3666 } 3640 }
3667 } else { 3641 } else {
3668 foundClause = false; 3642 foundClause = false;
3669 } 3643 }
3670 } 3644 }
3671 if (withClause != null && extendsClause == null) { 3645 if (withClause != null && extendsClause == null) {
3672 reportError14(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword , []); 3646 reportErrorForToken(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withK eyword, []);
3673 } 3647 }
3674 // 3648 //
3675 // Look for and skip over the extra-lingual 'native' specification. 3649 // Look for and skip over the extra-lingual 'native' specification.
3676 // 3650 //
3677 NativeClause nativeClause = null; 3651 NativeClause nativeClause = null;
3678 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { 3652 if (matchesString(_NATIVE) && tokenMatches(peek(), TokenType.STRING)) {
3679 nativeClause = parseNativeClause(); 3653 nativeClause = parseNativeClause();
3680 } 3654 }
3681 // 3655 //
3682 // Parse the body of the class. 3656 // Parse the body of the class.
3683 // 3657 //
3684 Token leftBracket = null; 3658 Token leftBracket = null;
3685 List<ClassMember> members = null; 3659 List<ClassMember> members = null;
3686 Token rightBracket = null; 3660 Token rightBracket = null;
3687 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3661 if (matches(TokenType.OPEN_CURLY_BRACKET)) {
3688 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 3662 leftBracket = expect(TokenType.OPEN_CURLY_BRACKET);
3689 members = parseClassMembers(className, getEndToken(leftBracket)); 3663 members = parseClassMembers(className, getEndToken(leftBracket));
3690 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3664 rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
3691 } else { 3665 } else {
3692 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); 3666 leftBracket = createSyntheticToken(TokenType.OPEN_CURLY_BRACKET);
3693 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); 3667 rightBracket = createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
3694 reportError13(ParserErrorCode.MISSING_CLASS_BODY, []); 3668 reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY, []);
3695 } 3669 }
3696 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket); 3670 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket);
3697 classDeclaration.nativeClause = nativeClause; 3671 classDeclaration.nativeClause = nativeClause;
3698 return classDeclaration; 3672 return classDeclaration;
3699 } 3673 }
3700 3674
3701 /** 3675 /**
3702 * Parse a list of class members. 3676 * Parse a list of class members.
3703 * 3677 *
3704 * <pre> 3678 * <pre>
3705 * classMembers ::= 3679 * classMembers ::=
3706 * (metadata memberDefinition)* 3680 * (metadata memberDefinition)*
3707 * </pre> 3681 * </pre>
3708 * 3682 *
3709 * @param className the name of the class whose members are being parsed 3683 * @param className the name of the class whose members are being parsed
3710 * @param closingBracket the closing bracket for the class, or `null` if the c losing bracket 3684 * @param closingBracket the closing bracket for the class, or `null` if the c losing bracket
3711 * is missing 3685 * is missing
3712 * @return the list of class members that were parsed 3686 * @return the list of class members that were parsed
3713 */ 3687 */
3714 List<ClassMember> parseClassMembers(String className, Token closingBracket) { 3688 List<ClassMember> parseClassMembers(String className, Token closingBracket) {
3715 List<ClassMember> members = new List<ClassMember>(); 3689 List<ClassMember> members = new List<ClassMember>();
3716 Token memberStart = _currentToken; 3690 Token memberStart = _currentToken;
3717 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && (closingBracket != null || (!matches(Keyword.CLASS) && !matches(Keyword.TYPED EF)))) { 3691 while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACKET) && (closingBracket != null || (!matchesKeyword(Keyword.CLASS) && !matchesKeyword(K eyword.TYPEDEF)))) {
3718 if (matches5(TokenType.SEMICOLON)) { 3692 if (matches(TokenType.SEMICOLON)) {
3719 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3693 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
3720 advance(); 3694 advance();
3721 } else { 3695 } else {
3722 ClassMember member = parseClassMember(className); 3696 ClassMember member = parseClassMember(className);
3723 if (member != null) { 3697 if (member != null) {
3724 members.add(member); 3698 members.add(member);
3725 } 3699 }
3726 } 3700 }
3727 if (identical(_currentToken, memberStart)) { 3701 if (identical(_currentToken, memberStart)) {
3728 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3702 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
3729 advance(); 3703 advance();
3730 } 3704 }
3731 memberStart = _currentToken; 3705 memberStart = _currentToken;
3732 } 3706 }
3733 return members; 3707 return members;
3734 } 3708 }
3735 3709
3736 /** 3710 /**
3737 * Parse a class type alias. 3711 * Parse a class type alias.
3738 * 3712 *
3739 * <pre> 3713 * <pre>
3740 * classTypeAlias ::= 3714 * classTypeAlias ::=
3741 * identifier typeParameters? '=' 'abstract'? mixinApplication 3715 * identifier typeParameters? '=' 'abstract'? mixinApplication
3742 * 3716 *
3743 * mixinApplication ::= 3717 * mixinApplication ::=
3744 * type withClause implementsClause? ';' 3718 * type withClause implementsClause? ';'
3745 * </pre> 3719 * </pre>
3746 * 3720 *
3747 * @param commentAndMetadata the metadata to be associated with the member 3721 * @param commentAndMetadata the metadata to be associated with the member
3748 * @param abstractKeyword the token representing the 'abstract' keyword 3722 * @param abstractKeyword the token representing the 'abstract' keyword
3749 * @param classKeyword the token representing the 'class' keyword 3723 * @param classKeyword the token representing the 'class' keyword
3750 * @return the class type alias that was parsed 3724 * @return the class type alias that was parsed
3751 */ 3725 */
3752 ClassTypeAlias parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Toke n abstractKeyword, Token classKeyword) { 3726 ClassTypeAlias parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Toke n abstractKeyword, Token classKeyword) {
3753 SimpleIdentifier className = parseSimpleIdentifier(); 3727 SimpleIdentifier className = parseSimpleIdentifier();
3754 TypeParameterList typeParameters = null; 3728 TypeParameterList typeParameters = null;
3755 if (matches5(TokenType.LT)) { 3729 if (matches(TokenType.LT)) {
3756 typeParameters = parseTypeParameterList(); 3730 typeParameters = parseTypeParameterList();
3757 } 3731 }
3758 Token equals = expect2(TokenType.EQ); 3732 Token equals = expect(TokenType.EQ);
3759 if (matches(Keyword.ABSTRACT)) { 3733 if (matchesKeyword(Keyword.ABSTRACT)) {
3760 abstractKeyword = andAdvance; 3734 abstractKeyword = andAdvance;
3761 } 3735 }
3762 TypeName superclass = parseTypeName(); 3736 TypeName superclass = parseTypeName();
3763 WithClause withClause = null; 3737 WithClause withClause = null;
3764 if (matches(Keyword.WITH)) { 3738 if (matchesKeyword(Keyword.WITH)) {
3765 withClause = parseWithClause(); 3739 withClause = parseWithClause();
3766 } 3740 }
3767 ImplementsClause implementsClause = null; 3741 ImplementsClause implementsClause = null;
3768 if (matches(Keyword.IMPLEMENTS)) { 3742 if (matchesKeyword(Keyword.IMPLEMENTS)) {
3769 implementsClause = parseImplementsClause(); 3743 implementsClause = parseImplementsClause();
3770 } 3744 }
3771 Token semicolon; 3745 Token semicolon;
3772 if (matches5(TokenType.SEMICOLON)) { 3746 if (matches(TokenType.SEMICOLON)) {
3773 semicolon = andAdvance; 3747 semicolon = andAdvance;
3774 } else { 3748 } else {
3775 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3749 if (matches(TokenType.OPEN_CURLY_BRACKET)) {
3776 reportError13(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]); 3750 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SE MICOLON.lexeme]);
3777 Token leftBracket = andAdvance; 3751 Token leftBracket = andAdvance;
3778 parseClassMembers(className.name, getEndToken(leftBracket)); 3752 parseClassMembers(className.name, getEndToken(leftBracket));
3779 expect2(TokenType.CLOSE_CURLY_BRACKET); 3753 expect(TokenType.CLOSE_CURLY_BRACKET);
3780 } else { 3754 } else {
3781 reportError14(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]); 3755 reportErrorForToken(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previo us, [TokenType.SEMICOLON.lexeme]);
3782 } 3756 }
3783 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 3757 semicolon = createSyntheticToken(TokenType.SEMICOLON);
3784 } 3758 }
3785 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, classKeyword, className, typeParameters, equals, abstractKeyword, supercl ass, withClause, implementsClause, semicolon); 3759 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, classKeyword, className, typeParameters, equals, abstractKeyword, supercl ass, withClause, implementsClause, semicolon);
3786 } 3760 }
3787 3761
3788 /** 3762 /**
3789 * Parse a list of combinators in a directive. 3763 * Parse a list of combinators in a directive.
3790 * 3764 *
3791 * <pre> 3765 * <pre>
3792 * combinator ::= 3766 * combinator ::=
3793 * 'show' identifier (',' identifier)* 3767 * 'show' identifier (',' identifier)*
3794 * | 'hide' identifier (',' identifier)* 3768 * | 'hide' identifier (',' identifier)*
3795 * </pre> 3769 * </pre>
3796 * 3770 *
3797 * @return the combinators that were parsed 3771 * @return the combinators that were parsed
3798 */ 3772 */
3799 List<Combinator> parseCombinators() { 3773 List<Combinator> parseCombinators() {
3800 List<Combinator> combinators = new List<Combinator>(); 3774 List<Combinator> combinators = new List<Combinator>();
3801 while (matches2(_SHOW) || matches2(_HIDE)) { 3775 while (matchesString(_SHOW) || matchesString(_HIDE)) {
3802 Token keyword = expect2(TokenType.IDENTIFIER); 3776 Token keyword = expect(TokenType.IDENTIFIER);
3803 if (keyword.lexeme == _SHOW) { 3777 if (keyword.lexeme == _SHOW) {
3804 List<SimpleIdentifier> shownNames = parseIdentifierList(); 3778 List<SimpleIdentifier> shownNames = parseIdentifierList();
3805 combinators.add(new ShowCombinator(keyword, shownNames)); 3779 combinators.add(new ShowCombinator(keyword, shownNames));
3806 } else { 3780 } else {
3807 List<SimpleIdentifier> hiddenNames = parseIdentifierList(); 3781 List<SimpleIdentifier> hiddenNames = parseIdentifierList();
3808 combinators.add(new HideCombinator(keyword, hiddenNames)); 3782 combinators.add(new HideCombinator(keyword, hiddenNames));
3809 } 3783 }
3810 } 3784 }
3811 return combinators; 3785 return combinators;
3812 } 3786 }
3813 3787
3814 /** 3788 /**
3815 * Parse the documentation comment and metadata preceding a declaration. This method allows any 3789 * Parse the documentation comment and metadata preceding a declaration. This method allows any
3816 * number of documentation comments to occur before, after or between the meta data, but only 3790 * number of documentation comments to occur before, after or between the meta data, but only
3817 * returns the last (right-most) documentation comment that is found. 3791 * returns the last (right-most) documentation comment that is found.
3818 * 3792 *
3819 * <pre> 3793 * <pre>
3820 * metadata ::= 3794 * metadata ::=
3821 * annotation* 3795 * annotation*
3822 * </pre> 3796 * </pre>
3823 * 3797 *
3824 * @return the documentation comment and metadata that were parsed 3798 * @return the documentation comment and metadata that were parsed
3825 */ 3799 */
3826 CommentAndMetadata parseCommentAndMetadata() { 3800 CommentAndMetadata parseCommentAndMetadata() {
3827 Comment comment = parseDocumentationComment(); 3801 Comment comment = parseDocumentationComment();
3828 List<Annotation> metadata = new List<Annotation>(); 3802 List<Annotation> metadata = new List<Annotation>();
3829 while (matches5(TokenType.AT)) { 3803 while (matches(TokenType.AT)) {
3830 metadata.add(parseAnnotation()); 3804 metadata.add(parseAnnotation());
3831 Comment optionalComment = parseDocumentationComment(); 3805 Comment optionalComment = parseDocumentationComment();
3832 if (optionalComment != null) { 3806 if (optionalComment != null) {
3833 comment = optionalComment; 3807 comment = optionalComment;
3834 } 3808 }
3835 } 3809 }
3836 return new CommentAndMetadata(comment, metadata); 3810 return new CommentAndMetadata(comment, metadata);
3837 } 3811 }
3838 3812
3839 /** 3813 /**
(...skipping 17 matching lines...) Expand all
3857 } 3831 }
3858 try { 3832 try {
3859 BooleanErrorListener listener = new BooleanErrorListener(); 3833 BooleanErrorListener listener = new BooleanErrorListener();
3860 Scanner scanner = new Scanner(null, new SubSequenceReader(referenceSource, sourceOffset), listener); 3834 Scanner scanner = new Scanner(null, new SubSequenceReader(referenceSource, sourceOffset), listener);
3861 scanner.setSourceStart(1, 1); 3835 scanner.setSourceStart(1, 1);
3862 Token firstToken = scanner.tokenize(); 3836 Token firstToken = scanner.tokenize();
3863 if (listener.errorReported) { 3837 if (listener.errorReported) {
3864 return null; 3838 return null;
3865 } 3839 }
3866 Token newKeyword = null; 3840 Token newKeyword = null;
3867 if (matches3(firstToken, Keyword.NEW)) { 3841 if (tokenMatchesKeyword(firstToken, Keyword.NEW)) {
3868 newKeyword = firstToken; 3842 newKeyword = firstToken;
3869 firstToken = firstToken.next; 3843 firstToken = firstToken.next;
3870 } 3844 }
3871 if (matchesIdentifier2(firstToken)) { 3845 if (tokenMatchesIdentifier(firstToken)) {
3872 Token secondToken = firstToken.next; 3846 Token secondToken = firstToken.next;
3873 Token thirdToken = secondToken.next; 3847 Token thirdToken = secondToken.next;
3874 Token nextToken; 3848 Token nextToken;
3875 Identifier identifier; 3849 Identifier identifier;
3876 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thirdT oken)) { 3850 if (tokenMatches(secondToken, TokenType.PERIOD) && tokenMatchesIdentifie r(thirdToken)) {
3877 identifier = new PrefixedIdentifier(new SimpleIdentifier(firstToken), secondToken, new SimpleIdentifier(thirdToken)); 3851 identifier = new PrefixedIdentifier(new SimpleIdentifier(firstToken), secondToken, new SimpleIdentifier(thirdToken));
3878 nextToken = thirdToken.next; 3852 nextToken = thirdToken.next;
3879 } else { 3853 } else {
3880 identifier = new SimpleIdentifier(firstToken); 3854 identifier = new SimpleIdentifier(firstToken);
3881 nextToken = firstToken.next; 3855 nextToken = firstToken.next;
3882 } 3856 }
3883 if (nextToken.type != TokenType.EOF) { 3857 if (nextToken.type != TokenType.EOF) {
3884 return null; 3858 return null;
3885 } 3859 }
3886 return new CommentReference(newKeyword, identifier); 3860 return new CommentReference(newKeyword, identifier);
3887 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword. FALSE)) { 3861 } else if (tokenMatchesKeyword(firstToken, Keyword.THIS) || tokenMatchesKe yword(firstToken, Keyword.NULL) || tokenMatchesKeyword(firstToken, Keyword.TRUE) || tokenMatchesKeyword(firstToken, Keyword.FALSE)) {
3888 // TODO(brianwilkerson) If we want to support this we will need to exten d the definition 3862 // TODO(brianwilkerson) If we want to support this we will need to exten d the definition
3889 // of CommentReference to take an expression rather than an identifier. For now we just 3863 // of CommentReference to take an expression rather than an identifier. For now we just
3890 // ignore it to reduce the number of errors produced, but that's probabl y not a valid 3864 // ignore it to reduce the number of errors produced, but that's probabl y not a valid
3891 // long term approach. 3865 // long term approach.
3892 return null; 3866 return null;
3893 } 3867 }
3894 } on JavaException catch (exception) { 3868 } on JavaException catch (exception) {
3895 } 3869 }
3896 return null; 3870 return null;
3897 } 3871 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3972 * | (final | const) type? staticFinalDeclarationList ';' 3946 * | (final | const) type? staticFinalDeclarationList ';'
3973 * | variableDeclaration ';' 3947 * | variableDeclaration ';'
3974 * </pre> 3948 * </pre>
3975 * 3949 *
3976 * @param commentAndMetadata the metadata to be associated with the member 3950 * @param commentAndMetadata the metadata to be associated with the member
3977 * @return the compilation unit member that was parsed, or `null` if what was parsed could 3951 * @return the compilation unit member that was parsed, or `null` if what was parsed could
3978 * not be represented as a compilation unit member 3952 * not be represented as a compilation unit member
3979 */ 3953 */
3980 CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata commentAnd Metadata) { 3954 CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata commentAnd Metadata) {
3981 Modifiers modifiers = parseModifiers(); 3955 Modifiers modifiers = parseModifiers();
3982 if (matches(Keyword.CLASS)) { 3956 if (matchesKeyword(Keyword.CLASS)) {
3983 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass (modifiers)); 3957 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass (modifiers));
3984 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) & & !matches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) { 3958 } else if (matchesKeyword(Keyword.TYPEDEF) && !tokenMatches(peek(), TokenTyp e.PERIOD) && !tokenMatches(peek(), TokenType.LT) && !tokenMatches(peek(), TokenT ype.OPEN_PAREN)) {
3985 validateModifiersForTypedef(modifiers); 3959 validateModifiersForTypedef(modifiers);
3986 return parseTypeAlias(commentAndMetadata); 3960 return parseTypeAlias(commentAndMetadata);
3987 } 3961 }
3988 if (matches(Keyword.VOID)) { 3962 if (matchesKeyword(Keyword.VOID)) {
3989 TypeName returnType = parseReturnType(); 3963 TypeName returnType = parseReturnType();
3990 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p eek())) { 3964 if ((matchesKeyword(Keyword.GET) || matchesKeyword(Keyword.SET)) && tokenM atchesIdentifier(peek())) {
3991 validateModifiersForTopLevelFunction(modifiers); 3965 validateModifiersForTopLevelFunction(modifiers);
3992 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3966 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3993 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3967 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
3994 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3968 reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, [ ]);
3995 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType)); 3969 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType));
3996 } else if (matchesIdentifier() && matchesAny(peek(), [ 3970 } else if (matchesIdentifier() && matchesAny(peek(), [
3997 TokenType.OPEN_PAREN, 3971 TokenType.OPEN_PAREN,
3998 TokenType.OPEN_CURLY_BRACKET, 3972 TokenType.OPEN_CURLY_BRACKET,
3999 TokenType.FUNCTION])) { 3973 TokenType.FUNCTION])) {
4000 validateModifiersForTopLevelFunction(modifiers); 3974 validateModifiersForTopLevelFunction(modifiers);
4001 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3975 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
4002 } else { 3976 } else {
4003 // 3977 //
4004 // We have found an error of some kind. Try to recover. 3978 // We have found an error of some kind. Try to recover.
4005 // 3979 //
4006 if (matchesIdentifier()) { 3980 if (matchesIdentifier()) {
4007 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 3981 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
4008 // 3982 //
4009 // We appear to have a variable declaration with a type of "void". 3983 // We appear to have a variable declaration with a type of "void".
4010 // 3984 //
4011 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []); 3985 reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []);
4012 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifier sForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 3986 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationListAfterType(null, validate ModifiersForTopLevelVariable(modifiers), null), expect(TokenType.SEMICOLON));
4013 } 3987 }
4014 } 3988 }
4015 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3989 reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
4016 return null; 3990 return null;
4017 } 3991 }
4018 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) { 3992 } else if ((matchesKeyword(Keyword.GET) || matchesKeyword(Keyword.SET)) && t okenMatchesIdentifier(peek())) {
4019 validateModifiersForTopLevelFunction(modifiers); 3993 validateModifiersForTopLevelFunction(modifiers);
4020 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3994 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
4021 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3995 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
4022 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3996 reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []) ;
4023 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null)); 3997 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null));
4024 } else if (!matchesIdentifier()) { 3998 } else if (!matchesIdentifier()) {
4025 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3999 reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, [] );
4026 return null; 4000 return null;
4027 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 4001 } else if (tokenMatches(peek(), TokenType.OPEN_PAREN)) {
4028 validateModifiersForTopLevelFunction(modifiers); 4002 validateModifiersForTopLevelFunction(modifiers);
4029 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 4003 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
4030 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 4004 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
4031 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 4005 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
4032 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4006 reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TY PE, []);
4033 } 4007 }
4034 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 4008 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationListAfterType(null, validateModifi ersForTopLevelVariable(modifiers), null), expect(TokenType.SEMICOLON));
4035 } 4009 }
4036 TypeName returnType = parseReturnType(); 4010 TypeName returnType = parseReturnType();
4037 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) { 4011 if ((matchesKeyword(Keyword.GET) || matchesKeyword(Keyword.SET)) && tokenMat chesIdentifier(peek())) {
4038 validateModifiersForTopLevelFunction(modifiers); 4012 validateModifiersForTopLevelFunction(modifiers);
4039 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 4013 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
4040 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 4014 } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
4041 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 4015 reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []) ;
4042 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType)); 4016 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType));
4043 } else if (matches5(TokenType.AT)) { 4017 } else if (matches(TokenType.AT)) {
4044 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 4018 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationListAfterType(null, validateModifi ersForTopLevelVariable(modifiers), returnType), expect(TokenType.SEMICOLON));
4045 } else if (!matchesIdentifier()) { 4019 } else if (!matchesIdentifier()) {
4046 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point. 4020 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point.
4047 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 4021 reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, [] );
4048 Token semicolon; 4022 Token semicolon;
4049 if (matches5(TokenType.SEMICOLON)) { 4023 if (matches(TokenType.SEMICOLON)) {
4050 semicolon = andAdvance; 4024 semicolon = andAdvance;
4051 } else { 4025 } else {
4052 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 4026 semicolon = createSyntheticToken(TokenType.SEMICOLON);
4053 } 4027 }
4054 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4028 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4055 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null)); 4029 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null));
4056 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon); 4030 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon);
4057 } 4031 }
4058 if (matchesAny(peek(), [ 4032 if (matchesAny(peek(), [
4059 TokenType.OPEN_PAREN, 4033 TokenType.OPEN_PAREN,
4060 TokenType.FUNCTION, 4034 TokenType.FUNCTION,
4061 TokenType.OPEN_CURLY_BRACKET])) { 4035 TokenType.OPEN_CURLY_BRACKET])) {
4062 validateModifiersForTopLevelFunction(modifiers); 4036 validateModifiersForTopLevelFunction(modifiers);
4063 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 4037 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
4064 } 4038 }
4065 return new TopLevelVariableDeclaration(commentAndMetadata.comment, commentAn dMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTopL evelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 4039 return new TopLevelVariableDeclaration(commentAndMetadata.comment, commentAn dMetadata.metadata, parseVariableDeclarationListAfterType(null, validateModifier sForTopLevelVariable(modifiers), returnType), expect(TokenType.SEMICOLON));
4066 } 4040 }
4067 4041
4068 /** 4042 /**
4069 * Parse a const expression. 4043 * Parse a const expression.
4070 * 4044 *
4071 * <pre> 4045 * <pre>
4072 * constExpression ::= 4046 * constExpression ::=
4073 * instanceCreationExpression 4047 * instanceCreationExpression
4074 * | listLiteral 4048 * | listLiteral
4075 * | mapLiteral 4049 * | mapLiteral
4076 * </pre> 4050 * </pre>
4077 * 4051 *
4078 * @return the const expression that was parsed 4052 * @return the const expression that was parsed
4079 */ 4053 */
4080 Expression parseConstExpression() { 4054 Expression parseConstExpression() {
4081 Token keyword = expect(Keyword.CONST); 4055 Token keyword = expectKeyword(Keyword.CONST);
4082 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.INDEX)) { 4056 if (matches(TokenType.OPEN_SQUARE_BRACKET) || matches(TokenType.INDEX)) {
4083 return parseListLiteral(keyword, null); 4057 return parseListLiteral(keyword, null);
4084 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4058 } else if (matches(TokenType.OPEN_CURLY_BRACKET)) {
4085 return parseMapLiteral(keyword, null); 4059 return parseMapLiteral(keyword, null);
4086 } else if (matches5(TokenType.LT)) { 4060 } else if (matches(TokenType.LT)) {
4087 return parseListOrMapLiteral(keyword); 4061 return parseListOrMapLiteral(keyword);
4088 } 4062 }
4089 return parseInstanceCreationExpression(keyword); 4063 return parseInstanceCreationExpression(keyword);
4090 } 4064 }
4091 4065
4092 ConstructorDeclaration parseConstructor(CommentAndMetadata commentAndMetadata, Token externalKeyword, Token constKeyword, Token factoryKeyword, SimpleIdentifi er returnType, Token period, SimpleIdentifier name, FormalParameterList paramete rs) { 4066 ConstructorDeclaration parseConstructor(CommentAndMetadata commentAndMetadata, Token externalKeyword, Token constKeyword, Token factoryKeyword, SimpleIdentifi er returnType, Token period, SimpleIdentifier name, FormalParameterList paramete rs) {
4093 bool bodyAllowed = externalKeyword == null; 4067 bool bodyAllowed = externalKeyword == null;
4094 Token separator = null; 4068 Token separator = null;
4095 List<ConstructorInitializer> initializers = null; 4069 List<ConstructorInitializer> initializers = null;
4096 if (matches5(TokenType.COLON)) { 4070 if (matches(TokenType.COLON)) {
4097 separator = andAdvance; 4071 separator = andAdvance;
4098 initializers = new List<ConstructorInitializer>(); 4072 initializers = new List<ConstructorInitializer>();
4099 do { 4073 do {
4100 if (matches(Keyword.THIS)) { 4074 if (matchesKeyword(Keyword.THIS)) {
4101 if (matches4(peek(), TokenType.OPEN_PAREN)) { 4075 if (tokenMatches(peek(), TokenType.OPEN_PAREN)) {
4102 bodyAllowed = false; 4076 bodyAllowed = false;
4103 initializers.add(parseRedirectingConstructorInvocation()); 4077 initializers.add(parseRedirectingConstructorInvocation());
4104 } else if (matches4(peek(), TokenType.PERIOD) && matches4(peek2(3), To kenType.OPEN_PAREN)) { 4078 } else if (tokenMatches(peek(), TokenType.PERIOD) && tokenMatches(peek 2(3), TokenType.OPEN_PAREN)) {
4105 bodyAllowed = false; 4079 bodyAllowed = false;
4106 initializers.add(parseRedirectingConstructorInvocation()); 4080 initializers.add(parseRedirectingConstructorInvocation());
4107 } else { 4081 } else {
4108 initializers.add(parseConstructorFieldInitializer()); 4082 initializers.add(parseConstructorFieldInitializer());
4109 } 4083 }
4110 } else if (matches(Keyword.SUPER)) { 4084 } else if (matchesKeyword(Keyword.SUPER)) {
4111 initializers.add(parseSuperConstructorInvocation()); 4085 initializers.add(parseSuperConstructorInvocation());
4112 } else { 4086 } else {
4113 initializers.add(parseConstructorFieldInitializer()); 4087 initializers.add(parseConstructorFieldInitializer());
4114 } 4088 }
4115 } while (optional(TokenType.COMMA)); 4089 } while (optional(TokenType.COMMA));
4116 } 4090 }
4117 ConstructorName redirectedConstructor = null; 4091 ConstructorName redirectedConstructor = null;
4118 FunctionBody body; 4092 FunctionBody body;
4119 if (matches5(TokenType.EQ)) { 4093 if (matches(TokenType.EQ)) {
4120 separator = andAdvance; 4094 separator = andAdvance;
4121 redirectedConstructor = parseConstructorName(); 4095 redirectedConstructor = parseConstructorName();
4122 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4096 body = new EmptyFunctionBody(expect(TokenType.SEMICOLON));
4123 if (factoryKeyword == null) { 4097 if (factoryKeyword == null) {
4124 reportError12(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, re directedConstructor, []); 4098 reportErrorForNode(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTO R, redirectedConstructor, []);
4125 } 4099 }
4126 } else { 4100 } else {
4127 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e); 4101 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e);
4128 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) { 4102 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) {
4129 reportError14(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); 4103 reportErrorForToken(ParserErrorCode.CONST_FACTORY, factoryKeyword, []);
4130 } else if (body is EmptyFunctionBody) { 4104 } else if (body is EmptyFunctionBody) {
4131 if (factoryKeyword != null && externalKeyword == null) { 4105 if (factoryKeyword != null && externalKeyword == null) {
4132 reportError14(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] ); 4106 reportErrorForToken(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeywo rd, []);
4133 } 4107 }
4134 } else { 4108 } else {
4135 if (constKeyword != null) { 4109 if (constKeyword != null) {
4136 reportError12(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); 4110 reportErrorForNode(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []);
4137 } else if (!bodyAllowed) { 4111 } else if (!bodyAllowed) {
4138 reportError12(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, [] ); 4112 reportErrorForNode(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, bod y, []);
4139 } 4113 }
4140 } 4114 }
4141 } 4115 }
4142 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body); 4116 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body);
4143 } 4117 }
4144 4118
4145 /** 4119 /**
4146 * Parse a field initializer within a constructor. 4120 * Parse a field initializer within a constructor.
4147 * 4121 *
4148 * <pre> 4122 * <pre>
4149 * fieldInitializer: 4123 * fieldInitializer:
4150 * ('this' '.')? identifier '=' conditionalExpression cascadeSection* 4124 * ('this' '.')? identifier '=' conditionalExpression cascadeSection*
4151 * </pre> 4125 * </pre>
4152 * 4126 *
4153 * @return the field initializer that was parsed 4127 * @return the field initializer that was parsed
4154 */ 4128 */
4155 ConstructorFieldInitializer parseConstructorFieldInitializer() { 4129 ConstructorFieldInitializer parseConstructorFieldInitializer() {
4156 Token keyword = null; 4130 Token keyword = null;
4157 Token period = null; 4131 Token period = null;
4158 if (matches(Keyword.THIS)) { 4132 if (matchesKeyword(Keyword.THIS)) {
4159 keyword = andAdvance; 4133 keyword = andAdvance;
4160 period = expect2(TokenType.PERIOD); 4134 period = expect(TokenType.PERIOD);
4161 } 4135 }
4162 SimpleIdentifier fieldName = parseSimpleIdentifier(); 4136 SimpleIdentifier fieldName = parseSimpleIdentifier();
4163 Token equals = expect2(TokenType.EQ); 4137 Token equals = expect(TokenType.EQ);
4164 Expression expression = parseConditionalExpression(); 4138 Expression expression = parseConditionalExpression();
4165 TokenType tokenType = _currentToken.type; 4139 TokenType tokenType = _currentToken.type;
4166 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 4140 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
4167 List<Expression> cascadeSections = new List<Expression>(); 4141 List<Expression> cascadeSections = new List<Expression>();
4168 while (identical(tokenType, TokenType.PERIOD_PERIOD)) { 4142 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
4169 Expression section = parseCascadeSection(); 4143 Expression section = parseCascadeSection();
4170 if (section != null) { 4144 if (section != null) {
4171 cascadeSections.add(section); 4145 cascadeSections.add(section);
4172 } 4146 }
4173 tokenType = _currentToken.type; 4147 tokenType = _currentToken.type;
4174 } 4148 }
4175 expression = new CascadeExpression(expression, cascadeSections); 4149 expression = new CascadeExpression(expression, cascadeSections);
4176 } 4150 }
4177 return new ConstructorFieldInitializer(keyword, period, fieldName, equals, e xpression); 4151 return new ConstructorFieldInitializer(keyword, period, fieldName, equals, e xpression);
4178 } 4152 }
4179 4153
4180 /** 4154 /**
4181 * Parse a continue statement. 4155 * Parse a continue statement.
4182 * 4156 *
4183 * <pre> 4157 * <pre>
4184 * continueStatement ::= 4158 * continueStatement ::=
4185 * 'continue' identifier? ';' 4159 * 'continue' identifier? ';'
4186 * </pre> 4160 * </pre>
4187 * 4161 *
4188 * @return the continue statement that was parsed 4162 * @return the continue statement that was parsed
4189 */ 4163 */
4190 Statement parseContinueStatement() { 4164 Statement parseContinueStatement() {
4191 Token continueKeyword = expect(Keyword.CONTINUE); 4165 Token continueKeyword = expectKeyword(Keyword.CONTINUE);
4192 if (!_inLoop && !_inSwitch) { 4166 if (!_inLoop && !_inSwitch) {
4193 reportError14(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]); 4167 reportErrorForToken(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyw ord, []);
4194 } 4168 }
4195 SimpleIdentifier label = null; 4169 SimpleIdentifier label = null;
4196 if (matchesIdentifier()) { 4170 if (matchesIdentifier()) {
4197 label = parseSimpleIdentifier(); 4171 label = parseSimpleIdentifier();
4198 } 4172 }
4199 if (_inSwitch && !_inLoop && label == null) { 4173 if (_inSwitch && !_inLoop && label == null) {
4200 reportError14(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []); 4174 reportErrorForToken(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, contin ueKeyword, []);
4201 } 4175 }
4202 Token semicolon = expect2(TokenType.SEMICOLON); 4176 Token semicolon = expect(TokenType.SEMICOLON);
4203 return new ContinueStatement(continueKeyword, label, semicolon); 4177 return new ContinueStatement(continueKeyword, label, semicolon);
4204 } 4178 }
4205 4179
4206 /** 4180 /**
4207 * Parse a directive. 4181 * Parse a directive.
4208 * 4182 *
4209 * <pre> 4183 * <pre>
4210 * directive ::= 4184 * directive ::=
4211 * exportDirective 4185 * exportDirective
4212 * | libraryDirective 4186 * | libraryDirective
4213 * | importDirective 4187 * | importDirective
4214 * | partDirective 4188 * | partDirective
4215 * </pre> 4189 * </pre>
4216 * 4190 *
4217 * @param commentAndMetadata the metadata to be associated with the directive 4191 * @param commentAndMetadata the metadata to be associated with the directive
4218 * @return the directive that was parsed 4192 * @return the directive that was parsed
4219 */ 4193 */
4220 Directive parseDirective(CommentAndMetadata commentAndMetadata) { 4194 Directive parseDirective(CommentAndMetadata commentAndMetadata) {
4221 if (matches(Keyword.IMPORT)) { 4195 if (matchesKeyword(Keyword.IMPORT)) {
4222 return parseImportDirective(commentAndMetadata); 4196 return parseImportDirective(commentAndMetadata);
4223 } else if (matches(Keyword.EXPORT)) { 4197 } else if (matchesKeyword(Keyword.EXPORT)) {
4224 return parseExportDirective(commentAndMetadata); 4198 return parseExportDirective(commentAndMetadata);
4225 } else if (matches(Keyword.LIBRARY)) { 4199 } else if (matchesKeyword(Keyword.LIBRARY)) {
4226 return parseLibraryDirective(commentAndMetadata); 4200 return parseLibraryDirective(commentAndMetadata);
4227 } else if (matches(Keyword.PART)) { 4201 } else if (matchesKeyword(Keyword.PART)) {
4228 return parsePartDirective(commentAndMetadata); 4202 return parsePartDirective(commentAndMetadata);
4229 } else { 4203 } else {
4230 // Internal error: this method should not have been invoked if the current token was something 4204 // Internal error: this method should not have been invoked if the current token was something
4231 // other than one of the above. 4205 // other than one of the above.
4232 throw new IllegalStateException("parseDirective invoked in an invalid stat e; currentToken = ${_currentToken}"); 4206 throw new IllegalStateException("parseDirective invoked in an invalid stat e; currentToken = ${_currentToken}");
4233 } 4207 }
4234 } 4208 }
4235 4209
4236 /** 4210 /**
4237 * Parse a documentation comment. 4211 * Parse a documentation comment.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 * doStatement ::= 4252 * doStatement ::=
4279 * 'do' statement 'while' '(' expression ')' ';' 4253 * 'do' statement 'while' '(' expression ')' ';'
4280 * </pre> 4254 * </pre>
4281 * 4255 *
4282 * @return the do statement that was parsed 4256 * @return the do statement that was parsed
4283 */ 4257 */
4284 Statement parseDoStatement() { 4258 Statement parseDoStatement() {
4285 bool wasInLoop = _inLoop; 4259 bool wasInLoop = _inLoop;
4286 _inLoop = true; 4260 _inLoop = true;
4287 try { 4261 try {
4288 Token doKeyword = expect(Keyword.DO); 4262 Token doKeyword = expectKeyword(Keyword.DO);
4289 Statement body = parseStatement2(); 4263 Statement body = parseStatement2();
4290 Token whileKeyword = expect(Keyword.WHILE); 4264 Token whileKeyword = expectKeyword(Keyword.WHILE);
4291 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4265 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
4292 Expression condition = parseExpression2(); 4266 Expression condition = parseExpression2();
4293 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4267 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
4294 Token semicolon = expect2(TokenType.SEMICOLON); 4268 Token semicolon = expect(TokenType.SEMICOLON);
4295 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon); 4269 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon);
4296 } finally { 4270 } finally {
4297 _inLoop = wasInLoop; 4271 _inLoop = wasInLoop;
4298 } 4272 }
4299 } 4273 }
4300 4274
4301 /** 4275 /**
4302 * Parse an empty statement. 4276 * Parse an empty statement.
4303 * 4277 *
4304 * <pre> 4278 * <pre>
(...skipping 11 matching lines...) Expand all
4316 * <pre> 4290 * <pre>
4317 * equalityExpression ::= 4291 * equalityExpression ::=
4318 * relationalExpression (equalityOperator relationalExpression)? 4292 * relationalExpression (equalityOperator relationalExpression)?
4319 * | 'super' equalityOperator relationalExpression 4293 * | 'super' equalityOperator relationalExpression
4320 * </pre> 4294 * </pre>
4321 * 4295 *
4322 * @return the equality expression that was parsed 4296 * @return the equality expression that was parsed
4323 */ 4297 */
4324 Expression parseEqualityExpression() { 4298 Expression parseEqualityExpression() {
4325 Expression expression; 4299 Expression expression;
4326 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) { 4300 if (matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isEqualityOpera tor) {
4327 expression = new SuperExpression(andAdvance); 4301 expression = new SuperExpression(andAdvance);
4328 } else { 4302 } else {
4329 expression = parseRelationalExpression(); 4303 expression = parseRelationalExpression();
4330 } 4304 }
4331 bool leftEqualityExpression = false; 4305 bool leftEqualityExpression = false;
4332 while (_currentToken.type.isEqualityOperator) { 4306 while (_currentToken.type.isEqualityOperator) {
4333 Token operator = andAdvance; 4307 Token operator = andAdvance;
4334 if (leftEqualityExpression) { 4308 if (leftEqualityExpression) {
4335 reportError12(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expre ssion, []); 4309 reportErrorForNode(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression, []);
4336 } 4310 }
4337 expression = new BinaryExpression(expression, operator, parseRelationalExp ression()); 4311 expression = new BinaryExpression(expression, operator, parseRelationalExp ression());
4338 leftEqualityExpression = true; 4312 leftEqualityExpression = true;
4339 } 4313 }
4340 return expression; 4314 return expression;
4341 } 4315 }
4342 4316
4343 /** 4317 /**
4344 * Parse an export directive. 4318 * Parse an export directive.
4345 * 4319 *
4346 * <pre> 4320 * <pre>
4347 * exportDirective ::= 4321 * exportDirective ::=
4348 * metadata 'export' stringLiteral combinator*';' 4322 * metadata 'export' stringLiteral combinator*';'
4349 * </pre> 4323 * </pre>
4350 * 4324 *
4351 * @param commentAndMetadata the metadata to be associated with the directive 4325 * @param commentAndMetadata the metadata to be associated with the directive
4352 * @return the export directive that was parsed 4326 * @return the export directive that was parsed
4353 */ 4327 */
4354 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { 4328 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) {
4355 Token exportKeyword = expect(Keyword.EXPORT); 4329 Token exportKeyword = expectKeyword(Keyword.EXPORT);
4356 StringLiteral libraryUri = parseStringLiteral(); 4330 StringLiteral libraryUri = parseStringLiteral();
4357 List<Combinator> combinators = parseCombinators(); 4331 List<Combinator> combinators = parseCombinators();
4358 Token semicolon = expectSemicolon(); 4332 Token semicolon = expectSemicolon();
4359 return new ExportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, exportKeyword, libraryUri, combinators, semicolon); 4333 return new ExportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, exportKeyword, libraryUri, combinators, semicolon);
4360 } 4334 }
4361 4335
4362 /** 4336 /**
4363 * Parse a list of expressions. 4337 * Parse a list of expressions.
4364 * 4338 *
4365 * <pre> 4339 * <pre>
(...skipping 22 matching lines...) Expand all
4388 * | 'var' 4362 * | 'var'
4389 * | type 4363 * | type
4390 * </pre> 4364 * </pre>
4391 * 4365 *
4392 * @param optional `true` if the keyword and type are optional 4366 * @param optional `true` if the keyword and type are optional
4393 * @return the 'final', 'const', 'var' or type that was parsed 4367 * @return the 'final', 'const', 'var' or type that was parsed
4394 */ 4368 */
4395 FinalConstVarOrType parseFinalConstVarOrType(bool optional) { 4369 FinalConstVarOrType parseFinalConstVarOrType(bool optional) {
4396 Token keyword = null; 4370 Token keyword = null;
4397 TypeName type = null; 4371 TypeName type = null;
4398 if (matches(Keyword.FINAL) || matches(Keyword.CONST)) { 4372 if (matchesKeyword(Keyword.FINAL) || matchesKeyword(Keyword.CONST)) {
4399 keyword = andAdvance; 4373 keyword = andAdvance;
4400 if (isTypedIdentifier(_currentToken)) { 4374 if (isTypedIdentifier(_currentToken)) {
4401 type = parseTypeName(); 4375 type = parseTypeName();
4402 } 4376 }
4403 } else if (matches(Keyword.VAR)) { 4377 } else if (matchesKeyword(Keyword.VAR)) {
4404 keyword = andAdvance; 4378 keyword = andAdvance;
4405 } else { 4379 } else {
4406 if (isTypedIdentifier(_currentToken)) { 4380 if (isTypedIdentifier(_currentToken)) {
4407 type = parseReturnType(); 4381 type = parseReturnType();
4408 } else if (!optional) { 4382 } else if (!optional) {
4409 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4383 reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TY PE, []);
4410 } 4384 }
4411 } 4385 }
4412 return new FinalConstVarOrType(keyword, type); 4386 return new FinalConstVarOrType(keyword, type);
4413 } 4387 }
4414 4388
4415 /** 4389 /**
4416 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be 4390 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
4417 * `true`. 4391 * `true`.
4418 * 4392 *
4419 * <pre> 4393 * <pre>
4420 * defaultFormalParameter ::= 4394 * defaultFormalParameter ::=
4421 * normalFormalParameter ('=' expression)? 4395 * normalFormalParameter ('=' expression)?
4422 * 4396 *
4423 * defaultNamedParameter ::= 4397 * defaultNamedParameter ::=
4424 * normalFormalParameter (':' expression)? 4398 * normalFormalParameter (':' expression)?
4425 * </pre> 4399 * </pre>
4426 * 4400 *
4427 * @param kind the kind of parameter being expected based on the presence or a bsence of group 4401 * @param kind the kind of parameter being expected based on the presence or a bsence of group
4428 * delimiters 4402 * delimiters
4429 * @return the formal parameter that was parsed 4403 * @return the formal parameter that was parsed
4430 */ 4404 */
4431 FormalParameter parseFormalParameter(ParameterKind kind) { 4405 FormalParameter parseFormalParameter(ParameterKind kind) {
4432 NormalFormalParameter parameter = parseNormalFormalParameter(); 4406 NormalFormalParameter parameter = parseNormalFormalParameter();
4433 if (matches5(TokenType.EQ)) { 4407 if (matches(TokenType.EQ)) {
4434 Token seperator = andAdvance; 4408 Token seperator = andAdvance;
4435 Expression defaultValue = parseExpression2(); 4409 Expression defaultValue = parseExpression2();
4436 if (identical(kind, ParameterKind.NAMED)) { 4410 if (identical(kind, ParameterKind.NAMED)) {
4437 reportError14(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []); 4411 reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seperator, []);
4438 } else if (identical(kind, ParameterKind.REQUIRED)) { 4412 } else if (identical(kind, ParameterKind.REQUIRED)) {
4439 reportError12(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parame ter, []); 4413 reportErrorForNode(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, p arameter, []);
4440 } 4414 }
4441 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4415 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4442 } else if (matches5(TokenType.COLON)) { 4416 } else if (matches(TokenType.COLON)) {
4443 Token seperator = andAdvance; 4417 Token seperator = andAdvance;
4444 Expression defaultValue = parseExpression2(); 4418 Expression defaultValue = parseExpression2();
4445 if (identical(kind, ParameterKind.POSITIONAL)) { 4419 if (identical(kind, ParameterKind.POSITIONAL)) {
4446 reportError14(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []); 4420 reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAM ETER, seperator, []);
4447 } else if (identical(kind, ParameterKind.REQUIRED)) { 4421 } else if (identical(kind, ParameterKind.REQUIRED)) {
4448 reportError12(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []); 4422 reportErrorForNode(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parame ter, []);
4449 } 4423 }
4450 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4424 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4451 } else if (kind != ParameterKind.REQUIRED) { 4425 } else if (kind != ParameterKind.REQUIRED) {
4452 return new DefaultFormalParameter(parameter, kind, null, null); 4426 return new DefaultFormalParameter(parameter, kind, null, null);
4453 } 4427 }
4454 return parameter; 4428 return parameter;
4455 } 4429 }
4456 4430
4457 /** 4431 /**
4458 * Parse a for statement. 4432 * Parse a for statement.
(...skipping 11 matching lines...) Expand all
4470 * localVariableDeclaration ';' 4444 * localVariableDeclaration ';'
4471 * | expression? ';' 4445 * | expression? ';'
4472 * </pre> 4446 * </pre>
4473 * 4447 *
4474 * @return the for statement that was parsed 4448 * @return the for statement that was parsed
4475 */ 4449 */
4476 Statement parseForStatement() { 4450 Statement parseForStatement() {
4477 bool wasInLoop = _inLoop; 4451 bool wasInLoop = _inLoop;
4478 _inLoop = true; 4452 _inLoop = true;
4479 try { 4453 try {
4480 Token forKeyword = expect(Keyword.FOR); 4454 Token forKeyword = expectKeyword(Keyword.FOR);
4481 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4455 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
4482 VariableDeclarationList variableList = null; 4456 VariableDeclarationList variableList = null;
4483 Expression initialization = null; 4457 Expression initialization = null;
4484 if (!matches5(TokenType.SEMICOLON)) { 4458 if (!matches(TokenType.SEMICOLON)) {
4485 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4459 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4486 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) { 4460 if (matchesIdentifier() && tokenMatchesKeyword(peek(), Keyword.IN)) {
4487 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4461 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4488 SimpleIdentifier variableName = parseSimpleIdentifier(); 4462 SimpleIdentifier variableName = parseSimpleIdentifier();
4489 variables.add(new VariableDeclaration(null, null, variableName, null, null)); 4463 variables.add(new VariableDeclaration(null, null, variableName, null, null));
4490 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables); 4464 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables);
4491 } else if (isInitializedVariableDeclaration()) { 4465 } else if (isInitializedVariableDeclaration()) {
4492 variableList = parseVariableDeclarationList(commentAndMetadata); 4466 variableList = parseVariableDeclarationListAfterMetadata(commentAndMet adata);
4493 } else { 4467 } else {
4494 initialization = parseExpression2(); 4468 initialization = parseExpression2();
4495 } 4469 }
4496 if (matches(Keyword.IN)) { 4470 if (matchesKeyword(Keyword.IN)) {
4497 DeclaredIdentifier loopVariable = null; 4471 DeclaredIdentifier loopVariable = null;
4498 SimpleIdentifier identifier = null; 4472 SimpleIdentifier identifier = null;
4499 if (variableList == null) { 4473 if (variableList == null) {
4500 // We found: <expression> 'in' 4474 // We found: <expression> 'in'
4501 reportError13(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); 4475 reportErrorForCurrentToken(ParserErrorCode.MISSING_VARIABLE_IN_FOR_E ACH, []);
4502 } else { 4476 } else {
4503 NodeList<VariableDeclaration> variables = variableList.variables; 4477 NodeList<VariableDeclaration> variables = variableList.variables;
4504 if (variables.length > 1) { 4478 if (variables.length > 1) {
4505 reportError13(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]); 4479 reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_VARIABLES_IN_F OR_EACH, [variables.length.toString()]);
4506 } 4480 }
4507 VariableDeclaration variable = variables[0]; 4481 VariableDeclaration variable = variables[0];
4508 if (variable.initializer != null) { 4482 if (variable.initializer != null) {
4509 reportError13(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] ); 4483 reportErrorForCurrentToken(ParserErrorCode.INITIALIZED_VARIABLE_IN _FOR_EACH, []);
4510 } 4484 }
4511 Token keyword = variableList.keyword; 4485 Token keyword = variableList.keyword;
4512 TypeName type = variableList.type; 4486 TypeName type = variableList.type;
4513 if (keyword != null || type != null) { 4487 if (keyword != null || type != null) {
4514 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name); 4488 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name);
4515 } else { 4489 } else {
4516 if (!commentAndMetadata.metadata.isEmpty) { 4490 if (!commentAndMetadata.metadata.isEmpty) {
4517 } 4491 }
4518 identifier = variable.name; 4492 identifier = variable.name;
4519 } 4493 }
4520 } 4494 }
4521 Token inKeyword = expect(Keyword.IN); 4495 Token inKeyword = expectKeyword(Keyword.IN);
4522 Expression iterator = parseExpression2(); 4496 Expression iterator = parseExpression2();
4523 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4497 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
4524 Statement body = parseStatement2(); 4498 Statement body = parseStatement2();
4525 if (loopVariable == null) { 4499 if (loopVariable == null) {
4526 return new ForEachStatement.con2(forKeyword, leftParenthesis, identi fier, inKeyword, iterator, rightParenthesis, body); 4500 return new ForEachStatement.con2(forKeyword, leftParenthesis, identi fier, inKeyword, iterator, rightParenthesis, body);
4527 } 4501 }
4528 return new ForEachStatement.con1(forKeyword, leftParenthesis, loopVari able, inKeyword, iterator, rightParenthesis, body); 4502 return new ForEachStatement.con1(forKeyword, leftParenthesis, loopVari able, inKeyword, iterator, rightParenthesis, body);
4529 } 4503 }
4530 } 4504 }
4531 Token leftSeparator = expect2(TokenType.SEMICOLON); 4505 Token leftSeparator = expect(TokenType.SEMICOLON);
4532 Expression condition = null; 4506 Expression condition = null;
4533 if (!matches5(TokenType.SEMICOLON)) { 4507 if (!matches(TokenType.SEMICOLON)) {
4534 condition = parseExpression2(); 4508 condition = parseExpression2();
4535 } 4509 }
4536 Token rightSeparator = expect2(TokenType.SEMICOLON); 4510 Token rightSeparator = expect(TokenType.SEMICOLON);
4537 List<Expression> updaters = null; 4511 List<Expression> updaters = null;
4538 if (!matches5(TokenType.CLOSE_PAREN)) { 4512 if (!matches(TokenType.CLOSE_PAREN)) {
4539 updaters = parseExpressionList(); 4513 updaters = parseExpressionList();
4540 } 4514 }
4541 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4515 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
4542 Statement body = parseStatement2(); 4516 Statement body = parseStatement2();
4543 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody); 4517 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody);
4544 } finally { 4518 } finally {
4545 _inLoop = wasInLoop; 4519 _inLoop = wasInLoop;
4546 } 4520 }
4547 } 4521 }
4548 4522
4549 /** 4523 /**
4550 * Parse a function body. 4524 * Parse a function body.
4551 * 4525 *
(...skipping 12 matching lines...) Expand all
4564 * @param inExpression `true` if the function body is being parsed as part of an expression 4538 * @param inExpression `true` if the function body is being parsed as part of an expression
4565 * and therefore does not have a terminating semicolon 4539 * and therefore does not have a terminating semicolon
4566 * @return the function body that was parsed 4540 * @return the function body that was parsed
4567 */ 4541 */
4568 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) { 4542 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) {
4569 bool wasInLoop = _inLoop; 4543 bool wasInLoop = _inLoop;
4570 bool wasInSwitch = _inSwitch; 4544 bool wasInSwitch = _inSwitch;
4571 _inLoop = false; 4545 _inLoop = false;
4572 _inSwitch = false; 4546 _inSwitch = false;
4573 try { 4547 try {
4574 if (matches5(TokenType.SEMICOLON)) { 4548 if (matches(TokenType.SEMICOLON)) {
4575 if (!mayBeEmpty) { 4549 if (!mayBeEmpty) {
4576 reportError13(emptyErrorCode, []); 4550 reportErrorForCurrentToken(emptyErrorCode, []);
4577 } 4551 }
4578 return new EmptyFunctionBody(andAdvance); 4552 return new EmptyFunctionBody(andAdvance);
4579 } else if (matches5(TokenType.FUNCTION)) { 4553 } else if (matches(TokenType.FUNCTION)) {
4580 Token functionDefinition = andAdvance; 4554 Token functionDefinition = andAdvance;
4581 Expression expression = parseExpression2(); 4555 Expression expression = parseExpression2();
4582 Token semicolon = null; 4556 Token semicolon = null;
4583 if (!inExpression) { 4557 if (!inExpression) {
4584 semicolon = expect2(TokenType.SEMICOLON); 4558 semicolon = expect(TokenType.SEMICOLON);
4585 } 4559 }
4586 if (!_parseFunctionBodies) { 4560 if (!_parseFunctionBodies) {
4587 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4561 return new EmptyFunctionBody(createSyntheticToken(TokenType.SEMICOLON) );
4588 } 4562 }
4589 return new ExpressionFunctionBody(functionDefinition, expression, semico lon); 4563 return new ExpressionFunctionBody(functionDefinition, expression, semico lon);
4590 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4564 } else if (matches(TokenType.OPEN_CURLY_BRACKET)) {
4591 if (!_parseFunctionBodies) { 4565 if (!_parseFunctionBodies) {
4592 skipBlock(); 4566 skipBlock();
4593 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4567 return new EmptyFunctionBody(createSyntheticToken(TokenType.SEMICOLON) );
4594 } 4568 }
4595 return new BlockFunctionBody(parseBlock()); 4569 return new BlockFunctionBody(parseBlock());
4596 } else if (matches2(_NATIVE)) { 4570 } else if (matchesString(_NATIVE)) {
4597 Token nativeToken = andAdvance; 4571 Token nativeToken = andAdvance;
4598 StringLiteral stringLiteral = null; 4572 StringLiteral stringLiteral = null;
4599 if (matches5(TokenType.STRING)) { 4573 if (matches(TokenType.STRING)) {
4600 stringLiteral = parseStringLiteral(); 4574 stringLiteral = parseStringLiteral();
4601 } 4575 }
4602 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON)); 4576 return new NativeFunctionBody(nativeToken, stringLiteral, expect(TokenTy pe.SEMICOLON));
4603 } else { 4577 } else {
4604 // Invalid function body 4578 // Invalid function body
4605 reportError13(emptyErrorCode, []); 4579 reportErrorForCurrentToken(emptyErrorCode, []);
4606 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ; 4580 return new EmptyFunctionBody(createSyntheticToken(TokenType.SEMICOLON));
4607 } 4581 }
4608 } finally { 4582 } finally {
4609 _inLoop = wasInLoop; 4583 _inLoop = wasInLoop;
4610 _inSwitch = wasInSwitch; 4584 _inSwitch = wasInSwitch;
4611 } 4585 }
4612 } 4586 }
4613 4587
4614 /** 4588 /**
4615 * Parse a function declaration. 4589 * Parse a function declaration.
4616 * 4590 *
4617 * <pre> 4591 * <pre>
4618 * functionDeclaration ::= 4592 * functionDeclaration ::=
4619 * functionSignature functionBody 4593 * functionSignature functionBody
4620 * | returnType? getOrSet identifier formalParameterList functionBody 4594 * | returnType? getOrSet identifier formalParameterList functionBody
4621 * </pre> 4595 * </pre>
4622 * 4596 *
4623 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4597 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4624 * declaration 4598 * declaration
4625 * @param externalKeyword the 'external' keyword, or `null` if the function is not external 4599 * @param externalKeyword the 'external' keyword, or `null` if the function is not external
4626 * @param returnType the return type, or `null` if there is no return type 4600 * @param returnType the return type, or `null` if there is no return type
4627 * @param isStatement `true` if the function declaration is being parsed as a statement 4601 * @param isStatement `true` if the function declaration is being parsed as a statement
4628 * @return the function declaration that was parsed 4602 * @return the function declaration that was parsed
4629 */ 4603 */
4630 FunctionDeclaration parseFunctionDeclaration(CommentAndMetadata commentAndMeta data, Token externalKeyword, TypeName returnType) { 4604 FunctionDeclaration parseFunctionDeclaration(CommentAndMetadata commentAndMeta data, Token externalKeyword, TypeName returnType) {
4631 Token keyword = null; 4605 Token keyword = null;
4632 bool isGetter = false; 4606 bool isGetter = false;
4633 if (matches(Keyword.GET) && !matches4(peek(), TokenType.OPEN_PAREN)) { 4607 if (matchesKeyword(Keyword.GET) && !tokenMatches(peek(), TokenType.OPEN_PARE N)) {
4634 keyword = andAdvance; 4608 keyword = andAdvance;
4635 isGetter = true; 4609 isGetter = true;
4636 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN)) { 4610 } else if (matchesKeyword(Keyword.SET) && !tokenMatches(peek(), TokenType.OP EN_PAREN)) {
4637 keyword = andAdvance; 4611 keyword = andAdvance;
4638 } 4612 }
4639 SimpleIdentifier name = parseSimpleIdentifier(); 4613 SimpleIdentifier name = parseSimpleIdentifier();
4640 FormalParameterList parameters = null; 4614 FormalParameterList parameters = null;
4641 if (!isGetter) { 4615 if (!isGetter) {
4642 if (matches5(TokenType.OPEN_PAREN)) { 4616 if (matches(TokenType.OPEN_PAREN)) {
4643 parameters = parseFormalParameterList(); 4617 parameters = parseFormalParameterList();
4644 validateFormalParameterList(parameters); 4618 validateFormalParameterList(parameters);
4645 } else { 4619 } else {
4646 reportError13(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); 4620 reportErrorForCurrentToken(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []);
4647 } 4621 }
4648 } else if (matches5(TokenType.OPEN_PAREN)) { 4622 } else if (matches(TokenType.OPEN_PAREN)) {
4649 reportError13(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4623 reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4650 parseFormalParameterList(); 4624 parseFormalParameterList();
4651 } 4625 }
4652 FunctionBody body; 4626 FunctionBody body;
4653 if (externalKeyword == null) { 4627 if (externalKeyword == null) {
4654 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se); 4628 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se);
4655 } else { 4629 } else {
4656 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4630 body = new EmptyFunctionBody(expect(TokenType.SEMICOLON));
4657 } 4631 }
4658 // if (!isStatement && matches(TokenType.SEMICOLON)) { 4632 // if (!isStatement && matches(TokenType.SEMICOLON)) {
4659 // // TODO(brianwilkerson) Improve this error message. 4633 // // TODO(brianwilkerson) Improve this error message.
4660 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ()); 4634 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ());
4661 // advance(); 4635 // advance();
4662 // } 4636 // }
4663 return new FunctionDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, externalKeyword, returnType, keyword, name, new FunctionExpression(p arameters, body)); 4637 return new FunctionDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, externalKeyword, returnType, keyword, name, new FunctionExpression(p arameters, body));
4664 } 4638 }
4665 4639
4666 /** 4640 /**
4667 * Parse a function declaration statement. 4641 * Parse a function declaration statement.
4668 * 4642 *
4669 * <pre> 4643 * <pre>
4670 * functionDeclarationStatement ::= 4644 * functionDeclarationStatement ::=
4671 * functionSignature functionBody 4645 * functionSignature functionBody
4672 * </pre> 4646 * </pre>
4673 * 4647 *
4674 * @return the function declaration statement that was parsed 4648 * @return the function declaration statement that was parsed
4675 */ 4649 */
4676 Statement parseFunctionDeclarationStatement() { 4650 Statement parseFunctionDeclarationStatement() {
4677 Modifiers modifiers = parseModifiers(); 4651 Modifiers modifiers = parseModifiers();
4678 validateModifiersForFunctionDeclarationStatement(modifiers); 4652 validateModifiersForFunctionDeclarationStatement(modifiers);
4679 return parseFunctionDeclarationStatement2(parseCommentAndMetadata(), parseOp tionalReturnType()); 4653 return parseFunctionDeclarationStatementAfterReturnType(parseCommentAndMetad ata(), parseOptionalReturnType());
4680 } 4654 }
4681 4655
4682 /** 4656 /**
4683 * Parse a function declaration statement. 4657 * Parse a function declaration statement.
4684 * 4658 *
4685 * <pre> 4659 * <pre>
4686 * functionDeclarationStatement ::= 4660 * functionDeclarationStatement ::=
4687 * functionSignature functionBody 4661 * functionSignature functionBody
4688 * </pre> 4662 * </pre>
4689 * 4663 *
4690 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4664 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4691 * declaration 4665 * declaration
4692 * @param returnType the return type, or `null` if there is no return type 4666 * @param returnType the return type, or `null` if there is no return type
4693 * @return the function declaration statement that was parsed 4667 * @return the function declaration statement that was parsed
4694 */ 4668 */
4695 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) { 4669 Statement parseFunctionDeclarationStatementAfterReturnType(CommentAndMetadata commentAndMetadata, TypeName returnType) {
4696 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType); 4670 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType);
4697 Token propertyKeyword = declaration.propertyKeyword; 4671 Token propertyKeyword = declaration.propertyKeyword;
4698 if (propertyKeyword != null) { 4672 if (propertyKeyword != null) {
4699 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) { 4673 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) {
4700 reportError14(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []); 4674 reportErrorForToken(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []);
4701 } else { 4675 } else {
4702 reportError14(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []); 4676 reportErrorForToken(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []);
4703 } 4677 }
4704 } 4678 }
4705 return new FunctionDeclarationStatement(declaration); 4679 return new FunctionDeclarationStatement(declaration);
4706 } 4680 }
4707 4681
4708 /** 4682 /**
4709 * Parse a function type alias. 4683 * Parse a function type alias.
4710 * 4684 *
4711 * <pre> 4685 * <pre>
4712 * functionTypeAlias ::= 4686 * functionTypeAlias ::=
4713 * functionPrefix typeParameterList? formalParameterList ';' 4687 * functionPrefix typeParameterList? formalParameterList ';'
4714 * 4688 *
4715 * functionPrefix ::= 4689 * functionPrefix ::=
4716 * returnType? name 4690 * returnType? name
4717 * </pre> 4691 * </pre>
4718 * 4692 *
4719 * @param commentAndMetadata the metadata to be associated with the member 4693 * @param commentAndMetadata the metadata to be associated with the member
4720 * @param keyword the token representing the 'typedef' keyword 4694 * @param keyword the token representing the 'typedef' keyword
4721 * @return the function type alias that was parsed 4695 * @return the function type alias that was parsed
4722 */ 4696 */
4723 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) { 4697 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) {
4724 TypeName returnType = null; 4698 TypeName returnType = null;
4725 if (hasReturnTypeInTypeAlias()) { 4699 if (hasReturnTypeInTypeAlias()) {
4726 returnType = parseReturnType(); 4700 returnType = parseReturnType();
4727 } 4701 }
4728 SimpleIdentifier name = parseSimpleIdentifier(); 4702 SimpleIdentifier name = parseSimpleIdentifier();
4729 TypeParameterList typeParameters = null; 4703 TypeParameterList typeParameters = null;
4730 if (matches5(TokenType.LT)) { 4704 if (matches(TokenType.LT)) {
4731 typeParameters = parseTypeParameterList(); 4705 typeParameters = parseTypeParameterList();
4732 } 4706 }
4733 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { 4707 if (matches(TokenType.SEMICOLON) || matches(TokenType.EOF)) {
4734 reportError13(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4708 reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []) ;
4735 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenType.CL OSE_PAREN)); 4709 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken(TokenType.CLOS E_PAREN));
4736 Token semicolon = expect2(TokenType.SEMICOLON); 4710 Token semicolon = expect(TokenType.SEMICOLON);
4737 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 4711 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4738 } else if (!matches5(TokenType.OPEN_PAREN)) { 4712 } else if (!matches(TokenType.OPEN_PAREN)) {
4739 reportError13(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4713 reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []) ;
4740 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start 4714 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start
4741 // of the next valid compilation unit member, allowing for the possibility of finding the 4715 // of the next valid compilation unit member, allowing for the possibility of finding the
4742 // typedef parameters before that point. 4716 // typedef parameters before that point.
4743 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(c reateSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticTok en2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON)); 4717 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(c reateSyntheticToken(TokenType.OPEN_PAREN), null, null, null, createSyntheticToke n(TokenType.CLOSE_PAREN)), createSyntheticToken(TokenType.SEMICOLON));
4744 } 4718 }
4745 FormalParameterList parameters = parseFormalParameterList(); 4719 FormalParameterList parameters = parseFormalParameterList();
4746 validateFormalParameterList(parameters); 4720 validateFormalParameterList(parameters);
4747 Token semicolon = expect2(TokenType.SEMICOLON); 4721 Token semicolon = expect(TokenType.SEMICOLON);
4748 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 4722 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4749 } 4723 }
4750 4724
4751 /** 4725 /**
4752 * Parse a getter. 4726 * Parse a getter.
4753 * 4727 *
4754 * <pre> 4728 * <pre>
4755 * getter ::= 4729 * getter ::=
4756 * getterSignature functionBody? 4730 * getterSignature functionBody?
4757 * 4731 *
4758 * getterSignature ::= 4732 * getterSignature ::=
4759 * 'external'? 'static'? returnType? 'get' identifier 4733 * 'external'? 'static'? returnType? 'get' identifier
4760 * </pre> 4734 * </pre>
4761 * 4735 *
4762 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4736 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4763 * declaration 4737 * declaration
4764 * @param externalKeyword the 'external' token 4738 * @param externalKeyword the 'external' token
4765 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 4739 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
4766 * @param the return type that has already been parsed, or `null` if there was no return 4740 * @param the return type that has already been parsed, or `null` if there was no return
4767 * type 4741 * type
4768 * @return the getter that was parsed 4742 * @return the getter that was parsed
4769 */ 4743 */
4770 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 4744 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
4771 Token propertyKeyword = expect(Keyword.GET); 4745 Token propertyKeyword = expectKeyword(Keyword.GET);
4772 SimpleIdentifier name = parseSimpleIdentifier(); 4746 SimpleIdentifier name = parseSimpleIdentifier();
4773 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) { 4747 if (matches(TokenType.OPEN_PAREN) && tokenMatches(peek(), TokenType.CLOSE_PA REN)) {
4774 reportError13(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4748 reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4775 advance(); 4749 advance();
4776 advance(); 4750 advance();
4777 } 4751 }
4778 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); 4752 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false);
4779 if (externalKeyword != null && body is! EmptyFunctionBody) { 4753 if (externalKeyword != null && body is! EmptyFunctionBody) {
4780 reportError13(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); 4754 reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []);
4781 } 4755 }
4782 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body); 4756 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body);
4783 } 4757 }
4784 4758
4785 /** 4759 /**
4786 * Parse a list of identifiers. 4760 * Parse a list of identifiers.
4787 * 4761 *
4788 * <pre> 4762 * <pre>
4789 * identifierList ::= 4763 * identifierList ::=
4790 * identifier (',' identifier)* 4764 * identifier (',' identifier)*
4791 * </pre> 4765 * </pre>
4792 * 4766 *
4793 * @return the list of identifiers that were parsed 4767 * @return the list of identifiers that were parsed
4794 */ 4768 */
4795 List<SimpleIdentifier> parseIdentifierList() { 4769 List<SimpleIdentifier> parseIdentifierList() {
4796 List<SimpleIdentifier> identifiers = new List<SimpleIdentifier>(); 4770 List<SimpleIdentifier> identifiers = new List<SimpleIdentifier>();
4797 identifiers.add(parseSimpleIdentifier()); 4771 identifiers.add(parseSimpleIdentifier());
4798 while (matches5(TokenType.COMMA)) { 4772 while (matches(TokenType.COMMA)) {
4799 advance(); 4773 advance();
4800 identifiers.add(parseSimpleIdentifier()); 4774 identifiers.add(parseSimpleIdentifier());
4801 } 4775 }
4802 return identifiers; 4776 return identifiers;
4803 } 4777 }
4804 4778
4805 /** 4779 /**
4806 * Parse an if statement. 4780 * Parse an if statement.
4807 * 4781 *
4808 * <pre> 4782 * <pre>
4809 * ifStatement ::= 4783 * ifStatement ::=
4810 * 'if' '(' expression ')' statement ('else' statement)? 4784 * 'if' '(' expression ')' statement ('else' statement)?
4811 * </pre> 4785 * </pre>
4812 * 4786 *
4813 * @return the if statement that was parsed 4787 * @return the if statement that was parsed
4814 */ 4788 */
4815 Statement parseIfStatement() { 4789 Statement parseIfStatement() {
4816 Token ifKeyword = expect(Keyword.IF); 4790 Token ifKeyword = expectKeyword(Keyword.IF);
4817 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4791 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
4818 Expression condition = parseExpression2(); 4792 Expression condition = parseExpression2();
4819 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4793 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
4820 Statement thenStatement = parseStatement2(); 4794 Statement thenStatement = parseStatement2();
4821 Token elseKeyword = null; 4795 Token elseKeyword = null;
4822 Statement elseStatement = null; 4796 Statement elseStatement = null;
4823 if (matches(Keyword.ELSE)) { 4797 if (matchesKeyword(Keyword.ELSE)) {
4824 elseKeyword = andAdvance; 4798 elseKeyword = andAdvance;
4825 elseStatement = parseStatement2(); 4799 elseStatement = parseStatement2();
4826 } 4800 }
4827 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement); 4801 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement);
4828 } 4802 }
4829 4803
4830 /** 4804 /**
4831 * Parse an import directive. 4805 * Parse an import directive.
4832 * 4806 *
4833 * <pre> 4807 * <pre>
4834 * importDirective ::= 4808 * importDirective ::=
4835 * metadata 'import' stringLiteral ('as' identifier)? combinator*';' 4809 * metadata 'import' stringLiteral ('as' identifier)? combinator*';'
4836 * </pre> 4810 * </pre>
4837 * 4811 *
4838 * @param commentAndMetadata the metadata to be associated with the directive 4812 * @param commentAndMetadata the metadata to be associated with the directive
4839 * @return the import directive that was parsed 4813 * @return the import directive that was parsed
4840 */ 4814 */
4841 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) { 4815 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) {
4842 Token importKeyword = expect(Keyword.IMPORT); 4816 Token importKeyword = expectKeyword(Keyword.IMPORT);
4843 StringLiteral libraryUri = parseStringLiteral(); 4817 StringLiteral libraryUri = parseStringLiteral();
4844 Token asToken = null; 4818 Token asToken = null;
4845 SimpleIdentifier prefix = null; 4819 SimpleIdentifier prefix = null;
4846 if (matches(Keyword.AS)) { 4820 if (matchesKeyword(Keyword.AS)) {
4847 asToken = andAdvance; 4821 asToken = andAdvance;
4848 prefix = parseSimpleIdentifier(); 4822 prefix = parseSimpleIdentifier();
4849 } 4823 }
4850 List<Combinator> combinators = parseCombinators(); 4824 List<Combinator> combinators = parseCombinators();
4851 Token semicolon = expectSemicolon(); 4825 Token semicolon = expectSemicolon();
4852 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon); 4826 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon);
4853 } 4827 }
4854 4828
4855 /** 4829 /**
4856 * Parse a list of initialized identifiers. 4830 * Parse a list of initialized identifiers.
(...skipping 12 matching lines...) Expand all
4869 * 4843 *
4870 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4844 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4871 * declaration 4845 * declaration
4872 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 4846 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
4873 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 4847 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
4874 * there is no keyword 4848 * there is no keyword
4875 * @param type the type that has already been parsed, or `null` if 'var' was p rovided 4849 * @param type the type that has already been parsed, or `null` if 'var' was p rovided
4876 * @return the getter that was parsed 4850 * @return the getter that was parsed
4877 */ 4851 */
4878 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) { 4852 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) {
4879 VariableDeclarationList fieldList = parseVariableDeclarationList2(null, keyw ord, type); 4853 VariableDeclarationList fieldList = parseVariableDeclarationListAfterType(nu ll, keyword, type);
4880 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetadata.m etadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON)); 4854 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetadata.m etadata, staticKeyword, fieldList, expect(TokenType.SEMICOLON));
4881 } 4855 }
4882 4856
4883 /** 4857 /**
4884 * Parse an instance creation expression. 4858 * Parse an instance creation expression.
4885 * 4859 *
4886 * <pre> 4860 * <pre>
4887 * instanceCreationExpression ::= 4861 * instanceCreationExpression ::=
4888 * ('new' | 'const') type ('.' identifier)? argumentList 4862 * ('new' | 'const') type ('.' identifier)? argumentList
4889 * </pre> 4863 * </pre>
4890 * 4864 *
(...skipping 11 matching lines...) Expand all
4902 * 4876 *
4903 * <pre> 4877 * <pre>
4904 * libraryDirective ::= 4878 * libraryDirective ::=
4905 * metadata 'library' identifier ';' 4879 * metadata 'library' identifier ';'
4906 * </pre> 4880 * </pre>
4907 * 4881 *
4908 * @param commentAndMetadata the metadata to be associated with the directive 4882 * @param commentAndMetadata the metadata to be associated with the directive
4909 * @return the library directive that was parsed 4883 * @return the library directive that was parsed
4910 */ 4884 */
4911 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) { 4885 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) {
4912 Token keyword = expect(Keyword.LIBRARY); 4886 Token keyword = expectKeyword(Keyword.LIBRARY);
4913 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword); 4887 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword);
4914 Token semicolon = expect2(TokenType.SEMICOLON); 4888 Token semicolon = expect(TokenType.SEMICOLON);
4915 return new LibraryDirective(commentAndMetadata.comment, commentAndMetadata.m etadata, keyword, libraryName, semicolon); 4889 return new LibraryDirective(commentAndMetadata.comment, commentAndMetadata.m etadata, keyword, libraryName, semicolon);
4916 } 4890 }
4917 4891
4918 /** 4892 /**
4919 * Parse a library name. 4893 * Parse a library name.
4920 * 4894 *
4921 * <pre> 4895 * <pre>
4922 * libraryName ::= 4896 * libraryName ::=
4923 * libraryIdentifier 4897 * libraryIdentifier
4924 * </pre> 4898 * </pre>
4925 * 4899 *
4926 * @param missingNameError the error code to be used if the library name is mi ssing 4900 * @param missingNameError the error code to be used if the library name is mi ssing
4927 * @param missingNameToken the token associated with the error produced if the library name is 4901 * @param missingNameToken the token associated with the error produced if the library name is
4928 * missing 4902 * missing
4929 * @return the library name that was parsed 4903 * @return the library name that was parsed
4930 */ 4904 */
4931 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) { 4905 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) {
4932 if (matchesIdentifier()) { 4906 if (matchesIdentifier()) {
4933 return parseLibraryIdentifier(); 4907 return parseLibraryIdentifier();
4934 } else if (matches5(TokenType.STRING)) { 4908 } else if (matches(TokenType.STRING)) {
4935 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we 4909 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we
4936 // can find a token that can start a compilation unit member. 4910 // can find a token that can start a compilation unit member.
4937 StringLiteral string = parseStringLiteral(); 4911 StringLiteral string = parseStringLiteral();
4938 reportError12(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); 4912 reportErrorForNode(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, [] );
4939 } else { 4913 } else {
4940 reportError14(missingNameError, missingNameToken, []); 4914 reportErrorForToken(missingNameError, missingNameToken, []);
4941 } 4915 }
4942 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 4916 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
4943 components.add(createSyntheticIdentifier()); 4917 components.add(createSyntheticIdentifier());
4944 return new LibraryIdentifier(components); 4918 return new LibraryIdentifier(components);
4945 } 4919 }
4946 4920
4947 /** 4921 /**
4948 * Parse a list literal. 4922 * Parse a list literal.
4949 * 4923 *
4950 * <pre> 4924 * <pre>
4951 * listLiteral ::= 4925 * listLiteral ::=
4952 * 'const'? typeArguments? '[' (expressionList ','?)? ']' 4926 * 'const'? typeArguments? '[' (expressionList ','?)? ']'
4953 * </pre> 4927 * </pre>
4954 * 4928 *
4955 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4929 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
4956 * no modifier 4930 * no modifier
4957 * @param typeArguments the type arguments appearing before the literal, or `n ull` if there 4931 * @param typeArguments the type arguments appearing before the literal, or `n ull` if there
4958 * are no type arguments 4932 * are no type arguments
4959 * @return the list literal that was parsed 4933 * @return the list literal that was parsed
4960 */ 4934 */
4961 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { 4935 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) {
4962 // may be empty list literal 4936 // may be empty list literal
4963 if (matches5(TokenType.INDEX)) { 4937 if (matches(TokenType.INDEX)) {
4964 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset); 4938 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset);
4965 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1); 4939 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1);
4966 leftBracket.endToken = rightBracket; 4940 leftBracket.endToken = rightBracket;
4967 rightBracket.setNext(_currentToken.next); 4941 rightBracket.setNext(_currentToken.next);
4968 leftBracket.setNext(rightBracket); 4942 leftBracket.setNext(rightBracket);
4969 _currentToken.previous.setNext(leftBracket); 4943 _currentToken.previous.setNext(leftBracket);
4970 _currentToken = _currentToken.next; 4944 _currentToken = _currentToken.next;
4971 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket); 4945 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket);
4972 } 4946 }
4973 // open 4947 // open
4974 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET); 4948 Token leftBracket = expect(TokenType.OPEN_SQUARE_BRACKET);
4975 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4949 if (matches(TokenType.CLOSE_SQUARE_BRACKET)) {
4976 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce); 4950 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce);
4977 } 4951 }
4978 List<Expression> elements = new List<Expression>(); 4952 List<Expression> elements = new List<Expression>();
4979 elements.add(parseExpression2()); 4953 elements.add(parseExpression2());
4980 while (optional(TokenType.COMMA)) { 4954 while (optional(TokenType.COMMA)) {
4981 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4955 if (matches(TokenType.CLOSE_SQUARE_BRACKET)) {
4982 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance); 4956 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance);
4983 } 4957 }
4984 elements.add(parseExpression2()); 4958 elements.add(parseExpression2());
4985 } 4959 }
4986 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 4960 Token rightBracket = expect(TokenType.CLOSE_SQUARE_BRACKET);
4987 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket); 4961 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket);
4988 } 4962 }
4989 4963
4990 /** 4964 /**
4991 * Parse a list or map literal. 4965 * Parse a list or map literal.
4992 * 4966 *
4993 * <pre> 4967 * <pre>
4994 * listOrMapLiteral ::= 4968 * listOrMapLiteral ::=
4995 * listLiteral 4969 * listLiteral
4996 * | mapLiteral 4970 * | mapLiteral
4997 * </pre> 4971 * </pre>
4998 * 4972 *
4999 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4973 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
5000 * no modifier 4974 * no modifier
5001 * @return the list or map literal that was parsed 4975 * @return the list or map literal that was parsed
5002 */ 4976 */
5003 TypedLiteral parseListOrMapLiteral(Token modifier) { 4977 TypedLiteral parseListOrMapLiteral(Token modifier) {
5004 TypeArgumentList typeArguments = null; 4978 TypeArgumentList typeArguments = null;
5005 if (matches5(TokenType.LT)) { 4979 if (matches(TokenType.LT)) {
5006 typeArguments = parseTypeArgumentList(); 4980 typeArguments = parseTypeArgumentList();
5007 } 4981 }
5008 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4982 if (matches(TokenType.OPEN_CURLY_BRACKET)) {
5009 return parseMapLiteral(modifier, typeArguments); 4983 return parseMapLiteral(modifier, typeArguments);
5010 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 4984 } else if (matches(TokenType.OPEN_SQUARE_BRACKET) || matches(TokenType.INDEX )) {
5011 return parseListLiteral(modifier, typeArguments); 4985 return parseListLiteral(modifier, typeArguments);
5012 } 4986 }
5013 reportError13(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); 4987 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []) ;
5014 return new ListLiteral(modifier, typeArguments, createSyntheticToken2(TokenT ype.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUARE_BRA CKET)); 4988 return new ListLiteral(modifier, typeArguments, createSyntheticToken(TokenTy pe.OPEN_SQUARE_BRACKET), null, createSyntheticToken(TokenType.CLOSE_SQUARE_BRACK ET));
5015 } 4989 }
5016 4990
5017 /** 4991 /**
5018 * Parse a logical and expression. 4992 * Parse a logical and expression.
5019 * 4993 *
5020 * <pre> 4994 * <pre>
5021 * logicalAndExpression ::= 4995 * logicalAndExpression ::=
5022 * equalityExpression ('&&' equalityExpression)* 4996 * equalityExpression ('&&' equalityExpression)*
5023 * </pre> 4997 * </pre>
5024 * 4998 *
5025 * @return the logical and expression that was parsed 4999 * @return the logical and expression that was parsed
5026 */ 5000 */
5027 Expression parseLogicalAndExpression() { 5001 Expression parseLogicalAndExpression() {
5028 Expression expression = parseEqualityExpression(); 5002 Expression expression = parseEqualityExpression();
5029 while (matches5(TokenType.AMPERSAND_AMPERSAND)) { 5003 while (matches(TokenType.AMPERSAND_AMPERSAND)) {
5030 Token operator = andAdvance; 5004 Token operator = andAdvance;
5031 expression = new BinaryExpression(expression, operator, parseEqualityExpre ssion()); 5005 expression = new BinaryExpression(expression, operator, parseEqualityExpre ssion());
5032 } 5006 }
5033 return expression; 5007 return expression;
5034 } 5008 }
5035 5009
5036 /** 5010 /**
5037 * Parse a map literal. 5011 * Parse a map literal.
5038 * 5012 *
5039 * <pre> 5013 * <pre>
5040 * mapLiteral ::= 5014 * mapLiteral ::=
5041 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}' 5015 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}'
5042 * </pre> 5016 * </pre>
5043 * 5017 *
5044 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 5018 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
5045 * no modifier 5019 * no modifier
5046 * @param typeArguments the type arguments that were declared, or `null` if th ere are no 5020 * @param typeArguments the type arguments that were declared, or `null` if th ere are no
5047 * type arguments 5021 * type arguments
5048 * @return the map literal that was parsed 5022 * @return the map literal that was parsed
5049 */ 5023 */
5050 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { 5024 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
5051 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 5025 Token leftBracket = expect(TokenType.OPEN_CURLY_BRACKET);
5052 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); 5026 List<MapLiteralEntry> entries = new List<MapLiteralEntry>();
5053 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5027 if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
5054 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd vance); 5028 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd vance);
5055 } 5029 }
5056 entries.add(parseMapLiteralEntry()); 5030 entries.add(parseMapLiteralEntry());
5057 while (optional(TokenType.COMMA)) { 5031 while (optional(TokenType.COMMA)) {
5058 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5032 if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
5059 return new MapLiteral(modifier, typeArguments, leftBracket, entries, and Advance); 5033 return new MapLiteral(modifier, typeArguments, leftBracket, entries, and Advance);
5060 } 5034 }
5061 entries.add(parseMapLiteralEntry()); 5035 entries.add(parseMapLiteralEntry());
5062 } 5036 }
5063 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5037 Token rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
5064 return new MapLiteral(modifier, typeArguments, leftBracket, entries, rightBr acket); 5038 return new MapLiteral(modifier, typeArguments, leftBracket, entries, rightBr acket);
5065 } 5039 }
5066 5040
5067 /** 5041 /**
5068 * Parse a method declaration. 5042 * Parse a method declaration.
5069 * 5043 *
5070 * <pre> 5044 * <pre>
5071 * functionDeclaration ::= 5045 * functionDeclaration ::=
5072 * 'external'? 'static'? functionSignature functionBody 5046 * ('external' 'static'?)? functionSignature functionBody
5073 * | 'external'? functionSignature ';' 5047 * | 'external'? functionSignature ';'
5074 * </pre> 5048 * </pre>
5075 * 5049 *
5076 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5050 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5077 * declaration 5051 * declaration
5078 * @param externalKeyword the 'external' token 5052 * @param externalKeyword the 'external' token
5079 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 5053 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
5080 * @param returnType the return type of the method 5054 * @param returnType the return type of the method
5055 * @param name the name of the method
5056 * @param parameters the parameters to the method
5081 * @return the method declaration that was parsed 5057 * @return the method declaration that was parsed
5082 */ 5058 */
5083 MethodDeclaration parseMethodDeclaration(CommentAndMetadata commentAndMetadata , Token externalKeyword, Token staticKeyword, TypeName returnType) { 5059 MethodDeclaration parseMethodDeclarationAfterParameters(CommentAndMetadata com mentAndMetadata, Token externalKeyword, Token staticKeyword, TypeName returnType , SimpleIdentifier name, FormalParameterList parameters) {
5084 SimpleIdentifier methodName = parseSimpleIdentifier(); 5060 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false);
5085 FormalParameterList parameters = parseFormalParameterList(); 5061 if (externalKeyword != null) {
5086 validateFormalParameterList(parameters); 5062 if (body is! EmptyFunctionBody) {
5087 return parseMethodDeclaration2(commentAndMetadata, externalKeyword, staticKe yword, returnType, methodName, parameters); 5063 reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []);
5064 }
5065 } else if (staticKeyword != null) {
5066 if (body is EmptyFunctionBody) {
5067 reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
5068 }
5069 }
5070 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body);
5088 } 5071 }
5089 5072
5090 /** 5073 /**
5091 * Parse a method declaration. 5074 * Parse a method declaration.
5092 * 5075 *
5093 * <pre> 5076 * <pre>
5094 * functionDeclaration ::= 5077 * functionDeclaration ::=
5095 * ('external' 'static'?)? functionSignature functionBody 5078 * 'external'? 'static'? functionSignature functionBody
5096 * | 'external'? functionSignature ';' 5079 * | 'external'? functionSignature ';'
5097 * </pre> 5080 * </pre>
5098 * 5081 *
5099 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5082 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5100 * declaration 5083 * declaration
5101 * @param externalKeyword the 'external' token 5084 * @param externalKeyword the 'external' token
5102 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 5085 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
5103 * @param returnType the return type of the method 5086 * @param returnType the return type of the method
5104 * @param name the name of the method
5105 * @param parameters the parameters to the method
5106 * @return the method declaration that was parsed 5087 * @return the method declaration that was parsed
5107 */ 5088 */
5108 MethodDeclaration parseMethodDeclaration2(CommentAndMetadata commentAndMetadat a, Token externalKeyword, Token staticKeyword, TypeName returnType, SimpleIdenti fier name, FormalParameterList parameters) { 5089 MethodDeclaration parseMethodDeclarationAfterReturnType(CommentAndMetadata com mentAndMetadata, Token externalKeyword, Token staticKeyword, TypeName returnType ) {
5109 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false); 5090 SimpleIdentifier methodName = parseSimpleIdentifier();
5110 if (externalKeyword != null) { 5091 FormalParameterList parameters = parseFormalParameterList();
5111 if (body is! EmptyFunctionBody) { 5092 validateFormalParameterList(parameters);
5112 reportError12(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); 5093 return parseMethodDeclarationAfterParameters(commentAndMetadata, externalKey word, staticKeyword, returnType, methodName, parameters);
5113 }
5114 } else if (staticKeyword != null) {
5115 if (body is EmptyFunctionBody) {
5116 reportError12(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
5117 }
5118 }
5119 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body);
5120 } 5094 }
5121 5095
5122 /** 5096 /**
5123 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any 5097 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any
5124 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as 5098 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as
5125 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are 5099 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are
5126 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`. 5100 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`.
5127 * 5101 *
5128 * <pre> 5102 * <pre>
5129 * modifiers ::= 5103 * modifiers ::=
5130 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')* 5104 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')*
5131 * </pre> 5105 * </pre>
5132 * 5106 *
5133 * @return the modifiers that were parsed 5107 * @return the modifiers that were parsed
5134 */ 5108 */
5135 Modifiers parseModifiers() { 5109 Modifiers parseModifiers() {
5136 Modifiers modifiers = new Modifiers(); 5110 Modifiers modifiers = new Modifiers();
5137 bool progress = true; 5111 bool progress = true;
5138 while (progress) { 5112 while (progress) {
5139 if (matches4(peek(), TokenType.PERIOD) || matches4(peek(), TokenType.LT) | | matches4(peek(), TokenType.OPEN_PAREN)) { 5113 if (tokenMatches(peek(), TokenType.PERIOD) || tokenMatches(peek(), TokenTy pe.LT) || tokenMatches(peek(), TokenType.OPEN_PAREN)) {
5140 return modifiers; 5114 return modifiers;
5141 } 5115 }
5142 if (matches(Keyword.ABSTRACT)) { 5116 if (matchesKeyword(Keyword.ABSTRACT)) {
5143 if (modifiers.abstractKeyword != null) { 5117 if (modifiers.abstractKeyword != null) {
5144 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5118 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5145 advance(); 5119 advance();
5146 } else { 5120 } else {
5147 modifiers.abstractKeyword = andAdvance; 5121 modifiers.abstractKeyword = andAdvance;
5148 } 5122 }
5149 } else if (matches(Keyword.CONST)) { 5123 } else if (matchesKeyword(Keyword.CONST)) {
5150 if (modifiers.constKeyword != null) { 5124 if (modifiers.constKeyword != null) {
5151 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5125 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5152 advance(); 5126 advance();
5153 } else { 5127 } else {
5154 modifiers.constKeyword = andAdvance; 5128 modifiers.constKeyword = andAdvance;
5155 } 5129 }
5156 } else if (matches(Keyword.EXTERNAL) && !matches4(peek(), TokenType.PERIOD ) && !matches4(peek(), TokenType.LT)) { 5130 } else if (matchesKeyword(Keyword.EXTERNAL) && !tokenMatches(peek(), Token Type.PERIOD) && !tokenMatches(peek(), TokenType.LT)) {
5157 if (modifiers.externalKeyword != null) { 5131 if (modifiers.externalKeyword != null) {
5158 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5132 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5159 advance(); 5133 advance();
5160 } else { 5134 } else {
5161 modifiers.externalKeyword = andAdvance; 5135 modifiers.externalKeyword = andAdvance;
5162 } 5136 }
5163 } else if (matches(Keyword.FACTORY) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) { 5137 } else if (matchesKeyword(Keyword.FACTORY) && !tokenMatches(peek(), TokenT ype.PERIOD) && !tokenMatches(peek(), TokenType.LT)) {
5164 if (modifiers.factoryKeyword != null) { 5138 if (modifiers.factoryKeyword != null) {
5165 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5139 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5166 advance(); 5140 advance();
5167 } else { 5141 } else {
5168 modifiers.factoryKeyword = andAdvance; 5142 modifiers.factoryKeyword = andAdvance;
5169 } 5143 }
5170 } else if (matches(Keyword.FINAL)) { 5144 } else if (matchesKeyword(Keyword.FINAL)) {
5171 if (modifiers.finalKeyword != null) { 5145 if (modifiers.finalKeyword != null) {
5172 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5146 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5173 advance(); 5147 advance();
5174 } else { 5148 } else {
5175 modifiers.finalKeyword = andAdvance; 5149 modifiers.finalKeyword = andAdvance;
5176 } 5150 }
5177 } else if (matches(Keyword.STATIC) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) { 5151 } else if (matchesKeyword(Keyword.STATIC) && !tokenMatches(peek(), TokenTy pe.PERIOD) && !tokenMatches(peek(), TokenType.LT)) {
5178 if (modifiers.staticKeyword != null) { 5152 if (modifiers.staticKeyword != null) {
5179 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5153 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5180 advance(); 5154 advance();
5181 } else { 5155 } else {
5182 modifiers.staticKeyword = andAdvance; 5156 modifiers.staticKeyword = andAdvance;
5183 } 5157 }
5184 } else if (matches(Keyword.VAR)) { 5158 } else if (matchesKeyword(Keyword.VAR)) {
5185 if (modifiers.varKeyword != null) { 5159 if (modifiers.varKeyword != null) {
5186 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5160 reportErrorForCurrentToken(ParserErrorCode.DUPLICATED_MODIFIER, [_curr entToken.lexeme]);
5187 advance(); 5161 advance();
5188 } else { 5162 } else {
5189 modifiers.varKeyword = andAdvance; 5163 modifiers.varKeyword = andAdvance;
5190 } 5164 }
5191 } else { 5165 } else {
5192 progress = false; 5166 progress = false;
5193 } 5167 }
5194 } 5168 }
5195 return modifiers; 5169 return modifiers;
5196 } 5170 }
5197 5171
5198 /** 5172 /**
5199 * Parse a multiplicative expression. 5173 * Parse a multiplicative expression.
5200 * 5174 *
5201 * <pre> 5175 * <pre>
5202 * multiplicativeExpression ::= 5176 * multiplicativeExpression ::=
5203 * unaryExpression (multiplicativeOperator unaryExpression)* 5177 * unaryExpression (multiplicativeOperator unaryExpression)*
5204 * | 'super' (multiplicativeOperator unaryExpression)+ 5178 * | 'super' (multiplicativeOperator unaryExpression)+
5205 * </pre> 5179 * </pre>
5206 * 5180 *
5207 * @return the multiplicative expression that was parsed 5181 * @return the multiplicative expression that was parsed
5208 */ 5182 */
5209 Expression parseMultiplicativeExpression() { 5183 Expression parseMultiplicativeExpression() {
5210 Expression expression; 5184 Expression expression;
5211 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat or) { 5185 if (matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isMultiplicativ eOperator) {
5212 expression = new SuperExpression(andAdvance); 5186 expression = new SuperExpression(andAdvance);
5213 } else { 5187 } else {
5214 expression = parseUnaryExpression(); 5188 expression = parseUnaryExpression();
5215 } 5189 }
5216 while (_currentToken.type.isMultiplicativeOperator) { 5190 while (_currentToken.type.isMultiplicativeOperator) {
5217 Token operator = andAdvance; 5191 Token operator = andAdvance;
5218 expression = new BinaryExpression(expression, operator, parseUnaryExpressi on()); 5192 expression = new BinaryExpression(expression, operator, parseUnaryExpressi on());
5219 } 5193 }
5220 return expression; 5194 return expression;
5221 } 5195 }
(...skipping 17 matching lines...) Expand all
5239 /** 5213 /**
5240 * Parse a new expression. 5214 * Parse a new expression.
5241 * 5215 *
5242 * <pre> 5216 * <pre>
5243 * newExpression ::= 5217 * newExpression ::=
5244 * instanceCreationExpression 5218 * instanceCreationExpression
5245 * </pre> 5219 * </pre>
5246 * 5220 *
5247 * @return the new expression that was parsed 5221 * @return the new expression that was parsed
5248 */ 5222 */
5249 InstanceCreationExpression parseNewExpression() => parseInstanceCreationExpres sion(expect(Keyword.NEW)); 5223 InstanceCreationExpression parseNewExpression() => parseInstanceCreationExpres sion(expectKeyword(Keyword.NEW));
5250 5224
5251 /** 5225 /**
5252 * Parse a non-labeled statement. 5226 * Parse a non-labeled statement.
5253 * 5227 *
5254 * <pre> 5228 * <pre>
5255 * nonLabeledStatement ::= 5229 * nonLabeledStatement ::=
5256 * block 5230 * block
5257 * | assertStatement 5231 * | assertStatement
5258 * | breakStatement 5232 * | breakStatement
5259 * | continueStatement 5233 * | continueStatement
5260 * | doStatement 5234 * | doStatement
5261 * | forStatement 5235 * | forStatement
5262 * | ifStatement 5236 * | ifStatement
5263 * | returnStatement 5237 * | returnStatement
5264 * | switchStatement 5238 * | switchStatement
5265 * | tryStatement 5239 * | tryStatement
5266 * | whileStatement 5240 * | whileStatement
5267 * | variableDeclarationList ';' 5241 * | variableDeclarationList ';'
5268 * | expressionStatement 5242 * | expressionStatement
5269 * | functionSignature functionBody 5243 * | functionSignature functionBody
5270 * </pre> 5244 * </pre>
5271 * 5245 *
5272 * @return the non-labeled statement that was parsed 5246 * @return the non-labeled statement that was parsed
5273 */ 5247 */
5274 Statement parseNonLabeledStatement() { 5248 Statement parseNonLabeledStatement() {
5275 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate. 5249 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate.
5276 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 5250 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
5277 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5251 if (matches(TokenType.OPEN_CURLY_BRACKET)) {
5278 if (matches4(peek(), TokenType.STRING)) { 5252 if (tokenMatches(peek(), TokenType.STRING)) {
5279 Token afterString = skipStringLiteral(_currentToken.next); 5253 Token afterString = skipStringLiteral(_currentToken.next);
5280 if (afterString != null && identical(afterString.type, TokenType.COLON)) { 5254 if (afterString != null && identical(afterString.type, TokenType.COLON)) {
5281 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON)); 5255 return new ExpressionStatement(parseExpression2(), expect(TokenType.SE MICOLON));
5282 } 5256 }
5283 } 5257 }
5284 return parseBlock(); 5258 return parseBlock();
5285 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) { 5259 } else if (matches(TokenType.KEYWORD) && !(_currentToken as KeywordToken).ke yword.isPseudoKeyword) {
5286 Keyword keyword = (_currentToken as KeywordToken).keyword; 5260 Keyword keyword = (_currentToken as KeywordToken).keyword;
5287 // TODO(jwren) compute some metrics to figure out a better order for this if-then sequence to optimize performance 5261 // TODO(jwren) compute some metrics to figure out a better order for this if-then sequence to optimize performance
5288 if (identical(keyword, Keyword.ASSERT)) { 5262 if (identical(keyword, Keyword.ASSERT)) {
5289 return parseAssertStatement(); 5263 return parseAssertStatement();
5290 } else if (identical(keyword, Keyword.BREAK)) { 5264 } else if (identical(keyword, Keyword.BREAK)) {
5291 return parseBreakStatement(); 5265 return parseBreakStatement();
5292 } else if (identical(keyword, Keyword.CONTINUE)) { 5266 } else if (identical(keyword, Keyword.CONTINUE)) {
5293 return parseContinueStatement(); 5267 return parseContinueStatement();
5294 } else if (identical(keyword, Keyword.DO)) { 5268 } else if (identical(keyword, Keyword.DO)) {
5295 return parseDoStatement(); 5269 return parseDoStatement();
5296 } else if (identical(keyword, Keyword.FOR)) { 5270 } else if (identical(keyword, Keyword.FOR)) {
5297 return parseForStatement(); 5271 return parseForStatement();
5298 } else if (identical(keyword, Keyword.IF)) { 5272 } else if (identical(keyword, Keyword.IF)) {
5299 return parseIfStatement(); 5273 return parseIfStatement();
5300 } else if (identical(keyword, Keyword.RETHROW)) { 5274 } else if (identical(keyword, Keyword.RETHROW)) {
5301 return new ExpressionStatement(parseRethrowExpression(), expect2(TokenTy pe.SEMICOLON)); 5275 return new ExpressionStatement(parseRethrowExpression(), expect(TokenTyp e.SEMICOLON));
5302 } else if (identical(keyword, Keyword.RETURN)) { 5276 } else if (identical(keyword, Keyword.RETURN)) {
5303 return parseReturnStatement(); 5277 return parseReturnStatement();
5304 } else if (identical(keyword, Keyword.SWITCH)) { 5278 } else if (identical(keyword, Keyword.SWITCH)) {
5305 return parseSwitchStatement(); 5279 return parseSwitchStatement();
5306 } else if (identical(keyword, Keyword.THROW)) { 5280 } else if (identical(keyword, Keyword.THROW)) {
5307 return new ExpressionStatement(parseThrowExpression(), expect2(TokenType .SEMICOLON)); 5281 return new ExpressionStatement(parseThrowExpression(), expect(TokenType. SEMICOLON));
5308 } else if (identical(keyword, Keyword.TRY)) { 5282 } else if (identical(keyword, Keyword.TRY)) {
5309 return parseTryStatement(); 5283 return parseTryStatement();
5310 } else if (identical(keyword, Keyword.WHILE)) { 5284 } else if (identical(keyword, Keyword.WHILE)) {
5311 return parseWhileStatement(); 5285 return parseWhileStatement();
5312 } else if (identical(keyword, Keyword.VAR) || identical(keyword, Keyword.F INAL)) { 5286 } else if (identical(keyword, Keyword.VAR) || identical(keyword, Keyword.F INAL)) {
5313 return parseVariableDeclarationStatement(commentAndMetadata); 5287 return parseVariableDeclarationStatementAfterMetadata(commentAndMetadata );
5314 } else if (identical(keyword, Keyword.VOID)) { 5288 } else if (identical(keyword, Keyword.VOID)) {
5315 TypeName returnType = parseReturnType(); 5289 TypeName returnType = parseReturnType();
5316 if (matchesIdentifier() && matchesAny(peek(), [ 5290 if (matchesIdentifier() && matchesAny(peek(), [
5317 TokenType.OPEN_PAREN, 5291 TokenType.OPEN_PAREN,
5318 TokenType.OPEN_CURLY_BRACKET, 5292 TokenType.OPEN_CURLY_BRACKET,
5319 TokenType.FUNCTION])) { 5293 TokenType.FUNCTION])) {
5320 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe); 5294 return parseFunctionDeclarationStatementAfterReturnType(commentAndMeta data, returnType);
5321 } else { 5295 } else {
5322 // 5296 //
5323 // We have found an error of some kind. Try to recover. 5297 // We have found an error of some kind. Try to recover.
5324 // 5298 //
5325 if (matchesIdentifier()) { 5299 if (matchesIdentifier()) {
5326 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 5300 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
5327 // 5301 //
5328 // We appear to have a variable declaration with a type of "void". 5302 // We appear to have a variable declaration with a type of "void".
5329 // 5303 //
5330 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []); 5304 reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []);
5331 return parseVariableDeclarationStatement(commentAndMetadata); 5305 return parseVariableDeclarationStatementAfterMetadata(commentAndMe tadata);
5332 } 5306 }
5333 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5307 } else if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
5334 // 5308 //
5335 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a 5309 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a
5336 // variable declaration. 5310 // variable declaration.
5337 // 5311 //
5338 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType); 5312 return parseVariableDeclarationStatementAfterType(commentAndMetadata , null, returnType);
5339 } 5313 }
5340 reportError13(ParserErrorCode.MISSING_STATEMENT, []); 5314 reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []);
5341 // TODO(brianwilkerson) Recover from this error. 5315 // TODO(brianwilkerson) Recover from this error.
5342 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5316 return new EmptyStatement(createSyntheticToken(TokenType.SEMICOLON));
5343 } 5317 }
5344 } else if (identical(keyword, Keyword.CONST)) { 5318 } else if (identical(keyword, Keyword.CONST)) {
5345 if (matchesAny(peek(), [ 5319 if (matchesAny(peek(), [
5346 TokenType.LT, 5320 TokenType.LT,
5347 TokenType.OPEN_CURLY_BRACKET, 5321 TokenType.OPEN_CURLY_BRACKET,
5348 TokenType.OPEN_SQUARE_BRACKET, 5322 TokenType.OPEN_SQUARE_BRACKET,
5349 TokenType.INDEX])) { 5323 TokenType.INDEX])) {
5350 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON)); 5324 return new ExpressionStatement(parseExpression2(), expect(TokenType.SE MICOLON));
5351 } else if (matches4(peek(), TokenType.IDENTIFIER)) { 5325 } else if (tokenMatches(peek(), TokenType.IDENTIFIER)) {
5352 Token afterType = skipTypeName(peek()); 5326 Token afterType = skipTypeName(peek());
5353 if (afterType != null) { 5327 if (afterType != null) {
5354 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) { 5328 if (tokenMatches(afterType, TokenType.OPEN_PAREN) || (tokenMatches(a fterType, TokenType.PERIOD) && tokenMatches(afterType.next, TokenType.IDENTIFIER ) && tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) {
5355 return new ExpressionStatement(parseExpression2(), expect2(TokenTy pe.SEMICOLON)); 5329 return new ExpressionStatement(parseExpression2(), expect(TokenTyp e.SEMICOLON));
5356 } 5330 }
5357 } 5331 }
5358 } 5332 }
5359 return parseVariableDeclarationStatement(commentAndMetadata); 5333 return parseVariableDeclarationStatementAfterMetadata(commentAndMetadata );
5360 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) { 5334 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) {
5361 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEM ICOLON)); 5335 return new ExpressionStatement(parseExpression2(), expect(TokenType.SEMI COLON));
5362 } else { 5336 } else {
5363 // 5337 //
5364 // We have found an error of some kind. Try to recover. 5338 // We have found an error of some kind. Try to recover.
5365 // 5339 //
5366 reportError13(ParserErrorCode.MISSING_STATEMENT, []); 5340 reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []);
5367 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5341 return new EmptyStatement(createSyntheticToken(TokenType.SEMICOLON));
5368 } 5342 }
5369 } else if (matches5(TokenType.SEMICOLON)) { 5343 } else if (matches(TokenType.SEMICOLON)) {
5370 return parseEmptyStatement(); 5344 return parseEmptyStatement();
5371 } else if (isInitializedVariableDeclaration()) { 5345 } else if (isInitializedVariableDeclaration()) {
5372 return parseVariableDeclarationStatement(commentAndMetadata); 5346 return parseVariableDeclarationStatementAfterMetadata(commentAndMetadata);
5373 } else if (isFunctionDeclaration()) { 5347 } else if (isFunctionDeclaration()) {
5374 return parseFunctionDeclarationStatement(); 5348 return parseFunctionDeclarationStatement();
5375 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5349 } else if (matches(TokenType.CLOSE_CURLY_BRACKET)) {
5376 reportError13(ParserErrorCode.MISSING_STATEMENT, []); 5350 reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []);
5377 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5351 return new EmptyStatement(createSyntheticToken(TokenType.SEMICOLON));
5378 } else { 5352 } else {
5379 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEMIC OLON)); 5353 return new ExpressionStatement(parseExpression2(), expect(TokenType.SEMICO LON));
5380 } 5354 }
5381 } 5355 }
5382 5356
5383 /** 5357 /**
5384 * Parse an operator declaration. 5358 * Parse an operator declaration.
5385 * 5359 *
5386 * <pre> 5360 * <pre>
5387 * operatorDeclaration ::= 5361 * operatorDeclaration ::=
5388 * operatorSignature (';' | functionBody) 5362 * operatorSignature (';' | functionBody)
5389 * 5363 *
5390 * operatorSignature ::= 5364 * operatorSignature ::=
5391 * 'external'? returnType? 'operator' operator formalParameterList 5365 * 'external'? returnType? 'operator' operator formalParameterList
5392 * </pre> 5366 * </pre>
5393 * 5367 *
5394 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5368 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5395 * declaration 5369 * declaration
5396 * @param externalKeyword the 'external' token 5370 * @param externalKeyword the 'external' token
5397 * @param the return type that has already been parsed, or `null` if there was no return 5371 * @param the return type that has already been parsed, or `null` if there was no return
5398 * type 5372 * type
5399 * @return the operator declaration that was parsed 5373 * @return the operator declaration that was parsed
5400 */ 5374 */
5401 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) { 5375 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) {
5402 Token operatorKeyword; 5376 Token operatorKeyword;
5403 if (matches(Keyword.OPERATOR)) { 5377 if (matchesKeyword(Keyword.OPERATOR)) {
5404 operatorKeyword = andAdvance; 5378 operatorKeyword = andAdvance;
5405 } else { 5379 } else {
5406 reportError14(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ; 5380 reportErrorForToken(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToke n, []);
5407 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); 5381 operatorKeyword = createSyntheticKeyword(Keyword.OPERATOR);
5408 } 5382 }
5409 if (!_currentToken.isUserDefinableOperator) { 5383 if (!_currentToken.isUserDefinableOperator) {
5410 reportError13(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]); 5384 reportErrorForCurrentToken(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_ currentToken.lexeme]);
5411 } 5385 }
5412 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 5386 SimpleIdentifier name = new SimpleIdentifier(andAdvance);
5413 if (matches5(TokenType.EQ)) { 5387 if (matches(TokenType.EQ)) {
5414 Token previous = _currentToken.previous; 5388 Token previous = _currentToken.previous;
5415 if ((matches4(previous, TokenType.EQ_EQ) || matches4(previous, TokenType.B ANG_EQ)) && _currentToken.offset == previous.offset + 2) { 5389 if ((tokenMatches(previous, TokenType.EQ_EQ) || tokenMatches(previous, Tok enType.BANG_EQ)) && _currentToken.offset == previous.offset + 2) {
5416 reportError13(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]); 5390 reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, ["${previou s.lexeme}${_currentToken.lexeme}"]);
5417 advance(); 5391 advance();
5418 } 5392 }
5419 } 5393 }
5420 FormalParameterList parameters = parseFormalParameterList(); 5394 FormalParameterList parameters = parseFormalParameterList();
5421 validateFormalParameterList(parameters); 5395 validateFormalParameterList(parameters);
5422 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false); 5396 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false);
5423 if (externalKeyword != null && body is! EmptyFunctionBody) { 5397 if (externalKeyword != null && body is! EmptyFunctionBody) {
5424 reportError13(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); 5398 reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, [] );
5425 } 5399 }
5426 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body); 5400 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body);
5427 } 5401 }
5428 5402
5429 /** 5403 /**
5430 * Parse a return type if one is given, otherwise return `null` without advanc ing. 5404 * Parse a return type if one is given, otherwise return `null` without advanc ing.
5431 * 5405 *
5432 * @return the return type that was parsed 5406 * @return the return type that was parsed
5433 */ 5407 */
5434 TypeName parseOptionalReturnType() { 5408 TypeName parseOptionalReturnType() {
5435 if (matches(Keyword.VOID)) { 5409 if (matchesKeyword(Keyword.VOID)) {
5436 return parseReturnType(); 5410 return parseReturnType();
5437 } else if (matchesIdentifier() && !matches(Keyword.GET) && !matches(Keyword. SET) && !matches(Keyword.OPERATOR) && (matchesIdentifier2(peek()) || matches4(pe ek(), TokenType.LT))) { 5411 } else if (matchesIdentifier() && !matchesKeyword(Keyword.GET) && !matchesKe yword(Keyword.SET) && !matchesKeyword(Keyword.OPERATOR) && (tokenMatchesIdentifi er(peek()) || tokenMatches(peek(), TokenType.LT))) {
5438 return parseReturnType(); 5412 return parseReturnType();
5439 } else if (matchesIdentifier() && matches4(peek(), TokenType.PERIOD) && matc hesIdentifier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType.LT))) { 5413 } else if (matchesIdentifier() && tokenMatches(peek(), TokenType.PERIOD) && tokenMatchesIdentifier(peek2(2)) && (tokenMatchesIdentifier(peek2(3)) || tokenMa tches(peek2(3), TokenType.LT))) {
5440 return parseReturnType(); 5414 return parseReturnType();
5441 } 5415 }
5442 return null; 5416 return null;
5443 } 5417 }
5444 5418
5445 /** 5419 /**
5446 * Parse a part or part-of directive. 5420 * Parse a part or part-of directive.
5447 * 5421 *
5448 * <pre> 5422 * <pre>
5449 * partDirective ::= 5423 * partDirective ::=
5450 * metadata 'part' stringLiteral ';' 5424 * metadata 'part' stringLiteral ';'
5451 * 5425 *
5452 * partOfDirective ::= 5426 * partOfDirective ::=
5453 * metadata 'part' 'of' identifier ';' 5427 * metadata 'part' 'of' identifier ';'
5454 * </pre> 5428 * </pre>
5455 * 5429 *
5456 * @param commentAndMetadata the metadata to be associated with the directive 5430 * @param commentAndMetadata the metadata to be associated with the directive
5457 * @return the part or part-of directive that was parsed 5431 * @return the part or part-of directive that was parsed
5458 */ 5432 */
5459 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) { 5433 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) {
5460 Token partKeyword = expect(Keyword.PART); 5434 Token partKeyword = expectKeyword(Keyword.PART);
5461 if (matches2(_OF)) { 5435 if (matchesString(_OF)) {
5462 Token ofKeyword = andAdvance; 5436 Token ofKeyword = andAdvance;
5463 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword); 5437 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword);
5464 Token semicolon = expect2(TokenType.SEMICOLON); 5438 Token semicolon = expect(TokenType.SEMICOLON);
5465 return new PartOfDirective(commentAndMetadata.comment, commentAndMetadata. metadata, partKeyword, ofKeyword, libraryName, semicolon); 5439 return new PartOfDirective(commentAndMetadata.comment, commentAndMetadata. metadata, partKeyword, ofKeyword, libraryName, semicolon);
5466 } 5440 }
5467 StringLiteral partUri = parseStringLiteral(); 5441 StringLiteral partUri = parseStringLiteral();
5468 Token semicolon = expect2(TokenType.SEMICOLON); 5442 Token semicolon = expect(TokenType.SEMICOLON);
5469 return new PartDirective(commentAndMetadata.comment, commentAndMetadata.meta data, partKeyword, partUri, semicolon); 5443 return new PartDirective(commentAndMetadata.comment, commentAndMetadata.meta data, partKeyword, partUri, semicolon);
5470 } 5444 }
5471 5445
5472 /** 5446 /**
5473 * Parse a postfix expression. 5447 * Parse a postfix expression.
5474 * 5448 *
5475 * <pre> 5449 * <pre>
5476 * postfixExpression ::= 5450 * postfixExpression ::=
5477 * assignableExpression postfixOperator 5451 * assignableExpression postfixOperator
5478 * | primary selector* 5452 * | primary selector*
5479 * 5453 *
5480 * selector ::= 5454 * selector ::=
5481 * assignableSelector 5455 * assignableSelector
5482 * | argumentList 5456 * | argumentList
5483 * </pre> 5457 * </pre>
5484 * 5458 *
5485 * @return the postfix expression that was parsed 5459 * @return the postfix expression that was parsed
5486 */ 5460 */
5487 Expression parsePostfixExpression() { 5461 Expression parsePostfixExpression() {
5488 Expression operand = parseAssignableExpression(true); 5462 Expression operand = parseAssignableExpression(true);
5489 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PERIOD) || matches5(TokenType.OPEN_PAREN)) { 5463 if (matches(TokenType.OPEN_SQUARE_BRACKET) || matches(TokenType.PERIOD) || m atches(TokenType.OPEN_PAREN)) {
5490 do { 5464 do {
5491 if (matches5(TokenType.OPEN_PAREN)) { 5465 if (matches(TokenType.OPEN_PAREN)) {
5492 ArgumentList argumentList = parseArgumentList(); 5466 ArgumentList argumentList = parseArgumentList();
5493 if (operand is PropertyAccess) { 5467 if (operand is PropertyAccess) {
5494 PropertyAccess access = operand as PropertyAccess; 5468 PropertyAccess access = operand as PropertyAccess;
5495 operand = new MethodInvocation(access.target, access.operator, acces s.propertyName, argumentList); 5469 operand = new MethodInvocation(access.target, access.operator, acces s.propertyName, argumentList);
5496 } else { 5470 } else {
5497 operand = new FunctionExpressionInvocation(operand, argumentList); 5471 operand = new FunctionExpressionInvocation(operand, argumentList);
5498 } 5472 }
5499 } else { 5473 } else {
5500 operand = parseAssignableSelector(operand, true); 5474 operand = parseAssignableSelector(operand, true);
5501 } 5475 }
5502 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN)); 5476 } while (matches(TokenType.OPEN_SQUARE_BRACKET) || matches(TokenType.PERIO D) || matches(TokenType.OPEN_PAREN));
5503 return operand; 5477 return operand;
5504 } 5478 }
5505 if (!_currentToken.type.isIncrementOperator) { 5479 if (!_currentToken.type.isIncrementOperator) {
5506 return operand; 5480 return operand;
5507 } 5481 }
5508 ensureAssignable(operand); 5482 ensureAssignable(operand);
5509 Token operator = andAdvance; 5483 Token operator = andAdvance;
5510 return new PostfixExpression(operand, operator); 5484 return new PostfixExpression(operand, operator);
5511 } 5485 }
5512 5486
(...skipping 18 matching lines...) Expand all
5531 * | numericLiteral 5505 * | numericLiteral
5532 * | stringLiteral 5506 * | stringLiteral
5533 * | symbolLiteral 5507 * | symbolLiteral
5534 * | mapLiteral 5508 * | mapLiteral
5535 * | listLiteral 5509 * | listLiteral
5536 * </pre> 5510 * </pre>
5537 * 5511 *
5538 * @return the primary expression that was parsed 5512 * @return the primary expression that was parsed
5539 */ 5513 */
5540 Expression parsePrimaryExpression() { 5514 Expression parsePrimaryExpression() {
5541 if (matches(Keyword.THIS)) { 5515 if (matchesKeyword(Keyword.THIS)) {
5542 return new ThisExpression(andAdvance); 5516 return new ThisExpression(andAdvance);
5543 } else if (matches(Keyword.SUPER)) { 5517 } else if (matchesKeyword(Keyword.SUPER)) {
5544 return parseAssignableSelector(new SuperExpression(andAdvance), false); 5518 return parseAssignableSelector(new SuperExpression(andAdvance), false);
5545 } else if (matches(Keyword.NULL)) { 5519 } else if (matchesKeyword(Keyword.NULL)) {
5546 return new NullLiteral(andAdvance); 5520 return new NullLiteral(andAdvance);
5547 } else if (matches(Keyword.FALSE)) { 5521 } else if (matchesKeyword(Keyword.FALSE)) {
5548 return new BooleanLiteral(andAdvance, false); 5522 return new BooleanLiteral(andAdvance, false);
5549 } else if (matches(Keyword.TRUE)) { 5523 } else if (matchesKeyword(Keyword.TRUE)) {
5550 return new BooleanLiteral(andAdvance, true); 5524 return new BooleanLiteral(andAdvance, true);
5551 } else if (matches5(TokenType.DOUBLE)) { 5525 } else if (matches(TokenType.DOUBLE)) {
5552 Token token = andAdvance; 5526 Token token = andAdvance;
5553 double value = 0.0; 5527 double value = 0.0;
5554 try { 5528 try {
5555 value = double.parse(token.lexeme); 5529 value = double.parse(token.lexeme);
5556 } on FormatException catch (exception) { 5530 } on FormatException catch (exception) {
5557 } 5531 }
5558 return new DoubleLiteral(token, value); 5532 return new DoubleLiteral(token, value);
5559 } else if (matches5(TokenType.HEXADECIMAL)) { 5533 } else if (matches(TokenType.HEXADECIMAL)) {
5560 Token token = andAdvance; 5534 Token token = andAdvance;
5561 int value = null; 5535 int value = null;
5562 try { 5536 try {
5563 value = int.parse(token.lexeme.substring(2), radix: 16); 5537 value = int.parse(token.lexeme.substring(2), radix: 16);
5564 } on FormatException catch (exception) { 5538 } on FormatException catch (exception) {
5565 } 5539 }
5566 return new IntegerLiteral(token, value); 5540 return new IntegerLiteral(token, value);
5567 } else if (matches5(TokenType.INT)) { 5541 } else if (matches(TokenType.INT)) {
5568 Token token = andAdvance; 5542 Token token = andAdvance;
5569 int value = null; 5543 int value = null;
5570 try { 5544 try {
5571 value = int.parse(token.lexeme); 5545 value = int.parse(token.lexeme);
5572 } on FormatException catch (exception) { 5546 } on FormatException catch (exception) {
5573 } 5547 }
5574 return new IntegerLiteral(token, value); 5548 return new IntegerLiteral(token, value);
5575 } else if (matches5(TokenType.STRING)) { 5549 } else if (matches(TokenType.STRING)) {
5576 return parseStringLiteral(); 5550 return parseStringLiteral();
5577 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5551 } else if (matches(TokenType.OPEN_CURLY_BRACKET)) {
5578 return parseMapLiteral(null, null); 5552 return parseMapLiteral(null, null);
5579 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 5553 } else if (matches(TokenType.OPEN_SQUARE_BRACKET) || matches(TokenType.INDEX )) {
5580 return parseListLiteral(null, null); 5554 return parseListLiteral(null, null);
5581 } else if (matchesIdentifier()) { 5555 } else if (matchesIdentifier()) {
5582 // TODO(brianwilkerson) The code below was an attempt to recover from an e rror case, but it 5556 // TODO(brianwilkerson) The code below was an attempt to recover from an e rror case, but it
5583 // needs to be applied as a recovery only after we know that parsing it as an identifier 5557 // needs to be applied as a recovery only after we know that parsing it as an identifier
5584 // doesn't work. Leaving the code as a reminder of how to recover. 5558 // doesn't work. Leaving the code as a reminder of how to recover.
5585 // if (isFunctionExpression(peek())) { 5559 // if (isFunctionExpression(peek())) {
5586 // // 5560 // //
5587 // // Function expressions were allowed to have names at one point, but this is now illegal. 5561 // // Function expressions were allowed to have names at one point, but this is now illegal.
5588 // // 5562 // //
5589 // reportError(ParserErrorCode.NAMED_FUNCTION_EXPRESSION, getAndAdv ance()); 5563 // reportError(ParserErrorCode.NAMED_FUNCTION_EXPRESSION, getAndAdv ance());
5590 // return parseFunctionExpression(); 5564 // return parseFunctionExpression();
5591 // } 5565 // }
5592 return parsePrefixedIdentifier(); 5566 return parsePrefixedIdentifier();
5593 } else if (matches(Keyword.NEW)) { 5567 } else if (matchesKeyword(Keyword.NEW)) {
5594 return parseNewExpression(); 5568 return parseNewExpression();
5595 } else if (matches(Keyword.CONST)) { 5569 } else if (matchesKeyword(Keyword.CONST)) {
5596 return parseConstExpression(); 5570 return parseConstExpression();
5597 } else if (matches5(TokenType.OPEN_PAREN)) { 5571 } else if (matches(TokenType.OPEN_PAREN)) {
5598 if (isFunctionExpression(_currentToken)) { 5572 if (isFunctionExpression(_currentToken)) {
5599 return parseFunctionExpression(); 5573 return parseFunctionExpression();
5600 } 5574 }
5601 Token leftParenthesis = andAdvance; 5575 Token leftParenthesis = andAdvance;
5602 Expression expression = parseExpression2(); 5576 Expression expression = parseExpression2();
5603 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5577 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
5604 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis); 5578 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis);
5605 } else if (matches5(TokenType.LT)) { 5579 } else if (matches(TokenType.LT)) {
5606 return parseListOrMapLiteral(null); 5580 return parseListOrMapLiteral(null);
5607 } else if (matches5(TokenType.QUESTION)) { 5581 } else if (matches(TokenType.QUESTION)) {
5608 return parseArgumentDefinitionTest(); 5582 return parseArgumentDefinitionTest();
5609 } else if (matches(Keyword.VOID)) { 5583 } else if (matchesKeyword(Keyword.VOID)) {
5610 // 5584 //
5611 // Recover from having a return type of "void" where a return type is not expected. 5585 // Recover from having a return type of "void" where a return type is not expected.
5612 // 5586 //
5613 // TODO(brianwilkerson) Improve this error message. 5587 // TODO(brianwilkerson) Improve this error message.
5614 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 5588 reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToke n.lexeme]);
5615 advance(); 5589 advance();
5616 return parsePrimaryExpression(); 5590 return parsePrimaryExpression();
5617 } else if (matches5(TokenType.HASH)) { 5591 } else if (matches(TokenType.HASH)) {
5618 return parseSymbolLiteral(); 5592 return parseSymbolLiteral();
5619 } else { 5593 } else {
5620 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []); 5594 reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []);
5621 return createSyntheticIdentifier(); 5595 return createSyntheticIdentifier();
5622 } 5596 }
5623 } 5597 }
5624 5598
5625 /** 5599 /**
5626 * Parse a redirecting constructor invocation. 5600 * Parse a redirecting constructor invocation.
5627 * 5601 *
5628 * <pre> 5602 * <pre>
5629 * redirectingConstructorInvocation ::= 5603 * redirectingConstructorInvocation ::=
5630 * 'this' ('.' identifier)? arguments 5604 * 'this' ('.' identifier)? arguments
5631 * </pre> 5605 * </pre>
5632 * 5606 *
5633 * @return the redirecting constructor invocation that was parsed 5607 * @return the redirecting constructor invocation that was parsed
5634 */ 5608 */
5635 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() { 5609 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() {
5636 Token keyword = expect(Keyword.THIS); 5610 Token keyword = expectKeyword(Keyword.THIS);
5637 Token period = null; 5611 Token period = null;
5638 SimpleIdentifier constructorName = null; 5612 SimpleIdentifier constructorName = null;
5639 if (matches5(TokenType.PERIOD)) { 5613 if (matches(TokenType.PERIOD)) {
5640 period = andAdvance; 5614 period = andAdvance;
5641 constructorName = parseSimpleIdentifier(); 5615 constructorName = parseSimpleIdentifier();
5642 } 5616 }
5643 ArgumentList argumentList = parseArgumentList(); 5617 ArgumentList argumentList = parseArgumentList();
5644 return new RedirectingConstructorInvocation(keyword, period, constructorName , argumentList); 5618 return new RedirectingConstructorInvocation(keyword, period, constructorName , argumentList);
5645 } 5619 }
5646 5620
5647 /** 5621 /**
5648 * Parse a relational expression. 5622 * Parse a relational expression.
5649 * 5623 *
5650 * <pre> 5624 * <pre>
5651 * relationalExpression ::= 5625 * relationalExpression ::=
5652 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)? 5626 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)?
5653 * | 'super' relationalOperator bitwiseOrExpression 5627 * | 'super' relationalOperator bitwiseOrExpression
5654 * </pre> 5628 * </pre>
5655 * 5629 *
5656 * @return the relational expression that was parsed 5630 * @return the relational expression that was parsed
5657 */ 5631 */
5658 Expression parseRelationalExpression() { 5632 Expression parseRelationalExpression() {
5659 if (matches(Keyword.SUPER) && _currentToken.next.type.isRelationalOperator) { 5633 if (matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isRelationalOpe rator) {
5660 Expression expression = new SuperExpression(andAdvance); 5634 Expression expression = new SuperExpression(andAdvance);
5661 Token operator = andAdvance; 5635 Token operator = andAdvance;
5662 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession()); 5636 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession());
5663 return expression; 5637 return expression;
5664 } 5638 }
5665 Expression expression = parseBitwiseOrExpression(); 5639 Expression expression = parseBitwiseOrExpression();
5666 if (matches(Keyword.AS)) { 5640 if (matchesKeyword(Keyword.AS)) {
5667 Token asOperator = andAdvance; 5641 Token asOperator = andAdvance;
5668 expression = new AsExpression(expression, asOperator, parseTypeName()); 5642 expression = new AsExpression(expression, asOperator, parseTypeName());
5669 } else if (matches(Keyword.IS)) { 5643 } else if (matchesKeyword(Keyword.IS)) {
5670 Token isOperator = andAdvance; 5644 Token isOperator = andAdvance;
5671 Token notOperator = null; 5645 Token notOperator = null;
5672 if (matches5(TokenType.BANG)) { 5646 if (matches(TokenType.BANG)) {
5673 notOperator = andAdvance; 5647 notOperator = andAdvance;
5674 } 5648 }
5675 expression = new IsExpression(expression, isOperator, notOperator, parseTy peName()); 5649 expression = new IsExpression(expression, isOperator, notOperator, parseTy peName());
5676 } else if (_currentToken.type.isRelationalOperator) { 5650 } else if (_currentToken.type.isRelationalOperator) {
5677 Token operator = andAdvance; 5651 Token operator = andAdvance;
5678 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession()); 5652 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession());
5679 } 5653 }
5680 return expression; 5654 return expression;
5681 } 5655 }
5682 5656
5683 /** 5657 /**
5684 * Parse a rethrow expression. 5658 * Parse a rethrow expression.
5685 * 5659 *
5686 * <pre> 5660 * <pre>
5687 * rethrowExpression ::= 5661 * rethrowExpression ::=
5688 * 'rethrow' 5662 * 'rethrow'
5689 * </pre> 5663 * </pre>
5690 * 5664 *
5691 * @return the rethrow expression that was parsed 5665 * @return the rethrow expression that was parsed
5692 */ 5666 */
5693 Expression parseRethrowExpression() => new RethrowExpression(expect(Keyword.RE THROW)); 5667 Expression parseRethrowExpression() => new RethrowExpression(expectKeyword(Key word.RETHROW));
5694 5668
5695 /** 5669 /**
5696 * Parse a return statement. 5670 * Parse a return statement.
5697 * 5671 *
5698 * <pre> 5672 * <pre>
5699 * returnStatement ::= 5673 * returnStatement ::=
5700 * 'return' expression? ';' 5674 * 'return' expression? ';'
5701 * </pre> 5675 * </pre>
5702 * 5676 *
5703 * @return the return statement that was parsed 5677 * @return the return statement that was parsed
5704 */ 5678 */
5705 Statement parseReturnStatement() { 5679 Statement parseReturnStatement() {
5706 Token returnKeyword = expect(Keyword.RETURN); 5680 Token returnKeyword = expectKeyword(Keyword.RETURN);
5707 if (matches5(TokenType.SEMICOLON)) { 5681 if (matches(TokenType.SEMICOLON)) {
5708 return new ReturnStatement(returnKeyword, null, andAdvance); 5682 return new ReturnStatement(returnKeyword, null, andAdvance);
5709 } 5683 }
5710 Expression expression = parseExpression2(); 5684 Expression expression = parseExpression2();
5711 Token semicolon = expect2(TokenType.SEMICOLON); 5685 Token semicolon = expect(TokenType.SEMICOLON);
5712 return new ReturnStatement(returnKeyword, expression, semicolon); 5686 return new ReturnStatement(returnKeyword, expression, semicolon);
5713 } 5687 }
5714 5688
5715 /** 5689 /**
5716 * Parse a setter. 5690 * Parse a setter.
5717 * 5691 *
5718 * <pre> 5692 * <pre>
5719 * setter ::= 5693 * setter ::=
5720 * setterSignature functionBody? 5694 * setterSignature functionBody?
5721 * 5695 *
5722 * setterSignature ::= 5696 * setterSignature ::=
5723 * 'external'? 'static'? returnType? 'set' identifier formalParameterList 5697 * 'external'? 'static'? returnType? 'set' identifier formalParameterList
5724 * </pre> 5698 * </pre>
5725 * 5699 *
5726 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5700 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5727 * declaration 5701 * declaration
5728 * @param externalKeyword the 'external' token 5702 * @param externalKeyword the 'external' token
5729 * @param staticKeyword the static keyword, or `null` if the setter is not sta tic 5703 * @param staticKeyword the static keyword, or `null` if the setter is not sta tic
5730 * @param the return type that has already been parsed, or `null` if there was no return 5704 * @param the return type that has already been parsed, or `null` if there was no return
5731 * type 5705 * type
5732 * @return the setter that was parsed 5706 * @return the setter that was parsed
5733 */ 5707 */
5734 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 5708 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
5735 Token propertyKeyword = expect(Keyword.SET); 5709 Token propertyKeyword = expectKeyword(Keyword.SET);
5736 SimpleIdentifier name = parseSimpleIdentifier(); 5710 SimpleIdentifier name = parseSimpleIdentifier();
5737 FormalParameterList parameters = parseFormalParameterList(); 5711 FormalParameterList parameters = parseFormalParameterList();
5738 validateFormalParameterList(parameters); 5712 validateFormalParameterList(parameters);
5739 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); 5713 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false);
5740 if (externalKeyword != null && body is! EmptyFunctionBody) { 5714 if (externalKeyword != null && body is! EmptyFunctionBody) {
5741 reportError13(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); 5715 reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []);
5742 } 5716 }
5743 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body); 5717 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body);
5744 } 5718 }
5745 5719
5746 /** 5720 /**
5747 * Parse a shift expression. 5721 * Parse a shift expression.
5748 * 5722 *
5749 * <pre> 5723 * <pre>
5750 * shiftExpression ::= 5724 * shiftExpression ::=
5751 * additiveExpression (shiftOperator additiveExpression)* 5725 * additiveExpression (shiftOperator additiveExpression)*
5752 * | 'super' (shiftOperator additiveExpression)+ 5726 * | 'super' (shiftOperator additiveExpression)+
5753 * </pre> 5727 * </pre>
5754 * 5728 *
5755 * @return the shift expression that was parsed 5729 * @return the shift expression that was parsed
5756 */ 5730 */
5757 Expression parseShiftExpression() { 5731 Expression parseShiftExpression() {
5758 Expression expression; 5732 Expression expression;
5759 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator) { 5733 if (matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isShiftOperator ) {
5760 expression = new SuperExpression(andAdvance); 5734 expression = new SuperExpression(andAdvance);
5761 } else { 5735 } else {
5762 expression = parseAdditiveExpression(); 5736 expression = parseAdditiveExpression();
5763 } 5737 }
5764 while (_currentToken.type.isShiftOperator) { 5738 while (_currentToken.type.isShiftOperator) {
5765 Token operator = andAdvance; 5739 Token operator = andAdvance;
5766 expression = new BinaryExpression(expression, operator, parseAdditiveExpre ssion()); 5740 expression = new BinaryExpression(expression, operator, parseAdditiveExpre ssion());
5767 } 5741 }
5768 return expression; 5742 return expression;
5769 } 5743 }
5770 5744
5771 /** 5745 /**
5772 * Parse a list of statements within a switch statement. 5746 * Parse a list of statements within a switch statement.
5773 * 5747 *
5774 * <pre> 5748 * <pre>
5775 * statements ::= 5749 * statements ::=
5776 * statement* 5750 * statement*
5777 * </pre> 5751 * </pre>
5778 * 5752 *
5779 * @return the statements that were parsed 5753 * @return the statements that were parsed
5780 */ 5754 */
5781 List<Statement> parseStatements2() { 5755 List<Statement> parseStatementList() {
5782 List<Statement> statements = new List<Statement>(); 5756 List<Statement> statements = new List<Statement>();
5783 Token statementStart = _currentToken; 5757 Token statementStart = _currentToken;
5784 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) { 5758 while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) {
5785 statements.add(parseStatement2()); 5759 statements.add(parseStatement2());
5786 if (identical(_currentToken, statementStart)) { 5760 if (identical(_currentToken, statementStart)) {
5787 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 5761 reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_c urrentToken.lexeme]);
5788 advance(); 5762 advance();
5789 } 5763 }
5790 statementStart = _currentToken; 5764 statementStart = _currentToken;
5791 } 5765 }
5792 return statements; 5766 return statements;
5793 } 5767 }
5794 5768
5795 /** 5769 /**
5796 * Parse a string literal that contains interpolations. 5770 * Parse a string literal that contains interpolations.
5797 * 5771 *
5798 * @return the string literal that was parsed 5772 * @return the string literal that was parsed
5799 */ 5773 */
5800 StringInterpolation parseStringInterpolation(Token string) { 5774 StringInterpolation parseStringInterpolation(Token string) {
5801 List<InterpolationElement> elements = new List<InterpolationElement>(); 5775 List<InterpolationElement> elements = new List<InterpolationElement>();
5802 bool hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matche s5(TokenType.STRING_INTERPOLATION_IDENTIFIER); 5776 bool hasMore = matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches (TokenType.STRING_INTERPOLATION_IDENTIFIER);
5803 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore))); 5777 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore)));
5804 while (hasMore) { 5778 while (hasMore) {
5805 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 5779 if (matches(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
5806 Token openToken = andAdvance; 5780 Token openToken = andAdvance;
5807 Expression expression = parseExpression2(); 5781 Expression expression = parseExpression2();
5808 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5782 Token rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
5809 elements.add(new InterpolationExpression(openToken, expression, rightBra cket)); 5783 elements.add(new InterpolationExpression(openToken, expression, rightBra cket));
5810 } else { 5784 } else {
5811 Token openToken = andAdvance; 5785 Token openToken = andAdvance;
5812 Expression expression = null; 5786 Expression expression = null;
5813 if (matches(Keyword.THIS)) { 5787 if (matchesKeyword(Keyword.THIS)) {
5814 expression = new ThisExpression(andAdvance); 5788 expression = new ThisExpression(andAdvance);
5815 } else { 5789 } else {
5816 expression = parseSimpleIdentifier(); 5790 expression = parseSimpleIdentifier();
5817 } 5791 }
5818 elements.add(new InterpolationExpression(openToken, expression, null)); 5792 elements.add(new InterpolationExpression(openToken, expression, null));
5819 } 5793 }
5820 if (matches5(TokenType.STRING)) { 5794 if (matches(TokenType.STRING)) {
5821 string = andAdvance; 5795 string = andAdvance;
5822 hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches 5(TokenType.STRING_INTERPOLATION_IDENTIFIER); 5796 hasMore = matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches( TokenType.STRING_INTERPOLATION_IDENTIFIER);
5823 elements.add(new InterpolationString(string, computeStringValue(string.l exeme, false, !hasMore))); 5797 elements.add(new InterpolationString(string, computeStringValue(string.l exeme, false, !hasMore)));
5824 } 5798 }
5825 } 5799 }
5826 return new StringInterpolation(elements); 5800 return new StringInterpolation(elements);
5827 } 5801 }
5828 5802
5829 /** 5803 /**
5830 * Parse a super constructor invocation. 5804 * Parse a super constructor invocation.
5831 * 5805 *
5832 * <pre> 5806 * <pre>
5833 * superConstructorInvocation ::= 5807 * superConstructorInvocation ::=
5834 * 'super' ('.' identifier)? arguments 5808 * 'super' ('.' identifier)? arguments
5835 * </pre> 5809 * </pre>
5836 * 5810 *
5837 * @return the super constructor invocation that was parsed 5811 * @return the super constructor invocation that was parsed
5838 */ 5812 */
5839 SuperConstructorInvocation parseSuperConstructorInvocation() { 5813 SuperConstructorInvocation parseSuperConstructorInvocation() {
5840 Token keyword = expect(Keyword.SUPER); 5814 Token keyword = expectKeyword(Keyword.SUPER);
5841 Token period = null; 5815 Token period = null;
5842 SimpleIdentifier constructorName = null; 5816 SimpleIdentifier constructorName = null;
5843 if (matches5(TokenType.PERIOD)) { 5817 if (matches(TokenType.PERIOD)) {
5844 period = andAdvance; 5818 period = andAdvance;
5845 constructorName = parseSimpleIdentifier(); 5819 constructorName = parseSimpleIdentifier();
5846 } 5820 }
5847 ArgumentList argumentList = parseArgumentList(); 5821 ArgumentList argumentList = parseArgumentList();
5848 return new SuperConstructorInvocation(keyword, period, constructorName, argu mentList); 5822 return new SuperConstructorInvocation(keyword, period, constructorName, argu mentList);
5849 } 5823 }
5850 5824
5851 /** 5825 /**
5852 * Parse a switch statement. 5826 * Parse a switch statement.
5853 * 5827 *
5854 * <pre> 5828 * <pre>
5855 * switchStatement ::= 5829 * switchStatement ::=
5856 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' 5830 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}'
5857 * 5831 *
5858 * switchCase ::= 5832 * switchCase ::=
5859 * label* ('case' expression ':') statements 5833 * label* ('case' expression ':') statements
5860 * 5834 *
5861 * defaultCase ::= 5835 * defaultCase ::=
5862 * label* 'default' ':' statements 5836 * label* 'default' ':' statements
5863 * </pre> 5837 * </pre>
5864 * 5838 *
5865 * @return the switch statement that was parsed 5839 * @return the switch statement that was parsed
5866 */ 5840 */
5867 SwitchStatement parseSwitchStatement() { 5841 SwitchStatement parseSwitchStatement() {
5868 bool wasInSwitch = _inSwitch; 5842 bool wasInSwitch = _inSwitch;
5869 _inSwitch = true; 5843 _inSwitch = true;
5870 try { 5844 try {
5871 Set<String> definedLabels = new Set<String>(); 5845 Set<String> definedLabels = new Set<String>();
5872 Token keyword = expect(Keyword.SWITCH); 5846 Token keyword = expectKeyword(Keyword.SWITCH);
5873 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 5847 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
5874 Expression expression = parseExpression2(); 5848 Expression expression = parseExpression2();
5875 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5849 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
5876 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 5850 Token leftBracket = expect(TokenType.OPEN_CURLY_BRACKET);
5877 Token defaultKeyword = null; 5851 Token defaultKeyword = null;
5878 List<SwitchMember> members = new List<SwitchMember>(); 5852 List<SwitchMember> members = new List<SwitchMember>();
5879 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET )) { 5853 while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACKET)) {
5880 List<Label> labels = new List<Label>(); 5854 List<Label> labels = new List<Label>();
5881 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 5855 while (matchesIdentifier() && tokenMatches(peek(), TokenType.COLON)) {
5882 SimpleIdentifier identifier = parseSimpleIdentifier(); 5856 SimpleIdentifier identifier = parseSimpleIdentifier();
5883 String label = identifier.token.lexeme; 5857 String label = identifier.token.lexeme;
5884 if (definedLabels.contains(label)) { 5858 if (definedLabels.contains(label)) {
5885 reportError14(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]); 5859 reportErrorForToken(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEM ENT, identifier.token, [label]);
5886 } else { 5860 } else {
5887 definedLabels.add(label); 5861 definedLabels.add(label);
5888 } 5862 }
5889 Token colon = expect2(TokenType.COLON); 5863 Token colon = expect(TokenType.COLON);
5890 labels.add(new Label(identifier, colon)); 5864 labels.add(new Label(identifier, colon));
5891 } 5865 }
5892 if (matches(Keyword.CASE)) { 5866 if (matchesKeyword(Keyword.CASE)) {
5893 Token caseKeyword = andAdvance; 5867 Token caseKeyword = andAdvance;
5894 Expression caseExpression = parseExpression2(); 5868 Expression caseExpression = parseExpression2();
5895 Token colon = expect2(TokenType.COLON); 5869 Token colon = expect(TokenType.COLON);
5896 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2())); 5870 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatementList()));
5897 if (defaultKeyword != null) { 5871 if (defaultKeyword != null) {
5898 reportError14(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []); 5872 reportErrorForToken(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CA SE, caseKeyword, []);
5899 } 5873 }
5900 } else if (matches(Keyword.DEFAULT)) { 5874 } else if (matchesKeyword(Keyword.DEFAULT)) {
5901 if (defaultKeyword != null) { 5875 if (defaultKeyword != null) {
5902 reportError14(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []); 5876 reportErrorForToken(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASE S, peek(), []);
5903 } 5877 }
5904 defaultKeyword = andAdvance; 5878 defaultKeyword = andAdvance;
5905 Token colon = expect2(TokenType.COLON); 5879 Token colon = expect(TokenType.COLON);
5906 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2())); 5880 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ementList()));
5907 } else { 5881 } else {
5908 // We need to advance, otherwise we could end up in an infinite loop, but this could be a 5882 // We need to advance, otherwise we could end up in an infinite loop, but this could be a
5909 // lot smarter about recovering from the error. 5883 // lot smarter about recovering from the error.
5910 reportError13(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 5884 reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, [ ]);
5911 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { 5885 while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACK ET) && !matchesKeyword(Keyword.CASE) && !matchesKeyword(Keyword.DEFAULT)) {
5912 advance(); 5886 advance();
5913 } 5887 }
5914 } 5888 }
5915 } 5889 }
5916 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5890 Token rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
5917 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket); 5891 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket);
5918 } finally { 5892 } finally {
5919 _inSwitch = wasInSwitch; 5893 _inSwitch = wasInSwitch;
5920 } 5894 }
5921 } 5895 }
5922 5896
5923 /** 5897 /**
5924 * Parse a symbol literal. 5898 * Parse a symbol literal.
5925 * 5899 *
5926 * <pre> 5900 * <pre>
5927 * symbolLiteral ::= 5901 * symbolLiteral ::=
5928 * '#' identifier ('.' identifier)* 5902 * '#' identifier ('.' identifier)*
5929 * </pre> 5903 * </pre>
5930 * 5904 *
5931 * @return the symbol literal that was parsed 5905 * @return the symbol literal that was parsed
5932 */ 5906 */
5933 SymbolLiteral parseSymbolLiteral() { 5907 SymbolLiteral parseSymbolLiteral() {
5934 Token poundSign = andAdvance; 5908 Token poundSign = andAdvance;
5935 List<Token> components = new List<Token>(); 5909 List<Token> components = new List<Token>();
5936 if (matchesIdentifier()) { 5910 if (matchesIdentifier()) {
5937 components.add(andAdvance); 5911 components.add(andAdvance);
5938 while (matches5(TokenType.PERIOD)) { 5912 while (matches(TokenType.PERIOD)) {
5939 advance(); 5913 advance();
5940 if (matchesIdentifier()) { 5914 if (matchesIdentifier()) {
5941 components.add(andAdvance); 5915 components.add(andAdvance);
5942 } else { 5916 } else {
5943 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []); 5917 reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []);
5944 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5918 components.add(createSyntheticToken(TokenType.IDENTIFIER));
5945 break; 5919 break;
5946 } 5920 }
5947 } 5921 }
5948 } else if (_currentToken.isOperator) { 5922 } else if (_currentToken.isOperator) {
5949 components.add(andAdvance); 5923 components.add(andAdvance);
5950 } else { 5924 } else {
5951 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []); 5925 reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []);
5952 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5926 components.add(createSyntheticToken(TokenType.IDENTIFIER));
5953 } 5927 }
5954 return new SymbolLiteral(poundSign, new List.from(components)); 5928 return new SymbolLiteral(poundSign, new List.from(components));
5955 } 5929 }
5956 5930
5957 /** 5931 /**
5958 * Parse a throw expression. 5932 * Parse a throw expression.
5959 * 5933 *
5960 * <pre> 5934 * <pre>
5961 * throwExpression ::= 5935 * throwExpression ::=
5962 * 'throw' expression 5936 * 'throw' expression
5963 * </pre> 5937 * </pre>
5964 * 5938 *
5965 * @return the throw expression that was parsed 5939 * @return the throw expression that was parsed
5966 */ 5940 */
5967 Expression parseThrowExpression() { 5941 Expression parseThrowExpression() {
5968 Token keyword = expect(Keyword.THROW); 5942 Token keyword = expectKeyword(Keyword.THROW);
5969 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5943 if (matches(TokenType.SEMICOLON) || matches(TokenType.CLOSE_PAREN)) {
5970 reportError14(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5944 reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentT oken, []);
5971 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5945 return new ThrowExpression(keyword, createSyntheticIdentifier());
5972 } 5946 }
5973 Expression expression = parseExpression2(); 5947 Expression expression = parseExpression2();
5974 return new ThrowExpression(keyword, expression); 5948 return new ThrowExpression(keyword, expression);
5975 } 5949 }
5976 5950
5977 /** 5951 /**
5978 * Parse a throw expression. 5952 * Parse a throw expression.
5979 * 5953 *
5980 * <pre> 5954 * <pre>
5981 * throwExpressionWithoutCascade ::= 5955 * throwExpressionWithoutCascade ::=
5982 * 'throw' expressionWithoutCascade 5956 * 'throw' expressionWithoutCascade
5983 * </pre> 5957 * </pre>
5984 * 5958 *
5985 * @return the throw expression that was parsed 5959 * @return the throw expression that was parsed
5986 */ 5960 */
5987 Expression parseThrowExpressionWithoutCascade() { 5961 Expression parseThrowExpressionWithoutCascade() {
5988 Token keyword = expect(Keyword.THROW); 5962 Token keyword = expectKeyword(Keyword.THROW);
5989 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5963 if (matches(TokenType.SEMICOLON) || matches(TokenType.CLOSE_PAREN)) {
5990 reportError14(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5964 reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentT oken, []);
5991 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5965 return new ThrowExpression(keyword, createSyntheticIdentifier());
5992 } 5966 }
5993 Expression expression = parseExpressionWithoutCascade(); 5967 Expression expression = parseExpressionWithoutCascade();
5994 return new ThrowExpression(keyword, expression); 5968 return new ThrowExpression(keyword, expression);
5995 } 5969 }
5996 5970
5997 /** 5971 /**
5998 * Parse a try statement. 5972 * Parse a try statement.
5999 * 5973 *
6000 * <pre> 5974 * <pre>
6001 * tryStatement ::= 5975 * tryStatement ::=
6002 * 'try' block (onPart+ finallyPart? | finallyPart) 5976 * 'try' block (onPart+ finallyPart? | finallyPart)
6003 * 5977 *
6004 * onPart ::= 5978 * onPart ::=
6005 * catchPart block 5979 * catchPart block
6006 * | 'on' type catchPart? block 5980 * | 'on' type catchPart? block
6007 * 5981 *
6008 * catchPart ::= 5982 * catchPart ::=
6009 * 'catch' '(' identifier (',' identifier)? ')' 5983 * 'catch' '(' identifier (',' identifier)? ')'
6010 * 5984 *
6011 * finallyPart ::= 5985 * finallyPart ::=
6012 * 'finally' block 5986 * 'finally' block
6013 * </pre> 5987 * </pre>
6014 * 5988 *
6015 * @return the try statement that was parsed 5989 * @return the try statement that was parsed
6016 */ 5990 */
6017 Statement parseTryStatement() { 5991 Statement parseTryStatement() {
6018 Token tryKeyword = expect(Keyword.TRY); 5992 Token tryKeyword = expectKeyword(Keyword.TRY);
6019 Block body = parseBlock(); 5993 Block body = parseBlock();
6020 List<CatchClause> catchClauses = new List<CatchClause>(); 5994 List<CatchClause> catchClauses = new List<CatchClause>();
6021 Block finallyClause = null; 5995 Block finallyClause = null;
6022 while (matches2(_ON) || matches(Keyword.CATCH)) { 5996 while (matchesString(_ON) || matchesKeyword(Keyword.CATCH)) {
6023 Token onKeyword = null; 5997 Token onKeyword = null;
6024 TypeName exceptionType = null; 5998 TypeName exceptionType = null;
6025 if (matches2(_ON)) { 5999 if (matchesString(_ON)) {
6026 onKeyword = andAdvance; 6000 onKeyword = andAdvance;
6027 exceptionType = parseTypeName(); 6001 exceptionType = parseTypeName();
6028 } 6002 }
6029 Token catchKeyword = null; 6003 Token catchKeyword = null;
6030 Token leftParenthesis = null; 6004 Token leftParenthesis = null;
6031 SimpleIdentifier exceptionParameter = null; 6005 SimpleIdentifier exceptionParameter = null;
6032 Token comma = null; 6006 Token comma = null;
6033 SimpleIdentifier stackTraceParameter = null; 6007 SimpleIdentifier stackTraceParameter = null;
6034 Token rightParenthesis = null; 6008 Token rightParenthesis = null;
6035 if (matches(Keyword.CATCH)) { 6009 if (matchesKeyword(Keyword.CATCH)) {
6036 catchKeyword = andAdvance; 6010 catchKeyword = andAdvance;
6037 leftParenthesis = expect2(TokenType.OPEN_PAREN); 6011 leftParenthesis = expect(TokenType.OPEN_PAREN);
6038 exceptionParameter = parseSimpleIdentifier(); 6012 exceptionParameter = parseSimpleIdentifier();
6039 if (matches5(TokenType.COMMA)) { 6013 if (matches(TokenType.COMMA)) {
6040 comma = andAdvance; 6014 comma = andAdvance;
6041 stackTraceParameter = parseSimpleIdentifier(); 6015 stackTraceParameter = parseSimpleIdentifier();
6042 } 6016 }
6043 rightParenthesis = expect2(TokenType.CLOSE_PAREN); 6017 rightParenthesis = expect(TokenType.CLOSE_PAREN);
6044 } 6018 }
6045 Block catchBody = parseBlock(); 6019 Block catchBody = parseBlock();
6046 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody)); 6020 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody));
6047 } 6021 }
6048 Token finallyKeyword = null; 6022 Token finallyKeyword = null;
6049 if (matches(Keyword.FINALLY)) { 6023 if (matchesKeyword(Keyword.FINALLY)) {
6050 finallyKeyword = andAdvance; 6024 finallyKeyword = andAdvance;
6051 finallyClause = parseBlock(); 6025 finallyClause = parseBlock();
6052 } else { 6026 } else {
6053 if (catchClauses.isEmpty) { 6027 if (catchClauses.isEmpty) {
6054 reportError13(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); 6028 reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []) ;
6055 } 6029 }
6056 } 6030 }
6057 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause); 6031 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause);
6058 } 6032 }
6059 6033
6060 /** 6034 /**
6061 * Parse a type alias. 6035 * Parse a type alias.
6062 * 6036 *
6063 * <pre> 6037 * <pre>
6064 * typeAlias ::= 6038 * typeAlias ::=
(...skipping 13 matching lines...) Expand all
6078 * functionPrefix typeParameterList? formalParameterList ';' 6052 * functionPrefix typeParameterList? formalParameterList ';'
6079 * 6053 *
6080 * functionPrefix ::= 6054 * functionPrefix ::=
6081 * returnType? name 6055 * returnType? name
6082 * </pre> 6056 * </pre>
6083 * 6057 *
6084 * @param commentAndMetadata the metadata to be associated with the member 6058 * @param commentAndMetadata the metadata to be associated with the member
6085 * @return the type alias that was parsed 6059 * @return the type alias that was parsed
6086 */ 6060 */
6087 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { 6061 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) {
6088 Token keyword = expect(Keyword.TYPEDEF); 6062 Token keyword = expectKeyword(Keyword.TYPEDEF);
6089 if (matchesIdentifier()) { 6063 if (matchesIdentifier()) {
6090 Token next = peek(); 6064 Token next = peek();
6091 if (matches4(next, TokenType.LT)) { 6065 if (tokenMatches(next, TokenType.LT)) {
6092 next = skipTypeParameterList(next); 6066 next = skipTypeParameterList(next);
6093 if (next != null && matches4(next, TokenType.EQ)) { 6067 if (next != null && tokenMatches(next, TokenType.EQ)) {
6094 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword); 6068 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword);
6095 reportError14(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, [] ); 6069 reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keywo rd, []);
6096 return typeAlias; 6070 return typeAlias;
6097 } 6071 }
6098 } else if (matches4(next, TokenType.EQ)) { 6072 } else if (tokenMatches(next, TokenType.EQ)) {
6099 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord); 6073 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord);
6100 reportError14(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, []); 6074 reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword , []);
6101 return typeAlias; 6075 return typeAlias;
6102 } 6076 }
6103 } 6077 }
6104 return parseFunctionTypeAlias(commentAndMetadata, keyword); 6078 return parseFunctionTypeAlias(commentAndMetadata, keyword);
6105 } 6079 }
6106 6080
6107 /** 6081 /**
6108 * Parse a unary expression. 6082 * Parse a unary expression.
6109 * 6083 *
6110 * <pre> 6084 * <pre>
6111 * unaryExpression ::= 6085 * unaryExpression ::=
6112 * prefixOperator unaryExpression 6086 * prefixOperator unaryExpression
6113 * | postfixExpression 6087 * | postfixExpression
6114 * | unaryOperator 'super' 6088 * | unaryOperator 'super'
6115 * | '-' 'super' 6089 * | '-' 'super'
6116 * | incrementOperator assignableExpression 6090 * | incrementOperator assignableExpression
6117 * </pre> 6091 * </pre>
6118 * 6092 *
6119 * @return the unary expression that was parsed 6093 * @return the unary expression that was parsed
6120 */ 6094 */
6121 Expression parseUnaryExpression() { 6095 Expression parseUnaryExpression() {
6122 if (matches5(TokenType.MINUS) || matches5(TokenType.BANG) || matches5(TokenT ype.TILDE)) { 6096 if (matches(TokenType.MINUS) || matches(TokenType.BANG) || matches(TokenType .TILDE)) {
6123 Token operator = andAdvance; 6097 Token operator = andAdvance;
6124 if (matches(Keyword.SUPER)) { 6098 if (matchesKeyword(Keyword.SUPER)) {
6125 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) { 6099 if (tokenMatches(peek(), TokenType.OPEN_SQUARE_BRACKET) || tokenMatches( peek(), TokenType.PERIOD)) {
6126 // "prefixOperator unaryExpression" 6100 // "prefixOperator unaryExpression"
6127 // --> "prefixOperator postfixExpression" 6101 // --> "prefixOperator postfixExpression"
6128 // --> "prefixOperator primary selector*" 6102 // --> "prefixOperator primary selector*"
6129 // --> "prefixOperator 'super' assignableSelector selector*" 6103 // --> "prefixOperator 'super' assignableSelector selector*"
6130 return new PrefixExpression(operator, parseUnaryExpression()); 6104 return new PrefixExpression(operator, parseUnaryExpression());
6131 } 6105 }
6132 return new PrefixExpression(operator, new SuperExpression(andAdvance)); 6106 return new PrefixExpression(operator, new SuperExpression(andAdvance));
6133 } 6107 }
6134 return new PrefixExpression(operator, parseUnaryExpression()); 6108 return new PrefixExpression(operator, parseUnaryExpression());
6135 } else if (_currentToken.type.isIncrementOperator) { 6109 } else if (_currentToken.type.isIncrementOperator) {
6136 Token operator = andAdvance; 6110 Token operator = andAdvance;
6137 if (matches(Keyword.SUPER)) { 6111 if (matchesKeyword(Keyword.SUPER)) {
6138 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) { 6112 if (tokenMatches(peek(), TokenType.OPEN_SQUARE_BRACKET) || tokenMatches( peek(), TokenType.PERIOD)) {
6139 // --> "prefixOperator 'super' assignableSelector selector*" 6113 // --> "prefixOperator 'super' assignableSelector selector*"
6140 return new PrefixExpression(operator, parseUnaryExpression()); 6114 return new PrefixExpression(operator, parseUnaryExpression());
6141 } 6115 }
6142 // 6116 //
6143 // Even though it is not valid to use an incrementing operator ('++' or '--') before 'super', 6117 // Even though it is not valid to use an incrementing operator ('++' or '--') before 'super',
6144 // we can (and therefore must) interpret "--super" as semantically equiv alent to "-(-super)". 6118 // we can (and therefore must) interpret "--super" as semantically equiv alent to "-(-super)".
6145 // Unfortunately, we cannot do the same for "++super" because "+super" i s also not valid. 6119 // Unfortunately, we cannot do the same for "++super" because "+super" i s also not valid.
6146 // 6120 //
6147 if (identical(operator.type, TokenType.MINUS_MINUS)) { 6121 if (identical(operator.type, TokenType.MINUS_MINUS)) {
6148 int offset = operator.offset; 6122 int offset = operator.offset;
6149 Token firstOperator = new Token(TokenType.MINUS, offset); 6123 Token firstOperator = new Token(TokenType.MINUS, offset);
6150 Token secondOperator = new Token(TokenType.MINUS, offset + 1); 6124 Token secondOperator = new Token(TokenType.MINUS, offset + 1);
6151 secondOperator.setNext(_currentToken); 6125 secondOperator.setNext(_currentToken);
6152 firstOperator.setNext(secondOperator); 6126 firstOperator.setNext(secondOperator);
6153 operator.previous.setNext(firstOperator); 6127 operator.previous.setNext(firstOperator);
6154 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance))); 6128 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance)));
6155 } else { 6129 } else {
6156 // Invalid operator before 'super' 6130 // Invalid operator before 'super'
6157 reportError13(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]); 6131 reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]);
6158 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ; 6132 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ;
6159 } 6133 }
6160 } 6134 }
6161 return new PrefixExpression(operator, parseAssignableExpression(false)); 6135 return new PrefixExpression(operator, parseAssignableExpression(false));
6162 } else if (matches5(TokenType.PLUS)) { 6136 } else if (matches(TokenType.PLUS)) {
6163 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []); 6137 reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []);
6164 return createSyntheticIdentifier(); 6138 return createSyntheticIdentifier();
6165 } 6139 }
6166 return parsePostfixExpression(); 6140 return parsePostfixExpression();
6167 } 6141 }
6168 6142
6169 /** 6143 /**
6170 * Parse a variable declaration. 6144 * Parse a variable declaration.
6171 * 6145 *
6172 * <pre> 6146 * <pre>
6173 * variableDeclaration ::= 6147 * variableDeclaration ::=
6174 * identifier ('=' expression)? 6148 * identifier ('=' expression)?
6175 * </pre> 6149 * </pre>
6176 * 6150 *
6177 * @return the variable declaration that was parsed 6151 * @return the variable declaration that was parsed
6178 */ 6152 */
6179 VariableDeclaration parseVariableDeclaration() { 6153 VariableDeclaration parseVariableDeclaration() {
6180 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 6154 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
6181 SimpleIdentifier name = parseSimpleIdentifier(); 6155 SimpleIdentifier name = parseSimpleIdentifier();
6182 Token equals = null; 6156 Token equals = null;
6183 Expression initializer = null; 6157 Expression initializer = null;
6184 if (matches5(TokenType.EQ)) { 6158 if (matches(TokenType.EQ)) {
6185 equals = andAdvance; 6159 equals = andAdvance;
6186 initializer = parseExpression2(); 6160 initializer = parseExpression2();
6187 } 6161 }
6188 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer); 6162 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer);
6189 } 6163 }
6190 6164
6191 /** 6165 /**
6192 * Parse a variable declaration list. 6166 * Parse a variable declaration list.
6193 * 6167 *
6194 * <pre> 6168 * <pre>
6195 * variableDeclarationList ::= 6169 * variableDeclarationList ::=
6196 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* 6170 * finalConstVarOrType variableDeclaration (',' variableDeclaration)*
6197 * </pre> 6171 * </pre>
6198 * 6172 *
6199 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list 6173 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list
6200 * @return the variable declaration list that was parsed 6174 * @return the variable declaration list that was parsed
6201 */ 6175 */
6202 VariableDeclarationList parseVariableDeclarationList(CommentAndMetadata commen tAndMetadata) { 6176 VariableDeclarationList parseVariableDeclarationListAfterMetadata(CommentAndMe tadata commentAndMetadata) {
6203 FinalConstVarOrType holder = parseFinalConstVarOrType(false); 6177 FinalConstVarOrType holder = parseFinalConstVarOrType(false);
6204 return parseVariableDeclarationList2(commentAndMetadata, holder.keyword, hol der.type); 6178 return parseVariableDeclarationListAfterType(commentAndMetadata, holder.keyw ord, holder.type);
6205 } 6179 }
6206 6180
6207 /** 6181 /**
6208 * Parse a variable declaration list. 6182 * Parse a variable declaration list.
6209 * 6183 *
6210 * <pre> 6184 * <pre>
6211 * variableDeclarationList ::= 6185 * variableDeclarationList ::=
6212 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* 6186 * finalConstVarOrType variableDeclaration (',' variableDeclaration)*
6213 * </pre> 6187 * </pre>
6214 * 6188 *
6215 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or 6189 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or
6216 * `null` if there is no attempt at parsing the comment and metadata 6190 * `null` if there is no attempt at parsing the comment and metadata
6217 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 6191 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
6218 * there is no keyword 6192 * there is no keyword
6219 * @param type the type of the variables in the list 6193 * @param type the type of the variables in the list
6220 * @return the variable declaration list that was parsed 6194 * @return the variable declaration list that was parsed
6221 */ 6195 */
6222 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) { 6196 VariableDeclarationList parseVariableDeclarationListAfterType(CommentAndMetada ta commentAndMetadata, Token keyword, TypeName type) {
6223 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) { 6197 if (type != null && keyword != null && tokenMatchesKeyword(keyword, Keyword. VAR)) {
6224 reportError14(ParserErrorCode.VAR_AND_TYPE, keyword, []); 6198 reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, keyword, []);
6225 } 6199 }
6226 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 6200 List<VariableDeclaration> variables = new List<VariableDeclaration>();
6227 variables.add(parseVariableDeclaration()); 6201 variables.add(parseVariableDeclaration());
6228 while (matches5(TokenType.COMMA)) { 6202 while (matches(TokenType.COMMA)) {
6229 advance(); 6203 advance();
6230 variables.add(parseVariableDeclaration()); 6204 variables.add(parseVariableDeclaration());
6231 } 6205 }
6232 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables); 6206 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables);
6233 } 6207 }
6234 6208
6235 /** 6209 /**
6236 * Parse a variable declaration statement. 6210 * Parse a variable declaration statement.
6237 * 6211 *
6238 * <pre> 6212 * <pre>
6239 * variableDeclarationStatement ::= 6213 * variableDeclarationStatement ::=
6240 * variableDeclarationList ';' 6214 * variableDeclarationList ';'
6241 * </pre> 6215 * </pre>
6242 * 6216 *
6243 * @param commentAndMetadata the metadata to be associated with the variable d eclaration 6217 * @param commentAndMetadata the metadata to be associated with the variable d eclaration
6244 * statement, or `null` if there is no attempt at parsing the comment and metadata 6218 * statement, or `null` if there is no attempt at parsing the comment and metadata
6245 * @return the variable declaration statement that was parsed 6219 * @return the variable declaration statement that was parsed
6246 */ 6220 */
6247 VariableDeclarationStatement parseVariableDeclarationStatement(CommentAndMetad ata commentAndMetadata) { 6221 VariableDeclarationStatement parseVariableDeclarationStatementAfterMetadata(Co mmentAndMetadata commentAndMetadata) {
6248 // Token startToken = currentToken; 6222 // Token startToken = currentToken;
6249 VariableDeclarationList variableList = parseVariableDeclarationList(commentA ndMetadata); 6223 VariableDeclarationList variableList = parseVariableDeclarationListAfterMeta data(commentAndMetadata);
6250 // if (!matches(TokenType.SEMICOLON)) { 6224 // if (!matches(TokenType.SEMICOLON)) {
6251 // if (matches(startToken, Keyword.VAR) && isTypedIdentifier(startToken .getNext())) { 6225 // if (matches(startToken, Keyword.VAR) && isTypedIdentifier(startToken .getNext())) {
6252 // // TODO(brianwilkerson) This appears to be of the form "var type v ariable". We should do 6226 // // TODO(brianwilkerson) This appears to be of the form "var type v ariable". We should do
6253 // // a better job of recovering in this case. 6227 // // a better job of recovering in this case.
6254 // } 6228 // }
6255 // } 6229 // }
6256 Token semicolon = expect2(TokenType.SEMICOLON); 6230 Token semicolon = expect(TokenType.SEMICOLON);
6257 return new VariableDeclarationStatement(variableList, semicolon); 6231 return new VariableDeclarationStatement(variableList, semicolon);
6258 } 6232 }
6259 6233
6260 /** 6234 /**
6261 * Parse a variable declaration statement. 6235 * Parse a variable declaration statement.
6262 * 6236 *
6263 * <pre> 6237 * <pre>
6264 * variableDeclarationStatement ::= 6238 * variableDeclarationStatement ::=
6265 * variableDeclarationList ';' 6239 * variableDeclarationList ';'
6266 * </pre> 6240 * </pre>
6267 * 6241 *
6268 * @param commentAndMetadata the metadata to be associated with the variable d eclaration 6242 * @param commentAndMetadata the metadata to be associated with the variable d eclaration
6269 * statement, or `null` if there is no attempt at parsing the comment and metadata 6243 * statement, or `null` if there is no attempt at parsing the comment and metadata
6270 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 6244 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
6271 * there is no keyword 6245 * there is no keyword
6272 * @param type the type of the variables in the list 6246 * @param type the type of the variables in the list
6273 * @return the variable declaration statement that was parsed 6247 * @return the variable declaration statement that was parsed
6274 */ 6248 */
6275 VariableDeclarationStatement parseVariableDeclarationStatement2(CommentAndMeta data commentAndMetadata, Token keyword, TypeName type) { 6249 VariableDeclarationStatement parseVariableDeclarationStatementAfterType(Commen tAndMetadata commentAndMetadata, Token keyword, TypeName type) {
6276 VariableDeclarationList variableList = parseVariableDeclarationList2(comment AndMetadata, keyword, type); 6250 VariableDeclarationList variableList = parseVariableDeclarationListAfterType (commentAndMetadata, keyword, type);
6277 Token semicolon = expect2(TokenType.SEMICOLON); 6251 Token semicolon = expect(TokenType.SEMICOLON);
6278 return new VariableDeclarationStatement(variableList, semicolon); 6252 return new VariableDeclarationStatement(variableList, semicolon);
6279 } 6253 }
6280 6254
6281 /** 6255 /**
6282 * Parse a while statement. 6256 * Parse a while statement.
6283 * 6257 *
6284 * <pre> 6258 * <pre>
6285 * whileStatement ::= 6259 * whileStatement ::=
6286 * 'while' '(' expression ')' statement 6260 * 'while' '(' expression ')' statement
6287 * </pre> 6261 * </pre>
6288 * 6262 *
6289 * @return the while statement that was parsed 6263 * @return the while statement that was parsed
6290 */ 6264 */
6291 Statement parseWhileStatement() { 6265 Statement parseWhileStatement() {
6292 bool wasInLoop = _inLoop; 6266 bool wasInLoop = _inLoop;
6293 _inLoop = true; 6267 _inLoop = true;
6294 try { 6268 try {
6295 Token keyword = expect(Keyword.WHILE); 6269 Token keyword = expectKeyword(Keyword.WHILE);
6296 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 6270 Token leftParenthesis = expect(TokenType.OPEN_PAREN);
6297 Expression condition = parseExpression2(); 6271 Expression condition = parseExpression2();
6298 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 6272 Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
6299 Statement body = parseStatement2(); 6273 Statement body = parseStatement2();
6300 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body); 6274 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body);
6301 } finally { 6275 } finally {
6302 _inLoop = wasInLoop; 6276 _inLoop = wasInLoop;
6303 } 6277 }
6304 } 6278 }
6305 6279
6306 /** 6280 /**
6307 * Return the token that is immediately after the current token. This is equiv alent to 6281 * Return the token that is immediately after the current token. This is equiv alent to
6308 * [peek]. 6282 * [peek].
(...skipping 26 matching lines...) Expand all
6335 if (_errorListenerLock != 0) { 6309 if (_errorListenerLock != 0) {
6336 return; 6310 return;
6337 } 6311 }
6338 _errorListener.onError(error); 6312 _errorListener.onError(error);
6339 } 6313 }
6340 6314
6341 /** 6315 /**
6342 * Report an error with the given error code and arguments. 6316 * Report an error with the given error code and arguments.
6343 * 6317 *
6344 * @param errorCode the error code of the error to be reported 6318 * @param errorCode the error code of the error to be reported
6319 * @param arguments the arguments to the error, used to compose the error mess age
6320 */
6321 void reportErrorForCurrentToken(ParserErrorCode errorCode, List<Object> argume nts) {
6322 reportErrorForToken(errorCode, _currentToken, arguments);
6323 }
6324
6325 /**
6326 * Report an error with the given error code and arguments.
6327 *
6328 * @param errorCode the error code of the error to be reported
6345 * @param node the node specifying the location of the error 6329 * @param node the node specifying the location of the error
6346 * @param arguments the arguments to the error, used to compose the error mess age 6330 * @param arguments the arguments to the error, used to compose the error mess age
6347 */ 6331 */
6348 void reportError12(ParserErrorCode errorCode, AstNode node, List<Object> argum ents) { 6332 void reportErrorForNode(ParserErrorCode errorCode, AstNode node, List<Object> arguments) {
6349 reportError(new AnalysisError.con2(_source, node.offset, node.length, errorC ode, arguments)); 6333 reportError(new AnalysisError.con2(_source, node.offset, node.length, errorC ode, arguments));
6350 } 6334 }
6351 6335
6352 /** 6336 /**
6353 * Report an error with the given error code and arguments.
6354 *
6355 * @param errorCode the error code of the error to be reported
6356 * @param arguments the arguments to the error, used to compose the error mess age
6357 */
6358 void reportError13(ParserErrorCode errorCode, List<Object> arguments) {
6359 reportError14(errorCode, _currentToken, arguments);
6360 }
6361
6362 /**
6363 * Report an error with the given error code and arguments. 6337 * Report an error with the given error code and arguments.
6364 * 6338 *
6365 * @param errorCode the error code of the error to be reported 6339 * @param errorCode the error code of the error to be reported
6366 * @param token the token specifying the location of the error 6340 * @param token the token specifying the location of the error
6367 * @param arguments the arguments to the error, used to compose the error mess age 6341 * @param arguments the arguments to the error, used to compose the error mess age
6368 */ 6342 */
6369 void reportError14(ParserErrorCode errorCode, Token token, List<Object> argume nts) { 6343 void reportErrorForToken(ParserErrorCode errorCode, Token token, List<Object> arguments) {
6370 reportError(new AnalysisError.con2(_source, token.offset, token.length, erro rCode, arguments)); 6344 reportError(new AnalysisError.con2(_source, token.offset, token.length, erro rCode, arguments));
6371 } 6345 }
6372 6346
6373 /** 6347 /**
6374 * Skips a block with all containing blocks. 6348 * Skips a block with all containing blocks.
6375 */ 6349 */
6376 void skipBlock() { 6350 void skipBlock() {
6377 _currentToken = (_currentToken as BeginToken).endToken.next; 6351 _currentToken = (_currentToken as BeginToken).endToken.next;
6378 } 6352 }
6379 6353
6380 /** 6354 /**
6381 * Parse the 'final', 'const', 'var' or type preceding a variable declaration, starting at the 6355 * Parse the 'final', 'const', 'var' or type preceding a variable declaration, starting at the
6382 * given token, without actually creating a type or changing the current token . Return the token 6356 * given token, without actually creating a type or changing the current token . Return the token
6383 * following the type that was parsed, or `null` if the given token is not the first token 6357 * following the type that was parsed, or `null` if the given token is not the first token
6384 * in a valid type. 6358 * in a valid type.
6385 * 6359 *
6386 * <pre> 6360 * <pre>
6387 * finalConstVarOrType ::= 6361 * finalConstVarOrType ::=
6388 * | 'final' type? 6362 * | 'final' type?
6389 * | 'const' type? 6363 * | 'const' type?
6390 * | 'var' 6364 * | 'var'
6391 * | type 6365 * | type
6392 * </pre> 6366 * </pre>
6393 * 6367 *
6394 * @param startToken the token at which parsing is to begin 6368 * @param startToken the token at which parsing is to begin
6395 * @return the token following the type that was parsed 6369 * @return the token following the type that was parsed
6396 */ 6370 */
6397 Token skipFinalConstVarOrType(Token startToken) { 6371 Token skipFinalConstVarOrType(Token startToken) {
6398 if (matches3(startToken, Keyword.FINAL) || matches3(startToken, Keyword.CONS T)) { 6372 if (tokenMatchesKeyword(startToken, Keyword.FINAL) || tokenMatchesKeyword(st artToken, Keyword.CONST)) {
6399 Token next = startToken.next; 6373 Token next = startToken.next;
6400 if (matchesIdentifier2(next)) { 6374 if (tokenMatchesIdentifier(next)) {
6401 Token next2 = next.next; 6375 Token next2 = next.next;
6402 // "Type parameter" or "Type<" or "prefix.Type" 6376 // "Type parameter" or "Type<" or "prefix.Type"
6403 if (matchesIdentifier2(next2) || matches4(next2, TokenType.LT) || matche s4(next2, TokenType.PERIOD)) { 6377 if (tokenMatchesIdentifier(next2) || tokenMatches(next2, TokenType.LT) | | tokenMatches(next2, TokenType.PERIOD)) {
6404 return skipTypeName(next); 6378 return skipTypeName(next);
6405 } 6379 }
6406 // "parameter" 6380 // "parameter"
6407 return next; 6381 return next;
6408 } 6382 }
6409 } else if (matches3(startToken, Keyword.VAR)) { 6383 } else if (tokenMatchesKeyword(startToken, Keyword.VAR)) {
6410 return startToken.next; 6384 return startToken.next;
6411 } else if (matchesIdentifier2(startToken)) { 6385 } else if (tokenMatchesIdentifier(startToken)) {
6412 Token next = startToken.next; 6386 Token next = startToken.next;
6413 if (matchesIdentifier2(next) || matches4(next, TokenType.LT) || matches3(n ext, Keyword.THIS) || (matches4(next, TokenType.PERIOD) && matchesIdentifier2(ne xt.next) && (matchesIdentifier2(next.next.next) || matches4(next.next.next, Toke nType.LT) || matches3(next.next.next, Keyword.THIS)))) { 6387 if (tokenMatchesIdentifier(next) || tokenMatches(next, TokenType.LT) || to kenMatchesKeyword(next, Keyword.THIS) || (tokenMatches(next, TokenType.PERIOD) & & tokenMatchesIdentifier(next.next) && (tokenMatchesIdentifier(next.next.next) | | tokenMatches(next.next.next, TokenType.LT) || tokenMatchesKeyword(next.next.ne xt, Keyword.THIS)))) {
6414 return skipReturnType(startToken); 6388 return skipReturnType(startToken);
6415 } 6389 }
6416 } 6390 }
6417 return null; 6391 return null;
6418 } 6392 }
6419 6393
6420 /** 6394 /**
6421 * Parse a list of formal parameters, starting at the given token, without act ually creating a 6395 * Parse a list of formal parameters, starting at the given token, without act ually creating a
6422 * formal parameter list or changing the current token. Return the token follo wing the formal 6396 * formal parameter list or changing the current token. Return the token follo wing the formal
6423 * parameter list that was parsed, or `null` if the given token is not the fir st token in a 6397 * parameter list that was parsed, or `null` if the given token is not the fir st token in a
(...skipping 24 matching lines...) Expand all
6448 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']' 6422 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']'
6449 * 6423 *
6450 * namedFormalParameters ::= 6424 * namedFormalParameters ::=
6451 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' 6425 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}'
6452 * </pre> 6426 * </pre>
6453 * 6427 *
6454 * @param startToken the token at which parsing is to begin 6428 * @param startToken the token at which parsing is to begin
6455 * @return the token following the formal parameter list that was parsed 6429 * @return the token following the formal parameter list that was parsed
6456 */ 6430 */
6457 Token skipFormalParameterList(Token startToken) { 6431 Token skipFormalParameterList(Token startToken) {
6458 if (!matches4(startToken, TokenType.OPEN_PAREN)) { 6432 if (!tokenMatches(startToken, TokenType.OPEN_PAREN)) {
6459 return null; 6433 return null;
6460 } 6434 }
6461 Token next = startToken.next; 6435 Token next = startToken.next;
6462 if (matches4(next, TokenType.CLOSE_PAREN)) { 6436 if (tokenMatches(next, TokenType.CLOSE_PAREN)) {
6463 return next.next; 6437 return next.next;
6464 } 6438 }
6465 // 6439 //
6466 // Look to see whether the token after the open parenthesis is something tha t should only occur 6440 // Look to see whether the token after the open parenthesis is something tha t should only occur
6467 // at the beginning of a parameter list. 6441 // at the beginning of a parameter list.
6468 // 6442 //
6469 if (matchesAny(next, [ 6443 if (matchesAny(next, [
6470 TokenType.AT, 6444 TokenType.AT,
6471 TokenType.OPEN_SQUARE_BRACKET, 6445 TokenType.OPEN_SQUARE_BRACKET,
6472 TokenType.OPEN_CURLY_BRACKET]) || matches3(next, Keyword.VOID) || (match esIdentifier2(next) && (matchesAny(next.next, [TokenType.COMMA, TokenType.CLOSE_ PAREN])))) { 6446 TokenType.OPEN_CURLY_BRACKET]) || tokenMatchesKeyword(next, Keyword.VOID ) || (tokenMatchesIdentifier(next) && (matchesAny(next.next, [TokenType.COMMA, T okenType.CLOSE_PAREN])))) {
6473 return skipPastMatchingToken(startToken); 6447 return skipPastMatchingToken(startToken);
6474 } 6448 }
6475 // 6449 //
6476 // Look to see whether the first parameter is a function typed parameter wit hout a return type. 6450 // Look to see whether the first parameter is a function typed parameter wit hout a return type.
6477 // 6451 //
6478 if (matchesIdentifier2(next) && matches4(next.next, TokenType.OPEN_PAREN)) { 6452 if (tokenMatchesIdentifier(next) && tokenMatches(next.next, TokenType.OPEN_P AREN)) {
6479 Token afterParameters = skipFormalParameterList(next.next); 6453 Token afterParameters = skipFormalParameterList(next.next);
6480 if (afterParameters != null && (matchesAny(afterParameters, [TokenType.COM MA, TokenType.CLOSE_PAREN]))) { 6454 if (afterParameters != null && (matchesAny(afterParameters, [TokenType.COM MA, TokenType.CLOSE_PAREN]))) {
6481 return skipPastMatchingToken(startToken); 6455 return skipPastMatchingToken(startToken);
6482 } 6456 }
6483 } 6457 }
6484 // 6458 //
6485 // Look to see whether the first parameter has a type or is a function typed parameter with a 6459 // Look to see whether the first parameter has a type or is a function typed parameter with a
6486 // return type. 6460 // return type.
6487 // 6461 //
6488 Token afterType = skipFinalConstVarOrType(next); 6462 Token afterType = skipFinalConstVarOrType(next);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
6526 * identifier ('.' identifier)? 6500 * identifier ('.' identifier)?
6527 * </pre> 6501 * </pre>
6528 * 6502 *
6529 * @param startToken the token at which parsing is to begin 6503 * @param startToken the token at which parsing is to begin
6530 * @return the token following the prefixed identifier that was parsed 6504 * @return the token following the prefixed identifier that was parsed
6531 */ 6505 */
6532 Token skipPrefixedIdentifier(Token startToken) { 6506 Token skipPrefixedIdentifier(Token startToken) {
6533 Token token = skipSimpleIdentifier(startToken); 6507 Token token = skipSimpleIdentifier(startToken);
6534 if (token == null) { 6508 if (token == null) {
6535 return null; 6509 return null;
6536 } else if (!matches4(token, TokenType.PERIOD)) { 6510 } else if (!tokenMatches(token, TokenType.PERIOD)) {
6537 return token; 6511 return token;
6538 } 6512 }
6539 return skipSimpleIdentifier(token.next); 6513 return skipSimpleIdentifier(token.next);
6540 } 6514 }
6541 6515
6542 /** 6516 /**
6543 * Parse a return type, starting at the given token, without actually creating a return type or 6517 * Parse a return type, starting at the given token, without actually creating a return type or
6544 * changing the current token. Return the token following the return type that was parsed, or 6518 * changing the current token. Return the token following the return type that was parsed, or
6545 * `null` if the given token is not the first token in a valid return type. 6519 * `null` if the given token is not the first token in a valid return type.
6546 * 6520 *
6547 * This method must be kept in sync with [parseReturnType]. 6521 * This method must be kept in sync with [parseReturnType].
6548 * 6522 *
6549 * <pre> 6523 * <pre>
6550 * returnType ::= 6524 * returnType ::=
6551 * 'void' 6525 * 'void'
6552 * | type 6526 * | type
6553 * </pre> 6527 * </pre>
6554 * 6528 *
6555 * @param startToken the token at which parsing is to begin 6529 * @param startToken the token at which parsing is to begin
6556 * @return the token following the return type that was parsed 6530 * @return the token following the return type that was parsed
6557 */ 6531 */
6558 Token skipReturnType(Token startToken) { 6532 Token skipReturnType(Token startToken) {
6559 if (matches3(startToken, Keyword.VOID)) { 6533 if (tokenMatchesKeyword(startToken, Keyword.VOID)) {
6560 return startToken.next; 6534 return startToken.next;
6561 } else { 6535 } else {
6562 return skipTypeName(startToken); 6536 return skipTypeName(startToken);
6563 } 6537 }
6564 } 6538 }
6565 6539
6566 /** 6540 /**
6567 * Parse a simple identifier, starting at the given token, without actually cr eating a simple 6541 * Parse a simple identifier, starting at the given token, without actually cr eating a simple
6568 * identifier or changing the current token. Return the token following the si mple identifier that 6542 * identifier or changing the current token. Return the token following the si mple identifier that
6569 * was parsed, or `null` if the given token is not the first token in a valid simple 6543 * was parsed, or `null` if the given token is not the first token in a valid simple
6570 * identifier. 6544 * identifier.
6571 * 6545 *
6572 * This method must be kept in sync with [parseSimpleIdentifier]. 6546 * This method must be kept in sync with [parseSimpleIdentifier].
6573 * 6547 *
6574 * <pre> 6548 * <pre>
6575 * identifier ::= 6549 * identifier ::=
6576 * IDENTIFIER 6550 * IDENTIFIER
6577 * </pre> 6551 * </pre>
6578 * 6552 *
6579 * @param startToken the token at which parsing is to begin 6553 * @param startToken the token at which parsing is to begin
6580 * @return the token following the simple identifier that was parsed 6554 * @return the token following the simple identifier that was parsed
6581 */ 6555 */
6582 Token skipSimpleIdentifier(Token startToken) { 6556 Token skipSimpleIdentifier(Token startToken) {
6583 if (matches4(startToken, TokenType.IDENTIFIER) || (matches4(startToken, Toke nType.KEYWORD) && (startToken as KeywordToken).keyword.isPseudoKeyword)) { 6557 if (tokenMatches(startToken, TokenType.IDENTIFIER) || (tokenMatches(startTok en, TokenType.KEYWORD) && (startToken as KeywordToken).keyword.isPseudoKeyword)) {
6584 return startToken.next; 6558 return startToken.next;
6585 } 6559 }
6586 return null; 6560 return null;
6587 } 6561 }
6588 6562
6589 /** 6563 /**
6590 * Parse a string literal that contains interpolations, starting at the given token, without 6564 * Parse a string literal that contains interpolations, starting at the given token, without
6591 * actually creating a string literal or changing the current token. Return th e token following 6565 * actually creating a string literal or changing the current token. Return th e token following
6592 * the string literal that was parsed, or `null` if the given token is not the first token 6566 * the string literal that was parsed, or `null` if the given token is not the first token
6593 * in a valid string literal. 6567 * in a valid string literal.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6656 * stringLiteral ::= 6630 * stringLiteral ::=
6657 * MULTI_LINE_STRING+ 6631 * MULTI_LINE_STRING+
6658 * | SINGLE_LINE_STRING+ 6632 * | SINGLE_LINE_STRING+
6659 * </pre> 6633 * </pre>
6660 * 6634 *
6661 * @param startToken the token at which parsing is to begin 6635 * @param startToken the token at which parsing is to begin
6662 * @return the token following the string literal that was parsed 6636 * @return the token following the string literal that was parsed
6663 */ 6637 */
6664 Token skipStringLiteral(Token startToken) { 6638 Token skipStringLiteral(Token startToken) {
6665 Token token = startToken; 6639 Token token = startToken;
6666 while (token != null && matches4(token, TokenType.STRING)) { 6640 while (token != null && tokenMatches(token, TokenType.STRING)) {
6667 token = token.next; 6641 token = token.next;
6668 TokenType type = token.type; 6642 TokenType type = token.type;
6669 if (identical(type, TokenType.STRING_INTERPOLATION_EXPRESSION) || identica l(type, TokenType.STRING_INTERPOLATION_IDENTIFIER)) { 6643 if (identical(type, TokenType.STRING_INTERPOLATION_EXPRESSION) || identica l(type, TokenType.STRING_INTERPOLATION_IDENTIFIER)) {
6670 token = skipStringInterpolation(token); 6644 token = skipStringInterpolation(token);
6671 } 6645 }
6672 } 6646 }
6673 if (identical(token, startToken)) { 6647 if (identical(token, startToken)) {
6674 return null; 6648 return null;
6675 } 6649 }
6676 return token; 6650 return token;
(...skipping 12 matching lines...) Expand all
6689 * 6663 *
6690 * typeList ::= 6664 * typeList ::=
6691 * type (',' type)* 6665 * type (',' type)*
6692 * </pre> 6666 * </pre>
6693 * 6667 *
6694 * @param startToken the token at which parsing is to begin 6668 * @param startToken the token at which parsing is to begin
6695 * @return the token following the type argument list that was parsed 6669 * @return the token following the type argument list that was parsed
6696 */ 6670 */
6697 Token skipTypeArgumentList(Token startToken) { 6671 Token skipTypeArgumentList(Token startToken) {
6698 Token token = startToken; 6672 Token token = startToken;
6699 if (!matches4(token, TokenType.LT)) { 6673 if (!tokenMatches(token, TokenType.LT)) {
6700 return null; 6674 return null;
6701 } 6675 }
6702 token = skipTypeName(token.next); 6676 token = skipTypeName(token.next);
6703 if (token == null) { 6677 if (token == null) {
6704 return null; 6678 return null;
6705 } 6679 }
6706 while (matches4(token, TokenType.COMMA)) { 6680 while (tokenMatches(token, TokenType.COMMA)) {
6707 token = skipTypeName(token.next); 6681 token = skipTypeName(token.next);
6708 if (token == null) { 6682 if (token == null) {
6709 return null; 6683 return null;
6710 } 6684 }
6711 } 6685 }
6712 if (identical(token.type, TokenType.GT)) { 6686 if (identical(token.type, TokenType.GT)) {
6713 return token.next; 6687 return token.next;
6714 } else if (identical(token.type, TokenType.GT_GT)) { 6688 } else if (identical(token.type, TokenType.GT_GT)) {
6715 Token second = new Token(TokenType.GT, token.offset + 1); 6689 Token second = new Token(TokenType.GT, token.offset + 1);
6716 second.setNextWithoutSettingPrevious(token.next); 6690 second.setNextWithoutSettingPrevious(token.next);
(...skipping 15 matching lines...) Expand all
6732 * </pre> 6706 * </pre>
6733 * 6707 *
6734 * @param startToken the token at which parsing is to begin 6708 * @param startToken the token at which parsing is to begin
6735 * @return the token following the type name that was parsed 6709 * @return the token following the type name that was parsed
6736 */ 6710 */
6737 Token skipTypeName(Token startToken) { 6711 Token skipTypeName(Token startToken) {
6738 Token token = skipPrefixedIdentifier(startToken); 6712 Token token = skipPrefixedIdentifier(startToken);
6739 if (token == null) { 6713 if (token == null) {
6740 return null; 6714 return null;
6741 } 6715 }
6742 if (matches4(token, TokenType.LT)) { 6716 if (tokenMatches(token, TokenType.LT)) {
6743 token = skipTypeArgumentList(token); 6717 token = skipTypeArgumentList(token);
6744 } 6718 }
6745 return token; 6719 return token;
6746 } 6720 }
6747 6721
6748 /** 6722 /**
6749 * Parse a list of type parameters, starting at the given token, without actua lly creating a type 6723 * Parse a list of type parameters, starting at the given token, without actua lly creating a type
6750 * parameter list or changing the current token. Return the token following th e type parameter 6724 * parameter list or changing the current token. Return the token following th e type parameter
6751 * list that was parsed, or `null` if the given token is not the first token i n a valid type 6725 * list that was parsed, or `null` if the given token is not the first token i n a valid type
6752 * parameter list. 6726 * parameter list.
6753 * 6727 *
6754 * This method must be kept in sync with [parseTypeParameterList]. 6728 * This method must be kept in sync with [parseTypeParameterList].
6755 * 6729 *
6756 * <pre> 6730 * <pre>
6757 * typeParameterList ::= 6731 * typeParameterList ::=
6758 * '<' typeParameter (',' typeParameter)* '>' 6732 * '<' typeParameter (',' typeParameter)* '>'
6759 * </pre> 6733 * </pre>
6760 * 6734 *
6761 * @param startToken the token at which parsing is to begin 6735 * @param startToken the token at which parsing is to begin
6762 * @return the token following the type parameter list that was parsed 6736 * @return the token following the type parameter list that was parsed
6763 */ 6737 */
6764 Token skipTypeParameterList(Token startToken) { 6738 Token skipTypeParameterList(Token startToken) {
6765 if (!matches4(startToken, TokenType.LT)) { 6739 if (!tokenMatches(startToken, TokenType.LT)) {
6766 return null; 6740 return null;
6767 } 6741 }
6768 // 6742 //
6769 // We can't skip a type parameter because it can be preceeded by metadata, s o we just assume 6743 // We can't skip a type parameter because it can be preceeded by metadata, s o we just assume
6770 // that everything before the matching end token is valid. 6744 // that everything before the matching end token is valid.
6771 // 6745 //
6772 int depth = 1; 6746 int depth = 1;
6773 Token next = startToken.next; 6747 Token next = startToken.next;
6774 while (depth > 0) { 6748 while (depth > 0) {
6775 if (matches4(next, TokenType.EOF)) { 6749 if (tokenMatches(next, TokenType.EOF)) {
6776 return null; 6750 return null;
6777 } else if (matches4(next, TokenType.LT)) { 6751 } else if (tokenMatches(next, TokenType.LT)) {
6778 depth++; 6752 depth++;
6779 } else if (matches4(next, TokenType.GT)) { 6753 } else if (tokenMatches(next, TokenType.GT)) {
6780 depth--; 6754 depth--;
6781 } else if (matches4(next, TokenType.GT_EQ)) { 6755 } else if (tokenMatches(next, TokenType.GT_EQ)) {
6782 if (depth == 1) { 6756 if (depth == 1) {
6783 Token fakeEquals = new Token(TokenType.EQ, next.offset + 2); 6757 Token fakeEquals = new Token(TokenType.EQ, next.offset + 2);
6784 fakeEquals.setNextWithoutSettingPrevious(next.next); 6758 fakeEquals.setNextWithoutSettingPrevious(next.next);
6785 return fakeEquals; 6759 return fakeEquals;
6786 } 6760 }
6787 depth--; 6761 depth--;
6788 } else if (matches4(next, TokenType.GT_GT)) { 6762 } else if (tokenMatches(next, TokenType.GT_GT)) {
6789 depth -= 2; 6763 depth -= 2;
6790 } else if (matches4(next, TokenType.GT_GT_EQ)) { 6764 } else if (tokenMatches(next, TokenType.GT_GT_EQ)) {
6791 if (depth < 2) { 6765 if (depth < 2) {
6792 return null; 6766 return null;
6793 } else if (depth == 2) { 6767 } else if (depth == 2) {
6794 Token fakeEquals = new Token(TokenType.EQ, next.offset + 2); 6768 Token fakeEquals = new Token(TokenType.EQ, next.offset + 2);
6795 fakeEquals.setNextWithoutSettingPrevious(next.next); 6769 fakeEquals.setNextWithoutSettingPrevious(next.next);
6796 return fakeEquals; 6770 return fakeEquals;
6797 } 6771 }
6798 depth -= 2; 6772 depth -= 2;
6799 } 6773 }
6800 next = next.next; 6774 next = next.next;
6801 } 6775 }
6802 return next; 6776 return next;
6803 } 6777 }
6804 6778
6805 /** 6779 /**
6780 * Return `true` if the given token has the given type.
6781 *
6782 * @param token the token being tested
6783 * @param type the type of token that is being tested for
6784 * @return `true` if the given token has the given type
6785 */
6786 bool tokenMatches(Token token, TokenType type) => identical(token.type, type);
6787
6788 /**
6789 * Return `true` if the given token is a valid identifier. Valid identifiers i nclude
6790 * built-in identifiers (pseudo-keywords).
6791 *
6792 * @return `true` if the given token is a valid identifier
6793 */
6794 bool tokenMatchesIdentifier(Token token) => tokenMatches(token, TokenType.IDEN TIFIER) || (tokenMatches(token, TokenType.KEYWORD) && (token as KeywordToken).ke yword.isPseudoKeyword);
6795
6796 /**
6797 * Return `true` if the given token matches the given keyword.
6798 *
6799 * @param token the token being tested
6800 * @param keyword the keyword that is being tested for
6801 * @return `true` if the given token matches the given keyword
6802 */
6803 bool tokenMatchesKeyword(Token token, Keyword keyword) => identical(token.type , TokenType.KEYWORD) && identical((token as KeywordToken).keyword, keyword);
6804
6805 /**
6806 * Translate the characters at the given index in the given string, appending the translated 6806 * Translate the characters at the given index in the given string, appending the translated
6807 * character to the given builder. The index is assumed to be valid. 6807 * character to the given builder. The index is assumed to be valid.
6808 * 6808 *
6809 * @param builder the builder to which the translated character is to be appen ded 6809 * @param builder the builder to which the translated character is to be appen ded
6810 * @param lexeme the string containing the character(s) to be translated 6810 * @param lexeme the string containing the character(s) to be translated
6811 * @param index the index of the character to be translated 6811 * @param index the index of the character to be translated
6812 * @return the index of the next character to be translated 6812 * @return the index of the next character to be translated
6813 */ 6813 */
6814 int translateCharacter(JavaStringBuilder builder, String lexeme, int index) { 6814 int translateCharacter(JavaStringBuilder builder, String lexeme, int index) {
6815 int currentChar = lexeme.codeUnitAt(index); 6815 int currentChar = lexeme.codeUnitAt(index);
(...skipping 24 matching lines...) Expand all
6840 builder.appendChar(0xC); 6840 builder.appendChar(0xC);
6841 } else if (currentChar == 0x62) { 6841 } else if (currentChar == 0x62) {
6842 builder.appendChar(0x8); 6842 builder.appendChar(0x8);
6843 } else if (currentChar == 0x74) { 6843 } else if (currentChar == 0x74) {
6844 builder.appendChar(0x9); 6844 builder.appendChar(0x9);
6845 } else if (currentChar == 0x76) { 6845 } else if (currentChar == 0x76) {
6846 builder.appendChar(0xB); 6846 builder.appendChar(0xB);
6847 } else if (currentChar == 0x78) { 6847 } else if (currentChar == 0x78) {
6848 if (currentIndex + 2 >= length) { 6848 if (currentIndex + 2 >= length) {
6849 // Illegal escape sequence: not enough hex digits 6849 // Illegal escape sequence: not enough hex digits
6850 reportError13(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6850 reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6851 return length; 6851 return length;
6852 } 6852 }
6853 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); 6853 int firstDigit = lexeme.codeUnitAt(currentIndex + 1);
6854 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); 6854 int secondDigit = lexeme.codeUnitAt(currentIndex + 2);
6855 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { 6855 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) {
6856 // Illegal escape sequence: invalid hex digit 6856 // Illegal escape sequence: invalid hex digit
6857 reportError13(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6857 reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6858 } else { 6858 } else {
6859 builder.appendChar(((Character.digit(firstDigit, 16) << 4) + Character.d igit(secondDigit, 16))); 6859 builder.appendChar(((Character.digit(firstDigit, 16) << 4) + Character.d igit(secondDigit, 16)));
6860 } 6860 }
6861 return currentIndex + 3; 6861 return currentIndex + 3;
6862 } else if (currentChar == 0x75) { 6862 } else if (currentChar == 0x75) {
6863 currentIndex++; 6863 currentIndex++;
6864 if (currentIndex >= length) { 6864 if (currentIndex >= length) {
6865 // Illegal escape sequence: not enough hex digits 6865 // Illegal escape sequence: not enough hex digits
6866 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6866 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6867 return length; 6867 return length;
6868 } 6868 }
6869 currentChar = lexeme.codeUnitAt(currentIndex); 6869 currentChar = lexeme.codeUnitAt(currentIndex);
6870 if (currentChar == 0x7B) { 6870 if (currentChar == 0x7B) {
6871 currentIndex++; 6871 currentIndex++;
6872 if (currentIndex >= length) { 6872 if (currentIndex >= length) {
6873 // Illegal escape sequence: incomplete escape 6873 // Illegal escape sequence: incomplete escape
6874 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6874 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []) ;
6875 return length; 6875 return length;
6876 } 6876 }
6877 currentChar = lexeme.codeUnitAt(currentIndex); 6877 currentChar = lexeme.codeUnitAt(currentIndex);
6878 int digitCount = 0; 6878 int digitCount = 0;
6879 int value = 0; 6879 int value = 0;
6880 while (currentChar != 0x7D) { 6880 while (currentChar != 0x7D) {
6881 if (!isHexDigit(currentChar)) { 6881 if (!isHexDigit(currentChar)) {
6882 // Illegal escape sequence: invalid hex digit 6882 // Illegal escape sequence: invalid hex digit
6883 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6883 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, [ ]);
6884 currentIndex++; 6884 currentIndex++;
6885 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) { 6885 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) {
6886 currentIndex++; 6886 currentIndex++;
6887 } 6887 }
6888 return currentIndex + 1; 6888 return currentIndex + 1;
6889 } 6889 }
6890 digitCount++; 6890 digitCount++;
6891 value = (value << 4) + Character.digit(currentChar, 16); 6891 value = (value << 4) + Character.digit(currentChar, 16);
6892 currentIndex++; 6892 currentIndex++;
6893 if (currentIndex >= length) { 6893 if (currentIndex >= length) {
6894 // Illegal escape sequence: incomplete escape 6894 // Illegal escape sequence: incomplete escape
6895 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6895 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, [ ]);
6896 return length; 6896 return length;
6897 } 6897 }
6898 currentChar = lexeme.codeUnitAt(currentIndex); 6898 currentChar = lexeme.codeUnitAt(currentIndex);
6899 } 6899 }
6900 if (digitCount < 1 || digitCount > 6) { 6900 if (digitCount < 1 || digitCount > 6) {
6901 // Illegal escape sequence: not enough or too many hex digits 6901 // Illegal escape sequence: not enough or too many hex digits
6902 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6902 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []) ;
6903 } 6903 }
6904 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex); 6904 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex);
6905 return currentIndex + 1; 6905 return currentIndex + 1;
6906 } else { 6906 } else {
6907 if (currentIndex + 3 >= length) { 6907 if (currentIndex + 3 >= length) {
6908 // Illegal escape sequence: not enough hex digits 6908 // Illegal escape sequence: not enough hex digits
6909 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6909 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []) ;
6910 return length; 6910 return length;
6911 } 6911 }
6912 int firstDigit = currentChar; 6912 int firstDigit = currentChar;
6913 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); 6913 int secondDigit = lexeme.codeUnitAt(currentIndex + 1);
6914 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); 6914 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2);
6915 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); 6915 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3);
6916 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) { 6916 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) {
6917 // Illegal escape sequence: invalid hex digits 6917 // Illegal escape sequence: invalid hex digits
6918 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6918 reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []) ;
6919 } else { 6919 } else {
6920 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), (((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) < < 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16) , index, currentIndex + 3); 6920 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), (((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) < < 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16) , index, currentIndex + 3);
6921 } 6921 }
6922 return currentIndex + 4; 6922 return currentIndex + 4;
6923 } 6923 }
6924 } else { 6924 } else {
6925 builder.appendChar(currentChar); 6925 builder.appendChar(currentChar);
6926 } 6926 }
6927 return currentIndex + 1; 6927 return currentIndex + 1;
6928 } 6928 }
(...skipping 10 matching lines...) Expand all
6939 } 6939 }
6940 6940
6941 /** 6941 /**
6942 * Validate that the given parameter list does not contain any field initializ ers. 6942 * Validate that the given parameter list does not contain any field initializ ers.
6943 * 6943 *
6944 * @param parameterList the parameter list to be validated 6944 * @param parameterList the parameter list to be validated
6945 */ 6945 */
6946 void validateFormalParameterList(FormalParameterList parameterList) { 6946 void validateFormalParameterList(FormalParameterList parameterList) {
6947 for (FormalParameter parameter in parameterList.parameters) { 6947 for (FormalParameter parameter in parameterList.parameters) {
6948 if (parameter is FieldFormalParameter) { 6948 if (parameter is FieldFormalParameter) {
6949 reportError12(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, par ameter.identifier, []); 6949 reportErrorForNode(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR , parameter.identifier, []);
6950 } 6950 }
6951 } 6951 }
6952 } 6952 }
6953 6953
6954 /** 6954 /**
6955 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 6955 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
6956 * keyword if there is one. 6956 * keyword if there is one.
6957 * 6957 *
6958 * @param modifiers the modifiers being validated 6958 * @param modifiers the modifiers being validated
6959 */ 6959 */
6960 Token validateModifiersForClass(Modifiers modifiers) { 6960 Token validateModifiersForClass(Modifiers modifiers) {
6961 validateModifiersForTopLevelDeclaration(modifiers); 6961 validateModifiersForTopLevelDeclaration(modifiers);
6962 if (modifiers.constKeyword != null) { 6962 if (modifiers.constKeyword != null) {
6963 reportError14(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 6963 reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, [ ]);
6964 } 6964 }
6965 if (modifiers.externalKeyword != null) { 6965 if (modifiers.externalKeyword != null) {
6966 reportError14(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, [ ]); 6966 reportErrorForToken(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyw ord, []);
6967 } 6967 }
6968 if (modifiers.finalKeyword != null) { 6968 if (modifiers.finalKeyword != null) {
6969 reportError14(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 6969 reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, [ ]);
6970 } 6970 }
6971 if (modifiers.varKeyword != null) { 6971 if (modifiers.varKeyword != null) {
6972 reportError14(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); 6972 reportErrorForToken(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []);
6973 } 6973 }
6974 return modifiers.abstractKeyword; 6974 return modifiers.abstractKeyword;
6975 } 6975 }
6976 6976
6977 /** 6977 /**
6978 * Validate that the given set of modifiers is appropriate for a constructor a nd return the 6978 * Validate that the given set of modifiers is appropriate for a constructor a nd return the
6979 * 'const' keyword if there is one. 6979 * 'const' keyword if there is one.
6980 * 6980 *
6981 * @param modifiers the modifiers being validated 6981 * @param modifiers the modifiers being validated
6982 * @return the 'const' or 'final' keyword associated with the constructor 6982 * @return the 'const' or 'final' keyword associated with the constructor
6983 */ 6983 */
6984 Token validateModifiersForConstructor(Modifiers modifiers) { 6984 Token validateModifiersForConstructor(Modifiers modifiers) {
6985 if (modifiers.abstractKeyword != null) { 6985 if (modifiers.abstractKeyword != null) {
6986 reportError14(ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abstractKey word, []); 6986 reportErrorForToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abstr actKeyword, []);
6987 } 6987 }
6988 if (modifiers.finalKeyword != null) { 6988 if (modifiers.finalKeyword != null) {
6989 reportError14(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, [ ]); 6989 reportErrorForToken(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyw ord, []);
6990 } 6990 }
6991 if (modifiers.staticKeyword != null) { 6991 if (modifiers.staticKeyword != null) {
6992 reportError14(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword, []); 6992 reportErrorForToken(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKe yword, []);
6993 } 6993 }
6994 if (modifiers.varKeyword != null) { 6994 if (modifiers.varKeyword != null) {
6995 reportError14(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varK eyword, []); 6995 reportErrorForToken(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifier s.varKeyword, []);
6996 } 6996 }
6997 Token externalKeyword = modifiers.externalKeyword; 6997 Token externalKeyword = modifiers.externalKeyword;
6998 Token constKeyword = modifiers.constKeyword; 6998 Token constKeyword = modifiers.constKeyword;
6999 Token factoryKeyword = modifiers.factoryKeyword; 6999 Token factoryKeyword = modifiers.factoryKeyword;
7000 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) { 7000 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) {
7001 reportError14(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []); 7001 reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []);
7002 } 7002 }
7003 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) { 7003 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) {
7004 reportError14(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword, []) ; 7004 reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeywor d, []);
7005 } 7005 }
7006 return constKeyword; 7006 return constKeyword;
7007 } 7007 }
7008 7008
7009 /** 7009 /**
7010 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 7010 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
7011 * 'const' or 'var' keyword if there is one. 7011 * 'const' or 'var' keyword if there is one.
7012 * 7012 *
7013 * @param modifiers the modifiers being validated 7013 * @param modifiers the modifiers being validated
7014 * @return the 'final', 'const' or 'var' keyword associated with the field 7014 * @return the 'final', 'const' or 'var' keyword associated with the field
7015 */ 7015 */
7016 Token validateModifiersForField(Modifiers modifiers) { 7016 Token validateModifiersForField(Modifiers modifiers) {
7017 if (modifiers.abstractKeyword != null) { 7017 if (modifiers.abstractKeyword != null) {
7018 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7018 reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7019 } 7019 }
7020 if (modifiers.externalKeyword != null) { 7020 if (modifiers.externalKeyword != null) {
7021 reportError14(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 7021 reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyw ord, []);
7022 } 7022 }
7023 if (modifiers.factoryKeyword != null) { 7023 if (modifiers.factoryKeyword != null) {
7024 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7024 reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fac toryKeyword, []);
7025 } 7025 }
7026 Token staticKeyword = modifiers.staticKeyword; 7026 Token staticKeyword = modifiers.staticKeyword;
7027 Token constKeyword = modifiers.constKeyword; 7027 Token constKeyword = modifiers.constKeyword;
7028 Token finalKeyword = modifiers.finalKeyword; 7028 Token finalKeyword = modifiers.finalKeyword;
7029 Token varKeyword = modifiers.varKeyword; 7029 Token varKeyword = modifiers.varKeyword;
7030 if (constKeyword != null) { 7030 if (constKeyword != null) {
7031 if (finalKeyword != null) { 7031 if (finalKeyword != null) {
7032 reportError14(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7032 reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
7033 } 7033 }
7034 if (varKeyword != null) { 7034 if (varKeyword != null) {
7035 reportError14(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7035 reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
7036 } 7036 }
7037 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) { 7037 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) {
7038 reportError14(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []); 7038 reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, [ ]);
7039 } 7039 }
7040 } else if (finalKeyword != null) { 7040 } else if (finalKeyword != null) {
7041 if (varKeyword != null) { 7041 if (varKeyword != null) {
7042 reportError14(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7042 reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7043 } 7043 }
7044 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) { 7044 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) {
7045 reportError14(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []); 7045 reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, [ ]);
7046 } 7046 }
7047 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) { 7047 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) {
7048 reportError14(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []); 7048 reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []);
7049 } 7049 }
7050 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7050 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7051 } 7051 }
7052 7052
7053 /** 7053 /**
7054 * Validate that the given set of modifiers is appropriate for a local functio n. 7054 * Validate that the given set of modifiers is appropriate for a local functio n.
7055 * 7055 *
7056 * @param modifiers the modifiers being validated 7056 * @param modifiers the modifiers being validated
7057 */ 7057 */
7058 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) { 7058 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) {
7059 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) { 7059 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) {
7060 reportError13(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER, []); 7060 reportErrorForCurrentToken(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODI FIER, []);
7061 } 7061 }
7062 } 7062 }
7063 7063
7064 /** 7064 /**
7065 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7065 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7066 * 7066 *
7067 * @param modifiers the modifiers being validated 7067 * @param modifiers the modifiers being validated
7068 */ 7068 */
7069 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { 7069 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) {
7070 if (modifiers.abstractKeyword != null) { 7070 if (modifiers.abstractKeyword != null) {
7071 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7071 reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7072 } 7072 }
7073 if (modifiers.constKeyword != null) { 7073 if (modifiers.constKeyword != null) {
7074 reportError14(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7074 reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7075 } 7075 }
7076 if (modifiers.factoryKeyword != null) { 7076 if (modifiers.factoryKeyword != null) {
7077 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7077 reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fac toryKeyword, []);
7078 } 7078 }
7079 if (modifiers.finalKeyword != null) { 7079 if (modifiers.finalKeyword != null) {
7080 reportError14(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7080 reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7081 } 7081 }
7082 if (modifiers.varKeyword != null) { 7082 if (modifiers.varKeyword != null) {
7083 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7083 reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7084 } 7084 }
7085 Token externalKeyword = modifiers.externalKeyword; 7085 Token externalKeyword = modifiers.externalKeyword;
7086 Token staticKeyword = modifiers.staticKeyword; 7086 Token staticKeyword = modifiers.staticKeyword;
7087 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) { 7087 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) {
7088 reportError14(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword, []); 7088 reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword , []);
7089 } 7089 }
7090 } 7090 }
7091 7091
7092 /** 7092 /**
7093 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7093 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7094 * 7094 *
7095 * @param modifiers the modifiers being validated 7095 * @param modifiers the modifiers being validated
7096 */ 7096 */
7097 void validateModifiersForOperator(Modifiers modifiers) { 7097 void validateModifiersForOperator(Modifiers modifiers) {
7098 if (modifiers.abstractKeyword != null) { 7098 if (modifiers.abstractKeyword != null) {
7099 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7099 reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7100 } 7100 }
7101 if (modifiers.constKeyword != null) { 7101 if (modifiers.constKeyword != null) {
7102 reportError14(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7102 reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7103 } 7103 }
7104 if (modifiers.factoryKeyword != null) { 7104 if (modifiers.factoryKeyword != null) {
7105 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7105 reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fac toryKeyword, []);
7106 } 7106 }
7107 if (modifiers.finalKeyword != null) { 7107 if (modifiers.finalKeyword != null) {
7108 reportError14(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7108 reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7109 } 7109 }
7110 if (modifiers.staticKeyword != null) { 7110 if (modifiers.staticKeyword != null) {
7111 reportError14(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [] ); 7111 reportErrorForToken(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeywo rd, []);
7112 } 7112 }
7113 if (modifiers.varKeyword != null) { 7113 if (modifiers.varKeyword != null) {
7114 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7114 reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7115 } 7115 }
7116 } 7116 }
7117 7117
7118 /** 7118 /**
7119 * Validate that the given set of modifiers is appropriate for a top-level dec laration. 7119 * Validate that the given set of modifiers is appropriate for a top-level dec laration.
7120 * 7120 *
7121 * @param modifiers the modifiers being validated 7121 * @param modifiers the modifiers being validated
7122 */ 7122 */
7123 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) { 7123 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) {
7124 if (modifiers.factoryKeyword != null) { 7124 if (modifiers.factoryKeyword != null) {
7125 reportError14(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fac toryKeyword, []); 7125 reportErrorForToken(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifie rs.factoryKeyword, []);
7126 } 7126 }
7127 if (modifiers.staticKeyword != null) { 7127 if (modifiers.staticKeyword != null) {
7128 reportError14(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stat icKeyword, []); 7128 reportErrorForToken(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifier s.staticKeyword, []);
7129 } 7129 }
7130 } 7130 }
7131 7131
7132 /** 7132 /**
7133 * Validate that the given set of modifiers is appropriate for a top-level fun ction. 7133 * Validate that the given set of modifiers is appropriate for a top-level fun ction.
7134 * 7134 *
7135 * @param modifiers the modifiers being validated 7135 * @param modifiers the modifiers being validated
7136 */ 7136 */
7137 void validateModifiersForTopLevelFunction(Modifiers modifiers) { 7137 void validateModifiersForTopLevelFunction(Modifiers modifiers) {
7138 validateModifiersForTopLevelDeclaration(modifiers); 7138 validateModifiersForTopLevelDeclaration(modifiers);
7139 if (modifiers.abstractKeyword != null) { 7139 if (modifiers.abstractKeyword != null) {
7140 reportError13(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []); 7140 reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, [] );
7141 } 7141 }
7142 if (modifiers.constKeyword != null) { 7142 if (modifiers.constKeyword != null) {
7143 reportError14(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 7143 reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, [ ]);
7144 } 7144 }
7145 if (modifiers.finalKeyword != null) { 7145 if (modifiers.finalKeyword != null) {
7146 reportError14(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 7146 reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, [ ]);
7147 } 7147 }
7148 if (modifiers.varKeyword != null) { 7148 if (modifiers.varKeyword != null) {
7149 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7149 reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7150 } 7150 }
7151 } 7151 }
7152 7152
7153 /** 7153 /**
7154 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 7154 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
7155 * 'const' or 'var' keyword if there is one. 7155 * 'const' or 'var' keyword if there is one.
7156 * 7156 *
7157 * @param modifiers the modifiers being validated 7157 * @param modifiers the modifiers being validated
7158 * @return the 'final', 'const' or 'var' keyword associated with the field 7158 * @return the 'final', 'const' or 'var' keyword associated with the field
7159 */ 7159 */
7160 Token validateModifiersForTopLevelVariable(Modifiers modifiers) { 7160 Token validateModifiersForTopLevelVariable(Modifiers modifiers) {
7161 validateModifiersForTopLevelDeclaration(modifiers); 7161 validateModifiersForTopLevelDeclaration(modifiers);
7162 if (modifiers.abstractKeyword != null) { 7162 if (modifiers.abstractKeyword != null) {
7163 reportError13(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []); 7163 reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, [] );
7164 } 7164 }
7165 if (modifiers.externalKeyword != null) { 7165 if (modifiers.externalKeyword != null) {
7166 reportError14(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 7166 reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyw ord, []);
7167 } 7167 }
7168 Token constKeyword = modifiers.constKeyword; 7168 Token constKeyword = modifiers.constKeyword;
7169 Token finalKeyword = modifiers.finalKeyword; 7169 Token finalKeyword = modifiers.finalKeyword;
7170 Token varKeyword = modifiers.varKeyword; 7170 Token varKeyword = modifiers.varKeyword;
7171 if (constKeyword != null) { 7171 if (constKeyword != null) {
7172 if (finalKeyword != null) { 7172 if (finalKeyword != null) {
7173 reportError14(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7173 reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
7174 } 7174 }
7175 if (varKeyword != null) { 7175 if (varKeyword != null) {
7176 reportError14(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7176 reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
7177 } 7177 }
7178 } else if (finalKeyword != null) { 7178 } else if (finalKeyword != null) {
7179 if (varKeyword != null) { 7179 if (varKeyword != null) {
7180 reportError14(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7180 reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7181 } 7181 }
7182 } 7182 }
7183 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7183 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7184 } 7184 }
7185 7185
7186 /** 7186 /**
7187 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 7187 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
7188 * keyword if there is one. 7188 * keyword if there is one.
7189 * 7189 *
7190 * @param modifiers the modifiers being validated 7190 * @param modifiers the modifiers being validated
7191 */ 7191 */
7192 void validateModifiersForTypedef(Modifiers modifiers) { 7192 void validateModifiersForTypedef(Modifiers modifiers) {
7193 validateModifiersForTopLevelDeclaration(modifiers); 7193 validateModifiersForTopLevelDeclaration(modifiers);
7194 if (modifiers.abstractKeyword != null) { 7194 if (modifiers.abstractKeyword != null) {
7195 reportError14(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword, []); 7195 reportErrorForToken(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKe yword, []);
7196 } 7196 }
7197 if (modifiers.constKeyword != null) { 7197 if (modifiers.constKeyword != null) {
7198 reportError14(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []); 7198 reportErrorForToken(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []);
7199 } 7199 }
7200 if (modifiers.externalKeyword != null) { 7200 if (modifiers.externalKeyword != null) {
7201 reportError14(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []); 7201 reportErrorForToken(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKe yword, []);
7202 } 7202 }
7203 if (modifiers.finalKeyword != null) { 7203 if (modifiers.finalKeyword != null) {
7204 reportError14(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); 7204 reportErrorForToken(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []);
7205 } 7205 }
7206 if (modifiers.varKeyword != null) { 7206 if (modifiers.varKeyword != null) {
7207 reportError14(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); 7207 reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []) ;
7208 } 7208 }
7209 } 7209 }
7210 } 7210 }
7211 7211
7212 /** 7212 /**
7213 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token. 7213 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
7214 */ 7214 */
7215 class Parser_SyntheticKeywordToken extends KeywordToken { 7215 class Parser_SyntheticKeywordToken extends KeywordToken {
7216 /** 7216 /**
7217 * Initialize a newly created token to represent the given keyword. 7217 * Initialize a newly created token to represent the given keyword.
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
7694 */ 7694 */
7695 class ResolutionCopier implements AstVisitor<bool> { 7695 class ResolutionCopier implements AstVisitor<bool> {
7696 /** 7696 /**
7697 * Copy resolution data from one node to another. 7697 * Copy resolution data from one node to another.
7698 * 7698 *
7699 * @param fromNode the node from which resolution information will be copied 7699 * @param fromNode the node from which resolution information will be copied
7700 * @param toNode the node to which resolution information will be copied 7700 * @param toNode the node to which resolution information will be copied
7701 */ 7701 */
7702 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 7702 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
7703 ResolutionCopier copier = new ResolutionCopier(); 7703 ResolutionCopier copier = new ResolutionCopier();
7704 copier.isEqual(fromNode, toNode); 7704 copier.isEqualNodes(fromNode, toNode);
7705 } 7705 }
7706 7706
7707 /** 7707 /**
7708 * The AST node with which the node being visited is to be compared. This is o nly valid at the 7708 * The AST node with which the node being visited is to be compared. This is o nly valid at the
7709 * beginning of each visit method (until [isEqual] is invoked). 7709 * beginning of each visit method (until [isEqualNodes] is invoked).
7710 */ 7710 */
7711 AstNode _toNode; 7711 AstNode _toNode;
7712 7712
7713 bool visitAdjacentStrings(AdjacentStrings node) { 7713 bool visitAdjacentStrings(AdjacentStrings node) {
7714 AdjacentStrings toNode = this._toNode as AdjacentStrings; 7714 AdjacentStrings toNode = this._toNode as AdjacentStrings;
7715 return isEqual2(node.strings, toNode.strings); 7715 return isEqualNodeLists(node.strings, toNode.strings);
7716 } 7716 }
7717 7717
7718 bool visitAnnotation(Annotation node) { 7718 bool visitAnnotation(Annotation node) {
7719 Annotation toNode = this._toNode as Annotation; 7719 Annotation toNode = this._toNode as Annotation;
7720 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(nod e.atSign, toNode.atSign), isEqual(node.name, toNode.name)), isEqual3(node.period , toNode.period)), isEqual(node.constructorName, toNode.constructorName)), isEqu al(node.arguments, toNode.arguments))) { 7720 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualToken s(node.atSign, toNode.atSign), isEqualNodes(node.name, toNode.name)), isEqualTok ens(node.period, toNode.period)), isEqualNodes(node.constructorName, toNode.cons tructorName)), isEqualNodes(node.arguments, toNode.arguments))) {
7721 toNode.element = node.element; 7721 toNode.element = node.element;
7722 return true; 7722 return true;
7723 } 7723 }
7724 return false; 7724 return false;
7725 } 7725 }
7726 7726
7727 bool visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 7727 bool visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
7728 ArgumentDefinitionTest toNode = this._toNode as ArgumentDefinitionTest; 7728 ArgumentDefinitionTest toNode = this._toNode as ArgumentDefinitionTest;
7729 if (javaBooleanAnd(isEqual3(node.question, toNode.question), isEqual(node.id entifier, toNode.identifier))) { 7729 if (javaBooleanAnd(isEqualTokens(node.question, toNode.question), isEqualNod es(node.identifier, toNode.identifier))) {
7730 toNode.propagatedType = node.propagatedType; 7730 toNode.propagatedType = node.propagatedType;
7731 toNode.staticType = node.staticType; 7731 toNode.staticType = node.staticType;
7732 return true; 7732 return true;
7733 } 7733 }
7734 return false; 7734 return false;
7735 } 7735 }
7736 7736
7737 bool visitArgumentList(ArgumentList node) { 7737 bool visitArgumentList(ArgumentList node) {
7738 ArgumentList toNode = this._toNode as ArgumentList; 7738 ArgumentList toNode = this._toNode as ArgumentList;
7739 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftParenthesis, toNode.l eftParenthesis), isEqual2(node.arguments, toNode.arguments)), isEqual3(node.righ tParenthesis, toNode.rightParenthesis)); 7739 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftParenthesis, toN ode.leftParenthesis), isEqualNodeLists(node.arguments, toNode.arguments)), isEqu alTokens(node.rightParenthesis, toNode.rightParenthesis));
7740 } 7740 }
7741 7741
7742 bool visitAsExpression(AsExpression node) { 7742 bool visitAsExpression(AsExpression node) {
7743 AsExpression toNode = this._toNode as AsExpression; 7743 AsExpression toNode = this._toNode as AsExpression;
7744 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.expression, toNode.expression ), isEqual3(node.asOperator, toNode.asOperator)), isEqual(node.type, toNode.type ))) { 7744 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.expression, toNode.expre ssion), isEqualTokens(node.asOperator, toNode.asOperator)), isEqualNodes(node.ty pe, toNode.type))) {
7745 toNode.propagatedType = node.propagatedType; 7745 toNode.propagatedType = node.propagatedType;
7746 toNode.staticType = node.staticType; 7746 toNode.staticType = node.staticType;
7747 return true; 7747 return true;
7748 } 7748 }
7749 return false; 7749 return false;
7750 } 7750 }
7751 7751
7752 bool visitAssertStatement(AssertStatement node) { 7752 bool visitAssertStatement(AssertStatement node) {
7753 AssertStatement toNode = this._toNode as AssertStatement; 7753 AssertStatement toNode = this._toNode as AssertStatement;
7754 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3( node.keyword, toNode.keyword), isEqual3(node.leftParenthesis, toNode.leftParenth esis)), isEqual(node.condition, toNode.condition)), isEqual3(node.rightParenthes is, toNode.rightParenthesis)), isEqual3(node.semicolon, toNode.semicolon)); 7754 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTo kens(node.keyword, toNode.keyword), isEqualTokens(node.leftParenthesis, toNode.l eftParenthesis)), isEqualNodes(node.condition, toNode.condition)), isEqualTokens (node.rightParenthesis, toNode.rightParenthesis)), isEqualTokens(node.semicolon, toNode.semicolon));
7755 } 7755 }
7756 7756
7757 bool visitAssignmentExpression(AssignmentExpression node) { 7757 bool visitAssignmentExpression(AssignmentExpression node) {
7758 AssignmentExpression toNode = this._toNode as AssignmentExpression; 7758 AssignmentExpression toNode = this._toNode as AssignmentExpression;
7759 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.leftHandSide, toNode.leftHand Side), isEqual3(node.operator, toNode.operator)), isEqual(node.rightHandSide, to Node.rightHandSide))) { 7759 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.leftHandSide, toNode.lef tHandSide), isEqualTokens(node.operator, toNode.operator)), isEqualNodes(node.ri ghtHandSide, toNode.rightHandSide))) {
7760 toNode.propagatedElement = node.propagatedElement; 7760 toNode.propagatedElement = node.propagatedElement;
7761 toNode.propagatedType = node.propagatedType; 7761 toNode.propagatedType = node.propagatedType;
7762 toNode.staticElement = node.staticElement; 7762 toNode.staticElement = node.staticElement;
7763 toNode.staticType = node.staticType; 7763 toNode.staticType = node.staticType;
7764 return true; 7764 return true;
7765 } 7765 }
7766 return false; 7766 return false;
7767 } 7767 }
7768 7768
7769 bool visitBinaryExpression(BinaryExpression node) { 7769 bool visitBinaryExpression(BinaryExpression node) {
7770 BinaryExpression toNode = this._toNode as BinaryExpression; 7770 BinaryExpression toNode = this._toNode as BinaryExpression;
7771 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.leftOperand, toNode.leftOpera nd), isEqual3(node.operator, toNode.operator)), isEqual(node.rightOperand, toNod e.rightOperand))) { 7771 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.leftOperand, toNode.left Operand), isEqualTokens(node.operator, toNode.operator)), isEqualNodes(node.righ tOperand, toNode.rightOperand))) {
7772 toNode.propagatedElement = node.propagatedElement; 7772 toNode.propagatedElement = node.propagatedElement;
7773 toNode.propagatedType = node.propagatedType; 7773 toNode.propagatedType = node.propagatedType;
7774 toNode.staticElement = node.staticElement; 7774 toNode.staticElement = node.staticElement;
7775 toNode.staticType = node.staticType; 7775 toNode.staticType = node.staticType;
7776 return true; 7776 return true;
7777 } 7777 }
7778 return false; 7778 return false;
7779 } 7779 }
7780 7780
7781 bool visitBlock(Block node) { 7781 bool visitBlock(Block node) {
7782 Block toNode = this._toNode as Block; 7782 Block toNode = this._toNode as Block;
7783 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftBracket, toNode.leftB racket), isEqual2(node.statements, toNode.statements)), isEqual3(node.rightBrack et, toNode.rightBracket)); 7783 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftBracket, toNode. leftBracket), isEqualNodeLists(node.statements, toNode.statements)), isEqualToke ns(node.rightBracket, toNode.rightBracket));
7784 } 7784 }
7785 7785
7786 bool visitBlockFunctionBody(BlockFunctionBody node) { 7786 bool visitBlockFunctionBody(BlockFunctionBody node) {
7787 BlockFunctionBody toNode = this._toNode as BlockFunctionBody; 7787 BlockFunctionBody toNode = this._toNode as BlockFunctionBody;
7788 return isEqual(node.block, toNode.block); 7788 return isEqualNodes(node.block, toNode.block);
7789 } 7789 }
7790 7790
7791 bool visitBooleanLiteral(BooleanLiteral node) { 7791 bool visitBooleanLiteral(BooleanLiteral node) {
7792 BooleanLiteral toNode = this._toNode as BooleanLiteral; 7792 BooleanLiteral toNode = this._toNode as BooleanLiteral;
7793 if (javaBooleanAnd(isEqual3(node.literal, toNode.literal), identical(node.va lue, toNode.value))) { 7793 if (javaBooleanAnd(isEqualTokens(node.literal, toNode.literal), identical(no de.value, toNode.value))) {
7794 toNode.propagatedType = node.propagatedType; 7794 toNode.propagatedType = node.propagatedType;
7795 toNode.staticType = node.staticType; 7795 toNode.staticType = node.staticType;
7796 return true; 7796 return true;
7797 } 7797 }
7798 return false; 7798 return false;
7799 } 7799 }
7800 7800
7801 bool visitBreakStatement(BreakStatement node) { 7801 bool visitBreakStatement(BreakStatement node) {
7802 BreakStatement toNode = this._toNode as BreakStatement; 7802 BreakStatement toNode = this._toNode as BreakStatement;
7803 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.label, toNode.label)), isEqual3(node.semicolon, toNode.semicolon)) ; 7803 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyw ord), isEqualNodes(node.label, toNode.label)), isEqualTokens(node.semicolon, toN ode.semicolon));
7804 } 7804 }
7805 7805
7806 bool visitCascadeExpression(CascadeExpression node) { 7806 bool visitCascadeExpression(CascadeExpression node) {
7807 CascadeExpression toNode = this._toNode as CascadeExpression; 7807 CascadeExpression toNode = this._toNode as CascadeExpression;
7808 if (javaBooleanAnd(isEqual(node.target, toNode.target), isEqual2(node.cascad eSections, toNode.cascadeSections))) { 7808 if (javaBooleanAnd(isEqualNodes(node.target, toNode.target), isEqualNodeList s(node.cascadeSections, toNode.cascadeSections))) {
7809 toNode.propagatedType = node.propagatedType; 7809 toNode.propagatedType = node.propagatedType;
7810 toNode.staticType = node.staticType; 7810 toNode.staticType = node.staticType;
7811 return true; 7811 return true;
7812 } 7812 }
7813 return false; 7813 return false;
7814 } 7814 }
7815 7815
7816 bool visitCatchClause(CatchClause node) { 7816 bool visitCatchClause(CatchClause node) {
7817 CatchClause toNode = this._toNode as CatchClause; 7817 CatchClause toNode = this._toNode as CatchClause;
7818 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(node.onKeyword, toNo de.onKeyword), isEqual(node.exceptionType, toNode.exceptionType)), isEqual3(node .catchKeyword, toNode.catchKeyword)), isEqual3(node.leftParenthesis, toNode.left Parenthesis)), isEqual(node.exceptionParameter, toNode.exceptionParameter)), isE qual3(node.comma, toNode.comma)), isEqual(node.stackTraceParameter, toNode.stack TraceParameter)), isEqual3(node.rightParenthesis, toNode.rightParenthesis)), isE qual(node.body, toNode.body)); 7818 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.onKeyword, toNode.onKeyword), isEqualNodes(node.exceptionType, toNode.exceptionType)), isE qualTokens(node.catchKeyword, toNode.catchKeyword)), isEqualTokens(node.leftPare nthesis, toNode.leftParenthesis)), isEqualNodes(node.exceptionParameter, toNode. exceptionParameter)), isEqualTokens(node.comma, toNode.comma)), isEqualNodes(nod e.stackTraceParameter, toNode.stackTraceParameter)), isEqualTokens(node.rightPar enthesis, toNode.rightParenthesis)), isEqualNodes(node.body, toNode.body));
7819 } 7819 }
7820 7820
7821 bool visitClassDeclaration(ClassDeclaration node) { 7821 bool visitClassDeclaration(ClassDeclaration node) {
7822 ClassDeclaration toNode = this._toNode as ClassDeclaration; 7822 ClassDeclaration toNode = this._toNode as ClassDeclaration;
7823 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd (javaBooleanAnd(isEqual(node.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.abstractKeyword, toNod e.abstractKeyword)), isEqual3(node.classKeyword, toNode.classKeyword)), isEqual( node.name, toNode.name)), isEqual(node.typeParameters, toNode.typeParameters)), isEqual(node.extendsClause, toNode.extendsClause)), isEqual(node.withClause, toN ode.withClause)), isEqual(node.implementsClause, toNode.implementsClause)), isEq ual3(node.leftBracket, toNode.leftBracket)), isEqual2(node.members, toNode.membe rs)), isEqual3(node.rightBracket, toNode.rightBracket)); 7823 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd (javaBooleanAnd(isEqualNodes(node.documentationComment, toNode.documentationComm ent), isEqualNodeLists(node.metadata, toNode.metadata)), isEqualTokens(node.abst ractKeyword, toNode.abstractKeyword)), isEqualTokens(node.classKeyword, toNode.c lassKeyword)), isEqualNodes(node.name, toNode.name)), isEqualNodes(node.typePara meters, toNode.typeParameters)), isEqualNodes(node.extendsClause, toNode.extends Clause)), isEqualNodes(node.withClause, toNode.withClause)), isEqualNodes(node.i mplementsClause, toNode.implementsClause)), isEqualTokens(node.leftBracket, toNo de.leftBracket)), isEqualNodeLists(node.members, toNode.members)), isEqualTokens (node.rightBracket, toNode.rightBracket));
7824 } 7824 }
7825 7825
7826 bool visitClassTypeAlias(ClassTypeAlias node) { 7826 bool visitClassTypeAlias(ClassTypeAlias node) {
7827 ClassTypeAlias toNode = this._toNode as ClassTypeAlias; 7827 ClassTypeAlias toNode = this._toNode as ClassTypeAlias;
7828 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd (isEqual(node.documentationComment, toNode.documentationComment), isEqual2(node. metadata, toNode.metadata)), isEqual3(node.keyword, toNode.keyword)), isEqual(no de.name, toNode.name)), isEqual(node.typeParameters, toNode.typeParameters)), is Equal3(node.equals, toNode.equals)), isEqual3(node.abstractKeyword, toNode.abstr actKeyword)), isEqual(node.superclass, toNode.superclass)), isEqual(node.withCla use, toNode.withClause)), isEqual(node.implementsClause, toNode.implementsClause )), isEqual3(node.semicolon, toNode.semicolon)); 7828 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd (isEqualNodes(node.documentationComment, toNode.documentationComment), isEqualNo deLists(node.metadata, toNode.metadata)), isEqualTokens(node.keyword, toNode.key word)), isEqualNodes(node.name, toNode.name)), isEqualNodes(node.typeParameters, toNode.typeParameters)), isEqualTokens(node.equals, toNode.equals)), isEqualTok ens(node.abstractKeyword, toNode.abstractKeyword)), isEqualNodes(node.superclass , toNode.superclass)), isEqualNodes(node.withClause, toNode.withClause)), isEqua lNodes(node.implementsClause, toNode.implementsClause)), isEqualTokens(node.semi colon, toNode.semicolon));
7829 } 7829 }
7830 7830
7831 bool visitComment(Comment node) { 7831 bool visitComment(Comment node) {
7832 Comment toNode = this._toNode as Comment; 7832 Comment toNode = this._toNode as Comment;
7833 return isEqual2(node.references, toNode.references); 7833 return isEqualNodeLists(node.references, toNode.references);
7834 } 7834 }
7835 7835
7836 bool visitCommentReference(CommentReference node) { 7836 bool visitCommentReference(CommentReference node) {
7837 CommentReference toNode = this._toNode as CommentReference; 7837 CommentReference toNode = this._toNode as CommentReference;
7838 return javaBooleanAnd(isEqual3(node.newKeyword, toNode.newKeyword), isEqual( node.identifier, toNode.identifier)); 7838 return javaBooleanAnd(isEqualTokens(node.newKeyword, toNode.newKeyword), isE qualNodes(node.identifier, toNode.identifier));
7839 } 7839 }
7840 7840
7841 bool visitCompilationUnit(CompilationUnit node) { 7841 bool visitCompilationUnit(CompilationUnit node) {
7842 CompilationUnit toNode = this._toNode as CompilationUnit; 7842 CompilationUnit toNode = this._toNode as CompilationUnit;
7843 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(nod e.beginToken, toNode.beginToken), isEqual(node.scriptTag, toNode.scriptTag)), is Equal2(node.directives, toNode.directives)), isEqual2(node.declarations, toNode. declarations)), isEqual3(node.endToken, toNode.endToken))) { 7843 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualToken s(node.beginToken, toNode.beginToken), isEqualNodes(node.scriptTag, toNode.scrip tTag)), isEqualNodeLists(node.directives, toNode.directives)), isEqualNodeLists( node.declarations, toNode.declarations)), isEqualTokens(node.endToken, toNode.en dToken))) {
7844 toNode.element = node.element; 7844 toNode.element = node.element;
7845 return true; 7845 return true;
7846 } 7846 }
7847 return false; 7847 return false;
7848 } 7848 }
7849 7849
7850 bool visitConditionalExpression(ConditionalExpression node) { 7850 bool visitConditionalExpression(ConditionalExpression node) {
7851 ConditionalExpression toNode = this._toNode as ConditionalExpression; 7851 ConditionalExpression toNode = this._toNode as ConditionalExpression;
7852 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node .condition, toNode.condition), isEqual3(node.question, toNode.question)), isEqua l(node.thenExpression, toNode.thenExpression)), isEqual3(node.colon, toNode.colo n)), isEqual(node.elseExpression, toNode.elseExpression))) { 7852 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes (node.condition, toNode.condition), isEqualTokens(node.question, toNode.question )), isEqualNodes(node.thenExpression, toNode.thenExpression)), isEqualTokens(nod e.colon, toNode.colon)), isEqualNodes(node.elseExpression, toNode.elseExpression ))) {
7853 toNode.propagatedType = node.propagatedType; 7853 toNode.propagatedType = node.propagatedType;
7854 toNode.staticType = node.staticType; 7854 toNode.staticType = node.staticType;
7855 return true; 7855 return true;
7856 } 7856 }
7857 return false; 7857 return false;
7858 } 7858 }
7859 7859
7860 bool visitConstructorDeclaration(ConstructorDeclaration node) { 7860 bool visitConstructorDeclaration(ConstructorDeclaration node) {
7861 ConstructorDeclaration toNode = this._toNode as ConstructorDeclaration; 7861 ConstructorDeclaration toNode = this._toNode as ConstructorDeclaration;
7862 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(ja vaBooleanAnd(javaBooleanAnd(isEqual(node.documentationComment, toNode.documentat ionComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.externalKe yword, toNode.externalKeyword)), isEqual3(node.constKeyword, toNode.constKeyword )), isEqual3(node.factoryKeyword, toNode.factoryKeyword)), isEqual(node.returnTy pe, toNode.returnType)), isEqual3(node.period, toNode.period)), isEqual(node.nam e, toNode.name)), isEqual(node.parameters, toNode.parameters)), isEqual3(node.se parator, toNode.separator)), isEqual2(node.initializers, toNode.initializers)), isEqual(node.redirectedConstructor, toNode.redirectedConstructor)), isEqual(node .body, toNode.body))) { 7862 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(ja vaBooleanAnd(javaBooleanAnd(isEqualNodes(node.documentationComment, toNode.docum entationComment), isEqualNodeLists(node.metadata, toNode.metadata)), isEqualToke ns(node.externalKeyword, toNode.externalKeyword)), isEqualTokens(node.constKeywo rd, toNode.constKeyword)), isEqualTokens(node.factoryKeyword, toNode.factoryKeyw ord)), isEqualNodes(node.returnType, toNode.returnType)), isEqualTokens(node.per iod, toNode.period)), isEqualNodes(node.name, toNode.name)), isEqualNodes(node.p arameters, toNode.parameters)), isEqualTokens(node.separator, toNode.separator)) , isEqualNodeLists(node.initializers, toNode.initializers)), isEqualNodes(node.r edirectedConstructor, toNode.redirectedConstructor)), isEqualNodes(node.body, to Node.body))) {
7863 toNode.element = node.element; 7863 toNode.element = node.element;
7864 return true; 7864 return true;
7865 } 7865 }
7866 return false; 7866 return false;
7867 } 7867 }
7868 7868
7869 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 7869 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
7870 ConstructorFieldInitializer toNode = this._toNode as ConstructorFieldInitial izer; 7870 ConstructorFieldInitializer toNode = this._toNode as ConstructorFieldInitial izer;
7871 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3( node.keyword, toNode.keyword), isEqual3(node.period, toNode.period)), isEqual(no de.fieldName, toNode.fieldName)), isEqual3(node.equals, toNode.equals)), isEqual (node.expression, toNode.expression)); 7871 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTo kens(node.keyword, toNode.keyword), isEqualTokens(node.period, toNode.period)), isEqualNodes(node.fieldName, toNode.fieldName)), isEqualTokens(node.equals, toNo de.equals)), isEqualNodes(node.expression, toNode.expression));
7872 } 7872 }
7873 7873
7874 bool visitConstructorName(ConstructorName node) { 7874 bool visitConstructorName(ConstructorName node) {
7875 ConstructorName toNode = this._toNode as ConstructorName; 7875 ConstructorName toNode = this._toNode as ConstructorName;
7876 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.type, toNode.type), isEqual3( node.period, toNode.period)), isEqual(node.name, toNode.name))) { 7876 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.type, toNode.type), isEq ualTokens(node.period, toNode.period)), isEqualNodes(node.name, toNode.name))) {
7877 toNode.staticElement = node.staticElement; 7877 toNode.staticElement = node.staticElement;
7878 return true; 7878 return true;
7879 } 7879 }
7880 return false; 7880 return false;
7881 } 7881 }
7882 7882
7883 bool visitContinueStatement(ContinueStatement node) { 7883 bool visitContinueStatement(ContinueStatement node) {
7884 ContinueStatement toNode = this._toNode as ContinueStatement; 7884 ContinueStatement toNode = this._toNode as ContinueStatement;
7885 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.label, toNode.label)), isEqual3(node.semicolon, toNode.semicolon)) ; 7885 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyw ord), isEqualNodes(node.label, toNode.label)), isEqualTokens(node.semicolon, toN ode.semicolon));
7886 } 7886 }
7887 7887
7888 bool visitDeclaredIdentifier(DeclaredIdentifier node) { 7888 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
7889 DeclaredIdentifier toNode = this._toNode as DeclaredIdentifier; 7889 DeclaredIdentifier toNode = this._toNode as DeclaredIdentifier;
7890 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.keyword, toNode.keyword)), isEqual(node.type, t oNode.type)), isEqual(node.identifier, toNode.identifier)); 7890 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualTokens(node.keyword, toNode.keyword)), is EqualNodes(node.type, toNode.type)), isEqualNodes(node.identifier, toNode.identi fier));
7891 } 7891 }
7892 7892
7893 bool visitDefaultFormalParameter(DefaultFormalParameter node) { 7893 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
7894 DefaultFormalParameter toNode = this._toNode as DefaultFormalParameter; 7894 DefaultFormalParameter toNode = this._toNode as DefaultFormalParameter;
7895 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.parameter, toNode.parameter), identical(node.kind, toNode.kind)), isEqual3(node.separator, toNode.separator)), isEqual(node.defaultValue, toNode.defaultValue)); 7895 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.parame ter, toNode.parameter), identical(node.kind, toNode.kind)), isEqualTokens(node.s eparator, toNode.separator)), isEqualNodes(node.defaultValue, toNode.defaultValu e));
7896 } 7896 }
7897 7897
7898 bool visitDoStatement(DoStatement node) { 7898 bool visitDoStatement(DoStatement node) {
7899 DoStatement toNode = this._toNode as DoStatement; 7899 DoStatement toNode = this._toNode as DoStatement;
7900 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual3(node.doKeyword, toNode.doKeyword), isEqual(node.bo dy, toNode.body)), isEqual3(node.whileKeyword, toNode.whileKeyword)), isEqual3(n ode.leftParenthesis, toNode.leftParenthesis)), isEqual(node.condition, toNode.co ndition)), isEqual3(node.rightParenthesis, toNode.rightParenthesis)), isEqual3(n ode.semicolon, toNode.semicolon)); 7900 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualTokens(node.doKeyword, toNode.doKeyword), isEqualNod es(node.body, toNode.body)), isEqualTokens(node.whileKeyword, toNode.whileKeywor d)), isEqualTokens(node.leftParenthesis, toNode.leftParenthesis)), isEqualNodes( node.condition, toNode.condition)), isEqualTokens(node.rightParenthesis, toNode. rightParenthesis)), isEqualTokens(node.semicolon, toNode.semicolon));
7901 } 7901 }
7902 7902
7903 bool visitDoubleLiteral(DoubleLiteral node) { 7903 bool visitDoubleLiteral(DoubleLiteral node) {
7904 DoubleLiteral toNode = this._toNode as DoubleLiteral; 7904 DoubleLiteral toNode = this._toNode as DoubleLiteral;
7905 if (javaBooleanAnd(isEqual3(node.literal, toNode.literal), node.value == toN ode.value)) { 7905 if (javaBooleanAnd(isEqualTokens(node.literal, toNode.literal), node.value = = toNode.value)) {
7906 toNode.propagatedType = node.propagatedType; 7906 toNode.propagatedType = node.propagatedType;
7907 toNode.staticType = node.staticType; 7907 toNode.staticType = node.staticType;
7908 return true; 7908 return true;
7909 } 7909 }
7910 return false; 7910 return false;
7911 } 7911 }
7912 7912
7913 bool visitEmptyFunctionBody(EmptyFunctionBody node) { 7913 bool visitEmptyFunctionBody(EmptyFunctionBody node) {
7914 EmptyFunctionBody toNode = this._toNode as EmptyFunctionBody; 7914 EmptyFunctionBody toNode = this._toNode as EmptyFunctionBody;
7915 return isEqual3(node.semicolon, toNode.semicolon); 7915 return isEqualTokens(node.semicolon, toNode.semicolon);
7916 } 7916 }
7917 7917
7918 bool visitEmptyStatement(EmptyStatement node) { 7918 bool visitEmptyStatement(EmptyStatement node) {
7919 EmptyStatement toNode = this._toNode as EmptyStatement; 7919 EmptyStatement toNode = this._toNode as EmptyStatement;
7920 return isEqual3(node.semicolon, toNode.semicolon); 7920 return isEqualTokens(node.semicolon, toNode.semicolon);
7921 } 7921 }
7922 7922
7923 bool visitExportDirective(ExportDirective node) { 7923 bool visitExportDirective(ExportDirective node) {
7924 ExportDirective toNode = this._toNode as ExportDirective; 7924 ExportDirective toNode = this._toNode as ExportDirective;
7925 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(isEqual(node.documentationComment, toNode.documentationComment), isEqual2(nod e.metadata, toNode.metadata)), isEqual3(node.keyword, toNode.keyword)), isEqual( node.uri, toNode.uri)), isEqual2(node.combinators, toNode.combinators)), isEqual 3(node.semicolon, toNode.semicolon))) { 7925 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(isEqualNodes(node.documentationComment, toNode.documentationComment), isEqual NodeLists(node.metadata, toNode.metadata)), isEqualTokens(node.keyword, toNode.k eyword)), isEqualNodes(node.uri, toNode.uri)), isEqualNodeLists(node.combinators , toNode.combinators)), isEqualTokens(node.semicolon, toNode.semicolon))) {
7926 toNode.element = node.element; 7926 toNode.element = node.element;
7927 return true; 7927 return true;
7928 } 7928 }
7929 return false; 7929 return false;
7930 } 7930 }
7931 7931
7932 bool visitExpressionFunctionBody(ExpressionFunctionBody node) { 7932 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
7933 ExpressionFunctionBody toNode = this._toNode as ExpressionFunctionBody; 7933 ExpressionFunctionBody toNode = this._toNode as ExpressionFunctionBody;
7934 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.functionDefinition, toNod e.functionDefinition), isEqual(node.expression, toNode.expression)), isEqual3(no de.semicolon, toNode.semicolon)); 7934 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.functionDefinition, toNode.functionDefinition), isEqualNodes(node.expression, toNode.expression)), i sEqualTokens(node.semicolon, toNode.semicolon));
7935 } 7935 }
7936 7936
7937 bool visitExpressionStatement(ExpressionStatement node) { 7937 bool visitExpressionStatement(ExpressionStatement node) {
7938 ExpressionStatement toNode = this._toNode as ExpressionStatement; 7938 ExpressionStatement toNode = this._toNode as ExpressionStatement;
7939 return javaBooleanAnd(isEqual(node.expression, toNode.expression), isEqual3( node.semicolon, toNode.semicolon)); 7939 return javaBooleanAnd(isEqualNodes(node.expression, toNode.expression), isEq ualTokens(node.semicolon, toNode.semicolon));
7940 } 7940 }
7941 7941
7942 bool visitExtendsClause(ExtendsClause node) { 7942 bool visitExtendsClause(ExtendsClause node) {
7943 ExtendsClause toNode = this._toNode as ExtendsClause; 7943 ExtendsClause toNode = this._toNode as ExtendsClause;
7944 return javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.s uperclass, toNode.superclass)); 7944 return javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNo des(node.superclass, toNode.superclass));
7945 } 7945 }
7946 7946
7947 bool visitFieldDeclaration(FieldDeclaration node) { 7947 bool visitFieldDeclaration(FieldDeclaration node) {
7948 FieldDeclaration toNode = this._toNode as FieldDeclaration; 7948 FieldDeclaration toNode = this._toNode as FieldDeclaration;
7949 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.staticKeyword, toNode.staticKeyword)), isEqual( node.fields, toNode.fields)), isEqual3(node.semicolon, toNode.semicolon)); 7949 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualTokens(node.staticKeyword, toNode.staticK eyword)), isEqualNodes(node.fields, toNode.fields)), isEqualTokens(node.semicolo n, toNode.semicolon));
7950 } 7950 }
7951 7951
7952 bool visitFieldFormalParameter(FieldFormalParameter node) { 7952 bool visitFieldFormalParameter(FieldFormalParameter node) {
7953 FieldFormalParameter toNode = this._toNode as FieldFormalParameter; 7953 FieldFormalParameter toNode = this._toNode as FieldFormalParameter;
7954 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual(node.documentationComment, toNode.documentationComm ent), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.keyword, toNode.k eyword)), isEqual(node.type, toNode.type)), isEqual3(node.thisToken, toNode.this Token)), isEqual3(node.period, toNode.period)), isEqual(node.identifier, toNode. identifier)); 7954 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualNodes(node.documentationComment, toNode.documentatio nComment), isEqualNodeLists(node.metadata, toNode.metadata)), isEqualTokens(node .keyword, toNode.keyword)), isEqualNodes(node.type, toNode.type)), isEqualTokens (node.thisToken, toNode.thisToken)), isEqualTokens(node.period, toNode.period)), isEqualNodes(node.identifier, toNode.identifier));
7955 } 7955 }
7956 7956
7957 bool visitForEachStatement(ForEachStatement node) { 7957 bool visitForEachStatement(ForEachStatement node) {
7958 ForEachStatement toNode = this._toNode as ForEachStatement; 7958 ForEachStatement toNode = this._toNode as ForEachStatement;
7959 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual3(node.forKeyword, toNode.forKeyword), isEqual3(node .leftParenthesis, toNode.leftParenthesis)), isEqual(node.loopVariable, toNode.lo opVariable)), isEqual3(node.inKeyword, toNode.inKeyword)), isEqual(node.iterator , toNode.iterator)), isEqual3(node.rightParenthesis, toNode.rightParenthesis)), isEqual(node.body, toNode.body)); 7959 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualTokens(node.forKeyword, toNode.forKeyword), isEqualT okens(node.leftParenthesis, toNode.leftParenthesis)), isEqualNodes(node.loopVari able, toNode.loopVariable)), isEqualTokens(node.inKeyword, toNode.inKeyword)), i sEqualNodes(node.iterator, toNode.iterator)), isEqualTokens(node.rightParenthesi s, toNode.rightParenthesis)), isEqualNodes(node.body, toNode.body));
7960 } 7960 }
7961 7961
7962 bool visitFormalParameterList(FormalParameterList node) { 7962 bool visitFormalParameterList(FormalParameterList node) {
7963 FormalParameterList toNode = this._toNode as FormalParameterList; 7963 FormalParameterList toNode = this._toNode as FormalParameterList;
7964 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3( node.leftParenthesis, toNode.leftParenthesis), isEqual2(node.parameters, toNode. parameters)), isEqual3(node.leftDelimiter, toNode.leftDelimiter)), isEqual3(node .rightDelimiter, toNode.rightDelimiter)), isEqual3(node.rightParenthesis, toNode .rightParenthesis)); 7964 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTo kens(node.leftParenthesis, toNode.leftParenthesis), isEqualNodeLists(node.parame ters, toNode.parameters)), isEqualTokens(node.leftDelimiter, toNode.leftDelimite r)), isEqualTokens(node.rightDelimiter, toNode.rightDelimiter)), isEqualTokens(n ode.rightParenthesis, toNode.rightParenthesis));
7965 } 7965 }
7966 7966
7967 bool visitForStatement(ForStatement node) { 7967 bool visitForStatement(ForStatement node) {
7968 ForStatement toNode = this._toNode as ForStatement; 7968 ForStatement toNode = this._toNode as ForStatement;
7969 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(node. forKeyword, toNode.forKeyword), isEqual3(node.leftParenthesis, toNode.leftParent hesis)), isEqual(node.variables, toNode.variables)), isEqual(node.initialization , toNode.initialization)), isEqual3(node.leftSeparator, toNode.leftSeparator)), isEqual(node.condition, toNode.condition)), isEqual3(node.rightSeparator, toNode .rightSeparator)), isEqual2(node.updaters, toNode.updaters)), isEqual3(node.righ tParenthesis, toNode.rightParenthesis)), isEqual(node.body, toNode.body)); 7969 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTokens( node.forKeyword, toNode.forKeyword), isEqualTokens(node.leftParenthesis, toNode. leftParenthesis)), isEqualNodes(node.variables, toNode.variables)), isEqualNodes (node.initialization, toNode.initialization)), isEqualTokens(node.leftSeparator, toNode.leftSeparator)), isEqualNodes(node.condition, toNode.condition)), isEqua lTokens(node.rightSeparator, toNode.rightSeparator)), isEqualNodeLists(node.upda ters, toNode.updaters)), isEqualTokens(node.rightParenthesis, toNode.rightParent hesis)), isEqualNodes(node.body, toNode.body));
7970 } 7970 }
7971 7971
7972 bool visitFunctionDeclaration(FunctionDeclaration node) { 7972 bool visitFunctionDeclaration(FunctionDeclaration node) {
7973 FunctionDeclaration toNode = this._toNode as FunctionDeclaration; 7973 FunctionDeclaration toNode = this._toNode as FunctionDeclaration;
7974 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual(node.documentationComment, toNode.documentationComm ent), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.externalKeyword, toNode.externalKeyword)), isEqual(node.returnType, toNode.returnType)), isEqual3 (node.propertyKeyword, toNode.propertyKeyword)), isEqual(node.name, toNode.name) ), isEqual(node.functionExpression, toNode.functionExpression)); 7974 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualNodes(node.documentationComment, toNode.documentatio nComment), isEqualNodeLists(node.metadata, toNode.metadata)), isEqualTokens(node .externalKeyword, toNode.externalKeyword)), isEqualNodes(node.returnType, toNode .returnType)), isEqualTokens(node.propertyKeyword, toNode.propertyKeyword)), isE qualNodes(node.name, toNode.name)), isEqualNodes(node.functionExpression, toNode .functionExpression));
7975 } 7975 }
7976 7976
7977 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { 7977 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
7978 FunctionDeclarationStatement toNode = this._toNode as FunctionDeclarationSta tement; 7978 FunctionDeclarationStatement toNode = this._toNode as FunctionDeclarationSta tement;
7979 return isEqual(node.functionDeclaration, toNode.functionDeclaration); 7979 return isEqualNodes(node.functionDeclaration, toNode.functionDeclaration);
7980 } 7980 }
7981 7981
7982 bool visitFunctionExpression(FunctionExpression node) { 7982 bool visitFunctionExpression(FunctionExpression node) {
7983 FunctionExpression toNode = this._toNode as FunctionExpression; 7983 FunctionExpression toNode = this._toNode as FunctionExpression;
7984 if (javaBooleanAnd(isEqual(node.parameters, toNode.parameters), isEqual(node .body, toNode.body))) { 7984 if (javaBooleanAnd(isEqualNodes(node.parameters, toNode.parameters), isEqual Nodes(node.body, toNode.body))) {
7985 toNode.element = node.element; 7985 toNode.element = node.element;
7986 toNode.propagatedType = node.propagatedType; 7986 toNode.propagatedType = node.propagatedType;
7987 toNode.staticType = node.staticType; 7987 toNode.staticType = node.staticType;
7988 return true; 7988 return true;
7989 } 7989 }
7990 return false; 7990 return false;
7991 } 7991 }
7992 7992
7993 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 7993 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
7994 FunctionExpressionInvocation toNode = this._toNode as FunctionExpressionInvo cation; 7994 FunctionExpressionInvocation toNode = this._toNode as FunctionExpressionInvo cation;
7995 if (javaBooleanAnd(isEqual(node.function, toNode.function), isEqual(node.arg umentList, toNode.argumentList))) { 7995 if (javaBooleanAnd(isEqualNodes(node.function, toNode.function), isEqualNode s(node.argumentList, toNode.argumentList))) {
7996 toNode.propagatedElement = node.propagatedElement; 7996 toNode.propagatedElement = node.propagatedElement;
7997 toNode.propagatedType = node.propagatedType; 7997 toNode.propagatedType = node.propagatedType;
7998 toNode.staticElement = node.staticElement; 7998 toNode.staticElement = node.staticElement;
7999 toNode.staticType = node.staticType; 7999 toNode.staticType = node.staticType;
8000 return true; 8000 return true;
8001 } 8001 }
8002 return false; 8002 return false;
8003 } 8003 }
8004 8004
8005 bool visitFunctionTypeAlias(FunctionTypeAlias node) { 8005 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
8006 FunctionTypeAlias toNode = this._toNode as FunctionTypeAlias; 8006 FunctionTypeAlias toNode = this._toNode as FunctionTypeAlias;
8007 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.documentationComment, toNode.do cumentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.ke yword, toNode.keyword)), isEqual(node.returnType, toNode.returnType)), isEqual(n ode.name, toNode.name)), isEqual(node.typeParameters, toNode.typeParameters)), i sEqual(node.parameters, toNode.parameters)), isEqual3(node.semicolon, toNode.sem icolon)); 8007 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.documentationComment, toNo de.documentationComment), isEqualNodeLists(node.metadata, toNode.metadata)), isE qualTokens(node.keyword, toNode.keyword)), isEqualNodes(node.returnType, toNode. returnType)), isEqualNodes(node.name, toNode.name)), isEqualNodes(node.typeParam eters, toNode.typeParameters)), isEqualNodes(node.parameters, toNode.parameters) ), isEqualTokens(node.semicolon, toNode.semicolon));
8008 } 8008 }
8009 8009
8010 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 8010 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
8011 FunctionTypedFormalParameter toNode = this._toNode as FunctionTypedFormalPar ameter; 8011 FunctionTypedFormalParameter toNode = this._toNode as FunctionTypedFormalPar ameter;
8012 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual(node.returnType, toNode.returnType)), isEqual(node.id entifier, toNode.identifier)), isEqual(node.parameters, toNode.parameters)); 8012 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualNodes(node.returnType, toNode.returnType) ), isEqualNodes(node.identifier, toNode.identifier)), isEqualNodes(node.paramete rs, toNode.parameters));
8013 } 8013 }
8014 8014
8015 bool visitHideCombinator(HideCombinator node) { 8015 bool visitHideCombinator(HideCombinator node) {
8016 HideCombinator toNode = this._toNode as HideCombinator; 8016 HideCombinator toNode = this._toNode as HideCombinator;
8017 return javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual2(node. hiddenNames, toNode.hiddenNames)); 8017 return javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNo deLists(node.hiddenNames, toNode.hiddenNames));
8018 } 8018 }
8019 8019
8020 bool visitIfStatement(IfStatement node) { 8020 bool visitIfStatement(IfStatement node) {
8021 IfStatement toNode = this._toNode as IfStatement; 8021 IfStatement toNode = this._toNode as IfStatement;
8022 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual3(node.ifKeyword, toNode.ifKeyword), isEqual3(node.l eftParenthesis, toNode.leftParenthesis)), isEqual(node.condition, toNode.conditi on)), isEqual3(node.rightParenthesis, toNode.rightParenthesis)), isEqual(node.th enStatement, toNode.thenStatement)), isEqual3(node.elseKeyword, toNode.elseKeywo rd)), isEqual(node.elseStatement, toNode.elseStatement)); 8022 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualTokens(node.ifKeyword, toNode.ifKeyword), isEqualTok ens(node.leftParenthesis, toNode.leftParenthesis)), isEqualNodes(node.condition, toNode.condition)), isEqualTokens(node.rightParenthesis, toNode.rightParenthesi s)), isEqualNodes(node.thenStatement, toNode.thenStatement)), isEqualTokens(node .elseKeyword, toNode.elseKeyword)), isEqualNodes(node.elseStatement, toNode.else Statement));
8023 } 8023 }
8024 8024
8025 bool visitImplementsClause(ImplementsClause node) { 8025 bool visitImplementsClause(ImplementsClause node) {
8026 ImplementsClause toNode = this._toNode as ImplementsClause; 8026 ImplementsClause toNode = this._toNode as ImplementsClause;
8027 return javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual2(node. interfaces, toNode.interfaces)); 8027 return javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNo deLists(node.interfaces, toNode.interfaces));
8028 } 8028 }
8029 8029
8030 bool visitImportDirective(ImportDirective node) { 8030 bool visitImportDirective(ImportDirective node) {
8031 ImportDirective toNode = this._toNode as ImportDirective; 8031 ImportDirective toNode = this._toNode as ImportDirective;
8032 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(javaBooleanAnd(javaBooleanAnd(isEqual(node.documentationComment, toNode.docum entationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.keywo rd, toNode.keyword)), isEqual(node.uri, toNode.uri)), isEqual3(node.asToken, toN ode.asToken)), isEqual(node.prefix, toNode.prefix)), isEqual2(node.combinators, toNode.combinators)), isEqual3(node.semicolon, toNode.semicolon))) { 8032 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.documentationComment, toNode. documentationComment), isEqualNodeLists(node.metadata, toNode.metadata)), isEqua lTokens(node.keyword, toNode.keyword)), isEqualNodes(node.uri, toNode.uri)), isE qualTokens(node.asToken, toNode.asToken)), isEqualNodes(node.prefix, toNode.pref ix)), isEqualNodeLists(node.combinators, toNode.combinators)), isEqualTokens(nod e.semicolon, toNode.semicolon))) {
8033 toNode.element = node.element; 8033 toNode.element = node.element;
8034 return true; 8034 return true;
8035 } 8035 }
8036 return false; 8036 return false;
8037 } 8037 }
8038 8038
8039 bool visitIndexExpression(IndexExpression node) { 8039 bool visitIndexExpression(IndexExpression node) {
8040 IndexExpression toNode = this._toNode as IndexExpression; 8040 IndexExpression toNode = this._toNode as IndexExpression;
8041 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.target, toNode .target), isEqual3(node.leftBracket, toNode.leftBracket)), isEqual(node.index, t oNode.index)), isEqual3(node.rightBracket, toNode.rightBracket))) { 8041 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.target, t oNode.target), isEqualTokens(node.leftBracket, toNode.leftBracket)), isEqualNode s(node.index, toNode.index)), isEqualTokens(node.rightBracket, toNode.rightBrack et))) {
8042 toNode.auxiliaryElements = node.auxiliaryElements; 8042 toNode.auxiliaryElements = node.auxiliaryElements;
8043 toNode.propagatedElement = node.propagatedElement; 8043 toNode.propagatedElement = node.propagatedElement;
8044 toNode.propagatedType = node.propagatedType; 8044 toNode.propagatedType = node.propagatedType;
8045 toNode.staticElement = node.staticElement; 8045 toNode.staticElement = node.staticElement;
8046 toNode.staticType = node.staticType; 8046 toNode.staticType = node.staticType;
8047 return true; 8047 return true;
8048 } 8048 }
8049 return false; 8049 return false;
8050 } 8050 }
8051 8051
8052 bool visitInstanceCreationExpression(InstanceCreationExpression node) { 8052 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
8053 InstanceCreationExpression toNode = this._toNode as InstanceCreationExpressi on; 8053 InstanceCreationExpression toNode = this._toNode as InstanceCreationExpressi on;
8054 if (javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), is Equal(node.constructorName, toNode.constructorName)), isEqual(node.argumentList, toNode.argumentList))) { 8054 if (javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword ), isEqualNodes(node.constructorName, toNode.constructorName)), isEqualNodes(nod e.argumentList, toNode.argumentList))) {
8055 toNode.propagatedType = node.propagatedType; 8055 toNode.propagatedType = node.propagatedType;
8056 toNode.staticElement = node.staticElement; 8056 toNode.staticElement = node.staticElement;
8057 toNode.staticType = node.staticType; 8057 toNode.staticType = node.staticType;
8058 return true; 8058 return true;
8059 } 8059 }
8060 return false; 8060 return false;
8061 } 8061 }
8062 8062
8063 bool visitIntegerLiteral(IntegerLiteral node) { 8063 bool visitIntegerLiteral(IntegerLiteral node) {
8064 IntegerLiteral toNode = this._toNode as IntegerLiteral; 8064 IntegerLiteral toNode = this._toNode as IntegerLiteral;
8065 if (javaBooleanAnd(isEqual3(node.literal, toNode.literal), identical(node.va lue, toNode.value))) { 8065 if (javaBooleanAnd(isEqualTokens(node.literal, toNode.literal), identical(no de.value, toNode.value))) {
8066 toNode.propagatedType = node.propagatedType; 8066 toNode.propagatedType = node.propagatedType;
8067 toNode.staticType = node.staticType; 8067 toNode.staticType = node.staticType;
8068 return true; 8068 return true;
8069 } 8069 }
8070 return false; 8070 return false;
8071 } 8071 }
8072 8072
8073 bool visitInterpolationExpression(InterpolationExpression node) { 8073 bool visitInterpolationExpression(InterpolationExpression node) {
8074 InterpolationExpression toNode = this._toNode as InterpolationExpression; 8074 InterpolationExpression toNode = this._toNode as InterpolationExpression;
8075 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftBracket, toNode.leftB racket), isEqual(node.expression, toNode.expression)), isEqual3(node.rightBracke t, toNode.rightBracket)); 8075 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftBracket, toNode. leftBracket), isEqualNodes(node.expression, toNode.expression)), isEqualTokens(n ode.rightBracket, toNode.rightBracket));
8076 } 8076 }
8077 8077
8078 bool visitInterpolationString(InterpolationString node) { 8078 bool visitInterpolationString(InterpolationString node) {
8079 InterpolationString toNode = this._toNode as InterpolationString; 8079 InterpolationString toNode = this._toNode as InterpolationString;
8080 return javaBooleanAnd(isEqual3(node.contents, toNode.contents), node.value = = toNode.value); 8080 return javaBooleanAnd(isEqualTokens(node.contents, toNode.contents), node.va lue == toNode.value);
8081 } 8081 }
8082 8082
8083 bool visitIsExpression(IsExpression node) { 8083 bool visitIsExpression(IsExpression node) {
8084 IsExpression toNode = this._toNode as IsExpression; 8084 IsExpression toNode = this._toNode as IsExpression;
8085 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.expression, to Node.expression), isEqual3(node.isOperator, toNode.isOperator)), isEqual3(node.n otOperator, toNode.notOperator)), isEqual(node.type, toNode.type))) { 8085 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.expressio n, toNode.expression), isEqualTokens(node.isOperator, toNode.isOperator)), isEqu alTokens(node.notOperator, toNode.notOperator)), isEqualNodes(node.type, toNode. type))) {
8086 toNode.propagatedType = node.propagatedType; 8086 toNode.propagatedType = node.propagatedType;
8087 toNode.staticType = node.staticType; 8087 toNode.staticType = node.staticType;
8088 return true; 8088 return true;
8089 } 8089 }
8090 return false; 8090 return false;
8091 } 8091 }
8092 8092
8093 bool visitLabel(Label node) { 8093 bool visitLabel(Label node) {
8094 Label toNode = this._toNode as Label; 8094 Label toNode = this._toNode as Label;
8095 return javaBooleanAnd(isEqual(node.label, toNode.label), isEqual3(node.colon , toNode.colon)); 8095 return javaBooleanAnd(isEqualNodes(node.label, toNode.label), isEqualTokens( node.colon, toNode.colon));
8096 } 8096 }
8097 8097
8098 bool visitLabeledStatement(LabeledStatement node) { 8098 bool visitLabeledStatement(LabeledStatement node) {
8099 LabeledStatement toNode = this._toNode as LabeledStatement; 8099 LabeledStatement toNode = this._toNode as LabeledStatement;
8100 return javaBooleanAnd(isEqual2(node.labels, toNode.labels), isEqual(node.sta tement, toNode.statement)); 8100 return javaBooleanAnd(isEqualNodeLists(node.labels, toNode.labels), isEqualN odes(node.statement, toNode.statement));
8101 } 8101 }
8102 8102
8103 bool visitLibraryDirective(LibraryDirective node) { 8103 bool visitLibraryDirective(LibraryDirective node) {
8104 LibraryDirective toNode = this._toNode as LibraryDirective; 8104 LibraryDirective toNode = this._toNode as LibraryDirective;
8105 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.libraryToken, toNode.libraryToken)), isEqual(no de.name, toNode.name)), isEqual3(node.semicolon, toNode.semicolon)); 8105 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualTokens(node.libraryToken, toNode.libraryT oken)), isEqualNodes(node.name, toNode.name)), isEqualTokens(node.semicolon, toN ode.semicolon));
8106 } 8106 }
8107 8107
8108 bool visitLibraryIdentifier(LibraryIdentifier node) { 8108 bool visitLibraryIdentifier(LibraryIdentifier node) {
8109 LibraryIdentifier toNode = this._toNode as LibraryIdentifier; 8109 LibraryIdentifier toNode = this._toNode as LibraryIdentifier;
8110 if (isEqual2(node.components, toNode.components)) { 8110 if (isEqualNodeLists(node.components, toNode.components)) {
8111 toNode.propagatedType = node.propagatedType; 8111 toNode.propagatedType = node.propagatedType;
8112 toNode.staticType = node.staticType; 8112 toNode.staticType = node.staticType;
8113 return true; 8113 return true;
8114 } 8114 }
8115 return false; 8115 return false;
8116 } 8116 }
8117 8117
8118 bool visitListLiteral(ListLiteral node) { 8118 bool visitListLiteral(ListLiteral node) {
8119 ListLiteral toNode = this._toNode as ListLiteral; 8119 ListLiteral toNode = this._toNode as ListLiteral;
8120 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(nod e.constKeyword, toNode.constKeyword), isEqual(node.typeArguments, toNode.typeArg uments)), isEqual3(node.leftBracket, toNode.leftBracket)), isEqual2(node.element s, toNode.elements)), isEqual3(node.rightBracket, toNode.rightBracket))) { 8120 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualToken s(node.constKeyword, toNode.constKeyword), isEqualNodes(node.typeArguments, toNo de.typeArguments)), isEqualTokens(node.leftBracket, toNode.leftBracket)), isEqua lNodeLists(node.elements, toNode.elements)), isEqualTokens(node.rightBracket, to Node.rightBracket))) {
8121 toNode.propagatedType = node.propagatedType; 8121 toNode.propagatedType = node.propagatedType;
8122 toNode.staticType = node.staticType; 8122 toNode.staticType = node.staticType;
8123 return true; 8123 return true;
8124 } 8124 }
8125 return false; 8125 return false;
8126 } 8126 }
8127 8127
8128 bool visitMapLiteral(MapLiteral node) { 8128 bool visitMapLiteral(MapLiteral node) {
8129 MapLiteral toNode = this._toNode as MapLiteral; 8129 MapLiteral toNode = this._toNode as MapLiteral;
8130 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(nod e.constKeyword, toNode.constKeyword), isEqual(node.typeArguments, toNode.typeArg uments)), isEqual3(node.leftBracket, toNode.leftBracket)), isEqual2(node.entries , toNode.entries)), isEqual3(node.rightBracket, toNode.rightBracket))) { 8130 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualToken s(node.constKeyword, toNode.constKeyword), isEqualNodes(node.typeArguments, toNo de.typeArguments)), isEqualTokens(node.leftBracket, toNode.leftBracket)), isEqua lNodeLists(node.entries, toNode.entries)), isEqualTokens(node.rightBracket, toNo de.rightBracket))) {
8131 toNode.propagatedType = node.propagatedType; 8131 toNode.propagatedType = node.propagatedType;
8132 toNode.staticType = node.staticType; 8132 toNode.staticType = node.staticType;
8133 return true; 8133 return true;
8134 } 8134 }
8135 return false; 8135 return false;
8136 } 8136 }
8137 8137
8138 bool visitMapLiteralEntry(MapLiteralEntry node) { 8138 bool visitMapLiteralEntry(MapLiteralEntry node) {
8139 MapLiteralEntry toNode = this._toNode as MapLiteralEntry; 8139 MapLiteralEntry toNode = this._toNode as MapLiteralEntry;
8140 return javaBooleanAnd(javaBooleanAnd(isEqual(node.key, toNode.key), isEqual3 (node.separator, toNode.separator)), isEqual(node.value, toNode.value)); 8140 return javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.key, toNode.key), isE qualTokens(node.separator, toNode.separator)), isEqualNodes(node.value, toNode.v alue));
8141 } 8141 }
8142 8142
8143 bool visitMethodDeclaration(MethodDeclaration node) { 8143 bool visitMethodDeclaration(MethodDeclaration node) {
8144 MethodDeclaration toNode = this._toNode as MethodDeclaration; 8144 MethodDeclaration toNode = this._toNode as MethodDeclaration;
8145 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.d ocumentationComment, toNode.documentationComment), isEqual2(node.metadata, toNod e.metadata)), isEqual3(node.externalKeyword, toNode.externalKeyword)), isEqual3( node.modifierKeyword, toNode.modifierKeyword)), isEqual(node.returnType, toNode. returnType)), isEqual3(node.propertyKeyword, toNode.propertyKeyword)), isEqual3( node.propertyKeyword, toNode.propertyKeyword)), isEqual(node.name, toNode.name)) , isEqual(node.parameters, toNode.parameters)), isEqual(node.body, toNode.body)) ; 8145 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(n ode.documentationComment, toNode.documentationComment), isEqualNodeLists(node.me tadata, toNode.metadata)), isEqualTokens(node.externalKeyword, toNode.externalKe yword)), isEqualTokens(node.modifierKeyword, toNode.modifierKeyword)), isEqualNo des(node.returnType, toNode.returnType)), isEqualTokens(node.propertyKeyword, to Node.propertyKeyword)), isEqualTokens(node.propertyKeyword, toNode.propertyKeywo rd)), isEqualNodes(node.name, toNode.name)), isEqualNodes(node.parameters, toNod e.parameters)), isEqualNodes(node.body, toNode.body));
8146 } 8146 }
8147 8147
8148 bool visitMethodInvocation(MethodInvocation node) { 8148 bool visitMethodInvocation(MethodInvocation node) {
8149 MethodInvocation toNode = this._toNode as MethodInvocation; 8149 MethodInvocation toNode = this._toNode as MethodInvocation;
8150 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.target, toNode .target), isEqual3(node.period, toNode.period)), isEqual(node.methodName, toNode .methodName)), isEqual(node.argumentList, toNode.argumentList))) { 8150 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.target, t oNode.target), isEqualTokens(node.period, toNode.period)), isEqualNodes(node.met hodName, toNode.methodName)), isEqualNodes(node.argumentList, toNode.argumentLis t))) {
8151 toNode.propagatedType = node.propagatedType; 8151 toNode.propagatedType = node.propagatedType;
8152 toNode.staticType = node.staticType; 8152 toNode.staticType = node.staticType;
8153 return true; 8153 return true;
8154 } 8154 }
8155 return false; 8155 return false;
8156 } 8156 }
8157 8157
8158 bool visitNamedExpression(NamedExpression node) { 8158 bool visitNamedExpression(NamedExpression node) {
8159 NamedExpression toNode = this._toNode as NamedExpression; 8159 NamedExpression toNode = this._toNode as NamedExpression;
8160 if (javaBooleanAnd(isEqual(node.name, toNode.name), isEqual(node.expression, toNode.expression))) { 8160 if (javaBooleanAnd(isEqualNodes(node.name, toNode.name), isEqualNodes(node.e xpression, toNode.expression))) {
8161 toNode.propagatedType = node.propagatedType; 8161 toNode.propagatedType = node.propagatedType;
8162 toNode.staticType = node.staticType; 8162 toNode.staticType = node.staticType;
8163 return true; 8163 return true;
8164 } 8164 }
8165 return false; 8165 return false;
8166 } 8166 }
8167 8167
8168 bool visitNativeClause(NativeClause node) { 8168 bool visitNativeClause(NativeClause node) {
8169 NativeClause toNode = this._toNode as NativeClause; 8169 NativeClause toNode = this._toNode as NativeClause;
8170 return javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.n ame, toNode.name)); 8170 return javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNo des(node.name, toNode.name));
8171 } 8171 }
8172 8172
8173 bool visitNativeFunctionBody(NativeFunctionBody node) { 8173 bool visitNativeFunctionBody(NativeFunctionBody node) {
8174 NativeFunctionBody toNode = this._toNode as NativeFunctionBody; 8174 NativeFunctionBody toNode = this._toNode as NativeFunctionBody;
8175 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.nativeToken, toNode.nativ eToken), isEqual(node.stringLiteral, toNode.stringLiteral)), isEqual3(node.semic olon, toNode.semicolon)); 8175 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.nativeToken, toNode. nativeToken), isEqualNodes(node.stringLiteral, toNode.stringLiteral)), isEqualTo kens(node.semicolon, toNode.semicolon));
8176 } 8176 }
8177 8177
8178 bool visitNullLiteral(NullLiteral node) { 8178 bool visitNullLiteral(NullLiteral node) {
8179 NullLiteral toNode = this._toNode as NullLiteral; 8179 NullLiteral toNode = this._toNode as NullLiteral;
8180 if (isEqual3(node.literal, toNode.literal)) { 8180 if (isEqualTokens(node.literal, toNode.literal)) {
8181 toNode.propagatedType = node.propagatedType; 8181 toNode.propagatedType = node.propagatedType;
8182 toNode.staticType = node.staticType; 8182 toNode.staticType = node.staticType;
8183 return true; 8183 return true;
8184 } 8184 }
8185 return false; 8185 return false;
8186 } 8186 }
8187 8187
8188 bool visitParenthesizedExpression(ParenthesizedExpression node) { 8188 bool visitParenthesizedExpression(ParenthesizedExpression node) {
8189 ParenthesizedExpression toNode = this._toNode as ParenthesizedExpression; 8189 ParenthesizedExpression toNode = this._toNode as ParenthesizedExpression;
8190 if (javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftParenthesis, toNode.left Parenthesis), isEqual(node.expression, toNode.expression)), isEqual3(node.rightP arenthesis, toNode.rightParenthesis))) { 8190 if (javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftParenthesis, toNode .leftParenthesis), isEqualNodes(node.expression, toNode.expression)), isEqualTok ens(node.rightParenthesis, toNode.rightParenthesis))) {
8191 toNode.propagatedType = node.propagatedType; 8191 toNode.propagatedType = node.propagatedType;
8192 toNode.staticType = node.staticType; 8192 toNode.staticType = node.staticType;
8193 return true; 8193 return true;
8194 } 8194 }
8195 return false; 8195 return false;
8196 } 8196 }
8197 8197
8198 bool visitPartDirective(PartDirective node) { 8198 bool visitPartDirective(PartDirective node) {
8199 PartDirective toNode = this._toNode as PartDirective; 8199 PartDirective toNode = this._toNode as PartDirective;
8200 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node .documentationComment, toNode.documentationComment), isEqual2(node.metadata, toN ode.metadata)), isEqual3(node.partToken, toNode.partToken)), isEqual(node.uri, t oNode.uri)), isEqual3(node.semicolon, toNode.semicolon))) { 8200 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes (node.documentationComment, toNode.documentationComment), isEqualNodeLists(node. metadata, toNode.metadata)), isEqualTokens(node.partToken, toNode.partToken)), i sEqualNodes(node.uri, toNode.uri)), isEqualTokens(node.semicolon, toNode.semicol on))) {
8201 toNode.element = node.element; 8201 toNode.element = node.element;
8202 return true; 8202 return true;
8203 } 8203 }
8204 return false; 8204 return false;
8205 } 8205 }
8206 8206
8207 bool visitPartOfDirective(PartOfDirective node) { 8207 bool visitPartOfDirective(PartOfDirective node) {
8208 PartOfDirective toNode = this._toNode as PartOfDirective; 8208 PartOfDirective toNode = this._toNode as PartOfDirective;
8209 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(isEqual(node.documentationComment, toNode.documentationComment), isEqual2(nod e.metadata, toNode.metadata)), isEqual3(node.partToken, toNode.partToken)), isEq ual3(node.ofToken, toNode.ofToken)), isEqual(node.libraryName, toNode.libraryNam e)), isEqual3(node.semicolon, toNode.semicolon))) { 8209 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanA nd(isEqualNodes(node.documentationComment, toNode.documentationComment), isEqual NodeLists(node.metadata, toNode.metadata)), isEqualTokens(node.partToken, toNode .partToken)), isEqualTokens(node.ofToken, toNode.ofToken)), isEqualNodes(node.li braryName, toNode.libraryName)), isEqualTokens(node.semicolon, toNode.semicolon) )) {
8210 toNode.element = node.element; 8210 toNode.element = node.element;
8211 return true; 8211 return true;
8212 } 8212 }
8213 return false; 8213 return false;
8214 } 8214 }
8215 8215
8216 bool visitPostfixExpression(PostfixExpression node) { 8216 bool visitPostfixExpression(PostfixExpression node) {
8217 PostfixExpression toNode = this._toNode as PostfixExpression; 8217 PostfixExpression toNode = this._toNode as PostfixExpression;
8218 if (javaBooleanAnd(isEqual(node.operand, toNode.operand), isEqual3(node.oper ator, toNode.operator))) { 8218 if (javaBooleanAnd(isEqualNodes(node.operand, toNode.operand), isEqualTokens (node.operator, toNode.operator))) {
8219 toNode.propagatedElement = node.propagatedElement; 8219 toNode.propagatedElement = node.propagatedElement;
8220 toNode.propagatedType = node.propagatedType; 8220 toNode.propagatedType = node.propagatedType;
8221 toNode.staticElement = node.staticElement; 8221 toNode.staticElement = node.staticElement;
8222 toNode.staticType = node.staticType; 8222 toNode.staticType = node.staticType;
8223 return true; 8223 return true;
8224 } 8224 }
8225 return false; 8225 return false;
8226 } 8226 }
8227 8227
8228 bool visitPrefixedIdentifier(PrefixedIdentifier node) { 8228 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
8229 PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier; 8229 PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier;
8230 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.prefix, toNode.prefix), isEqu al3(node.period, toNode.period)), isEqual(node.identifier, toNode.identifier))) { 8230 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.prefix, toNode.prefix), isEqualTokens(node.period, toNode.period)), isEqualNodes(node.identifier, toNode .identifier))) {
8231 toNode.propagatedType = node.propagatedType; 8231 toNode.propagatedType = node.propagatedType;
8232 toNode.staticType = node.staticType; 8232 toNode.staticType = node.staticType;
8233 return true; 8233 return true;
8234 } 8234 }
8235 return false; 8235 return false;
8236 } 8236 }
8237 8237
8238 bool visitPrefixExpression(PrefixExpression node) { 8238 bool visitPrefixExpression(PrefixExpression node) {
8239 PrefixExpression toNode = this._toNode as PrefixExpression; 8239 PrefixExpression toNode = this._toNode as PrefixExpression;
8240 if (javaBooleanAnd(isEqual3(node.operator, toNode.operator), isEqual(node.op erand, toNode.operand))) { 8240 if (javaBooleanAnd(isEqualTokens(node.operator, toNode.operator), isEqualNod es(node.operand, toNode.operand))) {
8241 toNode.propagatedElement = node.propagatedElement; 8241 toNode.propagatedElement = node.propagatedElement;
8242 toNode.propagatedType = node.propagatedType; 8242 toNode.propagatedType = node.propagatedType;
8243 toNode.staticElement = node.staticElement; 8243 toNode.staticElement = node.staticElement;
8244 toNode.staticType = node.staticType; 8244 toNode.staticType = node.staticType;
8245 return true; 8245 return true;
8246 } 8246 }
8247 return false; 8247 return false;
8248 } 8248 }
8249 8249
8250 bool visitPropertyAccess(PropertyAccess node) { 8250 bool visitPropertyAccess(PropertyAccess node) {
8251 PropertyAccess toNode = this._toNode as PropertyAccess; 8251 PropertyAccess toNode = this._toNode as PropertyAccess;
8252 if (javaBooleanAnd(javaBooleanAnd(isEqual(node.target, toNode.target), isEqu al3(node.operator, toNode.operator)), isEqual(node.propertyName, toNode.property Name))) { 8252 if (javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.target, toNode.target), isEqualTokens(node.operator, toNode.operator)), isEqualNodes(node.propertyName, toNode.propertyName))) {
8253 toNode.propagatedType = node.propagatedType; 8253 toNode.propagatedType = node.propagatedType;
8254 toNode.staticType = node.staticType; 8254 toNode.staticType = node.staticType;
8255 return true; 8255 return true;
8256 } 8256 }
8257 return false; 8257 return false;
8258 } 8258 }
8259 8259
8260 bool visitRedirectingConstructorInvocation(RedirectingConstructorInvocation no de) { 8260 bool visitRedirectingConstructorInvocation(RedirectingConstructorInvocation no de) {
8261 RedirectingConstructorInvocation toNode = this._toNode as RedirectingConstru ctorInvocation; 8261 RedirectingConstructorInvocation toNode = this._toNode as RedirectingConstru ctorInvocation;
8262 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNo de.keyword), isEqual3(node.period, toNode.period)), isEqual(node.constructorName , toNode.constructorName)), isEqual(node.argumentList, toNode.argumentList))) { 8262 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualTokens(node.period, toNode.period)), isEqualNodes(node. constructorName, toNode.constructorName)), isEqualNodes(node.argumentList, toNod e.argumentList))) {
8263 toNode.staticElement = node.staticElement; 8263 toNode.staticElement = node.staticElement;
8264 return true; 8264 return true;
8265 } 8265 }
8266 return false; 8266 return false;
8267 } 8267 }
8268 8268
8269 bool visitRethrowExpression(RethrowExpression node) { 8269 bool visitRethrowExpression(RethrowExpression node) {
8270 RethrowExpression toNode = this._toNode as RethrowExpression; 8270 RethrowExpression toNode = this._toNode as RethrowExpression;
8271 if (isEqual3(node.keyword, toNode.keyword)) { 8271 if (isEqualTokens(node.keyword, toNode.keyword)) {
8272 toNode.propagatedType = node.propagatedType; 8272 toNode.propagatedType = node.propagatedType;
8273 toNode.staticType = node.staticType; 8273 toNode.staticType = node.staticType;
8274 return true; 8274 return true;
8275 } 8275 }
8276 return false; 8276 return false;
8277 } 8277 }
8278 8278
8279 bool visitReturnStatement(ReturnStatement node) { 8279 bool visitReturnStatement(ReturnStatement node) {
8280 ReturnStatement toNode = this._toNode as ReturnStatement; 8280 ReturnStatement toNode = this._toNode as ReturnStatement;
8281 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.expression, toNode.expression)), isEqual3(node.semicolon, toNode.s emicolon)); 8281 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyw ord), isEqualNodes(node.expression, toNode.expression)), isEqualTokens(node.semi colon, toNode.semicolon));
8282 } 8282 }
8283 8283
8284 bool visitScriptTag(ScriptTag node) { 8284 bool visitScriptTag(ScriptTag node) {
8285 ScriptTag toNode = this._toNode as ScriptTag; 8285 ScriptTag toNode = this._toNode as ScriptTag;
8286 return isEqual3(node.scriptTag, toNode.scriptTag); 8286 return isEqualTokens(node.scriptTag, toNode.scriptTag);
8287 } 8287 }
8288 8288
8289 bool visitShowCombinator(ShowCombinator node) { 8289 bool visitShowCombinator(ShowCombinator node) {
8290 ShowCombinator toNode = this._toNode as ShowCombinator; 8290 ShowCombinator toNode = this._toNode as ShowCombinator;
8291 return javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual2(node. shownNames, toNode.shownNames)); 8291 return javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNo deLists(node.shownNames, toNode.shownNames));
8292 } 8292 }
8293 8293
8294 bool visitSimpleFormalParameter(SimpleFormalParameter node) { 8294 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
8295 SimpleFormalParameter toNode = this._toNode as SimpleFormalParameter; 8295 SimpleFormalParameter toNode = this._toNode as SimpleFormalParameter;
8296 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.keyword, toNode.keyword)), isEqual(node.type, t oNode.type)), isEqual(node.identifier, toNode.identifier)); 8296 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualTokens(node.keyword, toNode.keyword)), is EqualNodes(node.type, toNode.type)), isEqualNodes(node.identifier, toNode.identi fier));
8297 } 8297 }
8298 8298
8299 bool visitSimpleIdentifier(SimpleIdentifier node) { 8299 bool visitSimpleIdentifier(SimpleIdentifier node) {
8300 SimpleIdentifier toNode = this._toNode as SimpleIdentifier; 8300 SimpleIdentifier toNode = this._toNode as SimpleIdentifier;
8301 if (isEqual3(node.token, toNode.token)) { 8301 if (isEqualTokens(node.token, toNode.token)) {
8302 toNode.staticElement = node.staticElement; 8302 toNode.staticElement = node.staticElement;
8303 toNode.staticType = node.staticType; 8303 toNode.staticType = node.staticType;
8304 toNode.propagatedElement = node.propagatedElement; 8304 toNode.propagatedElement = node.propagatedElement;
8305 toNode.propagatedType = node.propagatedType; 8305 toNode.propagatedType = node.propagatedType;
8306 toNode.auxiliaryElements = node.auxiliaryElements; 8306 toNode.auxiliaryElements = node.auxiliaryElements;
8307 return true; 8307 return true;
8308 } 8308 }
8309 return false; 8309 return false;
8310 } 8310 }
8311 8311
8312 bool visitSimpleStringLiteral(SimpleStringLiteral node) { 8312 bool visitSimpleStringLiteral(SimpleStringLiteral node) {
8313 SimpleStringLiteral toNode = this._toNode as SimpleStringLiteral; 8313 SimpleStringLiteral toNode = this._toNode as SimpleStringLiteral;
8314 if (javaBooleanAnd(isEqual3(node.literal, toNode.literal), identical(node.va lue, toNode.value))) { 8314 if (javaBooleanAnd(isEqualTokens(node.literal, toNode.literal), identical(no de.value, toNode.value))) {
8315 toNode.propagatedType = node.propagatedType; 8315 toNode.propagatedType = node.propagatedType;
8316 toNode.staticType = node.staticType; 8316 toNode.staticType = node.staticType;
8317 return true; 8317 return true;
8318 } 8318 }
8319 return false; 8319 return false;
8320 } 8320 }
8321 8321
8322 bool visitStringInterpolation(StringInterpolation node) { 8322 bool visitStringInterpolation(StringInterpolation node) {
8323 StringInterpolation toNode = this._toNode as StringInterpolation; 8323 StringInterpolation toNode = this._toNode as StringInterpolation;
8324 if (isEqual2(node.elements, toNode.elements)) { 8324 if (isEqualNodeLists(node.elements, toNode.elements)) {
8325 toNode.propagatedType = node.propagatedType; 8325 toNode.propagatedType = node.propagatedType;
8326 toNode.staticType = node.staticType; 8326 toNode.staticType = node.staticType;
8327 return true; 8327 return true;
8328 } 8328 }
8329 return false; 8329 return false;
8330 } 8330 }
8331 8331
8332 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) { 8332 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
8333 SuperConstructorInvocation toNode = this._toNode as SuperConstructorInvocati on; 8333 SuperConstructorInvocation toNode = this._toNode as SuperConstructorInvocati on;
8334 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3(node.keyword, toNo de.keyword), isEqual3(node.period, toNode.period)), isEqual(node.constructorName , toNode.constructorName)), isEqual(node.argumentList, toNode.argumentList))) { 8334 if (javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualTokens(node.period, toNode.period)), isEqualNodes(node. constructorName, toNode.constructorName)), isEqualNodes(node.argumentList, toNod e.argumentList))) {
8335 toNode.staticElement = node.staticElement; 8335 toNode.staticElement = node.staticElement;
8336 return true; 8336 return true;
8337 } 8337 }
8338 return false; 8338 return false;
8339 } 8339 }
8340 8340
8341 bool visitSuperExpression(SuperExpression node) { 8341 bool visitSuperExpression(SuperExpression node) {
8342 SuperExpression toNode = this._toNode as SuperExpression; 8342 SuperExpression toNode = this._toNode as SuperExpression;
8343 if (isEqual3(node.keyword, toNode.keyword)) { 8343 if (isEqualTokens(node.keyword, toNode.keyword)) {
8344 toNode.propagatedType = node.propagatedType; 8344 toNode.propagatedType = node.propagatedType;
8345 toNode.staticType = node.staticType; 8345 toNode.staticType = node.staticType;
8346 return true; 8346 return true;
8347 } 8347 }
8348 return false; 8348 return false;
8349 } 8349 }
8350 8350
8351 bool visitSwitchCase(SwitchCase node) { 8351 bool visitSwitchCase(SwitchCase node) {
8352 SwitchCase toNode = this._toNode as SwitchCase; 8352 SwitchCase toNode = this._toNode as SwitchCase;
8353 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual2( node.labels, toNode.labels), isEqual3(node.keyword, toNode.keyword)), isEqual(no de.expression, toNode.expression)), isEqual3(node.colon, toNode.colon)), isEqual 2(node.statements, toNode.statements)); 8353 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo deLists(node.labels, toNode.labels), isEqualTokens(node.keyword, toNode.keyword) ), isEqualNodes(node.expression, toNode.expression)), isEqualTokens(node.colon, toNode.colon)), isEqualNodeLists(node.statements, toNode.statements));
8354 } 8354 }
8355 8355
8356 bool visitSwitchDefault(SwitchDefault node) { 8356 bool visitSwitchDefault(SwitchDefault node) {
8357 SwitchDefault toNode = this._toNode as SwitchDefault; 8357 SwitchDefault toNode = this._toNode as SwitchDefault;
8358 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual2(node.labels, to Node.labels), isEqual3(node.keyword, toNode.keyword)), isEqual3(node.colon, toNo de.colon)), isEqual2(node.statements, toNode.statements)); 8358 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodeLists(node.la bels, toNode.labels), isEqualTokens(node.keyword, toNode.keyword)), isEqualToken s(node.colon, toNode.colon)), isEqualNodeLists(node.statements, toNode.statement s));
8359 } 8359 }
8360 8360
8361 bool visitSwitchStatement(SwitchStatement node) { 8361 bool visitSwitchStatement(SwitchStatement node) {
8362 SwitchStatement toNode = this._toNode as SwitchStatement; 8362 SwitchStatement toNode = this._toNode as SwitchStatement;
8363 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual3(node.leftP arenthesis, toNode.leftParenthesis)), isEqual(node.expression, toNode.expression )), isEqual3(node.rightParenthesis, toNode.rightParenthesis)), isEqual3(node.lef tBracket, toNode.leftBracket)), isEqual2(node.members, toNode.members)), isEqual 3(node.rightBracket, toNode.rightBracket)); 8363 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBoole anAnd(javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualTokens( node.leftParenthesis, toNode.leftParenthesis)), isEqualNodes(node.expression, to Node.expression)), isEqualTokens(node.rightParenthesis, toNode.rightParenthesis) ), isEqualTokens(node.leftBracket, toNode.leftBracket)), isEqualNodeLists(node.m embers, toNode.members)), isEqualTokens(node.rightBracket, toNode.rightBracket)) ;
8364 } 8364 }
8365 8365
8366 bool visitSymbolLiteral(SymbolLiteral node) { 8366 bool visitSymbolLiteral(SymbolLiteral node) {
8367 SymbolLiteral toNode = this._toNode as SymbolLiteral; 8367 SymbolLiteral toNode = this._toNode as SymbolLiteral;
8368 if (javaBooleanAnd(isEqual3(node.poundSign, toNode.poundSign), isEqual4(node .components, toNode.components))) { 8368 if (javaBooleanAnd(isEqualTokens(node.poundSign, toNode.poundSign), isEqualT okenLists(node.components, toNode.components))) {
8369 toNode.propagatedType = node.propagatedType; 8369 toNode.propagatedType = node.propagatedType;
8370 toNode.staticType = node.staticType; 8370 toNode.staticType = node.staticType;
8371 return true; 8371 return true;
8372 } 8372 }
8373 return false; 8373 return false;
8374 } 8374 }
8375 8375
8376 bool visitThisExpression(ThisExpression node) { 8376 bool visitThisExpression(ThisExpression node) {
8377 ThisExpression toNode = this._toNode as ThisExpression; 8377 ThisExpression toNode = this._toNode as ThisExpression;
8378 if (isEqual3(node.keyword, toNode.keyword)) { 8378 if (isEqualTokens(node.keyword, toNode.keyword)) {
8379 toNode.propagatedType = node.propagatedType; 8379 toNode.propagatedType = node.propagatedType;
8380 toNode.staticType = node.staticType; 8380 toNode.staticType = node.staticType;
8381 return true; 8381 return true;
8382 } 8382 }
8383 return false; 8383 return false;
8384 } 8384 }
8385 8385
8386 bool visitThrowExpression(ThrowExpression node) { 8386 bool visitThrowExpression(ThrowExpression node) {
8387 ThrowExpression toNode = this._toNode as ThrowExpression; 8387 ThrowExpression toNode = this._toNode as ThrowExpression;
8388 if (javaBooleanAnd(isEqual3(node.keyword, toNode.keyword), isEqual(node.expr ession, toNode.expression))) { 8388 if (javaBooleanAnd(isEqualTokens(node.keyword, toNode.keyword), isEqualNodes (node.expression, toNode.expression))) {
8389 toNode.propagatedType = node.propagatedType; 8389 toNode.propagatedType = node.propagatedType;
8390 toNode.staticType = node.staticType; 8390 toNode.staticType = node.staticType;
8391 return true; 8391 return true;
8392 } 8392 }
8393 return false; 8393 return false;
8394 } 8394 }
8395 8395
8396 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 8396 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
8397 TopLevelVariableDeclaration toNode = this._toNode as TopLevelVariableDeclara tion; 8397 TopLevelVariableDeclaration toNode = this._toNode as TopLevelVariableDeclara tion;
8398 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(node.documentati onComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata )), isEqual(node.variables, toNode.variables)), isEqual3(node.semicolon, toNode. semicolon)); 8398 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNodes(node.docume ntationComment, toNode.documentationComment), isEqualNodeLists(node.metadata, to Node.metadata)), isEqualNodes(node.variables, toNode.variables)), isEqualTokens( node.semicolon, toNode.semicolon));
8399 } 8399 }
8400 8400
8401 bool visitTryStatement(TryStatement node) { 8401 bool visitTryStatement(TryStatement node) {
8402 TryStatement toNode = this._toNode as TryStatement; 8402 TryStatement toNode = this._toNode as TryStatement;
8403 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3( node.tryKeyword, toNode.tryKeyword), isEqual(node.body, toNode.body)), isEqual2( node.catchClauses, toNode.catchClauses)), isEqual3(node.finallyKeyword, toNode.f inallyKeyword)), isEqual(node.finallyBlock, toNode.finallyBlock)); 8403 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTo kens(node.tryKeyword, toNode.tryKeyword), isEqualNodes(node.body, toNode.body)), isEqualNodeLists(node.catchClauses, toNode.catchClauses)), isEqualTokens(node.f inallyKeyword, toNode.finallyKeyword)), isEqualNodes(node.finallyBlock, toNode.f inallyBlock));
8404 } 8404 }
8405 8405
8406 bool visitTypeArgumentList(TypeArgumentList node) { 8406 bool visitTypeArgumentList(TypeArgumentList node) {
8407 TypeArgumentList toNode = this._toNode as TypeArgumentList; 8407 TypeArgumentList toNode = this._toNode as TypeArgumentList;
8408 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftBracket, toNode.leftB racket), isEqual2(node.arguments, toNode.arguments)), isEqual3(node.rightBracket , toNode.rightBracket)); 8408 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftBracket, toNode. leftBracket), isEqualNodeLists(node.arguments, toNode.arguments)), isEqualTokens (node.rightBracket, toNode.rightBracket));
8409 } 8409 }
8410 8410
8411 bool visitTypeName(TypeName node) { 8411 bool visitTypeName(TypeName node) {
8412 TypeName toNode = this._toNode as TypeName; 8412 TypeName toNode = this._toNode as TypeName;
8413 if (javaBooleanAnd(isEqual(node.name, toNode.name), isEqual(node.typeArgumen ts, toNode.typeArguments))) { 8413 if (javaBooleanAnd(isEqualNodes(node.name, toNode.name), isEqualNodes(node.t ypeArguments, toNode.typeArguments))) {
8414 toNode.type = node.type; 8414 toNode.type = node.type;
8415 return true; 8415 return true;
8416 } 8416 }
8417 return false; 8417 return false;
8418 } 8418 }
8419 8419
8420 bool visitTypeParameter(TypeParameter node) { 8420 bool visitTypeParameter(TypeParameter node) {
8421 TypeParameter toNode = this._toNode as TypeParameter; 8421 TypeParameter toNode = this._toNode as TypeParameter;
8422 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual(node.name, toNode.name)), isEqual3(node.keyword, toNo de.keyword)), isEqual(node.bound, toNode.bound)); 8422 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualNodes(node.name, toNode.name)), isEqualTo kens(node.keyword, toNode.keyword)), isEqualNodes(node.bound, toNode.bound));
8423 } 8423 }
8424 8424
8425 bool visitTypeParameterList(TypeParameterList node) { 8425 bool visitTypeParameterList(TypeParameterList node) {
8426 TypeParameterList toNode = this._toNode as TypeParameterList; 8426 TypeParameterList toNode = this._toNode as TypeParameterList;
8427 return javaBooleanAnd(javaBooleanAnd(isEqual3(node.leftBracket, toNode.leftB racket), isEqual2(node.typeParameters, toNode.typeParameters)), isEqual3(node.ri ghtBracket, toNode.rightBracket)); 8427 return javaBooleanAnd(javaBooleanAnd(isEqualTokens(node.leftBracket, toNode. leftBracket), isEqualNodeLists(node.typeParameters, toNode.typeParameters)), isE qualTokens(node.rightBracket, toNode.rightBracket));
8428 } 8428 }
8429 8429
8430 bool visitVariableDeclaration(VariableDeclaration node) { 8430 bool visitVariableDeclaration(VariableDeclaration node) {
8431 VariableDeclaration toNode = this._toNode as VariableDeclaration; 8431 VariableDeclaration toNode = this._toNode as VariableDeclaration;
8432 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual(node.name, toNode.name)), isEqual3(node.equals, toNod e.equals)), isEqual(node.initializer, toNode.initializer)); 8432 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualNodes(node.name, toNode.name)), isEqualTo kens(node.equals, toNode.equals)), isEqualNodes(node.initializer, toNode.initial izer));
8433 } 8433 }
8434 8434
8435 bool visitVariableDeclarationList(VariableDeclarationList node) { 8435 bool visitVariableDeclarationList(VariableDeclarationList node) {
8436 VariableDeclarationList toNode = this._toNode as VariableDeclarationList; 8436 VariableDeclarationList toNode = this._toNode as VariableDeclarationList;
8437 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual(n ode.documentationComment, toNode.documentationComment), isEqual2(node.metadata, toNode.metadata)), isEqual3(node.keyword, toNode.keyword)), isEqual(node.type, t oNode.type)), isEqual2(node.variables, toNode.variables)); 8437 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualNo des(node.documentationComment, toNode.documentationComment), isEqualNodeLists(no de.metadata, toNode.metadata)), isEqualTokens(node.keyword, toNode.keyword)), is EqualNodes(node.type, toNode.type)), isEqualNodeLists(node.variables, toNode.var iables));
8438 } 8438 }
8439 8439
8440 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { 8440 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
8441 VariableDeclarationStatement toNode = this._toNode as VariableDeclarationSta tement; 8441 VariableDeclarationStatement toNode = this._toNode as VariableDeclarationSta tement;
8442 return javaBooleanAnd(isEqual(node.variables, toNode.variables), isEqual3(no de.semicolon, toNode.semicolon)); 8442 return javaBooleanAnd(isEqualNodes(node.variables, toNode.variables), isEqua lTokens(node.semicolon, toNode.semicolon));
8443 } 8443 }
8444 8444
8445 bool visitWhileStatement(WhileStatement node) { 8445 bool visitWhileStatement(WhileStatement node) {
8446 WhileStatement toNode = this._toNode as WhileStatement; 8446 WhileStatement toNode = this._toNode as WhileStatement;
8447 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqual3( node.keyword, toNode.keyword), isEqual3(node.leftParenthesis, toNode.leftParenth esis)), isEqual(node.condition, toNode.condition)), isEqual3(node.rightParenthes is, toNode.rightParenthesis)), isEqual(node.body, toNode.body)); 8447 return javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(javaBooleanAnd(isEqualTo kens(node.keyword, toNode.keyword), isEqualTokens(node.leftParenthesis, toNode.l eftParenthesis)), isEqualNodes(node.condition, toNode.condition)), isEqualTokens (node.rightParenthesis, toNode.rightParenthesis)), isEqualNodes(node.body, toNod e.body));
8448 } 8448 }
8449 8449
8450 bool visitWithClause(WithClause node) { 8450 bool visitWithClause(WithClause node) {
8451 WithClause toNode = this._toNode as WithClause; 8451 WithClause toNode = this._toNode as WithClause;
8452 return javaBooleanAnd(isEqual3(node.withKeyword, toNode.withKeyword), isEqua l2(node.mixinTypes, toNode.mixinTypes)); 8452 return javaBooleanAnd(isEqualTokens(node.withKeyword, toNode.withKeyword), i sEqualNodeLists(node.mixinTypes, toNode.mixinTypes));
8453 } 8453 }
8454 8454
8455 /** 8455 /**
8456 * Return `true` if the given lists of AST nodes have the same size and corres ponding
8457 * elements are equal.
8458 *
8459 * @param first the first node being compared
8460 * @param second the second node being compared
8461 * @return `true` if the given AST nodes have the same size and corresponding elements are
8462 * equal
8463 */
8464 bool isEqualNodeLists(NodeList first, NodeList second) {
8465 if (first == null) {
8466 return second == null;
8467 } else if (second == null) {
8468 return false;
8469 }
8470 int size = first.length;
8471 if (second.length != size) {
8472 return false;
8473 }
8474 bool equal = true;
8475 for (int i = 0; i < size; i++) {
8476 if (!isEqualNodes(first[i], second[i])) {
8477 equal = false;
8478 }
8479 }
8480 return equal;
8481 }
8482
8483 /**
8456 * Return `true` if the given AST nodes have the same structure. As a side-eff ect, if the 8484 * Return `true` if the given AST nodes have the same structure. As a side-eff ect, if the
8457 * nodes do have the same structure, any resolution data from the first node w ill be copied to the 8485 * nodes do have the same structure, any resolution data from the first node w ill be copied to the
8458 * second node. 8486 * second node.
8459 * 8487 *
8460 * @param fromNode the node from which resolution information will be copied 8488 * @param fromNode the node from which resolution information will be copied
8461 * @param toNode the node to which resolution information will be copied 8489 * @param toNode the node to which resolution information will be copied
8462 * @return `true` if the given AST nodes have the same structure 8490 * @return `true` if the given AST nodes have the same structure
8463 */ 8491 */
8464 bool isEqual(AstNode fromNode, AstNode toNode) { 8492 bool isEqualNodes(AstNode fromNode, AstNode toNode) {
8465 if (fromNode == null) { 8493 if (fromNode == null) {
8466 return toNode == null; 8494 return toNode == null;
8467 } else if (toNode == null) { 8495 } else if (toNode == null) {
8468 return false; 8496 return false;
8469 } else if (fromNode.runtimeType == toNode.runtimeType) { 8497 } else if (fromNode.runtimeType == toNode.runtimeType) {
8470 this._toNode = toNode; 8498 this._toNode = toNode;
8471 return fromNode.accept(this); 8499 return fromNode.accept(this);
8472 } 8500 }
8473 // 8501 //
8474 // Check for a simple transformation caused by entering a period. 8502 // Check for a simple transformation caused by entering a period.
8475 // 8503 //
8476 if (toNode is PrefixedIdentifier) { 8504 if (toNode is PrefixedIdentifier) {
8477 SimpleIdentifier prefix = toNode.prefix; 8505 SimpleIdentifier prefix = toNode.prefix;
8478 if (fromNode.runtimeType == prefix.runtimeType) { 8506 if (fromNode.runtimeType == prefix.runtimeType) {
8479 this._toNode = prefix; 8507 this._toNode = prefix;
8480 return fromNode.accept(this); 8508 return fromNode.accept(this);
8481 } 8509 }
8482 } else if (toNode is PropertyAccess) { 8510 } else if (toNode is PropertyAccess) {
8483 Expression target = toNode.target; 8511 Expression target = toNode.target;
8484 if (fromNode.runtimeType == target.runtimeType) { 8512 if (fromNode.runtimeType == target.runtimeType) {
8485 this._toNode = target; 8513 this._toNode = target;
8486 return fromNode.accept(this); 8514 return fromNode.accept(this);
8487 } 8515 }
8488 } 8516 }
8489 return false; 8517 return false;
8490 } 8518 }
8491 8519
8492 /** 8520 /**
8493 * Return `true` if the given lists of AST nodes have the same size and corres ponding 8521 * Return `true` if the given arrays of tokens have the same length and corres ponding
8494 * elements are equal. 8522 * elements are equal.
8495 * 8523 *
8496 * @param first the first node being compared 8524 * @param first the first node being compared
8497 * @param second the second node being compared 8525 * @param second the second node being compared
8498 * @return `true` if the given AST nodes have the same size and corresponding elements are 8526 * @return `true` if the given arrays of tokens have the same length and corre sponding
8499 * equal 8527 * elements are equal
8500 */ 8528 */
8501 bool isEqual2(NodeList first, NodeList second) { 8529 bool isEqualTokenLists(List<Token> first, List<Token> second) {
8502 if (first == null) { 8530 int length = first.length;
8503 return second == null; 8531 if (second.length != length) {
8504 } else if (second == null) {
8505 return false; 8532 return false;
8506 } 8533 }
8507 int size = first.length; 8534 for (int i = 0; i < length; i++) {
8508 if (second.length != size) { 8535 if (!isEqualTokens(first[i], second[i])) {
8509 return false; 8536 return false;
8510 }
8511 bool equal = true;
8512 for (int i = 0; i < size; i++) {
8513 if (!isEqual(first[i], second[i])) {
8514 equal = false;
8515 } 8537 }
8516 } 8538 }
8517 return equal; 8539 return true;
8518 } 8540 }
8519 8541
8520 /** 8542 /**
8521 * Return `true` if the given tokens have the same structure. 8543 * Return `true` if the given tokens have the same structure.
8522 * 8544 *
8523 * @param first the first node being compared 8545 * @param first the first node being compared
8524 * @param second the second node being compared 8546 * @param second the second node being compared
8525 * @return `true` if the given tokens have the same structure 8547 * @return `true` if the given tokens have the same structure
8526 */ 8548 */
8527 bool isEqual3(Token first, Token second) { 8549 bool isEqualTokens(Token first, Token second) {
8528 if (first == null) { 8550 if (first == null) {
8529 return second == null; 8551 return second == null;
8530 } else if (second == null) { 8552 } else if (second == null) {
8531 return false; 8553 return false;
8532 } 8554 }
8533 return first.lexeme == second.lexeme; 8555 return first.lexeme == second.lexeme;
8534 } 8556 }
8535
8536 /**
8537 * Return `true` if the given arrays of tokens have the same length and corres ponding
8538 * elements are equal.
8539 *
8540 * @param first the first node being compared
8541 * @param second the second node being compared
8542 * @return `true` if the given arrays of tokens have the same length and corre sponding
8543 * elements are equal
8544 */
8545 bool isEqual4(List<Token> first, List<Token> second) {
8546 int length = first.length;
8547 if (second.length != length) {
8548 return false;
8549 }
8550 for (int i = 0; i < length; i++) {
8551 if (!isEqual3(first[i], second[i])) {
8552 return false;
8553 }
8554 }
8555 return true;
8556 }
8557 } 8557 }
8558 8558
8559 /** 8559 /**
8560 * Instances of the class {link ToFormattedSourceVisitor} write a source represe ntation of a visited 8560 * Instances of the class {link ToFormattedSourceVisitor} write a source represe ntation of a visited
8561 * AST node (and all of it's children) to a writer. 8561 * AST node (and all of it's children) to a writer.
8562 */ 8562 */
8563 class ToFormattedSourceVisitor implements AstVisitor<Object> { 8563 class ToFormattedSourceVisitor implements AstVisitor<Object> {
8564 static String COMMENTS_KEY = "List of comments before statement"; 8564 static String COMMENTS_KEY = "List of comments before statement";
8565 8565
8566 /** 8566 /**
8567 * The writer to which the source is to be written. 8567 * The writer to which the source is to be written.
8568 */ 8568 */
8569 PrintWriter _writer; 8569 PrintWriter _writer;
8570 8570
8571 int _indentLevel = 0; 8571 int _indentLevel = 0;
8572 8572
8573 String _indentString = ""; 8573 String _indentString = "";
8574 8574
8575 /** 8575 /**
8576 * Initialize a newly created visitor to write source code representing the vi sited nodes to the 8576 * Initialize a newly created visitor to write source code representing the vi sited nodes to the
8577 * given writer. 8577 * given writer.
8578 * 8578 *
8579 * @param writer the writer to which the source is to be written 8579 * @param writer the writer to which the source is to be written
8580 */ 8580 */
8581 ToFormattedSourceVisitor(PrintWriter writer) { 8581 ToFormattedSourceVisitor(PrintWriter writer) {
8582 this._writer = writer; 8582 this._writer = writer;
8583 } 8583 }
8584 8584
8585 Object visitAdjacentStrings(AdjacentStrings node) { 8585 Object visitAdjacentStrings(AdjacentStrings node) {
8586 visitList5(node.strings, " "); 8586 visitNodeListWithSeparator(node.strings, " ");
8587 return null; 8587 return null;
8588 } 8588 }
8589 8589
8590 Object visitAnnotation(Annotation node) { 8590 Object visitAnnotation(Annotation node) {
8591 _writer.print('@'); 8591 _writer.print('@');
8592 visit(node.name); 8592 visitNode(node.name);
8593 visit7(".", node.constructorName); 8593 visitNodeWithPrefix(".", node.constructorName);
8594 visit(node.arguments); 8594 visitNode(node.arguments);
8595 return null; 8595 return null;
8596 } 8596 }
8597 8597
8598 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 8598 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
8599 _writer.print('?'); 8599 _writer.print('?');
8600 visit(node.identifier); 8600 visitNode(node.identifier);
8601 return null; 8601 return null;
8602 } 8602 }
8603 8603
8604 Object visitArgumentList(ArgumentList node) { 8604 Object visitArgumentList(ArgumentList node) {
8605 _writer.print('('); 8605 _writer.print('(');
8606 visitList5(node.arguments, ", "); 8606 visitNodeListWithSeparator(node.arguments, ", ");
8607 _writer.print(')'); 8607 _writer.print(')');
8608 return null; 8608 return null;
8609 } 8609 }
8610 8610
8611 Object visitAsExpression(AsExpression node) { 8611 Object visitAsExpression(AsExpression node) {
8612 visit(node.expression); 8612 visitNode(node.expression);
8613 _writer.print(" as "); 8613 _writer.print(" as ");
8614 visit(node.type); 8614 visitNode(node.type);
8615 return null; 8615 return null;
8616 } 8616 }
8617 8617
8618 Object visitAssertStatement(AssertStatement node) { 8618 Object visitAssertStatement(AssertStatement node) {
8619 _writer.print("assert("); 8619 _writer.print("assert(");
8620 visit(node.condition); 8620 visitNode(node.condition);
8621 _writer.print(");"); 8621 _writer.print(");");
8622 return null; 8622 return null;
8623 } 8623 }
8624 8624
8625 Object visitAssignmentExpression(AssignmentExpression node) { 8625 Object visitAssignmentExpression(AssignmentExpression node) {
8626 visit(node.leftHandSide); 8626 visitNode(node.leftHandSide);
8627 _writer.print(' '); 8627 _writer.print(' ');
8628 _writer.print(node.operator.lexeme); 8628 _writer.print(node.operator.lexeme);
8629 _writer.print(' '); 8629 _writer.print(' ');
8630 visit(node.rightHandSide); 8630 visitNode(node.rightHandSide);
8631 return null; 8631 return null;
8632 } 8632 }
8633 8633
8634 Object visitBinaryExpression(BinaryExpression node) { 8634 Object visitBinaryExpression(BinaryExpression node) {
8635 visit(node.leftOperand); 8635 visitNode(node.leftOperand);
8636 _writer.print(' '); 8636 _writer.print(' ');
8637 _writer.print(node.operator.lexeme); 8637 _writer.print(node.operator.lexeme);
8638 _writer.print(' '); 8638 _writer.print(' ');
8639 visit(node.rightOperand); 8639 visitNode(node.rightOperand);
8640 return null; 8640 return null;
8641 } 8641 }
8642 8642
8643 Object visitBlock(Block node) { 8643 Object visitBlock(Block node) {
8644 _writer.print('{'); 8644 _writer.print('{');
8645 { 8645 {
8646 indentInc(); 8646 indentInc();
8647 visitList7("\n", node.statements, "\n"); 8647 visitNodeListWithSeparatorAndPrefix("\n", node.statements, "\n");
8648 indentDec(); 8648 indentDec();
8649 } 8649 }
8650 nl2(); 8650 nl2();
8651 _writer.print('}'); 8651 _writer.print('}');
8652 return null; 8652 return null;
8653 } 8653 }
8654 8654
8655 Object visitBlockFunctionBody(BlockFunctionBody node) { 8655 Object visitBlockFunctionBody(BlockFunctionBody node) {
8656 visit(node.block); 8656 visitNode(node.block);
8657 return null; 8657 return null;
8658 } 8658 }
8659 8659
8660 Object visitBooleanLiteral(BooleanLiteral node) { 8660 Object visitBooleanLiteral(BooleanLiteral node) {
8661 _writer.print(node.literal.lexeme); 8661 _writer.print(node.literal.lexeme);
8662 return null; 8662 return null;
8663 } 8663 }
8664 8664
8665 Object visitBreakStatement(BreakStatement node) { 8665 Object visitBreakStatement(BreakStatement node) {
8666 _writer.print("break"); 8666 _writer.print("break");
8667 visit7(" ", node.label); 8667 visitNodeWithPrefix(" ", node.label);
8668 _writer.print(";"); 8668 _writer.print(";");
8669 return null; 8669 return null;
8670 } 8670 }
8671 8671
8672 Object visitCascadeExpression(CascadeExpression node) { 8672 Object visitCascadeExpression(CascadeExpression node) {
8673 visit(node.target); 8673 visitNode(node.target);
8674 visitList(node.cascadeSections); 8674 visitNodeList(node.cascadeSections);
8675 return null; 8675 return null;
8676 } 8676 }
8677 8677
8678 Object visitCatchClause(CatchClause node) { 8678 Object visitCatchClause(CatchClause node) {
8679 visit7("on ", node.exceptionType); 8679 visitNodeWithPrefix("on ", node.exceptionType);
8680 if (node.catchKeyword != null) { 8680 if (node.catchKeyword != null) {
8681 if (node.exceptionType != null) { 8681 if (node.exceptionType != null) {
8682 _writer.print(' '); 8682 _writer.print(' ');
8683 } 8683 }
8684 _writer.print("catch ("); 8684 _writer.print("catch (");
8685 visit(node.exceptionParameter); 8685 visitNode(node.exceptionParameter);
8686 visit7(", ", node.stackTraceParameter); 8686 visitNodeWithPrefix(", ", node.stackTraceParameter);
8687 _writer.print(") "); 8687 _writer.print(") ");
8688 } else { 8688 } else {
8689 _writer.print(" "); 8689 _writer.print(" ");
8690 } 8690 }
8691 visit(node.body); 8691 visitNode(node.body);
8692 return null; 8692 return null;
8693 } 8693 }
8694 8694
8695 Object visitClassDeclaration(ClassDeclaration node) { 8695 Object visitClassDeclaration(ClassDeclaration node) {
8696 visit(node.documentationComment); 8696 visitNode(node.documentationComment);
8697 visit8(node.abstractKeyword, " "); 8697 visitTokenWithSuffix(node.abstractKeyword, " ");
8698 _writer.print("class "); 8698 _writer.print("class ");
8699 visit(node.name); 8699 visitNode(node.name);
8700 visit(node.typeParameters); 8700 visitNode(node.typeParameters);
8701 visit7(" ", node.extendsClause); 8701 visitNodeWithPrefix(" ", node.extendsClause);
8702 visit7(" ", node.withClause); 8702 visitNodeWithPrefix(" ", node.withClause);
8703 visit7(" ", node.implementsClause); 8703 visitNodeWithPrefix(" ", node.implementsClause);
8704 _writer.print(" {"); 8704 _writer.print(" {");
8705 { 8705 {
8706 indentInc(); 8706 indentInc();
8707 visitList7("\n", node.members, "\n\n"); 8707 visitNodeListWithSeparatorAndPrefix("\n", node.members, "\n\n");
8708 indentDec(); 8708 indentDec();
8709 } 8709 }
8710 nl2(); 8710 nl2();
8711 _writer.print("}"); 8711 _writer.print("}");
8712 return null; 8712 return null;
8713 } 8713 }
8714 8714
8715 Object visitClassTypeAlias(ClassTypeAlias node) { 8715 Object visitClassTypeAlias(ClassTypeAlias node) {
8716 _writer.print("typedef "); 8716 _writer.print("typedef ");
8717 visit(node.name); 8717 visitNode(node.name);
8718 visit(node.typeParameters); 8718 visitNode(node.typeParameters);
8719 _writer.print(" = "); 8719 _writer.print(" = ");
8720 if (node.abstractKeyword != null) { 8720 if (node.abstractKeyword != null) {
8721 _writer.print("abstract "); 8721 _writer.print("abstract ");
8722 } 8722 }
8723 visit(node.superclass); 8723 visitNode(node.superclass);
8724 visit7(" ", node.withClause); 8724 visitNodeWithPrefix(" ", node.withClause);
8725 visit7(" ", node.implementsClause); 8725 visitNodeWithPrefix(" ", node.implementsClause);
8726 _writer.print(";"); 8726 _writer.print(";");
8727 return null; 8727 return null;
8728 } 8728 }
8729 8729
8730 Object visitComment(Comment node) { 8730 Object visitComment(Comment node) {
8731 Token token = node.beginToken; 8731 Token token = node.beginToken;
8732 while (token != null) { 8732 while (token != null) {
8733 bool firstLine = true; 8733 bool firstLine = true;
8734 for (String line in StringUtils.split(token.lexeme, "\n")) { 8734 for (String line in StringUtils.split(token.lexeme, "\n")) {
8735 if (firstLine) { 8735 if (firstLine) {
(...skipping 10 matching lines...) Expand all
8746 } 8746 }
8747 } 8747 }
8748 return null; 8748 return null;
8749 } 8749 }
8750 8750
8751 Object visitCommentReference(CommentReference node) => null; 8751 Object visitCommentReference(CommentReference node) => null;
8752 8752
8753 Object visitCompilationUnit(CompilationUnit node) { 8753 Object visitCompilationUnit(CompilationUnit node) {
8754 ScriptTag scriptTag = node.scriptTag; 8754 ScriptTag scriptTag = node.scriptTag;
8755 NodeList<Directive> directives = node.directives; 8755 NodeList<Directive> directives = node.directives;
8756 visit(scriptTag); 8756 visitNode(scriptTag);
8757 // directives 8757 // directives
8758 String prefix = scriptTag == null ? "" : " "; 8758 String prefix = scriptTag == null ? "" : " ";
8759 visitList7(prefix, directives, "\n"); 8759 visitNodeListWithSeparatorAndPrefix(prefix, directives, "\n");
8760 nl(); 8760 nl();
8761 // declarations 8761 // declarations
8762 prefix = scriptTag == null && directives.isEmpty ? "" : "\n"; 8762 prefix = scriptTag == null && directives.isEmpty ? "" : "\n";
8763 visitList7(prefix, node.declarations, "\n\n"); 8763 visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, "\n\n");
8764 return null; 8764 return null;
8765 } 8765 }
8766 8766
8767 Object visitConditionalExpression(ConditionalExpression node) { 8767 Object visitConditionalExpression(ConditionalExpression node) {
8768 visit(node.condition); 8768 visitNode(node.condition);
8769 _writer.print(" ? "); 8769 _writer.print(" ? ");
8770 visit(node.thenExpression); 8770 visitNode(node.thenExpression);
8771 _writer.print(" : "); 8771 _writer.print(" : ");
8772 visit(node.elseExpression); 8772 visitNode(node.elseExpression);
8773 return null; 8773 return null;
8774 } 8774 }
8775 8775
8776 Object visitConstructorDeclaration(ConstructorDeclaration node) { 8776 Object visitConstructorDeclaration(ConstructorDeclaration node) {
8777 visit(node.documentationComment); 8777 visitNode(node.documentationComment);
8778 visit8(node.externalKeyword, " "); 8778 visitTokenWithSuffix(node.externalKeyword, " ");
8779 visit8(node.constKeyword, " "); 8779 visitTokenWithSuffix(node.constKeyword, " ");
8780 visit8(node.factoryKeyword, " "); 8780 visitTokenWithSuffix(node.factoryKeyword, " ");
8781 visit(node.returnType); 8781 visitNode(node.returnType);
8782 visit7(".", node.name); 8782 visitNodeWithPrefix(".", node.name);
8783 visit(node.parameters); 8783 visitNode(node.parameters);
8784 visitList7(" : ", node.initializers, ", "); 8784 visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", ");
8785 visit7(" = ", node.redirectedConstructor); 8785 visitNodeWithPrefix(" = ", node.redirectedConstructor);
8786 if (node.body is! EmptyFunctionBody) { 8786 if (node.body is! EmptyFunctionBody) {
8787 _writer.print(' '); 8787 _writer.print(' ');
8788 } 8788 }
8789 visit(node.body); 8789 visitNode(node.body);
8790 return null; 8790 return null;
8791 } 8791 }
8792 8792
8793 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 8793 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
8794 visit8(node.keyword, "."); 8794 visitTokenWithSuffix(node.keyword, ".");
8795 visit(node.fieldName); 8795 visitNode(node.fieldName);
8796 _writer.print(" = "); 8796 _writer.print(" = ");
8797 visit(node.expression); 8797 visitNode(node.expression);
8798 return null; 8798 return null;
8799 } 8799 }
8800 8800
8801 Object visitConstructorName(ConstructorName node) { 8801 Object visitConstructorName(ConstructorName node) {
8802 visit(node.type); 8802 visitNode(node.type);
8803 visit7(".", node.name); 8803 visitNodeWithPrefix(".", node.name);
8804 return null; 8804 return null;
8805 } 8805 }
8806 8806
8807 Object visitContinueStatement(ContinueStatement node) { 8807 Object visitContinueStatement(ContinueStatement node) {
8808 _writer.print("continue"); 8808 _writer.print("continue");
8809 visit7(" ", node.label); 8809 visitNodeWithPrefix(" ", node.label);
8810 _writer.print(";"); 8810 _writer.print(";");
8811 return null; 8811 return null;
8812 } 8812 }
8813 8813
8814 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 8814 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
8815 visit8(node.keyword, " "); 8815 visitTokenWithSuffix(node.keyword, " ");
8816 visit6(node.type, " "); 8816 visitNodeWithSuffix(node.type, " ");
8817 visit(node.identifier); 8817 visitNode(node.identifier);
8818 return null; 8818 return null;
8819 } 8819 }
8820 8820
8821 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 8821 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
8822 visit(node.parameter); 8822 visitNode(node.parameter);
8823 if (node.separator != null) { 8823 if (node.separator != null) {
8824 _writer.print(" "); 8824 _writer.print(" ");
8825 _writer.print(node.separator.lexeme); 8825 _writer.print(node.separator.lexeme);
8826 visit7(" ", node.defaultValue); 8826 visitNodeWithPrefix(" ", node.defaultValue);
8827 } 8827 }
8828 return null; 8828 return null;
8829 } 8829 }
8830 8830
8831 Object visitDoStatement(DoStatement node) { 8831 Object visitDoStatement(DoStatement node) {
8832 _writer.print("do "); 8832 _writer.print("do ");
8833 visit(node.body); 8833 visitNode(node.body);
8834 _writer.print(" while ("); 8834 _writer.print(" while (");
8835 visit(node.condition); 8835 visitNode(node.condition);
8836 _writer.print(");"); 8836 _writer.print(");");
8837 return null; 8837 return null;
8838 } 8838 }
8839 8839
8840 Object visitDoubleLiteral(DoubleLiteral node) { 8840 Object visitDoubleLiteral(DoubleLiteral node) {
8841 _writer.print(node.literal.lexeme); 8841 _writer.print(node.literal.lexeme);
8842 return null; 8842 return null;
8843 } 8843 }
8844 8844
8845 Object visitEmptyFunctionBody(EmptyFunctionBody node) { 8845 Object visitEmptyFunctionBody(EmptyFunctionBody node) {
8846 _writer.print(';'); 8846 _writer.print(';');
8847 return null; 8847 return null;
8848 } 8848 }
8849 8849
8850 Object visitEmptyStatement(EmptyStatement node) { 8850 Object visitEmptyStatement(EmptyStatement node) {
8851 _writer.print(';'); 8851 _writer.print(';');
8852 return null; 8852 return null;
8853 } 8853 }
8854 8854
8855 Object visitExportDirective(ExportDirective node) { 8855 Object visitExportDirective(ExportDirective node) {
8856 _writer.print("export "); 8856 _writer.print("export ");
8857 visit(node.uri); 8857 visitNode(node.uri);
8858 visitList7(" ", node.combinators, " "); 8858 visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
8859 _writer.print(';'); 8859 _writer.print(';');
8860 return null; 8860 return null;
8861 } 8861 }
8862 8862
8863 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 8863 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
8864 _writer.print("=> "); 8864 _writer.print("=> ");
8865 visit(node.expression); 8865 visitNode(node.expression);
8866 if (node.semicolon != null) { 8866 if (node.semicolon != null) {
8867 _writer.print(';'); 8867 _writer.print(';');
8868 } 8868 }
8869 return null; 8869 return null;
8870 } 8870 }
8871 8871
8872 Object visitExpressionStatement(ExpressionStatement node) { 8872 Object visitExpressionStatement(ExpressionStatement node) {
8873 visit(node.expression); 8873 visitNode(node.expression);
8874 _writer.print(';'); 8874 _writer.print(';');
8875 return null; 8875 return null;
8876 } 8876 }
8877 8877
8878 Object visitExtendsClause(ExtendsClause node) { 8878 Object visitExtendsClause(ExtendsClause node) {
8879 _writer.print("extends "); 8879 _writer.print("extends ");
8880 visit(node.superclass); 8880 visitNode(node.superclass);
8881 return null; 8881 return null;
8882 } 8882 }
8883 8883
8884 Object visitFieldDeclaration(FieldDeclaration node) { 8884 Object visitFieldDeclaration(FieldDeclaration node) {
8885 visit(node.documentationComment); 8885 visitNode(node.documentationComment);
8886 visit8(node.staticKeyword, " "); 8886 visitTokenWithSuffix(node.staticKeyword, " ");
8887 visit(node.fields); 8887 visitNode(node.fields);
8888 _writer.print(";"); 8888 _writer.print(";");
8889 return null; 8889 return null;
8890 } 8890 }
8891 8891
8892 Object visitFieldFormalParameter(FieldFormalParameter node) { 8892 Object visitFieldFormalParameter(FieldFormalParameter node) {
8893 visit8(node.keyword, " "); 8893 visitTokenWithSuffix(node.keyword, " ");
8894 visit6(node.type, " "); 8894 visitNodeWithSuffix(node.type, " ");
8895 _writer.print("this."); 8895 _writer.print("this.");
8896 visit(node.identifier); 8896 visitNode(node.identifier);
8897 visit(node.parameters); 8897 visitNode(node.parameters);
8898 return null; 8898 return null;
8899 } 8899 }
8900 8900
8901 Object visitForEachStatement(ForEachStatement node) { 8901 Object visitForEachStatement(ForEachStatement node) {
8902 DeclaredIdentifier loopVariable = node.loopVariable; 8902 DeclaredIdentifier loopVariable = node.loopVariable;
8903 _writer.print("for ("); 8903 _writer.print("for (");
8904 if (loopVariable == null) { 8904 if (loopVariable == null) {
8905 visit(node.identifier); 8905 visitNode(node.identifier);
8906 } else { 8906 } else {
8907 visit(loopVariable); 8907 visitNode(loopVariable);
8908 } 8908 }
8909 _writer.print(" in "); 8909 _writer.print(" in ");
8910 visit(node.iterator); 8910 visitNode(node.iterator);
8911 _writer.print(") "); 8911 _writer.print(") ");
8912 visit(node.body); 8912 visitNode(node.body);
8913 return null; 8913 return null;
8914 } 8914 }
8915 8915
8916 Object visitFormalParameterList(FormalParameterList node) { 8916 Object visitFormalParameterList(FormalParameterList node) {
8917 String groupEnd = null; 8917 String groupEnd = null;
8918 _writer.print('('); 8918 _writer.print('(');
8919 NodeList<FormalParameter> parameters = node.parameters; 8919 NodeList<FormalParameter> parameters = node.parameters;
8920 int size = parameters.length; 8920 int size = parameters.length;
8921 for (int i = 0; i < size; i++) { 8921 for (int i = 0; i < size; i++) {
8922 FormalParameter parameter = parameters[i]; 8922 FormalParameter parameter = parameters[i];
(...skipping 15 matching lines...) Expand all
8938 _writer.print(groupEnd); 8938 _writer.print(groupEnd);
8939 } 8939 }
8940 _writer.print(')'); 8940 _writer.print(')');
8941 return null; 8941 return null;
8942 } 8942 }
8943 8943
8944 Object visitForStatement(ForStatement node) { 8944 Object visitForStatement(ForStatement node) {
8945 Expression initialization = node.initialization; 8945 Expression initialization = node.initialization;
8946 _writer.print("for ("); 8946 _writer.print("for (");
8947 if (initialization != null) { 8947 if (initialization != null) {
8948 visit(initialization); 8948 visitNode(initialization);
8949 } else { 8949 } else {
8950 visit(node.variables); 8950 visitNode(node.variables);
8951 } 8951 }
8952 _writer.print(";"); 8952 _writer.print(";");
8953 visit7(" ", node.condition); 8953 visitNodeWithPrefix(" ", node.condition);
8954 _writer.print(";"); 8954 _writer.print(";");
8955 visitList7(" ", node.updaters, ", "); 8955 visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", ");
8956 _writer.print(") "); 8956 _writer.print(") ");
8957 visit(node.body); 8957 visitNode(node.body);
8958 return null; 8958 return null;
8959 } 8959 }
8960 8960
8961 Object visitFunctionDeclaration(FunctionDeclaration node) { 8961 Object visitFunctionDeclaration(FunctionDeclaration node) {
8962 visit6(node.returnType, " "); 8962 visitNodeWithSuffix(node.returnType, " ");
8963 visit8(node.propertyKeyword, " "); 8963 visitTokenWithSuffix(node.propertyKeyword, " ");
8964 visit(node.name); 8964 visitNode(node.name);
8965 visit(node.functionExpression); 8965 visitNode(node.functionExpression);
8966 return null; 8966 return null;
8967 } 8967 }
8968 8968
8969 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { 8969 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
8970 visit(node.functionDeclaration); 8970 visitNode(node.functionDeclaration);
8971 _writer.print(';'); 8971 _writer.print(';');
8972 return null; 8972 return null;
8973 } 8973 }
8974 8974
8975 Object visitFunctionExpression(FunctionExpression node) { 8975 Object visitFunctionExpression(FunctionExpression node) {
8976 visit(node.parameters); 8976 visitNode(node.parameters);
8977 _writer.print(' '); 8977 _writer.print(' ');
8978 visit(node.body); 8978 visitNode(node.body);
8979 return null; 8979 return null;
8980 } 8980 }
8981 8981
8982 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 8982 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
8983 visit(node.function); 8983 visitNode(node.function);
8984 visit(node.argumentList); 8984 visitNode(node.argumentList);
8985 return null; 8985 return null;
8986 } 8986 }
8987 8987
8988 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 8988 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
8989 _writer.print("typedef "); 8989 _writer.print("typedef ");
8990 visit6(node.returnType, " "); 8990 visitNodeWithSuffix(node.returnType, " ");
8991 visit(node.name); 8991 visitNode(node.name);
8992 visit(node.typeParameters); 8992 visitNode(node.typeParameters);
8993 visit(node.parameters); 8993 visitNode(node.parameters);
8994 _writer.print(";"); 8994 _writer.print(";");
8995 return null; 8995 return null;
8996 } 8996 }
8997 8997
8998 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 8998 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
8999 visit6(node.returnType, " "); 8999 visitNodeWithSuffix(node.returnType, " ");
9000 visit(node.identifier); 9000 visitNode(node.identifier);
9001 visit(node.parameters); 9001 visitNode(node.parameters);
9002 return null; 9002 return null;
9003 } 9003 }
9004 9004
9005 Object visitHideCombinator(HideCombinator node) { 9005 Object visitHideCombinator(HideCombinator node) {
9006 _writer.print("hide "); 9006 _writer.print("hide ");
9007 visitList5(node.hiddenNames, ", "); 9007 visitNodeListWithSeparator(node.hiddenNames, ", ");
9008 return null; 9008 return null;
9009 } 9009 }
9010 9010
9011 Object visitIfStatement(IfStatement node) { 9011 Object visitIfStatement(IfStatement node) {
9012 _writer.print("if ("); 9012 _writer.print("if (");
9013 visit(node.condition); 9013 visitNode(node.condition);
9014 _writer.print(") "); 9014 _writer.print(") ");
9015 visit(node.thenStatement); 9015 visitNode(node.thenStatement);
9016 visit7(" else ", node.elseStatement); 9016 visitNodeWithPrefix(" else ", node.elseStatement);
9017 return null; 9017 return null;
9018 } 9018 }
9019 9019
9020 Object visitImplementsClause(ImplementsClause node) { 9020 Object visitImplementsClause(ImplementsClause node) {
9021 _writer.print("implements "); 9021 _writer.print("implements ");
9022 visitList5(node.interfaces, ", "); 9022 visitNodeListWithSeparator(node.interfaces, ", ");
9023 return null; 9023 return null;
9024 } 9024 }
9025 9025
9026 Object visitImportDirective(ImportDirective node) { 9026 Object visitImportDirective(ImportDirective node) {
9027 _writer.print("import "); 9027 _writer.print("import ");
9028 visit(node.uri); 9028 visitNode(node.uri);
9029 visit7(" as ", node.prefix); 9029 visitNodeWithPrefix(" as ", node.prefix);
9030 visitList7(" ", node.combinators, " "); 9030 visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
9031 _writer.print(';'); 9031 _writer.print(';');
9032 return null; 9032 return null;
9033 } 9033 }
9034 9034
9035 Object visitIndexExpression(IndexExpression node) { 9035 Object visitIndexExpression(IndexExpression node) {
9036 if (node.isCascaded) { 9036 if (node.isCascaded) {
9037 _writer.print(".."); 9037 _writer.print("..");
9038 } else { 9038 } else {
9039 visit(node.target); 9039 visitNode(node.target);
9040 } 9040 }
9041 _writer.print('['); 9041 _writer.print('[');
9042 visit(node.index); 9042 visitNode(node.index);
9043 _writer.print(']'); 9043 _writer.print(']');
9044 return null; 9044 return null;
9045 } 9045 }
9046 9046
9047 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 9047 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
9048 visit8(node.keyword, " "); 9048 visitTokenWithSuffix(node.keyword, " ");
9049 visit(node.constructorName); 9049 visitNode(node.constructorName);
9050 visit(node.argumentList); 9050 visitNode(node.argumentList);
9051 return null; 9051 return null;
9052 } 9052 }
9053 9053
9054 Object visitIntegerLiteral(IntegerLiteral node) { 9054 Object visitIntegerLiteral(IntegerLiteral node) {
9055 _writer.print(node.literal.lexeme); 9055 _writer.print(node.literal.lexeme);
9056 return null; 9056 return null;
9057 } 9057 }
9058 9058
9059 Object visitInterpolationExpression(InterpolationExpression node) { 9059 Object visitInterpolationExpression(InterpolationExpression node) {
9060 if (node.rightBracket != null) { 9060 if (node.rightBracket != null) {
9061 _writer.print("\${"); 9061 _writer.print("\${");
9062 visit(node.expression); 9062 visitNode(node.expression);
9063 _writer.print("}"); 9063 _writer.print("}");
9064 } else { 9064 } else {
9065 _writer.print("\$"); 9065 _writer.print("\$");
9066 visit(node.expression); 9066 visitNode(node.expression);
9067 } 9067 }
9068 return null; 9068 return null;
9069 } 9069 }
9070 9070
9071 Object visitInterpolationString(InterpolationString node) { 9071 Object visitInterpolationString(InterpolationString node) {
9072 _writer.print(node.contents.lexeme); 9072 _writer.print(node.contents.lexeme);
9073 return null; 9073 return null;
9074 } 9074 }
9075 9075
9076 Object visitIsExpression(IsExpression node) { 9076 Object visitIsExpression(IsExpression node) {
9077 visit(node.expression); 9077 visitNode(node.expression);
9078 if (node.notOperator == null) { 9078 if (node.notOperator == null) {
9079 _writer.print(" is "); 9079 _writer.print(" is ");
9080 } else { 9080 } else {
9081 _writer.print(" is! "); 9081 _writer.print(" is! ");
9082 } 9082 }
9083 visit(node.type); 9083 visitNode(node.type);
9084 return null; 9084 return null;
9085 } 9085 }
9086 9086
9087 Object visitLabel(Label node) { 9087 Object visitLabel(Label node) {
9088 visit(node.label); 9088 visitNode(node.label);
9089 _writer.print(":"); 9089 _writer.print(":");
9090 return null; 9090 return null;
9091 } 9091 }
9092 9092
9093 Object visitLabeledStatement(LabeledStatement node) { 9093 Object visitLabeledStatement(LabeledStatement node) {
9094 visitList6(node.labels, " ", " "); 9094 visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
9095 visit(node.statement); 9095 visitNode(node.statement);
9096 return null; 9096 return null;
9097 } 9097 }
9098 9098
9099 Object visitLibraryDirective(LibraryDirective node) { 9099 Object visitLibraryDirective(LibraryDirective node) {
9100 _writer.print("library "); 9100 _writer.print("library ");
9101 visit(node.name); 9101 visitNode(node.name);
9102 _writer.print(';'); 9102 _writer.print(';');
9103 nl(); 9103 nl();
9104 return null; 9104 return null;
9105 } 9105 }
9106 9106
9107 Object visitLibraryIdentifier(LibraryIdentifier node) { 9107 Object visitLibraryIdentifier(LibraryIdentifier node) {
9108 _writer.print(node.name); 9108 _writer.print(node.name);
9109 return null; 9109 return null;
9110 } 9110 }
9111 9111
9112 Object visitListLiteral(ListLiteral node) { 9112 Object visitListLiteral(ListLiteral node) {
9113 if (node.constKeyword != null) { 9113 if (node.constKeyword != null) {
9114 _writer.print(node.constKeyword.lexeme); 9114 _writer.print(node.constKeyword.lexeme);
9115 _writer.print(' '); 9115 _writer.print(' ');
9116 } 9116 }
9117 visit6(node.typeArguments, " "); 9117 visitNodeWithSuffix(node.typeArguments, " ");
9118 _writer.print("["); 9118 _writer.print("[");
9119 { 9119 {
9120 NodeList<Expression> elements = node.elements; 9120 NodeList<Expression> elements = node.elements;
9121 if (elements.length < 2 || elements.toString().length < 60) { 9121 if (elements.length < 2 || elements.toString().length < 60) {
9122 visitList5(elements, ", "); 9122 visitNodeListWithSeparator(elements, ", ");
9123 } else { 9123 } else {
9124 String elementIndent = "${_indentString} "; 9124 String elementIndent = "${_indentString} ";
9125 _writer.print("\n"); 9125 _writer.print("\n");
9126 _writer.print(elementIndent); 9126 _writer.print(elementIndent);
9127 visitList5(elements, ",\n${elementIndent}"); 9127 visitNodeListWithSeparator(elements, ",\n${elementIndent}");
9128 } 9128 }
9129 } 9129 }
9130 _writer.print("]"); 9130 _writer.print("]");
9131 return null; 9131 return null;
9132 } 9132 }
9133 9133
9134 Object visitMapLiteral(MapLiteral node) { 9134 Object visitMapLiteral(MapLiteral node) {
9135 if (node.constKeyword != null) { 9135 if (node.constKeyword != null) {
9136 _writer.print(node.constKeyword.lexeme); 9136 _writer.print(node.constKeyword.lexeme);
9137 _writer.print(' '); 9137 _writer.print(' ');
9138 } 9138 }
9139 visit6(node.typeArguments, " "); 9139 visitNodeWithSuffix(node.typeArguments, " ");
9140 _writer.print("{"); 9140 _writer.print("{");
9141 visitList5(node.entries, ", "); 9141 visitNodeListWithSeparator(node.entries, ", ");
9142 _writer.print("}"); 9142 _writer.print("}");
9143 return null; 9143 return null;
9144 } 9144 }
9145 9145
9146 Object visitMapLiteralEntry(MapLiteralEntry node) { 9146 Object visitMapLiteralEntry(MapLiteralEntry node) {
9147 visit(node.key); 9147 visitNode(node.key);
9148 _writer.print(" : "); 9148 _writer.print(" : ");
9149 visit(node.value); 9149 visitNode(node.value);
9150 return null; 9150 return null;
9151 } 9151 }
9152 9152
9153 Object visitMethodDeclaration(MethodDeclaration node) { 9153 Object visitMethodDeclaration(MethodDeclaration node) {
9154 visit(node.documentationComment); 9154 visitNode(node.documentationComment);
9155 visit8(node.externalKeyword, " "); 9155 visitTokenWithSuffix(node.externalKeyword, " ");
9156 visit8(node.modifierKeyword, " "); 9156 visitTokenWithSuffix(node.modifierKeyword, " ");
9157 visit6(node.returnType, " "); 9157 visitNodeWithSuffix(node.returnType, " ");
9158 visit8(node.propertyKeyword, " "); 9158 visitTokenWithSuffix(node.propertyKeyword, " ");
9159 visit8(node.operatorKeyword, " "); 9159 visitTokenWithSuffix(node.operatorKeyword, " ");
9160 visit(node.name); 9160 visitNode(node.name);
9161 if (!node.isGetter) { 9161 if (!node.isGetter) {
9162 visit(node.parameters); 9162 visitNode(node.parameters);
9163 } 9163 }
9164 if (node.body is! EmptyFunctionBody) { 9164 if (node.body is! EmptyFunctionBody) {
9165 _writer.print(' '); 9165 _writer.print(' ');
9166 } 9166 }
9167 visit(node.body); 9167 visitNode(node.body);
9168 return null; 9168 return null;
9169 } 9169 }
9170 9170
9171 Object visitMethodInvocation(MethodInvocation node) { 9171 Object visitMethodInvocation(MethodInvocation node) {
9172 if (node.isCascaded) { 9172 if (node.isCascaded) {
9173 _writer.print(".."); 9173 _writer.print("..");
9174 } else { 9174 } else {
9175 visit6(node.target, "."); 9175 visitNodeWithSuffix(node.target, ".");
9176 } 9176 }
9177 visit(node.methodName); 9177 visitNode(node.methodName);
9178 visit(node.argumentList); 9178 visitNode(node.argumentList);
9179 return null; 9179 return null;
9180 } 9180 }
9181 9181
9182 Object visitNamedExpression(NamedExpression node) { 9182 Object visitNamedExpression(NamedExpression node) {
9183 visit(node.name); 9183 visitNode(node.name);
9184 visit7(" ", node.expression); 9184 visitNodeWithPrefix(" ", node.expression);
9185 return null; 9185 return null;
9186 } 9186 }
9187 9187
9188 Object visitNativeClause(NativeClause node) { 9188 Object visitNativeClause(NativeClause node) {
9189 _writer.print("native "); 9189 _writer.print("native ");
9190 visit(node.name); 9190 visitNode(node.name);
9191 return null; 9191 return null;
9192 } 9192 }
9193 9193
9194 Object visitNativeFunctionBody(NativeFunctionBody node) { 9194 Object visitNativeFunctionBody(NativeFunctionBody node) {
9195 _writer.print("native "); 9195 _writer.print("native ");
9196 visit(node.stringLiteral); 9196 visitNode(node.stringLiteral);
9197 _writer.print(';'); 9197 _writer.print(';');
9198 return null; 9198 return null;
9199 } 9199 }
9200 9200
9201 Object visitNullLiteral(NullLiteral node) { 9201 Object visitNullLiteral(NullLiteral node) {
9202 _writer.print("null"); 9202 _writer.print("null");
9203 return null; 9203 return null;
9204 } 9204 }
9205 9205
9206 Object visitParenthesizedExpression(ParenthesizedExpression node) { 9206 Object visitParenthesizedExpression(ParenthesizedExpression node) {
9207 _writer.print('('); 9207 _writer.print('(');
9208 visit(node.expression); 9208 visitNode(node.expression);
9209 _writer.print(')'); 9209 _writer.print(')');
9210 return null; 9210 return null;
9211 } 9211 }
9212 9212
9213 Object visitPartDirective(PartDirective node) { 9213 Object visitPartDirective(PartDirective node) {
9214 _writer.print("part "); 9214 _writer.print("part ");
9215 visit(node.uri); 9215 visitNode(node.uri);
9216 _writer.print(';'); 9216 _writer.print(';');
9217 return null; 9217 return null;
9218 } 9218 }
9219 9219
9220 Object visitPartOfDirective(PartOfDirective node) { 9220 Object visitPartOfDirective(PartOfDirective node) {
9221 _writer.print("part of "); 9221 _writer.print("part of ");
9222 visit(node.libraryName); 9222 visitNode(node.libraryName);
9223 _writer.print(';'); 9223 _writer.print(';');
9224 return null; 9224 return null;
9225 } 9225 }
9226 9226
9227 Object visitPostfixExpression(PostfixExpression node) { 9227 Object visitPostfixExpression(PostfixExpression node) {
9228 visit(node.operand); 9228 visitNode(node.operand);
9229 _writer.print(node.operator.lexeme); 9229 _writer.print(node.operator.lexeme);
9230 return null; 9230 return null;
9231 } 9231 }
9232 9232
9233 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 9233 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
9234 visit(node.prefix); 9234 visitNode(node.prefix);
9235 _writer.print('.'); 9235 _writer.print('.');
9236 visit(node.identifier); 9236 visitNode(node.identifier);
9237 return null; 9237 return null;
9238 } 9238 }
9239 9239
9240 Object visitPrefixExpression(PrefixExpression node) { 9240 Object visitPrefixExpression(PrefixExpression node) {
9241 _writer.print(node.operator.lexeme); 9241 _writer.print(node.operator.lexeme);
9242 visit(node.operand); 9242 visitNode(node.operand);
9243 return null; 9243 return null;
9244 } 9244 }
9245 9245
9246 Object visitPropertyAccess(PropertyAccess node) { 9246 Object visitPropertyAccess(PropertyAccess node) {
9247 if (node.isCascaded) { 9247 if (node.isCascaded) {
9248 _writer.print(".."); 9248 _writer.print("..");
9249 } else { 9249 } else {
9250 visit6(node.target, "."); 9250 visitNodeWithSuffix(node.target, ".");
9251 } 9251 }
9252 visit(node.propertyName); 9252 visitNode(node.propertyName);
9253 return null; 9253 return null;
9254 } 9254 }
9255 9255
9256 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 9256 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
9257 _writer.print("this"); 9257 _writer.print("this");
9258 visit7(".", node.constructorName); 9258 visitNodeWithPrefix(".", node.constructorName);
9259 visit(node.argumentList); 9259 visitNode(node.argumentList);
9260 return null; 9260 return null;
9261 } 9261 }
9262 9262
9263 Object visitRethrowExpression(RethrowExpression node) { 9263 Object visitRethrowExpression(RethrowExpression node) {
9264 _writer.print("rethrow"); 9264 _writer.print("rethrow");
9265 return null; 9265 return null;
9266 } 9266 }
9267 9267
9268 Object visitReturnStatement(ReturnStatement node) { 9268 Object visitReturnStatement(ReturnStatement node) {
9269 Expression expression = node.expression; 9269 Expression expression = node.expression;
9270 if (expression == null) { 9270 if (expression == null) {
9271 _writer.print("return;"); 9271 _writer.print("return;");
9272 } else { 9272 } else {
9273 _writer.print("return "); 9273 _writer.print("return ");
9274 expression.accept(this); 9274 expression.accept(this);
9275 _writer.print(";"); 9275 _writer.print(";");
9276 } 9276 }
9277 return null; 9277 return null;
9278 } 9278 }
9279 9279
9280 Object visitScriptTag(ScriptTag node) { 9280 Object visitScriptTag(ScriptTag node) {
9281 _writer.print(node.scriptTag.lexeme); 9281 _writer.print(node.scriptTag.lexeme);
9282 return null; 9282 return null;
9283 } 9283 }
9284 9284
9285 Object visitShowCombinator(ShowCombinator node) { 9285 Object visitShowCombinator(ShowCombinator node) {
9286 _writer.print("show "); 9286 _writer.print("show ");
9287 visitList5(node.shownNames, ", "); 9287 visitNodeListWithSeparator(node.shownNames, ", ");
9288 return null; 9288 return null;
9289 } 9289 }
9290 9290
9291 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 9291 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
9292 visit8(node.keyword, " "); 9292 visitTokenWithSuffix(node.keyword, " ");
9293 visit6(node.type, " "); 9293 visitNodeWithSuffix(node.type, " ");
9294 visit(node.identifier); 9294 visitNode(node.identifier);
9295 return null; 9295 return null;
9296 } 9296 }
9297 9297
9298 Object visitSimpleIdentifier(SimpleIdentifier node) { 9298 Object visitSimpleIdentifier(SimpleIdentifier node) {
9299 _writer.print(node.token.lexeme); 9299 _writer.print(node.token.lexeme);
9300 return null; 9300 return null;
9301 } 9301 }
9302 9302
9303 Object visitSimpleStringLiteral(SimpleStringLiteral node) { 9303 Object visitSimpleStringLiteral(SimpleStringLiteral node) {
9304 _writer.print(node.literal.lexeme); 9304 _writer.print(node.literal.lexeme);
9305 return null; 9305 return null;
9306 } 9306 }
9307 9307
9308 Object visitStringInterpolation(StringInterpolation node) { 9308 Object visitStringInterpolation(StringInterpolation node) {
9309 visitList(node.elements); 9309 visitNodeList(node.elements);
9310 return null; 9310 return null;
9311 } 9311 }
9312 9312
9313 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 9313 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
9314 _writer.print("super"); 9314 _writer.print("super");
9315 visit7(".", node.constructorName); 9315 visitNodeWithPrefix(".", node.constructorName);
9316 visit(node.argumentList); 9316 visitNode(node.argumentList);
9317 return null; 9317 return null;
9318 } 9318 }
9319 9319
9320 Object visitSuperExpression(SuperExpression node) { 9320 Object visitSuperExpression(SuperExpression node) {
9321 _writer.print("super"); 9321 _writer.print("super");
9322 return null; 9322 return null;
9323 } 9323 }
9324 9324
9325 Object visitSwitchCase(SwitchCase node) { 9325 Object visitSwitchCase(SwitchCase node) {
9326 visitList6(node.labels, " ", " "); 9326 visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
9327 _writer.print("case "); 9327 _writer.print("case ");
9328 visit(node.expression); 9328 visitNode(node.expression);
9329 _writer.print(": "); 9329 _writer.print(": ");
9330 { 9330 {
9331 indentInc(); 9331 indentInc();
9332 visitList5(node.statements, "\n"); 9332 visitNodeListWithSeparator(node.statements, "\n");
9333 indentDec(); 9333 indentDec();
9334 } 9334 }
9335 return null; 9335 return null;
9336 } 9336 }
9337 9337
9338 Object visitSwitchDefault(SwitchDefault node) { 9338 Object visitSwitchDefault(SwitchDefault node) {
9339 visitList6(node.labels, " ", " "); 9339 visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
9340 _writer.print("default: "); 9340 _writer.print("default: ");
9341 { 9341 {
9342 indentInc(); 9342 indentInc();
9343 visitList5(node.statements, "\n"); 9343 visitNodeListWithSeparator(node.statements, "\n");
9344 indentDec(); 9344 indentDec();
9345 } 9345 }
9346 return null; 9346 return null;
9347 } 9347 }
9348 9348
9349 Object visitSwitchStatement(SwitchStatement node) { 9349 Object visitSwitchStatement(SwitchStatement node) {
9350 _writer.print("switch ("); 9350 _writer.print("switch (");
9351 visit(node.expression); 9351 visitNode(node.expression);
9352 _writer.print(") {"); 9352 _writer.print(") {");
9353 { 9353 {
9354 indentInc(); 9354 indentInc();
9355 visitList5(node.members, "\n"); 9355 visitNodeListWithSeparator(node.members, "\n");
9356 indentDec(); 9356 indentDec();
9357 } 9357 }
9358 nl2(); 9358 nl2();
9359 _writer.print('}'); 9359 _writer.print('}');
9360 return null; 9360 return null;
9361 } 9361 }
9362 9362
9363 Object visitSymbolLiteral(SymbolLiteral node) { 9363 Object visitSymbolLiteral(SymbolLiteral node) {
9364 _writer.print("#"); 9364 _writer.print("#");
9365 visitList9(node.components, "."); 9365 visitTokenListWithSeparator(node.components, ".");
9366 return null; 9366 return null;
9367 } 9367 }
9368 9368
9369 Object visitThisExpression(ThisExpression node) { 9369 Object visitThisExpression(ThisExpression node) {
9370 _writer.print("this"); 9370 _writer.print("this");
9371 return null; 9371 return null;
9372 } 9372 }
9373 9373
9374 Object visitThrowExpression(ThrowExpression node) { 9374 Object visitThrowExpression(ThrowExpression node) {
9375 _writer.print("throw "); 9375 _writer.print("throw ");
9376 visit(node.expression); 9376 visitNode(node.expression);
9377 return null; 9377 return null;
9378 } 9378 }
9379 9379
9380 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 9380 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
9381 visit6(node.variables, ";"); 9381 visitNodeWithSuffix(node.variables, ";");
9382 return null; 9382 return null;
9383 } 9383 }
9384 9384
9385 Object visitTryStatement(TryStatement node) { 9385 Object visitTryStatement(TryStatement node) {
9386 _writer.print("try "); 9386 _writer.print("try ");
9387 visit(node.body); 9387 visitNode(node.body);
9388 visitList7(" ", node.catchClauses, " "); 9388 visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " ");
9389 visit7(" finally ", node.finallyBlock); 9389 visitNodeWithPrefix(" finally ", node.finallyBlock);
9390 return null; 9390 return null;
9391 } 9391 }
9392 9392
9393 Object visitTypeArgumentList(TypeArgumentList node) { 9393 Object visitTypeArgumentList(TypeArgumentList node) {
9394 _writer.print('<'); 9394 _writer.print('<');
9395 visitList5(node.arguments, ", "); 9395 visitNodeListWithSeparator(node.arguments, ", ");
9396 _writer.print('>'); 9396 _writer.print('>');
9397 return null; 9397 return null;
9398 } 9398 }
9399 9399
9400 Object visitTypeName(TypeName node) { 9400 Object visitTypeName(TypeName node) {
9401 visit(node.name); 9401 visitNode(node.name);
9402 visit(node.typeArguments); 9402 visitNode(node.typeArguments);
9403 return null; 9403 return null;
9404 } 9404 }
9405 9405
9406 Object visitTypeParameter(TypeParameter node) { 9406 Object visitTypeParameter(TypeParameter node) {
9407 visit(node.name); 9407 visitNode(node.name);
9408 visit7(" extends ", node.bound); 9408 visitNodeWithPrefix(" extends ", node.bound);
9409 return null; 9409 return null;
9410 } 9410 }
9411 9411
9412 Object visitTypeParameterList(TypeParameterList node) { 9412 Object visitTypeParameterList(TypeParameterList node) {
9413 _writer.print('<'); 9413 _writer.print('<');
9414 visitList5(node.typeParameters, ", "); 9414 visitNodeListWithSeparator(node.typeParameters, ", ");
9415 _writer.print('>'); 9415 _writer.print('>');
9416 return null; 9416 return null;
9417 } 9417 }
9418 9418
9419 Object visitVariableDeclaration(VariableDeclaration node) { 9419 Object visitVariableDeclaration(VariableDeclaration node) {
9420 visit(node.name); 9420 visitNode(node.name);
9421 visit7(" = ", node.initializer); 9421 visitNodeWithPrefix(" = ", node.initializer);
9422 return null; 9422 return null;
9423 } 9423 }
9424 9424
9425 Object visitVariableDeclarationList(VariableDeclarationList node) { 9425 Object visitVariableDeclarationList(VariableDeclarationList node) {
9426 visit8(node.keyword, " "); 9426 visitTokenWithSuffix(node.keyword, " ");
9427 visit6(node.type, " "); 9427 visitNodeWithSuffix(node.type, " ");
9428 visitList5(node.variables, ", "); 9428 visitNodeListWithSeparator(node.variables, ", ");
9429 return null; 9429 return null;
9430 } 9430 }
9431 9431
9432 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { 9432 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
9433 visit(node.variables); 9433 visitNode(node.variables);
9434 _writer.print(";"); 9434 _writer.print(";");
9435 return null; 9435 return null;
9436 } 9436 }
9437 9437
9438 Object visitWhileStatement(WhileStatement node) { 9438 Object visitWhileStatement(WhileStatement node) {
9439 _writer.print("while ("); 9439 _writer.print("while (");
9440 visit(node.condition); 9440 visitNode(node.condition);
9441 _writer.print(") "); 9441 _writer.print(") ");
9442 visit(node.body); 9442 visitNode(node.body);
9443 return null; 9443 return null;
9444 } 9444 }
9445 9445
9446 Object visitWithClause(WithClause node) { 9446 Object visitWithClause(WithClause node) {
9447 _writer.print("with "); 9447 _writer.print("with ");
9448 visitList5(node.mixinTypes, ", "); 9448 visitNodeListWithSeparator(node.mixinTypes, ", ");
9449 return null; 9449 return null;
9450 } 9450 }
9451 9451
9452 void indent() { 9452 void indent() {
9453 _writer.print(_indentString); 9453 _writer.print(_indentString);
9454 } 9454 }
9455 9455
9456 void indentDec() { 9456 void indentDec() {
9457 _indentLevel -= 2; 9457 _indentLevel -= 2;
9458 _indentString = StringUtils.repeat(" ", _indentLevel); 9458 _indentString = StringUtils.repeat(" ", _indentLevel);
(...skipping 23 matching lines...) Expand all
9482 _writer.print("\n"); 9482 _writer.print("\n");
9483 indent(); 9483 indent();
9484 } 9484 }
9485 } 9485 }
9486 9486
9487 /** 9487 /**
9488 * Safely visit the given node. 9488 * Safely visit the given node.
9489 * 9489 *
9490 * @param node the node to be visited 9490 * @param node the node to be visited
9491 */ 9491 */
9492 void visit(AstNode node) { 9492 void visitNode(AstNode node) {
9493 if (node != null) { 9493 if (node != null) {
9494 node.accept(this); 9494 node.accept(this);
9495 } 9495 }
9496 } 9496 }
9497 9497
9498 /** 9498 /**
9499 * Safely visit the given node, printing the suffix after the node if it is no n-<code>null</code>.
9500 *
9501 * @param suffix the suffix to be printed if there is a node to visit
9502 * @param node the node to be visited
9503 */
9504 void visit6(AstNode node, String suffix) {
9505 if (node != null) {
9506 node.accept(this);
9507 _writer.print(suffix);
9508 }
9509 }
9510
9511 /**
9512 * Safely visit the given node, printing the prefix before the node if it is n on-<code>null</code>
9513 * .
9514 *
9515 * @param prefix the prefix to be printed if there is a node to visit
9516 * @param node the node to be visited
9517 */
9518 void visit7(String prefix, AstNode node) {
9519 if (node != null) {
9520 _writer.print(prefix);
9521 node.accept(this);
9522 }
9523 }
9524
9525 /**
9526 * Safely visit the given node, printing the suffix after the node if it is no n-<code>null</code>.
9527 *
9528 * @param suffix the suffix to be printed if there is a node to visit
9529 * @param node the node to be visited
9530 */
9531 void visit8(Token token, String suffix) {
9532 if (token != null) {
9533 _writer.print(token.lexeme);
9534 _writer.print(suffix);
9535 }
9536 }
9537
9538 /**
9539 * Print a list of nodes without any separation. 9499 * Print a list of nodes without any separation.
9540 * 9500 *
9541 * @param nodes the nodes to be printed 9501 * @param nodes the nodes to be printed
9542 * @param separator the separator to be printed between adjacent nodes 9502 * @param separator the separator to be printed between adjacent nodes
9543 */ 9503 */
9544 void visitList(NodeList<AstNode> nodes) { 9504 void visitNodeList(NodeList<AstNode> nodes) {
9545 visitList5(nodes, ""); 9505 visitNodeListWithSeparator(nodes, "");
9546 } 9506 }
9547 9507
9548 /** 9508 /**
9549 * Print a list of nodes, separated by the given separator. 9509 * Print a list of nodes, separated by the given separator.
9550 * 9510 *
9551 * @param nodes the nodes to be printed 9511 * @param nodes the nodes to be printed
9552 * @param separator the separator to be printed between adjacent nodes 9512 * @param separator the separator to be printed between adjacent nodes
9553 */ 9513 */
9554 void visitList5(NodeList<AstNode> nodes, String separator) { 9514 void visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) {
9555 visitList8("", nodes, separator, ""); 9515 visitNodeListWithSeparatorPrefixAndSuffix("", nodes, separator, "");
9516 }
9517
9518 /**
9519 * Print a list of nodes, separated by the given separator.
9520 *
9521 * @param prefix the prefix to be printed if the list is not empty
9522 * @param nodes the nodes to be printed
9523 * @param separator the separator to be printed between adjacent nodes
9524 */
9525 void visitNodeListWithSeparatorAndPrefix(String prefix, NodeList<AstNode> node s, String separator) {
9526 visitNodeListWithSeparatorPrefixAndSuffix(prefix, nodes, separator, "");
9556 } 9527 }
9557 9528
9558 /** 9529 /**
9559 * Print a list of nodes, separated by the given separator. 9530 * Print a list of nodes, separated by the given separator.
9560 * 9531 *
9561 * @param nodes the nodes to be printed 9532 * @param nodes the nodes to be printed
9562 * @param separator the separator to be printed between adjacent nodes 9533 * @param separator the separator to be printed between adjacent nodes
9563 * @param suffix the suffix to be printed if the list is not empty 9534 * @param suffix the suffix to be printed if the list is not empty
9564 */ 9535 */
9565 void visitList6(NodeList<AstNode> nodes, String separator, String suffix) { 9536 void visitNodeListWithSeparatorAndSuffix(NodeList<AstNode> nodes, String separ ator, String suffix) {
9566 visitList8("", nodes, separator, suffix); 9537 visitNodeListWithSeparatorPrefixAndSuffix("", nodes, separator, suffix);
9567 } 9538 }
9568 9539
9569 /** 9540 /**
9570 * Print a list of nodes, separated by the given separator.
9571 *
9572 * @param prefix the prefix to be printed if the list is not empty
9573 * @param nodes the nodes to be printed
9574 * @param separator the separator to be printed between adjacent nodes
9575 */
9576 void visitList7(String prefix, NodeList<AstNode> nodes, String separator) {
9577 visitList8(prefix, nodes, separator, "");
9578 }
9579
9580 /**
9581 * Print a list of nodes, separated by the given separator. 9541 * Print a list of nodes, separated by the given separator.
9582 * 9542 *
9583 * @param prefix the prefix to be printed if the list is not empty 9543 * @param prefix the prefix to be printed if the list is not empty
9584 * @param nodes the nodes to be printed 9544 * @param nodes the nodes to be printed
9585 * @param separator the separator to be printed between adjacent nodes 9545 * @param separator the separator to be printed between adjacent nodes
9586 * @param suffix the suffix to be printed if the list is not empty 9546 * @param suffix the suffix to be printed if the list is not empty
9587 */ 9547 */
9588 void visitList8(String prefix, NodeList<AstNode> nodes, String separator, Stri ng suffix) { 9548 void visitNodeListWithSeparatorPrefixAndSuffix(String prefix, NodeList<AstNode > nodes, String separator, String suffix) {
9589 if (nodes != null) { 9549 if (nodes != null) {
9590 int size = nodes.length; 9550 int size = nodes.length;
9591 if (size != 0) { 9551 if (size != 0) {
9592 // prefix 9552 // prefix
9593 _writer.print(prefix); 9553 _writer.print(prefix);
9594 if (prefix.endsWith("\n")) { 9554 if (prefix.endsWith("\n")) {
9595 indent(); 9555 indent();
9596 } 9556 }
9597 // nodes 9557 // nodes
9598 bool newLineSeparator = separator.endsWith("\n"); 9558 bool newLineSeparator = separator.endsWith("\n");
(...skipping 10 matching lines...) Expand all
9609 } 9569 }
9610 node.accept(this); 9570 node.accept(this);
9611 } 9571 }
9612 // suffix 9572 // suffix
9613 _writer.print(suffix); 9573 _writer.print(suffix);
9614 } 9574 }
9615 } 9575 }
9616 } 9576 }
9617 9577
9618 /** 9578 /**
9579 * Safely visit the given node, printing the prefix before the node if it is n on-<code>null</code>
9580 * .
9581 *
9582 * @param prefix the prefix to be printed if there is a node to visit
9583 * @param node the node to be visited
9584 */
9585 void visitNodeWithPrefix(String prefix, AstNode node) {
9586 if (node != null) {
9587 _writer.print(prefix);
9588 node.accept(this);
9589 }
9590 }
9591
9592 /**
9593 * Safely visit the given node, printing the suffix after the node if it is no n-<code>null</code>.
9594 *
9595 * @param suffix the suffix to be printed if there is a node to visit
9596 * @param node the node to be visited
9597 */
9598 void visitNodeWithSuffix(AstNode node, String suffix) {
9599 if (node != null) {
9600 node.accept(this);
9601 _writer.print(suffix);
9602 }
9603 }
9604
9605 /**
9619 * Print a list of tokens, separated by the given separator. 9606 * Print a list of tokens, separated by the given separator.
9620 * 9607 *
9621 * @param tokens the tokens to be printed 9608 * @param tokens the tokens to be printed
9622 * @param separator the separator to be printed between adjacent tokens 9609 * @param separator the separator to be printed between adjacent tokens
9623 */ 9610 */
9624 void visitList9(List<Token> tokens, String separator) { 9611 void visitTokenListWithSeparator(List<Token> tokens, String separator) {
9625 int size = tokens.length; 9612 int size = tokens.length;
9626 for (int i = 0; i < size; i++) { 9613 for (int i = 0; i < size; i++) {
9627 if ("\n" == separator) { 9614 if ("\n" == separator) {
9628 _writer.print("\n"); 9615 _writer.print("\n");
9629 indent(); 9616 indent();
9630 } else if (i > 0) { 9617 } else if (i > 0) {
9631 _writer.print(separator); 9618 _writer.print(separator);
9632 } 9619 }
9633 _writer.print(tokens[i].lexeme); 9620 _writer.print(tokens[i].lexeme);
9634 } 9621 }
9635 } 9622 }
9623
9624 /**
9625 * Safely visit the given node, printing the suffix after the node if it is no n-<code>null</code>.
9626 *
9627 * @param suffix the suffix to be printed if there is a node to visit
9628 * @param node the node to be visited
9629 */
9630 void visitTokenWithSuffix(Token token, String suffix) {
9631 if (token != null) {
9632 _writer.print(token.lexeme);
9633 _writer.print(suffix);
9634 }
9635 }
9636 } 9636 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/java_engine.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698