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

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

Issue 1558843002: First step towards a public API for AST nodes (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add new files Created 4 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | no next file » | 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 analyzer.src.generated.ast; 5 library analyzer.src.generated.ast;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/src/dart/ast/utilities.dart';
11 import 'package:analyzer/src/dart/element/element.dart'; 12 import 'package:analyzer/src/dart/element/element.dart';
12 import 'package:analyzer/src/dart/element/type.dart'; 13 import 'package:analyzer/src/dart/element/type.dart';
13 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; 14 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
14 import 'package:analyzer/src/generated/java_core.dart'; 15 import 'package:analyzer/src/generated/java_core.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 17 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/scanner.dart'; 18 import 'package:analyzer/src/generated/scanner.dart';
18 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; 19 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source;
19 import 'package:analyzer/src/generated/utilities_collection.dart' show TokenMap;
20 import 'package:analyzer/src/generated/utilities_dart.dart'; 20 import 'package:analyzer/src/generated/utilities_dart.dart';
21 21
22 export 'package:analyzer/dart/ast/visitor.dart';
23 export 'package:analyzer/src/dart/ast/utilities.dart';
24
22 /** 25 /**
23 * Two or more string literals that are implicitly concatenated because of being 26 * Two or more string literals that are implicitly concatenated because of being
24 * adjacent (separated only by whitespace). 27 * adjacent (separated only by whitespace).
25 * 28 *
26 * While the grammar only allows adjacent strings when all of the strings are of 29 * While the grammar only allows adjacent strings when all of the strings are of
27 * the same kind (single line or multi-line), this class doesn't enforce that 30 * the same kind (single line or multi-line), this class doesn't enforce that
28 * restriction. 31 * restriction.
29 * 32 *
30 * > adjacentStrings ::= 33 * > adjacentStrings ::=
31 * > [StringLiteral] [StringLiteral]+ 34 * > [StringLiteral] [StringLiteral]+
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this); 902 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this);
900 903
901 @override 904 @override
902 void visitChildren(AstVisitor visitor) { 905 void visitChildren(AstVisitor visitor) {
903 _safelyVisitChild(_leftHandSide, visitor); 906 _safelyVisitChild(_leftHandSide, visitor);
904 _safelyVisitChild(_rightHandSide, visitor); 907 _safelyVisitChild(_rightHandSide, visitor);
905 } 908 }
906 } 909 }
907 910
908 /** 911 /**
909 * An AST visitor that will clone any AST structure that it visits. The cloner
910 * will only clone the structure, it will not preserve any resolution results or
911 * properties associated with the nodes.
912 */
913 class AstCloner implements AstVisitor<AstNode> {
914 /**
915 * A flag indicating whether tokens should be cloned while cloning an AST
916 * structure.
917 */
918 final bool cloneTokens;
919
920 /**
921 * Initialize a newly created AST cloner to optionally clone tokens while
922 * cloning AST nodes if [cloneTokens] is `true`.
923 */
924 AstCloner(
925 [this.cloneTokens =
926 false]); // TODO(brianwilkerson) Change this to be a named parameter.
927
928 /**
929 * Return a clone of the given [node].
930 */
931 AstNode cloneNode(AstNode node) {
932 if (node == null) {
933 return null;
934 }
935 return node.accept(this) as AstNode;
936 }
937
938 /**
939 * Return a list containing cloned versions of the nodes in the given list of
940 * [nodes].
941 */
942 List<AstNode> cloneNodeList(NodeList nodes) {
943 int count = nodes.length;
944 List clonedNodes = new List();
945 for (int i = 0; i < count; i++) {
946 clonedNodes.add((nodes[i]).accept(this) as AstNode);
947 }
948 return clonedNodes;
949 }
950
951 /**
952 * Clone the given [token] if tokens are supposed to be cloned.
953 */
954 Token cloneToken(Token token) {
955 if (cloneTokens) {
956 return (token == null ? null : token.copy());
957 } else {
958 return token;
959 }
960 }
961
962 /**
963 * Clone the given [tokens] if tokens are supposed to be cloned.
964 */
965 List<Token> cloneTokenList(List<Token> tokens) {
966 if (cloneTokens) {
967 return tokens.map((Token token) => token.copy()).toList();
968 }
969 return tokens;
970 }
971
972 @override
973 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
974 new AdjacentStrings(cloneNodeList(node.strings));
975
976 @override
977 Annotation visitAnnotation(Annotation node) => new Annotation(
978 cloneToken(node.atSign),
979 cloneNode(node.name),
980 cloneToken(node.period),
981 cloneNode(node.constructorName),
982 cloneNode(node.arguments));
983
984 @override
985 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
986 cloneToken(node.leftParenthesis),
987 cloneNodeList(node.arguments),
988 cloneToken(node.rightParenthesis));
989
990 @override
991 AsExpression visitAsExpression(AsExpression node) => new AsExpression(
992 cloneNode(node.expression),
993 cloneToken(node.asOperator),
994 cloneNode(node.type));
995
996 @override
997 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
998 cloneToken(node.assertKeyword),
999 cloneToken(node.leftParenthesis),
1000 cloneNode(node.condition),
1001 cloneToken(node.comma),
1002 cloneNode(node.message),
1003 cloneToken(node.rightParenthesis),
1004 cloneToken(node.semicolon));
1005
1006 @override
1007 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) =>
1008 new AssignmentExpression(cloneNode(node.leftHandSide),
1009 cloneToken(node.operator), cloneNode(node.rightHandSide));
1010
1011 @override
1012 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
1013 new AwaitExpression(
1014 cloneToken(node.awaitKeyword), cloneNode(node.expression));
1015
1016 @override
1017 BinaryExpression visitBinaryExpression(BinaryExpression node) =>
1018 new BinaryExpression(cloneNode(node.leftOperand),
1019 cloneToken(node.operator), cloneNode(node.rightOperand));
1020
1021 @override
1022 Block visitBlock(Block node) => new Block(cloneToken(node.leftBracket),
1023 cloneNodeList(node.statements), cloneToken(node.rightBracket));
1024
1025 @override
1026 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) =>
1027 new BlockFunctionBody(cloneToken(node.keyword), cloneToken(node.star),
1028 cloneNode(node.block));
1029
1030 @override
1031 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) =>
1032 new BooleanLiteral(cloneToken(node.literal), node.value);
1033
1034 @override
1035 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
1036 cloneToken(node.breakKeyword),
1037 cloneNode(node.label),
1038 cloneToken(node.semicolon));
1039
1040 @override
1041 CascadeExpression visitCascadeExpression(CascadeExpression node) =>
1042 new CascadeExpression(
1043 cloneNode(node.target), cloneNodeList(node.cascadeSections));
1044
1045 @override
1046 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
1047 cloneToken(node.onKeyword),
1048 cloneNode(node.exceptionType),
1049 cloneToken(node.catchKeyword),
1050 cloneToken(node.leftParenthesis),
1051 cloneNode(node.exceptionParameter),
1052 cloneToken(node.comma),
1053 cloneNode(node.stackTraceParameter),
1054 cloneToken(node.rightParenthesis),
1055 cloneNode(node.body));
1056
1057 @override
1058 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
1059 ClassDeclaration copy = new ClassDeclaration(
1060 cloneNode(node.documentationComment),
1061 cloneNodeList(node.metadata),
1062 cloneToken(node.abstractKeyword),
1063 cloneToken(node.classKeyword),
1064 cloneNode(node.name),
1065 cloneNode(node.typeParameters),
1066 cloneNode(node.extendsClause),
1067 cloneNode(node.withClause),
1068 cloneNode(node.implementsClause),
1069 cloneToken(node.leftBracket),
1070 cloneNodeList(node.members),
1071 cloneToken(node.rightBracket));
1072 copy.nativeClause = cloneNode(node.nativeClause);
1073 return copy;
1074 }
1075
1076 @override
1077 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
1078 cloneNode(node.documentationComment),
1079 cloneNodeList(node.metadata),
1080 cloneToken(node.typedefKeyword),
1081 cloneNode(node.name),
1082 cloneNode(node.typeParameters),
1083 cloneToken(node.equals),
1084 cloneToken(node.abstractKeyword),
1085 cloneNode(node.superclass),
1086 cloneNode(node.withClause),
1087 cloneNode(node.implementsClause),
1088 cloneToken(node.semicolon));
1089
1090 @override
1091 Comment visitComment(Comment node) {
1092 if (node.isDocumentation) {
1093 return Comment.createDocumentationCommentWithReferences(
1094 cloneTokenList(node.tokens), cloneNodeList(node.references));
1095 } else if (node.isBlock) {
1096 return Comment.createBlockComment(cloneTokenList(node.tokens));
1097 }
1098 return Comment.createEndOfLineComment(cloneTokenList(node.tokens));
1099 }
1100
1101 @override
1102 CommentReference visitCommentReference(CommentReference node) =>
1103 new CommentReference(
1104 cloneToken(node.newKeyword), cloneNode(node.identifier));
1105
1106 @override
1107 CompilationUnit visitCompilationUnit(CompilationUnit node) {
1108 CompilationUnit clone = new CompilationUnit(
1109 cloneToken(node.beginToken),
1110 cloneNode(node.scriptTag),
1111 cloneNodeList(node.directives),
1112 cloneNodeList(node.declarations),
1113 cloneToken(node.endToken));
1114 clone.lineInfo = node.lineInfo;
1115 return clone;
1116 }
1117
1118 @override
1119 ConditionalExpression visitConditionalExpression(
1120 ConditionalExpression node) =>
1121 new ConditionalExpression(
1122 cloneNode(node.condition),
1123 cloneToken(node.question),
1124 cloneNode(node.thenExpression),
1125 cloneToken(node.colon),
1126 cloneNode(node.elseExpression));
1127
1128 @override
1129 Configuration visitConfiguration(Configuration node) => new Configuration(
1130 cloneToken(node.ifKeyword),
1131 cloneToken(node.leftParenthesis),
1132 cloneNode(node.name),
1133 cloneToken(node.equalToken),
1134 cloneNode(node.value),
1135 cloneToken(node.rightParenthesis),
1136 cloneNode(node.libraryUri));
1137
1138 @override
1139 ConstructorDeclaration visitConstructorDeclaration(
1140 ConstructorDeclaration node) =>
1141 new ConstructorDeclaration(
1142 cloneNode(node.documentationComment),
1143 cloneNodeList(node.metadata),
1144 cloneToken(node.externalKeyword),
1145 cloneToken(node.constKeyword),
1146 cloneToken(node.factoryKeyword),
1147 cloneNode(node.returnType),
1148 cloneToken(node.period),
1149 cloneNode(node.name),
1150 cloneNode(node.parameters),
1151 cloneToken(node.separator),
1152 cloneNodeList(node.initializers),
1153 cloneNode(node.redirectedConstructor),
1154 cloneNode(node.body));
1155
1156 @override
1157 ConstructorFieldInitializer visitConstructorFieldInitializer(
1158 ConstructorFieldInitializer node) =>
1159 new ConstructorFieldInitializer(
1160 cloneToken(node.thisKeyword),
1161 cloneToken(node.period),
1162 cloneNode(node.fieldName),
1163 cloneToken(node.equals),
1164 cloneNode(node.expression));
1165
1166 @override
1167 ConstructorName visitConstructorName(ConstructorName node) =>
1168 new ConstructorName(
1169 cloneNode(node.type), cloneToken(node.period), cloneNode(node.name));
1170
1171 @override
1172 ContinueStatement visitContinueStatement(ContinueStatement node) =>
1173 new ContinueStatement(cloneToken(node.continueKeyword),
1174 cloneNode(node.label), cloneToken(node.semicolon));
1175
1176 @override
1177 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
1178 new DeclaredIdentifier(
1179 cloneNode(node.documentationComment),
1180 cloneNodeList(node.metadata),
1181 cloneToken(node.keyword),
1182 cloneNode(node.type),
1183 cloneNode(node.identifier));
1184
1185 @override
1186 DefaultFormalParameter visitDefaultFormalParameter(
1187 DefaultFormalParameter node) =>
1188 new DefaultFormalParameter(cloneNode(node.parameter), node.kind,
1189 cloneToken(node.separator), cloneNode(node.defaultValue));
1190
1191 @override
1192 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
1193 cloneToken(node.doKeyword),
1194 cloneNode(node.body),
1195 cloneToken(node.whileKeyword),
1196 cloneToken(node.leftParenthesis),
1197 cloneNode(node.condition),
1198 cloneToken(node.rightParenthesis),
1199 cloneToken(node.semicolon));
1200
1201 @override
1202 DottedName visitDottedName(DottedName node) =>
1203 new DottedName(cloneNodeList(node.components));
1204
1205 @override
1206 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) =>
1207 new DoubleLiteral(cloneToken(node.literal), node.value);
1208
1209 @override
1210 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
1211 new EmptyFunctionBody(cloneToken(node.semicolon));
1212
1213 @override
1214 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
1215 new EmptyStatement(cloneToken(node.semicolon));
1216
1217 @override
1218 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
1219 new EnumConstantDeclaration(cloneNode(node.documentationComment),
1220 cloneNodeList(node.metadata), cloneNode(node.name));
1221
1222 @override
1223 EnumDeclaration visitEnumDeclaration(EnumDeclaration node) =>
1224 new EnumDeclaration(
1225 cloneNode(node.documentationComment),
1226 cloneNodeList(node.metadata),
1227 cloneToken(node.enumKeyword),
1228 cloneNode(node.name),
1229 cloneToken(node.leftBracket),
1230 cloneNodeList(node.constants),
1231 cloneToken(node.rightBracket));
1232
1233 @override
1234 ExportDirective visitExportDirective(ExportDirective node) {
1235 ExportDirective directive = new ExportDirective(
1236 cloneNode(node.documentationComment),
1237 cloneNodeList(node.metadata),
1238 cloneToken(node.keyword),
1239 cloneNode(node.uri),
1240 cloneNodeList(node.configurations),
1241 cloneNodeList(node.combinators),
1242 cloneToken(node.semicolon));
1243 directive.source = node.source;
1244 directive.uriContent = node.uriContent;
1245 return directive;
1246 }
1247
1248 @override
1249 ExpressionFunctionBody visitExpressionFunctionBody(
1250 ExpressionFunctionBody node) =>
1251 new ExpressionFunctionBody(
1252 cloneToken(node.keyword),
1253 cloneToken(node.functionDefinition),
1254 cloneNode(node.expression),
1255 cloneToken(node.semicolon));
1256
1257 @override
1258 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
1259 new ExpressionStatement(
1260 cloneNode(node.expression), cloneToken(node.semicolon));
1261
1262 @override
1263 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
1264 cloneToken(node.extendsKeyword), cloneNode(node.superclass));
1265
1266 @override
1267 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
1268 new FieldDeclaration(
1269 cloneNode(node.documentationComment),
1270 cloneNodeList(node.metadata),
1271 cloneToken(node.staticKeyword),
1272 cloneNode(node.fields),
1273 cloneToken(node.semicolon));
1274
1275 @override
1276 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
1277 new FieldFormalParameter(
1278 cloneNode(node.documentationComment),
1279 cloneNodeList(node.metadata),
1280 cloneToken(node.keyword),
1281 cloneNode(node.type),
1282 cloneToken(node.thisKeyword),
1283 cloneToken(node.period),
1284 cloneNode(node.identifier),
1285 cloneNode(node.typeParameters),
1286 cloneNode(node.parameters));
1287
1288 @override
1289 ForEachStatement visitForEachStatement(ForEachStatement node) {
1290 DeclaredIdentifier loopVariable = node.loopVariable;
1291 if (loopVariable == null) {
1292 return new ForEachStatement.withReference(
1293 cloneToken(node.awaitKeyword),
1294 cloneToken(node.forKeyword),
1295 cloneToken(node.leftParenthesis),
1296 cloneNode(node.identifier),
1297 cloneToken(node.inKeyword),
1298 cloneNode(node.iterable),
1299 cloneToken(node.rightParenthesis),
1300 cloneNode(node.body));
1301 }
1302 return new ForEachStatement.withDeclaration(
1303 cloneToken(node.awaitKeyword),
1304 cloneToken(node.forKeyword),
1305 cloneToken(node.leftParenthesis),
1306 cloneNode(loopVariable),
1307 cloneToken(node.inKeyword),
1308 cloneNode(node.iterable),
1309 cloneToken(node.rightParenthesis),
1310 cloneNode(node.body));
1311 }
1312
1313 @override
1314 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
1315 new FormalParameterList(
1316 cloneToken(node.leftParenthesis),
1317 cloneNodeList(node.parameters),
1318 cloneToken(node.leftDelimiter),
1319 cloneToken(node.rightDelimiter),
1320 cloneToken(node.rightParenthesis));
1321
1322 @override
1323 ForStatement visitForStatement(ForStatement node) => new ForStatement(
1324 cloneToken(node.forKeyword),
1325 cloneToken(node.leftParenthesis),
1326 cloneNode(node.variables),
1327 cloneNode(node.initialization),
1328 cloneToken(node.leftSeparator),
1329 cloneNode(node.condition),
1330 cloneToken(node.rightSeparator),
1331 cloneNodeList(node.updaters),
1332 cloneToken(node.rightParenthesis),
1333 cloneNode(node.body));
1334
1335 @override
1336 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
1337 new FunctionDeclaration(
1338 cloneNode(node.documentationComment),
1339 cloneNodeList(node.metadata),
1340 cloneToken(node.externalKeyword),
1341 cloneNode(node.returnType),
1342 cloneToken(node.propertyKeyword),
1343 cloneNode(node.name),
1344 cloneNode(node.functionExpression));
1345
1346 @override
1347 FunctionDeclarationStatement visitFunctionDeclarationStatement(
1348 FunctionDeclarationStatement node) =>
1349 new FunctionDeclarationStatement(cloneNode(node.functionDeclaration));
1350
1351 @override
1352 FunctionExpression visitFunctionExpression(FunctionExpression node) =>
1353 new FunctionExpression(cloneNode(node.typeParameters),
1354 cloneNode(node.parameters), cloneNode(node.body));
1355
1356 @override
1357 FunctionExpressionInvocation visitFunctionExpressionInvocation(
1358 FunctionExpressionInvocation node) =>
1359 new FunctionExpressionInvocation(cloneNode(node.function),
1360 cloneNode(node.typeArguments), cloneNode(node.argumentList));
1361
1362 @override
1363 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
1364 new FunctionTypeAlias(
1365 cloneNode(node.documentationComment),
1366 cloneNodeList(node.metadata),
1367 cloneToken(node.typedefKeyword),
1368 cloneNode(node.returnType),
1369 cloneNode(node.name),
1370 cloneNode(node.typeParameters),
1371 cloneNode(node.parameters),
1372 cloneToken(node.semicolon));
1373
1374 @override
1375 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
1376 FunctionTypedFormalParameter node) =>
1377 new FunctionTypedFormalParameter(
1378 cloneNode(node.documentationComment),
1379 cloneNodeList(node.metadata),
1380 cloneNode(node.returnType),
1381 cloneNode(node.identifier),
1382 cloneNode(node.typeParameters),
1383 cloneNode(node.parameters));
1384
1385 @override
1386 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
1387 cloneToken(node.keyword), cloneNodeList(node.hiddenNames));
1388
1389 @override
1390 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
1391 cloneToken(node.ifKeyword),
1392 cloneToken(node.leftParenthesis),
1393 cloneNode(node.condition),
1394 cloneToken(node.rightParenthesis),
1395 cloneNode(node.thenStatement),
1396 cloneToken(node.elseKeyword),
1397 cloneNode(node.elseStatement));
1398
1399 @override
1400 ImplementsClause visitImplementsClause(ImplementsClause node) =>
1401 new ImplementsClause(
1402 cloneToken(node.implementsKeyword), cloneNodeList(node.interfaces));
1403
1404 @override
1405 ImportDirective visitImportDirective(ImportDirective node) {
1406 ImportDirective directive = new ImportDirective(
1407 cloneNode(node.documentationComment),
1408 cloneNodeList(node.metadata),
1409 cloneToken(node.keyword),
1410 cloneNode(node.uri),
1411 cloneNodeList(node.configurations),
1412 cloneToken(node.deferredKeyword),
1413 cloneToken(node.asKeyword),
1414 cloneNode(node.prefix),
1415 cloneNodeList(node.combinators),
1416 cloneToken(node.semicolon));
1417 directive.source = node.source;
1418 directive.uriContent = node.uriContent;
1419 return directive;
1420 }
1421
1422 @override
1423 IndexExpression visitIndexExpression(IndexExpression node) {
1424 Token period = node.period;
1425 if (period == null) {
1426 return new IndexExpression.forTarget(
1427 cloneNode(node.target),
1428 cloneToken(node.leftBracket),
1429 cloneNode(node.index),
1430 cloneToken(node.rightBracket));
1431 } else {
1432 return new IndexExpression.forCascade(
1433 cloneToken(period),
1434 cloneToken(node.leftBracket),
1435 cloneNode(node.index),
1436 cloneToken(node.rightBracket));
1437 }
1438 }
1439
1440 @override
1441 InstanceCreationExpression visitInstanceCreationExpression(
1442 InstanceCreationExpression node) =>
1443 new InstanceCreationExpression(cloneToken(node.keyword),
1444 cloneNode(node.constructorName), cloneNode(node.argumentList));
1445
1446 @override
1447 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) =>
1448 new IntegerLiteral(cloneToken(node.literal), node.value);
1449
1450 @override
1451 InterpolationExpression visitInterpolationExpression(
1452 InterpolationExpression node) =>
1453 new InterpolationExpression(cloneToken(node.leftBracket),
1454 cloneNode(node.expression), cloneToken(node.rightBracket));
1455
1456 @override
1457 InterpolationString visitInterpolationString(InterpolationString node) =>
1458 new InterpolationString(cloneToken(node.contents), node.value);
1459
1460 @override
1461 IsExpression visitIsExpression(IsExpression node) => new IsExpression(
1462 cloneNode(node.expression),
1463 cloneToken(node.isOperator),
1464 cloneToken(node.notOperator),
1465 cloneNode(node.type));
1466
1467 @override
1468 Label visitLabel(Label node) =>
1469 new Label(cloneNode(node.label), cloneToken(node.colon));
1470
1471 @override
1472 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
1473 new LabeledStatement(
1474 cloneNodeList(node.labels), cloneNode(node.statement));
1475
1476 @override
1477 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
1478 new LibraryDirective(
1479 cloneNode(node.documentationComment),
1480 cloneNodeList(node.metadata),
1481 cloneToken(node.libraryKeyword),
1482 cloneNode(node.name),
1483 cloneToken(node.semicolon));
1484
1485 @override
1486 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) =>
1487 new LibraryIdentifier(cloneNodeList(node.components));
1488
1489 @override
1490 ListLiteral visitListLiteral(ListLiteral node) => new ListLiteral(
1491 cloneToken(node.constKeyword),
1492 cloneNode(node.typeArguments),
1493 cloneToken(node.leftBracket),
1494 cloneNodeList(node.elements),
1495 cloneToken(node.rightBracket));
1496
1497 @override
1498 MapLiteral visitMapLiteral(MapLiteral node) => new MapLiteral(
1499 cloneToken(node.constKeyword),
1500 cloneNode(node.typeArguments),
1501 cloneToken(node.leftBracket),
1502 cloneNodeList(node.entries),
1503 cloneToken(node.rightBracket));
1504
1505 @override
1506 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) =>
1507 new MapLiteralEntry(cloneNode(node.key), cloneToken(node.separator),
1508 cloneNode(node.value));
1509
1510 @override
1511 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
1512 new MethodDeclaration(
1513 cloneNode(node.documentationComment),
1514 cloneNodeList(node.metadata),
1515 cloneToken(node.externalKeyword),
1516 cloneToken(node.modifierKeyword),
1517 cloneNode(node.returnType),
1518 cloneToken(node.propertyKeyword),
1519 cloneToken(node.operatorKeyword),
1520 cloneNode(node.name),
1521 cloneNode(node.typeParameters),
1522 cloneNode(node.parameters),
1523 cloneNode(node.body));
1524
1525 @override
1526 MethodInvocation visitMethodInvocation(MethodInvocation node) =>
1527 new MethodInvocation(
1528 cloneNode(node.target),
1529 cloneToken(node.operator),
1530 cloneNode(node.methodName),
1531 cloneNode(node.typeArguments),
1532 cloneNode(node.argumentList));
1533
1534 @override
1535 NamedExpression visitNamedExpression(NamedExpression node) =>
1536 new NamedExpression(cloneNode(node.name), cloneNode(node.expression));
1537
1538 @override
1539 AstNode visitNativeClause(NativeClause node) =>
1540 new NativeClause(cloneToken(node.nativeKeyword), cloneNode(node.name));
1541
1542 @override
1543 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
1544 new NativeFunctionBody(cloneToken(node.nativeKeyword),
1545 cloneNode(node.stringLiteral), cloneToken(node.semicolon));
1546
1547 @override
1548 NullLiteral visitNullLiteral(NullLiteral node) =>
1549 new NullLiteral(cloneToken(node.literal));
1550
1551 @override
1552 ParenthesizedExpression visitParenthesizedExpression(
1553 ParenthesizedExpression node) =>
1554 new ParenthesizedExpression(cloneToken(node.leftParenthesis),
1555 cloneNode(node.expression), cloneToken(node.rightParenthesis));
1556
1557 @override
1558 PartDirective visitPartDirective(PartDirective node) {
1559 PartDirective directive = new PartDirective(
1560 cloneNode(node.documentationComment),
1561 cloneNodeList(node.metadata),
1562 cloneToken(node.partKeyword),
1563 cloneNode(node.uri),
1564 cloneToken(node.semicolon));
1565 directive.source = node.source;
1566 directive.uriContent = node.uriContent;
1567 return directive;
1568 }
1569
1570 @override
1571 PartOfDirective visitPartOfDirective(PartOfDirective node) =>
1572 new PartOfDirective(
1573 cloneNode(node.documentationComment),
1574 cloneNodeList(node.metadata),
1575 cloneToken(node.partKeyword),
1576 cloneToken(node.ofKeyword),
1577 cloneNode(node.libraryName),
1578 cloneToken(node.semicolon));
1579
1580 @override
1581 PostfixExpression visitPostfixExpression(PostfixExpression node) =>
1582 new PostfixExpression(cloneNode(node.operand), cloneToken(node.operator));
1583
1584 @override
1585 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) =>
1586 new PrefixedIdentifier(cloneNode(node.prefix), cloneToken(node.period),
1587 cloneNode(node.identifier));
1588
1589 @override
1590 PrefixExpression visitPrefixExpression(PrefixExpression node) =>
1591 new PrefixExpression(cloneToken(node.operator), cloneNode(node.operand));
1592
1593 @override
1594 PropertyAccess visitPropertyAccess(PropertyAccess node) => new PropertyAccess(
1595 cloneNode(node.target),
1596 cloneToken(node.operator),
1597 cloneNode(node.propertyName));
1598
1599 @override
1600 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
1601 RedirectingConstructorInvocation node) =>
1602 new RedirectingConstructorInvocation(
1603 cloneToken(node.thisKeyword),
1604 cloneToken(node.period),
1605 cloneNode(node.constructorName),
1606 cloneNode(node.argumentList));
1607
1608 @override
1609 RethrowExpression visitRethrowExpression(RethrowExpression node) =>
1610 new RethrowExpression(cloneToken(node.rethrowKeyword));
1611
1612 @override
1613 ReturnStatement visitReturnStatement(ReturnStatement node) =>
1614 new ReturnStatement(cloneToken(node.returnKeyword),
1615 cloneNode(node.expression), cloneToken(node.semicolon));
1616
1617 @override
1618 ScriptTag visitScriptTag(ScriptTag node) =>
1619 new ScriptTag(cloneToken(node.scriptTag));
1620
1621 @override
1622 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
1623 cloneToken(node.keyword), cloneNodeList(node.shownNames));
1624
1625 @override
1626 SimpleFormalParameter visitSimpleFormalParameter(
1627 SimpleFormalParameter node) =>
1628 new SimpleFormalParameter(
1629 cloneNode(node.documentationComment),
1630 cloneNodeList(node.metadata),
1631 cloneToken(node.keyword),
1632 cloneNode(node.type),
1633 cloneNode(node.identifier));
1634
1635 @override
1636 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) =>
1637 new SimpleIdentifier(cloneToken(node.token));
1638
1639 @override
1640 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) =>
1641 new SimpleStringLiteral(cloneToken(node.literal), node.value);
1642
1643 @override
1644 StringInterpolation visitStringInterpolation(StringInterpolation node) =>
1645 new StringInterpolation(cloneNodeList(node.elements));
1646
1647 @override
1648 SuperConstructorInvocation visitSuperConstructorInvocation(
1649 SuperConstructorInvocation node) =>
1650 new SuperConstructorInvocation(
1651 cloneToken(node.superKeyword),
1652 cloneToken(node.period),
1653 cloneNode(node.constructorName),
1654 cloneNode(node.argumentList));
1655
1656 @override
1657 SuperExpression visitSuperExpression(SuperExpression node) =>
1658 new SuperExpression(cloneToken(node.superKeyword));
1659
1660 @override
1661 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
1662 cloneNodeList(node.labels),
1663 cloneToken(node.keyword),
1664 cloneNode(node.expression),
1665 cloneToken(node.colon),
1666 cloneNodeList(node.statements));
1667
1668 @override
1669 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
1670 cloneNodeList(node.labels),
1671 cloneToken(node.keyword),
1672 cloneToken(node.colon),
1673 cloneNodeList(node.statements));
1674
1675 @override
1676 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
1677 new SwitchStatement(
1678 cloneToken(node.switchKeyword),
1679 cloneToken(node.leftParenthesis),
1680 cloneNode(node.expression),
1681 cloneToken(node.rightParenthesis),
1682 cloneToken(node.leftBracket),
1683 cloneNodeList(node.members),
1684 cloneToken(node.rightBracket));
1685
1686 @override
1687 SymbolLiteral visitSymbolLiteral(SymbolLiteral node) => new SymbolLiteral(
1688 cloneToken(node.poundSign), cloneTokenList(node.components));
1689
1690 @override
1691 ThisExpression visitThisExpression(ThisExpression node) =>
1692 new ThisExpression(cloneToken(node.thisKeyword));
1693
1694 @override
1695 ThrowExpression visitThrowExpression(ThrowExpression node) =>
1696 new ThrowExpression(
1697 cloneToken(node.throwKeyword), cloneNode(node.expression));
1698
1699 @override
1700 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
1701 TopLevelVariableDeclaration node) =>
1702 new TopLevelVariableDeclaration(
1703 cloneNode(node.documentationComment),
1704 cloneNodeList(node.metadata),
1705 cloneNode(node.variables),
1706 cloneToken(node.semicolon));
1707
1708 @override
1709 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
1710 cloneToken(node.tryKeyword),
1711 cloneNode(node.body),
1712 cloneNodeList(node.catchClauses),
1713 cloneToken(node.finallyKeyword),
1714 cloneNode(node.finallyBlock));
1715
1716 @override
1717 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
1718 new TypeArgumentList(cloneToken(node.leftBracket),
1719 cloneNodeList(node.arguments), cloneToken(node.rightBracket));
1720
1721 @override
1722 TypeName visitTypeName(TypeName node) =>
1723 new TypeName(cloneNode(node.name), cloneNode(node.typeArguments));
1724
1725 @override
1726 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
1727 cloneNode(node.documentationComment),
1728 cloneNodeList(node.metadata),
1729 cloneNode(node.name),
1730 cloneToken(node.extendsKeyword),
1731 cloneNode(node.bound));
1732
1733 @override
1734 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
1735 new TypeParameterList(cloneToken(node.leftBracket),
1736 cloneNodeList(node.typeParameters), cloneToken(node.rightBracket));
1737
1738 @override
1739 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
1740 new VariableDeclaration(cloneNode(node.name), cloneToken(node.equals),
1741 cloneNode(node.initializer));
1742
1743 @override
1744 VariableDeclarationList visitVariableDeclarationList(
1745 VariableDeclarationList node) =>
1746 new VariableDeclarationList(
1747 cloneNode(node.documentationComment),
1748 cloneNodeList(node.metadata),
1749 cloneToken(node.keyword),
1750 cloneNode(node.type),
1751 cloneNodeList(node.variables));
1752
1753 @override
1754 VariableDeclarationStatement visitVariableDeclarationStatement(
1755 VariableDeclarationStatement node) =>
1756 new VariableDeclarationStatement(
1757 cloneNode(node.variables), cloneToken(node.semicolon));
1758
1759 @override
1760 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
1761 cloneToken(node.whileKeyword),
1762 cloneToken(node.leftParenthesis),
1763 cloneNode(node.condition),
1764 cloneToken(node.rightParenthesis),
1765 cloneNode(node.body));
1766
1767 @override
1768 WithClause visitWithClause(WithClause node) => new WithClause(
1769 cloneToken(node.withKeyword), cloneNodeList(node.mixinTypes));
1770
1771 @override
1772 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
1773 cloneToken(node.yieldKeyword),
1774 cloneToken(node.star),
1775 cloneNode(node.expression),
1776 cloneToken(node.semicolon));
1777
1778 /**
1779 * Return a clone of the given [node].
1780 */
1781 static AstNode clone(AstNode node) {
1782 return node.accept(new AstCloner());
1783 }
1784 }
1785
1786 /**
1787 * An AstVisitor that compares the structure of two AstNodes to see whether they
1788 * are equal.
1789 */
1790 class AstComparator implements AstVisitor<bool> {
1791 /**
1792 * The AST node with which the node being visited is to be compared. This is
1793 * only valid at the beginning of each visit method (until [isEqualNodes] is
1794 * invoked).
1795 */
1796 AstNode _other;
1797
1798 /**
1799 * Return `true` if the [first] node and the [second] node have the same
1800 * structure.
1801 *
1802 * *Note:* This method is only visible for testing purposes and should not be
1803 * used by clients.
1804 */
1805 bool isEqualNodes(AstNode first, AstNode second) {
1806 if (first == null) {
1807 return second == null;
1808 } else if (second == null) {
1809 return false;
1810 } else if (first.runtimeType != second.runtimeType) {
1811 return false;
1812 }
1813 _other = second;
1814 return first.accept(this);
1815 }
1816
1817 /**
1818 * Return `true` if the [first] token and the [second] token have the same
1819 * structure.
1820 *
1821 * *Note:* This method is only visible for testing purposes and should not be
1822 * used by clients.
1823 */
1824 bool isEqualTokens(Token first, Token second) {
1825 if (first == null) {
1826 return second == null;
1827 } else if (second == null) {
1828 return false;
1829 } else if (identical(first, second)) {
1830 return true;
1831 }
1832 return first.offset == second.offset &&
1833 first.length == second.length &&
1834 first.lexeme == second.lexeme;
1835 }
1836
1837 @override
1838 bool visitAdjacentStrings(AdjacentStrings node) {
1839 AdjacentStrings other = _other as AdjacentStrings;
1840 return _isEqualNodeLists(node.strings, other.strings);
1841 }
1842
1843 @override
1844 bool visitAnnotation(Annotation node) {
1845 Annotation other = _other as Annotation;
1846 return isEqualTokens(node.atSign, other.atSign) &&
1847 isEqualNodes(node.name, other.name) &&
1848 isEqualTokens(node.period, other.period) &&
1849 isEqualNodes(node.constructorName, other.constructorName) &&
1850 isEqualNodes(node.arguments, other.arguments);
1851 }
1852
1853 @override
1854 bool visitArgumentList(ArgumentList node) {
1855 ArgumentList other = _other as ArgumentList;
1856 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1857 _isEqualNodeLists(node.arguments, other.arguments) &&
1858 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
1859 }
1860
1861 @override
1862 bool visitAsExpression(AsExpression node) {
1863 AsExpression other = _other as AsExpression;
1864 return isEqualNodes(node.expression, other.expression) &&
1865 isEqualTokens(node.asOperator, other.asOperator) &&
1866 isEqualNodes(node.type, other.type);
1867 }
1868
1869 @override
1870 bool visitAssertStatement(AssertStatement node) {
1871 AssertStatement other = _other as AssertStatement;
1872 return isEqualTokens(node.assertKeyword, other.assertKeyword) &&
1873 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1874 isEqualNodes(node.condition, other.condition) &&
1875 isEqualTokens(node.comma, other.comma) &&
1876 isEqualNodes(node.message, other.message) &&
1877 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1878 isEqualTokens(node.semicolon, other.semicolon);
1879 }
1880
1881 @override
1882 bool visitAssignmentExpression(AssignmentExpression node) {
1883 AssignmentExpression other = _other as AssignmentExpression;
1884 return isEqualNodes(node.leftHandSide, other.leftHandSide) &&
1885 isEqualTokens(node.operator, other.operator) &&
1886 isEqualNodes(node.rightHandSide, other.rightHandSide);
1887 }
1888
1889 @override
1890 bool visitAwaitExpression(AwaitExpression node) {
1891 AwaitExpression other = _other as AwaitExpression;
1892 return isEqualTokens(node.awaitKeyword, other.awaitKeyword) &&
1893 isEqualNodes(node.expression, other.expression);
1894 }
1895
1896 @override
1897 bool visitBinaryExpression(BinaryExpression node) {
1898 BinaryExpression other = _other as BinaryExpression;
1899 return isEqualNodes(node.leftOperand, other.leftOperand) &&
1900 isEqualTokens(node.operator, other.operator) &&
1901 isEqualNodes(node.rightOperand, other.rightOperand);
1902 }
1903
1904 @override
1905 bool visitBlock(Block node) {
1906 Block other = _other as Block;
1907 return isEqualTokens(node.leftBracket, other.leftBracket) &&
1908 _isEqualNodeLists(node.statements, other.statements) &&
1909 isEqualTokens(node.rightBracket, other.rightBracket);
1910 }
1911
1912 @override
1913 bool visitBlockFunctionBody(BlockFunctionBody node) {
1914 BlockFunctionBody other = _other as BlockFunctionBody;
1915 return isEqualNodes(node.block, other.block);
1916 }
1917
1918 @override
1919 bool visitBooleanLiteral(BooleanLiteral node) {
1920 BooleanLiteral other = _other as BooleanLiteral;
1921 return isEqualTokens(node.literal, other.literal) &&
1922 node.value == other.value;
1923 }
1924
1925 @override
1926 bool visitBreakStatement(BreakStatement node) {
1927 BreakStatement other = _other as BreakStatement;
1928 return isEqualTokens(node.breakKeyword, other.breakKeyword) &&
1929 isEqualNodes(node.label, other.label) &&
1930 isEqualTokens(node.semicolon, other.semicolon);
1931 }
1932
1933 @override
1934 bool visitCascadeExpression(CascadeExpression node) {
1935 CascadeExpression other = _other as CascadeExpression;
1936 return isEqualNodes(node.target, other.target) &&
1937 _isEqualNodeLists(node.cascadeSections, other.cascadeSections);
1938 }
1939
1940 @override
1941 bool visitCatchClause(CatchClause node) {
1942 CatchClause other = _other as CatchClause;
1943 return isEqualTokens(node.onKeyword, other.onKeyword) &&
1944 isEqualNodes(node.exceptionType, other.exceptionType) &&
1945 isEqualTokens(node.catchKeyword, other.catchKeyword) &&
1946 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1947 isEqualNodes(node.exceptionParameter, other.exceptionParameter) &&
1948 isEqualTokens(node.comma, other.comma) &&
1949 isEqualNodes(node.stackTraceParameter, other.stackTraceParameter) &&
1950 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1951 isEqualNodes(node.body, other.body);
1952 }
1953
1954 @override
1955 bool visitClassDeclaration(ClassDeclaration node) {
1956 ClassDeclaration other = _other as ClassDeclaration;
1957 return isEqualNodes(
1958 node.documentationComment, other.documentationComment) &&
1959 _isEqualNodeLists(node.metadata, other.metadata) &&
1960 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
1961 isEqualTokens(node.classKeyword, other.classKeyword) &&
1962 isEqualNodes(node.name, other.name) &&
1963 isEqualNodes(node.typeParameters, other.typeParameters) &&
1964 isEqualNodes(node.extendsClause, other.extendsClause) &&
1965 isEqualNodes(node.withClause, other.withClause) &&
1966 isEqualNodes(node.implementsClause, other.implementsClause) &&
1967 isEqualTokens(node.leftBracket, other.leftBracket) &&
1968 _isEqualNodeLists(node.members, other.members) &&
1969 isEqualTokens(node.rightBracket, other.rightBracket);
1970 }
1971
1972 @override
1973 bool visitClassTypeAlias(ClassTypeAlias node) {
1974 ClassTypeAlias other = _other as ClassTypeAlias;
1975 return isEqualNodes(
1976 node.documentationComment, other.documentationComment) &&
1977 _isEqualNodeLists(node.metadata, other.metadata) &&
1978 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
1979 isEqualNodes(node.name, other.name) &&
1980 isEqualNodes(node.typeParameters, other.typeParameters) &&
1981 isEqualTokens(node.equals, other.equals) &&
1982 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
1983 isEqualNodes(node.superclass, other.superclass) &&
1984 isEqualNodes(node.withClause, other.withClause) &&
1985 isEqualNodes(node.implementsClause, other.implementsClause) &&
1986 isEqualTokens(node.semicolon, other.semicolon);
1987 }
1988
1989 @override
1990 bool visitComment(Comment node) {
1991 Comment other = _other as Comment;
1992 return _isEqualNodeLists(node.references, other.references);
1993 }
1994
1995 @override
1996 bool visitCommentReference(CommentReference node) {
1997 CommentReference other = _other as CommentReference;
1998 return isEqualTokens(node.newKeyword, other.newKeyword) &&
1999 isEqualNodes(node.identifier, other.identifier);
2000 }
2001
2002 @override
2003 bool visitCompilationUnit(CompilationUnit node) {
2004 CompilationUnit other = _other as CompilationUnit;
2005 return isEqualTokens(node.beginToken, other.beginToken) &&
2006 isEqualNodes(node.scriptTag, other.scriptTag) &&
2007 _isEqualNodeLists(node.directives, other.directives) &&
2008 _isEqualNodeLists(node.declarations, other.declarations) &&
2009 isEqualTokens(node.endToken, other.endToken);
2010 }
2011
2012 @override
2013 bool visitConditionalExpression(ConditionalExpression node) {
2014 ConditionalExpression other = _other as ConditionalExpression;
2015 return isEqualNodes(node.condition, other.condition) &&
2016 isEqualTokens(node.question, other.question) &&
2017 isEqualNodes(node.thenExpression, other.thenExpression) &&
2018 isEqualTokens(node.colon, other.colon) &&
2019 isEqualNodes(node.elseExpression, other.elseExpression);
2020 }
2021
2022 @override
2023 bool visitConfiguration(Configuration node) {
2024 Configuration other = _other as Configuration;
2025 return isEqualTokens(node.ifKeyword, other.ifKeyword) &&
2026 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2027 isEqualNodes(node.name, other.name) &&
2028 isEqualTokens(node.equalToken, other.equalToken) &&
2029 isEqualNodes(node.value, other.value) &&
2030 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2031 isEqualNodes(node.libraryUri, other.libraryUri);
2032 }
2033
2034 @override
2035 bool visitConstructorDeclaration(ConstructorDeclaration node) {
2036 ConstructorDeclaration other = _other as ConstructorDeclaration;
2037 return isEqualNodes(
2038 node.documentationComment, other.documentationComment) &&
2039 _isEqualNodeLists(node.metadata, other.metadata) &&
2040 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2041 isEqualTokens(node.constKeyword, other.constKeyword) &&
2042 isEqualTokens(node.factoryKeyword, other.factoryKeyword) &&
2043 isEqualNodes(node.returnType, other.returnType) &&
2044 isEqualTokens(node.period, other.period) &&
2045 isEqualNodes(node.name, other.name) &&
2046 isEqualNodes(node.parameters, other.parameters) &&
2047 isEqualTokens(node.separator, other.separator) &&
2048 _isEqualNodeLists(node.initializers, other.initializers) &&
2049 isEqualNodes(node.redirectedConstructor, other.redirectedConstructor) &&
2050 isEqualNodes(node.body, other.body);
2051 }
2052
2053 @override
2054 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
2055 ConstructorFieldInitializer other = _other as ConstructorFieldInitializer;
2056 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2057 isEqualTokens(node.period, other.period) &&
2058 isEqualNodes(node.fieldName, other.fieldName) &&
2059 isEqualTokens(node.equals, other.equals) &&
2060 isEqualNodes(node.expression, other.expression);
2061 }
2062
2063 @override
2064 bool visitConstructorName(ConstructorName node) {
2065 ConstructorName other = _other as ConstructorName;
2066 return isEqualNodes(node.type, other.type) &&
2067 isEqualTokens(node.period, other.period) &&
2068 isEqualNodes(node.name, other.name);
2069 }
2070
2071 @override
2072 bool visitContinueStatement(ContinueStatement node) {
2073 ContinueStatement other = _other as ContinueStatement;
2074 return isEqualTokens(node.continueKeyword, other.continueKeyword) &&
2075 isEqualNodes(node.label, other.label) &&
2076 isEqualTokens(node.semicolon, other.semicolon);
2077 }
2078
2079 @override
2080 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
2081 DeclaredIdentifier other = _other as DeclaredIdentifier;
2082 return isEqualNodes(
2083 node.documentationComment, other.documentationComment) &&
2084 _isEqualNodeLists(node.metadata, other.metadata) &&
2085 isEqualTokens(node.keyword, other.keyword) &&
2086 isEqualNodes(node.type, other.type) &&
2087 isEqualNodes(node.identifier, other.identifier);
2088 }
2089
2090 @override
2091 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
2092 DefaultFormalParameter other = _other as DefaultFormalParameter;
2093 return isEqualNodes(node.parameter, other.parameter) &&
2094 node.kind == other.kind &&
2095 isEqualTokens(node.separator, other.separator) &&
2096 isEqualNodes(node.defaultValue, other.defaultValue);
2097 }
2098
2099 @override
2100 bool visitDoStatement(DoStatement node) {
2101 DoStatement other = _other as DoStatement;
2102 return isEqualTokens(node.doKeyword, other.doKeyword) &&
2103 isEqualNodes(node.body, other.body) &&
2104 isEqualTokens(node.whileKeyword, other.whileKeyword) &&
2105 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2106 isEqualNodes(node.condition, other.condition) &&
2107 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2108 isEqualTokens(node.semicolon, other.semicolon);
2109 }
2110
2111 @override
2112 bool visitDottedName(DottedName node) {
2113 DottedName other = _other as DottedName;
2114 return _isEqualNodeLists(node.components, other.components);
2115 }
2116
2117 @override
2118 bool visitDoubleLiteral(DoubleLiteral node) {
2119 DoubleLiteral other = _other as DoubleLiteral;
2120 return isEqualTokens(node.literal, other.literal) &&
2121 node.value == other.value;
2122 }
2123
2124 @override
2125 bool visitEmptyFunctionBody(EmptyFunctionBody node) {
2126 EmptyFunctionBody other = _other as EmptyFunctionBody;
2127 return isEqualTokens(node.semicolon, other.semicolon);
2128 }
2129
2130 @override
2131 bool visitEmptyStatement(EmptyStatement node) {
2132 EmptyStatement other = _other as EmptyStatement;
2133 return isEqualTokens(node.semicolon, other.semicolon);
2134 }
2135
2136 @override
2137 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
2138 EnumConstantDeclaration other = _other as EnumConstantDeclaration;
2139 return isEqualNodes(
2140 node.documentationComment, other.documentationComment) &&
2141 _isEqualNodeLists(node.metadata, other.metadata) &&
2142 isEqualNodes(node.name, other.name);
2143 }
2144
2145 @override
2146 bool visitEnumDeclaration(EnumDeclaration node) {
2147 EnumDeclaration other = _other as EnumDeclaration;
2148 return isEqualNodes(
2149 node.documentationComment, other.documentationComment) &&
2150 _isEqualNodeLists(node.metadata, other.metadata) &&
2151 isEqualTokens(node.enumKeyword, other.enumKeyword) &&
2152 isEqualNodes(node.name, other.name) &&
2153 isEqualTokens(node.leftBracket, other.leftBracket) &&
2154 _isEqualNodeLists(node.constants, other.constants) &&
2155 isEqualTokens(node.rightBracket, other.rightBracket);
2156 }
2157
2158 @override
2159 bool visitExportDirective(ExportDirective node) {
2160 ExportDirective other = _other as ExportDirective;
2161 return isEqualNodes(
2162 node.documentationComment, other.documentationComment) &&
2163 _isEqualNodeLists(node.metadata, other.metadata) &&
2164 isEqualTokens(node.keyword, other.keyword) &&
2165 isEqualNodes(node.uri, other.uri) &&
2166 _isEqualNodeLists(node.combinators, other.combinators) &&
2167 isEqualTokens(node.semicolon, other.semicolon);
2168 }
2169
2170 @override
2171 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
2172 ExpressionFunctionBody other = _other as ExpressionFunctionBody;
2173 return isEqualTokens(node.functionDefinition, other.functionDefinition) &&
2174 isEqualNodes(node.expression, other.expression) &&
2175 isEqualTokens(node.semicolon, other.semicolon);
2176 }
2177
2178 @override
2179 bool visitExpressionStatement(ExpressionStatement node) {
2180 ExpressionStatement other = _other as ExpressionStatement;
2181 return isEqualNodes(node.expression, other.expression) &&
2182 isEqualTokens(node.semicolon, other.semicolon);
2183 }
2184
2185 @override
2186 bool visitExtendsClause(ExtendsClause node) {
2187 ExtendsClause other = _other as ExtendsClause;
2188 return isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2189 isEqualNodes(node.superclass, other.superclass);
2190 }
2191
2192 @override
2193 bool visitFieldDeclaration(FieldDeclaration node) {
2194 FieldDeclaration other = _other as FieldDeclaration;
2195 return isEqualNodes(
2196 node.documentationComment, other.documentationComment) &&
2197 _isEqualNodeLists(node.metadata, other.metadata) &&
2198 isEqualTokens(node.staticKeyword, other.staticKeyword) &&
2199 isEqualNodes(node.fields, other.fields) &&
2200 isEqualTokens(node.semicolon, other.semicolon);
2201 }
2202
2203 @override
2204 bool visitFieldFormalParameter(FieldFormalParameter node) {
2205 FieldFormalParameter other = _other as FieldFormalParameter;
2206 return isEqualNodes(
2207 node.documentationComment, other.documentationComment) &&
2208 _isEqualNodeLists(node.metadata, other.metadata) &&
2209 isEqualTokens(node.keyword, other.keyword) &&
2210 isEqualNodes(node.type, other.type) &&
2211 isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2212 isEqualTokens(node.period, other.period) &&
2213 isEqualNodes(node.identifier, other.identifier);
2214 }
2215
2216 @override
2217 bool visitForEachStatement(ForEachStatement node) {
2218 ForEachStatement other = _other as ForEachStatement;
2219 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2220 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2221 isEqualNodes(node.loopVariable, other.loopVariable) &&
2222 isEqualTokens(node.inKeyword, other.inKeyword) &&
2223 isEqualNodes(node.iterable, other.iterable) &&
2224 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2225 isEqualNodes(node.body, other.body);
2226 }
2227
2228 @override
2229 bool visitFormalParameterList(FormalParameterList node) {
2230 FormalParameterList other = _other as FormalParameterList;
2231 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2232 _isEqualNodeLists(node.parameters, other.parameters) &&
2233 isEqualTokens(node.leftDelimiter, other.leftDelimiter) &&
2234 isEqualTokens(node.rightDelimiter, other.rightDelimiter) &&
2235 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2236 }
2237
2238 @override
2239 bool visitForStatement(ForStatement node) {
2240 ForStatement other = _other as ForStatement;
2241 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2242 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2243 isEqualNodes(node.variables, other.variables) &&
2244 isEqualNodes(node.initialization, other.initialization) &&
2245 isEqualTokens(node.leftSeparator, other.leftSeparator) &&
2246 isEqualNodes(node.condition, other.condition) &&
2247 isEqualTokens(node.rightSeparator, other.rightSeparator) &&
2248 _isEqualNodeLists(node.updaters, other.updaters) &&
2249 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2250 isEqualNodes(node.body, other.body);
2251 }
2252
2253 @override
2254 bool visitFunctionDeclaration(FunctionDeclaration node) {
2255 FunctionDeclaration other = _other as FunctionDeclaration;
2256 return isEqualNodes(
2257 node.documentationComment, other.documentationComment) &&
2258 _isEqualNodeLists(node.metadata, other.metadata) &&
2259 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2260 isEqualNodes(node.returnType, other.returnType) &&
2261 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2262 isEqualNodes(node.name, other.name) &&
2263 isEqualNodes(node.functionExpression, other.functionExpression);
2264 }
2265
2266 @override
2267 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
2268 FunctionDeclarationStatement other = _other as FunctionDeclarationStatement;
2269 return isEqualNodes(node.functionDeclaration, other.functionDeclaration);
2270 }
2271
2272 @override
2273 bool visitFunctionExpression(FunctionExpression node) {
2274 FunctionExpression other = _other as FunctionExpression;
2275 return isEqualNodes(node.parameters, other.parameters) &&
2276 isEqualNodes(node.body, other.body);
2277 }
2278
2279 @override
2280 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
2281 FunctionExpressionInvocation other = _other as FunctionExpressionInvocation;
2282 return isEqualNodes(node.function, other.function) &&
2283 isEqualNodes(node.argumentList, other.argumentList);
2284 }
2285
2286 @override
2287 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
2288 FunctionTypeAlias other = _other as FunctionTypeAlias;
2289 return isEqualNodes(
2290 node.documentationComment, other.documentationComment) &&
2291 _isEqualNodeLists(node.metadata, other.metadata) &&
2292 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
2293 isEqualNodes(node.returnType, other.returnType) &&
2294 isEqualNodes(node.name, other.name) &&
2295 isEqualNodes(node.typeParameters, other.typeParameters) &&
2296 isEqualNodes(node.parameters, other.parameters) &&
2297 isEqualTokens(node.semicolon, other.semicolon);
2298 }
2299
2300 @override
2301 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2302 FunctionTypedFormalParameter other = _other as FunctionTypedFormalParameter;
2303 return isEqualNodes(
2304 node.documentationComment, other.documentationComment) &&
2305 _isEqualNodeLists(node.metadata, other.metadata) &&
2306 isEqualNodes(node.returnType, other.returnType) &&
2307 isEqualNodes(node.identifier, other.identifier) &&
2308 isEqualNodes(node.parameters, other.parameters);
2309 }
2310
2311 @override
2312 bool visitHideCombinator(HideCombinator node) {
2313 HideCombinator other = _other as HideCombinator;
2314 return isEqualTokens(node.keyword, other.keyword) &&
2315 _isEqualNodeLists(node.hiddenNames, other.hiddenNames);
2316 }
2317
2318 @override
2319 bool visitIfStatement(IfStatement node) {
2320 IfStatement other = _other as IfStatement;
2321 return isEqualTokens(node.ifKeyword, other.ifKeyword) &&
2322 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2323 isEqualNodes(node.condition, other.condition) &&
2324 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2325 isEqualNodes(node.thenStatement, other.thenStatement) &&
2326 isEqualTokens(node.elseKeyword, other.elseKeyword) &&
2327 isEqualNodes(node.elseStatement, other.elseStatement);
2328 }
2329
2330 @override
2331 bool visitImplementsClause(ImplementsClause node) {
2332 ImplementsClause other = _other as ImplementsClause;
2333 return isEqualTokens(node.implementsKeyword, other.implementsKeyword) &&
2334 _isEqualNodeLists(node.interfaces, other.interfaces);
2335 }
2336
2337 @override
2338 bool visitImportDirective(ImportDirective node) {
2339 ImportDirective other = _other as ImportDirective;
2340 return isEqualNodes(
2341 node.documentationComment, other.documentationComment) &&
2342 _isEqualNodeLists(node.metadata, other.metadata) &&
2343 isEqualTokens(node.keyword, other.keyword) &&
2344 isEqualNodes(node.uri, other.uri) &&
2345 isEqualTokens(node.deferredKeyword, other.deferredKeyword) &&
2346 isEqualTokens(node.asKeyword, other.asKeyword) &&
2347 isEqualNodes(node.prefix, other.prefix) &&
2348 _isEqualNodeLists(node.combinators, other.combinators) &&
2349 isEqualTokens(node.semicolon, other.semicolon);
2350 }
2351
2352 @override
2353 bool visitIndexExpression(IndexExpression node) {
2354 IndexExpression other = _other as IndexExpression;
2355 return isEqualNodes(node.target, other.target) &&
2356 isEqualTokens(node.leftBracket, other.leftBracket) &&
2357 isEqualNodes(node.index, other.index) &&
2358 isEqualTokens(node.rightBracket, other.rightBracket);
2359 }
2360
2361 @override
2362 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
2363 InstanceCreationExpression other = _other as InstanceCreationExpression;
2364 return isEqualTokens(node.keyword, other.keyword) &&
2365 isEqualNodes(node.constructorName, other.constructorName) &&
2366 isEqualNodes(node.argumentList, other.argumentList);
2367 }
2368
2369 @override
2370 bool visitIntegerLiteral(IntegerLiteral node) {
2371 IntegerLiteral other = _other as IntegerLiteral;
2372 return isEqualTokens(node.literal, other.literal) &&
2373 (node.value == other.value);
2374 }
2375
2376 @override
2377 bool visitInterpolationExpression(InterpolationExpression node) {
2378 InterpolationExpression other = _other as InterpolationExpression;
2379 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2380 isEqualNodes(node.expression, other.expression) &&
2381 isEqualTokens(node.rightBracket, other.rightBracket);
2382 }
2383
2384 @override
2385 bool visitInterpolationString(InterpolationString node) {
2386 InterpolationString other = _other as InterpolationString;
2387 return isEqualTokens(node.contents, other.contents) &&
2388 node.value == other.value;
2389 }
2390
2391 @override
2392 bool visitIsExpression(IsExpression node) {
2393 IsExpression other = _other as IsExpression;
2394 return isEqualNodes(node.expression, other.expression) &&
2395 isEqualTokens(node.isOperator, other.isOperator) &&
2396 isEqualTokens(node.notOperator, other.notOperator) &&
2397 isEqualNodes(node.type, other.type);
2398 }
2399
2400 @override
2401 bool visitLabel(Label node) {
2402 Label other = _other as Label;
2403 return isEqualNodes(node.label, other.label) &&
2404 isEqualTokens(node.colon, other.colon);
2405 }
2406
2407 @override
2408 bool visitLabeledStatement(LabeledStatement node) {
2409 LabeledStatement other = _other as LabeledStatement;
2410 return _isEqualNodeLists(node.labels, other.labels) &&
2411 isEqualNodes(node.statement, other.statement);
2412 }
2413
2414 @override
2415 bool visitLibraryDirective(LibraryDirective node) {
2416 LibraryDirective other = _other as LibraryDirective;
2417 return isEqualNodes(
2418 node.documentationComment, other.documentationComment) &&
2419 _isEqualNodeLists(node.metadata, other.metadata) &&
2420 isEqualTokens(node.libraryKeyword, other.libraryKeyword) &&
2421 isEqualNodes(node.name, other.name) &&
2422 isEqualTokens(node.semicolon, other.semicolon);
2423 }
2424
2425 @override
2426 bool visitLibraryIdentifier(LibraryIdentifier node) {
2427 LibraryIdentifier other = _other as LibraryIdentifier;
2428 return _isEqualNodeLists(node.components, other.components);
2429 }
2430
2431 @override
2432 bool visitListLiteral(ListLiteral node) {
2433 ListLiteral other = _other as ListLiteral;
2434 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2435 isEqualNodes(node.typeArguments, other.typeArguments) &&
2436 isEqualTokens(node.leftBracket, other.leftBracket) &&
2437 _isEqualNodeLists(node.elements, other.elements) &&
2438 isEqualTokens(node.rightBracket, other.rightBracket);
2439 }
2440
2441 @override
2442 bool visitMapLiteral(MapLiteral node) {
2443 MapLiteral other = _other as MapLiteral;
2444 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2445 isEqualNodes(node.typeArguments, other.typeArguments) &&
2446 isEqualTokens(node.leftBracket, other.leftBracket) &&
2447 _isEqualNodeLists(node.entries, other.entries) &&
2448 isEqualTokens(node.rightBracket, other.rightBracket);
2449 }
2450
2451 @override
2452 bool visitMapLiteralEntry(MapLiteralEntry node) {
2453 MapLiteralEntry other = _other as MapLiteralEntry;
2454 return isEqualNodes(node.key, other.key) &&
2455 isEqualTokens(node.separator, other.separator) &&
2456 isEqualNodes(node.value, other.value);
2457 }
2458
2459 @override
2460 bool visitMethodDeclaration(MethodDeclaration node) {
2461 MethodDeclaration other = _other as MethodDeclaration;
2462 return isEqualNodes(
2463 node.documentationComment, other.documentationComment) &&
2464 _isEqualNodeLists(node.metadata, other.metadata) &&
2465 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2466 isEqualTokens(node.modifierKeyword, other.modifierKeyword) &&
2467 isEqualNodes(node.returnType, other.returnType) &&
2468 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2469 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2470 isEqualNodes(node.name, other.name) &&
2471 isEqualNodes(node.parameters, other.parameters) &&
2472 isEqualNodes(node.body, other.body);
2473 }
2474
2475 @override
2476 bool visitMethodInvocation(MethodInvocation node) {
2477 MethodInvocation other = _other as MethodInvocation;
2478 return isEqualNodes(node.target, other.target) &&
2479 isEqualTokens(node.operator, other.operator) &&
2480 isEqualNodes(node.methodName, other.methodName) &&
2481 isEqualNodes(node.argumentList, other.argumentList);
2482 }
2483
2484 @override
2485 bool visitNamedExpression(NamedExpression node) {
2486 NamedExpression other = _other as NamedExpression;
2487 return isEqualNodes(node.name, other.name) &&
2488 isEqualNodes(node.expression, other.expression);
2489 }
2490
2491 @override
2492 bool visitNativeClause(NativeClause node) {
2493 NativeClause other = _other as NativeClause;
2494 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2495 isEqualNodes(node.name, other.name);
2496 }
2497
2498 @override
2499 bool visitNativeFunctionBody(NativeFunctionBody node) {
2500 NativeFunctionBody other = _other as NativeFunctionBody;
2501 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2502 isEqualNodes(node.stringLiteral, other.stringLiteral) &&
2503 isEqualTokens(node.semicolon, other.semicolon);
2504 }
2505
2506 @override
2507 bool visitNullLiteral(NullLiteral node) {
2508 NullLiteral other = _other as NullLiteral;
2509 return isEqualTokens(node.literal, other.literal);
2510 }
2511
2512 @override
2513 bool visitParenthesizedExpression(ParenthesizedExpression node) {
2514 ParenthesizedExpression other = _other as ParenthesizedExpression;
2515 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2516 isEqualNodes(node.expression, other.expression) &&
2517 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2518 }
2519
2520 @override
2521 bool visitPartDirective(PartDirective node) {
2522 PartDirective other = _other as PartDirective;
2523 return isEqualNodes(
2524 node.documentationComment, other.documentationComment) &&
2525 _isEqualNodeLists(node.metadata, other.metadata) &&
2526 isEqualTokens(node.partKeyword, other.partKeyword) &&
2527 isEqualNodes(node.uri, other.uri) &&
2528 isEqualTokens(node.semicolon, other.semicolon);
2529 }
2530
2531 @override
2532 bool visitPartOfDirective(PartOfDirective node) {
2533 PartOfDirective other = _other as PartOfDirective;
2534 return isEqualNodes(
2535 node.documentationComment, other.documentationComment) &&
2536 _isEqualNodeLists(node.metadata, other.metadata) &&
2537 isEqualTokens(node.partKeyword, other.partKeyword) &&
2538 isEqualTokens(node.ofKeyword, other.ofKeyword) &&
2539 isEqualNodes(node.libraryName, other.libraryName) &&
2540 isEqualTokens(node.semicolon, other.semicolon);
2541 }
2542
2543 @override
2544 bool visitPostfixExpression(PostfixExpression node) {
2545 PostfixExpression other = _other as PostfixExpression;
2546 return isEqualNodes(node.operand, other.operand) &&
2547 isEqualTokens(node.operator, other.operator);
2548 }
2549
2550 @override
2551 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
2552 PrefixedIdentifier other = _other as PrefixedIdentifier;
2553 return isEqualNodes(node.prefix, other.prefix) &&
2554 isEqualTokens(node.period, other.period) &&
2555 isEqualNodes(node.identifier, other.identifier);
2556 }
2557
2558 @override
2559 bool visitPrefixExpression(PrefixExpression node) {
2560 PrefixExpression other = _other as PrefixExpression;
2561 return isEqualTokens(node.operator, other.operator) &&
2562 isEqualNodes(node.operand, other.operand);
2563 }
2564
2565 @override
2566 bool visitPropertyAccess(PropertyAccess node) {
2567 PropertyAccess other = _other as PropertyAccess;
2568 return isEqualNodes(node.target, other.target) &&
2569 isEqualTokens(node.operator, other.operator) &&
2570 isEqualNodes(node.propertyName, other.propertyName);
2571 }
2572
2573 @override
2574 bool visitRedirectingConstructorInvocation(
2575 RedirectingConstructorInvocation node) {
2576 RedirectingConstructorInvocation other =
2577 _other as RedirectingConstructorInvocation;
2578 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2579 isEqualTokens(node.period, other.period) &&
2580 isEqualNodes(node.constructorName, other.constructorName) &&
2581 isEqualNodes(node.argumentList, other.argumentList);
2582 }
2583
2584 @override
2585 bool visitRethrowExpression(RethrowExpression node) {
2586 RethrowExpression other = _other as RethrowExpression;
2587 return isEqualTokens(node.rethrowKeyword, other.rethrowKeyword);
2588 }
2589
2590 @override
2591 bool visitReturnStatement(ReturnStatement node) {
2592 ReturnStatement other = _other as ReturnStatement;
2593 return isEqualTokens(node.returnKeyword, other.returnKeyword) &&
2594 isEqualNodes(node.expression, other.expression) &&
2595 isEqualTokens(node.semicolon, other.semicolon);
2596 }
2597
2598 @override
2599 bool visitScriptTag(ScriptTag node) {
2600 ScriptTag other = _other as ScriptTag;
2601 return isEqualTokens(node.scriptTag, other.scriptTag);
2602 }
2603
2604 @override
2605 bool visitShowCombinator(ShowCombinator node) {
2606 ShowCombinator other = _other as ShowCombinator;
2607 return isEqualTokens(node.keyword, other.keyword) &&
2608 _isEqualNodeLists(node.shownNames, other.shownNames);
2609 }
2610
2611 @override
2612 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
2613 SimpleFormalParameter other = _other as SimpleFormalParameter;
2614 return isEqualNodes(
2615 node.documentationComment, other.documentationComment) &&
2616 _isEqualNodeLists(node.metadata, other.metadata) &&
2617 isEqualTokens(node.keyword, other.keyword) &&
2618 isEqualNodes(node.type, other.type) &&
2619 isEqualNodes(node.identifier, other.identifier);
2620 }
2621
2622 @override
2623 bool visitSimpleIdentifier(SimpleIdentifier node) {
2624 SimpleIdentifier other = _other as SimpleIdentifier;
2625 return isEqualTokens(node.token, other.token);
2626 }
2627
2628 @override
2629 bool visitSimpleStringLiteral(SimpleStringLiteral node) {
2630 SimpleStringLiteral other = _other as SimpleStringLiteral;
2631 return isEqualTokens(node.literal, other.literal) &&
2632 (node.value == other.value);
2633 }
2634
2635 @override
2636 bool visitStringInterpolation(StringInterpolation node) {
2637 StringInterpolation other = _other as StringInterpolation;
2638 return _isEqualNodeLists(node.elements, other.elements);
2639 }
2640
2641 @override
2642 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2643 SuperConstructorInvocation other = _other as SuperConstructorInvocation;
2644 return isEqualTokens(node.superKeyword, other.superKeyword) &&
2645 isEqualTokens(node.period, other.period) &&
2646 isEqualNodes(node.constructorName, other.constructorName) &&
2647 isEqualNodes(node.argumentList, other.argumentList);
2648 }
2649
2650 @override
2651 bool visitSuperExpression(SuperExpression node) {
2652 SuperExpression other = _other as SuperExpression;
2653 return isEqualTokens(node.superKeyword, other.superKeyword);
2654 }
2655
2656 @override
2657 bool visitSwitchCase(SwitchCase node) {
2658 SwitchCase other = _other as SwitchCase;
2659 return _isEqualNodeLists(node.labels, other.labels) &&
2660 isEqualTokens(node.keyword, other.keyword) &&
2661 isEqualNodes(node.expression, other.expression) &&
2662 isEqualTokens(node.colon, other.colon) &&
2663 _isEqualNodeLists(node.statements, other.statements);
2664 }
2665
2666 @override
2667 bool visitSwitchDefault(SwitchDefault node) {
2668 SwitchDefault other = _other as SwitchDefault;
2669 return _isEqualNodeLists(node.labels, other.labels) &&
2670 isEqualTokens(node.keyword, other.keyword) &&
2671 isEqualTokens(node.colon, other.colon) &&
2672 _isEqualNodeLists(node.statements, other.statements);
2673 }
2674
2675 @override
2676 bool visitSwitchStatement(SwitchStatement node) {
2677 SwitchStatement other = _other as SwitchStatement;
2678 return isEqualTokens(node.switchKeyword, other.switchKeyword) &&
2679 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2680 isEqualNodes(node.expression, other.expression) &&
2681 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2682 isEqualTokens(node.leftBracket, other.leftBracket) &&
2683 _isEqualNodeLists(node.members, other.members) &&
2684 isEqualTokens(node.rightBracket, other.rightBracket);
2685 }
2686
2687 @override
2688 bool visitSymbolLiteral(SymbolLiteral node) {
2689 SymbolLiteral other = _other as SymbolLiteral;
2690 return isEqualTokens(node.poundSign, other.poundSign) &&
2691 _isEqualTokenLists(node.components, other.components);
2692 }
2693
2694 @override
2695 bool visitThisExpression(ThisExpression node) {
2696 ThisExpression other = _other as ThisExpression;
2697 return isEqualTokens(node.thisKeyword, other.thisKeyword);
2698 }
2699
2700 @override
2701 bool visitThrowExpression(ThrowExpression node) {
2702 ThrowExpression other = _other as ThrowExpression;
2703 return isEqualTokens(node.throwKeyword, other.throwKeyword) &&
2704 isEqualNodes(node.expression, other.expression);
2705 }
2706
2707 @override
2708 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
2709 TopLevelVariableDeclaration other = _other as TopLevelVariableDeclaration;
2710 return isEqualNodes(
2711 node.documentationComment, other.documentationComment) &&
2712 _isEqualNodeLists(node.metadata, other.metadata) &&
2713 isEqualNodes(node.variables, other.variables) &&
2714 isEqualTokens(node.semicolon, other.semicolon);
2715 }
2716
2717 @override
2718 bool visitTryStatement(TryStatement node) {
2719 TryStatement other = _other as TryStatement;
2720 return isEqualTokens(node.tryKeyword, other.tryKeyword) &&
2721 isEqualNodes(node.body, other.body) &&
2722 _isEqualNodeLists(node.catchClauses, other.catchClauses) &&
2723 isEqualTokens(node.finallyKeyword, other.finallyKeyword) &&
2724 isEqualNodes(node.finallyBlock, other.finallyBlock);
2725 }
2726
2727 @override
2728 bool visitTypeArgumentList(TypeArgumentList node) {
2729 TypeArgumentList other = _other as TypeArgumentList;
2730 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2731 _isEqualNodeLists(node.arguments, other.arguments) &&
2732 isEqualTokens(node.rightBracket, other.rightBracket);
2733 }
2734
2735 @override
2736 bool visitTypeName(TypeName node) {
2737 TypeName other = _other as TypeName;
2738 return isEqualNodes(node.name, other.name) &&
2739 isEqualNodes(node.typeArguments, other.typeArguments);
2740 }
2741
2742 @override
2743 bool visitTypeParameter(TypeParameter node) {
2744 TypeParameter other = _other as TypeParameter;
2745 return isEqualNodes(
2746 node.documentationComment, other.documentationComment) &&
2747 _isEqualNodeLists(node.metadata, other.metadata) &&
2748 isEqualNodes(node.name, other.name) &&
2749 isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2750 isEqualNodes(node.bound, other.bound);
2751 }
2752
2753 @override
2754 bool visitTypeParameterList(TypeParameterList node) {
2755 TypeParameterList other = _other as TypeParameterList;
2756 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2757 _isEqualNodeLists(node.typeParameters, other.typeParameters) &&
2758 isEqualTokens(node.rightBracket, other.rightBracket);
2759 }
2760
2761 @override
2762 bool visitVariableDeclaration(VariableDeclaration node) {
2763 VariableDeclaration other = _other as VariableDeclaration;
2764 return isEqualNodes(
2765 node.documentationComment, other.documentationComment) &&
2766 _isEqualNodeLists(node.metadata, other.metadata) &&
2767 isEqualNodes(node.name, other.name) &&
2768 isEqualTokens(node.equals, other.equals) &&
2769 isEqualNodes(node.initializer, other.initializer);
2770 }
2771
2772 @override
2773 bool visitVariableDeclarationList(VariableDeclarationList node) {
2774 VariableDeclarationList other = _other as VariableDeclarationList;
2775 return isEqualNodes(
2776 node.documentationComment, other.documentationComment) &&
2777 _isEqualNodeLists(node.metadata, other.metadata) &&
2778 isEqualTokens(node.keyword, other.keyword) &&
2779 isEqualNodes(node.type, other.type) &&
2780 _isEqualNodeLists(node.variables, other.variables);
2781 }
2782
2783 @override
2784 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
2785 VariableDeclarationStatement other = _other as VariableDeclarationStatement;
2786 return isEqualNodes(node.variables, other.variables) &&
2787 isEqualTokens(node.semicolon, other.semicolon);
2788 }
2789
2790 @override
2791 bool visitWhileStatement(WhileStatement node) {
2792 WhileStatement other = _other as WhileStatement;
2793 return isEqualTokens(node.whileKeyword, other.whileKeyword) &&
2794 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2795 isEqualNodes(node.condition, other.condition) &&
2796 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2797 isEqualNodes(node.body, other.body);
2798 }
2799
2800 @override
2801 bool visitWithClause(WithClause node) {
2802 WithClause other = _other as WithClause;
2803 return isEqualTokens(node.withKeyword, other.withKeyword) &&
2804 _isEqualNodeLists(node.mixinTypes, other.mixinTypes);
2805 }
2806
2807 @override
2808 bool visitYieldStatement(YieldStatement node) {
2809 YieldStatement other = _other as YieldStatement;
2810 return isEqualTokens(node.yieldKeyword, other.yieldKeyword) &&
2811 isEqualNodes(node.expression, other.expression) &&
2812 isEqualTokens(node.semicolon, other.semicolon);
2813 }
2814
2815 /**
2816 * Return `true` if the [first] and [second] lists of AST nodes have the same
2817 * size and corresponding elements are equal.
2818 */
2819 bool _isEqualNodeLists(NodeList first, NodeList second) {
2820 if (first == null) {
2821 return second == null;
2822 } else if (second == null) {
2823 return false;
2824 }
2825 int size = first.length;
2826 if (second.length != size) {
2827 return false;
2828 }
2829 for (int i = 0; i < size; i++) {
2830 if (!isEqualNodes(first[i], second[i])) {
2831 return false;
2832 }
2833 }
2834 return true;
2835 }
2836
2837 /**
2838 * Return `true` if the [first] and [second] lists of tokens have the same
2839 * length and corresponding elements are equal.
2840 */
2841 bool _isEqualTokenLists(List<Token> first, List<Token> second) {
2842 int length = first.length;
2843 if (second.length != length) {
2844 return false;
2845 }
2846 for (int i = 0; i < length; i++) {
2847 if (!isEqualTokens(first[i], second[i])) {
2848 return false;
2849 }
2850 }
2851 return true;
2852 }
2853
2854 /**
2855 * Return `true` if the [first] and [second] nodes are equal.
2856 */
2857 static bool equalNodes(AstNode first, AstNode second) {
2858 AstComparator comparator = new AstComparator();
2859 return comparator.isEqualNodes(first, second);
2860 }
2861 }
2862
2863 /**
2864 * A node in the AST structure for a Dart program. 912 * A node in the AST structure for a Dart program.
2865 */ 913 */
2866 abstract class AstNode { 914 abstract class AstNode {
2867 /** 915 /**
2868 * An empty list of AST nodes. 916 * An empty list of AST nodes.
2869 */ 917 */
2870 static const List<AstNode> EMPTY_LIST = const <AstNode>[]; 918 static const List<AstNode> EMPTY_LIST = const <AstNode>[];
2871 919
2872 /** 920 /**
2873 * A comparator that can be used to sort AST nodes in lexical order. In other 921 * A comparator that can be used to sort AST nodes in lexical order. In other
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 @override 1712 @override
3665 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this); 1713 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this);
3666 1714
3667 @override 1715 @override
3668 void visitChildren(AstVisitor visitor) { 1716 void visitChildren(AstVisitor visitor) {
3669 // There are no children to visit. 1717 // There are no children to visit.
3670 } 1718 }
3671 } 1719 }
3672 1720
3673 /** 1721 /**
3674 * An AST visitor that will recursively visit all of the nodes in an AST
3675 * structure, similar to [GeneralizingAstVisitor]. This visitor uses a
3676 * breadth-first ordering rather than the depth-first ordering of
3677 * [GeneralizingAstVisitor].
3678 *
3679 * Subclasses that override a visit method must either invoke the overridden
3680 * visit method or explicitly invoke the more general visit method. Failure to
3681 * do so will cause the visit methods for superclasses of the node to not be
3682 * invoked and will cause the children of the visited node to not be visited.
3683 *
3684 * In addition, subclasses should <b>not</b> explicitly visit the children of a
3685 * node, but should ensure that the method [visitNode] is used to visit the
3686 * children (either directly or indirectly). Failure to do will break the order
3687 * in which nodes are visited.
3688 */
3689 class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
3690 /**
3691 * A queue holding the nodes that have not yet been visited in the order in
3692 * which they ought to be visited.
3693 */
3694 Queue<AstNode> _queue = new Queue<AstNode>();
3695
3696 /**
3697 * A visitor, used to visit the children of the current node, that will add
3698 * the nodes it visits to the [_queue].
3699 */
3700 GeneralizingAstVisitor<Object> _childVisitor;
3701
3702 /**
3703 * Initialize a newly created visitor.
3704 */
3705 BreadthFirstVisitor() {
3706 _childVisitor = new GeneralizingAstVisitor_BreadthFirstVisitor(this);
3707 }
3708
3709 /**
3710 * Visit all nodes in the tree starting at the given [root] node, in
3711 * breadth-first order.
3712 */
3713 void visitAllNodes(AstNode root) {
3714 _queue.add(root);
3715 while (!_queue.isEmpty) {
3716 AstNode next = _queue.removeFirst();
3717 next.accept(this);
3718 }
3719 }
3720
3721 @override
3722 R visitNode(AstNode node) {
3723 node.visitChildren(_childVisitor);
3724 return null;
3725 }
3726 }
3727
3728 /**
3729 * A break statement. 1722 * A break statement.
3730 * 1723 *
3731 * > breakStatement ::= 1724 * > breakStatement ::=
3732 * > 'break' [SimpleIdentifier]? ';' 1725 * > 'break' [SimpleIdentifier]? ';'
3733 */ 1726 */
3734 class BreakStatement extends Statement { 1727 class BreakStatement extends Statement {
3735 /** 1728 /**
3736 * The token representing the 'break' keyword. 1729 * The token representing the 'break' keyword.
3737 */ 1730 */
3738 Token breakKeyword; 1731 Token breakKeyword;
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
5122 accept(AstVisitor visitor) => visitor.visitConfiguration(this); 3115 accept(AstVisitor visitor) => visitor.visitConfiguration(this);
5123 3116
5124 @override 3117 @override
5125 void visitChildren(AstVisitor visitor) { 3118 void visitChildren(AstVisitor visitor) {
5126 _safelyVisitChild(_name, visitor); 3119 _safelyVisitChild(_name, visitor);
5127 _safelyVisitChild(_value, visitor); 3120 _safelyVisitChild(_value, visitor);
5128 _safelyVisitChild(_libraryUri, visitor); 3121 _safelyVisitChild(_libraryUri, visitor);
5129 } 3122 }
5130 } 3123 }
5131 3124
5132 /// Instances of the class [ConstantEvaluator] evaluate constant expressions to
5133 /// produce their compile-time value.
5134 ///
5135 /// According to the Dart Language Specification:
5136 ///
5137 /// > A constant expression is one of the following:
5138 /// >
5139 /// > * A literal number.
5140 /// > * A literal boolean.
5141 /// > * A literal string where any interpolated expression is a compile-time
5142 /// > constant that evaluates to a numeric, string or boolean value or to
5143 /// > **null**.
5144 /// > * A literal symbol.
5145 /// > * **null**.
5146 /// > * A qualified reference to a static constant variable.
5147 /// > * An identifier expression that denotes a constant variable, class or type
5148 /// > alias.
5149 /// > * A constant constructor invocation.
5150 /// > * A constant list literal.
5151 /// > * A constant map literal.
5152 /// > * A simple or qualified identifier denoting a top-level function or a
5153 /// > static method.
5154 /// > * A parenthesized expression _(e)_ where _e_ is a constant expression.
5155 /// > * <span>
5156 /// > An expression of the form <i>identical(e<sub>1</sub>, e<sub>2</sub>)</i>
5157 /// > where <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5158 /// > expressions and <i>identical()</i> is statically bound to the predefined
5159 /// > dart function <i>identical()</i> discussed above.
5160 /// > </span>
5161 /// > * <span>
5162 /// > An expression of one of the forms <i>e<sub>1</sub> == e<sub>2</sub></i>
5163 /// > or <i>e<sub>1</sub> != e<sub>2</sub></i> where <i>e<sub>1</sub></i> and
5164 /// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a
5165 /// > numeric, string or boolean value.
5166 /// > </span>
5167 /// > * <span>
5168 /// > An expression of one of the forms <i>!e</i>, <i>e<sub>1</sub> &amp;&amp;
5169 /// > e<sub>2</sub></i> or <i>e<sub>1</sub> || e<sub>2</sub></i>, where
5170 /// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5171 /// > expressions that evaluate to a boolean value.
5172 /// > </span>
5173 /// > * <span>
5174 /// > An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^
5175 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> &amp; e<sub>2</sub></i>,
5176 /// > <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;&gt;
5177 /// > e<sub>2</sub></i> or <i>e<sub>1</sub> &lt;&lt; e<sub>2</sub></i>, where
5178 /// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5179 /// > expressions that evaluate to an integer value or to <b>null</b>.
5180 /// > </span>
5181 /// > * <span>
5182 /// > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> +
5183 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>,
5184 /// > <i>e<sub>1</sub> * e<sub>2</sub></i>, <i>e<sub>1</sub> /
5185 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>,
5186 /// > <i>e<sub>1</sub> &gt; e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;
5187 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;= e<sub>2</sub></i>,
5188 /// > <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</sub> %
5189 /// > e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and
5190 /// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric
5191 /// > value or to <b>null</b>.
5192 /// > </span>
5193 /// > * <span>
5194 /// > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> :
5195 /// > e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and
5196 /// > <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i>
5197 /// > evaluates to a boolean value.
5198 /// > </span>
5199 ///
5200 /// The values returned by instances of this class are therefore `null` and
5201 /// instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
5202 /// `DartObject`.
5203 ///
5204 /// In addition, this class defines several values that can be returned to
5205 /// indicate various conditions encountered during evaluation. These are
5206 /// documented with the static fields that define those values.
5207 class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
5208 /**
5209 * The value returned for expressions (or non-expression nodes) that are not
5210 * compile-time constant expressions.
5211 */
5212 static Object NOT_A_CONSTANT = new Object();
5213
5214 @override
5215 Object visitAdjacentStrings(AdjacentStrings node) {
5216 StringBuffer buffer = new StringBuffer();
5217 for (StringLiteral string in node.strings) {
5218 Object value = string.accept(this);
5219 if (identical(value, NOT_A_CONSTANT)) {
5220 return value;
5221 }
5222 buffer.write(value);
5223 }
5224 return buffer.toString();
5225 }
5226
5227 @override
5228 Object visitBinaryExpression(BinaryExpression node) {
5229 Object leftOperand = node.leftOperand.accept(this);
5230 if (identical(leftOperand, NOT_A_CONSTANT)) {
5231 return leftOperand;
5232 }
5233 Object rightOperand = node.rightOperand.accept(this);
5234 if (identical(rightOperand, NOT_A_CONSTANT)) {
5235 return rightOperand;
5236 }
5237 while (true) {
5238 if (node.operator.type == TokenType.AMPERSAND) {
5239 // integer or {@code null}
5240 if (leftOperand is int && rightOperand is int) {
5241 return leftOperand & rightOperand;
5242 }
5243 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) {
5244 // boolean or {@code null}
5245 if (leftOperand is bool && rightOperand is bool) {
5246 return leftOperand && rightOperand;
5247 }
5248 } else if (node.operator.type == TokenType.BANG_EQ) {
5249 // numeric, string, boolean, or {@code null}
5250 if (leftOperand is bool && rightOperand is bool) {
5251 return leftOperand != rightOperand;
5252 } else if (leftOperand is num && rightOperand is num) {
5253 return leftOperand != rightOperand;
5254 } else if (leftOperand is String && rightOperand is String) {
5255 return leftOperand != rightOperand;
5256 }
5257 } else if (node.operator.type == TokenType.BAR) {
5258 // integer or {@code null}
5259 if (leftOperand is int && rightOperand is int) {
5260 return leftOperand | rightOperand;
5261 }
5262 } else if (node.operator.type == TokenType.BAR_BAR) {
5263 // boolean or {@code null}
5264 if (leftOperand is bool && rightOperand is bool) {
5265 return leftOperand || rightOperand;
5266 }
5267 } else if (node.operator.type == TokenType.CARET) {
5268 // integer or {@code null}
5269 if (leftOperand is int && rightOperand is int) {
5270 return leftOperand ^ rightOperand;
5271 }
5272 } else if (node.operator.type == TokenType.EQ_EQ) {
5273 // numeric, string, boolean, or {@code null}
5274 if (leftOperand is bool && rightOperand is bool) {
5275 return leftOperand == rightOperand;
5276 } else if (leftOperand is num && rightOperand is num) {
5277 return leftOperand == rightOperand;
5278 } else if (leftOperand is String && rightOperand is String) {
5279 return leftOperand == rightOperand;
5280 }
5281 } else if (node.operator.type == TokenType.GT) {
5282 // numeric or {@code null}
5283 if (leftOperand is num && rightOperand is num) {
5284 return leftOperand.compareTo(rightOperand) > 0;
5285 }
5286 } else if (node.operator.type == TokenType.GT_EQ) {
5287 // numeric or {@code null}
5288 if (leftOperand is num && rightOperand is num) {
5289 return leftOperand.compareTo(rightOperand) >= 0;
5290 }
5291 } else if (node.operator.type == TokenType.GT_GT) {
5292 // integer or {@code null}
5293 if (leftOperand is int && rightOperand is int) {
5294 return leftOperand >> rightOperand;
5295 }
5296 } else if (node.operator.type == TokenType.LT) {
5297 // numeric or {@code null}
5298 if (leftOperand is num && rightOperand is num) {
5299 return leftOperand.compareTo(rightOperand) < 0;
5300 }
5301 } else if (node.operator.type == TokenType.LT_EQ) {
5302 // numeric or {@code null}
5303 if (leftOperand is num && rightOperand is num) {
5304 return leftOperand.compareTo(rightOperand) <= 0;
5305 }
5306 } else if (node.operator.type == TokenType.LT_LT) {
5307 // integer or {@code null}
5308 if (leftOperand is int && rightOperand is int) {
5309 return leftOperand << rightOperand;
5310 }
5311 } else if (node.operator.type == TokenType.MINUS) {
5312 // numeric or {@code null}
5313 if (leftOperand is num && rightOperand is num) {
5314 return leftOperand - rightOperand;
5315 }
5316 } else if (node.operator.type == TokenType.PERCENT) {
5317 // numeric or {@code null}
5318 if (leftOperand is num && rightOperand is num) {
5319 return leftOperand.remainder(rightOperand);
5320 }
5321 } else if (node.operator.type == TokenType.PLUS) {
5322 // numeric or {@code null}
5323 if (leftOperand is num && rightOperand is num) {
5324 return leftOperand + rightOperand;
5325 }
5326 } else if (node.operator.type == TokenType.STAR) {
5327 // numeric or {@code null}
5328 if (leftOperand is num && rightOperand is num) {
5329 return leftOperand * rightOperand;
5330 }
5331 } else if (node.operator.type == TokenType.SLASH) {
5332 // numeric or {@code null}
5333 if (leftOperand is num && rightOperand is num) {
5334 return leftOperand / rightOperand;
5335 }
5336 } else if (node.operator.type == TokenType.TILDE_SLASH) {
5337 // numeric or {@code null}
5338 if (leftOperand is num && rightOperand is num) {
5339 return leftOperand ~/ rightOperand;
5340 }
5341 } else {}
5342 break;
5343 }
5344 // TODO(brianwilkerson) This doesn't handle numeric conversions.
5345 return visitExpression(node);
5346 }
5347
5348 @override
5349 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
5350
5351 @override
5352 Object visitDoubleLiteral(DoubleLiteral node) => node.value;
5353
5354 @override
5355 Object visitIntegerLiteral(IntegerLiteral node) => node.value;
5356
5357 @override
5358 Object visitInterpolationExpression(InterpolationExpression node) {
5359 Object value = node.expression.accept(this);
5360 if (value == null || value is bool || value is String || value is num) {
5361 return value;
5362 }
5363 return NOT_A_CONSTANT;
5364 }
5365
5366 @override
5367 Object visitInterpolationString(InterpolationString node) => node.value;
5368
5369 @override
5370 Object visitListLiteral(ListLiteral node) {
5371 List<Object> list = new List<Object>();
5372 for (Expression element in node.elements) {
5373 Object value = element.accept(this);
5374 if (identical(value, NOT_A_CONSTANT)) {
5375 return value;
5376 }
5377 list.add(value);
5378 }
5379 return list;
5380 }
5381
5382 @override
5383 Object visitMapLiteral(MapLiteral node) {
5384 HashMap<String, Object> map = new HashMap<String, Object>();
5385 for (MapLiteralEntry entry in node.entries) {
5386 Object key = entry.key.accept(this);
5387 Object value = entry.value.accept(this);
5388 if (key is! String || identical(value, NOT_A_CONSTANT)) {
5389 return NOT_A_CONSTANT;
5390 }
5391 map[(key as String)] = value;
5392 }
5393 return map;
5394 }
5395
5396 @override
5397 Object visitMethodInvocation(MethodInvocation node) => visitNode(node);
5398
5399 @override
5400 Object visitNode(AstNode node) => NOT_A_CONSTANT;
5401
5402 @override
5403 Object visitNullLiteral(NullLiteral node) => null;
5404
5405 @override
5406 Object visitParenthesizedExpression(ParenthesizedExpression node) =>
5407 node.expression.accept(this);
5408
5409 @override
5410 Object visitPrefixedIdentifier(PrefixedIdentifier node) =>
5411 _getConstantValue(null);
5412
5413 @override
5414 Object visitPrefixExpression(PrefixExpression node) {
5415 Object operand = node.operand.accept(this);
5416 if (identical(operand, NOT_A_CONSTANT)) {
5417 return operand;
5418 }
5419 while (true) {
5420 if (node.operator.type == TokenType.BANG) {
5421 if (identical(operand, true)) {
5422 return false;
5423 } else if (identical(operand, false)) {
5424 return true;
5425 }
5426 } else if (node.operator.type == TokenType.TILDE) {
5427 if (operand is int) {
5428 return ~operand;
5429 }
5430 } else if (node.operator.type == TokenType.MINUS) {
5431 if (operand == null) {
5432 return null;
5433 } else if (operand is num) {
5434 return -operand;
5435 }
5436 } else {}
5437 break;
5438 }
5439 return NOT_A_CONSTANT;
5440 }
5441
5442 @override
5443 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null);
5444
5445 @override
5446 Object visitSimpleIdentifier(SimpleIdentifier node) =>
5447 _getConstantValue(null);
5448
5449 @override
5450 Object visitSimpleStringLiteral(SimpleStringLiteral node) => node.value;
5451
5452 @override
5453 Object visitStringInterpolation(StringInterpolation node) {
5454 StringBuffer buffer = new StringBuffer();
5455 for (InterpolationElement element in node.elements) {
5456 Object value = element.accept(this);
5457 if (identical(value, NOT_A_CONSTANT)) {
5458 return value;
5459 }
5460 buffer.write(value);
5461 }
5462 return buffer.toString();
5463 }
5464
5465 @override
5466 Object visitSymbolLiteral(SymbolLiteral node) {
5467 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String.
5468 StringBuffer buffer = new StringBuffer();
5469 for (Token component in node.components) {
5470 if (buffer.length > 0) {
5471 buffer.writeCharCode(0x2E);
5472 }
5473 buffer.write(component.lexeme);
5474 }
5475 return buffer.toString();
5476 }
5477
5478 /**
5479 * Return the constant value of the static constant represented by the given
5480 * [element].
5481 */
5482 Object _getConstantValue(Element element) {
5483 // TODO(brianwilkerson) Implement this
5484 if (element is FieldElement) {
5485 FieldElement field = element;
5486 if (field.isStatic && field.isConst) {
5487 //field.getConstantValue();
5488 }
5489 // } else if (element instanceof VariableElement) {
5490 // VariableElement variable = (VariableElement) element;
5491 // if (variable.isStatic() && variable.isConst()) {
5492 // //variable.getConstantValue();
5493 // }
5494 }
5495 return NOT_A_CONSTANT;
5496 }
5497 }
5498
5499 /** 3125 /**
5500 * A constructor declaration. 3126 * A constructor declaration.
5501 * 3127 *
5502 * > constructorDeclaration ::= 3128 * > constructorDeclaration ::=
5503 * > constructorSignature [FunctionBody]? 3129 * > constructorSignature [FunctionBody]?
5504 * > | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier]) ? arguments 3130 * > | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier]) ? arguments
5505 * > 3131 * >
5506 * > constructorSignature ::= 3132 * > constructorSignature ::=
5507 * > 'external'? constructorName formalParameterList initializerList? 3133 * > 'external'? constructorName formalParameterList initializerList?
5508 * > | 'external'? 'factory' factoryName formalParameterList initializerList? 3134 * > | 'external'? 'factory' factoryName formalParameterList initializerList?
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
6258 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this); 3884 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this);
6259 3885
6260 @override 3886 @override
6261 void visitChildren(AstVisitor visitor) { 3887 void visitChildren(AstVisitor visitor) {
6262 _safelyVisitChild(_parameter, visitor); 3888 _safelyVisitChild(_parameter, visitor);
6263 _safelyVisitChild(_defaultValue, visitor); 3889 _safelyVisitChild(_defaultValue, visitor);
6264 } 3890 }
6265 } 3891 }
6266 3892
6267 /** 3893 /**
6268 * A recursive AST visitor that is used to run over [Expression]s to determine
6269 * whether the expression is composed by at least one deferred
6270 * [PrefixedIdentifier].
6271 *
6272 * See [PrefixedIdentifier.isDeferred].
6273 */
6274 class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<Object> {
6275 /**
6276 * A flag indicating whether an identifier from a deferred library has been
6277 * found.
6278 */
6279 bool _result = false;
6280
6281 /**
6282 * Return `true` if the visitor found a [PrefixedIdentifier] that returned
6283 * `true` to the [PrefixedIdentifier.isDeferred] query.
6284 */
6285 bool get result => _result;
6286
6287 @override
6288 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
6289 if (!_result) {
6290 if (node.isDeferred) {
6291 _result = true;
6292 }
6293 }
6294 return null;
6295 }
6296 }
6297
6298 /**
6299 * A node that represents a directive. 3894 * A node that represents a directive.
6300 * 3895 *
6301 * > directive ::= 3896 * > directive ::=
6302 * > [ExportDirective] 3897 * > [ExportDirective]
6303 * > | [ImportDirective] 3898 * > | [ImportDirective]
6304 * > | [LibraryDirective] 3899 * > | [LibraryDirective]
6305 * > | [PartDirective] 3900 * > | [PartDirective]
6306 * > | [PartOfDirective] 3901 * > | [PartOfDirective]
6307 */ 3902 */
6308 abstract class Directive extends AnnotatedNode { 3903 abstract class Directive extends AnnotatedNode {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
6516 @override 4111 @override
6517 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this); 4112 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this);
6518 4113
6519 @override 4114 @override
6520 void visitChildren(AstVisitor visitor) { 4115 void visitChildren(AstVisitor visitor) {
6521 // There are no children to visit. 4116 // There are no children to visit.
6522 } 4117 }
6523 } 4118 }
6524 4119
6525 /** 4120 /**
6526 * An object used to locate the [Element] associated with a given [AstNode].
6527 */
6528 class ElementLocator {
6529 /**
6530 * Return the element associated with the given [node], or `null` if there is
6531 * no element associated with the node.
6532 */
6533 static Element locate(AstNode node) {
6534 if (node == null) {
6535 return null;
6536 }
6537 ElementLocator_ElementMapper mapper = new ElementLocator_ElementMapper();
6538 return node.accept(mapper);
6539 }
6540 }
6541
6542 /**
6543 * Visitor that maps nodes to elements.
6544 */
6545 class ElementLocator_ElementMapper extends GeneralizingAstVisitor<Element> {
6546 @override
6547 Element visitAnnotation(Annotation node) => node.element;
6548
6549 @override
6550 Element visitAssignmentExpression(AssignmentExpression node) =>
6551 node.bestElement;
6552
6553 @override
6554 Element visitBinaryExpression(BinaryExpression node) => node.bestElement;
6555
6556 @override
6557 Element visitClassDeclaration(ClassDeclaration node) => node.element;
6558
6559 @override
6560 Element visitCompilationUnit(CompilationUnit node) => node.element;
6561
6562 @override
6563 Element visitConstructorDeclaration(ConstructorDeclaration node) =>
6564 node.element;
6565
6566 @override
6567 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element;
6568
6569 @override
6570 Element visitIdentifier(Identifier node) {
6571 AstNode parent = node.parent;
6572 // Type name in Annotation
6573 if (parent is Annotation) {
6574 Annotation annotation = parent;
6575 if (identical(annotation.name, node) &&
6576 annotation.constructorName == null) {
6577 return annotation.element;
6578 }
6579 }
6580 // Extra work to map Constructor Declarations to their associated
6581 // Constructor Elements
6582 if (parent is ConstructorDeclaration) {
6583 ConstructorDeclaration decl = parent;
6584 Identifier returnType = decl.returnType;
6585 if (identical(returnType, node)) {
6586 SimpleIdentifier name = decl.name;
6587 if (name != null) {
6588 return name.bestElement;
6589 }
6590 Element element = node.bestElement;
6591 if (element is ClassElement) {
6592 return element.unnamedConstructor;
6593 }
6594 }
6595 }
6596 if (parent is LibraryIdentifier) {
6597 AstNode grandParent = parent.parent;
6598 if (grandParent is PartOfDirective) {
6599 Element element = grandParent.element;
6600 if (element is LibraryElement) {
6601 return element.definingCompilationUnit;
6602 }
6603 }
6604 }
6605 return node.bestElement;
6606 }
6607
6608 @override
6609 Element visitImportDirective(ImportDirective node) => node.element;
6610
6611 @override
6612 Element visitIndexExpression(IndexExpression node) => node.bestElement;
6613
6614 @override
6615 Element visitInstanceCreationExpression(InstanceCreationExpression node) =>
6616 node.staticElement;
6617
6618 @override
6619 Element visitLibraryDirective(LibraryDirective node) => node.element;
6620
6621 @override
6622 Element visitMethodDeclaration(MethodDeclaration node) => node.element;
6623
6624 @override
6625 Element visitMethodInvocation(MethodInvocation node) =>
6626 node.methodName.bestElement;
6627
6628 @override
6629 Element visitPartOfDirective(PartOfDirective node) => node.element;
6630
6631 @override
6632 Element visitPostfixExpression(PostfixExpression node) => node.bestElement;
6633
6634 @override
6635 Element visitPrefixedIdentifier(PrefixedIdentifier node) => node.bestElement;
6636
6637 @override
6638 Element visitPrefixExpression(PrefixExpression node) => node.bestElement;
6639
6640 @override
6641 Element visitStringLiteral(StringLiteral node) {
6642 AstNode parent = node.parent;
6643 if (parent is UriBasedDirective) {
6644 return parent.uriElement;
6645 }
6646 return null;
6647 }
6648
6649 @override
6650 Element visitVariableDeclaration(VariableDeclaration node) => node.element;
6651 }
6652
6653 /**
6654 * An empty function body, which can only appear in constructors or abstract 4121 * An empty function body, which can only appear in constructors or abstract
6655 * methods. 4122 * methods.
6656 * 4123 *
6657 * > emptyFunctionBody ::= 4124 * > emptyFunctionBody ::=
6658 * > ';' 4125 * > ';'
6659 */ 4126 */
6660 class EmptyFunctionBody extends FunctionBody { 4127 class EmptyFunctionBody extends FunctionBody {
6661 /** 4128 /**
6662 * The token representing the semicolon that marks the end of the function 4129 * The token representing the semicolon that marks the end of the function
6663 * body. 4130 * body.
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
8373 _safelyVisitChild(_body, visitor); 5840 _safelyVisitChild(_body, visitor);
8374 } 5841 }
8375 } 5842 }
8376 5843
8377 /** 5844 /**
8378 * The invocation of a function resulting from evaluating an expression. 5845 * The invocation of a function resulting from evaluating an expression.
8379 * Invocations of methods and other forms of functions are represented by 5846 * Invocations of methods and other forms of functions are represented by
8380 * [MethodInvocation] nodes. Invocations of getters and setters are represented 5847 * [MethodInvocation] nodes. Invocations of getters and setters are represented
8381 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. 5848 * by either [PrefixedIdentifier] or [PropertyAccess] nodes.
8382 * 5849 *
8383 * > functionExpressionInvoction ::= 5850 * > functionExpressionInvocation ::=
8384 * > [Expression] [TypeArgumentList]? [ArgumentList] 5851 * > [Expression] [TypeArgumentList]? [ArgumentList]
8385 */ 5852 */
8386 class FunctionExpressionInvocation extends Expression { 5853 class FunctionExpressionInvocation extends Expression {
8387 /** 5854 /**
8388 * The expression producing the function being invoked. 5855 * The expression producing the function being invoked.
8389 */ 5856 */
8390 Expression _function; 5857 Expression _function;
8391 5858
8392 /** 5859 /**
8393 * The type arguments to be applied to the method being invoked, or `null` if 5860 * The type arguments to be applied to the method being invoked, or `null` if
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
8729 void visitChildren(AstVisitor visitor) { 6196 void visitChildren(AstVisitor visitor) {
8730 super.visitChildren(visitor); 6197 super.visitChildren(visitor);
8731 _safelyVisitChild(_returnType, visitor); 6198 _safelyVisitChild(_returnType, visitor);
8732 _safelyVisitChild(identifier, visitor); 6199 _safelyVisitChild(identifier, visitor);
8733 _safelyVisitChild(_typeParameters, visitor); 6200 _safelyVisitChild(_typeParameters, visitor);
8734 _safelyVisitChild(_parameters, visitor); 6201 _safelyVisitChild(_parameters, visitor);
8735 } 6202 }
8736 } 6203 }
8737 6204
8738 /** 6205 /**
8739 * An AST visitor that will recursively visit all of the nodes in an AST
8740 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
8741 * when a node of a specific type is visited not only will the visit method for
8742 * that specific type of node be invoked, but additional methods for the
8743 * superclasses of that node will also be invoked. For example, using an
8744 * instance of this class to visit a [Block] will cause the method [visitBlock]
8745 * to be invoked but will also cause the methods [visitStatement] and
8746 * [visitNode] to be subsequently invoked. This allows visitors to be written
8747 * that visit all statements without needing to override the visit method for
8748 * each of the specific subclasses of [Statement].
8749 *
8750 * Subclasses that override a visit method must either invoke the overridden
8751 * visit method or explicitly invoke the more general visit method. Failure to
8752 * do so will cause the visit methods for superclasses of the node to not be
8753 * invoked and will cause the children of the visited node to not be visited.
8754 */
8755 class GeneralizingAstVisitor<R> implements AstVisitor<R> {
8756 @override
8757 R visitAdjacentStrings(AdjacentStrings node) => visitStringLiteral(node);
8758
8759 R visitAnnotatedNode(AnnotatedNode node) => visitNode(node);
8760
8761 @override
8762 R visitAnnotation(Annotation node) => visitNode(node);
8763
8764 @override
8765 R visitArgumentList(ArgumentList node) => visitNode(node);
8766
8767 @override
8768 R visitAsExpression(AsExpression node) => visitExpression(node);
8769
8770 @override
8771 R visitAssertStatement(AssertStatement node) => visitStatement(node);
8772
8773 @override
8774 R visitAssignmentExpression(AssignmentExpression node) =>
8775 visitExpression(node);
8776
8777 @override
8778 R visitAwaitExpression(AwaitExpression node) => visitExpression(node);
8779
8780 @override
8781 R visitBinaryExpression(BinaryExpression node) => visitExpression(node);
8782
8783 @override
8784 R visitBlock(Block node) => visitStatement(node);
8785
8786 @override
8787 R visitBlockFunctionBody(BlockFunctionBody node) => visitFunctionBody(node);
8788
8789 @override
8790 R visitBooleanLiteral(BooleanLiteral node) => visitLiteral(node);
8791
8792 @override
8793 R visitBreakStatement(BreakStatement node) => visitStatement(node);
8794
8795 @override
8796 R visitCascadeExpression(CascadeExpression node) => visitExpression(node);
8797
8798 @override
8799 R visitCatchClause(CatchClause node) => visitNode(node);
8800
8801 @override
8802 R visitClassDeclaration(ClassDeclaration node) =>
8803 visitNamedCompilationUnitMember(node);
8804
8805 R visitClassMember(ClassMember node) => visitDeclaration(node);
8806
8807 @override
8808 R visitClassTypeAlias(ClassTypeAlias node) => visitTypeAlias(node);
8809
8810 R visitCombinator(Combinator node) => visitNode(node);
8811
8812 @override
8813 R visitComment(Comment node) => visitNode(node);
8814
8815 @override
8816 R visitCommentReference(CommentReference node) => visitNode(node);
8817
8818 @override
8819 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
8820
8821 R visitCompilationUnitMember(CompilationUnitMember node) =>
8822 visitDeclaration(node);
8823
8824 @override
8825 R visitConditionalExpression(ConditionalExpression node) =>
8826 visitExpression(node);
8827
8828 @override
8829 R visitConfiguration(Configuration node) => visitNode(node);
8830
8831 @override
8832 R visitConstructorDeclaration(ConstructorDeclaration node) =>
8833 visitClassMember(node);
8834
8835 @override
8836 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
8837 visitConstructorInitializer(node);
8838
8839 R visitConstructorInitializer(ConstructorInitializer node) => visitNode(node);
8840
8841 @override
8842 R visitConstructorName(ConstructorName node) => visitNode(node);
8843
8844 @override
8845 R visitContinueStatement(ContinueStatement node) => visitStatement(node);
8846
8847 R visitDeclaration(Declaration node) => visitAnnotatedNode(node);
8848
8849 @override
8850 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitDeclaration(node);
8851
8852 @override
8853 R visitDefaultFormalParameter(DefaultFormalParameter node) =>
8854 visitFormalParameter(node);
8855
8856 R visitDirective(Directive node) => visitAnnotatedNode(node);
8857
8858 @override
8859 R visitDoStatement(DoStatement node) => visitStatement(node);
8860
8861 @override
8862 R visitDottedName(DottedName node) => visitNode(node);
8863
8864 @override
8865 R visitDoubleLiteral(DoubleLiteral node) => visitLiteral(node);
8866
8867 @override
8868 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitFunctionBody(node);
8869
8870 @override
8871 R visitEmptyStatement(EmptyStatement node) => visitStatement(node);
8872
8873 @override
8874 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
8875 visitDeclaration(node);
8876
8877 @override
8878 R visitEnumDeclaration(EnumDeclaration node) =>
8879 visitNamedCompilationUnitMember(node);
8880
8881 @override
8882 R visitExportDirective(ExportDirective node) => visitNamespaceDirective(node);
8883
8884 R visitExpression(Expression node) => visitNode(node);
8885
8886 @override
8887 R visitExpressionFunctionBody(ExpressionFunctionBody node) =>
8888 visitFunctionBody(node);
8889
8890 @override
8891 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node);
8892
8893 @override
8894 R visitExtendsClause(ExtendsClause node) => visitNode(node);
8895
8896 @override
8897 R visitFieldDeclaration(FieldDeclaration node) => visitClassMember(node);
8898
8899 @override
8900 R visitFieldFormalParameter(FieldFormalParameter node) =>
8901 visitNormalFormalParameter(node);
8902
8903 @override
8904 R visitForEachStatement(ForEachStatement node) => visitStatement(node);
8905
8906 R visitFormalParameter(FormalParameter node) => visitNode(node);
8907
8908 @override
8909 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
8910
8911 @override
8912 R visitForStatement(ForStatement node) => visitStatement(node);
8913
8914 R visitFunctionBody(FunctionBody node) => visitNode(node);
8915
8916 @override
8917 R visitFunctionDeclaration(FunctionDeclaration node) =>
8918 visitNamedCompilationUnitMember(node);
8919
8920 @override
8921 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
8922 visitStatement(node);
8923
8924 @override
8925 R visitFunctionExpression(FunctionExpression node) => visitExpression(node);
8926
8927 @override
8928 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
8929 visitExpression(node);
8930
8931 @override
8932 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitTypeAlias(node);
8933
8934 @override
8935 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
8936 visitNormalFormalParameter(node);
8937
8938 @override
8939 R visitHideCombinator(HideCombinator node) => visitCombinator(node);
8940
8941 R visitIdentifier(Identifier node) => visitExpression(node);
8942
8943 @override
8944 R visitIfStatement(IfStatement node) => visitStatement(node);
8945
8946 @override
8947 R visitImplementsClause(ImplementsClause node) => visitNode(node);
8948
8949 @override
8950 R visitImportDirective(ImportDirective node) => visitNamespaceDirective(node);
8951
8952 @override
8953 R visitIndexExpression(IndexExpression node) => visitExpression(node);
8954
8955 @override
8956 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
8957 visitExpression(node);
8958
8959 @override
8960 R visitIntegerLiteral(IntegerLiteral node) => visitLiteral(node);
8961
8962 R visitInterpolationElement(InterpolationElement node) => visitNode(node);
8963
8964 @override
8965 R visitInterpolationExpression(InterpolationExpression node) =>
8966 visitInterpolationElement(node);
8967
8968 @override
8969 R visitInterpolationString(InterpolationString node) =>
8970 visitInterpolationElement(node);
8971
8972 @override
8973 R visitIsExpression(IsExpression node) => visitExpression(node);
8974
8975 @override
8976 R visitLabel(Label node) => visitNode(node);
8977
8978 @override
8979 R visitLabeledStatement(LabeledStatement node) => visitStatement(node);
8980
8981 @override
8982 R visitLibraryDirective(LibraryDirective node) => visitDirective(node);
8983
8984 @override
8985 R visitLibraryIdentifier(LibraryIdentifier node) => visitIdentifier(node);
8986
8987 @override
8988 R visitListLiteral(ListLiteral node) => visitTypedLiteral(node);
8989
8990 R visitLiteral(Literal node) => visitExpression(node);
8991
8992 @override
8993 R visitMapLiteral(MapLiteral node) => visitTypedLiteral(node);
8994
8995 @override
8996 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
8997
8998 @override
8999 R visitMethodDeclaration(MethodDeclaration node) => visitClassMember(node);
9000
9001 @override
9002 R visitMethodInvocation(MethodInvocation node) => visitExpression(node);
9003
9004 R visitNamedCompilationUnitMember(NamedCompilationUnitMember node) =>
9005 visitCompilationUnitMember(node);
9006
9007 @override
9008 R visitNamedExpression(NamedExpression node) => visitExpression(node);
9009
9010 R visitNamespaceDirective(NamespaceDirective node) =>
9011 visitUriBasedDirective(node);
9012
9013 @override
9014 R visitNativeClause(NativeClause node) => visitNode(node);
9015
9016 @override
9017 R visitNativeFunctionBody(NativeFunctionBody node) => visitFunctionBody(node);
9018
9019 R visitNode(AstNode node) {
9020 node.visitChildren(this);
9021 return null;
9022 }
9023
9024 R visitNormalFormalParameter(NormalFormalParameter node) =>
9025 visitFormalParameter(node);
9026
9027 @override
9028 R visitNullLiteral(NullLiteral node) => visitLiteral(node);
9029
9030 @override
9031 R visitParenthesizedExpression(ParenthesizedExpression node) =>
9032 visitExpression(node);
9033
9034 @override
9035 R visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
9036
9037 @override
9038 R visitPartOfDirective(PartOfDirective node) => visitDirective(node);
9039
9040 @override
9041 R visitPostfixExpression(PostfixExpression node) => visitExpression(node);
9042
9043 @override
9044 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitIdentifier(node);
9045
9046 @override
9047 R visitPrefixExpression(PrefixExpression node) => visitExpression(node);
9048
9049 @override
9050 R visitPropertyAccess(PropertyAccess node) => visitExpression(node);
9051
9052 @override
9053 R visitRedirectingConstructorInvocation(
9054 RedirectingConstructorInvocation node) =>
9055 visitConstructorInitializer(node);
9056
9057 @override
9058 R visitRethrowExpression(RethrowExpression node) => visitExpression(node);
9059
9060 @override
9061 R visitReturnStatement(ReturnStatement node) => visitStatement(node);
9062
9063 @override
9064 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
9065
9066 @override
9067 R visitShowCombinator(ShowCombinator node) => visitCombinator(node);
9068
9069 @override
9070 R visitSimpleFormalParameter(SimpleFormalParameter node) =>
9071 visitNormalFormalParameter(node);
9072
9073 @override
9074 R visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node);
9075
9076 @override
9077 R visitSimpleStringLiteral(SimpleStringLiteral node) =>
9078 visitSingleStringLiteral(node);
9079
9080 R visitSingleStringLiteral(SingleStringLiteral node) =>
9081 visitStringLiteral(node);
9082
9083 R visitStatement(Statement node) => visitNode(node);
9084
9085 @override
9086 R visitStringInterpolation(StringInterpolation node) =>
9087 visitSingleStringLiteral(node);
9088
9089 R visitStringLiteral(StringLiteral node) => visitLiteral(node);
9090
9091 @override
9092 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
9093 visitConstructorInitializer(node);
9094
9095 @override
9096 R visitSuperExpression(SuperExpression node) => visitExpression(node);
9097
9098 @override
9099 R visitSwitchCase(SwitchCase node) => visitSwitchMember(node);
9100
9101 @override
9102 R visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
9103
9104 R visitSwitchMember(SwitchMember node) => visitNode(node);
9105
9106 @override
9107 R visitSwitchStatement(SwitchStatement node) => visitStatement(node);
9108
9109 @override
9110 R visitSymbolLiteral(SymbolLiteral node) => visitLiteral(node);
9111
9112 @override
9113 R visitThisExpression(ThisExpression node) => visitExpression(node);
9114
9115 @override
9116 R visitThrowExpression(ThrowExpression node) => visitExpression(node);
9117
9118 @override
9119 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
9120 visitCompilationUnitMember(node);
9121
9122 @override
9123 R visitTryStatement(TryStatement node) => visitStatement(node);
9124
9125 R visitTypeAlias(TypeAlias node) => visitNamedCompilationUnitMember(node);
9126
9127 @override
9128 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
9129
9130 R visitTypedLiteral(TypedLiteral node) => visitLiteral(node);
9131
9132 @override
9133 R visitTypeName(TypeName node) => visitNode(node);
9134
9135 @override
9136 R visitTypeParameter(TypeParameter node) => visitNode(node);
9137
9138 @override
9139 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
9140
9141 R visitUriBasedDirective(UriBasedDirective node) => visitDirective(node);
9142
9143 @override
9144 R visitVariableDeclaration(VariableDeclaration node) =>
9145 visitDeclaration(node);
9146
9147 @override
9148 R visitVariableDeclarationList(VariableDeclarationList node) =>
9149 visitNode(node);
9150
9151 @override
9152 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
9153 visitStatement(node);
9154
9155 @override
9156 R visitWhileStatement(WhileStatement node) => visitStatement(node);
9157
9158 @override
9159 R visitWithClause(WithClause node) => visitNode(node);
9160
9161 @override
9162 R visitYieldStatement(YieldStatement node) => visitStatement(node);
9163 }
9164
9165 class GeneralizingAstVisitor_BreadthFirstVisitor
9166 extends GeneralizingAstVisitor<Object> {
9167 final BreadthFirstVisitor BreadthFirstVisitor_this;
9168
9169 GeneralizingAstVisitor_BreadthFirstVisitor(this.BreadthFirstVisitor_this)
9170 : super();
9171
9172 @override
9173 Object visitNode(AstNode node) {
9174 BreadthFirstVisitor_this._queue.add(node);
9175 return null;
9176 }
9177 }
9178
9179 /**
9180 * A combinator that restricts the names being imported to those that are not in 6206 * A combinator that restricts the names being imported to those that are not in
9181 * a given list. 6207 * a given list.
9182 * 6208 *
9183 * > hideCombinator ::= 6209 * > hideCombinator ::=
9184 * > 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])* 6210 * > 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])*
9185 */ 6211 */
9186 class HideCombinator extends Combinator { 6212 class HideCombinator extends Combinator {
9187 /** 6213 /**
9188 * The list of names from the library that are hidden by this combinator. 6214 * The list of names from the library that are hidden by this combinator.
9189 */ 6215 */
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
9286 */ 6312 */
9287 Token leftParenthesis; 6313 Token leftParenthesis;
9288 6314
9289 /** 6315 /**
9290 * The condition used to determine which of the statements is executed next. 6316 * The condition used to determine which of the statements is executed next.
9291 */ 6317 */
9292 Expression _condition; 6318 Expression _condition;
9293 6319
9294 /** 6320 /**
9295 * The right parenthesis. 6321 * The right parenthesis.
9296 */
9297 Token rightParenthesis;
9298
9299 /**
9300 * The statement that is executed if the condition evaluates to `true`.
9301 */
9302 Statement _thenStatement;
9303
9304 /**
9305 * The token representing the 'else' keyword, or `null` if there is no else
9306 * statement.
9307 */
9308 Token elseKeyword;
9309
9310 /**
9311 * The statement that is executed if the condition evaluates to `false`, or
9312 * `null` if there is no else statement.
9313 */
9314 Statement _elseStatement;
9315
9316 /**
9317 * Initialize a newly created if statement. The [elseKeyword] and
9318 * [elseStatement] can be `null` if there is no else clause.
9319 */
9320 IfStatement(
9321 this.ifKeyword,
9322 this.leftParenthesis,
9323 Expression condition,
9324 this.rightParenthesis,
9325 Statement thenStatement,
9326 this.elseKeyword,
9327 Statement elseStatement) {
9328 _condition = _becomeParentOf(condition);
9329 _thenStatement = _becomeParentOf(thenStatement);
9330 _elseStatement = _becomeParentOf(elseStatement);
9331 }
9332
9333 @override
9334 Token get beginToken => ifKeyword;
9335
9336 @override
9337 Iterable get childEntities => new ChildEntities()
9338 ..add(ifKeyword)
9339 ..add(leftParenthesis)
9340 ..add(_condition)
9341 ..add(rightParenthesis)
9342 ..add(_thenStatement)
9343 ..add(elseKeyword)
9344 ..add(_elseStatement);
9345
9346 /**
9347 * Return the condition used to determine which of the statements is executed
9348 * next.
9349 */
9350 Expression get condition => _condition;
9351
9352 /**
9353 * Set the condition used to determine which of the statements is executed
9354 * next to the given [expression].
9355 */
9356 void set condition(Expression expression) {
9357 _condition = _becomeParentOf(expression);
9358 }
9359
9360 /**
9361 * Return the statement that is executed if the condition evaluates to
9362 * `false`, or `null` if there is no else statement.
9363 */
9364 Statement get elseStatement => _elseStatement;
9365
9366 /**
9367 * Set the statement that is executed if the condition evaluates to `false`
9368 * to the given [statement].
9369 */
9370 void set elseStatement(Statement statement) {
9371 _elseStatement = _becomeParentOf(statement);
9372 }
9373
9374 @override
9375 Token get endToken {
9376 if (_elseStatement != null) {
9377 return _elseStatement.endToken;
9378 }
9379 return _thenStatement.endToken;
9380 }
9381
9382 /**
9383 * Return the statement that is executed if the condition evaluates to `true`.
9384 */
9385 Statement get thenStatement => _thenStatement;
9386
9387 /**
9388 * Set the statement that is executed if the condition evaluates to `true` to
9389 * the given [statement].
9390 */
9391 void set thenStatement(Statement statement) {
9392 _thenStatement = _becomeParentOf(statement);
9393 }
9394
9395 @override
9396 accept(AstVisitor visitor) => visitor.visitIfStatement(this);
9397
9398 @override
9399 void visitChildren(AstVisitor visitor) {
9400 _safelyVisitChild(_condition, visitor);
9401 _safelyVisitChild(_thenStatement, visitor);
9402 _safelyVisitChild(_elseStatement, visitor);
9403 }
9404 }
9405
9406 /**
9407 * The "implements" clause in an class declaration.
9408 *
9409 * > implementsClause ::=
9410 * > 'implements' [TypeName] (',' [TypeName])*
9411 */
9412 class ImplementsClause extends AstNode {
9413 /**
9414 * The token representing the 'implements' keyword.
9415 */
9416 Token implementsKeyword;
9417
9418 /**
9419 * The interfaces that are being implemented.
9420 */
9421 NodeList<TypeName> _interfaces;
9422
9423 /**
9424 * Initialize a newly created implements clause.
9425 */
9426 ImplementsClause(this.implementsKeyword, List<TypeName> interfaces) {
9427 _interfaces = new NodeList<TypeName>(this, interfaces);
9428 }
9429
9430 @override
9431 Token get beginToken => implementsKeyword;
9432
9433 @override
9434 // TODO(paulberry): add commas.
9435 Iterable get childEntities => new ChildEntities()
9436 ..add(implementsKeyword)
9437 ..addAll(interfaces);
9438
9439 @override
9440 Token get endToken => _interfaces.endToken;
9441
9442 /**
9443 * Return the list of the interfaces that are being implemented.
9444 */
9445 NodeList<TypeName> get interfaces => _interfaces;
9446
9447 @override
9448 accept(AstVisitor visitor) => visitor.visitImplementsClause(this);
9449
9450 @override
9451 void visitChildren(AstVisitor visitor) {
9452 _interfaces.accept(visitor);
9453 }
9454 }
9455
9456 /**
9457 * An import directive.
9458 *
9459 * > importDirective ::=
9460 * > [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* ';'
9461 * > | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combi nator]* ';'
9462 */
9463 class ImportDirective extends NamespaceDirective {
9464 static Comparator<ImportDirective> COMPARATOR =
9465 (ImportDirective import1, ImportDirective import2) {
9466 //
9467 // uri
9468 //
9469 StringLiteral uri1 = import1.uri;
9470 StringLiteral uri2 = import2.uri;
9471 String uriStr1 = uri1.stringValue;
9472 String uriStr2 = uri2.stringValue;
9473 if (uriStr1 != null || uriStr2 != null) {
9474 if (uriStr1 == null) {
9475 return -1;
9476 } else if (uriStr2 == null) {
9477 return 1;
9478 } else {
9479 int compare = uriStr1.compareTo(uriStr2);
9480 if (compare != 0) {
9481 return compare;
9482 }
9483 }
9484 }
9485 //
9486 // as
9487 //
9488 SimpleIdentifier prefix1 = import1.prefix;
9489 SimpleIdentifier prefix2 = import2.prefix;
9490 String prefixStr1 = prefix1 != null ? prefix1.name : null;
9491 String prefixStr2 = prefix2 != null ? prefix2.name : null;
9492 if (prefixStr1 != null || prefixStr2 != null) {
9493 if (prefixStr1 == null) {
9494 return -1;
9495 } else if (prefixStr2 == null) {
9496 return 1;
9497 } else {
9498 int compare = prefixStr1.compareTo(prefixStr2);
9499 if (compare != 0) {
9500 return compare;
9501 }
9502 }
9503 }
9504 //
9505 // hides and shows
9506 //
9507 NodeList<Combinator> combinators1 = import1.combinators;
9508 List<String> allHides1 = new List<String>();
9509 List<String> allShows1 = new List<String>();
9510 for (Combinator combinator in combinators1) {
9511 if (combinator is HideCombinator) {
9512 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9513 for (SimpleIdentifier simpleIdentifier in hides) {
9514 allHides1.add(simpleIdentifier.name);
9515 }
9516 } else {
9517 NodeList<SimpleIdentifier> shows =
9518 (combinator as ShowCombinator).shownNames;
9519 for (SimpleIdentifier simpleIdentifier in shows) {
9520 allShows1.add(simpleIdentifier.name);
9521 }
9522 }
9523 }
9524 NodeList<Combinator> combinators2 = import2.combinators;
9525 List<String> allHides2 = new List<String>();
9526 List<String> allShows2 = new List<String>();
9527 for (Combinator combinator in combinators2) {
9528 if (combinator is HideCombinator) {
9529 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9530 for (SimpleIdentifier simpleIdentifier in hides) {
9531 allHides2.add(simpleIdentifier.name);
9532 }
9533 } else {
9534 NodeList<SimpleIdentifier> shows =
9535 (combinator as ShowCombinator).shownNames;
9536 for (SimpleIdentifier simpleIdentifier in shows) {
9537 allShows2.add(simpleIdentifier.name);
9538 }
9539 }
9540 }
9541 // test lengths of combinator lists first
9542 if (allHides1.length != allHides2.length) {
9543 return allHides1.length - allHides2.length;
9544 }
9545 if (allShows1.length != allShows2.length) {
9546 return allShows1.length - allShows2.length;
9547 }
9548 // next ensure that the lists are equivalent
9549 if (!javaCollectionContainsAll(allHides1, allHides2)) {
9550 return -1;
9551 }
9552 if (!javaCollectionContainsAll(allShows1, allShows2)) {
9553 return -1;
9554 }
9555 return 0;
9556 };
9557
9558 /**
9559 * The token representing the 'deferred' keyword, or `null` if the imported is
9560 * not deferred.
9561 */
9562 Token deferredKeyword;
9563
9564 /**
9565 * The token representing the 'as' keyword, or `null` if the imported names ar e
9566 * not prefixed.
9567 */
9568 Token asKeyword;
9569
9570 /**
9571 * The prefix to be used with the imported names, or `null` if the imported
9572 * names are not prefixed.
9573 */
9574 SimpleIdentifier _prefix;
9575
9576 /**
9577 * Initialize a newly created import directive. Either or both of the
9578 * [comment] and [metadata] can be `null` if the function does not have the
9579 * corresponding attribute. The [deferredKeyword] can be `null` if the import
9580 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import
9581 * does not specify a prefix. The list of [combinators] can be `null` if there
9582 * are no combinators.
9583 */
9584 ImportDirective(
9585 Comment comment,
9586 List<Annotation> metadata,
9587 Token keyword,
9588 StringLiteral libraryUri,
9589 List<Configuration> configurations,
9590 this.deferredKeyword,
9591 this.asKeyword,
9592 SimpleIdentifier prefix,
9593 List<Combinator> combinators,
9594 Token semicolon)
9595 : super(comment, metadata, keyword, libraryUri, configurations,
9596 combinators, semicolon) {
9597 _prefix = _becomeParentOf(prefix);
9598 }
9599
9600 @override
9601 Iterable get childEntities => super._childEntities
9602 ..add(_uri)
9603 ..add(deferredKeyword)
9604 ..add(asKeyword)
9605 ..add(_prefix)
9606 ..addAll(combinators)
9607 ..add(semicolon);
9608
9609 @override
9610 ImportElement get element => super.element as ImportElement;
9611
9612 /**
9613 * Return the prefix to be used with the imported names, or `null` if the
9614 * imported names are not prefixed.
9615 */
9616 SimpleIdentifier get prefix => _prefix;
9617
9618 /**
9619 * Set the prefix to be used with the imported names to the given [identifier] .
9620 */
9621 void set prefix(SimpleIdentifier identifier) {
9622 _prefix = _becomeParentOf(identifier);
9623 }
9624
9625 @override
9626 LibraryElement get uriElement {
9627 ImportElement element = this.element;
9628 if (element == null) {
9629 return null;
9630 }
9631 return element.importedLibrary;
9632 }
9633
9634 @override
9635 accept(AstVisitor visitor) => visitor.visitImportDirective(this);
9636
9637 @override
9638 void visitChildren(AstVisitor visitor) {
9639 super.visitChildren(visitor);
9640 _safelyVisitChild(_prefix, visitor);
9641 combinators.accept(visitor);
9642 }
9643 }
9644
9645 /**
9646 * An object that will clone any AST structure that it visits. The cloner will
9647 * clone the structure, replacing the specified ASTNode with a new ASTNode,
9648 * mapping the old token stream to a new token stream, and preserving resolution
9649 * results.
9650 */
9651 class IncrementalAstCloner implements AstVisitor<AstNode> {
9652 /**
9653 * The node to be replaced during the cloning process.
9654 */
9655 final AstNode _oldNode;
9656
9657 /**
9658 * The replacement node used during the cloning process.
9659 */
9660 final AstNode _newNode;
9661
9662 /**
9663 * A mapping of old tokens to new tokens used during the cloning process.
9664 */
9665 final TokenMap _tokenMap;
9666
9667 /**
9668 * Construct a new instance that will replace the [oldNode] with the [newNode]
9669 * in the process of cloning an existing AST structure. The [tokenMap] is a
9670 * mapping of old tokens to new tokens.
9671 */
9672 IncrementalAstCloner(this._oldNode, this._newNode, this._tokenMap);
9673
9674 @override
9675 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
9676 new AdjacentStrings(_cloneNodeList(node.strings));
9677
9678 @override
9679 Annotation visitAnnotation(Annotation node) {
9680 Annotation copy = new Annotation(
9681 _mapToken(node.atSign),
9682 _cloneNode(node.name),
9683 _mapToken(node.period),
9684 _cloneNode(node.constructorName),
9685 _cloneNode(node.arguments));
9686 copy.element = node.element;
9687 return copy;
9688 }
9689
9690 @override
9691 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
9692 _mapToken(node.leftParenthesis),
9693 _cloneNodeList(node.arguments),
9694 _mapToken(node.rightParenthesis));
9695
9696 @override
9697 AsExpression visitAsExpression(AsExpression node) {
9698 AsExpression copy = new AsExpression(_cloneNode(node.expression),
9699 _mapToken(node.asOperator), _cloneNode(node.type));
9700 copy.propagatedType = node.propagatedType;
9701 copy.staticType = node.staticType;
9702 return copy;
9703 }
9704
9705 @override
9706 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
9707 _mapToken(node.assertKeyword),
9708 _mapToken(node.leftParenthesis),
9709 _cloneNode(node.condition),
9710 _mapToken(node.comma),
9711 _cloneNode(node.message),
9712 _mapToken(node.rightParenthesis),
9713 _mapToken(node.semicolon));
9714
9715 @override
9716 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) {
9717 AssignmentExpression copy = new AssignmentExpression(
9718 _cloneNode(node.leftHandSide),
9719 _mapToken(node.operator),
9720 _cloneNode(node.rightHandSide));
9721 copy.propagatedElement = node.propagatedElement;
9722 copy.propagatedType = node.propagatedType;
9723 copy.staticElement = node.staticElement;
9724 copy.staticType = node.staticType;
9725 return copy;
9726 }
9727
9728 @override
9729 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
9730 new AwaitExpression(
9731 _mapToken(node.awaitKeyword), _cloneNode(node.expression));
9732
9733 @override
9734 BinaryExpression visitBinaryExpression(BinaryExpression node) {
9735 BinaryExpression copy = new BinaryExpression(_cloneNode(node.leftOperand),
9736 _mapToken(node.operator), _cloneNode(node.rightOperand));
9737 copy.propagatedElement = node.propagatedElement;
9738 copy.propagatedType = node.propagatedType;
9739 copy.staticElement = node.staticElement;
9740 copy.staticType = node.staticType;
9741 return copy;
9742 }
9743
9744 @override
9745 Block visitBlock(Block node) => new Block(_mapToken(node.leftBracket),
9746 _cloneNodeList(node.statements), _mapToken(node.rightBracket));
9747
9748 @override
9749 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) =>
9750 new BlockFunctionBody(_mapToken(node.keyword), _mapToken(node.star),
9751 _cloneNode(node.block));
9752
9753 @override
9754 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) {
9755 BooleanLiteral copy =
9756 new BooleanLiteral(_mapToken(node.literal), node.value);
9757 copy.propagatedType = node.propagatedType;
9758 copy.staticType = node.staticType;
9759 return copy;
9760 }
9761
9762 @override
9763 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
9764 _mapToken(node.breakKeyword),
9765 _cloneNode(node.label),
9766 _mapToken(node.semicolon));
9767
9768 @override
9769 CascadeExpression visitCascadeExpression(CascadeExpression node) {
9770 CascadeExpression copy = new CascadeExpression(
9771 _cloneNode(node.target), _cloneNodeList(node.cascadeSections));
9772 copy.propagatedType = node.propagatedType;
9773 copy.staticType = node.staticType;
9774 return copy;
9775 }
9776
9777 @override
9778 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
9779 _mapToken(node.onKeyword),
9780 _cloneNode(node.exceptionType),
9781 _mapToken(node.catchKeyword),
9782 _mapToken(node.leftParenthesis),
9783 _cloneNode(node.exceptionParameter),
9784 _mapToken(node.comma),
9785 _cloneNode(node.stackTraceParameter),
9786 _mapToken(node.rightParenthesis),
9787 _cloneNode(node.body));
9788
9789 @override
9790 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
9791 ClassDeclaration copy = new ClassDeclaration(
9792 _cloneNode(node.documentationComment),
9793 _cloneNodeList(node.metadata),
9794 _mapToken(node.abstractKeyword),
9795 _mapToken(node.classKeyword),
9796 _cloneNode(node.name),
9797 _cloneNode(node.typeParameters),
9798 _cloneNode(node.extendsClause),
9799 _cloneNode(node.withClause),
9800 _cloneNode(node.implementsClause),
9801 _mapToken(node.leftBracket),
9802 _cloneNodeList(node.members),
9803 _mapToken(node.rightBracket));
9804 copy.nativeClause = _cloneNode(node.nativeClause);
9805 return copy;
9806 }
9807
9808 @override
9809 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
9810 _cloneNode(node.documentationComment),
9811 _cloneNodeList(node.metadata),
9812 _mapToken(node.typedefKeyword),
9813 _cloneNode(node.name),
9814 _cloneNode(node.typeParameters),
9815 _mapToken(node.equals),
9816 _mapToken(node.abstractKeyword),
9817 _cloneNode(node.superclass),
9818 _cloneNode(node.withClause),
9819 _cloneNode(node.implementsClause),
9820 _mapToken(node.semicolon));
9821
9822 @override
9823 Comment visitComment(Comment node) {
9824 if (node.isDocumentation) {
9825 return Comment.createDocumentationCommentWithReferences(
9826 _mapTokens(node.tokens), _cloneNodeList(node.references));
9827 } else if (node.isBlock) {
9828 return Comment.createBlockComment(_mapTokens(node.tokens));
9829 }
9830 return Comment.createEndOfLineComment(_mapTokens(node.tokens));
9831 }
9832
9833 @override
9834 CommentReference visitCommentReference(CommentReference node) =>
9835 new CommentReference(
9836 _mapToken(node.newKeyword), _cloneNode(node.identifier));
9837
9838 @override
9839 CompilationUnit visitCompilationUnit(CompilationUnit node) {
9840 CompilationUnit copy = new CompilationUnit(
9841 _mapToken(node.beginToken),
9842 _cloneNode(node.scriptTag),
9843 _cloneNodeList(node.directives),
9844 _cloneNodeList(node.declarations),
9845 _mapToken(node.endToken));
9846 copy.lineInfo = node.lineInfo;
9847 copy.element = node.element;
9848 return copy;
9849 }
9850
9851 @override
9852 ConditionalExpression visitConditionalExpression(ConditionalExpression node) {
9853 ConditionalExpression copy = new ConditionalExpression(
9854 _cloneNode(node.condition),
9855 _mapToken(node.question),
9856 _cloneNode(node.thenExpression),
9857 _mapToken(node.colon),
9858 _cloneNode(node.elseExpression));
9859 copy.propagatedType = node.propagatedType;
9860 copy.staticType = node.staticType;
9861 return copy;
9862 }
9863
9864 @override
9865 Configuration visitConfiguration(Configuration node) => new Configuration(
9866 _mapToken(node.ifKeyword),
9867 _mapToken(node.leftParenthesis),
9868 _cloneNode(node.name),
9869 _mapToken(node.equalToken),
9870 _cloneNode(node.value),
9871 _mapToken(node.rightParenthesis),
9872 _cloneNode(node.libraryUri));
9873
9874 @override
9875 ConstructorDeclaration visitConstructorDeclaration(
9876 ConstructorDeclaration node) {
9877 ConstructorDeclaration copy = new ConstructorDeclaration(
9878 _cloneNode(node.documentationComment),
9879 _cloneNodeList(node.metadata),
9880 _mapToken(node.externalKeyword),
9881 _mapToken(node.constKeyword),
9882 _mapToken(node.factoryKeyword),
9883 _cloneNode(node.returnType),
9884 _mapToken(node.period),
9885 _cloneNode(node.name),
9886 _cloneNode(node.parameters),
9887 _mapToken(node.separator),
9888 _cloneNodeList(node.initializers),
9889 _cloneNode(node.redirectedConstructor),
9890 _cloneNode(node.body));
9891 copy.element = node.element;
9892 return copy;
9893 }
9894
9895 @override
9896 ConstructorFieldInitializer visitConstructorFieldInitializer(
9897 ConstructorFieldInitializer node) =>
9898 new ConstructorFieldInitializer(
9899 _mapToken(node.thisKeyword),
9900 _mapToken(node.period),
9901 _cloneNode(node.fieldName),
9902 _mapToken(node.equals),
9903 _cloneNode(node.expression));
9904
9905 @override
9906 ConstructorName visitConstructorName(ConstructorName node) {
9907 ConstructorName copy = new ConstructorName(
9908 _cloneNode(node.type), _mapToken(node.period), _cloneNode(node.name));
9909 copy.staticElement = node.staticElement;
9910 return copy;
9911 }
9912
9913 @override
9914 ContinueStatement visitContinueStatement(ContinueStatement node) =>
9915 new ContinueStatement(_mapToken(node.continueKeyword),
9916 _cloneNode(node.label), _mapToken(node.semicolon));
9917
9918 @override
9919 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
9920 new DeclaredIdentifier(
9921 _cloneNode(node.documentationComment),
9922 _cloneNodeList(node.metadata),
9923 _mapToken(node.keyword),
9924 _cloneNode(node.type),
9925 _cloneNode(node.identifier));
9926
9927 @override
9928 DefaultFormalParameter visitDefaultFormalParameter(
9929 DefaultFormalParameter node) =>
9930 new DefaultFormalParameter(_cloneNode(node.parameter), node.kind,
9931 _mapToken(node.separator), _cloneNode(node.defaultValue));
9932
9933 @override
9934 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
9935 _mapToken(node.doKeyword),
9936 _cloneNode(node.body),
9937 _mapToken(node.whileKeyword),
9938 _mapToken(node.leftParenthesis),
9939 _cloneNode(node.condition),
9940 _mapToken(node.rightParenthesis),
9941 _mapToken(node.semicolon));
9942
9943 @override
9944 DottedName visitDottedName(DottedName node) =>
9945 new DottedName(_cloneNodeList(node.components));
9946
9947 @override
9948 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) {
9949 DoubleLiteral copy = new DoubleLiteral(_mapToken(node.literal), node.value);
9950 copy.propagatedType = node.propagatedType;
9951 copy.staticType = node.staticType;
9952 return copy;
9953 }
9954
9955 @override
9956 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
9957 new EmptyFunctionBody(_mapToken(node.semicolon));
9958
9959 @override
9960 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
9961 new EmptyStatement(_mapToken(node.semicolon));
9962
9963 @override
9964 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
9965 new EnumConstantDeclaration(_cloneNode(node.documentationComment),
9966 _cloneNodeList(node.metadata), _cloneNode(node.name));
9967
9968 @override
9969 AstNode visitEnumDeclaration(EnumDeclaration node) => new EnumDeclaration(
9970 _cloneNode(node.documentationComment),
9971 _cloneNodeList(node.metadata),
9972 _mapToken(node.enumKeyword),
9973 _cloneNode(node.name),
9974 _mapToken(node.leftBracket),
9975 _cloneNodeList(node.constants),
9976 _mapToken(node.rightBracket));
9977
9978 @override
9979 ExportDirective visitExportDirective(ExportDirective node) {
9980 ExportDirective copy = new ExportDirective(
9981 _cloneNode(node.documentationComment),
9982 _cloneNodeList(node.metadata),
9983 _mapToken(node.keyword),
9984 _cloneNode(node.uri),
9985 _cloneNodeList(node.configurations),
9986 _cloneNodeList(node.combinators),
9987 _mapToken(node.semicolon));
9988 copy.element = node.element;
9989 return copy;
9990 }
9991
9992 @override
9993 ExpressionFunctionBody visitExpressionFunctionBody(
9994 ExpressionFunctionBody node) =>
9995 new ExpressionFunctionBody(
9996 _mapToken(node.keyword),
9997 _mapToken(node.functionDefinition),
9998 _cloneNode(node.expression),
9999 _mapToken(node.semicolon));
10000
10001 @override
10002 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
10003 new ExpressionStatement(
10004 _cloneNode(node.expression), _mapToken(node.semicolon));
10005
10006 @override
10007 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
10008 _mapToken(node.extendsKeyword), _cloneNode(node.superclass));
10009
10010 @override
10011 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
10012 new FieldDeclaration(
10013 _cloneNode(node.documentationComment),
10014 _cloneNodeList(node.metadata),
10015 _mapToken(node.staticKeyword),
10016 _cloneNode(node.fields),
10017 _mapToken(node.semicolon));
10018
10019 @override
10020 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
10021 new FieldFormalParameter(
10022 _cloneNode(node.documentationComment),
10023 _cloneNodeList(node.metadata),
10024 _mapToken(node.keyword),
10025 _cloneNode(node.type),
10026 _mapToken(node.thisKeyword),
10027 _mapToken(node.period),
10028 _cloneNode(node.identifier),
10029 _cloneNode(node.typeParameters),
10030 _cloneNode(node.parameters));
10031
10032 @override
10033 ForEachStatement visitForEachStatement(ForEachStatement node) {
10034 DeclaredIdentifier loopVariable = node.loopVariable;
10035 if (loopVariable == null) {
10036 return new ForEachStatement.withReference(
10037 _mapToken(node.awaitKeyword),
10038 _mapToken(node.forKeyword),
10039 _mapToken(node.leftParenthesis),
10040 _cloneNode(node.identifier),
10041 _mapToken(node.inKeyword),
10042 _cloneNode(node.iterable),
10043 _mapToken(node.rightParenthesis),
10044 _cloneNode(node.body));
10045 }
10046 return new ForEachStatement.withDeclaration(
10047 _mapToken(node.awaitKeyword),
10048 _mapToken(node.forKeyword),
10049 _mapToken(node.leftParenthesis),
10050 _cloneNode(loopVariable),
10051 _mapToken(node.inKeyword),
10052 _cloneNode(node.iterable),
10053 _mapToken(node.rightParenthesis),
10054 _cloneNode(node.body));
10055 }
10056
10057 @override
10058 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
10059 new FormalParameterList(
10060 _mapToken(node.leftParenthesis),
10061 _cloneNodeList(node.parameters),
10062 _mapToken(node.leftDelimiter),
10063 _mapToken(node.rightDelimiter),
10064 _mapToken(node.rightParenthesis));
10065
10066 @override
10067 ForStatement visitForStatement(ForStatement node) => new ForStatement(
10068 _mapToken(node.forKeyword),
10069 _mapToken(node.leftParenthesis),
10070 _cloneNode(node.variables),
10071 _cloneNode(node.initialization),
10072 _mapToken(node.leftSeparator),
10073 _cloneNode(node.condition),
10074 _mapToken(node.rightSeparator),
10075 _cloneNodeList(node.updaters),
10076 _mapToken(node.rightParenthesis),
10077 _cloneNode(node.body));
10078
10079 @override
10080 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
10081 new FunctionDeclaration(
10082 _cloneNode(node.documentationComment),
10083 _cloneNodeList(node.metadata),
10084 _mapToken(node.externalKeyword),
10085 _cloneNode(node.returnType),
10086 _mapToken(node.propertyKeyword),
10087 _cloneNode(node.name),
10088 _cloneNode(node.functionExpression));
10089
10090 @override
10091 FunctionDeclarationStatement visitFunctionDeclarationStatement(
10092 FunctionDeclarationStatement node) =>
10093 new FunctionDeclarationStatement(_cloneNode(node.functionDeclaration));
10094
10095 @override
10096 FunctionExpression visitFunctionExpression(FunctionExpression node) {
10097 FunctionExpression copy = new FunctionExpression(
10098 _cloneNode(node.typeParameters),
10099 _cloneNode(node.parameters),
10100 _cloneNode(node.body));
10101 copy.element = node.element;
10102 copy.propagatedType = node.propagatedType;
10103 copy.staticType = node.staticType;
10104 return copy;
10105 }
10106
10107 @override
10108 FunctionExpressionInvocation visitFunctionExpressionInvocation(
10109 FunctionExpressionInvocation node) {
10110 FunctionExpressionInvocation copy = new FunctionExpressionInvocation(
10111 _cloneNode(node.function),
10112 _cloneNode(node.typeArguments),
10113 _cloneNode(node.argumentList));
10114 copy.propagatedElement = node.propagatedElement;
10115 copy.propagatedType = node.propagatedType;
10116 copy.staticElement = node.staticElement;
10117 copy.staticType = node.staticType;
10118 return copy;
10119 }
10120
10121 @override
10122 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
10123 new FunctionTypeAlias(
10124 _cloneNode(node.documentationComment),
10125 _cloneNodeList(node.metadata),
10126 _mapToken(node.typedefKeyword),
10127 _cloneNode(node.returnType),
10128 _cloneNode(node.name),
10129 _cloneNode(node.typeParameters),
10130 _cloneNode(node.parameters),
10131 _mapToken(node.semicolon));
10132
10133 @override
10134 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
10135 FunctionTypedFormalParameter node) =>
10136 new FunctionTypedFormalParameter(
10137 _cloneNode(node.documentationComment),
10138 _cloneNodeList(node.metadata),
10139 _cloneNode(node.returnType),
10140 _cloneNode(node.identifier),
10141 _cloneNode(node.typeParameters),
10142 _cloneNode(node.parameters));
10143
10144 @override
10145 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
10146 _mapToken(node.keyword), _cloneNodeList(node.hiddenNames));
10147
10148 @override
10149 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
10150 _mapToken(node.ifKeyword),
10151 _mapToken(node.leftParenthesis),
10152 _cloneNode(node.condition),
10153 _mapToken(node.rightParenthesis),
10154 _cloneNode(node.thenStatement),
10155 _mapToken(node.elseKeyword),
10156 _cloneNode(node.elseStatement));
10157
10158 @override
10159 ImplementsClause visitImplementsClause(ImplementsClause node) =>
10160 new ImplementsClause(
10161 _mapToken(node.implementsKeyword), _cloneNodeList(node.interfaces));
10162
10163 @override
10164 ImportDirective visitImportDirective(ImportDirective node) =>
10165 new ImportDirective(
10166 _cloneNode(node.documentationComment),
10167 _cloneNodeList(node.metadata),
10168 _mapToken(node.keyword),
10169 _cloneNode(node.uri),
10170 _cloneNodeList(node.configurations),
10171 _mapToken(node.deferredKeyword),
10172 _mapToken(node.asKeyword),
10173 _cloneNode(node.prefix),
10174 _cloneNodeList(node.combinators),
10175 _mapToken(node.semicolon));
10176
10177 @override
10178 IndexExpression visitIndexExpression(IndexExpression node) {
10179 Token period = _mapToken(node.period);
10180 IndexExpression copy;
10181 if (period == null) {
10182 copy = new IndexExpression.forTarget(
10183 _cloneNode(node.target),
10184 _mapToken(node.leftBracket),
10185 _cloneNode(node.index),
10186 _mapToken(node.rightBracket));
10187 } else {
10188 copy = new IndexExpression.forCascade(period, _mapToken(node.leftBracket),
10189 _cloneNode(node.index), _mapToken(node.rightBracket));
10190 }
10191 copy.auxiliaryElements = node.auxiliaryElements;
10192 copy.propagatedElement = node.propagatedElement;
10193 copy.propagatedType = node.propagatedType;
10194 copy.staticElement = node.staticElement;
10195 copy.staticType = node.staticType;
10196 return copy;
10197 }
10198
10199 @override
10200 InstanceCreationExpression visitInstanceCreationExpression(
10201 InstanceCreationExpression node) {
10202 InstanceCreationExpression copy = new InstanceCreationExpression(
10203 _mapToken(node.keyword),
10204 _cloneNode(node.constructorName),
10205 _cloneNode(node.argumentList));
10206 copy.propagatedType = node.propagatedType;
10207 copy.staticElement = node.staticElement;
10208 copy.staticType = node.staticType;
10209 return copy;
10210 }
10211
10212 @override
10213 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) {
10214 IntegerLiteral copy =
10215 new IntegerLiteral(_mapToken(node.literal), node.value);
10216 copy.propagatedType = node.propagatedType;
10217 copy.staticType = node.staticType;
10218 return copy;
10219 }
10220
10221 @override
10222 InterpolationExpression visitInterpolationExpression(
10223 InterpolationExpression node) =>
10224 new InterpolationExpression(_mapToken(node.leftBracket),
10225 _cloneNode(node.expression), _mapToken(node.rightBracket));
10226
10227 @override
10228 InterpolationString visitInterpolationString(InterpolationString node) =>
10229 new InterpolationString(_mapToken(node.contents), node.value);
10230
10231 @override
10232 IsExpression visitIsExpression(IsExpression node) {
10233 IsExpression copy = new IsExpression(
10234 _cloneNode(node.expression),
10235 _mapToken(node.isOperator),
10236 _mapToken(node.notOperator),
10237 _cloneNode(node.type));
10238 copy.propagatedType = node.propagatedType;
10239 copy.staticType = node.staticType;
10240 return copy;
10241 }
10242
10243 @override
10244 Label visitLabel(Label node) =>
10245 new Label(_cloneNode(node.label), _mapToken(node.colon));
10246
10247 @override
10248 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
10249 new LabeledStatement(
10250 _cloneNodeList(node.labels), _cloneNode(node.statement));
10251
10252 @override
10253 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
10254 new LibraryDirective(
10255 _cloneNode(node.documentationComment),
10256 _cloneNodeList(node.metadata),
10257 _mapToken(node.libraryKeyword),
10258 _cloneNode(node.name),
10259 _mapToken(node.semicolon));
10260
10261 @override
10262 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) {
10263 LibraryIdentifier copy =
10264 new LibraryIdentifier(_cloneNodeList(node.components));
10265 copy.propagatedType = node.propagatedType;
10266 copy.staticType = node.staticType;
10267 return copy;
10268 }
10269
10270 @override
10271 ListLiteral visitListLiteral(ListLiteral node) {
10272 ListLiteral copy = new ListLiteral(
10273 _mapToken(node.constKeyword),
10274 _cloneNode(node.typeArguments),
10275 _mapToken(node.leftBracket),
10276 _cloneNodeList(node.elements),
10277 _mapToken(node.rightBracket));
10278 copy.propagatedType = node.propagatedType;
10279 copy.staticType = node.staticType;
10280 return copy;
10281 }
10282
10283 @override
10284 MapLiteral visitMapLiteral(MapLiteral node) {
10285 MapLiteral copy = new MapLiteral(
10286 _mapToken(node.constKeyword),
10287 _cloneNode(node.typeArguments),
10288 _mapToken(node.leftBracket),
10289 _cloneNodeList(node.entries),
10290 _mapToken(node.rightBracket));
10291 copy.propagatedType = node.propagatedType;
10292 copy.staticType = node.staticType;
10293 return copy;
10294 }
10295
10296 @override
10297 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) =>
10298 new MapLiteralEntry(_cloneNode(node.key), _mapToken(node.separator),
10299 _cloneNode(node.value));
10300
10301 @override
10302 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
10303 new MethodDeclaration(
10304 _cloneNode(node.documentationComment),
10305 _cloneNodeList(node.metadata),
10306 _mapToken(node.externalKeyword),
10307 _mapToken(node.modifierKeyword),
10308 _cloneNode(node.returnType),
10309 _mapToken(node.propertyKeyword),
10310 _mapToken(node.operatorKeyword),
10311 _cloneNode(node.name),
10312 _cloneNode(node._typeParameters),
10313 _cloneNode(node.parameters),
10314 _cloneNode(node.body));
10315
10316 @override
10317 MethodInvocation visitMethodInvocation(MethodInvocation node) {
10318 MethodInvocation copy = new MethodInvocation(
10319 _cloneNode(node.target),
10320 _mapToken(node.operator),
10321 _cloneNode(node.methodName),
10322 _cloneNode(node.typeArguments),
10323 _cloneNode(node.argumentList));
10324 copy.propagatedType = node.propagatedType;
10325 copy.staticType = node.staticType;
10326 return copy;
10327 }
10328
10329 @override
10330 NamedExpression visitNamedExpression(NamedExpression node) {
10331 NamedExpression copy =
10332 new NamedExpression(_cloneNode(node.name), _cloneNode(node.expression));
10333 copy.propagatedType = node.propagatedType;
10334 copy.staticType = node.staticType;
10335 return copy;
10336 }
10337
10338 @override
10339 AstNode visitNativeClause(NativeClause node) =>
10340 new NativeClause(_mapToken(node.nativeKeyword), _cloneNode(node.name));
10341
10342 @override
10343 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
10344 new NativeFunctionBody(_mapToken(node.nativeKeyword),
10345 _cloneNode(node.stringLiteral), _mapToken(node.semicolon));
10346
10347 @override
10348 NullLiteral visitNullLiteral(NullLiteral node) {
10349 NullLiteral copy = new NullLiteral(_mapToken(node.literal));
10350 copy.propagatedType = node.propagatedType;
10351 copy.staticType = node.staticType;
10352 return copy;
10353 }
10354
10355 @override
10356 ParenthesizedExpression visitParenthesizedExpression(
10357 ParenthesizedExpression node) {
10358 ParenthesizedExpression copy = new ParenthesizedExpression(
10359 _mapToken(node.leftParenthesis),
10360 _cloneNode(node.expression),
10361 _mapToken(node.rightParenthesis));
10362 copy.propagatedType = node.propagatedType;
10363 copy.staticType = node.staticType;
10364 return copy;
10365 }
10366
10367 @override
10368 PartDirective visitPartDirective(PartDirective node) {
10369 PartDirective copy = new PartDirective(
10370 _cloneNode(node.documentationComment),
10371 _cloneNodeList(node.metadata),
10372 _mapToken(node.partKeyword),
10373 _cloneNode(node.uri),
10374 _mapToken(node.semicolon));
10375 copy.element = node.element;
10376 return copy;
10377 }
10378
10379 @override
10380 PartOfDirective visitPartOfDirective(PartOfDirective node) {
10381 PartOfDirective copy = new PartOfDirective(
10382 _cloneNode(node.documentationComment),
10383 _cloneNodeList(node.metadata),
10384 _mapToken(node.partKeyword),
10385 _mapToken(node.ofKeyword),
10386 _cloneNode(node.libraryName),
10387 _mapToken(node.semicolon));
10388 copy.element = node.element;
10389 return copy;
10390 }
10391
10392 @override
10393 PostfixExpression visitPostfixExpression(PostfixExpression node) {
10394 PostfixExpression copy = new PostfixExpression(
10395 _cloneNode(node.operand), _mapToken(node.operator));
10396 copy.propagatedElement = node.propagatedElement;
10397 copy.propagatedType = node.propagatedType;
10398 copy.staticElement = node.staticElement;
10399 copy.staticType = node.staticType;
10400 return copy;
10401 }
10402
10403 @override
10404 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) {
10405 PrefixedIdentifier copy = new PrefixedIdentifier(_cloneNode(node.prefix),
10406 _mapToken(node.period), _cloneNode(node.identifier));
10407 copy.propagatedType = node.propagatedType;
10408 copy.staticType = node.staticType;
10409 return copy;
10410 }
10411
10412 @override
10413 PrefixExpression visitPrefixExpression(PrefixExpression node) {
10414 PrefixExpression copy = new PrefixExpression(
10415 _mapToken(node.operator), _cloneNode(node.operand));
10416 copy.propagatedElement = node.propagatedElement;
10417 copy.propagatedType = node.propagatedType;
10418 copy.staticElement = node.staticElement;
10419 copy.staticType = node.staticType;
10420 return copy;
10421 }
10422
10423 @override
10424 PropertyAccess visitPropertyAccess(PropertyAccess node) {
10425 PropertyAccess copy = new PropertyAccess(_cloneNode(node.target),
10426 _mapToken(node.operator), _cloneNode(node.propertyName));
10427 copy.propagatedType = node.propagatedType;
10428 copy.staticType = node.staticType;
10429 return copy;
10430 }
10431
10432 @override
10433 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
10434 RedirectingConstructorInvocation node) {
10435 RedirectingConstructorInvocation copy =
10436 new RedirectingConstructorInvocation(
10437 _mapToken(node.thisKeyword),
10438 _mapToken(node.period),
10439 _cloneNode(node.constructorName),
10440 _cloneNode(node.argumentList));
10441 copy.staticElement = node.staticElement;
10442 return copy;
10443 }
10444
10445 @override
10446 RethrowExpression visitRethrowExpression(RethrowExpression node) {
10447 RethrowExpression copy =
10448 new RethrowExpression(_mapToken(node.rethrowKeyword));
10449 copy.propagatedType = node.propagatedType;
10450 copy.staticType = node.staticType;
10451 return copy;
10452 }
10453
10454 @override
10455 ReturnStatement visitReturnStatement(ReturnStatement node) =>
10456 new ReturnStatement(_mapToken(node.returnKeyword),
10457 _cloneNode(node.expression), _mapToken(node.semicolon));
10458
10459 @override
10460 ScriptTag visitScriptTag(ScriptTag node) =>
10461 new ScriptTag(_mapToken(node.scriptTag));
10462
10463 @override
10464 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
10465 _mapToken(node.keyword), _cloneNodeList(node.shownNames));
10466
10467 @override
10468 SimpleFormalParameter visitSimpleFormalParameter(
10469 SimpleFormalParameter node) =>
10470 new SimpleFormalParameter(
10471 _cloneNode(node.documentationComment),
10472 _cloneNodeList(node.metadata),
10473 _mapToken(node.keyword),
10474 _cloneNode(node.type),
10475 _cloneNode(node.identifier));
10476
10477 @override
10478 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
10479 Token mappedToken = _mapToken(node.token);
10480 if (mappedToken == null) {
10481 // This only happens for SimpleIdentifiers created by the parser as part
10482 // of scanning documentation comments (the tokens for those identifiers
10483 // are not in the original token stream and hence do not get copied).
10484 // This extra check can be removed if the scanner is changed to scan
10485 // documentation comments for the parser.
10486 mappedToken = node.token;
10487 }
10488 SimpleIdentifier copy = new SimpleIdentifier(mappedToken);
10489 copy.auxiliaryElements = node.auxiliaryElements;
10490 copy.propagatedElement = node.propagatedElement;
10491 copy.propagatedType = node.propagatedType;
10492 copy.staticElement = node.staticElement;
10493 copy.staticType = node.staticType;
10494 return copy;
10495 }
10496
10497 @override
10498 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) {
10499 SimpleStringLiteral copy =
10500 new SimpleStringLiteral(_mapToken(node.literal), node.value);
10501 copy.propagatedType = node.propagatedType;
10502 copy.staticType = node.staticType;
10503 return copy;
10504 }
10505
10506 @override
10507 StringInterpolation visitStringInterpolation(StringInterpolation node) {
10508 StringInterpolation copy =
10509 new StringInterpolation(_cloneNodeList(node.elements));
10510 copy.propagatedType = node.propagatedType;
10511 copy.staticType = node.staticType;
10512 return copy;
10513 }
10514
10515 @override
10516 SuperConstructorInvocation visitSuperConstructorInvocation(
10517 SuperConstructorInvocation node) {
10518 SuperConstructorInvocation copy = new SuperConstructorInvocation(
10519 _mapToken(node.superKeyword),
10520 _mapToken(node.period),
10521 _cloneNode(node.constructorName),
10522 _cloneNode(node.argumentList));
10523 copy.staticElement = node.staticElement;
10524 return copy;
10525 }
10526
10527 @override
10528 SuperExpression visitSuperExpression(SuperExpression node) {
10529 SuperExpression copy = new SuperExpression(_mapToken(node.superKeyword));
10530 copy.propagatedType = node.propagatedType;
10531 copy.staticType = node.staticType;
10532 return copy;
10533 }
10534
10535 @override
10536 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
10537 _cloneNodeList(node.labels),
10538 _mapToken(node.keyword),
10539 _cloneNode(node.expression),
10540 _mapToken(node.colon),
10541 _cloneNodeList(node.statements));
10542
10543 @override
10544 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
10545 _cloneNodeList(node.labels),
10546 _mapToken(node.keyword),
10547 _mapToken(node.colon),
10548 _cloneNodeList(node.statements));
10549
10550 @override
10551 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
10552 new SwitchStatement(
10553 _mapToken(node.switchKeyword),
10554 _mapToken(node.leftParenthesis),
10555 _cloneNode(node.expression),
10556 _mapToken(node.rightParenthesis),
10557 _mapToken(node.leftBracket),
10558 _cloneNodeList(node.members),
10559 _mapToken(node.rightBracket));
10560
10561 @override
10562 AstNode visitSymbolLiteral(SymbolLiteral node) {
10563 SymbolLiteral copy = new SymbolLiteral(
10564 _mapToken(node.poundSign), _mapTokens(node.components));
10565 copy.propagatedType = node.propagatedType;
10566 copy.staticType = node.staticType;
10567 return copy;
10568 }
10569
10570 @override
10571 ThisExpression visitThisExpression(ThisExpression node) {
10572 ThisExpression copy = new ThisExpression(_mapToken(node.thisKeyword));
10573 copy.propagatedType = node.propagatedType;
10574 copy.staticType = node.staticType;
10575 return copy;
10576 }
10577
10578 @override
10579 ThrowExpression visitThrowExpression(ThrowExpression node) {
10580 ThrowExpression copy = new ThrowExpression(
10581 _mapToken(node.throwKeyword), _cloneNode(node.expression));
10582 copy.propagatedType = node.propagatedType;
10583 copy.staticType = node.staticType;
10584 return copy;
10585 }
10586
10587 @override
10588 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
10589 TopLevelVariableDeclaration node) =>
10590 new TopLevelVariableDeclaration(
10591 _cloneNode(node.documentationComment),
10592 _cloneNodeList(node.metadata),
10593 _cloneNode(node.variables),
10594 _mapToken(node.semicolon));
10595
10596 @override
10597 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
10598 _mapToken(node.tryKeyword),
10599 _cloneNode(node.body),
10600 _cloneNodeList(node.catchClauses),
10601 _mapToken(node.finallyKeyword),
10602 _cloneNode(node.finallyBlock));
10603
10604 @override
10605 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
10606 new TypeArgumentList(_mapToken(node.leftBracket),
10607 _cloneNodeList(node.arguments), _mapToken(node.rightBracket));
10608
10609 @override
10610 TypeName visitTypeName(TypeName node) {
10611 TypeName copy =
10612 new TypeName(_cloneNode(node.name), _cloneNode(node.typeArguments));
10613 copy.type = node.type;
10614 return copy;
10615 }
10616
10617 @override
10618 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
10619 _cloneNode(node.documentationComment),
10620 _cloneNodeList(node.metadata),
10621 _cloneNode(node.name),
10622 _mapToken(node.extendsKeyword),
10623 _cloneNode(node.bound));
10624
10625 @override
10626 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
10627 new TypeParameterList(_mapToken(node.leftBracket),
10628 _cloneNodeList(node.typeParameters), _mapToken(node.rightBracket));
10629
10630 @override
10631 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
10632 new VariableDeclaration(_cloneNode(node.name), _mapToken(node.equals),
10633 _cloneNode(node.initializer));
10634
10635 @override
10636 VariableDeclarationList visitVariableDeclarationList(
10637 VariableDeclarationList node) =>
10638 new VariableDeclarationList(
10639 null,
10640 _cloneNodeList(node.metadata),
10641 _mapToken(node.keyword),
10642 _cloneNode(node.type),
10643 _cloneNodeList(node.variables));
10644
10645 @override
10646 VariableDeclarationStatement visitVariableDeclarationStatement(
10647 VariableDeclarationStatement node) =>
10648 new VariableDeclarationStatement(
10649 _cloneNode(node.variables), _mapToken(node.semicolon));
10650
10651 @override
10652 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
10653 _mapToken(node.whileKeyword),
10654 _mapToken(node.leftParenthesis),
10655 _cloneNode(node.condition),
10656 _mapToken(node.rightParenthesis),
10657 _cloneNode(node.body));
10658
10659 @override
10660 WithClause visitWithClause(WithClause node) => new WithClause(
10661 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes));
10662
10663 @override
10664 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
10665 _mapToken(node.yieldKeyword),
10666 _mapToken(node.star),
10667 _cloneNode(node.expression),
10668 _mapToken(node.semicolon));
10669
10670 AstNode _cloneNode(AstNode node) {
10671 if (node == null) {
10672 return null;
10673 }
10674 if (identical(node, _oldNode)) {
10675 return _newNode;
10676 }
10677 return node.accept(this) as AstNode;
10678 }
10679
10680 List _cloneNodeList(NodeList nodes) {
10681 List clonedNodes = new List();
10682 for (AstNode node in nodes) {
10683 clonedNodes.add(_cloneNode(node));
10684 }
10685 return clonedNodes;
10686 }
10687
10688 Token _mapToken(Token oldToken) {
10689 if (oldToken == null) {
10690 return null;
10691 }
10692 return _tokenMap.get(oldToken);
10693 }
10694
10695 List<Token> _mapTokens(List<Token> oldTokens) {
10696 List<Token> newTokens = new List<Token>(oldTokens.length);
10697 for (int index = 0; index < newTokens.length; index++) {
10698 newTokens[index] = _mapToken(oldTokens[index]);
10699 }
10700 return newTokens;
10701 }
10702 }
10703
10704 /**
10705 * An index expression.
10706 *
10707 * > indexExpression ::=
10708 * > [Expression] '[' [Expression] ']'
10709 */
10710 class IndexExpression extends Expression {
10711 /**
10712 * The expression used to compute the object being indexed, or `null` if this
10713 * index expression is part of a cascade expression.
10714 */
10715 Expression _target;
10716
10717 /**
10718 * The period ("..") before a cascaded index expression, or `null` if this
10719 * index expression is not part of a cascade expression.
10720 */
10721 Token period;
10722
10723 /**
10724 * The left square bracket.
10725 */
10726 Token leftBracket;
10727
10728 /**
10729 * The expression used to compute the index.
10730 */
10731 Expression _index;
10732
10733 /**
10734 * The right square bracket.
10735 */
10736 Token rightBracket;
10737
10738 /**
10739 * The element associated with the operator based on the static type of the
10740 * target, or `null` if the AST structure has not been resolved or if the
10741 * operator could not be resolved.
10742 */
10743 MethodElement staticElement;
10744
10745 /**
10746 * The element associated with the operator based on the propagated type of
10747 * the target, or `null` if the AST structure has not been resolved or if the
10748 * operator could not be resolved.
10749 */
10750 MethodElement propagatedElement;
10751
10752 /**
10753 * If this expression is both in a getter and setter context, the
10754 * [AuxiliaryElements] will be set to hold onto the static and propagated
10755 * information. The auxiliary element will hold onto the elements from the
10756 * getter context.
10757 */
10758 AuxiliaryElements auxiliaryElements = null;
10759
10760 /**
10761 * Initialize a newly created index expression.
10762 */
10763 IndexExpression.forCascade(
10764 this.period, this.leftBracket, Expression index, this.rightBracket) {
10765 _index = _becomeParentOf(index);
10766 }
10767
10768 /**
10769 * Initialize a newly created index expression.
10770 */
10771 IndexExpression.forTarget(Expression target, this.leftBracket,
10772 Expression index, this.rightBracket) {
10773 _target = _becomeParentOf(target);
10774 _index = _becomeParentOf(index);
10775 }
10776
10777 @override
10778 Token get beginToken {
10779 if (_target != null) {
10780 return _target.beginToken;
10781 }
10782 return period;
10783 }
10784
10785 /**
10786 * Return the best element available for this operator. If resolution was able
10787 * to find a better element based on type propagation, that element will be
10788 * returned. Otherwise, the element found using the result of static analysis
10789 * will be returned. If resolution has not been performed, then `null` will be
10790 * returned.
10791 */
10792 MethodElement get bestElement {
10793 MethodElement element = propagatedElement;
10794 if (element == null) {
10795 element = staticElement;
10796 }
10797 return element;
10798 }
10799
10800 @override
10801 Iterable get childEntities => new ChildEntities()
10802 ..add(_target)
10803 ..add(period)
10804 ..add(leftBracket)
10805 ..add(_index)
10806 ..add(rightBracket);
10807
10808 @override
10809 Token get endToken => rightBracket;
10810
10811 /**
10812 * Return the expression used to compute the index.
10813 */
10814 Expression get index => _index;
10815
10816 /**
10817 * Set the expression used to compute the index to the given [expression].
10818 */
10819 void set index(Expression expression) {
10820 _index = _becomeParentOf(expression);
10821 }
10822
10823 @override
10824 bool get isAssignable => true;
10825
10826 /**
10827 * Return `true` if this expression is cascaded. If it is, then the target of
10828 * this expression is not stored locally but is stored in the nearest ancestor
10829 * that is a [CascadeExpression].
10830 */
10831 bool get isCascaded => period != null;
10832
10833 @override
10834 int get precedence => 15;
10835
10836 /**
10837 * Return the expression used to compute the object being indexed. If this
10838 * index expression is not part of a cascade expression, then this is the same
10839 * as [target]. If this index expression is part of a cascade expression, then
10840 * the target expression stored with the cascade expression is returned.
10841 */
10842 Expression get realTarget {
10843 if (isCascaded) {
10844 AstNode ancestor = parent;
10845 while (ancestor is! CascadeExpression) {
10846 if (ancestor == null) {
10847 return _target;
10848 }
10849 ancestor = ancestor.parent;
10850 }
10851 return (ancestor as CascadeExpression).target;
10852 }
10853 return _target;
10854 }
10855
10856 /**
10857 * Return the expression used to compute the object being indexed, or `null`
10858 * if this index expression is part of a cascade expression.
10859 *
10860 * Use [realTarget] to get the target independent of whether this is part of a
10861 * cascade expression.
10862 */
10863 Expression get target => _target;
10864
10865 /**
10866 * Set the expression used to compute the object being indexed to the given
10867 * [expression].
10868 */
10869 void set target(Expression expression) {
10870 _target = _becomeParentOf(expression);
10871 }
10872
10873 /**
10874 * If the AST structure has been resolved, and the function being invoked is
10875 * known based on propagated type information, then return the parameter
10876 * element representing the parameter to which the value of the index
10877 * expression will be bound. Otherwise, return `null`.
10878 */
10879 ParameterElement get _propagatedParameterElementForIndex {
10880 if (propagatedElement == null) {
10881 return null;
10882 }
10883 List<ParameterElement> parameters = propagatedElement.parameters;
10884 if (parameters.length < 1) {
10885 return null;
10886 }
10887 return parameters[0];
10888 }
10889
10890 /**
10891 * If the AST structure has been resolved, and the function being invoked is
10892 * known based on static type information, then return the parameter element
10893 * representing the parameter to which the value of the index expression will
10894 * be bound. Otherwise, return `null`.
10895 */
10896 ParameterElement get _staticParameterElementForIndex {
10897 if (staticElement == null) {
10898 return null;
10899 }
10900 List<ParameterElement> parameters = staticElement.parameters;
10901 if (parameters.length < 1) {
10902 return null;
10903 }
10904 return parameters[0];
10905 }
10906
10907 @override
10908 accept(AstVisitor visitor) => visitor.visitIndexExpression(this);
10909
10910 /**
10911 * Return `true` if this expression is computing a right-hand value (that is,
10912 * if this expression is in a context where the operator '[]' will be
10913 * invoked).
10914 *
10915 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10916 * are they mutually exclusive. In other words, it is possible for both
10917 * methods to return `true` when invoked on the same node.
10918 */
10919 bool inGetterContext() {
10920 // TODO(brianwilkerson) Convert this to a getter.
10921 AstNode parent = this.parent;
10922 if (parent is AssignmentExpression) {
10923 AssignmentExpression assignment = parent;
10924 if (identical(assignment.leftHandSide, this) &&
10925 assignment.operator.type == TokenType.EQ) {
10926 return false;
10927 }
10928 }
10929 return true;
10930 }
10931
10932 /**
10933 * Return `true` if this expression is computing a left-hand value (that is,
10934 * if this expression is in a context where the operator '[]=' will be
10935 * invoked).
10936 *
10937 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10938 * are they mutually exclusive. In other words, it is possible for both
10939 * methods to return `true` when invoked on the same node.
10940 */
10941 bool inSetterContext() {
10942 // TODO(brianwilkerson) Convert this to a getter.
10943 AstNode parent = this.parent;
10944 if (parent is PrefixExpression) {
10945 return parent.operator.type.isIncrementOperator;
10946 } else if (parent is PostfixExpression) {
10947 return true;
10948 } else if (parent is AssignmentExpression) {
10949 return identical(parent.leftHandSide, this);
10950 }
10951 return false;
10952 }
10953
10954 @override
10955 void visitChildren(AstVisitor visitor) {
10956 _safelyVisitChild(_target, visitor);
10957 _safelyVisitChild(_index, visitor);
10958 }
10959 }
10960
10961 /**
10962 * An instance creation expression.
10963 *
10964 * > newExpression ::=
10965 * > ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList]
10966 */
10967 class InstanceCreationExpression extends Expression {
10968 /**
10969 * The 'new' or 'const' keyword used to indicate how an object should be
10970 * created.
10971 */
10972 Token keyword;
10973
10974 /**
10975 * The name of the constructor to be invoked.
10976 */
10977 ConstructorName _constructorName;
10978
10979 /**
10980 * The list of arguments to the constructor.
10981 */
10982 ArgumentList _argumentList;
10983
10984 /**
10985 * The element associated with the constructor based on static type
10986 * information, or `null` if the AST structure has not been resolved or if the
10987 * constructor could not be resolved.
10988 */
10989 ConstructorElement staticElement;
10990
10991 /**
10992 * Initialize a newly created instance creation expression.
10993 */
10994 InstanceCreationExpression(this.keyword, ConstructorName constructorName,
10995 ArgumentList argumentList) {
10996 _constructorName = _becomeParentOf(constructorName);
10997 _argumentList = _becomeParentOf(argumentList);
10998 }
10999
11000 /**
11001 * Return the list of arguments to the constructor.
11002 */
11003 ArgumentList get argumentList => _argumentList;
11004
11005 /**
11006 * Set the list of arguments to the constructor to the given [argumentList].
11007 */
11008 void set argumentList(ArgumentList argumentList) {
11009 _argumentList = _becomeParentOf(argumentList);
11010 }
11011
11012 @override
11013 Token get beginToken => keyword;
11014
11015 @override
11016 Iterable get childEntities => new ChildEntities()
11017 ..add(keyword)
11018 ..add(_constructorName)
11019 ..add(_argumentList);
11020
11021 /**
11022 * Return the name of the constructor to be invoked.
11023 */
11024 ConstructorName get constructorName => _constructorName;
11025
11026 /**
11027 * Set the name of the constructor to be invoked to the given [name].
11028 */
11029 void set constructorName(ConstructorName name) {
11030 _constructorName = _becomeParentOf(name);
11031 }
11032
11033 @override
11034 Token get endToken => _argumentList.endToken;
11035
11036 /**
11037 * Return `true` if this creation expression is used to invoke a constant
11038 * constructor.
11039 */
11040 bool get isConst =>
11041 keyword is KeywordToken &&
11042 (keyword as KeywordToken).keyword == Keyword.CONST;
11043
11044 @override
11045 int get precedence => 16;
11046
11047 @override
11048 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this);
11049
11050 @override
11051 void visitChildren(AstVisitor visitor) {
11052 _safelyVisitChild(_constructorName, visitor);
11053 _safelyVisitChild(_argumentList, visitor);
11054 }
11055 }
11056
11057 /**
11058 * An integer literal expression.
11059 *
11060 * > integerLiteral ::=
11061 * > decimalIntegerLiteral
11062 * > | hexidecimalIntegerLiteral
11063 * >
11064 * > decimalIntegerLiteral ::=
11065 * > decimalDigit+
11066 * >
11067 * > hexidecimalIntegerLiteral ::=
11068 * > '0x' hexidecimalDigit+
11069 * > | '0X' hexidecimalDigit+
11070 */
11071 class IntegerLiteral extends Literal {
11072 /**
11073 * The token representing the literal.
11074 */
11075 Token literal;
11076
11077 /**
11078 * The value of the literal.
11079 */
11080 int value = 0;
11081
11082 /**
11083 * Initialize a newly created integer literal.
11084 */
11085 IntegerLiteral(this.literal, this.value);
11086
11087 @override
11088 Token get beginToken => literal;
11089
11090 @override
11091 Iterable get childEntities => new ChildEntities()..add(literal);
11092
11093 @override
11094 Token get endToken => literal;
11095
11096 @override
11097 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this);
11098
11099 @override
11100 void visitChildren(AstVisitor visitor) {
11101 // There are no children to visit.
11102 }
11103 }
11104
11105 /**
11106 * A node within a [StringInterpolation].
11107 *
11108 * > interpolationElement ::=
11109 * > [InterpolationExpression]
11110 * > | [InterpolationString]
11111 */
11112 abstract class InterpolationElement extends AstNode {}
11113
11114 /**
11115 * An expression embedded in a string interpolation.
11116 *
11117 * > interpolationExpression ::=
11118 * > '$' [SimpleIdentifier]
11119 * > | '$' '{' [Expression] '}'
11120 */
11121 class InterpolationExpression extends InterpolationElement {
11122 /**
11123 * The token used to introduce the interpolation expression; either '$' if the
11124 * expression is a simple identifier or '${' if the expression is a full
11125 * expression.
11126 */
11127 Token leftBracket;
11128
11129 /**
11130 * The expression to be evaluated for the value to be converted into a string.
11131 */
11132 Expression _expression;
11133
11134 /**
11135 * The right curly bracket, or `null` if the expression is an identifier
11136 * without brackets.
11137 */
11138 Token rightBracket;
11139
11140 /**
11141 * Initialize a newly created interpolation expression.
11142 */
11143 InterpolationExpression(
11144 this.leftBracket, Expression expression, this.rightBracket) {
11145 _expression = _becomeParentOf(expression);
11146 }
11147
11148 @override
11149 Token get beginToken => leftBracket;
11150
11151 @override
11152 Iterable get childEntities => new ChildEntities()
11153 ..add(leftBracket)
11154 ..add(_expression)
11155 ..add(rightBracket);
11156
11157 @override
11158 Token get endToken {
11159 if (rightBracket != null) {
11160 return rightBracket;
11161 }
11162 return _expression.endToken;
11163 }
11164
11165 /**
11166 * Return the expression to be evaluated for the value to be converted into a
11167 * string.
11168 */
11169 Expression get expression => _expression;
11170
11171 /**
11172 * Set the expression to be evaluated for the value to be converted into a
11173 * string to the given [expression].
11174 */
11175 void set expression(Expression expression) {
11176 _expression = _becomeParentOf(expression);
11177 }
11178
11179 @override
11180 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this);
11181
11182 @override
11183 void visitChildren(AstVisitor visitor) {
11184 _safelyVisitChild(_expression, visitor);
11185 }
11186 }
11187
11188 /**
11189 * A non-empty substring of an interpolated string.
11190 *
11191 * > interpolationString ::=
11192 * > characters
11193 */
11194 class InterpolationString extends InterpolationElement {
11195 /**
11196 * The characters that will be added to the string.
11197 */
11198 Token contents;
11199
11200 /**
11201 * The value of the literal.
11202 */
11203 String value;
11204
11205 /**
11206 * Initialize a newly created string of characters that are part of a string
11207 * interpolation.
11208 */
11209 InterpolationString(this.contents, this.value);
11210
11211 @override
11212 Token get beginToken => contents;
11213
11214 @override
11215 Iterable get childEntities => new ChildEntities()..add(contents);
11216
11217 /**
11218 * Return the offset of the after-last contents character.
11219 */
11220 int get contentsEnd {
11221 String lexeme = contents.lexeme;
11222 return offset + new StringLexemeHelper(lexeme, true, true).end;
11223 }
11224
11225 /**
11226 * Return the offset of the first contents character.
11227 */
11228 int get contentsOffset {
11229 int offset = contents.offset;
11230 String lexeme = contents.lexeme;
11231 return offset + new StringLexemeHelper(lexeme, true, true).start;
11232 }
11233
11234 @override
11235 Token get endToken => contents;
11236
11237 @override
11238 accept(AstVisitor visitor) => visitor.visitInterpolationString(this);
11239
11240 @override
11241 void visitChildren(AstVisitor visitor) {}
11242 }
11243
11244 /**
11245 * An is expression.
11246 *
11247 * > isExpression ::=
11248 * > [Expression] 'is' '!'? [TypeName]
11249 */
11250 class IsExpression extends Expression {
11251 /**
11252 * The expression used to compute the value whose type is being tested.
11253 */
11254 Expression _expression;
11255
11256 /**
11257 * The is operator.
11258 */
11259 Token isOperator;
11260
11261 /**
11262 * The not operator, or `null` if the sense of the test is not negated.
11263 */
11264 Token notOperator;
11265
11266 /**
11267 * The name of the type being tested for.
11268 */
11269 TypeName _type;
11270
11271 /**
11272 * Initialize a newly created is expression. The [notOperator] can be `null`
11273 * if the sense of the test is not negated.
11274 */
11275 IsExpression(
11276 Expression expression, this.isOperator, this.notOperator, TypeName type) {
11277 _expression = _becomeParentOf(expression);
11278 _type = _becomeParentOf(type);
11279 }
11280
11281 @override
11282 Token get beginToken => _expression.beginToken;
11283
11284 @override
11285 Iterable get childEntities => new ChildEntities()
11286 ..add(_expression)
11287 ..add(isOperator)
11288 ..add(notOperator)
11289 ..add(_type);
11290
11291 @override
11292 Token get endToken => _type.endToken;
11293
11294 /**
11295 * Return the expression used to compute the value whose type is being tested.
11296 */
11297 Expression get expression => _expression;
11298
11299 /**
11300 * Set the expression used to compute the value whose type is being tested to
11301 * the given [expression].
11302 */
11303 void set expression(Expression expression) {
11304 _expression = _becomeParentOf(expression);
11305 }
11306
11307 @override
11308 int get precedence => 7;
11309
11310 /**
11311 * Return the name of the type being tested for.
11312 */
11313 TypeName get type => _type;
11314
11315 /**
11316 * Set the name of the type being tested for to the given [name].
11317 */
11318 void set type(TypeName name) {
11319 _type = _becomeParentOf(name);
11320 }
11321
11322 @override
11323 accept(AstVisitor visitor) => visitor.visitIsExpression(this);
11324
11325 @override
11326 void visitChildren(AstVisitor visitor) {
11327 _safelyVisitChild(_expression, visitor);
11328 _safelyVisitChild(_type, visitor);
11329 }
11330 }
11331
11332 /**
11333 * A label on either a [LabeledStatement] or a [NamedExpression].
11334 *
11335 * > label ::=
11336 * > [SimpleIdentifier] ':'
11337 */
11338 class Label extends AstNode {
11339 /**
11340 * The label being associated with the statement.
11341 */
11342 SimpleIdentifier _label;
11343
11344 /**
11345 * The colon that separates the label from the statement.
11346 */
11347 Token colon;
11348
11349 /**
11350 * Initialize a newly created label.
11351 */
11352 Label(SimpleIdentifier label, this.colon) {
11353 _label = _becomeParentOf(label);
11354 }
11355
11356 @override
11357 Token get beginToken => _label.beginToken;
11358
11359 @override
11360 Iterable get childEntities => new ChildEntities()..add(_label)..add(colon);
11361
11362 @override
11363 Token get endToken => colon;
11364
11365 /**
11366 * Return the label being associated with the statement.
11367 */
11368 SimpleIdentifier get label => _label;
11369
11370 /**
11371 * Set the label being associated with the statement to the given [label].
11372 */
11373 void set label(SimpleIdentifier label) {
11374 _label = _becomeParentOf(label);
11375 }
11376
11377 @override
11378 accept(AstVisitor visitor) => visitor.visitLabel(this);
11379
11380 @override
11381 void visitChildren(AstVisitor visitor) {
11382 _safelyVisitChild(_label, visitor);
11383 }
11384 }
11385
11386 /**
11387 * A statement that has a label associated with them.
11388 *
11389 * > labeledStatement ::=
11390 * > [Label]+ [Statement]
11391 */
11392 class LabeledStatement extends Statement {
11393 /**
11394 * The labels being associated with the statement.
11395 */
11396 NodeList<Label> _labels;
11397
11398 /**
11399 * The statement with which the labels are being associated.
11400 */
11401 Statement _statement;
11402
11403 /**
11404 * Initialize a newly created labeled statement.
11405 */
11406 LabeledStatement(List<Label> labels, Statement statement) {
11407 _labels = new NodeList<Label>(this, labels);
11408 _statement = _becomeParentOf(statement);
11409 }
11410
11411 @override
11412 Token get beginToken {
11413 if (!_labels.isEmpty) {
11414 return _labels.beginToken;
11415 }
11416 return _statement.beginToken;
11417 }
11418
11419 @override
11420 Iterable get childEntities => new ChildEntities()
11421 ..addAll(_labels)
11422 ..add(_statement);
11423
11424 @override
11425 Token get endToken => _statement.endToken;
11426
11427 /**
11428 * Return the labels being associated with the statement.
11429 */
11430 NodeList<Label> get labels => _labels;
11431
11432 /**
11433 * Return the statement with which the labels are being associated.
11434 */
11435 Statement get statement => _statement;
11436
11437 /**
11438 * Set the statement with which the labels are being associated to the given
11439 * [statement].
11440 */
11441 void set statement(Statement statement) {
11442 _statement = _becomeParentOf(statement);
11443 }
11444
11445 @override
11446 Statement get unlabeled => _statement.unlabeled;
11447
11448 @override
11449 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this);
11450
11451 @override
11452 void visitChildren(AstVisitor visitor) {
11453 _labels.accept(visitor);
11454 _safelyVisitChild(_statement, visitor);
11455 }
11456 }
11457
11458 /**
11459 * A library directive.
11460 *
11461 * > libraryDirective ::=
11462 * > [Annotation] 'library' [Identifier] ';'
11463 */
11464 class LibraryDirective extends Directive {
11465 /**
11466 * The token representing the 'library' keyword.
11467 */
11468 Token libraryKeyword;
11469
11470 /**
11471 * The name of the library being defined.
11472 */
11473 LibraryIdentifier _name;
11474
11475 /**
11476 * The semicolon terminating the directive.
11477 */
11478 Token semicolon;
11479
11480 /**
11481 * Initialize a newly created library directive. Either or both of the
11482 * [comment] and [metadata] can be `null` if the directive does not have the
11483 * corresponding attribute.
11484 */
11485 LibraryDirective(Comment comment, List<Annotation> metadata,
11486 this.libraryKeyword, LibraryIdentifier name, this.semicolon)
11487 : super(comment, metadata) {
11488 _name = _becomeParentOf(name);
11489 }
11490
11491 @override
11492 Iterable get childEntities =>
11493 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon);
11494
11495 @override
11496 Token get endToken => semicolon;
11497
11498 @override
11499 Token get firstTokenAfterCommentAndMetadata => libraryKeyword;
11500
11501 @override
11502 Token get keyword => libraryKeyword;
11503
11504 /**
11505 * Return the name of the library being defined.
11506 */
11507 LibraryIdentifier get name => _name;
11508
11509 /**
11510 * Set the name of the library being defined to the given [name].
11511 */
11512 void set name(LibraryIdentifier name) {
11513 _name = _becomeParentOf(name);
11514 }
11515
11516 @override
11517 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this);
11518
11519 @override
11520 void visitChildren(AstVisitor visitor) {
11521 super.visitChildren(visitor);
11522 _safelyVisitChild(_name, visitor);
11523 }
11524 }
11525
11526 /**
11527 * The identifier for a library.
11528 *
11529 * > libraryIdentifier ::=
11530 * > [SimpleIdentifier] ('.' [SimpleIdentifier])*
11531 */
11532 class LibraryIdentifier extends Identifier {
11533 /**
11534 * The components of the identifier.
11535 */
11536 NodeList<SimpleIdentifier> _components;
11537
11538 /**
11539 * Initialize a newly created prefixed identifier.
11540 */
11541 LibraryIdentifier(List<SimpleIdentifier> components) {
11542 _components = new NodeList<SimpleIdentifier>(this, components);
11543 }
11544
11545 @override
11546 Token get beginToken => _components.beginToken;
11547
11548 @override
11549 Element get bestElement => staticElement;
11550
11551 @override
11552 // TODO(paulberry): add "." tokens.
11553 Iterable get childEntities => new ChildEntities()..addAll(_components);
11554
11555 /**
11556 * Return the components of the identifier.
11557 */
11558 NodeList<SimpleIdentifier> get components => _components;
11559
11560 @override
11561 Token get endToken => _components.endToken;
11562
11563 @override
11564 String get name {
11565 StringBuffer buffer = new StringBuffer();
11566 bool needsPeriod = false;
11567 for (SimpleIdentifier identifier in _components) {
11568 if (needsPeriod) {
11569 buffer.write(".");
11570 } else {
11571 needsPeriod = true;
11572 }
11573 buffer.write(identifier.name);
11574 }
11575 return buffer.toString();
11576 }
11577
11578 @override
11579 int get precedence => 15;
11580
11581 @override
11582 Element get propagatedElement => null;
11583
11584 @override
11585 Element get staticElement => null;
11586
11587 @override
11588 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this);
11589
11590 @override
11591 void visitChildren(AstVisitor visitor) {
11592 _components.accept(visitor);
11593 }
11594 }
11595
11596 /**
11597 * A list literal.
11598 *
11599 * > listLiteral ::=
11600 * > 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']'
11601 */
11602 class ListLiteral extends TypedLiteral {
11603 /**
11604 * The left square bracket.
11605 */
11606 Token leftBracket;
11607
11608 /**
11609 * The expressions used to compute the elements of the list.
11610 */
11611 NodeList<Expression> _elements;
11612
11613 /**
11614 * The right square bracket.
11615 */
11616 Token rightBracket;
11617
11618 /**
11619 * Initialize a newly created list literal. The [constKeyword] can be `null`
11620 * if the literal is not a constant. The [typeArguments] can be `null` if no
11621 * type arguments were declared. The list of [elements] can be `null` if the
11622 * list is empty.
11623 */
11624 ListLiteral(Token constKeyword, TypeArgumentList typeArguments,
11625 this.leftBracket, List<Expression> elements, this.rightBracket)
11626 : super(constKeyword, typeArguments) {
11627 _elements = new NodeList<Expression>(this, elements);
11628 }
11629
11630 @override
11631 Token get beginToken {
11632 if (constKeyword != null) {
11633 return constKeyword;
11634 }
11635 TypeArgumentList typeArguments = this.typeArguments;
11636 if (typeArguments != null) {
11637 return typeArguments.beginToken;
11638 }
11639 return leftBracket;
11640 }
11641
11642 @override
11643 // TODO(paulberry): add commas.
11644 Iterable get childEntities => super._childEntities
11645 ..add(leftBracket)
11646 ..addAll(_elements)
11647 ..add(rightBracket);
11648
11649 /**
11650 * Return the expressions used to compute the elements of the list.
11651 */
11652 NodeList<Expression> get elements => _elements;
11653
11654 @override
11655 Token get endToken => rightBracket;
11656
11657 @override
11658 accept(AstVisitor visitor) => visitor.visitListLiteral(this);
11659
11660 @override
11661 void visitChildren(AstVisitor visitor) {
11662 super.visitChildren(visitor);
11663 _elements.accept(visitor);
11664 }
11665 }
11666
11667 /**
11668 * A node that represents a literal expression.
11669 *
11670 * > literal ::=
11671 * > [BooleanLiteral]
11672 * > | [DoubleLiteral]
11673 * > | [IntegerLiteral]
11674 * > | [ListLiteral]
11675 * > | [MapLiteral]
11676 * > | [NullLiteral]
11677 * > | [StringLiteral]
11678 */
11679 abstract class Literal extends Expression {
11680 @override
11681 int get precedence => 16;
11682 }
11683
11684 /**
11685 * A literal map.
11686 *
11687 * > mapLiteral ::=
11688 * > 'const'? ('<' [TypeName] (',' [TypeName])* '>')?
11689 * > '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}'
11690 */
11691 class MapLiteral extends TypedLiteral {
11692 /**
11693 * The left curly bracket.
11694 */
11695 Token leftBracket;
11696
11697 /**
11698 * The entries in the map.
11699 */
11700 NodeList<MapLiteralEntry> _entries;
11701
11702 /**
11703 * The right curly bracket.
11704 */
11705 Token rightBracket;
11706
11707 /**
11708 * Initialize a newly created map literal. The [constKeyword] can be `null` if
11709 * the literal is not a constant. The [typeArguments] can be `null` if no type
11710 * arguments were declared. The [entries] can be `null` if the map is empty.
11711 */
11712 MapLiteral(Token constKeyword, TypeArgumentList typeArguments,
11713 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket)
11714 : super(constKeyword, typeArguments) {
11715 _entries = new NodeList<MapLiteralEntry>(this, entries);
11716 }
11717
11718 @override
11719 Token get beginToken {
11720 if (constKeyword != null) {
11721 return constKeyword;
11722 }
11723 TypeArgumentList typeArguments = this.typeArguments;
11724 if (typeArguments != null) {
11725 return typeArguments.beginToken;
11726 }
11727 return leftBracket;
11728 }
11729
11730 @override
11731 // TODO(paulberry): add commas.
11732 Iterable get childEntities => super._childEntities
11733 ..add(leftBracket)
11734 ..addAll(entries)
11735 ..add(rightBracket);
11736
11737 @override
11738 Token get endToken => rightBracket;
11739
11740 /**
11741 * Return the entries in the map.
11742 */
11743 NodeList<MapLiteralEntry> get entries => _entries;
11744
11745 @override
11746 accept(AstVisitor visitor) => visitor.visitMapLiteral(this);
11747
11748 @override
11749 void visitChildren(AstVisitor visitor) {
11750 super.visitChildren(visitor);
11751 _entries.accept(visitor);
11752 }
11753 }
11754
11755 /**
11756 * A single key/value pair in a map literal.
11757 *
11758 * > mapLiteralEntry ::=
11759 * > [Expression] ':' [Expression]
11760 */
11761 class MapLiteralEntry extends AstNode {
11762 /**
11763 * The expression computing the key with which the value will be associated.
11764 */
11765 Expression _key;
11766
11767 /**
11768 * The colon that separates the key from the value.
11769 */
11770 Token separator;
11771
11772 /**
11773 * The expression computing the value that will be associated with the key.
11774 */
11775 Expression _value;
11776
11777 /**
11778 * Initialize a newly created map literal entry.
11779 */
11780 MapLiteralEntry(Expression key, this.separator, Expression value) {
11781 _key = _becomeParentOf(key);
11782 _value = _becomeParentOf(value);
11783 }
11784
11785 @override
11786 Token get beginToken => _key.beginToken;
11787
11788 @override
11789 Iterable get childEntities =>
11790 new ChildEntities()..add(_key)..add(separator)..add(_value);
11791
11792 @override
11793 Token get endToken => _value.endToken;
11794
11795 /**
11796 * Return the expression computing the key with which the value will be
11797 * associated.
11798 */
11799 Expression get key => _key;
11800
11801 /**
11802 * Set the expression computing the key with which the value will be
11803 * associated to the given [string].
11804 */
11805 void set key(Expression string) {
11806 _key = _becomeParentOf(string);
11807 }
11808
11809 /**
11810 * Return the expression computing the value that will be associated with the
11811 * key.
11812 */
11813 Expression get value => _value;
11814
11815 /**
11816 * Set the expression computing the value that will be associated with the key
11817 * to the given [expression].
11818 */
11819 void set value(Expression expression) {
11820 _value = _becomeParentOf(expression);
11821 }
11822
11823 @override
11824 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this);
11825
11826 @override
11827 void visitChildren(AstVisitor visitor) {
11828 _safelyVisitChild(_key, visitor);
11829 _safelyVisitChild(_value, visitor);
11830 }
11831 }
11832
11833 /**
11834 * A method declaration.
11835 *
11836 * > methodDeclaration ::=
11837 * > methodSignature [FunctionBody]
11838 * >
11839 * > methodSignature ::=
11840 * > 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')?
11841 * > methodName [TypeParameterList] [FormalParameterList]
11842 * >
11843 * > methodName ::=
11844 * > [SimpleIdentifier]
11845 * > | 'operator' [SimpleIdentifier]
11846 */
11847 class MethodDeclaration extends ClassMember {
11848 /**
11849 * The token for the 'external' keyword, or `null` if the constructor is not
11850 * external.
11851 */
11852 Token externalKeyword;
11853
11854 /**
11855 * The token representing the 'abstract' or 'static' keyword, or `null` if
11856 * neither modifier was specified.
11857 */
11858 Token modifierKeyword;
11859
11860 /**
11861 * The return type of the method, or `null` if no return type was declared.
11862 */
11863 TypeName _returnType;
11864
11865 /**
11866 * The token representing the 'get' or 'set' keyword, or `null` if this is a
11867 * method declaration rather than a property declaration.
11868 */
11869 Token propertyKeyword;
11870
11871 /**
11872 * The token representing the 'operator' keyword, or `null` if this method
11873 * does not declare an operator.
11874 */
11875 Token operatorKeyword;
11876
11877 /**
11878 * The name of the method.
11879 */
11880 SimpleIdentifier _name;
11881
11882 /**
11883 * The type parameters associated with the method, or `null` if the method is
11884 * not a generic method.
11885 */
11886 TypeParameterList _typeParameters;
11887
11888 /**
11889 * The parameters associated with the method, or `null` if this method
11890 * declares a getter.
11891 */
11892 FormalParameterList _parameters;
11893
11894 /**
11895 * The body of the method.
11896 */
11897 FunctionBody _body;
11898
11899 /**
11900 * Initialize a newly created method declaration. Either or both of the
11901 * [comment] and [metadata] can be `null` if the declaration does not have the
11902 * corresponding attribute. The [externalKeyword] can be `null` if the method
11903 * is not external. The [modifierKeyword] can be `null` if the method is
11904 * neither abstract nor static. The [returnType] can be `null` if no return
11905 * type was specified. The [propertyKeyword] can be `null` if the method is
11906 * neither a getter or a setter. The [operatorKeyword] can be `null` if the
11907 * method does not implement an operator. The [parameters] must be `null` if
11908 * this method declares a getter.
11909 */
11910 MethodDeclaration(
11911 Comment comment,
11912 List<Annotation> metadata,
11913 this.externalKeyword,
11914 this.modifierKeyword,
11915 TypeName returnType,
11916 this.propertyKeyword,
11917 this.operatorKeyword,
11918 SimpleIdentifier name,
11919 TypeParameterList typeParameters,
11920 FormalParameterList parameters,
11921 FunctionBody body)
11922 : super(comment, metadata) {
11923 _returnType = _becomeParentOf(returnType);
11924 _name = _becomeParentOf(name);
11925 _typeParameters = _becomeParentOf(typeParameters);
11926 _parameters = _becomeParentOf(parameters);
11927 _body = _becomeParentOf(body);
11928 }
11929
11930 /**
11931 * Return the body of the method.
11932 */
11933 FunctionBody get body => _body;
11934
11935 /**
11936 * Set the body of the method to the given [functionBody].
11937 */
11938 void set body(FunctionBody functionBody) {
11939 _body = _becomeParentOf(functionBody);
11940 }
11941
11942 @override
11943 Iterable get childEntities => super._childEntities
11944 ..add(externalKeyword)
11945 ..add(modifierKeyword)
11946 ..add(_returnType)
11947 ..add(propertyKeyword)
11948 ..add(operatorKeyword)
11949 ..add(_name)
11950 ..add(_parameters)
11951 ..add(_body);
11952
11953 /**
11954 * Return the element associated with this method, or `null` if the AST
11955 * structure has not been resolved. The element can either be a
11956 * [MethodElement], if this represents the declaration of a normal method, or
11957 * a [PropertyAccessorElement] if this represents the declaration of either a
11958 * getter or a setter.
11959 */
11960 @override
11961 ExecutableElement get element =>
11962 _name != null ? (_name.staticElement as ExecutableElement) : null;
11963
11964 @override
11965 Token get endToken => _body.endToken;
11966
11967 @override
11968 Token get firstTokenAfterCommentAndMetadata {
11969 if (modifierKeyword != null) {
11970 return modifierKeyword;
11971 } else if (_returnType != null) {
11972 return _returnType.beginToken;
11973 } else if (propertyKeyword != null) {
11974 return propertyKeyword;
11975 } else if (operatorKeyword != null) {
11976 return operatorKeyword;
11977 }
11978 return _name.beginToken;
11979 }
11980
11981 /**
11982 * Return `true` if this method is declared to be an abstract method.
11983 */
11984 bool get isAbstract {
11985 FunctionBody body = _body;
11986 return externalKeyword == null &&
11987 (body is EmptyFunctionBody && !body.semicolon.isSynthetic);
11988 }
11989
11990 /**
11991 * Return `true` if this method declares a getter.
11992 */
11993 bool get isGetter =>
11994 propertyKeyword != null &&
11995 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
11996
11997 /**
11998 * Return `true` if this method declares an operator.
11999 */
12000 bool get isOperator => operatorKeyword != null;
12001
12002 /**
12003 * Return `true` if this method declares a setter.
12004 */
12005 bool get isSetter =>
12006 propertyKeyword != null &&
12007 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
12008
12009 /**
12010 * Return `true` if this method is declared to be a static method.
12011 */
12012 bool get isStatic =>
12013 modifierKeyword != null &&
12014 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC;
12015
12016 /**
12017 * Return the name of the method.
12018 */
12019 SimpleIdentifier get name => _name;
12020
12021 /**
12022 * Set the name of the method to the given [identifier].
12023 */
12024 void set name(SimpleIdentifier identifier) {
12025 _name = _becomeParentOf(identifier);
12026 }
12027
12028 /**
12029 * Return the parameters associated with the method, or `null` if this method
12030 * declares a getter.
12031 */
12032 FormalParameterList get parameters => _parameters;
12033
12034 /**
12035 * Set the parameters associated with the method to the given list of
12036 * [parameters].
12037 */
12038 void set parameters(FormalParameterList parameters) {
12039 _parameters = _becomeParentOf(parameters);
12040 }
12041
12042 /**
12043 * Return the return type of the method, or `null` if no return type was
12044 * declared.
12045 */
12046 TypeName get returnType => _returnType;
12047
12048 /**
12049 * Set the return type of the method to the given [typeName].
12050 */
12051 void set returnType(TypeName typeName) {
12052 _returnType = _becomeParentOf(typeName);
12053 }
12054
12055 /**
12056 * Return the type parameters associated with this method, or `null` if this
12057 * method is not a generic method.
12058 */
12059 TypeParameterList get typeParameters => _typeParameters;
12060
12061 /**
12062 * Set the type parameters associated with this method to the given
12063 * [typeParameters].
12064 */
12065 void set typeParameters(TypeParameterList typeParameters) {
12066 _typeParameters = _becomeParentOf(typeParameters);
12067 }
12068
12069 @override
12070 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this);
12071
12072 @override
12073 void visitChildren(AstVisitor visitor) {
12074 super.visitChildren(visitor);
12075 _safelyVisitChild(_returnType, visitor);
12076 _safelyVisitChild(_name, visitor);
12077 _safelyVisitChild(_typeParameters, visitor);
12078 _safelyVisitChild(_parameters, visitor);
12079 _safelyVisitChild(_body, visitor);
12080 }
12081 }
12082
12083 /**
12084 * The invocation of either a function or a method. Invocations of functions
12085 * resulting from evaluating an expression are represented by
12086 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are
12087 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes.
12088 *
12089 * > methodInvoction ::=
12090 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t]
12091 */
12092 class MethodInvocation extends Expression {
12093 /**
12094 * The expression producing the object on which the method is defined, or
12095 * `null` if there is no target (that is, the target is implicitly `this`).
12096 */
12097 Expression _target;
12098
12099 /**
12100 * The operator that separates the target from the method name, or `null`
12101 * if there is no target. In an ordinary method invocation this will be a
12102 * period ('.'). In a cascade section this will be the cascade operator
12103 * ('..').
12104 */
12105 Token operator;
12106
12107 /**
12108 * The name of the method being invoked.
12109 */
12110 SimpleIdentifier _methodName;
12111
12112 /**
12113 * The type arguments to be applied to the method being invoked, or `null` if
12114 * no type arguments were provided.
12115 */
12116 TypeArgumentList _typeArguments;
12117
12118 /**
12119 * The list of arguments to the method.
12120 */
12121 ArgumentList _argumentList;
12122
12123 /**
12124 * Initialize a newly created method invocation. The [target] and [operator]
12125 * can be `null` if there is no target.
12126 */
12127 MethodInvocation(
12128 Expression target,
12129 this.operator,
12130 SimpleIdentifier methodName,
12131 TypeArgumentList typeArguments,
12132 ArgumentList argumentList) {
12133 _target = _becomeParentOf(target);
12134 _methodName = _becomeParentOf(methodName);
12135 _typeArguments = _becomeParentOf(typeArguments);
12136 _argumentList = _becomeParentOf(argumentList);
12137 }
12138
12139 /**
12140 * Return the list of arguments to the method.
12141 */
12142 ArgumentList get argumentList => _argumentList;
12143
12144 /**
12145 * Set the list of arguments to the method to the given [argumentList].
12146 */
12147 void set argumentList(ArgumentList argumentList) {
12148 _argumentList = _becomeParentOf(argumentList);
12149 }
12150
12151 @override
12152 Token get beginToken {
12153 if (_target != null) {
12154 return _target.beginToken;
12155 } else if (operator != null) {
12156 return operator;
12157 }
12158 return _methodName.beginToken;
12159 }
12160
12161 @override
12162 Iterable get childEntities => new ChildEntities()
12163 ..add(_target)
12164 ..add(operator)
12165 ..add(_methodName)
12166 ..add(_argumentList);
12167
12168 @override
12169 Token get endToken => _argumentList.endToken;
12170
12171 /**
12172 * Return `true` if this expression is cascaded. If it is, then the target of
12173 * this expression is not stored locally but is stored in the nearest ancestor
12174 * that is a [CascadeExpression].
12175 */
12176 bool get isCascaded =>
12177 operator != null && operator.type == TokenType.PERIOD_PERIOD;
12178
12179 /**
12180 * Return the name of the method being invoked.
12181 */
12182 SimpleIdentifier get methodName => _methodName;
12183
12184 /**
12185 * Set the name of the method being invoked to the given [identifier].
12186 */
12187 void set methodName(SimpleIdentifier identifier) {
12188 _methodName = _becomeParentOf(identifier);
12189 }
12190
12191 @override
12192 int get precedence => 15;
12193
12194 /**
12195 * Return the expression used to compute the receiver of the invocation. If
12196 * this invocation is not part of a cascade expression, then this is the same
12197 * as [target]. If this invocation is part of a cascade expression, then the
12198 * target stored with the cascade expression is returned.
12199 */
12200 Expression get realTarget {
12201 if (isCascaded) {
12202 AstNode ancestor = parent;
12203 while (ancestor is! CascadeExpression) {
12204 if (ancestor == null) {
12205 return _target;
12206 }
12207 ancestor = ancestor.parent;
12208 }
12209 return (ancestor as CascadeExpression).target;
12210 }
12211 return _target;
12212 }
12213
12214 /**
12215 * Return the expression producing the object on which the method is defined,
12216 * or `null` if there is no target (that is, the target is implicitly `this`)
12217 * or if this method invocation is part of a cascade expression.
12218 *
12219 * Use [realTarget] to get the target independent of whether this is part of a
12220 * cascade expression.
12221 */
12222 Expression get target => _target;
12223
12224 /**
12225 * Set the expression producing the object on which the method is defined to
12226 * the given [expression].
12227 */
12228 void set target(Expression expression) {
12229 _target = _becomeParentOf(expression);
12230 }
12231
12232 /**
12233 * Return the type arguments to be applied to the method being invoked, or
12234 * `null` if no type arguments were provided.
12235 */
12236 TypeArgumentList get typeArguments => _typeArguments;
12237
12238 /**
12239 * Set the type arguments to be applied to the method being invoked to the
12240 * given [typeArguments].
12241 */
12242 void set typeArguments(TypeArgumentList typeArguments) {
12243 _typeArguments = _becomeParentOf(typeArguments);
12244 }
12245
12246 @override
12247 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this);
12248
12249 @override
12250 void visitChildren(AstVisitor visitor) {
12251 _safelyVisitChild(_target, visitor);
12252 _safelyVisitChild(_methodName, visitor);
12253 _safelyVisitChild(_typeArguments, visitor);
12254 _safelyVisitChild(_argumentList, visitor);
12255 }
12256 }
12257
12258 /**
12259 * A node that declares a single name within the scope of a compilation unit.
12260 */
12261 abstract class NamedCompilationUnitMember extends CompilationUnitMember {
12262 /**
12263 * The name of the member being declared.
12264 */
12265 SimpleIdentifier _name;
12266
12267 /**
12268 * Initialize a newly created compilation unit member with the given [name].
12269 * Either or both of the [comment] and [metadata] can be `null` if the member
12270 * does not have the corresponding attribute.
12271 */
12272 NamedCompilationUnitMember(
12273 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
12274 : super(comment, metadata) {
12275 _name = _becomeParentOf(name);
12276 }
12277
12278 /**
12279 * Return the name of the member being declared.
12280 */
12281 SimpleIdentifier get name => _name;
12282
12283 /**
12284 * Set the name of the member being declared to the given [identifier].
12285 */
12286 void set name(SimpleIdentifier identifier) {
12287 _name = _becomeParentOf(identifier);
12288 }
12289 }
12290
12291 /**
12292 * An expression that has a name associated with it. They are used in method
12293 * invocations when there are named parameters.
12294 *
12295 * > namedExpression ::=
12296 * > [Label] [Expression]
12297 */
12298 class NamedExpression extends Expression {
12299 /**
12300 * The name associated with the expression.
12301 */
12302 Label _name;
12303
12304 /**
12305 * The expression with which the name is associated.
12306 */
12307 Expression _expression;
12308
12309 /**
12310 * Initialize a newly created named expression..
12311 */
12312 NamedExpression(Label name, Expression expression) {
12313 _name = _becomeParentOf(name);
12314 _expression = _becomeParentOf(expression);
12315 }
12316
12317 @override
12318 Token get beginToken => _name.beginToken;
12319
12320 @override
12321 Iterable get childEntities =>
12322 new ChildEntities()..add(_name)..add(_expression);
12323
12324 /**
12325 * Return the element representing the parameter being named by this
12326 * expression, or `null` if the AST structure has not been resolved or if
12327 * there is no parameter with the same name as this expression.
12328 */
12329 ParameterElement get element {
12330 Element element = _name.label.staticElement;
12331 if (element is ParameterElement) {
12332 return element;
12333 }
12334 return null;
12335 }
12336
12337 @override
12338 Token get endToken => _expression.endToken;
12339
12340 /**
12341 * Return the expression with which the name is associated.
12342 */
12343 Expression get expression => _expression;
12344
12345 /**
12346 * Set the expression with which the name is associated to the given
12347 * [expression].
12348 */
12349 void set expression(Expression expression) {
12350 _expression = _becomeParentOf(expression);
12351 }
12352
12353 /**
12354 * Return the name associated with the expression.
12355 */
12356 Label get name => _name;
12357
12358 /**
12359 * Set the name associated with the expression to the given [identifier].
12360 */
12361 void set name(Label identifier) {
12362 _name = _becomeParentOf(identifier);
12363 }
12364
12365 @override
12366 int get precedence => 0;
12367
12368 @override
12369 accept(AstVisitor visitor) => visitor.visitNamedExpression(this);
12370
12371 @override
12372 void visitChildren(AstVisitor visitor) {
12373 _safelyVisitChild(_name, visitor);
12374 _safelyVisitChild(_expression, visitor);
12375 }
12376 }
12377
12378 /**
12379 * A node that represents a directive that impacts the namespace of a library.
12380 *
12381 * > directive ::=
12382 * > [ExportDirective]
12383 * > | [ImportDirective]
12384 */
12385 abstract class NamespaceDirective extends UriBasedDirective {
12386 /**
12387 * The token representing the 'import' or 'export' keyword.
12388 */
12389 Token keyword;
12390
12391 /**
12392 * The configurations used to control which library will actually be loaded at
12393 * run-time.
12394 */
12395 NodeList<Configuration> _configurations;
12396
12397 /**
12398 * The combinators used to control which names are imported or exported.
12399 */
12400 NodeList<Combinator> _combinators;
12401
12402 /**
12403 * The semicolon terminating the directive.
12404 */
12405 Token semicolon;
12406
12407 /**
12408 * Initialize a newly created namespace directive. Either or both of the
12409 * [comment] and [metadata] can be `null` if the directive does not have the
12410 * corresponding attribute. The list of [combinators] can be `null` if there
12411 * are no combinators.
12412 */
12413 NamespaceDirective(
12414 Comment comment,
12415 List<Annotation> metadata,
12416 this.keyword,
12417 StringLiteral libraryUri,
12418 List<Configuration> configurations,
12419 List<Combinator> combinators,
12420 this.semicolon)
12421 : super(comment, metadata, libraryUri) {
12422 _configurations = new NodeList<Configuration>(this, configurations);
12423 _combinators = new NodeList<Combinator>(this, combinators);
12424 }
12425
12426 /**
12427 * Return the combinators used to control how names are imported or exported.
12428 */
12429 NodeList<Combinator> get combinators => _combinators;
12430
12431 /**
12432 * Return the configurations used to control which library will actually be
12433 * loaded at run-time.
12434 */
12435 NodeList<Configuration> get configurations => _configurations;
12436
12437 @override
12438 Token get endToken => semicolon;
12439
12440 @override
12441 Token get firstTokenAfterCommentAndMetadata => keyword;
12442
12443 @override
12444 LibraryElement get uriElement;
12445 }
12446
12447 /**
12448 * The "native" clause in an class declaration.
12449 *
12450 * > nativeClause ::=
12451 * > 'native' [StringLiteral]
12452 */
12453 class NativeClause extends AstNode {
12454 /**
12455 * The token representing the 'native' keyword.
12456 */
12457 Token nativeKeyword;
12458
12459 /**
12460 * The name of the native object that implements the class.
12461 */
12462 StringLiteral _name;
12463
12464 /**
12465 * Initialize a newly created native clause.
12466 */
12467 NativeClause(this.nativeKeyword, StringLiteral name) {
12468 _name = _becomeParentOf(name);
12469 }
12470
12471 @override
12472 Token get beginToken => nativeKeyword;
12473
12474 @override
12475 Iterable get childEntities =>
12476 new ChildEntities()..add(nativeKeyword)..add(_name);
12477
12478 @override
12479 Token get endToken => _name.endToken;
12480
12481 /**
12482 * Return the name of the native object that implements the class.
12483 */
12484 StringLiteral get name => _name;
12485
12486 /**
12487 * Set the name of the native object that implements the class to the given
12488 * [name].
12489 */
12490 void set name(StringLiteral name) {
12491 _name = _becomeParentOf(name);
12492 }
12493
12494 @override
12495 accept(AstVisitor visitor) => visitor.visitNativeClause(this);
12496
12497 @override
12498 void visitChildren(AstVisitor visitor) {
12499 _safelyVisitChild(_name, visitor);
12500 }
12501 }
12502
12503 /**
12504 * A function body that consists of a native keyword followed by a string
12505 * literal.
12506 *
12507 * > nativeFunctionBody ::=
12508 * > 'native' [SimpleStringLiteral] ';'
12509 */
12510 class NativeFunctionBody extends FunctionBody {
12511 /**
12512 * The token representing 'native' that marks the start of the function body.
12513 */
12514 Token nativeKeyword;
12515
12516 /**
12517 * The string literal, after the 'native' token.
12518 */
12519 StringLiteral _stringLiteral;
12520
12521 /**
12522 * The token representing the semicolon that marks the end of the function
12523 * body.
12524 */
12525 Token semicolon;
12526
12527 /**
12528 * Initialize a newly created function body consisting of the 'native' token,
12529 * a string literal, and a semicolon.
12530 */
12531 NativeFunctionBody(
12532 this.nativeKeyword, StringLiteral stringLiteral, this.semicolon) {
12533 _stringLiteral = _becomeParentOf(stringLiteral);
12534 }
12535
12536 @override
12537 Token get beginToken => nativeKeyword;
12538
12539 @override
12540 Iterable get childEntities => new ChildEntities()
12541 ..add(nativeKeyword)
12542 ..add(_stringLiteral)
12543 ..add(semicolon);
12544
12545 @override
12546 Token get endToken => semicolon;
12547
12548 /**
12549 * Return the string literal representing the string after the 'native' token.
12550 */
12551 StringLiteral get stringLiteral => _stringLiteral;
12552
12553 /**
12554 * Set the string literal representing the string after the 'native' token to
12555 * the given [stringLiteral].
12556 */
12557 void set stringLiteral(StringLiteral stringLiteral) {
12558 _stringLiteral = _becomeParentOf(stringLiteral);
12559 }
12560
12561 @override
12562 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this);
12563
12564 @override
12565 void visitChildren(AstVisitor visitor) {
12566 _safelyVisitChild(_stringLiteral, visitor);
12567 }
12568 }
12569
12570 /**
12571 * A list of AST nodes that have a common parent.
12572 */
12573 class NodeList<E extends AstNode> extends Object with ListMixin<E> {
12574 /**
12575 * The node that is the parent of each of the elements in the list.
12576 */
12577 AstNode owner;
12578
12579 /**
12580 * The elements contained in the list.
12581 */
12582 List<E> _elements = <E>[];
12583
12584 /**
12585 * Initialize a newly created list of nodes such that all of the nodes that
12586 * are added to the list will have their parent set to the given [owner]. The
12587 * list will initially be populated with the given [elements].
12588 */
12589 NodeList(this.owner, [List<E> elements]) {
12590 addAll(elements);
12591 }
12592
12593 /**
12594 * Return the first token included in this node list's source range, or `null`
12595 * if the list is empty.
12596 */
12597 Token get beginToken {
12598 if (_elements.length == 0) {
12599 return null;
12600 }
12601 return _elements[0].beginToken;
12602 }
12603
12604 /**
12605 * Return the last token included in this node list's source range, or `null`
12606 * if the list is empty.
12607 */
12608 Token get endToken {
12609 int length = _elements.length;
12610 if (length == 0) {
12611 return null;
12612 }
12613 return _elements[length - 1].endToken;
12614 }
12615
12616 int get length => _elements.length;
12617
12618 @deprecated // Never intended for public use.
12619 @override
12620 void set length(int newLength) {
12621 throw new UnsupportedError("Cannot resize NodeList.");
12622 }
12623
12624 E operator [](int index) {
12625 if (index < 0 || index >= _elements.length) {
12626 throw new RangeError("Index: $index, Size: ${_elements.length}");
12627 }
12628 return _elements[index];
12629 }
12630
12631 void operator []=(int index, E node) {
12632 if (index < 0 || index >= _elements.length) {
12633 throw new RangeError("Index: $index, Size: ${_elements.length}");
12634 }
12635 owner._becomeParentOf(node);
12636 _elements[index] = node;
12637 }
12638
12639 /**
12640 * Use the given [visitor] to visit each of the nodes in this list.
12641 */
12642 accept(AstVisitor visitor) {
12643 int length = _elements.length;
12644 for (var i = 0; i < length; i++) {
12645 _elements[i].accept(visitor);
12646 }
12647 }
12648
12649 @override
12650 void add(E node) {
12651 insert(length, node);
12652 }
12653
12654 @override
12655 bool addAll(Iterable<E> nodes) {
12656 if (nodes != null && !nodes.isEmpty) {
12657 _elements.addAll(nodes);
12658 for (E node in nodes) {
12659 owner._becomeParentOf(node);
12660 }
12661 return true;
12662 }
12663 return false;
12664 }
12665
12666 @override
12667 void clear() {
12668 _elements = <E>[];
12669 }
12670
12671 @override
12672 void insert(int index, E node) {
12673 int length = _elements.length;
12674 if (index < 0 || index > length) {
12675 throw new RangeError("Index: $index, Size: ${_elements.length}");
12676 }
12677 owner._becomeParentOf(node);
12678 if (length == 0) {
12679 _elements.add(node);
12680 } else {
12681 _elements.insert(index, node);
12682 }
12683 }
12684
12685 @override
12686 E removeAt(int index) {
12687 if (index < 0 || index >= _elements.length) {
12688 throw new RangeError("Index: $index, Size: ${_elements.length}");
12689 }
12690 E removedNode = _elements[index];
12691 _elements.removeAt(index);
12692 return removedNode;
12693 }
12694 }
12695
12696 /**
12697 * An object used to locate the [AstNode] associated with a source range, given
12698 * the AST structure built from the source. More specifically, they will return
12699 * the [AstNode] with the shortest length whose source range completely
12700 * encompasses the specified range.
12701 */
12702 class NodeLocator extends UnifyingAstVisitor<Object> {
12703 /**
12704 * The start offset of the range used to identify the node.
12705 */
12706 int _startOffset = 0;
12707
12708 /**
12709 * The end offset of the range used to identify the node.
12710 */
12711 int _endOffset = 0;
12712
12713 /**
12714 * The element that was found that corresponds to the given source range, or
12715 * `null` if there is no such element.
12716 */
12717 AstNode _foundNode;
12718
12719 /**
12720 * Initialize a newly created locator to locate an [AstNode] by locating the
12721 * node within an AST structure that corresponds to the given range of
12722 * characters (between the [startOffset] and [endOffset] in the source.
12723 */
12724 NodeLocator(int startOffset, [int endOffset])
12725 : this._startOffset = startOffset,
12726 this._endOffset = endOffset == null ? startOffset : endOffset;
12727
12728 /**
12729 * Return the node that was found that corresponds to the given source range
12730 * or `null` if there is no such node.
12731 */
12732 AstNode get foundNode => _foundNode;
12733
12734 /**
12735 * Search within the given AST [node] for an identifier representing an
12736 * element in the specified source range. Return the element that was found,
12737 * or `null` if no element was found.
12738 */
12739 AstNode searchWithin(AstNode node) {
12740 if (node == null) {
12741 return null;
12742 }
12743 try {
12744 node.accept(this);
12745 } on NodeLocator_NodeFoundException {
12746 // A node with the right source position was found.
12747 } catch (exception, stackTrace) {
12748 AnalysisEngine.instance.logger.logInformation(
12749 "Unable to locate element at offset ($_startOffset - $_endOffset)",
12750 new CaughtException(exception, stackTrace));
12751 return null;
12752 }
12753 return _foundNode;
12754 }
12755
12756 @override
12757 Object visitNode(AstNode node) {
12758 Token beginToken = node.beginToken;
12759 Token endToken = node.endToken;
12760 // Don't include synthetic tokens.
12761 while (endToken != beginToken) {
12762 if (endToken.type == TokenType.EOF || !endToken.isSynthetic) {
12763 break;
12764 }
12765 endToken = endToken.previous;
12766 }
12767 int end = endToken.end;
12768 int start = node.offset;
12769 if (end < _startOffset) {
12770 return null;
12771 }
12772 if (start > _endOffset) {
12773 return null;
12774 }
12775 try {
12776 node.visitChildren(this);
12777 } on NodeLocator_NodeFoundException {
12778 rethrow;
12779 } catch (exception, stackTrace) {
12780 // Ignore the exception and proceed in order to visit the rest of the
12781 // structure.
12782 AnalysisEngine.instance.logger.logInformation(
12783 "Exception caught while traversing an AST structure.",
12784 new CaughtException(exception, stackTrace));
12785 }
12786 if (start <= _startOffset && _endOffset <= end) {
12787 _foundNode = node;
12788 throw new NodeLocator_NodeFoundException();
12789 }
12790 return null;
12791 }
12792 }
12793
12794 /**
12795 * An object used to locate the [AstNode] associated with a source range.
12796 * More specifically, they will return the deepest [AstNode] which completely
12797 * encompasses the specified range.
12798 */
12799 class NodeLocator2 extends UnifyingAstVisitor<Object> {
12800 /**
12801 * The inclusive start offset of the range used to identify the node.
12802 */
12803 int _startOffset = 0;
12804
12805 /**
12806 * The inclusive end offset of the range used to identify the node.
12807 */
12808 int _endOffset = 0;
12809
12810 /**
12811 * The found node or `null` if there is no such node.
12812 */
12813 AstNode _foundNode;
12814
12815 /**
12816 * Initialize a newly created locator to locate the deepest [AstNode] for
12817 * which `node.offset <= [startOffset]` and `[endOffset] < node.end`.
12818 *
12819 * If [endOffset] is not provided, then it is considered the same as the
12820 * given [startOffset].
12821 */
12822 NodeLocator2(int startOffset, [int endOffset])
12823 : this._startOffset = startOffset,
12824 this._endOffset = endOffset == null ? startOffset : endOffset;
12825
12826 /**
12827 * Search within the given AST [node] and return the node that was found,
12828 * or `null` if no node was found.
12829 */
12830 AstNode searchWithin(AstNode node) {
12831 if (node == null) {
12832 return null;
12833 }
12834 try {
12835 node.accept(this);
12836 } on NodeLocator_NodeFoundException {} catch (exception, stackTrace) {
12837 AnalysisEngine.instance.logger.logInformation(
12838 "Unable to locate element at offset ($_startOffset - $_endOffset)",
12839 new CaughtException(exception, stackTrace));
12840 return null;
12841 }
12842 return _foundNode;
12843 }
12844
12845 @override
12846 Object visitNode(AstNode node) {
12847 Token beginToken = node.beginToken;
12848 Token endToken = node.endToken;
12849 // Don't include synthetic tokens.
12850 while (endToken != beginToken) {
12851 if (endToken.type == TokenType.EOF || !endToken.isSynthetic) {
12852 break;
12853 }
12854 endToken = endToken.previous;
12855 }
12856 int end = endToken.end;
12857 int start = node.offset;
12858 if (end <= _startOffset) {
12859 return null;
12860 }
12861 if (start > _endOffset) {
12862 return null;
12863 }
12864 try {
12865 node.visitChildren(this);
12866 } on NodeLocator_NodeFoundException {
12867 rethrow;
12868 } catch (exception, stackTrace) {
12869 // Ignore the exception and proceed in order to visit the rest of the
12870 // structure.
12871 AnalysisEngine.instance.logger.logInformation(
12872 "Exception caught while traversing an AST structure.",
12873 new CaughtException(exception, stackTrace));
12874 }
12875 if (start <= _startOffset && _endOffset < end) {
12876 _foundNode = node;
12877 throw new NodeLocator_NodeFoundException();
12878 }
12879 return null;
12880 }
12881 }
12882
12883 /**
12884 * An exception used by [NodeLocator] to cancel visiting after a node has been
12885 * found.
12886 */
12887 class NodeLocator_NodeFoundException extends RuntimeException {}
12888
12889 /**
12890 * An object that will replace one child node in an AST node with another node.
12891 */
12892 class NodeReplacer implements AstVisitor<bool> {
12893 /**
12894 * The node being replaced.
12895 */
12896 final AstNode _oldNode;
12897
12898 /**
12899 * The node that is replacing the old node.
12900 */
12901 final AstNode _newNode;
12902
12903 /**
12904 * Initialize a newly created node locator to replace the [_oldNode] with the
12905 * [_newNode].
12906 */
12907 NodeReplacer(this._oldNode, this._newNode);
12908
12909 @override
12910 bool visitAdjacentStrings(AdjacentStrings node) {
12911 if (_replaceInList(node.strings)) {
12912 return true;
12913 }
12914 return visitNode(node);
12915 }
12916
12917 bool visitAnnotatedNode(AnnotatedNode node) {
12918 if (identical(node.documentationComment, _oldNode)) {
12919 node.documentationComment = _newNode as Comment;
12920 return true;
12921 } else if (_replaceInList(node.metadata)) {
12922 return true;
12923 }
12924 return visitNode(node);
12925 }
12926
12927 @override
12928 bool visitAnnotation(Annotation node) {
12929 if (identical(node.arguments, _oldNode)) {
12930 node.arguments = _newNode as ArgumentList;
12931 return true;
12932 } else if (identical(node.constructorName, _oldNode)) {
12933 node.constructorName = _newNode as SimpleIdentifier;
12934 return true;
12935 } else if (identical(node.name, _oldNode)) {
12936 node.name = _newNode as Identifier;
12937 return true;
12938 }
12939 return visitNode(node);
12940 }
12941
12942 @override
12943 bool visitArgumentList(ArgumentList node) {
12944 if (_replaceInList(node.arguments)) {
12945 return true;
12946 }
12947 return visitNode(node);
12948 }
12949
12950 @override
12951 bool visitAsExpression(AsExpression node) {
12952 if (identical(node.expression, _oldNode)) {
12953 node.expression = _newNode as Expression;
12954 return true;
12955 } else if (identical(node.type, _oldNode)) {
12956 node.type = _newNode as TypeName;
12957 return true;
12958 }
12959 return visitNode(node);
12960 }
12961
12962 @override
12963 bool visitAssertStatement(AssertStatement node) {
12964 if (identical(node.condition, _oldNode)) {
12965 node.condition = _newNode as Expression;
12966 return true;
12967 }
12968 if (identical(node._message, _oldNode)) {
12969 node.message = _newNode as Expression;
12970 return true;
12971 }
12972 return visitNode(node);
12973 }
12974
12975 @override
12976 bool visitAssignmentExpression(AssignmentExpression node) {
12977 if (identical(node.leftHandSide, _oldNode)) {
12978 node.leftHandSide = _newNode as Expression;
12979 return true;
12980 } else if (identical(node.rightHandSide, _oldNode)) {
12981 node.rightHandSide = _newNode as Expression;
12982 return true;
12983 }
12984 return visitNode(node);
12985 }
12986
12987 @override
12988 bool visitAwaitExpression(AwaitExpression node) {
12989 if (identical(node.expression, _oldNode)) {
12990 node.expression = _newNode as Expression;
12991 return true;
12992 }
12993 return visitNode(node);
12994 }
12995
12996 @override
12997 bool visitBinaryExpression(BinaryExpression node) {
12998 if (identical(node.leftOperand, _oldNode)) {
12999 node.leftOperand = _newNode as Expression;
13000 return true;
13001 } else if (identical(node.rightOperand, _oldNode)) {
13002 node.rightOperand = _newNode as Expression;
13003 return true;
13004 }
13005 return visitNode(node);
13006 }
13007
13008 @override
13009 bool visitBlock(Block node) {
13010 if (_replaceInList(node.statements)) {
13011 return true;
13012 }
13013 return visitNode(node);
13014 }
13015
13016 @override
13017 bool visitBlockFunctionBody(BlockFunctionBody node) {
13018 if (identical(node.block, _oldNode)) {
13019 node.block = _newNode as Block;
13020 return true;
13021 }
13022 return visitNode(node);
13023 }
13024
13025 @override
13026 bool visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
13027
13028 @override
13029 bool visitBreakStatement(BreakStatement node) {
13030 if (identical(node.label, _oldNode)) {
13031 node.label = _newNode as SimpleIdentifier;
13032 return true;
13033 }
13034 return visitNode(node);
13035 }
13036
13037 @override
13038 bool visitCascadeExpression(CascadeExpression node) {
13039 if (identical(node.target, _oldNode)) {
13040 node.target = _newNode as Expression;
13041 return true;
13042 } else if (_replaceInList(node.cascadeSections)) {
13043 return true;
13044 }
13045 return visitNode(node);
13046 }
13047
13048 @override
13049 bool visitCatchClause(CatchClause node) {
13050 if (identical(node.exceptionType, _oldNode)) {
13051 node.exceptionType = _newNode as TypeName;
13052 return true;
13053 } else if (identical(node.exceptionParameter, _oldNode)) {
13054 node.exceptionParameter = _newNode as SimpleIdentifier;
13055 return true;
13056 } else if (identical(node.stackTraceParameter, _oldNode)) {
13057 node.stackTraceParameter = _newNode as SimpleIdentifier;
13058 return true;
13059 }
13060 return visitNode(node);
13061 }
13062
13063 @override
13064 bool visitClassDeclaration(ClassDeclaration node) {
13065 if (identical(node.name, _oldNode)) {
13066 node.name = _newNode as SimpleIdentifier;
13067 return true;
13068 } else if (identical(node.typeParameters, _oldNode)) {
13069 node.typeParameters = _newNode as TypeParameterList;
13070 return true;
13071 } else if (identical(node.extendsClause, _oldNode)) {
13072 node.extendsClause = _newNode as ExtendsClause;
13073 return true;
13074 } else if (identical(node.withClause, _oldNode)) {
13075 node.withClause = _newNode as WithClause;
13076 return true;
13077 } else if (identical(node.implementsClause, _oldNode)) {
13078 node.implementsClause = _newNode as ImplementsClause;
13079 return true;
13080 } else if (identical(node.nativeClause, _oldNode)) {
13081 node.nativeClause = _newNode as NativeClause;
13082 return true;
13083 } else if (_replaceInList(node.members)) {
13084 return true;
13085 }
13086 return visitAnnotatedNode(node);
13087 }
13088
13089 @override
13090 bool visitClassTypeAlias(ClassTypeAlias node) {
13091 if (identical(node.name, _oldNode)) {
13092 node.name = _newNode as SimpleIdentifier;
13093 return true;
13094 } else if (identical(node.typeParameters, _oldNode)) {
13095 node.typeParameters = _newNode as TypeParameterList;
13096 return true;
13097 } else if (identical(node.superclass, _oldNode)) {
13098 node.superclass = _newNode as TypeName;
13099 return true;
13100 } else if (identical(node.withClause, _oldNode)) {
13101 node.withClause = _newNode as WithClause;
13102 return true;
13103 } else if (identical(node.implementsClause, _oldNode)) {
13104 node.implementsClause = _newNode as ImplementsClause;
13105 return true;
13106 }
13107 return visitAnnotatedNode(node);
13108 }
13109
13110 @override
13111 bool visitComment(Comment node) {
13112 if (_replaceInList(node.references)) {
13113 return true;
13114 }
13115 return visitNode(node);
13116 }
13117
13118 @override
13119 bool visitCommentReference(CommentReference node) {
13120 if (identical(node.identifier, _oldNode)) {
13121 node.identifier = _newNode as Identifier;
13122 return true;
13123 }
13124 return visitNode(node);
13125 }
13126
13127 @override
13128 bool visitCompilationUnit(CompilationUnit node) {
13129 if (identical(node.scriptTag, _oldNode)) {
13130 node.scriptTag = _newNode as ScriptTag;
13131 return true;
13132 } else if (_replaceInList(node.directives)) {
13133 return true;
13134 } else if (_replaceInList(node.declarations)) {
13135 return true;
13136 }
13137 return visitNode(node);
13138 }
13139
13140 @override
13141 bool visitConditionalExpression(ConditionalExpression node) {
13142 if (identical(node.condition, _oldNode)) {
13143 node.condition = _newNode as Expression;
13144 return true;
13145 } else if (identical(node.thenExpression, _oldNode)) {
13146 node.thenExpression = _newNode as Expression;
13147 return true;
13148 } else if (identical(node.elseExpression, _oldNode)) {
13149 node.elseExpression = _newNode as Expression;
13150 return true;
13151 }
13152 return visitNode(node);
13153 }
13154
13155 @override
13156 bool visitConfiguration(Configuration node) {
13157 if (identical(node.name, _oldNode)) {
13158 node.name = _newNode as DottedName;
13159 return true;
13160 } else if (identical(node.value, _oldNode)) {
13161 node.value = _newNode as StringLiteral;
13162 return true;
13163 } else if (identical(node.libraryUri, _oldNode)) {
13164 node.libraryUri = _newNode as StringLiteral;
13165 return true;
13166 }
13167 return visitNode(node);
13168 }
13169
13170 @override
13171 bool visitConstructorDeclaration(ConstructorDeclaration node) {
13172 if (identical(node.returnType, _oldNode)) {
13173 node.returnType = _newNode as Identifier;
13174 return true;
13175 } else if (identical(node.name, _oldNode)) {
13176 node.name = _newNode as SimpleIdentifier;
13177 return true;
13178 } else if (identical(node.parameters, _oldNode)) {
13179 node.parameters = _newNode as FormalParameterList;
13180 return true;
13181 } else if (identical(node.redirectedConstructor, _oldNode)) {
13182 node.redirectedConstructor = _newNode as ConstructorName;
13183 return true;
13184 } else if (identical(node.body, _oldNode)) {
13185 node.body = _newNode as FunctionBody;
13186 return true;
13187 } else if (_replaceInList(node.initializers)) {
13188 return true;
13189 }
13190 return visitAnnotatedNode(node);
13191 }
13192
13193 @override
13194 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
13195 if (identical(node.fieldName, _oldNode)) {
13196 node.fieldName = _newNode as SimpleIdentifier;
13197 return true;
13198 } else if (identical(node.expression, _oldNode)) {
13199 node.expression = _newNode as Expression;
13200 return true;
13201 }
13202 return visitNode(node);
13203 }
13204
13205 @override
13206 bool visitConstructorName(ConstructorName node) {
13207 if (identical(node.type, _oldNode)) {
13208 node.type = _newNode as TypeName;
13209 return true;
13210 } else if (identical(node.name, _oldNode)) {
13211 node.name = _newNode as SimpleIdentifier;
13212 return true;
13213 }
13214 return visitNode(node);
13215 }
13216
13217 @override
13218 bool visitContinueStatement(ContinueStatement node) {
13219 if (identical(node.label, _oldNode)) {
13220 node.label = _newNode as SimpleIdentifier;
13221 return true;
13222 }
13223 return visitNode(node);
13224 }
13225
13226 @override
13227 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
13228 if (identical(node.type, _oldNode)) {
13229 node.type = _newNode as TypeName;
13230 return true;
13231 } else if (identical(node.identifier, _oldNode)) {
13232 node.identifier = _newNode as SimpleIdentifier;
13233 return true;
13234 }
13235 return visitAnnotatedNode(node);
13236 }
13237
13238 @override
13239 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
13240 if (identical(node.parameter, _oldNode)) {
13241 node.parameter = _newNode as NormalFormalParameter;
13242 return true;
13243 } else if (identical(node.defaultValue, _oldNode)) {
13244 node.defaultValue = _newNode as Expression;
13245 return true;
13246 }
13247 return visitNode(node);
13248 }
13249
13250 @override
13251 bool visitDoStatement(DoStatement node) {
13252 if (identical(node.body, _oldNode)) {
13253 node.body = _newNode as Statement;
13254 return true;
13255 } else if (identical(node.condition, _oldNode)) {
13256 node.condition = _newNode as Expression;
13257 return true;
13258 }
13259 return visitNode(node);
13260 }
13261
13262 @override
13263 bool visitDottedName(DottedName node) {
13264 if (_replaceInList(node.components)) {
13265 return true;
13266 }
13267 return visitNode(node);
13268 }
13269
13270 @override
13271 bool visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
13272
13273 @override
13274 bool visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
13275
13276 @override
13277 bool visitEmptyStatement(EmptyStatement node) => visitNode(node);
13278
13279 @override
13280 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
13281 if (identical(node.name, _oldNode)) {
13282 node.name = _newNode as SimpleIdentifier;
13283 return true;
13284 }
13285 return visitAnnotatedNode(node);
13286 }
13287
13288 @override
13289 bool visitEnumDeclaration(EnumDeclaration node) {
13290 if (identical(node.name, _oldNode)) {
13291 node.name = _newNode as SimpleIdentifier;
13292 return true;
13293 } else if (_replaceInList(node.constants)) {
13294 return true;
13295 }
13296 return visitAnnotatedNode(node);
13297 }
13298
13299 @override
13300 bool visitExportDirective(ExportDirective node) =>
13301 visitNamespaceDirective(node);
13302
13303 @override
13304 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
13305 if (identical(node.expression, _oldNode)) {
13306 node.expression = _newNode as Expression;
13307 return true;
13308 }
13309 return visitNode(node);
13310 }
13311
13312 @override
13313 bool visitExpressionStatement(ExpressionStatement node) {
13314 if (identical(node.expression, _oldNode)) {
13315 node.expression = _newNode as Expression;
13316 return true;
13317 }
13318 return visitNode(node);
13319 }
13320
13321 @override
13322 bool visitExtendsClause(ExtendsClause node) {
13323 if (identical(node.superclass, _oldNode)) {
13324 node.superclass = _newNode as TypeName;
13325 return true;
13326 }
13327 return visitNode(node);
13328 }
13329
13330 @override
13331 bool visitFieldDeclaration(FieldDeclaration node) {
13332 if (identical(node.fields, _oldNode)) {
13333 node.fields = _newNode as VariableDeclarationList;
13334 return true;
13335 }
13336 return visitAnnotatedNode(node);
13337 }
13338
13339 @override
13340 bool visitFieldFormalParameter(FieldFormalParameter node) {
13341 if (identical(node.type, _oldNode)) {
13342 node.type = _newNode as TypeName;
13343 return true;
13344 } else if (identical(node.parameters, _oldNode)) {
13345 node.parameters = _newNode as FormalParameterList;
13346 return true;
13347 }
13348 return visitNormalFormalParameter(node);
13349 }
13350
13351 @override
13352 bool visitForEachStatement(ForEachStatement node) {
13353 if (identical(node.loopVariable, _oldNode)) {
13354 node.loopVariable = _newNode as DeclaredIdentifier;
13355 return true;
13356 } else if (identical(node.identifier, _oldNode)) {
13357 node.identifier = _newNode as SimpleIdentifier;
13358 return true;
13359 } else if (identical(node.iterable, _oldNode)) {
13360 node.iterable = _newNode as Expression;
13361 return true;
13362 } else if (identical(node.body, _oldNode)) {
13363 node.body = _newNode as Statement;
13364 return true;
13365 }
13366 return visitNode(node);
13367 }
13368
13369 @override
13370 bool visitFormalParameterList(FormalParameterList node) {
13371 if (_replaceInList(node.parameters)) {
13372 return true;
13373 }
13374 return visitNode(node);
13375 }
13376
13377 @override
13378 bool visitForStatement(ForStatement node) {
13379 if (identical(node.variables, _oldNode)) {
13380 node.variables = _newNode as VariableDeclarationList;
13381 return true;
13382 } else if (identical(node.initialization, _oldNode)) {
13383 node.initialization = _newNode as Expression;
13384 return true;
13385 } else if (identical(node.condition, _oldNode)) {
13386 node.condition = _newNode as Expression;
13387 return true;
13388 } else if (identical(node.body, _oldNode)) {
13389 node.body = _newNode as Statement;
13390 return true;
13391 } else if (_replaceInList(node.updaters)) {
13392 return true;
13393 }
13394 return visitNode(node);
13395 }
13396
13397 @override
13398 bool visitFunctionDeclaration(FunctionDeclaration node) {
13399 if (identical(node.returnType, _oldNode)) {
13400 node.returnType = _newNode as TypeName;
13401 return true;
13402 } else if (identical(node.name, _oldNode)) {
13403 node.name = _newNode as SimpleIdentifier;
13404 return true;
13405 } else if (identical(node.functionExpression, _oldNode)) {
13406 node.functionExpression = _newNode as FunctionExpression;
13407 return true;
13408 }
13409 return visitAnnotatedNode(node);
13410 }
13411
13412 @override
13413 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
13414 if (identical(node.functionDeclaration, _oldNode)) {
13415 node.functionDeclaration = _newNode as FunctionDeclaration;
13416 return true;
13417 }
13418 return visitNode(node);
13419 }
13420
13421 @override
13422 bool visitFunctionExpression(FunctionExpression node) {
13423 if (identical(node.parameters, _oldNode)) {
13424 node.parameters = _newNode as FormalParameterList;
13425 return true;
13426 } else if (identical(node.body, _oldNode)) {
13427 node.body = _newNode as FunctionBody;
13428 return true;
13429 }
13430 return visitNode(node);
13431 }
13432
13433 @override
13434 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
13435 if (identical(node.function, _oldNode)) {
13436 node.function = _newNode as Expression;
13437 return true;
13438 } else if (identical(node.argumentList, _oldNode)) {
13439 node.argumentList = _newNode as ArgumentList;
13440 return true;
13441 }
13442 return visitNode(node);
13443 }
13444
13445 @override
13446 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
13447 if (identical(node.returnType, _oldNode)) {
13448 node.returnType = _newNode as TypeName;
13449 return true;
13450 } else if (identical(node.name, _oldNode)) {
13451 node.name = _newNode as SimpleIdentifier;
13452 return true;
13453 } else if (identical(node.typeParameters, _oldNode)) {
13454 node.typeParameters = _newNode as TypeParameterList;
13455 return true;
13456 } else if (identical(node.parameters, _oldNode)) {
13457 node.parameters = _newNode as FormalParameterList;
13458 return true;
13459 }
13460 return visitAnnotatedNode(node);
13461 }
13462
13463 @override
13464 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
13465 if (identical(node.returnType, _oldNode)) {
13466 node.returnType = _newNode as TypeName;
13467 return true;
13468 } else if (identical(node.parameters, _oldNode)) {
13469 node.parameters = _newNode as FormalParameterList;
13470 return true;
13471 }
13472 return visitNormalFormalParameter(node);
13473 }
13474
13475 @override
13476 bool visitHideCombinator(HideCombinator node) {
13477 if (_replaceInList(node.hiddenNames)) {
13478 return true;
13479 }
13480 return visitNode(node);
13481 }
13482
13483 @override
13484 bool visitIfStatement(IfStatement node) {
13485 if (identical(node.condition, _oldNode)) {
13486 node.condition = _newNode as Expression;
13487 return true;
13488 } else if (identical(node.thenStatement, _oldNode)) {
13489 node.thenStatement = _newNode as Statement;
13490 return true;
13491 } else if (identical(node.elseStatement, _oldNode)) {
13492 node.elseStatement = _newNode as Statement;
13493 return true;
13494 }
13495 return visitNode(node);
13496 }
13497
13498 @override
13499 bool visitImplementsClause(ImplementsClause node) {
13500 if (_replaceInList(node.interfaces)) {
13501 return true;
13502 }
13503 return visitNode(node);
13504 }
13505
13506 @override
13507 bool visitImportDirective(ImportDirective node) {
13508 if (identical(node.prefix, _oldNode)) {
13509 node.prefix = _newNode as SimpleIdentifier;
13510 return true;
13511 }
13512 return visitNamespaceDirective(node);
13513 }
13514
13515 @override
13516 bool visitIndexExpression(IndexExpression node) {
13517 if (identical(node.target, _oldNode)) {
13518 node.target = _newNode as Expression;
13519 return true;
13520 } else if (identical(node.index, _oldNode)) {
13521 node.index = _newNode as Expression;
13522 return true;
13523 }
13524 return visitNode(node);
13525 }
13526
13527 @override
13528 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
13529 if (identical(node.constructorName, _oldNode)) {
13530 node.constructorName = _newNode as ConstructorName;
13531 return true;
13532 } else if (identical(node.argumentList, _oldNode)) {
13533 node.argumentList = _newNode as ArgumentList;
13534 return true;
13535 }
13536 return visitNode(node);
13537 }
13538
13539 @override
13540 bool visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
13541
13542 @override
13543 bool visitInterpolationExpression(InterpolationExpression node) {
13544 if (identical(node.expression, _oldNode)) {
13545 node.expression = _newNode as Expression;
13546 return true;
13547 }
13548 return visitNode(node);
13549 }
13550
13551 @override
13552 bool visitInterpolationString(InterpolationString node) => visitNode(node);
13553
13554 @override
13555 bool visitIsExpression(IsExpression node) {
13556 if (identical(node.expression, _oldNode)) {
13557 node.expression = _newNode as Expression;
13558 return true;
13559 } else if (identical(node.type, _oldNode)) {
13560 node.type = _newNode as TypeName;
13561 return true;
13562 }
13563 return visitNode(node);
13564 }
13565
13566 @override
13567 bool visitLabel(Label node) {
13568 if (identical(node.label, _oldNode)) {
13569 node.label = _newNode as SimpleIdentifier;
13570 return true;
13571 }
13572 return visitNode(node);
13573 }
13574
13575 @override
13576 bool visitLabeledStatement(LabeledStatement node) {
13577 if (identical(node.statement, _oldNode)) {
13578 node.statement = _newNode as Statement;
13579 return true;
13580 } else if (_replaceInList(node.labels)) {
13581 return true;
13582 }
13583 return visitNode(node);
13584 }
13585
13586 @override
13587 bool visitLibraryDirective(LibraryDirective node) {
13588 if (identical(node.name, _oldNode)) {
13589 node.name = _newNode as LibraryIdentifier;
13590 return true;
13591 }
13592 return visitAnnotatedNode(node);
13593 }
13594
13595 @override
13596 bool visitLibraryIdentifier(LibraryIdentifier node) {
13597 if (_replaceInList(node.components)) {
13598 return true;
13599 }
13600 return visitNode(node);
13601 }
13602
13603 @override
13604 bool visitListLiteral(ListLiteral node) {
13605 if (_replaceInList(node.elements)) {
13606 return true;
13607 }
13608 return visitTypedLiteral(node);
13609 }
13610
13611 @override
13612 bool visitMapLiteral(MapLiteral node) {
13613 if (_replaceInList(node.entries)) {
13614 return true;
13615 }
13616 return visitTypedLiteral(node);
13617 }
13618
13619 @override
13620 bool visitMapLiteralEntry(MapLiteralEntry node) {
13621 if (identical(node.key, _oldNode)) {
13622 node.key = _newNode as Expression;
13623 return true;
13624 } else if (identical(node.value, _oldNode)) {
13625 node.value = _newNode as Expression;
13626 return true;
13627 }
13628 return visitNode(node);
13629 }
13630
13631 @override
13632 bool visitMethodDeclaration(MethodDeclaration node) {
13633 if (identical(node.returnType, _oldNode)) {
13634 node.returnType = _newNode as TypeName;
13635 return true;
13636 } else if (identical(node.name, _oldNode)) {
13637 node.name = _newNode as SimpleIdentifier;
13638 return true;
13639 } else if (identical(node.parameters, _oldNode)) {
13640 node.parameters = _newNode as FormalParameterList;
13641 return true;
13642 } else if (identical(node.body, _oldNode)) {
13643 node.body = _newNode as FunctionBody;
13644 return true;
13645 }
13646 return visitAnnotatedNode(node);
13647 }
13648
13649 @override
13650 bool visitMethodInvocation(MethodInvocation node) {
13651 if (identical(node.target, _oldNode)) {
13652 node.target = _newNode as Expression;
13653 return true;
13654 } else if (identical(node.methodName, _oldNode)) {
13655 node.methodName = _newNode as SimpleIdentifier;
13656 return true;
13657 } else if (identical(node.argumentList, _oldNode)) {
13658 node.argumentList = _newNode as ArgumentList;
13659 return true;
13660 }
13661 return visitNode(node);
13662 }
13663
13664 @override
13665 bool visitNamedExpression(NamedExpression node) {
13666 if (identical(node.name, _oldNode)) {
13667 node.name = _newNode as Label;
13668 return true;
13669 } else if (identical(node.expression, _oldNode)) {
13670 node.expression = _newNode as Expression;
13671 return true;
13672 }
13673 return visitNode(node);
13674 }
13675
13676 bool visitNamespaceDirective(NamespaceDirective node) {
13677 if (_replaceInList(node.combinators)) {
13678 return true;
13679 }
13680 return visitUriBasedDirective(node);
13681 }
13682
13683 @override
13684 bool visitNativeClause(NativeClause node) {
13685 if (identical(node.name, _oldNode)) {
13686 node.name = _newNode as StringLiteral;
13687 return true;
13688 }
13689 return visitNode(node);
13690 }
13691
13692 @override
13693 bool visitNativeFunctionBody(NativeFunctionBody node) {
13694 if (identical(node.stringLiteral, _oldNode)) {
13695 node.stringLiteral = _newNode as StringLiteral;
13696 return true;
13697 }
13698 return visitNode(node);
13699 }
13700
13701 bool visitNode(AstNode node) {
13702 throw new IllegalArgumentException(
13703 "The old node is not a child of it's parent");
13704 }
13705
13706 bool visitNormalFormalParameter(NormalFormalParameter node) {
13707 if (identical(node.documentationComment, _oldNode)) {
13708 node.documentationComment = _newNode as Comment;
13709 return true;
13710 } else if (identical(node.identifier, _oldNode)) {
13711 node.identifier = _newNode as SimpleIdentifier;
13712 return true;
13713 } else if (_replaceInList(node.metadata)) {
13714 return true;
13715 }
13716 return visitNode(node);
13717 }
13718
13719 @override
13720 bool visitNullLiteral(NullLiteral node) => visitNode(node);
13721
13722 @override
13723 bool visitParenthesizedExpression(ParenthesizedExpression node) {
13724 if (identical(node.expression, _oldNode)) {
13725 node.expression = _newNode as Expression;
13726 return true;
13727 }
13728 return visitNode(node);
13729 }
13730
13731 @override
13732 bool visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
13733
13734 @override
13735 bool visitPartOfDirective(PartOfDirective node) {
13736 if (identical(node.libraryName, _oldNode)) {
13737 node.libraryName = _newNode as LibraryIdentifier;
13738 return true;
13739 }
13740 return visitAnnotatedNode(node);
13741 }
13742
13743 @override
13744 bool visitPostfixExpression(PostfixExpression node) {
13745 if (identical(node.operand, _oldNode)) {
13746 node.operand = _newNode as Expression;
13747 return true;
13748 }
13749 return visitNode(node);
13750 }
13751
13752 @override
13753 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
13754 if (identical(node.prefix, _oldNode)) {
13755 node.prefix = _newNode as SimpleIdentifier;
13756 return true;
13757 } else if (identical(node.identifier, _oldNode)) {
13758 node.identifier = _newNode as SimpleIdentifier;
13759 return true;
13760 }
13761 return visitNode(node);
13762 }
13763
13764 @override
13765 bool visitPrefixExpression(PrefixExpression node) {
13766 if (identical(node.operand, _oldNode)) {
13767 node.operand = _newNode as Expression;
13768 return true;
13769 }
13770 return visitNode(node);
13771 }
13772
13773 @override
13774 bool visitPropertyAccess(PropertyAccess node) {
13775 if (identical(node.target, _oldNode)) {
13776 node.target = _newNode as Expression;
13777 return true;
13778 } else if (identical(node.propertyName, _oldNode)) {
13779 node.propertyName = _newNode as SimpleIdentifier;
13780 return true;
13781 }
13782 return visitNode(node);
13783 }
13784
13785 @override
13786 bool visitRedirectingConstructorInvocation(
13787 RedirectingConstructorInvocation node) {
13788 if (identical(node.constructorName, _oldNode)) {
13789 node.constructorName = _newNode as SimpleIdentifier;
13790 return true;
13791 } else if (identical(node.argumentList, _oldNode)) {
13792 node.argumentList = _newNode as ArgumentList;
13793 return true;
13794 }
13795 return visitNode(node);
13796 }
13797
13798 @override
13799 bool visitRethrowExpression(RethrowExpression node) => visitNode(node);
13800
13801 @override
13802 bool visitReturnStatement(ReturnStatement node) {
13803 if (identical(node.expression, _oldNode)) {
13804 node.expression = _newNode as Expression;
13805 return true;
13806 }
13807 return visitNode(node);
13808 }
13809
13810 @override
13811 bool visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
13812
13813 @override
13814 bool visitShowCombinator(ShowCombinator node) {
13815 if (_replaceInList(node.shownNames)) {
13816 return true;
13817 }
13818 return visitNode(node);
13819 }
13820
13821 @override
13822 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
13823 if (identical(node.type, _oldNode)) {
13824 node.type = _newNode as TypeName;
13825 return true;
13826 }
13827 return visitNormalFormalParameter(node);
13828 }
13829
13830 @override
13831 bool visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
13832
13833 @override
13834 bool visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
13835
13836 @override
13837 bool visitStringInterpolation(StringInterpolation node) {
13838 if (_replaceInList(node.elements)) {
13839 return true;
13840 }
13841 return visitNode(node);
13842 }
13843
13844 @override
13845 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
13846 if (identical(node.constructorName, _oldNode)) {
13847 node.constructorName = _newNode as SimpleIdentifier;
13848 return true;
13849 } else if (identical(node.argumentList, _oldNode)) {
13850 node.argumentList = _newNode as ArgumentList;
13851 return true;
13852 }
13853 return visitNode(node);
13854 }
13855
13856 @override
13857 bool visitSuperExpression(SuperExpression node) => visitNode(node);
13858
13859 @override
13860 bool visitSwitchCase(SwitchCase node) {
13861 if (identical(node.expression, _oldNode)) {
13862 node.expression = _newNode as Expression;
13863 return true;
13864 }
13865 return visitSwitchMember(node);
13866 }
13867
13868 @override
13869 bool visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
13870
13871 bool visitSwitchMember(SwitchMember node) {
13872 if (_replaceInList(node.labels)) {
13873 return true;
13874 } else if (_replaceInList(node.statements)) {
13875 return true;
13876 }
13877 return visitNode(node);
13878 }
13879
13880 @override
13881 bool visitSwitchStatement(SwitchStatement node) {
13882 if (identical(node.expression, _oldNode)) {
13883 node.expression = _newNode as Expression;
13884 return true;
13885 } else if (_replaceInList(node.members)) {
13886 return true;
13887 }
13888 return visitNode(node);
13889 }
13890
13891 @override
13892 bool visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
13893
13894 @override
13895 bool visitThisExpression(ThisExpression node) => visitNode(node);
13896
13897 @override
13898 bool visitThrowExpression(ThrowExpression node) {
13899 if (identical(node.expression, _oldNode)) {
13900 node.expression = _newNode as Expression;
13901 return true;
13902 }
13903 return visitNode(node);
13904 }
13905
13906 @override
13907 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
13908 if (identical(node.variables, _oldNode)) {
13909 node.variables = _newNode as VariableDeclarationList;
13910 return true;
13911 }
13912 return visitAnnotatedNode(node);
13913 }
13914
13915 @override
13916 bool visitTryStatement(TryStatement node) {
13917 if (identical(node.body, _oldNode)) {
13918 node.body = _newNode as Block;
13919 return true;
13920 } else if (identical(node.finallyBlock, _oldNode)) {
13921 node.finallyBlock = _newNode as Block;
13922 return true;
13923 } else if (_replaceInList(node.catchClauses)) {
13924 return true;
13925 }
13926 return visitNode(node);
13927 }
13928
13929 @override
13930 bool visitTypeArgumentList(TypeArgumentList node) {
13931 if (_replaceInList(node.arguments)) {
13932 return true;
13933 }
13934 return visitNode(node);
13935 }
13936
13937 bool visitTypedLiteral(TypedLiteral node) {
13938 if (identical(node.typeArguments, _oldNode)) {
13939 node.typeArguments = _newNode as TypeArgumentList;
13940 return true;
13941 }
13942 return visitNode(node);
13943 }
13944
13945 @override
13946 bool visitTypeName(TypeName node) {
13947 if (identical(node.name, _oldNode)) {
13948 node.name = _newNode as Identifier;
13949 return true;
13950 } else if (identical(node.typeArguments, _oldNode)) {
13951 node.typeArguments = _newNode as TypeArgumentList;
13952 return true;
13953 }
13954 return visitNode(node);
13955 }
13956
13957 @override
13958 bool visitTypeParameter(TypeParameter node) {
13959 if (identical(node.name, _oldNode)) {
13960 node.name = _newNode as SimpleIdentifier;
13961 return true;
13962 } else if (identical(node.bound, _oldNode)) {
13963 node.bound = _newNode as TypeName;
13964 return true;
13965 }
13966 return visitNode(node);
13967 }
13968
13969 @override
13970 bool visitTypeParameterList(TypeParameterList node) {
13971 if (_replaceInList(node.typeParameters)) {
13972 return true;
13973 }
13974 return visitNode(node);
13975 }
13976
13977 bool visitUriBasedDirective(UriBasedDirective node) {
13978 if (identical(node.uri, _oldNode)) {
13979 node.uri = _newNode as StringLiteral;
13980 return true;
13981 }
13982 return visitAnnotatedNode(node);
13983 }
13984
13985 @override
13986 bool visitVariableDeclaration(VariableDeclaration node) {
13987 if (identical(node.name, _oldNode)) {
13988 node.name = _newNode as SimpleIdentifier;
13989 return true;
13990 } else if (identical(node.initializer, _oldNode)) {
13991 node.initializer = _newNode as Expression;
13992 return true;
13993 }
13994 return visitAnnotatedNode(node);
13995 }
13996
13997 @override
13998 bool visitVariableDeclarationList(VariableDeclarationList node) {
13999 if (identical(node.type, _oldNode)) {
14000 node.type = _newNode as TypeName;
14001 return true;
14002 } else if (_replaceInList(node.variables)) {
14003 return true;
14004 }
14005 return visitNode(node);
14006 }
14007
14008 @override
14009 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
14010 if (identical(node.variables, _oldNode)) {
14011 node.variables = _newNode as VariableDeclarationList;
14012 return true;
14013 }
14014 return visitNode(node);
14015 }
14016
14017 @override
14018 bool visitWhileStatement(WhileStatement node) {
14019 if (identical(node.condition, _oldNode)) {
14020 node.condition = _newNode as Expression;
14021 return true;
14022 } else if (identical(node.body, _oldNode)) {
14023 node.body = _newNode as Statement;
14024 return true;
14025 }
14026 return visitNode(node);
14027 }
14028
14029 @override
14030 bool visitWithClause(WithClause node) {
14031 if (_replaceInList(node.mixinTypes)) {
14032 return true;
14033 }
14034 return visitNode(node);
14035 }
14036
14037 @override
14038 bool visitYieldStatement(YieldStatement node) {
14039 if (identical(node.expression, _oldNode)) {
14040 node.expression = _newNode as Expression;
14041 return true;
14042 }
14043 return visitNode(node);
14044 }
14045
14046 bool _replaceInList(NodeList list) {
14047 int count = list.length;
14048 for (int i = 0; i < count; i++) {
14049 if (identical(_oldNode, list[i])) {
14050 list[i] = _newNode;
14051 return true;
14052 }
14053 }
14054 return false;
14055 }
14056
14057 /**
14058 * Replace the [oldNode] with the [newNode] in the AST structure containing
14059 * the old node. Return `true` if the replacement was successful.
14060 *
14061 * Throws an [IllegalArgumentException] if either node is `null`, if the old
14062 * node does not have a parent node, or if the AST structure has been
14063 * corrupted.
14064 */
14065 static bool replace(AstNode oldNode, AstNode newNode) {
14066 if (oldNode == null || newNode == null) {
14067 throw new IllegalArgumentException(
14068 "The old and new nodes must be non-null");
14069 } else if (identical(oldNode, newNode)) {
14070 return true;
14071 }
14072 AstNode parent = oldNode.parent;
14073 if (parent == null) {
14074 throw new IllegalArgumentException(
14075 "The old node is not a child of another node");
14076 }
14077 NodeReplacer replacer = new NodeReplacer(oldNode, newNode);
14078 return parent.accept(replacer);
14079 }
14080 }
14081
14082 /**
14083 * A formal parameter that is required (is not optional).
14084 *
14085 * > normalFormalParameter ::=
14086 * > [FunctionTypedFormalParameter]
14087 * > | [FieldFormalParameter]
14088 * > | [SimpleFormalParameter]
14089 */
14090 abstract class NormalFormalParameter extends FormalParameter {
14091 /**
14092 * The documentation comment associated with this parameter, or `null` if this
14093 * parameter does not have a documentation comment associated with it.
14094 */
14095 Comment _comment;
14096
14097 /**
14098 * The annotations associated with this parameter.
14099 */
14100 NodeList<Annotation> _metadata;
14101
14102 /**
14103 * The name of the parameter being declared.
14104 */
14105 SimpleIdentifier _identifier;
14106
14107 /**
14108 * Initialize a newly created formal parameter. Either or both of the
14109 * [comment] and [metadata] can be `null` if the parameter does not have the
14110 * corresponding attribute.
14111 */
14112 NormalFormalParameter(
14113 Comment comment, List<Annotation> metadata, SimpleIdentifier identifier) {
14114 _comment = _becomeParentOf(comment);
14115 _metadata = new NodeList<Annotation>(this, metadata);
14116 _identifier = _becomeParentOf(identifier);
14117 }
14118
14119 /**
14120 * Return the documentation comment associated with this parameter, or `null`
14121 * if this parameter does not have a documentation comment associated with it.
14122 */
14123 Comment get documentationComment => _comment;
14124
14125 /**
14126 * Set the documentation comment associated with this parameter to the given
14127 * [comment].
14128 */
14129 void set documentationComment(Comment comment) {
14130 _comment = _becomeParentOf(comment);
14131 }
14132
14133 @override
14134 SimpleIdentifier get identifier => _identifier;
14135
14136 /**
14137 * Set the name of the parameter being declared to the given [identifier].
14138 */
14139 void set identifier(SimpleIdentifier identifier) {
14140 _identifier = _becomeParentOf(identifier);
14141 }
14142
14143 @override
14144 ParameterKind get kind {
14145 AstNode parent = this.parent;
14146 if (parent is DefaultFormalParameter) {
14147 return parent.kind;
14148 }
14149 return ParameterKind.REQUIRED;
14150 }
14151
14152 @override
14153 NodeList<Annotation> get metadata => _metadata;
14154
14155 /**
14156 * Set the metadata associated with this node to the given [metadata].
14157 */
14158 void set metadata(List<Annotation> metadata) {
14159 _metadata.clear();
14160 _metadata.addAll(metadata);
14161 }
14162
14163 /**
14164 * Return a list containing the comment and annotations associated with this
14165 * parameter, sorted in lexical order.
14166 */
14167 List<AstNode> get sortedCommentAndAnnotations {
14168 return <AstNode>[]
14169 ..add(_comment)
14170 ..addAll(_metadata)
14171 ..sort(AstNode.LEXICAL_ORDER);
14172 }
14173
14174 ChildEntities get _childEntities {
14175 ChildEntities result = new ChildEntities();
14176 if (_commentIsBeforeAnnotations()) {
14177 result
14178 ..add(_comment)
14179 ..addAll(_metadata);
14180 } else {
14181 result.addAll(sortedCommentAndAnnotations);
14182 }
14183 return result;
14184 }
14185
14186 @override
14187 void visitChildren(AstVisitor visitor) {
14188 //
14189 // Note that subclasses are responsible for visiting the identifier because
14190 // they often need to visit other nodes before visiting the identifier.
14191 //
14192 if (_commentIsBeforeAnnotations()) {
14193 _safelyVisitChild(_comment, visitor);
14194 _metadata.accept(visitor);
14195 } else {
14196 for (AstNode child in sortedCommentAndAnnotations) {
14197 child.accept(visitor);
14198 }
14199 }
14200 }
14201
14202 /**
14203 * Return `true` if the comment is lexically before any annotations.
14204 */
14205 bool _commentIsBeforeAnnotations() {
14206 if (_comment == null || _metadata.isEmpty) {
14207 return true;
14208 }
14209 Annotation firstAnnotation = _metadata[0];
14210 return _comment.offset < firstAnnotation.offset;
14211 }
14212 }
14213
14214 /**
14215 * A null literal expression.
14216 *
14217 * > nullLiteral ::=
14218 * > 'null'
14219 */
14220 class NullLiteral extends Literal {
14221 /**
14222 * The token representing the literal.
14223 */
14224 Token literal;
14225
14226 /**
14227 * Initialize a newly created null literal.
14228 */
14229 NullLiteral(this.literal);
14230
14231 @override
14232 Token get beginToken => literal;
14233
14234 @override
14235 Iterable get childEntities => new ChildEntities()..add(literal);
14236
14237 @override
14238 Token get endToken => literal;
14239
14240 @override
14241 accept(AstVisitor visitor) => visitor.visitNullLiteral(this);
14242
14243 @override
14244 void visitChildren(AstVisitor visitor) {
14245 // There are no children to visit.
14246 }
14247 }
14248
14249 /**
14250 * A parenthesized expression.
14251 *
14252 * > parenthesizedExpression ::=
14253 * > '(' [Expression] ')'
14254 */
14255 class ParenthesizedExpression extends Expression {
14256 /**
14257 * The left parenthesis.
14258 */
14259 Token leftParenthesis;
14260
14261 /**
14262 * The expression within the parentheses.
14263 */
14264 Expression _expression;
14265
14266 /**
14267 * The right parenthesis.
14268 */ 6322 */
14269 Token rightParenthesis; 6323 Token rightParenthesis;
14270 6324
14271 /** 6325 /**
14272 * Initialize a newly created parenthesized expression. 6326 * The statement that is executed if the condition evaluates to `true`.
14273 */ 6327 */
14274 ParenthesizedExpression( 6328 Statement _thenStatement;
14275 this.leftParenthesis, Expression expression, this.rightParenthesis) { 6329
14276 _expression = _becomeParentOf(expression); 6330 /**
14277 } 6331 * The token representing the 'else' keyword, or `null` if there is no else
14278 6332 * statement.
14279 @override 6333 */
14280 Token get beginToken => leftParenthesis; 6334 Token elseKeyword;
6335
6336 /**
6337 * The statement that is executed if the condition evaluates to `false`, or
6338 * `null` if there is no else statement.
6339 */
6340 Statement _elseStatement;
6341
6342 /**
6343 * Initialize a newly created if statement. The [elseKeyword] and
6344 * [elseStatement] can be `null` if there is no else clause.
6345 */
6346 IfStatement(
6347 this.ifKeyword,
6348 this.leftParenthesis,
6349 Expression condition,
6350 this.rightParenthesis,
6351 Statement thenStatement,
6352 this.elseKeyword,
6353 Statement elseStatement) {
6354 _condition = _becomeParentOf(condition);
6355 _thenStatement = _becomeParentOf(thenStatement);
6356 _elseStatement = _becomeParentOf(elseStatement);
6357 }
6358
6359 @override
6360 Token get beginToken => ifKeyword;
14281 6361
14282 @override 6362 @override
14283 Iterable get childEntities => new ChildEntities() 6363 Iterable get childEntities => new ChildEntities()
6364 ..add(ifKeyword)
14284 ..add(leftParenthesis) 6365 ..add(leftParenthesis)
14285 ..add(_expression) 6366 ..add(_condition)
14286 ..add(rightParenthesis); 6367 ..add(rightParenthesis)
14287 6368 ..add(_thenStatement)
14288 @override 6369 ..add(elseKeyword)
14289 Token get endToken => rightParenthesis; 6370 ..add(_elseStatement);
14290 6371
14291 /** 6372 /**
14292 * Return the expression within the parentheses. 6373 * Return the condition used to determine which of the statements is executed
14293 */ 6374 * next.
14294 Expression get expression => _expression; 6375 */
14295 6376 Expression get condition => _condition;
14296 /** 6377
14297 * Set the expression within the parentheses to the given [expression]. 6378 /**
14298 */ 6379 * Set the condition used to determine which of the statements is executed
14299 void set expression(Expression expression) { 6380 * next to the given [expression].
14300 _expression = _becomeParentOf(expression); 6381 */
14301 } 6382 void set condition(Expression expression) {
14302 6383 _condition = _becomeParentOf(expression);
14303 @override 6384 }
14304 int get precedence => 15; 6385
14305 6386 /**
14306 @override 6387 * Return the statement that is executed if the condition evaluates to
14307 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this); 6388 * `false`, or `null` if there is no else statement.
6389 */
6390 Statement get elseStatement => _elseStatement;
6391
6392 /**
6393 * Set the statement that is executed if the condition evaluates to `false`
6394 * to the given [statement].
6395 */
6396 void set elseStatement(Statement statement) {
6397 _elseStatement = _becomeParentOf(statement);
6398 }
6399
6400 @override
6401 Token get endToken {
6402 if (_elseStatement != null) {
6403 return _elseStatement.endToken;
6404 }
6405 return _thenStatement.endToken;
6406 }
6407
6408 /**
6409 * Return the statement that is executed if the condition evaluates to `true`.
6410 */
6411 Statement get thenStatement => _thenStatement;
6412
6413 /**
6414 * Set the statement that is executed if the condition evaluates to `true` to
6415 * the given [statement].
6416 */
6417 void set thenStatement(Statement statement) {
6418 _thenStatement = _becomeParentOf(statement);
6419 }
6420
6421 @override
6422 accept(AstVisitor visitor) => visitor.visitIfStatement(this);
14308 6423
14309 @override 6424 @override
14310 void visitChildren(AstVisitor visitor) { 6425 void visitChildren(AstVisitor visitor) {
14311 _safelyVisitChild(_expression, visitor); 6426 _safelyVisitChild(_condition, visitor);
6427 _safelyVisitChild(_thenStatement, visitor);
6428 _safelyVisitChild(_elseStatement, visitor);
14312 } 6429 }
14313 } 6430 }
14314 6431
14315 /** 6432 /**
14316 * A part directive. 6433 * The "implements" clause in an class declaration.
14317 * 6434 *
14318 * > partDirective ::= 6435 * > implementsClause ::=
14319 * > [Annotation] 'part' [StringLiteral] ';' 6436 * > 'implements' [TypeName] (',' [TypeName])*
14320 */ 6437 */
14321 class PartDirective extends UriBasedDirective { 6438 class ImplementsClause extends AstNode {
14322 /** 6439 /**
14323 * The token representing the 'part' keyword. 6440 * The token representing the 'implements' keyword.
14324 */ 6441 */
14325 Token partKeyword; 6442 Token implementsKeyword;
14326 6443
14327 /** 6444 /**
14328 * The semicolon terminating the directive. 6445 * The interfaces that are being implemented.
14329 */ 6446 */
14330 Token semicolon; 6447 NodeList<TypeName> _interfaces;
14331 6448
14332 /** 6449 /**
14333 * Initialize a newly created part directive. Either or both of the [comment] 6450 * Initialize a newly created implements clause.
14334 * and [metadata] can be `null` if the directive does not have the 6451 */
14335 * corresponding attribute. 6452 ImplementsClause(this.implementsKeyword, List<TypeName> interfaces) {
14336 */ 6453 _interfaces = new NodeList<TypeName>(this, interfaces);
14337 PartDirective(Comment comment, List<Annotation> metadata, this.partKeyword, 6454 }
14338 StringLiteral partUri, this.semicolon) 6455
14339 : super(comment, metadata, partUri); 6456 @override
14340 6457 Token get beginToken => implementsKeyword;
14341 @override 6458
14342 Iterable get childEntities => 6459 @override
14343 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon); 6460 // TODO(paulberry): add commas.
14344 6461 Iterable get childEntities => new ChildEntities()
14345 @override 6462 ..add(implementsKeyword)
14346 Token get endToken => semicolon; 6463 ..addAll(interfaces);
14347 6464
14348 @override 6465 @override
14349 Token get firstTokenAfterCommentAndMetadata => partKeyword; 6466 Token get endToken => _interfaces.endToken;
14350 6467
14351 @override 6468 /**
14352 Token get keyword => partKeyword; 6469 * Return the list of the interfaces that are being implemented.
14353 6470 */
14354 @override 6471 NodeList<TypeName> get interfaces => _interfaces;
14355 CompilationUnitElement get uriElement => element as CompilationUnitElement; 6472
14356 6473 @override
14357 @override 6474 accept(AstVisitor visitor) => visitor.visitImplementsClause(this);
14358 accept(AstVisitor visitor) => visitor.visitPartDirective(this); 6475
6476 @override
6477 void visitChildren(AstVisitor visitor) {
6478 _interfaces.accept(visitor);
6479 }
14359 } 6480 }
14360 6481
14361 /** 6482 /**
14362 * A part-of directive. 6483 * An import directive.
14363 * 6484 *
14364 * > partOfDirective ::= 6485 * > importDirective ::=
14365 * > [Annotation] 'part' 'of' [Identifier] ';' 6486 * > [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* ';'
6487 * > | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combi nator]* ';'
14366 */ 6488 */
14367 class PartOfDirective extends Directive { 6489 class ImportDirective extends NamespaceDirective {
14368 /** 6490 static Comparator<ImportDirective> COMPARATOR =
14369 * The token representing the 'part' keyword. 6491 (ImportDirective import1, ImportDirective import2) {
14370 */ 6492 //
14371 Token partKeyword; 6493 // uri
14372 6494 //
14373 /** 6495 StringLiteral uri1 = import1.uri;
14374 * The token representing the 'of' keyword. 6496 StringLiteral uri2 = import2.uri;
14375 */ 6497 String uriStr1 = uri1.stringValue;
14376 Token ofKeyword; 6498 String uriStr2 = uri2.stringValue;
14377 6499 if (uriStr1 != null || uriStr2 != null) {
14378 /** 6500 if (uriStr1 == null) {
14379 * The name of the library that the containing compilation unit is part of. 6501 return -1;
14380 */ 6502 } else if (uriStr2 == null) {
14381 LibraryIdentifier _libraryName; 6503 return 1;
14382 6504 } else {
14383 /** 6505 int compare = uriStr1.compareTo(uriStr2);
14384 * The semicolon terminating the directive. 6506 if (compare != 0) {
14385 */ 6507 return compare;
14386 Token semicolon; 6508 }
14387 6509 }
14388 /** 6510 }
14389 * Initialize a newly created part-of directive. Either or both of the 6511 //
14390 * [comment] and [metadata] can be `null` if the directive does not have the 6512 // as
14391 * corresponding attribute. 6513 //
14392 */ 6514 SimpleIdentifier prefix1 = import1.prefix;
14393 PartOfDirective(Comment comment, List<Annotation> metadata, this.partKeyword, 6515 SimpleIdentifier prefix2 = import2.prefix;
14394 this.ofKeyword, LibraryIdentifier libraryName, this.semicolon) 6516 String prefixStr1 = prefix1 != null ? prefix1.name : null;
14395 : super(comment, metadata) { 6517 String prefixStr2 = prefix2 != null ? prefix2.name : null;
14396 _libraryName = _becomeParentOf(libraryName); 6518 if (prefixStr1 != null || prefixStr2 != null) {
6519 if (prefixStr1 == null) {
6520 return -1;
6521 } else if (prefixStr2 == null) {
6522 return 1;
6523 } else {
6524 int compare = prefixStr1.compareTo(prefixStr2);
6525 if (compare != 0) {
6526 return compare;
6527 }
6528 }
6529 }
6530 //
6531 // hides and shows
6532 //
6533 NodeList<Combinator> combinators1 = import1.combinators;
6534 List<String> allHides1 = new List<String>();
6535 List<String> allShows1 = new List<String>();
6536 for (Combinator combinator in combinators1) {
6537 if (combinator is HideCombinator) {
6538 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
6539 for (SimpleIdentifier simpleIdentifier in hides) {
6540 allHides1.add(simpleIdentifier.name);
6541 }
6542 } else {
6543 NodeList<SimpleIdentifier> shows =
6544 (combinator as ShowCombinator).shownNames;
6545 for (SimpleIdentifier simpleIdentifier in shows) {
6546 allShows1.add(simpleIdentifier.name);
6547 }
6548 }
6549 }
6550 NodeList<Combinator> combinators2 = import2.combinators;
6551 List<String> allHides2 = new List<String>();
6552 List<String> allShows2 = new List<String>();
6553 for (Combinator combinator in combinators2) {
6554 if (combinator is HideCombinator) {
6555 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
6556 for (SimpleIdentifier simpleIdentifier in hides) {
6557 allHides2.add(simpleIdentifier.name);
6558 }
6559 } else {
6560 NodeList<SimpleIdentifier> shows =
6561 (combinator as ShowCombinator).shownNames;
6562 for (SimpleIdentifier simpleIdentifier in shows) {
6563 allShows2.add(simpleIdentifier.name);
6564 }
6565 }
6566 }
6567 // test lengths of combinator lists first
6568 if (allHides1.length != allHides2.length) {
6569 return allHides1.length - allHides2.length;
6570 }
6571 if (allShows1.length != allShows2.length) {
6572 return allShows1.length - allShows2.length;
6573 }
6574 // next ensure that the lists are equivalent
6575 if (!javaCollectionContainsAll(allHides1, allHides2)) {
6576 return -1;
6577 }
6578 if (!javaCollectionContainsAll(allShows1, allShows2)) {
6579 return -1;
6580 }
6581 return 0;
6582 };
6583
6584 /**
6585 * The token representing the 'deferred' keyword, or `null` if the imported is
6586 * not deferred.
6587 */
6588 Token deferredKeyword;
6589
6590 /**
6591 * The token representing the 'as' keyword, or `null` if the imported names ar e
6592 * not prefixed.
6593 */
6594 Token asKeyword;
6595
6596 /**
6597 * The prefix to be used with the imported names, or `null` if the imported
6598 * names are not prefixed.
6599 */
6600 SimpleIdentifier _prefix;
6601
6602 /**
6603 * Initialize a newly created import directive. Either or both of the
6604 * [comment] and [metadata] can be `null` if the function does not have the
6605 * corresponding attribute. The [deferredKeyword] can be `null` if the import
6606 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import
6607 * does not specify a prefix. The list of [combinators] can be `null` if there
6608 * are no combinators.
6609 */
6610 ImportDirective(
6611 Comment comment,
6612 List<Annotation> metadata,
6613 Token keyword,
6614 StringLiteral libraryUri,
6615 List<Configuration> configurations,
6616 this.deferredKeyword,
6617 this.asKeyword,
6618 SimpleIdentifier prefix,
6619 List<Combinator> combinators,
6620 Token semicolon)
6621 : super(comment, metadata, keyword, libraryUri, configurations,
6622 combinators, semicolon) {
6623 _prefix = _becomeParentOf(prefix);
14397 } 6624 }
14398 6625
14399 @override 6626 @override
14400 Iterable get childEntities => super._childEntities 6627 Iterable get childEntities => super._childEntities
14401 ..add(partKeyword) 6628 ..add(_uri)
14402 ..add(ofKeyword) 6629 ..add(deferredKeyword)
14403 ..add(_libraryName) 6630 ..add(asKeyword)
6631 ..add(_prefix)
6632 ..addAll(combinators)
14404 ..add(semicolon); 6633 ..add(semicolon);
14405 6634
14406 @override 6635 @override
14407 Token get endToken => semicolon; 6636 ImportElement get element => super.element as ImportElement;
14408 6637
14409 @override 6638 /**
14410 Token get firstTokenAfterCommentAndMetadata => partKeyword; 6639 * Return the prefix to be used with the imported names, or `null` if the
14411 6640 * imported names are not prefixed.
14412 @override 6641 */
14413 Token get keyword => partKeyword; 6642 SimpleIdentifier get prefix => _prefix;
14414 6643
14415 /** 6644 /**
14416 * Return the name of the library that the containing compilation unit is part 6645 * Set the prefix to be used with the imported names to the given [identifier] .
14417 * of. 6646 */
14418 */ 6647 void set prefix(SimpleIdentifier identifier) {
14419 LibraryIdentifier get libraryName => _libraryName; 6648 _prefix = _becomeParentOf(identifier);
14420 6649 }
14421 /** 6650
14422 * Set the name of the library that the containing compilation unit is part of 6651 @override
14423 * to the given [libraryName]. 6652 LibraryElement get uriElement {
14424 */ 6653 ImportElement element = this.element;
14425 void set libraryName(LibraryIdentifier libraryName) { 6654 if (element == null) {
14426 _libraryName = _becomeParentOf(libraryName); 6655 return null;
14427 } 6656 }
14428 6657 return element.importedLibrary;
14429 @override 6658 }
14430 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this); 6659
6660 @override
6661 accept(AstVisitor visitor) => visitor.visitImportDirective(this);
14431 6662
14432 @override 6663 @override
14433 void visitChildren(AstVisitor visitor) { 6664 void visitChildren(AstVisitor visitor) {
14434 super.visitChildren(visitor); 6665 super.visitChildren(visitor);
14435 _safelyVisitChild(_libraryName, visitor); 6666 _safelyVisitChild(_prefix, visitor);
6667 combinators.accept(visitor);
14436 } 6668 }
14437 } 6669 }
14438 6670
14439 /** 6671 /**
14440 * A postfix unary expression. 6672 * An index expression.
14441 * 6673 *
14442 * > postfixExpression ::= 6674 * > indexExpression ::=
14443 * > [Expression] [Token] 6675 * > [Expression] '[' [Expression] ']'
14444 */ 6676 */
14445 class PostfixExpression extends Expression { 6677 class IndexExpression extends Expression {
14446 /** 6678 /**
14447 * The expression computing the operand for the operator. 6679 * The expression used to compute the object being indexed, or `null` if this
14448 */ 6680 * index expression is part of a cascade expression.
14449 Expression _operand; 6681 */
14450 6682 Expression _target;
14451 /** 6683
14452 * The postfix operator being applied to the operand. 6684 /**
14453 */ 6685 * The period ("..") before a cascaded index expression, or `null` if this
14454 Token operator; 6686 * index expression is not part of a cascade expression.
14455 6687 */
14456 /** 6688 Token period;
14457 * The element associated with this the operator based on the propagated type 6689
14458 * of the operand, or `null` if the AST structure has not been resolved, if 6690 /**
14459 * the operator is not user definable, or if the operator could not be 6691 * The left square bracket.
14460 * resolved. 6692 */
6693 Token leftBracket;
6694
6695 /**
6696 * The expression used to compute the index.
6697 */
6698 Expression _index;
6699
6700 /**
6701 * The right square bracket.
6702 */
6703 Token rightBracket;
6704
6705 /**
6706 * The element associated with the operator based on the static type of the
6707 * target, or `null` if the AST structure has not been resolved or if the
6708 * operator could not be resolved.
6709 */
6710 MethodElement staticElement;
6711
6712 /**
6713 * The element associated with the operator based on the propagated type of
6714 * the target, or `null` if the AST structure has not been resolved or if the
6715 * operator could not be resolved.
14461 */ 6716 */
14462 MethodElement propagatedElement; 6717 MethodElement propagatedElement;
14463 6718
14464 /** 6719 /**
14465 * The element associated with the operator based on the static type of the 6720 * If this expression is both in a getter and setter context, the
14466 * operand, or `null` if the AST structure has not been resolved, if the 6721 * [AuxiliaryElements] will be set to hold onto the static and propagated
14467 * operator is not user definable, or if the operator could not be resolved. 6722 * information. The auxiliary element will hold onto the elements from the
14468 */ 6723 * getter context.
14469 MethodElement staticElement; 6724 */
14470 6725 AuxiliaryElements auxiliaryElements = null;
14471 /** 6726
14472 * Initialize a newly created postfix expression. 6727 /**
14473 */ 6728 * Initialize a newly created index expression.
14474 PostfixExpression(Expression operand, this.operator) { 6729 */
14475 _operand = _becomeParentOf(operand); 6730 IndexExpression.forCascade(
14476 } 6731 this.period, this.leftBracket, Expression index, this.rightBracket) {
14477 6732 _index = _becomeParentOf(index);
14478 @override 6733 }
14479 Token get beginToken => _operand.beginToken; 6734
6735 /**
6736 * Initialize a newly created index expression.
6737 */
6738 IndexExpression.forTarget(Expression target, this.leftBracket,
6739 Expression index, this.rightBracket) {
6740 _target = _becomeParentOf(target);
6741 _index = _becomeParentOf(index);
6742 }
6743
6744 @override
6745 Token get beginToken {
6746 if (_target != null) {
6747 return _target.beginToken;
6748 }
6749 return period;
6750 }
14480 6751
14481 /** 6752 /**
14482 * Return the best element available for this operator. If resolution was able 6753 * Return the best element available for this operator. If resolution was able
14483 * to find a better element based on type propagation, that element will be 6754 * to find a better element based on type propagation, that element will be
14484 * returned. Otherwise, the element found using the result of static analysis 6755 * returned. Otherwise, the element found using the result of static analysis
14485 * will be returned. If resolution has not been performed, then `null` will be 6756 * will be returned. If resolution has not been performed, then `null` will be
14486 * returned. 6757 * returned.
14487 */ 6758 */
14488 MethodElement get bestElement { 6759 MethodElement get bestElement {
14489 MethodElement element = propagatedElement; 6760 MethodElement element = propagatedElement;
14490 if (element == null) { 6761 if (element == null) {
14491 element = staticElement; 6762 element = staticElement;
14492 } 6763 }
14493 return element; 6764 return element;
14494 } 6765 }
14495 6766
14496 @override 6767 @override
14497 Iterable get childEntities => 6768 Iterable get childEntities => new ChildEntities()
14498 new ChildEntities()..add(_operand)..add(operator); 6769 ..add(_target)
6770 ..add(period)
6771 ..add(leftBracket)
6772 ..add(_index)
6773 ..add(rightBracket);
14499 6774
14500 @override 6775 @override
14501 Token get endToken => operator; 6776 Token get endToken => rightBracket;
14502 6777
14503 /** 6778 /**
14504 * Return the expression computing the operand for the operator. 6779 * Return the expression used to compute the index.
14505 */ 6780 */
14506 Expression get operand => _operand; 6781 Expression get index => _index;
14507 6782
14508 /** 6783 /**
14509 * Set the expression computing the operand for the operator to the given 6784 * Set the expression used to compute the index to the given [expression].
14510 * [expression].
14511 */ 6785 */
14512 void set operand(Expression expression) { 6786 void set index(Expression expression) {
14513 _operand = _becomeParentOf(expression); 6787 _index = _becomeParentOf(expression);
14514 } 6788 }
14515 6789
14516 @override 6790 @override
6791 bool get isAssignable => true;
6792
6793 /**
6794 * Return `true` if this expression is cascaded. If it is, then the target of
6795 * this expression is not stored locally but is stored in the nearest ancestor
6796 * that is a [CascadeExpression].
6797 */
6798 bool get isCascaded => period != null;
6799
6800 @override
14517 int get precedence => 15; 6801 int get precedence => 15;
14518 6802
14519 /** 6803 /**
6804 * Return the expression used to compute the object being indexed. If this
6805 * index expression is not part of a cascade expression, then this is the same
6806 * as [target]. If this index expression is part of a cascade expression, then
6807 * the target expression stored with the cascade expression is returned.
6808 */
6809 Expression get realTarget {
6810 if (isCascaded) {
6811 AstNode ancestor = parent;
6812 while (ancestor is! CascadeExpression) {
6813 if (ancestor == null) {
6814 return _target;
6815 }
6816 ancestor = ancestor.parent;
6817 }
6818 return (ancestor as CascadeExpression).target;
6819 }
6820 return _target;
6821 }
6822
6823 /**
6824 * Return the expression used to compute the object being indexed, or `null`
6825 * if this index expression is part of a cascade expression.
6826 *
6827 * Use [realTarget] to get the target independent of whether this is part of a
6828 * cascade expression.
6829 */
6830 Expression get target => _target;
6831
6832 /**
6833 * Set the expression used to compute the object being indexed to the given
6834 * [expression].
6835 */
6836 void set target(Expression expression) {
6837 _target = _becomeParentOf(expression);
6838 }
6839
6840 /**
14520 * If the AST structure has been resolved, and the function being invoked is 6841 * If the AST structure has been resolved, and the function being invoked is
14521 * known based on propagated type information, then return the parameter 6842 * known based on propagated type information, then return the parameter
14522 * element representing the parameter to which the value of the operand will 6843 * element representing the parameter to which the value of the index
14523 * be bound. Otherwise, return `null`. 6844 * expression will be bound. Otherwise, return `null`.
14524 */ 6845 */
14525 ParameterElement get _propagatedParameterElementForOperand { 6846 ParameterElement get _propagatedParameterElementForIndex {
14526 if (propagatedElement == null) { 6847 if (propagatedElement == null) {
14527 return null; 6848 return null;
14528 } 6849 }
14529 List<ParameterElement> parameters = propagatedElement.parameters; 6850 List<ParameterElement> parameters = propagatedElement.parameters;
14530 if (parameters.length < 1) { 6851 if (parameters.length < 1) {
14531 return null; 6852 return null;
14532 } 6853 }
14533 return parameters[0]; 6854 return parameters[0];
14534 } 6855 }
14535 6856
14536 /** 6857 /**
14537 * If the AST structure has been resolved, and the function being invoked is 6858 * If the AST structure has been resolved, and the function being invoked is
14538 * known based on static type information, then return the parameter element 6859 * known based on static type information, then return the parameter element
14539 * representing the parameter to which the value of the operand will be bound. 6860 * representing the parameter to which the value of the index expression will
14540 * Otherwise, return `null`. 6861 * be bound. Otherwise, return `null`.
14541 */ 6862 */
14542 ParameterElement get _staticParameterElementForOperand { 6863 ParameterElement get _staticParameterElementForIndex {
14543 if (staticElement == null) { 6864 if (staticElement == null) {
14544 return null; 6865 return null;
14545 } 6866 }
14546 List<ParameterElement> parameters = staticElement.parameters; 6867 List<ParameterElement> parameters = staticElement.parameters;
14547 if (parameters.length < 1) { 6868 if (parameters.length < 1) {
14548 return null; 6869 return null;
14549 } 6870 }
14550 return parameters[0]; 6871 return parameters[0];
14551 } 6872 }
14552 6873
14553 @override 6874 @override
14554 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this); 6875 accept(AstVisitor visitor) => visitor.visitIndexExpression(this);
6876
6877 /**
6878 * Return `true` if this expression is computing a right-hand value (that is,
6879 * if this expression is in a context where the operator '[]' will be
6880 * invoked).
6881 *
6882 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
6883 * are they mutually exclusive. In other words, it is possible for both
6884 * methods to return `true` when invoked on the same node.
6885 */
6886 bool inGetterContext() {
6887 // TODO(brianwilkerson) Convert this to a getter.
6888 AstNode parent = this.parent;
6889 if (parent is AssignmentExpression) {
6890 AssignmentExpression assignment = parent;
6891 if (identical(assignment.leftHandSide, this) &&
6892 assignment.operator.type == TokenType.EQ) {
6893 return false;
6894 }
6895 }
6896 return true;
6897 }
6898
6899 /**
6900 * Return `true` if this expression is computing a left-hand value (that is,
6901 * if this expression is in a context where the operator '[]=' will be
6902 * invoked).
6903 *
6904 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
6905 * are they mutually exclusive. In other words, it is possible for both
6906 * methods to return `true` when invoked on the same node.
6907 */
6908 bool inSetterContext() {
6909 // TODO(brianwilkerson) Convert this to a getter.
6910 AstNode parent = this.parent;
6911 if (parent is PrefixExpression) {
6912 return parent.operator.type.isIncrementOperator;
6913 } else if (parent is PostfixExpression) {
6914 return true;
6915 } else if (parent is AssignmentExpression) {
6916 return identical(parent.leftHandSide, this);
6917 }
6918 return false;
6919 }
14555 6920
14556 @override 6921 @override
14557 void visitChildren(AstVisitor visitor) { 6922 void visitChildren(AstVisitor visitor) {
14558 _safelyVisitChild(_operand, visitor); 6923 _safelyVisitChild(_target, visitor);
14559 } 6924 _safelyVisitChild(_index, visitor);
14560 } 6925 }
14561 6926 }
14562 /** 6927
14563 * An identifier that is prefixed or an access to an object property where the 6928 /**
14564 * target of the property access is a simple identifier. 6929 * An instance creation expression.
14565 * 6930 *
14566 * > prefixedIdentifier ::= 6931 * > newExpression ::=
14567 * > [SimpleIdentifier] '.' [SimpleIdentifier] 6932 * > ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList]
14568 */ 6933 */
14569 class PrefixedIdentifier extends Identifier { 6934 class InstanceCreationExpression extends Expression {
14570 /** 6935 /**
14571 * The prefix associated with the library in which the identifier is defined. 6936 * The 'new' or 'const' keyword used to indicate how an object should be
14572 */ 6937 * created.
14573 SimpleIdentifier _prefix; 6938 */
14574 6939 Token keyword;
14575 /** 6940
14576 * The period used to separate the prefix from the identifier. 6941 /**
14577 */ 6942 * The name of the constructor to be invoked.
14578 Token period; 6943 */
14579 6944 ConstructorName _constructorName;
14580 /** 6945
14581 * The identifier being prefixed. 6946 /**
14582 */ 6947 * The list of arguments to the constructor.
14583 SimpleIdentifier _identifier; 6948 */
6949 ArgumentList _argumentList;
6950
6951 /**
6952 * The element associated with the constructor based on static type
6953 * information, or `null` if the AST structure has not been resolved or if the
6954 * constructor could not be resolved.
6955 */
6956 ConstructorElement staticElement;
6957
6958 /**
6959 * Initialize a newly created instance creation expression.
6960 */
6961 InstanceCreationExpression(this.keyword, ConstructorName constructorName,
6962 ArgumentList argumentList) {
6963 _constructorName = _becomeParentOf(constructorName);
6964 _argumentList = _becomeParentOf(argumentList);
6965 }
6966
6967 /**
6968 * Return the list of arguments to the constructor.
6969 */
6970 ArgumentList get argumentList => _argumentList;
6971
6972 /**
6973 * Set the list of arguments to the constructor to the given [argumentList].
6974 */
6975 void set argumentList(ArgumentList argumentList) {
6976 _argumentList = _becomeParentOf(argumentList);
6977 }
6978
6979 @override
6980 Token get beginToken => keyword;
6981
6982 @override
6983 Iterable get childEntities => new ChildEntities()
6984 ..add(keyword)
6985 ..add(_constructorName)
6986 ..add(_argumentList);
6987
6988 /**
6989 * Return the name of the constructor to be invoked.
6990 */
6991 ConstructorName get constructorName => _constructorName;
6992
6993 /**
6994 * Set the name of the constructor to be invoked to the given [name].
6995 */
6996 void set constructorName(ConstructorName name) {
6997 _constructorName = _becomeParentOf(name);
6998 }
6999
7000 @override
7001 Token get endToken => _argumentList.endToken;
7002
7003 /**
7004 * Return `true` if this creation expression is used to invoke a constant
7005 * constructor.
7006 */
7007 bool get isConst =>
7008 keyword is KeywordToken &&
7009 (keyword as KeywordToken).keyword == Keyword.CONST;
7010
7011 @override
7012 int get precedence => 16;
7013
7014 @override
7015 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this);
7016
7017 @override
7018 void visitChildren(AstVisitor visitor) {
7019 _safelyVisitChild(_constructorName, visitor);
7020 _safelyVisitChild(_argumentList, visitor);
7021 }
7022 }
7023
7024 /**
7025 * An integer literal expression.
7026 *
7027 * > integerLiteral ::=
7028 * > decimalIntegerLiteral
7029 * > | hexadecimalIntegerLiteral
7030 * >
7031 * > decimalIntegerLiteral ::=
7032 * > decimalDigit+
7033 * >
7034 * > hexadecimalIntegerLiteral ::=
7035 * > '0x' hexadecimalDigit+
7036 * > | '0X' hexadecimalDigit+
7037 */
7038 class IntegerLiteral extends Literal {
7039 /**
7040 * The token representing the literal.
7041 */
7042 Token literal;
7043
7044 /**
7045 * The value of the literal.
7046 */
7047 int value = 0;
7048
7049 /**
7050 * Initialize a newly created integer literal.
7051 */
7052 IntegerLiteral(this.literal, this.value);
7053
7054 @override
7055 Token get beginToken => literal;
7056
7057 @override
7058 Iterable get childEntities => new ChildEntities()..add(literal);
7059
7060 @override
7061 Token get endToken => literal;
7062
7063 @override
7064 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this);
7065
7066 @override
7067 void visitChildren(AstVisitor visitor) {
7068 // There are no children to visit.
7069 }
7070 }
7071
7072 /**
7073 * A node within a [StringInterpolation].
7074 *
7075 * > interpolationElement ::=
7076 * > [InterpolationExpression]
7077 * > | [InterpolationString]
7078 */
7079 abstract class InterpolationElement extends AstNode {}
7080
7081 /**
7082 * An expression embedded in a string interpolation.
7083 *
7084 * > interpolationExpression ::=
7085 * > '$' [SimpleIdentifier]
7086 * > | '$' '{' [Expression] '}'
7087 */
7088 class InterpolationExpression extends InterpolationElement {
7089 /**
7090 * The token used to introduce the interpolation expression; either '$' if the
7091 * expression is a simple identifier or '${' if the expression is a full
7092 * expression.
7093 */
7094 Token leftBracket;
7095
7096 /**
7097 * The expression to be evaluated for the value to be converted into a string.
7098 */
7099 Expression _expression;
7100
7101 /**
7102 * The right curly bracket, or `null` if the expression is an identifier
7103 * without brackets.
7104 */
7105 Token rightBracket;
7106
7107 /**
7108 * Initialize a newly created interpolation expression.
7109 */
7110 InterpolationExpression(
7111 this.leftBracket, Expression expression, this.rightBracket) {
7112 _expression = _becomeParentOf(expression);
7113 }
7114
7115 @override
7116 Token get beginToken => leftBracket;
7117
7118 @override
7119 Iterable get childEntities => new ChildEntities()
7120 ..add(leftBracket)
7121 ..add(_expression)
7122 ..add(rightBracket);
7123
7124 @override
7125 Token get endToken {
7126 if (rightBracket != null) {
7127 return rightBracket;
7128 }
7129 return _expression.endToken;
7130 }
7131
7132 /**
7133 * Return the expression to be evaluated for the value to be converted into a
7134 * string.
7135 */
7136 Expression get expression => _expression;
7137
7138 /**
7139 * Set the expression to be evaluated for the value to be converted into a
7140 * string to the given [expression].
7141 */
7142 void set expression(Expression expression) {
7143 _expression = _becomeParentOf(expression);
7144 }
7145
7146 @override
7147 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this);
7148
7149 @override
7150 void visitChildren(AstVisitor visitor) {
7151 _safelyVisitChild(_expression, visitor);
7152 }
7153 }
7154
7155 /**
7156 * A non-empty substring of an interpolated string.
7157 *
7158 * > interpolationString ::=
7159 * > characters
7160 */
7161 class InterpolationString extends InterpolationElement {
7162 /**
7163 * The characters that will be added to the string.
7164 */
7165 Token contents;
7166
7167 /**
7168 * The value of the literal.
7169 */
7170 String value;
7171
7172 /**
7173 * Initialize a newly created string of characters that are part of a string
7174 * interpolation.
7175 */
7176 InterpolationString(this.contents, this.value);
7177
7178 @override
7179 Token get beginToken => contents;
7180
7181 @override
7182 Iterable get childEntities => new ChildEntities()..add(contents);
7183
7184 /**
7185 * Return the offset of the after-last contents character.
7186 */
7187 int get contentsEnd {
7188 String lexeme = contents.lexeme;
7189 return offset + new StringLexemeHelper(lexeme, true, true).end;
7190 }
7191
7192 /**
7193 * Return the offset of the first contents character.
7194 */
7195 int get contentsOffset {
7196 int offset = contents.offset;
7197 String lexeme = contents.lexeme;
7198 return offset + new StringLexemeHelper(lexeme, true, true).start;
7199 }
7200
7201 @override
7202 Token get endToken => contents;
7203
7204 @override
7205 accept(AstVisitor visitor) => visitor.visitInterpolationString(this);
7206
7207 @override
7208 void visitChildren(AstVisitor visitor) {}
7209 }
7210
7211 /**
7212 * An is expression.
7213 *
7214 * > isExpression ::=
7215 * > [Expression] 'is' '!'? [TypeName]
7216 */
7217 class IsExpression extends Expression {
7218 /**
7219 * The expression used to compute the value whose type is being tested.
7220 */
7221 Expression _expression;
7222
7223 /**
7224 * The is operator.
7225 */
7226 Token isOperator;
7227
7228 /**
7229 * The not operator, or `null` if the sense of the test is not negated.
7230 */
7231 Token notOperator;
7232
7233 /**
7234 * The name of the type being tested for.
7235 */
7236 TypeName _type;
7237
7238 /**
7239 * Initialize a newly created is expression. The [notOperator] can be `null`
7240 * if the sense of the test is not negated.
7241 */
7242 IsExpression(
7243 Expression expression, this.isOperator, this.notOperator, TypeName type) {
7244 _expression = _becomeParentOf(expression);
7245 _type = _becomeParentOf(type);
7246 }
7247
7248 @override
7249 Token get beginToken => _expression.beginToken;
7250
7251 @override
7252 Iterable get childEntities => new ChildEntities()
7253 ..add(_expression)
7254 ..add(isOperator)
7255 ..add(notOperator)
7256 ..add(_type);
7257
7258 @override
7259 Token get endToken => _type.endToken;
7260
7261 /**
7262 * Return the expression used to compute the value whose type is being tested.
7263 */
7264 Expression get expression => _expression;
7265
7266 /**
7267 * Set the expression used to compute the value whose type is being tested to
7268 * the given [expression].
7269 */
7270 void set expression(Expression expression) {
7271 _expression = _becomeParentOf(expression);
7272 }
7273
7274 @override
7275 int get precedence => 7;
7276
7277 /**
7278 * Return the name of the type being tested for.
7279 */
7280 TypeName get type => _type;
7281
7282 /**
7283 * Set the name of the type being tested for to the given [name].
7284 */
7285 void set type(TypeName name) {
7286 _type = _becomeParentOf(name);
7287 }
7288
7289 @override
7290 accept(AstVisitor visitor) => visitor.visitIsExpression(this);
7291
7292 @override
7293 void visitChildren(AstVisitor visitor) {
7294 _safelyVisitChild(_expression, visitor);
7295 _safelyVisitChild(_type, visitor);
7296 }
7297 }
7298
7299 /**
7300 * A label on either a [LabeledStatement] or a [NamedExpression].
7301 *
7302 * > label ::=
7303 * > [SimpleIdentifier] ':'
7304 */
7305 class Label extends AstNode {
7306 /**
7307 * The label being associated with the statement.
7308 */
7309 SimpleIdentifier _label;
7310
7311 /**
7312 * The colon that separates the label from the statement.
7313 */
7314 Token colon;
7315
7316 /**
7317 * Initialize a newly created label.
7318 */
7319 Label(SimpleIdentifier label, this.colon) {
7320 _label = _becomeParentOf(label);
7321 }
7322
7323 @override
7324 Token get beginToken => _label.beginToken;
7325
7326 @override
7327 Iterable get childEntities => new ChildEntities()..add(_label)..add(colon);
7328
7329 @override
7330 Token get endToken => colon;
7331
7332 /**
7333 * Return the label being associated with the statement.
7334 */
7335 SimpleIdentifier get label => _label;
7336
7337 /**
7338 * Set the label being associated with the statement to the given [label].
7339 */
7340 void set label(SimpleIdentifier label) {
7341 _label = _becomeParentOf(label);
7342 }
7343
7344 @override
7345 accept(AstVisitor visitor) => visitor.visitLabel(this);
7346
7347 @override
7348 void visitChildren(AstVisitor visitor) {
7349 _safelyVisitChild(_label, visitor);
7350 }
7351 }
7352
7353 /**
7354 * A statement that has a label associated with them.
7355 *
7356 * > labeledStatement ::=
7357 * > [Label]+ [Statement]
7358 */
7359 class LabeledStatement extends Statement {
7360 /**
7361 * The labels being associated with the statement.
7362 */
7363 NodeList<Label> _labels;
7364
7365 /**
7366 * The statement with which the labels are being associated.
7367 */
7368 Statement _statement;
7369
7370 /**
7371 * Initialize a newly created labeled statement.
7372 */
7373 LabeledStatement(List<Label> labels, Statement statement) {
7374 _labels = new NodeList<Label>(this, labels);
7375 _statement = _becomeParentOf(statement);
7376 }
7377
7378 @override
7379 Token get beginToken {
7380 if (!_labels.isEmpty) {
7381 return _labels.beginToken;
7382 }
7383 return _statement.beginToken;
7384 }
7385
7386 @override
7387 Iterable get childEntities => new ChildEntities()
7388 ..addAll(_labels)
7389 ..add(_statement);
7390
7391 @override
7392 Token get endToken => _statement.endToken;
7393
7394 /**
7395 * Return the labels being associated with the statement.
7396 */
7397 NodeList<Label> get labels => _labels;
7398
7399 /**
7400 * Return the statement with which the labels are being associated.
7401 */
7402 Statement get statement => _statement;
7403
7404 /**
7405 * Set the statement with which the labels are being associated to the given
7406 * [statement].
7407 */
7408 void set statement(Statement statement) {
7409 _statement = _becomeParentOf(statement);
7410 }
7411
7412 @override
7413 Statement get unlabeled => _statement.unlabeled;
7414
7415 @override
7416 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this);
7417
7418 @override
7419 void visitChildren(AstVisitor visitor) {
7420 _labels.accept(visitor);
7421 _safelyVisitChild(_statement, visitor);
7422 }
7423 }
7424
7425 /**
7426 * A library directive.
7427 *
7428 * > libraryDirective ::=
7429 * > [Annotation] 'library' [Identifier] ';'
7430 */
7431 class LibraryDirective extends Directive {
7432 /**
7433 * The token representing the 'library' keyword.
7434 */
7435 Token libraryKeyword;
7436
7437 /**
7438 * The name of the library being defined.
7439 */
7440 LibraryIdentifier _name;
7441
7442 /**
7443 * The semicolon terminating the directive.
7444 */
7445 Token semicolon;
7446
7447 /**
7448 * Initialize a newly created library directive. Either or both of the
7449 * [comment] and [metadata] can be `null` if the directive does not have the
7450 * corresponding attribute.
7451 */
7452 LibraryDirective(Comment comment, List<Annotation> metadata,
7453 this.libraryKeyword, LibraryIdentifier name, this.semicolon)
7454 : super(comment, metadata) {
7455 _name = _becomeParentOf(name);
7456 }
7457
7458 @override
7459 Iterable get childEntities =>
7460 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon);
7461
7462 @override
7463 Token get endToken => semicolon;
7464
7465 @override
7466 Token get firstTokenAfterCommentAndMetadata => libraryKeyword;
7467
7468 @override
7469 Token get keyword => libraryKeyword;
7470
7471 /**
7472 * Return the name of the library being defined.
7473 */
7474 LibraryIdentifier get name => _name;
7475
7476 /**
7477 * Set the name of the library being defined to the given [name].
7478 */
7479 void set name(LibraryIdentifier name) {
7480 _name = _becomeParentOf(name);
7481 }
7482
7483 @override
7484 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this);
7485
7486 @override
7487 void visitChildren(AstVisitor visitor) {
7488 super.visitChildren(visitor);
7489 _safelyVisitChild(_name, visitor);
7490 }
7491 }
7492
7493 /**
7494 * The identifier for a library.
7495 *
7496 * > libraryIdentifier ::=
7497 * > [SimpleIdentifier] ('.' [SimpleIdentifier])*
7498 */
7499 class LibraryIdentifier extends Identifier {
7500 /**
7501 * The components of the identifier.
7502 */
7503 NodeList<SimpleIdentifier> _components;
14584 7504
14585 /** 7505 /**
14586 * Initialize a newly created prefixed identifier. 7506 * Initialize a newly created prefixed identifier.
14587 */ 7507 */
14588 PrefixedIdentifier( 7508 LibraryIdentifier(List<SimpleIdentifier> components) {
14589 SimpleIdentifier prefix, this.period, SimpleIdentifier identifier) { 7509 _components = new NodeList<SimpleIdentifier>(this, components);
14590 _prefix = _becomeParentOf(prefix); 7510 }
14591 _identifier = _becomeParentOf(identifier); 7511
14592 } 7512 @override
14593 7513 Token get beginToken => _components.beginToken;
14594 @override 7514
14595 Token get beginToken => _prefix.beginToken; 7515 @override
14596 7516 Element get bestElement => staticElement;
14597 @override 7517
14598 Element get bestElement { 7518 @override
14599 if (_identifier == null) { 7519 // TODO(paulberry): add "." tokens.
14600 return null; 7520 Iterable get childEntities => new ChildEntities()..addAll(_components);
14601 } 7521
14602 return _identifier.bestElement; 7522 /**
14603 } 7523 * Return the components of the identifier.
7524 */
7525 NodeList<SimpleIdentifier> get components => _components;
7526
7527 @override
7528 Token get endToken => _components.endToken;
7529
7530 @override
7531 String get name {
7532 StringBuffer buffer = new StringBuffer();
7533 bool needsPeriod = false;
7534 for (SimpleIdentifier identifier in _components) {
7535 if (needsPeriod) {
7536 buffer.write(".");
7537 } else {
7538 needsPeriod = true;
7539 }
7540 buffer.write(identifier.name);
7541 }
7542 return buffer.toString();
7543 }
7544
7545 @override
7546 int get precedence => 15;
7547
7548 @override
7549 Element get propagatedElement => null;
7550
7551 @override
7552 Element get staticElement => null;
7553
7554 @override
7555 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this);
7556
7557 @override
7558 void visitChildren(AstVisitor visitor) {
7559 _components.accept(visitor);
7560 }
7561 }
7562
7563 /**
7564 * A list literal.
7565 *
7566 * > listLiteral ::=
7567 * > 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']'
7568 */
7569 class ListLiteral extends TypedLiteral {
7570 /**
7571 * The left square bracket.
7572 */
7573 Token leftBracket;
7574
7575 /**
7576 * The expressions used to compute the elements of the list.
7577 */
7578 NodeList<Expression> _elements;
7579
7580 /**
7581 * The right square bracket.
7582 */
7583 Token rightBracket;
7584
7585 /**
7586 * Initialize a newly created list literal. The [constKeyword] can be `null`
7587 * if the literal is not a constant. The [typeArguments] can be `null` if no
7588 * type arguments were declared. The list of [elements] can be `null` if the
7589 * list is empty.
7590 */
7591 ListLiteral(Token constKeyword, TypeArgumentList typeArguments,
7592 this.leftBracket, List<Expression> elements, this.rightBracket)
7593 : super(constKeyword, typeArguments) {
7594 _elements = new NodeList<Expression>(this, elements);
7595 }
7596
7597 @override
7598 Token get beginToken {
7599 if (constKeyword != null) {
7600 return constKeyword;
7601 }
7602 TypeArgumentList typeArguments = this.typeArguments;
7603 if (typeArguments != null) {
7604 return typeArguments.beginToken;
7605 }
7606 return leftBracket;
7607 }
7608
7609 @override
7610 // TODO(paulberry): add commas.
7611 Iterable get childEntities => super._childEntities
7612 ..add(leftBracket)
7613 ..addAll(_elements)
7614 ..add(rightBracket);
7615
7616 /**
7617 * Return the expressions used to compute the elements of the list.
7618 */
7619 NodeList<Expression> get elements => _elements;
7620
7621 @override
7622 Token get endToken => rightBracket;
7623
7624 @override
7625 accept(AstVisitor visitor) => visitor.visitListLiteral(this);
7626
7627 @override
7628 void visitChildren(AstVisitor visitor) {
7629 super.visitChildren(visitor);
7630 _elements.accept(visitor);
7631 }
7632 }
7633
7634 /**
7635 * A node that represents a literal expression.
7636 *
7637 * > literal ::=
7638 * > [BooleanLiteral]
7639 * > | [DoubleLiteral]
7640 * > | [IntegerLiteral]
7641 * > | [ListLiteral]
7642 * > | [MapLiteral]
7643 * > | [NullLiteral]
7644 * > | [StringLiteral]
7645 */
7646 abstract class Literal extends Expression {
7647 @override
7648 int get precedence => 16;
7649 }
7650
7651 /**
7652 * A literal map.
7653 *
7654 * > mapLiteral ::=
7655 * > 'const'? ('<' [TypeName] (',' [TypeName])* '>')?
7656 * > '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}'
7657 */
7658 class MapLiteral extends TypedLiteral {
7659 /**
7660 * The left curly bracket.
7661 */
7662 Token leftBracket;
7663
7664 /**
7665 * The entries in the map.
7666 */
7667 NodeList<MapLiteralEntry> _entries;
7668
7669 /**
7670 * The right curly bracket.
7671 */
7672 Token rightBracket;
7673
7674 /**
7675 * Initialize a newly created map literal. The [constKeyword] can be `null` if
7676 * the literal is not a constant. The [typeArguments] can be `null` if no type
7677 * arguments were declared. The [entries] can be `null` if the map is empty.
7678 */
7679 MapLiteral(Token constKeyword, TypeArgumentList typeArguments,
7680 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket)
7681 : super(constKeyword, typeArguments) {
7682 _entries = new NodeList<MapLiteralEntry>(this, entries);
7683 }
7684
7685 @override
7686 Token get beginToken {
7687 if (constKeyword != null) {
7688 return constKeyword;
7689 }
7690 TypeArgumentList typeArguments = this.typeArguments;
7691 if (typeArguments != null) {
7692 return typeArguments.beginToken;
7693 }
7694 return leftBracket;
7695 }
7696
7697 @override
7698 // TODO(paulberry): add commas.
7699 Iterable get childEntities => super._childEntities
7700 ..add(leftBracket)
7701 ..addAll(entries)
7702 ..add(rightBracket);
7703
7704 @override
7705 Token get endToken => rightBracket;
7706
7707 /**
7708 * Return the entries in the map.
7709 */
7710 NodeList<MapLiteralEntry> get entries => _entries;
7711
7712 @override
7713 accept(AstVisitor visitor) => visitor.visitMapLiteral(this);
7714
7715 @override
7716 void visitChildren(AstVisitor visitor) {
7717 super.visitChildren(visitor);
7718 _entries.accept(visitor);
7719 }
7720 }
7721
7722 /**
7723 * A single key/value pair in a map literal.
7724 *
7725 * > mapLiteralEntry ::=
7726 * > [Expression] ':' [Expression]
7727 */
7728 class MapLiteralEntry extends AstNode {
7729 /**
7730 * The expression computing the key with which the value will be associated.
7731 */
7732 Expression _key;
7733
7734 /**
7735 * The colon that separates the key from the value.
7736 */
7737 Token separator;
7738
7739 /**
7740 * The expression computing the value that will be associated with the key.
7741 */
7742 Expression _value;
7743
7744 /**
7745 * Initialize a newly created map literal entry.
7746 */
7747 MapLiteralEntry(Expression key, this.separator, Expression value) {
7748 _key = _becomeParentOf(key);
7749 _value = _becomeParentOf(value);
7750 }
7751
7752 @override
7753 Token get beginToken => _key.beginToken;
14604 7754
14605 @override 7755 @override
14606 Iterable get childEntities => 7756 Iterable get childEntities =>
14607 new ChildEntities()..add(_prefix)..add(period)..add(_identifier); 7757 new ChildEntities()..add(_key)..add(separator)..add(_value);
14608 7758
14609 @override 7759 @override
14610 Token get endToken => _identifier.endToken; 7760 Token get endToken => _value.endToken;
14611 7761
14612 /** 7762 /**
14613 * Return the identifier being prefixed. 7763 * Return the expression computing the key with which the value will be
14614 */ 7764 * associated.
14615 SimpleIdentifier get identifier => _identifier; 7765 */
14616 7766 Expression get key => _key;
14617 /** 7767
14618 * Set the identifier being prefixed to the given [identifier]. 7768 /**
14619 */ 7769 * Set the expression computing the key with which the value will be
14620 void set identifier(SimpleIdentifier identifier) { 7770 * associated to the given [string].
14621 _identifier = _becomeParentOf(identifier); 7771 */
14622 } 7772 void set key(Expression string) {
14623 7773 _key = _becomeParentOf(string);
14624 /** 7774 }
14625 * Return `true` if this type is a deferred type. If the AST structure has not 7775
14626 * been resolved, then return `false`. 7776 /**
14627 * 7777 * Return the expression computing the value that will be associated with the
14628 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form 7778 * key.
14629 * </i>p.T</i> where <i>p</i> is a deferred prefix. 7779 */
14630 */ 7780 Expression get value => _value;
14631 bool get isDeferred { 7781
14632 Element element = _prefix.staticElement; 7782 /**
14633 if (element is! PrefixElement) { 7783 * Set the expression computing the value that will be associated with the key
14634 return false; 7784 * to the given [expression].
14635 } 7785 */
14636 PrefixElement prefixElement = element as PrefixElement; 7786 void set value(Expression expression) {
14637 List<ImportElement> imports = 7787 _value = _becomeParentOf(expression);
14638 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement); 7788 }
14639 if (imports.length != 1) { 7789
14640 return false; 7790 @override
14641 } 7791 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this);
14642 return imports[0].isDeferred;
14643 }
14644
14645 @override
14646 String get name => "${_prefix.name}.${_identifier.name}";
14647
14648 @override
14649 int get precedence => 15;
14650
14651 /**
14652 * Return the prefix associated with the library in which the identifier is
14653 * defined.
14654 */
14655 SimpleIdentifier get prefix => _prefix;
14656
14657 /**
14658 * Set the prefix associated with the library in which the identifier is
14659 * defined to the given [identifier].
14660 */
14661 void set prefix(SimpleIdentifier identifier) {
14662 _prefix = _becomeParentOf(identifier);
14663 }
14664
14665 @override
14666 Element get propagatedElement {
14667 if (_identifier == null) {
14668 return null;
14669 }
14670 return _identifier.propagatedElement;
14671 }
14672
14673 @override
14674 Element get staticElement {
14675 if (_identifier == null) {
14676 return null;
14677 }
14678 return _identifier.staticElement;
14679 }
14680
14681 @override
14682 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this);
14683 7792
14684 @override 7793 @override
14685 void visitChildren(AstVisitor visitor) { 7794 void visitChildren(AstVisitor visitor) {
14686 _safelyVisitChild(_prefix, visitor); 7795 _safelyVisitChild(_key, visitor);
14687 _safelyVisitChild(_identifier, visitor); 7796 _safelyVisitChild(_value, visitor);
14688 } 7797 }
14689 } 7798 }
14690 7799
14691 /** 7800 /**
14692 * A prefix unary expression. 7801 * A method declaration.
14693 * 7802 *
14694 * > prefixExpression ::= 7803 * > methodDeclaration ::=
14695 * > [Token] [Expression] 7804 * > methodSignature [FunctionBody]
14696 */ 7805 * >
14697 class PrefixExpression extends Expression { 7806 * > methodSignature ::=
14698 /** 7807 * > 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')?
14699 * The prefix operator being applied to the operand. 7808 * > methodName [TypeParameterList] [FormalParameterList]
7809 * >
7810 * > methodName ::=
7811 * > [SimpleIdentifier]
7812 * > | 'operator' [SimpleIdentifier]
7813 */
7814 class MethodDeclaration extends ClassMember {
7815 /**
7816 * The token for the 'external' keyword, or `null` if the constructor is not
7817 * external.
7818 */
7819 Token externalKeyword;
7820
7821 /**
7822 * The token representing the 'abstract' or 'static' keyword, or `null` if
7823 * neither modifier was specified.
7824 */
7825 Token modifierKeyword;
7826
7827 /**
7828 * The return type of the method, or `null` if no return type was declared.
7829 */
7830 TypeName _returnType;
7831
7832 /**
7833 * The token representing the 'get' or 'set' keyword, or `null` if this is a
7834 * method declaration rather than a property declaration.
7835 */
7836 Token propertyKeyword;
7837
7838 /**
7839 * The token representing the 'operator' keyword, or `null` if this method
7840 * does not declare an operator.
7841 */
7842 Token operatorKeyword;
7843
7844 /**
7845 * The name of the method.
7846 */
7847 SimpleIdentifier _name;
7848
7849 /**
7850 * The type parameters associated with the method, or `null` if the method is
7851 * not a generic method.
7852 */
7853 TypeParameterList _typeParameters;
7854
7855 /**
7856 * The parameters associated with the method, or `null` if this method
7857 * declares a getter.
7858 */
7859 FormalParameterList _parameters;
7860
7861 /**
7862 * The body of the method.
7863 */
7864 FunctionBody _body;
7865
7866 /**
7867 * Initialize a newly created method declaration. Either or both of the
7868 * [comment] and [metadata] can be `null` if the declaration does not have the
7869 * corresponding attribute. The [externalKeyword] can be `null` if the method
7870 * is not external. The [modifierKeyword] can be `null` if the method is
7871 * neither abstract nor static. The [returnType] can be `null` if no return
7872 * type was specified. The [propertyKeyword] can be `null` if the method is
7873 * neither a getter or a setter. The [operatorKeyword] can be `null` if the
7874 * method does not implement an operator. The [parameters] must be `null` if
7875 * this method declares a getter.
7876 */
7877 MethodDeclaration(
7878 Comment comment,
7879 List<Annotation> metadata,
7880 this.externalKeyword,
7881 this.modifierKeyword,
7882 TypeName returnType,
7883 this.propertyKeyword,
7884 this.operatorKeyword,
7885 SimpleIdentifier name,
7886 TypeParameterList typeParameters,
7887 FormalParameterList parameters,
7888 FunctionBody body)
7889 : super(comment, metadata) {
7890 _returnType = _becomeParentOf(returnType);
7891 _name = _becomeParentOf(name);
7892 _typeParameters = _becomeParentOf(typeParameters);
7893 _parameters = _becomeParentOf(parameters);
7894 _body = _becomeParentOf(body);
7895 }
7896
7897 /**
7898 * Return the body of the method.
7899 */
7900 FunctionBody get body => _body;
7901
7902 /**
7903 * Set the body of the method to the given [functionBody].
7904 */
7905 void set body(FunctionBody functionBody) {
7906 _body = _becomeParentOf(functionBody);
7907 }
7908
7909 @override
7910 Iterable get childEntities => super._childEntities
7911 ..add(externalKeyword)
7912 ..add(modifierKeyword)
7913 ..add(_returnType)
7914 ..add(propertyKeyword)
7915 ..add(operatorKeyword)
7916 ..add(_name)
7917 ..add(_parameters)
7918 ..add(_body);
7919
7920 /**
7921 * Return the element associated with this method, or `null` if the AST
7922 * structure has not been resolved. The element can either be a
7923 * [MethodElement], if this represents the declaration of a normal method, or
7924 * a [PropertyAccessorElement] if this represents the declaration of either a
7925 * getter or a setter.
7926 */
7927 @override
7928 ExecutableElement get element =>
7929 _name != null ? (_name.staticElement as ExecutableElement) : null;
7930
7931 @override
7932 Token get endToken => _body.endToken;
7933
7934 @override
7935 Token get firstTokenAfterCommentAndMetadata {
7936 if (modifierKeyword != null) {
7937 return modifierKeyword;
7938 } else if (_returnType != null) {
7939 return _returnType.beginToken;
7940 } else if (propertyKeyword != null) {
7941 return propertyKeyword;
7942 } else if (operatorKeyword != null) {
7943 return operatorKeyword;
7944 }
7945 return _name.beginToken;
7946 }
7947
7948 /**
7949 * Return `true` if this method is declared to be an abstract method.
7950 */
7951 bool get isAbstract {
7952 FunctionBody body = _body;
7953 return externalKeyword == null &&
7954 (body is EmptyFunctionBody && !body.semicolon.isSynthetic);
7955 }
7956
7957 /**
7958 * Return `true` if this method declares a getter.
7959 */
7960 bool get isGetter =>
7961 propertyKeyword != null &&
7962 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
7963
7964 /**
7965 * Return `true` if this method declares an operator.
7966 */
7967 bool get isOperator => operatorKeyword != null;
7968
7969 /**
7970 * Return `true` if this method declares a setter.
7971 */
7972 bool get isSetter =>
7973 propertyKeyword != null &&
7974 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
7975
7976 /**
7977 * Return `true` if this method is declared to be a static method.
7978 */
7979 bool get isStatic =>
7980 modifierKeyword != null &&
7981 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC;
7982
7983 /**
7984 * Return the name of the method.
7985 */
7986 SimpleIdentifier get name => _name;
7987
7988 /**
7989 * Set the name of the method to the given [identifier].
7990 */
7991 void set name(SimpleIdentifier identifier) {
7992 _name = _becomeParentOf(identifier);
7993 }
7994
7995 /**
7996 * Return the parameters associated with the method, or `null` if this method
7997 * declares a getter.
7998 */
7999 FormalParameterList get parameters => _parameters;
8000
8001 /**
8002 * Set the parameters associated with the method to the given list of
8003 * [parameters].
8004 */
8005 void set parameters(FormalParameterList parameters) {
8006 _parameters = _becomeParentOf(parameters);
8007 }
8008
8009 /**
8010 * Return the return type of the method, or `null` if no return type was
8011 * declared.
8012 */
8013 TypeName get returnType => _returnType;
8014
8015 /**
8016 * Set the return type of the method to the given [typeName].
8017 */
8018 void set returnType(TypeName typeName) {
8019 _returnType = _becomeParentOf(typeName);
8020 }
8021
8022 /**
8023 * Return the type parameters associated with this method, or `null` if this
8024 * method is not a generic method.
8025 */
8026 TypeParameterList get typeParameters => _typeParameters;
8027
8028 /**
8029 * Set the type parameters associated with this method to the given
8030 * [typeParameters].
8031 */
8032 void set typeParameters(TypeParameterList typeParameters) {
8033 _typeParameters = _becomeParentOf(typeParameters);
8034 }
8035
8036 @override
8037 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this);
8038
8039 @override
8040 void visitChildren(AstVisitor visitor) {
8041 super.visitChildren(visitor);
8042 _safelyVisitChild(_returnType, visitor);
8043 _safelyVisitChild(_name, visitor);
8044 _safelyVisitChild(_typeParameters, visitor);
8045 _safelyVisitChild(_parameters, visitor);
8046 _safelyVisitChild(_body, visitor);
8047 }
8048 }
8049
8050 /**
8051 * The invocation of either a function or a method. Invocations of functions
8052 * resulting from evaluating an expression are represented by
8053 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are
8054 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes.
8055 *
8056 * > methodInvocation ::=
8057 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t]
8058 */
8059 class MethodInvocation extends Expression {
8060 /**
8061 * The expression producing the object on which the method is defined, or
8062 * `null` if there is no target (that is, the target is implicitly `this`).
8063 */
8064 Expression _target;
8065
8066 /**
8067 * The operator that separates the target from the method name, or `null`
8068 * if there is no target. In an ordinary method invocation this will be a
8069 * period ('.'). In a cascade section this will be the cascade operator
8070 * ('..').
14700 */ 8071 */
14701 Token operator; 8072 Token operator;
14702 8073
14703 /** 8074 /**
14704 * The expression computing the operand for the operator. 8075 * The name of the method being invoked.
14705 */ 8076 */
14706 Expression _operand; 8077 SimpleIdentifier _methodName;
14707 8078
14708 /** 8079 /**
14709 * The element associated with the operator based on the static type of the 8080 * The type arguments to be applied to the method being invoked, or `null` if
14710 * operand, or `null` if the AST structure has not been resolved, if the 8081 * no type arguments were provided.
14711 * operator is not user definable, or if the operator could not be resolved. 8082 */
14712 */ 8083 TypeArgumentList _typeArguments;
14713 MethodElement staticElement; 8084
14714 8085 /**
14715 /** 8086 * The list of arguments to the method.
14716 * The element associated with the operator based on the propagated type of 8087 */
14717 * the operand, or `null` if the AST structure has not been resolved, if the 8088 ArgumentList _argumentList;
14718 * operator is not user definable, or if the operator could not be resolved. 8089
14719 */ 8090 /**
14720 MethodElement propagatedElement; 8091 * Initialize a newly created method invocation. The [target] and [operator]
14721 8092 * can be `null` if there is no target.
14722 /** 8093 */
14723 * Initialize a newly created prefix expression. 8094 MethodInvocation(
14724 */ 8095 Expression target,
14725 PrefixExpression(this.operator, Expression operand) { 8096 this.operator,
14726 _operand = _becomeParentOf(operand); 8097 SimpleIdentifier methodName,
14727 } 8098 TypeArgumentList typeArguments,
14728 8099 ArgumentList argumentList) {
14729 @override
14730 Token get beginToken => operator;
14731
14732 /**
14733 * Return the best element available for this operator. If resolution was able
14734 * to find a better element based on type propagation, that element will be
14735 * returned. Otherwise, the element found using the result of static analysis
14736 * will be returned. If resolution has not been performed, then `null` will be
14737 * returned.
14738 */
14739 MethodElement get bestElement {
14740 MethodElement element = propagatedElement;
14741 if (element == null) {
14742 element = staticElement;
14743 }
14744 return element;
14745 }
14746
14747 @override
14748 Iterable get childEntities =>
14749 new ChildEntities()..add(operator)..add(_operand);
14750
14751 @override
14752 Token get endToken => _operand.endToken;
14753
14754 /**
14755 * Return the expression computing the operand for the operator.
14756 */
14757 Expression get operand => _operand;
14758
14759 /**
14760 * Set the expression computing the operand for the operator to the given
14761 * [expression].
14762 */
14763 void set operand(Expression expression) {
14764 _operand = _becomeParentOf(expression);
14765 }
14766
14767 @override
14768 int get precedence => 14;
14769
14770 /**
14771 * If the AST structure has been resolved, and the function being invoked is
14772 * known based on propagated type information, then return the parameter
14773 * element representing the parameter to which the value of the operand will
14774 * be bound. Otherwise, return `null`.
14775 */
14776 ParameterElement get _propagatedParameterElementForOperand {
14777 if (propagatedElement == null) {
14778 return null;
14779 }
14780 List<ParameterElement> parameters = propagatedElement.parameters;
14781 if (parameters.length < 1) {
14782 return null;
14783 }
14784 return parameters[0];
14785 }
14786
14787 /**
14788 * If the AST structure has been resolved, and the function being invoked is
14789 * known based on static type information, then return the parameter element
14790 * representing the parameter to which the value of the operand will be bound.
14791 * Otherwise, return `null`.
14792 */
14793 ParameterElement get _staticParameterElementForOperand {
14794 if (staticElement == null) {
14795 return null;
14796 }
14797 List<ParameterElement> parameters = staticElement.parameters;
14798 if (parameters.length < 1) {
14799 return null;
14800 }
14801 return parameters[0];
14802 }
14803
14804 @override
14805 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this);
14806
14807 @override
14808 void visitChildren(AstVisitor visitor) {
14809 _safelyVisitChild(_operand, visitor);
14810 }
14811 }
14812
14813 /**
14814 * The access of a property of an object.
14815 *
14816 * Note, however, that accesses to properties of objects can also be represented
14817 * as [PrefixedIdentifier] nodes in cases where the target is also a simple
14818 * identifier.
14819 *
14820 * > propertyAccess ::=
14821 * > [Expression] '.' [SimpleIdentifier]
14822 */
14823 class PropertyAccess extends Expression {
14824 /**
14825 * The expression computing the object defining the property being accessed.
14826 */
14827 Expression _target;
14828
14829 /**
14830 * The property access operator.
14831 */
14832 Token operator;
14833
14834 /**
14835 * The name of the property being accessed.
14836 */
14837 SimpleIdentifier _propertyName;
14838
14839 /**
14840 * Initialize a newly created property access expression.
14841 */
14842 PropertyAccess(
14843 Expression target, this.operator, SimpleIdentifier propertyName) {
14844 _target = _becomeParentOf(target); 8100 _target = _becomeParentOf(target);
14845 _propertyName = _becomeParentOf(propertyName); 8101 _methodName = _becomeParentOf(methodName);
8102 _typeArguments = _becomeParentOf(typeArguments);
8103 _argumentList = _becomeParentOf(argumentList);
8104 }
8105
8106 /**
8107 * Return the list of arguments to the method.
8108 */
8109 ArgumentList get argumentList => _argumentList;
8110
8111 /**
8112 * Set the list of arguments to the method to the given [argumentList].
8113 */
8114 void set argumentList(ArgumentList argumentList) {
8115 _argumentList = _becomeParentOf(argumentList);
14846 } 8116 }
14847 8117
14848 @override 8118 @override
14849 Token get beginToken { 8119 Token get beginToken {
14850 if (_target != null) { 8120 if (_target != null) {
14851 return _target.beginToken; 8121 return _target.beginToken;
14852 } 8122 } else if (operator != null) {
14853 return operator; 8123 return operator;
14854 } 8124 }
14855 8125 return _methodName.beginToken;
14856 @override 8126 }
14857 Iterable get childEntities => 8127
14858 new ChildEntities()..add(_target)..add(operator)..add(_propertyName); 8128 @override
14859 8129 Iterable get childEntities => new ChildEntities()
14860 @override 8130 ..add(_target)
14861 Token get endToken => _propertyName.endToken; 8131 ..add(operator)
14862 8132 ..add(_methodName)
14863 @override 8133 ..add(_argumentList);
14864 bool get isAssignable => true; 8134
8135 @override
8136 Token get endToken => _argumentList.endToken;
14865 8137
14866 /** 8138 /**
14867 * Return `true` if this expression is cascaded. If it is, then the target of 8139 * Return `true` if this expression is cascaded. If it is, then the target of
14868 * this expression is not stored locally but is stored in the nearest ancestor 8140 * this expression is not stored locally but is stored in the nearest ancestor
14869 * that is a [CascadeExpression]. 8141 * that is a [CascadeExpression].
14870 */ 8142 */
14871 bool get isCascaded => 8143 bool get isCascaded =>
14872 operator != null && operator.type == TokenType.PERIOD_PERIOD; 8144 operator != null && operator.type == TokenType.PERIOD_PERIOD;
14873 8145
8146 /**
8147 * Return the name of the method being invoked.
8148 */
8149 SimpleIdentifier get methodName => _methodName;
8150
8151 /**
8152 * Set the name of the method being invoked to the given [identifier].
8153 */
8154 void set methodName(SimpleIdentifier identifier) {
8155 _methodName = _becomeParentOf(identifier);
8156 }
8157
14874 @override 8158 @override
14875 int get precedence => 15; 8159 int get precedence => 15;
14876 8160
14877 /** 8161 /**
14878 * Return the name of the property being accessed.
14879 */
14880 SimpleIdentifier get propertyName => _propertyName;
14881
14882 /**
14883 * Set the name of the property being accessed to the given [identifier].
14884 */
14885 void set propertyName(SimpleIdentifier identifier) {
14886 _propertyName = _becomeParentOf(identifier);
14887 }
14888
14889 /**
14890 * Return the expression used to compute the receiver of the invocation. If 8162 * Return the expression used to compute the receiver of the invocation. If
14891 * this invocation is not part of a cascade expression, then this is the same 8163 * this invocation is not part of a cascade expression, then this is the same
14892 * as [target]. If this invocation is part of a cascade expression, then the 8164 * as [target]. If this invocation is part of a cascade expression, then the
14893 * target stored with the cascade expression is returned. 8165 * target stored with the cascade expression is returned.
14894 */ 8166 */
14895 Expression get realTarget { 8167 Expression get realTarget {
14896 if (isCascaded) { 8168 if (isCascaded) {
14897 AstNode ancestor = parent; 8169 AstNode ancestor = parent;
14898 while (ancestor is! CascadeExpression) { 8170 while (ancestor is! CascadeExpression) {
14899 if (ancestor == null) { 8171 if (ancestor == null) {
14900 return _target; 8172 return _target;
14901 } 8173 }
14902 ancestor = ancestor.parent; 8174 ancestor = ancestor.parent;
14903 } 8175 }
14904 return (ancestor as CascadeExpression).target; 8176 return (ancestor as CascadeExpression).target;
14905 } 8177 }
14906 return _target; 8178 return _target;
14907 } 8179 }
14908 8180
14909 /** 8181 /**
8182 * Return the expression producing the object on which the method is defined,
8183 * or `null` if there is no target (that is, the target is implicitly `this`)
8184 * or if this method invocation is part of a cascade expression.
8185 *
8186 * Use [realTarget] to get the target independent of whether this is part of a
8187 * cascade expression.
8188 */
8189 Expression get target => _target;
8190
8191 /**
8192 * Set the expression producing the object on which the method is defined to
8193 * the given [expression].
8194 */
8195 void set target(Expression expression) {
8196 _target = _becomeParentOf(expression);
8197 }
8198
8199 /**
8200 * Return the type arguments to be applied to the method being invoked, or
8201 * `null` if no type arguments were provided.
8202 */
8203 TypeArgumentList get typeArguments => _typeArguments;
8204
8205 /**
8206 * Set the type arguments to be applied to the method being invoked to the
8207 * given [typeArguments].
8208 */
8209 void set typeArguments(TypeArgumentList typeArguments) {
8210 _typeArguments = _becomeParentOf(typeArguments);
8211 }
8212
8213 @override
8214 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this);
8215
8216 @override
8217 void visitChildren(AstVisitor visitor) {
8218 _safelyVisitChild(_target, visitor);
8219 _safelyVisitChild(_methodName, visitor);
8220 _safelyVisitChild(_typeArguments, visitor);
8221 _safelyVisitChild(_argumentList, visitor);
8222 }
8223 }
8224
8225 /**
8226 * A node that declares a single name within the scope of a compilation unit.
8227 */
8228 abstract class NamedCompilationUnitMember extends CompilationUnitMember {
8229 /**
8230 * The name of the member being declared.
8231 */
8232 SimpleIdentifier _name;
8233
8234 /**
8235 * Initialize a newly created compilation unit member with the given [name].
8236 * Either or both of the [comment] and [metadata] can be `null` if the member
8237 * does not have the corresponding attribute.
8238 */
8239 NamedCompilationUnitMember(
8240 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
8241 : super(comment, metadata) {
8242 _name = _becomeParentOf(name);
8243 }
8244
8245 /**
8246 * Return the name of the member being declared.
8247 */
8248 SimpleIdentifier get name => _name;
8249
8250 /**
8251 * Set the name of the member being declared to the given [identifier].
8252 */
8253 void set name(SimpleIdentifier identifier) {
8254 _name = _becomeParentOf(identifier);
8255 }
8256 }
8257
8258 /**
8259 * An expression that has a name associated with it. They are used in method
8260 * invocations when there are named parameters.
8261 *
8262 * > namedExpression ::=
8263 * > [Label] [Expression]
8264 */
8265 class NamedExpression extends Expression {
8266 /**
8267 * The name associated with the expression.
8268 */
8269 Label _name;
8270
8271 /**
8272 * The expression with which the name is associated.
8273 */
8274 Expression _expression;
8275
8276 /**
8277 * Initialize a newly created named expression..
8278 */
8279 NamedExpression(Label name, Expression expression) {
8280 _name = _becomeParentOf(name);
8281 _expression = _becomeParentOf(expression);
8282 }
8283
8284 @override
8285 Token get beginToken => _name.beginToken;
8286
8287 @override
8288 Iterable get childEntities =>
8289 new ChildEntities()..add(_name)..add(_expression);
8290
8291 /**
8292 * Return the element representing the parameter being named by this
8293 * expression, or `null` if the AST structure has not been resolved or if
8294 * there is no parameter with the same name as this expression.
8295 */
8296 ParameterElement get element {
8297 Element element = _name.label.staticElement;
8298 if (element is ParameterElement) {
8299 return element;
8300 }
8301 return null;
8302 }
8303
8304 @override
8305 Token get endToken => _expression.endToken;
8306
8307 /**
8308 * Return the expression with which the name is associated.
8309 */
8310 Expression get expression => _expression;
8311
8312 /**
8313 * Set the expression with which the name is associated to the given
8314 * [expression].
8315 */
8316 void set expression(Expression expression) {
8317 _expression = _becomeParentOf(expression);
8318 }
8319
8320 /**
8321 * Return the name associated with the expression.
8322 */
8323 Label get name => _name;
8324
8325 /**
8326 * Set the name associated with the expression to the given [identifier].
8327 */
8328 void set name(Label identifier) {
8329 _name = _becomeParentOf(identifier);
8330 }
8331
8332 @override
8333 int get precedence => 0;
8334
8335 @override
8336 accept(AstVisitor visitor) => visitor.visitNamedExpression(this);
8337
8338 @override
8339 void visitChildren(AstVisitor visitor) {
8340 _safelyVisitChild(_name, visitor);
8341 _safelyVisitChild(_expression, visitor);
8342 }
8343 }
8344
8345 /**
8346 * A node that represents a directive that impacts the namespace of a library.
8347 *
8348 * > directive ::=
8349 * > [ExportDirective]
8350 * > | [ImportDirective]
8351 */
8352 abstract class NamespaceDirective extends UriBasedDirective {
8353 /**
8354 * The token representing the 'import' or 'export' keyword.
8355 */
8356 Token keyword;
8357
8358 /**
8359 * The configurations used to control which library will actually be loaded at
8360 * run-time.
8361 */
8362 NodeList<Configuration> _configurations;
8363
8364 /**
8365 * The combinators used to control which names are imported or exported.
8366 */
8367 NodeList<Combinator> _combinators;
8368
8369 /**
8370 * The semicolon terminating the directive.
8371 */
8372 Token semicolon;
8373
8374 /**
8375 * Initialize a newly created namespace directive. Either or both of the
8376 * [comment] and [metadata] can be `null` if the directive does not have the
8377 * corresponding attribute. The list of [combinators] can be `null` if there
8378 * are no combinators.
8379 */
8380 NamespaceDirective(
8381 Comment comment,
8382 List<Annotation> metadata,
8383 this.keyword,
8384 StringLiteral libraryUri,
8385 List<Configuration> configurations,
8386 List<Combinator> combinators,
8387 this.semicolon)
8388 : super(comment, metadata, libraryUri) {
8389 _configurations = new NodeList<Configuration>(this, configurations);
8390 _combinators = new NodeList<Combinator>(this, combinators);
8391 }
8392
8393 /**
8394 * Return the combinators used to control how names are imported or exported.
8395 */
8396 NodeList<Combinator> get combinators => _combinators;
8397
8398 /**
8399 * Return the configurations used to control which library will actually be
8400 * loaded at run-time.
8401 */
8402 NodeList<Configuration> get configurations => _configurations;
8403
8404 @override
8405 Token get endToken => semicolon;
8406
8407 @override
8408 Token get firstTokenAfterCommentAndMetadata => keyword;
8409
8410 @override
8411 LibraryElement get uriElement;
8412 }
8413
8414 /**
8415 * The "native" clause in an class declaration.
8416 *
8417 * > nativeClause ::=
8418 * > 'native' [StringLiteral]
8419 */
8420 class NativeClause extends AstNode {
8421 /**
8422 * The token representing the 'native' keyword.
8423 */
8424 Token nativeKeyword;
8425
8426 /**
8427 * The name of the native object that implements the class.
8428 */
8429 StringLiteral _name;
8430
8431 /**
8432 * Initialize a newly created native clause.
8433 */
8434 NativeClause(this.nativeKeyword, StringLiteral name) {
8435 _name = _becomeParentOf(name);
8436 }
8437
8438 @override
8439 Token get beginToken => nativeKeyword;
8440
8441 @override
8442 Iterable get childEntities =>
8443 new ChildEntities()..add(nativeKeyword)..add(_name);
8444
8445 @override
8446 Token get endToken => _name.endToken;
8447
8448 /**
8449 * Return the name of the native object that implements the class.
8450 */
8451 StringLiteral get name => _name;
8452
8453 /**
8454 * Set the name of the native object that implements the class to the given
8455 * [name].
8456 */
8457 void set name(StringLiteral name) {
8458 _name = _becomeParentOf(name);
8459 }
8460
8461 @override
8462 accept(AstVisitor visitor) => visitor.visitNativeClause(this);
8463
8464 @override
8465 void visitChildren(AstVisitor visitor) {
8466 _safelyVisitChild(_name, visitor);
8467 }
8468 }
8469
8470 /**
8471 * A function body that consists of a native keyword followed by a string
8472 * literal.
8473 *
8474 * > nativeFunctionBody ::=
8475 * > 'native' [SimpleStringLiteral] ';'
8476 */
8477 class NativeFunctionBody extends FunctionBody {
8478 /**
8479 * The token representing 'native' that marks the start of the function body.
8480 */
8481 Token nativeKeyword;
8482
8483 /**
8484 * The string literal, after the 'native' token.
8485 */
8486 StringLiteral _stringLiteral;
8487
8488 /**
8489 * The token representing the semicolon that marks the end of the function
8490 * body.
8491 */
8492 Token semicolon;
8493
8494 /**
8495 * Initialize a newly created function body consisting of the 'native' token,
8496 * a string literal, and a semicolon.
8497 */
8498 NativeFunctionBody(
8499 this.nativeKeyword, StringLiteral stringLiteral, this.semicolon) {
8500 _stringLiteral = _becomeParentOf(stringLiteral);
8501 }
8502
8503 @override
8504 Token get beginToken => nativeKeyword;
8505
8506 @override
8507 Iterable get childEntities => new ChildEntities()
8508 ..add(nativeKeyword)
8509 ..add(_stringLiteral)
8510 ..add(semicolon);
8511
8512 @override
8513 Token get endToken => semicolon;
8514
8515 /**
8516 * Return the string literal representing the string after the 'native' token.
8517 */
8518 StringLiteral get stringLiteral => _stringLiteral;
8519
8520 /**
8521 * Set the string literal representing the string after the 'native' token to
8522 * the given [stringLiteral].
8523 */
8524 void set stringLiteral(StringLiteral stringLiteral) {
8525 _stringLiteral = _becomeParentOf(stringLiteral);
8526 }
8527
8528 @override
8529 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this);
8530
8531 @override
8532 void visitChildren(AstVisitor visitor) {
8533 _safelyVisitChild(_stringLiteral, visitor);
8534 }
8535 }
8536
8537 /**
8538 * A list of AST nodes that have a common parent.
8539 */
8540 class NodeList<E extends AstNode> extends Object with ListMixin<E> {
8541 /**
8542 * The node that is the parent of each of the elements in the list.
8543 */
8544 AstNode owner;
8545
8546 /**
8547 * The elements contained in the list.
8548 */
8549 List<E> _elements = <E>[];
8550
8551 /**
8552 * Initialize a newly created list of nodes such that all of the nodes that
8553 * are added to the list will have their parent set to the given [owner]. The
8554 * list will initially be populated with the given [elements].
8555 */
8556 NodeList(this.owner, [List<E> elements]) {
8557 addAll(elements);
8558 }
8559
8560 /**
8561 * Return the first token included in this node list's source range, or `null`
8562 * if the list is empty.
8563 */
8564 Token get beginToken {
8565 if (_elements.length == 0) {
8566 return null;
8567 }
8568 return _elements[0].beginToken;
8569 }
8570
8571 /**
8572 * Return the last token included in this node list's source range, or `null`
8573 * if the list is empty.
8574 */
8575 Token get endToken {
8576 int length = _elements.length;
8577 if (length == 0) {
8578 return null;
8579 }
8580 return _elements[length - 1].endToken;
8581 }
8582
8583 int get length => _elements.length;
8584
8585 @deprecated // Never intended for public use.
8586 @override
8587 void set length(int newLength) {
8588 throw new UnsupportedError("Cannot resize NodeList.");
8589 }
8590
8591 E operator [](int index) {
8592 if (index < 0 || index >= _elements.length) {
8593 throw new RangeError("Index: $index, Size: ${_elements.length}");
8594 }
8595 return _elements[index];
8596 }
8597
8598 void operator []=(int index, E node) {
8599 if (index < 0 || index >= _elements.length) {
8600 throw new RangeError("Index: $index, Size: ${_elements.length}");
8601 }
8602 owner._becomeParentOf(node);
8603 _elements[index] = node;
8604 }
8605
8606 /**
8607 * Use the given [visitor] to visit each of the nodes in this list.
8608 */
8609 accept(AstVisitor visitor) {
8610 int length = _elements.length;
8611 for (var i = 0; i < length; i++) {
8612 _elements[i].accept(visitor);
8613 }
8614 }
8615
8616 @override
8617 void add(E node) {
8618 insert(length, node);
8619 }
8620
8621 @override
8622 bool addAll(Iterable<E> nodes) {
8623 if (nodes != null && !nodes.isEmpty) {
8624 _elements.addAll(nodes);
8625 for (E node in nodes) {
8626 owner._becomeParentOf(node);
8627 }
8628 return true;
8629 }
8630 return false;
8631 }
8632
8633 @override
8634 void clear() {
8635 _elements = <E>[];
8636 }
8637
8638 @override
8639 void insert(int index, E node) {
8640 int length = _elements.length;
8641 if (index < 0 || index > length) {
8642 throw new RangeError("Index: $index, Size: ${_elements.length}");
8643 }
8644 owner._becomeParentOf(node);
8645 if (length == 0) {
8646 _elements.add(node);
8647 } else {
8648 _elements.insert(index, node);
8649 }
8650 }
8651
8652 @override
8653 E removeAt(int index) {
8654 if (index < 0 || index >= _elements.length) {
8655 throw new RangeError("Index: $index, Size: ${_elements.length}");
8656 }
8657 E removedNode = _elements[index];
8658 _elements.removeAt(index);
8659 return removedNode;
8660 }
8661 }
8662
8663 /**
8664 * A formal parameter that is required (is not optional).
8665 *
8666 * > normalFormalParameter ::=
8667 * > [FunctionTypedFormalParameter]
8668 * > | [FieldFormalParameter]
8669 * > | [SimpleFormalParameter]
8670 */
8671 abstract class NormalFormalParameter extends FormalParameter {
8672 /**
8673 * The documentation comment associated with this parameter, or `null` if this
8674 * parameter does not have a documentation comment associated with it.
8675 */
8676 Comment _comment;
8677
8678 /**
8679 * The annotations associated with this parameter.
8680 */
8681 NodeList<Annotation> _metadata;
8682
8683 /**
8684 * The name of the parameter being declared.
8685 */
8686 SimpleIdentifier _identifier;
8687
8688 /**
8689 * Initialize a newly created formal parameter. Either or both of the
8690 * [comment] and [metadata] can be `null` if the parameter does not have the
8691 * corresponding attribute.
8692 */
8693 NormalFormalParameter(
8694 Comment comment, List<Annotation> metadata, SimpleIdentifier identifier) {
8695 _comment = _becomeParentOf(comment);
8696 _metadata = new NodeList<Annotation>(this, metadata);
8697 _identifier = _becomeParentOf(identifier);
8698 }
8699
8700 /**
8701 * Return the documentation comment associated with this parameter, or `null`
8702 * if this parameter does not have a documentation comment associated with it.
8703 */
8704 Comment get documentationComment => _comment;
8705
8706 /**
8707 * Set the documentation comment associated with this parameter to the given
8708 * [comment].
8709 */
8710 void set documentationComment(Comment comment) {
8711 _comment = _becomeParentOf(comment);
8712 }
8713
8714 @override
8715 SimpleIdentifier get identifier => _identifier;
8716
8717 /**
8718 * Set the name of the parameter being declared to the given [identifier].
8719 */
8720 void set identifier(SimpleIdentifier identifier) {
8721 _identifier = _becomeParentOf(identifier);
8722 }
8723
8724 @override
8725 ParameterKind get kind {
8726 AstNode parent = this.parent;
8727 if (parent is DefaultFormalParameter) {
8728 return parent.kind;
8729 }
8730 return ParameterKind.REQUIRED;
8731 }
8732
8733 @override
8734 NodeList<Annotation> get metadata => _metadata;
8735
8736 /**
8737 * Set the metadata associated with this node to the given [metadata].
8738 */
8739 void set metadata(List<Annotation> metadata) {
8740 _metadata.clear();
8741 _metadata.addAll(metadata);
8742 }
8743
8744 /**
8745 * Return a list containing the comment and annotations associated with this
8746 * parameter, sorted in lexical order.
8747 */
8748 List<AstNode> get sortedCommentAndAnnotations {
8749 return <AstNode>[]
8750 ..add(_comment)
8751 ..addAll(_metadata)
8752 ..sort(AstNode.LEXICAL_ORDER);
8753 }
8754
8755 ChildEntities get _childEntities {
8756 ChildEntities result = new ChildEntities();
8757 if (_commentIsBeforeAnnotations()) {
8758 result
8759 ..add(_comment)
8760 ..addAll(_metadata);
8761 } else {
8762 result.addAll(sortedCommentAndAnnotations);
8763 }
8764 return result;
8765 }
8766
8767 @override
8768 void visitChildren(AstVisitor visitor) {
8769 //
8770 // Note that subclasses are responsible for visiting the identifier because
8771 // they often need to visit other nodes before visiting the identifier.
8772 //
8773 if (_commentIsBeforeAnnotations()) {
8774 _safelyVisitChild(_comment, visitor);
8775 _metadata.accept(visitor);
8776 } else {
8777 for (AstNode child in sortedCommentAndAnnotations) {
8778 child.accept(visitor);
8779 }
8780 }
8781 }
8782
8783 /**
8784 * Return `true` if the comment is lexically before any annotations.
8785 */
8786 bool _commentIsBeforeAnnotations() {
8787 if (_comment == null || _metadata.isEmpty) {
8788 return true;
8789 }
8790 Annotation firstAnnotation = _metadata[0];
8791 return _comment.offset < firstAnnotation.offset;
8792 }
8793 }
8794
8795 /**
8796 * A null literal expression.
8797 *
8798 * > nullLiteral ::=
8799 * > 'null'
8800 */
8801 class NullLiteral extends Literal {
8802 /**
8803 * The token representing the literal.
8804 */
8805 Token literal;
8806
8807 /**
8808 * Initialize a newly created null literal.
8809 */
8810 NullLiteral(this.literal);
8811
8812 @override
8813 Token get beginToken => literal;
8814
8815 @override
8816 Iterable get childEntities => new ChildEntities()..add(literal);
8817
8818 @override
8819 Token get endToken => literal;
8820
8821 @override
8822 accept(AstVisitor visitor) => visitor.visitNullLiteral(this);
8823
8824 @override
8825 void visitChildren(AstVisitor visitor) {
8826 // There are no children to visit.
8827 }
8828 }
8829
8830 /**
8831 * A parenthesized expression.
8832 *
8833 * > parenthesizedExpression ::=
8834 * > '(' [Expression] ')'
8835 */
8836 class ParenthesizedExpression extends Expression {
8837 /**
8838 * The left parenthesis.
8839 */
8840 Token leftParenthesis;
8841
8842 /**
8843 * The expression within the parentheses.
8844 */
8845 Expression _expression;
8846
8847 /**
8848 * The right parenthesis.
8849 */
8850 Token rightParenthesis;
8851
8852 /**
8853 * Initialize a newly created parenthesized expression.
8854 */
8855 ParenthesizedExpression(
8856 this.leftParenthesis, Expression expression, this.rightParenthesis) {
8857 _expression = _becomeParentOf(expression);
8858 }
8859
8860 @override
8861 Token get beginToken => leftParenthesis;
8862
8863 @override
8864 Iterable get childEntities => new ChildEntities()
8865 ..add(leftParenthesis)
8866 ..add(_expression)
8867 ..add(rightParenthesis);
8868
8869 @override
8870 Token get endToken => rightParenthesis;
8871
8872 /**
8873 * Return the expression within the parentheses.
8874 */
8875 Expression get expression => _expression;
8876
8877 /**
8878 * Set the expression within the parentheses to the given [expression].
8879 */
8880 void set expression(Expression expression) {
8881 _expression = _becomeParentOf(expression);
8882 }
8883
8884 @override
8885 int get precedence => 15;
8886
8887 @override
8888 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this);
8889
8890 @override
8891 void visitChildren(AstVisitor visitor) {
8892 _safelyVisitChild(_expression, visitor);
8893 }
8894 }
8895
8896 /**
8897 * A part directive.
8898 *
8899 * > partDirective ::=
8900 * > [Annotation] 'part' [StringLiteral] ';'
8901 */
8902 class PartDirective extends UriBasedDirective {
8903 /**
8904 * The token representing the 'part' keyword.
8905 */
8906 Token partKeyword;
8907
8908 /**
8909 * The semicolon terminating the directive.
8910 */
8911 Token semicolon;
8912
8913 /**
8914 * Initialize a newly created part directive. Either or both of the [comment]
8915 * and [metadata] can be `null` if the directive does not have the
8916 * corresponding attribute.
8917 */
8918 PartDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
8919 StringLiteral partUri, this.semicolon)
8920 : super(comment, metadata, partUri);
8921
8922 @override
8923 Iterable get childEntities =>
8924 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon);
8925
8926 @override
8927 Token get endToken => semicolon;
8928
8929 @override
8930 Token get firstTokenAfterCommentAndMetadata => partKeyword;
8931
8932 @override
8933 Token get keyword => partKeyword;
8934
8935 @override
8936 CompilationUnitElement get uriElement => element as CompilationUnitElement;
8937
8938 @override
8939 accept(AstVisitor visitor) => visitor.visitPartDirective(this);
8940 }
8941
8942 /**
8943 * A part-of directive.
8944 *
8945 * > partOfDirective ::=
8946 * > [Annotation] 'part' 'of' [Identifier] ';'
8947 */
8948 class PartOfDirective extends Directive {
8949 /**
8950 * The token representing the 'part' keyword.
8951 */
8952 Token partKeyword;
8953
8954 /**
8955 * The token representing the 'of' keyword.
8956 */
8957 Token ofKeyword;
8958
8959 /**
8960 * The name of the library that the containing compilation unit is part of.
8961 */
8962 LibraryIdentifier _libraryName;
8963
8964 /**
8965 * The semicolon terminating the directive.
8966 */
8967 Token semicolon;
8968
8969 /**
8970 * Initialize a newly created part-of directive. Either or both of the
8971 * [comment] and [metadata] can be `null` if the directive does not have the
8972 * corresponding attribute.
8973 */
8974 PartOfDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
8975 this.ofKeyword, LibraryIdentifier libraryName, this.semicolon)
8976 : super(comment, metadata) {
8977 _libraryName = _becomeParentOf(libraryName);
8978 }
8979
8980 @override
8981 Iterable get childEntities => super._childEntities
8982 ..add(partKeyword)
8983 ..add(ofKeyword)
8984 ..add(_libraryName)
8985 ..add(semicolon);
8986
8987 @override
8988 Token get endToken => semicolon;
8989
8990 @override
8991 Token get firstTokenAfterCommentAndMetadata => partKeyword;
8992
8993 @override
8994 Token get keyword => partKeyword;
8995
8996 /**
8997 * Return the name of the library that the containing compilation unit is part
8998 * of.
8999 */
9000 LibraryIdentifier get libraryName => _libraryName;
9001
9002 /**
9003 * Set the name of the library that the containing compilation unit is part of
9004 * to the given [libraryName].
9005 */
9006 void set libraryName(LibraryIdentifier libraryName) {
9007 _libraryName = _becomeParentOf(libraryName);
9008 }
9009
9010 @override
9011 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this);
9012
9013 @override
9014 void visitChildren(AstVisitor visitor) {
9015 super.visitChildren(visitor);
9016 _safelyVisitChild(_libraryName, visitor);
9017 }
9018 }
9019
9020 /**
9021 * A postfix unary expression.
9022 *
9023 * > postfixExpression ::=
9024 * > [Expression] [Token]
9025 */
9026 class PostfixExpression extends Expression {
9027 /**
9028 * The expression computing the operand for the operator.
9029 */
9030 Expression _operand;
9031
9032 /**
9033 * The postfix operator being applied to the operand.
9034 */
9035 Token operator;
9036
9037 /**
9038 * The element associated with this the operator based on the propagated type
9039 * of the operand, or `null` if the AST structure has not been resolved, if
9040 * the operator is not user definable, or if the operator could not be
9041 * resolved.
9042 */
9043 MethodElement propagatedElement;
9044
9045 /**
9046 * The element associated with the operator based on the static type of the
9047 * operand, or `null` if the AST structure has not been resolved, if the
9048 * operator is not user definable, or if the operator could not be resolved.
9049 */
9050 MethodElement staticElement;
9051
9052 /**
9053 * Initialize a newly created postfix expression.
9054 */
9055 PostfixExpression(Expression operand, this.operator) {
9056 _operand = _becomeParentOf(operand);
9057 }
9058
9059 @override
9060 Token get beginToken => _operand.beginToken;
9061
9062 /**
9063 * Return the best element available for this operator. If resolution was able
9064 * to find a better element based on type propagation, that element will be
9065 * returned. Otherwise, the element found using the result of static analysis
9066 * will be returned. If resolution has not been performed, then `null` will be
9067 * returned.
9068 */
9069 MethodElement get bestElement {
9070 MethodElement element = propagatedElement;
9071 if (element == null) {
9072 element = staticElement;
9073 }
9074 return element;
9075 }
9076
9077 @override
9078 Iterable get childEntities =>
9079 new ChildEntities()..add(_operand)..add(operator);
9080
9081 @override
9082 Token get endToken => operator;
9083
9084 /**
9085 * Return the expression computing the operand for the operator.
9086 */
9087 Expression get operand => _operand;
9088
9089 /**
9090 * Set the expression computing the operand for the operator to the given
9091 * [expression].
9092 */
9093 void set operand(Expression expression) {
9094 _operand = _becomeParentOf(expression);
9095 }
9096
9097 @override
9098 int get precedence => 15;
9099
9100 /**
9101 * If the AST structure has been resolved, and the function being invoked is
9102 * known based on propagated type information, then return the parameter
9103 * element representing the parameter to which the value of the operand will
9104 * be bound. Otherwise, return `null`.
9105 */
9106 ParameterElement get _propagatedParameterElementForOperand {
9107 if (propagatedElement == null) {
9108 return null;
9109 }
9110 List<ParameterElement> parameters = propagatedElement.parameters;
9111 if (parameters.length < 1) {
9112 return null;
9113 }
9114 return parameters[0];
9115 }
9116
9117 /**
9118 * If the AST structure has been resolved, and the function being invoked is
9119 * known based on static type information, then return the parameter element
9120 * representing the parameter to which the value of the operand will be bound.
9121 * Otherwise, return `null`.
9122 */
9123 ParameterElement get _staticParameterElementForOperand {
9124 if (staticElement == null) {
9125 return null;
9126 }
9127 List<ParameterElement> parameters = staticElement.parameters;
9128 if (parameters.length < 1) {
9129 return null;
9130 }
9131 return parameters[0];
9132 }
9133
9134 @override
9135 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this);
9136
9137 @override
9138 void visitChildren(AstVisitor visitor) {
9139 _safelyVisitChild(_operand, visitor);
9140 }
9141 }
9142
9143 /**
9144 * An identifier that is prefixed or an access to an object property where the
9145 * target of the property access is a simple identifier.
9146 *
9147 * > prefixedIdentifier ::=
9148 * > [SimpleIdentifier] '.' [SimpleIdentifier]
9149 */
9150 class PrefixedIdentifier extends Identifier {
9151 /**
9152 * The prefix associated with the library in which the identifier is defined.
9153 */
9154 SimpleIdentifier _prefix;
9155
9156 /**
9157 * The period used to separate the prefix from the identifier.
9158 */
9159 Token period;
9160
9161 /**
9162 * The identifier being prefixed.
9163 */
9164 SimpleIdentifier _identifier;
9165
9166 /**
9167 * Initialize a newly created prefixed identifier.
9168 */
9169 PrefixedIdentifier(
9170 SimpleIdentifier prefix, this.period, SimpleIdentifier identifier) {
9171 _prefix = _becomeParentOf(prefix);
9172 _identifier = _becomeParentOf(identifier);
9173 }
9174
9175 @override
9176 Token get beginToken => _prefix.beginToken;
9177
9178 @override
9179 Element get bestElement {
9180 if (_identifier == null) {
9181 return null;
9182 }
9183 return _identifier.bestElement;
9184 }
9185
9186 @override
9187 Iterable get childEntities =>
9188 new ChildEntities()..add(_prefix)..add(period)..add(_identifier);
9189
9190 @override
9191 Token get endToken => _identifier.endToken;
9192
9193 /**
9194 * Return the identifier being prefixed.
9195 */
9196 SimpleIdentifier get identifier => _identifier;
9197
9198 /**
9199 * Set the identifier being prefixed to the given [identifier].
9200 */
9201 void set identifier(SimpleIdentifier identifier) {
9202 _identifier = _becomeParentOf(identifier);
9203 }
9204
9205 /**
9206 * Return `true` if this type is a deferred type. If the AST structure has not
9207 * been resolved, then return `false`.
9208 *
9209 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form
9210 * </i>p.T</i> where <i>p</i> is a deferred prefix.
9211 */
9212 bool get isDeferred {
9213 Element element = _prefix.staticElement;
9214 if (element is! PrefixElement) {
9215 return false;
9216 }
9217 PrefixElement prefixElement = element as PrefixElement;
9218 List<ImportElement> imports =
9219 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement);
9220 if (imports.length != 1) {
9221 return false;
9222 }
9223 return imports[0].isDeferred;
9224 }
9225
9226 @override
9227 String get name => "${_prefix.name}.${_identifier.name}";
9228
9229 @override
9230 int get precedence => 15;
9231
9232 /**
9233 * Return the prefix associated with the library in which the identifier is
9234 * defined.
9235 */
9236 SimpleIdentifier get prefix => _prefix;
9237
9238 /**
9239 * Set the prefix associated with the library in which the identifier is
9240 * defined to the given [identifier].
9241 */
9242 void set prefix(SimpleIdentifier identifier) {
9243 _prefix = _becomeParentOf(identifier);
9244 }
9245
9246 @override
9247 Element get propagatedElement {
9248 if (_identifier == null) {
9249 return null;
9250 }
9251 return _identifier.propagatedElement;
9252 }
9253
9254 @override
9255 Element get staticElement {
9256 if (_identifier == null) {
9257 return null;
9258 }
9259 return _identifier.staticElement;
9260 }
9261
9262 @override
9263 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this);
9264
9265 @override
9266 void visitChildren(AstVisitor visitor) {
9267 _safelyVisitChild(_prefix, visitor);
9268 _safelyVisitChild(_identifier, visitor);
9269 }
9270 }
9271
9272 /**
9273 * A prefix unary expression.
9274 *
9275 * > prefixExpression ::=
9276 * > [Token] [Expression]
9277 */
9278 class PrefixExpression extends Expression {
9279 /**
9280 * The prefix operator being applied to the operand.
9281 */
9282 Token operator;
9283
9284 /**
9285 * The expression computing the operand for the operator.
9286 */
9287 Expression _operand;
9288
9289 /**
9290 * The element associated with the operator based on the static type of the
9291 * operand, or `null` if the AST structure has not been resolved, if the
9292 * operator is not user definable, or if the operator could not be resolved.
9293 */
9294 MethodElement staticElement;
9295
9296 /**
9297 * The element associated with the operator based on the propagated type of
9298 * the operand, or `null` if the AST structure has not been resolved, if the
9299 * operator is not user definable, or if the operator could not be resolved.
9300 */
9301 MethodElement propagatedElement;
9302
9303 /**
9304 * Initialize a newly created prefix expression.
9305 */
9306 PrefixExpression(this.operator, Expression operand) {
9307 _operand = _becomeParentOf(operand);
9308 }
9309
9310 @override
9311 Token get beginToken => operator;
9312
9313 /**
9314 * Return the best element available for this operator. If resolution was able
9315 * to find a better element based on type propagation, that element will be
9316 * returned. Otherwise, the element found using the result of static analysis
9317 * will be returned. If resolution has not been performed, then `null` will be
9318 * returned.
9319 */
9320 MethodElement get bestElement {
9321 MethodElement element = propagatedElement;
9322 if (element == null) {
9323 element = staticElement;
9324 }
9325 return element;
9326 }
9327
9328 @override
9329 Iterable get childEntities =>
9330 new ChildEntities()..add(operator)..add(_operand);
9331
9332 @override
9333 Token get endToken => _operand.endToken;
9334
9335 /**
9336 * Return the expression computing the operand for the operator.
9337 */
9338 Expression get operand => _operand;
9339
9340 /**
9341 * Set the expression computing the operand for the operator to the given
9342 * [expression].
9343 */
9344 void set operand(Expression expression) {
9345 _operand = _becomeParentOf(expression);
9346 }
9347
9348 @override
9349 int get precedence => 14;
9350
9351 /**
9352 * If the AST structure has been resolved, and the function being invoked is
9353 * known based on propagated type information, then return the parameter
9354 * element representing the parameter to which the value of the operand will
9355 * be bound. Otherwise, return `null`.
9356 */
9357 ParameterElement get _propagatedParameterElementForOperand {
9358 if (propagatedElement == null) {
9359 return null;
9360 }
9361 List<ParameterElement> parameters = propagatedElement.parameters;
9362 if (parameters.length < 1) {
9363 return null;
9364 }
9365 return parameters[0];
9366 }
9367
9368 /**
9369 * If the AST structure has been resolved, and the function being invoked is
9370 * known based on static type information, then return the parameter element
9371 * representing the parameter to which the value of the operand will be bound.
9372 * Otherwise, return `null`.
9373 */
9374 ParameterElement get _staticParameterElementForOperand {
9375 if (staticElement == null) {
9376 return null;
9377 }
9378 List<ParameterElement> parameters = staticElement.parameters;
9379 if (parameters.length < 1) {
9380 return null;
9381 }
9382 return parameters[0];
9383 }
9384
9385 @override
9386 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this);
9387
9388 @override
9389 void visitChildren(AstVisitor visitor) {
9390 _safelyVisitChild(_operand, visitor);
9391 }
9392 }
9393
9394 /**
9395 * The access of a property of an object.
9396 *
9397 * Note, however, that accesses to properties of objects can also be represented
9398 * as [PrefixedIdentifier] nodes in cases where the target is also a simple
9399 * identifier.
9400 *
9401 * > propertyAccess ::=
9402 * > [Expression] '.' [SimpleIdentifier]
9403 */
9404 class PropertyAccess extends Expression {
9405 /**
9406 * The expression computing the object defining the property being accessed.
9407 */
9408 Expression _target;
9409
9410 /**
9411 * The property access operator.
9412 */
9413 Token operator;
9414
9415 /**
9416 * The name of the property being accessed.
9417 */
9418 SimpleIdentifier _propertyName;
9419
9420 /**
9421 * Initialize a newly created property access expression.
9422 */
9423 PropertyAccess(
9424 Expression target, this.operator, SimpleIdentifier propertyName) {
9425 _target = _becomeParentOf(target);
9426 _propertyName = _becomeParentOf(propertyName);
9427 }
9428
9429 @override
9430 Token get beginToken {
9431 if (_target != null) {
9432 return _target.beginToken;
9433 }
9434 return operator;
9435 }
9436
9437 @override
9438 Iterable get childEntities =>
9439 new ChildEntities()..add(_target)..add(operator)..add(_propertyName);
9440
9441 @override
9442 Token get endToken => _propertyName.endToken;
9443
9444 @override
9445 bool get isAssignable => true;
9446
9447 /**
9448 * Return `true` if this expression is cascaded. If it is, then the target of
9449 * this expression is not stored locally but is stored in the nearest ancestor
9450 * that is a [CascadeExpression].
9451 */
9452 bool get isCascaded =>
9453 operator != null && operator.type == TokenType.PERIOD_PERIOD;
9454
9455 @override
9456 int get precedence => 15;
9457
9458 /**
9459 * Return the name of the property being accessed.
9460 */
9461 SimpleIdentifier get propertyName => _propertyName;
9462
9463 /**
9464 * Set the name of the property being accessed to the given [identifier].
9465 */
9466 void set propertyName(SimpleIdentifier identifier) {
9467 _propertyName = _becomeParentOf(identifier);
9468 }
9469
9470 /**
9471 * Return the expression used to compute the receiver of the invocation. If
9472 * this invocation is not part of a cascade expression, then this is the same
9473 * as [target]. If this invocation is part of a cascade expression, then the
9474 * target stored with the cascade expression is returned.
9475 */
9476 Expression get realTarget {
9477 if (isCascaded) {
9478 AstNode ancestor = parent;
9479 while (ancestor is! CascadeExpression) {
9480 if (ancestor == null) {
9481 return _target;
9482 }
9483 ancestor = ancestor.parent;
9484 }
9485 return (ancestor as CascadeExpression).target;
9486 }
9487 return _target;
9488 }
9489
9490 /**
14910 * Return the expression computing the object defining the property being 9491 * Return the expression computing the object defining the property being
14911 * accessed, or `null` if this property access is part of a cascade expression . 9492 * accessed, or `null` if this property access is part of a cascade expression .
14912 * 9493 *
14913 * Use [realTarget] to get the target independent of whether this is part of a 9494 * Use [realTarget] to get the target independent of whether this is part of a
14914 * cascade expression. 9495 * cascade expression.
14915 */ 9496 */
14916 Expression get target => _target; 9497 Expression get target => _target;
14917 9498
14918 /** 9499 /**
14919 * Set the expression computing the object defining the property being 9500 * Set the expression computing the object defining the property being
14920 * accessed to the given [expression]. 9501 * accessed to the given [expression].
14921 */ 9502 */
14922 void set target(Expression expression) { 9503 void set target(Expression expression) {
14923 _target = _becomeParentOf(expression); 9504 _target = _becomeParentOf(expression);
14924 } 9505 }
14925 9506
14926 @override 9507 @override
14927 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this); 9508 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this);
14928 9509
14929 @override 9510 @override
14930 void visitChildren(AstVisitor visitor) { 9511 void visitChildren(AstVisitor visitor) {
14931 _safelyVisitChild(_target, visitor); 9512 _safelyVisitChild(_target, visitor);
14932 _safelyVisitChild(_propertyName, visitor); 9513 _safelyVisitChild(_propertyName, visitor);
14933 } 9514 }
14934 } 9515 }
14935 9516
14936 /** 9517 /**
14937 * An AST visitor that will recursively visit all of the nodes in an AST
14938 * structure. For example, using an instance of this class to visit a [Block]
14939 * will also cause all of the statements in the block to be visited.
14940 *
14941 * Subclasses that override a visit method must either invoke the overridden
14942 * visit method or must explicitly ask the visited node to visit its children.
14943 * Failure to do so will cause the children of the visited node to not be
14944 * visited.
14945 */
14946 class RecursiveAstVisitor<R> implements AstVisitor<R> {
14947 @override
14948 R visitAdjacentStrings(AdjacentStrings node) {
14949 node.visitChildren(this);
14950 return null;
14951 }
14952
14953 @override
14954 R visitAnnotation(Annotation node) {
14955 node.visitChildren(this);
14956 return null;
14957 }
14958
14959 @override
14960 R visitArgumentList(ArgumentList node) {
14961 node.visitChildren(this);
14962 return null;
14963 }
14964
14965 @override
14966 R visitAsExpression(AsExpression node) {
14967 node.visitChildren(this);
14968 return null;
14969 }
14970
14971 @override
14972 R visitAssertStatement(AssertStatement node) {
14973 node.visitChildren(this);
14974 return null;
14975 }
14976
14977 @override
14978 R visitAssignmentExpression(AssignmentExpression node) {
14979 node.visitChildren(this);
14980 return null;
14981 }
14982
14983 @override
14984 R visitAwaitExpression(AwaitExpression node) {
14985 node.visitChildren(this);
14986 return null;
14987 }
14988
14989 @override
14990 R visitBinaryExpression(BinaryExpression node) {
14991 node.visitChildren(this);
14992 return null;
14993 }
14994
14995 @override
14996 R visitBlock(Block node) {
14997 node.visitChildren(this);
14998 return null;
14999 }
15000
15001 @override
15002 R visitBlockFunctionBody(BlockFunctionBody node) {
15003 node.visitChildren(this);
15004 return null;
15005 }
15006
15007 @override
15008 R visitBooleanLiteral(BooleanLiteral node) {
15009 node.visitChildren(this);
15010 return null;
15011 }
15012
15013 @override
15014 R visitBreakStatement(BreakStatement node) {
15015 node.visitChildren(this);
15016 return null;
15017 }
15018
15019 @override
15020 R visitCascadeExpression(CascadeExpression node) {
15021 node.visitChildren(this);
15022 return null;
15023 }
15024
15025 @override
15026 R visitCatchClause(CatchClause node) {
15027 node.visitChildren(this);
15028 return null;
15029 }
15030
15031 @override
15032 R visitClassDeclaration(ClassDeclaration node) {
15033 node.visitChildren(this);
15034 return null;
15035 }
15036
15037 @override
15038 R visitClassTypeAlias(ClassTypeAlias node) {
15039 node.visitChildren(this);
15040 return null;
15041 }
15042
15043 @override
15044 R visitComment(Comment node) {
15045 node.visitChildren(this);
15046 return null;
15047 }
15048
15049 @override
15050 R visitCommentReference(CommentReference node) {
15051 node.visitChildren(this);
15052 return null;
15053 }
15054
15055 @override
15056 R visitCompilationUnit(CompilationUnit node) {
15057 node.visitChildren(this);
15058 return null;
15059 }
15060
15061 @override
15062 R visitConditionalExpression(ConditionalExpression node) {
15063 node.visitChildren(this);
15064 return null;
15065 }
15066
15067 @override
15068 R visitConfiguration(Configuration node) {
15069 node.visitChildren(this);
15070 return null;
15071 }
15072
15073 @override
15074 R visitConstructorDeclaration(ConstructorDeclaration node) {
15075 node.visitChildren(this);
15076 return null;
15077 }
15078
15079 @override
15080 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
15081 node.visitChildren(this);
15082 return null;
15083 }
15084
15085 @override
15086 R visitConstructorName(ConstructorName node) {
15087 node.visitChildren(this);
15088 return null;
15089 }
15090
15091 @override
15092 R visitContinueStatement(ContinueStatement node) {
15093 node.visitChildren(this);
15094 return null;
15095 }
15096
15097 @override
15098 R visitDeclaredIdentifier(DeclaredIdentifier node) {
15099 node.visitChildren(this);
15100 return null;
15101 }
15102
15103 @override
15104 R visitDefaultFormalParameter(DefaultFormalParameter node) {
15105 node.visitChildren(this);
15106 return null;
15107 }
15108
15109 @override
15110 R visitDoStatement(DoStatement node) {
15111 node.visitChildren(this);
15112 return null;
15113 }
15114
15115 @override
15116 R visitDottedName(DottedName node) {
15117 node.visitChildren(this);
15118 return null;
15119 }
15120
15121 @override
15122 R visitDoubleLiteral(DoubleLiteral node) {
15123 node.visitChildren(this);
15124 return null;
15125 }
15126
15127 @override
15128 R visitEmptyFunctionBody(EmptyFunctionBody node) {
15129 node.visitChildren(this);
15130 return null;
15131 }
15132
15133 @override
15134 R visitEmptyStatement(EmptyStatement node) {
15135 node.visitChildren(this);
15136 return null;
15137 }
15138
15139 @override
15140 R visitEnumConstantDeclaration(EnumConstantDeclaration node) {
15141 node.visitChildren(this);
15142 return null;
15143 }
15144
15145 @override
15146 R visitEnumDeclaration(EnumDeclaration node) {
15147 node.visitChildren(this);
15148 return null;
15149 }
15150
15151 @override
15152 R visitExportDirective(ExportDirective node) {
15153 node.visitChildren(this);
15154 return null;
15155 }
15156
15157 @override
15158 R visitExpressionFunctionBody(ExpressionFunctionBody node) {
15159 node.visitChildren(this);
15160 return null;
15161 }
15162
15163 @override
15164 R visitExpressionStatement(ExpressionStatement node) {
15165 node.visitChildren(this);
15166 return null;
15167 }
15168
15169 @override
15170 R visitExtendsClause(ExtendsClause node) {
15171 node.visitChildren(this);
15172 return null;
15173 }
15174
15175 @override
15176 R visitFieldDeclaration(FieldDeclaration node) {
15177 node.visitChildren(this);
15178 return null;
15179 }
15180
15181 @override
15182 R visitFieldFormalParameter(FieldFormalParameter node) {
15183 node.visitChildren(this);
15184 return null;
15185 }
15186
15187 @override
15188 R visitForEachStatement(ForEachStatement node) {
15189 node.visitChildren(this);
15190 return null;
15191 }
15192
15193 @override
15194 R visitFormalParameterList(FormalParameterList node) {
15195 node.visitChildren(this);
15196 return null;
15197 }
15198
15199 @override
15200 R visitForStatement(ForStatement node) {
15201 node.visitChildren(this);
15202 return null;
15203 }
15204
15205 @override
15206 R visitFunctionDeclaration(FunctionDeclaration node) {
15207 node.visitChildren(this);
15208 return null;
15209 }
15210
15211 @override
15212 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
15213 node.visitChildren(this);
15214 return null;
15215 }
15216
15217 @override
15218 R visitFunctionExpression(FunctionExpression node) {
15219 node.visitChildren(this);
15220 return null;
15221 }
15222
15223 @override
15224 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
15225 node.visitChildren(this);
15226 return null;
15227 }
15228
15229 @override
15230 R visitFunctionTypeAlias(FunctionTypeAlias node) {
15231 node.visitChildren(this);
15232 return null;
15233 }
15234
15235 @override
15236 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
15237 node.visitChildren(this);
15238 return null;
15239 }
15240
15241 @override
15242 R visitHideCombinator(HideCombinator node) {
15243 node.visitChildren(this);
15244 return null;
15245 }
15246
15247 @override
15248 R visitIfStatement(IfStatement node) {
15249 node.visitChildren(this);
15250 return null;
15251 }
15252
15253 @override
15254 R visitImplementsClause(ImplementsClause node) {
15255 node.visitChildren(this);
15256 return null;
15257 }
15258
15259 @override
15260 R visitImportDirective(ImportDirective node) {
15261 node.visitChildren(this);
15262 return null;
15263 }
15264
15265 @override
15266 R visitIndexExpression(IndexExpression node) {
15267 node.visitChildren(this);
15268 return null;
15269 }
15270
15271 @override
15272 R visitInstanceCreationExpression(InstanceCreationExpression node) {
15273 node.visitChildren(this);
15274 return null;
15275 }
15276
15277 @override
15278 R visitIntegerLiteral(IntegerLiteral node) {
15279 node.visitChildren(this);
15280 return null;
15281 }
15282
15283 @override
15284 R visitInterpolationExpression(InterpolationExpression node) {
15285 node.visitChildren(this);
15286 return null;
15287 }
15288
15289 @override
15290 R visitInterpolationString(InterpolationString node) {
15291 node.visitChildren(this);
15292 return null;
15293 }
15294
15295 @override
15296 R visitIsExpression(IsExpression node) {
15297 node.visitChildren(this);
15298 return null;
15299 }
15300
15301 @override
15302 R visitLabel(Label node) {
15303 node.visitChildren(this);
15304 return null;
15305 }
15306
15307 @override
15308 R visitLabeledStatement(LabeledStatement node) {
15309 node.visitChildren(this);
15310 return null;
15311 }
15312
15313 @override
15314 R visitLibraryDirective(LibraryDirective node) {
15315 node.visitChildren(this);
15316 return null;
15317 }
15318
15319 @override
15320 R visitLibraryIdentifier(LibraryIdentifier node) {
15321 node.visitChildren(this);
15322 return null;
15323 }
15324
15325 @override
15326 R visitListLiteral(ListLiteral node) {
15327 node.visitChildren(this);
15328 return null;
15329 }
15330
15331 @override
15332 R visitMapLiteral(MapLiteral node) {
15333 node.visitChildren(this);
15334 return null;
15335 }
15336
15337 @override
15338 R visitMapLiteralEntry(MapLiteralEntry node) {
15339 node.visitChildren(this);
15340 return null;
15341 }
15342
15343 @override
15344 R visitMethodDeclaration(MethodDeclaration node) {
15345 node.visitChildren(this);
15346 return null;
15347 }
15348
15349 @override
15350 R visitMethodInvocation(MethodInvocation node) {
15351 node.visitChildren(this);
15352 return null;
15353 }
15354
15355 @override
15356 R visitNamedExpression(NamedExpression node) {
15357 node.visitChildren(this);
15358 return null;
15359 }
15360
15361 @override
15362 R visitNativeClause(NativeClause node) {
15363 node.visitChildren(this);
15364 return null;
15365 }
15366
15367 @override
15368 R visitNativeFunctionBody(NativeFunctionBody node) {
15369 node.visitChildren(this);
15370 return null;
15371 }
15372
15373 @override
15374 R visitNullLiteral(NullLiteral node) {
15375 node.visitChildren(this);
15376 return null;
15377 }
15378
15379 @override
15380 R visitParenthesizedExpression(ParenthesizedExpression node) {
15381 node.visitChildren(this);
15382 return null;
15383 }
15384
15385 @override
15386 R visitPartDirective(PartDirective node) {
15387 node.visitChildren(this);
15388 return null;
15389 }
15390
15391 @override
15392 R visitPartOfDirective(PartOfDirective node) {
15393 node.visitChildren(this);
15394 return null;
15395 }
15396
15397 @override
15398 R visitPostfixExpression(PostfixExpression node) {
15399 node.visitChildren(this);
15400 return null;
15401 }
15402
15403 @override
15404 R visitPrefixedIdentifier(PrefixedIdentifier node) {
15405 node.visitChildren(this);
15406 return null;
15407 }
15408
15409 @override
15410 R visitPrefixExpression(PrefixExpression node) {
15411 node.visitChildren(this);
15412 return null;
15413 }
15414
15415 @override
15416 R visitPropertyAccess(PropertyAccess node) {
15417 node.visitChildren(this);
15418 return null;
15419 }
15420
15421 @override
15422 R visitRedirectingConstructorInvocation(
15423 RedirectingConstructorInvocation node) {
15424 node.visitChildren(this);
15425 return null;
15426 }
15427
15428 @override
15429 R visitRethrowExpression(RethrowExpression node) {
15430 node.visitChildren(this);
15431 return null;
15432 }
15433
15434 @override
15435 R visitReturnStatement(ReturnStatement node) {
15436 node.visitChildren(this);
15437 return null;
15438 }
15439
15440 @override
15441 R visitScriptTag(ScriptTag node) {
15442 node.visitChildren(this);
15443 return null;
15444 }
15445
15446 @override
15447 R visitShowCombinator(ShowCombinator node) {
15448 node.visitChildren(this);
15449 return null;
15450 }
15451
15452 @override
15453 R visitSimpleFormalParameter(SimpleFormalParameter node) {
15454 node.visitChildren(this);
15455 return null;
15456 }
15457
15458 @override
15459 R visitSimpleIdentifier(SimpleIdentifier node) {
15460 node.visitChildren(this);
15461 return null;
15462 }
15463
15464 @override
15465 R visitSimpleStringLiteral(SimpleStringLiteral node) {
15466 node.visitChildren(this);
15467 return null;
15468 }
15469
15470 @override
15471 R visitStringInterpolation(StringInterpolation node) {
15472 node.visitChildren(this);
15473 return null;
15474 }
15475
15476 @override
15477 R visitSuperConstructorInvocation(SuperConstructorInvocation node) {
15478 node.visitChildren(this);
15479 return null;
15480 }
15481
15482 @override
15483 R visitSuperExpression(SuperExpression node) {
15484 node.visitChildren(this);
15485 return null;
15486 }
15487
15488 @override
15489 R visitSwitchCase(SwitchCase node) {
15490 node.visitChildren(this);
15491 return null;
15492 }
15493
15494 @override
15495 R visitSwitchDefault(SwitchDefault node) {
15496 node.visitChildren(this);
15497 return null;
15498 }
15499
15500 @override
15501 R visitSwitchStatement(SwitchStatement node) {
15502 node.visitChildren(this);
15503 return null;
15504 }
15505
15506 @override
15507 R visitSymbolLiteral(SymbolLiteral node) {
15508 node.visitChildren(this);
15509 return null;
15510 }
15511
15512 @override
15513 R visitThisExpression(ThisExpression node) {
15514 node.visitChildren(this);
15515 return null;
15516 }
15517
15518 @override
15519 R visitThrowExpression(ThrowExpression node) {
15520 node.visitChildren(this);
15521 return null;
15522 }
15523
15524 @override
15525 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
15526 node.visitChildren(this);
15527 return null;
15528 }
15529
15530 @override
15531 R visitTryStatement(TryStatement node) {
15532 node.visitChildren(this);
15533 return null;
15534 }
15535
15536 @override
15537 R visitTypeArgumentList(TypeArgumentList node) {
15538 node.visitChildren(this);
15539 return null;
15540 }
15541
15542 @override
15543 R visitTypeName(TypeName node) {
15544 node.visitChildren(this);
15545 return null;
15546 }
15547
15548 @override
15549 R visitTypeParameter(TypeParameter node) {
15550 node.visitChildren(this);
15551 return null;
15552 }
15553
15554 @override
15555 R visitTypeParameterList(TypeParameterList node) {
15556 node.visitChildren(this);
15557 return null;
15558 }
15559
15560 @override
15561 R visitVariableDeclaration(VariableDeclaration node) {
15562 node.visitChildren(this);
15563 return null;
15564 }
15565
15566 @override
15567 R visitVariableDeclarationList(VariableDeclarationList node) {
15568 node.visitChildren(this);
15569 return null;
15570 }
15571
15572 @override
15573 R visitVariableDeclarationStatement(VariableDeclarationStatement node) {
15574 node.visitChildren(this);
15575 return null;
15576 }
15577
15578 @override
15579 R visitWhileStatement(WhileStatement node) {
15580 node.visitChildren(this);
15581 return null;
15582 }
15583
15584 @override
15585 R visitWithClause(WithClause node) {
15586 node.visitChildren(this);
15587 return null;
15588 }
15589
15590 @override
15591 R visitYieldStatement(YieldStatement node) {
15592 node.visitChildren(this);
15593 return null;
15594 }
15595 }
15596
15597 /**
15598 * The invocation of a constructor in the same class from within a constructor's 9518 * The invocation of a constructor in the same class from within a constructor's
15599 * initialization list. 9519 * initialization list.
15600 * 9520 *
15601 * > redirectingConstructorInvocation ::= 9521 * > redirectingConstructorInvocation ::=
15602 * > 'this' ('.' identifier)? arguments 9522 * > 'this' ('.' identifier)? arguments
15603 */ 9523 */
15604 class RedirectingConstructorInvocation extends ConstructorInitializer { 9524 class RedirectingConstructorInvocation extends ConstructorInitializer {
15605 /** 9525 /**
15606 * The token for the 'this' keyword. 9526 * The token for the 'this' keyword.
15607 */ 9527 */
15608 Token thisKeyword; 9528 Token thisKeyword;
15609 9529
15610 /** 9530 /**
15611 * The token for the period before the name of the constructor that is being 9531 * The token for the period before the name of the constructor that is being
15612 * invoked, or `null` if the unnamed constructor is being invoked.
15613 */
15614 Token period;
15615
15616 /**
15617 * The name of the constructor that is being invoked, or `null` if the unnamed
15618 * constructor is being invoked.
15619 */
15620 SimpleIdentifier _constructorName;
15621
15622 /**
15623 * The list of arguments to the constructor.
15624 */
15625 ArgumentList _argumentList;
15626
15627 /**
15628 * The element associated with the constructor based on static type
15629 * information, or `null` if the AST structure has not been resolved or if the
15630 * constructor could not be resolved.
15631 */
15632 ConstructorElement staticElement;
15633
15634 /**
15635 * Initialize a newly created redirecting invocation to invoke the constructor
15636 * with the given name with the given arguments. The [constructorName] can be
15637 * `null` if the constructor being invoked is the unnamed constructor.
15638 */
15639 RedirectingConstructorInvocation(this.thisKeyword, this.period,
15640 SimpleIdentifier constructorName, ArgumentList argumentList) {
15641 _constructorName = _becomeParentOf(constructorName);
15642 _argumentList = _becomeParentOf(argumentList);
15643 }
15644
15645 /**
15646 * Return the list of arguments to the constructor.
15647 */
15648 ArgumentList get argumentList => _argumentList;
15649
15650 /**
15651 * Set the list of arguments to the constructor to the given [argumentList].
15652 */
15653 void set argumentList(ArgumentList argumentList) {
15654 _argumentList = _becomeParentOf(argumentList);
15655 }
15656
15657 @override
15658 Token get beginToken => thisKeyword;
15659
15660 @override
15661 Iterable get childEntities => new ChildEntities()
15662 ..add(thisKeyword)
15663 ..add(period)
15664 ..add(_constructorName)
15665 ..add(_argumentList);
15666
15667 /**
15668 * Return the name of the constructor that is being invoked, or `null` if the
15669 * unnamed constructor is being invoked.
15670 */
15671 SimpleIdentifier get constructorName => _constructorName;
15672
15673 /**
15674 * Set the name of the constructor that is being invoked to the given
15675 * [identifier].
15676 */
15677 void set constructorName(SimpleIdentifier identifier) {
15678 _constructorName = _becomeParentOf(identifier);
15679 }
15680
15681 @override
15682 Token get endToken => _argumentList.endToken;
15683
15684 @override
15685 accept(AstVisitor visitor) =>
15686 visitor.visitRedirectingConstructorInvocation(this);
15687
15688 @override
15689 void visitChildren(AstVisitor visitor) {
15690 _safelyVisitChild(_constructorName, visitor);
15691 _safelyVisitChild(_argumentList, visitor);
15692 }
15693 }
15694
15695 /**
15696 * A rethrow expression.
15697 *
15698 * > rethrowExpression ::=
15699 * > 'rethrow'
15700 */
15701 class RethrowExpression extends Expression {
15702 /**
15703 * The token representing the 'rethrow' keyword.
15704 */
15705 Token rethrowKeyword;
15706
15707 /**
15708 * Initialize a newly created rethrow expression.
15709 */
15710 RethrowExpression(this.rethrowKeyword);
15711
15712 @override
15713 Token get beginToken => rethrowKeyword;
15714
15715 @override
15716 Iterable get childEntities => new ChildEntities()..add(rethrowKeyword);
15717
15718 @override
15719 Token get endToken => rethrowKeyword;
15720
15721 @override
15722 int get precedence => 0;
15723
15724 @override
15725 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this);
15726
15727 @override
15728 void visitChildren(AstVisitor visitor) {
15729 // There are no children to visit.
15730 }
15731 }
15732
15733 /**
15734 * A return statement.
15735 *
15736 * > returnStatement ::=
15737 * > 'return' [Expression]? ';'
15738 */
15739 class ReturnStatement extends Statement {
15740 /**
15741 * The token representing the 'return' keyword.
15742 */
15743 Token returnKeyword;
15744
15745 /**
15746 * The expression computing the value to be returned, or `null` if no explicit
15747 * value was provided.
15748 */
15749 Expression _expression;
15750
15751 /**
15752 * The semicolon terminating the statement.
15753 */
15754 Token semicolon;
15755
15756 /**
15757 * Initialize a newly created return statement. The [expression] can be `null`
15758 * if no explicit value was provided.
15759 */
15760 ReturnStatement(this.returnKeyword, Expression expression, this.semicolon) {
15761 _expression = _becomeParentOf(expression);
15762 }
15763
15764 @override
15765 Token get beginToken => returnKeyword;
15766
15767 @override
15768 Iterable get childEntities =>
15769 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon);
15770
15771 @override
15772 Token get endToken => semicolon;
15773
15774 /**
15775 * Return the expression computing the value to be returned, or `null` if no
15776 * explicit value was provided.
15777 */
15778 Expression get expression => _expression;
15779
15780 /**
15781 * Set the expression computing the value to be returned to the given
15782 * [expression].
15783 */
15784 void set expression(Expression expression) {
15785 _expression = _becomeParentOf(expression);
15786 }
15787
15788 @override
15789 accept(AstVisitor visitor) => visitor.visitReturnStatement(this);
15790
15791 @override
15792 void visitChildren(AstVisitor visitor) {
15793 _safelyVisitChild(_expression, visitor);
15794 }
15795 }
15796
15797 /**
15798 * Traverse the AST from initial child node to successive parents, building a
15799 * collection of local variable and parameter names visible to the initial child
15800 * node. In case of name shadowing, the first name seen is the most specific one
15801 * so names are not redefined.
15802 *
15803 * Completion test code coverage is 95%. The two basic blocks that are not
15804 * executed cannot be executed. They are included for future reference.
15805 */
15806 class ScopedNameFinder extends GeneralizingAstVisitor<Object> {
15807 Declaration _declarationNode;
15808
15809 AstNode _immediateChild;
15810
15811 Map<String, SimpleIdentifier> _locals =
15812 new HashMap<String, SimpleIdentifier>();
15813
15814 final int _position;
15815
15816 bool _referenceIsWithinLocalFunction = false;
15817
15818 ScopedNameFinder(this._position);
15819
15820 Declaration get declaration => _declarationNode;
15821
15822 Map<String, SimpleIdentifier> get locals => _locals;
15823
15824 @override
15825 Object visitBlock(Block node) {
15826 _checkStatements(node.statements);
15827 return super.visitBlock(node);
15828 }
15829
15830 @override
15831 Object visitCatchClause(CatchClause node) {
15832 _addToScope(node.exceptionParameter);
15833 _addToScope(node.stackTraceParameter);
15834 return super.visitCatchClause(node);
15835 }
15836
15837 @override
15838 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15839 if (!identical(_immediateChild, node.parameters)) {
15840 _addParameters(node.parameters.parameters);
15841 }
15842 _declarationNode = node;
15843 return null;
15844 }
15845
15846 @override
15847 Object visitFieldDeclaration(FieldDeclaration node) {
15848 _declarationNode = node;
15849 return null;
15850 }
15851
15852 @override
15853 Object visitForEachStatement(ForEachStatement node) {
15854 DeclaredIdentifier loopVariable = node.loopVariable;
15855 if (loopVariable != null) {
15856 _addToScope(loopVariable.identifier);
15857 }
15858 return super.visitForEachStatement(node);
15859 }
15860
15861 @override
15862 Object visitForStatement(ForStatement node) {
15863 if (!identical(_immediateChild, node.variables) && node.variables != null) {
15864 _addVariables(node.variables.variables);
15865 }
15866 return super.visitForStatement(node);
15867 }
15868
15869 @override
15870 Object visitFunctionDeclaration(FunctionDeclaration node) {
15871 if (node.parent is! FunctionDeclarationStatement) {
15872 _declarationNode = node;
15873 return null;
15874 }
15875 return super.visitFunctionDeclaration(node);
15876 }
15877
15878 @override
15879 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
15880 _referenceIsWithinLocalFunction = true;
15881 return super.visitFunctionDeclarationStatement(node);
15882 }
15883
15884 @override
15885 Object visitFunctionExpression(FunctionExpression node) {
15886 if (node.parameters != null &&
15887 !identical(_immediateChild, node.parameters)) {
15888 _addParameters(node.parameters.parameters);
15889 }
15890 return super.visitFunctionExpression(node);
15891 }
15892
15893 @override
15894 Object visitMethodDeclaration(MethodDeclaration node) {
15895 _declarationNode = node;
15896 if (node.parameters == null) {
15897 return null;
15898 }
15899 if (!identical(_immediateChild, node.parameters)) {
15900 _addParameters(node.parameters.parameters);
15901 }
15902 return null;
15903 }
15904
15905 @override
15906 Object visitNode(AstNode node) {
15907 _immediateChild = node;
15908 AstNode parent = node.parent;
15909 if (parent != null) {
15910 parent.accept(this);
15911 }
15912 return null;
15913 }
15914
15915 @override
15916 Object visitSwitchMember(SwitchMember node) {
15917 _checkStatements(node.statements);
15918 return super.visitSwitchMember(node);
15919 }
15920
15921 @override
15922 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
15923 _declarationNode = node;
15924 return null;
15925 }
15926
15927 @override
15928 Object visitTypeAlias(TypeAlias node) {
15929 _declarationNode = node;
15930 return null;
15931 }
15932
15933 void _addParameters(NodeList<FormalParameter> vars) {
15934 for (FormalParameter var2 in vars) {
15935 _addToScope(var2.identifier);
15936 }
15937 }
15938
15939 void _addToScope(SimpleIdentifier identifier) {
15940 if (identifier != null && _isInRange(identifier)) {
15941 String name = identifier.name;
15942 if (!_locals.containsKey(name)) {
15943 _locals[name] = identifier;
15944 }
15945 }
15946 }
15947
15948 void _addVariables(NodeList<VariableDeclaration> variables) {
15949 for (VariableDeclaration variable in variables) {
15950 _addToScope(variable.name);
15951 }
15952 }
15953
15954 /**
15955 * Check the given list of [statements] for any that come before the immediate
15956 * child and that define a name that would be visible to the immediate child.
15957 */
15958 void _checkStatements(List<Statement> statements) {
15959 for (Statement statement in statements) {
15960 if (identical(statement, _immediateChild)) {
15961 return;
15962 }
15963 if (statement is VariableDeclarationStatement) {
15964 _addVariables(statement.variables.variables);
15965 } else if (statement is FunctionDeclarationStatement &&
15966 !_referenceIsWithinLocalFunction) {
15967 _addToScope(statement.functionDeclaration.name);
15968 }
15969 }
15970 }
15971
15972 bool _isInRange(AstNode node) {
15973 if (_position < 0) {
15974 // if source position is not set then all nodes are in range
15975 return true;
15976 // not reached
15977 }
15978 return node.end < _position;
15979 }
15980 }
15981
15982 /**
15983 * A script tag that can optionally occur at the beginning of a compilation unit .
15984 *
15985 * > scriptTag ::=
15986 * > '#!' (~NEWLINE)* NEWLINE
15987 */
15988 class ScriptTag extends AstNode {
15989 /**
15990 * The token representing this script tag.
15991 */
15992 Token scriptTag;
15993
15994 /**
15995 * Initialize a newly created script tag.
15996 */
15997 ScriptTag(this.scriptTag);
15998
15999 @override
16000 Token get beginToken => scriptTag;
16001
16002 @override
16003 Iterable get childEntities => new ChildEntities()..add(scriptTag);
16004
16005 @override
16006 Token get endToken => scriptTag;
16007
16008 @override
16009 accept(AstVisitor visitor) => visitor.visitScriptTag(this);
16010
16011 @override
16012 void visitChildren(AstVisitor visitor) {
16013 // There are no children to visit.
16014 }
16015 }
16016
16017 /**
16018 * A combinator that restricts the names being imported to those in a given list .
16019 *
16020 * > showCombinator ::=
16021 * > 'show' [SimpleIdentifier] (',' [SimpleIdentifier])*
16022 */
16023 class ShowCombinator extends Combinator {
16024 /**
16025 * The list of names from the library that are made visible by this combinator .
16026 */
16027 NodeList<SimpleIdentifier> _shownNames;
16028
16029 /**
16030 * Initialize a newly created import show combinator.
16031 */
16032 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames)
16033 : super(keyword) {
16034 _shownNames = new NodeList<SimpleIdentifier>(this, shownNames);
16035 }
16036
16037 @override
16038 // TODO(paulberry): add commas.
16039 Iterable get childEntities => new ChildEntities()
16040 ..add(keyword)
16041 ..addAll(_shownNames);
16042
16043 @override
16044 Token get endToken => _shownNames.endToken;
16045
16046 /**
16047 * Return the list of names from the library that are made visible by this
16048 * combinator.
16049 */
16050 NodeList<SimpleIdentifier> get shownNames => _shownNames;
16051
16052 @override
16053 accept(AstVisitor visitor) => visitor.visitShowCombinator(this);
16054
16055 @override
16056 void visitChildren(AstVisitor visitor) {
16057 _shownNames.accept(visitor);
16058 }
16059 }
16060
16061 /**
16062 * An AST visitor that will do nothing when visiting an AST node. It is intended
16063 * to be a superclass for classes that use the visitor pattern primarily as a
16064 * dispatch mechanism (and hence don't need to recursively visit a whole
16065 * structure) and that only need to visit a small number of node types.
16066 */
16067 class SimpleAstVisitor<R> implements AstVisitor<R> {
16068 @override
16069 R visitAdjacentStrings(AdjacentStrings node) => null;
16070
16071 @override
16072 R visitAnnotation(Annotation node) => null;
16073
16074 @override
16075 R visitArgumentList(ArgumentList node) => null;
16076
16077 @override
16078 R visitAsExpression(AsExpression node) => null;
16079
16080 @override
16081 R visitAssertStatement(AssertStatement node) => null;
16082
16083 @override
16084 R visitAssignmentExpression(AssignmentExpression node) => null;
16085
16086 @override
16087 R visitAwaitExpression(AwaitExpression node) => null;
16088
16089 @override
16090 R visitBinaryExpression(BinaryExpression node) => null;
16091
16092 @override
16093 R visitBlock(Block node) => null;
16094
16095 @override
16096 R visitBlockFunctionBody(BlockFunctionBody node) => null;
16097
16098 @override
16099 R visitBooleanLiteral(BooleanLiteral node) => null;
16100
16101 @override
16102 R visitBreakStatement(BreakStatement node) => null;
16103
16104 @override
16105 R visitCascadeExpression(CascadeExpression node) => null;
16106
16107 @override
16108 R visitCatchClause(CatchClause node) => null;
16109
16110 @override
16111 R visitClassDeclaration(ClassDeclaration node) => null;
16112
16113 @override
16114 R visitClassTypeAlias(ClassTypeAlias node) => null;
16115
16116 @override
16117 R visitComment(Comment node) => null;
16118
16119 @override
16120 R visitCommentReference(CommentReference node) => null;
16121
16122 @override
16123 R visitCompilationUnit(CompilationUnit node) => null;
16124
16125 @override
16126 R visitConditionalExpression(ConditionalExpression node) => null;
16127
16128 @override
16129 R visitConfiguration(Configuration node) => null;
16130
16131 @override
16132 R visitConstructorDeclaration(ConstructorDeclaration node) => null;
16133
16134 @override
16135 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => null;
16136
16137 @override
16138 R visitConstructorName(ConstructorName node) => null;
16139
16140 @override
16141 R visitContinueStatement(ContinueStatement node) => null;
16142
16143 @override
16144 R visitDeclaredIdentifier(DeclaredIdentifier node) => null;
16145
16146 @override
16147 R visitDefaultFormalParameter(DefaultFormalParameter node) => null;
16148
16149 @override
16150 R visitDoStatement(DoStatement node) => null;
16151
16152 @override
16153 R visitDottedName(DottedName node) => null;
16154
16155 @override
16156 R visitDoubleLiteral(DoubleLiteral node) => null;
16157
16158 @override
16159 R visitEmptyFunctionBody(EmptyFunctionBody node) => null;
16160
16161 @override
16162 R visitEmptyStatement(EmptyStatement node) => null;
16163
16164 @override
16165 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => null;
16166
16167 @override
16168 R visitEnumDeclaration(EnumDeclaration node) => null;
16169
16170 @override
16171 R visitExportDirective(ExportDirective node) => null;
16172
16173 @override
16174 R visitExpressionFunctionBody(ExpressionFunctionBody node) => null;
16175
16176 @override
16177 R visitExpressionStatement(ExpressionStatement node) => null;
16178
16179 @override
16180 R visitExtendsClause(ExtendsClause node) => null;
16181
16182 @override
16183 R visitFieldDeclaration(FieldDeclaration node) => null;
16184
16185 @override
16186 R visitFieldFormalParameter(FieldFormalParameter node) => null;
16187
16188 @override
16189 R visitForEachStatement(ForEachStatement node) => null;
16190
16191 @override
16192 R visitFormalParameterList(FormalParameterList node) => null;
16193
16194 @override
16195 R visitForStatement(ForStatement node) => null;
16196
16197 @override
16198 R visitFunctionDeclaration(FunctionDeclaration node) => null;
16199
16200 @override
16201 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
16202 null;
16203
16204 @override
16205 R visitFunctionExpression(FunctionExpression node) => null;
16206
16207 @override
16208 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
16209 null;
16210
16211 @override
16212 R visitFunctionTypeAlias(FunctionTypeAlias node) => null;
16213
16214 @override
16215 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
16216 null;
16217
16218 @override
16219 R visitHideCombinator(HideCombinator node) => null;
16220
16221 @override
16222 R visitIfStatement(IfStatement node) => null;
16223
16224 @override
16225 R visitImplementsClause(ImplementsClause node) => null;
16226
16227 @override
16228 R visitImportDirective(ImportDirective node) => null;
16229
16230 @override
16231 R visitIndexExpression(IndexExpression node) => null;
16232
16233 @override
16234 R visitInstanceCreationExpression(InstanceCreationExpression node) => null;
16235
16236 @override
16237 R visitIntegerLiteral(IntegerLiteral node) => null;
16238
16239 @override
16240 R visitInterpolationExpression(InterpolationExpression node) => null;
16241
16242 @override
16243 R visitInterpolationString(InterpolationString node) => null;
16244
16245 @override
16246 R visitIsExpression(IsExpression node) => null;
16247
16248 @override
16249 R visitLabel(Label node) => null;
16250
16251 @override
16252 R visitLabeledStatement(LabeledStatement node) => null;
16253
16254 @override
16255 R visitLibraryDirective(LibraryDirective node) => null;
16256
16257 @override
16258 R visitLibraryIdentifier(LibraryIdentifier node) => null;
16259
16260 @override
16261 R visitListLiteral(ListLiteral node) => null;
16262
16263 @override
16264 R visitMapLiteral(MapLiteral node) => null;
16265
16266 @override
16267 R visitMapLiteralEntry(MapLiteralEntry node) => null;
16268
16269 @override
16270 R visitMethodDeclaration(MethodDeclaration node) => null;
16271
16272 @override
16273 R visitMethodInvocation(MethodInvocation node) => null;
16274
16275 @override
16276 R visitNamedExpression(NamedExpression node) => null;
16277
16278 @override
16279 R visitNativeClause(NativeClause node) => null;
16280
16281 @override
16282 R visitNativeFunctionBody(NativeFunctionBody node) => null;
16283
16284 @override
16285 R visitNullLiteral(NullLiteral node) => null;
16286
16287 @override
16288 R visitParenthesizedExpression(ParenthesizedExpression node) => null;
16289
16290 @override
16291 R visitPartDirective(PartDirective node) => null;
16292
16293 @override
16294 R visitPartOfDirective(PartOfDirective node) => null;
16295
16296 @override
16297 R visitPostfixExpression(PostfixExpression node) => null;
16298
16299 @override
16300 R visitPrefixedIdentifier(PrefixedIdentifier node) => null;
16301
16302 @override
16303 R visitPrefixExpression(PrefixExpression node) => null;
16304
16305 @override
16306 R visitPropertyAccess(PropertyAccess node) => null;
16307
16308 @override
16309 R visitRedirectingConstructorInvocation(
16310 RedirectingConstructorInvocation node) =>
16311 null;
16312
16313 @override
16314 R visitRethrowExpression(RethrowExpression node) => null;
16315
16316 @override
16317 R visitReturnStatement(ReturnStatement node) => null;
16318
16319 @override
16320 R visitScriptTag(ScriptTag node) => null;
16321
16322 @override
16323 R visitShowCombinator(ShowCombinator node) => null;
16324
16325 @override
16326 R visitSimpleFormalParameter(SimpleFormalParameter node) => null;
16327
16328 @override
16329 R visitSimpleIdentifier(SimpleIdentifier node) => null;
16330
16331 @override
16332 R visitSimpleStringLiteral(SimpleStringLiteral node) => null;
16333
16334 @override
16335 R visitStringInterpolation(StringInterpolation node) => null;
16336
16337 @override
16338 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => null;
16339
16340 @override
16341 R visitSuperExpression(SuperExpression node) => null;
16342
16343 @override
16344 R visitSwitchCase(SwitchCase node) => null;
16345
16346 @override
16347 R visitSwitchDefault(SwitchDefault node) => null;
16348
16349 @override
16350 R visitSwitchStatement(SwitchStatement node) => null;
16351
16352 @override
16353 R visitSymbolLiteral(SymbolLiteral node) => null;
16354
16355 @override
16356 R visitThisExpression(ThisExpression node) => null;
16357
16358 @override
16359 R visitThrowExpression(ThrowExpression node) => null;
16360
16361 @override
16362 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => null;
16363
16364 @override
16365 R visitTryStatement(TryStatement node) => null;
16366
16367 @override
16368 R visitTypeArgumentList(TypeArgumentList node) => null;
16369
16370 @override
16371 R visitTypeName(TypeName node) => null;
16372
16373 @override
16374 R visitTypeParameter(TypeParameter node) => null;
16375
16376 @override
16377 R visitTypeParameterList(TypeParameterList node) => null;
16378
16379 @override
16380 R visitVariableDeclaration(VariableDeclaration node) => null;
16381
16382 @override
16383 R visitVariableDeclarationList(VariableDeclarationList node) => null;
16384
16385 @override
16386 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
16387 null;
16388
16389 @override
16390 R visitWhileStatement(WhileStatement node) => null;
16391
16392 @override
16393 R visitWithClause(WithClause node) => null;
16394
16395 @override
16396 R visitYieldStatement(YieldStatement node) => null;
16397 }
16398
16399 /**
16400 * A simple formal parameter.
16401 *
16402 * > simpleFormalParameter ::=
16403 * > ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier]
16404 */
16405 class SimpleFormalParameter extends NormalFormalParameter {
16406 /**
16407 * The token representing either the 'final', 'const' or 'var' keyword, or
16408 * `null` if no keyword was used.
16409 */
16410 Token keyword;
16411
16412 /**
16413 * The name of the declared type of the parameter, or `null` if the parameter
16414 * does not have a declared type.
16415 */
16416 TypeName _type;
16417
16418 /**
16419 * Initialize a newly created formal parameter. Either or both of the
16420 * [comment] and [metadata] can be `null` if the parameter does not have the
16421 * corresponding attribute. The [keyword] can be `null` if a type was
16422 * specified. The [type] must be `null` if the keyword is 'var'.
16423 */
16424 SimpleFormalParameter(Comment comment, List<Annotation> metadata,
16425 this.keyword, TypeName type, SimpleIdentifier identifier)
16426 : super(comment, metadata, identifier) {
16427 _type = _becomeParentOf(type);
16428 }
16429
16430 @override
16431 Token get beginToken {
16432 NodeList<Annotation> metadata = this.metadata;
16433 if (!metadata.isEmpty) {
16434 return metadata.beginToken;
16435 } else if (keyword != null) {
16436 return keyword;
16437 } else if (_type != null) {
16438 return _type.beginToken;
16439 }
16440 return identifier.beginToken;
16441 }
16442
16443 @override
16444 Iterable get childEntities =>
16445 super._childEntities..add(keyword)..add(_type)..add(identifier);
16446
16447 @override
16448 Token get endToken => identifier.endToken;
16449
16450 @override
16451 bool get isConst =>
16452 (keyword is KeywordToken) &&
16453 (keyword as KeywordToken).keyword == Keyword.CONST;
16454
16455 @override
16456 bool get isFinal =>
16457 (keyword is KeywordToken) &&
16458 (keyword as KeywordToken).keyword == Keyword.FINAL;
16459
16460 /**
16461 * Return the name of the declared type of the parameter, or `null` if the
16462 * parameter does not have a declared type.
16463 */
16464 TypeName get type => _type;
16465
16466 /**
16467 * Set the name of the declared type of the parameter to the given [typeName].
16468 */
16469 void set type(TypeName typeName) {
16470 _type = _becomeParentOf(typeName);
16471 }
16472
16473 @override
16474 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this);
16475
16476 @override
16477 void visitChildren(AstVisitor visitor) {
16478 super.visitChildren(visitor);
16479 _safelyVisitChild(_type, visitor);
16480 _safelyVisitChild(identifier, visitor);
16481 }
16482 }
16483
16484 /**
16485 * A simple identifier.
16486 *
16487 * > simpleIdentifier ::=
16488 * > initialCharacter internalCharacter*
16489 * >
16490 * > initialCharacter ::= '_' | '$' | letter
16491 * >
16492 * > internalCharacter ::= '_' | '$' | letter | digit
16493 */
16494 class SimpleIdentifier extends Identifier {
16495 /**
16496 * The token representing the identifier.
16497 */
16498 Token token;
16499
16500 /**
16501 * The element associated with this identifier based on static type
16502 * information, or `null` if the AST structure has not been resolved or if
16503 * this identifier could not be resolved.
16504 */
16505 Element _staticElement;
16506
16507 /**
16508 * The element associated with this identifier based on propagated type
16509 * information, or `null` if the AST structure has not been resolved or if
16510 * this identifier could not be resolved.
16511 */
16512 Element _propagatedElement;
16513
16514 /**
16515 * If this expression is both in a getter and setter context, the
16516 * [AuxiliaryElements] will be set to hold onto the static and propagated
16517 * information. The auxiliary element will hold onto the elements from the
16518 * getter context.
16519 */
16520 AuxiliaryElements auxiliaryElements = null;
16521
16522 /**
16523 * Initialize a newly created identifier.
16524 */
16525 SimpleIdentifier(this.token);
16526
16527 @override
16528 Token get beginToken => token;
16529
16530 @override
16531 Element get bestElement {
16532 if (_propagatedElement == null) {
16533 return _staticElement;
16534 }
16535 return _propagatedElement;
16536 }
16537
16538 @override
16539 Iterable get childEntities => new ChildEntities()..add(token);
16540
16541 @override
16542 Token get endToken => token;
16543
16544 /**
16545 * Return `true` if this identifier is the "name" part of a prefixed
16546 * identifier or a method invocation.
16547 */
16548 bool get isQualified {
16549 AstNode parent = this.parent;
16550 if (parent is PrefixedIdentifier) {
16551 return identical(parent.identifier, this);
16552 }
16553 if (parent is PropertyAccess) {
16554 return identical(parent.propertyName, this);
16555 }
16556 if (parent is MethodInvocation) {
16557 MethodInvocation invocation = parent;
16558 return identical(invocation.methodName, this) &&
16559 invocation.realTarget != null;
16560 }
16561 return false;
16562 }
16563
16564 @override
16565 bool get isSynthetic => token.isSynthetic;
16566
16567 @override
16568 String get name => token.lexeme;
16569
16570 @override
16571 int get precedence => 16;
16572
16573 @override
16574 Element get propagatedElement => _propagatedElement;
16575
16576 /**
16577 * Set the element associated with this identifier based on propagated type
16578 * information to the given [element].
16579 */
16580 void set propagatedElement(Element element) {
16581 _propagatedElement = _validateElement(element);
16582 }
16583
16584 @override
16585 Element get staticElement => _staticElement;
16586
16587 /**
16588 * Set the element associated with this identifier based on static type
16589 * information to the given [element].
16590 */
16591 void set staticElement(Element element) {
16592 _staticElement = _validateElement(element);
16593 }
16594
16595 @override
16596 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this);
16597
16598 /**
16599 * Return `true` if this identifier is the name being declared in a
16600 * declaration.
16601 */
16602 bool inDeclarationContext() {
16603 // TODO(brianwilkerson) Convert this to a getter.
16604 AstNode parent = this.parent;
16605 if (parent is CatchClause) {
16606 CatchClause clause = parent;
16607 return identical(this, clause.exceptionParameter) ||
16608 identical(this, clause.stackTraceParameter);
16609 } else if (parent is ClassDeclaration) {
16610 return identical(this, parent.name);
16611 } else if (parent is ClassTypeAlias) {
16612 return identical(this, parent.name);
16613 } else if (parent is ConstructorDeclaration) {
16614 return identical(this, parent.name);
16615 } else if (parent is DeclaredIdentifier) {
16616 return identical(this, parent.identifier);
16617 } else if (parent is EnumDeclaration) {
16618 return identical(this, parent.name);
16619 } else if (parent is EnumConstantDeclaration) {
16620 return identical(this, parent.name);
16621 } else if (parent is FunctionDeclaration) {
16622 return identical(this, parent.name);
16623 } else if (parent is FunctionTypeAlias) {
16624 return identical(this, parent.name);
16625 } else if (parent is ImportDirective) {
16626 return identical(this, parent.prefix);
16627 } else if (parent is Label) {
16628 return identical(this, parent.label) &&
16629 (parent.parent is LabeledStatement);
16630 } else if (parent is MethodDeclaration) {
16631 return identical(this, parent.name);
16632 } else if (parent is FunctionTypedFormalParameter ||
16633 parent is SimpleFormalParameter) {
16634 return identical(this, (parent as NormalFormalParameter).identifier);
16635 } else if (parent is TypeParameter) {
16636 return identical(this, parent.name);
16637 } else if (parent is VariableDeclaration) {
16638 return identical(this, parent.name);
16639 }
16640 return false;
16641 }
16642
16643 /**
16644 * Return `true` if this expression is computing a right-hand value.
16645 *
16646 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16647 * are they mutually exclusive. In other words, it is possible for both
16648 * methods to return `true` when invoked on the same node.
16649 */
16650 bool inGetterContext() {
16651 // TODO(brianwilkerson) Convert this to a getter.
16652 AstNode parent = this.parent;
16653 AstNode target = this;
16654 // skip prefix
16655 if (parent is PrefixedIdentifier) {
16656 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16657 if (identical(prefixed.prefix, this)) {
16658 return true;
16659 }
16660 parent = prefixed.parent;
16661 target = prefixed;
16662 } else if (parent is PropertyAccess) {
16663 PropertyAccess access = parent as PropertyAccess;
16664 if (identical(access.target, this)) {
16665 return true;
16666 }
16667 parent = access.parent;
16668 target = access;
16669 }
16670 // skip label
16671 if (parent is Label) {
16672 return false;
16673 }
16674 // analyze usage
16675 if (parent is AssignmentExpression) {
16676 if (identical(parent.leftHandSide, target) &&
16677 parent.operator.type == TokenType.EQ) {
16678 return false;
16679 }
16680 }
16681 if (parent is ForEachStatement) {
16682 if (identical(parent.identifier, target)) {
16683 return false;
16684 }
16685 }
16686 return true;
16687 }
16688
16689 /**
16690 * Return `true` if this expression is computing a left-hand value.
16691 *
16692 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16693 * are they mutually exclusive. In other words, it is possible for both
16694 * methods to return `true` when invoked on the same node.
16695 */
16696 bool inSetterContext() {
16697 // TODO(brianwilkerson) Convert this to a getter.
16698 AstNode parent = this.parent;
16699 AstNode target = this;
16700 // skip prefix
16701 if (parent is PrefixedIdentifier) {
16702 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16703 // if this is the prefix, then return false
16704 if (identical(prefixed.prefix, this)) {
16705 return false;
16706 }
16707 parent = prefixed.parent;
16708 target = prefixed;
16709 } else if (parent is PropertyAccess) {
16710 PropertyAccess access = parent as PropertyAccess;
16711 if (identical(access.target, this)) {
16712 return false;
16713 }
16714 parent = access.parent;
16715 target = access;
16716 }
16717 // analyze usage
16718 if (parent is PrefixExpression) {
16719 return parent.operator.type.isIncrementOperator;
16720 } else if (parent is PostfixExpression) {
16721 return true;
16722 } else if (parent is AssignmentExpression) {
16723 return identical(parent.leftHandSide, target);
16724 } else if (parent is ForEachStatement) {
16725 return identical(parent.identifier, target);
16726 }
16727 return false;
16728 }
16729
16730 @override
16731 void visitChildren(AstVisitor visitor) {
16732 // There are no children to visit.
16733 }
16734
16735 /**
16736 * Return the given element if it is valid, or report the problem and return
16737 * `null` if it is not appropriate.
16738 *
16739 * The [parent] is the parent of the element, used for reporting when there is
16740 * a problem.
16741 * The [isValid] is `true` if the element is appropriate.
16742 * The [element] is the element to be associated with this identifier.
16743 */
16744 Element _returnOrReportElement(
16745 AstNode parent, bool isValid, Element element) {
16746 if (!isValid) {
16747 AnalysisEngine.instance.logger.logInformation(
16748 "Internal error: attempting to set the name of a ${parent.runtimeType} to a ${element.runtimeType}",
16749 new CaughtException(new AnalysisException(), null));
16750 return null;
16751 }
16752 return element;
16753 }
16754
16755 /**
16756 * Return the given [element] if it is an appropriate element based on the
16757 * parent of this identifier, or `null` if it is not appropriate.
16758 */
16759 Element _validateElement(Element element) {
16760 if (element == null) {
16761 return null;
16762 }
16763 AstNode parent = this.parent;
16764 if (parent is ClassDeclaration && identical(parent.name, this)) {
16765 return _returnOrReportElement(parent, element is ClassElement, element);
16766 } else if (parent is ClassTypeAlias && identical(parent.name, this)) {
16767 return _returnOrReportElement(parent, element is ClassElement, element);
16768 } else if (parent is DeclaredIdentifier &&
16769 identical(parent.identifier, this)) {
16770 return _returnOrReportElement(
16771 parent, element is LocalVariableElement, element);
16772 } else if (parent is FormalParameter &&
16773 identical(parent.identifier, this)) {
16774 return _returnOrReportElement(
16775 parent, element is ParameterElement, element);
16776 } else if (parent is FunctionDeclaration && identical(parent.name, this)) {
16777 return _returnOrReportElement(
16778 parent, element is ExecutableElement, element);
16779 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) {
16780 return _returnOrReportElement(
16781 parent, element is FunctionTypeAliasElement, element);
16782 } else if (parent is MethodDeclaration && identical(parent.name, this)) {
16783 return _returnOrReportElement(
16784 parent, element is ExecutableElement, element);
16785 } else if (parent is TypeParameter && identical(parent.name, this)) {
16786 return _returnOrReportElement(
16787 parent, element is TypeParameterElement, element);
16788 } else if (parent is VariableDeclaration && identical(parent.name, this)) {
16789 return _returnOrReportElement(
16790 parent, element is VariableElement, element);
16791 }
16792 return element;
16793 }
16794 }
16795
16796 /**
16797 * A string literal expression that does not contain any interpolations.
16798 *
16799 * > simpleStringLiteral ::=
16800 * > rawStringLiteral
16801 * > | basicStringLiteral
16802 * >
16803 * > rawStringLiteral ::=
16804 * > 'r' basicStringLiteral
16805 * >
16806 * > simpleStringLiteral ::=
16807 * > multiLineStringLiteral
16808 * > | singleLineStringLiteral
16809 * >
16810 * > multiLineStringLiteral ::=
16811 * > "'''" characters "'''"
16812 * > | '"""' characters '"""'
16813 * >
16814 * > singleLineStringLiteral ::=
16815 * > "'" characters "'"
16816 * > | '"' characters '"'
16817 */
16818 class SimpleStringLiteral extends SingleStringLiteral {
16819 /**
16820 * The token representing the literal.
16821 */
16822 Token literal;
16823
16824 /**
16825 * The value of the literal.
16826 */
16827 String _value;
16828
16829 /**
16830 * Initialize a newly created simple string literal.
16831 */
16832 SimpleStringLiteral(this.literal, String value) {
16833 _value = StringUtilities.intern(value);
16834 }
16835
16836 @override
16837 Token get beginToken => literal;
16838
16839 @override
16840 Iterable get childEntities => new ChildEntities()..add(literal);
16841
16842 @override
16843 int get contentsEnd => offset + _helper.end;
16844
16845 @override
16846 int get contentsOffset => offset + _helper.start;
16847
16848 @override
16849 Token get endToken => literal;
16850
16851 @override
16852 bool get isMultiline => _helper.isMultiline;
16853
16854 @override
16855 bool get isRaw => _helper.isRaw;
16856
16857 @override
16858 bool get isSingleQuoted => _helper.isSingleQuoted;
16859
16860 @override
16861 bool get isSynthetic => literal.isSynthetic;
16862
16863 /**
16864 * Return the value of the literal.
16865 */
16866 String get value => _value;
16867
16868 /**
16869 * Set the value of the literal to the given [string].
16870 */
16871 void set value(String string) {
16872 _value = StringUtilities.intern(_value);
16873 }
16874
16875 StringLexemeHelper get _helper {
16876 return new StringLexemeHelper(literal.lexeme, true, true);
16877 }
16878
16879 @override
16880 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this);
16881
16882 @override
16883 void visitChildren(AstVisitor visitor) {
16884 // There are no children to visit.
16885 }
16886
16887 @override
16888 void _appendStringValue(StringBuffer buffer) {
16889 buffer.write(value);
16890 }
16891 }
16892
16893 /**
16894 * A single string literal expression.
16895 *
16896 * > singleStringLiteral ::=
16897 * > [SimpleStringLiteral]
16898 * > | [StringInterpolation]
16899 */
16900 abstract class SingleStringLiteral extends StringLiteral {
16901 /**
16902 * Return the offset of the after-last contents character.
16903 */
16904 int get contentsEnd;
16905
16906 /**
16907 * Return the offset of the first contents character.
16908 * If the string is multiline, then leading whitespaces are skipped.
16909 */
16910 int get contentsOffset;
16911
16912 /**
16913 * Return `true` if this string literal is a multi-line string.
16914 */
16915 bool get isMultiline;
16916
16917 /**
16918 * Return `true` if this string literal is a raw string.
16919 */
16920 bool get isRaw;
16921
16922 /**
16923 * Return `true` if this string literal uses single qoutes (' or ''').
16924 * Return `false` if this string literal uses double qoutes (" or """).
16925 */
16926 bool get isSingleQuoted;
16927 }
16928
16929 /**
16930 * A node that represents a statement.
16931 *
16932 * > statement ::=
16933 * > [Block]
16934 * > | [VariableDeclarationStatement]
16935 * > | [ForStatement]
16936 * > | [ForEachStatement]
16937 * > | [WhileStatement]
16938 * > | [DoStatement]
16939 * > | [SwitchStatement]
16940 * > | [IfStatement]
16941 * > | [TryStatement]
16942 * > | [BreakStatement]
16943 * > | [ContinueStatement]
16944 * > | [ReturnStatement]
16945 * > | [ExpressionStatement]
16946 * > | [FunctionDeclarationStatement]
16947 */
16948 abstract class Statement extends AstNode {
16949 /**
16950 * If this is a labeled statement, return the unlabeled portion of the
16951 * statement. Otherwise return the statement itself.
16952 */
16953 Statement get unlabeled => this;
16954 }
16955
16956 /**
16957 * A string interpolation literal.
16958 *
16959 * > stringInterpolation ::=
16960 * > ''' [InterpolationElement]* '''
16961 * > | '"' [InterpolationElement]* '"'
16962 */
16963 class StringInterpolation extends SingleStringLiteral {
16964 /**
16965 * The elements that will be composed to produce the resulting string.
16966 */
16967 NodeList<InterpolationElement> _elements;
16968
16969 /**
16970 * Initialize a newly created string interpolation expression.
16971 */
16972 StringInterpolation(List<InterpolationElement> elements) {
16973 _elements = new NodeList<InterpolationElement>(this, elements);
16974 }
16975
16976 @override
16977 Token get beginToken => _elements.beginToken;
16978
16979 @override
16980 Iterable get childEntities => new ChildEntities()..addAll(_elements);
16981
16982 @override
16983 int get contentsEnd {
16984 InterpolationString element = _elements.last;
16985 return element.contentsEnd;
16986 }
16987
16988 @override
16989 int get contentsOffset {
16990 InterpolationString element = _elements.first;
16991 return element.contentsOffset;
16992 }
16993
16994 /**
16995 * Return the elements that will be composed to produce the resulting string.
16996 */
16997 NodeList<InterpolationElement> get elements => _elements;
16998
16999 @override
17000 Token get endToken => _elements.endToken;
17001
17002 @override
17003 bool get isMultiline => _firstHelper.isMultiline;
17004
17005 @override
17006 bool get isRaw => false;
17007
17008 @override
17009 bool get isSingleQuoted => _firstHelper.isSingleQuoted;
17010
17011 StringLexemeHelper get _firstHelper {
17012 InterpolationString lastString = _elements.first;
17013 String lexeme = lastString.contents.lexeme;
17014 return new StringLexemeHelper(lexeme, true, false);
17015 }
17016
17017 @override
17018 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this);
17019
17020 @override
17021 void visitChildren(AstVisitor visitor) {
17022 _elements.accept(visitor);
17023 }
17024
17025 @override
17026 void _appendStringValue(StringBuffer buffer) {
17027 throw new IllegalArgumentException();
17028 }
17029 }
17030
17031 /**
17032 * A helper for analyzing string lexemes.
17033 */
17034 class StringLexemeHelper {
17035 final String lexeme;
17036 final bool isFirst;
17037 final bool isLast;
17038
17039 bool isRaw = false;
17040 bool isSingleQuoted = false;
17041 bool isMultiline = false;
17042 int start = 0;
17043 int end;
17044
17045 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) {
17046 if (isFirst) {
17047 isRaw = StringUtilities.startsWithChar(lexeme, 0x72);
17048 if (isRaw) {
17049 start++;
17050 }
17051 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) {
17052 isSingleQuoted = true;
17053 isMultiline = true;
17054 start += 3;
17055 start = _trimInitialWhitespace(start);
17056 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) {
17057 isSingleQuoted = false;
17058 isMultiline = true;
17059 start += 3;
17060 start = _trimInitialWhitespace(start);
17061 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) {
17062 isSingleQuoted = true;
17063 isMultiline = false;
17064 start++;
17065 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) {
17066 isSingleQuoted = false;
17067 isMultiline = false;
17068 start++;
17069 }
17070 }
17071 end = lexeme.length;
17072 if (isLast) {
17073 if (start + 3 <= end &&
17074 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
17075 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) {
17076 end -= 3;
17077 } else if (start + 1 <= end &&
17078 (StringUtilities.endsWithChar(lexeme, 0x22) ||
17079 StringUtilities.endsWithChar(lexeme, 0x27))) {
17080 end -= 1;
17081 }
17082 }
17083 }
17084
17085 /**
17086 * Given the [lexeme] for a multi-line string whose content begins at the
17087 * given [start] index, return the index of the first character that is
17088 * included in the value of the string. According to the specification:
17089 *
17090 * If the first line of a multiline string consists solely of the whitespace
17091 * characters defined by the production WHITESPACE 20.1), possibly prefixed
17092 * by \, then that line is ignored, including the new line at its end.
17093 */
17094 int _trimInitialWhitespace(int start) {
17095 int length = lexeme.length;
17096 int index = start;
17097 while (index < length) {
17098 int currentChar = lexeme.codeUnitAt(index);
17099 if (currentChar == 0x0D) {
17100 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
17101 return index + 2;
17102 }
17103 return index + 1;
17104 } else if (currentChar == 0x0A) {
17105 return index + 1;
17106 } else if (currentChar == 0x5C) {
17107 if (index + 1 >= length) {
17108 return start;
17109 }
17110 currentChar = lexeme.codeUnitAt(index + 1);
17111 if (currentChar != 0x0D &&
17112 currentChar != 0x0A &&
17113 currentChar != 0x09 &&
17114 currentChar != 0x20) {
17115 return start;
17116 }
17117 } else if (currentChar != 0x09 && currentChar != 0x20) {
17118 return start;
17119 }
17120 index++;
17121 }
17122 return start;
17123 }
17124 }
17125
17126 /**
17127 * A string literal expression.
17128 *
17129 * > stringLiteral ::=
17130 * > [SimpleStringLiteral]
17131 * > | [AdjacentStrings]
17132 * > | [StringInterpolation]
17133 */
17134 abstract class StringLiteral extends Literal {
17135 /**
17136 * Return the value of the string literal, or `null` if the string is not a
17137 * constant string without any string interpolation.
17138 */
17139 String get stringValue {
17140 StringBuffer buffer = new StringBuffer();
17141 try {
17142 _appendStringValue(buffer);
17143 } on IllegalArgumentException {
17144 return null;
17145 }
17146 return buffer.toString();
17147 }
17148
17149 /**
17150 * Append the value of this string literal to the given [buffer]. Throw an
17151 * [IllegalArgumentException] if the string is not a constant string without
17152 * any string interpolation.
17153 */
17154 void _appendStringValue(StringBuffer buffer);
17155 }
17156
17157 /**
17158 * The invocation of a superclass' constructor from within a constructor's
17159 * initialization list.
17160 *
17161 * > superInvocation ::=
17162 * > 'super' ('.' [SimpleIdentifier])? [ArgumentList]
17163 */
17164 class SuperConstructorInvocation extends ConstructorInitializer {
17165 /**
17166 * The token for the 'super' keyword.
17167 */
17168 Token superKeyword;
17169
17170 /**
17171 * The token for the period before the name of the constructor that is being
17172 * invoked, or `null` if the unnamed constructor is being invoked. 9532 * invoked, or `null` if the unnamed constructor is being invoked.
17173 */ 9533 */
17174 Token period; 9534 Token period;
17175 9535
17176 /** 9536 /**
17177 * The name of the constructor that is being invoked, or `null` if the unnamed 9537 * The name of the constructor that is being invoked, or `null` if the unnamed
17178 * constructor is being invoked. 9538 * constructor is being invoked.
17179 */ 9539 */
17180 SimpleIdentifier _constructorName; 9540 SimpleIdentifier _constructorName;
17181 9541
17182 /** 9542 /**
17183 * The list of arguments to the constructor. 9543 * The list of arguments to the constructor.
17184 */ 9544 */
17185 ArgumentList _argumentList; 9545 ArgumentList _argumentList;
17186 9546
17187 /** 9547 /**
17188 * The element associated with the constructor based on static type 9548 * The element associated with the constructor based on static type
17189 * information, or `null` if the AST structure has not been resolved or if the 9549 * information, or `null` if the AST structure has not been resolved or if the
17190 * constructor could not be resolved. 9550 * constructor could not be resolved.
17191 */ 9551 */
17192 ConstructorElement staticElement; 9552 ConstructorElement staticElement;
17193 9553
17194 /** 9554 /**
17195 * Initialize a newly created super invocation to invoke the inherited 9555 * Initialize a newly created redirecting invocation to invoke the constructor
17196 * constructor with the given name with the given arguments. The [period] and 9556 * with the given name with the given arguments. The [constructorName] can be
17197 * [constructorName] can be `null` if the constructor being invoked is the 9557 * `null` if the constructor being invoked is the unnamed constructor.
17198 * unnamed constructor.
17199 */ 9558 */
17200 SuperConstructorInvocation(this.superKeyword, this.period, 9559 RedirectingConstructorInvocation(this.thisKeyword, this.period,
17201 SimpleIdentifier constructorName, ArgumentList argumentList) { 9560 SimpleIdentifier constructorName, ArgumentList argumentList) {
17202 _constructorName = _becomeParentOf(constructorName); 9561 _constructorName = _becomeParentOf(constructorName);
17203 _argumentList = _becomeParentOf(argumentList); 9562 _argumentList = _becomeParentOf(argumentList);
17204 } 9563 }
17205 9564
17206 /** 9565 /**
17207 * Return the list of arguments to the constructor. 9566 * Return the list of arguments to the constructor.
17208 */ 9567 */
17209 ArgumentList get argumentList => _argumentList; 9568 ArgumentList get argumentList => _argumentList;
17210 9569
17211 /** 9570 /**
17212 * Set the list of arguments to the constructor to the given [argumentList]. 9571 * Set the list of arguments to the constructor to the given [argumentList].
17213 */ 9572 */
17214 void set argumentList(ArgumentList argumentList) { 9573 void set argumentList(ArgumentList argumentList) {
17215 _argumentList = _becomeParentOf(argumentList); 9574 _argumentList = _becomeParentOf(argumentList);
17216 } 9575 }
17217 9576
17218 @override 9577 @override
17219 Token get beginToken => superKeyword; 9578 Token get beginToken => thisKeyword;
17220 9579
17221 @override 9580 @override
17222 Iterable get childEntities => new ChildEntities() 9581 Iterable get childEntities => new ChildEntities()
17223 ..add(superKeyword) 9582 ..add(thisKeyword)
17224 ..add(period) 9583 ..add(period)
17225 ..add(_constructorName) 9584 ..add(_constructorName)
17226 ..add(_argumentList); 9585 ..add(_argumentList);
17227 9586
17228 /** 9587 /**
17229 * Return the name of the constructor that is being invoked, or `null` if the 9588 * Return the name of the constructor that is being invoked, or `null` if the
17230 * unnamed constructor is being invoked. 9589 * unnamed constructor is being invoked.
17231 */ 9590 */
17232 SimpleIdentifier get constructorName => _constructorName; 9591 SimpleIdentifier get constructorName => _constructorName;
17233 9592
17234 /** 9593 /**
17235 * Set the name of the constructor that is being invoked to the given 9594 * Set the name of the constructor that is being invoked to the given
17236 * [identifier]. 9595 * [identifier].
17237 */ 9596 */
17238 void set constructorName(SimpleIdentifier identifier) { 9597 void set constructorName(SimpleIdentifier identifier) {
17239 _constructorName = _becomeParentOf(identifier); 9598 _constructorName = _becomeParentOf(identifier);
17240 } 9599 }
17241 9600
17242 @override 9601 @override
17243 Token get endToken => _argumentList.endToken; 9602 Token get endToken => _argumentList.endToken;
17244 9603
17245 @override 9604 @override
17246 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this); 9605 accept(AstVisitor visitor) =>
9606 visitor.visitRedirectingConstructorInvocation(this);
17247 9607
17248 @override 9608 @override
17249 void visitChildren(AstVisitor visitor) { 9609 void visitChildren(AstVisitor visitor) {
17250 _safelyVisitChild(_constructorName, visitor); 9610 _safelyVisitChild(_constructorName, visitor);
17251 _safelyVisitChild(_argumentList, visitor); 9611 _safelyVisitChild(_argumentList, visitor);
17252 } 9612 }
17253 } 9613 }
17254 9614
17255 /** 9615 /**
9616 * A rethrow expression.
9617 *
9618 * > rethrowExpression ::=
9619 * > 'rethrow'
9620 */
9621 class RethrowExpression extends Expression {
9622 /**
9623 * The token representing the 'rethrow' keyword.
9624 */
9625 Token rethrowKeyword;
9626
9627 /**
9628 * Initialize a newly created rethrow expression.
9629 */
9630 RethrowExpression(this.rethrowKeyword);
9631
9632 @override
9633 Token get beginToken => rethrowKeyword;
9634
9635 @override
9636 Iterable get childEntities => new ChildEntities()..add(rethrowKeyword);
9637
9638 @override
9639 Token get endToken => rethrowKeyword;
9640
9641 @override
9642 int get precedence => 0;
9643
9644 @override
9645 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this);
9646
9647 @override
9648 void visitChildren(AstVisitor visitor) {
9649 // There are no children to visit.
9650 }
9651 }
9652
9653 /**
9654 * A return statement.
9655 *
9656 * > returnStatement ::=
9657 * > 'return' [Expression]? ';'
9658 */
9659 class ReturnStatement extends Statement {
9660 /**
9661 * The token representing the 'return' keyword.
9662 */
9663 Token returnKeyword;
9664
9665 /**
9666 * The expression computing the value to be returned, or `null` if no explicit
9667 * value was provided.
9668 */
9669 Expression _expression;
9670
9671 /**
9672 * The semicolon terminating the statement.
9673 */
9674 Token semicolon;
9675
9676 /**
9677 * Initialize a newly created return statement. The [expression] can be `null`
9678 * if no explicit value was provided.
9679 */
9680 ReturnStatement(this.returnKeyword, Expression expression, this.semicolon) {
9681 _expression = _becomeParentOf(expression);
9682 }
9683
9684 @override
9685 Token get beginToken => returnKeyword;
9686
9687 @override
9688 Iterable get childEntities =>
9689 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon);
9690
9691 @override
9692 Token get endToken => semicolon;
9693
9694 /**
9695 * Return the expression computing the value to be returned, or `null` if no
9696 * explicit value was provided.
9697 */
9698 Expression get expression => _expression;
9699
9700 /**
9701 * Set the expression computing the value to be returned to the given
9702 * [expression].
9703 */
9704 void set expression(Expression expression) {
9705 _expression = _becomeParentOf(expression);
9706 }
9707
9708 @override
9709 accept(AstVisitor visitor) => visitor.visitReturnStatement(this);
9710
9711 @override
9712 void visitChildren(AstVisitor visitor) {
9713 _safelyVisitChild(_expression, visitor);
9714 }
9715 }
9716
9717 /**
9718 * A script tag that can optionally occur at the beginning of a compilation unit .
9719 *
9720 * > scriptTag ::=
9721 * > '#!' (~NEWLINE)* NEWLINE
9722 */
9723 class ScriptTag extends AstNode {
9724 /**
9725 * The token representing this script tag.
9726 */
9727 Token scriptTag;
9728
9729 /**
9730 * Initialize a newly created script tag.
9731 */
9732 ScriptTag(this.scriptTag);
9733
9734 @override
9735 Token get beginToken => scriptTag;
9736
9737 @override
9738 Iterable get childEntities => new ChildEntities()..add(scriptTag);
9739
9740 @override
9741 Token get endToken => scriptTag;
9742
9743 @override
9744 accept(AstVisitor visitor) => visitor.visitScriptTag(this);
9745
9746 @override
9747 void visitChildren(AstVisitor visitor) {
9748 // There are no children to visit.
9749 }
9750 }
9751
9752 /**
9753 * A combinator that restricts the names being imported to those in a given list .
9754 *
9755 * > showCombinator ::=
9756 * > 'show' [SimpleIdentifier] (',' [SimpleIdentifier])*
9757 */
9758 class ShowCombinator extends Combinator {
9759 /**
9760 * The list of names from the library that are made visible by this combinator .
9761 */
9762 NodeList<SimpleIdentifier> _shownNames;
9763
9764 /**
9765 * Initialize a newly created import show combinator.
9766 */
9767 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames)
9768 : super(keyword) {
9769 _shownNames = new NodeList<SimpleIdentifier>(this, shownNames);
9770 }
9771
9772 @override
9773 // TODO(paulberry): add commas.
9774 Iterable get childEntities => new ChildEntities()
9775 ..add(keyword)
9776 ..addAll(_shownNames);
9777
9778 @override
9779 Token get endToken => _shownNames.endToken;
9780
9781 /**
9782 * Return the list of names from the library that are made visible by this
9783 * combinator.
9784 */
9785 NodeList<SimpleIdentifier> get shownNames => _shownNames;
9786
9787 @override
9788 accept(AstVisitor visitor) => visitor.visitShowCombinator(this);
9789
9790 @override
9791 void visitChildren(AstVisitor visitor) {
9792 _shownNames.accept(visitor);
9793 }
9794 }
9795
9796 /**
9797 * A simple formal parameter.
9798 *
9799 * > simpleFormalParameter ::=
9800 * > ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier]
9801 */
9802 class SimpleFormalParameter extends NormalFormalParameter {
9803 /**
9804 * The token representing either the 'final', 'const' or 'var' keyword, or
9805 * `null` if no keyword was used.
9806 */
9807 Token keyword;
9808
9809 /**
9810 * The name of the declared type of the parameter, or `null` if the parameter
9811 * does not have a declared type.
9812 */
9813 TypeName _type;
9814
9815 /**
9816 * Initialize a newly created formal parameter. Either or both of the
9817 * [comment] and [metadata] can be `null` if the parameter does not have the
9818 * corresponding attribute. The [keyword] can be `null` if a type was
9819 * specified. The [type] must be `null` if the keyword is 'var'.
9820 */
9821 SimpleFormalParameter(Comment comment, List<Annotation> metadata,
9822 this.keyword, TypeName type, SimpleIdentifier identifier)
9823 : super(comment, metadata, identifier) {
9824 _type = _becomeParentOf(type);
9825 }
9826
9827 @override
9828 Token get beginToken {
9829 NodeList<Annotation> metadata = this.metadata;
9830 if (!metadata.isEmpty) {
9831 return metadata.beginToken;
9832 } else if (keyword != null) {
9833 return keyword;
9834 } else if (_type != null) {
9835 return _type.beginToken;
9836 }
9837 return identifier.beginToken;
9838 }
9839
9840 @override
9841 Iterable get childEntities =>
9842 super._childEntities..add(keyword)..add(_type)..add(identifier);
9843
9844 @override
9845 Token get endToken => identifier.endToken;
9846
9847 @override
9848 bool get isConst =>
9849 (keyword is KeywordToken) &&
9850 (keyword as KeywordToken).keyword == Keyword.CONST;
9851
9852 @override
9853 bool get isFinal =>
9854 (keyword is KeywordToken) &&
9855 (keyword as KeywordToken).keyword == Keyword.FINAL;
9856
9857 /**
9858 * Return the name of the declared type of the parameter, or `null` if the
9859 * parameter does not have a declared type.
9860 */
9861 TypeName get type => _type;
9862
9863 /**
9864 * Set the name of the declared type of the parameter to the given [typeName].
9865 */
9866 void set type(TypeName typeName) {
9867 _type = _becomeParentOf(typeName);
9868 }
9869
9870 @override
9871 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this);
9872
9873 @override
9874 void visitChildren(AstVisitor visitor) {
9875 super.visitChildren(visitor);
9876 _safelyVisitChild(_type, visitor);
9877 _safelyVisitChild(identifier, visitor);
9878 }
9879 }
9880
9881 /**
9882 * A simple identifier.
9883 *
9884 * > simpleIdentifier ::=
9885 * > initialCharacter internalCharacter*
9886 * >
9887 * > initialCharacter ::= '_' | '$' | letter
9888 * >
9889 * > internalCharacter ::= '_' | '$' | letter | digit
9890 */
9891 class SimpleIdentifier extends Identifier {
9892 /**
9893 * The token representing the identifier.
9894 */
9895 Token token;
9896
9897 /**
9898 * The element associated with this identifier based on static type
9899 * information, or `null` if the AST structure has not been resolved or if
9900 * this identifier could not be resolved.
9901 */
9902 Element _staticElement;
9903
9904 /**
9905 * The element associated with this identifier based on propagated type
9906 * information, or `null` if the AST structure has not been resolved or if
9907 * this identifier could not be resolved.
9908 */
9909 Element _propagatedElement;
9910
9911 /**
9912 * If this expression is both in a getter and setter context, the
9913 * [AuxiliaryElements] will be set to hold onto the static and propagated
9914 * information. The auxiliary element will hold onto the elements from the
9915 * getter context.
9916 */
9917 AuxiliaryElements auxiliaryElements = null;
9918
9919 /**
9920 * Initialize a newly created identifier.
9921 */
9922 SimpleIdentifier(this.token);
9923
9924 @override
9925 Token get beginToken => token;
9926
9927 @override
9928 Element get bestElement {
9929 if (_propagatedElement == null) {
9930 return _staticElement;
9931 }
9932 return _propagatedElement;
9933 }
9934
9935 @override
9936 Iterable get childEntities => new ChildEntities()..add(token);
9937
9938 @override
9939 Token get endToken => token;
9940
9941 /**
9942 * Return `true` if this identifier is the "name" part of a prefixed
9943 * identifier or a method invocation.
9944 */
9945 bool get isQualified {
9946 AstNode parent = this.parent;
9947 if (parent is PrefixedIdentifier) {
9948 return identical(parent.identifier, this);
9949 }
9950 if (parent is PropertyAccess) {
9951 return identical(parent.propertyName, this);
9952 }
9953 if (parent is MethodInvocation) {
9954 MethodInvocation invocation = parent;
9955 return identical(invocation.methodName, this) &&
9956 invocation.realTarget != null;
9957 }
9958 return false;
9959 }
9960
9961 @override
9962 bool get isSynthetic => token.isSynthetic;
9963
9964 @override
9965 String get name => token.lexeme;
9966
9967 @override
9968 int get precedence => 16;
9969
9970 @override
9971 Element get propagatedElement => _propagatedElement;
9972
9973 /**
9974 * Set the element associated with this identifier based on propagated type
9975 * information to the given [element].
9976 */
9977 void set propagatedElement(Element element) {
9978 _propagatedElement = _validateElement(element);
9979 }
9980
9981 @override
9982 Element get staticElement => _staticElement;
9983
9984 /**
9985 * Set the element associated with this identifier based on static type
9986 * information to the given [element].
9987 */
9988 void set staticElement(Element element) {
9989 _staticElement = _validateElement(element);
9990 }
9991
9992 @override
9993 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this);
9994
9995 /**
9996 * Return `true` if this identifier is the name being declared in a
9997 * declaration.
9998 */
9999 bool inDeclarationContext() {
10000 // TODO(brianwilkerson) Convert this to a getter.
10001 AstNode parent = this.parent;
10002 if (parent is CatchClause) {
10003 CatchClause clause = parent;
10004 return identical(this, clause.exceptionParameter) ||
10005 identical(this, clause.stackTraceParameter);
10006 } else if (parent is ClassDeclaration) {
10007 return identical(this, parent.name);
10008 } else if (parent is ClassTypeAlias) {
10009 return identical(this, parent.name);
10010 } else if (parent is ConstructorDeclaration) {
10011 return identical(this, parent.name);
10012 } else if (parent is DeclaredIdentifier) {
10013 return identical(this, parent.identifier);
10014 } else if (parent is EnumDeclaration) {
10015 return identical(this, parent.name);
10016 } else if (parent is EnumConstantDeclaration) {
10017 return identical(this, parent.name);
10018 } else if (parent is FunctionDeclaration) {
10019 return identical(this, parent.name);
10020 } else if (parent is FunctionTypeAlias) {
10021 return identical(this, parent.name);
10022 } else if (parent is ImportDirective) {
10023 return identical(this, parent.prefix);
10024 } else if (parent is Label) {
10025 return identical(this, parent.label) &&
10026 (parent.parent is LabeledStatement);
10027 } else if (parent is MethodDeclaration) {
10028 return identical(this, parent.name);
10029 } else if (parent is FunctionTypedFormalParameter ||
10030 parent is SimpleFormalParameter) {
10031 return identical(this, (parent as NormalFormalParameter).identifier);
10032 } else if (parent is TypeParameter) {
10033 return identical(this, parent.name);
10034 } else if (parent is VariableDeclaration) {
10035 return identical(this, parent.name);
10036 }
10037 return false;
10038 }
10039
10040 /**
10041 * Return `true` if this expression is computing a right-hand value.
10042 *
10043 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10044 * are they mutually exclusive. In other words, it is possible for both
10045 * methods to return `true` when invoked on the same node.
10046 */
10047 bool inGetterContext() {
10048 // TODO(brianwilkerson) Convert this to a getter.
10049 AstNode parent = this.parent;
10050 AstNode target = this;
10051 // skip prefix
10052 if (parent is PrefixedIdentifier) {
10053 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
10054 if (identical(prefixed.prefix, this)) {
10055 return true;
10056 }
10057 parent = prefixed.parent;
10058 target = prefixed;
10059 } else if (parent is PropertyAccess) {
10060 PropertyAccess access = parent as PropertyAccess;
10061 if (identical(access.target, this)) {
10062 return true;
10063 }
10064 parent = access.parent;
10065 target = access;
10066 }
10067 // skip label
10068 if (parent is Label) {
10069 return false;
10070 }
10071 // analyze usage
10072 if (parent is AssignmentExpression) {
10073 if (identical(parent.leftHandSide, target) &&
10074 parent.operator.type == TokenType.EQ) {
10075 return false;
10076 }
10077 }
10078 if (parent is ForEachStatement) {
10079 if (identical(parent.identifier, target)) {
10080 return false;
10081 }
10082 }
10083 return true;
10084 }
10085
10086 /**
10087 * Return `true` if this expression is computing a left-hand value.
10088 *
10089 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10090 * are they mutually exclusive. In other words, it is possible for both
10091 * methods to return `true` when invoked on the same node.
10092 */
10093 bool inSetterContext() {
10094 // TODO(brianwilkerson) Convert this to a getter.
10095 AstNode parent = this.parent;
10096 AstNode target = this;
10097 // skip prefix
10098 if (parent is PrefixedIdentifier) {
10099 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
10100 // if this is the prefix, then return false
10101 if (identical(prefixed.prefix, this)) {
10102 return false;
10103 }
10104 parent = prefixed.parent;
10105 target = prefixed;
10106 } else if (parent is PropertyAccess) {
10107 PropertyAccess access = parent as PropertyAccess;
10108 if (identical(access.target, this)) {
10109 return false;
10110 }
10111 parent = access.parent;
10112 target = access;
10113 }
10114 // analyze usage
10115 if (parent is PrefixExpression) {
10116 return parent.operator.type.isIncrementOperator;
10117 } else if (parent is PostfixExpression) {
10118 return true;
10119 } else if (parent is AssignmentExpression) {
10120 return identical(parent.leftHandSide, target);
10121 } else if (parent is ForEachStatement) {
10122 return identical(parent.identifier, target);
10123 }
10124 return false;
10125 }
10126
10127 @override
10128 void visitChildren(AstVisitor visitor) {
10129 // There are no children to visit.
10130 }
10131
10132 /**
10133 * Return the given element if it is valid, or report the problem and return
10134 * `null` if it is not appropriate.
10135 *
10136 * The [parent] is the parent of the element, used for reporting when there is
10137 * a problem.
10138 * The [isValid] is `true` if the element is appropriate.
10139 * The [element] is the element to be associated with this identifier.
10140 */
10141 Element _returnOrReportElement(
10142 AstNode parent, bool isValid, Element element) {
10143 if (!isValid) {
10144 AnalysisEngine.instance.logger.logInformation(
10145 "Internal error: attempting to set the name of a ${parent.runtimeType} to a ${element.runtimeType}",
10146 new CaughtException(new AnalysisException(), null));
10147 return null;
10148 }
10149 return element;
10150 }
10151
10152 /**
10153 * Return the given [element] if it is an appropriate element based on the
10154 * parent of this identifier, or `null` if it is not appropriate.
10155 */
10156 Element _validateElement(Element element) {
10157 if (element == null) {
10158 return null;
10159 }
10160 AstNode parent = this.parent;
10161 if (parent is ClassDeclaration && identical(parent.name, this)) {
10162 return _returnOrReportElement(parent, element is ClassElement, element);
10163 } else if (parent is ClassTypeAlias && identical(parent.name, this)) {
10164 return _returnOrReportElement(parent, element is ClassElement, element);
10165 } else if (parent is DeclaredIdentifier &&
10166 identical(parent.identifier, this)) {
10167 return _returnOrReportElement(
10168 parent, element is LocalVariableElement, element);
10169 } else if (parent is FormalParameter &&
10170 identical(parent.identifier, this)) {
10171 return _returnOrReportElement(
10172 parent, element is ParameterElement, element);
10173 } else if (parent is FunctionDeclaration && identical(parent.name, this)) {
10174 return _returnOrReportElement(
10175 parent, element is ExecutableElement, element);
10176 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) {
10177 return _returnOrReportElement(
10178 parent, element is FunctionTypeAliasElement, element);
10179 } else if (parent is MethodDeclaration && identical(parent.name, this)) {
10180 return _returnOrReportElement(
10181 parent, element is ExecutableElement, element);
10182 } else if (parent is TypeParameter && identical(parent.name, this)) {
10183 return _returnOrReportElement(
10184 parent, element is TypeParameterElement, element);
10185 } else if (parent is VariableDeclaration && identical(parent.name, this)) {
10186 return _returnOrReportElement(
10187 parent, element is VariableElement, element);
10188 }
10189 return element;
10190 }
10191 }
10192
10193 /**
10194 * A string literal expression that does not contain any interpolations.
10195 *
10196 * > simpleStringLiteral ::=
10197 * > rawStringLiteral
10198 * > | basicStringLiteral
10199 * >
10200 * > rawStringLiteral ::=
10201 * > 'r' basicStringLiteral
10202 * >
10203 * > simpleStringLiteral ::=
10204 * > multiLineStringLiteral
10205 * > | singleLineStringLiteral
10206 * >
10207 * > multiLineStringLiteral ::=
10208 * > "'''" characters "'''"
10209 * > | '"""' characters '"""'
10210 * >
10211 * > singleLineStringLiteral ::=
10212 * > "'" characters "'"
10213 * > | '"' characters '"'
10214 */
10215 class SimpleStringLiteral extends SingleStringLiteral {
10216 /**
10217 * The token representing the literal.
10218 */
10219 Token literal;
10220
10221 /**
10222 * The value of the literal.
10223 */
10224 String _value;
10225
10226 /**
10227 * Initialize a newly created simple string literal.
10228 */
10229 SimpleStringLiteral(this.literal, String value) {
10230 _value = StringUtilities.intern(value);
10231 }
10232
10233 @override
10234 Token get beginToken => literal;
10235
10236 @override
10237 Iterable get childEntities => new ChildEntities()..add(literal);
10238
10239 @override
10240 int get contentsEnd => offset + _helper.end;
10241
10242 @override
10243 int get contentsOffset => offset + _helper.start;
10244
10245 @override
10246 Token get endToken => literal;
10247
10248 @override
10249 bool get isMultiline => _helper.isMultiline;
10250
10251 @override
10252 bool get isRaw => _helper.isRaw;
10253
10254 @override
10255 bool get isSingleQuoted => _helper.isSingleQuoted;
10256
10257 @override
10258 bool get isSynthetic => literal.isSynthetic;
10259
10260 /**
10261 * Return the value of the literal.
10262 */
10263 String get value => _value;
10264
10265 /**
10266 * Set the value of the literal to the given [string].
10267 */
10268 void set value(String string) {
10269 _value = StringUtilities.intern(_value);
10270 }
10271
10272 StringLexemeHelper get _helper {
10273 return new StringLexemeHelper(literal.lexeme, true, true);
10274 }
10275
10276 @override
10277 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this);
10278
10279 @override
10280 void visitChildren(AstVisitor visitor) {
10281 // There are no children to visit.
10282 }
10283
10284 @override
10285 void _appendStringValue(StringBuffer buffer) {
10286 buffer.write(value);
10287 }
10288 }
10289
10290 /**
10291 * A single string literal expression.
10292 *
10293 * > singleStringLiteral ::=
10294 * > [SimpleStringLiteral]
10295 * > | [StringInterpolation]
10296 */
10297 abstract class SingleStringLiteral extends StringLiteral {
10298 /**
10299 * Return the offset of the after-last contents character.
10300 */
10301 int get contentsEnd;
10302
10303 /**
10304 * Return the offset of the first contents character.
10305 * If the string is multiline, then leading whitespaces are skipped.
10306 */
10307 int get contentsOffset;
10308
10309 /**
10310 * Return `true` if this string literal is a multi-line string.
10311 */
10312 bool get isMultiline;
10313
10314 /**
10315 * Return `true` if this string literal is a raw string.
10316 */
10317 bool get isRaw;
10318
10319 /**
10320 * Return `true` if this string literal uses single quotes (' or ''').
10321 * Return `false` if this string literal uses double quotes (" or """).
10322 */
10323 bool get isSingleQuoted;
10324 }
10325
10326 /**
10327 * A node that represents a statement.
10328 *
10329 * > statement ::=
10330 * > [Block]
10331 * > | [VariableDeclarationStatement]
10332 * > | [ForStatement]
10333 * > | [ForEachStatement]
10334 * > | [WhileStatement]
10335 * > | [DoStatement]
10336 * > | [SwitchStatement]
10337 * > | [IfStatement]
10338 * > | [TryStatement]
10339 * > | [BreakStatement]
10340 * > | [ContinueStatement]
10341 * > | [ReturnStatement]
10342 * > | [ExpressionStatement]
10343 * > | [FunctionDeclarationStatement]
10344 */
10345 abstract class Statement extends AstNode {
10346 /**
10347 * If this is a labeled statement, return the unlabeled portion of the
10348 * statement. Otherwise return the statement itself.
10349 */
10350 Statement get unlabeled => this;
10351 }
10352
10353 /**
10354 * A string interpolation literal.
10355 *
10356 * > stringInterpolation ::=
10357 * > ''' [InterpolationElement]* '''
10358 * > | '"' [InterpolationElement]* '"'
10359 */
10360 class StringInterpolation extends SingleStringLiteral {
10361 /**
10362 * The elements that will be composed to produce the resulting string.
10363 */
10364 NodeList<InterpolationElement> _elements;
10365
10366 /**
10367 * Initialize a newly created string interpolation expression.
10368 */
10369 StringInterpolation(List<InterpolationElement> elements) {
10370 _elements = new NodeList<InterpolationElement>(this, elements);
10371 }
10372
10373 @override
10374 Token get beginToken => _elements.beginToken;
10375
10376 @override
10377 Iterable get childEntities => new ChildEntities()..addAll(_elements);
10378
10379 @override
10380 int get contentsEnd {
10381 InterpolationString element = _elements.last;
10382 return element.contentsEnd;
10383 }
10384
10385 @override
10386 int get contentsOffset {
10387 InterpolationString element = _elements.first;
10388 return element.contentsOffset;
10389 }
10390
10391 /**
10392 * Return the elements that will be composed to produce the resulting string.
10393 */
10394 NodeList<InterpolationElement> get elements => _elements;
10395
10396 @override
10397 Token get endToken => _elements.endToken;
10398
10399 @override
10400 bool get isMultiline => _firstHelper.isMultiline;
10401
10402 @override
10403 bool get isRaw => false;
10404
10405 @override
10406 bool get isSingleQuoted => _firstHelper.isSingleQuoted;
10407
10408 StringLexemeHelper get _firstHelper {
10409 InterpolationString lastString = _elements.first;
10410 String lexeme = lastString.contents.lexeme;
10411 return new StringLexemeHelper(lexeme, true, false);
10412 }
10413
10414 @override
10415 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this);
10416
10417 @override
10418 void visitChildren(AstVisitor visitor) {
10419 _elements.accept(visitor);
10420 }
10421
10422 @override
10423 void _appendStringValue(StringBuffer buffer) {
10424 throw new IllegalArgumentException();
10425 }
10426 }
10427
10428 /**
10429 * A helper for analyzing string lexemes.
10430 */
10431 class StringLexemeHelper {
10432 final String lexeme;
10433 final bool isFirst;
10434 final bool isLast;
10435
10436 bool isRaw = false;
10437 bool isSingleQuoted = false;
10438 bool isMultiline = false;
10439 int start = 0;
10440 int end;
10441
10442 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) {
10443 if (isFirst) {
10444 isRaw = StringUtilities.startsWithChar(lexeme, 0x72);
10445 if (isRaw) {
10446 start++;
10447 }
10448 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) {
10449 isSingleQuoted = true;
10450 isMultiline = true;
10451 start += 3;
10452 start = _trimInitialWhitespace(start);
10453 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) {
10454 isSingleQuoted = false;
10455 isMultiline = true;
10456 start += 3;
10457 start = _trimInitialWhitespace(start);
10458 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) {
10459 isSingleQuoted = true;
10460 isMultiline = false;
10461 start++;
10462 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) {
10463 isSingleQuoted = false;
10464 isMultiline = false;
10465 start++;
10466 }
10467 }
10468 end = lexeme.length;
10469 if (isLast) {
10470 if (start + 3 <= end &&
10471 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
10472 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) {
10473 end -= 3;
10474 } else if (start + 1 <= end &&
10475 (StringUtilities.endsWithChar(lexeme, 0x22) ||
10476 StringUtilities.endsWithChar(lexeme, 0x27))) {
10477 end -= 1;
10478 }
10479 }
10480 }
10481
10482 /**
10483 * Given the [lexeme] for a multi-line string whose content begins at the
10484 * given [start] index, return the index of the first character that is
10485 * included in the value of the string. According to the specification:
10486 *
10487 * If the first line of a multiline string consists solely of the whitespace
10488 * characters defined by the production WHITESPACE 20.1), possibly prefixed
10489 * by \, then that line is ignored, including the new line at its end.
10490 */
10491 int _trimInitialWhitespace(int start) {
10492 int length = lexeme.length;
10493 int index = start;
10494 while (index < length) {
10495 int currentChar = lexeme.codeUnitAt(index);
10496 if (currentChar == 0x0D) {
10497 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
10498 return index + 2;
10499 }
10500 return index + 1;
10501 } else if (currentChar == 0x0A) {
10502 return index + 1;
10503 } else if (currentChar == 0x5C) {
10504 if (index + 1 >= length) {
10505 return start;
10506 }
10507 currentChar = lexeme.codeUnitAt(index + 1);
10508 if (currentChar != 0x0D &&
10509 currentChar != 0x0A &&
10510 currentChar != 0x09 &&
10511 currentChar != 0x20) {
10512 return start;
10513 }
10514 } else if (currentChar != 0x09 && currentChar != 0x20) {
10515 return start;
10516 }
10517 index++;
10518 }
10519 return start;
10520 }
10521 }
10522
10523 /**
10524 * A string literal expression.
10525 *
10526 * > stringLiteral ::=
10527 * > [SimpleStringLiteral]
10528 * > | [AdjacentStrings]
10529 * > | [StringInterpolation]
10530 */
10531 abstract class StringLiteral extends Literal {
10532 /**
10533 * Return the value of the string literal, or `null` if the string is not a
10534 * constant string without any string interpolation.
10535 */
10536 String get stringValue {
10537 StringBuffer buffer = new StringBuffer();
10538 try {
10539 _appendStringValue(buffer);
10540 } on IllegalArgumentException {
10541 return null;
10542 }
10543 return buffer.toString();
10544 }
10545
10546 /**
10547 * Append the value of this string literal to the given [buffer]. Throw an
10548 * [IllegalArgumentException] if the string is not a constant string without
10549 * any string interpolation.
10550 */
10551 void _appendStringValue(StringBuffer buffer);
10552 }
10553
10554 /**
10555 * The invocation of a superclass' constructor from within a constructor's
10556 * initialization list.
10557 *
10558 * > superInvocation ::=
10559 * > 'super' ('.' [SimpleIdentifier])? [ArgumentList]
10560 */
10561 class SuperConstructorInvocation extends ConstructorInitializer {
10562 /**
10563 * The token for the 'super' keyword.
10564 */
10565 Token superKeyword;
10566
10567 /**
10568 * The token for the period before the name of the constructor that is being
10569 * invoked, or `null` if the unnamed constructor is being invoked.
10570 */
10571 Token period;
10572
10573 /**
10574 * The name of the constructor that is being invoked, or `null` if the unnamed
10575 * constructor is being invoked.
10576 */
10577 SimpleIdentifier _constructorName;
10578
10579 /**
10580 * The list of arguments to the constructor.
10581 */
10582 ArgumentList _argumentList;
10583
10584 /**
10585 * The element associated with the constructor based on static type
10586 * information, or `null` if the AST structure has not been resolved or if the
10587 * constructor could not be resolved.
10588 */
10589 ConstructorElement staticElement;
10590
10591 /**
10592 * Initialize a newly created super invocation to invoke the inherited
10593 * constructor with the given name with the given arguments. The [period] and
10594 * [constructorName] can be `null` if the constructor being invoked is the
10595 * unnamed constructor.
10596 */
10597 SuperConstructorInvocation(this.superKeyword, this.period,
10598 SimpleIdentifier constructorName, ArgumentList argumentList) {
10599 _constructorName = _becomeParentOf(constructorName);
10600 _argumentList = _becomeParentOf(argumentList);
10601 }
10602
10603 /**
10604 * Return the list of arguments to the constructor.
10605 */
10606 ArgumentList get argumentList => _argumentList;
10607
10608 /**
10609 * Set the list of arguments to the constructor to the given [argumentList].
10610 */
10611 void set argumentList(ArgumentList argumentList) {
10612 _argumentList = _becomeParentOf(argumentList);
10613 }
10614
10615 @override
10616 Token get beginToken => superKeyword;
10617
10618 @override
10619 Iterable get childEntities => new ChildEntities()
10620 ..add(superKeyword)
10621 ..add(period)
10622 ..add(_constructorName)
10623 ..add(_argumentList);
10624
10625 /**
10626 * Return the name of the constructor that is being invoked, or `null` if the
10627 * unnamed constructor is being invoked.
10628 */
10629 SimpleIdentifier get constructorName => _constructorName;
10630
10631 /**
10632 * Set the name of the constructor that is being invoked to the given
10633 * [identifier].
10634 */
10635 void set constructorName(SimpleIdentifier identifier) {
10636 _constructorName = _becomeParentOf(identifier);
10637 }
10638
10639 @override
10640 Token get endToken => _argumentList.endToken;
10641
10642 @override
10643 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this);
10644
10645 @override
10646 void visitChildren(AstVisitor visitor) {
10647 _safelyVisitChild(_constructorName, visitor);
10648 _safelyVisitChild(_argumentList, visitor);
10649 }
10650 }
10651
10652 /**
17256 * A super expression. 10653 * A super expression.
17257 * 10654 *
17258 * > superExpression ::= 10655 * > superExpression ::=
17259 * > 'super' 10656 * > 'super'
17260 */ 10657 */
17261 class SuperExpression extends Expression { 10658 class SuperExpression extends Expression {
17262 /** 10659 /**
17263 * The token representing the 'super' keyword. 10660 * The token representing the 'super' keyword.
17264 */ 10661 */
17265 Token superKeyword; 10662 Token superKeyword;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
17749 @override 11146 @override
17750 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this); 11147 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this);
17751 11148
17752 @override 11149 @override
17753 void visitChildren(AstVisitor visitor) { 11150 void visitChildren(AstVisitor visitor) {
17754 super.visitChildren(visitor); 11151 super.visitChildren(visitor);
17755 _safelyVisitChild(_variableList, visitor); 11152 _safelyVisitChild(_variableList, visitor);
17756 } 11153 }
17757 } 11154 }
17758 11155
17759 /**
17760 * A visitor used to write a source representation of a visited AST node (and
17761 * all of it's children) to a writer.
17762 */
17763 class ToSourceVisitor implements AstVisitor<Object> {
17764 /**
17765 * The writer to which the source is to be written.
17766 */
17767 final PrintWriter _writer;
17768
17769 /**
17770 * Initialize a newly created visitor to write source code representing the
17771 * visited nodes to the given [writer].
17772 */
17773 ToSourceVisitor(this._writer);
17774
17775 @override
17776 Object visitAdjacentStrings(AdjacentStrings node) {
17777 _visitNodeListWithSeparator(node.strings, " ");
17778 return null;
17779 }
17780
17781 @override
17782 Object visitAnnotation(Annotation node) {
17783 _writer.print('@');
17784 _visitNode(node.name);
17785 _visitNodeWithPrefix(".", node.constructorName);
17786 _visitNode(node.arguments);
17787 return null;
17788 }
17789
17790 @override
17791 Object visitArgumentList(ArgumentList node) {
17792 _writer.print('(');
17793 _visitNodeListWithSeparator(node.arguments, ", ");
17794 _writer.print(')');
17795 return null;
17796 }
17797
17798 @override
17799 Object visitAsExpression(AsExpression node) {
17800 _visitNode(node.expression);
17801 _writer.print(" as ");
17802 _visitNode(node.type);
17803 return null;
17804 }
17805
17806 @override
17807 Object visitAssertStatement(AssertStatement node) {
17808 _writer.print("assert (");
17809 _visitNode(node.condition);
17810 if (node.message != null) {
17811 _writer.print(', ');
17812 _visitNode(node.message);
17813 }
17814 _writer.print(");");
17815 return null;
17816 }
17817
17818 @override
17819 Object visitAssignmentExpression(AssignmentExpression node) {
17820 _visitNode(node.leftHandSide);
17821 _writer.print(' ');
17822 _writer.print(node.operator.lexeme);
17823 _writer.print(' ');
17824 _visitNode(node.rightHandSide);
17825 return null;
17826 }
17827
17828 @override
17829 Object visitAwaitExpression(AwaitExpression node) {
17830 _writer.print("await ");
17831 _visitNode(node.expression);
17832 return null;
17833 }
17834
17835 @override
17836 Object visitBinaryExpression(BinaryExpression node) {
17837 _visitNode(node.leftOperand);
17838 _writer.print(' ');
17839 _writer.print(node.operator.lexeme);
17840 _writer.print(' ');
17841 _visitNode(node.rightOperand);
17842 return null;
17843 }
17844
17845 @override
17846 Object visitBlock(Block node) {
17847 _writer.print('{');
17848 _visitNodeListWithSeparator(node.statements, " ");
17849 _writer.print('}');
17850 return null;
17851 }
17852
17853 @override
17854 Object visitBlockFunctionBody(BlockFunctionBody node) {
17855 Token keyword = node.keyword;
17856 if (keyword != null) {
17857 _writer.print(keyword.lexeme);
17858 if (node.star != null) {
17859 _writer.print('*');
17860 }
17861 _writer.print(' ');
17862 }
17863 _visitNode(node.block);
17864 return null;
17865 }
17866
17867 @override
17868 Object visitBooleanLiteral(BooleanLiteral node) {
17869 _writer.print(node.literal.lexeme);
17870 return null;
17871 }
17872
17873 @override
17874 Object visitBreakStatement(BreakStatement node) {
17875 _writer.print("break");
17876 _visitNodeWithPrefix(" ", node.label);
17877 _writer.print(";");
17878 return null;
17879 }
17880
17881 @override
17882 Object visitCascadeExpression(CascadeExpression node) {
17883 _visitNode(node.target);
17884 _visitNodeList(node.cascadeSections);
17885 return null;
17886 }
17887
17888 @override
17889 Object visitCatchClause(CatchClause node) {
17890 _visitNodeWithPrefix("on ", node.exceptionType);
17891 if (node.catchKeyword != null) {
17892 if (node.exceptionType != null) {
17893 _writer.print(' ');
17894 }
17895 _writer.print("catch (");
17896 _visitNode(node.exceptionParameter);
17897 _visitNodeWithPrefix(", ", node.stackTraceParameter);
17898 _writer.print(") ");
17899 } else {
17900 _writer.print(" ");
17901 }
17902 _visitNode(node.body);
17903 return null;
17904 }
17905
17906 @override
17907 Object visitClassDeclaration(ClassDeclaration node) {
17908 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17909 _visitTokenWithSuffix(node.abstractKeyword, " ");
17910 _writer.print("class ");
17911 _visitNode(node.name);
17912 _visitNode(node.typeParameters);
17913 _visitNodeWithPrefix(" ", node.extendsClause);
17914 _visitNodeWithPrefix(" ", node.withClause);
17915 _visitNodeWithPrefix(" ", node.implementsClause);
17916 _writer.print(" {");
17917 _visitNodeListWithSeparator(node.members, " ");
17918 _writer.print("}");
17919 return null;
17920 }
17921
17922 @override
17923 Object visitClassTypeAlias(ClassTypeAlias node) {
17924 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17925 if (node.abstractKeyword != null) {
17926 _writer.print("abstract ");
17927 }
17928 _writer.print("class ");
17929 _visitNode(node.name);
17930 _visitNode(node.typeParameters);
17931 _writer.print(" = ");
17932 _visitNode(node.superclass);
17933 _visitNodeWithPrefix(" ", node.withClause);
17934 _visitNodeWithPrefix(" ", node.implementsClause);
17935 _writer.print(";");
17936 return null;
17937 }
17938
17939 @override
17940 Object visitComment(Comment node) => null;
17941
17942 @override
17943 Object visitCommentReference(CommentReference node) => null;
17944
17945 @override
17946 Object visitCompilationUnit(CompilationUnit node) {
17947 ScriptTag scriptTag = node.scriptTag;
17948 NodeList<Directive> directives = node.directives;
17949 _visitNode(scriptTag);
17950 String prefix = scriptTag == null ? "" : " ";
17951 _visitNodeListWithSeparatorAndPrefix(prefix, directives, " ");
17952 prefix = scriptTag == null && directives.isEmpty ? "" : " ";
17953 _visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, " ");
17954 return null;
17955 }
17956
17957 @override
17958 Object visitConditionalExpression(ConditionalExpression node) {
17959 _visitNode(node.condition);
17960 _writer.print(" ? ");
17961 _visitNode(node.thenExpression);
17962 _writer.print(" : ");
17963 _visitNode(node.elseExpression);
17964 return null;
17965 }
17966
17967 @override
17968 Object visitConfiguration(Configuration node) {
17969 _writer.print('if (');
17970 _visitNode(node.name);
17971 _visitNodeWithPrefix(" == ", node.value);
17972 _writer.print(') ');
17973 _visitNode(node.libraryUri);
17974 return null;
17975 }
17976
17977 @override
17978 Object visitConstructorDeclaration(ConstructorDeclaration node) {
17979 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17980 _visitTokenWithSuffix(node.externalKeyword, " ");
17981 _visitTokenWithSuffix(node.constKeyword, " ");
17982 _visitTokenWithSuffix(node.factoryKeyword, " ");
17983 _visitNode(node.returnType);
17984 _visitNodeWithPrefix(".", node.name);
17985 _visitNode(node.parameters);
17986 _visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", ");
17987 _visitNodeWithPrefix(" = ", node.redirectedConstructor);
17988 _visitFunctionWithPrefix(" ", node.body);
17989 return null;
17990 }
17991
17992 @override
17993 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
17994 _visitTokenWithSuffix(node.thisKeyword, ".");
17995 _visitNode(node.fieldName);
17996 _writer.print(" = ");
17997 _visitNode(node.expression);
17998 return null;
17999 }
18000
18001 @override
18002 Object visitConstructorName(ConstructorName node) {
18003 _visitNode(node.type);
18004 _visitNodeWithPrefix(".", node.name);
18005 return null;
18006 }
18007
18008 @override
18009 Object visitContinueStatement(ContinueStatement node) {
18010 _writer.print("continue");
18011 _visitNodeWithPrefix(" ", node.label);
18012 _writer.print(";");
18013 return null;
18014 }
18015
18016 @override
18017 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
18018 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18019 _visitTokenWithSuffix(node.keyword, " ");
18020 _visitNodeWithSuffix(node.type, " ");
18021 _visitNode(node.identifier);
18022 return null;
18023 }
18024
18025 @override
18026 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
18027 _visitNode(node.parameter);
18028 if (node.separator != null) {
18029 _writer.print(" ");
18030 _writer.print(node.separator.lexeme);
18031 _visitNodeWithPrefix(" ", node.defaultValue);
18032 }
18033 return null;
18034 }
18035
18036 @override
18037 Object visitDoStatement(DoStatement node) {
18038 _writer.print("do ");
18039 _visitNode(node.body);
18040 _writer.print(" while (");
18041 _visitNode(node.condition);
18042 _writer.print(");");
18043 return null;
18044 }
18045
18046 @override
18047 Object visitDottedName(DottedName node) {
18048 _visitNodeListWithSeparator(node.components, ".");
18049 return null;
18050 }
18051
18052 @override
18053 Object visitDoubleLiteral(DoubleLiteral node) {
18054 _writer.print(node.literal.lexeme);
18055 return null;
18056 }
18057
18058 @override
18059 Object visitEmptyFunctionBody(EmptyFunctionBody node) {
18060 _writer.print(';');
18061 return null;
18062 }
18063
18064 @override
18065 Object visitEmptyStatement(EmptyStatement node) {
18066 _writer.print(';');
18067 return null;
18068 }
18069
18070 @override
18071 Object visitEnumConstantDeclaration(EnumConstantDeclaration node) {
18072 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18073 _visitNode(node.name);
18074 return null;
18075 }
18076
18077 @override
18078 Object visitEnumDeclaration(EnumDeclaration node) {
18079 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18080 _writer.print("enum ");
18081 _visitNode(node.name);
18082 _writer.print(" {");
18083 _visitNodeListWithSeparator(node.constants, ", ");
18084 _writer.print("}");
18085 return null;
18086 }
18087
18088 @override
18089 Object visitExportDirective(ExportDirective node) {
18090 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18091 _writer.print("export ");
18092 _visitNode(node.uri);
18093 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
18094 _writer.print(';');
18095 return null;
18096 }
18097
18098 @override
18099 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
18100 Token keyword = node.keyword;
18101 if (keyword != null) {
18102 _writer.print(keyword.lexeme);
18103 _writer.print(' ');
18104 }
18105 _writer.print("=> ");
18106 _visitNode(node.expression);
18107 if (node.semicolon != null) {
18108 _writer.print(';');
18109 }
18110 return null;
18111 }
18112
18113 @override
18114 Object visitExpressionStatement(ExpressionStatement node) {
18115 _visitNode(node.expression);
18116 _writer.print(';');
18117 return null;
18118 }
18119
18120 @override
18121 Object visitExtendsClause(ExtendsClause node) {
18122 _writer.print("extends ");
18123 _visitNode(node.superclass);
18124 return null;
18125 }
18126
18127 @override
18128 Object visitFieldDeclaration(FieldDeclaration node) {
18129 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18130 _visitTokenWithSuffix(node.staticKeyword, " ");
18131 _visitNode(node.fields);
18132 _writer.print(";");
18133 return null;
18134 }
18135
18136 @override
18137 Object visitFieldFormalParameter(FieldFormalParameter node) {
18138 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18139 _visitTokenWithSuffix(node.keyword, " ");
18140 _visitNodeWithSuffix(node.type, " ");
18141 _writer.print("this.");
18142 _visitNode(node.identifier);
18143 _visitNode(node.typeParameters);
18144 _visitNode(node.parameters);
18145 return null;
18146 }
18147
18148 @override
18149 Object visitForEachStatement(ForEachStatement node) {
18150 DeclaredIdentifier loopVariable = node.loopVariable;
18151 if (node.awaitKeyword != null) {
18152 _writer.print("await ");
18153 }
18154 _writer.print("for (");
18155 if (loopVariable == null) {
18156 _visitNode(node.identifier);
18157 } else {
18158 _visitNode(loopVariable);
18159 }
18160 _writer.print(" in ");
18161 _visitNode(node.iterable);
18162 _writer.print(") ");
18163 _visitNode(node.body);
18164 return null;
18165 }
18166
18167 @override
18168 Object visitFormalParameterList(FormalParameterList node) {
18169 String groupEnd = null;
18170 _writer.print('(');
18171 NodeList<FormalParameter> parameters = node.parameters;
18172 int size = parameters.length;
18173 for (int i = 0; i < size; i++) {
18174 FormalParameter parameter = parameters[i];
18175 if (i > 0) {
18176 _writer.print(", ");
18177 }
18178 if (groupEnd == null && parameter is DefaultFormalParameter) {
18179 if (parameter.kind == ParameterKind.NAMED) {
18180 groupEnd = "}";
18181 _writer.print('{');
18182 } else {
18183 groupEnd = "]";
18184 _writer.print('[');
18185 }
18186 }
18187 parameter.accept(this);
18188 }
18189 if (groupEnd != null) {
18190 _writer.print(groupEnd);
18191 }
18192 _writer.print(')');
18193 return null;
18194 }
18195
18196 @override
18197 Object visitForStatement(ForStatement node) {
18198 Expression initialization = node.initialization;
18199 _writer.print("for (");
18200 if (initialization != null) {
18201 _visitNode(initialization);
18202 } else {
18203 _visitNode(node.variables);
18204 }
18205 _writer.print(";");
18206 _visitNodeWithPrefix(" ", node.condition);
18207 _writer.print(";");
18208 _visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", ");
18209 _writer.print(") ");
18210 _visitNode(node.body);
18211 return null;
18212 }
18213
18214 @override
18215 Object visitFunctionDeclaration(FunctionDeclaration node) {
18216 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18217 _visitTokenWithSuffix(node.externalKeyword, " ");
18218 _visitNodeWithSuffix(node.returnType, " ");
18219 _visitTokenWithSuffix(node.propertyKeyword, " ");
18220 _visitNode(node.name);
18221 _visitNode(node.functionExpression);
18222 return null;
18223 }
18224
18225 @override
18226 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
18227 _visitNode(node.functionDeclaration);
18228 return null;
18229 }
18230
18231 @override
18232 Object visitFunctionExpression(FunctionExpression node) {
18233 _visitNode(node.typeParameters);
18234 _visitNode(node.parameters);
18235 if (node.body is! EmptyFunctionBody) {
18236 _writer.print(' ');
18237 }
18238 _visitNode(node.body);
18239 return null;
18240 }
18241
18242 @override
18243 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
18244 _visitNode(node.function);
18245 _visitNode(node.typeArguments);
18246 _visitNode(node.argumentList);
18247 return null;
18248 }
18249
18250 @override
18251 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
18252 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18253 _writer.print("typedef ");
18254 _visitNodeWithSuffix(node.returnType, " ");
18255 _visitNode(node.name);
18256 _visitNode(node.typeParameters);
18257 _visitNode(node.parameters);
18258 _writer.print(";");
18259 return null;
18260 }
18261
18262 @override
18263 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
18264 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18265 _visitNodeWithSuffix(node.returnType, " ");
18266 _visitNode(node.identifier);
18267 _visitNode(node.typeParameters);
18268 _visitNode(node.parameters);
18269 return null;
18270 }
18271
18272 @override
18273 Object visitHideCombinator(HideCombinator node) {
18274 _writer.print("hide ");
18275 _visitNodeListWithSeparator(node.hiddenNames, ", ");
18276 return null;
18277 }
18278
18279 @override
18280 Object visitIfStatement(IfStatement node) {
18281 _writer.print("if (");
18282 _visitNode(node.condition);
18283 _writer.print(") ");
18284 _visitNode(node.thenStatement);
18285 _visitNodeWithPrefix(" else ", node.elseStatement);
18286 return null;
18287 }
18288
18289 @override
18290 Object visitImplementsClause(ImplementsClause node) {
18291 _writer.print("implements ");
18292 _visitNodeListWithSeparator(node.interfaces, ", ");
18293 return null;
18294 }
18295
18296 @override
18297 Object visitImportDirective(ImportDirective node) {
18298 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18299 _writer.print("import ");
18300 _visitNode(node.uri);
18301 if (node.deferredKeyword != null) {
18302 _writer.print(" deferred");
18303 }
18304 _visitNodeWithPrefix(" as ", node.prefix);
18305 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
18306 _writer.print(';');
18307 return null;
18308 }
18309
18310 @override
18311 Object visitIndexExpression(IndexExpression node) {
18312 if (node.isCascaded) {
18313 _writer.print("..");
18314 } else {
18315 _visitNode(node.target);
18316 }
18317 _writer.print('[');
18318 _visitNode(node.index);
18319 _writer.print(']');
18320 return null;
18321 }
18322
18323 @override
18324 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
18325 _visitTokenWithSuffix(node.keyword, " ");
18326 _visitNode(node.constructorName);
18327 _visitNode(node.argumentList);
18328 return null;
18329 }
18330
18331 @override
18332 Object visitIntegerLiteral(IntegerLiteral node) {
18333 _writer.print(node.literal.lexeme);
18334 return null;
18335 }
18336
18337 @override
18338 Object visitInterpolationExpression(InterpolationExpression node) {
18339 if (node.rightBracket != null) {
18340 _writer.print("\${");
18341 _visitNode(node.expression);
18342 _writer.print("}");
18343 } else {
18344 _writer.print("\$");
18345 _visitNode(node.expression);
18346 }
18347 return null;
18348 }
18349
18350 @override
18351 Object visitInterpolationString(InterpolationString node) {
18352 _writer.print(node.contents.lexeme);
18353 return null;
18354 }
18355
18356 @override
18357 Object visitIsExpression(IsExpression node) {
18358 _visitNode(node.expression);
18359 if (node.notOperator == null) {
18360 _writer.print(" is ");
18361 } else {
18362 _writer.print(" is! ");
18363 }
18364 _visitNode(node.type);
18365 return null;
18366 }
18367
18368 @override
18369 Object visitLabel(Label node) {
18370 _visitNode(node.label);
18371 _writer.print(":");
18372 return null;
18373 }
18374
18375 @override
18376 Object visitLabeledStatement(LabeledStatement node) {
18377 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18378 _visitNode(node.statement);
18379 return null;
18380 }
18381
18382 @override
18383 Object visitLibraryDirective(LibraryDirective node) {
18384 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18385 _writer.print("library ");
18386 _visitNode(node.name);
18387 _writer.print(';');
18388 return null;
18389 }
18390
18391 @override
18392 Object visitLibraryIdentifier(LibraryIdentifier node) {
18393 _writer.print(node.name);
18394 return null;
18395 }
18396
18397 @override
18398 Object visitListLiteral(ListLiteral node) {
18399 if (node.constKeyword != null) {
18400 _writer.print(node.constKeyword.lexeme);
18401 _writer.print(' ');
18402 }
18403 _visitNodeWithSuffix(node.typeArguments, " ");
18404 _writer.print("[");
18405 _visitNodeListWithSeparator(node.elements, ", ");
18406 _writer.print("]");
18407 return null;
18408 }
18409
18410 @override
18411 Object visitMapLiteral(MapLiteral node) {
18412 if (node.constKeyword != null) {
18413 _writer.print(node.constKeyword.lexeme);
18414 _writer.print(' ');
18415 }
18416 _visitNodeWithSuffix(node.typeArguments, " ");
18417 _writer.print("{");
18418 _visitNodeListWithSeparator(node.entries, ", ");
18419 _writer.print("}");
18420 return null;
18421 }
18422
18423 @override
18424 Object visitMapLiteralEntry(MapLiteralEntry node) {
18425 _visitNode(node.key);
18426 _writer.print(" : ");
18427 _visitNode(node.value);
18428 return null;
18429 }
18430
18431 @override
18432 Object visitMethodDeclaration(MethodDeclaration node) {
18433 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18434 _visitTokenWithSuffix(node.externalKeyword, " ");
18435 _visitTokenWithSuffix(node.modifierKeyword, " ");
18436 _visitNodeWithSuffix(node.returnType, " ");
18437 _visitTokenWithSuffix(node.propertyKeyword, " ");
18438 _visitTokenWithSuffix(node.operatorKeyword, " ");
18439 _visitNode(node.name);
18440 if (!node.isGetter) {
18441 _visitNode(node.typeParameters);
18442 _visitNode(node.parameters);
18443 }
18444 _visitFunctionWithPrefix(" ", node.body);
18445 return null;
18446 }
18447
18448 @override
18449 Object visitMethodInvocation(MethodInvocation node) {
18450 if (node.isCascaded) {
18451 _writer.print("..");
18452 } else {
18453 if (node.target != null) {
18454 node.target.accept(this);
18455 _writer.print(node.operator.lexeme);
18456 }
18457 }
18458 _visitNode(node.methodName);
18459 _visitNode(node.typeArguments);
18460 _visitNode(node.argumentList);
18461 return null;
18462 }
18463
18464 @override
18465 Object visitNamedExpression(NamedExpression node) {
18466 _visitNode(node.name);
18467 _visitNodeWithPrefix(" ", node.expression);
18468 return null;
18469 }
18470
18471 @override
18472 Object visitNativeClause(NativeClause node) {
18473 _writer.print("native ");
18474 _visitNode(node.name);
18475 return null;
18476 }
18477
18478 @override
18479 Object visitNativeFunctionBody(NativeFunctionBody node) {
18480 _writer.print("native ");
18481 _visitNode(node.stringLiteral);
18482 _writer.print(';');
18483 return null;
18484 }
18485
18486 @override
18487 Object visitNullLiteral(NullLiteral node) {
18488 _writer.print("null");
18489 return null;
18490 }
18491
18492 @override
18493 Object visitParenthesizedExpression(ParenthesizedExpression node) {
18494 _writer.print('(');
18495 _visitNode(node.expression);
18496 _writer.print(')');
18497 return null;
18498 }
18499
18500 @override
18501 Object visitPartDirective(PartDirective node) {
18502 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18503 _writer.print("part ");
18504 _visitNode(node.uri);
18505 _writer.print(';');
18506 return null;
18507 }
18508
18509 @override
18510 Object visitPartOfDirective(PartOfDirective node) {
18511 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18512 _writer.print("part of ");
18513 _visitNode(node.libraryName);
18514 _writer.print(';');
18515 return null;
18516 }
18517
18518 @override
18519 Object visitPostfixExpression(PostfixExpression node) {
18520 _visitNode(node.operand);
18521 _writer.print(node.operator.lexeme);
18522 return null;
18523 }
18524
18525 @override
18526 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
18527 _visitNode(node.prefix);
18528 _writer.print('.');
18529 _visitNode(node.identifier);
18530 return null;
18531 }
18532
18533 @override
18534 Object visitPrefixExpression(PrefixExpression node) {
18535 _writer.print(node.operator.lexeme);
18536 _visitNode(node.operand);
18537 return null;
18538 }
18539
18540 @override
18541 Object visitPropertyAccess(PropertyAccess node) {
18542 if (node.isCascaded) {
18543 _writer.print("..");
18544 } else {
18545 _visitNode(node.target);
18546 _writer.print(node.operator.lexeme);
18547 }
18548 _visitNode(node.propertyName);
18549 return null;
18550 }
18551
18552 @override
18553 Object visitRedirectingConstructorInvocation(
18554 RedirectingConstructorInvocation node) {
18555 _writer.print("this");
18556 _visitNodeWithPrefix(".", node.constructorName);
18557 _visitNode(node.argumentList);
18558 return null;
18559 }
18560
18561 @override
18562 Object visitRethrowExpression(RethrowExpression node) {
18563 _writer.print("rethrow");
18564 return null;
18565 }
18566
18567 @override
18568 Object visitReturnStatement(ReturnStatement node) {
18569 Expression expression = node.expression;
18570 if (expression == null) {
18571 _writer.print("return;");
18572 } else {
18573 _writer.print("return ");
18574 expression.accept(this);
18575 _writer.print(";");
18576 }
18577 return null;
18578 }
18579
18580 @override
18581 Object visitScriptTag(ScriptTag node) {
18582 _writer.print(node.scriptTag.lexeme);
18583 return null;
18584 }
18585
18586 @override
18587 Object visitShowCombinator(ShowCombinator node) {
18588 _writer.print("show ");
18589 _visitNodeListWithSeparator(node.shownNames, ", ");
18590 return null;
18591 }
18592
18593 @override
18594 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
18595 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18596 _visitTokenWithSuffix(node.keyword, " ");
18597 _visitNodeWithSuffix(node.type, " ");
18598 _visitNode(node.identifier);
18599 return null;
18600 }
18601
18602 @override
18603 Object visitSimpleIdentifier(SimpleIdentifier node) {
18604 _writer.print(node.token.lexeme);
18605 return null;
18606 }
18607
18608 @override
18609 Object visitSimpleStringLiteral(SimpleStringLiteral node) {
18610 _writer.print(node.literal.lexeme);
18611 return null;
18612 }
18613
18614 @override
18615 Object visitStringInterpolation(StringInterpolation node) {
18616 _visitNodeList(node.elements);
18617 return null;
18618 }
18619
18620 @override
18621 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
18622 _writer.print("super");
18623 _visitNodeWithPrefix(".", node.constructorName);
18624 _visitNode(node.argumentList);
18625 return null;
18626 }
18627
18628 @override
18629 Object visitSuperExpression(SuperExpression node) {
18630 _writer.print("super");
18631 return null;
18632 }
18633
18634 @override
18635 Object visitSwitchCase(SwitchCase node) {
18636 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18637 _writer.print("case ");
18638 _visitNode(node.expression);
18639 _writer.print(": ");
18640 _visitNodeListWithSeparator(node.statements, " ");
18641 return null;
18642 }
18643
18644 @override
18645 Object visitSwitchDefault(SwitchDefault node) {
18646 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18647 _writer.print("default: ");
18648 _visitNodeListWithSeparator(node.statements, " ");
18649 return null;
18650 }
18651
18652 @override
18653 Object visitSwitchStatement(SwitchStatement node) {
18654 _writer.print("switch (");
18655 _visitNode(node.expression);
18656 _writer.print(") {");
18657 _visitNodeListWithSeparator(node.members, " ");
18658 _writer.print("}");
18659 return null;
18660 }
18661
18662 @override
18663 Object visitSymbolLiteral(SymbolLiteral node) {
18664 _writer.print("#");
18665 List<Token> components = node.components;
18666 for (int i = 0; i < components.length; i++) {
18667 if (i > 0) {
18668 _writer.print(".");
18669 }
18670 _writer.print(components[i].lexeme);
18671 }
18672 return null;
18673 }
18674
18675 @override
18676 Object visitThisExpression(ThisExpression node) {
18677 _writer.print("this");
18678 return null;
18679 }
18680
18681 @override
18682 Object visitThrowExpression(ThrowExpression node) {
18683 _writer.print("throw ");
18684 _visitNode(node.expression);
18685 return null;
18686 }
18687
18688 @override
18689 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
18690 _visitNodeWithSuffix(node.variables, ";");
18691 return null;
18692 }
18693
18694 @override
18695 Object visitTryStatement(TryStatement node) {
18696 _writer.print("try ");
18697 _visitNode(node.body);
18698 _visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " ");
18699 _visitNodeWithPrefix(" finally ", node.finallyBlock);
18700 return null;
18701 }
18702
18703 @override
18704 Object visitTypeArgumentList(TypeArgumentList node) {
18705 _writer.print('<');
18706 _visitNodeListWithSeparator(node.arguments, ", ");
18707 _writer.print('>');
18708 return null;
18709 }
18710
18711 @override
18712 Object visitTypeName(TypeName node) {
18713 _visitNode(node.name);
18714 _visitNode(node.typeArguments);
18715 return null;
18716 }
18717
18718 @override
18719 Object visitTypeParameter(TypeParameter node) {
18720 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18721 _visitNode(node.name);
18722 _visitNodeWithPrefix(" extends ", node.bound);
18723 return null;
18724 }
18725
18726 @override
18727 Object visitTypeParameterList(TypeParameterList node) {
18728 _writer.print('<');
18729 _visitNodeListWithSeparator(node.typeParameters, ", ");
18730 _writer.print('>');
18731 return null;
18732 }
18733
18734 @override
18735 Object visitVariableDeclaration(VariableDeclaration node) {
18736 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18737 _visitNode(node.name);
18738 _visitNodeWithPrefix(" = ", node.initializer);
18739 return null;
18740 }
18741
18742 @override
18743 Object visitVariableDeclarationList(VariableDeclarationList node) {
18744 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18745 _visitTokenWithSuffix(node.keyword, " ");
18746 _visitNodeWithSuffix(node.type, " ");
18747 _visitNodeListWithSeparator(node.variables, ", ");
18748 return null;
18749 }
18750
18751 @override
18752 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
18753 _visitNode(node.variables);
18754 _writer.print(";");
18755 return null;
18756 }
18757
18758 @override
18759 Object visitWhileStatement(WhileStatement node) {
18760 _writer.print("while (");
18761 _visitNode(node.condition);
18762 _writer.print(") ");
18763 _visitNode(node.body);
18764 return null;
18765 }
18766
18767 @override
18768 Object visitWithClause(WithClause node) {
18769 _writer.print("with ");
18770 _visitNodeListWithSeparator(node.mixinTypes, ", ");
18771 return null;
18772 }
18773
18774 @override
18775 Object visitYieldStatement(YieldStatement node) {
18776 if (node.star != null) {
18777 _writer.print("yield* ");
18778 } else {
18779 _writer.print("yield ");
18780 }
18781 _visitNode(node.expression);
18782 _writer.print(";");
18783 return null;
18784 }
18785
18786 /**
18787 * Visit the given function [body], printing the [prefix] before if the body
18788 * is not empty.
18789 */
18790 void _visitFunctionWithPrefix(String prefix, FunctionBody body) {
18791 if (body is! EmptyFunctionBody) {
18792 _writer.print(prefix);
18793 }
18794 _visitNode(body);
18795 }
18796
18797 /**
18798 * Safely visit the given [node].
18799 */
18800 void _visitNode(AstNode node) {
18801 if (node != null) {
18802 node.accept(this);
18803 }
18804 }
18805
18806 /**
18807 * Print a list of [nodes] without any separation.
18808 */
18809 void _visitNodeList(NodeList<AstNode> nodes) {
18810 _visitNodeListWithSeparator(nodes, "");
18811 }
18812
18813 /**
18814 * Print a list of [nodes], separated by the given [separator].
18815 */
18816 void _visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) {
18817 if (nodes != null) {
18818 int size = nodes.length;
18819 for (int i = 0; i < size; i++) {
18820 if (i > 0) {
18821 _writer.print(separator);
18822 }
18823 nodes[i].accept(this);
18824 }
18825 }
18826 }
18827
18828 /**
18829 * Print a list of [nodes], prefixed by the given [prefix] if the list is not
18830 * empty, and separated by the given [separator].
18831 */
18832 void _visitNodeListWithSeparatorAndPrefix(
18833 String prefix, NodeList<AstNode> nodes, String separator) {
18834 if (nodes != null) {
18835 int size = nodes.length;
18836 if (size > 0) {
18837 _writer.print(prefix);
18838 for (int i = 0; i < size; i++) {
18839 if (i > 0) {
18840 _writer.print(separator);
18841 }
18842 nodes[i].accept(this);
18843 }
18844 }
18845 }
18846 }
18847
18848 /**
18849 * Print a list of [nodes], separated by the given [separator], followed by
18850 * the given [suffix] if the list is not empty.
18851 */
18852 void _visitNodeListWithSeparatorAndSuffix(
18853 NodeList<AstNode> nodes, String separator, String suffix) {
18854 if (nodes != null) {
18855 int size = nodes.length;
18856 if (size > 0) {
18857 for (int i = 0; i < size; i++) {
18858 if (i > 0) {
18859 _writer.print(separator);
18860 }
18861 nodes[i].accept(this);
18862 }
18863 _writer.print(suffix);
18864 }
18865 }
18866 }
18867
18868 /**
18869 * Safely visit the given [node], printing the [prefix] before the node if it
18870 * is non-`null`.
18871 */
18872 void _visitNodeWithPrefix(String prefix, AstNode node) {
18873 if (node != null) {
18874 _writer.print(prefix);
18875 node.accept(this);
18876 }
18877 }
18878
18879 /**
18880 * Safely visit the given [node], printing the [suffix] after the node if it
18881 * is non-`null`.
18882 */
18883 void _visitNodeWithSuffix(AstNode node, String suffix) {
18884 if (node != null) {
18885 node.accept(this);
18886 _writer.print(suffix);
18887 }
18888 }
18889
18890 /**
18891 * Safely visit the given [token], printing the [suffix] after the token if it
18892 * is non-`null`.
18893 */
18894 void _visitTokenWithSuffix(Token token, String suffix) {
18895 if (token != null) {
18896 _writer.print(token.lexeme);
18897 _writer.print(suffix);
18898 }
18899 }
18900 }
18901
18902 /** 11156 /**
18903 * A try statement. 11157 * A try statement.
18904 * 11158 *
18905 * > tryStatement ::= 11159 * > tryStatement ::=
18906 * > 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause) 11160 * > 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause)
18907 * > 11161 * >
18908 * > finallyClause ::= 11162 * > finallyClause ::=
18909 * > 'finally' [Block] 11163 * > 'finally' [Block]
18910 */ 11164 */
18911 class TryStatement extends Statement { 11165 class TryStatement extends Statement {
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
19401 @override 11655 @override
19402 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this); 11656 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this);
19403 11657
19404 @override 11658 @override
19405 void visitChildren(AstVisitor visitor) { 11659 void visitChildren(AstVisitor visitor) {
19406 _typeParameters.accept(visitor); 11660 _typeParameters.accept(visitor);
19407 } 11661 }
19408 } 11662 }
19409 11663
19410 /** 11664 /**
19411 * An AST visitor that will recursively visit all of the nodes in an AST
19412 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
19413 * every node will also be visited by using a single unified [visitNode] method.
19414 *
19415 * Subclasses that override a visit method must either invoke the overridden
19416 * visit method or explicitly invoke the more general [visitNode] method.
19417 * Failure to do so will cause the children of the visited node to not be
19418 * visited.
19419 */
19420 class UnifyingAstVisitor<R> implements AstVisitor<R> {
19421 @override
19422 R visitAdjacentStrings(AdjacentStrings node) => visitNode(node);
19423
19424 @override
19425 R visitAnnotation(Annotation node) => visitNode(node);
19426
19427 @override
19428 R visitArgumentList(ArgumentList node) => visitNode(node);
19429
19430 @override
19431 R visitAsExpression(AsExpression node) => visitNode(node);
19432
19433 @override
19434 R visitAssertStatement(AssertStatement node) => visitNode(node);
19435
19436 @override
19437 R visitAssignmentExpression(AssignmentExpression node) => visitNode(node);
19438
19439 @override
19440 R visitAwaitExpression(AwaitExpression node) => visitNode(node);
19441
19442 @override
19443 R visitBinaryExpression(BinaryExpression node) => visitNode(node);
19444
19445 @override
19446 R visitBlock(Block node) => visitNode(node);
19447
19448 @override
19449 R visitBlockFunctionBody(BlockFunctionBody node) => visitNode(node);
19450
19451 @override
19452 R visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
19453
19454 @override
19455 R visitBreakStatement(BreakStatement node) => visitNode(node);
19456
19457 @override
19458 R visitCascadeExpression(CascadeExpression node) => visitNode(node);
19459
19460 @override
19461 R visitCatchClause(CatchClause node) => visitNode(node);
19462
19463 @override
19464 R visitClassDeclaration(ClassDeclaration node) => visitNode(node);
19465
19466 @override
19467 R visitClassTypeAlias(ClassTypeAlias node) => visitNode(node);
19468
19469 @override
19470 R visitComment(Comment node) => visitNode(node);
19471
19472 @override
19473 R visitCommentReference(CommentReference node) => visitNode(node);
19474
19475 @override
19476 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
19477
19478 @override
19479 R visitConditionalExpression(ConditionalExpression node) => visitNode(node);
19480
19481 @override
19482 R visitConfiguration(Configuration node) => visitNode(node);
19483
19484 @override
19485 R visitConstructorDeclaration(ConstructorDeclaration node) => visitNode(node);
19486
19487 @override
19488 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
19489 visitNode(node);
19490
19491 @override
19492 R visitConstructorName(ConstructorName node) => visitNode(node);
19493
19494 @override
19495 R visitContinueStatement(ContinueStatement node) => visitNode(node);
19496
19497 @override
19498 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitNode(node);
19499
19500 @override
19501 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitNode(node);
19502
19503 @override
19504 R visitDoStatement(DoStatement node) => visitNode(node);
19505
19506 @override
19507 R visitDottedName(DottedName node) => visitNode(node);
19508
19509 @override
19510 R visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
19511
19512 @override
19513 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
19514
19515 @override
19516 R visitEmptyStatement(EmptyStatement node) => visitNode(node);
19517
19518 @override
19519 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
19520 visitNode(node);
19521
19522 @override
19523 R visitEnumDeclaration(EnumDeclaration node) => visitNode(node);
19524
19525 @override
19526 R visitExportDirective(ExportDirective node) => visitNode(node);
19527
19528 @override
19529 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitNode(node);
19530
19531 @override
19532 R visitExpressionStatement(ExpressionStatement node) => visitNode(node);
19533
19534 @override
19535 R visitExtendsClause(ExtendsClause node) => visitNode(node);
19536
19537 @override
19538 R visitFieldDeclaration(FieldDeclaration node) => visitNode(node);
19539
19540 @override
19541 R visitFieldFormalParameter(FieldFormalParameter node) => visitNode(node);
19542
19543 @override
19544 R visitForEachStatement(ForEachStatement node) => visitNode(node);
19545
19546 @override
19547 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
19548
19549 @override
19550 R visitForStatement(ForStatement node) => visitNode(node);
19551
19552 @override
19553 R visitFunctionDeclaration(FunctionDeclaration node) => visitNode(node);
19554
19555 @override
19556 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
19557 visitNode(node);
19558
19559 @override
19560 R visitFunctionExpression(FunctionExpression node) => visitNode(node);
19561
19562 @override
19563 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
19564 visitNode(node);
19565
19566 @override
19567 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitNode(node);
19568
19569 @override
19570 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
19571 visitNode(node);
19572
19573 @override
19574 R visitHideCombinator(HideCombinator node) => visitNode(node);
19575
19576 @override
19577 R visitIfStatement(IfStatement node) => visitNode(node);
19578
19579 @override
19580 R visitImplementsClause(ImplementsClause node) => visitNode(node);
19581
19582 @override
19583 R visitImportDirective(ImportDirective node) => visitNode(node);
19584
19585 @override
19586 R visitIndexExpression(IndexExpression node) => visitNode(node);
19587
19588 @override
19589 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
19590 visitNode(node);
19591
19592 @override
19593 R visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
19594
19595 @override
19596 R visitInterpolationExpression(InterpolationExpression node) =>
19597 visitNode(node);
19598
19599 @override
19600 R visitInterpolationString(InterpolationString node) => visitNode(node);
19601
19602 @override
19603 R visitIsExpression(IsExpression node) => visitNode(node);
19604
19605 @override
19606 R visitLabel(Label node) => visitNode(node);
19607
19608 @override
19609 R visitLabeledStatement(LabeledStatement node) => visitNode(node);
19610
19611 @override
19612 R visitLibraryDirective(LibraryDirective node) => visitNode(node);
19613
19614 @override
19615 R visitLibraryIdentifier(LibraryIdentifier node) => visitNode(node);
19616
19617 @override
19618 R visitListLiteral(ListLiteral node) => visitNode(node);
19619
19620 @override
19621 R visitMapLiteral(MapLiteral node) => visitNode(node);
19622
19623 @override
19624 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
19625
19626 @override
19627 R visitMethodDeclaration(MethodDeclaration node) => visitNode(node);
19628
19629 @override
19630 R visitMethodInvocation(MethodInvocation node) => visitNode(node);
19631
19632 @override
19633 R visitNamedExpression(NamedExpression node) => visitNode(node);
19634
19635 @override
19636 R visitNativeClause(NativeClause node) => visitNode(node);
19637
19638 @override
19639 R visitNativeFunctionBody(NativeFunctionBody node) => visitNode(node);
19640
19641 R visitNode(AstNode node) {
19642 node.visitChildren(this);
19643 return null;
19644 }
19645
19646 @override
19647 R visitNullLiteral(NullLiteral node) => visitNode(node);
19648
19649 @override
19650 R visitParenthesizedExpression(ParenthesizedExpression node) =>
19651 visitNode(node);
19652
19653 @override
19654 R visitPartDirective(PartDirective node) => visitNode(node);
19655
19656 @override
19657 R visitPartOfDirective(PartOfDirective node) => visitNode(node);
19658
19659 @override
19660 R visitPostfixExpression(PostfixExpression node) => visitNode(node);
19661
19662 @override
19663 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitNode(node);
19664
19665 @override
19666 R visitPrefixExpression(PrefixExpression node) => visitNode(node);
19667
19668 @override
19669 R visitPropertyAccess(PropertyAccess node) => visitNode(node);
19670
19671 @override
19672 R visitRedirectingConstructorInvocation(
19673 RedirectingConstructorInvocation node) =>
19674 visitNode(node);
19675
19676 @override
19677 R visitRethrowExpression(RethrowExpression node) => visitNode(node);
19678
19679 @override
19680 R visitReturnStatement(ReturnStatement node) => visitNode(node);
19681
19682 @override
19683 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
19684
19685 @override
19686 R visitShowCombinator(ShowCombinator node) => visitNode(node);
19687
19688 @override
19689 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNode(node);
19690
19691 @override
19692 R visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
19693
19694 @override
19695 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
19696
19697 @override
19698 R visitStringInterpolation(StringInterpolation node) => visitNode(node);
19699
19700 @override
19701 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
19702 visitNode(node);
19703
19704 @override
19705 R visitSuperExpression(SuperExpression node) => visitNode(node);
19706
19707 @override
19708 R visitSwitchCase(SwitchCase node) => visitNode(node);
19709
19710 @override
19711 R visitSwitchDefault(SwitchDefault node) => visitNode(node);
19712
19713 @override
19714 R visitSwitchStatement(SwitchStatement node) => visitNode(node);
19715
19716 @override
19717 R visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
19718
19719 @override
19720 R visitThisExpression(ThisExpression node) => visitNode(node);
19721
19722 @override
19723 R visitThrowExpression(ThrowExpression node) => visitNode(node);
19724
19725 @override
19726 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
19727 visitNode(node);
19728
19729 @override
19730 R visitTryStatement(TryStatement node) => visitNode(node);
19731
19732 @override
19733 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
19734
19735 @override
19736 R visitTypeName(TypeName node) => visitNode(node);
19737
19738 @override
19739 R visitTypeParameter(TypeParameter node) => visitNode(node);
19740
19741 @override
19742 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
19743
19744 @override
19745 R visitVariableDeclaration(VariableDeclaration node) => visitNode(node);
19746
19747 @override
19748 R visitVariableDeclarationList(VariableDeclarationList node) =>
19749 visitNode(node);
19750
19751 @override
19752 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
19753 visitNode(node);
19754
19755 @override
19756 R visitWhileStatement(WhileStatement node) => visitNode(node);
19757
19758 @override
19759 R visitWithClause(WithClause node) => visitNode(node);
19760
19761 @override
19762 R visitYieldStatement(YieldStatement node) => visitNode(node);
19763 }
19764
19765 /**
19766 * A directive that references a URI. 11665 * A directive that references a URI.
19767 * 11666 *
19768 * > uriBasedDirective ::= 11667 * > uriBasedDirective ::=
19769 * > [ExportDirective] 11668 * > [ExportDirective]
19770 * > | [ImportDirective] 11669 * > | [ImportDirective]
19771 * > | [PartDirective] 11670 * > | [PartDirective]
19772 */ 11671 */
19773 abstract class UriBasedDirective extends Directive { 11672 abstract class UriBasedDirective extends Directive {
19774 /** 11673 /**
19775 * The prefix of a URI using the `dart-ext` scheme to reference a native code 11674 * The prefix of a URI using the `dart-ext` scheme to reference a native code
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
19921 _name = _becomeParentOf(name); 11820 _name = _becomeParentOf(name);
19922 _initializer = _becomeParentOf(initializer); 11821 _initializer = _becomeParentOf(initializer);
19923 } 11822 }
19924 11823
19925 @override 11824 @override
19926 Iterable get childEntities => 11825 Iterable get childEntities =>
19927 super._childEntities..add(_name)..add(equals)..add(_initializer); 11826 super._childEntities..add(_name)..add(equals)..add(_initializer);
19928 11827
19929 /** 11828 /**
19930 * This overridden implementation of getDocumentationComment() looks in the 11829 * This overridden implementation of getDocumentationComment() looks in the
19931 * grandparent node for dartdoc comments if no documentation is specifically 11830 * grandparent node for Dartdoc comments if no documentation is specifically
19932 * available on the node. 11831 * available on the node.
19933 */ 11832 */
19934 @override 11833 @override
19935 Comment get documentationComment { 11834 Comment get documentationComment {
19936 Comment comment = super.documentationComment; 11835 Comment comment = super.documentationComment;
19937 if (comment == null) { 11836 if (comment == null) {
19938 if (parent != null && parent.parent != null) { 11837 if (parent != null && parent.parent != null) {
19939 AstNode node = parent.parent; 11838 AstNode node = parent.parent;
19940 if (node is AnnotatedNode) { 11839 if (node is AnnotatedNode) {
19941 return node.documentationComment; 11840 return node.documentationComment;
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
20394 } 12293 }
20395 12294
20396 @override 12295 @override
20397 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 12296 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20398 12297
20399 @override 12298 @override
20400 void visitChildren(AstVisitor visitor) { 12299 void visitChildren(AstVisitor visitor) {
20401 _safelyVisitChild(_expression, visitor); 12300 _safelyVisitChild(_expression, visitor);
20402 } 12301 }
20403 } 12302 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698