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

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

Issue 1480433002: Add support for assert statements with messages to the analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library engine.ast; 5 library engine.ast;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'element.dart'; 9 import 'element.dart';
10 import 'engine.dart' show AnalysisEngine; 10 import 'engine.dart' show AnalysisEngine;
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 * The left parenthesis. 649 * The left parenthesis.
650 */ 650 */
651 Token leftParenthesis; 651 Token leftParenthesis;
652 652
653 /** 653 /**
654 * The condition that is being asserted to be `true`. 654 * The condition that is being asserted to be `true`.
655 */ 655 */
656 Expression _condition; 656 Expression _condition;
657 657
658 /** 658 /**
659 * The comma, if a message expression was supplied. Otherwise `null`.
660 */
661 Token comma;
662
663 /**
664 * The message to report if the assertion fails. `null` if no message was
665 * supplied.
666 */
667 Expression _message;
668
669 /**
659 * The right parenthesis. 670 * The right parenthesis.
660 */ 671 */
661 Token rightParenthesis; 672 Token rightParenthesis;
662 673
663 /** 674 /**
664 * The semicolon terminating the statement. 675 * The semicolon terminating the statement.
665 */ 676 */
666 Token semicolon; 677 Token semicolon;
667 678
668 /** 679 /**
669 * Initialize a newly created assert statement. 680 * Initialize a newly created assert statement.
670 */ 681 */
671 AssertStatement(this.assertKeyword, this.leftParenthesis, 682 AssertStatement(
672 Expression condition, this.rightParenthesis, this.semicolon) { 683 this.assertKeyword,
684 this.leftParenthesis,
685 Expression condition,
686 this.comma,
687 Expression message,
688 this.rightParenthesis,
689 this.semicolon) {
673 _condition = _becomeParentOf(condition); 690 _condition = _becomeParentOf(condition);
691 _message = _becomeParentOf(message);
674 } 692 }
675 693
676 @override 694 @override
677 Token get beginToken => assertKeyword; 695 Token get beginToken => assertKeyword;
678 696
679 @override 697 @override
680 Iterable get childEntities => new ChildEntities() 698 Iterable get childEntities => new ChildEntities()
681 ..add(assertKeyword) 699 ..add(assertKeyword)
682 ..add(leftParenthesis) 700 ..add(leftParenthesis)
683 ..add(_condition) 701 ..add(_condition)
702 ..add(comma)
703 ..add(_message)
684 ..add(rightParenthesis) 704 ..add(rightParenthesis)
685 ..add(semicolon); 705 ..add(semicolon);
686 706
687 /** 707 /**
688 * Return the condition that is being asserted to be `true`. 708 * Return the condition that is being asserted to be `true`.
689 */ 709 */
690 Expression get condition => _condition; 710 Expression get condition => _condition;
691 711
692 /** 712 /**
693 * Set the condition that is being asserted to be `true` to the given 713 * Set the condition that is being asserted to be `true` to the given
(...skipping 13 matching lines...) Expand all
707 Token get keyword => assertKeyword; 727 Token get keyword => assertKeyword;
708 728
709 /** 729 /**
710 * Set the token representing the 'assert' keyword to the given [token]. 730 * Set the token representing the 'assert' keyword to the given [token].
711 */ 731 */
712 @deprecated // Use "this.assertKeyword" 732 @deprecated // Use "this.assertKeyword"
713 set keyword(Token token) { 733 set keyword(Token token) {
714 assertKeyword = token; 734 assertKeyword = token;
715 } 735 }
716 736
737 /**
738 * Return the messasge to report if the assertion fails.
scheglov 2015/11/24 23:01:24 messasge -> message
Paul Berry 2015/11/24 23:54:39 Done.
739 */
740 Expression get message => _message;
741
742 /**
743 * Set the message to report if the assertion fails to the given
744 * [expression].
745 */
746 void set message(Expression expression) {
747 _message = _becomeParentOf(expression);
748 }
749
717 @override 750 @override
718 accept(AstVisitor visitor) => visitor.visitAssertStatement(this); 751 accept(AstVisitor visitor) => visitor.visitAssertStatement(this);
719 752
720 @override 753 @override
721 void visitChildren(AstVisitor visitor) { 754 void visitChildren(AstVisitor visitor) {
722 _safelyVisitChild(_condition, visitor); 755 _safelyVisitChild(_condition, visitor);
756 _safelyVisitChild(message, visitor);
723 } 757 }
724 } 758 }
725 759
726 /** 760 /**
727 * An assignment expression. 761 * An assignment expression.
728 * 762 *
729 * > assignmentExpression ::= 763 * > assignmentExpression ::=
730 * > [Expression] operator [Expression] 764 * > [Expression] operator [Expression]
731 */ 765 */
732 class AssignmentExpression extends Expression { 766 class AssignmentExpression extends Expression {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 AsExpression visitAsExpression(AsExpression node) => new AsExpression( 1064 AsExpression visitAsExpression(AsExpression node) => new AsExpression(
1031 cloneNode(node.expression), 1065 cloneNode(node.expression),
1032 cloneToken(node.asOperator), 1066 cloneToken(node.asOperator),
1033 cloneNode(node.type)); 1067 cloneNode(node.type));
1034 1068
1035 @override 1069 @override
1036 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement( 1070 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
1037 cloneToken(node.assertKeyword), 1071 cloneToken(node.assertKeyword),
1038 cloneToken(node.leftParenthesis), 1072 cloneToken(node.leftParenthesis),
1039 cloneNode(node.condition), 1073 cloneNode(node.condition),
1074 cloneToken(node.comma),
1075 cloneNode(node.message),
1040 cloneToken(node.rightParenthesis), 1076 cloneToken(node.rightParenthesis),
1041 cloneToken(node.semicolon)); 1077 cloneToken(node.semicolon));
1042 1078
1043 @override 1079 @override
1044 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) => 1080 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) =>
1045 new AssignmentExpression(cloneNode(node.leftHandSide), 1081 new AssignmentExpression(cloneNode(node.leftHandSide),
1046 cloneToken(node.operator), cloneNode(node.rightHandSide)); 1082 cloneToken(node.operator), cloneNode(node.rightHandSide));
1047 1083
1048 @override 1084 @override
1049 AwaitExpression visitAwaitExpression(AwaitExpression node) => 1085 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 isEqualTokens(node.asOperator, other.asOperator) && 1922 isEqualTokens(node.asOperator, other.asOperator) &&
1887 isEqualNodes(node.type, other.type); 1923 isEqualNodes(node.type, other.type);
1888 } 1924 }
1889 1925
1890 @override 1926 @override
1891 bool visitAssertStatement(AssertStatement node) { 1927 bool visitAssertStatement(AssertStatement node) {
1892 AssertStatement other = _other as AssertStatement; 1928 AssertStatement other = _other as AssertStatement;
1893 return isEqualTokens(node.assertKeyword, other.assertKeyword) && 1929 return isEqualTokens(node.assertKeyword, other.assertKeyword) &&
1894 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && 1930 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1895 isEqualNodes(node.condition, other.condition) && 1931 isEqualNodes(node.condition, other.condition) &&
1932 isEqualTokens(node.comma, other.comma) &&
1933 isEqualNodes(node.message, other.message) &&
1896 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && 1934 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1897 isEqualTokens(node.semicolon, other.semicolon); 1935 isEqualTokens(node.semicolon, other.semicolon);
1898 } 1936 }
1899 1937
1900 @override 1938 @override
1901 bool visitAssignmentExpression(AssignmentExpression node) { 1939 bool visitAssignmentExpression(AssignmentExpression node) {
1902 AssignmentExpression other = _other as AssignmentExpression; 1940 AssignmentExpression other = _other as AssignmentExpression;
1903 return isEqualNodes(node.leftHandSide, other.leftHandSide) && 1941 return isEqualNodes(node.leftHandSide, other.leftHandSide) &&
1904 isEqualTokens(node.operator, other.operator) && 1942 isEqualTokens(node.operator, other.operator) &&
1905 isEqualNodes(node.rightHandSide, other.rightHandSide); 1943 isEqualNodes(node.rightHandSide, other.rightHandSide);
(...skipping 7882 matching lines...) Expand 10 before | Expand all | Expand 10 after
9788 copy.propagatedType = node.propagatedType; 9826 copy.propagatedType = node.propagatedType;
9789 copy.staticType = node.staticType; 9827 copy.staticType = node.staticType;
9790 return copy; 9828 return copy;
9791 } 9829 }
9792 9830
9793 @override 9831 @override
9794 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement( 9832 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
9795 _mapToken(node.assertKeyword), 9833 _mapToken(node.assertKeyword),
9796 _mapToken(node.leftParenthesis), 9834 _mapToken(node.leftParenthesis),
9797 _cloneNode(node.condition), 9835 _cloneNode(node.condition),
9836 _mapToken(node.comma),
9837 _cloneNode(node.message),
9798 _mapToken(node.rightParenthesis), 9838 _mapToken(node.rightParenthesis),
9799 _mapToken(node.semicolon)); 9839 _mapToken(node.semicolon));
9800 9840
9801 @override 9841 @override
9802 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) { 9842 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) {
9803 AssignmentExpression copy = new AssignmentExpression( 9843 AssignmentExpression copy = new AssignmentExpression(
9804 _cloneNode(node.leftHandSide), 9844 _cloneNode(node.leftHandSide),
9805 _mapToken(node.operator), 9845 _mapToken(node.operator),
9806 _cloneNode(node.rightHandSide)); 9846 _cloneNode(node.rightHandSide));
9807 copy.propagatedElement = node.propagatedElement; 9847 copy.propagatedElement = node.propagatedElement;
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after
13023 } 13063 }
13024 return visitNode(node); 13064 return visitNode(node);
13025 } 13065 }
13026 13066
13027 @override 13067 @override
13028 bool visitAssertStatement(AssertStatement node) { 13068 bool visitAssertStatement(AssertStatement node) {
13029 if (identical(node.condition, _oldNode)) { 13069 if (identical(node.condition, _oldNode)) {
13030 node.condition = _newNode as Expression; 13070 node.condition = _newNode as Expression;
13031 return true; 13071 return true;
13032 } 13072 }
13073 if (identical(node._message, _oldNode)) {
13074 node.message = _newNode as Expression;
13075 return true;
13076 }
13033 return visitNode(node); 13077 return visitNode(node);
13034 } 13078 }
13035 13079
13036 @override 13080 @override
13037 bool visitAssignmentExpression(AssignmentExpression node) { 13081 bool visitAssignmentExpression(AssignmentExpression node) {
13038 if (identical(node.leftHandSide, _oldNode)) { 13082 if (identical(node.leftHandSide, _oldNode)) {
13039 node.leftHandSide = _newNode as Expression; 13083 node.leftHandSide = _newNode as Expression;
13040 return true; 13084 return true;
13041 } else if (identical(node.rightHandSide, _oldNode)) { 13085 } else if (identical(node.rightHandSide, _oldNode)) {
13042 node.rightHandSide = _newNode as Expression; 13086 node.rightHandSide = _newNode as Expression;
(...skipping 4987 matching lines...) Expand 10 before | Expand all | Expand 10 after
18030 _visitNode(node.expression); 18074 _visitNode(node.expression);
18031 _writer.print(" as "); 18075 _writer.print(" as ");
18032 _visitNode(node.type); 18076 _visitNode(node.type);
18033 return null; 18077 return null;
18034 } 18078 }
18035 18079
18036 @override 18080 @override
18037 Object visitAssertStatement(AssertStatement node) { 18081 Object visitAssertStatement(AssertStatement node) {
18038 _writer.print("assert ("); 18082 _writer.print("assert (");
18039 _visitNode(node.condition); 18083 _visitNode(node.condition);
18084 if (node.message != null) {
18085 _writer.print(', ');
18086 _visitNode(node.message);
18087 }
18040 _writer.print(");"); 18088 _writer.print(");");
18041 return null; 18089 return null;
18042 } 18090 }
18043 18091
18044 @override 18092 @override
18045 Object visitAssignmentExpression(AssignmentExpression node) { 18093 Object visitAssignmentExpression(AssignmentExpression node) {
18046 _visitNode(node.leftHandSide); 18094 _visitNode(node.leftHandSide);
18047 _writer.print(' '); 18095 _writer.print(' ');
18048 _writer.print(node.operator.lexeme); 18096 _writer.print(node.operator.lexeme);
18049 _writer.print(' '); 18097 _writer.print(' ');
(...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after
20647 } 20695 }
20648 20696
20649 @override 20697 @override
20650 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 20698 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20651 20699
20652 @override 20700 @override
20653 void visitChildren(AstVisitor visitor) { 20701 void visitChildren(AstVisitor visitor) {
20654 _safelyVisitChild(_expression, visitor); 20702 _safelyVisitChild(_expression, visitor);
20655 } 20703 }
20656 } 20704 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698