| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | |
| 6 // significant change. Please see the README file for more information. | |
| 7 | |
| 8 library engine.ast; | |
| 9 | |
| 10 import 'dart:collection'; | |
| 11 | |
| 12 import 'element.dart'; | |
| 13 import 'engine.dart' show AnalysisEngine; | |
| 14 import 'java_core.dart'; | |
| 15 import 'java_engine.dart'; | |
| 16 import 'parser.dart'; | |
| 17 import 'scanner.dart'; | |
| 18 import 'source.dart' show LineInfo, Source; | |
| 19 import 'utilities_collection.dart' show TokenMap; | |
| 20 import 'utilities_dart.dart'; | |
| 21 | |
| 22 /** | |
| 23 * Two or more string literals that are implicitly concatenated because of being | |
| 24 * adjacent (separated only by whitespace). | |
| 25 * | |
| 26 * 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 | |
| 28 * restriction. | |
| 29 * | |
| 30 * > adjacentStrings ::= | |
| 31 * > [StringLiteral] [StringLiteral]+ | |
| 32 */ | |
| 33 class AdjacentStrings extends StringLiteral { | |
| 34 /** | |
| 35 * The strings that are implicitly concatenated. | |
| 36 */ | |
| 37 NodeList<StringLiteral> _strings; | |
| 38 | |
| 39 /** | |
| 40 * Initialize a newly created list of adjacent strings. To be syntactically | |
| 41 * valid, the list of [strings] must contain at least two elements. | |
| 42 */ | |
| 43 AdjacentStrings(List<StringLiteral> strings) { | |
| 44 _strings = new NodeList<StringLiteral>(this, strings); | |
| 45 } | |
| 46 | |
| 47 @override | |
| 48 Token get beginToken => _strings.beginToken; | |
| 49 | |
| 50 @override | |
| 51 Iterable get childEntities => new ChildEntities()..addAll(_strings); | |
| 52 | |
| 53 @override | |
| 54 Token get endToken => _strings.endToken; | |
| 55 | |
| 56 /** | |
| 57 * Return the strings that are implicitly concatenated. | |
| 58 */ | |
| 59 NodeList<StringLiteral> get strings => _strings; | |
| 60 | |
| 61 @override | |
| 62 accept(AstVisitor visitor) => visitor.visitAdjacentStrings(this); | |
| 63 | |
| 64 @override | |
| 65 void visitChildren(AstVisitor visitor) { | |
| 66 _strings.accept(visitor); | |
| 67 } | |
| 68 | |
| 69 @override | |
| 70 void _appendStringValue(StringBuffer buffer) { | |
| 71 for (StringLiteral stringLiteral in strings) { | |
| 72 stringLiteral._appendStringValue(buffer); | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 /** | |
| 78 * An AST node that can be annotated with both a documentation comment and a | |
| 79 * list of annotations. | |
| 80 */ | |
| 81 abstract class AnnotatedNode extends AstNode { | |
| 82 /** | |
| 83 * The documentation comment associated with this node, or `null` if this node | |
| 84 * does not have a documentation comment associated with it. | |
| 85 */ | |
| 86 Comment _comment; | |
| 87 | |
| 88 /** | |
| 89 * The annotations associated with this node. | |
| 90 */ | |
| 91 NodeList<Annotation> _metadata; | |
| 92 | |
| 93 /** | |
| 94 * Initialize a newly created annotated node. Either or both of the [comment] | |
| 95 * and [metadata] can be `null` if the node does not have the corresponding | |
| 96 * attribute. | |
| 97 */ | |
| 98 AnnotatedNode(Comment comment, List<Annotation> metadata) { | |
| 99 _comment = _becomeParentOf(comment); | |
| 100 _metadata = new NodeList<Annotation>(this, metadata); | |
| 101 } | |
| 102 | |
| 103 @override | |
| 104 Token get beginToken { | |
| 105 if (_comment == null) { | |
| 106 if (_metadata.isEmpty) { | |
| 107 return firstTokenAfterCommentAndMetadata; | |
| 108 } | |
| 109 return _metadata.beginToken; | |
| 110 } else if (_metadata.isEmpty) { | |
| 111 return _comment.beginToken; | |
| 112 } | |
| 113 Token commentToken = _comment.beginToken; | |
| 114 Token metadataToken = _metadata.beginToken; | |
| 115 if (commentToken.offset < metadataToken.offset) { | |
| 116 return commentToken; | |
| 117 } | |
| 118 return metadataToken; | |
| 119 } | |
| 120 | |
| 121 /** | |
| 122 * Return the documentation comment associated with this node, or `null` if | |
| 123 * this node does not have a documentation comment associated with it. | |
| 124 */ | |
| 125 Comment get documentationComment => _comment; | |
| 126 | |
| 127 /** | |
| 128 * Set the documentation comment associated with this node to the given | |
| 129 * [comment]. | |
| 130 */ | |
| 131 void set documentationComment(Comment comment) { | |
| 132 _comment = _becomeParentOf(comment); | |
| 133 } | |
| 134 | |
| 135 /** | |
| 136 * Return the first token following the comment and metadata. | |
| 137 */ | |
| 138 Token get firstTokenAfterCommentAndMetadata; | |
| 139 | |
| 140 /** | |
| 141 * Return the annotations associated with this node. | |
| 142 */ | |
| 143 NodeList<Annotation> get metadata => _metadata; | |
| 144 | |
| 145 /** | |
| 146 * Set the metadata associated with this node to the given [metadata]. | |
| 147 */ | |
| 148 @deprecated // Directly modify the list returned by "this.metadata" | |
| 149 void set metadata(List<Annotation> metadata) { | |
| 150 _metadata.clear(); | |
| 151 _metadata.addAll(metadata); | |
| 152 } | |
| 153 | |
| 154 /** | |
| 155 * Return a list containing the comment and annotations associated with this | |
| 156 * node, sorted in lexical order. | |
| 157 */ | |
| 158 List<AstNode> get sortedCommentAndAnnotations { | |
| 159 return <AstNode>[] | |
| 160 ..add(_comment) | |
| 161 ..addAll(_metadata) | |
| 162 ..sort(AstNode.LEXICAL_ORDER); | |
| 163 } | |
| 164 | |
| 165 /** | |
| 166 * Return a holder of child entities that subclasses can add to. | |
| 167 */ | |
| 168 ChildEntities get _childEntities { | |
| 169 ChildEntities result = new ChildEntities(); | |
| 170 if (_commentIsBeforeAnnotations()) { | |
| 171 result | |
| 172 ..add(_comment) | |
| 173 ..addAll(_metadata); | |
| 174 } else { | |
| 175 result.addAll(sortedCommentAndAnnotations); | |
| 176 } | |
| 177 return result; | |
| 178 } | |
| 179 | |
| 180 @override | |
| 181 void visitChildren(AstVisitor visitor) { | |
| 182 if (_commentIsBeforeAnnotations()) { | |
| 183 _safelyVisitChild(_comment, visitor); | |
| 184 _metadata.accept(visitor); | |
| 185 } else { | |
| 186 for (AstNode child in sortedCommentAndAnnotations) { | |
| 187 child.accept(visitor); | |
| 188 } | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 /** | |
| 193 * Return `true` if there are no annotations before the comment. Note that a | |
| 194 * result of `true` does not imply that there is a comment, nor that there are | |
| 195 * annotations associated with this node. | |
| 196 */ | |
| 197 bool _commentIsBeforeAnnotations() { | |
| 198 // TODO(brianwilkerson) Convert this to a getter. | |
| 199 if (_comment == null || _metadata.isEmpty) { | |
| 200 return true; | |
| 201 } | |
| 202 Annotation firstAnnotation = _metadata[0]; | |
| 203 return _comment.offset < firstAnnotation.offset; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 /** | |
| 208 * An annotation that can be associated with an AST node. | |
| 209 * | |
| 210 * > metadata ::= | |
| 211 * > annotation* | |
| 212 * > | |
| 213 * > annotation ::= | |
| 214 * > '@' [Identifier] ('.' [SimpleIdentifier])? [ArgumentList]? | |
| 215 */ | |
| 216 class Annotation extends AstNode { | |
| 217 /** | |
| 218 * The at sign that introduced the annotation. | |
| 219 */ | |
| 220 Token atSign; | |
| 221 | |
| 222 /** | |
| 223 * The name of the class defining the constructor that is being invoked or the | |
| 224 * name of the field that is being referenced. | |
| 225 */ | |
| 226 Identifier _name; | |
| 227 | |
| 228 /** | |
| 229 * The period before the constructor name, or `null` if this annotation is not | |
| 230 * the invocation of a named constructor. | |
| 231 */ | |
| 232 Token period; | |
| 233 | |
| 234 /** | |
| 235 * The name of the constructor being invoked, or `null` if this annotation is | |
| 236 * not the invocation of a named constructor. | |
| 237 */ | |
| 238 SimpleIdentifier _constructorName; | |
| 239 | |
| 240 /** | |
| 241 * The arguments to the constructor being invoked, or `null` if this | |
| 242 * annotation is not the invocation of a constructor. | |
| 243 */ | |
| 244 ArgumentList _arguments; | |
| 245 | |
| 246 /** | |
| 247 * The element associated with this annotation, or `null` if the AST structure | |
| 248 * has not been resolved or if this annotation could not be resolved. | |
| 249 */ | |
| 250 Element _element; | |
| 251 | |
| 252 /** | |
| 253 * The element annotation representing this annotation in the element model. | |
| 254 */ | |
| 255 ElementAnnotation elementAnnotation; | |
| 256 | |
| 257 /** | |
| 258 * Initialize a newly created annotation. Both the [period] and the | |
| 259 * [constructorName] can be `null` if the annotation is not referencing a | |
| 260 * named constructor. The [arguments] can be `null` if the annotation is not | |
| 261 * referencing a constructor. | |
| 262 */ | |
| 263 Annotation(this.atSign, Identifier name, this.period, | |
| 264 SimpleIdentifier constructorName, ArgumentList arguments) { | |
| 265 _name = _becomeParentOf(name); | |
| 266 _constructorName = _becomeParentOf(constructorName); | |
| 267 _arguments = _becomeParentOf(arguments); | |
| 268 } | |
| 269 | |
| 270 /** | |
| 271 * Return the arguments to the constructor being invoked, or `null` if this | |
| 272 * annotation is not the invocation of a constructor. | |
| 273 */ | |
| 274 ArgumentList get arguments => _arguments; | |
| 275 | |
| 276 /** | |
| 277 * Set the arguments to the constructor being invoked to the given arguments. | |
| 278 */ | |
| 279 void set arguments(ArgumentList arguments) { | |
| 280 _arguments = _becomeParentOf(arguments); | |
| 281 } | |
| 282 | |
| 283 @override | |
| 284 Token get beginToken => atSign; | |
| 285 | |
| 286 @override | |
| 287 Iterable get childEntities => new ChildEntities() | |
| 288 ..add(atSign) | |
| 289 ..add(_name) | |
| 290 ..add(period) | |
| 291 ..add(_constructorName) | |
| 292 ..add(_arguments); | |
| 293 | |
| 294 /** | |
| 295 * Return the name of the constructor being invoked, or `null` if this | |
| 296 * annotation is not the invocation of a named constructor. | |
| 297 */ | |
| 298 SimpleIdentifier get constructorName => _constructorName; | |
| 299 | |
| 300 /** | |
| 301 * Set the name of the constructor being invoked to the given [name]. | |
| 302 */ | |
| 303 void set constructorName(SimpleIdentifier name) { | |
| 304 _constructorName = _becomeParentOf(name); | |
| 305 } | |
| 306 | |
| 307 /** | |
| 308 * Return the element associated with this annotation, or `null` if the AST | |
| 309 * structure has not been resolved or if this annotation could not be | |
| 310 * resolved. | |
| 311 */ | |
| 312 Element get element { | |
| 313 if (_element != null) { | |
| 314 return _element; | |
| 315 } else if (_name != null) { | |
| 316 return _name.staticElement; | |
| 317 } | |
| 318 return null; | |
| 319 } | |
| 320 | |
| 321 /** | |
| 322 * Set the element associated with this annotation to the given [element]. | |
| 323 */ | |
| 324 void set element(Element element) { | |
| 325 _element = element; | |
| 326 } | |
| 327 | |
| 328 @override | |
| 329 Token get endToken { | |
| 330 if (_arguments != null) { | |
| 331 return _arguments.endToken; | |
| 332 } else if (_constructorName != null) { | |
| 333 return _constructorName.endToken; | |
| 334 } | |
| 335 return _name.endToken; | |
| 336 } | |
| 337 | |
| 338 /** | |
| 339 * Return the name of the class defining the constructor that is being invoked | |
| 340 * or the name of the field that is being referenced. | |
| 341 */ | |
| 342 Identifier get name => _name; | |
| 343 | |
| 344 /** | |
| 345 * Set the name of the class defining the constructor that is being invoked or | |
| 346 * the name of the field that is being referenced to the given [name]. | |
| 347 */ | |
| 348 void set name(Identifier name) { | |
| 349 _name = _becomeParentOf(name); | |
| 350 } | |
| 351 | |
| 352 @override | |
| 353 accept(AstVisitor visitor) => visitor.visitAnnotation(this); | |
| 354 | |
| 355 @override | |
| 356 void visitChildren(AstVisitor visitor) { | |
| 357 _safelyVisitChild(_name, visitor); | |
| 358 _safelyVisitChild(_constructorName, visitor); | |
| 359 _safelyVisitChild(_arguments, visitor); | |
| 360 } | |
| 361 } | |
| 362 | |
| 363 /** | |
| 364 * A list of arguments in the invocation of an executable element (that is, a | |
| 365 * function, method, or constructor). | |
| 366 * | |
| 367 * > argumentList ::= | |
| 368 * > '(' arguments? ')' | |
| 369 * > | |
| 370 * > arguments ::= | |
| 371 * > [NamedExpression] (',' [NamedExpression])* | |
| 372 * > | [Expression] (',' [Expression])* (',' [NamedExpression])* | |
| 373 */ | |
| 374 class ArgumentList extends AstNode { | |
| 375 /** | |
| 376 * The left parenthesis. | |
| 377 */ | |
| 378 Token leftParenthesis; | |
| 379 | |
| 380 /** | |
| 381 * The expressions producing the values of the arguments. | |
| 382 */ | |
| 383 NodeList<Expression> _arguments; | |
| 384 | |
| 385 /** | |
| 386 * The right parenthesis. | |
| 387 */ | |
| 388 Token rightParenthesis; | |
| 389 | |
| 390 /** | |
| 391 * A list containing the elements representing the parameters corresponding to | |
| 392 * each of the arguments in this list, or `null` if the AST has not been | |
| 393 * resolved or if the function or method being invoked could not be determined | |
| 394 * based on static type information. The list must be the same length as the | |
| 395 * number of arguments, but can contain `null` entries if a given argument | |
| 396 * does not correspond to a formal parameter. | |
| 397 */ | |
| 398 List<ParameterElement> _correspondingStaticParameters; | |
| 399 | |
| 400 /** | |
| 401 * A list containing the elements representing the parameters corresponding to | |
| 402 * each of the arguments in this list, or `null` if the AST has not been | |
| 403 * resolved or if the function or method being invoked could not be determined | |
| 404 * based on propagated type information. The list must be the same length as | |
| 405 * the number of arguments, but can contain `null` entries if a given argument | |
| 406 * does not correspond to a formal parameter. | |
| 407 */ | |
| 408 List<ParameterElement> _correspondingPropagatedParameters; | |
| 409 | |
| 410 /** | |
| 411 * Initialize a newly created list of arguments. The list of [arguments] can | |
| 412 * be `null` if there are no arguments. | |
| 413 */ | |
| 414 ArgumentList( | |
| 415 this.leftParenthesis, List<Expression> arguments, this.rightParenthesis) { | |
| 416 _arguments = new NodeList<Expression>(this, arguments); | |
| 417 } | |
| 418 | |
| 419 /** | |
| 420 * Return the expressions producing the values of the arguments. Although the | |
| 421 * language requires that positional arguments appear before named arguments, | |
| 422 * this class allows them to be intermixed. | |
| 423 */ | |
| 424 NodeList<Expression> get arguments => _arguments; | |
| 425 | |
| 426 @override | |
| 427 Token get beginToken => leftParenthesis; | |
| 428 | |
| 429 /** | |
| 430 * TODO(paulberry): Add commas. | |
| 431 */ | |
| 432 @override | |
| 433 Iterable get childEntities => new ChildEntities() | |
| 434 ..add(leftParenthesis) | |
| 435 ..addAll(_arguments) | |
| 436 ..add(rightParenthesis); | |
| 437 | |
| 438 /** | |
| 439 * Set the parameter elements corresponding to each of the arguments in this | |
| 440 * list to the given list of [parameters]. The list of parameters must be the | |
| 441 * same length as the number of arguments, but can contain `null` entries if a | |
| 442 * given argument does not correspond to a formal parameter. | |
| 443 */ | |
| 444 void set correspondingPropagatedParameters( | |
| 445 List<ParameterElement> parameters) { | |
| 446 if (parameters.length != _arguments.length) { | |
| 447 throw new IllegalArgumentException( | |
| 448 "Expected ${_arguments.length} parameters, not ${parameters.length}"); | |
| 449 } | |
| 450 _correspondingPropagatedParameters = parameters; | |
| 451 } | |
| 452 | |
| 453 /** | |
| 454 * Set the parameter elements corresponding to each of the arguments in this | |
| 455 * list to the given list of parameters. The list of parameters must be the | |
| 456 * same length as the number of arguments, but can contain `null` entries if a | |
| 457 * given argument does not correspond to a formal parameter. | |
| 458 */ | |
| 459 void set correspondingStaticParameters(List<ParameterElement> parameters) { | |
| 460 if (parameters.length != _arguments.length) { | |
| 461 throw new IllegalArgumentException( | |
| 462 "Expected ${_arguments.length} parameters, not ${parameters.length}"); | |
| 463 } | |
| 464 _correspondingStaticParameters = parameters; | |
| 465 } | |
| 466 | |
| 467 @override | |
| 468 Token get endToken => rightParenthesis; | |
| 469 | |
| 470 @override | |
| 471 accept(AstVisitor visitor) => visitor.visitArgumentList(this); | |
| 472 | |
| 473 /** | |
| 474 * If | |
| 475 * * the given [expression] is a child of this list, | |
| 476 * * the AST structure has been resolved, | |
| 477 * * the function being invoked is known based on propagated type information, | |
| 478 * and | |
| 479 * * the expression corresponds to one of the parameters of the function being | |
| 480 * invoked, | |
| 481 * then return the parameter element representing the parameter to which the | |
| 482 * value of the given expression will be bound. Otherwise, return `null`. | |
| 483 */ | |
| 484 @deprecated // Use "expression.propagatedParameterElement" | |
| 485 ParameterElement getPropagatedParameterElementFor(Expression expression) { | |
| 486 return _getPropagatedParameterElementFor(expression); | |
| 487 } | |
| 488 | |
| 489 /** | |
| 490 * If | |
| 491 * * the given [expression] is a child of this list, | |
| 492 * * the AST structure has been resolved, | |
| 493 * * the function being invoked is known based on static type information, and | |
| 494 * * the expression corresponds to one of the parameters of the function being | |
| 495 * invoked, | |
| 496 * then return the parameter element representing the parameter to which the | |
| 497 * value of the given expression will be bound. Otherwise, return `null`. | |
| 498 */ | |
| 499 @deprecated // Use "expression.staticParameterElement" | |
| 500 ParameterElement getStaticParameterElementFor(Expression expression) { | |
| 501 return _getStaticParameterElementFor(expression); | |
| 502 } | |
| 503 | |
| 504 @override | |
| 505 void visitChildren(AstVisitor visitor) { | |
| 506 _arguments.accept(visitor); | |
| 507 } | |
| 508 | |
| 509 /** | |
| 510 * If | |
| 511 * * the given [expression] is a child of this list, | |
| 512 * * the AST structure has been resolved, | |
| 513 * * the function being invoked is known based on propagated type information, | |
| 514 * and | |
| 515 * * the expression corresponds to one of the parameters of the function being | |
| 516 * invoked, | |
| 517 * then return the parameter element representing the parameter to which the | |
| 518 * value of the given expression will be bound. Otherwise, return `null`. | |
| 519 */ | |
| 520 ParameterElement _getPropagatedParameterElementFor(Expression expression) { | |
| 521 if (_correspondingPropagatedParameters == null || | |
| 522 _correspondingPropagatedParameters.length != _arguments.length) { | |
| 523 // Either the AST structure has not been resolved, the invocation of which | |
| 524 // this list is a part could not be resolved, or the argument list was | |
| 525 // modified after the parameters were set. | |
| 526 return null; | |
| 527 } | |
| 528 int index = _arguments.indexOf(expression); | |
| 529 if (index < 0) { | |
| 530 // The expression isn't a child of this node. | |
| 531 return null; | |
| 532 } | |
| 533 return _correspondingPropagatedParameters[index]; | |
| 534 } | |
| 535 | |
| 536 /** | |
| 537 * If | |
| 538 * * the given [expression] is a child of this list, | |
| 539 * * the AST structure has been resolved, | |
| 540 * * the function being invoked is known based on static type information, and | |
| 541 * * the expression corresponds to one of the parameters of the function being | |
| 542 * invoked, | |
| 543 * then return the parameter element representing the parameter to which the | |
| 544 * value of the given expression will be bound. Otherwise, return `null`. | |
| 545 */ | |
| 546 ParameterElement _getStaticParameterElementFor(Expression expression) { | |
| 547 if (_correspondingStaticParameters == null || | |
| 548 _correspondingStaticParameters.length != _arguments.length) { | |
| 549 // Either the AST structure has not been resolved, the invocation of which | |
| 550 // this list is a part could not be resolved, or the argument list was | |
| 551 // modified after the parameters were set. | |
| 552 return null; | |
| 553 } | |
| 554 int index = _arguments.indexOf(expression); | |
| 555 if (index < 0) { | |
| 556 // The expression isn't a child of this node. | |
| 557 return null; | |
| 558 } | |
| 559 return _correspondingStaticParameters[index]; | |
| 560 } | |
| 561 } | |
| 562 | |
| 563 /** | |
| 564 * An as expression. | |
| 565 * | |
| 566 * > asExpression ::= | |
| 567 * > [Expression] 'as' [TypeName] | |
| 568 */ | |
| 569 class AsExpression extends Expression { | |
| 570 /** | |
| 571 * The expression used to compute the value being cast. | |
| 572 */ | |
| 573 Expression _expression; | |
| 574 | |
| 575 /** | |
| 576 * The 'as' operator. | |
| 577 */ | |
| 578 Token asOperator; | |
| 579 | |
| 580 /** | |
| 581 * The name of the type being cast to. | |
| 582 */ | |
| 583 TypeName _type; | |
| 584 | |
| 585 /** | |
| 586 * Initialize a newly created as expression. | |
| 587 */ | |
| 588 AsExpression(Expression expression, this.asOperator, TypeName type) { | |
| 589 _expression = _becomeParentOf(expression); | |
| 590 _type = _becomeParentOf(type); | |
| 591 } | |
| 592 | |
| 593 @override | |
| 594 Token get beginToken => _expression.beginToken; | |
| 595 | |
| 596 @override | |
| 597 Iterable get childEntities => | |
| 598 new ChildEntities()..add(_expression)..add(asOperator)..add(_type); | |
| 599 | |
| 600 @override | |
| 601 Token get endToken => _type.endToken; | |
| 602 | |
| 603 /** | |
| 604 * Return the expression used to compute the value being cast. | |
| 605 */ | |
| 606 Expression get expression => _expression; | |
| 607 | |
| 608 /** | |
| 609 * Set the expression used to compute the value being cast to the given | |
| 610 * [expression]. | |
| 611 */ | |
| 612 void set expression(Expression expression) { | |
| 613 _expression = _becomeParentOf(expression); | |
| 614 } | |
| 615 | |
| 616 @override | |
| 617 int get precedence => 7; | |
| 618 | |
| 619 /** | |
| 620 * Return the name of the type being cast to. | |
| 621 */ | |
| 622 TypeName get type => _type; | |
| 623 | |
| 624 /** | |
| 625 * Set the name of the type being cast to to the given [name]. | |
| 626 */ | |
| 627 void set type(TypeName name) { | |
| 628 _type = _becomeParentOf(name); | |
| 629 } | |
| 630 | |
| 631 @override | |
| 632 accept(AstVisitor visitor) => visitor.visitAsExpression(this); | |
| 633 | |
| 634 @override | |
| 635 void visitChildren(AstVisitor visitor) { | |
| 636 _safelyVisitChild(_expression, visitor); | |
| 637 _safelyVisitChild(_type, visitor); | |
| 638 } | |
| 639 } | |
| 640 | |
| 641 /** | |
| 642 * An assert statement. | |
| 643 * | |
| 644 * > assertStatement ::= | |
| 645 * > 'assert' '(' [Expression] ')' ';' | |
| 646 */ | |
| 647 class AssertStatement extends Statement { | |
| 648 /** | |
| 649 * The token representing the 'assert' keyword. | |
| 650 */ | |
| 651 Token assertKeyword; | |
| 652 | |
| 653 /** | |
| 654 * The left parenthesis. | |
| 655 */ | |
| 656 Token leftParenthesis; | |
| 657 | |
| 658 /** | |
| 659 * The condition that is being asserted to be `true`. | |
| 660 */ | |
| 661 Expression _condition; | |
| 662 | |
| 663 /** | |
| 664 * The right parenthesis. | |
| 665 */ | |
| 666 Token rightParenthesis; | |
| 667 | |
| 668 /** | |
| 669 * The semicolon terminating the statement. | |
| 670 */ | |
| 671 Token semicolon; | |
| 672 | |
| 673 /** | |
| 674 * Initialize a newly created assert statement. | |
| 675 */ | |
| 676 AssertStatement(this.assertKeyword, this.leftParenthesis, | |
| 677 Expression condition, this.rightParenthesis, this.semicolon) { | |
| 678 _condition = _becomeParentOf(condition); | |
| 679 } | |
| 680 | |
| 681 @override | |
| 682 Token get beginToken => assertKeyword; | |
| 683 | |
| 684 @override | |
| 685 Iterable get childEntities => new ChildEntities() | |
| 686 ..add(assertKeyword) | |
| 687 ..add(leftParenthesis) | |
| 688 ..add(_condition) | |
| 689 ..add(rightParenthesis) | |
| 690 ..add(semicolon); | |
| 691 | |
| 692 /** | |
| 693 * Return the condition that is being asserted to be `true`. | |
| 694 */ | |
| 695 Expression get condition => _condition; | |
| 696 | |
| 697 /** | |
| 698 * Set the condition that is being asserted to be `true` to the given | |
| 699 * [expression]. | |
| 700 */ | |
| 701 void set condition(Expression condition) { | |
| 702 _condition = _becomeParentOf(condition); | |
| 703 } | |
| 704 | |
| 705 @override | |
| 706 Token get endToken => semicolon; | |
| 707 | |
| 708 /** | |
| 709 * Return the token representing the 'assert' keyword. | |
| 710 */ | |
| 711 @deprecated // Use "this.assertKeyword" | |
| 712 Token get keyword => assertKeyword; | |
| 713 | |
| 714 /** | |
| 715 * Set the token representing the 'assert' keyword to the given [token]. | |
| 716 */ | |
| 717 @deprecated // Use "this.assertKeyword" | |
| 718 set keyword(Token token) { | |
| 719 assertKeyword = token; | |
| 720 } | |
| 721 | |
| 722 @override | |
| 723 accept(AstVisitor visitor) => visitor.visitAssertStatement(this); | |
| 724 | |
| 725 @override | |
| 726 void visitChildren(AstVisitor visitor) { | |
| 727 _safelyVisitChild(_condition, visitor); | |
| 728 } | |
| 729 } | |
| 730 | |
| 731 /** | |
| 732 * An assignment expression. | |
| 733 * | |
| 734 * > assignmentExpression ::= | |
| 735 * > [Expression] operator [Expression] | |
| 736 */ | |
| 737 class AssignmentExpression extends Expression { | |
| 738 /** | |
| 739 * The expression used to compute the left hand side. | |
| 740 */ | |
| 741 Expression _leftHandSide; | |
| 742 | |
| 743 /** | |
| 744 * The assignment operator being applied. | |
| 745 */ | |
| 746 Token operator; | |
| 747 | |
| 748 /** | |
| 749 * The expression used to compute the right hand side. | |
| 750 */ | |
| 751 Expression _rightHandSide; | |
| 752 | |
| 753 /** | |
| 754 * The element associated with the operator based on the static type of the | |
| 755 * left-hand-side, or `null` if the AST structure has not been resolved, if | |
| 756 * the operator is not a compound operator, or if the operator could not be | |
| 757 * resolved. | |
| 758 */ | |
| 759 MethodElement staticElement; | |
| 760 | |
| 761 /** | |
| 762 * The element associated with the operator based on the propagated type of | |
| 763 * the left-hand-side, or `null` if the AST structure has not been resolved, | |
| 764 * if the operator is not a compound operator, or if the operator could not be | |
| 765 * resolved. | |
| 766 */ | |
| 767 MethodElement propagatedElement; | |
| 768 | |
| 769 /** | |
| 770 * Initialize a newly created assignment expression. | |
| 771 */ | |
| 772 AssignmentExpression( | |
| 773 Expression leftHandSide, this.operator, Expression rightHandSide) { | |
| 774 if (leftHandSide == null || rightHandSide == null) { | |
| 775 String message; | |
| 776 if (leftHandSide == null) { | |
| 777 if (rightHandSide == null) { | |
| 778 message = "Both the left-hand and right-hand sides are null"; | |
| 779 } else { | |
| 780 message = "The left-hand size is null"; | |
| 781 } | |
| 782 } else { | |
| 783 message = "The right-hand size is null"; | |
| 784 } | |
| 785 AnalysisEngine.instance.logger.logError( | |
| 786 message, new CaughtException(new AnalysisException(message), null)); | |
| 787 } | |
| 788 _leftHandSide = _becomeParentOf(leftHandSide); | |
| 789 _rightHandSide = _becomeParentOf(rightHandSide); | |
| 790 } | |
| 791 | |
| 792 @override | |
| 793 Token get beginToken => _leftHandSide.beginToken; | |
| 794 | |
| 795 /** | |
| 796 * Return the best element available for this operator. If resolution was able | |
| 797 * to find a better element based on type propagation, that element will be | |
| 798 * returned. Otherwise, the element found using the result of static analysis | |
| 799 * will be returned. If resolution has not been performed, then `null` will be | |
| 800 * returned. | |
| 801 */ | |
| 802 MethodElement get bestElement { | |
| 803 MethodElement element = propagatedElement; | |
| 804 if (element == null) { | |
| 805 element = staticElement; | |
| 806 } | |
| 807 return element; | |
| 808 } | |
| 809 | |
| 810 @override | |
| 811 Iterable get childEntities => new ChildEntities() | |
| 812 ..add(_leftHandSide) | |
| 813 ..add(operator) | |
| 814 ..add(_rightHandSide); | |
| 815 | |
| 816 @override | |
| 817 Token get endToken => _rightHandSide.endToken; | |
| 818 | |
| 819 /** | |
| 820 * Set the expression used to compute the left hand side to the given | |
| 821 * [expression]. | |
| 822 */ | |
| 823 Expression get leftHandSide => _leftHandSide; | |
| 824 | |
| 825 /** | |
| 826 * Return the expression used to compute the left hand side. | |
| 827 */ | |
| 828 void set leftHandSide(Expression expression) { | |
| 829 _leftHandSide = _becomeParentOf(expression); | |
| 830 } | |
| 831 | |
| 832 @override | |
| 833 int get precedence => 1; | |
| 834 | |
| 835 /** | |
| 836 * If the AST structure has been resolved, and the function being invoked is | |
| 837 * known based on propagated type information, then return the parameter | |
| 838 * element representing the parameter to which the value of the right operand | |
| 839 * will be bound. Otherwise, return `null`. | |
| 840 */ | |
| 841 @deprecated // Use "expression.propagatedParameterElement" | |
| 842 ParameterElement get propagatedParameterElementForRightHandSide { | |
| 843 return _propagatedParameterElementForRightHandSide; | |
| 844 } | |
| 845 | |
| 846 /** | |
| 847 * Return the expression used to compute the right hand side. | |
| 848 */ | |
| 849 Expression get rightHandSide => _rightHandSide; | |
| 850 | |
| 851 /** | |
| 852 * Set the expression used to compute the left hand side to the given | |
| 853 * [expression]. | |
| 854 */ | |
| 855 void set rightHandSide(Expression expression) { | |
| 856 _rightHandSide = _becomeParentOf(expression); | |
| 857 } | |
| 858 | |
| 859 /** | |
| 860 * If the AST structure has been resolved, and the function being invoked is | |
| 861 * known based on static type information, then return the parameter element | |
| 862 * representing the parameter to which the value of the right operand will be | |
| 863 * bound. Otherwise, return `null`. | |
| 864 */ | |
| 865 @deprecated // Use "expression.staticParameterElement" | |
| 866 ParameterElement get staticParameterElementForRightHandSide { | |
| 867 return _staticParameterElementForRightHandSide; | |
| 868 } | |
| 869 | |
| 870 /** | |
| 871 * If the AST structure has been resolved, and the function being invoked is | |
| 872 * known based on propagated type information, then return the parameter | |
| 873 * element representing the parameter to which the value of the right operand | |
| 874 * will be bound. Otherwise, return `null`. | |
| 875 */ | |
| 876 ParameterElement get _propagatedParameterElementForRightHandSide { | |
| 877 ExecutableElement executableElement = null; | |
| 878 if (propagatedElement != null) { | |
| 879 executableElement = propagatedElement; | |
| 880 } else { | |
| 881 if (_leftHandSide is Identifier) { | |
| 882 Identifier identifier = _leftHandSide as Identifier; | |
| 883 Element leftElement = identifier.propagatedElement; | |
| 884 if (leftElement is ExecutableElement) { | |
| 885 executableElement = leftElement; | |
| 886 } | |
| 887 } | |
| 888 if (_leftHandSide is PropertyAccess) { | |
| 889 SimpleIdentifier identifier = | |
| 890 (_leftHandSide as PropertyAccess).propertyName; | |
| 891 Element leftElement = identifier.propagatedElement; | |
| 892 if (leftElement is ExecutableElement) { | |
| 893 executableElement = leftElement; | |
| 894 } | |
| 895 } | |
| 896 } | |
| 897 if (executableElement == null) { | |
| 898 return null; | |
| 899 } | |
| 900 List<ParameterElement> parameters = executableElement.parameters; | |
| 901 if (parameters.length < 1) { | |
| 902 return null; | |
| 903 } | |
| 904 return parameters[0]; | |
| 905 } | |
| 906 | |
| 907 /** | |
| 908 * If the AST structure has been resolved, and the function being invoked is | |
| 909 * known based on static type information, then return the parameter element | |
| 910 * representing the parameter to which the value of the right operand will be | |
| 911 * bound. Otherwise, return `null`. | |
| 912 */ | |
| 913 ParameterElement get _staticParameterElementForRightHandSide { | |
| 914 ExecutableElement executableElement = null; | |
| 915 if (staticElement != null) { | |
| 916 executableElement = staticElement; | |
| 917 } else { | |
| 918 if (_leftHandSide is Identifier) { | |
| 919 Element leftElement = (_leftHandSide as Identifier).staticElement; | |
| 920 if (leftElement is ExecutableElement) { | |
| 921 executableElement = leftElement; | |
| 922 } | |
| 923 } | |
| 924 if (_leftHandSide is PropertyAccess) { | |
| 925 Element leftElement = | |
| 926 (_leftHandSide as PropertyAccess).propertyName.staticElement; | |
| 927 if (leftElement is ExecutableElement) { | |
| 928 executableElement = leftElement; | |
| 929 } | |
| 930 } | |
| 931 } | |
| 932 if (executableElement == null) { | |
| 933 return null; | |
| 934 } | |
| 935 List<ParameterElement> parameters = executableElement.parameters; | |
| 936 if (parameters.length < 1) { | |
| 937 return null; | |
| 938 } | |
| 939 return parameters[0]; | |
| 940 } | |
| 941 | |
| 942 @override | |
| 943 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this); | |
| 944 | |
| 945 @override | |
| 946 void visitChildren(AstVisitor visitor) { | |
| 947 _safelyVisitChild(_leftHandSide, visitor); | |
| 948 _safelyVisitChild(_rightHandSide, visitor); | |
| 949 } | |
| 950 } | |
| 951 | |
| 952 /** | |
| 953 * An AST visitor that will clone any AST structure that it visits. The cloner | |
| 954 * will only clone the structure, it will not preserve any resolution results or | |
| 955 * properties associated with the nodes. | |
| 956 */ | |
| 957 class AstCloner implements AstVisitor<AstNode> { | |
| 958 /** | |
| 959 * A flag indicating whether tokens should be cloned while cloning an AST | |
| 960 * structure. | |
| 961 */ | |
| 962 final bool cloneTokens; | |
| 963 | |
| 964 /** | |
| 965 * Initialize a newly created AST cloner to optionally clone tokens while | |
| 966 * cloning AST nodes if [cloneTokens] is `true`. | |
| 967 */ | |
| 968 AstCloner( | |
| 969 [this.cloneTokens = false]); // TODO(brianwilkerson) Change this to be a n
amed parameter. | |
| 970 | |
| 971 /** | |
| 972 * Return a clone of the given [node]. | |
| 973 */ | |
| 974 AstNode cloneNode(AstNode node) { | |
| 975 if (node == null) { | |
| 976 return null; | |
| 977 } | |
| 978 return node.accept(this) as AstNode; | |
| 979 } | |
| 980 | |
| 981 /** | |
| 982 * Return a list containing cloned versions of the nodes in the given list of | |
| 983 * [nodes]. | |
| 984 */ | |
| 985 List<AstNode> cloneNodeList(NodeList nodes) { | |
| 986 int count = nodes.length; | |
| 987 List clonedNodes = new List(); | |
| 988 for (int i = 0; i < count; i++) { | |
| 989 clonedNodes.add((nodes[i]).accept(this) as AstNode); | |
| 990 } | |
| 991 return clonedNodes; | |
| 992 } | |
| 993 | |
| 994 /** | |
| 995 * Clone the given [token] if tokens are supposed to be cloned. | |
| 996 */ | |
| 997 Token cloneToken(Token token) { | |
| 998 if (cloneTokens) { | |
| 999 return (token == null ? null : token.copy()); | |
| 1000 } else { | |
| 1001 return token; | |
| 1002 } | |
| 1003 } | |
| 1004 | |
| 1005 /** | |
| 1006 * Clone the given [tokens] if tokens are supposed to be cloned. | |
| 1007 */ | |
| 1008 List<Token> cloneTokenList(List<Token> tokens) { | |
| 1009 if (cloneTokens) { | |
| 1010 return tokens.map((Token token) => token.copy()).toList(); | |
| 1011 } | |
| 1012 return tokens; | |
| 1013 } | |
| 1014 | |
| 1015 @override | |
| 1016 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) => | |
| 1017 new AdjacentStrings(cloneNodeList(node.strings)); | |
| 1018 | |
| 1019 @override | |
| 1020 Annotation visitAnnotation(Annotation node) => new Annotation( | |
| 1021 cloneToken(node.atSign), cloneNode(node.name), cloneToken(node.period), | |
| 1022 cloneNode(node.constructorName), cloneNode(node.arguments)); | |
| 1023 | |
| 1024 @override | |
| 1025 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList( | |
| 1026 cloneToken(node.leftParenthesis), cloneNodeList(node.arguments), | |
| 1027 cloneToken(node.rightParenthesis)); | |
| 1028 | |
| 1029 @override | |
| 1030 AsExpression visitAsExpression(AsExpression node) => new AsExpression( | |
| 1031 cloneNode(node.expression), cloneToken(node.asOperator), | |
| 1032 cloneNode(node.type)); | |
| 1033 | |
| 1034 @override | |
| 1035 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement( | |
| 1036 cloneToken(node.assertKeyword), cloneToken(node.leftParenthesis), | |
| 1037 cloneNode(node.condition), cloneToken(node.rightParenthesis), | |
| 1038 cloneToken(node.semicolon)); | |
| 1039 | |
| 1040 @override | |
| 1041 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) => | |
| 1042 new AssignmentExpression(cloneNode(node.leftHandSide), | |
| 1043 cloneToken(node.operator), cloneNode(node.rightHandSide)); | |
| 1044 | |
| 1045 @override | |
| 1046 AwaitExpression visitAwaitExpression(AwaitExpression node) => | |
| 1047 new AwaitExpression( | |
| 1048 cloneToken(node.awaitKeyword), cloneNode(node.expression)); | |
| 1049 | |
| 1050 @override | |
| 1051 BinaryExpression visitBinaryExpression(BinaryExpression node) => | |
| 1052 new BinaryExpression(cloneNode(node.leftOperand), | |
| 1053 cloneToken(node.operator), cloneNode(node.rightOperand)); | |
| 1054 | |
| 1055 @override | |
| 1056 Block visitBlock(Block node) => new Block(cloneToken(node.leftBracket), | |
| 1057 cloneNodeList(node.statements), cloneToken(node.rightBracket)); | |
| 1058 | |
| 1059 @override | |
| 1060 BlockFunctionBody visitBlockFunctionBody( | |
| 1061 BlockFunctionBody node) => new BlockFunctionBody( | |
| 1062 cloneToken(node.keyword), cloneToken(node.star), cloneNode(node.block)); | |
| 1063 | |
| 1064 @override | |
| 1065 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) => | |
| 1066 new BooleanLiteral(cloneToken(node.literal), node.value); | |
| 1067 | |
| 1068 @override | |
| 1069 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement( | |
| 1070 cloneToken(node.breakKeyword), cloneNode(node.label), | |
| 1071 cloneToken(node.semicolon)); | |
| 1072 | |
| 1073 @override | |
| 1074 CascadeExpression visitCascadeExpression(CascadeExpression node) => | |
| 1075 new CascadeExpression( | |
| 1076 cloneNode(node.target), cloneNodeList(node.cascadeSections)); | |
| 1077 | |
| 1078 @override | |
| 1079 CatchClause visitCatchClause(CatchClause node) => new CatchClause( | |
| 1080 cloneToken(node.onKeyword), cloneNode(node.exceptionType), | |
| 1081 cloneToken(node.catchKeyword), cloneToken(node.leftParenthesis), | |
| 1082 cloneNode(node.exceptionParameter), cloneToken(node.comma), | |
| 1083 cloneNode(node.stackTraceParameter), cloneToken(node.rightParenthesis), | |
| 1084 cloneNode(node.body)); | |
| 1085 | |
| 1086 @override | |
| 1087 ClassDeclaration visitClassDeclaration(ClassDeclaration node) { | |
| 1088 ClassDeclaration copy = new ClassDeclaration( | |
| 1089 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1090 cloneToken(node.abstractKeyword), cloneToken(node.classKeyword), | |
| 1091 cloneNode(node.name), cloneNode(node.typeParameters), | |
| 1092 cloneNode(node.extendsClause), cloneNode(node.withClause), | |
| 1093 cloneNode(node.implementsClause), cloneToken(node.leftBracket), | |
| 1094 cloneNodeList(node.members), cloneToken(node.rightBracket)); | |
| 1095 copy.nativeClause = cloneNode(node.nativeClause); | |
| 1096 return copy; | |
| 1097 } | |
| 1098 | |
| 1099 @override | |
| 1100 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias( | |
| 1101 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1102 cloneToken(node.typedefKeyword), cloneNode(node.name), | |
| 1103 cloneNode(node.typeParameters), cloneToken(node.equals), | |
| 1104 cloneToken(node.abstractKeyword), cloneNode(node.superclass), | |
| 1105 cloneNode(node.withClause), cloneNode(node.implementsClause), | |
| 1106 cloneToken(node.semicolon)); | |
| 1107 | |
| 1108 @override | |
| 1109 Comment visitComment(Comment node) { | |
| 1110 if (node.isDocumentation) { | |
| 1111 return Comment.createDocumentationCommentWithReferences( | |
| 1112 cloneTokenList(node.tokens), cloneNodeList(node.references)); | |
| 1113 } else if (node.isBlock) { | |
| 1114 return Comment.createBlockComment(cloneTokenList(node.tokens)); | |
| 1115 } | |
| 1116 return Comment.createEndOfLineComment(cloneTokenList(node.tokens)); | |
| 1117 } | |
| 1118 | |
| 1119 @override | |
| 1120 CommentReference visitCommentReference(CommentReference node) => | |
| 1121 new CommentReference( | |
| 1122 cloneToken(node.newKeyword), cloneNode(node.identifier)); | |
| 1123 | |
| 1124 @override | |
| 1125 CompilationUnit visitCompilationUnit(CompilationUnit node) { | |
| 1126 CompilationUnit clone = new CompilationUnit(cloneToken(node.beginToken), | |
| 1127 cloneNode(node.scriptTag), cloneNodeList(node.directives), | |
| 1128 cloneNodeList(node.declarations), cloneToken(node.endToken)); | |
| 1129 clone.lineInfo = node.lineInfo; | |
| 1130 return clone; | |
| 1131 } | |
| 1132 | |
| 1133 @override | |
| 1134 ConditionalExpression visitConditionalExpression( | |
| 1135 ConditionalExpression node) => new ConditionalExpression( | |
| 1136 cloneNode(node.condition), cloneToken(node.question), | |
| 1137 cloneNode(node.thenExpression), cloneToken(node.colon), | |
| 1138 cloneNode(node.elseExpression)); | |
| 1139 | |
| 1140 @override | |
| 1141 ConstructorDeclaration visitConstructorDeclaration( | |
| 1142 ConstructorDeclaration node) => new ConstructorDeclaration( | |
| 1143 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1144 cloneToken(node.externalKeyword), cloneToken(node.constKeyword), | |
| 1145 cloneToken(node.factoryKeyword), cloneNode(node.returnType), | |
| 1146 cloneToken(node.period), cloneNode(node.name), cloneNode(node.parameters), | |
| 1147 cloneToken(node.separator), cloneNodeList(node.initializers), | |
| 1148 cloneNode(node.redirectedConstructor), cloneNode(node.body)); | |
| 1149 | |
| 1150 @override | |
| 1151 ConstructorFieldInitializer visitConstructorFieldInitializer( | |
| 1152 ConstructorFieldInitializer node) => new ConstructorFieldInitializer( | |
| 1153 cloneToken(node.thisKeyword), cloneToken(node.period), | |
| 1154 cloneNode(node.fieldName), cloneToken(node.equals), | |
| 1155 cloneNode(node.expression)); | |
| 1156 | |
| 1157 @override | |
| 1158 ConstructorName visitConstructorName(ConstructorName node) => | |
| 1159 new ConstructorName( | |
| 1160 cloneNode(node.type), cloneToken(node.period), cloneNode(node.name)); | |
| 1161 | |
| 1162 @override | |
| 1163 ContinueStatement visitContinueStatement(ContinueStatement node) => | |
| 1164 new ContinueStatement(cloneToken(node.continueKeyword), | |
| 1165 cloneNode(node.label), cloneToken(node.semicolon)); | |
| 1166 | |
| 1167 @override | |
| 1168 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) => | |
| 1169 new DeclaredIdentifier(cloneNode(node.documentationComment), | |
| 1170 cloneNodeList(node.metadata), cloneToken(node.keyword), | |
| 1171 cloneNode(node.type), cloneNode(node.identifier)); | |
| 1172 | |
| 1173 @override | |
| 1174 DefaultFormalParameter visitDefaultFormalParameter( | |
| 1175 DefaultFormalParameter node) => new DefaultFormalParameter( | |
| 1176 cloneNode(node.parameter), node.kind, cloneToken(node.separator), | |
| 1177 cloneNode(node.defaultValue)); | |
| 1178 | |
| 1179 @override | |
| 1180 DoStatement visitDoStatement(DoStatement node) => new DoStatement( | |
| 1181 cloneToken(node.doKeyword), cloneNode(node.body), | |
| 1182 cloneToken(node.whileKeyword), cloneToken(node.leftParenthesis), | |
| 1183 cloneNode(node.condition), cloneToken(node.rightParenthesis), | |
| 1184 cloneToken(node.semicolon)); | |
| 1185 | |
| 1186 @override | |
| 1187 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) => | |
| 1188 new DoubleLiteral(cloneToken(node.literal), node.value); | |
| 1189 | |
| 1190 @override | |
| 1191 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) => | |
| 1192 new EmptyFunctionBody(cloneToken(node.semicolon)); | |
| 1193 | |
| 1194 @override | |
| 1195 EmptyStatement visitEmptyStatement(EmptyStatement node) => | |
| 1196 new EmptyStatement(cloneToken(node.semicolon)); | |
| 1197 | |
| 1198 @override | |
| 1199 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) => | |
| 1200 new EnumConstantDeclaration(cloneNode(node.documentationComment), | |
| 1201 cloneNodeList(node.metadata), cloneNode(node.name)); | |
| 1202 | |
| 1203 @override | |
| 1204 EnumDeclaration visitEnumDeclaration(EnumDeclaration node) => | |
| 1205 new EnumDeclaration(cloneNode(node.documentationComment), | |
| 1206 cloneNodeList(node.metadata), cloneToken(node.enumKeyword), | |
| 1207 cloneNode(node.name), cloneToken(node.leftBracket), | |
| 1208 cloneNodeList(node.constants), cloneToken(node.rightBracket)); | |
| 1209 | |
| 1210 @override | |
| 1211 ExportDirective visitExportDirective(ExportDirective node) { | |
| 1212 ExportDirective directive = new ExportDirective( | |
| 1213 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1214 cloneToken(node.keyword), cloneNode(node.uri), | |
| 1215 cloneNodeList(node.combinators), cloneToken(node.semicolon)); | |
| 1216 directive.source = node.source; | |
| 1217 directive.uriContent = node.uriContent; | |
| 1218 return directive; | |
| 1219 } | |
| 1220 | |
| 1221 @override | |
| 1222 ExpressionFunctionBody visitExpressionFunctionBody( | |
| 1223 ExpressionFunctionBody node) => new ExpressionFunctionBody( | |
| 1224 cloneToken(node.keyword), cloneToken(node.functionDefinition), | |
| 1225 cloneNode(node.expression), cloneToken(node.semicolon)); | |
| 1226 | |
| 1227 @override | |
| 1228 ExpressionStatement visitExpressionStatement(ExpressionStatement node) => | |
| 1229 new ExpressionStatement( | |
| 1230 cloneNode(node.expression), cloneToken(node.semicolon)); | |
| 1231 | |
| 1232 @override | |
| 1233 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause( | |
| 1234 cloneToken(node.extendsKeyword), cloneNode(node.superclass)); | |
| 1235 | |
| 1236 @override | |
| 1237 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) => | |
| 1238 new FieldDeclaration(cloneNode(node.documentationComment), | |
| 1239 cloneNodeList(node.metadata), cloneToken(node.staticKeyword), | |
| 1240 cloneNode(node.fields), cloneToken(node.semicolon)); | |
| 1241 | |
| 1242 @override | |
| 1243 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) => | |
| 1244 new FieldFormalParameter(cloneNode(node.documentationComment), | |
| 1245 cloneNodeList(node.metadata), cloneToken(node.keyword), | |
| 1246 cloneNode(node.type), cloneToken(node.thisKeyword), | |
| 1247 cloneToken(node.period), cloneNode(node.identifier), | |
| 1248 cloneNode(node.typeParameters), cloneNode(node.parameters)); | |
| 1249 | |
| 1250 @override | |
| 1251 ForEachStatement visitForEachStatement(ForEachStatement node) { | |
| 1252 DeclaredIdentifier loopVariable = node.loopVariable; | |
| 1253 if (loopVariable == null) { | |
| 1254 return new ForEachStatement.withReference(cloneToken(node.awaitKeyword), | |
| 1255 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis), | |
| 1256 cloneNode(node.identifier), cloneToken(node.inKeyword), | |
| 1257 cloneNode(node.iterable), cloneToken(node.rightParenthesis), | |
| 1258 cloneNode(node.body)); | |
| 1259 } | |
| 1260 return new ForEachStatement.withDeclaration(cloneToken(node.awaitKeyword), | |
| 1261 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis), | |
| 1262 cloneNode(loopVariable), cloneToken(node.inKeyword), | |
| 1263 cloneNode(node.iterable), cloneToken(node.rightParenthesis), | |
| 1264 cloneNode(node.body)); | |
| 1265 } | |
| 1266 | |
| 1267 @override | |
| 1268 FormalParameterList visitFormalParameterList(FormalParameterList node) => | |
| 1269 new FormalParameterList(cloneToken(node.leftParenthesis), | |
| 1270 cloneNodeList(node.parameters), cloneToken(node.leftDelimiter), | |
| 1271 cloneToken(node.rightDelimiter), cloneToken(node.rightParenthesis)); | |
| 1272 | |
| 1273 @override | |
| 1274 ForStatement visitForStatement(ForStatement node) => new ForStatement( | |
| 1275 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis), | |
| 1276 cloneNode(node.variables), cloneNode(node.initialization), | |
| 1277 cloneToken(node.leftSeparator), cloneNode(node.condition), | |
| 1278 cloneToken(node.rightSeparator), cloneNodeList(node.updaters), | |
| 1279 cloneToken(node.rightParenthesis), cloneNode(node.body)); | |
| 1280 | |
| 1281 @override | |
| 1282 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) => | |
| 1283 new FunctionDeclaration(cloneNode(node.documentationComment), | |
| 1284 cloneNodeList(node.metadata), cloneToken(node.externalKeyword), | |
| 1285 cloneNode(node.returnType), cloneToken(node.propertyKeyword), | |
| 1286 cloneNode(node.name), cloneNode(node.functionExpression)); | |
| 1287 | |
| 1288 @override | |
| 1289 FunctionDeclarationStatement visitFunctionDeclarationStatement( | |
| 1290 FunctionDeclarationStatement node) => | |
| 1291 new FunctionDeclarationStatement(cloneNode(node.functionDeclaration)); | |
| 1292 | |
| 1293 @override | |
| 1294 FunctionExpression visitFunctionExpression(FunctionExpression node) => | |
| 1295 new FunctionExpression(cloneNode(node.typeParameters), | |
| 1296 cloneNode(node.parameters), cloneNode(node.body)); | |
| 1297 | |
| 1298 @override | |
| 1299 FunctionExpressionInvocation visitFunctionExpressionInvocation( | |
| 1300 FunctionExpressionInvocation node) => new FunctionExpressionInvocation( | |
| 1301 cloneNode(node.function), cloneNode(node.typeArguments), | |
| 1302 cloneNode(node.argumentList)); | |
| 1303 | |
| 1304 @override | |
| 1305 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) => | |
| 1306 new FunctionTypeAlias(cloneNode(node.documentationComment), | |
| 1307 cloneNodeList(node.metadata), cloneToken(node.typedefKeyword), | |
| 1308 cloneNode(node.returnType), cloneNode(node.name), | |
| 1309 cloneNode(node.typeParameters), cloneNode(node.parameters), | |
| 1310 cloneToken(node.semicolon)); | |
| 1311 | |
| 1312 @override | |
| 1313 FunctionTypedFormalParameter visitFunctionTypedFormalParameter( | |
| 1314 FunctionTypedFormalParameter node) => new FunctionTypedFormalParameter( | |
| 1315 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1316 cloneNode(node.returnType), cloneNode(node.identifier), | |
| 1317 cloneNode(node.typeParameters), cloneNode(node.parameters)); | |
| 1318 | |
| 1319 @override | |
| 1320 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator( | |
| 1321 cloneToken(node.keyword), cloneNodeList(node.hiddenNames)); | |
| 1322 | |
| 1323 @override | |
| 1324 IfStatement visitIfStatement(IfStatement node) => new IfStatement( | |
| 1325 cloneToken(node.ifKeyword), cloneToken(node.leftParenthesis), | |
| 1326 cloneNode(node.condition), cloneToken(node.rightParenthesis), | |
| 1327 cloneNode(node.thenStatement), cloneToken(node.elseKeyword), | |
| 1328 cloneNode(node.elseStatement)); | |
| 1329 | |
| 1330 @override | |
| 1331 ImplementsClause visitImplementsClause(ImplementsClause node) => | |
| 1332 new ImplementsClause( | |
| 1333 cloneToken(node.implementsKeyword), cloneNodeList(node.interfaces)); | |
| 1334 | |
| 1335 @override | |
| 1336 ImportDirective visitImportDirective(ImportDirective node) { | |
| 1337 ImportDirective directive = new ImportDirective( | |
| 1338 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1339 cloneToken(node.keyword), cloneNode(node.uri), | |
| 1340 cloneToken(node.deferredKeyword), cloneToken(node.asKeyword), | |
| 1341 cloneNode(node.prefix), cloneNodeList(node.combinators), | |
| 1342 cloneToken(node.semicolon)); | |
| 1343 directive.source = node.source; | |
| 1344 directive.uriContent = node.uriContent; | |
| 1345 return directive; | |
| 1346 } | |
| 1347 | |
| 1348 @override | |
| 1349 IndexExpression visitIndexExpression(IndexExpression node) { | |
| 1350 Token period = node.period; | |
| 1351 if (period == null) { | |
| 1352 return new IndexExpression.forTarget(cloneNode(node.target), | |
| 1353 cloneToken(node.leftBracket), cloneNode(node.index), | |
| 1354 cloneToken(node.rightBracket)); | |
| 1355 } else { | |
| 1356 return new IndexExpression.forCascade(cloneToken(period), | |
| 1357 cloneToken(node.leftBracket), cloneNode(node.index), | |
| 1358 cloneToken(node.rightBracket)); | |
| 1359 } | |
| 1360 } | |
| 1361 | |
| 1362 @override | |
| 1363 InstanceCreationExpression visitInstanceCreationExpression( | |
| 1364 InstanceCreationExpression node) => new InstanceCreationExpression( | |
| 1365 cloneToken(node.keyword), cloneNode(node.constructorName), | |
| 1366 cloneNode(node.argumentList)); | |
| 1367 | |
| 1368 @override | |
| 1369 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) => | |
| 1370 new IntegerLiteral(cloneToken(node.literal), node.value); | |
| 1371 | |
| 1372 @override | |
| 1373 InterpolationExpression visitInterpolationExpression( | |
| 1374 InterpolationExpression node) => new InterpolationExpression( | |
| 1375 cloneToken(node.leftBracket), cloneNode(node.expression), | |
| 1376 cloneToken(node.rightBracket)); | |
| 1377 | |
| 1378 @override | |
| 1379 InterpolationString visitInterpolationString(InterpolationString node) => | |
| 1380 new InterpolationString(cloneToken(node.contents), node.value); | |
| 1381 | |
| 1382 @override | |
| 1383 IsExpression visitIsExpression(IsExpression node) => new IsExpression( | |
| 1384 cloneNode(node.expression), cloneToken(node.isOperator), | |
| 1385 cloneToken(node.notOperator), cloneNode(node.type)); | |
| 1386 | |
| 1387 @override | |
| 1388 Label visitLabel(Label node) => | |
| 1389 new Label(cloneNode(node.label), cloneToken(node.colon)); | |
| 1390 | |
| 1391 @override | |
| 1392 LabeledStatement visitLabeledStatement(LabeledStatement node) => | |
| 1393 new LabeledStatement( | |
| 1394 cloneNodeList(node.labels), cloneNode(node.statement)); | |
| 1395 | |
| 1396 @override | |
| 1397 LibraryDirective visitLibraryDirective(LibraryDirective node) => | |
| 1398 new LibraryDirective(cloneNode(node.documentationComment), | |
| 1399 cloneNodeList(node.metadata), cloneToken(node.libraryKeyword), | |
| 1400 cloneNode(node.name), cloneToken(node.semicolon)); | |
| 1401 | |
| 1402 @override | |
| 1403 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) => | |
| 1404 new LibraryIdentifier(cloneNodeList(node.components)); | |
| 1405 | |
| 1406 @override | |
| 1407 ListLiteral visitListLiteral(ListLiteral node) => new ListLiteral( | |
| 1408 cloneToken(node.constKeyword), cloneNode(node.typeArguments), | |
| 1409 cloneToken(node.leftBracket), cloneNodeList(node.elements), | |
| 1410 cloneToken(node.rightBracket)); | |
| 1411 | |
| 1412 @override | |
| 1413 MapLiteral visitMapLiteral(MapLiteral node) => new MapLiteral( | |
| 1414 cloneToken(node.constKeyword), cloneNode(node.typeArguments), | |
| 1415 cloneToken(node.leftBracket), cloneNodeList(node.entries), | |
| 1416 cloneToken(node.rightBracket)); | |
| 1417 | |
| 1418 @override | |
| 1419 MapLiteralEntry visitMapLiteralEntry( | |
| 1420 MapLiteralEntry node) => new MapLiteralEntry( | |
| 1421 cloneNode(node.key), cloneToken(node.separator), cloneNode(node.value)); | |
| 1422 | |
| 1423 @override | |
| 1424 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) => | |
| 1425 new MethodDeclaration(cloneNode(node.documentationComment), | |
| 1426 cloneNodeList(node.metadata), cloneToken(node.externalKeyword), | |
| 1427 cloneToken(node.modifierKeyword), cloneNode(node.returnType), | |
| 1428 cloneToken(node.propertyKeyword), cloneToken(node.operatorKeyword), | |
| 1429 cloneNode(node.name), cloneNode(node.typeParameters), | |
| 1430 cloneNode(node.parameters), cloneNode(node.body)); | |
| 1431 | |
| 1432 @override | |
| 1433 MethodInvocation visitMethodInvocation(MethodInvocation node) => | |
| 1434 new MethodInvocation(cloneNode(node.target), cloneToken(node.operator), | |
| 1435 cloneNode(node.methodName), cloneNode(node.typeArguments), | |
| 1436 cloneNode(node.argumentList)); | |
| 1437 | |
| 1438 @override | |
| 1439 NamedExpression visitNamedExpression(NamedExpression node) => | |
| 1440 new NamedExpression(cloneNode(node.name), cloneNode(node.expression)); | |
| 1441 | |
| 1442 @override | |
| 1443 AstNode visitNativeClause(NativeClause node) => | |
| 1444 new NativeClause(cloneToken(node.nativeKeyword), cloneNode(node.name)); | |
| 1445 | |
| 1446 @override | |
| 1447 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) => | |
| 1448 new NativeFunctionBody(cloneToken(node.nativeKeyword), | |
| 1449 cloneNode(node.stringLiteral), cloneToken(node.semicolon)); | |
| 1450 | |
| 1451 @override | |
| 1452 NullLiteral visitNullLiteral(NullLiteral node) => | |
| 1453 new NullLiteral(cloneToken(node.literal)); | |
| 1454 | |
| 1455 @override | |
| 1456 ParenthesizedExpression visitParenthesizedExpression( | |
| 1457 ParenthesizedExpression node) => new ParenthesizedExpression( | |
| 1458 cloneToken(node.leftParenthesis), cloneNode(node.expression), | |
| 1459 cloneToken(node.rightParenthesis)); | |
| 1460 | |
| 1461 @override | |
| 1462 PartDirective visitPartDirective(PartDirective node) { | |
| 1463 PartDirective directive = new PartDirective( | |
| 1464 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1465 cloneToken(node.partKeyword), cloneNode(node.uri), | |
| 1466 cloneToken(node.semicolon)); | |
| 1467 directive.source = node.source; | |
| 1468 directive.uriContent = node.uriContent; | |
| 1469 return directive; | |
| 1470 } | |
| 1471 | |
| 1472 @override | |
| 1473 PartOfDirective visitPartOfDirective(PartOfDirective node) => | |
| 1474 new PartOfDirective(cloneNode(node.documentationComment), | |
| 1475 cloneNodeList(node.metadata), cloneToken(node.partKeyword), | |
| 1476 cloneToken(node.ofKeyword), cloneNode(node.libraryName), | |
| 1477 cloneToken(node.semicolon)); | |
| 1478 | |
| 1479 @override | |
| 1480 PostfixExpression visitPostfixExpression(PostfixExpression node) => | |
| 1481 new PostfixExpression(cloneNode(node.operand), cloneToken(node.operator)); | |
| 1482 | |
| 1483 @override | |
| 1484 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) => | |
| 1485 new PrefixedIdentifier(cloneNode(node.prefix), cloneToken(node.period), | |
| 1486 cloneNode(node.identifier)); | |
| 1487 | |
| 1488 @override | |
| 1489 PrefixExpression visitPrefixExpression(PrefixExpression node) => | |
| 1490 new PrefixExpression(cloneToken(node.operator), cloneNode(node.operand)); | |
| 1491 | |
| 1492 @override | |
| 1493 PropertyAccess visitPropertyAccess(PropertyAccess node) => new PropertyAccess( | |
| 1494 cloneNode(node.target), cloneToken(node.operator), | |
| 1495 cloneNode(node.propertyName)); | |
| 1496 | |
| 1497 @override | |
| 1498 RedirectingConstructorInvocation visitRedirectingConstructorInvocation( | |
| 1499 RedirectingConstructorInvocation node) => | |
| 1500 new RedirectingConstructorInvocation(cloneToken(node.thisKeyword), | |
| 1501 cloneToken(node.period), cloneNode(node.constructorName), | |
| 1502 cloneNode(node.argumentList)); | |
| 1503 | |
| 1504 @override | |
| 1505 RethrowExpression visitRethrowExpression(RethrowExpression node) => | |
| 1506 new RethrowExpression(cloneToken(node.rethrowKeyword)); | |
| 1507 | |
| 1508 @override | |
| 1509 ReturnStatement visitReturnStatement(ReturnStatement node) => | |
| 1510 new ReturnStatement(cloneToken(node.returnKeyword), | |
| 1511 cloneNode(node.expression), cloneToken(node.semicolon)); | |
| 1512 | |
| 1513 @override | |
| 1514 ScriptTag visitScriptTag(ScriptTag node) => | |
| 1515 new ScriptTag(cloneToken(node.scriptTag)); | |
| 1516 | |
| 1517 @override | |
| 1518 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator( | |
| 1519 cloneToken(node.keyword), cloneNodeList(node.shownNames)); | |
| 1520 | |
| 1521 @override | |
| 1522 SimpleFormalParameter visitSimpleFormalParameter( | |
| 1523 SimpleFormalParameter node) => new SimpleFormalParameter( | |
| 1524 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1525 cloneToken(node.keyword), cloneNode(node.type), | |
| 1526 cloneNode(node.identifier)); | |
| 1527 | |
| 1528 @override | |
| 1529 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) => | |
| 1530 new SimpleIdentifier(cloneToken(node.token)); | |
| 1531 | |
| 1532 @override | |
| 1533 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) => | |
| 1534 new SimpleStringLiteral(cloneToken(node.literal), node.value); | |
| 1535 | |
| 1536 @override | |
| 1537 StringInterpolation visitStringInterpolation(StringInterpolation node) => | |
| 1538 new StringInterpolation(cloneNodeList(node.elements)); | |
| 1539 | |
| 1540 @override | |
| 1541 SuperConstructorInvocation visitSuperConstructorInvocation( | |
| 1542 SuperConstructorInvocation node) => new SuperConstructorInvocation( | |
| 1543 cloneToken(node.superKeyword), cloneToken(node.period), | |
| 1544 cloneNode(node.constructorName), cloneNode(node.argumentList)); | |
| 1545 | |
| 1546 @override | |
| 1547 SuperExpression visitSuperExpression(SuperExpression node) => | |
| 1548 new SuperExpression(cloneToken(node.superKeyword)); | |
| 1549 | |
| 1550 @override | |
| 1551 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase( | |
| 1552 cloneNodeList(node.labels), cloneToken(node.keyword), | |
| 1553 cloneNode(node.expression), cloneToken(node.colon), | |
| 1554 cloneNodeList(node.statements)); | |
| 1555 | |
| 1556 @override | |
| 1557 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault( | |
| 1558 cloneNodeList(node.labels), cloneToken(node.keyword), | |
| 1559 cloneToken(node.colon), cloneNodeList(node.statements)); | |
| 1560 | |
| 1561 @override | |
| 1562 SwitchStatement visitSwitchStatement(SwitchStatement node) => | |
| 1563 new SwitchStatement(cloneToken(node.switchKeyword), | |
| 1564 cloneToken(node.leftParenthesis), cloneNode(node.expression), | |
| 1565 cloneToken(node.rightParenthesis), cloneToken(node.leftBracket), | |
| 1566 cloneNodeList(node.members), cloneToken(node.rightBracket)); | |
| 1567 | |
| 1568 @override | |
| 1569 SymbolLiteral visitSymbolLiteral(SymbolLiteral node) => new SymbolLiteral( | |
| 1570 cloneToken(node.poundSign), cloneTokenList(node.components)); | |
| 1571 | |
| 1572 @override | |
| 1573 ThisExpression visitThisExpression(ThisExpression node) => | |
| 1574 new ThisExpression(cloneToken(node.thisKeyword)); | |
| 1575 | |
| 1576 @override | |
| 1577 ThrowExpression visitThrowExpression(ThrowExpression node) => | |
| 1578 new ThrowExpression( | |
| 1579 cloneToken(node.throwKeyword), cloneNode(node.expression)); | |
| 1580 | |
| 1581 @override | |
| 1582 TopLevelVariableDeclaration visitTopLevelVariableDeclaration( | |
| 1583 TopLevelVariableDeclaration node) => new TopLevelVariableDeclaration( | |
| 1584 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1585 cloneNode(node.variables), cloneToken(node.semicolon)); | |
| 1586 | |
| 1587 @override | |
| 1588 TryStatement visitTryStatement(TryStatement node) => new TryStatement( | |
| 1589 cloneToken(node.tryKeyword), cloneNode(node.body), | |
| 1590 cloneNodeList(node.catchClauses), cloneToken(node.finallyKeyword), | |
| 1591 cloneNode(node.finallyBlock)); | |
| 1592 | |
| 1593 @override | |
| 1594 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) => | |
| 1595 new TypeArgumentList(cloneToken(node.leftBracket), | |
| 1596 cloneNodeList(node.arguments), cloneToken(node.rightBracket)); | |
| 1597 | |
| 1598 @override | |
| 1599 TypeName visitTypeName(TypeName node) => | |
| 1600 new TypeName(cloneNode(node.name), cloneNode(node.typeArguments)); | |
| 1601 | |
| 1602 @override | |
| 1603 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter( | |
| 1604 cloneNode(node.documentationComment), cloneNodeList(node.metadata), | |
| 1605 cloneNode(node.name), cloneToken(node.extendsKeyword), | |
| 1606 cloneNode(node.bound)); | |
| 1607 | |
| 1608 @override | |
| 1609 TypeParameterList visitTypeParameterList(TypeParameterList node) => | |
| 1610 new TypeParameterList(cloneToken(node.leftBracket), | |
| 1611 cloneNodeList(node.typeParameters), cloneToken(node.rightBracket)); | |
| 1612 | |
| 1613 @override | |
| 1614 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) => | |
| 1615 new VariableDeclaration(cloneNode(node.name), cloneToken(node.equals), | |
| 1616 cloneNode(node.initializer)); | |
| 1617 | |
| 1618 @override | |
| 1619 VariableDeclarationList visitVariableDeclarationList( | |
| 1620 VariableDeclarationList node) => new VariableDeclarationList(null, | |
| 1621 cloneNodeList(node.metadata), cloneToken(node.keyword), | |
| 1622 cloneNode(node.type), cloneNodeList(node.variables)); | |
| 1623 | |
| 1624 @override | |
| 1625 VariableDeclarationStatement visitVariableDeclarationStatement( | |
| 1626 VariableDeclarationStatement node) => new VariableDeclarationStatement( | |
| 1627 cloneNode(node.variables), cloneToken(node.semicolon)); | |
| 1628 | |
| 1629 @override | |
| 1630 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement( | |
| 1631 cloneToken(node.whileKeyword), cloneToken(node.leftParenthesis), | |
| 1632 cloneNode(node.condition), cloneToken(node.rightParenthesis), | |
| 1633 cloneNode(node.body)); | |
| 1634 | |
| 1635 @override | |
| 1636 WithClause visitWithClause(WithClause node) => new WithClause( | |
| 1637 cloneToken(node.withKeyword), cloneNodeList(node.mixinTypes)); | |
| 1638 | |
| 1639 @override | |
| 1640 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement( | |
| 1641 cloneToken(node.yieldKeyword), cloneToken(node.star), | |
| 1642 cloneNode(node.expression), cloneToken(node.semicolon)); | |
| 1643 | |
| 1644 /** | |
| 1645 * Return a clone of the given [node]. | |
| 1646 */ | |
| 1647 static AstNode clone(AstNode node) { | |
| 1648 return node.accept(new AstCloner()); | |
| 1649 } | |
| 1650 } | |
| 1651 | |
| 1652 /** | |
| 1653 * An AstVisitor that compares the structure of two AstNodes to see whether they | |
| 1654 * are equal. | |
| 1655 */ | |
| 1656 class AstComparator implements AstVisitor<bool> { | |
| 1657 /** | |
| 1658 * The AST node with which the node being visited is to be compared. This is | |
| 1659 * only valid at the beginning of each visit method (until [isEqualNodes] is | |
| 1660 * invoked). | |
| 1661 */ | |
| 1662 AstNode _other; | |
| 1663 | |
| 1664 /** | |
| 1665 * Return `true` if the [first] node and the [second] node have the same | |
| 1666 * structure. | |
| 1667 * | |
| 1668 * *Note:* This method is only visible for testing purposes and should not be | |
| 1669 * used by clients. | |
| 1670 */ | |
| 1671 bool isEqualNodes(AstNode first, AstNode second) { | |
| 1672 if (first == null) { | |
| 1673 return second == null; | |
| 1674 } else if (second == null) { | |
| 1675 return false; | |
| 1676 } else if (first.runtimeType != second.runtimeType) { | |
| 1677 return false; | |
| 1678 } | |
| 1679 _other = second; | |
| 1680 return first.accept(this); | |
| 1681 } | |
| 1682 | |
| 1683 /** | |
| 1684 * Return `true` if the [first] token and the [second] token have the same | |
| 1685 * structure. | |
| 1686 * | |
| 1687 * *Note:* This method is only visible for testing purposes and should not be | |
| 1688 * used by clients. | |
| 1689 */ | |
| 1690 bool isEqualTokens(Token first, Token second) { | |
| 1691 if (first == null) { | |
| 1692 return second == null; | |
| 1693 } else if (second == null) { | |
| 1694 return false; | |
| 1695 } else if (identical(first, second)) { | |
| 1696 return true; | |
| 1697 } | |
| 1698 return first.offset == second.offset && | |
| 1699 first.length == second.length && | |
| 1700 first.lexeme == second.lexeme; | |
| 1701 } | |
| 1702 | |
| 1703 @override | |
| 1704 bool visitAdjacentStrings(AdjacentStrings node) { | |
| 1705 AdjacentStrings other = _other as AdjacentStrings; | |
| 1706 return _isEqualNodeLists(node.strings, other.strings); | |
| 1707 } | |
| 1708 | |
| 1709 @override | |
| 1710 bool visitAnnotation(Annotation node) { | |
| 1711 Annotation other = _other as Annotation; | |
| 1712 return isEqualTokens(node.atSign, other.atSign) && | |
| 1713 isEqualNodes(node.name, other.name) && | |
| 1714 isEqualTokens(node.period, other.period) && | |
| 1715 isEqualNodes(node.constructorName, other.constructorName) && | |
| 1716 isEqualNodes(node.arguments, other.arguments); | |
| 1717 } | |
| 1718 | |
| 1719 @override | |
| 1720 bool visitArgumentList(ArgumentList node) { | |
| 1721 ArgumentList other = _other as ArgumentList; | |
| 1722 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 1723 _isEqualNodeLists(node.arguments, other.arguments) && | |
| 1724 isEqualTokens(node.rightParenthesis, other.rightParenthesis); | |
| 1725 } | |
| 1726 | |
| 1727 @override | |
| 1728 bool visitAsExpression(AsExpression node) { | |
| 1729 AsExpression other = _other as AsExpression; | |
| 1730 return isEqualNodes(node.expression, other.expression) && | |
| 1731 isEqualTokens(node.asOperator, other.asOperator) && | |
| 1732 isEqualNodes(node.type, other.type); | |
| 1733 } | |
| 1734 | |
| 1735 @override | |
| 1736 bool visitAssertStatement(AssertStatement node) { | |
| 1737 AssertStatement other = _other as AssertStatement; | |
| 1738 return isEqualTokens(node.assertKeyword, other.assertKeyword) && | |
| 1739 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 1740 isEqualNodes(node.condition, other.condition) && | |
| 1741 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 1742 isEqualTokens(node.semicolon, other.semicolon); | |
| 1743 } | |
| 1744 | |
| 1745 @override | |
| 1746 bool visitAssignmentExpression(AssignmentExpression node) { | |
| 1747 AssignmentExpression other = _other as AssignmentExpression; | |
| 1748 return isEqualNodes(node.leftHandSide, other.leftHandSide) && | |
| 1749 isEqualTokens(node.operator, other.operator) && | |
| 1750 isEqualNodes(node.rightHandSide, other.rightHandSide); | |
| 1751 } | |
| 1752 | |
| 1753 @override | |
| 1754 bool visitAwaitExpression(AwaitExpression node) { | |
| 1755 AwaitExpression other = _other as AwaitExpression; | |
| 1756 return isEqualTokens(node.awaitKeyword, other.awaitKeyword) && | |
| 1757 isEqualNodes(node.expression, other.expression); | |
| 1758 } | |
| 1759 | |
| 1760 @override | |
| 1761 bool visitBinaryExpression(BinaryExpression node) { | |
| 1762 BinaryExpression other = _other as BinaryExpression; | |
| 1763 return isEqualNodes(node.leftOperand, other.leftOperand) && | |
| 1764 isEqualTokens(node.operator, other.operator) && | |
| 1765 isEqualNodes(node.rightOperand, other.rightOperand); | |
| 1766 } | |
| 1767 | |
| 1768 @override | |
| 1769 bool visitBlock(Block node) { | |
| 1770 Block other = _other as Block; | |
| 1771 return isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 1772 _isEqualNodeLists(node.statements, other.statements) && | |
| 1773 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 1774 } | |
| 1775 | |
| 1776 @override | |
| 1777 bool visitBlockFunctionBody(BlockFunctionBody node) { | |
| 1778 BlockFunctionBody other = _other as BlockFunctionBody; | |
| 1779 return isEqualNodes(node.block, other.block); | |
| 1780 } | |
| 1781 | |
| 1782 @override | |
| 1783 bool visitBooleanLiteral(BooleanLiteral node) { | |
| 1784 BooleanLiteral other = _other as BooleanLiteral; | |
| 1785 return isEqualTokens(node.literal, other.literal) && | |
| 1786 node.value == other.value; | |
| 1787 } | |
| 1788 | |
| 1789 @override | |
| 1790 bool visitBreakStatement(BreakStatement node) { | |
| 1791 BreakStatement other = _other as BreakStatement; | |
| 1792 return isEqualTokens(node.breakKeyword, other.breakKeyword) && | |
| 1793 isEqualNodes(node.label, other.label) && | |
| 1794 isEqualTokens(node.semicolon, other.semicolon); | |
| 1795 } | |
| 1796 | |
| 1797 @override | |
| 1798 bool visitCascadeExpression(CascadeExpression node) { | |
| 1799 CascadeExpression other = _other as CascadeExpression; | |
| 1800 return isEqualNodes(node.target, other.target) && | |
| 1801 _isEqualNodeLists(node.cascadeSections, other.cascadeSections); | |
| 1802 } | |
| 1803 | |
| 1804 @override | |
| 1805 bool visitCatchClause(CatchClause node) { | |
| 1806 CatchClause other = _other as CatchClause; | |
| 1807 return isEqualTokens(node.onKeyword, other.onKeyword) && | |
| 1808 isEqualNodes(node.exceptionType, other.exceptionType) && | |
| 1809 isEqualTokens(node.catchKeyword, other.catchKeyword) && | |
| 1810 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 1811 isEqualNodes(node.exceptionParameter, other.exceptionParameter) && | |
| 1812 isEqualTokens(node.comma, other.comma) && | |
| 1813 isEqualNodes(node.stackTraceParameter, other.stackTraceParameter) && | |
| 1814 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 1815 isEqualNodes(node.body, other.body); | |
| 1816 } | |
| 1817 | |
| 1818 @override | |
| 1819 bool visitClassDeclaration(ClassDeclaration node) { | |
| 1820 ClassDeclaration other = _other as ClassDeclaration; | |
| 1821 return isEqualNodes( | |
| 1822 node.documentationComment, other.documentationComment) && | |
| 1823 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1824 isEqualTokens(node.abstractKeyword, other.abstractKeyword) && | |
| 1825 isEqualTokens(node.classKeyword, other.classKeyword) && | |
| 1826 isEqualNodes(node.name, other.name) && | |
| 1827 isEqualNodes(node.typeParameters, other.typeParameters) && | |
| 1828 isEqualNodes(node.extendsClause, other.extendsClause) && | |
| 1829 isEqualNodes(node.withClause, other.withClause) && | |
| 1830 isEqualNodes(node.implementsClause, other.implementsClause) && | |
| 1831 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 1832 _isEqualNodeLists(node.members, other.members) && | |
| 1833 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 1834 } | |
| 1835 | |
| 1836 @override | |
| 1837 bool visitClassTypeAlias(ClassTypeAlias node) { | |
| 1838 ClassTypeAlias other = _other as ClassTypeAlias; | |
| 1839 return isEqualNodes( | |
| 1840 node.documentationComment, other.documentationComment) && | |
| 1841 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1842 isEqualTokens(node.typedefKeyword, other.typedefKeyword) && | |
| 1843 isEqualNodes(node.name, other.name) && | |
| 1844 isEqualNodes(node.typeParameters, other.typeParameters) && | |
| 1845 isEqualTokens(node.equals, other.equals) && | |
| 1846 isEqualTokens(node.abstractKeyword, other.abstractKeyword) && | |
| 1847 isEqualNodes(node.superclass, other.superclass) && | |
| 1848 isEqualNodes(node.withClause, other.withClause) && | |
| 1849 isEqualNodes(node.implementsClause, other.implementsClause) && | |
| 1850 isEqualTokens(node.semicolon, other.semicolon); | |
| 1851 } | |
| 1852 | |
| 1853 @override | |
| 1854 bool visitComment(Comment node) { | |
| 1855 Comment other = _other as Comment; | |
| 1856 return _isEqualNodeLists(node.references, other.references); | |
| 1857 } | |
| 1858 | |
| 1859 @override | |
| 1860 bool visitCommentReference(CommentReference node) { | |
| 1861 CommentReference other = _other as CommentReference; | |
| 1862 return isEqualTokens(node.newKeyword, other.newKeyword) && | |
| 1863 isEqualNodes(node.identifier, other.identifier); | |
| 1864 } | |
| 1865 | |
| 1866 @override | |
| 1867 bool visitCompilationUnit(CompilationUnit node) { | |
| 1868 CompilationUnit other = _other as CompilationUnit; | |
| 1869 return isEqualTokens(node.beginToken, other.beginToken) && | |
| 1870 isEqualNodes(node.scriptTag, other.scriptTag) && | |
| 1871 _isEqualNodeLists(node.directives, other.directives) && | |
| 1872 _isEqualNodeLists(node.declarations, other.declarations) && | |
| 1873 isEqualTokens(node.endToken, other.endToken); | |
| 1874 } | |
| 1875 | |
| 1876 @override | |
| 1877 bool visitConditionalExpression(ConditionalExpression node) { | |
| 1878 ConditionalExpression other = _other as ConditionalExpression; | |
| 1879 return isEqualNodes(node.condition, other.condition) && | |
| 1880 isEqualTokens(node.question, other.question) && | |
| 1881 isEqualNodes(node.thenExpression, other.thenExpression) && | |
| 1882 isEqualTokens(node.colon, other.colon) && | |
| 1883 isEqualNodes(node.elseExpression, other.elseExpression); | |
| 1884 } | |
| 1885 | |
| 1886 @override | |
| 1887 bool visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 1888 ConstructorDeclaration other = _other as ConstructorDeclaration; | |
| 1889 return isEqualNodes( | |
| 1890 node.documentationComment, other.documentationComment) && | |
| 1891 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1892 isEqualTokens(node.externalKeyword, other.externalKeyword) && | |
| 1893 isEqualTokens(node.constKeyword, other.constKeyword) && | |
| 1894 isEqualTokens(node.factoryKeyword, other.factoryKeyword) && | |
| 1895 isEqualNodes(node.returnType, other.returnType) && | |
| 1896 isEqualTokens(node.period, other.period) && | |
| 1897 isEqualNodes(node.name, other.name) && | |
| 1898 isEqualNodes(node.parameters, other.parameters) && | |
| 1899 isEqualTokens(node.separator, other.separator) && | |
| 1900 _isEqualNodeLists(node.initializers, other.initializers) && | |
| 1901 isEqualNodes(node.redirectedConstructor, other.redirectedConstructor) && | |
| 1902 isEqualNodes(node.body, other.body); | |
| 1903 } | |
| 1904 | |
| 1905 @override | |
| 1906 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 1907 ConstructorFieldInitializer other = _other as ConstructorFieldInitializer; | |
| 1908 return isEqualTokens(node.thisKeyword, other.thisKeyword) && | |
| 1909 isEqualTokens(node.period, other.period) && | |
| 1910 isEqualNodes(node.fieldName, other.fieldName) && | |
| 1911 isEqualTokens(node.equals, other.equals) && | |
| 1912 isEqualNodes(node.expression, other.expression); | |
| 1913 } | |
| 1914 | |
| 1915 @override | |
| 1916 bool visitConstructorName(ConstructorName node) { | |
| 1917 ConstructorName other = _other as ConstructorName; | |
| 1918 return isEqualNodes(node.type, other.type) && | |
| 1919 isEqualTokens(node.period, other.period) && | |
| 1920 isEqualNodes(node.name, other.name); | |
| 1921 } | |
| 1922 | |
| 1923 @override | |
| 1924 bool visitContinueStatement(ContinueStatement node) { | |
| 1925 ContinueStatement other = _other as ContinueStatement; | |
| 1926 return isEqualTokens(node.continueKeyword, other.continueKeyword) && | |
| 1927 isEqualNodes(node.label, other.label) && | |
| 1928 isEqualTokens(node.semicolon, other.semicolon); | |
| 1929 } | |
| 1930 | |
| 1931 @override | |
| 1932 bool visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 1933 DeclaredIdentifier other = _other as DeclaredIdentifier; | |
| 1934 return isEqualNodes( | |
| 1935 node.documentationComment, other.documentationComment) && | |
| 1936 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1937 isEqualTokens(node.keyword, other.keyword) && | |
| 1938 isEqualNodes(node.type, other.type) && | |
| 1939 isEqualNodes(node.identifier, other.identifier); | |
| 1940 } | |
| 1941 | |
| 1942 @override | |
| 1943 bool visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 1944 DefaultFormalParameter other = _other as DefaultFormalParameter; | |
| 1945 return isEqualNodes(node.parameter, other.parameter) && | |
| 1946 node.kind == other.kind && | |
| 1947 isEqualTokens(node.separator, other.separator) && | |
| 1948 isEqualNodes(node.defaultValue, other.defaultValue); | |
| 1949 } | |
| 1950 | |
| 1951 @override | |
| 1952 bool visitDoStatement(DoStatement node) { | |
| 1953 DoStatement other = _other as DoStatement; | |
| 1954 return isEqualTokens(node.doKeyword, other.doKeyword) && | |
| 1955 isEqualNodes(node.body, other.body) && | |
| 1956 isEqualTokens(node.whileKeyword, other.whileKeyword) && | |
| 1957 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 1958 isEqualNodes(node.condition, other.condition) && | |
| 1959 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 1960 isEqualTokens(node.semicolon, other.semicolon); | |
| 1961 } | |
| 1962 | |
| 1963 @override | |
| 1964 bool visitDoubleLiteral(DoubleLiteral node) { | |
| 1965 DoubleLiteral other = _other as DoubleLiteral; | |
| 1966 return isEqualTokens(node.literal, other.literal) && | |
| 1967 node.value == other.value; | |
| 1968 } | |
| 1969 | |
| 1970 @override | |
| 1971 bool visitEmptyFunctionBody(EmptyFunctionBody node) { | |
| 1972 EmptyFunctionBody other = _other as EmptyFunctionBody; | |
| 1973 return isEqualTokens(node.semicolon, other.semicolon); | |
| 1974 } | |
| 1975 | |
| 1976 @override | |
| 1977 bool visitEmptyStatement(EmptyStatement node) { | |
| 1978 EmptyStatement other = _other as EmptyStatement; | |
| 1979 return isEqualTokens(node.semicolon, other.semicolon); | |
| 1980 } | |
| 1981 | |
| 1982 @override | |
| 1983 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 1984 EnumConstantDeclaration other = _other as EnumConstantDeclaration; | |
| 1985 return isEqualNodes( | |
| 1986 node.documentationComment, other.documentationComment) && | |
| 1987 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1988 isEqualNodes(node.name, other.name); | |
| 1989 } | |
| 1990 | |
| 1991 @override | |
| 1992 bool visitEnumDeclaration(EnumDeclaration node) { | |
| 1993 EnumDeclaration other = _other as EnumDeclaration; | |
| 1994 return isEqualNodes( | |
| 1995 node.documentationComment, other.documentationComment) && | |
| 1996 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 1997 isEqualTokens(node.enumKeyword, other.enumKeyword) && | |
| 1998 isEqualNodes(node.name, other.name) && | |
| 1999 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2000 _isEqualNodeLists(node.constants, other.constants) && | |
| 2001 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2002 } | |
| 2003 | |
| 2004 @override | |
| 2005 bool visitExportDirective(ExportDirective node) { | |
| 2006 ExportDirective other = _other as ExportDirective; | |
| 2007 return isEqualNodes( | |
| 2008 node.documentationComment, other.documentationComment) && | |
| 2009 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2010 isEqualTokens(node.keyword, other.keyword) && | |
| 2011 isEqualNodes(node.uri, other.uri) && | |
| 2012 _isEqualNodeLists(node.combinators, other.combinators) && | |
| 2013 isEqualTokens(node.semicolon, other.semicolon); | |
| 2014 } | |
| 2015 | |
| 2016 @override | |
| 2017 bool visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 2018 ExpressionFunctionBody other = _other as ExpressionFunctionBody; | |
| 2019 return isEqualTokens(node.functionDefinition, other.functionDefinition) && | |
| 2020 isEqualNodes(node.expression, other.expression) && | |
| 2021 isEqualTokens(node.semicolon, other.semicolon); | |
| 2022 } | |
| 2023 | |
| 2024 @override | |
| 2025 bool visitExpressionStatement(ExpressionStatement node) { | |
| 2026 ExpressionStatement other = _other as ExpressionStatement; | |
| 2027 return isEqualNodes(node.expression, other.expression) && | |
| 2028 isEqualTokens(node.semicolon, other.semicolon); | |
| 2029 } | |
| 2030 | |
| 2031 @override | |
| 2032 bool visitExtendsClause(ExtendsClause node) { | |
| 2033 ExtendsClause other = _other as ExtendsClause; | |
| 2034 return isEqualTokens(node.extendsKeyword, other.extendsKeyword) && | |
| 2035 isEqualNodes(node.superclass, other.superclass); | |
| 2036 } | |
| 2037 | |
| 2038 @override | |
| 2039 bool visitFieldDeclaration(FieldDeclaration node) { | |
| 2040 FieldDeclaration other = _other as FieldDeclaration; | |
| 2041 return isEqualNodes( | |
| 2042 node.documentationComment, other.documentationComment) && | |
| 2043 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2044 isEqualTokens(node.staticKeyword, other.staticKeyword) && | |
| 2045 isEqualNodes(node.fields, other.fields) && | |
| 2046 isEqualTokens(node.semicolon, other.semicolon); | |
| 2047 } | |
| 2048 | |
| 2049 @override | |
| 2050 bool visitFieldFormalParameter(FieldFormalParameter node) { | |
| 2051 FieldFormalParameter other = _other as FieldFormalParameter; | |
| 2052 return isEqualNodes( | |
| 2053 node.documentationComment, other.documentationComment) && | |
| 2054 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2055 isEqualTokens(node.keyword, other.keyword) && | |
| 2056 isEqualNodes(node.type, other.type) && | |
| 2057 isEqualTokens(node.thisKeyword, other.thisKeyword) && | |
| 2058 isEqualTokens(node.period, other.period) && | |
| 2059 isEqualNodes(node.identifier, other.identifier); | |
| 2060 } | |
| 2061 | |
| 2062 @override | |
| 2063 bool visitForEachStatement(ForEachStatement node) { | |
| 2064 ForEachStatement other = _other as ForEachStatement; | |
| 2065 return isEqualTokens(node.forKeyword, other.forKeyword) && | |
| 2066 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2067 isEqualNodes(node.loopVariable, other.loopVariable) && | |
| 2068 isEqualTokens(node.inKeyword, other.inKeyword) && | |
| 2069 isEqualNodes(node.iterable, other.iterable) && | |
| 2070 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 2071 isEqualNodes(node.body, other.body); | |
| 2072 } | |
| 2073 | |
| 2074 @override | |
| 2075 bool visitFormalParameterList(FormalParameterList node) { | |
| 2076 FormalParameterList other = _other as FormalParameterList; | |
| 2077 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2078 _isEqualNodeLists(node.parameters, other.parameters) && | |
| 2079 isEqualTokens(node.leftDelimiter, other.leftDelimiter) && | |
| 2080 isEqualTokens(node.rightDelimiter, other.rightDelimiter) && | |
| 2081 isEqualTokens(node.rightParenthesis, other.rightParenthesis); | |
| 2082 } | |
| 2083 | |
| 2084 @override | |
| 2085 bool visitForStatement(ForStatement node) { | |
| 2086 ForStatement other = _other as ForStatement; | |
| 2087 return isEqualTokens(node.forKeyword, other.forKeyword) && | |
| 2088 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2089 isEqualNodes(node.variables, other.variables) && | |
| 2090 isEqualNodes(node.initialization, other.initialization) && | |
| 2091 isEqualTokens(node.leftSeparator, other.leftSeparator) && | |
| 2092 isEqualNodes(node.condition, other.condition) && | |
| 2093 isEqualTokens(node.rightSeparator, other.rightSeparator) && | |
| 2094 _isEqualNodeLists(node.updaters, other.updaters) && | |
| 2095 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 2096 isEqualNodes(node.body, other.body); | |
| 2097 } | |
| 2098 | |
| 2099 @override | |
| 2100 bool visitFunctionDeclaration(FunctionDeclaration node) { | |
| 2101 FunctionDeclaration other = _other as FunctionDeclaration; | |
| 2102 return isEqualNodes( | |
| 2103 node.documentationComment, other.documentationComment) && | |
| 2104 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2105 isEqualTokens(node.externalKeyword, other.externalKeyword) && | |
| 2106 isEqualNodes(node.returnType, other.returnType) && | |
| 2107 isEqualTokens(node.propertyKeyword, other.propertyKeyword) && | |
| 2108 isEqualNodes(node.name, other.name) && | |
| 2109 isEqualNodes(node.functionExpression, other.functionExpression); | |
| 2110 } | |
| 2111 | |
| 2112 @override | |
| 2113 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 2114 FunctionDeclarationStatement other = _other as FunctionDeclarationStatement; | |
| 2115 return isEqualNodes(node.functionDeclaration, other.functionDeclaration); | |
| 2116 } | |
| 2117 | |
| 2118 @override | |
| 2119 bool visitFunctionExpression(FunctionExpression node) { | |
| 2120 FunctionExpression other = _other as FunctionExpression; | |
| 2121 return isEqualNodes(node.parameters, other.parameters) && | |
| 2122 isEqualNodes(node.body, other.body); | |
| 2123 } | |
| 2124 | |
| 2125 @override | |
| 2126 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 2127 FunctionExpressionInvocation other = _other as FunctionExpressionInvocation; | |
| 2128 return isEqualNodes(node.function, other.function) && | |
| 2129 isEqualNodes(node.argumentList, other.argumentList); | |
| 2130 } | |
| 2131 | |
| 2132 @override | |
| 2133 bool visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 2134 FunctionTypeAlias other = _other as FunctionTypeAlias; | |
| 2135 return isEqualNodes( | |
| 2136 node.documentationComment, other.documentationComment) && | |
| 2137 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2138 isEqualTokens(node.typedefKeyword, other.typedefKeyword) && | |
| 2139 isEqualNodes(node.returnType, other.returnType) && | |
| 2140 isEqualNodes(node.name, other.name) && | |
| 2141 isEqualNodes(node.typeParameters, other.typeParameters) && | |
| 2142 isEqualNodes(node.parameters, other.parameters) && | |
| 2143 isEqualTokens(node.semicolon, other.semicolon); | |
| 2144 } | |
| 2145 | |
| 2146 @override | |
| 2147 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 2148 FunctionTypedFormalParameter other = _other as FunctionTypedFormalParameter; | |
| 2149 return isEqualNodes( | |
| 2150 node.documentationComment, other.documentationComment) && | |
| 2151 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2152 isEqualNodes(node.returnType, other.returnType) && | |
| 2153 isEqualNodes(node.identifier, other.identifier) && | |
| 2154 isEqualNodes(node.parameters, other.parameters); | |
| 2155 } | |
| 2156 | |
| 2157 @override | |
| 2158 bool visitHideCombinator(HideCombinator node) { | |
| 2159 HideCombinator other = _other as HideCombinator; | |
| 2160 return isEqualTokens(node.keyword, other.keyword) && | |
| 2161 _isEqualNodeLists(node.hiddenNames, other.hiddenNames); | |
| 2162 } | |
| 2163 | |
| 2164 @override | |
| 2165 bool visitIfStatement(IfStatement node) { | |
| 2166 IfStatement other = _other as IfStatement; | |
| 2167 return isEqualTokens(node.ifKeyword, other.ifKeyword) && | |
| 2168 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2169 isEqualNodes(node.condition, other.condition) && | |
| 2170 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 2171 isEqualNodes(node.thenStatement, other.thenStatement) && | |
| 2172 isEqualTokens(node.elseKeyword, other.elseKeyword) && | |
| 2173 isEqualNodes(node.elseStatement, other.elseStatement); | |
| 2174 } | |
| 2175 | |
| 2176 @override | |
| 2177 bool visitImplementsClause(ImplementsClause node) { | |
| 2178 ImplementsClause other = _other as ImplementsClause; | |
| 2179 return isEqualTokens(node.implementsKeyword, other.implementsKeyword) && | |
| 2180 _isEqualNodeLists(node.interfaces, other.interfaces); | |
| 2181 } | |
| 2182 | |
| 2183 @override | |
| 2184 bool visitImportDirective(ImportDirective node) { | |
| 2185 ImportDirective other = _other as ImportDirective; | |
| 2186 return isEqualNodes( | |
| 2187 node.documentationComment, other.documentationComment) && | |
| 2188 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2189 isEqualTokens(node.keyword, other.keyword) && | |
| 2190 isEqualNodes(node.uri, other.uri) && | |
| 2191 isEqualTokens(node.deferredKeyword, other.deferredKeyword) && | |
| 2192 isEqualTokens(node.asKeyword, other.asKeyword) && | |
| 2193 isEqualNodes(node.prefix, other.prefix) && | |
| 2194 _isEqualNodeLists(node.combinators, other.combinators) && | |
| 2195 isEqualTokens(node.semicolon, other.semicolon); | |
| 2196 } | |
| 2197 | |
| 2198 @override | |
| 2199 bool visitIndexExpression(IndexExpression node) { | |
| 2200 IndexExpression other = _other as IndexExpression; | |
| 2201 return isEqualNodes(node.target, other.target) && | |
| 2202 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2203 isEqualNodes(node.index, other.index) && | |
| 2204 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2205 } | |
| 2206 | |
| 2207 @override | |
| 2208 bool visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 2209 InstanceCreationExpression other = _other as InstanceCreationExpression; | |
| 2210 return isEqualTokens(node.keyword, other.keyword) && | |
| 2211 isEqualNodes(node.constructorName, other.constructorName) && | |
| 2212 isEqualNodes(node.argumentList, other.argumentList); | |
| 2213 } | |
| 2214 | |
| 2215 @override | |
| 2216 bool visitIntegerLiteral(IntegerLiteral node) { | |
| 2217 IntegerLiteral other = _other as IntegerLiteral; | |
| 2218 return isEqualTokens(node.literal, other.literal) && | |
| 2219 (node.value == other.value); | |
| 2220 } | |
| 2221 | |
| 2222 @override | |
| 2223 bool visitInterpolationExpression(InterpolationExpression node) { | |
| 2224 InterpolationExpression other = _other as InterpolationExpression; | |
| 2225 return isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2226 isEqualNodes(node.expression, other.expression) && | |
| 2227 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2228 } | |
| 2229 | |
| 2230 @override | |
| 2231 bool visitInterpolationString(InterpolationString node) { | |
| 2232 InterpolationString other = _other as InterpolationString; | |
| 2233 return isEqualTokens(node.contents, other.contents) && | |
| 2234 node.value == other.value; | |
| 2235 } | |
| 2236 | |
| 2237 @override | |
| 2238 bool visitIsExpression(IsExpression node) { | |
| 2239 IsExpression other = _other as IsExpression; | |
| 2240 return isEqualNodes(node.expression, other.expression) && | |
| 2241 isEqualTokens(node.isOperator, other.isOperator) && | |
| 2242 isEqualTokens(node.notOperator, other.notOperator) && | |
| 2243 isEqualNodes(node.type, other.type); | |
| 2244 } | |
| 2245 | |
| 2246 @override | |
| 2247 bool visitLabel(Label node) { | |
| 2248 Label other = _other as Label; | |
| 2249 return isEqualNodes(node.label, other.label) && | |
| 2250 isEqualTokens(node.colon, other.colon); | |
| 2251 } | |
| 2252 | |
| 2253 @override | |
| 2254 bool visitLabeledStatement(LabeledStatement node) { | |
| 2255 LabeledStatement other = _other as LabeledStatement; | |
| 2256 return _isEqualNodeLists(node.labels, other.labels) && | |
| 2257 isEqualNodes(node.statement, other.statement); | |
| 2258 } | |
| 2259 | |
| 2260 @override | |
| 2261 bool visitLibraryDirective(LibraryDirective node) { | |
| 2262 LibraryDirective other = _other as LibraryDirective; | |
| 2263 return isEqualNodes( | |
| 2264 node.documentationComment, other.documentationComment) && | |
| 2265 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2266 isEqualTokens(node.libraryKeyword, other.libraryKeyword) && | |
| 2267 isEqualNodes(node.name, other.name) && | |
| 2268 isEqualTokens(node.semicolon, other.semicolon); | |
| 2269 } | |
| 2270 | |
| 2271 @override | |
| 2272 bool visitLibraryIdentifier(LibraryIdentifier node) { | |
| 2273 LibraryIdentifier other = _other as LibraryIdentifier; | |
| 2274 return _isEqualNodeLists(node.components, other.components); | |
| 2275 } | |
| 2276 | |
| 2277 @override | |
| 2278 bool visitListLiteral(ListLiteral node) { | |
| 2279 ListLiteral other = _other as ListLiteral; | |
| 2280 return isEqualTokens(node.constKeyword, other.constKeyword) && | |
| 2281 isEqualNodes(node.typeArguments, other.typeArguments) && | |
| 2282 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2283 _isEqualNodeLists(node.elements, other.elements) && | |
| 2284 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2285 } | |
| 2286 | |
| 2287 @override | |
| 2288 bool visitMapLiteral(MapLiteral node) { | |
| 2289 MapLiteral other = _other as MapLiteral; | |
| 2290 return isEqualTokens(node.constKeyword, other.constKeyword) && | |
| 2291 isEqualNodes(node.typeArguments, other.typeArguments) && | |
| 2292 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2293 _isEqualNodeLists(node.entries, other.entries) && | |
| 2294 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2295 } | |
| 2296 | |
| 2297 @override | |
| 2298 bool visitMapLiteralEntry(MapLiteralEntry node) { | |
| 2299 MapLiteralEntry other = _other as MapLiteralEntry; | |
| 2300 return isEqualNodes(node.key, other.key) && | |
| 2301 isEqualTokens(node.separator, other.separator) && | |
| 2302 isEqualNodes(node.value, other.value); | |
| 2303 } | |
| 2304 | |
| 2305 @override | |
| 2306 bool visitMethodDeclaration(MethodDeclaration node) { | |
| 2307 MethodDeclaration other = _other as MethodDeclaration; | |
| 2308 return isEqualNodes( | |
| 2309 node.documentationComment, other.documentationComment) && | |
| 2310 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2311 isEqualTokens(node.externalKeyword, other.externalKeyword) && | |
| 2312 isEqualTokens(node.modifierKeyword, other.modifierKeyword) && | |
| 2313 isEqualNodes(node.returnType, other.returnType) && | |
| 2314 isEqualTokens(node.propertyKeyword, other.propertyKeyword) && | |
| 2315 isEqualTokens(node.propertyKeyword, other.propertyKeyword) && | |
| 2316 isEqualNodes(node.name, other.name) && | |
| 2317 isEqualNodes(node.parameters, other.parameters) && | |
| 2318 isEqualNodes(node.body, other.body); | |
| 2319 } | |
| 2320 | |
| 2321 @override | |
| 2322 bool visitMethodInvocation(MethodInvocation node) { | |
| 2323 MethodInvocation other = _other as MethodInvocation; | |
| 2324 return isEqualNodes(node.target, other.target) && | |
| 2325 isEqualTokens(node.operator, other.operator) && | |
| 2326 isEqualNodes(node.methodName, other.methodName) && | |
| 2327 isEqualNodes(node.argumentList, other.argumentList); | |
| 2328 } | |
| 2329 | |
| 2330 @override | |
| 2331 bool visitNamedExpression(NamedExpression node) { | |
| 2332 NamedExpression other = _other as NamedExpression; | |
| 2333 return isEqualNodes(node.name, other.name) && | |
| 2334 isEqualNodes(node.expression, other.expression); | |
| 2335 } | |
| 2336 | |
| 2337 @override | |
| 2338 bool visitNativeClause(NativeClause node) { | |
| 2339 NativeClause other = _other as NativeClause; | |
| 2340 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) && | |
| 2341 isEqualNodes(node.name, other.name); | |
| 2342 } | |
| 2343 | |
| 2344 @override | |
| 2345 bool visitNativeFunctionBody(NativeFunctionBody node) { | |
| 2346 NativeFunctionBody other = _other as NativeFunctionBody; | |
| 2347 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) && | |
| 2348 isEqualNodes(node.stringLiteral, other.stringLiteral) && | |
| 2349 isEqualTokens(node.semicolon, other.semicolon); | |
| 2350 } | |
| 2351 | |
| 2352 @override | |
| 2353 bool visitNullLiteral(NullLiteral node) { | |
| 2354 NullLiteral other = _other as NullLiteral; | |
| 2355 return isEqualTokens(node.literal, other.literal); | |
| 2356 } | |
| 2357 | |
| 2358 @override | |
| 2359 bool visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 2360 ParenthesizedExpression other = _other as ParenthesizedExpression; | |
| 2361 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2362 isEqualNodes(node.expression, other.expression) && | |
| 2363 isEqualTokens(node.rightParenthesis, other.rightParenthesis); | |
| 2364 } | |
| 2365 | |
| 2366 @override | |
| 2367 bool visitPartDirective(PartDirective node) { | |
| 2368 PartDirective other = _other as PartDirective; | |
| 2369 return isEqualNodes( | |
| 2370 node.documentationComment, other.documentationComment) && | |
| 2371 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2372 isEqualTokens(node.partKeyword, other.partKeyword) && | |
| 2373 isEqualNodes(node.uri, other.uri) && | |
| 2374 isEqualTokens(node.semicolon, other.semicolon); | |
| 2375 } | |
| 2376 | |
| 2377 @override | |
| 2378 bool visitPartOfDirective(PartOfDirective node) { | |
| 2379 PartOfDirective other = _other as PartOfDirective; | |
| 2380 return isEqualNodes( | |
| 2381 node.documentationComment, other.documentationComment) && | |
| 2382 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2383 isEqualTokens(node.partKeyword, other.partKeyword) && | |
| 2384 isEqualTokens(node.ofKeyword, other.ofKeyword) && | |
| 2385 isEqualNodes(node.libraryName, other.libraryName) && | |
| 2386 isEqualTokens(node.semicolon, other.semicolon); | |
| 2387 } | |
| 2388 | |
| 2389 @override | |
| 2390 bool visitPostfixExpression(PostfixExpression node) { | |
| 2391 PostfixExpression other = _other as PostfixExpression; | |
| 2392 return isEqualNodes(node.operand, other.operand) && | |
| 2393 isEqualTokens(node.operator, other.operator); | |
| 2394 } | |
| 2395 | |
| 2396 @override | |
| 2397 bool visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 2398 PrefixedIdentifier other = _other as PrefixedIdentifier; | |
| 2399 return isEqualNodes(node.prefix, other.prefix) && | |
| 2400 isEqualTokens(node.period, other.period) && | |
| 2401 isEqualNodes(node.identifier, other.identifier); | |
| 2402 } | |
| 2403 | |
| 2404 @override | |
| 2405 bool visitPrefixExpression(PrefixExpression node) { | |
| 2406 PrefixExpression other = _other as PrefixExpression; | |
| 2407 return isEqualTokens(node.operator, other.operator) && | |
| 2408 isEqualNodes(node.operand, other.operand); | |
| 2409 } | |
| 2410 | |
| 2411 @override | |
| 2412 bool visitPropertyAccess(PropertyAccess node) { | |
| 2413 PropertyAccess other = _other as PropertyAccess; | |
| 2414 return isEqualNodes(node.target, other.target) && | |
| 2415 isEqualTokens(node.operator, other.operator) && | |
| 2416 isEqualNodes(node.propertyName, other.propertyName); | |
| 2417 } | |
| 2418 | |
| 2419 @override | |
| 2420 bool visitRedirectingConstructorInvocation( | |
| 2421 RedirectingConstructorInvocation node) { | |
| 2422 RedirectingConstructorInvocation other = | |
| 2423 _other as RedirectingConstructorInvocation; | |
| 2424 return isEqualTokens(node.thisKeyword, other.thisKeyword) && | |
| 2425 isEqualTokens(node.period, other.period) && | |
| 2426 isEqualNodes(node.constructorName, other.constructorName) && | |
| 2427 isEqualNodes(node.argumentList, other.argumentList); | |
| 2428 } | |
| 2429 | |
| 2430 @override | |
| 2431 bool visitRethrowExpression(RethrowExpression node) { | |
| 2432 RethrowExpression other = _other as RethrowExpression; | |
| 2433 return isEqualTokens(node.rethrowKeyword, other.rethrowKeyword); | |
| 2434 } | |
| 2435 | |
| 2436 @override | |
| 2437 bool visitReturnStatement(ReturnStatement node) { | |
| 2438 ReturnStatement other = _other as ReturnStatement; | |
| 2439 return isEqualTokens(node.returnKeyword, other.returnKeyword) && | |
| 2440 isEqualNodes(node.expression, other.expression) && | |
| 2441 isEqualTokens(node.semicolon, other.semicolon); | |
| 2442 } | |
| 2443 | |
| 2444 @override | |
| 2445 bool visitScriptTag(ScriptTag node) { | |
| 2446 ScriptTag other = _other as ScriptTag; | |
| 2447 return isEqualTokens(node.scriptTag, other.scriptTag); | |
| 2448 } | |
| 2449 | |
| 2450 @override | |
| 2451 bool visitShowCombinator(ShowCombinator node) { | |
| 2452 ShowCombinator other = _other as ShowCombinator; | |
| 2453 return isEqualTokens(node.keyword, other.keyword) && | |
| 2454 _isEqualNodeLists(node.shownNames, other.shownNames); | |
| 2455 } | |
| 2456 | |
| 2457 @override | |
| 2458 bool visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 2459 SimpleFormalParameter other = _other as SimpleFormalParameter; | |
| 2460 return isEqualNodes( | |
| 2461 node.documentationComment, other.documentationComment) && | |
| 2462 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2463 isEqualTokens(node.keyword, other.keyword) && | |
| 2464 isEqualNodes(node.type, other.type) && | |
| 2465 isEqualNodes(node.identifier, other.identifier); | |
| 2466 } | |
| 2467 | |
| 2468 @override | |
| 2469 bool visitSimpleIdentifier(SimpleIdentifier node) { | |
| 2470 SimpleIdentifier other = _other as SimpleIdentifier; | |
| 2471 return isEqualTokens(node.token, other.token); | |
| 2472 } | |
| 2473 | |
| 2474 @override | |
| 2475 bool visitSimpleStringLiteral(SimpleStringLiteral node) { | |
| 2476 SimpleStringLiteral other = _other as SimpleStringLiteral; | |
| 2477 return isEqualTokens(node.literal, other.literal) && | |
| 2478 (node.value == other.value); | |
| 2479 } | |
| 2480 | |
| 2481 @override | |
| 2482 bool visitStringInterpolation(StringInterpolation node) { | |
| 2483 StringInterpolation other = _other as StringInterpolation; | |
| 2484 return _isEqualNodeLists(node.elements, other.elements); | |
| 2485 } | |
| 2486 | |
| 2487 @override | |
| 2488 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 2489 SuperConstructorInvocation other = _other as SuperConstructorInvocation; | |
| 2490 return isEqualTokens(node.superKeyword, other.superKeyword) && | |
| 2491 isEqualTokens(node.period, other.period) && | |
| 2492 isEqualNodes(node.constructorName, other.constructorName) && | |
| 2493 isEqualNodes(node.argumentList, other.argumentList); | |
| 2494 } | |
| 2495 | |
| 2496 @override | |
| 2497 bool visitSuperExpression(SuperExpression node) { | |
| 2498 SuperExpression other = _other as SuperExpression; | |
| 2499 return isEqualTokens(node.superKeyword, other.superKeyword); | |
| 2500 } | |
| 2501 | |
| 2502 @override | |
| 2503 bool visitSwitchCase(SwitchCase node) { | |
| 2504 SwitchCase other = _other as SwitchCase; | |
| 2505 return _isEqualNodeLists(node.labels, other.labels) && | |
| 2506 isEqualTokens(node.keyword, other.keyword) && | |
| 2507 isEqualNodes(node.expression, other.expression) && | |
| 2508 isEqualTokens(node.colon, other.colon) && | |
| 2509 _isEqualNodeLists(node.statements, other.statements); | |
| 2510 } | |
| 2511 | |
| 2512 @override | |
| 2513 bool visitSwitchDefault(SwitchDefault node) { | |
| 2514 SwitchDefault other = _other as SwitchDefault; | |
| 2515 return _isEqualNodeLists(node.labels, other.labels) && | |
| 2516 isEqualTokens(node.keyword, other.keyword) && | |
| 2517 isEqualTokens(node.colon, other.colon) && | |
| 2518 _isEqualNodeLists(node.statements, other.statements); | |
| 2519 } | |
| 2520 | |
| 2521 @override | |
| 2522 bool visitSwitchStatement(SwitchStatement node) { | |
| 2523 SwitchStatement other = _other as SwitchStatement; | |
| 2524 return isEqualTokens(node.switchKeyword, other.switchKeyword) && | |
| 2525 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2526 isEqualNodes(node.expression, other.expression) && | |
| 2527 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 2528 isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2529 _isEqualNodeLists(node.members, other.members) && | |
| 2530 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2531 } | |
| 2532 | |
| 2533 @override | |
| 2534 bool visitSymbolLiteral(SymbolLiteral node) { | |
| 2535 SymbolLiteral other = _other as SymbolLiteral; | |
| 2536 return isEqualTokens(node.poundSign, other.poundSign) && | |
| 2537 _isEqualTokenLists(node.components, other.components); | |
| 2538 } | |
| 2539 | |
| 2540 @override | |
| 2541 bool visitThisExpression(ThisExpression node) { | |
| 2542 ThisExpression other = _other as ThisExpression; | |
| 2543 return isEqualTokens(node.thisKeyword, other.thisKeyword); | |
| 2544 } | |
| 2545 | |
| 2546 @override | |
| 2547 bool visitThrowExpression(ThrowExpression node) { | |
| 2548 ThrowExpression other = _other as ThrowExpression; | |
| 2549 return isEqualTokens(node.throwKeyword, other.throwKeyword) && | |
| 2550 isEqualNodes(node.expression, other.expression); | |
| 2551 } | |
| 2552 | |
| 2553 @override | |
| 2554 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 2555 TopLevelVariableDeclaration other = _other as TopLevelVariableDeclaration; | |
| 2556 return isEqualNodes( | |
| 2557 node.documentationComment, other.documentationComment) && | |
| 2558 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2559 isEqualNodes(node.variables, other.variables) && | |
| 2560 isEqualTokens(node.semicolon, other.semicolon); | |
| 2561 } | |
| 2562 | |
| 2563 @override | |
| 2564 bool visitTryStatement(TryStatement node) { | |
| 2565 TryStatement other = _other as TryStatement; | |
| 2566 return isEqualTokens(node.tryKeyword, other.tryKeyword) && | |
| 2567 isEqualNodes(node.body, other.body) && | |
| 2568 _isEqualNodeLists(node.catchClauses, other.catchClauses) && | |
| 2569 isEqualTokens(node.finallyKeyword, other.finallyKeyword) && | |
| 2570 isEqualNodes(node.finallyBlock, other.finallyBlock); | |
| 2571 } | |
| 2572 | |
| 2573 @override | |
| 2574 bool visitTypeArgumentList(TypeArgumentList node) { | |
| 2575 TypeArgumentList other = _other as TypeArgumentList; | |
| 2576 return isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2577 _isEqualNodeLists(node.arguments, other.arguments) && | |
| 2578 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2579 } | |
| 2580 | |
| 2581 @override | |
| 2582 bool visitTypeName(TypeName node) { | |
| 2583 TypeName other = _other as TypeName; | |
| 2584 return isEqualNodes(node.name, other.name) && | |
| 2585 isEqualNodes(node.typeArguments, other.typeArguments); | |
| 2586 } | |
| 2587 | |
| 2588 @override | |
| 2589 bool visitTypeParameter(TypeParameter node) { | |
| 2590 TypeParameter other = _other as TypeParameter; | |
| 2591 return isEqualNodes( | |
| 2592 node.documentationComment, other.documentationComment) && | |
| 2593 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2594 isEqualNodes(node.name, other.name) && | |
| 2595 isEqualTokens(node.extendsKeyword, other.extendsKeyword) && | |
| 2596 isEqualNodes(node.bound, other.bound); | |
| 2597 } | |
| 2598 | |
| 2599 @override | |
| 2600 bool visitTypeParameterList(TypeParameterList node) { | |
| 2601 TypeParameterList other = _other as TypeParameterList; | |
| 2602 return isEqualTokens(node.leftBracket, other.leftBracket) && | |
| 2603 _isEqualNodeLists(node.typeParameters, other.typeParameters) && | |
| 2604 isEqualTokens(node.rightBracket, other.rightBracket); | |
| 2605 } | |
| 2606 | |
| 2607 @override | |
| 2608 bool visitVariableDeclaration(VariableDeclaration node) { | |
| 2609 VariableDeclaration other = _other as VariableDeclaration; | |
| 2610 return isEqualNodes( | |
| 2611 node.documentationComment, other.documentationComment) && | |
| 2612 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2613 isEqualNodes(node.name, other.name) && | |
| 2614 isEqualTokens(node.equals, other.equals) && | |
| 2615 isEqualNodes(node.initializer, other.initializer); | |
| 2616 } | |
| 2617 | |
| 2618 @override | |
| 2619 bool visitVariableDeclarationList(VariableDeclarationList node) { | |
| 2620 VariableDeclarationList other = _other as VariableDeclarationList; | |
| 2621 return isEqualNodes( | |
| 2622 node.documentationComment, other.documentationComment) && | |
| 2623 _isEqualNodeLists(node.metadata, other.metadata) && | |
| 2624 isEqualTokens(node.keyword, other.keyword) && | |
| 2625 isEqualNodes(node.type, other.type) && | |
| 2626 _isEqualNodeLists(node.variables, other.variables); | |
| 2627 } | |
| 2628 | |
| 2629 @override | |
| 2630 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 2631 VariableDeclarationStatement other = _other as VariableDeclarationStatement; | |
| 2632 return isEqualNodes(node.variables, other.variables) && | |
| 2633 isEqualTokens(node.semicolon, other.semicolon); | |
| 2634 } | |
| 2635 | |
| 2636 @override | |
| 2637 bool visitWhileStatement(WhileStatement node) { | |
| 2638 WhileStatement other = _other as WhileStatement; | |
| 2639 return isEqualTokens(node.whileKeyword, other.whileKeyword) && | |
| 2640 isEqualTokens(node.leftParenthesis, other.leftParenthesis) && | |
| 2641 isEqualNodes(node.condition, other.condition) && | |
| 2642 isEqualTokens(node.rightParenthesis, other.rightParenthesis) && | |
| 2643 isEqualNodes(node.body, other.body); | |
| 2644 } | |
| 2645 | |
| 2646 @override | |
| 2647 bool visitWithClause(WithClause node) { | |
| 2648 WithClause other = _other as WithClause; | |
| 2649 return isEqualTokens(node.withKeyword, other.withKeyword) && | |
| 2650 _isEqualNodeLists(node.mixinTypes, other.mixinTypes); | |
| 2651 } | |
| 2652 | |
| 2653 @override | |
| 2654 bool visitYieldStatement(YieldStatement node) { | |
| 2655 YieldStatement other = _other as YieldStatement; | |
| 2656 return isEqualTokens(node.yieldKeyword, other.yieldKeyword) && | |
| 2657 isEqualNodes(node.expression, other.expression) && | |
| 2658 isEqualTokens(node.semicolon, other.semicolon); | |
| 2659 } | |
| 2660 | |
| 2661 /** | |
| 2662 * Return `true` if the [first] and [second] lists of AST nodes have the same | |
| 2663 * size and corresponding elements are equal. | |
| 2664 */ | |
| 2665 bool _isEqualNodeLists(NodeList first, NodeList second) { | |
| 2666 if (first == null) { | |
| 2667 return second == null; | |
| 2668 } else if (second == null) { | |
| 2669 return false; | |
| 2670 } | |
| 2671 int size = first.length; | |
| 2672 if (second.length != size) { | |
| 2673 return false; | |
| 2674 } | |
| 2675 for (int i = 0; i < size; i++) { | |
| 2676 if (!isEqualNodes(first[i], second[i])) { | |
| 2677 return false; | |
| 2678 } | |
| 2679 } | |
| 2680 return true; | |
| 2681 } | |
| 2682 | |
| 2683 /** | |
| 2684 * Return `true` if the [first] and [second] lists of tokens have the same | |
| 2685 * length and corresponding elements are equal. | |
| 2686 */ | |
| 2687 bool _isEqualTokenLists(List<Token> first, List<Token> second) { | |
| 2688 int length = first.length; | |
| 2689 if (second.length != length) { | |
| 2690 return false; | |
| 2691 } | |
| 2692 for (int i = 0; i < length; i++) { | |
| 2693 if (!isEqualTokens(first[i], second[i])) { | |
| 2694 return false; | |
| 2695 } | |
| 2696 } | |
| 2697 return true; | |
| 2698 } | |
| 2699 | |
| 2700 /** | |
| 2701 * Return `true` if the [first] and [second] nodes are equal. | |
| 2702 */ | |
| 2703 static bool equalNodes(AstNode first, AstNode second) { | |
| 2704 AstComparator comparator = new AstComparator(); | |
| 2705 return comparator.isEqualNodes(first, second); | |
| 2706 } | |
| 2707 } | |
| 2708 | |
| 2709 /** | |
| 2710 * A node in the AST structure for a Dart program. | |
| 2711 */ | |
| 2712 abstract class AstNode { | |
| 2713 /** | |
| 2714 * An empty list of AST nodes. | |
| 2715 */ | |
| 2716 @deprecated // Use "AstNode.EMPTY_LIST" | |
| 2717 static const List<AstNode> EMPTY_ARRAY = EMPTY_LIST; | |
| 2718 | |
| 2719 /** | |
| 2720 * An empty list of AST nodes. | |
| 2721 */ | |
| 2722 static const List<AstNode> EMPTY_LIST = const <AstNode>[]; | |
| 2723 | |
| 2724 /** | |
| 2725 * A comparator that can be used to sort AST nodes in lexical order. In other | |
| 2726 * words, `compare` will return a negative value if the offset of the first | |
| 2727 * node is less than the offset of the second node, zero (0) if the nodes have | |
| 2728 * the same offset, and a positive value if the offset of the first node is | |
| 2729 * greater than the offset of the second node. | |
| 2730 */ | |
| 2731 static Comparator<AstNode> LEXICAL_ORDER = | |
| 2732 (AstNode first, AstNode second) => second.offset - first.offset; | |
| 2733 | |
| 2734 /** | |
| 2735 * The parent of the node, or `null` if the node is the root of an AST | |
| 2736 * structure. | |
| 2737 */ | |
| 2738 AstNode _parent; | |
| 2739 | |
| 2740 /** | |
| 2741 * A table mapping the names of properties to their values, or `null` if this | |
| 2742 * node does not have any properties associated with it. | |
| 2743 */ | |
| 2744 Map<String, Object> _propertyMap; | |
| 2745 | |
| 2746 /** | |
| 2747 * Return the first token included in this node's source range. | |
| 2748 */ | |
| 2749 Token get beginToken; | |
| 2750 | |
| 2751 /** | |
| 2752 * Iterate through all the entities (either AST nodes or tokens) which make | |
| 2753 * up the contents of this node, including doc comments but excluding other | |
| 2754 * comments. | |
| 2755 */ | |
| 2756 Iterable /*<AstNode | Token>*/ get childEntities; | |
| 2757 | |
| 2758 /** | |
| 2759 * Return the offset of the character immediately following the last character | |
| 2760 * of this node's source range. This is equivalent to | |
| 2761 * `node.getOffset() + node.getLength()`. For a compilation unit this will be | |
| 2762 * equal to the length of the unit's source. For synthetic nodes this will be | |
| 2763 * equivalent to the node's offset (because the length is zero (0) by | |
| 2764 * definition). | |
| 2765 */ | |
| 2766 int get end => offset + length; | |
| 2767 | |
| 2768 /** | |
| 2769 * Return the last token included in this node's source range. | |
| 2770 */ | |
| 2771 Token get endToken; | |
| 2772 | |
| 2773 /** | |
| 2774 * Return `true` if this node is a synthetic node. A synthetic node is a node | |
| 2775 * that was introduced by the parser in order to recover from an error in the | |
| 2776 * code. Synthetic nodes always have a length of zero (`0`). | |
| 2777 */ | |
| 2778 bool get isSynthetic => false; | |
| 2779 | |
| 2780 /** | |
| 2781 * Return the number of characters in the node's source range. | |
| 2782 */ | |
| 2783 int get length { | |
| 2784 Token beginToken = this.beginToken; | |
| 2785 Token endToken = this.endToken; | |
| 2786 if (beginToken == null || endToken == null) { | |
| 2787 return -1; | |
| 2788 } | |
| 2789 return endToken.offset + endToken.length - beginToken.offset; | |
| 2790 } | |
| 2791 | |
| 2792 /** | |
| 2793 * Return the offset from the beginning of the file to the first character in | |
| 2794 * the node's source range. | |
| 2795 */ | |
| 2796 int get offset { | |
| 2797 Token beginToken = this.beginToken; | |
| 2798 if (beginToken == null) { | |
| 2799 return -1; | |
| 2800 } | |
| 2801 return beginToken.offset; | |
| 2802 } | |
| 2803 | |
| 2804 /** | |
| 2805 * Return this node's parent node, or `null` if this node is the root of an | |
| 2806 * AST structure. | |
| 2807 * | |
| 2808 * Note that the relationship between an AST node and its parent node may | |
| 2809 * change over the lifetime of a node. | |
| 2810 */ | |
| 2811 AstNode get parent => _parent; | |
| 2812 | |
| 2813 /** | |
| 2814 * Set the parent of this node to the [newParent]. | |
| 2815 */ | |
| 2816 @deprecated // Never intended for public use. | |
| 2817 void set parent(AstNode newParent) { | |
| 2818 _parent = newParent; | |
| 2819 } | |
| 2820 | |
| 2821 /** | |
| 2822 * Return the node at the root of this node's AST structure. Note that this | |
| 2823 * method's performance is linear with respect to the depth of the node in the | |
| 2824 * AST structure (O(depth)). | |
| 2825 */ | |
| 2826 AstNode get root { | |
| 2827 AstNode root = this; | |
| 2828 AstNode parent = this.parent; | |
| 2829 while (parent != null) { | |
| 2830 root = parent; | |
| 2831 parent = root.parent; | |
| 2832 } | |
| 2833 return root; | |
| 2834 } | |
| 2835 | |
| 2836 /** | |
| 2837 * Use the given [visitor] to visit this node. Return the value returned by | |
| 2838 * the visitor as a result of visiting this node. | |
| 2839 */ | |
| 2840 /* <E> E */ accept(AstVisitor /*<E>*/ visitor); | |
| 2841 | |
| 2842 /** | |
| 2843 * Make this node the parent of the given [child] node. Return the child node. | |
| 2844 */ | |
| 2845 @deprecated // Never intended for public use. | |
| 2846 AstNode becomeParentOf(AstNode child) { | |
| 2847 return _becomeParentOf(child); | |
| 2848 } | |
| 2849 | |
| 2850 /** | |
| 2851 * Return the most immediate ancestor of this node for which the [predicate] | |
| 2852 * returns `true`, or `null` if there is no such ancestor. Note that this node | |
| 2853 * will never be returned. | |
| 2854 */ | |
| 2855 AstNode getAncestor(Predicate<AstNode> predicate) { | |
| 2856 // TODO(brianwilkerson) It is a bug that this method can return `this`. | |
| 2857 AstNode node = this; | |
| 2858 while (node != null && !predicate(node)) { | |
| 2859 node = node.parent; | |
| 2860 } | |
| 2861 return node; | |
| 2862 } | |
| 2863 | |
| 2864 /** | |
| 2865 * Return the value of the property with the given [name], or `null` if this | |
| 2866 * node does not have a property with the given name. | |
| 2867 */ | |
| 2868 Object getProperty(String name) { | |
| 2869 if (_propertyMap == null) { | |
| 2870 return null; | |
| 2871 } | |
| 2872 return _propertyMap[name]; | |
| 2873 } | |
| 2874 | |
| 2875 /** | |
| 2876 * If the given [child] is not `null`, use the given [visitor] to visit it. | |
| 2877 */ | |
| 2878 @deprecated // Never intended for public use. | |
| 2879 void safelyVisitChild(AstNode child, AstVisitor visitor) { | |
| 2880 if (child != null) { | |
| 2881 child.accept(visitor); | |
| 2882 } | |
| 2883 } | |
| 2884 | |
| 2885 /** | |
| 2886 * Set the value of the property with the given [name] to the given [value]. | |
| 2887 * If the value is `null`, the property will effectively be removed. | |
| 2888 */ | |
| 2889 void setProperty(String name, Object value) { | |
| 2890 if (value == null) { | |
| 2891 if (_propertyMap != null) { | |
| 2892 _propertyMap.remove(name); | |
| 2893 if (_propertyMap.isEmpty) { | |
| 2894 _propertyMap = null; | |
| 2895 } | |
| 2896 } | |
| 2897 } else { | |
| 2898 if (_propertyMap == null) { | |
| 2899 _propertyMap = new HashMap<String, Object>(); | |
| 2900 } | |
| 2901 _propertyMap[name] = value; | |
| 2902 } | |
| 2903 } | |
| 2904 | |
| 2905 /** | |
| 2906 * Return a textual description of this node in a form approximating valid | |
| 2907 * source. The returned string will not be valid source primarily in the case | |
| 2908 * where the node itself is not well-formed. | |
| 2909 */ | |
| 2910 String toSource() { | |
| 2911 PrintStringWriter writer = new PrintStringWriter(); | |
| 2912 accept(new ToSourceVisitor(writer)); | |
| 2913 return writer.toString(); | |
| 2914 } | |
| 2915 | |
| 2916 @override | |
| 2917 String toString() => toSource(); | |
| 2918 | |
| 2919 /** | |
| 2920 * Use the given [visitor] to visit all of the children of this node. The | |
| 2921 * children will be visited in lexical order. | |
| 2922 */ | |
| 2923 void visitChildren(AstVisitor visitor); | |
| 2924 | |
| 2925 /** | |
| 2926 * Make this node the parent of the given [child] node. Return the child node. | |
| 2927 */ | |
| 2928 AstNode _becomeParentOf(AstNode child) { | |
| 2929 if (child != null) { | |
| 2930 child._parent = this; | |
| 2931 } | |
| 2932 return child; | |
| 2933 } | |
| 2934 | |
| 2935 /** | |
| 2936 * If the given [child] is not `null`, use the given [visitor] to visit it. | |
| 2937 */ | |
| 2938 void _safelyVisitChild(AstNode child, AstVisitor visitor) { | |
| 2939 if (child != null) { | |
| 2940 child.accept(visitor); | |
| 2941 } | |
| 2942 } | |
| 2943 } | |
| 2944 | |
| 2945 /** | |
| 2946 * An object that can be used to visit an AST structure. | |
| 2947 */ | |
| 2948 abstract class AstVisitor<R> { | |
| 2949 R visitAdjacentStrings(AdjacentStrings node); | |
| 2950 | |
| 2951 R visitAnnotation(Annotation node); | |
| 2952 | |
| 2953 R visitArgumentList(ArgumentList node); | |
| 2954 | |
| 2955 R visitAsExpression(AsExpression node); | |
| 2956 | |
| 2957 R visitAssertStatement(AssertStatement assertStatement); | |
| 2958 | |
| 2959 R visitAssignmentExpression(AssignmentExpression node); | |
| 2960 | |
| 2961 R visitAwaitExpression(AwaitExpression node); | |
| 2962 | |
| 2963 R visitBinaryExpression(BinaryExpression node); | |
| 2964 | |
| 2965 R visitBlock(Block node); | |
| 2966 | |
| 2967 R visitBlockFunctionBody(BlockFunctionBody node); | |
| 2968 | |
| 2969 R visitBooleanLiteral(BooleanLiteral node); | |
| 2970 | |
| 2971 R visitBreakStatement(BreakStatement node); | |
| 2972 | |
| 2973 R visitCascadeExpression(CascadeExpression node); | |
| 2974 | |
| 2975 R visitCatchClause(CatchClause node); | |
| 2976 | |
| 2977 R visitClassDeclaration(ClassDeclaration node); | |
| 2978 | |
| 2979 R visitClassTypeAlias(ClassTypeAlias node); | |
| 2980 | |
| 2981 R visitComment(Comment node); | |
| 2982 | |
| 2983 R visitCommentReference(CommentReference node); | |
| 2984 | |
| 2985 R visitCompilationUnit(CompilationUnit node); | |
| 2986 | |
| 2987 R visitConditionalExpression(ConditionalExpression node); | |
| 2988 | |
| 2989 R visitConstructorDeclaration(ConstructorDeclaration node); | |
| 2990 | |
| 2991 R visitConstructorFieldInitializer(ConstructorFieldInitializer node); | |
| 2992 | |
| 2993 R visitConstructorName(ConstructorName node); | |
| 2994 | |
| 2995 R visitContinueStatement(ContinueStatement node); | |
| 2996 | |
| 2997 R visitDeclaredIdentifier(DeclaredIdentifier node); | |
| 2998 | |
| 2999 R visitDefaultFormalParameter(DefaultFormalParameter node); | |
| 3000 | |
| 3001 R visitDoStatement(DoStatement node); | |
| 3002 | |
| 3003 R visitDoubleLiteral(DoubleLiteral node); | |
| 3004 | |
| 3005 R visitEmptyFunctionBody(EmptyFunctionBody node); | |
| 3006 | |
| 3007 R visitEmptyStatement(EmptyStatement node); | |
| 3008 | |
| 3009 R visitEnumConstantDeclaration(EnumConstantDeclaration node); | |
| 3010 | |
| 3011 R visitEnumDeclaration(EnumDeclaration node); | |
| 3012 | |
| 3013 R visitExportDirective(ExportDirective node); | |
| 3014 | |
| 3015 R visitExpressionFunctionBody(ExpressionFunctionBody node); | |
| 3016 | |
| 3017 R visitExpressionStatement(ExpressionStatement node); | |
| 3018 | |
| 3019 R visitExtendsClause(ExtendsClause node); | |
| 3020 | |
| 3021 R visitFieldDeclaration(FieldDeclaration node); | |
| 3022 | |
| 3023 R visitFieldFormalParameter(FieldFormalParameter node); | |
| 3024 | |
| 3025 R visitForEachStatement(ForEachStatement node); | |
| 3026 | |
| 3027 R visitFormalParameterList(FormalParameterList node); | |
| 3028 | |
| 3029 R visitForStatement(ForStatement node); | |
| 3030 | |
| 3031 R visitFunctionDeclaration(FunctionDeclaration node); | |
| 3032 | |
| 3033 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node); | |
| 3034 | |
| 3035 R visitFunctionExpression(FunctionExpression node); | |
| 3036 | |
| 3037 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node); | |
| 3038 | |
| 3039 R visitFunctionTypeAlias(FunctionTypeAlias functionTypeAlias); | |
| 3040 | |
| 3041 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node); | |
| 3042 | |
| 3043 R visitHideCombinator(HideCombinator node); | |
| 3044 | |
| 3045 R visitIfStatement(IfStatement node); | |
| 3046 | |
| 3047 R visitImplementsClause(ImplementsClause node); | |
| 3048 | |
| 3049 R visitImportDirective(ImportDirective node); | |
| 3050 | |
| 3051 R visitIndexExpression(IndexExpression node); | |
| 3052 | |
| 3053 R visitInstanceCreationExpression(InstanceCreationExpression node); | |
| 3054 | |
| 3055 R visitIntegerLiteral(IntegerLiteral node); | |
| 3056 | |
| 3057 R visitInterpolationExpression(InterpolationExpression node); | |
| 3058 | |
| 3059 R visitInterpolationString(InterpolationString node); | |
| 3060 | |
| 3061 R visitIsExpression(IsExpression node); | |
| 3062 | |
| 3063 R visitLabel(Label node); | |
| 3064 | |
| 3065 R visitLabeledStatement(LabeledStatement node); | |
| 3066 | |
| 3067 R visitLibraryDirective(LibraryDirective node); | |
| 3068 | |
| 3069 R visitLibraryIdentifier(LibraryIdentifier node); | |
| 3070 | |
| 3071 R visitListLiteral(ListLiteral node); | |
| 3072 | |
| 3073 R visitMapLiteral(MapLiteral node); | |
| 3074 | |
| 3075 R visitMapLiteralEntry(MapLiteralEntry node); | |
| 3076 | |
| 3077 R visitMethodDeclaration(MethodDeclaration node); | |
| 3078 | |
| 3079 R visitMethodInvocation(MethodInvocation node); | |
| 3080 | |
| 3081 R visitNamedExpression(NamedExpression node); | |
| 3082 | |
| 3083 R visitNativeClause(NativeClause node); | |
| 3084 | |
| 3085 R visitNativeFunctionBody(NativeFunctionBody node); | |
| 3086 | |
| 3087 R visitNullLiteral(NullLiteral node); | |
| 3088 | |
| 3089 R visitParenthesizedExpression(ParenthesizedExpression node); | |
| 3090 | |
| 3091 R visitPartDirective(PartDirective node); | |
| 3092 | |
| 3093 R visitPartOfDirective(PartOfDirective node); | |
| 3094 | |
| 3095 R visitPostfixExpression(PostfixExpression node); | |
| 3096 | |
| 3097 R visitPrefixedIdentifier(PrefixedIdentifier node); | |
| 3098 | |
| 3099 R visitPrefixExpression(PrefixExpression node); | |
| 3100 | |
| 3101 R visitPropertyAccess(PropertyAccess node); | |
| 3102 | |
| 3103 R visitRedirectingConstructorInvocation( | |
| 3104 RedirectingConstructorInvocation node); | |
| 3105 | |
| 3106 R visitRethrowExpression(RethrowExpression node); | |
| 3107 | |
| 3108 R visitReturnStatement(ReturnStatement node); | |
| 3109 | |
| 3110 R visitScriptTag(ScriptTag node); | |
| 3111 | |
| 3112 R visitShowCombinator(ShowCombinator node); | |
| 3113 | |
| 3114 R visitSimpleFormalParameter(SimpleFormalParameter node); | |
| 3115 | |
| 3116 R visitSimpleIdentifier(SimpleIdentifier node); | |
| 3117 | |
| 3118 R visitSimpleStringLiteral(SimpleStringLiteral node); | |
| 3119 | |
| 3120 R visitStringInterpolation(StringInterpolation node); | |
| 3121 | |
| 3122 R visitSuperConstructorInvocation(SuperConstructorInvocation node); | |
| 3123 | |
| 3124 R visitSuperExpression(SuperExpression node); | |
| 3125 | |
| 3126 R visitSwitchCase(SwitchCase node); | |
| 3127 | |
| 3128 R visitSwitchDefault(SwitchDefault node); | |
| 3129 | |
| 3130 R visitSwitchStatement(SwitchStatement node); | |
| 3131 | |
| 3132 R visitSymbolLiteral(SymbolLiteral node); | |
| 3133 | |
| 3134 R visitThisExpression(ThisExpression node); | |
| 3135 | |
| 3136 R visitThrowExpression(ThrowExpression node); | |
| 3137 | |
| 3138 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node); | |
| 3139 | |
| 3140 R visitTryStatement(TryStatement node); | |
| 3141 | |
| 3142 R visitTypeArgumentList(TypeArgumentList node); | |
| 3143 | |
| 3144 R visitTypeName(TypeName node); | |
| 3145 | |
| 3146 R visitTypeParameter(TypeParameter node); | |
| 3147 | |
| 3148 R visitTypeParameterList(TypeParameterList node); | |
| 3149 | |
| 3150 R visitVariableDeclaration(VariableDeclaration node); | |
| 3151 | |
| 3152 R visitVariableDeclarationList(VariableDeclarationList node); | |
| 3153 | |
| 3154 R visitVariableDeclarationStatement(VariableDeclarationStatement node); | |
| 3155 | |
| 3156 R visitWhileStatement(WhileStatement node); | |
| 3157 | |
| 3158 R visitWithClause(WithClause node); | |
| 3159 | |
| 3160 R visitYieldStatement(YieldStatement node); | |
| 3161 } | |
| 3162 | |
| 3163 /** | |
| 3164 * An await expression. | |
| 3165 * | |
| 3166 * > awaitExpression ::= | |
| 3167 * > 'await' [Expression] | |
| 3168 */ | |
| 3169 class AwaitExpression extends Expression { | |
| 3170 /** | |
| 3171 * The 'await' keyword. | |
| 3172 */ | |
| 3173 Token awaitKeyword; | |
| 3174 | |
| 3175 /** | |
| 3176 * The expression whose value is being waited on. | |
| 3177 */ | |
| 3178 Expression _expression; | |
| 3179 | |
| 3180 /** | |
| 3181 * Initialize a newly created await expression. | |
| 3182 */ | |
| 3183 AwaitExpression(this.awaitKeyword, Expression expression) { | |
| 3184 _expression = _becomeParentOf(expression); | |
| 3185 } | |
| 3186 | |
| 3187 @override | |
| 3188 Token get beginToken { | |
| 3189 if (awaitKeyword != null) { | |
| 3190 return awaitKeyword; | |
| 3191 } | |
| 3192 return _expression.beginToken; | |
| 3193 } | |
| 3194 | |
| 3195 @override | |
| 3196 Iterable get childEntities => | |
| 3197 new ChildEntities()..add(awaitKeyword)..add(_expression); | |
| 3198 | |
| 3199 @override | |
| 3200 Token get endToken => _expression.endToken; | |
| 3201 | |
| 3202 /** | |
| 3203 * Return the expression whose value is being waited on. | |
| 3204 */ | |
| 3205 Expression get expression => _expression; | |
| 3206 | |
| 3207 /** | |
| 3208 * Set the expression whose value is being waited on to the given [expression]
. | |
| 3209 */ | |
| 3210 void set expression(Expression expression) { | |
| 3211 _expression = _becomeParentOf(expression); | |
| 3212 } | |
| 3213 | |
| 3214 @override | |
| 3215 int get precedence => 0; | |
| 3216 | |
| 3217 @override | |
| 3218 accept(AstVisitor visitor) => visitor.visitAwaitExpression(this); | |
| 3219 | |
| 3220 @override | |
| 3221 void visitChildren(AstVisitor visitor) { | |
| 3222 _safelyVisitChild(_expression, visitor); | |
| 3223 } | |
| 3224 } | |
| 3225 | |
| 3226 /** | |
| 3227 * A binary (infix) expression. | |
| 3228 * | |
| 3229 * > binaryExpression ::= | |
| 3230 * > [Expression] [Token] [Expression] | |
| 3231 */ | |
| 3232 class BinaryExpression extends Expression { | |
| 3233 /** | |
| 3234 * The expression used to compute the left operand. | |
| 3235 */ | |
| 3236 Expression _leftOperand; | |
| 3237 | |
| 3238 /** | |
| 3239 * The binary operator being applied. | |
| 3240 */ | |
| 3241 Token operator; | |
| 3242 | |
| 3243 /** | |
| 3244 * The expression used to compute the right operand. | |
| 3245 */ | |
| 3246 Expression _rightOperand; | |
| 3247 | |
| 3248 /** | |
| 3249 * The element associated with the operator based on the static type of the | |
| 3250 * left operand, or `null` if the AST structure has not been resolved, if the | |
| 3251 * operator is not user definable, or if the operator could not be resolved. | |
| 3252 */ | |
| 3253 MethodElement staticElement; | |
| 3254 | |
| 3255 /** | |
| 3256 * The element associated with the operator based on the propagated type of | |
| 3257 * the left operand, or `null` if the AST structure has not been resolved, if | |
| 3258 * the operator is not user definable, or if the operator could not be | |
| 3259 * resolved. | |
| 3260 */ | |
| 3261 MethodElement propagatedElement; | |
| 3262 | |
| 3263 /** | |
| 3264 * Initialize a newly created binary expression. | |
| 3265 */ | |
| 3266 BinaryExpression( | |
| 3267 Expression leftOperand, this.operator, Expression rightOperand) { | |
| 3268 _leftOperand = _becomeParentOf(leftOperand); | |
| 3269 _rightOperand = _becomeParentOf(rightOperand); | |
| 3270 } | |
| 3271 | |
| 3272 @override | |
| 3273 Token get beginToken => _leftOperand.beginToken; | |
| 3274 | |
| 3275 /** | |
| 3276 * Return the best element available for this operator. If resolution was able | |
| 3277 * to find a better element based on type propagation, that element will be | |
| 3278 * returned. Otherwise, the element found using the result of static analysis | |
| 3279 * will be returned. If resolution has not been performed, then `null` will be | |
| 3280 * returned. | |
| 3281 */ | |
| 3282 MethodElement get bestElement { | |
| 3283 MethodElement element = propagatedElement; | |
| 3284 if (element == null) { | |
| 3285 element = staticElement; | |
| 3286 } | |
| 3287 return element; | |
| 3288 } | |
| 3289 | |
| 3290 @override | |
| 3291 Iterable get childEntities => | |
| 3292 new ChildEntities()..add(_leftOperand)..add(operator)..add(_rightOperand); | |
| 3293 | |
| 3294 @override | |
| 3295 Token get endToken => _rightOperand.endToken; | |
| 3296 | |
| 3297 /** | |
| 3298 * Return the expression used to compute the left operand. | |
| 3299 */ | |
| 3300 Expression get leftOperand => _leftOperand; | |
| 3301 | |
| 3302 /** | |
| 3303 * Set the expression used to compute the left operand to the given | |
| 3304 * [expression]. | |
| 3305 */ | |
| 3306 void set leftOperand(Expression expression) { | |
| 3307 _leftOperand = _becomeParentOf(expression); | |
| 3308 } | |
| 3309 | |
| 3310 @override | |
| 3311 int get precedence => operator.type.precedence; | |
| 3312 | |
| 3313 /** | |
| 3314 * If the AST structure has been resolved, and the function being invoked is | |
| 3315 * known based on propagated type information, then return the parameter | |
| 3316 * element representing the parameter to which the value of the right operand | |
| 3317 * will be bound. Otherwise, return `null`. | |
| 3318 */ | |
| 3319 @deprecated // Use "expression.propagatedParameterElement" | |
| 3320 ParameterElement get propagatedParameterElementForRightOperand { | |
| 3321 return _propagatedParameterElementForRightOperand; | |
| 3322 } | |
| 3323 | |
| 3324 /** | |
| 3325 * Return the expression used to compute the right operand. | |
| 3326 */ | |
| 3327 Expression get rightOperand => _rightOperand; | |
| 3328 | |
| 3329 /** | |
| 3330 * Set the expression used to compute the right operand to the given | |
| 3331 * [expression]. | |
| 3332 */ | |
| 3333 void set rightOperand(Expression expression) { | |
| 3334 _rightOperand = _becomeParentOf(expression); | |
| 3335 } | |
| 3336 | |
| 3337 /** | |
| 3338 * If the AST structure has been resolved, and the function being invoked is | |
| 3339 * known based on static type information, then return the parameter element | |
| 3340 * representing the parameter to which the value of the right operand will be | |
| 3341 * bound. Otherwise, return `null`. | |
| 3342 */ | |
| 3343 @deprecated // Use "expression.staticParameterElement" | |
| 3344 ParameterElement get staticParameterElementForRightOperand { | |
| 3345 return _staticParameterElementForRightOperand; | |
| 3346 } | |
| 3347 | |
| 3348 /** | |
| 3349 * If the AST structure has been resolved, and the function being invoked is | |
| 3350 * known based on propagated type information, then return the parameter | |
| 3351 * element representing the parameter to which the value of the right operand | |
| 3352 * will be bound. Otherwise, return `null`. | |
| 3353 */ | |
| 3354 ParameterElement get _propagatedParameterElementForRightOperand { | |
| 3355 if (propagatedElement == null) { | |
| 3356 return null; | |
| 3357 } | |
| 3358 List<ParameterElement> parameters = propagatedElement.parameters; | |
| 3359 if (parameters.length < 1) { | |
| 3360 return null; | |
| 3361 } | |
| 3362 return parameters[0]; | |
| 3363 } | |
| 3364 | |
| 3365 /** | |
| 3366 * If the AST structure has been resolved, and the function being invoked is | |
| 3367 * known based on static type information, then return the parameter element | |
| 3368 * representing the parameter to which the value of the right operand will be | |
| 3369 * bound. Otherwise, return `null`. | |
| 3370 */ | |
| 3371 ParameterElement get _staticParameterElementForRightOperand { | |
| 3372 if (staticElement == null) { | |
| 3373 return null; | |
| 3374 } | |
| 3375 List<ParameterElement> parameters = staticElement.parameters; | |
| 3376 if (parameters.length < 1) { | |
| 3377 return null; | |
| 3378 } | |
| 3379 return parameters[0]; | |
| 3380 } | |
| 3381 | |
| 3382 @override | |
| 3383 accept(AstVisitor visitor) => visitor.visitBinaryExpression(this); | |
| 3384 | |
| 3385 @override | |
| 3386 void visitChildren(AstVisitor visitor) { | |
| 3387 _safelyVisitChild(_leftOperand, visitor); | |
| 3388 _safelyVisitChild(_rightOperand, visitor); | |
| 3389 } | |
| 3390 } | |
| 3391 | |
| 3392 /** | |
| 3393 * A sequence of statements. | |
| 3394 * | |
| 3395 * > block ::= | |
| 3396 * > '{' statement* '}' | |
| 3397 */ | |
| 3398 class Block extends Statement { | |
| 3399 /** | |
| 3400 * The left curly bracket. | |
| 3401 */ | |
| 3402 Token leftBracket; | |
| 3403 | |
| 3404 /** | |
| 3405 * The statements contained in the block. | |
| 3406 */ | |
| 3407 NodeList<Statement> _statements; | |
| 3408 | |
| 3409 /** | |
| 3410 * The right curly bracket. | |
| 3411 */ | |
| 3412 Token rightBracket; | |
| 3413 | |
| 3414 /** | |
| 3415 * Initialize a newly created block of code. | |
| 3416 */ | |
| 3417 Block(this.leftBracket, List<Statement> statements, this.rightBracket) { | |
| 3418 _statements = new NodeList<Statement>(this, statements); | |
| 3419 } | |
| 3420 | |
| 3421 @override | |
| 3422 Token get beginToken => leftBracket; | |
| 3423 | |
| 3424 @override | |
| 3425 Iterable get childEntities => new ChildEntities() | |
| 3426 ..add(leftBracket) | |
| 3427 ..addAll(_statements) | |
| 3428 ..add(rightBracket); | |
| 3429 | |
| 3430 @override | |
| 3431 Token get endToken => rightBracket; | |
| 3432 | |
| 3433 /** | |
| 3434 * Return the statements contained in the block. | |
| 3435 */ | |
| 3436 NodeList<Statement> get statements => _statements; | |
| 3437 | |
| 3438 @override | |
| 3439 accept(AstVisitor visitor) => visitor.visitBlock(this); | |
| 3440 | |
| 3441 @override | |
| 3442 void visitChildren(AstVisitor visitor) { | |
| 3443 _statements.accept(visitor); | |
| 3444 } | |
| 3445 } | |
| 3446 | |
| 3447 /** | |
| 3448 * A function body that consists of a block of statements. | |
| 3449 * | |
| 3450 * > blockFunctionBody ::= | |
| 3451 * > ('async' | 'async' '*' | 'sync' '*')? [Block] | |
| 3452 */ | |
| 3453 class BlockFunctionBody extends FunctionBody { | |
| 3454 /** | |
| 3455 * The token representing the 'async' or 'sync' keyword, or `null` if there is | |
| 3456 * no such keyword. | |
| 3457 */ | |
| 3458 Token keyword; | |
| 3459 | |
| 3460 /** | |
| 3461 * The star optionally following the 'async' or 'sync' keyword, or `null` if | |
| 3462 * there is wither no such keyword or no star. | |
| 3463 */ | |
| 3464 Token star; | |
| 3465 | |
| 3466 /** | |
| 3467 * The block representing the body of the function. | |
| 3468 */ | |
| 3469 Block _block; | |
| 3470 | |
| 3471 /** | |
| 3472 * Initialize a newly created function body consisting of a block of | |
| 3473 * statements. The [keyword] can be `null` if there is no keyword specified | |
| 3474 * for the block. The [star] can be `null` if there is no star following the | |
| 3475 * keyword (and must be `null` if there is no keyword). | |
| 3476 */ | |
| 3477 BlockFunctionBody(this.keyword, this.star, Block block) { | |
| 3478 _block = _becomeParentOf(block); | |
| 3479 } | |
| 3480 | |
| 3481 @override | |
| 3482 Token get beginToken => _block.beginToken; | |
| 3483 | |
| 3484 /** | |
| 3485 * Return the block representing the body of the function. | |
| 3486 */ | |
| 3487 Block get block => _block; | |
| 3488 | |
| 3489 /** | |
| 3490 * Set the block representing the body of the function to the given [block]. | |
| 3491 */ | |
| 3492 void set block(Block block) { | |
| 3493 _block = _becomeParentOf(block); | |
| 3494 } | |
| 3495 | |
| 3496 @override | |
| 3497 Iterable get childEntities => | |
| 3498 new ChildEntities()..add(keyword)..add(star)..add(_block); | |
| 3499 | |
| 3500 @override | |
| 3501 Token get endToken => _block.endToken; | |
| 3502 | |
| 3503 @override | |
| 3504 bool get isAsynchronous => keyword != null && keyword.lexeme == Parser.ASYNC; | |
| 3505 | |
| 3506 @override | |
| 3507 bool get isGenerator => star != null; | |
| 3508 | |
| 3509 @override | |
| 3510 bool get isSynchronous => keyword == null || keyword.lexeme != Parser.ASYNC; | |
| 3511 | |
| 3512 @override | |
| 3513 accept(AstVisitor visitor) => visitor.visitBlockFunctionBody(this); | |
| 3514 | |
| 3515 @override | |
| 3516 void visitChildren(AstVisitor visitor) { | |
| 3517 _safelyVisitChild(_block, visitor); | |
| 3518 } | |
| 3519 } | |
| 3520 | |
| 3521 /** | |
| 3522 * A boolean literal expression. | |
| 3523 * | |
| 3524 * > booleanLiteral ::= | |
| 3525 * > 'false' | 'true' | |
| 3526 */ | |
| 3527 class BooleanLiteral extends Literal { | |
| 3528 /** | |
| 3529 * The token representing the literal. | |
| 3530 */ | |
| 3531 Token literal; | |
| 3532 | |
| 3533 /** | |
| 3534 * The value of the literal. | |
| 3535 */ | |
| 3536 bool value = false; | |
| 3537 | |
| 3538 /** | |
| 3539 * Initialize a newly created boolean literal. | |
| 3540 */ | |
| 3541 BooleanLiteral(this.literal, this.value); | |
| 3542 | |
| 3543 @override | |
| 3544 Token get beginToken => literal; | |
| 3545 | |
| 3546 @override | |
| 3547 Iterable get childEntities => new ChildEntities()..add(literal); | |
| 3548 | |
| 3549 @override | |
| 3550 Token get endToken => literal; | |
| 3551 | |
| 3552 @override | |
| 3553 bool get isSynthetic => literal.isSynthetic; | |
| 3554 | |
| 3555 @override | |
| 3556 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this); | |
| 3557 | |
| 3558 @override | |
| 3559 void visitChildren(AstVisitor visitor) { | |
| 3560 // There are no children to visit. | |
| 3561 } | |
| 3562 } | |
| 3563 | |
| 3564 /** | |
| 3565 * An AST visitor that will recursively visit all of the nodes in an AST | |
| 3566 * structure, similar to [GeneralizingAstVisitor]. This visitor uses a | |
| 3567 * breadth-first ordering rather than the depth-first ordering of | |
| 3568 * [GeneralizingAstVisitor]. | |
| 3569 * | |
| 3570 * Subclasses that override a visit method must either invoke the overridden | |
| 3571 * visit method or explicitly invoke the more general visit method. Failure to | |
| 3572 * do so will cause the visit methods for superclasses of the node to not be | |
| 3573 * invoked and will cause the children of the visited node to not be visited. | |
| 3574 * | |
| 3575 * In addition, subclasses should <b>not</b> explicitly visit the children of a | |
| 3576 * node, but should ensure that the method [visitNode] is used to visit the | |
| 3577 * children (either directly or indirectly). Failure to do will break the order | |
| 3578 * in which nodes are visited. | |
| 3579 */ | |
| 3580 class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> { | |
| 3581 /** | |
| 3582 * A queue holding the nodes that have not yet been visited in the order in | |
| 3583 * which they ought to be visited. | |
| 3584 */ | |
| 3585 Queue<AstNode> _queue = new Queue<AstNode>(); | |
| 3586 | |
| 3587 /** | |
| 3588 * A visitor, used to visit the children of the current node, that will add | |
| 3589 * the nodes it visits to the [_queue]. | |
| 3590 */ | |
| 3591 GeneralizingAstVisitor<Object> _childVisitor; | |
| 3592 | |
| 3593 /** | |
| 3594 * Initialize a newly created visitor. | |
| 3595 */ | |
| 3596 BreadthFirstVisitor() { | |
| 3597 _childVisitor = new GeneralizingAstVisitor_BreadthFirstVisitor(this); | |
| 3598 } | |
| 3599 | |
| 3600 /** | |
| 3601 * Visit all nodes in the tree starting at the given [root] node, in | |
| 3602 * breadth-first order. | |
| 3603 */ | |
| 3604 void visitAllNodes(AstNode root) { | |
| 3605 _queue.add(root); | |
| 3606 while (!_queue.isEmpty) { | |
| 3607 AstNode next = _queue.removeFirst(); | |
| 3608 next.accept(this); | |
| 3609 } | |
| 3610 } | |
| 3611 | |
| 3612 @override | |
| 3613 R visitNode(AstNode node) { | |
| 3614 node.visitChildren(_childVisitor); | |
| 3615 return null; | |
| 3616 } | |
| 3617 } | |
| 3618 | |
| 3619 /** | |
| 3620 * A break statement. | |
| 3621 * | |
| 3622 * > breakStatement ::= | |
| 3623 * > 'break' [SimpleIdentifier]? ';' | |
| 3624 */ | |
| 3625 class BreakStatement extends Statement { | |
| 3626 /** | |
| 3627 * The token representing the 'break' keyword. | |
| 3628 */ | |
| 3629 Token breakKeyword; | |
| 3630 | |
| 3631 /** | |
| 3632 * The label associated with the statement, or `null` if there is no label. | |
| 3633 */ | |
| 3634 SimpleIdentifier _label; | |
| 3635 | |
| 3636 /** | |
| 3637 * The semicolon terminating the statement. | |
| 3638 */ | |
| 3639 Token semicolon; | |
| 3640 | |
| 3641 /** | |
| 3642 * The AstNode which this break statement is breaking from. This will be | |
| 3643 * either a [Statement] (in the case of breaking out of a loop), a | |
| 3644 * [SwitchMember] (in the case of a labeled break statement whose label | |
| 3645 * matches a label on a switch case in an enclosing switch statement), or | |
| 3646 * `null` if the AST has not yet been resolved or if the target could not be | |
| 3647 * resolved. Note that if the source code has errors, the target might be | |
| 3648 * invalid (e.g. trying to break to a switch case). | |
| 3649 */ | |
| 3650 AstNode target; | |
| 3651 | |
| 3652 /** | |
| 3653 * Initialize a newly created break statement. The [label] can be `null` if | |
| 3654 * there is no label associated with the statement. | |
| 3655 */ | |
| 3656 BreakStatement(this.breakKeyword, SimpleIdentifier label, this.semicolon) { | |
| 3657 _label = _becomeParentOf(label); | |
| 3658 } | |
| 3659 | |
| 3660 @override | |
| 3661 Token get beginToken => breakKeyword; | |
| 3662 | |
| 3663 @override | |
| 3664 Iterable get childEntities => | |
| 3665 new ChildEntities()..add(breakKeyword)..add(_label)..add(semicolon); | |
| 3666 | |
| 3667 @override | |
| 3668 Token get endToken => semicolon; | |
| 3669 | |
| 3670 /** | |
| 3671 * Return the token representing the 'break' keyword. | |
| 3672 */ | |
| 3673 @deprecated // Use "this.breakKeyword" | |
| 3674 Token get keyword => breakKeyword; | |
| 3675 | |
| 3676 /** | |
| 3677 * Sethe token representing the 'break' keyword to the given [token]. | |
| 3678 */ | |
| 3679 @deprecated // Use "this.breakKeyword" | |
| 3680 void set keyword(Token token) { | |
| 3681 breakKeyword = token; | |
| 3682 } | |
| 3683 | |
| 3684 /** | |
| 3685 * Return the label associated with the statement, or `null` if there is no | |
| 3686 * label. | |
| 3687 */ | |
| 3688 SimpleIdentifier get label => _label; | |
| 3689 | |
| 3690 /** | |
| 3691 * Set the label associated with the statement to the given [identifier]. | |
| 3692 */ | |
| 3693 void set label(SimpleIdentifier identifier) { | |
| 3694 _label = _becomeParentOf(identifier); | |
| 3695 } | |
| 3696 | |
| 3697 @override | |
| 3698 accept(AstVisitor visitor) => visitor.visitBreakStatement(this); | |
| 3699 | |
| 3700 @override | |
| 3701 void visitChildren(AstVisitor visitor) { | |
| 3702 _safelyVisitChild(_label, visitor); | |
| 3703 } | |
| 3704 } | |
| 3705 | |
| 3706 /** | |
| 3707 * A sequence of cascaded expressions: expressions that share a common target. | |
| 3708 * There are three kinds of expressions that can be used in a cascade | |
| 3709 * expression: [IndexExpression], [MethodInvocation] and [PropertyAccess]. | |
| 3710 * | |
| 3711 * > cascadeExpression ::= | |
| 3712 * > [Expression] cascadeSection* | |
| 3713 * > | |
| 3714 * > cascadeSection ::= | |
| 3715 * > '..' (cascadeSelector arguments*) (assignableSelector arguments*)* | |
| 3716 * > (assignmentOperator expressionWithoutCascade)? | |
| 3717 * > | |
| 3718 * > cascadeSelector ::= | |
| 3719 * > '[ ' expression '] ' | |
| 3720 * > | identifier | |
| 3721 */ | |
| 3722 class CascadeExpression extends Expression { | |
| 3723 /** | |
| 3724 * The target of the cascade sections. | |
| 3725 */ | |
| 3726 Expression _target; | |
| 3727 | |
| 3728 /** | |
| 3729 * The cascade sections sharing the common target. | |
| 3730 */ | |
| 3731 NodeList<Expression> _cascadeSections; | |
| 3732 | |
| 3733 /** | |
| 3734 * Initialize a newly created cascade expression. The list of | |
| 3735 * [cascadeSections] must contain at least one element. | |
| 3736 */ | |
| 3737 CascadeExpression(Expression target, List<Expression> cascadeSections) { | |
| 3738 _target = _becomeParentOf(target); | |
| 3739 _cascadeSections = new NodeList<Expression>(this, cascadeSections); | |
| 3740 } | |
| 3741 | |
| 3742 @override | |
| 3743 Token get beginToken => _target.beginToken; | |
| 3744 | |
| 3745 /** | |
| 3746 * Return the cascade sections sharing the common target. | |
| 3747 */ | |
| 3748 NodeList<Expression> get cascadeSections => _cascadeSections; | |
| 3749 | |
| 3750 @override | |
| 3751 Iterable get childEntities => new ChildEntities() | |
| 3752 ..add(_target) | |
| 3753 ..addAll(_cascadeSections); | |
| 3754 | |
| 3755 @override | |
| 3756 Token get endToken => _cascadeSections.endToken; | |
| 3757 | |
| 3758 @override | |
| 3759 int get precedence => 2; | |
| 3760 | |
| 3761 /** | |
| 3762 * Return the target of the cascade sections. | |
| 3763 */ | |
| 3764 Expression get target => _target; | |
| 3765 | |
| 3766 /** | |
| 3767 * Set the target of the cascade sections to the given [expression]. | |
| 3768 */ | |
| 3769 void set target(Expression target) { | |
| 3770 _target = _becomeParentOf(target); | |
| 3771 } | |
| 3772 | |
| 3773 @override | |
| 3774 accept(AstVisitor visitor) => visitor.visitCascadeExpression(this); | |
| 3775 | |
| 3776 @override | |
| 3777 void visitChildren(AstVisitor visitor) { | |
| 3778 _safelyVisitChild(_target, visitor); | |
| 3779 _cascadeSections.accept(visitor); | |
| 3780 } | |
| 3781 } | |
| 3782 | |
| 3783 /** | |
| 3784 * A catch clause within a try statement. | |
| 3785 * | |
| 3786 * > onPart ::= | |
| 3787 * > catchPart [Block] | |
| 3788 * > | 'on' type catchPart? [Block] | |
| 3789 * > | |
| 3790 * > catchPart ::= | |
| 3791 * > 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')' | |
| 3792 */ | |
| 3793 class CatchClause extends AstNode { | |
| 3794 /** | |
| 3795 * The token representing the 'on' keyword, or `null` if there is no 'on' | |
| 3796 * keyword. | |
| 3797 */ | |
| 3798 Token onKeyword; | |
| 3799 | |
| 3800 /** | |
| 3801 * The type of exceptions caught by this catch clause, or `null` if this catch | |
| 3802 * clause catches every type of exception. | |
| 3803 */ | |
| 3804 TypeName _exceptionType; | |
| 3805 | |
| 3806 /** | |
| 3807 * The token representing the 'catch' keyword, or `null` if there is no | |
| 3808 * 'catch' keyword. | |
| 3809 */ | |
| 3810 Token catchKeyword; | |
| 3811 | |
| 3812 /** | |
| 3813 * The left parenthesis, or `null` if there is no 'catch' keyword. | |
| 3814 */ | |
| 3815 Token leftParenthesis; | |
| 3816 | |
| 3817 /** | |
| 3818 * The parameter whose value will be the exception that was thrown, or `null` | |
| 3819 * if there is no 'catch' keyword. | |
| 3820 */ | |
| 3821 SimpleIdentifier _exceptionParameter; | |
| 3822 | |
| 3823 /** | |
| 3824 * The comma separating the exception parameter from the stack trace | |
| 3825 * parameter, or `null` if there is no stack trace parameter. | |
| 3826 */ | |
| 3827 Token comma; | |
| 3828 | |
| 3829 /** | |
| 3830 * The parameter whose value will be the stack trace associated with the | |
| 3831 * exception, or `null` if there is no stack trace parameter. | |
| 3832 */ | |
| 3833 SimpleIdentifier _stackTraceParameter; | |
| 3834 | |
| 3835 /** | |
| 3836 * The right parenthesis, or `null` if there is no 'catch' keyword. | |
| 3837 */ | |
| 3838 Token rightParenthesis; | |
| 3839 | |
| 3840 /** | |
| 3841 * The body of the catch block. | |
| 3842 */ | |
| 3843 Block _body; | |
| 3844 | |
| 3845 /** | |
| 3846 * Initialize a newly created catch clause. The [onKeyword] and | |
| 3847 * [exceptionType] can be `null` if the clause will catch all exceptions. The | |
| 3848 * [comma] and [stackTraceParameter] can be `null` if the stack trace is not | |
| 3849 * referencable within the body. | |
| 3850 */ | |
| 3851 CatchClause(this.onKeyword, TypeName exceptionType, this.catchKeyword, | |
| 3852 this.leftParenthesis, SimpleIdentifier exceptionParameter, this.comma, | |
| 3853 SimpleIdentifier stackTraceParameter, this.rightParenthesis, Block body) { | |
| 3854 _exceptionType = _becomeParentOf(exceptionType); | |
| 3855 _exceptionParameter = _becomeParentOf(exceptionParameter); | |
| 3856 _stackTraceParameter = _becomeParentOf(stackTraceParameter); | |
| 3857 _body = _becomeParentOf(body); | |
| 3858 } | |
| 3859 | |
| 3860 @override | |
| 3861 Token get beginToken { | |
| 3862 if (onKeyword != null) { | |
| 3863 return onKeyword; | |
| 3864 } | |
| 3865 return catchKeyword; | |
| 3866 } | |
| 3867 | |
| 3868 /** | |
| 3869 * Return the body of the catch block. | |
| 3870 */ | |
| 3871 Block get body => _body; | |
| 3872 | |
| 3873 /** | |
| 3874 * Set the body of the catch block to the given [block]. | |
| 3875 */ | |
| 3876 void set body(Block block) { | |
| 3877 _body = _becomeParentOf(block); | |
| 3878 } | |
| 3879 | |
| 3880 @override | |
| 3881 Iterable get childEntities => new ChildEntities() | |
| 3882 ..add(onKeyword) | |
| 3883 ..add(_exceptionType) | |
| 3884 ..add(catchKeyword) | |
| 3885 ..add(leftParenthesis) | |
| 3886 ..add(_exceptionParameter) | |
| 3887 ..add(comma) | |
| 3888 ..add(_stackTraceParameter) | |
| 3889 ..add(rightParenthesis) | |
| 3890 ..add(_body); | |
| 3891 | |
| 3892 @override | |
| 3893 Token get endToken => _body.endToken; | |
| 3894 | |
| 3895 /** | |
| 3896 * Return the parameter whose value will be the exception that was thrown, or | |
| 3897 * `null` if there is no 'catch' keyword. | |
| 3898 */ | |
| 3899 SimpleIdentifier get exceptionParameter => _exceptionParameter; | |
| 3900 | |
| 3901 /** | |
| 3902 * Set the parameter whose value will be the exception that was thrown to the | |
| 3903 * given [parameter]. | |
| 3904 */ | |
| 3905 void set exceptionParameter(SimpleIdentifier parameter) { | |
| 3906 _exceptionParameter = _becomeParentOf(parameter); | |
| 3907 } | |
| 3908 | |
| 3909 /** | |
| 3910 * Return the type of exceptions caught by this catch clause, or `null` if | |
| 3911 * this catch clause catches every type of exception. | |
| 3912 */ | |
| 3913 TypeName get exceptionType => _exceptionType; | |
| 3914 | |
| 3915 /** | |
| 3916 * Set the type of exceptions caught by this catch clause to the given | |
| 3917 * [exceptionType]. | |
| 3918 */ | |
| 3919 void set exceptionType(TypeName exceptionType) { | |
| 3920 _exceptionType = _becomeParentOf(exceptionType); | |
| 3921 } | |
| 3922 | |
| 3923 /** | |
| 3924 * Return the parameter whose value will be the stack trace associated with | |
| 3925 * the exception, or `null` if there is no stack trace parameter. | |
| 3926 */ | |
| 3927 SimpleIdentifier get stackTraceParameter => _stackTraceParameter; | |
| 3928 | |
| 3929 /** | |
| 3930 * Set the parameter whose value will be the stack trace associated with the | |
| 3931 * exception to the given [parameter]. | |
| 3932 */ | |
| 3933 void set stackTraceParameter(SimpleIdentifier parameter) { | |
| 3934 _stackTraceParameter = _becomeParentOf(parameter); | |
| 3935 } | |
| 3936 | |
| 3937 @override | |
| 3938 accept(AstVisitor visitor) => visitor.visitCatchClause(this); | |
| 3939 | |
| 3940 @override | |
| 3941 void visitChildren(AstVisitor visitor) { | |
| 3942 _safelyVisitChild(_exceptionType, visitor); | |
| 3943 _safelyVisitChild(_exceptionParameter, visitor); | |
| 3944 _safelyVisitChild(_stackTraceParameter, visitor); | |
| 3945 _safelyVisitChild(_body, visitor); | |
| 3946 } | |
| 3947 } | |
| 3948 | |
| 3949 /** | |
| 3950 * Helper class to allow iteration of child entities of an AST node. | |
| 3951 */ | |
| 3952 class ChildEntities extends Object with IterableMixin implements Iterable { | |
| 3953 /** | |
| 3954 * The list of child entities to be iterated over. | |
| 3955 */ | |
| 3956 List _entities = []; | |
| 3957 | |
| 3958 @override | |
| 3959 Iterator get iterator => _entities.iterator; | |
| 3960 | |
| 3961 /** | |
| 3962 * Add an AST node or token as the next child entity, if it is not null. | |
| 3963 */ | |
| 3964 void add(entity) { | |
| 3965 if (entity != null) { | |
| 3966 assert(entity is Token || entity is AstNode); | |
| 3967 _entities.add(entity); | |
| 3968 } | |
| 3969 } | |
| 3970 | |
| 3971 /** | |
| 3972 * Add the given items as the next child entities, if [items] is not null. | |
| 3973 */ | |
| 3974 void addAll(Iterable items) { | |
| 3975 if (items != null) { | |
| 3976 _entities.addAll(items); | |
| 3977 } | |
| 3978 } | |
| 3979 } | |
| 3980 | |
| 3981 /** | |
| 3982 * The declaration of a class. | |
| 3983 * | |
| 3984 * > classDeclaration ::= | |
| 3985 * > 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]? | |
| 3986 * > ([ExtendsClause] [WithClause]?)? | |
| 3987 * > [ImplementsClause]? | |
| 3988 * > '{' [ClassMember]* '}' | |
| 3989 */ | |
| 3990 class ClassDeclaration extends NamedCompilationUnitMember { | |
| 3991 /** | |
| 3992 * The 'abstract' keyword, or `null` if the keyword was absent. | |
| 3993 */ | |
| 3994 Token abstractKeyword; | |
| 3995 | |
| 3996 /** | |
| 3997 * The token representing the 'class' keyword. | |
| 3998 */ | |
| 3999 Token classKeyword; | |
| 4000 | |
| 4001 /** | |
| 4002 * The type parameters for the class, or `null` if the class does not have any | |
| 4003 * type parameters. | |
| 4004 */ | |
| 4005 TypeParameterList _typeParameters; | |
| 4006 | |
| 4007 /** | |
| 4008 * The extends clause for the class, or `null` if the class does not extend | |
| 4009 * any other class. | |
| 4010 */ | |
| 4011 ExtendsClause _extendsClause; | |
| 4012 | |
| 4013 /** | |
| 4014 * The with clause for the class, or `null` if the class does not have a with | |
| 4015 * clause. | |
| 4016 */ | |
| 4017 WithClause _withClause; | |
| 4018 | |
| 4019 /** | |
| 4020 * The implements clause for the class, or `null` if the class does not | |
| 4021 * implement any interfaces. | |
| 4022 */ | |
| 4023 ImplementsClause _implementsClause; | |
| 4024 | |
| 4025 /** | |
| 4026 * The native clause for the class, or `null` if the class does not have a | |
| 4027 * native clause. | |
| 4028 */ | |
| 4029 NativeClause _nativeClause; | |
| 4030 | |
| 4031 /** | |
| 4032 * The left curly bracket. | |
| 4033 */ | |
| 4034 Token leftBracket; | |
| 4035 | |
| 4036 /** | |
| 4037 * The members defined by the class. | |
| 4038 */ | |
| 4039 NodeList<ClassMember> _members; | |
| 4040 | |
| 4041 /** | |
| 4042 * The right curly bracket. | |
| 4043 */ | |
| 4044 Token rightBracket; | |
| 4045 | |
| 4046 /** | |
| 4047 * Initialize a newly created class declaration. Either or both of the | |
| 4048 * [comment] and [metadata] can be `null` if the class does not have the | |
| 4049 * corresponding attribute. The [abstractKeyword] can be `null` if the class | |
| 4050 * is not abstract. The [typeParameters] can be `null` if the class does not | |
| 4051 * have any type parameters. Any or all of the [extendsClause], [withClause], | |
| 4052 * and [implementsClause] can be `null` if the class does not have the | |
| 4053 * corresponding clause. The list of [members] can be `null` if the class does | |
| 4054 * not have any members. | |
| 4055 */ | |
| 4056 ClassDeclaration(Comment comment, List<Annotation> metadata, | |
| 4057 this.abstractKeyword, this.classKeyword, SimpleIdentifier name, | |
| 4058 TypeParameterList typeParameters, ExtendsClause extendsClause, | |
| 4059 WithClause withClause, ImplementsClause implementsClause, | |
| 4060 this.leftBracket, List<ClassMember> members, this.rightBracket) | |
| 4061 : super(comment, metadata, name) { | |
| 4062 _typeParameters = _becomeParentOf(typeParameters); | |
| 4063 _extendsClause = _becomeParentOf(extendsClause); | |
| 4064 _withClause = _becomeParentOf(withClause); | |
| 4065 _implementsClause = _becomeParentOf(implementsClause); | |
| 4066 _members = new NodeList<ClassMember>(this, members); | |
| 4067 } | |
| 4068 | |
| 4069 @override | |
| 4070 Iterable get childEntities => super._childEntities | |
| 4071 ..add(abstractKeyword) | |
| 4072 ..add(classKeyword) | |
| 4073 ..add(_name) | |
| 4074 ..add(_typeParameters) | |
| 4075 ..add(_extendsClause) | |
| 4076 ..add(_withClause) | |
| 4077 ..add(_implementsClause) | |
| 4078 ..add(_nativeClause) | |
| 4079 ..add(leftBracket) | |
| 4080 ..addAll(members) | |
| 4081 ..add(rightBracket); | |
| 4082 | |
| 4083 @override | |
| 4084 ClassElement get element => | |
| 4085 _name != null ? (_name.staticElement as ClassElement) : null; | |
| 4086 | |
| 4087 @override | |
| 4088 Token get endToken => rightBracket; | |
| 4089 | |
| 4090 /** | |
| 4091 * Return the extends clause for this class, or `null` if the class does not | |
| 4092 * extend any other class. | |
| 4093 */ | |
| 4094 ExtendsClause get extendsClause => _extendsClause; | |
| 4095 | |
| 4096 /** | |
| 4097 * Set the extends clause for this class to the given [extendsClause]. | |
| 4098 */ | |
| 4099 void set extendsClause(ExtendsClause extendsClause) { | |
| 4100 _extendsClause = _becomeParentOf(extendsClause); | |
| 4101 } | |
| 4102 | |
| 4103 @override | |
| 4104 Token get firstTokenAfterCommentAndMetadata { | |
| 4105 if (abstractKeyword != null) { | |
| 4106 return abstractKeyword; | |
| 4107 } | |
| 4108 return classKeyword; | |
| 4109 } | |
| 4110 | |
| 4111 /** | |
| 4112 * Return the implements clause for the class, or `null` if the class does not | |
| 4113 * implement any interfaces. | |
| 4114 */ | |
| 4115 ImplementsClause get implementsClause => _implementsClause; | |
| 4116 | |
| 4117 /** | |
| 4118 * Set the implements clause for the class to the given [implementsClause]. | |
| 4119 */ | |
| 4120 void set implementsClause(ImplementsClause implementsClause) { | |
| 4121 _implementsClause = _becomeParentOf(implementsClause); | |
| 4122 } | |
| 4123 | |
| 4124 /** | |
| 4125 * Return `true` if this class is declared to be an abstract class. | |
| 4126 */ | |
| 4127 bool get isAbstract => abstractKeyword != null; | |
| 4128 | |
| 4129 /** | |
| 4130 * Return the members defined by the class. | |
| 4131 */ | |
| 4132 NodeList<ClassMember> get members => _members; | |
| 4133 | |
| 4134 /** | |
| 4135 * Return the native clause for this class, or `null` if the class does not | |
| 4136 * have a native clause. | |
| 4137 */ | |
| 4138 NativeClause get nativeClause => _nativeClause; | |
| 4139 | |
| 4140 /** | |
| 4141 * Set the native clause for this class to the given [nativeClause]. | |
| 4142 */ | |
| 4143 void set nativeClause(NativeClause nativeClause) { | |
| 4144 _nativeClause = _becomeParentOf(nativeClause); | |
| 4145 } | |
| 4146 | |
| 4147 /** | |
| 4148 * Return the type parameters for the class, or `null` if the class does not | |
| 4149 * have any type parameters. | |
| 4150 */ | |
| 4151 TypeParameterList get typeParameters => _typeParameters; | |
| 4152 | |
| 4153 /** | |
| 4154 * Set the type parameters for the class to the given list of [typeParameters]
. | |
| 4155 */ | |
| 4156 void set typeParameters(TypeParameterList typeParameters) { | |
| 4157 _typeParameters = _becomeParentOf(typeParameters); | |
| 4158 } | |
| 4159 | |
| 4160 /** | |
| 4161 * Return the with clause for the class, or `null` if the class does not have | |
| 4162 * a with clause. | |
| 4163 */ | |
| 4164 WithClause get withClause => _withClause; | |
| 4165 | |
| 4166 /** | |
| 4167 * Set the with clause for the class to the given [withClause]. | |
| 4168 */ | |
| 4169 void set withClause(WithClause withClause) { | |
| 4170 _withClause = _becomeParentOf(withClause); | |
| 4171 } | |
| 4172 | |
| 4173 @override | |
| 4174 accept(AstVisitor visitor) => visitor.visitClassDeclaration(this); | |
| 4175 | |
| 4176 /** | |
| 4177 * Return the constructor declared in the class with the given [name], or | |
| 4178 * `null` if there is no such constructor. If the [name] is `null` then the | |
| 4179 * default constructor will be searched for. | |
| 4180 */ | |
| 4181 ConstructorDeclaration getConstructor(String name) { | |
| 4182 for (ClassMember classMember in _members) { | |
| 4183 if (classMember is ConstructorDeclaration) { | |
| 4184 ConstructorDeclaration constructor = classMember; | |
| 4185 SimpleIdentifier constructorName = constructor.name; | |
| 4186 if (name == null && constructorName == null) { | |
| 4187 return constructor; | |
| 4188 } | |
| 4189 if (constructorName != null && constructorName.name == name) { | |
| 4190 return constructor; | |
| 4191 } | |
| 4192 } | |
| 4193 } | |
| 4194 return null; | |
| 4195 } | |
| 4196 | |
| 4197 /** | |
| 4198 * Return the field declared in the class with the given [name], or `null` if | |
| 4199 * there is no such field. | |
| 4200 */ | |
| 4201 VariableDeclaration getField(String name) { | |
| 4202 for (ClassMember classMember in _members) { | |
| 4203 if (classMember is FieldDeclaration) { | |
| 4204 FieldDeclaration fieldDeclaration = classMember; | |
| 4205 NodeList<VariableDeclaration> fields = | |
| 4206 fieldDeclaration.fields.variables; | |
| 4207 for (VariableDeclaration field in fields) { | |
| 4208 SimpleIdentifier fieldName = field.name; | |
| 4209 if (fieldName != null && name == fieldName.name) { | |
| 4210 return field; | |
| 4211 } | |
| 4212 } | |
| 4213 } | |
| 4214 } | |
| 4215 return null; | |
| 4216 } | |
| 4217 | |
| 4218 /** | |
| 4219 * Return the method declared in the class with the given [name], or `null` if | |
| 4220 * there is no such method. | |
| 4221 */ | |
| 4222 MethodDeclaration getMethod(String name) { | |
| 4223 for (ClassMember classMember in _members) { | |
| 4224 if (classMember is MethodDeclaration) { | |
| 4225 MethodDeclaration method = classMember; | |
| 4226 SimpleIdentifier methodName = method.name; | |
| 4227 if (methodName != null && name == methodName.name) { | |
| 4228 return method; | |
| 4229 } | |
| 4230 } | |
| 4231 } | |
| 4232 return null; | |
| 4233 } | |
| 4234 | |
| 4235 @override | |
| 4236 void visitChildren(AstVisitor visitor) { | |
| 4237 super.visitChildren(visitor); | |
| 4238 _safelyVisitChild(_name, visitor); | |
| 4239 _safelyVisitChild(_typeParameters, visitor); | |
| 4240 _safelyVisitChild(_extendsClause, visitor); | |
| 4241 _safelyVisitChild(_withClause, visitor); | |
| 4242 _safelyVisitChild(_implementsClause, visitor); | |
| 4243 _safelyVisitChild(_nativeClause, visitor); | |
| 4244 members.accept(visitor); | |
| 4245 } | |
| 4246 } | |
| 4247 | |
| 4248 /** | |
| 4249 * A node that declares a name within the scope of a class. | |
| 4250 */ | |
| 4251 abstract class ClassMember extends Declaration { | |
| 4252 /** | |
| 4253 * Initialize a newly created member of a class. Either or both of the | |
| 4254 * [comment] and [metadata] can be `null` if the member does not have the | |
| 4255 * corresponding attribute. | |
| 4256 */ | |
| 4257 ClassMember(Comment comment, List<Annotation> metadata) | |
| 4258 : super(comment, metadata); | |
| 4259 } | |
| 4260 | |
| 4261 /** | |
| 4262 * A class type alias. | |
| 4263 * | |
| 4264 * > classTypeAlias ::= | |
| 4265 * > [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplicatio
n | |
| 4266 * > | |
| 4267 * > mixinApplication ::= | |
| 4268 * > [TypeName] [WithClause] [ImplementsClause]? ';' | |
| 4269 */ | |
| 4270 class ClassTypeAlias extends TypeAlias { | |
| 4271 /** | |
| 4272 * The type parameters for the class, or `null` if the class does not have any | |
| 4273 * type parameters. | |
| 4274 */ | |
| 4275 TypeParameterList _typeParameters; | |
| 4276 | |
| 4277 /** | |
| 4278 * The token for the '=' separating the name from the definition. | |
| 4279 */ | |
| 4280 Token equals; | |
| 4281 | |
| 4282 /** | |
| 4283 * The token for the 'abstract' keyword, or `null` if this is not defining an | |
| 4284 * abstract class. | |
| 4285 */ | |
| 4286 Token abstractKeyword; | |
| 4287 | |
| 4288 /** | |
| 4289 * The name of the superclass of the class being declared. | |
| 4290 */ | |
| 4291 TypeName _superclass; | |
| 4292 | |
| 4293 /** | |
| 4294 * The with clause for this class. | |
| 4295 */ | |
| 4296 WithClause _withClause; | |
| 4297 | |
| 4298 /** | |
| 4299 * The implements clause for this class, or `null` if there is no implements | |
| 4300 * clause. | |
| 4301 */ | |
| 4302 ImplementsClause _implementsClause; | |
| 4303 | |
| 4304 /** | |
| 4305 * Initialize a newly created class type alias. Either or both of the | |
| 4306 * [comment] and [metadata] can be `null` if the class type alias does not | |
| 4307 * have the corresponding attribute. The [typeParameters] can be `null` if the | |
| 4308 * class does not have any type parameters. The [abstractKeyword] can be | |
| 4309 * `null` if the class is not abstract. The [implementsClause] can be `null` | |
| 4310 * if the class does not implement any interfaces. | |
| 4311 */ | |
| 4312 ClassTypeAlias(Comment comment, List<Annotation> metadata, Token keyword, | |
| 4313 SimpleIdentifier name, TypeParameterList typeParameters, this.equals, | |
| 4314 this.abstractKeyword, TypeName superclass, WithClause withClause, | |
| 4315 ImplementsClause implementsClause, Token semicolon) | |
| 4316 : super(comment, metadata, keyword, name, semicolon) { | |
| 4317 _typeParameters = _becomeParentOf(typeParameters); | |
| 4318 _superclass = _becomeParentOf(superclass); | |
| 4319 _withClause = _becomeParentOf(withClause); | |
| 4320 _implementsClause = _becomeParentOf(implementsClause); | |
| 4321 } | |
| 4322 | |
| 4323 @override | |
| 4324 Iterable get childEntities => super._childEntities | |
| 4325 ..add(typedefKeyword) | |
| 4326 ..add(_name) | |
| 4327 ..add(_typeParameters) | |
| 4328 ..add(equals) | |
| 4329 ..add(abstractKeyword) | |
| 4330 ..add(_superclass) | |
| 4331 ..add(_withClause) | |
| 4332 ..add(_implementsClause) | |
| 4333 ..add(semicolon); | |
| 4334 | |
| 4335 @override | |
| 4336 ClassElement get element => | |
| 4337 _name != null ? (_name.staticElement as ClassElement) : null; | |
| 4338 | |
| 4339 /** | |
| 4340 * Return the implements clause for this class, or `null` if there is no | |
| 4341 * implements clause. | |
| 4342 */ | |
| 4343 ImplementsClause get implementsClause => _implementsClause; | |
| 4344 | |
| 4345 /** | |
| 4346 * Set the implements clause for this class to the given [implementsClause]. | |
| 4347 */ | |
| 4348 void set implementsClause(ImplementsClause implementsClause) { | |
| 4349 _implementsClause = _becomeParentOf(implementsClause); | |
| 4350 } | |
| 4351 | |
| 4352 /** | |
| 4353 * Return `true` if this class is declared to be an abstract class. | |
| 4354 */ | |
| 4355 bool get isAbstract => abstractKeyword != null; | |
| 4356 | |
| 4357 /** | |
| 4358 * Return the name of the superclass of the class being declared. | |
| 4359 */ | |
| 4360 TypeName get superclass => _superclass; | |
| 4361 | |
| 4362 /** | |
| 4363 * Set the name of the superclass of the class being declared to the given | |
| 4364 * [superclass] name. | |
| 4365 */ | |
| 4366 void set superclass(TypeName superclass) { | |
| 4367 _superclass = _becomeParentOf(superclass); | |
| 4368 } | |
| 4369 | |
| 4370 /** | |
| 4371 * Return the type parameters for the class, or `null` if the class does not | |
| 4372 * have any type parameters. | |
| 4373 */ | |
| 4374 TypeParameterList get typeParameters => _typeParameters; | |
| 4375 | |
| 4376 /** | |
| 4377 * Set the type parameters for the class to the given list of [typeParameters]
. | |
| 4378 */ | |
| 4379 void set typeParameters(TypeParameterList typeParameters) { | |
| 4380 _typeParameters = _becomeParentOf(typeParameters); | |
| 4381 } | |
| 4382 | |
| 4383 /** | |
| 4384 * Return the with clause for this class. | |
| 4385 */ | |
| 4386 WithClause get withClause => _withClause; | |
| 4387 | |
| 4388 /** | |
| 4389 * Set the with clause for this class to the given with [withClause]. | |
| 4390 */ | |
| 4391 void set withClause(WithClause withClause) { | |
| 4392 _withClause = _becomeParentOf(withClause); | |
| 4393 } | |
| 4394 | |
| 4395 @override | |
| 4396 accept(AstVisitor visitor) => visitor.visitClassTypeAlias(this); | |
| 4397 | |
| 4398 @override | |
| 4399 void visitChildren(AstVisitor visitor) { | |
| 4400 super.visitChildren(visitor); | |
| 4401 _safelyVisitChild(_name, visitor); | |
| 4402 _safelyVisitChild(_typeParameters, visitor); | |
| 4403 _safelyVisitChild(_superclass, visitor); | |
| 4404 _safelyVisitChild(_withClause, visitor); | |
| 4405 _safelyVisitChild(_implementsClause, visitor); | |
| 4406 } | |
| 4407 } | |
| 4408 | |
| 4409 /** | |
| 4410 * A combinator associated with an import or export directive. | |
| 4411 * | |
| 4412 * > combinator ::= | |
| 4413 * > [HideCombinator] | |
| 4414 * > | [ShowCombinator] | |
| 4415 */ | |
| 4416 abstract class Combinator extends AstNode { | |
| 4417 /** | |
| 4418 * The 'hide' or 'show' keyword specifying what kind of processing is to be | |
| 4419 * done on the names. | |
| 4420 */ | |
| 4421 Token keyword; | |
| 4422 | |
| 4423 /** | |
| 4424 * Initialize a newly created combinator. | |
| 4425 */ | |
| 4426 Combinator(this.keyword); | |
| 4427 | |
| 4428 @override | |
| 4429 Token get beginToken => keyword; | |
| 4430 } | |
| 4431 | |
| 4432 /** | |
| 4433 * A comment within the source code. | |
| 4434 * | |
| 4435 * > comment ::= | |
| 4436 * > endOfLineComment | |
| 4437 * > | blockComment | |
| 4438 * > | documentationComment | |
| 4439 * > | |
| 4440 * > endOfLineComment ::= | |
| 4441 * > '//' (CHARACTER - EOL)* EOL | |
| 4442 * > | |
| 4443 * > blockComment ::= | |
| 4444 * > '/ *' CHARACTER* '*/' | |
| 4445 * > | |
| 4446 * > documentationComment ::= | |
| 4447 * > '/ **' (CHARACTER | [CommentReference])* '*/' | |
| 4448 * > | ('///' (CHARACTER - EOL)* EOL)+ | |
| 4449 */ | |
| 4450 class Comment extends AstNode { | |
| 4451 /** | |
| 4452 * The tokens representing the comment. | |
| 4453 */ | |
| 4454 final List<Token> tokens; | |
| 4455 | |
| 4456 /** | |
| 4457 * The type of the comment. | |
| 4458 */ | |
| 4459 final CommentType _type; | |
| 4460 | |
| 4461 /** | |
| 4462 * The references embedded within the documentation comment. This list will be | |
| 4463 * empty unless this is a documentation comment that has references embedded | |
| 4464 * within it. | |
| 4465 */ | |
| 4466 NodeList<CommentReference> _references; | |
| 4467 | |
| 4468 /** | |
| 4469 * Initialize a newly created comment. The list of [tokens] must contain at | |
| 4470 * least one token. The [type] is the type of the comment. The list of | |
| 4471 * [references] can be empty if the comment does not contain any embedded | |
| 4472 * references. | |
| 4473 */ | |
| 4474 Comment(this.tokens, this._type, List<CommentReference> references) { | |
| 4475 _references = new NodeList<CommentReference>(this, references); | |
| 4476 } | |
| 4477 | |
| 4478 @override | |
| 4479 Token get beginToken => tokens[0]; | |
| 4480 | |
| 4481 @override | |
| 4482 Iterable get childEntities => new ChildEntities()..addAll(tokens); | |
| 4483 | |
| 4484 @override | |
| 4485 Token get endToken => tokens[tokens.length - 1]; | |
| 4486 | |
| 4487 /** | |
| 4488 * Return `true` if this is a block comment. | |
| 4489 */ | |
| 4490 bool get isBlock => _type == CommentType.BLOCK; | |
| 4491 | |
| 4492 /** | |
| 4493 * Return `true` if this is a documentation comment. | |
| 4494 */ | |
| 4495 bool get isDocumentation => _type == CommentType.DOCUMENTATION; | |
| 4496 | |
| 4497 /** | |
| 4498 * Return `true` if this is an end-of-line comment. | |
| 4499 */ | |
| 4500 bool get isEndOfLine => _type == CommentType.END_OF_LINE; | |
| 4501 | |
| 4502 /** | |
| 4503 * Return the references embedded within the documentation comment. | |
| 4504 */ | |
| 4505 NodeList<CommentReference> get references => _references; | |
| 4506 | |
| 4507 @override | |
| 4508 accept(AstVisitor visitor) => visitor.visitComment(this); | |
| 4509 | |
| 4510 @override | |
| 4511 void visitChildren(AstVisitor visitor) { | |
| 4512 _references.accept(visitor); | |
| 4513 } | |
| 4514 | |
| 4515 /** | |
| 4516 * Create a block comment consisting of the given [tokens]. | |
| 4517 */ | |
| 4518 static Comment createBlockComment(List<Token> tokens) => | |
| 4519 new Comment(tokens, CommentType.BLOCK, null); | |
| 4520 | |
| 4521 /** | |
| 4522 * Create a documentation comment consisting of the given [tokens]. | |
| 4523 */ | |
| 4524 static Comment createDocumentationComment(List<Token> tokens) => new Comment( | |
| 4525 tokens, CommentType.DOCUMENTATION, new List<CommentReference>()); | |
| 4526 | |
| 4527 /** | |
| 4528 * Create a documentation comment consisting of the given [tokens] and having | |
| 4529 * the given [references] embedded within it. | |
| 4530 */ | |
| 4531 static Comment createDocumentationCommentWithReferences( | |
| 4532 List<Token> tokens, List<CommentReference> references) => | |
| 4533 new Comment(tokens, CommentType.DOCUMENTATION, references); | |
| 4534 | |
| 4535 /** | |
| 4536 * Create an end-of-line comment consisting of the given [tokens]. | |
| 4537 */ | |
| 4538 static Comment createEndOfLineComment(List<Token> tokens) => | |
| 4539 new Comment(tokens, CommentType.END_OF_LINE, null); | |
| 4540 } | |
| 4541 | |
| 4542 /** | |
| 4543 * A reference to a Dart element that is found within a documentation comment. | |
| 4544 * | |
| 4545 * > commentReference ::= | |
| 4546 * > '[' 'new'? [Identifier] ']' | |
| 4547 */ | |
| 4548 class CommentReference extends AstNode { | |
| 4549 /** | |
| 4550 * The token representing the 'new' keyword, or `null` if there was no 'new' | |
| 4551 * keyword. | |
| 4552 */ | |
| 4553 Token newKeyword; | |
| 4554 | |
| 4555 /** | |
| 4556 * The identifier being referenced. | |
| 4557 */ | |
| 4558 Identifier _identifier; | |
| 4559 | |
| 4560 /** | |
| 4561 * Initialize a newly created reference to a Dart element. The [newKeyword] | |
| 4562 * can be `null` if the reference is not to a constructor. | |
| 4563 */ | |
| 4564 CommentReference(this.newKeyword, Identifier identifier) { | |
| 4565 _identifier = _becomeParentOf(identifier); | |
| 4566 } | |
| 4567 | |
| 4568 @override | |
| 4569 Token get beginToken => _identifier.beginToken; | |
| 4570 | |
| 4571 @override | |
| 4572 Iterable get childEntities => | |
| 4573 new ChildEntities()..add(newKeyword)..add(_identifier); | |
| 4574 | |
| 4575 @override | |
| 4576 Token get endToken => _identifier.endToken; | |
| 4577 | |
| 4578 /** | |
| 4579 * Return the identifier being referenced. | |
| 4580 */ | |
| 4581 Identifier get identifier => _identifier; | |
| 4582 | |
| 4583 /** | |
| 4584 * Set the identifier being referenced to the given [identifier]. | |
| 4585 */ | |
| 4586 void set identifier(Identifier identifier) { | |
| 4587 _identifier = _becomeParentOf(identifier); | |
| 4588 } | |
| 4589 | |
| 4590 @override | |
| 4591 accept(AstVisitor visitor) => visitor.visitCommentReference(this); | |
| 4592 | |
| 4593 @override | |
| 4594 void visitChildren(AstVisitor visitor) { | |
| 4595 _safelyVisitChild(_identifier, visitor); | |
| 4596 } | |
| 4597 } | |
| 4598 | |
| 4599 /** | |
| 4600 * The possible types of comments that are recognized by the parser. | |
| 4601 */ | |
| 4602 class CommentType { | |
| 4603 /** | |
| 4604 * A block comment. | |
| 4605 */ | |
| 4606 static const CommentType BLOCK = const CommentType('BLOCK'); | |
| 4607 | |
| 4608 /** | |
| 4609 * A documentation comment. | |
| 4610 */ | |
| 4611 static const CommentType DOCUMENTATION = const CommentType('DOCUMENTATION'); | |
| 4612 | |
| 4613 /** | |
| 4614 * An end-of-line comment. | |
| 4615 */ | |
| 4616 static const CommentType END_OF_LINE = const CommentType('END_OF_LINE'); | |
| 4617 | |
| 4618 /** | |
| 4619 * The name of the comment type. | |
| 4620 */ | |
| 4621 final String name; | |
| 4622 | |
| 4623 /** | |
| 4624 * Initialize a newly created comment type to have the given [name]. | |
| 4625 */ | |
| 4626 const CommentType(this.name); | |
| 4627 | |
| 4628 @override | |
| 4629 String toString() => name; | |
| 4630 } | |
| 4631 | |
| 4632 /** | |
| 4633 * A compilation unit. | |
| 4634 * | |
| 4635 * While the grammar restricts the order of the directives and declarations | |
| 4636 * within a compilation unit, this class does not enforce those restrictions. | |
| 4637 * In particular, the children of a compilation unit will be visited in lexical | |
| 4638 * order even if lexical order does not conform to the restrictions of the | |
| 4639 * grammar. | |
| 4640 * | |
| 4641 * > compilationUnit ::= | |
| 4642 * > directives declarations | |
| 4643 * > | |
| 4644 * > directives ::= | |
| 4645 * > [ScriptTag]? [LibraryDirective]? namespaceDirective* [PartDirective]* | |
| 4646 * > | [PartOfDirective] | |
| 4647 * > | |
| 4648 * > namespaceDirective ::= | |
| 4649 * > [ImportDirective] | |
| 4650 * > | [ExportDirective] | |
| 4651 * > | |
| 4652 * > declarations ::= | |
| 4653 * > [CompilationUnitMember]* | |
| 4654 */ | |
| 4655 class CompilationUnit extends AstNode { | |
| 4656 /** | |
| 4657 * The first token in the token stream that was parsed to form this | |
| 4658 * compilation unit. | |
| 4659 */ | |
| 4660 Token beginToken; | |
| 4661 | |
| 4662 /** | |
| 4663 * The script tag at the beginning of the compilation unit, or `null` if there | |
| 4664 * is no script tag in this compilation unit. | |
| 4665 */ | |
| 4666 ScriptTag _scriptTag; | |
| 4667 | |
| 4668 /** | |
| 4669 * The directives contained in this compilation unit. | |
| 4670 */ | |
| 4671 NodeList<Directive> _directives; | |
| 4672 | |
| 4673 /** | |
| 4674 * The declarations contained in this compilation unit. | |
| 4675 */ | |
| 4676 NodeList<CompilationUnitMember> _declarations; | |
| 4677 | |
| 4678 /** | |
| 4679 * The last token in the token stream that was parsed to form this compilation | |
| 4680 * unit. This token should always have a type of [TokenType.EOF]. | |
| 4681 */ | |
| 4682 Token endToken; | |
| 4683 | |
| 4684 /** | |
| 4685 * The element associated with this compilation unit, or `null` if the AST | |
| 4686 * structure has not been resolved. | |
| 4687 */ | |
| 4688 CompilationUnitElement element; | |
| 4689 | |
| 4690 /** | |
| 4691 * The line information for this compilation unit. | |
| 4692 */ | |
| 4693 LineInfo lineInfo; | |
| 4694 | |
| 4695 /** | |
| 4696 * Initialize a newly created compilation unit to have the given directives | |
| 4697 * and declarations. The [scriptTag] can be `null` if there is no script tag | |
| 4698 * in the compilation unit. The list of [directives] can be `null` if there | |
| 4699 * are no directives in the compilation unit. The list of [declarations] can | |
| 4700 * be `null` if there are no declarations in the compilation unit. | |
| 4701 */ | |
| 4702 CompilationUnit(this.beginToken, ScriptTag scriptTag, | |
| 4703 List<Directive> directives, List<CompilationUnitMember> declarations, | |
| 4704 this.endToken) { | |
| 4705 _scriptTag = _becomeParentOf(scriptTag); | |
| 4706 _directives = new NodeList<Directive>(this, directives); | |
| 4707 _declarations = new NodeList<CompilationUnitMember>(this, declarations); | |
| 4708 } | |
| 4709 | |
| 4710 @override | |
| 4711 Iterable get childEntities { | |
| 4712 ChildEntities result = new ChildEntities()..add(_scriptTag); | |
| 4713 if (_directivesAreBeforeDeclarations) { | |
| 4714 result..addAll(_directives)..addAll(_declarations); | |
| 4715 } else { | |
| 4716 result.addAll(sortedDirectivesAndDeclarations); | |
| 4717 } | |
| 4718 return result; | |
| 4719 } | |
| 4720 | |
| 4721 /** | |
| 4722 * Return the declarations contained in this compilation unit. | |
| 4723 */ | |
| 4724 NodeList<CompilationUnitMember> get declarations => _declarations; | |
| 4725 | |
| 4726 /** | |
| 4727 * Return the directives contained in this compilation unit. | |
| 4728 */ | |
| 4729 NodeList<Directive> get directives => _directives; | |
| 4730 | |
| 4731 @override | |
| 4732 int get length { | |
| 4733 Token endToken = this.endToken; | |
| 4734 if (endToken == null) { | |
| 4735 return 0; | |
| 4736 } | |
| 4737 return endToken.offset + endToken.length; | |
| 4738 } | |
| 4739 | |
| 4740 @override | |
| 4741 int get offset => 0; | |
| 4742 | |
| 4743 /** | |
| 4744 * Return the script tag at the beginning of the compilation unit, or `null` | |
| 4745 * if there is no script tag in this compilation unit. | |
| 4746 */ | |
| 4747 ScriptTag get scriptTag => _scriptTag; | |
| 4748 | |
| 4749 /** | |
| 4750 * Set the script tag at the beginning of the compilation unit to the given | |
| 4751 * [scriptTag]. | |
| 4752 */ | |
| 4753 void set scriptTag(ScriptTag scriptTag) { | |
| 4754 _scriptTag = _becomeParentOf(scriptTag); | |
| 4755 } | |
| 4756 | |
| 4757 /** | |
| 4758 * Return a list containing all of the directives and declarations in this | |
| 4759 * compilation unit, sorted in lexical order. | |
| 4760 */ | |
| 4761 List<AstNode> get sortedDirectivesAndDeclarations { | |
| 4762 return <AstNode>[] | |
| 4763 ..addAll(_directives) | |
| 4764 ..addAll(_declarations) | |
| 4765 ..sort(AstNode.LEXICAL_ORDER); | |
| 4766 } | |
| 4767 | |
| 4768 /** | |
| 4769 * Return `true` if all of the directives are lexically before any | |
| 4770 * declarations. | |
| 4771 */ | |
| 4772 bool get _directivesAreBeforeDeclarations { | |
| 4773 if (_directives.isEmpty || _declarations.isEmpty) { | |
| 4774 return true; | |
| 4775 } | |
| 4776 Directive lastDirective = _directives[_directives.length - 1]; | |
| 4777 CompilationUnitMember firstDeclaration = _declarations[0]; | |
| 4778 return lastDirective.offset < firstDeclaration.offset; | |
| 4779 } | |
| 4780 | |
| 4781 @override | |
| 4782 accept(AstVisitor visitor) => visitor.visitCompilationUnit(this); | |
| 4783 | |
| 4784 @override | |
| 4785 void visitChildren(AstVisitor visitor) { | |
| 4786 _safelyVisitChild(_scriptTag, visitor); | |
| 4787 if (_directivesAreBeforeDeclarations) { | |
| 4788 _directives.accept(visitor); | |
| 4789 _declarations.accept(visitor); | |
| 4790 } else { | |
| 4791 for (AstNode child in sortedDirectivesAndDeclarations) { | |
| 4792 child.accept(visitor); | |
| 4793 } | |
| 4794 } | |
| 4795 } | |
| 4796 } | |
| 4797 | |
| 4798 /** | |
| 4799 * A node that declares one or more names within the scope of a compilation | |
| 4800 * unit. | |
| 4801 * | |
| 4802 * > compilationUnitMember ::= | |
| 4803 * > [ClassDeclaration] | |
| 4804 * > | [TypeAlias] | |
| 4805 * > | [FunctionDeclaration] | |
| 4806 * > | [MethodDeclaration] | |
| 4807 * > | [VariableDeclaration] | |
| 4808 * > | [VariableDeclaration] | |
| 4809 */ | |
| 4810 abstract class CompilationUnitMember extends Declaration { | |
| 4811 /** | |
| 4812 * Initialize a newly created generic compilation unit member. Either or both | |
| 4813 * of the [comment] and [metadata] can be `null` if the member does not have | |
| 4814 * the corresponding attribute. | |
| 4815 */ | |
| 4816 CompilationUnitMember(Comment comment, List<Annotation> metadata) | |
| 4817 : super(comment, metadata); | |
| 4818 } | |
| 4819 | |
| 4820 /** | |
| 4821 * A conditional expression. | |
| 4822 * | |
| 4823 * > conditionalExpression ::= | |
| 4824 * > [Expression] '?' [Expression] ':' [Expression] | |
| 4825 */ | |
| 4826 class ConditionalExpression extends Expression { | |
| 4827 /** | |
| 4828 * The condition used to determine which of the expressions is executed next. | |
| 4829 */ | |
| 4830 Expression _condition; | |
| 4831 | |
| 4832 /** | |
| 4833 * The token used to separate the condition from the then expression. | |
| 4834 */ | |
| 4835 Token question; | |
| 4836 | |
| 4837 /** | |
| 4838 * The expression that is executed if the condition evaluates to `true`. | |
| 4839 */ | |
| 4840 Expression _thenExpression; | |
| 4841 | |
| 4842 /** | |
| 4843 * The token used to separate the then expression from the else expression. | |
| 4844 */ | |
| 4845 Token colon; | |
| 4846 | |
| 4847 /** | |
| 4848 * The expression that is executed if the condition evaluates to `false`. | |
| 4849 */ | |
| 4850 Expression _elseExpression; | |
| 4851 | |
| 4852 /** | |
| 4853 * Initialize a newly created conditional expression. | |
| 4854 */ | |
| 4855 ConditionalExpression(Expression condition, this.question, | |
| 4856 Expression thenExpression, this.colon, Expression elseExpression) { | |
| 4857 _condition = _becomeParentOf(condition); | |
| 4858 _thenExpression = _becomeParentOf(thenExpression); | |
| 4859 _elseExpression = _becomeParentOf(elseExpression); | |
| 4860 } | |
| 4861 | |
| 4862 @override | |
| 4863 Token get beginToken => _condition.beginToken; | |
| 4864 | |
| 4865 @override | |
| 4866 Iterable get childEntities => new ChildEntities() | |
| 4867 ..add(_condition) | |
| 4868 ..add(question) | |
| 4869 ..add(_thenExpression) | |
| 4870 ..add(colon) | |
| 4871 ..add(_elseExpression); | |
| 4872 | |
| 4873 /** | |
| 4874 * Return the condition used to determine which of the expressions is executed | |
| 4875 * next. | |
| 4876 */ | |
| 4877 Expression get condition => _condition; | |
| 4878 | |
| 4879 /** | |
| 4880 * Set the condition used to determine which of the expressions is executed | |
| 4881 * next to the given [expression]. | |
| 4882 */ | |
| 4883 void set condition(Expression expression) { | |
| 4884 _condition = _becomeParentOf(expression); | |
| 4885 } | |
| 4886 | |
| 4887 /** | |
| 4888 * Return the expression that is executed if the condition evaluates to | |
| 4889 * `false`. | |
| 4890 */ | |
| 4891 Expression get elseExpression => _elseExpression; | |
| 4892 | |
| 4893 /** | |
| 4894 * Set the expression that is executed if the condition evaluates to `false` | |
| 4895 * to the given [expression]. | |
| 4896 */ | |
| 4897 void set elseExpression(Expression expression) { | |
| 4898 _elseExpression = _becomeParentOf(expression); | |
| 4899 } | |
| 4900 | |
| 4901 @override | |
| 4902 Token get endToken => _elseExpression.endToken; | |
| 4903 | |
| 4904 @override | |
| 4905 int get precedence => 3; | |
| 4906 | |
| 4907 /** | |
| 4908 * Return the expression that is executed if the condition evaluates to | |
| 4909 * `true`. | |
| 4910 */ | |
| 4911 Expression get thenExpression => _thenExpression; | |
| 4912 | |
| 4913 /** | |
| 4914 * Set the expression that is executed if the condition evaluates to `true` to | |
| 4915 * the given [expression]. | |
| 4916 */ | |
| 4917 void set thenExpression(Expression expression) { | |
| 4918 _thenExpression = _becomeParentOf(expression); | |
| 4919 } | |
| 4920 | |
| 4921 @override | |
| 4922 accept(AstVisitor visitor) => visitor.visitConditionalExpression(this); | |
| 4923 | |
| 4924 @override | |
| 4925 void visitChildren(AstVisitor visitor) { | |
| 4926 _safelyVisitChild(_condition, visitor); | |
| 4927 _safelyVisitChild(_thenExpression, visitor); | |
| 4928 _safelyVisitChild(_elseExpression, visitor); | |
| 4929 } | |
| 4930 } | |
| 4931 | |
| 4932 /** | |
| 4933 * An object that can be used to evaluate constant expressions to produce their | |
| 4934 * compile-time value. According to the Dart Language Specification: | |
| 4935 * <blockquote> | |
| 4936 * A constant expression is one of the following: | |
| 4937 * * A literal number. | |
| 4938 * * A literal boolean. | |
| 4939 * * A literal string where any interpolated expression is a compile-time | |
| 4940 * constant that evaluates to a numeric, string or boolean value or to `null`. | |
| 4941 * * `null`. | |
| 4942 * * A reference to a static constant variable. | |
| 4943 * * An identifier expression that denotes a constant variable, a class or a | |
| 4944 * type parameter. | |
| 4945 * * A constant constructor invocation. | |
| 4946 * * A constant list literal. | |
| 4947 * * A constant map literal. | |
| 4948 * * A simple or qualified identifier denoting a top-level function or a static | |
| 4949 * method. | |
| 4950 * * A parenthesized expression `(e)` where `e` is a constant expression. | |
| 4951 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, | |
| 4952 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a | |
| 4953 * numeric, string or boolean value or to `null`. | |
| 4954 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where | |
| 4955 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean | |
| 4956 * value or to `null`. | |
| 4957 * * An expression of one of the forms `~e`, `e1 ^ e2`, `e1 & e2`, `e1 | e2`, | |
| 4958 * `e1 >> e2` or `e1 << e2`, where `e`, `e1` and `e2` are constant expressions | |
| 4959 * that evaluate to an integer value or to `null`. | |
| 4960 * * An expression of one of the forms `-e`, `e1 + e2`, `e1 - e2`, `e1 * e2`, | |
| 4961 * `e1 / e2`, `e1 ~/ e2`, `e1 > e2`, `e1 < e2`, `e1 >= e2`, `e1 <= e2` or | |
| 4962 * `e1 % e2`, where `e`, `e1` and `e2` are constant expressions that evaluate | |
| 4963 * to a numeric value or to `null`. | |
| 4964 * </blockquote> | |
| 4965 * The values returned by instances of this class are therefore `null` and | |
| 4966 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and | |
| 4967 * `DartObject`. | |
| 4968 * | |
| 4969 * In addition, this class defines several values that can be returned to | |
| 4970 * indicate various conditions encountered during evaluation. These are | |
| 4971 * documented with the static fields that define those values. | |
| 4972 */ | |
| 4973 class ConstantEvaluator extends GeneralizingAstVisitor<Object> { | |
| 4974 /** | |
| 4975 * The value returned for expressions (or non-expression nodes) that are not | |
| 4976 * compile-time constant expressions. | |
| 4977 */ | |
| 4978 static Object NOT_A_CONSTANT = new Object(); | |
| 4979 | |
| 4980 @override | |
| 4981 Object visitAdjacentStrings(AdjacentStrings node) { | |
| 4982 StringBuffer buffer = new StringBuffer(); | |
| 4983 for (StringLiteral string in node.strings) { | |
| 4984 Object value = string.accept(this); | |
| 4985 if (identical(value, NOT_A_CONSTANT)) { | |
| 4986 return value; | |
| 4987 } | |
| 4988 buffer.write(value); | |
| 4989 } | |
| 4990 return buffer.toString(); | |
| 4991 } | |
| 4992 | |
| 4993 @override | |
| 4994 Object visitBinaryExpression(BinaryExpression node) { | |
| 4995 Object leftOperand = node.leftOperand.accept(this); | |
| 4996 if (identical(leftOperand, NOT_A_CONSTANT)) { | |
| 4997 return leftOperand; | |
| 4998 } | |
| 4999 Object rightOperand = node.rightOperand.accept(this); | |
| 5000 if (identical(rightOperand, NOT_A_CONSTANT)) { | |
| 5001 return rightOperand; | |
| 5002 } | |
| 5003 while (true) { | |
| 5004 if (node.operator.type == TokenType.AMPERSAND) { | |
| 5005 // integer or {@code null} | |
| 5006 if (leftOperand is int && rightOperand is int) { | |
| 5007 return leftOperand & rightOperand; | |
| 5008 } | |
| 5009 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) { | |
| 5010 // boolean or {@code null} | |
| 5011 if (leftOperand is bool && rightOperand is bool) { | |
| 5012 return leftOperand && rightOperand; | |
| 5013 } | |
| 5014 } else if (node.operator.type == TokenType.BANG_EQ) { | |
| 5015 // numeric, string, boolean, or {@code null} | |
| 5016 if (leftOperand is bool && rightOperand is bool) { | |
| 5017 return leftOperand != rightOperand; | |
| 5018 } else if (leftOperand is num && rightOperand is num) { | |
| 5019 return leftOperand != rightOperand; | |
| 5020 } else if (leftOperand is String && rightOperand is String) { | |
| 5021 return leftOperand != rightOperand; | |
| 5022 } | |
| 5023 } else if (node.operator.type == TokenType.BAR) { | |
| 5024 // integer or {@code null} | |
| 5025 if (leftOperand is int && rightOperand is int) { | |
| 5026 return leftOperand | rightOperand; | |
| 5027 } | |
| 5028 } else if (node.operator.type == TokenType.BAR_BAR) { | |
| 5029 // boolean or {@code null} | |
| 5030 if (leftOperand is bool && rightOperand is bool) { | |
| 5031 return leftOperand || rightOperand; | |
| 5032 } | |
| 5033 } else if (node.operator.type == TokenType.CARET) { | |
| 5034 // integer or {@code null} | |
| 5035 if (leftOperand is int && rightOperand is int) { | |
| 5036 return leftOperand ^ rightOperand; | |
| 5037 } | |
| 5038 } else if (node.operator.type == TokenType.EQ_EQ) { | |
| 5039 // numeric, string, boolean, or {@code null} | |
| 5040 if (leftOperand is bool && rightOperand is bool) { | |
| 5041 return leftOperand == rightOperand; | |
| 5042 } else if (leftOperand is num && rightOperand is num) { | |
| 5043 return leftOperand == rightOperand; | |
| 5044 } else if (leftOperand is String && rightOperand is String) { | |
| 5045 return leftOperand == rightOperand; | |
| 5046 } | |
| 5047 } else if (node.operator.type == TokenType.GT) { | |
| 5048 // numeric or {@code null} | |
| 5049 if (leftOperand is num && rightOperand is num) { | |
| 5050 return leftOperand.compareTo(rightOperand) > 0; | |
| 5051 } | |
| 5052 } else if (node.operator.type == TokenType.GT_EQ) { | |
| 5053 // numeric or {@code null} | |
| 5054 if (leftOperand is num && rightOperand is num) { | |
| 5055 return leftOperand.compareTo(rightOperand) >= 0; | |
| 5056 } | |
| 5057 } else if (node.operator.type == TokenType.GT_GT) { | |
| 5058 // integer or {@code null} | |
| 5059 if (leftOperand is int && rightOperand is int) { | |
| 5060 return leftOperand >> rightOperand; | |
| 5061 } | |
| 5062 } else if (node.operator.type == TokenType.LT) { | |
| 5063 // numeric or {@code null} | |
| 5064 if (leftOperand is num && rightOperand is num) { | |
| 5065 return leftOperand.compareTo(rightOperand) < 0; | |
| 5066 } | |
| 5067 } else if (node.operator.type == TokenType.LT_EQ) { | |
| 5068 // numeric or {@code null} | |
| 5069 if (leftOperand is num && rightOperand is num) { | |
| 5070 return leftOperand.compareTo(rightOperand) <= 0; | |
| 5071 } | |
| 5072 } else if (node.operator.type == TokenType.LT_LT) { | |
| 5073 // integer or {@code null} | |
| 5074 if (leftOperand is int && rightOperand is int) { | |
| 5075 return leftOperand << rightOperand; | |
| 5076 } | |
| 5077 } else if (node.operator.type == TokenType.MINUS) { | |
| 5078 // numeric or {@code null} | |
| 5079 if (leftOperand is num && rightOperand is num) { | |
| 5080 return leftOperand - rightOperand; | |
| 5081 } | |
| 5082 } else if (node.operator.type == TokenType.PERCENT) { | |
| 5083 // numeric or {@code null} | |
| 5084 if (leftOperand is num && rightOperand is num) { | |
| 5085 return leftOperand.remainder(rightOperand); | |
| 5086 } | |
| 5087 } else if (node.operator.type == TokenType.PLUS) { | |
| 5088 // numeric or {@code null} | |
| 5089 if (leftOperand is num && rightOperand is num) { | |
| 5090 return leftOperand + rightOperand; | |
| 5091 } | |
| 5092 } else if (node.operator.type == TokenType.STAR) { | |
| 5093 // numeric or {@code null} | |
| 5094 if (leftOperand is num && rightOperand is num) { | |
| 5095 return leftOperand * rightOperand; | |
| 5096 } | |
| 5097 } else if (node.operator.type == TokenType.SLASH) { | |
| 5098 // numeric or {@code null} | |
| 5099 if (leftOperand is num && rightOperand is num) { | |
| 5100 return leftOperand / rightOperand; | |
| 5101 } | |
| 5102 } else if (node.operator.type == TokenType.TILDE_SLASH) { | |
| 5103 // numeric or {@code null} | |
| 5104 if (leftOperand is num && rightOperand is num) { | |
| 5105 return leftOperand ~/ rightOperand; | |
| 5106 } | |
| 5107 } else {} | |
| 5108 break; | |
| 5109 } | |
| 5110 // TODO(brianwilkerson) This doesn't handle numeric conversions. | |
| 5111 return visitExpression(node); | |
| 5112 } | |
| 5113 | |
| 5114 @override | |
| 5115 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false; | |
| 5116 | |
| 5117 @override | |
| 5118 Object visitDoubleLiteral(DoubleLiteral node) => node.value; | |
| 5119 | |
| 5120 @override | |
| 5121 Object visitIntegerLiteral(IntegerLiteral node) => node.value; | |
| 5122 | |
| 5123 @override | |
| 5124 Object visitInterpolationExpression(InterpolationExpression node) { | |
| 5125 Object value = node.expression.accept(this); | |
| 5126 if (value == null || value is bool || value is String || value is num) { | |
| 5127 return value; | |
| 5128 } | |
| 5129 return NOT_A_CONSTANT; | |
| 5130 } | |
| 5131 | |
| 5132 @override | |
| 5133 Object visitInterpolationString(InterpolationString node) => node.value; | |
| 5134 | |
| 5135 @override | |
| 5136 Object visitListLiteral(ListLiteral node) { | |
| 5137 List<Object> list = new List<Object>(); | |
| 5138 for (Expression element in node.elements) { | |
| 5139 Object value = element.accept(this); | |
| 5140 if (identical(value, NOT_A_CONSTANT)) { | |
| 5141 return value; | |
| 5142 } | |
| 5143 list.add(value); | |
| 5144 } | |
| 5145 return list; | |
| 5146 } | |
| 5147 | |
| 5148 @override | |
| 5149 Object visitMapLiteral(MapLiteral node) { | |
| 5150 HashMap<String, Object> map = new HashMap<String, Object>(); | |
| 5151 for (MapLiteralEntry entry in node.entries) { | |
| 5152 Object key = entry.key.accept(this); | |
| 5153 Object value = entry.value.accept(this); | |
| 5154 if (key is! String || identical(value, NOT_A_CONSTANT)) { | |
| 5155 return NOT_A_CONSTANT; | |
| 5156 } | |
| 5157 map[(key as String)] = value; | |
| 5158 } | |
| 5159 return map; | |
| 5160 } | |
| 5161 | |
| 5162 @override | |
| 5163 Object visitMethodInvocation(MethodInvocation node) => visitNode(node); | |
| 5164 | |
| 5165 @override | |
| 5166 Object visitNode(AstNode node) => NOT_A_CONSTANT; | |
| 5167 | |
| 5168 @override | |
| 5169 Object visitNullLiteral(NullLiteral node) => null; | |
| 5170 | |
| 5171 @override | |
| 5172 Object visitParenthesizedExpression(ParenthesizedExpression node) => | |
| 5173 node.expression.accept(this); | |
| 5174 | |
| 5175 @override | |
| 5176 Object visitPrefixedIdentifier(PrefixedIdentifier node) => | |
| 5177 _getConstantValue(null); | |
| 5178 | |
| 5179 @override | |
| 5180 Object visitPrefixExpression(PrefixExpression node) { | |
| 5181 Object operand = node.operand.accept(this); | |
| 5182 if (identical(operand, NOT_A_CONSTANT)) { | |
| 5183 return operand; | |
| 5184 } | |
| 5185 while (true) { | |
| 5186 if (node.operator.type == TokenType.BANG) { | |
| 5187 if (identical(operand, true)) { | |
| 5188 return false; | |
| 5189 } else if (identical(operand, false)) { | |
| 5190 return true; | |
| 5191 } | |
| 5192 } else if (node.operator.type == TokenType.TILDE) { | |
| 5193 if (operand is int) { | |
| 5194 return ~operand; | |
| 5195 } | |
| 5196 } else if (node.operator.type == TokenType.MINUS) { | |
| 5197 if (operand == null) { | |
| 5198 return null; | |
| 5199 } else if (operand is num) { | |
| 5200 return -operand; | |
| 5201 } | |
| 5202 } else {} | |
| 5203 break; | |
| 5204 } | |
| 5205 return NOT_A_CONSTANT; | |
| 5206 } | |
| 5207 | |
| 5208 @override | |
| 5209 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null); | |
| 5210 | |
| 5211 @override | |
| 5212 Object visitSimpleIdentifier(SimpleIdentifier node) => | |
| 5213 _getConstantValue(null); | |
| 5214 | |
| 5215 @override | |
| 5216 Object visitSimpleStringLiteral(SimpleStringLiteral node) => node.value; | |
| 5217 | |
| 5218 @override | |
| 5219 Object visitStringInterpolation(StringInterpolation node) { | |
| 5220 StringBuffer buffer = new StringBuffer(); | |
| 5221 for (InterpolationElement element in node.elements) { | |
| 5222 Object value = element.accept(this); | |
| 5223 if (identical(value, NOT_A_CONSTANT)) { | |
| 5224 return value; | |
| 5225 } | |
| 5226 buffer.write(value); | |
| 5227 } | |
| 5228 return buffer.toString(); | |
| 5229 } | |
| 5230 | |
| 5231 @override | |
| 5232 Object visitSymbolLiteral(SymbolLiteral node) { | |
| 5233 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String. | |
| 5234 StringBuffer buffer = new StringBuffer(); | |
| 5235 for (Token component in node.components) { | |
| 5236 if (buffer.length > 0) { | |
| 5237 buffer.writeCharCode(0x2E); | |
| 5238 } | |
| 5239 buffer.write(component.lexeme); | |
| 5240 } | |
| 5241 return buffer.toString(); | |
| 5242 } | |
| 5243 | |
| 5244 /** | |
| 5245 * Return the constant value of the static constant represented by the given | |
| 5246 * [element]. | |
| 5247 */ | |
| 5248 Object _getConstantValue(Element element) { | |
| 5249 // TODO(brianwilkerson) Implement this | |
| 5250 if (element is FieldElement) { | |
| 5251 FieldElement field = element; | |
| 5252 if (field.isStatic && field.isConst) { | |
| 5253 //field.getConstantValue(); | |
| 5254 } | |
| 5255 // } else if (element instanceof VariableElement) { | |
| 5256 // VariableElement variable = (VariableElement) element; | |
| 5257 // if (variable.isStatic() && variable.isConst()) { | |
| 5258 // //variable.getConstantValue(); | |
| 5259 // } | |
| 5260 } | |
| 5261 return NOT_A_CONSTANT; | |
| 5262 } | |
| 5263 } | |
| 5264 | |
| 5265 /** | |
| 5266 * A constructor declaration. | |
| 5267 * | |
| 5268 * > constructorDeclaration ::= | |
| 5269 * > constructorSignature [FunctionBody]? | |
| 5270 * > | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier])
? arguments | |
| 5271 * > | |
| 5272 * > constructorSignature ::= | |
| 5273 * > 'external'? constructorName formalParameterList initializerList? | |
| 5274 * > | 'external'? 'factory' factoryName formalParameterList initializerList? | |
| 5275 * > | 'external'? 'const' constructorName formalParameterList initializerLis
t? | |
| 5276 * > | |
| 5277 * > constructorName ::= | |
| 5278 * > [SimpleIdentifier] ('.' [SimpleIdentifier])? | |
| 5279 * > | |
| 5280 * > factoryName ::= | |
| 5281 * > [Identifier] ('.' [SimpleIdentifier])? | |
| 5282 * > | |
| 5283 * > initializerList ::= | |
| 5284 * > ':' [ConstructorInitializer] (',' [ConstructorInitializer])* | |
| 5285 */ | |
| 5286 class ConstructorDeclaration extends ClassMember { | |
| 5287 /** | |
| 5288 * The token for the 'external' keyword, or `null` if the constructor is not | |
| 5289 * external. | |
| 5290 */ | |
| 5291 Token externalKeyword; | |
| 5292 | |
| 5293 /** | |
| 5294 * The token for the 'const' keyword, or `null` if the constructor is not a | |
| 5295 * const constructor. | |
| 5296 */ | |
| 5297 Token constKeyword; | |
| 5298 | |
| 5299 /** | |
| 5300 * The token for the 'factory' keyword, or `null` if the constructor is not a | |
| 5301 * factory constructor. | |
| 5302 */ | |
| 5303 Token factoryKeyword; | |
| 5304 | |
| 5305 /** | |
| 5306 * The type of object being created. This can be different than the type in | |
| 5307 * which the constructor is being declared if the constructor is the | |
| 5308 * implementation of a factory constructor. | |
| 5309 */ | |
| 5310 Identifier _returnType; | |
| 5311 | |
| 5312 /** | |
| 5313 * The token for the period before the constructor name, or `null` if the | |
| 5314 * constructor being declared is unnamed. | |
| 5315 */ | |
| 5316 Token period; | |
| 5317 | |
| 5318 /** | |
| 5319 * The name of the constructor, or `null` if the constructor being declared is | |
| 5320 * unnamed. | |
| 5321 */ | |
| 5322 SimpleIdentifier _name; | |
| 5323 | |
| 5324 /** | |
| 5325 * The parameters associated with the constructor. | |
| 5326 */ | |
| 5327 FormalParameterList _parameters; | |
| 5328 | |
| 5329 /** | |
| 5330 * The token for the separator (colon or equals) before the initializer list | |
| 5331 * or redirection, or `null` if there are no initializers. | |
| 5332 */ | |
| 5333 Token separator; | |
| 5334 | |
| 5335 /** | |
| 5336 * The initializers associated with the constructor. | |
| 5337 */ | |
| 5338 NodeList<ConstructorInitializer> _initializers; | |
| 5339 | |
| 5340 /** | |
| 5341 * The name of the constructor to which this constructor will be redirected, | |
| 5342 * or `null` if this is not a redirecting factory constructor. | |
| 5343 */ | |
| 5344 ConstructorName _redirectedConstructor; | |
| 5345 | |
| 5346 /** | |
| 5347 * The body of the constructor, or `null` if the constructor does not have a | |
| 5348 * body. | |
| 5349 */ | |
| 5350 FunctionBody _body; | |
| 5351 | |
| 5352 /** | |
| 5353 * The element associated with this constructor, or `null` if the AST | |
| 5354 * structure has not been resolved or if this constructor could not be | |
| 5355 * resolved. | |
| 5356 */ | |
| 5357 ConstructorElement element; | |
| 5358 | |
| 5359 /** | |
| 5360 * Initialize a newly created constructor declaration. The [externalKeyword] | |
| 5361 * can be `null` if the constructor is not external. Either or both of the | |
| 5362 * [comment] and [metadata] can be `null` if the constructor does not have the | |
| 5363 * corresponding attribute. The [constKeyword] can be `null` if the | |
| 5364 * constructor cannot be used to create a constant. The [factoryKeyword] can | |
| 5365 * be `null` if the constructor is not a factory. The [period] and [name] can | |
| 5366 * both be `null` if the constructor is not a named constructor. The | |
| 5367 * [separator] can be `null` if the constructor does not have any initializers | |
| 5368 * and does not redirect to a different constructor. The list of | |
| 5369 * [initializers] can be `null` if the constructor does not have any | |
| 5370 * initializers. The [redirectedConstructor] can be `null` if the constructor | |
| 5371 * does not redirect to a different constructor. The [body] can be `null` if | |
| 5372 * the constructor does not have a body. | |
| 5373 */ | |
| 5374 ConstructorDeclaration(Comment comment, List<Annotation> metadata, | |
| 5375 this.externalKeyword, this.constKeyword, this.factoryKeyword, | |
| 5376 Identifier returnType, this.period, SimpleIdentifier name, | |
| 5377 FormalParameterList parameters, this.separator, | |
| 5378 List<ConstructorInitializer> initializers, | |
| 5379 ConstructorName redirectedConstructor, FunctionBody body) | |
| 5380 : super(comment, metadata) { | |
| 5381 _returnType = _becomeParentOf(returnType); | |
| 5382 _name = _becomeParentOf(name); | |
| 5383 _parameters = _becomeParentOf(parameters); | |
| 5384 _initializers = new NodeList<ConstructorInitializer>(this, initializers); | |
| 5385 _redirectedConstructor = _becomeParentOf(redirectedConstructor); | |
| 5386 _body = _becomeParentOf(body); | |
| 5387 } | |
| 5388 | |
| 5389 /** | |
| 5390 * Return the body of the constructor, or `null` if the constructor does not | |
| 5391 * have a body. | |
| 5392 */ | |
| 5393 FunctionBody get body => _body; | |
| 5394 | |
| 5395 /** | |
| 5396 * Set the body of the constructor to the given [functionBody]. | |
| 5397 */ | |
| 5398 void set body(FunctionBody functionBody) { | |
| 5399 _body = _becomeParentOf(functionBody); | |
| 5400 } | |
| 5401 | |
| 5402 @override | |
| 5403 Iterable get childEntities => super._childEntities | |
| 5404 ..add(externalKeyword) | |
| 5405 ..add(constKeyword) | |
| 5406 ..add(factoryKeyword) | |
| 5407 ..add(_returnType) | |
| 5408 ..add(period) | |
| 5409 ..add(_name) | |
| 5410 ..add(_parameters) | |
| 5411 ..add(separator) | |
| 5412 ..addAll(initializers) | |
| 5413 ..add(_redirectedConstructor) | |
| 5414 ..add(_body); | |
| 5415 | |
| 5416 @override | |
| 5417 Token get endToken { | |
| 5418 if (_body != null) { | |
| 5419 return _body.endToken; | |
| 5420 } else if (!_initializers.isEmpty) { | |
| 5421 return _initializers.endToken; | |
| 5422 } | |
| 5423 return _parameters.endToken; | |
| 5424 } | |
| 5425 | |
| 5426 @override | |
| 5427 Token get firstTokenAfterCommentAndMetadata { | |
| 5428 Token leftMost = | |
| 5429 Token.lexicallyFirst([externalKeyword, constKeyword, factoryKeyword]); | |
| 5430 if (leftMost != null) { | |
| 5431 return leftMost; | |
| 5432 } | |
| 5433 return _returnType.beginToken; | |
| 5434 } | |
| 5435 | |
| 5436 /** | |
| 5437 * Return the initializers associated with the constructor. | |
| 5438 */ | |
| 5439 NodeList<ConstructorInitializer> get initializers => _initializers; | |
| 5440 | |
| 5441 /** | |
| 5442 * Return the name of the constructor, or `null` if the constructor being | |
| 5443 * declared is unnamed. | |
| 5444 */ | |
| 5445 SimpleIdentifier get name => _name; | |
| 5446 | |
| 5447 /** | |
| 5448 * Set the name of the constructor to the given [identifier]. | |
| 5449 */ | |
| 5450 void set name(SimpleIdentifier identifier) { | |
| 5451 _name = _becomeParentOf(identifier); | |
| 5452 } | |
| 5453 | |
| 5454 /** | |
| 5455 * Return the parameters associated with the constructor. | |
| 5456 */ | |
| 5457 FormalParameterList get parameters => _parameters; | |
| 5458 | |
| 5459 /** | |
| 5460 * Set the parameters associated with the constructor to the given list of | |
| 5461 * [parameters]. | |
| 5462 */ | |
| 5463 void set parameters(FormalParameterList parameters) { | |
| 5464 _parameters = _becomeParentOf(parameters); | |
| 5465 } | |
| 5466 | |
| 5467 /** | |
| 5468 * Return the name of the constructor to which this constructor will be | |
| 5469 * redirected, or `null` if this is not a redirecting factory constructor. | |
| 5470 */ | |
| 5471 ConstructorName get redirectedConstructor => _redirectedConstructor; | |
| 5472 | |
| 5473 /** | |
| 5474 * Set the name of the constructor to which this constructor will be | |
| 5475 * redirected to the given [redirectedConstructor] name. | |
| 5476 */ | |
| 5477 void set redirectedConstructor(ConstructorName redirectedConstructor) { | |
| 5478 _redirectedConstructor = _becomeParentOf(redirectedConstructor); | |
| 5479 } | |
| 5480 | |
| 5481 /** | |
| 5482 * Return the type of object being created. This can be different than the | |
| 5483 * type in which the constructor is being declared if the constructor is the | |
| 5484 * implementation of a factory constructor. | |
| 5485 */ | |
| 5486 Identifier get returnType => _returnType; | |
| 5487 | |
| 5488 /** | |
| 5489 * Set the type of object being created to the given [typeName]. | |
| 5490 */ | |
| 5491 void set returnType(Identifier typeName) { | |
| 5492 _returnType = _becomeParentOf(typeName); | |
| 5493 } | |
| 5494 | |
| 5495 @override | |
| 5496 accept(AstVisitor visitor) => visitor.visitConstructorDeclaration(this); | |
| 5497 | |
| 5498 @override | |
| 5499 void visitChildren(AstVisitor visitor) { | |
| 5500 super.visitChildren(visitor); | |
| 5501 _safelyVisitChild(_returnType, visitor); | |
| 5502 _safelyVisitChild(_name, visitor); | |
| 5503 _safelyVisitChild(_parameters, visitor); | |
| 5504 _initializers.accept(visitor); | |
| 5505 _safelyVisitChild(_redirectedConstructor, visitor); | |
| 5506 _safelyVisitChild(_body, visitor); | |
| 5507 } | |
| 5508 } | |
| 5509 | |
| 5510 /** | |
| 5511 * The initialization of a field within a constructor's initialization list. | |
| 5512 * | |
| 5513 * > fieldInitializer ::= | |
| 5514 * > ('this' '.')? [SimpleIdentifier] '=' [Expression] | |
| 5515 */ | |
| 5516 class ConstructorFieldInitializer extends ConstructorInitializer { | |
| 5517 /** | |
| 5518 * The token for the 'this' keyword, or `null` if there is no 'this' keyword. | |
| 5519 */ | |
| 5520 Token thisKeyword; | |
| 5521 | |
| 5522 /** | |
| 5523 * The token for the period after the 'this' keyword, or `null` if there is no | |
| 5524 * 'this' keyword. | |
| 5525 */ | |
| 5526 Token period; | |
| 5527 | |
| 5528 /** | |
| 5529 * The name of the field being initialized. | |
| 5530 */ | |
| 5531 SimpleIdentifier _fieldName; | |
| 5532 | |
| 5533 /** | |
| 5534 * The token for the equal sign between the field name and the expression. | |
| 5535 */ | |
| 5536 Token equals; | |
| 5537 | |
| 5538 /** | |
| 5539 * The expression computing the value to which the field will be initialized. | |
| 5540 */ | |
| 5541 Expression _expression; | |
| 5542 | |
| 5543 /** | |
| 5544 * Initialize a newly created field initializer to initialize the field with | |
| 5545 * the given name to the value of the given expression. The [thisKeyword] and | |
| 5546 * [period] can be `null` if the 'this' keyword was not specified. | |
| 5547 */ | |
| 5548 ConstructorFieldInitializer(this.thisKeyword, this.period, | |
| 5549 SimpleIdentifier fieldName, this.equals, Expression expression) { | |
| 5550 _fieldName = _becomeParentOf(fieldName); | |
| 5551 _expression = _becomeParentOf(expression); | |
| 5552 } | |
| 5553 | |
| 5554 @override | |
| 5555 Token get beginToken { | |
| 5556 if (thisKeyword != null) { | |
| 5557 return thisKeyword; | |
| 5558 } | |
| 5559 return _fieldName.beginToken; | |
| 5560 } | |
| 5561 | |
| 5562 @override | |
| 5563 Iterable get childEntities => new ChildEntities() | |
| 5564 ..add(thisKeyword) | |
| 5565 ..add(period) | |
| 5566 ..add(_fieldName) | |
| 5567 ..add(equals) | |
| 5568 ..add(_expression); | |
| 5569 | |
| 5570 @override | |
| 5571 Token get endToken => _expression.endToken; | |
| 5572 | |
| 5573 /** | |
| 5574 * Return the expression computing the value to which the field will be | |
| 5575 * initialized. | |
| 5576 */ | |
| 5577 Expression get expression => _expression; | |
| 5578 | |
| 5579 /** | |
| 5580 * Set the expression computing the value to which the field will be | |
| 5581 * initialized to the given [expression]. | |
| 5582 */ | |
| 5583 void set expression(Expression expression) { | |
| 5584 _expression = _becomeParentOf(expression); | |
| 5585 } | |
| 5586 | |
| 5587 /** | |
| 5588 * Return the name of the field being initialized. | |
| 5589 */ | |
| 5590 SimpleIdentifier get fieldName => _fieldName; | |
| 5591 | |
| 5592 /** | |
| 5593 * Set the name of the field being initialized to the given [identifier]. | |
| 5594 */ | |
| 5595 void set fieldName(SimpleIdentifier identifier) { | |
| 5596 _fieldName = _becomeParentOf(identifier); | |
| 5597 } | |
| 5598 | |
| 5599 /** | |
| 5600 * Return the token for the 'this' keyword, or `null` if there is no 'this' | |
| 5601 * keyword. | |
| 5602 */ | |
| 5603 @deprecated // Use "this.thisKeyword" | |
| 5604 Token get keyword => thisKeyword; | |
| 5605 | |
| 5606 /** | |
| 5607 * Set the token for the 'this' keyword to the given [token]. | |
| 5608 */ | |
| 5609 @deprecated // Use "this.thisKeyword" | |
| 5610 set keyword(Token token) { | |
| 5611 thisKeyword = token; | |
| 5612 } | |
| 5613 | |
| 5614 @override | |
| 5615 accept(AstVisitor visitor) => visitor.visitConstructorFieldInitializer(this); | |
| 5616 | |
| 5617 @override | |
| 5618 void visitChildren(AstVisitor visitor) { | |
| 5619 _safelyVisitChild(_fieldName, visitor); | |
| 5620 _safelyVisitChild(_expression, visitor); | |
| 5621 } | |
| 5622 } | |
| 5623 | |
| 5624 /** | |
| 5625 * A node that can occur in the initializer list of a constructor declaration. | |
| 5626 * | |
| 5627 * > constructorInitializer ::= | |
| 5628 * > [SuperConstructorInvocation] | |
| 5629 * > | [ConstructorFieldInitializer] | |
| 5630 */ | |
| 5631 abstract class ConstructorInitializer extends AstNode {} | |
| 5632 | |
| 5633 /** | |
| 5634 * The name of the constructor. | |
| 5635 * | |
| 5636 * > constructorName ::= | |
| 5637 * > type ('.' identifier)? | |
| 5638 */ | |
| 5639 class ConstructorName extends AstNode { | |
| 5640 /** | |
| 5641 * The name of the type defining the constructor. | |
| 5642 */ | |
| 5643 TypeName _type; | |
| 5644 | |
| 5645 /** | |
| 5646 * The token for the period before the constructor name, or `null` if the | |
| 5647 * specified constructor is the unnamed constructor. | |
| 5648 */ | |
| 5649 Token period; | |
| 5650 | |
| 5651 /** | |
| 5652 * The name of the constructor, or `null` if the specified constructor is the | |
| 5653 * unnamed constructor. | |
| 5654 */ | |
| 5655 SimpleIdentifier _name; | |
| 5656 | |
| 5657 /** | |
| 5658 * The element associated with this constructor name based on static type | |
| 5659 * information, or `null` if the AST structure has not been resolved or if | |
| 5660 * this constructor name could not be resolved. | |
| 5661 */ | |
| 5662 ConstructorElement staticElement; | |
| 5663 | |
| 5664 /** | |
| 5665 * Initialize a newly created constructor name. The [period] and [name] can be | |
| 5666 * `null` if the constructor being named is the unnamed constructor. | |
| 5667 */ | |
| 5668 ConstructorName(TypeName type, this.period, SimpleIdentifier name) { | |
| 5669 _type = _becomeParentOf(type); | |
| 5670 _name = _becomeParentOf(name); | |
| 5671 } | |
| 5672 | |
| 5673 @override | |
| 5674 Token get beginToken => _type.beginToken; | |
| 5675 | |
| 5676 @override | |
| 5677 Iterable get childEntities => | |
| 5678 new ChildEntities()..add(_type)..add(period)..add(_name); | |
| 5679 | |
| 5680 @override | |
| 5681 Token get endToken { | |
| 5682 if (_name != null) { | |
| 5683 return _name.endToken; | |
| 5684 } | |
| 5685 return _type.endToken; | |
| 5686 } | |
| 5687 | |
| 5688 /** | |
| 5689 * Return the name of the constructor, or `null` if the specified constructor | |
| 5690 * is the unnamed constructor. | |
| 5691 */ | |
| 5692 SimpleIdentifier get name => _name; | |
| 5693 | |
| 5694 /** | |
| 5695 * Set the name of the constructor to the given [name]. | |
| 5696 */ | |
| 5697 void set name(SimpleIdentifier name) { | |
| 5698 _name = _becomeParentOf(name); | |
| 5699 } | |
| 5700 | |
| 5701 /** | |
| 5702 * Return the name of the type defining the constructor. | |
| 5703 */ | |
| 5704 TypeName get type => _type; | |
| 5705 | |
| 5706 /** | |
| 5707 * Set the name of the type defining the constructor to the given [type] name. | |
| 5708 */ | |
| 5709 void set type(TypeName type) { | |
| 5710 _type = _becomeParentOf(type); | |
| 5711 } | |
| 5712 | |
| 5713 @override | |
| 5714 accept(AstVisitor visitor) => visitor.visitConstructorName(this); | |
| 5715 | |
| 5716 @override | |
| 5717 void visitChildren(AstVisitor visitor) { | |
| 5718 _safelyVisitChild(_type, visitor); | |
| 5719 _safelyVisitChild(_name, visitor); | |
| 5720 } | |
| 5721 } | |
| 5722 | |
| 5723 /** | |
| 5724 * A continue statement. | |
| 5725 * | |
| 5726 * > continueStatement ::= | |
| 5727 * > 'continue' [SimpleIdentifier]? ';' | |
| 5728 */ | |
| 5729 class ContinueStatement extends Statement { | |
| 5730 /** | |
| 5731 * The token representing the 'continue' keyword. | |
| 5732 */ | |
| 5733 Token continueKeyword; | |
| 5734 | |
| 5735 /** | |
| 5736 * The label associated with the statement, or `null` if there is no label. | |
| 5737 */ | |
| 5738 SimpleIdentifier _label; | |
| 5739 | |
| 5740 /** | |
| 5741 * The semicolon terminating the statement. | |
| 5742 */ | |
| 5743 Token semicolon; | |
| 5744 | |
| 5745 /** | |
| 5746 * The AstNode which this continue statement is continuing to. This will be | |
| 5747 * either a Statement (in the case of continuing a loop) or a SwitchMember | |
| 5748 * (in the case of continuing from one switch case to another). Null if the | |
| 5749 * AST has not yet been resolved or if the target could not be resolved. | |
| 5750 * Note that if the source code has errors, the target may be invalid (e.g. | |
| 5751 * the target may be in an enclosing function). | |
| 5752 */ | |
| 5753 AstNode target; | |
| 5754 | |
| 5755 /** | |
| 5756 * Initialize a newly created continue statement. The [label] can be `null` if | |
| 5757 * there is no label associated with the statement. | |
| 5758 */ | |
| 5759 ContinueStatement( | |
| 5760 this.continueKeyword, SimpleIdentifier label, this.semicolon) { | |
| 5761 _label = _becomeParentOf(label); | |
| 5762 } | |
| 5763 | |
| 5764 @override | |
| 5765 Token get beginToken => continueKeyword; | |
| 5766 | |
| 5767 @override | |
| 5768 Iterable get childEntities => | |
| 5769 new ChildEntities()..add(continueKeyword)..add(_label)..add(semicolon); | |
| 5770 | |
| 5771 @override | |
| 5772 Token get endToken => semicolon; | |
| 5773 | |
| 5774 /** | |
| 5775 * Return the token for the 'continue' keyword, or `null` if there is no | |
| 5776 * 'continue' keyword. | |
| 5777 */ | |
| 5778 @deprecated // Use "this.continueKeyword" | |
| 5779 Token get keyword => continueKeyword; | |
| 5780 | |
| 5781 /** | |
| 5782 * Set the token for the 'continue' keyword to the given [token]. | |
| 5783 */ | |
| 5784 @deprecated // Use "this.continueKeyword" | |
| 5785 set keyword(Token token) { | |
| 5786 continueKeyword = token; | |
| 5787 } | |
| 5788 | |
| 5789 /** | |
| 5790 * Return the label associated with the statement, or `null` if there is no | |
| 5791 * label. | |
| 5792 */ | |
| 5793 SimpleIdentifier get label => _label; | |
| 5794 | |
| 5795 /** | |
| 5796 * Set the label associated with the statement to the given [identifier]. | |
| 5797 */ | |
| 5798 void set label(SimpleIdentifier identifier) { | |
| 5799 _label = _becomeParentOf(identifier); | |
| 5800 } | |
| 5801 | |
| 5802 @override | |
| 5803 accept(AstVisitor visitor) => visitor.visitContinueStatement(this); | |
| 5804 | |
| 5805 @override | |
| 5806 void visitChildren(AstVisitor visitor) { | |
| 5807 _safelyVisitChild(_label, visitor); | |
| 5808 } | |
| 5809 } | |
| 5810 | |
| 5811 /** | |
| 5812 * A node that represents the declaration of one or more names. Each declared | |
| 5813 * name is visible within a name scope. | |
| 5814 */ | |
| 5815 abstract class Declaration extends AnnotatedNode { | |
| 5816 /** | |
| 5817 * Initialize a newly created declaration. Either or both of the [comment] and | |
| 5818 * [metadata] can be `null` if the declaration does not have the corresponding | |
| 5819 * attribute. | |
| 5820 */ | |
| 5821 Declaration(Comment comment, List<Annotation> metadata) | |
| 5822 : super(comment, metadata); | |
| 5823 | |
| 5824 /** | |
| 5825 * Return the element associated with this declaration, or `null` if either | |
| 5826 * this node corresponds to a list of declarations or if the AST structure has | |
| 5827 * not been resolved. | |
| 5828 */ | |
| 5829 Element get element; | |
| 5830 } | |
| 5831 | |
| 5832 /** | |
| 5833 * The declaration of a single identifier. | |
| 5834 * | |
| 5835 * > declaredIdentifier ::= | |
| 5836 * > [Annotation] finalConstVarOrType [SimpleIdentifier] | |
| 5837 */ | |
| 5838 class DeclaredIdentifier extends Declaration { | |
| 5839 /** | |
| 5840 * The token representing either the 'final', 'const' or 'var' keyword, or | |
| 5841 * `null` if no keyword was used. | |
| 5842 */ | |
| 5843 Token keyword; | |
| 5844 | |
| 5845 /** | |
| 5846 * The name of the declared type of the parameter, or `null` if the parameter | |
| 5847 * does not have a declared type. | |
| 5848 */ | |
| 5849 TypeName _type; | |
| 5850 | |
| 5851 /** | |
| 5852 * The name of the variable being declared. | |
| 5853 */ | |
| 5854 SimpleIdentifier _identifier; | |
| 5855 | |
| 5856 /** | |
| 5857 * Initialize a newly created formal parameter. Either or both of the | |
| 5858 * [comment] and [metadata] can be `null` if the declaration does not have the | |
| 5859 * corresponding attribute. The [keyword] can be `null` if a type name is | |
| 5860 * given. The [type] must be `null` if the keyword is 'var'. | |
| 5861 */ | |
| 5862 DeclaredIdentifier(Comment comment, List<Annotation> metadata, this.keyword, | |
| 5863 TypeName type, SimpleIdentifier identifier) | |
| 5864 : super(comment, metadata) { | |
| 5865 _type = _becomeParentOf(type); | |
| 5866 _identifier = _becomeParentOf(identifier); | |
| 5867 } | |
| 5868 | |
| 5869 @override | |
| 5870 Iterable get childEntities => | |
| 5871 super._childEntities..add(keyword)..add(_type)..add(_identifier); | |
| 5872 | |
| 5873 @override | |
| 5874 LocalVariableElement get element { | |
| 5875 if (_identifier == null) { | |
| 5876 return null; | |
| 5877 } | |
| 5878 return _identifier.staticElement as LocalVariableElement; | |
| 5879 } | |
| 5880 | |
| 5881 @override | |
| 5882 Token get endToken => _identifier.endToken; | |
| 5883 | |
| 5884 @override | |
| 5885 Token get firstTokenAfterCommentAndMetadata { | |
| 5886 if (keyword != null) { | |
| 5887 return keyword; | |
| 5888 } else if (_type != null) { | |
| 5889 return _type.beginToken; | |
| 5890 } | |
| 5891 return _identifier.beginToken; | |
| 5892 } | |
| 5893 | |
| 5894 /** | |
| 5895 * Return the name of the variable being declared. | |
| 5896 */ | |
| 5897 SimpleIdentifier get identifier => _identifier; | |
| 5898 | |
| 5899 /** | |
| 5900 * Set the name of the variable being declared to the given [identifier]. | |
| 5901 */ | |
| 5902 void set identifier(SimpleIdentifier identifier) { | |
| 5903 _identifier = _becomeParentOf(identifier); | |
| 5904 } | |
| 5905 | |
| 5906 /** | |
| 5907 * Return `true` if this variable was declared with the 'const' modifier. | |
| 5908 */ | |
| 5909 bool get isConst => (keyword is KeywordToken) && | |
| 5910 (keyword as KeywordToken).keyword == Keyword.CONST; | |
| 5911 | |
| 5912 /** | |
| 5913 * Return `true` if this variable was declared with the 'final' modifier. | |
| 5914 * Variables that are declared with the 'const' modifier will return `false` | |
| 5915 * even though they are implicitly final. | |
| 5916 */ | |
| 5917 bool get isFinal => (keyword is KeywordToken) && | |
| 5918 (keyword as KeywordToken).keyword == Keyword.FINAL; | |
| 5919 | |
| 5920 /** | |
| 5921 * Return the name of the declared type of the parameter, or `null` if the | |
| 5922 * parameter does not have a declared type. | |
| 5923 */ | |
| 5924 TypeName get type => _type; | |
| 5925 | |
| 5926 /** | |
| 5927 * Set the name of the declared type of the parameter to the given [typeName]. | |
| 5928 */ | |
| 5929 void set type(TypeName typeName) { | |
| 5930 _type = _becomeParentOf(typeName); | |
| 5931 } | |
| 5932 | |
| 5933 @override | |
| 5934 accept(AstVisitor visitor) => visitor.visitDeclaredIdentifier(this); | |
| 5935 | |
| 5936 @override | |
| 5937 void visitChildren(AstVisitor visitor) { | |
| 5938 super.visitChildren(visitor); | |
| 5939 _safelyVisitChild(_type, visitor); | |
| 5940 _safelyVisitChild(_identifier, visitor); | |
| 5941 } | |
| 5942 } | |
| 5943 | |
| 5944 /** | |
| 5945 * A formal parameter with a default value. There are two kinds of parameters | |
| 5946 * that are both represented by this class: named formal parameters and | |
| 5947 * positional formal parameters. | |
| 5948 * | |
| 5949 * > defaultFormalParameter ::= | |
| 5950 * > [NormalFormalParameter] ('=' [Expression])? | |
| 5951 * > | |
| 5952 * > defaultNamedParameter ::= | |
| 5953 * > [NormalFormalParameter] (':' [Expression])? | |
| 5954 */ | |
| 5955 class DefaultFormalParameter extends FormalParameter { | |
| 5956 /** | |
| 5957 * The formal parameter with which the default value is associated. | |
| 5958 */ | |
| 5959 NormalFormalParameter _parameter; | |
| 5960 | |
| 5961 /** | |
| 5962 * The kind of this parameter. | |
| 5963 */ | |
| 5964 ParameterKind kind; | |
| 5965 | |
| 5966 /** | |
| 5967 * The token separating the parameter from the default value, or `null` if | |
| 5968 * there is no default value. | |
| 5969 */ | |
| 5970 Token separator; | |
| 5971 | |
| 5972 /** | |
| 5973 * The expression computing the default value for the parameter, or `null` if | |
| 5974 * there is no default value. | |
| 5975 */ | |
| 5976 Expression _defaultValue; | |
| 5977 | |
| 5978 /** | |
| 5979 * Initialize a newly created default formal parameter. The [separator] and | |
| 5980 * [defaultValue] can be `null` if there is no default value. | |
| 5981 */ | |
| 5982 DefaultFormalParameter(NormalFormalParameter parameter, this.kind, | |
| 5983 this.separator, Expression defaultValue) { | |
| 5984 _parameter = _becomeParentOf(parameter); | |
| 5985 _defaultValue = _becomeParentOf(defaultValue); | |
| 5986 } | |
| 5987 | |
| 5988 @override | |
| 5989 Token get beginToken => _parameter.beginToken; | |
| 5990 | |
| 5991 @override | |
| 5992 Iterable get childEntities => | |
| 5993 new ChildEntities()..add(_parameter)..add(separator)..add(_defaultValue); | |
| 5994 | |
| 5995 /** | |
| 5996 * Return the expression computing the default value for the parameter, or | |
| 5997 * `null` if there is no default value. | |
| 5998 */ | |
| 5999 Expression get defaultValue => _defaultValue; | |
| 6000 | |
| 6001 /** | |
| 6002 * Set the expression computing the default value for the parameter to the | |
| 6003 * given [expression]. | |
| 6004 */ | |
| 6005 void set defaultValue(Expression expression) { | |
| 6006 _defaultValue = _becomeParentOf(expression); | |
| 6007 } | |
| 6008 | |
| 6009 @override | |
| 6010 Token get endToken { | |
| 6011 if (_defaultValue != null) { | |
| 6012 return _defaultValue.endToken; | |
| 6013 } | |
| 6014 return _parameter.endToken; | |
| 6015 } | |
| 6016 | |
| 6017 @override | |
| 6018 SimpleIdentifier get identifier => _parameter.identifier; | |
| 6019 | |
| 6020 @override | |
| 6021 bool get isConst => _parameter != null && _parameter.isConst; | |
| 6022 | |
| 6023 @override | |
| 6024 bool get isFinal => _parameter != null && _parameter.isFinal; | |
| 6025 | |
| 6026 /** | |
| 6027 * Return the formal parameter with which the default value is associated. | |
| 6028 */ | |
| 6029 NormalFormalParameter get parameter => _parameter; | |
| 6030 | |
| 6031 /** | |
| 6032 * Set the formal parameter with which the default value is associated to the | |
| 6033 * given [formalParameter]. | |
| 6034 */ | |
| 6035 void set parameter(NormalFormalParameter formalParameter) { | |
| 6036 _parameter = _becomeParentOf(formalParameter); | |
| 6037 } | |
| 6038 | |
| 6039 @override | |
| 6040 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this); | |
| 6041 | |
| 6042 @override | |
| 6043 void visitChildren(AstVisitor visitor) { | |
| 6044 _safelyVisitChild(_parameter, visitor); | |
| 6045 _safelyVisitChild(_defaultValue, visitor); | |
| 6046 } | |
| 6047 } | |
| 6048 | |
| 6049 /** | |
| 6050 * A recursive AST visitor that is used to run over [Expression]s to determine | |
| 6051 * whether the expression is composed by at least one deferred | |
| 6052 * [PrefixedIdentifier]. | |
| 6053 * | |
| 6054 * See [PrefixedIdentifier.isDeferred]. | |
| 6055 */ | |
| 6056 class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<Object> { | |
| 6057 /** | |
| 6058 * A flag indicating whether an identifier from a deferred library has been | |
| 6059 * found. | |
| 6060 */ | |
| 6061 bool _result = false; | |
| 6062 | |
| 6063 /** | |
| 6064 * Return `true` if the visitor found a [PrefixedIdentifier] that returned | |
| 6065 * `true` to the [PrefixedIdentifier.isDeferred] query. | |
| 6066 */ | |
| 6067 bool get result => _result; | |
| 6068 | |
| 6069 @override | |
| 6070 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 6071 if (!_result) { | |
| 6072 if (node.isDeferred) { | |
| 6073 _result = true; | |
| 6074 } | |
| 6075 } | |
| 6076 return null; | |
| 6077 } | |
| 6078 } | |
| 6079 | |
| 6080 /** | |
| 6081 * A node that represents a directive. | |
| 6082 * | |
| 6083 * > directive ::= | |
| 6084 * > [ExportDirective] | |
| 6085 * > | [ImportDirective] | |
| 6086 * > | [LibraryDirective] | |
| 6087 * > | [PartDirective] | |
| 6088 * > | [PartOfDirective] | |
| 6089 */ | |
| 6090 abstract class Directive extends AnnotatedNode { | |
| 6091 /** | |
| 6092 * The element associated with this directive, or `null` if the AST structure | |
| 6093 * has not been resolved or if this directive could not be resolved. | |
| 6094 */ | |
| 6095 Element element; | |
| 6096 | |
| 6097 /** | |
| 6098 * Initialize a newly create directive. Either or both of the [comment] and | |
| 6099 * [metadata] can be `null` if the directive does not have the corresponding | |
| 6100 * attribute. | |
| 6101 */ | |
| 6102 Directive(Comment comment, List<Annotation> metadata) | |
| 6103 : super(comment, metadata); | |
| 6104 | |
| 6105 /** | |
| 6106 * Return the token representing the keyword that introduces this directive | |
| 6107 * ('import', 'export', 'library' or 'part'). | |
| 6108 */ | |
| 6109 Token get keyword; | |
| 6110 } | |
| 6111 | |
| 6112 /** | |
| 6113 * A do statement. | |
| 6114 * | |
| 6115 * > doStatement ::= | |
| 6116 * > 'do' [Statement] 'while' '(' [Expression] ')' ';' | |
| 6117 */ | |
| 6118 class DoStatement extends Statement { | |
| 6119 /** | |
| 6120 * The token representing the 'do' keyword. | |
| 6121 */ | |
| 6122 Token doKeyword; | |
| 6123 | |
| 6124 /** | |
| 6125 * The body of the loop. | |
| 6126 */ | |
| 6127 Statement _body; | |
| 6128 | |
| 6129 /** | |
| 6130 * The token representing the 'while' keyword. | |
| 6131 */ | |
| 6132 Token whileKeyword; | |
| 6133 | |
| 6134 /** | |
| 6135 * The left parenthesis. | |
| 6136 */ | |
| 6137 Token leftParenthesis; | |
| 6138 | |
| 6139 /** | |
| 6140 * The condition that determines when the loop will terminate. | |
| 6141 */ | |
| 6142 Expression _condition; | |
| 6143 | |
| 6144 /** | |
| 6145 * The right parenthesis. | |
| 6146 */ | |
| 6147 Token rightParenthesis; | |
| 6148 | |
| 6149 /** | |
| 6150 * The semicolon terminating the statement. | |
| 6151 */ | |
| 6152 Token semicolon; | |
| 6153 | |
| 6154 /** | |
| 6155 * Initialize a newly created do loop. | |
| 6156 */ | |
| 6157 DoStatement(this.doKeyword, Statement body, this.whileKeyword, | |
| 6158 this.leftParenthesis, Expression condition, this.rightParenthesis, | |
| 6159 this.semicolon) { | |
| 6160 _body = _becomeParentOf(body); | |
| 6161 _condition = _becomeParentOf(condition); | |
| 6162 } | |
| 6163 | |
| 6164 @override | |
| 6165 Token get beginToken => doKeyword; | |
| 6166 | |
| 6167 /** | |
| 6168 * Return the body of the loop. | |
| 6169 */ | |
| 6170 Statement get body => _body; | |
| 6171 | |
| 6172 /** | |
| 6173 * Set the body of the loop to the given [statement]. | |
| 6174 */ | |
| 6175 void set body(Statement statement) { | |
| 6176 _body = _becomeParentOf(statement); | |
| 6177 } | |
| 6178 | |
| 6179 @override | |
| 6180 Iterable get childEntities => new ChildEntities() | |
| 6181 ..add(doKeyword) | |
| 6182 ..add(_body) | |
| 6183 ..add(whileKeyword) | |
| 6184 ..add(leftParenthesis) | |
| 6185 ..add(_condition) | |
| 6186 ..add(rightParenthesis) | |
| 6187 ..add(semicolon); | |
| 6188 | |
| 6189 /** | |
| 6190 * Return the condition that determines when the loop will terminate. | |
| 6191 */ | |
| 6192 Expression get condition => _condition; | |
| 6193 | |
| 6194 /** | |
| 6195 * Set the condition that determines when the loop will terminate to the given | |
| 6196 * [expression]. | |
| 6197 */ | |
| 6198 void set condition(Expression expression) { | |
| 6199 _condition = _becomeParentOf(expression); | |
| 6200 } | |
| 6201 | |
| 6202 @override | |
| 6203 Token get endToken => semicolon; | |
| 6204 | |
| 6205 @override | |
| 6206 accept(AstVisitor visitor) => visitor.visitDoStatement(this); | |
| 6207 | |
| 6208 @override | |
| 6209 void visitChildren(AstVisitor visitor) { | |
| 6210 _safelyVisitChild(_body, visitor); | |
| 6211 _safelyVisitChild(_condition, visitor); | |
| 6212 } | |
| 6213 } | |
| 6214 | |
| 6215 /** | |
| 6216 * A floating point literal expression. | |
| 6217 * | |
| 6218 * > doubleLiteral ::= | |
| 6219 * > decimalDigit+ ('.' decimalDigit*)? exponent? | |
| 6220 * > | '.' decimalDigit+ exponent? | |
| 6221 * > | |
| 6222 * > exponent ::= | |
| 6223 * > ('e' | 'E') ('+' | '-')? decimalDigit+ | |
| 6224 */ | |
| 6225 class DoubleLiteral extends Literal { | |
| 6226 /** | |
| 6227 * The token representing the literal. | |
| 6228 */ | |
| 6229 Token literal; | |
| 6230 | |
| 6231 /** | |
| 6232 * The value of the literal. | |
| 6233 */ | |
| 6234 double value; | |
| 6235 | |
| 6236 /** | |
| 6237 * Initialize a newly created floating point literal. | |
| 6238 */ | |
| 6239 DoubleLiteral(this.literal, this.value); | |
| 6240 | |
| 6241 @override | |
| 6242 Token get beginToken => literal; | |
| 6243 | |
| 6244 @override | |
| 6245 Iterable get childEntities => new ChildEntities()..add(literal); | |
| 6246 | |
| 6247 @override | |
| 6248 Token get endToken => literal; | |
| 6249 | |
| 6250 @override | |
| 6251 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this); | |
| 6252 | |
| 6253 @override | |
| 6254 void visitChildren(AstVisitor visitor) { | |
| 6255 // There are no children to visit. | |
| 6256 } | |
| 6257 } | |
| 6258 | |
| 6259 /** | |
| 6260 * An object used to locate the [Element] associated with a given [AstNode]. | |
| 6261 */ | |
| 6262 class ElementLocator { | |
| 6263 /** | |
| 6264 * Return the element associated with the given [node], or `null` if there is | |
| 6265 * no element associated with the node. | |
| 6266 */ | |
| 6267 static Element locate(AstNode node) { | |
| 6268 if (node == null) { | |
| 6269 return null; | |
| 6270 } | |
| 6271 ElementLocator_ElementMapper mapper = new ElementLocator_ElementMapper(); | |
| 6272 return node.accept(mapper); | |
| 6273 } | |
| 6274 | |
| 6275 /** | |
| 6276 * Return the element associated with the given [node], or `null` if there is | |
| 6277 * no element associated with the node. | |
| 6278 */ | |
| 6279 static Element locateWithOffset(AstNode node, int offset) { | |
| 6280 // TODO(brianwilkerson) 'offset' is not used. Figure out what's going on: | |
| 6281 // whether there's a bug or whether this method is unnecessary. | |
| 6282 if (node == null) { | |
| 6283 return null; | |
| 6284 } | |
| 6285 // try to get Element from node | |
| 6286 Element nodeElement = locate(node); | |
| 6287 if (nodeElement != null) { | |
| 6288 return nodeElement; | |
| 6289 } | |
| 6290 // no Element | |
| 6291 return null; | |
| 6292 } | |
| 6293 } | |
| 6294 | |
| 6295 /** | |
| 6296 * Visitor that maps nodes to elements. | |
| 6297 */ | |
| 6298 class ElementLocator_ElementMapper extends GeneralizingAstVisitor<Element> { | |
| 6299 @override | |
| 6300 Element visitAnnotation(Annotation node) => node.element; | |
| 6301 | |
| 6302 @override | |
| 6303 Element visitAssignmentExpression(AssignmentExpression node) => | |
| 6304 node.bestElement; | |
| 6305 | |
| 6306 @override | |
| 6307 Element visitBinaryExpression(BinaryExpression node) => node.bestElement; | |
| 6308 | |
| 6309 @override | |
| 6310 Element visitClassDeclaration(ClassDeclaration node) => node.element; | |
| 6311 | |
| 6312 @override | |
| 6313 Element visitCompilationUnit(CompilationUnit node) => node.element; | |
| 6314 | |
| 6315 @override | |
| 6316 Element visitConstructorDeclaration(ConstructorDeclaration node) => | |
| 6317 node.element; | |
| 6318 | |
| 6319 @override | |
| 6320 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element; | |
| 6321 | |
| 6322 @override | |
| 6323 Element visitIdentifier(Identifier node) { | |
| 6324 AstNode parent = node.parent; | |
| 6325 // Type name in Annotation | |
| 6326 if (parent is Annotation) { | |
| 6327 Annotation annotation = parent; | |
| 6328 if (identical(annotation.name, node) && | |
| 6329 annotation.constructorName == null) { | |
| 6330 return annotation.element; | |
| 6331 } | |
| 6332 } | |
| 6333 // Extra work to map Constructor Declarations to their associated | |
| 6334 // Constructor Elements | |
| 6335 if (parent is ConstructorDeclaration) { | |
| 6336 ConstructorDeclaration decl = parent; | |
| 6337 Identifier returnType = decl.returnType; | |
| 6338 if (identical(returnType, node)) { | |
| 6339 SimpleIdentifier name = decl.name; | |
| 6340 if (name != null) { | |
| 6341 return name.bestElement; | |
| 6342 } | |
| 6343 Element element = node.bestElement; | |
| 6344 if (element is ClassElement) { | |
| 6345 return element.unnamedConstructor; | |
| 6346 } | |
| 6347 } | |
| 6348 } | |
| 6349 if (parent is LibraryIdentifier) { | |
| 6350 AstNode grandParent = parent.parent; | |
| 6351 if (grandParent is PartOfDirective) { | |
| 6352 Element element = grandParent.element; | |
| 6353 if (element is LibraryElement) { | |
| 6354 return element.definingCompilationUnit; | |
| 6355 } | |
| 6356 } | |
| 6357 } | |
| 6358 return node.bestElement; | |
| 6359 } | |
| 6360 | |
| 6361 @override | |
| 6362 Element visitImportDirective(ImportDirective node) => node.element; | |
| 6363 | |
| 6364 @override | |
| 6365 Element visitIndexExpression(IndexExpression node) => node.bestElement; | |
| 6366 | |
| 6367 @override | |
| 6368 Element visitInstanceCreationExpression(InstanceCreationExpression node) => | |
| 6369 node.staticElement; | |
| 6370 | |
| 6371 @override | |
| 6372 Element visitLibraryDirective(LibraryDirective node) => node.element; | |
| 6373 | |
| 6374 @override | |
| 6375 Element visitMethodDeclaration(MethodDeclaration node) => node.element; | |
| 6376 | |
| 6377 @override | |
| 6378 Element visitMethodInvocation(MethodInvocation node) => | |
| 6379 node.methodName.bestElement; | |
| 6380 | |
| 6381 @override | |
| 6382 Element visitPostfixExpression(PostfixExpression node) => node.bestElement; | |
| 6383 | |
| 6384 @override | |
| 6385 Element visitPrefixedIdentifier(PrefixedIdentifier node) => node.bestElement; | |
| 6386 | |
| 6387 @override | |
| 6388 Element visitPrefixExpression(PrefixExpression node) => node.bestElement; | |
| 6389 | |
| 6390 @override | |
| 6391 Element visitStringLiteral(StringLiteral node) { | |
| 6392 AstNode parent = node.parent; | |
| 6393 if (parent is UriBasedDirective) { | |
| 6394 return parent.uriElement; | |
| 6395 } | |
| 6396 return null; | |
| 6397 } | |
| 6398 | |
| 6399 @override | |
| 6400 Element visitVariableDeclaration(VariableDeclaration node) => node.element; | |
| 6401 } | |
| 6402 | |
| 6403 /** | |
| 6404 * An empty function body, which can only appear in constructors or abstract | |
| 6405 * methods. | |
| 6406 * | |
| 6407 * > emptyFunctionBody ::= | |
| 6408 * > ';' | |
| 6409 */ | |
| 6410 class EmptyFunctionBody extends FunctionBody { | |
| 6411 /** | |
| 6412 * The token representing the semicolon that marks the end of the function | |
| 6413 * body. | |
| 6414 */ | |
| 6415 Token semicolon; | |
| 6416 | |
| 6417 /** | |
| 6418 * Initialize a newly created function body. | |
| 6419 */ | |
| 6420 EmptyFunctionBody(this.semicolon); | |
| 6421 | |
| 6422 @override | |
| 6423 Token get beginToken => semicolon; | |
| 6424 | |
| 6425 @override | |
| 6426 Iterable get childEntities => new ChildEntities()..add(semicolon); | |
| 6427 | |
| 6428 @override | |
| 6429 Token get endToken => semicolon; | |
| 6430 | |
| 6431 @override | |
| 6432 accept(AstVisitor visitor) => visitor.visitEmptyFunctionBody(this); | |
| 6433 | |
| 6434 @override | |
| 6435 void visitChildren(AstVisitor visitor) { | |
| 6436 // Empty function bodies have no children. | |
| 6437 } | |
| 6438 } | |
| 6439 | |
| 6440 /** | |
| 6441 * An empty statement. | |
| 6442 * | |
| 6443 * > emptyStatement ::= | |
| 6444 * > ';' | |
| 6445 */ | |
| 6446 class EmptyStatement extends Statement { | |
| 6447 /** | |
| 6448 * The semicolon terminating the statement. | |
| 6449 */ | |
| 6450 Token semicolon; | |
| 6451 | |
| 6452 /** | |
| 6453 * Initialize a newly created empty statement. | |
| 6454 */ | |
| 6455 EmptyStatement(this.semicolon); | |
| 6456 | |
| 6457 @override | |
| 6458 Token get beginToken => semicolon; | |
| 6459 | |
| 6460 @override | |
| 6461 Iterable get childEntities => new ChildEntities()..add(semicolon); | |
| 6462 | |
| 6463 @override | |
| 6464 Token get endToken => semicolon; | |
| 6465 | |
| 6466 @override | |
| 6467 accept(AstVisitor visitor) => visitor.visitEmptyStatement(this); | |
| 6468 | |
| 6469 @override | |
| 6470 void visitChildren(AstVisitor visitor) { | |
| 6471 // There are no children to visit. | |
| 6472 } | |
| 6473 } | |
| 6474 | |
| 6475 /** | |
| 6476 * The declaration of an enum constant. | |
| 6477 */ | |
| 6478 class EnumConstantDeclaration extends Declaration { | |
| 6479 /** | |
| 6480 * The name of the constant. | |
| 6481 */ | |
| 6482 SimpleIdentifier _name; | |
| 6483 | |
| 6484 /** | |
| 6485 * Initialize a newly created enum constant declaration. Either or both of the | |
| 6486 * [comment] and [metadata] can be `null` if the constant does not have the | |
| 6487 * corresponding attribute. (Technically, enum constants cannot have metadata, | |
| 6488 * but we allow it for consistency.) | |
| 6489 */ | |
| 6490 EnumConstantDeclaration( | |
| 6491 Comment comment, List<Annotation> metadata, SimpleIdentifier name) | |
| 6492 : super(comment, metadata) { | |
| 6493 _name = _becomeParentOf(name); | |
| 6494 } | |
| 6495 | |
| 6496 @override | |
| 6497 Iterable get childEntities => super._childEntities..add(_name); | |
| 6498 | |
| 6499 @override | |
| 6500 FieldElement get element => | |
| 6501 _name == null ? null : (_name.staticElement as FieldElement); | |
| 6502 | |
| 6503 @override | |
| 6504 Token get endToken => _name.endToken; | |
| 6505 | |
| 6506 @override | |
| 6507 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; | |
| 6508 | |
| 6509 /** | |
| 6510 * Return the name of the constant. | |
| 6511 */ | |
| 6512 SimpleIdentifier get name => _name; | |
| 6513 | |
| 6514 /** | |
| 6515 * Set the name of the constant to the given [name]. | |
| 6516 */ | |
| 6517 void set name(SimpleIdentifier name) { | |
| 6518 _name = _becomeParentOf(name); | |
| 6519 } | |
| 6520 | |
| 6521 @override | |
| 6522 accept(AstVisitor visitor) => visitor.visitEnumConstantDeclaration(this); | |
| 6523 | |
| 6524 @override | |
| 6525 void visitChildren(AstVisitor visitor) { | |
| 6526 super.visitChildren(visitor); | |
| 6527 _safelyVisitChild(_name, visitor); | |
| 6528 } | |
| 6529 } | |
| 6530 | |
| 6531 /** | |
| 6532 * The declaration of an enumeration. | |
| 6533 * | |
| 6534 * > enumType ::= | |
| 6535 * > metadata 'enum' [SimpleIdentifier] '{' [SimpleIdentifier] (',' [SimpleI
dentifier])* (',')? '}' | |
| 6536 */ | |
| 6537 class EnumDeclaration extends NamedCompilationUnitMember { | |
| 6538 /** | |
| 6539 * The 'enum' keyword. | |
| 6540 */ | |
| 6541 Token enumKeyword; | |
| 6542 | |
| 6543 /** | |
| 6544 * The left curly bracket. | |
| 6545 */ | |
| 6546 Token leftBracket; | |
| 6547 | |
| 6548 /** | |
| 6549 * The enumeration constants being declared. | |
| 6550 */ | |
| 6551 NodeList<EnumConstantDeclaration> _constants; | |
| 6552 | |
| 6553 /** | |
| 6554 * The right curly bracket. | |
| 6555 */ | |
| 6556 Token rightBracket; | |
| 6557 | |
| 6558 /** | |
| 6559 * Initialize a newly created enumeration declaration. Either or both of the | |
| 6560 * [comment] and [metadata] can be `null` if the declaration does not have the | |
| 6561 * corresponding attribute. The list of [constants] must contain at least one | |
| 6562 * value. | |
| 6563 */ | |
| 6564 EnumDeclaration(Comment comment, List<Annotation> metadata, this.enumKeyword, | |
| 6565 SimpleIdentifier name, this.leftBracket, | |
| 6566 List<EnumConstantDeclaration> constants, this.rightBracket) | |
| 6567 : super(comment, metadata, name) { | |
| 6568 _constants = new NodeList<EnumConstantDeclaration>(this, constants); | |
| 6569 } | |
| 6570 | |
| 6571 @override | |
| 6572 // TODO(brianwilkerson) Add commas? | |
| 6573 Iterable get childEntities => super._childEntities | |
| 6574 ..add(enumKeyword) | |
| 6575 ..add(_name) | |
| 6576 ..add(leftBracket) | |
| 6577 ..addAll(_constants) | |
| 6578 ..add(rightBracket); | |
| 6579 | |
| 6580 /** | |
| 6581 * Return the enumeration constants being declared. | |
| 6582 */ | |
| 6583 NodeList<EnumConstantDeclaration> get constants => _constants; | |
| 6584 | |
| 6585 @override | |
| 6586 ClassElement get element => | |
| 6587 _name != null ? (_name.staticElement as ClassElement) : null; | |
| 6588 | |
| 6589 @override | |
| 6590 Token get endToken => rightBracket; | |
| 6591 | |
| 6592 @override | |
| 6593 Token get firstTokenAfterCommentAndMetadata => enumKeyword; | |
| 6594 | |
| 6595 /** | |
| 6596 * Return the token for the 'enum' keyword, or `null` if there is no | |
| 6597 * 'enum' keyword. | |
| 6598 */ | |
| 6599 @deprecated // Use "this.enumKeyword" | |
| 6600 Token get keyword => enumKeyword; | |
| 6601 | |
| 6602 /** | |
| 6603 * Set the token for the 'enum' keyword to the given [token]. | |
| 6604 */ | |
| 6605 @deprecated // Use "this.enumKeyword" | |
| 6606 set keyword(Token token) { | |
| 6607 enumKeyword = token; | |
| 6608 } | |
| 6609 | |
| 6610 @override | |
| 6611 accept(AstVisitor visitor) => visitor.visitEnumDeclaration(this); | |
| 6612 | |
| 6613 @override | |
| 6614 void visitChildren(AstVisitor visitor) { | |
| 6615 super.visitChildren(visitor); | |
| 6616 _safelyVisitChild(_name, visitor); | |
| 6617 _constants.accept(visitor); | |
| 6618 } | |
| 6619 } | |
| 6620 | |
| 6621 /** | |
| 6622 * Ephemeral identifiers are created as needed to mimic the presence of an empty | |
| 6623 * identifier. | |
| 6624 */ | |
| 6625 class EphemeralIdentifier extends SimpleIdentifier { | |
| 6626 EphemeralIdentifier(AstNode parent, int location) | |
| 6627 : super(new StringToken(TokenType.IDENTIFIER, "", location)) { | |
| 6628 parent._becomeParentOf(this); | |
| 6629 } | |
| 6630 } | |
| 6631 | |
| 6632 /** | |
| 6633 * An export directive. | |
| 6634 * | |
| 6635 * > exportDirective ::= | |
| 6636 * > [Annotation] 'export' [StringLiteral] [Combinator]* ';' | |
| 6637 */ | |
| 6638 class ExportDirective extends NamespaceDirective { | |
| 6639 /** | |
| 6640 * Initialize a newly created export directive. Either or both of the | |
| 6641 * [comment] and [metadata] can be `null` if the directive does not have the | |
| 6642 * corresponding attribute. The list of [combinators] can be `null` if there | |
| 6643 * are no combinators. | |
| 6644 */ | |
| 6645 ExportDirective(Comment comment, List<Annotation> metadata, Token keyword, | |
| 6646 StringLiteral libraryUri, List<Combinator> combinators, Token semicolon) | |
| 6647 : super(comment, metadata, keyword, libraryUri, combinators, semicolon); | |
| 6648 | |
| 6649 @override | |
| 6650 Iterable get childEntities => super._childEntities | |
| 6651 ..add(_uri) | |
| 6652 ..addAll(combinators) | |
| 6653 ..add(semicolon); | |
| 6654 | |
| 6655 @override | |
| 6656 ExportElement get element => super.element as ExportElement; | |
| 6657 | |
| 6658 @override | |
| 6659 LibraryElement get uriElement { | |
| 6660 if (element != null) { | |
| 6661 return element.exportedLibrary; | |
| 6662 } | |
| 6663 return null; | |
| 6664 } | |
| 6665 | |
| 6666 @override | |
| 6667 accept(AstVisitor visitor) => visitor.visitExportDirective(this); | |
| 6668 | |
| 6669 @override | |
| 6670 void visitChildren(AstVisitor visitor) { | |
| 6671 super.visitChildren(visitor); | |
| 6672 combinators.accept(visitor); | |
| 6673 } | |
| 6674 } | |
| 6675 | |
| 6676 /** | |
| 6677 * A node that represents an expression. | |
| 6678 * | |
| 6679 * > expression ::= | |
| 6680 * > [AssignmentExpression] | |
| 6681 * > | [ConditionalExpression] cascadeSection* | |
| 6682 * > | [ThrowExpression] | |
| 6683 */ | |
| 6684 abstract class Expression extends AstNode { | |
| 6685 /** | |
| 6686 * An empty list of expressions. | |
| 6687 */ | |
| 6688 @deprecated // Use "Expression.EMPTY_LIST" | |
| 6689 static const List<Expression> EMPTY_ARRAY = EMPTY_LIST; | |
| 6690 | |
| 6691 /** | |
| 6692 * An empty list of expressions. | |
| 6693 */ | |
| 6694 static const List<Expression> EMPTY_LIST = const <Expression>[]; | |
| 6695 | |
| 6696 /** | |
| 6697 * The static type of this expression, or `null` if the AST structure has not | |
| 6698 * been resolved. | |
| 6699 */ | |
| 6700 DartType staticType; | |
| 6701 | |
| 6702 /** | |
| 6703 * The propagated type of this expression, or `null` if type propagation has | |
| 6704 * not been performed on the AST structure. | |
| 6705 */ | |
| 6706 DartType propagatedType; | |
| 6707 | |
| 6708 /** | |
| 6709 * Return the best parameter element information available for this | |
| 6710 * expression. If type propagation was able to find a better parameter element | |
| 6711 * than static analysis, that type will be returned. Otherwise, the result of | |
| 6712 * static analysis will be returned. | |
| 6713 */ | |
| 6714 ParameterElement get bestParameterElement { | |
| 6715 ParameterElement propagatedElement = propagatedParameterElement; | |
| 6716 if (propagatedElement != null) { | |
| 6717 return propagatedElement; | |
| 6718 } | |
| 6719 return staticParameterElement; | |
| 6720 } | |
| 6721 | |
| 6722 /** | |
| 6723 * Return the best type information available for this expression. If type | |
| 6724 * propagation was able to find a better type than static analysis, that type | |
| 6725 * will be returned. Otherwise, the result of static analysis will be | |
| 6726 * returned. If no type analysis has been performed, then the type 'dynamic' | |
| 6727 * will be returned. | |
| 6728 */ | |
| 6729 DartType get bestType { | |
| 6730 if (propagatedType != null) { | |
| 6731 return propagatedType; | |
| 6732 } else if (staticType != null) { | |
| 6733 return staticType; | |
| 6734 } | |
| 6735 return DynamicTypeImpl.instance; | |
| 6736 } | |
| 6737 | |
| 6738 /** | |
| 6739 * Return `true` if this expression is syntactically valid for the LHS of an | |
| 6740 * [AssignmentExpression]. | |
| 6741 */ | |
| 6742 bool get isAssignable => false; | |
| 6743 | |
| 6744 /** | |
| 6745 * Return the precedence of this expression. The precedence is a positive | |
| 6746 * integer value that defines how the source code is parsed into an AST. For | |
| 6747 * example `a * b + c` is parsed as `(a * b) + c` because the precedence of | |
| 6748 * `*` is greater than the precedence of `+`. | |
| 6749 * | |
| 6750 * Clients should not assume that returned values will stay the same, they | |
| 6751 * might change as result of specification change. Only relative order should | |
| 6752 * be used. | |
| 6753 */ | |
| 6754 int get precedence; | |
| 6755 | |
| 6756 /** | |
| 6757 * If this expression is an argument to an invocation, and the AST structure | |
| 6758 * has been resolved, and the function being invoked is known based on | |
| 6759 * propagated type information, and this expression corresponds to one of the | |
| 6760 * parameters of the function being invoked, then return the parameter element | |
| 6761 * representing the parameter to which the value of this expression will be | |
| 6762 * bound. Otherwise, return `null`. | |
| 6763 */ | |
| 6764 ParameterElement get propagatedParameterElement { | |
| 6765 AstNode parent = this.parent; | |
| 6766 if (parent is ArgumentList) { | |
| 6767 return parent._getPropagatedParameterElementFor(this); | |
| 6768 } else if (parent is IndexExpression) { | |
| 6769 IndexExpression indexExpression = parent; | |
| 6770 if (identical(indexExpression.index, this)) { | |
| 6771 return indexExpression._propagatedParameterElementForIndex; | |
| 6772 } | |
| 6773 } else if (parent is BinaryExpression) { | |
| 6774 BinaryExpression binaryExpression = parent; | |
| 6775 if (identical(binaryExpression.rightOperand, this)) { | |
| 6776 return binaryExpression._propagatedParameterElementForRightOperand; | |
| 6777 } | |
| 6778 } else if (parent is AssignmentExpression) { | |
| 6779 AssignmentExpression assignmentExpression = parent; | |
| 6780 if (identical(assignmentExpression.rightHandSide, this)) { | |
| 6781 return assignmentExpression._propagatedParameterElementForRightHandSide; | |
| 6782 } | |
| 6783 } else if (parent is PrefixExpression) { | |
| 6784 return parent._propagatedParameterElementForOperand; | |
| 6785 } else if (parent is PostfixExpression) { | |
| 6786 return parent._propagatedParameterElementForOperand; | |
| 6787 } | |
| 6788 return null; | |
| 6789 } | |
| 6790 | |
| 6791 /** | |
| 6792 * If this expression is an argument to an invocation, and the AST structure | |
| 6793 * has been resolved, and the function being invoked is known based on static | |
| 6794 * type information, and this expression corresponds to one of the parameters | |
| 6795 * of the function being invoked, then return the parameter element | |
| 6796 * representing the parameter to which the value of this expression will be | |
| 6797 * bound. Otherwise, return `null`. | |
| 6798 */ | |
| 6799 ParameterElement get staticParameterElement { | |
| 6800 AstNode parent = this.parent; | |
| 6801 if (parent is ArgumentList) { | |
| 6802 return parent._getStaticParameterElementFor(this); | |
| 6803 } else if (parent is IndexExpression) { | |
| 6804 IndexExpression indexExpression = parent; | |
| 6805 if (identical(indexExpression.index, this)) { | |
| 6806 return indexExpression._staticParameterElementForIndex; | |
| 6807 } | |
| 6808 } else if (parent is BinaryExpression) { | |
| 6809 BinaryExpression binaryExpression = parent; | |
| 6810 if (identical(binaryExpression.rightOperand, this)) { | |
| 6811 return binaryExpression._staticParameterElementForRightOperand; | |
| 6812 } | |
| 6813 } else if (parent is AssignmentExpression) { | |
| 6814 AssignmentExpression assignmentExpression = parent; | |
| 6815 if (identical(assignmentExpression.rightHandSide, this)) { | |
| 6816 return assignmentExpression._staticParameterElementForRightHandSide; | |
| 6817 } | |
| 6818 } else if (parent is PrefixExpression) { | |
| 6819 return parent._staticParameterElementForOperand; | |
| 6820 } else if (parent is PostfixExpression) { | |
| 6821 return parent._staticParameterElementForOperand; | |
| 6822 } | |
| 6823 return null; | |
| 6824 } | |
| 6825 } | |
| 6826 | |
| 6827 /** | |
| 6828 * A function body consisting of a single expression. | |
| 6829 * | |
| 6830 * > expressionFunctionBody ::= | |
| 6831 * > 'async'? '=>' [Expression] ';' | |
| 6832 */ | |
| 6833 class ExpressionFunctionBody extends FunctionBody { | |
| 6834 /** | |
| 6835 * The token representing the 'async' keyword, or `null` if there is no such | |
| 6836 * keyword. | |
| 6837 */ | |
| 6838 Token keyword; | |
| 6839 | |
| 6840 /** | |
| 6841 * The token introducing the expression that represents the body of the | |
| 6842 * function. | |
| 6843 */ | |
| 6844 Token functionDefinition; | |
| 6845 | |
| 6846 /** | |
| 6847 * The expression representing the body of the function. | |
| 6848 */ | |
| 6849 Expression _expression; | |
| 6850 | |
| 6851 /** | |
| 6852 * The semicolon terminating the statement. | |
| 6853 */ | |
| 6854 Token semicolon; | |
| 6855 | |
| 6856 /** | |
| 6857 * Initialize a newly created function body consisting of a block of | |
| 6858 * statements. The [keyword] can be `null` if the function body is not an | |
| 6859 * async function body. | |
| 6860 */ | |
| 6861 ExpressionFunctionBody(this.keyword, this.functionDefinition, | |
| 6862 Expression expression, this.semicolon) { | |
| 6863 _expression = _becomeParentOf(expression); | |
| 6864 } | |
| 6865 | |
| 6866 @override | |
| 6867 Token get beginToken { | |
| 6868 if (keyword != null) { | |
| 6869 return keyword; | |
| 6870 } | |
| 6871 return functionDefinition; | |
| 6872 } | |
| 6873 | |
| 6874 @override | |
| 6875 Iterable get childEntities => new ChildEntities() | |
| 6876 ..add(keyword) | |
| 6877 ..add(functionDefinition) | |
| 6878 ..add(_expression) | |
| 6879 ..add(semicolon); | |
| 6880 | |
| 6881 @override | |
| 6882 Token get endToken { | |
| 6883 if (semicolon != null) { | |
| 6884 return semicolon; | |
| 6885 } | |
| 6886 return _expression.endToken; | |
| 6887 } | |
| 6888 | |
| 6889 /** | |
| 6890 * Return the expression representing the body of the function. | |
| 6891 */ | |
| 6892 Expression get expression => _expression; | |
| 6893 | |
| 6894 /** | |
| 6895 * Set the expression representing the body of the function to the given | |
| 6896 * [expression]. | |
| 6897 */ | |
| 6898 void set expression(Expression expression) { | |
| 6899 _expression = _becomeParentOf(expression); | |
| 6900 } | |
| 6901 | |
| 6902 @override | |
| 6903 bool get isAsynchronous => keyword != null; | |
| 6904 | |
| 6905 @override | |
| 6906 bool get isSynchronous => keyword == null; | |
| 6907 | |
| 6908 @override | |
| 6909 accept(AstVisitor visitor) => visitor.visitExpressionFunctionBody(this); | |
| 6910 | |
| 6911 @override | |
| 6912 void visitChildren(AstVisitor visitor) { | |
| 6913 _safelyVisitChild(_expression, visitor); | |
| 6914 } | |
| 6915 } | |
| 6916 | |
| 6917 /** | |
| 6918 * An expression used as a statement. | |
| 6919 * | |
| 6920 * > expressionStatement ::= | |
| 6921 * > [Expression]? ';' | |
| 6922 */ | |
| 6923 class ExpressionStatement extends Statement { | |
| 6924 /** | |
| 6925 * The expression that comprises the statement. | |
| 6926 */ | |
| 6927 Expression _expression; | |
| 6928 | |
| 6929 /** | |
| 6930 * The semicolon terminating the statement, or `null` if the expression is a | |
| 6931 * function expression and therefore isn't followed by a semicolon. | |
| 6932 */ | |
| 6933 Token semicolon; | |
| 6934 | |
| 6935 /** | |
| 6936 * Initialize a newly created expression statement. | |
| 6937 */ | |
| 6938 ExpressionStatement(Expression expression, this.semicolon) { | |
| 6939 _expression = _becomeParentOf(expression); | |
| 6940 } | |
| 6941 | |
| 6942 @override | |
| 6943 Token get beginToken => _expression.beginToken; | |
| 6944 | |
| 6945 @override | |
| 6946 Iterable get childEntities => | |
| 6947 new ChildEntities()..add(_expression)..add(semicolon); | |
| 6948 | |
| 6949 @override | |
| 6950 Token get endToken { | |
| 6951 if (semicolon != null) { | |
| 6952 return semicolon; | |
| 6953 } | |
| 6954 return _expression.endToken; | |
| 6955 } | |
| 6956 | |
| 6957 /** | |
| 6958 * Return the expression that comprises the statement. | |
| 6959 */ | |
| 6960 Expression get expression => _expression; | |
| 6961 | |
| 6962 /** | |
| 6963 * Set the expression that comprises the statement to the given [expression]. | |
| 6964 */ | |
| 6965 void set expression(Expression expression) { | |
| 6966 _expression = _becomeParentOf(expression); | |
| 6967 } | |
| 6968 | |
| 6969 @override | |
| 6970 bool get isSynthetic => _expression.isSynthetic && semicolon.isSynthetic; | |
| 6971 | |
| 6972 @override | |
| 6973 accept(AstVisitor visitor) => visitor.visitExpressionStatement(this); | |
| 6974 | |
| 6975 @override | |
| 6976 void visitChildren(AstVisitor visitor) { | |
| 6977 _safelyVisitChild(_expression, visitor); | |
| 6978 } | |
| 6979 } | |
| 6980 | |
| 6981 /** | |
| 6982 * The "extends" clause in a class declaration. | |
| 6983 * | |
| 6984 * > extendsClause ::= | |
| 6985 * > 'extends' [TypeName] | |
| 6986 */ | |
| 6987 class ExtendsClause extends AstNode { | |
| 6988 /** | |
| 6989 * The token representing the 'extends' keyword. | |
| 6990 */ | |
| 6991 Token extendsKeyword; | |
| 6992 | |
| 6993 /** | |
| 6994 * The name of the class that is being extended. | |
| 6995 */ | |
| 6996 TypeName _superclass; | |
| 6997 | |
| 6998 /** | |
| 6999 * Initialize a newly created extends clause. | |
| 7000 */ | |
| 7001 ExtendsClause(this.extendsKeyword, TypeName superclass) { | |
| 7002 _superclass = _becomeParentOf(superclass); | |
| 7003 } | |
| 7004 | |
| 7005 @override | |
| 7006 Token get beginToken => extendsKeyword; | |
| 7007 | |
| 7008 @override | |
| 7009 Iterable get childEntities => | |
| 7010 new ChildEntities()..add(extendsKeyword)..add(_superclass); | |
| 7011 | |
| 7012 @override | |
| 7013 Token get endToken => _superclass.endToken; | |
| 7014 | |
| 7015 /** | |
| 7016 * Return the token for the 'extends' keyword. | |
| 7017 */ | |
| 7018 @deprecated // Use "this.extendsKeyword" | |
| 7019 Token get keyword => extendsKeyword; | |
| 7020 | |
| 7021 /** | |
| 7022 * Set the token for the 'extends' keyword to the given [token]. | |
| 7023 */ | |
| 7024 @deprecated // Use "this.extendsKeyword" | |
| 7025 set keyword(Token token) { | |
| 7026 extendsKeyword = token; | |
| 7027 } | |
| 7028 | |
| 7029 /** | |
| 7030 * Return the name of the class that is being extended. | |
| 7031 */ | |
| 7032 TypeName get superclass => _superclass; | |
| 7033 | |
| 7034 /** | |
| 7035 * Set the name of the class that is being extended to the given [name]. | |
| 7036 */ | |
| 7037 void set superclass(TypeName name) { | |
| 7038 _superclass = _becomeParentOf(name); | |
| 7039 } | |
| 7040 | |
| 7041 @override | |
| 7042 accept(AstVisitor visitor) => visitor.visitExtendsClause(this); | |
| 7043 | |
| 7044 @override | |
| 7045 void visitChildren(AstVisitor visitor) { | |
| 7046 _safelyVisitChild(_superclass, visitor); | |
| 7047 } | |
| 7048 } | |
| 7049 | |
| 7050 /** | |
| 7051 * The declaration of one or more fields of the same type. | |
| 7052 * | |
| 7053 * > fieldDeclaration ::= | |
| 7054 * > 'static'? [VariableDeclarationList] ';' | |
| 7055 */ | |
| 7056 class FieldDeclaration extends ClassMember { | |
| 7057 /** | |
| 7058 * The token representing the 'static' keyword, or `null` if the fields are | |
| 7059 * not static. | |
| 7060 */ | |
| 7061 Token staticKeyword; | |
| 7062 | |
| 7063 /** | |
| 7064 * The fields being declared. | |
| 7065 */ | |
| 7066 VariableDeclarationList _fieldList; | |
| 7067 | |
| 7068 /** | |
| 7069 * The semicolon terminating the declaration. | |
| 7070 */ | |
| 7071 Token semicolon; | |
| 7072 | |
| 7073 /** | |
| 7074 * Initialize a newly created field declaration. Either or both of the | |
| 7075 * [comment] and [metadata] can be `null` if the declaration does not have the | |
| 7076 * corresponding attribute. The [staticKeyword] can be `null` if the field is | |
| 7077 * not a static field. | |
| 7078 */ | |
| 7079 FieldDeclaration(Comment comment, List<Annotation> metadata, | |
| 7080 this.staticKeyword, VariableDeclarationList fieldList, this.semicolon) | |
| 7081 : super(comment, metadata) { | |
| 7082 _fieldList = _becomeParentOf(fieldList); | |
| 7083 } | |
| 7084 | |
| 7085 @override | |
| 7086 Iterable get childEntities => | |
| 7087 super._childEntities..add(staticKeyword)..add(_fieldList)..add(semicolon); | |
| 7088 | |
| 7089 @override | |
| 7090 Element get element => null; | |
| 7091 | |
| 7092 @override | |
| 7093 Token get endToken => semicolon; | |
| 7094 | |
| 7095 /** | |
| 7096 * Return the fields being declared. | |
| 7097 */ | |
| 7098 VariableDeclarationList get fields => _fieldList; | |
| 7099 | |
| 7100 /** | |
| 7101 * Set the fields being declared to the given list of [fields]. | |
| 7102 */ | |
| 7103 void set fields(VariableDeclarationList fields) { | |
| 7104 _fieldList = _becomeParentOf(fields); | |
| 7105 } | |
| 7106 | |
| 7107 @override | |
| 7108 Token get firstTokenAfterCommentAndMetadata { | |
| 7109 if (staticKeyword != null) { | |
| 7110 return staticKeyword; | |
| 7111 } | |
| 7112 return _fieldList.beginToken; | |
| 7113 } | |
| 7114 | |
| 7115 /** | |
| 7116 * Return `true` if the fields are declared to be static. | |
| 7117 */ | |
| 7118 bool get isStatic => staticKeyword != null; | |
| 7119 | |
| 7120 @override | |
| 7121 accept(AstVisitor visitor) => visitor.visitFieldDeclaration(this); | |
| 7122 | |
| 7123 @override | |
| 7124 void visitChildren(AstVisitor visitor) { | |
| 7125 super.visitChildren(visitor); | |
| 7126 _safelyVisitChild(_fieldList, visitor); | |
| 7127 } | |
| 7128 } | |
| 7129 | |
| 7130 /** | |
| 7131 * A field formal parameter. | |
| 7132 * | |
| 7133 * > fieldFormalParameter ::= | |
| 7134 * > ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])? | |
| 7135 * > 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterLis
t])? | |
| 7136 */ | |
| 7137 class FieldFormalParameter extends NormalFormalParameter { | |
| 7138 /** | |
| 7139 * The token representing either the 'final', 'const' or 'var' keyword, or | |
| 7140 * `null` if no keyword was used. | |
| 7141 */ | |
| 7142 Token keyword; | |
| 7143 | |
| 7144 /** | |
| 7145 * The name of the declared type of the parameter, or `null` if the parameter | |
| 7146 * does not have a declared type. | |
| 7147 */ | |
| 7148 TypeName _type; | |
| 7149 | |
| 7150 /** | |
| 7151 * The token representing the 'this' keyword. | |
| 7152 */ | |
| 7153 Token thisKeyword; | |
| 7154 | |
| 7155 /** | |
| 7156 * The token representing the period. | |
| 7157 */ | |
| 7158 Token period; | |
| 7159 | |
| 7160 /** | |
| 7161 * The type parameters associated with the method, or `null` if the method is | |
| 7162 * not a generic method. | |
| 7163 */ | |
| 7164 TypeParameterList _typeParameters; | |
| 7165 | |
| 7166 /** | |
| 7167 * The parameters of the function-typed parameter, or `null` if this is not a | |
| 7168 * function-typed field formal parameter. | |
| 7169 */ | |
| 7170 FormalParameterList _parameters; | |
| 7171 | |
| 7172 /** | |
| 7173 * Initialize a newly created formal parameter. Either or both of the | |
| 7174 * [comment] and [metadata] can be `null` if the parameter does not have the | |
| 7175 * corresponding attribute. The [keyword] can be `null` if there is a type. | |
| 7176 * The [type] must be `null` if the keyword is 'var'. The [thisKeyword] and | |
| 7177 * [period] can be `null` if the keyword 'this' was not provided. The | |
| 7178 * [parameters] can be `null` if this is not a function-typed field formal | |
| 7179 * parameter. | |
| 7180 */ | |
| 7181 FieldFormalParameter(Comment comment, List<Annotation> metadata, this.keyword, | |
| 7182 TypeName type, this.thisKeyword, this.period, SimpleIdentifier identifier, | |
| 7183 TypeParameterList typeParameters, FormalParameterList parameters) | |
| 7184 : super(comment, metadata, identifier) { | |
| 7185 _type = _becomeParentOf(type); | |
| 7186 _typeParameters = _becomeParentOf(typeParameters); | |
| 7187 _parameters = _becomeParentOf(parameters); | |
| 7188 } | |
| 7189 | |
| 7190 @override | |
| 7191 Token get beginToken { | |
| 7192 if (keyword != null) { | |
| 7193 return keyword; | |
| 7194 } else if (_type != null) { | |
| 7195 return _type.beginToken; | |
| 7196 } | |
| 7197 return thisKeyword; | |
| 7198 } | |
| 7199 | |
| 7200 @override | |
| 7201 Iterable get childEntities => super._childEntities | |
| 7202 ..add(keyword) | |
| 7203 ..add(_type) | |
| 7204 ..add(thisKeyword) | |
| 7205 ..add(period) | |
| 7206 ..add(identifier) | |
| 7207 ..add(_parameters); | |
| 7208 | |
| 7209 @override | |
| 7210 Token get endToken { | |
| 7211 if (_parameters != null) { | |
| 7212 return _parameters.endToken; | |
| 7213 } | |
| 7214 return identifier.endToken; | |
| 7215 } | |
| 7216 | |
| 7217 @override | |
| 7218 bool get isConst => (keyword is KeywordToken) && | |
| 7219 (keyword as KeywordToken).keyword == Keyword.CONST; | |
| 7220 | |
| 7221 @override | |
| 7222 bool get isFinal => (keyword is KeywordToken) && | |
| 7223 (keyword as KeywordToken).keyword == Keyword.FINAL; | |
| 7224 | |
| 7225 /** | |
| 7226 * Return the parameters of the function-typed parameter, or `null` if this is | |
| 7227 * not a function-typed field formal parameter. | |
| 7228 */ | |
| 7229 FormalParameterList get parameters => _parameters; | |
| 7230 | |
| 7231 /** | |
| 7232 * Set the parameters of the function-typed parameter to the given | |
| 7233 * [parameters]. | |
| 7234 */ | |
| 7235 void set parameters(FormalParameterList parameters) { | |
| 7236 _parameters = _becomeParentOf(parameters); | |
| 7237 } | |
| 7238 | |
| 7239 /** | |
| 7240 * Return the token representing the 'this' keyword. | |
| 7241 */ | |
| 7242 @deprecated // Use "this.thisKeyword" | |
| 7243 Token get thisToken => thisKeyword; | |
| 7244 | |
| 7245 /** | |
| 7246 * Set the token representing the 'this' keyword to the given [token]. | |
| 7247 */ | |
| 7248 @deprecated // Use "this.thisKeyword" | |
| 7249 set thisToken(Token token) { | |
| 7250 thisKeyword = token; | |
| 7251 } | |
| 7252 | |
| 7253 /** | |
| 7254 * Return the name of the declared type of the parameter, or `null` if the | |
| 7255 * parameter does not have a declared type. Note that if this is a | |
| 7256 * function-typed field formal parameter this is the return type of the | |
| 7257 * function. | |
| 7258 */ | |
| 7259 TypeName get type => _type; | |
| 7260 | |
| 7261 /** | |
| 7262 * Set the name of the declared type of the parameter to the given [typeName]. | |
| 7263 */ | |
| 7264 void set type(TypeName typeName) { | |
| 7265 _type = _becomeParentOf(typeName); | |
| 7266 } | |
| 7267 | |
| 7268 /** | |
| 7269 * Return the type parameters associated with this method, or `null` if this | |
| 7270 * method is not a generic method. | |
| 7271 */ | |
| 7272 TypeParameterList get typeParameters => _typeParameters; | |
| 7273 | |
| 7274 /** | |
| 7275 * Set the type parameters associated with this method to the given | |
| 7276 * [typeParameters]. | |
| 7277 */ | |
| 7278 void set typeParameters(TypeParameterList typeParameters) { | |
| 7279 _typeParameters = _becomeParentOf(typeParameters); | |
| 7280 } | |
| 7281 | |
| 7282 @override | |
| 7283 accept(AstVisitor visitor) => visitor.visitFieldFormalParameter(this); | |
| 7284 | |
| 7285 @override | |
| 7286 void visitChildren(AstVisitor visitor) { | |
| 7287 super.visitChildren(visitor); | |
| 7288 _safelyVisitChild(_type, visitor); | |
| 7289 _safelyVisitChild(identifier, visitor); | |
| 7290 _safelyVisitChild(_typeParameters, visitor); | |
| 7291 _safelyVisitChild(_parameters, visitor); | |
| 7292 } | |
| 7293 } | |
| 7294 | |
| 7295 /** | |
| 7296 * A for-each statement. | |
| 7297 * | |
| 7298 * > forEachStatement ::= | |
| 7299 * > 'await'? 'for' '(' [DeclaredIdentifier] 'in' [Expression] ')' [Block] | |
| 7300 * > | 'await'? 'for' '(' [SimpleIdentifier] 'in' [Expression] ')' [Block] | |
| 7301 */ | |
| 7302 class ForEachStatement extends Statement { | |
| 7303 /** | |
| 7304 * The token representing the 'await' keyword, or `null` if there is no | |
| 7305 * 'await' keyword. | |
| 7306 */ | |
| 7307 Token awaitKeyword; | |
| 7308 | |
| 7309 /** | |
| 7310 * The token representing the 'for' keyword. | |
| 7311 */ | |
| 7312 Token forKeyword; | |
| 7313 | |
| 7314 /** | |
| 7315 * The left parenthesis. | |
| 7316 */ | |
| 7317 Token leftParenthesis; | |
| 7318 | |
| 7319 /** | |
| 7320 * The declaration of the loop variable, or `null` if the loop variable is a | |
| 7321 * simple identifier. | |
| 7322 */ | |
| 7323 DeclaredIdentifier _loopVariable; | |
| 7324 | |
| 7325 /** | |
| 7326 * The loop variable, or `null` if the loop variable is declared in the 'for'. | |
| 7327 */ | |
| 7328 SimpleIdentifier _identifier; | |
| 7329 | |
| 7330 /** | |
| 7331 * The token representing the 'in' keyword. | |
| 7332 */ | |
| 7333 Token inKeyword; | |
| 7334 | |
| 7335 /** | |
| 7336 * The expression evaluated to produce the iterator. | |
| 7337 */ | |
| 7338 Expression _iterable; | |
| 7339 | |
| 7340 /** | |
| 7341 * The right parenthesis. | |
| 7342 */ | |
| 7343 Token rightParenthesis; | |
| 7344 | |
| 7345 /** | |
| 7346 * The body of the loop. | |
| 7347 */ | |
| 7348 Statement _body; | |
| 7349 | |
| 7350 /** | |
| 7351 * Initialize a newly created for-each statement. The [awaitKeyword] can be | |
| 7352 * `null` if this is not an asynchronous for loop. | |
| 7353 */ | |
| 7354 @deprecated // Use new ForEachStatement.withDeclaration(...) | |
| 7355 ForEachStatement.con1(this.awaitKeyword, this.forKeyword, | |
| 7356 this.leftParenthesis, DeclaredIdentifier loopVariable, this.inKeyword, | |
| 7357 Expression iterator, this.rightParenthesis, Statement body) { | |
| 7358 _loopVariable = _becomeParentOf(loopVariable); | |
| 7359 _iterable = _becomeParentOf(iterator); | |
| 7360 _body = _becomeParentOf(body); | |
| 7361 } | |
| 7362 | |
| 7363 /** | |
| 7364 * Initialize a newly created for-each statement. The [awaitKeyword] can be | |
| 7365 * `null` if this is not an asynchronous for loop. | |
| 7366 */ | |
| 7367 @deprecated // Use new ForEachStatement.withReference(...) | |
| 7368 ForEachStatement.con2(this.awaitKeyword, this.forKeyword, | |
| 7369 this.leftParenthesis, SimpleIdentifier identifier, this.inKeyword, | |
| 7370 Expression iterator, this.rightParenthesis, Statement body) { | |
| 7371 _identifier = _becomeParentOf(identifier); | |
| 7372 _iterable = _becomeParentOf(iterator); | |
| 7373 _body = _becomeParentOf(body); | |
| 7374 } | |
| 7375 | |
| 7376 /** | |
| 7377 * Initialize a newly created for-each statement whose loop control variable | |
| 7378 * is declared internally (in the for-loop part). The [awaitKeyword] can be | |
| 7379 * `null` if this is not an asynchronous for loop. | |
| 7380 */ | |
| 7381 ForEachStatement.withDeclaration(this.awaitKeyword, this.forKeyword, | |
| 7382 this.leftParenthesis, DeclaredIdentifier loopVariable, this.inKeyword, | |
| 7383 Expression iterator, this.rightParenthesis, Statement body) { | |
| 7384 _loopVariable = _becomeParentOf(loopVariable); | |
| 7385 _iterable = _becomeParentOf(iterator); | |
| 7386 _body = _becomeParentOf(body); | |
| 7387 } | |
| 7388 | |
| 7389 /** | |
| 7390 * Initialize a newly created for-each statement whose loop control variable | |
| 7391 * is declared outside the for loop. The [awaitKeyword] can be `null` if this | |
| 7392 * is not an asynchronous for loop. | |
| 7393 */ | |
| 7394 ForEachStatement.withReference(this.awaitKeyword, this.forKeyword, | |
| 7395 this.leftParenthesis, SimpleIdentifier identifier, this.inKeyword, | |
| 7396 Expression iterator, this.rightParenthesis, Statement body) { | |
| 7397 _identifier = _becomeParentOf(identifier); | |
| 7398 _iterable = _becomeParentOf(iterator); | |
| 7399 _body = _becomeParentOf(body); | |
| 7400 } | |
| 7401 | |
| 7402 @override | |
| 7403 Token get beginToken => forKeyword; | |
| 7404 | |
| 7405 /** | |
| 7406 * Return the body of the loop. | |
| 7407 */ | |
| 7408 Statement get body => _body; | |
| 7409 | |
| 7410 /** | |
| 7411 * Set the body of the loop to the given [statement]. | |
| 7412 */ | |
| 7413 void set body(Statement statement) { | |
| 7414 _body = _becomeParentOf(statement); | |
| 7415 } | |
| 7416 | |
| 7417 @override | |
| 7418 Iterable get childEntities => new ChildEntities() | |
| 7419 ..add(awaitKeyword) | |
| 7420 ..add(forKeyword) | |
| 7421 ..add(leftParenthesis) | |
| 7422 ..add(_loopVariable) | |
| 7423 ..add(_identifier) | |
| 7424 ..add(inKeyword) | |
| 7425 ..add(_iterable) | |
| 7426 ..add(rightParenthesis) | |
| 7427 ..add(_body); | |
| 7428 | |
| 7429 @override | |
| 7430 Token get endToken => _body.endToken; | |
| 7431 | |
| 7432 /** | |
| 7433 * Return the loop variable, or `null` if the loop variable is declared in the | |
| 7434 * 'for'. | |
| 7435 */ | |
| 7436 SimpleIdentifier get identifier => _identifier; | |
| 7437 | |
| 7438 /** | |
| 7439 * Set the loop variable to the given [identifier]. | |
| 7440 */ | |
| 7441 void set identifier(SimpleIdentifier identifier) { | |
| 7442 _identifier = _becomeParentOf(identifier); | |
| 7443 } | |
| 7444 | |
| 7445 /** | |
| 7446 * Return the expression evaluated to produce the iterator. | |
| 7447 */ | |
| 7448 Expression get iterable => _iterable; | |
| 7449 | |
| 7450 /** | |
| 7451 * Set the expression evaluated to produce the iterator to the given | |
| 7452 * [expression]. | |
| 7453 */ | |
| 7454 void set iterable(Expression expression) { | |
| 7455 _iterable = _becomeParentOf(expression); | |
| 7456 } | |
| 7457 | |
| 7458 /** | |
| 7459 * Return the expression evaluated to produce the iterator. | |
| 7460 */ | |
| 7461 @deprecated // Use "this.iterable" | |
| 7462 Expression get iterator => iterable; | |
| 7463 | |
| 7464 /** | |
| 7465 * Return the declaration of the loop variable, or `null` if the loop variable | |
| 7466 * is a simple identifier. | |
| 7467 */ | |
| 7468 DeclaredIdentifier get loopVariable => _loopVariable; | |
| 7469 | |
| 7470 /** | |
| 7471 * Set the declaration of the loop variable to the given [variable]. | |
| 7472 */ | |
| 7473 void set loopVariable(DeclaredIdentifier variable) { | |
| 7474 _loopVariable = _becomeParentOf(variable); | |
| 7475 } | |
| 7476 | |
| 7477 @override | |
| 7478 accept(AstVisitor visitor) => visitor.visitForEachStatement(this); | |
| 7479 | |
| 7480 @override | |
| 7481 void visitChildren(AstVisitor visitor) { | |
| 7482 _safelyVisitChild(_loopVariable, visitor); | |
| 7483 _safelyVisitChild(_identifier, visitor); | |
| 7484 _safelyVisitChild(_iterable, visitor); | |
| 7485 _safelyVisitChild(_body, visitor); | |
| 7486 } | |
| 7487 } | |
| 7488 | |
| 7489 /** | |
| 7490 * A node representing a parameter to a function. | |
| 7491 * | |
| 7492 * > formalParameter ::= | |
| 7493 * > [NormalFormalParameter] | |
| 7494 * > | [DefaultFormalParameter] | |
| 7495 */ | |
| 7496 abstract class FormalParameter extends AstNode { | |
| 7497 /** | |
| 7498 * Return the element representing this parameter, or `null` if this parameter | |
| 7499 * has not been resolved. | |
| 7500 */ | |
| 7501 ParameterElement get element { | |
| 7502 SimpleIdentifier identifier = this.identifier; | |
| 7503 if (identifier == null) { | |
| 7504 return null; | |
| 7505 } | |
| 7506 return identifier.staticElement as ParameterElement; | |
| 7507 } | |
| 7508 | |
| 7509 /** | |
| 7510 * Return the name of the parameter being declared. | |
| 7511 */ | |
| 7512 SimpleIdentifier get identifier; | |
| 7513 | |
| 7514 /** | |
| 7515 * Return `true` if this parameter was declared with the 'const' modifier. | |
| 7516 */ | |
| 7517 bool get isConst; | |
| 7518 | |
| 7519 /** | |
| 7520 * Return `true` if this parameter was declared with the 'final' modifier. | |
| 7521 * Parameters that are declared with the 'const' modifier will return `false` | |
| 7522 * even though they are implicitly final. | |
| 7523 */ | |
| 7524 bool get isFinal; | |
| 7525 | |
| 7526 /** | |
| 7527 * Return the kind of this parameter. | |
| 7528 */ | |
| 7529 ParameterKind get kind; | |
| 7530 } | |
| 7531 | |
| 7532 /** | |
| 7533 * The formal parameter list of a method declaration, function declaration, or | |
| 7534 * function type alias. | |
| 7535 * | |
| 7536 * While the grammar requires all optional formal parameters to follow all of | |
| 7537 * the normal formal parameters and at most one grouping of optional formal | |
| 7538 * parameters, this class does not enforce those constraints. All parameters are | |
| 7539 * flattened into a single list, which can have any or all kinds of parameters | |
| 7540 * (normal, named, and positional) in any order. | |
| 7541 * | |
| 7542 * > formalParameterList ::= | |
| 7543 * > '(' ')' | |
| 7544 * > | '(' normalFormalParameters (',' optionalFormalParameters)? ')' | |
| 7545 * > | '(' optionalFormalParameters ')' | |
| 7546 * > | |
| 7547 * > normalFormalParameters ::= | |
| 7548 * > [NormalFormalParameter] (',' [NormalFormalParameter])* | |
| 7549 * > | |
| 7550 * > optionalFormalParameters ::= | |
| 7551 * > optionalPositionalFormalParameters | |
| 7552 * > | namedFormalParameters | |
| 7553 * > | |
| 7554 * > optionalPositionalFormalParameters ::= | |
| 7555 * > '[' [DefaultFormalParameter] (',' [DefaultFormalParameter])* ']' | |
| 7556 * > | |
| 7557 * > namedFormalParameters ::= | |
| 7558 * > '{' [DefaultFormalParameter] (',' [DefaultFormalParameter])* '}' | |
| 7559 */ | |
| 7560 class FormalParameterList extends AstNode { | |
| 7561 /** | |
| 7562 * The left parenthesis. | |
| 7563 */ | |
| 7564 Token leftParenthesis; | |
| 7565 | |
| 7566 /** | |
| 7567 * The parameters associated with the method. | |
| 7568 */ | |
| 7569 NodeList<FormalParameter> _parameters; | |
| 7570 | |
| 7571 /** | |
| 7572 * The left square bracket ('[') or left curly brace ('{') introducing the | |
| 7573 * optional parameters, or `null` if there are no optional parameters. | |
| 7574 */ | |
| 7575 Token leftDelimiter; | |
| 7576 | |
| 7577 /** | |
| 7578 * The right square bracket (']') or right curly brace ('}') terminating the | |
| 7579 * optional parameters, or `null` if there are no optional parameters. | |
| 7580 */ | |
| 7581 Token rightDelimiter; | |
| 7582 | |
| 7583 /** | |
| 7584 * The right parenthesis. | |
| 7585 */ | |
| 7586 Token rightParenthesis; | |
| 7587 | |
| 7588 /** | |
| 7589 * Initialize a newly created parameter list. The list of [parameters] can be | |
| 7590 * `null` if there are no parameters. The [leftDelimiter] and [rightDelimiter] | |
| 7591 * can be `null` if there are no optional parameters. | |
| 7592 */ | |
| 7593 FormalParameterList(this.leftParenthesis, List<FormalParameter> parameters, | |
| 7594 this.leftDelimiter, this.rightDelimiter, this.rightParenthesis) { | |
| 7595 _parameters = new NodeList<FormalParameter>(this, parameters); | |
| 7596 } | |
| 7597 | |
| 7598 @override | |
| 7599 Token get beginToken => leftParenthesis; | |
| 7600 | |
| 7601 @override | |
| 7602 Iterable get childEntities { | |
| 7603 // TODO(paulberry): include commas. | |
| 7604 ChildEntities result = new ChildEntities()..add(leftParenthesis); | |
| 7605 bool leftDelimiterNeeded = leftDelimiter != null; | |
| 7606 for (FormalParameter parameter in _parameters) { | |
| 7607 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) { | |
| 7608 result.add(leftDelimiter); | |
| 7609 leftDelimiterNeeded = false; | |
| 7610 } | |
| 7611 result.add(parameter); | |
| 7612 } | |
| 7613 return result..add(rightDelimiter)..add(rightParenthesis); | |
| 7614 } | |
| 7615 | |
| 7616 @override | |
| 7617 Token get endToken => rightParenthesis; | |
| 7618 | |
| 7619 /** | |
| 7620 * Return a list containing the elements representing the parameters in this | |
| 7621 * list. The list will contain `null`s if the parameters in this list have not | |
| 7622 * been resolved. | |
| 7623 */ | |
| 7624 List<ParameterElement> get parameterElements { | |
| 7625 int count = _parameters.length; | |
| 7626 List<ParameterElement> types = new List<ParameterElement>(count); | |
| 7627 for (int i = 0; i < count; i++) { | |
| 7628 types[i] = _parameters[i].element; | |
| 7629 } | |
| 7630 return types; | |
| 7631 } | |
| 7632 | |
| 7633 /** | |
| 7634 * Return the parameters associated with the method. | |
| 7635 */ | |
| 7636 NodeList<FormalParameter> get parameters => _parameters; | |
| 7637 | |
| 7638 @override | |
| 7639 accept(AstVisitor visitor) => visitor.visitFormalParameterList(this); | |
| 7640 | |
| 7641 @override | |
| 7642 void visitChildren(AstVisitor visitor) { | |
| 7643 _parameters.accept(visitor); | |
| 7644 } | |
| 7645 } | |
| 7646 | |
| 7647 /** | |
| 7648 * A for statement. | |
| 7649 * | |
| 7650 * > forStatement ::= | |
| 7651 * > 'for' '(' forLoopParts ')' [Statement] | |
| 7652 * > | |
| 7653 * > forLoopParts ::= | |
| 7654 * > forInitializerStatement ';' [Expression]? ';' [Expression]? | |
| 7655 * > | |
| 7656 * > forInitializerStatement ::= | |
| 7657 * > [DefaultFormalParameter] | |
| 7658 * > | [Expression]? | |
| 7659 */ | |
| 7660 class ForStatement extends Statement { | |
| 7661 /** | |
| 7662 * The token representing the 'for' keyword. | |
| 7663 */ | |
| 7664 Token forKeyword; | |
| 7665 | |
| 7666 /** | |
| 7667 * The left parenthesis. | |
| 7668 */ | |
| 7669 Token leftParenthesis; | |
| 7670 | |
| 7671 /** | |
| 7672 * The declaration of the loop variables, or `null` if there are no variables. | |
| 7673 * Note that a for statement cannot have both a variable list and an | |
| 7674 * initialization expression, but can validly have neither. | |
| 7675 */ | |
| 7676 VariableDeclarationList _variableList; | |
| 7677 | |
| 7678 /** | |
| 7679 * The initialization expression, or `null` if there is no initialization | |
| 7680 * expression. Note that a for statement cannot have both a variable list and | |
| 7681 * an initialization expression, but can validly have neither. | |
| 7682 */ | |
| 7683 Expression _initialization; | |
| 7684 | |
| 7685 /** | |
| 7686 * The semicolon separating the initializer and the condition. | |
| 7687 */ | |
| 7688 Token leftSeparator; | |
| 7689 | |
| 7690 /** | |
| 7691 * The condition used to determine when to terminate the loop, or `null` if | |
| 7692 * there is no condition. | |
| 7693 */ | |
| 7694 Expression _condition; | |
| 7695 | |
| 7696 /** | |
| 7697 * The semicolon separating the condition and the updater. | |
| 7698 */ | |
| 7699 Token rightSeparator; | |
| 7700 | |
| 7701 /** | |
| 7702 * The list of expressions run after each execution of the loop body. | |
| 7703 */ | |
| 7704 NodeList<Expression> _updaters; | |
| 7705 | |
| 7706 /** | |
| 7707 * The right parenthesis. | |
| 7708 */ | |
| 7709 Token rightParenthesis; | |
| 7710 | |
| 7711 /** | |
| 7712 * The body of the loop. | |
| 7713 */ | |
| 7714 Statement _body; | |
| 7715 | |
| 7716 /** | |
| 7717 * Initialize a newly created for statement. Either the [variableList] or the | |
| 7718 * [initialization] must be `null`. Either the [condition] and the list of | |
| 7719 * [updaters] can be `null` if the loop does not have the corresponding | |
| 7720 * attribute. | |
| 7721 */ | |
| 7722 ForStatement(this.forKeyword, this.leftParenthesis, | |
| 7723 VariableDeclarationList variableList, Expression initialization, | |
| 7724 this.leftSeparator, Expression condition, this.rightSeparator, | |
| 7725 List<Expression> updaters, this.rightParenthesis, Statement body) { | |
| 7726 _variableList = _becomeParentOf(variableList); | |
| 7727 _initialization = _becomeParentOf(initialization); | |
| 7728 _condition = _becomeParentOf(condition); | |
| 7729 _updaters = new NodeList<Expression>(this, updaters); | |
| 7730 _body = _becomeParentOf(body); | |
| 7731 } | |
| 7732 | |
| 7733 @override | |
| 7734 Token get beginToken => forKeyword; | |
| 7735 | |
| 7736 /** | |
| 7737 * Return the body of the loop. | |
| 7738 */ | |
| 7739 Statement get body => _body; | |
| 7740 | |
| 7741 /** | |
| 7742 * Set the body of the loop to the given [statement]. | |
| 7743 */ | |
| 7744 void set body(Statement statement) { | |
| 7745 _body = _becomeParentOf(statement); | |
| 7746 } | |
| 7747 | |
| 7748 @override | |
| 7749 Iterable get childEntities => new ChildEntities() | |
| 7750 ..add(forKeyword) | |
| 7751 ..add(leftParenthesis) | |
| 7752 ..add(_variableList) | |
| 7753 ..add(_initialization) | |
| 7754 ..add(leftSeparator) | |
| 7755 ..add(_condition) | |
| 7756 ..add(rightSeparator) | |
| 7757 ..addAll(_updaters) | |
| 7758 ..add(rightParenthesis) | |
| 7759 ..add(_body); | |
| 7760 | |
| 7761 /** | |
| 7762 * Return the condition used to determine when to terminate the loop, or | |
| 7763 * `null` if there is no condition. | |
| 7764 */ | |
| 7765 Expression get condition => _condition; | |
| 7766 | |
| 7767 /** | |
| 7768 * Set the condition used to determine when to terminate the loop to the given | |
| 7769 * [expression]. | |
| 7770 */ | |
| 7771 void set condition(Expression expression) { | |
| 7772 _condition = _becomeParentOf(expression); | |
| 7773 } | |
| 7774 | |
| 7775 @override | |
| 7776 Token get endToken => _body.endToken; | |
| 7777 | |
| 7778 /** | |
| 7779 * Return the initialization expression, or `null` if there is no | |
| 7780 * initialization expression. | |
| 7781 */ | |
| 7782 Expression get initialization => _initialization; | |
| 7783 | |
| 7784 /** | |
| 7785 * Set the initialization expression to the given [expression]. | |
| 7786 */ | |
| 7787 void set initialization(Expression initialization) { | |
| 7788 _initialization = _becomeParentOf(initialization); | |
| 7789 } | |
| 7790 | |
| 7791 /** | |
| 7792 * Return the list of expressions run after each execution of the loop body. | |
| 7793 */ | |
| 7794 NodeList<Expression> get updaters => _updaters; | |
| 7795 | |
| 7796 /** | |
| 7797 * Return the declaration of the loop variables, or `null` if there are no | |
| 7798 * variables. | |
| 7799 */ | |
| 7800 VariableDeclarationList get variables => _variableList; | |
| 7801 | |
| 7802 /** | |
| 7803 * Set the declaration of the loop variables to the given [variableList]. | |
| 7804 */ | |
| 7805 void set variables(VariableDeclarationList variableList) { | |
| 7806 _variableList = _becomeParentOf(variableList); | |
| 7807 } | |
| 7808 | |
| 7809 @override | |
| 7810 accept(AstVisitor visitor) => visitor.visitForStatement(this); | |
| 7811 | |
| 7812 @override | |
| 7813 void visitChildren(AstVisitor visitor) { | |
| 7814 _safelyVisitChild(_variableList, visitor); | |
| 7815 _safelyVisitChild(_initialization, visitor); | |
| 7816 _safelyVisitChild(_condition, visitor); | |
| 7817 _updaters.accept(visitor); | |
| 7818 _safelyVisitChild(_body, visitor); | |
| 7819 } | |
| 7820 } | |
| 7821 | |
| 7822 /** | |
| 7823 * A node representing the body of a function or method. | |
| 7824 * | |
| 7825 * > functionBody ::= | |
| 7826 * > [BlockFunctionBody] | |
| 7827 * > | [EmptyFunctionBody] | |
| 7828 * > | [ExpressionFunctionBody] | |
| 7829 */ | |
| 7830 abstract class FunctionBody extends AstNode { | |
| 7831 /** | |
| 7832 * Return `true` if this function body is asynchronous. | |
| 7833 */ | |
| 7834 bool get isAsynchronous => false; | |
| 7835 | |
| 7836 /** | |
| 7837 * Return `true` if this function body is a generator. | |
| 7838 */ | |
| 7839 bool get isGenerator => false; | |
| 7840 | |
| 7841 /** | |
| 7842 * Return `true` if this function body is synchronous. | |
| 7843 */ | |
| 7844 bool get isSynchronous => true; | |
| 7845 | |
| 7846 /** | |
| 7847 * Return the token representing the 'async' or 'sync' keyword, or `null` if | |
| 7848 * there is no such keyword. | |
| 7849 */ | |
| 7850 Token get keyword => null; | |
| 7851 | |
| 7852 /** | |
| 7853 * Return the star following the 'async' or 'sync' keyword, or `null` if there | |
| 7854 * is no star. | |
| 7855 */ | |
| 7856 Token get star => null; | |
| 7857 } | |
| 7858 | |
| 7859 /** | |
| 7860 * A top-level declaration. | |
| 7861 * | |
| 7862 * > functionDeclaration ::= | |
| 7863 * > 'external' functionSignature | |
| 7864 * > | functionSignature [FunctionBody] | |
| 7865 * > | |
| 7866 * > functionSignature ::= | |
| 7867 * > [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList] | |
| 7868 */ | |
| 7869 class FunctionDeclaration extends NamedCompilationUnitMember { | |
| 7870 /** | |
| 7871 * The token representing the 'external' keyword, or `null` if this is not an | |
| 7872 * external function. | |
| 7873 */ | |
| 7874 Token externalKeyword; | |
| 7875 | |
| 7876 /** | |
| 7877 * The return type of the function, or `null` if no return type was declared. | |
| 7878 */ | |
| 7879 TypeName _returnType; | |
| 7880 | |
| 7881 /** | |
| 7882 * The token representing the 'get' or 'set' keyword, or `null` if this is a | |
| 7883 * function declaration rather than a property declaration. | |
| 7884 */ | |
| 7885 Token propertyKeyword; | |
| 7886 | |
| 7887 /** | |
| 7888 * The function expression being wrapped. | |
| 7889 */ | |
| 7890 FunctionExpression _functionExpression; | |
| 7891 | |
| 7892 /** | |
| 7893 * Initialize a newly created function declaration. Either or both of the | |
| 7894 * [comment] and [metadata] can be `null` if the function does not have the | |
| 7895 * corresponding attribute. The [externalKeyword] can be `null` if the | |
| 7896 * function is not an external function. The [returnType] can be `null` if no | |
| 7897 * return type was specified. The [propertyKeyword] can be `null` if the | |
| 7898 * function is neither a getter or a setter. | |
| 7899 */ | |
| 7900 FunctionDeclaration(Comment comment, List<Annotation> metadata, | |
| 7901 this.externalKeyword, TypeName returnType, this.propertyKeyword, | |
| 7902 SimpleIdentifier name, FunctionExpression functionExpression) | |
| 7903 : super(comment, metadata, name) { | |
| 7904 _returnType = _becomeParentOf(returnType); | |
| 7905 _functionExpression = _becomeParentOf(functionExpression); | |
| 7906 } | |
| 7907 | |
| 7908 @override | |
| 7909 Iterable get childEntities => super._childEntities | |
| 7910 ..add(externalKeyword) | |
| 7911 ..add(_returnType) | |
| 7912 ..add(propertyKeyword) | |
| 7913 ..add(_name) | |
| 7914 ..add(_functionExpression); | |
| 7915 | |
| 7916 @override | |
| 7917 ExecutableElement get element => | |
| 7918 _name != null ? (_name.staticElement as ExecutableElement) : null; | |
| 7919 | |
| 7920 @override | |
| 7921 Token get endToken => _functionExpression.endToken; | |
| 7922 | |
| 7923 @override | |
| 7924 Token get firstTokenAfterCommentAndMetadata { | |
| 7925 if (externalKeyword != null) { | |
| 7926 return externalKeyword; | |
| 7927 } else if (_returnType != null) { | |
| 7928 return _returnType.beginToken; | |
| 7929 } else if (propertyKeyword != null) { | |
| 7930 return propertyKeyword; | |
| 7931 } else if (_name != null) { | |
| 7932 return _name.beginToken; | |
| 7933 } | |
| 7934 return _functionExpression.beginToken; | |
| 7935 } | |
| 7936 | |
| 7937 /** | |
| 7938 * Return the function expression being wrapped. | |
| 7939 */ | |
| 7940 FunctionExpression get functionExpression => _functionExpression; | |
| 7941 | |
| 7942 /** | |
| 7943 * Set the function expression being wrapped to the given | |
| 7944 * [functionExpression]. | |
| 7945 */ | |
| 7946 void set functionExpression(FunctionExpression functionExpression) { | |
| 7947 _functionExpression = _becomeParentOf(functionExpression); | |
| 7948 } | |
| 7949 | |
| 7950 /** | |
| 7951 * Return `true` if this function declares a getter. | |
| 7952 */ | |
| 7953 bool get isGetter => propertyKeyword != null && | |
| 7954 (propertyKeyword as KeywordToken).keyword == Keyword.GET; | |
| 7955 | |
| 7956 /** | |
| 7957 * Return `true` if this function declares a setter. | |
| 7958 */ | |
| 7959 bool get isSetter => propertyKeyword != null && | |
| 7960 (propertyKeyword as KeywordToken).keyword == Keyword.SET; | |
| 7961 | |
| 7962 /** | |
| 7963 * Return the return type of the function, or `null` if no return type was | |
| 7964 * declared. | |
| 7965 */ | |
| 7966 TypeName get returnType => _returnType; | |
| 7967 | |
| 7968 /** | |
| 7969 * Set the return type of the function to the given [returnType]. | |
| 7970 */ | |
| 7971 void set returnType(TypeName returnType) { | |
| 7972 _returnType = _becomeParentOf(returnType); | |
| 7973 } | |
| 7974 | |
| 7975 @override | |
| 7976 accept(AstVisitor visitor) => visitor.visitFunctionDeclaration(this); | |
| 7977 | |
| 7978 @override | |
| 7979 void visitChildren(AstVisitor visitor) { | |
| 7980 super.visitChildren(visitor); | |
| 7981 _safelyVisitChild(_returnType, visitor); | |
| 7982 _safelyVisitChild(_name, visitor); | |
| 7983 _safelyVisitChild(_functionExpression, visitor); | |
| 7984 } | |
| 7985 } | |
| 7986 | |
| 7987 /** | |
| 7988 * A [FunctionDeclaration] used as a statement. | |
| 7989 */ | |
| 7990 class FunctionDeclarationStatement extends Statement { | |
| 7991 /** | |
| 7992 * The function declaration being wrapped. | |
| 7993 */ | |
| 7994 FunctionDeclaration _functionDeclaration; | |
| 7995 | |
| 7996 /** | |
| 7997 * Initialize a newly created function declaration statement. | |
| 7998 */ | |
| 7999 FunctionDeclarationStatement(FunctionDeclaration functionDeclaration) { | |
| 8000 _functionDeclaration = _becomeParentOf(functionDeclaration); | |
| 8001 } | |
| 8002 | |
| 8003 @override | |
| 8004 Token get beginToken => _functionDeclaration.beginToken; | |
| 8005 | |
| 8006 @override | |
| 8007 Iterable get childEntities => new ChildEntities()..add(_functionDeclaration); | |
| 8008 | |
| 8009 @override | |
| 8010 Token get endToken => _functionDeclaration.endToken; | |
| 8011 | |
| 8012 /** | |
| 8013 * Return the function declaration being wrapped. | |
| 8014 */ | |
| 8015 FunctionDeclaration get functionDeclaration => _functionDeclaration; | |
| 8016 | |
| 8017 /** | |
| 8018 * Set the function declaration being wrapped to the given | |
| 8019 * [functionDeclaration]. | |
| 8020 */ | |
| 8021 void set functionDeclaration(FunctionDeclaration functionDeclaration) { | |
| 8022 _functionDeclaration = _becomeParentOf(functionDeclaration); | |
| 8023 } | |
| 8024 | |
| 8025 @override | |
| 8026 accept(AstVisitor visitor) => visitor.visitFunctionDeclarationStatement(this); | |
| 8027 | |
| 8028 @override | |
| 8029 void visitChildren(AstVisitor visitor) { | |
| 8030 _safelyVisitChild(_functionDeclaration, visitor); | |
| 8031 } | |
| 8032 } | |
| 8033 | |
| 8034 /** | |
| 8035 * A function expression. | |
| 8036 * | |
| 8037 * > functionExpression ::= | |
| 8038 * > [TypeParameterList]? [FormalParameterList] [FunctionBody] | |
| 8039 */ | |
| 8040 class FunctionExpression extends Expression { | |
| 8041 /** | |
| 8042 * The type parameters associated with the method, or `null` if the method is | |
| 8043 * not a generic method. | |
| 8044 */ | |
| 8045 TypeParameterList _typeParameters; | |
| 8046 | |
| 8047 /** | |
| 8048 * The parameters associated with the function. | |
| 8049 */ | |
| 8050 FormalParameterList _parameters; | |
| 8051 | |
| 8052 /** | |
| 8053 * The body of the function, or `null` if this is an external function. | |
| 8054 */ | |
| 8055 FunctionBody _body; | |
| 8056 | |
| 8057 /** | |
| 8058 * The element associated with the function, or `null` if the AST structure | |
| 8059 * has not been resolved. | |
| 8060 */ | |
| 8061 ExecutableElement element; | |
| 8062 | |
| 8063 /** | |
| 8064 * Initialize a newly created function declaration. | |
| 8065 */ | |
| 8066 FunctionExpression(TypeParameterList typeParameters, | |
| 8067 FormalParameterList parameters, FunctionBody body) { | |
| 8068 _typeParameters = _becomeParentOf(typeParameters); | |
| 8069 _parameters = _becomeParentOf(parameters); | |
| 8070 _body = _becomeParentOf(body); | |
| 8071 } | |
| 8072 | |
| 8073 @override | |
| 8074 Token get beginToken { | |
| 8075 if (_typeParameters != null) { | |
| 8076 return _typeParameters.beginToken; | |
| 8077 } else if (_parameters != null) { | |
| 8078 return _parameters.beginToken; | |
| 8079 } else if (_body != null) { | |
| 8080 return _body.beginToken; | |
| 8081 } | |
| 8082 // This should never be reached because external functions must be named, | |
| 8083 // hence either the body or the name should be non-null. | |
| 8084 throw new IllegalStateException("Non-external functions must have a body"); | |
| 8085 } | |
| 8086 | |
| 8087 /** | |
| 8088 * Return the body of the function, or `null` if this is an external function. | |
| 8089 */ | |
| 8090 FunctionBody get body => _body; | |
| 8091 | |
| 8092 /** | |
| 8093 * Set the body of the function to the given [functionBody]. | |
| 8094 */ | |
| 8095 void set body(FunctionBody functionBody) { | |
| 8096 _body = _becomeParentOf(functionBody); | |
| 8097 } | |
| 8098 | |
| 8099 @override | |
| 8100 Iterable get childEntities => | |
| 8101 new ChildEntities()..add(_parameters)..add(_body); | |
| 8102 | |
| 8103 @override | |
| 8104 Token get endToken { | |
| 8105 if (_body != null) { | |
| 8106 return _body.endToken; | |
| 8107 } else if (_parameters != null) { | |
| 8108 return _parameters.endToken; | |
| 8109 } | |
| 8110 // This should never be reached because external functions must be named, | |
| 8111 // hence either the body or the name should be non-null. | |
| 8112 throw new IllegalStateException("Non-external functions must have a body"); | |
| 8113 } | |
| 8114 | |
| 8115 /** | |
| 8116 * Return the parameters associated with the function. | |
| 8117 */ | |
| 8118 FormalParameterList get parameters => _parameters; | |
| 8119 | |
| 8120 /** | |
| 8121 * Set the parameters associated with the function to the given list of | |
| 8122 * [parameters]. | |
| 8123 */ | |
| 8124 void set parameters(FormalParameterList parameters) { | |
| 8125 _parameters = _becomeParentOf(parameters); | |
| 8126 } | |
| 8127 | |
| 8128 @override | |
| 8129 int get precedence => 16; | |
| 8130 | |
| 8131 /** | |
| 8132 * Return the type parameters associated with this method, or `null` if this | |
| 8133 * method is not a generic method. | |
| 8134 */ | |
| 8135 TypeParameterList get typeParameters => _typeParameters; | |
| 8136 | |
| 8137 /** | |
| 8138 * Set the type parameters associated with this method to the given | |
| 8139 * [typeParameters]. | |
| 8140 */ | |
| 8141 void set typeParameters(TypeParameterList typeParameters) { | |
| 8142 _typeParameters = _becomeParentOf(typeParameters); | |
| 8143 } | |
| 8144 | |
| 8145 @override | |
| 8146 accept(AstVisitor visitor) => visitor.visitFunctionExpression(this); | |
| 8147 | |
| 8148 @override | |
| 8149 void visitChildren(AstVisitor visitor) { | |
| 8150 _safelyVisitChild(_typeParameters, visitor); | |
| 8151 _safelyVisitChild(_parameters, visitor); | |
| 8152 _safelyVisitChild(_body, visitor); | |
| 8153 } | |
| 8154 } | |
| 8155 | |
| 8156 /** | |
| 8157 * The invocation of a function resulting from evaluating an expression. | |
| 8158 * Invocations of methods and other forms of functions are represented by | |
| 8159 * [MethodInvocation] nodes. Invocations of getters and setters are represented | |
| 8160 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. | |
| 8161 * | |
| 8162 * > functionExpressionInvoction ::= | |
| 8163 * > [Expression] [TypeArgumentList]? [ArgumentList] | |
| 8164 */ | |
| 8165 class FunctionExpressionInvocation extends Expression { | |
| 8166 /** | |
| 8167 * The expression producing the function being invoked. | |
| 8168 */ | |
| 8169 Expression _function; | |
| 8170 | |
| 8171 /** | |
| 8172 * The type arguments to be applied to the method being invoked, or `null` if | |
| 8173 * no type arguments were provided. | |
| 8174 */ | |
| 8175 TypeArgumentList _typeArguments; | |
| 8176 | |
| 8177 /** | |
| 8178 * The list of arguments to the function. | |
| 8179 */ | |
| 8180 ArgumentList _argumentList; | |
| 8181 | |
| 8182 /** | |
| 8183 * The element associated with the function being invoked based on static type | |
| 8184 * information, or `null` if the AST structure has not been resolved or the | |
| 8185 * function could not be resolved. | |
| 8186 */ | |
| 8187 ExecutableElement staticElement; | |
| 8188 | |
| 8189 /** | |
| 8190 * The element associated with the function being invoked based on propagated | |
| 8191 * type information, or `null` if the AST structure has not been resolved or | |
| 8192 * the function could not be resolved. | |
| 8193 */ | |
| 8194 ExecutableElement propagatedElement; | |
| 8195 | |
| 8196 /** | |
| 8197 * Initialize a newly created function expression invocation. | |
| 8198 */ | |
| 8199 FunctionExpressionInvocation(Expression function, | |
| 8200 TypeArgumentList typeArguments, ArgumentList argumentList) { | |
| 8201 _function = _becomeParentOf(function); | |
| 8202 _typeArguments = _becomeParentOf(typeArguments); | |
| 8203 _argumentList = _becomeParentOf(argumentList); | |
| 8204 } | |
| 8205 | |
| 8206 /** | |
| 8207 * Return the list of arguments to the method. | |
| 8208 */ | |
| 8209 ArgumentList get argumentList => _argumentList; | |
| 8210 | |
| 8211 /** | |
| 8212 * Set the list of arguments to the method to the given [argumentList]. | |
| 8213 */ | |
| 8214 void set argumentList(ArgumentList argumentList) { | |
| 8215 _argumentList = _becomeParentOf(argumentList); | |
| 8216 } | |
| 8217 | |
| 8218 @override | |
| 8219 Token get beginToken => _function.beginToken; | |
| 8220 | |
| 8221 /** | |
| 8222 * Return the best element available for the function being invoked. If | |
| 8223 * resolution was able to find a better element based on type propagation, | |
| 8224 * that element will be returned. Otherwise, the element found using the | |
| 8225 * result of static analysis will be returned. If resolution has not been | |
| 8226 * performed, then `null` will be returned. | |
| 8227 */ | |
| 8228 ExecutableElement get bestElement { | |
| 8229 ExecutableElement element = propagatedElement; | |
| 8230 if (element == null) { | |
| 8231 element = staticElement; | |
| 8232 } | |
| 8233 return element; | |
| 8234 } | |
| 8235 | |
| 8236 @override | |
| 8237 Iterable get childEntities => | |
| 8238 new ChildEntities()..add(_function)..add(_argumentList); | |
| 8239 | |
| 8240 @override | |
| 8241 Token get endToken => _argumentList.endToken; | |
| 8242 | |
| 8243 /** | |
| 8244 * Return the expression producing the function being invoked. | |
| 8245 */ | |
| 8246 Expression get function => _function; | |
| 8247 | |
| 8248 /** | |
| 8249 * Set the expression producing the function being invoked to the given | |
| 8250 * [expression]. | |
| 8251 */ | |
| 8252 void set function(Expression expression) { | |
| 8253 _function = _becomeParentOf(expression); | |
| 8254 } | |
| 8255 | |
| 8256 @override | |
| 8257 int get precedence => 15; | |
| 8258 | |
| 8259 /** | |
| 8260 * Return the type arguments to be applied to the method being invoked, or | |
| 8261 * `null` if no type arguments were provided. | |
| 8262 */ | |
| 8263 TypeArgumentList get typeArguments => _typeArguments; | |
| 8264 | |
| 8265 /** | |
| 8266 * Set the type arguments to be applied to the method being invoked to the | |
| 8267 * given [typeArguments]. | |
| 8268 */ | |
| 8269 void set typeArguments(TypeArgumentList typeArguments) { | |
| 8270 _typeArguments = _becomeParentOf(typeArguments); | |
| 8271 } | |
| 8272 | |
| 8273 @override | |
| 8274 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this); | |
| 8275 | |
| 8276 @override | |
| 8277 void visitChildren(AstVisitor visitor) { | |
| 8278 _safelyVisitChild(_function, visitor); | |
| 8279 _safelyVisitChild(_typeArguments, visitor); | |
| 8280 _safelyVisitChild(_argumentList, visitor); | |
| 8281 } | |
| 8282 } | |
| 8283 | |
| 8284 /** | |
| 8285 * A function type alias. | |
| 8286 * | |
| 8287 * > functionTypeAlias ::= | |
| 8288 * > functionPrefix [TypeParameterList]? [FormalParameterList] ';' | |
| 8289 * > | |
| 8290 * > functionPrefix ::= | |
| 8291 * > [TypeName]? [SimpleIdentifier] | |
| 8292 */ | |
| 8293 class FunctionTypeAlias extends TypeAlias { | |
| 8294 /** | |
| 8295 * The name of the return type of the function type being defined, or `null` | |
| 8296 * if no return type was given. | |
| 8297 */ | |
| 8298 TypeName _returnType; | |
| 8299 | |
| 8300 /** | |
| 8301 * The type parameters for the function type, or `null` if the function type | |
| 8302 * does not have any type parameters. | |
| 8303 */ | |
| 8304 TypeParameterList _typeParameters; | |
| 8305 | |
| 8306 /** | |
| 8307 * The parameters associated with the function type. | |
| 8308 */ | |
| 8309 FormalParameterList _parameters; | |
| 8310 | |
| 8311 /** | |
| 8312 * Initialize a newly created function type alias. Either or both of the | |
| 8313 * [comment] and [metadata] can be `null` if the function does not have the | |
| 8314 * corresponding attribute. The [returnType] can be `null` if no return type | |
| 8315 * was specified. The [typeParameters] can be `null` if the function has no | |
| 8316 * type parameters. | |
| 8317 */ | |
| 8318 FunctionTypeAlias(Comment comment, List<Annotation> metadata, Token keyword, | |
| 8319 TypeName returnType, SimpleIdentifier name, | |
| 8320 TypeParameterList typeParameters, FormalParameterList parameters, | |
| 8321 Token semicolon) | |
| 8322 : super(comment, metadata, keyword, name, semicolon) { | |
| 8323 _returnType = _becomeParentOf(returnType); | |
| 8324 _typeParameters = _becomeParentOf(typeParameters); | |
| 8325 _parameters = _becomeParentOf(parameters); | |
| 8326 } | |
| 8327 | |
| 8328 @override | |
| 8329 Iterable get childEntities => super._childEntities | |
| 8330 ..add(typedefKeyword) | |
| 8331 ..add(_returnType) | |
| 8332 ..add(_name) | |
| 8333 ..add(_typeParameters) | |
| 8334 ..add(_parameters) | |
| 8335 ..add(semicolon); | |
| 8336 | |
| 8337 @override | |
| 8338 FunctionTypeAliasElement get element => | |
| 8339 _name != null ? (_name.staticElement as FunctionTypeAliasElement) : null; | |
| 8340 | |
| 8341 /** | |
| 8342 * Return the parameters associated with the function type. | |
| 8343 */ | |
| 8344 FormalParameterList get parameters => _parameters; | |
| 8345 | |
| 8346 /** | |
| 8347 * Set the parameters associated with the function type to the given list of | |
| 8348 * [parameters]. | |
| 8349 */ | |
| 8350 void set parameters(FormalParameterList parameters) { | |
| 8351 _parameters = _becomeParentOf(parameters); | |
| 8352 } | |
| 8353 | |
| 8354 /** | |
| 8355 * Return the name of the return type of the function type being defined, or | |
| 8356 * `null` if no return type was given. | |
| 8357 */ | |
| 8358 TypeName get returnType => _returnType; | |
| 8359 | |
| 8360 /** | |
| 8361 * Set the name of the return type of the function type being defined to the | |
| 8362 * given [typeName]. | |
| 8363 */ | |
| 8364 void set returnType(TypeName typeName) { | |
| 8365 _returnType = _becomeParentOf(typeName); | |
| 8366 } | |
| 8367 | |
| 8368 /** | |
| 8369 * Return the type parameters for the function type, or `null` if the function | |
| 8370 * type does not have any type parameters. | |
| 8371 */ | |
| 8372 TypeParameterList get typeParameters => _typeParameters; | |
| 8373 | |
| 8374 /** | |
| 8375 * Set the type parameters for the function type to the given list of | |
| 8376 * [typeParameters]. | |
| 8377 */ | |
| 8378 void set typeParameters(TypeParameterList typeParameters) { | |
| 8379 _typeParameters = _becomeParentOf(typeParameters); | |
| 8380 } | |
| 8381 | |
| 8382 @override | |
| 8383 accept(AstVisitor visitor) => visitor.visitFunctionTypeAlias(this); | |
| 8384 | |
| 8385 @override | |
| 8386 void visitChildren(AstVisitor visitor) { | |
| 8387 super.visitChildren(visitor); | |
| 8388 _safelyVisitChild(_returnType, visitor); | |
| 8389 _safelyVisitChild(_name, visitor); | |
| 8390 _safelyVisitChild(_typeParameters, visitor); | |
| 8391 _safelyVisitChild(_parameters, visitor); | |
| 8392 } | |
| 8393 } | |
| 8394 | |
| 8395 /** | |
| 8396 * A function-typed formal parameter. | |
| 8397 * | |
| 8398 * > functionSignature ::= | |
| 8399 * > [TypeName]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterLis
t] | |
| 8400 */ | |
| 8401 class FunctionTypedFormalParameter extends NormalFormalParameter { | |
| 8402 /** | |
| 8403 * The return type of the function, or `null` if the function does not have a | |
| 8404 * return type. | |
| 8405 */ | |
| 8406 TypeName _returnType; | |
| 8407 | |
| 8408 /** | |
| 8409 * The type parameters associated with the function, or `null` if the function | |
| 8410 * is not a generic function. | |
| 8411 */ | |
| 8412 TypeParameterList _typeParameters; | |
| 8413 | |
| 8414 /** | |
| 8415 * The parameters of the function-typed parameter. | |
| 8416 */ | |
| 8417 FormalParameterList _parameters; | |
| 8418 | |
| 8419 /** | |
| 8420 * Initialize a newly created formal parameter. Either or both of the | |
| 8421 * [comment] and [metadata] can be `null` if the parameter does not have the | |
| 8422 * corresponding attribute. The [returnType] can be `null` if no return type | |
| 8423 * was specified. | |
| 8424 */ | |
| 8425 FunctionTypedFormalParameter(Comment comment, List<Annotation> metadata, | |
| 8426 TypeName returnType, SimpleIdentifier identifier, | |
| 8427 TypeParameterList typeParameters, FormalParameterList parameters) | |
| 8428 : super(comment, metadata, identifier) { | |
| 8429 _returnType = _becomeParentOf(returnType); | |
| 8430 _typeParameters = _becomeParentOf(typeParameters); | |
| 8431 _parameters = _becomeParentOf(parameters); | |
| 8432 } | |
| 8433 | |
| 8434 @override | |
| 8435 Token get beginToken { | |
| 8436 if (_returnType != null) { | |
| 8437 return _returnType.beginToken; | |
| 8438 } | |
| 8439 return identifier.beginToken; | |
| 8440 } | |
| 8441 | |
| 8442 @override | |
| 8443 Iterable get childEntities => | |
| 8444 super._childEntities..add(_returnType)..add(identifier)..add(parameters); | |
| 8445 | |
| 8446 @override | |
| 8447 Token get endToken => _parameters.endToken; | |
| 8448 | |
| 8449 @override | |
| 8450 bool get isConst => false; | |
| 8451 | |
| 8452 @override | |
| 8453 bool get isFinal => false; | |
| 8454 | |
| 8455 /** | |
| 8456 * Return the parameters of the function-typed parameter. | |
| 8457 */ | |
| 8458 FormalParameterList get parameters => _parameters; | |
| 8459 | |
| 8460 /** | |
| 8461 * Set the parameters of the function-typed parameter to the given | |
| 8462 * [parameters]. | |
| 8463 */ | |
| 8464 void set parameters(FormalParameterList parameters) { | |
| 8465 _parameters = _becomeParentOf(parameters); | |
| 8466 } | |
| 8467 | |
| 8468 /** | |
| 8469 * Return the return type of the function, or `null` if the function does not | |
| 8470 * have a return type. | |
| 8471 */ | |
| 8472 TypeName get returnType => _returnType; | |
| 8473 | |
| 8474 /** | |
| 8475 * Set the return type of the function to the given [type]. | |
| 8476 */ | |
| 8477 void set returnType(TypeName type) { | |
| 8478 _returnType = _becomeParentOf(type); | |
| 8479 } | |
| 8480 | |
| 8481 /** | |
| 8482 * Return the type parameters associated with this function, or `null` if | |
| 8483 * this function is not a generic function. | |
| 8484 */ | |
| 8485 TypeParameterList get typeParameters => _typeParameters; | |
| 8486 | |
| 8487 /** | |
| 8488 * Set the type parameters associated with this method to the given | |
| 8489 * [typeParameters]. | |
| 8490 */ | |
| 8491 void set typeParameters(TypeParameterList typeParameters) { | |
| 8492 _typeParameters = _becomeParentOf(typeParameters); | |
| 8493 } | |
| 8494 | |
| 8495 @override | |
| 8496 accept(AstVisitor visitor) => visitor.visitFunctionTypedFormalParameter(this); | |
| 8497 | |
| 8498 @override | |
| 8499 void visitChildren(AstVisitor visitor) { | |
| 8500 super.visitChildren(visitor); | |
| 8501 _safelyVisitChild(_returnType, visitor); | |
| 8502 _safelyVisitChild(identifier, visitor); | |
| 8503 _safelyVisitChild(_typeParameters, visitor); | |
| 8504 _safelyVisitChild(_parameters, visitor); | |
| 8505 } | |
| 8506 } | |
| 8507 | |
| 8508 /** | |
| 8509 * An AST visitor that will recursively visit all of the nodes in an AST | |
| 8510 * structure (like instances of the class [RecursiveAstVisitor]). In addition, | |
| 8511 * when a node of a specific type is visited not only will the visit method for | |
| 8512 * that specific type of node be invoked, but additional methods for the | |
| 8513 * superclasses of that node will also be invoked. For example, using an | |
| 8514 * instance of this class to visit a [Block] will cause the method [visitBlock] | |
| 8515 * to be invoked but will also cause the methods [visitStatement] and | |
| 8516 * [visitNode] to be subsequently invoked. This allows visitors to be written | |
| 8517 * that visit all statements without needing to override the visit method for | |
| 8518 * each of the specific subclasses of [Statement]. | |
| 8519 * | |
| 8520 * Subclasses that override a visit method must either invoke the overridden | |
| 8521 * visit method or explicitly invoke the more general visit method. Failure to | |
| 8522 * do so will cause the visit methods for superclasses of the node to not be | |
| 8523 * invoked and will cause the children of the visited node to not be visited. | |
| 8524 */ | |
| 8525 class GeneralizingAstVisitor<R> implements AstVisitor<R> { | |
| 8526 @override | |
| 8527 R visitAdjacentStrings(AdjacentStrings node) => visitStringLiteral(node); | |
| 8528 | |
| 8529 R visitAnnotatedNode(AnnotatedNode node) => visitNode(node); | |
| 8530 | |
| 8531 @override | |
| 8532 R visitAnnotation(Annotation node) => visitNode(node); | |
| 8533 | |
| 8534 @override | |
| 8535 R visitArgumentList(ArgumentList node) => visitNode(node); | |
| 8536 | |
| 8537 @override | |
| 8538 R visitAsExpression(AsExpression node) => visitExpression(node); | |
| 8539 | |
| 8540 @override | |
| 8541 R visitAssertStatement(AssertStatement node) => visitStatement(node); | |
| 8542 | |
| 8543 @override | |
| 8544 R visitAssignmentExpression(AssignmentExpression node) => | |
| 8545 visitExpression(node); | |
| 8546 | |
| 8547 @override | |
| 8548 R visitAwaitExpression(AwaitExpression node) => visitExpression(node); | |
| 8549 | |
| 8550 @override | |
| 8551 R visitBinaryExpression(BinaryExpression node) => visitExpression(node); | |
| 8552 | |
| 8553 @override | |
| 8554 R visitBlock(Block node) => visitStatement(node); | |
| 8555 | |
| 8556 @override | |
| 8557 R visitBlockFunctionBody(BlockFunctionBody node) => visitFunctionBody(node); | |
| 8558 | |
| 8559 @override | |
| 8560 R visitBooleanLiteral(BooleanLiteral node) => visitLiteral(node); | |
| 8561 | |
| 8562 @override | |
| 8563 R visitBreakStatement(BreakStatement node) => visitStatement(node); | |
| 8564 | |
| 8565 @override | |
| 8566 R visitCascadeExpression(CascadeExpression node) => visitExpression(node); | |
| 8567 | |
| 8568 @override | |
| 8569 R visitCatchClause(CatchClause node) => visitNode(node); | |
| 8570 | |
| 8571 @override | |
| 8572 R visitClassDeclaration(ClassDeclaration node) => | |
| 8573 visitNamedCompilationUnitMember(node); | |
| 8574 | |
| 8575 R visitClassMember(ClassMember node) => visitDeclaration(node); | |
| 8576 | |
| 8577 @override | |
| 8578 R visitClassTypeAlias(ClassTypeAlias node) => visitTypeAlias(node); | |
| 8579 | |
| 8580 R visitCombinator(Combinator node) => visitNode(node); | |
| 8581 | |
| 8582 @override | |
| 8583 R visitComment(Comment node) => visitNode(node); | |
| 8584 | |
| 8585 @override | |
| 8586 R visitCommentReference(CommentReference node) => visitNode(node); | |
| 8587 | |
| 8588 @override | |
| 8589 R visitCompilationUnit(CompilationUnit node) => visitNode(node); | |
| 8590 | |
| 8591 R visitCompilationUnitMember(CompilationUnitMember node) => | |
| 8592 visitDeclaration(node); | |
| 8593 | |
| 8594 @override | |
| 8595 R visitConditionalExpression(ConditionalExpression node) => | |
| 8596 visitExpression(node); | |
| 8597 | |
| 8598 @override | |
| 8599 R visitConstructorDeclaration(ConstructorDeclaration node) => | |
| 8600 visitClassMember(node); | |
| 8601 | |
| 8602 @override | |
| 8603 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => | |
| 8604 visitConstructorInitializer(node); | |
| 8605 | |
| 8606 R visitConstructorInitializer(ConstructorInitializer node) => visitNode(node); | |
| 8607 | |
| 8608 @override | |
| 8609 R visitConstructorName(ConstructorName node) => visitNode(node); | |
| 8610 | |
| 8611 @override | |
| 8612 R visitContinueStatement(ContinueStatement node) => visitStatement(node); | |
| 8613 | |
| 8614 R visitDeclaration(Declaration node) => visitAnnotatedNode(node); | |
| 8615 | |
| 8616 @override | |
| 8617 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitDeclaration(node); | |
| 8618 | |
| 8619 @override | |
| 8620 R visitDefaultFormalParameter(DefaultFormalParameter node) => | |
| 8621 visitFormalParameter(node); | |
| 8622 | |
| 8623 R visitDirective(Directive node) => visitAnnotatedNode(node); | |
| 8624 | |
| 8625 @override | |
| 8626 R visitDoStatement(DoStatement node) => visitStatement(node); | |
| 8627 | |
| 8628 @override | |
| 8629 R visitDoubleLiteral(DoubleLiteral node) => visitLiteral(node); | |
| 8630 | |
| 8631 @override | |
| 8632 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitFunctionBody(node); | |
| 8633 | |
| 8634 @override | |
| 8635 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); | |
| 8636 | |
| 8637 @override | |
| 8638 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => | |
| 8639 visitDeclaration(node); | |
| 8640 | |
| 8641 @override | |
| 8642 R visitEnumDeclaration(EnumDeclaration node) => | |
| 8643 visitNamedCompilationUnitMember(node); | |
| 8644 | |
| 8645 @override | |
| 8646 R visitExportDirective(ExportDirective node) => visitNamespaceDirective(node); | |
| 8647 | |
| 8648 R visitExpression(Expression node) => visitNode(node); | |
| 8649 | |
| 8650 @override | |
| 8651 R visitExpressionFunctionBody(ExpressionFunctionBody node) => | |
| 8652 visitFunctionBody(node); | |
| 8653 | |
| 8654 @override | |
| 8655 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); | |
| 8656 | |
| 8657 @override | |
| 8658 R visitExtendsClause(ExtendsClause node) => visitNode(node); | |
| 8659 | |
| 8660 @override | |
| 8661 R visitFieldDeclaration(FieldDeclaration node) => visitClassMember(node); | |
| 8662 | |
| 8663 @override | |
| 8664 R visitFieldFormalParameter(FieldFormalParameter node) => | |
| 8665 visitNormalFormalParameter(node); | |
| 8666 | |
| 8667 @override | |
| 8668 R visitForEachStatement(ForEachStatement node) => visitStatement(node); | |
| 8669 | |
| 8670 R visitFormalParameter(FormalParameter node) => visitNode(node); | |
| 8671 | |
| 8672 @override | |
| 8673 R visitFormalParameterList(FormalParameterList node) => visitNode(node); | |
| 8674 | |
| 8675 @override | |
| 8676 R visitForStatement(ForStatement node) => visitStatement(node); | |
| 8677 | |
| 8678 R visitFunctionBody(FunctionBody node) => visitNode(node); | |
| 8679 | |
| 8680 @override | |
| 8681 R visitFunctionDeclaration(FunctionDeclaration node) => | |
| 8682 visitNamedCompilationUnitMember(node); | |
| 8683 | |
| 8684 @override | |
| 8685 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => | |
| 8686 visitStatement(node); | |
| 8687 | |
| 8688 @override | |
| 8689 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); | |
| 8690 | |
| 8691 @override | |
| 8692 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => | |
| 8693 visitExpression(node); | |
| 8694 | |
| 8695 @override | |
| 8696 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitTypeAlias(node); | |
| 8697 | |
| 8698 @override | |
| 8699 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => | |
| 8700 visitNormalFormalParameter(node); | |
| 8701 | |
| 8702 @override | |
| 8703 R visitHideCombinator(HideCombinator node) => visitCombinator(node); | |
| 8704 | |
| 8705 R visitIdentifier(Identifier node) => visitExpression(node); | |
| 8706 | |
| 8707 @override | |
| 8708 R visitIfStatement(IfStatement node) => visitStatement(node); | |
| 8709 | |
| 8710 @override | |
| 8711 R visitImplementsClause(ImplementsClause node) => visitNode(node); | |
| 8712 | |
| 8713 @override | |
| 8714 R visitImportDirective(ImportDirective node) => visitNamespaceDirective(node); | |
| 8715 | |
| 8716 @override | |
| 8717 R visitIndexExpression(IndexExpression node) => visitExpression(node); | |
| 8718 | |
| 8719 @override | |
| 8720 R visitInstanceCreationExpression(InstanceCreationExpression node) => | |
| 8721 visitExpression(node); | |
| 8722 | |
| 8723 @override | |
| 8724 R visitIntegerLiteral(IntegerLiteral node) => visitLiteral(node); | |
| 8725 | |
| 8726 R visitInterpolationElement(InterpolationElement node) => visitNode(node); | |
| 8727 | |
| 8728 @override | |
| 8729 R visitInterpolationExpression(InterpolationExpression node) => | |
| 8730 visitInterpolationElement(node); | |
| 8731 | |
| 8732 @override | |
| 8733 R visitInterpolationString(InterpolationString node) => | |
| 8734 visitInterpolationElement(node); | |
| 8735 | |
| 8736 @override | |
| 8737 R visitIsExpression(IsExpression node) => visitExpression(node); | |
| 8738 | |
| 8739 @override | |
| 8740 R visitLabel(Label node) => visitNode(node); | |
| 8741 | |
| 8742 @override | |
| 8743 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); | |
| 8744 | |
| 8745 @override | |
| 8746 R visitLibraryDirective(LibraryDirective node) => visitDirective(node); | |
| 8747 | |
| 8748 @override | |
| 8749 R visitLibraryIdentifier(LibraryIdentifier node) => visitIdentifier(node); | |
| 8750 | |
| 8751 @override | |
| 8752 R visitListLiteral(ListLiteral node) => visitTypedLiteral(node); | |
| 8753 | |
| 8754 R visitLiteral(Literal node) => visitExpression(node); | |
| 8755 | |
| 8756 @override | |
| 8757 R visitMapLiteral(MapLiteral node) => visitTypedLiteral(node); | |
| 8758 | |
| 8759 @override | |
| 8760 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node); | |
| 8761 | |
| 8762 @override | |
| 8763 R visitMethodDeclaration(MethodDeclaration node) => visitClassMember(node); | |
| 8764 | |
| 8765 @override | |
| 8766 R visitMethodInvocation(MethodInvocation node) => visitExpression(node); | |
| 8767 | |
| 8768 R visitNamedCompilationUnitMember(NamedCompilationUnitMember node) => | |
| 8769 visitCompilationUnitMember(node); | |
| 8770 | |
| 8771 @override | |
| 8772 R visitNamedExpression(NamedExpression node) => visitExpression(node); | |
| 8773 | |
| 8774 R visitNamespaceDirective(NamespaceDirective node) => | |
| 8775 visitUriBasedDirective(node); | |
| 8776 | |
| 8777 @override | |
| 8778 R visitNativeClause(NativeClause node) => visitNode(node); | |
| 8779 | |
| 8780 @override | |
| 8781 R visitNativeFunctionBody(NativeFunctionBody node) => visitFunctionBody(node); | |
| 8782 | |
| 8783 R visitNode(AstNode node) { | |
| 8784 node.visitChildren(this); | |
| 8785 return null; | |
| 8786 } | |
| 8787 | |
| 8788 R visitNormalFormalParameter(NormalFormalParameter node) => | |
| 8789 visitFormalParameter(node); | |
| 8790 | |
| 8791 @override | |
| 8792 R visitNullLiteral(NullLiteral node) => visitLiteral(node); | |
| 8793 | |
| 8794 @override | |
| 8795 R visitParenthesizedExpression(ParenthesizedExpression node) => | |
| 8796 visitExpression(node); | |
| 8797 | |
| 8798 @override | |
| 8799 R visitPartDirective(PartDirective node) => visitUriBasedDirective(node); | |
| 8800 | |
| 8801 @override | |
| 8802 R visitPartOfDirective(PartOfDirective node) => visitDirective(node); | |
| 8803 | |
| 8804 @override | |
| 8805 R visitPostfixExpression(PostfixExpression node) => visitExpression(node); | |
| 8806 | |
| 8807 @override | |
| 8808 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitIdentifier(node); | |
| 8809 | |
| 8810 @override | |
| 8811 R visitPrefixExpression(PrefixExpression node) => visitExpression(node); | |
| 8812 | |
| 8813 @override | |
| 8814 R visitPropertyAccess(PropertyAccess node) => visitExpression(node); | |
| 8815 | |
| 8816 @override | |
| 8817 R visitRedirectingConstructorInvocation( | |
| 8818 RedirectingConstructorInvocation node) => | |
| 8819 visitConstructorInitializer(node); | |
| 8820 | |
| 8821 @override | |
| 8822 R visitRethrowExpression(RethrowExpression node) => visitExpression(node); | |
| 8823 | |
| 8824 @override | |
| 8825 R visitReturnStatement(ReturnStatement node) => visitStatement(node); | |
| 8826 | |
| 8827 @override | |
| 8828 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); | |
| 8829 | |
| 8830 @override | |
| 8831 R visitShowCombinator(ShowCombinator node) => visitCombinator(node); | |
| 8832 | |
| 8833 @override | |
| 8834 R visitSimpleFormalParameter(SimpleFormalParameter node) => | |
| 8835 visitNormalFormalParameter(node); | |
| 8836 | |
| 8837 @override | |
| 8838 R visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node); | |
| 8839 | |
| 8840 @override | |
| 8841 R visitSimpleStringLiteral(SimpleStringLiteral node) => | |
| 8842 visitSingleStringLiteral(node); | |
| 8843 | |
| 8844 R visitSingleStringLiteral(SingleStringLiteral node) => | |
| 8845 visitStringLiteral(node); | |
| 8846 | |
| 8847 R visitStatement(Statement node) => visitNode(node); | |
| 8848 | |
| 8849 @override | |
| 8850 R visitStringInterpolation(StringInterpolation node) => | |
| 8851 visitSingleStringLiteral(node); | |
| 8852 | |
| 8853 R visitStringLiteral(StringLiteral node) => visitLiteral(node); | |
| 8854 | |
| 8855 @override | |
| 8856 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => | |
| 8857 visitConstructorInitializer(node); | |
| 8858 | |
| 8859 @override | |
| 8860 R visitSuperExpression(SuperExpression node) => visitExpression(node); | |
| 8861 | |
| 8862 @override | |
| 8863 R visitSwitchCase(SwitchCase node) => visitSwitchMember(node); | |
| 8864 | |
| 8865 @override | |
| 8866 R visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node); | |
| 8867 | |
| 8868 R visitSwitchMember(SwitchMember node) => visitNode(node); | |
| 8869 | |
| 8870 @override | |
| 8871 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); | |
| 8872 | |
| 8873 @override | |
| 8874 R visitSymbolLiteral(SymbolLiteral node) => visitLiteral(node); | |
| 8875 | |
| 8876 @override | |
| 8877 R visitThisExpression(ThisExpression node) => visitExpression(node); | |
| 8878 | |
| 8879 @override | |
| 8880 R visitThrowExpression(ThrowExpression node) => visitExpression(node); | |
| 8881 | |
| 8882 @override | |
| 8883 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => | |
| 8884 visitCompilationUnitMember(node); | |
| 8885 | |
| 8886 @override | |
| 8887 R visitTryStatement(TryStatement node) => visitStatement(node); | |
| 8888 | |
| 8889 R visitTypeAlias(TypeAlias node) => visitNamedCompilationUnitMember(node); | |
| 8890 | |
| 8891 @override | |
| 8892 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node); | |
| 8893 | |
| 8894 R visitTypedLiteral(TypedLiteral node) => visitLiteral(node); | |
| 8895 | |
| 8896 @override | |
| 8897 R visitTypeName(TypeName node) => visitNode(node); | |
| 8898 | |
| 8899 @override | |
| 8900 R visitTypeParameter(TypeParameter node) => visitNode(node); | |
| 8901 | |
| 8902 @override | |
| 8903 R visitTypeParameterList(TypeParameterList node) => visitNode(node); | |
| 8904 | |
| 8905 R visitUriBasedDirective(UriBasedDirective node) => visitDirective(node); | |
| 8906 | |
| 8907 @override | |
| 8908 R visitVariableDeclaration(VariableDeclaration node) => | |
| 8909 visitDeclaration(node); | |
| 8910 | |
| 8911 @override | |
| 8912 R visitVariableDeclarationList(VariableDeclarationList node) => | |
| 8913 visitNode(node); | |
| 8914 | |
| 8915 @override | |
| 8916 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => | |
| 8917 visitStatement(node); | |
| 8918 | |
| 8919 @override | |
| 8920 R visitWhileStatement(WhileStatement node) => visitStatement(node); | |
| 8921 | |
| 8922 @override | |
| 8923 R visitWithClause(WithClause node) => visitNode(node); | |
| 8924 | |
| 8925 @override | |
| 8926 R visitYieldStatement(YieldStatement node) => visitStatement(node); | |
| 8927 } | |
| 8928 | |
| 8929 class GeneralizingAstVisitor_BreadthFirstVisitor | |
| 8930 extends GeneralizingAstVisitor<Object> { | |
| 8931 final BreadthFirstVisitor BreadthFirstVisitor_this; | |
| 8932 | |
| 8933 GeneralizingAstVisitor_BreadthFirstVisitor(this.BreadthFirstVisitor_this) | |
| 8934 : super(); | |
| 8935 | |
| 8936 @override | |
| 8937 Object visitNode(AstNode node) { | |
| 8938 BreadthFirstVisitor_this._queue.add(node); | |
| 8939 return null; | |
| 8940 } | |
| 8941 } | |
| 8942 | |
| 8943 /** | |
| 8944 * A combinator that restricts the names being imported to those that are not in | |
| 8945 * a given list. | |
| 8946 * | |
| 8947 * > hideCombinator ::= | |
| 8948 * > 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])* | |
| 8949 */ | |
| 8950 class HideCombinator extends Combinator { | |
| 8951 /** | |
| 8952 * The list of names from the library that are hidden by this combinator. | |
| 8953 */ | |
| 8954 NodeList<SimpleIdentifier> _hiddenNames; | |
| 8955 | |
| 8956 /** | |
| 8957 * Initialize a newly created import show combinator. | |
| 8958 */ | |
| 8959 HideCombinator(Token keyword, List<SimpleIdentifier> hiddenNames) | |
| 8960 : super(keyword) { | |
| 8961 _hiddenNames = new NodeList<SimpleIdentifier>(this, hiddenNames); | |
| 8962 } | |
| 8963 | |
| 8964 @override | |
| 8965 Iterable get childEntities => new ChildEntities() | |
| 8966 ..add(keyword) | |
| 8967 ..addAll(_hiddenNames); | |
| 8968 | |
| 8969 @override | |
| 8970 Token get endToken => _hiddenNames.endToken; | |
| 8971 | |
| 8972 /** | |
| 8973 * Return the list of names from the library that are hidden by this | |
| 8974 * combinator. | |
| 8975 */ | |
| 8976 NodeList<SimpleIdentifier> get hiddenNames => _hiddenNames; | |
| 8977 | |
| 8978 @override | |
| 8979 accept(AstVisitor visitor) => visitor.visitHideCombinator(this); | |
| 8980 | |
| 8981 @override | |
| 8982 void visitChildren(AstVisitor visitor) { | |
| 8983 _hiddenNames.accept(visitor); | |
| 8984 } | |
| 8985 } | |
| 8986 | |
| 8987 /** | |
| 8988 * A node that represents an identifier. | |
| 8989 * | |
| 8990 * > identifier ::= | |
| 8991 * > [SimpleIdentifier] | |
| 8992 * > | [PrefixedIdentifier] | |
| 8993 */ | |
| 8994 abstract class Identifier extends Expression { | |
| 8995 /** | |
| 8996 * Return the best element available for this operator. If resolution was able | |
| 8997 * to find a better element based on type propagation, that element will be | |
| 8998 * returned. Otherwise, the element found using the result of static analysis | |
| 8999 * will be returned. If resolution has not been performed, then `null` will be | |
| 9000 * returned. | |
| 9001 */ | |
| 9002 Element get bestElement; | |
| 9003 | |
| 9004 @override | |
| 9005 bool get isAssignable => true; | |
| 9006 | |
| 9007 /** | |
| 9008 * Return the lexical representation of the identifier. | |
| 9009 */ | |
| 9010 String get name; | |
| 9011 | |
| 9012 /** | |
| 9013 * Return the element associated with this identifier based on propagated type | |
| 9014 * information, or `null` if the AST structure has not been resolved or if | |
| 9015 * this identifier could not be resolved. One example of the latter case is an | |
| 9016 * identifier that is not defined within the scope in which it appears. | |
| 9017 */ | |
| 9018 Element get propagatedElement; | |
| 9019 | |
| 9020 /** | |
| 9021 * Return the element associated with this identifier based on static type | |
| 9022 * information, or `null` if the AST structure has not been resolved or if | |
| 9023 * this identifier could not be resolved. One example of the latter case is an | |
| 9024 * identifier that is not defined within the scope in which it appears | |
| 9025 */ | |
| 9026 Element get staticElement; | |
| 9027 | |
| 9028 /** | |
| 9029 * Return `true` if the given [name] is visible only within the library in | |
| 9030 * which it is declared. | |
| 9031 */ | |
| 9032 static bool isPrivateName(String name) => | |
| 9033 StringUtilities.startsWithChar(name, 0x5F); | |
| 9034 } | |
| 9035 | |
| 9036 /** | |
| 9037 * An if statement. | |
| 9038 * | |
| 9039 * > ifStatement ::= | |
| 9040 * > 'if' '(' [Expression] ')' [Statement] ('else' [Statement])? | |
| 9041 */ | |
| 9042 class IfStatement extends Statement { | |
| 9043 /** | |
| 9044 * The token representing the 'if' keyword. | |
| 9045 */ | |
| 9046 Token ifKeyword; | |
| 9047 | |
| 9048 /** | |
| 9049 * The left parenthesis. | |
| 9050 */ | |
| 9051 Token leftParenthesis; | |
| 9052 | |
| 9053 /** | |
| 9054 * The condition used to determine which of the statements is executed next. | |
| 9055 */ | |
| 9056 Expression _condition; | |
| 9057 | |
| 9058 /** | |
| 9059 * The right parenthesis. | |
| 9060 */ | |
| 9061 Token rightParenthesis; | |
| 9062 | |
| 9063 /** | |
| 9064 * The statement that is executed if the condition evaluates to `true`. | |
| 9065 */ | |
| 9066 Statement _thenStatement; | |
| 9067 | |
| 9068 /** | |
| 9069 * The token representing the 'else' keyword, or `null` if there is no else | |
| 9070 * statement. | |
| 9071 */ | |
| 9072 Token elseKeyword; | |
| 9073 | |
| 9074 /** | |
| 9075 * The statement that is executed if the condition evaluates to `false`, or | |
| 9076 * `null` if there is no else statement. | |
| 9077 */ | |
| 9078 Statement _elseStatement; | |
| 9079 | |
| 9080 /** | |
| 9081 * Initialize a newly created if statement. The [elseKeyword] and | |
| 9082 * [elseStatement] can be `null` if there is no else clause. | |
| 9083 */ | |
| 9084 IfStatement(this.ifKeyword, this.leftParenthesis, Expression condition, | |
| 9085 this.rightParenthesis, Statement thenStatement, this.elseKeyword, | |
| 9086 Statement elseStatement) { | |
| 9087 _condition = _becomeParentOf(condition); | |
| 9088 _thenStatement = _becomeParentOf(thenStatement); | |
| 9089 _elseStatement = _becomeParentOf(elseStatement); | |
| 9090 } | |
| 9091 | |
| 9092 @override | |
| 9093 Token get beginToken => ifKeyword; | |
| 9094 | |
| 9095 @override | |
| 9096 Iterable get childEntities => new ChildEntities() | |
| 9097 ..add(ifKeyword) | |
| 9098 ..add(leftParenthesis) | |
| 9099 ..add(_condition) | |
| 9100 ..add(rightParenthesis) | |
| 9101 ..add(_thenStatement) | |
| 9102 ..add(elseKeyword) | |
| 9103 ..add(_elseStatement); | |
| 9104 | |
| 9105 /** | |
| 9106 * Return the condition used to determine which of the statements is executed | |
| 9107 * next. | |
| 9108 */ | |
| 9109 Expression get condition => _condition; | |
| 9110 | |
| 9111 /** | |
| 9112 * Set the condition used to determine which of the statements is executed | |
| 9113 * next to the given [expression]. | |
| 9114 */ | |
| 9115 void set condition(Expression expression) { | |
| 9116 _condition = _becomeParentOf(expression); | |
| 9117 } | |
| 9118 | |
| 9119 /** | |
| 9120 * Return the statement that is executed if the condition evaluates to | |
| 9121 * `false`, or `null` if there is no else statement. | |
| 9122 */ | |
| 9123 Statement get elseStatement => _elseStatement; | |
| 9124 | |
| 9125 /** | |
| 9126 * Set the statement that is executed if the condition evaluates to `false` | |
| 9127 * to the given [statement]. | |
| 9128 */ | |
| 9129 void set elseStatement(Statement statement) { | |
| 9130 _elseStatement = _becomeParentOf(statement); | |
| 9131 } | |
| 9132 | |
| 9133 @override | |
| 9134 Token get endToken { | |
| 9135 if (_elseStatement != null) { | |
| 9136 return _elseStatement.endToken; | |
| 9137 } | |
| 9138 return _thenStatement.endToken; | |
| 9139 } | |
| 9140 | |
| 9141 /** | |
| 9142 * Return the statement that is executed if the condition evaluates to `true`. | |
| 9143 */ | |
| 9144 Statement get thenStatement => _thenStatement; | |
| 9145 | |
| 9146 /** | |
| 9147 * Set the statement that is executed if the condition evaluates to `true` to | |
| 9148 * the given [statement]. | |
| 9149 */ | |
| 9150 void set thenStatement(Statement statement) { | |
| 9151 _thenStatement = _becomeParentOf(statement); | |
| 9152 } | |
| 9153 | |
| 9154 @override | |
| 9155 accept(AstVisitor visitor) => visitor.visitIfStatement(this); | |
| 9156 | |
| 9157 @override | |
| 9158 void visitChildren(AstVisitor visitor) { | |
| 9159 _safelyVisitChild(_condition, visitor); | |
| 9160 _safelyVisitChild(_thenStatement, visitor); | |
| 9161 _safelyVisitChild(_elseStatement, visitor); | |
| 9162 } | |
| 9163 } | |
| 9164 | |
| 9165 /** | |
| 9166 * The "implements" clause in an class declaration. | |
| 9167 * | |
| 9168 * > implementsClause ::= | |
| 9169 * > 'implements' [TypeName] (',' [TypeName])* | |
| 9170 */ | |
| 9171 class ImplementsClause extends AstNode { | |
| 9172 /** | |
| 9173 * The token representing the 'implements' keyword. | |
| 9174 */ | |
| 9175 Token implementsKeyword; | |
| 9176 | |
| 9177 /** | |
| 9178 * The interfaces that are being implemented. | |
| 9179 */ | |
| 9180 NodeList<TypeName> _interfaces; | |
| 9181 | |
| 9182 /** | |
| 9183 * Initialize a newly created implements clause. | |
| 9184 */ | |
| 9185 ImplementsClause(this.implementsKeyword, List<TypeName> interfaces) { | |
| 9186 _interfaces = new NodeList<TypeName>(this, interfaces); | |
| 9187 } | |
| 9188 | |
| 9189 @override | |
| 9190 Token get beginToken => implementsKeyword; | |
| 9191 | |
| 9192 /** | |
| 9193 * TODO(paulberry): add commas. | |
| 9194 */ | |
| 9195 @override | |
| 9196 Iterable get childEntities => new ChildEntities() | |
| 9197 ..add(implementsKeyword) | |
| 9198 ..addAll(interfaces); | |
| 9199 | |
| 9200 @override | |
| 9201 Token get endToken => _interfaces.endToken; | |
| 9202 | |
| 9203 /** | |
| 9204 * Return the list of the interfaces that are being implemented. | |
| 9205 */ | |
| 9206 NodeList<TypeName> get interfaces => _interfaces; | |
| 9207 | |
| 9208 /** | |
| 9209 * Return the token representing the 'implements' keyword. | |
| 9210 */ | |
| 9211 @deprecated // Use "this.implementsKeyword" | |
| 9212 Token get keyword => implementsKeyword; | |
| 9213 | |
| 9214 /** | |
| 9215 * Set the token representing the 'implements' keyword to the given [token]. | |
| 9216 */ | |
| 9217 @deprecated // Use "this.implementsKeyword" | |
| 9218 set keyword(Token token) { | |
| 9219 implementsKeyword = token; | |
| 9220 } | |
| 9221 | |
| 9222 @override | |
| 9223 accept(AstVisitor visitor) => visitor.visitImplementsClause(this); | |
| 9224 | |
| 9225 @override | |
| 9226 void visitChildren(AstVisitor visitor) { | |
| 9227 _interfaces.accept(visitor); | |
| 9228 } | |
| 9229 } | |
| 9230 | |
| 9231 /** | |
| 9232 * An import directive. | |
| 9233 * | |
| 9234 * > importDirective ::= | |
| 9235 * > [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]*
';' | |
| 9236 * > | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combi
nator]* ';' | |
| 9237 */ | |
| 9238 class ImportDirective extends NamespaceDirective { | |
| 9239 static Comparator<ImportDirective> COMPARATOR = (ImportDirective import1, | |
| 9240 ImportDirective import2) { | |
| 9241 // | |
| 9242 // uri | |
| 9243 // | |
| 9244 StringLiteral uri1 = import1.uri; | |
| 9245 StringLiteral uri2 = import2.uri; | |
| 9246 String uriStr1 = uri1.stringValue; | |
| 9247 String uriStr2 = uri2.stringValue; | |
| 9248 if (uriStr1 != null || uriStr2 != null) { | |
| 9249 if (uriStr1 == null) { | |
| 9250 return -1; | |
| 9251 } else if (uriStr2 == null) { | |
| 9252 return 1; | |
| 9253 } else { | |
| 9254 int compare = uriStr1.compareTo(uriStr2); | |
| 9255 if (compare != 0) { | |
| 9256 return compare; | |
| 9257 } | |
| 9258 } | |
| 9259 } | |
| 9260 // | |
| 9261 // as | |
| 9262 // | |
| 9263 SimpleIdentifier prefix1 = import1.prefix; | |
| 9264 SimpleIdentifier prefix2 = import2.prefix; | |
| 9265 String prefixStr1 = prefix1 != null ? prefix1.name : null; | |
| 9266 String prefixStr2 = prefix2 != null ? prefix2.name : null; | |
| 9267 if (prefixStr1 != null || prefixStr2 != null) { | |
| 9268 if (prefixStr1 == null) { | |
| 9269 return -1; | |
| 9270 } else if (prefixStr2 == null) { | |
| 9271 return 1; | |
| 9272 } else { | |
| 9273 int compare = prefixStr1.compareTo(prefixStr2); | |
| 9274 if (compare != 0) { | |
| 9275 return compare; | |
| 9276 } | |
| 9277 } | |
| 9278 } | |
| 9279 // | |
| 9280 // hides and shows | |
| 9281 // | |
| 9282 NodeList<Combinator> combinators1 = import1.combinators; | |
| 9283 List<String> allHides1 = new List<String>(); | |
| 9284 List<String> allShows1 = new List<String>(); | |
| 9285 for (Combinator combinator in combinators1) { | |
| 9286 if (combinator is HideCombinator) { | |
| 9287 NodeList<SimpleIdentifier> hides = combinator.hiddenNames; | |
| 9288 for (SimpleIdentifier simpleIdentifier in hides) { | |
| 9289 allHides1.add(simpleIdentifier.name); | |
| 9290 } | |
| 9291 } else { | |
| 9292 NodeList<SimpleIdentifier> shows = | |
| 9293 (combinator as ShowCombinator).shownNames; | |
| 9294 for (SimpleIdentifier simpleIdentifier in shows) { | |
| 9295 allShows1.add(simpleIdentifier.name); | |
| 9296 } | |
| 9297 } | |
| 9298 } | |
| 9299 NodeList<Combinator> combinators2 = import2.combinators; | |
| 9300 List<String> allHides2 = new List<String>(); | |
| 9301 List<String> allShows2 = new List<String>(); | |
| 9302 for (Combinator combinator in combinators2) { | |
| 9303 if (combinator is HideCombinator) { | |
| 9304 NodeList<SimpleIdentifier> hides = combinator.hiddenNames; | |
| 9305 for (SimpleIdentifier simpleIdentifier in hides) { | |
| 9306 allHides2.add(simpleIdentifier.name); | |
| 9307 } | |
| 9308 } else { | |
| 9309 NodeList<SimpleIdentifier> shows = | |
| 9310 (combinator as ShowCombinator).shownNames; | |
| 9311 for (SimpleIdentifier simpleIdentifier in shows) { | |
| 9312 allShows2.add(simpleIdentifier.name); | |
| 9313 } | |
| 9314 } | |
| 9315 } | |
| 9316 // test lengths of combinator lists first | |
| 9317 if (allHides1.length != allHides2.length) { | |
| 9318 return allHides1.length - allHides2.length; | |
| 9319 } | |
| 9320 if (allShows1.length != allShows2.length) { | |
| 9321 return allShows1.length - allShows2.length; | |
| 9322 } | |
| 9323 // next ensure that the lists are equivalent | |
| 9324 if (!javaCollectionContainsAll(allHides1, allHides2)) { | |
| 9325 return -1; | |
| 9326 } | |
| 9327 if (!javaCollectionContainsAll(allShows1, allShows2)) { | |
| 9328 return -1; | |
| 9329 } | |
| 9330 return 0; | |
| 9331 }; | |
| 9332 | |
| 9333 /** | |
| 9334 * The token representing the 'deferred' keyword, or `null` if the imported is | |
| 9335 * not deferred. | |
| 9336 */ | |
| 9337 Token deferredKeyword; | |
| 9338 | |
| 9339 /** | |
| 9340 * The token representing the 'as' keyword, or `null` if the imported names ar
e | |
| 9341 * not prefixed. | |
| 9342 */ | |
| 9343 Token asKeyword; | |
| 9344 | |
| 9345 /** | |
| 9346 * The prefix to be used with the imported names, or `null` if the imported | |
| 9347 * names are not prefixed. | |
| 9348 */ | |
| 9349 SimpleIdentifier _prefix; | |
| 9350 | |
| 9351 /** | |
| 9352 * Initialize a newly created import directive. Either or both of the | |
| 9353 * [comment] and [metadata] can be `null` if the function does not have the | |
| 9354 * corresponding attribute. The [deferredKeyword] can be `null` if the import | |
| 9355 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import | |
| 9356 * does not specify a prefix. The list of [combinators] can be `null` if there | |
| 9357 * are no combinators. | |
| 9358 */ | |
| 9359 ImportDirective(Comment comment, List<Annotation> metadata, Token keyword, | |
| 9360 StringLiteral libraryUri, this.deferredKeyword, this.asKeyword, | |
| 9361 SimpleIdentifier prefix, List<Combinator> combinators, Token semicolon) | |
| 9362 : super(comment, metadata, keyword, libraryUri, combinators, semicolon) { | |
| 9363 _prefix = _becomeParentOf(prefix); | |
| 9364 } | |
| 9365 | |
| 9366 /** | |
| 9367 * The token representing the 'as' token, or `null` if the imported names are | |
| 9368 * not prefixed. | |
| 9369 */ | |
| 9370 @deprecated // Use "this.asKeyword" | |
| 9371 Token get asToken => asKeyword; | |
| 9372 | |
| 9373 /** | |
| 9374 * The token representing the 'as' token to the given token. | |
| 9375 */ | |
| 9376 @deprecated // Use "this.asKeyword" | |
| 9377 set asToken(Token token) { | |
| 9378 asKeyword = token; | |
| 9379 } | |
| 9380 | |
| 9381 @override | |
| 9382 Iterable get childEntities => super._childEntities | |
| 9383 ..add(_uri) | |
| 9384 ..add(deferredKeyword) | |
| 9385 ..add(asKeyword) | |
| 9386 ..add(_prefix) | |
| 9387 ..addAll(combinators) | |
| 9388 ..add(semicolon); | |
| 9389 | |
| 9390 /** | |
| 9391 * Return the token representing the 'deferred' token, or `null` if the | |
| 9392 * imported is not deferred. | |
| 9393 */ | |
| 9394 @deprecated // Use "this.deferredKeyword" | |
| 9395 Token get deferredToken => deferredKeyword; | |
| 9396 | |
| 9397 /** | |
| 9398 * Set the token representing the 'deferred' token to the given token. | |
| 9399 */ | |
| 9400 @deprecated // Use "this.deferredKeyword" | |
| 9401 set deferredToken(Token token) { | |
| 9402 deferredKeyword = token; | |
| 9403 } | |
| 9404 | |
| 9405 @override | |
| 9406 ImportElement get element => super.element as ImportElement; | |
| 9407 | |
| 9408 /** | |
| 9409 * Return the prefix to be used with the imported names, or `null` if the | |
| 9410 * imported names are not prefixed. | |
| 9411 */ | |
| 9412 SimpleIdentifier get prefix => _prefix; | |
| 9413 | |
| 9414 /** | |
| 9415 * Set the prefix to be used with the imported names to the given [identifier]
. | |
| 9416 */ | |
| 9417 void set prefix(SimpleIdentifier identifier) { | |
| 9418 _prefix = _becomeParentOf(identifier); | |
| 9419 } | |
| 9420 | |
| 9421 @override | |
| 9422 LibraryElement get uriElement { | |
| 9423 ImportElement element = this.element; | |
| 9424 if (element == null) { | |
| 9425 return null; | |
| 9426 } | |
| 9427 return element.importedLibrary; | |
| 9428 } | |
| 9429 | |
| 9430 @override | |
| 9431 accept(AstVisitor visitor) => visitor.visitImportDirective(this); | |
| 9432 | |
| 9433 @override | |
| 9434 void visitChildren(AstVisitor visitor) { | |
| 9435 super.visitChildren(visitor); | |
| 9436 _safelyVisitChild(_prefix, visitor); | |
| 9437 combinators.accept(visitor); | |
| 9438 } | |
| 9439 } | |
| 9440 | |
| 9441 /** | |
| 9442 * An object that will clone any AST structure that it visits. The cloner will | |
| 9443 * clone the structure, replacing the specified ASTNode with a new ASTNode, | |
| 9444 * mapping the old token stream to a new token stream, and preserving resolution | |
| 9445 * results. | |
| 9446 */ | |
| 9447 class IncrementalAstCloner implements AstVisitor<AstNode> { | |
| 9448 /** | |
| 9449 * The node to be replaced during the cloning process. | |
| 9450 */ | |
| 9451 final AstNode _oldNode; | |
| 9452 | |
| 9453 /** | |
| 9454 * The replacement node used during the cloning process. | |
| 9455 */ | |
| 9456 final AstNode _newNode; | |
| 9457 | |
| 9458 /** | |
| 9459 * A mapping of old tokens to new tokens used during the cloning process. | |
| 9460 */ | |
| 9461 final TokenMap _tokenMap; | |
| 9462 | |
| 9463 /** | |
| 9464 * Construct a new instance that will replace the [oldNode] with the [newNode] | |
| 9465 * in the process of cloning an existing AST structure. The [tokenMap] is a | |
| 9466 * mapping of old tokens to new tokens. | |
| 9467 */ | |
| 9468 IncrementalAstCloner(this._oldNode, this._newNode, this._tokenMap); | |
| 9469 | |
| 9470 @override | |
| 9471 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) => | |
| 9472 new AdjacentStrings(_cloneNodeList(node.strings)); | |
| 9473 | |
| 9474 @override | |
| 9475 Annotation visitAnnotation(Annotation node) { | |
| 9476 Annotation copy = new Annotation(_mapToken(node.atSign), | |
| 9477 _cloneNode(node.name), _mapToken(node.period), | |
| 9478 _cloneNode(node.constructorName), _cloneNode(node.arguments)); | |
| 9479 copy.element = node.element; | |
| 9480 return copy; | |
| 9481 } | |
| 9482 | |
| 9483 @override | |
| 9484 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList( | |
| 9485 _mapToken(node.leftParenthesis), _cloneNodeList(node.arguments), | |
| 9486 _mapToken(node.rightParenthesis)); | |
| 9487 | |
| 9488 @override | |
| 9489 AsExpression visitAsExpression(AsExpression node) { | |
| 9490 AsExpression copy = new AsExpression(_cloneNode(node.expression), | |
| 9491 _mapToken(node.asOperator), _cloneNode(node.type)); | |
| 9492 copy.propagatedType = node.propagatedType; | |
| 9493 copy.staticType = node.staticType; | |
| 9494 return copy; | |
| 9495 } | |
| 9496 | |
| 9497 @override | |
| 9498 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement( | |
| 9499 _mapToken(node.assertKeyword), _mapToken(node.leftParenthesis), | |
| 9500 _cloneNode(node.condition), _mapToken(node.rightParenthesis), | |
| 9501 _mapToken(node.semicolon)); | |
| 9502 | |
| 9503 @override | |
| 9504 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) { | |
| 9505 AssignmentExpression copy = new AssignmentExpression( | |
| 9506 _cloneNode(node.leftHandSide), _mapToken(node.operator), | |
| 9507 _cloneNode(node.rightHandSide)); | |
| 9508 copy.propagatedElement = node.propagatedElement; | |
| 9509 copy.propagatedType = node.propagatedType; | |
| 9510 copy.staticElement = node.staticElement; | |
| 9511 copy.staticType = node.staticType; | |
| 9512 return copy; | |
| 9513 } | |
| 9514 | |
| 9515 @override | |
| 9516 AwaitExpression visitAwaitExpression(AwaitExpression node) => | |
| 9517 new AwaitExpression( | |
| 9518 _mapToken(node.awaitKeyword), _cloneNode(node.expression)); | |
| 9519 | |
| 9520 @override | |
| 9521 BinaryExpression visitBinaryExpression(BinaryExpression node) { | |
| 9522 BinaryExpression copy = new BinaryExpression(_cloneNode(node.leftOperand), | |
| 9523 _mapToken(node.operator), _cloneNode(node.rightOperand)); | |
| 9524 copy.propagatedElement = node.propagatedElement; | |
| 9525 copy.propagatedType = node.propagatedType; | |
| 9526 copy.staticElement = node.staticElement; | |
| 9527 copy.staticType = node.staticType; | |
| 9528 return copy; | |
| 9529 } | |
| 9530 | |
| 9531 @override | |
| 9532 Block visitBlock(Block node) => new Block(_mapToken(node.leftBracket), | |
| 9533 _cloneNodeList(node.statements), _mapToken(node.rightBracket)); | |
| 9534 | |
| 9535 @override | |
| 9536 BlockFunctionBody visitBlockFunctionBody( | |
| 9537 BlockFunctionBody node) => new BlockFunctionBody( | |
| 9538 _mapToken(node.keyword), _mapToken(node.star), _cloneNode(node.block)); | |
| 9539 | |
| 9540 @override | |
| 9541 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) { | |
| 9542 BooleanLiteral copy = | |
| 9543 new BooleanLiteral(_mapToken(node.literal), node.value); | |
| 9544 copy.propagatedType = node.propagatedType; | |
| 9545 copy.staticType = node.staticType; | |
| 9546 return copy; | |
| 9547 } | |
| 9548 | |
| 9549 @override | |
| 9550 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement( | |
| 9551 _mapToken(node.breakKeyword), _cloneNode(node.label), | |
| 9552 _mapToken(node.semicolon)); | |
| 9553 | |
| 9554 @override | |
| 9555 CascadeExpression visitCascadeExpression(CascadeExpression node) { | |
| 9556 CascadeExpression copy = new CascadeExpression( | |
| 9557 _cloneNode(node.target), _cloneNodeList(node.cascadeSections)); | |
| 9558 copy.propagatedType = node.propagatedType; | |
| 9559 copy.staticType = node.staticType; | |
| 9560 return copy; | |
| 9561 } | |
| 9562 | |
| 9563 @override | |
| 9564 CatchClause visitCatchClause(CatchClause node) => new CatchClause( | |
| 9565 _mapToken(node.onKeyword), _cloneNode(node.exceptionType), | |
| 9566 _mapToken(node.catchKeyword), _mapToken(node.leftParenthesis), | |
| 9567 _cloneNode(node.exceptionParameter), _mapToken(node.comma), | |
| 9568 _cloneNode(node.stackTraceParameter), _mapToken(node.rightParenthesis), | |
| 9569 _cloneNode(node.body)); | |
| 9570 | |
| 9571 @override | |
| 9572 ClassDeclaration visitClassDeclaration(ClassDeclaration node) { | |
| 9573 ClassDeclaration copy = new ClassDeclaration( | |
| 9574 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9575 _mapToken(node.abstractKeyword), _mapToken(node.classKeyword), | |
| 9576 _cloneNode(node.name), _cloneNode(node.typeParameters), | |
| 9577 _cloneNode(node.extendsClause), _cloneNode(node.withClause), | |
| 9578 _cloneNode(node.implementsClause), _mapToken(node.leftBracket), | |
| 9579 _cloneNodeList(node.members), _mapToken(node.rightBracket)); | |
| 9580 copy.nativeClause = _cloneNode(node.nativeClause); | |
| 9581 return copy; | |
| 9582 } | |
| 9583 | |
| 9584 @override | |
| 9585 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias( | |
| 9586 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9587 _mapToken(node.typedefKeyword), _cloneNode(node.name), | |
| 9588 _cloneNode(node.typeParameters), _mapToken(node.equals), | |
| 9589 _mapToken(node.abstractKeyword), _cloneNode(node.superclass), | |
| 9590 _cloneNode(node.withClause), _cloneNode(node.implementsClause), | |
| 9591 _mapToken(node.semicolon)); | |
| 9592 | |
| 9593 @override | |
| 9594 Comment visitComment(Comment node) { | |
| 9595 if (node.isDocumentation) { | |
| 9596 return Comment.createDocumentationCommentWithReferences( | |
| 9597 _mapTokens(node.tokens), _cloneNodeList(node.references)); | |
| 9598 } else if (node.isBlock) { | |
| 9599 return Comment.createBlockComment(_mapTokens(node.tokens)); | |
| 9600 } | |
| 9601 return Comment.createEndOfLineComment(_mapTokens(node.tokens)); | |
| 9602 } | |
| 9603 | |
| 9604 @override | |
| 9605 CommentReference visitCommentReference(CommentReference node) => | |
| 9606 new CommentReference( | |
| 9607 _mapToken(node.newKeyword), _cloneNode(node.identifier)); | |
| 9608 | |
| 9609 @override | |
| 9610 CompilationUnit visitCompilationUnit(CompilationUnit node) { | |
| 9611 CompilationUnit copy = new CompilationUnit(_mapToken(node.beginToken), | |
| 9612 _cloneNode(node.scriptTag), _cloneNodeList(node.directives), | |
| 9613 _cloneNodeList(node.declarations), _mapToken(node.endToken)); | |
| 9614 copy.lineInfo = node.lineInfo; | |
| 9615 copy.element = node.element; | |
| 9616 return copy; | |
| 9617 } | |
| 9618 | |
| 9619 @override | |
| 9620 ConditionalExpression visitConditionalExpression(ConditionalExpression node) { | |
| 9621 ConditionalExpression copy = new ConditionalExpression( | |
| 9622 _cloneNode(node.condition), _mapToken(node.question), | |
| 9623 _cloneNode(node.thenExpression), _mapToken(node.colon), | |
| 9624 _cloneNode(node.elseExpression)); | |
| 9625 copy.propagatedType = node.propagatedType; | |
| 9626 copy.staticType = node.staticType; | |
| 9627 return copy; | |
| 9628 } | |
| 9629 | |
| 9630 @override | |
| 9631 ConstructorDeclaration visitConstructorDeclaration( | |
| 9632 ConstructorDeclaration node) { | |
| 9633 ConstructorDeclaration copy = new ConstructorDeclaration( | |
| 9634 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9635 _mapToken(node.externalKeyword), _mapToken(node.constKeyword), | |
| 9636 _mapToken(node.factoryKeyword), _cloneNode(node.returnType), | |
| 9637 _mapToken(node.period), _cloneNode(node.name), | |
| 9638 _cloneNode(node.parameters), _mapToken(node.separator), | |
| 9639 _cloneNodeList(node.initializers), | |
| 9640 _cloneNode(node.redirectedConstructor), _cloneNode(node.body)); | |
| 9641 copy.element = node.element; | |
| 9642 return copy; | |
| 9643 } | |
| 9644 | |
| 9645 @override | |
| 9646 ConstructorFieldInitializer visitConstructorFieldInitializer( | |
| 9647 ConstructorFieldInitializer node) => new ConstructorFieldInitializer( | |
| 9648 _mapToken(node.thisKeyword), _mapToken(node.period), | |
| 9649 _cloneNode(node.fieldName), _mapToken(node.equals), | |
| 9650 _cloneNode(node.expression)); | |
| 9651 | |
| 9652 @override | |
| 9653 ConstructorName visitConstructorName(ConstructorName node) { | |
| 9654 ConstructorName copy = new ConstructorName( | |
| 9655 _cloneNode(node.type), _mapToken(node.period), _cloneNode(node.name)); | |
| 9656 copy.staticElement = node.staticElement; | |
| 9657 return copy; | |
| 9658 } | |
| 9659 | |
| 9660 @override | |
| 9661 ContinueStatement visitContinueStatement(ContinueStatement node) => | |
| 9662 new ContinueStatement(_mapToken(node.continueKeyword), | |
| 9663 _cloneNode(node.label), _mapToken(node.semicolon)); | |
| 9664 | |
| 9665 @override | |
| 9666 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) => | |
| 9667 new DeclaredIdentifier(_cloneNode(node.documentationComment), | |
| 9668 _cloneNodeList(node.metadata), _mapToken(node.keyword), | |
| 9669 _cloneNode(node.type), _cloneNode(node.identifier)); | |
| 9670 | |
| 9671 @override | |
| 9672 DefaultFormalParameter visitDefaultFormalParameter( | |
| 9673 DefaultFormalParameter node) => new DefaultFormalParameter( | |
| 9674 _cloneNode(node.parameter), node.kind, _mapToken(node.separator), | |
| 9675 _cloneNode(node.defaultValue)); | |
| 9676 | |
| 9677 @override | |
| 9678 DoStatement visitDoStatement(DoStatement node) => new DoStatement( | |
| 9679 _mapToken(node.doKeyword), _cloneNode(node.body), | |
| 9680 _mapToken(node.whileKeyword), _mapToken(node.leftParenthesis), | |
| 9681 _cloneNode(node.condition), _mapToken(node.rightParenthesis), | |
| 9682 _mapToken(node.semicolon)); | |
| 9683 | |
| 9684 @override | |
| 9685 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) { | |
| 9686 DoubleLiteral copy = new DoubleLiteral(_mapToken(node.literal), node.value); | |
| 9687 copy.propagatedType = node.propagatedType; | |
| 9688 copy.staticType = node.staticType; | |
| 9689 return copy; | |
| 9690 } | |
| 9691 | |
| 9692 @override | |
| 9693 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) => | |
| 9694 new EmptyFunctionBody(_mapToken(node.semicolon)); | |
| 9695 | |
| 9696 @override | |
| 9697 EmptyStatement visitEmptyStatement(EmptyStatement node) => | |
| 9698 new EmptyStatement(_mapToken(node.semicolon)); | |
| 9699 | |
| 9700 @override | |
| 9701 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) => | |
| 9702 new EnumConstantDeclaration(_cloneNode(node.documentationComment), | |
| 9703 _cloneNodeList(node.metadata), _cloneNode(node.name)); | |
| 9704 | |
| 9705 @override | |
| 9706 AstNode visitEnumDeclaration(EnumDeclaration node) => new EnumDeclaration( | |
| 9707 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9708 _mapToken(node.enumKeyword), _cloneNode(node.name), | |
| 9709 _mapToken(node.leftBracket), _cloneNodeList(node.constants), | |
| 9710 _mapToken(node.rightBracket)); | |
| 9711 | |
| 9712 @override | |
| 9713 ExportDirective visitExportDirective(ExportDirective node) { | |
| 9714 ExportDirective copy = new ExportDirective( | |
| 9715 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9716 _mapToken(node.keyword), _cloneNode(node.uri), | |
| 9717 _cloneNodeList(node.combinators), _mapToken(node.semicolon)); | |
| 9718 copy.element = node.element; | |
| 9719 return copy; | |
| 9720 } | |
| 9721 | |
| 9722 @override | |
| 9723 ExpressionFunctionBody visitExpressionFunctionBody( | |
| 9724 ExpressionFunctionBody node) => new ExpressionFunctionBody( | |
| 9725 _mapToken(node.keyword), _mapToken(node.functionDefinition), | |
| 9726 _cloneNode(node.expression), _mapToken(node.semicolon)); | |
| 9727 | |
| 9728 @override | |
| 9729 ExpressionStatement visitExpressionStatement(ExpressionStatement node) => | |
| 9730 new ExpressionStatement( | |
| 9731 _cloneNode(node.expression), _mapToken(node.semicolon)); | |
| 9732 | |
| 9733 @override | |
| 9734 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause( | |
| 9735 _mapToken(node.extendsKeyword), _cloneNode(node.superclass)); | |
| 9736 | |
| 9737 @override | |
| 9738 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) => | |
| 9739 new FieldDeclaration(_cloneNode(node.documentationComment), | |
| 9740 _cloneNodeList(node.metadata), _mapToken(node.staticKeyword), | |
| 9741 _cloneNode(node.fields), _mapToken(node.semicolon)); | |
| 9742 | |
| 9743 @override | |
| 9744 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) => | |
| 9745 new FieldFormalParameter(_cloneNode(node.documentationComment), | |
| 9746 _cloneNodeList(node.metadata), _mapToken(node.keyword), | |
| 9747 _cloneNode(node.type), _mapToken(node.thisKeyword), | |
| 9748 _mapToken(node.period), _cloneNode(node.identifier), | |
| 9749 _cloneNode(node.typeParameters), _cloneNode(node.parameters)); | |
| 9750 | |
| 9751 @override | |
| 9752 ForEachStatement visitForEachStatement(ForEachStatement node) { | |
| 9753 DeclaredIdentifier loopVariable = node.loopVariable; | |
| 9754 if (loopVariable == null) { | |
| 9755 return new ForEachStatement.withReference(_mapToken(node.awaitKeyword), | |
| 9756 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis), | |
| 9757 _cloneNode(node.identifier), _mapToken(node.inKeyword), | |
| 9758 _cloneNode(node.iterable), _mapToken(node.rightParenthesis), | |
| 9759 _cloneNode(node.body)); | |
| 9760 } | |
| 9761 return new ForEachStatement.withDeclaration(_mapToken(node.awaitKeyword), | |
| 9762 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis), | |
| 9763 _cloneNode(loopVariable), _mapToken(node.inKeyword), | |
| 9764 _cloneNode(node.iterable), _mapToken(node.rightParenthesis), | |
| 9765 _cloneNode(node.body)); | |
| 9766 } | |
| 9767 | |
| 9768 @override | |
| 9769 FormalParameterList visitFormalParameterList(FormalParameterList node) => | |
| 9770 new FormalParameterList(_mapToken(node.leftParenthesis), | |
| 9771 _cloneNodeList(node.parameters), _mapToken(node.leftDelimiter), | |
| 9772 _mapToken(node.rightDelimiter), _mapToken(node.rightParenthesis)); | |
| 9773 | |
| 9774 @override | |
| 9775 ForStatement visitForStatement(ForStatement node) => new ForStatement( | |
| 9776 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis), | |
| 9777 _cloneNode(node.variables), _cloneNode(node.initialization), | |
| 9778 _mapToken(node.leftSeparator), _cloneNode(node.condition), | |
| 9779 _mapToken(node.rightSeparator), _cloneNodeList(node.updaters), | |
| 9780 _mapToken(node.rightParenthesis), _cloneNode(node.body)); | |
| 9781 | |
| 9782 @override | |
| 9783 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) => | |
| 9784 new FunctionDeclaration(_cloneNode(node.documentationComment), | |
| 9785 _cloneNodeList(node.metadata), _mapToken(node.externalKeyword), | |
| 9786 _cloneNode(node.returnType), _mapToken(node.propertyKeyword), | |
| 9787 _cloneNode(node.name), _cloneNode(node.functionExpression)); | |
| 9788 | |
| 9789 @override | |
| 9790 FunctionDeclarationStatement visitFunctionDeclarationStatement( | |
| 9791 FunctionDeclarationStatement node) => | |
| 9792 new FunctionDeclarationStatement(_cloneNode(node.functionDeclaration)); | |
| 9793 | |
| 9794 @override | |
| 9795 FunctionExpression visitFunctionExpression(FunctionExpression node) { | |
| 9796 FunctionExpression copy = new FunctionExpression( | |
| 9797 _cloneNode(node.typeParameters), _cloneNode(node.parameters), | |
| 9798 _cloneNode(node.body)); | |
| 9799 copy.element = node.element; | |
| 9800 copy.propagatedType = node.propagatedType; | |
| 9801 copy.staticType = node.staticType; | |
| 9802 return copy; | |
| 9803 } | |
| 9804 | |
| 9805 @override | |
| 9806 FunctionExpressionInvocation visitFunctionExpressionInvocation( | |
| 9807 FunctionExpressionInvocation node) { | |
| 9808 FunctionExpressionInvocation copy = new FunctionExpressionInvocation( | |
| 9809 _cloneNode(node.function), _cloneNode(node.typeArguments), | |
| 9810 _cloneNode(node.argumentList)); | |
| 9811 copy.propagatedElement = node.propagatedElement; | |
| 9812 copy.propagatedType = node.propagatedType; | |
| 9813 copy.staticElement = node.staticElement; | |
| 9814 copy.staticType = node.staticType; | |
| 9815 return copy; | |
| 9816 } | |
| 9817 | |
| 9818 @override | |
| 9819 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) => | |
| 9820 new FunctionTypeAlias(_cloneNode(node.documentationComment), | |
| 9821 _cloneNodeList(node.metadata), _mapToken(node.typedefKeyword), | |
| 9822 _cloneNode(node.returnType), _cloneNode(node.name), | |
| 9823 _cloneNode(node.typeParameters), _cloneNode(node.parameters), | |
| 9824 _mapToken(node.semicolon)); | |
| 9825 | |
| 9826 @override | |
| 9827 FunctionTypedFormalParameter visitFunctionTypedFormalParameter( | |
| 9828 FunctionTypedFormalParameter node) => new FunctionTypedFormalParameter( | |
| 9829 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 9830 _cloneNode(node.returnType), _cloneNode(node.identifier), | |
| 9831 _cloneNode(node.typeParameters), _cloneNode(node.parameters)); | |
| 9832 | |
| 9833 @override | |
| 9834 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator( | |
| 9835 _mapToken(node.keyword), _cloneNodeList(node.hiddenNames)); | |
| 9836 | |
| 9837 @override | |
| 9838 IfStatement visitIfStatement(IfStatement node) => new IfStatement( | |
| 9839 _mapToken(node.ifKeyword), _mapToken(node.leftParenthesis), | |
| 9840 _cloneNode(node.condition), _mapToken(node.rightParenthesis), | |
| 9841 _cloneNode(node.thenStatement), _mapToken(node.elseKeyword), | |
| 9842 _cloneNode(node.elseStatement)); | |
| 9843 | |
| 9844 @override | |
| 9845 ImplementsClause visitImplementsClause(ImplementsClause node) => | |
| 9846 new ImplementsClause( | |
| 9847 _mapToken(node.implementsKeyword), _cloneNodeList(node.interfaces)); | |
| 9848 | |
| 9849 @override | |
| 9850 ImportDirective visitImportDirective(ImportDirective node) => | |
| 9851 new ImportDirective(_cloneNode(node.documentationComment), | |
| 9852 _cloneNodeList(node.metadata), _mapToken(node.keyword), | |
| 9853 _cloneNode(node.uri), _mapToken(node.deferredKeyword), | |
| 9854 _mapToken(node.asKeyword), _cloneNode(node.prefix), | |
| 9855 _cloneNodeList(node.combinators), _mapToken(node.semicolon)); | |
| 9856 | |
| 9857 @override | |
| 9858 IndexExpression visitIndexExpression(IndexExpression node) { | |
| 9859 Token period = _mapToken(node.period); | |
| 9860 IndexExpression copy; | |
| 9861 if (period == null) { | |
| 9862 copy = new IndexExpression.forTarget(_cloneNode(node.target), | |
| 9863 _mapToken(node.leftBracket), _cloneNode(node.index), | |
| 9864 _mapToken(node.rightBracket)); | |
| 9865 } else { | |
| 9866 copy = new IndexExpression.forCascade(period, _mapToken(node.leftBracket), | |
| 9867 _cloneNode(node.index), _mapToken(node.rightBracket)); | |
| 9868 } | |
| 9869 copy.auxiliaryElements = node.auxiliaryElements; | |
| 9870 copy.propagatedElement = node.propagatedElement; | |
| 9871 copy.propagatedType = node.propagatedType; | |
| 9872 copy.staticElement = node.staticElement; | |
| 9873 copy.staticType = node.staticType; | |
| 9874 return copy; | |
| 9875 } | |
| 9876 | |
| 9877 @override | |
| 9878 InstanceCreationExpression visitInstanceCreationExpression( | |
| 9879 InstanceCreationExpression node) { | |
| 9880 InstanceCreationExpression copy = new InstanceCreationExpression( | |
| 9881 _mapToken(node.keyword), _cloneNode(node.constructorName), | |
| 9882 _cloneNode(node.argumentList)); | |
| 9883 copy.propagatedType = node.propagatedType; | |
| 9884 copy.staticElement = node.staticElement; | |
| 9885 copy.staticType = node.staticType; | |
| 9886 return copy; | |
| 9887 } | |
| 9888 | |
| 9889 @override | |
| 9890 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) { | |
| 9891 IntegerLiteral copy = | |
| 9892 new IntegerLiteral(_mapToken(node.literal), node.value); | |
| 9893 copy.propagatedType = node.propagatedType; | |
| 9894 copy.staticType = node.staticType; | |
| 9895 return copy; | |
| 9896 } | |
| 9897 | |
| 9898 @override | |
| 9899 InterpolationExpression visitInterpolationExpression( | |
| 9900 InterpolationExpression node) => new InterpolationExpression( | |
| 9901 _mapToken(node.leftBracket), _cloneNode(node.expression), | |
| 9902 _mapToken(node.rightBracket)); | |
| 9903 | |
| 9904 @override | |
| 9905 InterpolationString visitInterpolationString(InterpolationString node) => | |
| 9906 new InterpolationString(_mapToken(node.contents), node.value); | |
| 9907 | |
| 9908 @override | |
| 9909 IsExpression visitIsExpression(IsExpression node) { | |
| 9910 IsExpression copy = new IsExpression(_cloneNode(node.expression), | |
| 9911 _mapToken(node.isOperator), _mapToken(node.notOperator), | |
| 9912 _cloneNode(node.type)); | |
| 9913 copy.propagatedType = node.propagatedType; | |
| 9914 copy.staticType = node.staticType; | |
| 9915 return copy; | |
| 9916 } | |
| 9917 | |
| 9918 @override | |
| 9919 Label visitLabel(Label node) => | |
| 9920 new Label(_cloneNode(node.label), _mapToken(node.colon)); | |
| 9921 | |
| 9922 @override | |
| 9923 LabeledStatement visitLabeledStatement(LabeledStatement node) => | |
| 9924 new LabeledStatement( | |
| 9925 _cloneNodeList(node.labels), _cloneNode(node.statement)); | |
| 9926 | |
| 9927 @override | |
| 9928 LibraryDirective visitLibraryDirective(LibraryDirective node) => | |
| 9929 new LibraryDirective(_cloneNode(node.documentationComment), | |
| 9930 _cloneNodeList(node.metadata), _mapToken(node.libraryKeyword), | |
| 9931 _cloneNode(node.name), _mapToken(node.semicolon)); | |
| 9932 | |
| 9933 @override | |
| 9934 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) { | |
| 9935 LibraryIdentifier copy = | |
| 9936 new LibraryIdentifier(_cloneNodeList(node.components)); | |
| 9937 copy.propagatedType = node.propagatedType; | |
| 9938 copy.staticType = node.staticType; | |
| 9939 return copy; | |
| 9940 } | |
| 9941 | |
| 9942 @override | |
| 9943 ListLiteral visitListLiteral(ListLiteral node) { | |
| 9944 ListLiteral copy = new ListLiteral(_mapToken(node.constKeyword), | |
| 9945 _cloneNode(node.typeArguments), _mapToken(node.leftBracket), | |
| 9946 _cloneNodeList(node.elements), _mapToken(node.rightBracket)); | |
| 9947 copy.propagatedType = node.propagatedType; | |
| 9948 copy.staticType = node.staticType; | |
| 9949 return copy; | |
| 9950 } | |
| 9951 | |
| 9952 @override | |
| 9953 MapLiteral visitMapLiteral(MapLiteral node) { | |
| 9954 MapLiteral copy = new MapLiteral(_mapToken(node.constKeyword), | |
| 9955 _cloneNode(node.typeArguments), _mapToken(node.leftBracket), | |
| 9956 _cloneNodeList(node.entries), _mapToken(node.rightBracket)); | |
| 9957 copy.propagatedType = node.propagatedType; | |
| 9958 copy.staticType = node.staticType; | |
| 9959 return copy; | |
| 9960 } | |
| 9961 | |
| 9962 @override | |
| 9963 MapLiteralEntry visitMapLiteralEntry( | |
| 9964 MapLiteralEntry node) => new MapLiteralEntry( | |
| 9965 _cloneNode(node.key), _mapToken(node.separator), _cloneNode(node.value)); | |
| 9966 | |
| 9967 @override | |
| 9968 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) => | |
| 9969 new MethodDeclaration(_cloneNode(node.documentationComment), | |
| 9970 _cloneNodeList(node.metadata), _mapToken(node.externalKeyword), | |
| 9971 _mapToken(node.modifierKeyword), _cloneNode(node.returnType), | |
| 9972 _mapToken(node.propertyKeyword), _mapToken(node.operatorKeyword), | |
| 9973 _cloneNode(node.name), _cloneNode(node._typeParameters), | |
| 9974 _cloneNode(node.parameters), _cloneNode(node.body)); | |
| 9975 | |
| 9976 @override | |
| 9977 MethodInvocation visitMethodInvocation(MethodInvocation node) { | |
| 9978 MethodInvocation copy = new MethodInvocation(_cloneNode(node.target), | |
| 9979 _mapToken(node.operator), _cloneNode(node.methodName), | |
| 9980 _cloneNode(node.typeArguments), _cloneNode(node.argumentList)); | |
| 9981 copy.propagatedType = node.propagatedType; | |
| 9982 copy.staticType = node.staticType; | |
| 9983 return copy; | |
| 9984 } | |
| 9985 | |
| 9986 @override | |
| 9987 NamedExpression visitNamedExpression(NamedExpression node) { | |
| 9988 NamedExpression copy = | |
| 9989 new NamedExpression(_cloneNode(node.name), _cloneNode(node.expression)); | |
| 9990 copy.propagatedType = node.propagatedType; | |
| 9991 copy.staticType = node.staticType; | |
| 9992 return copy; | |
| 9993 } | |
| 9994 | |
| 9995 @override | |
| 9996 AstNode visitNativeClause(NativeClause node) => | |
| 9997 new NativeClause(_mapToken(node.nativeKeyword), _cloneNode(node.name)); | |
| 9998 | |
| 9999 @override | |
| 10000 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) => | |
| 10001 new NativeFunctionBody(_mapToken(node.nativeKeyword), | |
| 10002 _cloneNode(node.stringLiteral), _mapToken(node.semicolon)); | |
| 10003 | |
| 10004 @override | |
| 10005 NullLiteral visitNullLiteral(NullLiteral node) { | |
| 10006 NullLiteral copy = new NullLiteral(_mapToken(node.literal)); | |
| 10007 copy.propagatedType = node.propagatedType; | |
| 10008 copy.staticType = node.staticType; | |
| 10009 return copy; | |
| 10010 } | |
| 10011 | |
| 10012 @override | |
| 10013 ParenthesizedExpression visitParenthesizedExpression( | |
| 10014 ParenthesizedExpression node) { | |
| 10015 ParenthesizedExpression copy = new ParenthesizedExpression( | |
| 10016 _mapToken(node.leftParenthesis), _cloneNode(node.expression), | |
| 10017 _mapToken(node.rightParenthesis)); | |
| 10018 copy.propagatedType = node.propagatedType; | |
| 10019 copy.staticType = node.staticType; | |
| 10020 return copy; | |
| 10021 } | |
| 10022 | |
| 10023 @override | |
| 10024 PartDirective visitPartDirective(PartDirective node) { | |
| 10025 PartDirective copy = new PartDirective( | |
| 10026 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 10027 _mapToken(node.partKeyword), _cloneNode(node.uri), | |
| 10028 _mapToken(node.semicolon)); | |
| 10029 copy.element = node.element; | |
| 10030 return copy; | |
| 10031 } | |
| 10032 | |
| 10033 @override | |
| 10034 PartOfDirective visitPartOfDirective(PartOfDirective node) { | |
| 10035 PartOfDirective copy = new PartOfDirective( | |
| 10036 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 10037 _mapToken(node.partKeyword), _mapToken(node.ofKeyword), | |
| 10038 _cloneNode(node.libraryName), _mapToken(node.semicolon)); | |
| 10039 copy.element = node.element; | |
| 10040 return copy; | |
| 10041 } | |
| 10042 | |
| 10043 @override | |
| 10044 PostfixExpression visitPostfixExpression(PostfixExpression node) { | |
| 10045 PostfixExpression copy = new PostfixExpression( | |
| 10046 _cloneNode(node.operand), _mapToken(node.operator)); | |
| 10047 copy.propagatedElement = node.propagatedElement; | |
| 10048 copy.propagatedType = node.propagatedType; | |
| 10049 copy.staticElement = node.staticElement; | |
| 10050 copy.staticType = node.staticType; | |
| 10051 return copy; | |
| 10052 } | |
| 10053 | |
| 10054 @override | |
| 10055 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 10056 PrefixedIdentifier copy = new PrefixedIdentifier(_cloneNode(node.prefix), | |
| 10057 _mapToken(node.period), _cloneNode(node.identifier)); | |
| 10058 copy.propagatedType = node.propagatedType; | |
| 10059 copy.staticType = node.staticType; | |
| 10060 return copy; | |
| 10061 } | |
| 10062 | |
| 10063 @override | |
| 10064 PrefixExpression visitPrefixExpression(PrefixExpression node) { | |
| 10065 PrefixExpression copy = new PrefixExpression( | |
| 10066 _mapToken(node.operator), _cloneNode(node.operand)); | |
| 10067 copy.propagatedElement = node.propagatedElement; | |
| 10068 copy.propagatedType = node.propagatedType; | |
| 10069 copy.staticElement = node.staticElement; | |
| 10070 copy.staticType = node.staticType; | |
| 10071 return copy; | |
| 10072 } | |
| 10073 | |
| 10074 @override | |
| 10075 PropertyAccess visitPropertyAccess(PropertyAccess node) { | |
| 10076 PropertyAccess copy = new PropertyAccess(_cloneNode(node.target), | |
| 10077 _mapToken(node.operator), _cloneNode(node.propertyName)); | |
| 10078 copy.propagatedType = node.propagatedType; | |
| 10079 copy.staticType = node.staticType; | |
| 10080 return copy; | |
| 10081 } | |
| 10082 | |
| 10083 @override | |
| 10084 RedirectingConstructorInvocation visitRedirectingConstructorInvocation( | |
| 10085 RedirectingConstructorInvocation node) { | |
| 10086 RedirectingConstructorInvocation copy = | |
| 10087 new RedirectingConstructorInvocation(_mapToken(node.thisKeyword), | |
| 10088 _mapToken(node.period), _cloneNode(node.constructorName), | |
| 10089 _cloneNode(node.argumentList)); | |
| 10090 copy.staticElement = node.staticElement; | |
| 10091 return copy; | |
| 10092 } | |
| 10093 | |
| 10094 @override | |
| 10095 RethrowExpression visitRethrowExpression(RethrowExpression node) { | |
| 10096 RethrowExpression copy = | |
| 10097 new RethrowExpression(_mapToken(node.rethrowKeyword)); | |
| 10098 copy.propagatedType = node.propagatedType; | |
| 10099 copy.staticType = node.staticType; | |
| 10100 return copy; | |
| 10101 } | |
| 10102 | |
| 10103 @override | |
| 10104 ReturnStatement visitReturnStatement(ReturnStatement node) => | |
| 10105 new ReturnStatement(_mapToken(node.returnKeyword), | |
| 10106 _cloneNode(node.expression), _mapToken(node.semicolon)); | |
| 10107 | |
| 10108 @override | |
| 10109 ScriptTag visitScriptTag(ScriptTag node) => | |
| 10110 new ScriptTag(_mapToken(node.scriptTag)); | |
| 10111 | |
| 10112 @override | |
| 10113 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator( | |
| 10114 _mapToken(node.keyword), _cloneNodeList(node.shownNames)); | |
| 10115 | |
| 10116 @override | |
| 10117 SimpleFormalParameter visitSimpleFormalParameter( | |
| 10118 SimpleFormalParameter node) => new SimpleFormalParameter( | |
| 10119 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 10120 _mapToken(node.keyword), _cloneNode(node.type), | |
| 10121 _cloneNode(node.identifier)); | |
| 10122 | |
| 10123 @override | |
| 10124 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) { | |
| 10125 Token mappedToken = _mapToken(node.token); | |
| 10126 if (mappedToken == null) { | |
| 10127 // This only happens for SimpleIdentifiers created by the parser as part | |
| 10128 // of scanning documentation comments (the tokens for those identifiers | |
| 10129 // are not in the original token stream and hence do not get copied). | |
| 10130 // This extra check can be removed if the scanner is changed to scan | |
| 10131 // documentation comments for the parser. | |
| 10132 mappedToken = node.token; | |
| 10133 } | |
| 10134 SimpleIdentifier copy = new SimpleIdentifier(mappedToken); | |
| 10135 copy.auxiliaryElements = node.auxiliaryElements; | |
| 10136 copy.propagatedElement = node.propagatedElement; | |
| 10137 copy.propagatedType = node.propagatedType; | |
| 10138 copy.staticElement = node.staticElement; | |
| 10139 copy.staticType = node.staticType; | |
| 10140 return copy; | |
| 10141 } | |
| 10142 | |
| 10143 @override | |
| 10144 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) { | |
| 10145 SimpleStringLiteral copy = | |
| 10146 new SimpleStringLiteral(_mapToken(node.literal), node.value); | |
| 10147 copy.propagatedType = node.propagatedType; | |
| 10148 copy.staticType = node.staticType; | |
| 10149 return copy; | |
| 10150 } | |
| 10151 | |
| 10152 @override | |
| 10153 StringInterpolation visitStringInterpolation(StringInterpolation node) { | |
| 10154 StringInterpolation copy = | |
| 10155 new StringInterpolation(_cloneNodeList(node.elements)); | |
| 10156 copy.propagatedType = node.propagatedType; | |
| 10157 copy.staticType = node.staticType; | |
| 10158 return copy; | |
| 10159 } | |
| 10160 | |
| 10161 @override | |
| 10162 SuperConstructorInvocation visitSuperConstructorInvocation( | |
| 10163 SuperConstructorInvocation node) { | |
| 10164 SuperConstructorInvocation copy = new SuperConstructorInvocation( | |
| 10165 _mapToken(node.superKeyword), _mapToken(node.period), | |
| 10166 _cloneNode(node.constructorName), _cloneNode(node.argumentList)); | |
| 10167 copy.staticElement = node.staticElement; | |
| 10168 return copy; | |
| 10169 } | |
| 10170 | |
| 10171 @override | |
| 10172 SuperExpression visitSuperExpression(SuperExpression node) { | |
| 10173 SuperExpression copy = new SuperExpression(_mapToken(node.superKeyword)); | |
| 10174 copy.propagatedType = node.propagatedType; | |
| 10175 copy.staticType = node.staticType; | |
| 10176 return copy; | |
| 10177 } | |
| 10178 | |
| 10179 @override | |
| 10180 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase( | |
| 10181 _cloneNodeList(node.labels), _mapToken(node.keyword), | |
| 10182 _cloneNode(node.expression), _mapToken(node.colon), | |
| 10183 _cloneNodeList(node.statements)); | |
| 10184 | |
| 10185 @override | |
| 10186 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault( | |
| 10187 _cloneNodeList(node.labels), _mapToken(node.keyword), | |
| 10188 _mapToken(node.colon), _cloneNodeList(node.statements)); | |
| 10189 | |
| 10190 @override | |
| 10191 SwitchStatement visitSwitchStatement(SwitchStatement node) => | |
| 10192 new SwitchStatement(_mapToken(node.switchKeyword), | |
| 10193 _mapToken(node.leftParenthesis), _cloneNode(node.expression), | |
| 10194 _mapToken(node.rightParenthesis), _mapToken(node.leftBracket), | |
| 10195 _cloneNodeList(node.members), _mapToken(node.rightBracket)); | |
| 10196 | |
| 10197 @override | |
| 10198 AstNode visitSymbolLiteral(SymbolLiteral node) { | |
| 10199 SymbolLiteral copy = new SymbolLiteral( | |
| 10200 _mapToken(node.poundSign), _mapTokens(node.components)); | |
| 10201 copy.propagatedType = node.propagatedType; | |
| 10202 copy.staticType = node.staticType; | |
| 10203 return copy; | |
| 10204 } | |
| 10205 | |
| 10206 @override | |
| 10207 ThisExpression visitThisExpression(ThisExpression node) { | |
| 10208 ThisExpression copy = new ThisExpression(_mapToken(node.thisKeyword)); | |
| 10209 copy.propagatedType = node.propagatedType; | |
| 10210 copy.staticType = node.staticType; | |
| 10211 return copy; | |
| 10212 } | |
| 10213 | |
| 10214 @override | |
| 10215 ThrowExpression visitThrowExpression(ThrowExpression node) { | |
| 10216 ThrowExpression copy = new ThrowExpression( | |
| 10217 _mapToken(node.throwKeyword), _cloneNode(node.expression)); | |
| 10218 copy.propagatedType = node.propagatedType; | |
| 10219 copy.staticType = node.staticType; | |
| 10220 return copy; | |
| 10221 } | |
| 10222 | |
| 10223 @override | |
| 10224 TopLevelVariableDeclaration visitTopLevelVariableDeclaration( | |
| 10225 TopLevelVariableDeclaration node) => new TopLevelVariableDeclaration( | |
| 10226 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 10227 _cloneNode(node.variables), _mapToken(node.semicolon)); | |
| 10228 | |
| 10229 @override | |
| 10230 TryStatement visitTryStatement(TryStatement node) => new TryStatement( | |
| 10231 _mapToken(node.tryKeyword), _cloneNode(node.body), | |
| 10232 _cloneNodeList(node.catchClauses), _mapToken(node.finallyKeyword), | |
| 10233 _cloneNode(node.finallyBlock)); | |
| 10234 | |
| 10235 @override | |
| 10236 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) => | |
| 10237 new TypeArgumentList(_mapToken(node.leftBracket), | |
| 10238 _cloneNodeList(node.arguments), _mapToken(node.rightBracket)); | |
| 10239 | |
| 10240 @override | |
| 10241 TypeName visitTypeName(TypeName node) { | |
| 10242 TypeName copy = | |
| 10243 new TypeName(_cloneNode(node.name), _cloneNode(node.typeArguments)); | |
| 10244 copy.type = node.type; | |
| 10245 return copy; | |
| 10246 } | |
| 10247 | |
| 10248 @override | |
| 10249 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter( | |
| 10250 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata), | |
| 10251 _cloneNode(node.name), _mapToken(node.extendsKeyword), | |
| 10252 _cloneNode(node.bound)); | |
| 10253 | |
| 10254 @override | |
| 10255 TypeParameterList visitTypeParameterList(TypeParameterList node) => | |
| 10256 new TypeParameterList(_mapToken(node.leftBracket), | |
| 10257 _cloneNodeList(node.typeParameters), _mapToken(node.rightBracket)); | |
| 10258 | |
| 10259 @override | |
| 10260 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) => | |
| 10261 new VariableDeclaration(_cloneNode(node.name), _mapToken(node.equals), | |
| 10262 _cloneNode(node.initializer)); | |
| 10263 | |
| 10264 @override | |
| 10265 VariableDeclarationList visitVariableDeclarationList( | |
| 10266 VariableDeclarationList node) => new VariableDeclarationList(null, | |
| 10267 _cloneNodeList(node.metadata), _mapToken(node.keyword), | |
| 10268 _cloneNode(node.type), _cloneNodeList(node.variables)); | |
| 10269 | |
| 10270 @override | |
| 10271 VariableDeclarationStatement visitVariableDeclarationStatement( | |
| 10272 VariableDeclarationStatement node) => new VariableDeclarationStatement( | |
| 10273 _cloneNode(node.variables), _mapToken(node.semicolon)); | |
| 10274 | |
| 10275 @override | |
| 10276 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement( | |
| 10277 _mapToken(node.whileKeyword), _mapToken(node.leftParenthesis), | |
| 10278 _cloneNode(node.condition), _mapToken(node.rightParenthesis), | |
| 10279 _cloneNode(node.body)); | |
| 10280 | |
| 10281 @override | |
| 10282 WithClause visitWithClause(WithClause node) => new WithClause( | |
| 10283 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes)); | |
| 10284 | |
| 10285 @override | |
| 10286 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement( | |
| 10287 _mapToken(node.yieldKeyword), _mapToken(node.star), | |
| 10288 _cloneNode(node.expression), _mapToken(node.semicolon)); | |
| 10289 | |
| 10290 AstNode _cloneNode(AstNode node) { | |
| 10291 if (node == null) { | |
| 10292 return null; | |
| 10293 } | |
| 10294 if (identical(node, _oldNode)) { | |
| 10295 return _newNode; | |
| 10296 } | |
| 10297 return node.accept(this) as AstNode; | |
| 10298 } | |
| 10299 | |
| 10300 List _cloneNodeList(NodeList nodes) { | |
| 10301 List clonedNodes = new List(); | |
| 10302 for (AstNode node in nodes) { | |
| 10303 clonedNodes.add(_cloneNode(node)); | |
| 10304 } | |
| 10305 return clonedNodes; | |
| 10306 } | |
| 10307 | |
| 10308 Token _mapToken(Token oldToken) { | |
| 10309 if (oldToken == null) { | |
| 10310 return null; | |
| 10311 } | |
| 10312 return _tokenMap.get(oldToken); | |
| 10313 } | |
| 10314 | |
| 10315 List<Token> _mapTokens(List<Token> oldTokens) { | |
| 10316 List<Token> newTokens = new List<Token>(oldTokens.length); | |
| 10317 for (int index = 0; index < newTokens.length; index++) { | |
| 10318 newTokens[index] = _mapToken(oldTokens[index]); | |
| 10319 } | |
| 10320 return newTokens; | |
| 10321 } | |
| 10322 } | |
| 10323 | |
| 10324 /** | |
| 10325 * An index expression. | |
| 10326 * | |
| 10327 * > indexExpression ::= | |
| 10328 * > [Expression] '[' [Expression] ']' | |
| 10329 */ | |
| 10330 class IndexExpression extends Expression { | |
| 10331 /** | |
| 10332 * The expression used to compute the object being indexed, or `null` if this | |
| 10333 * index expression is part of a cascade expression. | |
| 10334 */ | |
| 10335 Expression _target; | |
| 10336 | |
| 10337 /** | |
| 10338 * The period ("..") before a cascaded index expression, or `null` if this | |
| 10339 * index expression is not part of a cascade expression. | |
| 10340 */ | |
| 10341 Token period; | |
| 10342 | |
| 10343 /** | |
| 10344 * The left square bracket. | |
| 10345 */ | |
| 10346 Token leftBracket; | |
| 10347 | |
| 10348 /** | |
| 10349 * The expression used to compute the index. | |
| 10350 */ | |
| 10351 Expression _index; | |
| 10352 | |
| 10353 /** | |
| 10354 * The right square bracket. | |
| 10355 */ | |
| 10356 Token rightBracket; | |
| 10357 | |
| 10358 /** | |
| 10359 * The element associated with the operator based on the static type of the | |
| 10360 * target, or `null` if the AST structure has not been resolved or if the | |
| 10361 * operator could not be resolved. | |
| 10362 */ | |
| 10363 MethodElement staticElement; | |
| 10364 | |
| 10365 /** | |
| 10366 * The element associated with the operator based on the propagated type of | |
| 10367 * the target, or `null` if the AST structure has not been resolved or if the | |
| 10368 * operator could not be resolved. | |
| 10369 */ | |
| 10370 MethodElement propagatedElement; | |
| 10371 | |
| 10372 /** | |
| 10373 * If this expression is both in a getter and setter context, the | |
| 10374 * [AuxiliaryElements] will be set to hold onto the static and propagated | |
| 10375 * information. The auxiliary element will hold onto the elements from the | |
| 10376 * getter context. | |
| 10377 */ | |
| 10378 AuxiliaryElements auxiliaryElements = null; | |
| 10379 | |
| 10380 /** | |
| 10381 * Initialize a newly created index expression. | |
| 10382 */ | |
| 10383 IndexExpression.forCascade( | |
| 10384 this.period, this.leftBracket, Expression index, this.rightBracket) { | |
| 10385 _index = _becomeParentOf(index); | |
| 10386 } | |
| 10387 | |
| 10388 /** | |
| 10389 * Initialize a newly created index expression. | |
| 10390 */ | |
| 10391 IndexExpression.forTarget(Expression target, this.leftBracket, | |
| 10392 Expression index, this.rightBracket) { | |
| 10393 _target = _becomeParentOf(target); | |
| 10394 _index = _becomeParentOf(index); | |
| 10395 } | |
| 10396 | |
| 10397 @override | |
| 10398 Token get beginToken { | |
| 10399 if (_target != null) { | |
| 10400 return _target.beginToken; | |
| 10401 } | |
| 10402 return period; | |
| 10403 } | |
| 10404 | |
| 10405 /** | |
| 10406 * Return the best element available for this operator. If resolution was able | |
| 10407 * to find a better element based on type propagation, that element will be | |
| 10408 * returned. Otherwise, the element found using the result of static analysis | |
| 10409 * will be returned. If resolution has not been performed, then `null` will be | |
| 10410 * returned. | |
| 10411 */ | |
| 10412 MethodElement get bestElement { | |
| 10413 MethodElement element = propagatedElement; | |
| 10414 if (element == null) { | |
| 10415 element = staticElement; | |
| 10416 } | |
| 10417 return element; | |
| 10418 } | |
| 10419 | |
| 10420 @override | |
| 10421 Iterable get childEntities => new ChildEntities() | |
| 10422 ..add(_target) | |
| 10423 ..add(period) | |
| 10424 ..add(leftBracket) | |
| 10425 ..add(_index) | |
| 10426 ..add(rightBracket); | |
| 10427 | |
| 10428 @override | |
| 10429 Token get endToken => rightBracket; | |
| 10430 | |
| 10431 /** | |
| 10432 * Return the expression used to compute the index. | |
| 10433 */ | |
| 10434 Expression get index => _index; | |
| 10435 | |
| 10436 /** | |
| 10437 * Set the expression used to compute the index to the given [expression]. | |
| 10438 */ | |
| 10439 void set index(Expression expression) { | |
| 10440 _index = _becomeParentOf(expression); | |
| 10441 } | |
| 10442 | |
| 10443 @override | |
| 10444 bool get isAssignable => true; | |
| 10445 | |
| 10446 /** | |
| 10447 * Return `true` if this expression is cascaded. If it is, then the target of | |
| 10448 * this expression is not stored locally but is stored in the nearest ancestor | |
| 10449 * that is a [CascadeExpression]. | |
| 10450 */ | |
| 10451 bool get isCascaded => period != null; | |
| 10452 | |
| 10453 @override | |
| 10454 int get precedence => 15; | |
| 10455 | |
| 10456 /** | |
| 10457 * If the AST structure has been resolved, and the function being invoked is | |
| 10458 * known based on propagated type information, then return the parameter | |
| 10459 * element representing the parameter to which the value of the index | |
| 10460 * expression will be bound. Otherwise, return `null`. | |
| 10461 */ | |
| 10462 @deprecated // Use "expression.propagatedParameterElement" | |
| 10463 ParameterElement get propagatedParameterElementForIndex { | |
| 10464 return _propagatedParameterElementForIndex; | |
| 10465 } | |
| 10466 | |
| 10467 /** | |
| 10468 * Return the expression used to compute the object being indexed. If this | |
| 10469 * index expression is not part of a cascade expression, then this is the same | |
| 10470 * as [target]. If this index expression is part of a cascade expression, then | |
| 10471 * the target expression stored with the cascade expression is returned. | |
| 10472 */ | |
| 10473 Expression get realTarget { | |
| 10474 if (isCascaded) { | |
| 10475 AstNode ancestor = parent; | |
| 10476 while (ancestor is! CascadeExpression) { | |
| 10477 if (ancestor == null) { | |
| 10478 return _target; | |
| 10479 } | |
| 10480 ancestor = ancestor.parent; | |
| 10481 } | |
| 10482 return (ancestor as CascadeExpression).target; | |
| 10483 } | |
| 10484 return _target; | |
| 10485 } | |
| 10486 | |
| 10487 /** | |
| 10488 * If the AST structure has been resolved, and the function being invoked is | |
| 10489 * known based on static type information, then return the parameter element | |
| 10490 * representing the parameter to which the value of the index expression will | |
| 10491 * be bound. Otherwise, return `null`. | |
| 10492 */ | |
| 10493 @deprecated // Use "expression.propagatedParameterElement" | |
| 10494 ParameterElement get staticParameterElementForIndex { | |
| 10495 return _staticParameterElementForIndex; | |
| 10496 } | |
| 10497 | |
| 10498 /** | |
| 10499 * Return the expression used to compute the object being indexed, or `null` | |
| 10500 * if this index expression is part of a cascade expression. | |
| 10501 * | |
| 10502 * Use [realTarget] to get the target independent of whether this is part of a | |
| 10503 * cascade expression. | |
| 10504 */ | |
| 10505 Expression get target => _target; | |
| 10506 | |
| 10507 /** | |
| 10508 * Set the expression used to compute the object being indexed to the given | |
| 10509 * [expression]. | |
| 10510 */ | |
| 10511 void set target(Expression expression) { | |
| 10512 _target = _becomeParentOf(expression); | |
| 10513 } | |
| 10514 | |
| 10515 /** | |
| 10516 * If the AST structure has been resolved, and the function being invoked is | |
| 10517 * known based on propagated type information, then return the parameter | |
| 10518 * element representing the parameter to which the value of the index | |
| 10519 * expression will be bound. Otherwise, return `null`. | |
| 10520 */ | |
| 10521 ParameterElement get _propagatedParameterElementForIndex { | |
| 10522 if (propagatedElement == null) { | |
| 10523 return null; | |
| 10524 } | |
| 10525 List<ParameterElement> parameters = propagatedElement.parameters; | |
| 10526 if (parameters.length < 1) { | |
| 10527 return null; | |
| 10528 } | |
| 10529 return parameters[0]; | |
| 10530 } | |
| 10531 | |
| 10532 /** | |
| 10533 * If the AST structure has been resolved, and the function being invoked is | |
| 10534 * known based on static type information, then return the parameter element | |
| 10535 * representing the parameter to which the value of the index expression will | |
| 10536 * be bound. Otherwise, return `null`. | |
| 10537 */ | |
| 10538 ParameterElement get _staticParameterElementForIndex { | |
| 10539 if (staticElement == null) { | |
| 10540 return null; | |
| 10541 } | |
| 10542 List<ParameterElement> parameters = staticElement.parameters; | |
| 10543 if (parameters.length < 1) { | |
| 10544 return null; | |
| 10545 } | |
| 10546 return parameters[0]; | |
| 10547 } | |
| 10548 | |
| 10549 @override | |
| 10550 accept(AstVisitor visitor) => visitor.visitIndexExpression(this); | |
| 10551 | |
| 10552 /** | |
| 10553 * Return `true` if this expression is computing a right-hand value (that is, | |
| 10554 * if this expression is in a context where the operator '[]' will be | |
| 10555 * invoked). | |
| 10556 * | |
| 10557 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor | |
| 10558 * are they mutually exclusive. In other words, it is possible for both | |
| 10559 * methods to return `true` when invoked on the same node. | |
| 10560 */ | |
| 10561 bool inGetterContext() { | |
| 10562 // TODO(brianwilkerson) Convert this to a getter. | |
| 10563 AstNode parent = this.parent; | |
| 10564 if (parent is AssignmentExpression) { | |
| 10565 AssignmentExpression assignment = parent; | |
| 10566 if (identical(assignment.leftHandSide, this) && | |
| 10567 assignment.operator.type == TokenType.EQ) { | |
| 10568 return false; | |
| 10569 } | |
| 10570 } | |
| 10571 return true; | |
| 10572 } | |
| 10573 | |
| 10574 /** | |
| 10575 * Return `true` if this expression is computing a left-hand value (that is, | |
| 10576 * if this expression is in a context where the operator '[]=' will be | |
| 10577 * invoked). | |
| 10578 * | |
| 10579 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor | |
| 10580 * are they mutually exclusive. In other words, it is possible for both | |
| 10581 * methods to return `true` when invoked on the same node. | |
| 10582 */ | |
| 10583 bool inSetterContext() { | |
| 10584 // TODO(brianwilkerson) Convert this to a getter. | |
| 10585 AstNode parent = this.parent; | |
| 10586 if (parent is PrefixExpression) { | |
| 10587 return parent.operator.type.isIncrementOperator; | |
| 10588 } else if (parent is PostfixExpression) { | |
| 10589 return true; | |
| 10590 } else if (parent is AssignmentExpression) { | |
| 10591 return identical(parent.leftHandSide, this); | |
| 10592 } | |
| 10593 return false; | |
| 10594 } | |
| 10595 | |
| 10596 @override | |
| 10597 void visitChildren(AstVisitor visitor) { | |
| 10598 _safelyVisitChild(_target, visitor); | |
| 10599 _safelyVisitChild(_index, visitor); | |
| 10600 } | |
| 10601 } | |
| 10602 | |
| 10603 /** | |
| 10604 * An instance creation expression. | |
| 10605 * | |
| 10606 * > newExpression ::= | |
| 10607 * > ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList] | |
| 10608 */ | |
| 10609 class InstanceCreationExpression extends Expression { | |
| 10610 /** | |
| 10611 * The 'new' or 'const' keyword used to indicate how an object should be | |
| 10612 * created. | |
| 10613 */ | |
| 10614 Token keyword; | |
| 10615 | |
| 10616 /** | |
| 10617 * The name of the constructor to be invoked. | |
| 10618 */ | |
| 10619 ConstructorName _constructorName; | |
| 10620 | |
| 10621 /** | |
| 10622 * The list of arguments to the constructor. | |
| 10623 */ | |
| 10624 ArgumentList _argumentList; | |
| 10625 | |
| 10626 /** | |
| 10627 * The element associated with the constructor based on static type | |
| 10628 * information, or `null` if the AST structure has not been resolved or if the | |
| 10629 * constructor could not be resolved. | |
| 10630 */ | |
| 10631 ConstructorElement staticElement; | |
| 10632 | |
| 10633 /** | |
| 10634 * Initialize a newly created instance creation expression. | |
| 10635 */ | |
| 10636 InstanceCreationExpression(this.keyword, ConstructorName constructorName, | |
| 10637 ArgumentList argumentList) { | |
| 10638 _constructorName = _becomeParentOf(constructorName); | |
| 10639 _argumentList = _becomeParentOf(argumentList); | |
| 10640 } | |
| 10641 | |
| 10642 /** | |
| 10643 * Return the list of arguments to the constructor. | |
| 10644 */ | |
| 10645 ArgumentList get argumentList => _argumentList; | |
| 10646 | |
| 10647 /** | |
| 10648 * Set the list of arguments to the constructor to the given [argumentList]. | |
| 10649 */ | |
| 10650 void set argumentList(ArgumentList argumentList) { | |
| 10651 _argumentList = _becomeParentOf(argumentList); | |
| 10652 } | |
| 10653 | |
| 10654 @override | |
| 10655 Token get beginToken => keyword; | |
| 10656 | |
| 10657 @override | |
| 10658 Iterable get childEntities => new ChildEntities() | |
| 10659 ..add(keyword) | |
| 10660 ..add(_constructorName) | |
| 10661 ..add(_argumentList); | |
| 10662 | |
| 10663 /** | |
| 10664 * Return the name of the constructor to be invoked. | |
| 10665 */ | |
| 10666 ConstructorName get constructorName => _constructorName; | |
| 10667 | |
| 10668 /** | |
| 10669 * Set the name of the constructor to be invoked to the given [name]. | |
| 10670 */ | |
| 10671 void set constructorName(ConstructorName name) { | |
| 10672 _constructorName = _becomeParentOf(name); | |
| 10673 } | |
| 10674 | |
| 10675 @override | |
| 10676 Token get endToken => _argumentList.endToken; | |
| 10677 | |
| 10678 /** | |
| 10679 * Return `true` if this creation expression is used to invoke a constant | |
| 10680 * constructor. | |
| 10681 */ | |
| 10682 bool get isConst => keyword is KeywordToken && | |
| 10683 (keyword as KeywordToken).keyword == Keyword.CONST; | |
| 10684 | |
| 10685 @override | |
| 10686 int get precedence => 16; | |
| 10687 | |
| 10688 @override | |
| 10689 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this); | |
| 10690 | |
| 10691 @override | |
| 10692 void visitChildren(AstVisitor visitor) { | |
| 10693 _safelyVisitChild(_constructorName, visitor); | |
| 10694 _safelyVisitChild(_argumentList, visitor); | |
| 10695 } | |
| 10696 } | |
| 10697 | |
| 10698 /** | |
| 10699 * An integer literal expression. | |
| 10700 * | |
| 10701 * > integerLiteral ::= | |
| 10702 * > decimalIntegerLiteral | |
| 10703 * > | hexidecimalIntegerLiteral | |
| 10704 * > | |
| 10705 * > decimalIntegerLiteral ::= | |
| 10706 * > decimalDigit+ | |
| 10707 * > | |
| 10708 * > hexidecimalIntegerLiteral ::= | |
| 10709 * > '0x' hexidecimalDigit+ | |
| 10710 * > | '0X' hexidecimalDigit+ | |
| 10711 */ | |
| 10712 class IntegerLiteral extends Literal { | |
| 10713 /** | |
| 10714 * The token representing the literal. | |
| 10715 */ | |
| 10716 Token literal; | |
| 10717 | |
| 10718 /** | |
| 10719 * The value of the literal. | |
| 10720 */ | |
| 10721 int value = 0; | |
| 10722 | |
| 10723 /** | |
| 10724 * Initialize a newly created integer literal. | |
| 10725 */ | |
| 10726 IntegerLiteral(this.literal, this.value); | |
| 10727 | |
| 10728 @override | |
| 10729 Token get beginToken => literal; | |
| 10730 | |
| 10731 @override | |
| 10732 Iterable get childEntities => new ChildEntities()..add(literal); | |
| 10733 | |
| 10734 @override | |
| 10735 Token get endToken => literal; | |
| 10736 | |
| 10737 @override | |
| 10738 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this); | |
| 10739 | |
| 10740 @override | |
| 10741 void visitChildren(AstVisitor visitor) { | |
| 10742 // There are no children to visit. | |
| 10743 } | |
| 10744 } | |
| 10745 | |
| 10746 /** | |
| 10747 * A node within a [StringInterpolation]. | |
| 10748 * | |
| 10749 * > interpolationElement ::= | |
| 10750 * > [InterpolationExpression] | |
| 10751 * > | [InterpolationString] | |
| 10752 */ | |
| 10753 abstract class InterpolationElement extends AstNode {} | |
| 10754 | |
| 10755 /** | |
| 10756 * An expression embedded in a string interpolation. | |
| 10757 * | |
| 10758 * > interpolationExpression ::= | |
| 10759 * > '$' [SimpleIdentifier] | |
| 10760 * > | '$' '{' [Expression] '}' | |
| 10761 */ | |
| 10762 class InterpolationExpression extends InterpolationElement { | |
| 10763 /** | |
| 10764 * The token used to introduce the interpolation expression; either '$' if the | |
| 10765 * expression is a simple identifier or '${' if the expression is a full | |
| 10766 * expression. | |
| 10767 */ | |
| 10768 Token leftBracket; | |
| 10769 | |
| 10770 /** | |
| 10771 * The expression to be evaluated for the value to be converted into a string. | |
| 10772 */ | |
| 10773 Expression _expression; | |
| 10774 | |
| 10775 /** | |
| 10776 * The right curly bracket, or `null` if the expression is an identifier | |
| 10777 * without brackets. | |
| 10778 */ | |
| 10779 Token rightBracket; | |
| 10780 | |
| 10781 /** | |
| 10782 * Initialize a newly created interpolation expression. | |
| 10783 */ | |
| 10784 InterpolationExpression( | |
| 10785 this.leftBracket, Expression expression, this.rightBracket) { | |
| 10786 _expression = _becomeParentOf(expression); | |
| 10787 } | |
| 10788 | |
| 10789 @override | |
| 10790 Token get beginToken => leftBracket; | |
| 10791 | |
| 10792 @override | |
| 10793 Iterable get childEntities => new ChildEntities() | |
| 10794 ..add(leftBracket) | |
| 10795 ..add(_expression) | |
| 10796 ..add(rightBracket); | |
| 10797 | |
| 10798 @override | |
| 10799 Token get endToken { | |
| 10800 if (rightBracket != null) { | |
| 10801 return rightBracket; | |
| 10802 } | |
| 10803 return _expression.endToken; | |
| 10804 } | |
| 10805 | |
| 10806 /** | |
| 10807 * Return the expression to be evaluated for the value to be converted into a | |
| 10808 * string. | |
| 10809 */ | |
| 10810 Expression get expression => _expression; | |
| 10811 | |
| 10812 /** | |
| 10813 * Set the expression to be evaluated for the value to be converted into a | |
| 10814 * string to the given [expression]. | |
| 10815 */ | |
| 10816 void set expression(Expression expression) { | |
| 10817 _expression = _becomeParentOf(expression); | |
| 10818 } | |
| 10819 | |
| 10820 @override | |
| 10821 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this); | |
| 10822 | |
| 10823 @override | |
| 10824 void visitChildren(AstVisitor visitor) { | |
| 10825 _safelyVisitChild(_expression, visitor); | |
| 10826 } | |
| 10827 } | |
| 10828 | |
| 10829 /** | |
| 10830 * A non-empty substring of an interpolated string. | |
| 10831 * | |
| 10832 * > interpolationString ::= | |
| 10833 * > characters | |
| 10834 */ | |
| 10835 class InterpolationString extends InterpolationElement { | |
| 10836 /** | |
| 10837 * The characters that will be added to the string. | |
| 10838 */ | |
| 10839 Token contents; | |
| 10840 | |
| 10841 /** | |
| 10842 * The value of the literal. | |
| 10843 */ | |
| 10844 String _value; | |
| 10845 | |
| 10846 /** | |
| 10847 * Initialize a newly created string of characters that are part of a string | |
| 10848 * interpolation. | |
| 10849 */ | |
| 10850 InterpolationString(this.contents, String value) { | |
| 10851 _value = value; | |
| 10852 } | |
| 10853 | |
| 10854 @override | |
| 10855 Token get beginToken => contents; | |
| 10856 | |
| 10857 @override | |
| 10858 Iterable get childEntities => new ChildEntities()..add(contents); | |
| 10859 | |
| 10860 /** | |
| 10861 * Return the offset of the after-last contents character. | |
| 10862 */ | |
| 10863 int get contentsEnd { | |
| 10864 String lexeme = contents.lexeme; | |
| 10865 return offset + new StringLexemeHelper(lexeme, true, true).end; | |
| 10866 } | |
| 10867 | |
| 10868 /** | |
| 10869 * Return the offset of the first contents character. | |
| 10870 */ | |
| 10871 int get contentsOffset { | |
| 10872 int offset = contents.offset; | |
| 10873 String lexeme = contents.lexeme; | |
| 10874 return offset + new StringLexemeHelper(lexeme, true, true).start; | |
| 10875 } | |
| 10876 | |
| 10877 @override | |
| 10878 Token get endToken => contents; | |
| 10879 | |
| 10880 /** | |
| 10881 * Return the value of the literal. | |
| 10882 */ | |
| 10883 String get value => _value; | |
| 10884 | |
| 10885 /** | |
| 10886 * Set the value of the literal to the given [string]. | |
| 10887 */ | |
| 10888 void set value(String string) { | |
| 10889 _value = string; | |
| 10890 } | |
| 10891 | |
| 10892 @override | |
| 10893 accept(AstVisitor visitor) => visitor.visitInterpolationString(this); | |
| 10894 | |
| 10895 @override | |
| 10896 void visitChildren(AstVisitor visitor) {} | |
| 10897 } | |
| 10898 | |
| 10899 /** | |
| 10900 * An is expression. | |
| 10901 * | |
| 10902 * > isExpression ::= | |
| 10903 * > [Expression] 'is' '!'? [TypeName] | |
| 10904 */ | |
| 10905 class IsExpression extends Expression { | |
| 10906 /** | |
| 10907 * The expression used to compute the value whose type is being tested. | |
| 10908 */ | |
| 10909 Expression _expression; | |
| 10910 | |
| 10911 /** | |
| 10912 * The is operator. | |
| 10913 */ | |
| 10914 Token isOperator; | |
| 10915 | |
| 10916 /** | |
| 10917 * The not operator, or `null` if the sense of the test is not negated. | |
| 10918 */ | |
| 10919 Token notOperator; | |
| 10920 | |
| 10921 /** | |
| 10922 * The name of the type being tested for. | |
| 10923 */ | |
| 10924 TypeName _type; | |
| 10925 | |
| 10926 /** | |
| 10927 * Initialize a newly created is expression. The [notOperator] can be `null` | |
| 10928 * if the sense of the test is not negated. | |
| 10929 */ | |
| 10930 IsExpression( | |
| 10931 Expression expression, this.isOperator, this.notOperator, TypeName type) { | |
| 10932 _expression = _becomeParentOf(expression); | |
| 10933 _type = _becomeParentOf(type); | |
| 10934 } | |
| 10935 | |
| 10936 @override | |
| 10937 Token get beginToken => _expression.beginToken; | |
| 10938 | |
| 10939 @override | |
| 10940 Iterable get childEntities => new ChildEntities() | |
| 10941 ..add(_expression) | |
| 10942 ..add(isOperator) | |
| 10943 ..add(notOperator) | |
| 10944 ..add(_type); | |
| 10945 | |
| 10946 @override | |
| 10947 Token get endToken => _type.endToken; | |
| 10948 | |
| 10949 /** | |
| 10950 * Return the expression used to compute the value whose type is being tested. | |
| 10951 */ | |
| 10952 Expression get expression => _expression; | |
| 10953 | |
| 10954 /** | |
| 10955 * Set the expression used to compute the value whose type is being tested to | |
| 10956 * the given [expression]. | |
| 10957 */ | |
| 10958 void set expression(Expression expression) { | |
| 10959 _expression = _becomeParentOf(expression); | |
| 10960 } | |
| 10961 | |
| 10962 @override | |
| 10963 int get precedence => 7; | |
| 10964 | |
| 10965 /** | |
| 10966 * Return the name of the type being tested for. | |
| 10967 */ | |
| 10968 TypeName get type => _type; | |
| 10969 | |
| 10970 /** | |
| 10971 * Set the name of the type being tested for to the given [name]. | |
| 10972 */ | |
| 10973 void set type(TypeName name) { | |
| 10974 _type = _becomeParentOf(name); | |
| 10975 } | |
| 10976 | |
| 10977 @override | |
| 10978 accept(AstVisitor visitor) => visitor.visitIsExpression(this); | |
| 10979 | |
| 10980 @override | |
| 10981 void visitChildren(AstVisitor visitor) { | |
| 10982 _safelyVisitChild(_expression, visitor); | |
| 10983 _safelyVisitChild(_type, visitor); | |
| 10984 } | |
| 10985 } | |
| 10986 | |
| 10987 /** | |
| 10988 * A label on either a [LabeledStatement] or a [NamedExpression]. | |
| 10989 * | |
| 10990 * > label ::= | |
| 10991 * > [SimpleIdentifier] ':' | |
| 10992 */ | |
| 10993 class Label extends AstNode { | |
| 10994 /** | |
| 10995 * The label being associated with the statement. | |
| 10996 */ | |
| 10997 SimpleIdentifier _label; | |
| 10998 | |
| 10999 /** | |
| 11000 * The colon that separates the label from the statement. | |
| 11001 */ | |
| 11002 Token colon; | |
| 11003 | |
| 11004 /** | |
| 11005 * Initialize a newly created label. | |
| 11006 */ | |
| 11007 Label(SimpleIdentifier label, this.colon) { | |
| 11008 _label = _becomeParentOf(label); | |
| 11009 } | |
| 11010 | |
| 11011 @override | |
| 11012 Token get beginToken => _label.beginToken; | |
| 11013 | |
| 11014 @override | |
| 11015 Iterable get childEntities => new ChildEntities()..add(_label)..add(colon); | |
| 11016 | |
| 11017 @override | |
| 11018 Token get endToken => colon; | |
| 11019 | |
| 11020 /** | |
| 11021 * Return the label being associated with the statement. | |
| 11022 */ | |
| 11023 SimpleIdentifier get label => _label; | |
| 11024 | |
| 11025 /** | |
| 11026 * Set the label being associated with the statement to the given [label]. | |
| 11027 */ | |
| 11028 void set label(SimpleIdentifier label) { | |
| 11029 _label = _becomeParentOf(label); | |
| 11030 } | |
| 11031 | |
| 11032 @override | |
| 11033 accept(AstVisitor visitor) => visitor.visitLabel(this); | |
| 11034 | |
| 11035 @override | |
| 11036 void visitChildren(AstVisitor visitor) { | |
| 11037 _safelyVisitChild(_label, visitor); | |
| 11038 } | |
| 11039 } | |
| 11040 | |
| 11041 /** | |
| 11042 * A statement that has a label associated with them. | |
| 11043 * | |
| 11044 * > labeledStatement ::= | |
| 11045 * > [Label]+ [Statement] | |
| 11046 */ | |
| 11047 class LabeledStatement extends Statement { | |
| 11048 /** | |
| 11049 * The labels being associated with the statement. | |
| 11050 */ | |
| 11051 NodeList<Label> _labels; | |
| 11052 | |
| 11053 /** | |
| 11054 * The statement with which the labels are being associated. | |
| 11055 */ | |
| 11056 Statement _statement; | |
| 11057 | |
| 11058 /** | |
| 11059 * Initialize a newly created labeled statement. | |
| 11060 */ | |
| 11061 LabeledStatement(List<Label> labels, Statement statement) { | |
| 11062 _labels = new NodeList<Label>(this, labels); | |
| 11063 _statement = _becomeParentOf(statement); | |
| 11064 } | |
| 11065 | |
| 11066 @override | |
| 11067 Token get beginToken { | |
| 11068 if (!_labels.isEmpty) { | |
| 11069 return _labels.beginToken; | |
| 11070 } | |
| 11071 return _statement.beginToken; | |
| 11072 } | |
| 11073 | |
| 11074 @override | |
| 11075 Iterable get childEntities => new ChildEntities() | |
| 11076 ..addAll(_labels) | |
| 11077 ..add(_statement); | |
| 11078 | |
| 11079 @override | |
| 11080 Token get endToken => _statement.endToken; | |
| 11081 | |
| 11082 /** | |
| 11083 * Return the labels being associated with the statement. | |
| 11084 */ | |
| 11085 NodeList<Label> get labels => _labels; | |
| 11086 | |
| 11087 /** | |
| 11088 * Return the statement with which the labels are being associated. | |
| 11089 */ | |
| 11090 Statement get statement => _statement; | |
| 11091 | |
| 11092 /** | |
| 11093 * Set the statement with which the labels are being associated to the given | |
| 11094 * [statement]. | |
| 11095 */ | |
| 11096 void set statement(Statement statement) { | |
| 11097 _statement = _becomeParentOf(statement); | |
| 11098 } | |
| 11099 | |
| 11100 @override | |
| 11101 Statement get unlabeled => _statement.unlabeled; | |
| 11102 | |
| 11103 @override | |
| 11104 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this); | |
| 11105 | |
| 11106 @override | |
| 11107 void visitChildren(AstVisitor visitor) { | |
| 11108 _labels.accept(visitor); | |
| 11109 _safelyVisitChild(_statement, visitor); | |
| 11110 } | |
| 11111 } | |
| 11112 | |
| 11113 /** | |
| 11114 * A library directive. | |
| 11115 * | |
| 11116 * > libraryDirective ::= | |
| 11117 * > [Annotation] 'library' [Identifier] ';' | |
| 11118 */ | |
| 11119 class LibraryDirective extends Directive { | |
| 11120 /** | |
| 11121 * The token representing the 'library' keyword. | |
| 11122 */ | |
| 11123 Token libraryKeyword; | |
| 11124 | |
| 11125 /** | |
| 11126 * The name of the library being defined. | |
| 11127 */ | |
| 11128 LibraryIdentifier _name; | |
| 11129 | |
| 11130 /** | |
| 11131 * The semicolon terminating the directive. | |
| 11132 */ | |
| 11133 Token semicolon; | |
| 11134 | |
| 11135 /** | |
| 11136 * Initialize a newly created library directive. Either or both of the | |
| 11137 * [comment] and [metadata] can be `null` if the directive does not have the | |
| 11138 * corresponding attribute. | |
| 11139 */ | |
| 11140 LibraryDirective(Comment comment, List<Annotation> metadata, | |
| 11141 this.libraryKeyword, LibraryIdentifier name, this.semicolon) | |
| 11142 : super(comment, metadata) { | |
| 11143 _name = _becomeParentOf(name); | |
| 11144 } | |
| 11145 | |
| 11146 @override | |
| 11147 Iterable get childEntities => | |
| 11148 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon); | |
| 11149 | |
| 11150 @override | |
| 11151 Token get endToken => semicolon; | |
| 11152 | |
| 11153 @override | |
| 11154 Token get firstTokenAfterCommentAndMetadata => libraryKeyword; | |
| 11155 | |
| 11156 @override | |
| 11157 Token get keyword => libraryKeyword; | |
| 11158 | |
| 11159 /** | |
| 11160 * Return the token representing the 'library' token. | |
| 11161 */ | |
| 11162 @deprecated // Use "this.libraryKeyword" | |
| 11163 Token get libraryToken => libraryKeyword; | |
| 11164 | |
| 11165 /** | |
| 11166 * Set the token representing the 'library' token to the given [token]. | |
| 11167 */ | |
| 11168 @deprecated // Use "this.libraryKeyword" | |
| 11169 set libraryToken(Token token) { | |
| 11170 libraryKeyword = token; | |
| 11171 } | |
| 11172 | |
| 11173 /** | |
| 11174 * Return the name of the library being defined. | |
| 11175 */ | |
| 11176 LibraryIdentifier get name => _name; | |
| 11177 | |
| 11178 /** | |
| 11179 * Set the name of the library being defined to the given [name]. | |
| 11180 */ | |
| 11181 void set name(LibraryIdentifier name) { | |
| 11182 _name = _becomeParentOf(name); | |
| 11183 } | |
| 11184 | |
| 11185 @override | |
| 11186 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this); | |
| 11187 | |
| 11188 @override | |
| 11189 void visitChildren(AstVisitor visitor) { | |
| 11190 super.visitChildren(visitor); | |
| 11191 _safelyVisitChild(_name, visitor); | |
| 11192 } | |
| 11193 } | |
| 11194 | |
| 11195 /** | |
| 11196 * The identifier for a library. | |
| 11197 * | |
| 11198 * > libraryIdentifier ::= | |
| 11199 * > [SimpleIdentifier] ('.' [SimpleIdentifier])* | |
| 11200 */ | |
| 11201 class LibraryIdentifier extends Identifier { | |
| 11202 /** | |
| 11203 * The components of the identifier. | |
| 11204 */ | |
| 11205 NodeList<SimpleIdentifier> _components; | |
| 11206 | |
| 11207 /** | |
| 11208 * Initialize a newly created prefixed identifier. | |
| 11209 */ | |
| 11210 LibraryIdentifier(List<SimpleIdentifier> components) { | |
| 11211 _components = new NodeList<SimpleIdentifier>(this, components); | |
| 11212 } | |
| 11213 | |
| 11214 @override | |
| 11215 Token get beginToken => _components.beginToken; | |
| 11216 | |
| 11217 @override | |
| 11218 Element get bestElement => staticElement; | |
| 11219 | |
| 11220 /** | |
| 11221 * TODO(paulberry): add "." tokens. | |
| 11222 */ | |
| 11223 @override | |
| 11224 Iterable get childEntities => new ChildEntities()..addAll(_components); | |
| 11225 | |
| 11226 /** | |
| 11227 * Return the components of the identifier. | |
| 11228 */ | |
| 11229 NodeList<SimpleIdentifier> get components => _components; | |
| 11230 | |
| 11231 @override | |
| 11232 Token get endToken => _components.endToken; | |
| 11233 | |
| 11234 @override | |
| 11235 String get name { | |
| 11236 StringBuffer buffer = new StringBuffer(); | |
| 11237 bool needsPeriod = false; | |
| 11238 for (SimpleIdentifier identifier in _components) { | |
| 11239 if (needsPeriod) { | |
| 11240 buffer.write("."); | |
| 11241 } else { | |
| 11242 needsPeriod = true; | |
| 11243 } | |
| 11244 buffer.write(identifier.name); | |
| 11245 } | |
| 11246 return buffer.toString(); | |
| 11247 } | |
| 11248 | |
| 11249 @override | |
| 11250 int get precedence => 15; | |
| 11251 | |
| 11252 @override | |
| 11253 Element get propagatedElement => null; | |
| 11254 | |
| 11255 @override | |
| 11256 Element get staticElement => null; | |
| 11257 | |
| 11258 @override | |
| 11259 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this); | |
| 11260 | |
| 11261 @override | |
| 11262 void visitChildren(AstVisitor visitor) { | |
| 11263 _components.accept(visitor); | |
| 11264 } | |
| 11265 } | |
| 11266 | |
| 11267 /** | |
| 11268 * A list literal. | |
| 11269 * | |
| 11270 * > listLiteral ::= | |
| 11271 * > 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']' | |
| 11272 */ | |
| 11273 class ListLiteral extends TypedLiteral { | |
| 11274 /** | |
| 11275 * The left square bracket. | |
| 11276 */ | |
| 11277 Token leftBracket; | |
| 11278 | |
| 11279 /** | |
| 11280 * The expressions used to compute the elements of the list. | |
| 11281 */ | |
| 11282 NodeList<Expression> _elements; | |
| 11283 | |
| 11284 /** | |
| 11285 * The right square bracket. | |
| 11286 */ | |
| 11287 Token rightBracket; | |
| 11288 | |
| 11289 /** | |
| 11290 * Initialize a newly created list literal. The [constKeyword] can be `null` | |
| 11291 * if the literal is not a constant. The [typeArguments] can be `null` if no | |
| 11292 * type arguments were declared. The list of [elements] can be `null` if the | |
| 11293 * list is empty. | |
| 11294 */ | |
| 11295 ListLiteral(Token constKeyword, TypeArgumentList typeArguments, | |
| 11296 this.leftBracket, List<Expression> elements, this.rightBracket) | |
| 11297 : super(constKeyword, typeArguments) { | |
| 11298 _elements = new NodeList<Expression>(this, elements); | |
| 11299 } | |
| 11300 | |
| 11301 @override | |
| 11302 Token get beginToken { | |
| 11303 if (constKeyword != null) { | |
| 11304 return constKeyword; | |
| 11305 } | |
| 11306 TypeArgumentList typeArguments = this.typeArguments; | |
| 11307 if (typeArguments != null) { | |
| 11308 return typeArguments.beginToken; | |
| 11309 } | |
| 11310 return leftBracket; | |
| 11311 } | |
| 11312 | |
| 11313 /** | |
| 11314 * TODO(paulberry): add commas. | |
| 11315 */ | |
| 11316 @override | |
| 11317 Iterable get childEntities => super._childEntities | |
| 11318 ..add(leftBracket) | |
| 11319 ..addAll(_elements) | |
| 11320 ..add(rightBracket); | |
| 11321 | |
| 11322 /** | |
| 11323 * Return the expressions used to compute the elements of the list. | |
| 11324 */ | |
| 11325 NodeList<Expression> get elements => _elements; | |
| 11326 | |
| 11327 @override | |
| 11328 Token get endToken => rightBracket; | |
| 11329 | |
| 11330 @override | |
| 11331 accept(AstVisitor visitor) => visitor.visitListLiteral(this); | |
| 11332 | |
| 11333 @override | |
| 11334 void visitChildren(AstVisitor visitor) { | |
| 11335 super.visitChildren(visitor); | |
| 11336 _elements.accept(visitor); | |
| 11337 } | |
| 11338 } | |
| 11339 | |
| 11340 /** | |
| 11341 * A node that represents a literal expression. | |
| 11342 * | |
| 11343 * > literal ::= | |
| 11344 * > [BooleanLiteral] | |
| 11345 * > | [DoubleLiteral] | |
| 11346 * > | [IntegerLiteral] | |
| 11347 * > | [ListLiteral] | |
| 11348 * > | [MapLiteral] | |
| 11349 * > | [NullLiteral] | |
| 11350 * > | [StringLiteral] | |
| 11351 */ | |
| 11352 abstract class Literal extends Expression { | |
| 11353 @override | |
| 11354 int get precedence => 16; | |
| 11355 } | |
| 11356 | |
| 11357 /** | |
| 11358 * A literal map. | |
| 11359 * | |
| 11360 * > mapLiteral ::= | |
| 11361 * > 'const'? ('<' [TypeName] (',' [TypeName])* '>')? | |
| 11362 * > '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}' | |
| 11363 */ | |
| 11364 class MapLiteral extends TypedLiteral { | |
| 11365 /** | |
| 11366 * The left curly bracket. | |
| 11367 */ | |
| 11368 Token leftBracket; | |
| 11369 | |
| 11370 /** | |
| 11371 * The entries in the map. | |
| 11372 */ | |
| 11373 NodeList<MapLiteralEntry> _entries; | |
| 11374 | |
| 11375 /** | |
| 11376 * The right curly bracket. | |
| 11377 */ | |
| 11378 Token rightBracket; | |
| 11379 | |
| 11380 /** | |
| 11381 * Initialize a newly created map literal. The [constKeyword] can be `null` if | |
| 11382 * the literal is not a constant. The [typeArguments] can be `null` if no type | |
| 11383 * arguments were declared. The [entries] can be `null` if the map is empty. | |
| 11384 */ | |
| 11385 MapLiteral(Token constKeyword, TypeArgumentList typeArguments, | |
| 11386 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket) | |
| 11387 : super(constKeyword, typeArguments) { | |
| 11388 _entries = new NodeList<MapLiteralEntry>(this, entries); | |
| 11389 } | |
| 11390 | |
| 11391 @override | |
| 11392 Token get beginToken { | |
| 11393 if (constKeyword != null) { | |
| 11394 return constKeyword; | |
| 11395 } | |
| 11396 TypeArgumentList typeArguments = this.typeArguments; | |
| 11397 if (typeArguments != null) { | |
| 11398 return typeArguments.beginToken; | |
| 11399 } | |
| 11400 return leftBracket; | |
| 11401 } | |
| 11402 | |
| 11403 /** | |
| 11404 * TODO(paulberry): add commas. | |
| 11405 */ | |
| 11406 @override | |
| 11407 Iterable get childEntities => super._childEntities | |
| 11408 ..add(leftBracket) | |
| 11409 ..addAll(entries) | |
| 11410 ..add(rightBracket); | |
| 11411 | |
| 11412 @override | |
| 11413 Token get endToken => rightBracket; | |
| 11414 | |
| 11415 /** | |
| 11416 * Return the entries in the map. | |
| 11417 */ | |
| 11418 NodeList<MapLiteralEntry> get entries => _entries; | |
| 11419 | |
| 11420 @override | |
| 11421 accept(AstVisitor visitor) => visitor.visitMapLiteral(this); | |
| 11422 | |
| 11423 @override | |
| 11424 void visitChildren(AstVisitor visitor) { | |
| 11425 super.visitChildren(visitor); | |
| 11426 _entries.accept(visitor); | |
| 11427 } | |
| 11428 } | |
| 11429 | |
| 11430 /** | |
| 11431 * A single key/value pair in a map literal. | |
| 11432 * | |
| 11433 * > mapLiteralEntry ::= | |
| 11434 * > [Expression] ':' [Expression] | |
| 11435 */ | |
| 11436 class MapLiteralEntry extends AstNode { | |
| 11437 /** | |
| 11438 * The expression computing the key with which the value will be associated. | |
| 11439 */ | |
| 11440 Expression _key; | |
| 11441 | |
| 11442 /** | |
| 11443 * The colon that separates the key from the value. | |
| 11444 */ | |
| 11445 Token separator; | |
| 11446 | |
| 11447 /** | |
| 11448 * The expression computing the value that will be associated with the key. | |
| 11449 */ | |
| 11450 Expression _value; | |
| 11451 | |
| 11452 /** | |
| 11453 * Initialize a newly created map literal entry. | |
| 11454 */ | |
| 11455 MapLiteralEntry(Expression key, this.separator, Expression value) { | |
| 11456 _key = _becomeParentOf(key); | |
| 11457 _value = _becomeParentOf(value); | |
| 11458 } | |
| 11459 | |
| 11460 @override | |
| 11461 Token get beginToken => _key.beginToken; | |
| 11462 | |
| 11463 @override | |
| 11464 Iterable get childEntities => | |
| 11465 new ChildEntities()..add(_key)..add(separator)..add(_value); | |
| 11466 | |
| 11467 @override | |
| 11468 Token get endToken => _value.endToken; | |
| 11469 | |
| 11470 /** | |
| 11471 * Return the expression computing the key with which the value will be | |
| 11472 * associated. | |
| 11473 */ | |
| 11474 Expression get key => _key; | |
| 11475 | |
| 11476 /** | |
| 11477 * Set the expression computing the key with which the value will be | |
| 11478 * associated to the given [string]. | |
| 11479 */ | |
| 11480 void set key(Expression string) { | |
| 11481 _key = _becomeParentOf(string); | |
| 11482 } | |
| 11483 | |
| 11484 /** | |
| 11485 * Return the expression computing the value that will be associated with the | |
| 11486 * key. | |
| 11487 */ | |
| 11488 Expression get value => _value; | |
| 11489 | |
| 11490 /** | |
| 11491 * Set the expression computing the value that will be associated with the key | |
| 11492 * to the given [expression]. | |
| 11493 */ | |
| 11494 void set value(Expression expression) { | |
| 11495 _value = _becomeParentOf(expression); | |
| 11496 } | |
| 11497 | |
| 11498 @override | |
| 11499 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this); | |
| 11500 | |
| 11501 @override | |
| 11502 void visitChildren(AstVisitor visitor) { | |
| 11503 _safelyVisitChild(_key, visitor); | |
| 11504 _safelyVisitChild(_value, visitor); | |
| 11505 } | |
| 11506 } | |
| 11507 | |
| 11508 /** | |
| 11509 * A method declaration. | |
| 11510 * | |
| 11511 * > methodDeclaration ::= | |
| 11512 * > methodSignature [FunctionBody] | |
| 11513 * > | |
| 11514 * > methodSignature ::= | |
| 11515 * > 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')? | |
| 11516 * > methodName [TypeParameterList] [FormalParameterList] | |
| 11517 * > | |
| 11518 * > methodName ::= | |
| 11519 * > [SimpleIdentifier] | |
| 11520 * > | 'operator' [SimpleIdentifier] | |
| 11521 */ | |
| 11522 class MethodDeclaration extends ClassMember { | |
| 11523 /** | |
| 11524 * The token for the 'external' keyword, or `null` if the constructor is not | |
| 11525 * external. | |
| 11526 */ | |
| 11527 Token externalKeyword; | |
| 11528 | |
| 11529 /** | |
| 11530 * The token representing the 'abstract' or 'static' keyword, or `null` if | |
| 11531 * neither modifier was specified. | |
| 11532 */ | |
| 11533 Token modifierKeyword; | |
| 11534 | |
| 11535 /** | |
| 11536 * The return type of the method, or `null` if no return type was declared. | |
| 11537 */ | |
| 11538 TypeName _returnType; | |
| 11539 | |
| 11540 /** | |
| 11541 * The token representing the 'get' or 'set' keyword, or `null` if this is a | |
| 11542 * method declaration rather than a property declaration. | |
| 11543 */ | |
| 11544 Token propertyKeyword; | |
| 11545 | |
| 11546 /** | |
| 11547 * The token representing the 'operator' keyword, or `null` if this method | |
| 11548 * does not declare an operator. | |
| 11549 */ | |
| 11550 Token operatorKeyword; | |
| 11551 | |
| 11552 /** | |
| 11553 * The name of the method. | |
| 11554 */ | |
| 11555 SimpleIdentifier _name; | |
| 11556 | |
| 11557 /** | |
| 11558 * The type parameters associated with the method, or `null` if the method is | |
| 11559 * not a generic method. | |
| 11560 */ | |
| 11561 TypeParameterList _typeParameters; | |
| 11562 | |
| 11563 /** | |
| 11564 * The parameters associated with the method, or `null` if this method | |
| 11565 * declares a getter. | |
| 11566 */ | |
| 11567 FormalParameterList _parameters; | |
| 11568 | |
| 11569 /** | |
| 11570 * The body of the method. | |
| 11571 */ | |
| 11572 FunctionBody _body; | |
| 11573 | |
| 11574 /** | |
| 11575 * Initialize a newly created method declaration. Either or both of the | |
| 11576 * [comment] and [metadata] can be `null` if the declaration does not have the | |
| 11577 * corresponding attribute. The [externalKeyword] can be `null` if the method | |
| 11578 * is not external. The [modifierKeyword] can be `null` if the method is | |
| 11579 * neither abstract nor static. The [returnType] can be `null` if no return | |
| 11580 * type was specified. The [propertyKeyword] can be `null` if the method is | |
| 11581 * neither a getter or a setter. The [operatorKeyword] can be `null` if the | |
| 11582 * method does not implement an operator. The [parameters] must be `null` if | |
| 11583 * this method declares a getter. | |
| 11584 */ | |
| 11585 MethodDeclaration(Comment comment, List<Annotation> metadata, | |
| 11586 this.externalKeyword, this.modifierKeyword, TypeName returnType, | |
| 11587 this.propertyKeyword, this.operatorKeyword, SimpleIdentifier name, | |
| 11588 TypeParameterList typeParameters, FormalParameterList parameters, | |
| 11589 FunctionBody body) | |
| 11590 : super(comment, metadata) { | |
| 11591 _returnType = _becomeParentOf(returnType); | |
| 11592 _name = _becomeParentOf(name); | |
| 11593 _typeParameters = _becomeParentOf(typeParameters); | |
| 11594 _parameters = _becomeParentOf(parameters); | |
| 11595 _body = _becomeParentOf(body); | |
| 11596 } | |
| 11597 | |
| 11598 /** | |
| 11599 * Return the body of the method. | |
| 11600 */ | |
| 11601 FunctionBody get body => _body; | |
| 11602 | |
| 11603 /** | |
| 11604 * Set the body of the method to the given [functionBody]. | |
| 11605 */ | |
| 11606 void set body(FunctionBody functionBody) { | |
| 11607 _body = _becomeParentOf(functionBody); | |
| 11608 } | |
| 11609 | |
| 11610 @override | |
| 11611 Iterable get childEntities => super._childEntities | |
| 11612 ..add(externalKeyword) | |
| 11613 ..add(modifierKeyword) | |
| 11614 ..add(_returnType) | |
| 11615 ..add(propertyKeyword) | |
| 11616 ..add(operatorKeyword) | |
| 11617 ..add(_name) | |
| 11618 ..add(_parameters) | |
| 11619 ..add(_body); | |
| 11620 | |
| 11621 /** | |
| 11622 * Return the element associated with this method, or `null` if the AST | |
| 11623 * structure has not been resolved. The element can either be a | |
| 11624 * [MethodElement], if this represents the declaration of a normal method, or | |
| 11625 * a [PropertyAccessorElement] if this represents the declaration of either a | |
| 11626 * getter or a setter. | |
| 11627 */ | |
| 11628 @override | |
| 11629 ExecutableElement get element => | |
| 11630 _name != null ? (_name.staticElement as ExecutableElement) : null; | |
| 11631 | |
| 11632 @override | |
| 11633 Token get endToken => _body.endToken; | |
| 11634 | |
| 11635 @override | |
| 11636 Token get firstTokenAfterCommentAndMetadata { | |
| 11637 if (modifierKeyword != null) { | |
| 11638 return modifierKeyword; | |
| 11639 } else if (_returnType != null) { | |
| 11640 return _returnType.beginToken; | |
| 11641 } else if (propertyKeyword != null) { | |
| 11642 return propertyKeyword; | |
| 11643 } else if (operatorKeyword != null) { | |
| 11644 return operatorKeyword; | |
| 11645 } | |
| 11646 return _name.beginToken; | |
| 11647 } | |
| 11648 | |
| 11649 /** | |
| 11650 * Return `true` if this method is declared to be an abstract method. | |
| 11651 */ | |
| 11652 bool get isAbstract { | |
| 11653 FunctionBody body = _body; | |
| 11654 return externalKeyword == null && | |
| 11655 (body is EmptyFunctionBody && !body.semicolon.isSynthetic); | |
| 11656 } | |
| 11657 | |
| 11658 /** | |
| 11659 * Return `true` if this method declares a getter. | |
| 11660 */ | |
| 11661 bool get isGetter => propertyKeyword != null && | |
| 11662 (propertyKeyword as KeywordToken).keyword == Keyword.GET; | |
| 11663 | |
| 11664 /** | |
| 11665 * Return `true` if this method declares an operator. | |
| 11666 */ | |
| 11667 bool get isOperator => operatorKeyword != null; | |
| 11668 | |
| 11669 /** | |
| 11670 * Return `true` if this method declares a setter. | |
| 11671 */ | |
| 11672 bool get isSetter => propertyKeyword != null && | |
| 11673 (propertyKeyword as KeywordToken).keyword == Keyword.SET; | |
| 11674 | |
| 11675 /** | |
| 11676 * Return `true` if this method is declared to be a static method. | |
| 11677 */ | |
| 11678 bool get isStatic => modifierKeyword != null && | |
| 11679 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC; | |
| 11680 | |
| 11681 /** | |
| 11682 * Return the name of the method. | |
| 11683 */ | |
| 11684 SimpleIdentifier get name => _name; | |
| 11685 | |
| 11686 /** | |
| 11687 * Set the name of the method to the given [identifier]. | |
| 11688 */ | |
| 11689 void set name(SimpleIdentifier identifier) { | |
| 11690 _name = _becomeParentOf(identifier); | |
| 11691 } | |
| 11692 | |
| 11693 /** | |
| 11694 * Return the parameters associated with the method, or `null` if this method | |
| 11695 * declares a getter. | |
| 11696 */ | |
| 11697 FormalParameterList get parameters => _parameters; | |
| 11698 | |
| 11699 /** | |
| 11700 * Set the parameters associated with the method to the given list of | |
| 11701 * [parameters]. | |
| 11702 */ | |
| 11703 void set parameters(FormalParameterList parameters) { | |
| 11704 _parameters = _becomeParentOf(parameters); | |
| 11705 } | |
| 11706 | |
| 11707 /** | |
| 11708 * Return the return type of the method, or `null` if no return type was | |
| 11709 * declared. | |
| 11710 */ | |
| 11711 TypeName get returnType => _returnType; | |
| 11712 | |
| 11713 /** | |
| 11714 * Set the return type of the method to the given [typeName]. | |
| 11715 */ | |
| 11716 void set returnType(TypeName typeName) { | |
| 11717 _returnType = _becomeParentOf(typeName); | |
| 11718 } | |
| 11719 | |
| 11720 /** | |
| 11721 * Return the type parameters associated with this method, or `null` if this | |
| 11722 * method is not a generic method. | |
| 11723 */ | |
| 11724 TypeParameterList get typeParameters => _typeParameters; | |
| 11725 | |
| 11726 /** | |
| 11727 * Set the type parameters associated with this method to the given | |
| 11728 * [typeParameters]. | |
| 11729 */ | |
| 11730 void set typeParameters(TypeParameterList typeParameters) { | |
| 11731 _typeParameters = _becomeParentOf(typeParameters); | |
| 11732 } | |
| 11733 | |
| 11734 @override | |
| 11735 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this); | |
| 11736 | |
| 11737 @override | |
| 11738 void visitChildren(AstVisitor visitor) { | |
| 11739 super.visitChildren(visitor); | |
| 11740 _safelyVisitChild(_returnType, visitor); | |
| 11741 _safelyVisitChild(_name, visitor); | |
| 11742 _safelyVisitChild(_typeParameters, visitor); | |
| 11743 _safelyVisitChild(_parameters, visitor); | |
| 11744 _safelyVisitChild(_body, visitor); | |
| 11745 } | |
| 11746 } | |
| 11747 | |
| 11748 /** | |
| 11749 * The invocation of either a function or a method. Invocations of functions | |
| 11750 * resulting from evaluating an expression are represented by | |
| 11751 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are | |
| 11752 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes. | |
| 11753 * | |
| 11754 * > methodInvoction ::= | |
| 11755 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis
t] | |
| 11756 */ | |
| 11757 class MethodInvocation extends Expression { | |
| 11758 /** | |
| 11759 * The expression producing the object on which the method is defined, or | |
| 11760 * `null` if there is no target (that is, the target is implicitly `this`). | |
| 11761 */ | |
| 11762 Expression _target; | |
| 11763 | |
| 11764 /** | |
| 11765 * The operator that separates the target from the method name, or `null` | |
| 11766 * if there is no target. In an ordinary method invocation this will be a | |
| 11767 * period ('.'). In a cascade section this will be the cascade operator | |
| 11768 * ('..'). | |
| 11769 */ | |
| 11770 Token operator; | |
| 11771 | |
| 11772 /** | |
| 11773 * The name of the method being invoked. | |
| 11774 */ | |
| 11775 SimpleIdentifier _methodName; | |
| 11776 | |
| 11777 /** | |
| 11778 * The type arguments to be applied to the method being invoked, or `null` if | |
| 11779 * no type arguments were provided. | |
| 11780 */ | |
| 11781 TypeArgumentList _typeArguments; | |
| 11782 | |
| 11783 /** | |
| 11784 * The list of arguments to the method. | |
| 11785 */ | |
| 11786 ArgumentList _argumentList; | |
| 11787 | |
| 11788 /** | |
| 11789 * Initialize a newly created method invocation. The [target] and [operator] | |
| 11790 * can be `null` if there is no target. | |
| 11791 */ | |
| 11792 MethodInvocation(Expression target, this.operator, | |
| 11793 SimpleIdentifier methodName, TypeArgumentList typeArguments, | |
| 11794 ArgumentList argumentList) { | |
| 11795 _target = _becomeParentOf(target); | |
| 11796 _methodName = _becomeParentOf(methodName); | |
| 11797 _typeArguments = _becomeParentOf(typeArguments); | |
| 11798 _argumentList = _becomeParentOf(argumentList); | |
| 11799 } | |
| 11800 | |
| 11801 /** | |
| 11802 * Return the list of arguments to the method. | |
| 11803 */ | |
| 11804 ArgumentList get argumentList => _argumentList; | |
| 11805 | |
| 11806 /** | |
| 11807 * Set the list of arguments to the method to the given [argumentList]. | |
| 11808 */ | |
| 11809 void set argumentList(ArgumentList argumentList) { | |
| 11810 _argumentList = _becomeParentOf(argumentList); | |
| 11811 } | |
| 11812 | |
| 11813 @override | |
| 11814 Token get beginToken { | |
| 11815 if (_target != null) { | |
| 11816 return _target.beginToken; | |
| 11817 } else if (operator != null) { | |
| 11818 return operator; | |
| 11819 } | |
| 11820 return _methodName.beginToken; | |
| 11821 } | |
| 11822 | |
| 11823 @override | |
| 11824 Iterable get childEntities => new ChildEntities() | |
| 11825 ..add(_target) | |
| 11826 ..add(operator) | |
| 11827 ..add(_methodName) | |
| 11828 ..add(_argumentList); | |
| 11829 | |
| 11830 @override | |
| 11831 Token get endToken => _argumentList.endToken; | |
| 11832 | |
| 11833 /** | |
| 11834 * Return `true` if this expression is cascaded. If it is, then the target of | |
| 11835 * this expression is not stored locally but is stored in the nearest ancestor | |
| 11836 * that is a [CascadeExpression]. | |
| 11837 */ | |
| 11838 bool get isCascaded => | |
| 11839 operator != null && operator.type == TokenType.PERIOD_PERIOD; | |
| 11840 | |
| 11841 /** | |
| 11842 * Return the name of the method being invoked. | |
| 11843 */ | |
| 11844 SimpleIdentifier get methodName => _methodName; | |
| 11845 | |
| 11846 /** | |
| 11847 * Set the name of the method being invoked to the given [identifier]. | |
| 11848 */ | |
| 11849 void set methodName(SimpleIdentifier identifier) { | |
| 11850 _methodName = _becomeParentOf(identifier); | |
| 11851 } | |
| 11852 | |
| 11853 /** | |
| 11854 * The operator that separates the target from the method name, or `null` | |
| 11855 * if there is no target. In an ordinary method invocation this will be a | |
| 11856 * period ('.'). In a cascade section this will be the cascade operator | |
| 11857 * ('..'). | |
| 11858 */ | |
| 11859 @deprecated // Use this.operator | |
| 11860 Token get period => operator; | |
| 11861 | |
| 11862 /** | |
| 11863 * The operator that separates the target from the method name, or `null` | |
| 11864 * if there is no target. In an ordinary method invocation this will be a | |
| 11865 * period ('.'). In a cascade section this will be the cascade operator | |
| 11866 * ('..'). | |
| 11867 */ | |
| 11868 @deprecated // Use this.operator | |
| 11869 void set period(Token value) { | |
| 11870 operator = value; | |
| 11871 } | |
| 11872 | |
| 11873 @override | |
| 11874 int get precedence => 15; | |
| 11875 | |
| 11876 /** | |
| 11877 * Return the expression used to compute the receiver of the invocation. If | |
| 11878 * this invocation is not part of a cascade expression, then this is the same | |
| 11879 * as [target]. If this invocation is part of a cascade expression, then the | |
| 11880 * target stored with the cascade expression is returned. | |
| 11881 */ | |
| 11882 Expression get realTarget { | |
| 11883 if (isCascaded) { | |
| 11884 AstNode ancestor = parent; | |
| 11885 while (ancestor is! CascadeExpression) { | |
| 11886 if (ancestor == null) { | |
| 11887 return _target; | |
| 11888 } | |
| 11889 ancestor = ancestor.parent; | |
| 11890 } | |
| 11891 return (ancestor as CascadeExpression).target; | |
| 11892 } | |
| 11893 return _target; | |
| 11894 } | |
| 11895 | |
| 11896 /** | |
| 11897 * Return the expression producing the object on which the method is defined, | |
| 11898 * or `null` if there is no target (that is, the target is implicitly `this`) | |
| 11899 * or if this method invocation is part of a cascade expression. | |
| 11900 * | |
| 11901 * Use [realTarget] to get the target independent of whether this is part of a | |
| 11902 * cascade expression. | |
| 11903 */ | |
| 11904 Expression get target => _target; | |
| 11905 | |
| 11906 /** | |
| 11907 * Set the expression producing the object on which the method is defined to | |
| 11908 * the given [expression]. | |
| 11909 */ | |
| 11910 void set target(Expression expression) { | |
| 11911 _target = _becomeParentOf(expression); | |
| 11912 } | |
| 11913 | |
| 11914 /** | |
| 11915 * Return the type arguments to be applied to the method being invoked, or | |
| 11916 * `null` if no type arguments were provided. | |
| 11917 */ | |
| 11918 TypeArgumentList get typeArguments => _typeArguments; | |
| 11919 | |
| 11920 /** | |
| 11921 * Set the type arguments to be applied to the method being invoked to the | |
| 11922 * given [typeArguments]. | |
| 11923 */ | |
| 11924 void set typeArguments(TypeArgumentList typeArguments) { | |
| 11925 _typeArguments = _becomeParentOf(typeArguments); | |
| 11926 } | |
| 11927 | |
| 11928 @override | |
| 11929 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this); | |
| 11930 | |
| 11931 @override | |
| 11932 void visitChildren(AstVisitor visitor) { | |
| 11933 _safelyVisitChild(_target, visitor); | |
| 11934 _safelyVisitChild(_methodName, visitor); | |
| 11935 _safelyVisitChild(_typeArguments, visitor); | |
| 11936 _safelyVisitChild(_argumentList, visitor); | |
| 11937 } | |
| 11938 } | |
| 11939 | |
| 11940 /** | |
| 11941 * A node that declares a single name within the scope of a compilation unit. | |
| 11942 */ | |
| 11943 abstract class NamedCompilationUnitMember extends CompilationUnitMember { | |
| 11944 /** | |
| 11945 * The name of the member being declared. | |
| 11946 */ | |
| 11947 SimpleIdentifier _name; | |
| 11948 | |
| 11949 /** | |
| 11950 * Initialize a newly created compilation unit member with the given [name]. | |
| 11951 * Either or both of the [comment] and [metadata] can be `null` if the member | |
| 11952 * does not have the corresponding attribute. | |
| 11953 */ | |
| 11954 NamedCompilationUnitMember( | |
| 11955 Comment comment, List<Annotation> metadata, SimpleIdentifier name) | |
| 11956 : super(comment, metadata) { | |
| 11957 _name = _becomeParentOf(name); | |
| 11958 } | |
| 11959 | |
| 11960 /** | |
| 11961 * Return the name of the member being declared. | |
| 11962 */ | |
| 11963 SimpleIdentifier get name => _name; | |
| 11964 | |
| 11965 /** | |
| 11966 * Set the name of the member being declared to the given [identifier]. | |
| 11967 */ | |
| 11968 void set name(SimpleIdentifier identifier) { | |
| 11969 _name = _becomeParentOf(identifier); | |
| 11970 } | |
| 11971 } | |
| 11972 | |
| 11973 /** | |
| 11974 * An expression that has a name associated with it. They are used in method | |
| 11975 * invocations when there are named parameters. | |
| 11976 * | |
| 11977 * > namedExpression ::= | |
| 11978 * > [Label] [Expression] | |
| 11979 */ | |
| 11980 class NamedExpression extends Expression { | |
| 11981 /** | |
| 11982 * The name associated with the expression. | |
| 11983 */ | |
| 11984 Label _name; | |
| 11985 | |
| 11986 /** | |
| 11987 * The expression with which the name is associated. | |
| 11988 */ | |
| 11989 Expression _expression; | |
| 11990 | |
| 11991 /** | |
| 11992 * Initialize a newly created named expression.. | |
| 11993 */ | |
| 11994 NamedExpression(Label name, Expression expression) { | |
| 11995 _name = _becomeParentOf(name); | |
| 11996 _expression = _becomeParentOf(expression); | |
| 11997 } | |
| 11998 | |
| 11999 @override | |
| 12000 Token get beginToken => _name.beginToken; | |
| 12001 | |
| 12002 @override | |
| 12003 Iterable get childEntities => | |
| 12004 new ChildEntities()..add(_name)..add(_expression); | |
| 12005 | |
| 12006 /** | |
| 12007 * Return the element representing the parameter being named by this | |
| 12008 * expression, or `null` if the AST structure has not been resolved or if | |
| 12009 * there is no parameter with the same name as this expression. | |
| 12010 */ | |
| 12011 ParameterElement get element { | |
| 12012 Element element = _name.label.staticElement; | |
| 12013 if (element is ParameterElement) { | |
| 12014 return element; | |
| 12015 } | |
| 12016 return null; | |
| 12017 } | |
| 12018 | |
| 12019 @override | |
| 12020 Token get endToken => _expression.endToken; | |
| 12021 | |
| 12022 /** | |
| 12023 * Return the expression with which the name is associated. | |
| 12024 */ | |
| 12025 Expression get expression => _expression; | |
| 12026 | |
| 12027 /** | |
| 12028 * Set the expression with which the name is associated to the given | |
| 12029 * [expression]. | |
| 12030 */ | |
| 12031 void set expression(Expression expression) { | |
| 12032 _expression = _becomeParentOf(expression); | |
| 12033 } | |
| 12034 | |
| 12035 /** | |
| 12036 * Return the name associated with the expression. | |
| 12037 */ | |
| 12038 Label get name => _name; | |
| 12039 | |
| 12040 /** | |
| 12041 * Set the name associated with the expression to the given [identifier]. | |
| 12042 */ | |
| 12043 void set name(Label identifier) { | |
| 12044 _name = _becomeParentOf(identifier); | |
| 12045 } | |
| 12046 | |
| 12047 @override | |
| 12048 int get precedence => 0; | |
| 12049 | |
| 12050 @override | |
| 12051 accept(AstVisitor visitor) => visitor.visitNamedExpression(this); | |
| 12052 | |
| 12053 @override | |
| 12054 void visitChildren(AstVisitor visitor) { | |
| 12055 _safelyVisitChild(_name, visitor); | |
| 12056 _safelyVisitChild(_expression, visitor); | |
| 12057 } | |
| 12058 } | |
| 12059 | |
| 12060 /** | |
| 12061 * A node that represents a directive that impacts the namespace of a library. | |
| 12062 * | |
| 12063 * > directive ::= | |
| 12064 * > [ExportDirective] | |
| 12065 * > | [ImportDirective] | |
| 12066 */ | |
| 12067 abstract class NamespaceDirective extends UriBasedDirective { | |
| 12068 /** | |
| 12069 * The token representing the 'import' or 'export' keyword. | |
| 12070 */ | |
| 12071 Token keyword; | |
| 12072 | |
| 12073 /** | |
| 12074 * The combinators used to control which names are imported or exported. | |
| 12075 */ | |
| 12076 NodeList<Combinator> _combinators; | |
| 12077 | |
| 12078 /** | |
| 12079 * The semicolon terminating the directive. | |
| 12080 */ | |
| 12081 Token semicolon; | |
| 12082 | |
| 12083 /** | |
| 12084 * Initialize a newly created namespace directive. Either or both of the | |
| 12085 * [comment] and [metadata] can be `null` if the directive does not have the | |
| 12086 * corresponding attribute. The list of [combinators] can be `null` if there | |
| 12087 * are no combinators. | |
| 12088 */ | |
| 12089 NamespaceDirective(Comment comment, List<Annotation> metadata, this.keyword, | |
| 12090 StringLiteral libraryUri, List<Combinator> combinators, this.semicolon) | |
| 12091 : super(comment, metadata, libraryUri) { | |
| 12092 _combinators = new NodeList<Combinator>(this, combinators); | |
| 12093 } | |
| 12094 | |
| 12095 /** | |
| 12096 * Return the combinators used to control how names are imported or exported. | |
| 12097 */ | |
| 12098 NodeList<Combinator> get combinators => _combinators; | |
| 12099 | |
| 12100 @override | |
| 12101 Token get endToken => semicolon; | |
| 12102 | |
| 12103 @override | |
| 12104 Token get firstTokenAfterCommentAndMetadata => keyword; | |
| 12105 | |
| 12106 @override | |
| 12107 LibraryElement get uriElement; | |
| 12108 } | |
| 12109 | |
| 12110 /** | |
| 12111 * The "native" clause in an class declaration. | |
| 12112 * | |
| 12113 * > nativeClause ::= | |
| 12114 * > 'native' [StringLiteral] | |
| 12115 */ | |
| 12116 class NativeClause extends AstNode { | |
| 12117 /** | |
| 12118 * The token representing the 'native' keyword. | |
| 12119 */ | |
| 12120 Token nativeKeyword; | |
| 12121 | |
| 12122 /** | |
| 12123 * The name of the native object that implements the class. | |
| 12124 */ | |
| 12125 StringLiteral _name; | |
| 12126 | |
| 12127 /** | |
| 12128 * Initialize a newly created native clause. | |
| 12129 */ | |
| 12130 NativeClause(this.nativeKeyword, StringLiteral name) { | |
| 12131 _name = _becomeParentOf(name); | |
| 12132 } | |
| 12133 | |
| 12134 @override | |
| 12135 Token get beginToken => nativeKeyword; | |
| 12136 | |
| 12137 @override | |
| 12138 Iterable get childEntities => | |
| 12139 new ChildEntities()..add(nativeKeyword)..add(_name); | |
| 12140 | |
| 12141 @override | |
| 12142 Token get endToken => _name.endToken; | |
| 12143 | |
| 12144 /** | |
| 12145 * Get the token representing the 'native' keyword. | |
| 12146 */ | |
| 12147 @deprecated // Use "this.nativeKeyword" | |
| 12148 Token get keyword => nativeKeyword; | |
| 12149 | |
| 12150 /** | |
| 12151 * Set the token representing the 'native' keyword to the given [token]. | |
| 12152 */ | |
| 12153 @deprecated // Use "this.nativeKeyword" | |
| 12154 set keyword(Token token) { | |
| 12155 nativeKeyword = token; | |
| 12156 } | |
| 12157 | |
| 12158 /** | |
| 12159 * Return the name of the native object that implements the class. | |
| 12160 */ | |
| 12161 StringLiteral get name => _name; | |
| 12162 | |
| 12163 /** | |
| 12164 * Sets the name of the native object that implements the class to the given | |
| 12165 * [name]. | |
| 12166 */ | |
| 12167 void set name(StringLiteral name) { | |
| 12168 _name = _becomeParentOf(name); | |
| 12169 } | |
| 12170 | |
| 12171 @override | |
| 12172 accept(AstVisitor visitor) => visitor.visitNativeClause(this); | |
| 12173 | |
| 12174 @override | |
| 12175 void visitChildren(AstVisitor visitor) { | |
| 12176 _safelyVisitChild(_name, visitor); | |
| 12177 } | |
| 12178 } | |
| 12179 | |
| 12180 /** | |
| 12181 * A function body that consists of a native keyword followed by a string | |
| 12182 * literal. | |
| 12183 * | |
| 12184 * > nativeFunctionBody ::= | |
| 12185 * > 'native' [SimpleStringLiteral] ';' | |
| 12186 */ | |
| 12187 class NativeFunctionBody extends FunctionBody { | |
| 12188 /** | |
| 12189 * The token representing 'native' that marks the start of the function body. | |
| 12190 */ | |
| 12191 Token nativeKeyword; | |
| 12192 | |
| 12193 /** | |
| 12194 * The string literal, after the 'native' token. | |
| 12195 */ | |
| 12196 StringLiteral _stringLiteral; | |
| 12197 | |
| 12198 /** | |
| 12199 * The token representing the semicolon that marks the end of the function | |
| 12200 * body. | |
| 12201 */ | |
| 12202 Token semicolon; | |
| 12203 | |
| 12204 /** | |
| 12205 * Initialize a newly created function body consisting of the 'native' token, | |
| 12206 * a string literal, and a semicolon. | |
| 12207 */ | |
| 12208 NativeFunctionBody( | |
| 12209 this.nativeKeyword, StringLiteral stringLiteral, this.semicolon) { | |
| 12210 _stringLiteral = _becomeParentOf(stringLiteral); | |
| 12211 } | |
| 12212 | |
| 12213 @override | |
| 12214 Token get beginToken => nativeKeyword; | |
| 12215 | |
| 12216 @override | |
| 12217 Iterable get childEntities => new ChildEntities() | |
| 12218 ..add(nativeKeyword) | |
| 12219 ..add(_stringLiteral) | |
| 12220 ..add(semicolon); | |
| 12221 | |
| 12222 @override | |
| 12223 Token get endToken => semicolon; | |
| 12224 | |
| 12225 /** | |
| 12226 * Return the token representing 'native' that marks the start of the function | |
| 12227 * body. | |
| 12228 */ | |
| 12229 @deprecated // Use "this.nativeKeyword" | |
| 12230 Token get nativeToken => nativeKeyword; | |
| 12231 | |
| 12232 /** | |
| 12233 * Set the token representing 'native' that marks the start of the function | |
| 12234 * body to the given [token]. | |
| 12235 */ | |
| 12236 @deprecated // Use "this.nativeKeyword" | |
| 12237 set nativeToken(Token token) { | |
| 12238 nativeKeyword = token; | |
| 12239 } | |
| 12240 | |
| 12241 /** | |
| 12242 * Return the string literal representing the string after the 'native' token. | |
| 12243 */ | |
| 12244 StringLiteral get stringLiteral => _stringLiteral; | |
| 12245 | |
| 12246 /** | |
| 12247 * Set the string literal representing the string after the 'native' token to | |
| 12248 * the given [stringLiteral]. | |
| 12249 */ | |
| 12250 void set stringLiteral(StringLiteral stringLiteral) { | |
| 12251 _stringLiteral = _becomeParentOf(stringLiteral); | |
| 12252 } | |
| 12253 | |
| 12254 @override | |
| 12255 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this); | |
| 12256 | |
| 12257 @override | |
| 12258 void visitChildren(AstVisitor visitor) { | |
| 12259 _safelyVisitChild(_stringLiteral, visitor); | |
| 12260 } | |
| 12261 } | |
| 12262 | |
| 12263 /** | |
| 12264 * A list of AST nodes that have a common parent. | |
| 12265 */ | |
| 12266 class NodeList<E extends AstNode> extends Object with ListMixin<E> { | |
| 12267 /** | |
| 12268 * The node that is the parent of each of the elements in the list. | |
| 12269 */ | |
| 12270 AstNode owner; | |
| 12271 | |
| 12272 /** | |
| 12273 * The elements contained in the list. | |
| 12274 */ | |
| 12275 List<E> _elements = <E>[]; | |
| 12276 | |
| 12277 /** | |
| 12278 * Initialize a newly created list of nodes such that all of the nodes that | |
| 12279 * are added to the list will have their parent set to the given [owner]. The | |
| 12280 * list will initially be populated with the given [elements]. | |
| 12281 */ | |
| 12282 NodeList(this.owner, [List<E> elements]) { | |
| 12283 addAll(elements); | |
| 12284 } | |
| 12285 | |
| 12286 /** | |
| 12287 * Return the first token included in this node list's source range, or `null` | |
| 12288 * if the list is empty. | |
| 12289 */ | |
| 12290 Token get beginToken { | |
| 12291 if (_elements.length == 0) { | |
| 12292 return null; | |
| 12293 } | |
| 12294 return _elements[0].beginToken; | |
| 12295 } | |
| 12296 | |
| 12297 /** | |
| 12298 * Return the last token included in this node list's source range, or `null` | |
| 12299 * if the list is empty. | |
| 12300 */ | |
| 12301 Token get endToken { | |
| 12302 int length = _elements.length; | |
| 12303 if (length == 0) { | |
| 12304 return null; | |
| 12305 } | |
| 12306 return _elements[length - 1].endToken; | |
| 12307 } | |
| 12308 | |
| 12309 int get length => _elements.length; | |
| 12310 | |
| 12311 @deprecated // Never intended for public use. | |
| 12312 void set length(int value) { | |
| 12313 throw new UnsupportedError("Cannot resize NodeList."); | |
| 12314 } | |
| 12315 | |
| 12316 E operator [](int index) { | |
| 12317 if (index < 0 || index >= _elements.length) { | |
| 12318 throw new RangeError("Index: $index, Size: ${_elements.length}"); | |
| 12319 } | |
| 12320 return _elements[index]; | |
| 12321 } | |
| 12322 | |
| 12323 void operator []=(int index, E node) { | |
| 12324 if (index < 0 || index >= _elements.length) { | |
| 12325 throw new RangeError("Index: $index, Size: ${_elements.length}"); | |
| 12326 } | |
| 12327 owner._becomeParentOf(node); | |
| 12328 _elements[index] = node; | |
| 12329 } | |
| 12330 | |
| 12331 /** | |
| 12332 * Use the given [visitor] to visit each of the nodes in this list. | |
| 12333 */ | |
| 12334 accept(AstVisitor visitor) { | |
| 12335 int length = _elements.length; | |
| 12336 for (var i = 0; i < length; i++) { | |
| 12337 _elements[i].accept(visitor); | |
| 12338 } | |
| 12339 } | |
| 12340 | |
| 12341 @override | |
| 12342 void add(E node) { | |
| 12343 insert(length, node); | |
| 12344 } | |
| 12345 | |
| 12346 @override | |
| 12347 bool addAll(Iterable<E> nodes) { | |
| 12348 if (nodes != null && !nodes.isEmpty) { | |
| 12349 _elements.addAll(nodes); | |
| 12350 for (E node in nodes) { | |
| 12351 owner._becomeParentOf(node); | |
| 12352 } | |
| 12353 return true; | |
| 12354 } | |
| 12355 return false; | |
| 12356 } | |
| 12357 | |
| 12358 @override | |
| 12359 void clear() { | |
| 12360 _elements = <E>[]; | |
| 12361 } | |
| 12362 | |
| 12363 @override | |
| 12364 void insert(int index, E node) { | |
| 12365 int length = _elements.length; | |
| 12366 if (index < 0 || index > length) { | |
| 12367 throw new RangeError("Index: $index, Size: ${_elements.length}"); | |
| 12368 } | |
| 12369 owner._becomeParentOf(node); | |
| 12370 if (length == 0) { | |
| 12371 _elements.add(node); | |
| 12372 } else { | |
| 12373 _elements.insert(index, node); | |
| 12374 } | |
| 12375 } | |
| 12376 | |
| 12377 @override | |
| 12378 E removeAt(int index) { | |
| 12379 if (index < 0 || index >= _elements.length) { | |
| 12380 throw new RangeError("Index: $index, Size: ${_elements.length}"); | |
| 12381 } | |
| 12382 E removedNode = _elements[index]; | |
| 12383 _elements.removeAt(index); | |
| 12384 return removedNode; | |
| 12385 } | |
| 12386 | |
| 12387 /** | |
| 12388 * Create an empty list with the given [owner]. | |
| 12389 */ | |
| 12390 @deprecated // Use "new NodeList<E>(owner)" | |
| 12391 static NodeList create(AstNode owner) => new NodeList(owner); | |
| 12392 } | |
| 12393 | |
| 12394 /** | |
| 12395 * An object used to locate the [AstNode] associated with a source range, given | |
| 12396 * the AST structure built from the source. More specifically, they will return | |
| 12397 * the [AstNode] with the shortest length whose source range completely | |
| 12398 * encompasses the specified range. | |
| 12399 */ | |
| 12400 class NodeLocator extends UnifyingAstVisitor<Object> { | |
| 12401 /** | |
| 12402 * The start offset of the range used to identify the node. | |
| 12403 */ | |
| 12404 int _startOffset = 0; | |
| 12405 | |
| 12406 /** | |
| 12407 * The end offset of the range used to identify the node. | |
| 12408 */ | |
| 12409 int _endOffset = 0; | |
| 12410 | |
| 12411 /** | |
| 12412 * The element that was found that corresponds to the given source range, or | |
| 12413 * `null` if there is no such element. | |
| 12414 */ | |
| 12415 AstNode _foundNode; | |
| 12416 | |
| 12417 /** | |
| 12418 * Initialize a newly created locator to locate an [AstNode] by locating the | |
| 12419 * node within an AST structure that corresponds to the given range of | |
| 12420 * characters (between the [startOffset] and [endOffset] in the source. | |
| 12421 */ | |
| 12422 NodeLocator(int startOffset, [int endOffset]) | |
| 12423 : this._startOffset = startOffset, | |
| 12424 this._endOffset = endOffset == null ? startOffset : endOffset; | |
| 12425 | |
| 12426 /** | |
| 12427 * Initialize a newly created locator to locate an [AstNode] by locating the | |
| 12428 * node within an AST structure that corresponds to the given [offset] in the | |
| 12429 * source. | |
| 12430 */ | |
| 12431 @deprecated // Use new NodeLocator(offset) | |
| 12432 NodeLocator.con1(int offset) : this(offset); | |
| 12433 | |
| 12434 /** | |
| 12435 * Initialize a newly created locator to locate an [AstNode] by locating the | |
| 12436 * node within an AST structure that corresponds to the given range of | |
| 12437 * characters (between the [startOffset] and [endOffset] in the source. | |
| 12438 */ | |
| 12439 @deprecated // Use new NodeLocator(startOffset, endOffset) | |
| 12440 NodeLocator.con2(this._startOffset, this._endOffset); | |
| 12441 | |
| 12442 /** | |
| 12443 * Return the node that was found that corresponds to the given source range | |
| 12444 * or `null` if there is no such node. | |
| 12445 */ | |
| 12446 AstNode get foundNode => _foundNode; | |
| 12447 | |
| 12448 /** | |
| 12449 * Search within the given AST [node] for an identifier representing an | |
| 12450 * element in the specified source range. Return the element that was found, | |
| 12451 * or `null` if no element was found. | |
| 12452 */ | |
| 12453 AstNode searchWithin(AstNode node) { | |
| 12454 if (node == null) { | |
| 12455 return null; | |
| 12456 } | |
| 12457 try { | |
| 12458 node.accept(this); | |
| 12459 } on NodeLocator_NodeFoundException { | |
| 12460 // A node with the right source position was found. | |
| 12461 } catch (exception, stackTrace) { | |
| 12462 AnalysisEngine.instance.logger.logInformation( | |
| 12463 "Unable to locate element at offset ($_startOffset - $_endOffset)", | |
| 12464 new CaughtException(exception, stackTrace)); | |
| 12465 return null; | |
| 12466 } | |
| 12467 return _foundNode; | |
| 12468 } | |
| 12469 | |
| 12470 @override | |
| 12471 Object visitNode(AstNode node) { | |
| 12472 Token beginToken = node.beginToken; | |
| 12473 Token endToken = node.endToken; | |
| 12474 // Don't include synthetic tokens. | |
| 12475 while (endToken != beginToken) { | |
| 12476 if (endToken.type == TokenType.EOF || !endToken.isSynthetic) { | |
| 12477 break; | |
| 12478 } | |
| 12479 endToken = endToken.previous; | |
| 12480 } | |
| 12481 int end = endToken.end; | |
| 12482 int start = node.offset; | |
| 12483 if (end < _startOffset) { | |
| 12484 return null; | |
| 12485 } | |
| 12486 if (start > _endOffset) { | |
| 12487 return null; | |
| 12488 } | |
| 12489 try { | |
| 12490 node.visitChildren(this); | |
| 12491 } on NodeLocator_NodeFoundException { | |
| 12492 rethrow; | |
| 12493 } catch (exception, stackTrace) { | |
| 12494 // Ignore the exception and proceed in order to visit the rest of the | |
| 12495 // structure. | |
| 12496 AnalysisEngine.instance.logger.logInformation( | |
| 12497 "Exception caught while traversing an AST structure.", | |
| 12498 new CaughtException(exception, stackTrace)); | |
| 12499 } | |
| 12500 if (start <= _startOffset && _endOffset <= end) { | |
| 12501 _foundNode = node; | |
| 12502 throw new NodeLocator_NodeFoundException(); | |
| 12503 } | |
| 12504 return null; | |
| 12505 } | |
| 12506 } | |
| 12507 | |
| 12508 /** | |
| 12509 * An exception used by [NodeLocator] to cancel visiting after a node has been | |
| 12510 * found. | |
| 12511 */ | |
| 12512 class NodeLocator_NodeFoundException extends RuntimeException {} | |
| 12513 | |
| 12514 /** | |
| 12515 * An object that will replace one child node in an AST node with another node. | |
| 12516 */ | |
| 12517 class NodeReplacer implements AstVisitor<bool> { | |
| 12518 /** | |
| 12519 * The node being replaced. | |
| 12520 */ | |
| 12521 final AstNode _oldNode; | |
| 12522 | |
| 12523 /** | |
| 12524 * The node that is replacing the old node. | |
| 12525 */ | |
| 12526 final AstNode _newNode; | |
| 12527 | |
| 12528 /** | |
| 12529 * Initialize a newly created node locator to replace the [_oldNode] with the | |
| 12530 * [_newNode]. | |
| 12531 */ | |
| 12532 NodeReplacer(this._oldNode, this._newNode); | |
| 12533 | |
| 12534 @override | |
| 12535 bool visitAdjacentStrings(AdjacentStrings node) { | |
| 12536 if (_replaceInList(node.strings)) { | |
| 12537 return true; | |
| 12538 } | |
| 12539 return visitNode(node); | |
| 12540 } | |
| 12541 | |
| 12542 bool visitAnnotatedNode(AnnotatedNode node) { | |
| 12543 if (identical(node.documentationComment, _oldNode)) { | |
| 12544 node.documentationComment = _newNode as Comment; | |
| 12545 return true; | |
| 12546 } else if (_replaceInList(node.metadata)) { | |
| 12547 return true; | |
| 12548 } | |
| 12549 return visitNode(node); | |
| 12550 } | |
| 12551 | |
| 12552 @override | |
| 12553 bool visitAnnotation(Annotation node) { | |
| 12554 if (identical(node.arguments, _oldNode)) { | |
| 12555 node.arguments = _newNode as ArgumentList; | |
| 12556 return true; | |
| 12557 } else if (identical(node.constructorName, _oldNode)) { | |
| 12558 node.constructorName = _newNode as SimpleIdentifier; | |
| 12559 return true; | |
| 12560 } else if (identical(node.name, _oldNode)) { | |
| 12561 node.name = _newNode as Identifier; | |
| 12562 return true; | |
| 12563 } | |
| 12564 return visitNode(node); | |
| 12565 } | |
| 12566 | |
| 12567 @override | |
| 12568 bool visitArgumentList(ArgumentList node) { | |
| 12569 if (_replaceInList(node.arguments)) { | |
| 12570 return true; | |
| 12571 } | |
| 12572 return visitNode(node); | |
| 12573 } | |
| 12574 | |
| 12575 @override | |
| 12576 bool visitAsExpression(AsExpression node) { | |
| 12577 if (identical(node.expression, _oldNode)) { | |
| 12578 node.expression = _newNode as Expression; | |
| 12579 return true; | |
| 12580 } else if (identical(node.type, _oldNode)) { | |
| 12581 node.type = _newNode as TypeName; | |
| 12582 return true; | |
| 12583 } | |
| 12584 return visitNode(node); | |
| 12585 } | |
| 12586 | |
| 12587 @override | |
| 12588 bool visitAssertStatement(AssertStatement node) { | |
| 12589 if (identical(node.condition, _oldNode)) { | |
| 12590 node.condition = _newNode as Expression; | |
| 12591 return true; | |
| 12592 } | |
| 12593 return visitNode(node); | |
| 12594 } | |
| 12595 | |
| 12596 @override | |
| 12597 bool visitAssignmentExpression(AssignmentExpression node) { | |
| 12598 if (identical(node.leftHandSide, _oldNode)) { | |
| 12599 node.leftHandSide = _newNode as Expression; | |
| 12600 return true; | |
| 12601 } else if (identical(node.rightHandSide, _oldNode)) { | |
| 12602 node.rightHandSide = _newNode as Expression; | |
| 12603 return true; | |
| 12604 } | |
| 12605 return visitNode(node); | |
| 12606 } | |
| 12607 | |
| 12608 @override | |
| 12609 bool visitAwaitExpression(AwaitExpression node) { | |
| 12610 if (identical(node.expression, _oldNode)) { | |
| 12611 node.expression = _newNode as Expression; | |
| 12612 return true; | |
| 12613 } | |
| 12614 return visitNode(node); | |
| 12615 } | |
| 12616 | |
| 12617 @override | |
| 12618 bool visitBinaryExpression(BinaryExpression node) { | |
| 12619 if (identical(node.leftOperand, _oldNode)) { | |
| 12620 node.leftOperand = _newNode as Expression; | |
| 12621 return true; | |
| 12622 } else if (identical(node.rightOperand, _oldNode)) { | |
| 12623 node.rightOperand = _newNode as Expression; | |
| 12624 return true; | |
| 12625 } | |
| 12626 return visitNode(node); | |
| 12627 } | |
| 12628 | |
| 12629 @override | |
| 12630 bool visitBlock(Block node) { | |
| 12631 if (_replaceInList(node.statements)) { | |
| 12632 return true; | |
| 12633 } | |
| 12634 return visitNode(node); | |
| 12635 } | |
| 12636 | |
| 12637 @override | |
| 12638 bool visitBlockFunctionBody(BlockFunctionBody node) { | |
| 12639 if (identical(node.block, _oldNode)) { | |
| 12640 node.block = _newNode as Block; | |
| 12641 return true; | |
| 12642 } | |
| 12643 return visitNode(node); | |
| 12644 } | |
| 12645 | |
| 12646 @override | |
| 12647 bool visitBooleanLiteral(BooleanLiteral node) => visitNode(node); | |
| 12648 | |
| 12649 @override | |
| 12650 bool visitBreakStatement(BreakStatement node) { | |
| 12651 if (identical(node.label, _oldNode)) { | |
| 12652 node.label = _newNode as SimpleIdentifier; | |
| 12653 return true; | |
| 12654 } | |
| 12655 return visitNode(node); | |
| 12656 } | |
| 12657 | |
| 12658 @override | |
| 12659 bool visitCascadeExpression(CascadeExpression node) { | |
| 12660 if (identical(node.target, _oldNode)) { | |
| 12661 node.target = _newNode as Expression; | |
| 12662 return true; | |
| 12663 } else if (_replaceInList(node.cascadeSections)) { | |
| 12664 return true; | |
| 12665 } | |
| 12666 return visitNode(node); | |
| 12667 } | |
| 12668 | |
| 12669 @override | |
| 12670 bool visitCatchClause(CatchClause node) { | |
| 12671 if (identical(node.exceptionType, _oldNode)) { | |
| 12672 node.exceptionType = _newNode as TypeName; | |
| 12673 return true; | |
| 12674 } else if (identical(node.exceptionParameter, _oldNode)) { | |
| 12675 node.exceptionParameter = _newNode as SimpleIdentifier; | |
| 12676 return true; | |
| 12677 } else if (identical(node.stackTraceParameter, _oldNode)) { | |
| 12678 node.stackTraceParameter = _newNode as SimpleIdentifier; | |
| 12679 return true; | |
| 12680 } | |
| 12681 return visitNode(node); | |
| 12682 } | |
| 12683 | |
| 12684 @override | |
| 12685 bool visitClassDeclaration(ClassDeclaration node) { | |
| 12686 if (identical(node.name, _oldNode)) { | |
| 12687 node.name = _newNode as SimpleIdentifier; | |
| 12688 return true; | |
| 12689 } else if (identical(node.typeParameters, _oldNode)) { | |
| 12690 node.typeParameters = _newNode as TypeParameterList; | |
| 12691 return true; | |
| 12692 } else if (identical(node.extendsClause, _oldNode)) { | |
| 12693 node.extendsClause = _newNode as ExtendsClause; | |
| 12694 return true; | |
| 12695 } else if (identical(node.withClause, _oldNode)) { | |
| 12696 node.withClause = _newNode as WithClause; | |
| 12697 return true; | |
| 12698 } else if (identical(node.implementsClause, _oldNode)) { | |
| 12699 node.implementsClause = _newNode as ImplementsClause; | |
| 12700 return true; | |
| 12701 } else if (identical(node.nativeClause, _oldNode)) { | |
| 12702 node.nativeClause = _newNode as NativeClause; | |
| 12703 return true; | |
| 12704 } else if (_replaceInList(node.members)) { | |
| 12705 return true; | |
| 12706 } | |
| 12707 return visitAnnotatedNode(node); | |
| 12708 } | |
| 12709 | |
| 12710 @override | |
| 12711 bool visitClassTypeAlias(ClassTypeAlias node) { | |
| 12712 if (identical(node.name, _oldNode)) { | |
| 12713 node.name = _newNode as SimpleIdentifier; | |
| 12714 return true; | |
| 12715 } else if (identical(node.typeParameters, _oldNode)) { | |
| 12716 node.typeParameters = _newNode as TypeParameterList; | |
| 12717 return true; | |
| 12718 } else if (identical(node.superclass, _oldNode)) { | |
| 12719 node.superclass = _newNode as TypeName; | |
| 12720 return true; | |
| 12721 } else if (identical(node.withClause, _oldNode)) { | |
| 12722 node.withClause = _newNode as WithClause; | |
| 12723 return true; | |
| 12724 } else if (identical(node.implementsClause, _oldNode)) { | |
| 12725 node.implementsClause = _newNode as ImplementsClause; | |
| 12726 return true; | |
| 12727 } | |
| 12728 return visitAnnotatedNode(node); | |
| 12729 } | |
| 12730 | |
| 12731 @override | |
| 12732 bool visitComment(Comment node) { | |
| 12733 if (_replaceInList(node.references)) { | |
| 12734 return true; | |
| 12735 } | |
| 12736 return visitNode(node); | |
| 12737 } | |
| 12738 | |
| 12739 @override | |
| 12740 bool visitCommentReference(CommentReference node) { | |
| 12741 if (identical(node.identifier, _oldNode)) { | |
| 12742 node.identifier = _newNode as Identifier; | |
| 12743 return true; | |
| 12744 } | |
| 12745 return visitNode(node); | |
| 12746 } | |
| 12747 | |
| 12748 @override | |
| 12749 bool visitCompilationUnit(CompilationUnit node) { | |
| 12750 if (identical(node.scriptTag, _oldNode)) { | |
| 12751 node.scriptTag = _newNode as ScriptTag; | |
| 12752 return true; | |
| 12753 } else if (_replaceInList(node.directives)) { | |
| 12754 return true; | |
| 12755 } else if (_replaceInList(node.declarations)) { | |
| 12756 return true; | |
| 12757 } | |
| 12758 return visitNode(node); | |
| 12759 } | |
| 12760 | |
| 12761 @override | |
| 12762 bool visitConditionalExpression(ConditionalExpression node) { | |
| 12763 if (identical(node.condition, _oldNode)) { | |
| 12764 node.condition = _newNode as Expression; | |
| 12765 return true; | |
| 12766 } else if (identical(node.thenExpression, _oldNode)) { | |
| 12767 node.thenExpression = _newNode as Expression; | |
| 12768 return true; | |
| 12769 } else if (identical(node.elseExpression, _oldNode)) { | |
| 12770 node.elseExpression = _newNode as Expression; | |
| 12771 return true; | |
| 12772 } | |
| 12773 return visitNode(node); | |
| 12774 } | |
| 12775 | |
| 12776 @override | |
| 12777 bool visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 12778 if (identical(node.returnType, _oldNode)) { | |
| 12779 node.returnType = _newNode as Identifier; | |
| 12780 return true; | |
| 12781 } else if (identical(node.name, _oldNode)) { | |
| 12782 node.name = _newNode as SimpleIdentifier; | |
| 12783 return true; | |
| 12784 } else if (identical(node.parameters, _oldNode)) { | |
| 12785 node.parameters = _newNode as FormalParameterList; | |
| 12786 return true; | |
| 12787 } else if (identical(node.redirectedConstructor, _oldNode)) { | |
| 12788 node.redirectedConstructor = _newNode as ConstructorName; | |
| 12789 return true; | |
| 12790 } else if (identical(node.body, _oldNode)) { | |
| 12791 node.body = _newNode as FunctionBody; | |
| 12792 return true; | |
| 12793 } else if (_replaceInList(node.initializers)) { | |
| 12794 return true; | |
| 12795 } | |
| 12796 return visitAnnotatedNode(node); | |
| 12797 } | |
| 12798 | |
| 12799 @override | |
| 12800 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 12801 if (identical(node.fieldName, _oldNode)) { | |
| 12802 node.fieldName = _newNode as SimpleIdentifier; | |
| 12803 return true; | |
| 12804 } else if (identical(node.expression, _oldNode)) { | |
| 12805 node.expression = _newNode as Expression; | |
| 12806 return true; | |
| 12807 } | |
| 12808 return visitNode(node); | |
| 12809 } | |
| 12810 | |
| 12811 @override | |
| 12812 bool visitConstructorName(ConstructorName node) { | |
| 12813 if (identical(node.type, _oldNode)) { | |
| 12814 node.type = _newNode as TypeName; | |
| 12815 return true; | |
| 12816 } else if (identical(node.name, _oldNode)) { | |
| 12817 node.name = _newNode as SimpleIdentifier; | |
| 12818 return true; | |
| 12819 } | |
| 12820 return visitNode(node); | |
| 12821 } | |
| 12822 | |
| 12823 @override | |
| 12824 bool visitContinueStatement(ContinueStatement node) { | |
| 12825 if (identical(node.label, _oldNode)) { | |
| 12826 node.label = _newNode as SimpleIdentifier; | |
| 12827 return true; | |
| 12828 } | |
| 12829 return visitNode(node); | |
| 12830 } | |
| 12831 | |
| 12832 @override | |
| 12833 bool visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 12834 if (identical(node.type, _oldNode)) { | |
| 12835 node.type = _newNode as TypeName; | |
| 12836 return true; | |
| 12837 } else if (identical(node.identifier, _oldNode)) { | |
| 12838 node.identifier = _newNode as SimpleIdentifier; | |
| 12839 return true; | |
| 12840 } | |
| 12841 return visitAnnotatedNode(node); | |
| 12842 } | |
| 12843 | |
| 12844 @override | |
| 12845 bool visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 12846 if (identical(node.parameter, _oldNode)) { | |
| 12847 node.parameter = _newNode as NormalFormalParameter; | |
| 12848 return true; | |
| 12849 } else if (identical(node.defaultValue, _oldNode)) { | |
| 12850 node.defaultValue = _newNode as Expression; | |
| 12851 return true; | |
| 12852 } | |
| 12853 return visitNode(node); | |
| 12854 } | |
| 12855 | |
| 12856 @override | |
| 12857 bool visitDoStatement(DoStatement node) { | |
| 12858 if (identical(node.body, _oldNode)) { | |
| 12859 node.body = _newNode as Statement; | |
| 12860 return true; | |
| 12861 } else if (identical(node.condition, _oldNode)) { | |
| 12862 node.condition = _newNode as Expression; | |
| 12863 return true; | |
| 12864 } | |
| 12865 return visitNode(node); | |
| 12866 } | |
| 12867 | |
| 12868 @override | |
| 12869 bool visitDoubleLiteral(DoubleLiteral node) => visitNode(node); | |
| 12870 | |
| 12871 @override | |
| 12872 bool visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node); | |
| 12873 | |
| 12874 @override | |
| 12875 bool visitEmptyStatement(EmptyStatement node) => visitNode(node); | |
| 12876 | |
| 12877 @override | |
| 12878 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 12879 if (identical(node.name, _oldNode)) { | |
| 12880 node.name = _newNode as SimpleIdentifier; | |
| 12881 return true; | |
| 12882 } | |
| 12883 return visitAnnotatedNode(node); | |
| 12884 } | |
| 12885 | |
| 12886 @override | |
| 12887 bool visitEnumDeclaration(EnumDeclaration node) { | |
| 12888 if (identical(node.name, _oldNode)) { | |
| 12889 node.name = _newNode as SimpleIdentifier; | |
| 12890 return true; | |
| 12891 } else if (_replaceInList(node.constants)) { | |
| 12892 return true; | |
| 12893 } | |
| 12894 return visitAnnotatedNode(node); | |
| 12895 } | |
| 12896 | |
| 12897 @override | |
| 12898 bool visitExportDirective(ExportDirective node) => | |
| 12899 visitNamespaceDirective(node); | |
| 12900 | |
| 12901 @override | |
| 12902 bool visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 12903 if (identical(node.expression, _oldNode)) { | |
| 12904 node.expression = _newNode as Expression; | |
| 12905 return true; | |
| 12906 } | |
| 12907 return visitNode(node); | |
| 12908 } | |
| 12909 | |
| 12910 @override | |
| 12911 bool visitExpressionStatement(ExpressionStatement node) { | |
| 12912 if (identical(node.expression, _oldNode)) { | |
| 12913 node.expression = _newNode as Expression; | |
| 12914 return true; | |
| 12915 } | |
| 12916 return visitNode(node); | |
| 12917 } | |
| 12918 | |
| 12919 @override | |
| 12920 bool visitExtendsClause(ExtendsClause node) { | |
| 12921 if (identical(node.superclass, _oldNode)) { | |
| 12922 node.superclass = _newNode as TypeName; | |
| 12923 return true; | |
| 12924 } | |
| 12925 return visitNode(node); | |
| 12926 } | |
| 12927 | |
| 12928 @override | |
| 12929 bool visitFieldDeclaration(FieldDeclaration node) { | |
| 12930 if (identical(node.fields, _oldNode)) { | |
| 12931 node.fields = _newNode as VariableDeclarationList; | |
| 12932 return true; | |
| 12933 } | |
| 12934 return visitAnnotatedNode(node); | |
| 12935 } | |
| 12936 | |
| 12937 @override | |
| 12938 bool visitFieldFormalParameter(FieldFormalParameter node) { | |
| 12939 if (identical(node.type, _oldNode)) { | |
| 12940 node.type = _newNode as TypeName; | |
| 12941 return true; | |
| 12942 } else if (identical(node.parameters, _oldNode)) { | |
| 12943 node.parameters = _newNode as FormalParameterList; | |
| 12944 return true; | |
| 12945 } | |
| 12946 return visitNormalFormalParameter(node); | |
| 12947 } | |
| 12948 | |
| 12949 @override | |
| 12950 bool visitForEachStatement(ForEachStatement node) { | |
| 12951 if (identical(node.loopVariable, _oldNode)) { | |
| 12952 node.loopVariable = _newNode as DeclaredIdentifier; | |
| 12953 return true; | |
| 12954 } else if (identical(node.identifier, _oldNode)) { | |
| 12955 node.identifier = _newNode as SimpleIdentifier; | |
| 12956 return true; | |
| 12957 } else if (identical(node.iterable, _oldNode)) { | |
| 12958 node.iterable = _newNode as Expression; | |
| 12959 return true; | |
| 12960 } else if (identical(node.body, _oldNode)) { | |
| 12961 node.body = _newNode as Statement; | |
| 12962 return true; | |
| 12963 } | |
| 12964 return visitNode(node); | |
| 12965 } | |
| 12966 | |
| 12967 @override | |
| 12968 bool visitFormalParameterList(FormalParameterList node) { | |
| 12969 if (_replaceInList(node.parameters)) { | |
| 12970 return true; | |
| 12971 } | |
| 12972 return visitNode(node); | |
| 12973 } | |
| 12974 | |
| 12975 @override | |
| 12976 bool visitForStatement(ForStatement node) { | |
| 12977 if (identical(node.variables, _oldNode)) { | |
| 12978 node.variables = _newNode as VariableDeclarationList; | |
| 12979 return true; | |
| 12980 } else if (identical(node.initialization, _oldNode)) { | |
| 12981 node.initialization = _newNode as Expression; | |
| 12982 return true; | |
| 12983 } else if (identical(node.condition, _oldNode)) { | |
| 12984 node.condition = _newNode as Expression; | |
| 12985 return true; | |
| 12986 } else if (identical(node.body, _oldNode)) { | |
| 12987 node.body = _newNode as Statement; | |
| 12988 return true; | |
| 12989 } else if (_replaceInList(node.updaters)) { | |
| 12990 return true; | |
| 12991 } | |
| 12992 return visitNode(node); | |
| 12993 } | |
| 12994 | |
| 12995 @override | |
| 12996 bool visitFunctionDeclaration(FunctionDeclaration node) { | |
| 12997 if (identical(node.returnType, _oldNode)) { | |
| 12998 node.returnType = _newNode as TypeName; | |
| 12999 return true; | |
| 13000 } else if (identical(node.name, _oldNode)) { | |
| 13001 node.name = _newNode as SimpleIdentifier; | |
| 13002 return true; | |
| 13003 } else if (identical(node.functionExpression, _oldNode)) { | |
| 13004 node.functionExpression = _newNode as FunctionExpression; | |
| 13005 return true; | |
| 13006 } | |
| 13007 return visitAnnotatedNode(node); | |
| 13008 } | |
| 13009 | |
| 13010 @override | |
| 13011 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 13012 if (identical(node.functionDeclaration, _oldNode)) { | |
| 13013 node.functionDeclaration = _newNode as FunctionDeclaration; | |
| 13014 return true; | |
| 13015 } | |
| 13016 return visitNode(node); | |
| 13017 } | |
| 13018 | |
| 13019 @override | |
| 13020 bool visitFunctionExpression(FunctionExpression node) { | |
| 13021 if (identical(node.parameters, _oldNode)) { | |
| 13022 node.parameters = _newNode as FormalParameterList; | |
| 13023 return true; | |
| 13024 } else if (identical(node.body, _oldNode)) { | |
| 13025 node.body = _newNode as FunctionBody; | |
| 13026 return true; | |
| 13027 } | |
| 13028 return visitNode(node); | |
| 13029 } | |
| 13030 | |
| 13031 @override | |
| 13032 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 13033 if (identical(node.function, _oldNode)) { | |
| 13034 node.function = _newNode as Expression; | |
| 13035 return true; | |
| 13036 } else if (identical(node.argumentList, _oldNode)) { | |
| 13037 node.argumentList = _newNode as ArgumentList; | |
| 13038 return true; | |
| 13039 } | |
| 13040 return visitNode(node); | |
| 13041 } | |
| 13042 | |
| 13043 @override | |
| 13044 bool visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 13045 if (identical(node.returnType, _oldNode)) { | |
| 13046 node.returnType = _newNode as TypeName; | |
| 13047 return true; | |
| 13048 } else if (identical(node.name, _oldNode)) { | |
| 13049 node.name = _newNode as SimpleIdentifier; | |
| 13050 return true; | |
| 13051 } else if (identical(node.typeParameters, _oldNode)) { | |
| 13052 node.typeParameters = _newNode as TypeParameterList; | |
| 13053 return true; | |
| 13054 } else if (identical(node.parameters, _oldNode)) { | |
| 13055 node.parameters = _newNode as FormalParameterList; | |
| 13056 return true; | |
| 13057 } | |
| 13058 return visitAnnotatedNode(node); | |
| 13059 } | |
| 13060 | |
| 13061 @override | |
| 13062 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 13063 if (identical(node.returnType, _oldNode)) { | |
| 13064 node.returnType = _newNode as TypeName; | |
| 13065 return true; | |
| 13066 } else if (identical(node.parameters, _oldNode)) { | |
| 13067 node.parameters = _newNode as FormalParameterList; | |
| 13068 return true; | |
| 13069 } | |
| 13070 return visitNormalFormalParameter(node); | |
| 13071 } | |
| 13072 | |
| 13073 @override | |
| 13074 bool visitHideCombinator(HideCombinator node) { | |
| 13075 if (_replaceInList(node.hiddenNames)) { | |
| 13076 return true; | |
| 13077 } | |
| 13078 return visitNode(node); | |
| 13079 } | |
| 13080 | |
| 13081 @override | |
| 13082 bool visitIfStatement(IfStatement node) { | |
| 13083 if (identical(node.condition, _oldNode)) { | |
| 13084 node.condition = _newNode as Expression; | |
| 13085 return true; | |
| 13086 } else if (identical(node.thenStatement, _oldNode)) { | |
| 13087 node.thenStatement = _newNode as Statement; | |
| 13088 return true; | |
| 13089 } else if (identical(node.elseStatement, _oldNode)) { | |
| 13090 node.elseStatement = _newNode as Statement; | |
| 13091 return true; | |
| 13092 } | |
| 13093 return visitNode(node); | |
| 13094 } | |
| 13095 | |
| 13096 @override | |
| 13097 bool visitImplementsClause(ImplementsClause node) { | |
| 13098 if (_replaceInList(node.interfaces)) { | |
| 13099 return true; | |
| 13100 } | |
| 13101 return visitNode(node); | |
| 13102 } | |
| 13103 | |
| 13104 @override | |
| 13105 bool visitImportDirective(ImportDirective node) { | |
| 13106 if (identical(node.prefix, _oldNode)) { | |
| 13107 node.prefix = _newNode as SimpleIdentifier; | |
| 13108 return true; | |
| 13109 } | |
| 13110 return visitNamespaceDirective(node); | |
| 13111 } | |
| 13112 | |
| 13113 @override | |
| 13114 bool visitIndexExpression(IndexExpression node) { | |
| 13115 if (identical(node.target, _oldNode)) { | |
| 13116 node.target = _newNode as Expression; | |
| 13117 return true; | |
| 13118 } else if (identical(node.index, _oldNode)) { | |
| 13119 node.index = _newNode as Expression; | |
| 13120 return true; | |
| 13121 } | |
| 13122 return visitNode(node); | |
| 13123 } | |
| 13124 | |
| 13125 @override | |
| 13126 bool visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 13127 if (identical(node.constructorName, _oldNode)) { | |
| 13128 node.constructorName = _newNode as ConstructorName; | |
| 13129 return true; | |
| 13130 } else if (identical(node.argumentList, _oldNode)) { | |
| 13131 node.argumentList = _newNode as ArgumentList; | |
| 13132 return true; | |
| 13133 } | |
| 13134 return visitNode(node); | |
| 13135 } | |
| 13136 | |
| 13137 @override | |
| 13138 bool visitIntegerLiteral(IntegerLiteral node) => visitNode(node); | |
| 13139 | |
| 13140 @override | |
| 13141 bool visitInterpolationExpression(InterpolationExpression node) { | |
| 13142 if (identical(node.expression, _oldNode)) { | |
| 13143 node.expression = _newNode as Expression; | |
| 13144 return true; | |
| 13145 } | |
| 13146 return visitNode(node); | |
| 13147 } | |
| 13148 | |
| 13149 @override | |
| 13150 bool visitInterpolationString(InterpolationString node) => visitNode(node); | |
| 13151 | |
| 13152 @override | |
| 13153 bool visitIsExpression(IsExpression node) { | |
| 13154 if (identical(node.expression, _oldNode)) { | |
| 13155 node.expression = _newNode as Expression; | |
| 13156 return true; | |
| 13157 } else if (identical(node.type, _oldNode)) { | |
| 13158 node.type = _newNode as TypeName; | |
| 13159 return true; | |
| 13160 } | |
| 13161 return visitNode(node); | |
| 13162 } | |
| 13163 | |
| 13164 @override | |
| 13165 bool visitLabel(Label node) { | |
| 13166 if (identical(node.label, _oldNode)) { | |
| 13167 node.label = _newNode as SimpleIdentifier; | |
| 13168 return true; | |
| 13169 } | |
| 13170 return visitNode(node); | |
| 13171 } | |
| 13172 | |
| 13173 @override | |
| 13174 bool visitLabeledStatement(LabeledStatement node) { | |
| 13175 if (identical(node.statement, _oldNode)) { | |
| 13176 node.statement = _newNode as Statement; | |
| 13177 return true; | |
| 13178 } else if (_replaceInList(node.labels)) { | |
| 13179 return true; | |
| 13180 } | |
| 13181 return visitNode(node); | |
| 13182 } | |
| 13183 | |
| 13184 @override | |
| 13185 bool visitLibraryDirective(LibraryDirective node) { | |
| 13186 if (identical(node.name, _oldNode)) { | |
| 13187 node.name = _newNode as LibraryIdentifier; | |
| 13188 return true; | |
| 13189 } | |
| 13190 return visitAnnotatedNode(node); | |
| 13191 } | |
| 13192 | |
| 13193 @override | |
| 13194 bool visitLibraryIdentifier(LibraryIdentifier node) { | |
| 13195 if (_replaceInList(node.components)) { | |
| 13196 return true; | |
| 13197 } | |
| 13198 return visitNode(node); | |
| 13199 } | |
| 13200 | |
| 13201 @override | |
| 13202 bool visitListLiteral(ListLiteral node) { | |
| 13203 if (_replaceInList(node.elements)) { | |
| 13204 return true; | |
| 13205 } | |
| 13206 return visitTypedLiteral(node); | |
| 13207 } | |
| 13208 | |
| 13209 @override | |
| 13210 bool visitMapLiteral(MapLiteral node) { | |
| 13211 if (_replaceInList(node.entries)) { | |
| 13212 return true; | |
| 13213 } | |
| 13214 return visitTypedLiteral(node); | |
| 13215 } | |
| 13216 | |
| 13217 @override | |
| 13218 bool visitMapLiteralEntry(MapLiteralEntry node) { | |
| 13219 if (identical(node.key, _oldNode)) { | |
| 13220 node.key = _newNode as Expression; | |
| 13221 return true; | |
| 13222 } else if (identical(node.value, _oldNode)) { | |
| 13223 node.value = _newNode as Expression; | |
| 13224 return true; | |
| 13225 } | |
| 13226 return visitNode(node); | |
| 13227 } | |
| 13228 | |
| 13229 @override | |
| 13230 bool visitMethodDeclaration(MethodDeclaration node) { | |
| 13231 if (identical(node.returnType, _oldNode)) { | |
| 13232 node.returnType = _newNode as TypeName; | |
| 13233 return true; | |
| 13234 } else if (identical(node.name, _oldNode)) { | |
| 13235 node.name = _newNode as SimpleIdentifier; | |
| 13236 return true; | |
| 13237 } else if (identical(node.parameters, _oldNode)) { | |
| 13238 node.parameters = _newNode as FormalParameterList; | |
| 13239 return true; | |
| 13240 } else if (identical(node.body, _oldNode)) { | |
| 13241 node.body = _newNode as FunctionBody; | |
| 13242 return true; | |
| 13243 } | |
| 13244 return visitAnnotatedNode(node); | |
| 13245 } | |
| 13246 | |
| 13247 @override | |
| 13248 bool visitMethodInvocation(MethodInvocation node) { | |
| 13249 if (identical(node.target, _oldNode)) { | |
| 13250 node.target = _newNode as Expression; | |
| 13251 return true; | |
| 13252 } else if (identical(node.methodName, _oldNode)) { | |
| 13253 node.methodName = _newNode as SimpleIdentifier; | |
| 13254 return true; | |
| 13255 } else if (identical(node.argumentList, _oldNode)) { | |
| 13256 node.argumentList = _newNode as ArgumentList; | |
| 13257 return true; | |
| 13258 } | |
| 13259 return visitNode(node); | |
| 13260 } | |
| 13261 | |
| 13262 @override | |
| 13263 bool visitNamedExpression(NamedExpression node) { | |
| 13264 if (identical(node.name, _oldNode)) { | |
| 13265 node.name = _newNode as Label; | |
| 13266 return true; | |
| 13267 } else if (identical(node.expression, _oldNode)) { | |
| 13268 node.expression = _newNode as Expression; | |
| 13269 return true; | |
| 13270 } | |
| 13271 return visitNode(node); | |
| 13272 } | |
| 13273 | |
| 13274 bool visitNamespaceDirective(NamespaceDirective node) { | |
| 13275 if (_replaceInList(node.combinators)) { | |
| 13276 return true; | |
| 13277 } | |
| 13278 return visitUriBasedDirective(node); | |
| 13279 } | |
| 13280 | |
| 13281 @override | |
| 13282 bool visitNativeClause(NativeClause node) { | |
| 13283 if (identical(node.name, _oldNode)) { | |
| 13284 node.name = _newNode as StringLiteral; | |
| 13285 return true; | |
| 13286 } | |
| 13287 return visitNode(node); | |
| 13288 } | |
| 13289 | |
| 13290 @override | |
| 13291 bool visitNativeFunctionBody(NativeFunctionBody node) { | |
| 13292 if (identical(node.stringLiteral, _oldNode)) { | |
| 13293 node.stringLiteral = _newNode as StringLiteral; | |
| 13294 return true; | |
| 13295 } | |
| 13296 return visitNode(node); | |
| 13297 } | |
| 13298 | |
| 13299 bool visitNode(AstNode node) { | |
| 13300 throw new IllegalArgumentException( | |
| 13301 "The old node is not a child of it's parent"); | |
| 13302 } | |
| 13303 | |
| 13304 bool visitNormalFormalParameter(NormalFormalParameter node) { | |
| 13305 if (identical(node.documentationComment, _oldNode)) { | |
| 13306 node.documentationComment = _newNode as Comment; | |
| 13307 return true; | |
| 13308 } else if (identical(node.identifier, _oldNode)) { | |
| 13309 node.identifier = _newNode as SimpleIdentifier; | |
| 13310 return true; | |
| 13311 } else if (_replaceInList(node.metadata)) { | |
| 13312 return true; | |
| 13313 } | |
| 13314 return visitNode(node); | |
| 13315 } | |
| 13316 | |
| 13317 @override | |
| 13318 bool visitNullLiteral(NullLiteral node) => visitNode(node); | |
| 13319 | |
| 13320 @override | |
| 13321 bool visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 13322 if (identical(node.expression, _oldNode)) { | |
| 13323 node.expression = _newNode as Expression; | |
| 13324 return true; | |
| 13325 } | |
| 13326 return visitNode(node); | |
| 13327 } | |
| 13328 | |
| 13329 @override | |
| 13330 bool visitPartDirective(PartDirective node) => visitUriBasedDirective(node); | |
| 13331 | |
| 13332 @override | |
| 13333 bool visitPartOfDirective(PartOfDirective node) { | |
| 13334 if (identical(node.libraryName, _oldNode)) { | |
| 13335 node.libraryName = _newNode as LibraryIdentifier; | |
| 13336 return true; | |
| 13337 } | |
| 13338 return visitAnnotatedNode(node); | |
| 13339 } | |
| 13340 | |
| 13341 @override | |
| 13342 bool visitPostfixExpression(PostfixExpression node) { | |
| 13343 if (identical(node.operand, _oldNode)) { | |
| 13344 node.operand = _newNode as Expression; | |
| 13345 return true; | |
| 13346 } | |
| 13347 return visitNode(node); | |
| 13348 } | |
| 13349 | |
| 13350 @override | |
| 13351 bool visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 13352 if (identical(node.prefix, _oldNode)) { | |
| 13353 node.prefix = _newNode as SimpleIdentifier; | |
| 13354 return true; | |
| 13355 } else if (identical(node.identifier, _oldNode)) { | |
| 13356 node.identifier = _newNode as SimpleIdentifier; | |
| 13357 return true; | |
| 13358 } | |
| 13359 return visitNode(node); | |
| 13360 } | |
| 13361 | |
| 13362 @override | |
| 13363 bool visitPrefixExpression(PrefixExpression node) { | |
| 13364 if (identical(node.operand, _oldNode)) { | |
| 13365 node.operand = _newNode as Expression; | |
| 13366 return true; | |
| 13367 } | |
| 13368 return visitNode(node); | |
| 13369 } | |
| 13370 | |
| 13371 @override | |
| 13372 bool visitPropertyAccess(PropertyAccess node) { | |
| 13373 if (identical(node.target, _oldNode)) { | |
| 13374 node.target = _newNode as Expression; | |
| 13375 return true; | |
| 13376 } else if (identical(node.propertyName, _oldNode)) { | |
| 13377 node.propertyName = _newNode as SimpleIdentifier; | |
| 13378 return true; | |
| 13379 } | |
| 13380 return visitNode(node); | |
| 13381 } | |
| 13382 | |
| 13383 @override | |
| 13384 bool visitRedirectingConstructorInvocation( | |
| 13385 RedirectingConstructorInvocation node) { | |
| 13386 if (identical(node.constructorName, _oldNode)) { | |
| 13387 node.constructorName = _newNode as SimpleIdentifier; | |
| 13388 return true; | |
| 13389 } else if (identical(node.argumentList, _oldNode)) { | |
| 13390 node.argumentList = _newNode as ArgumentList; | |
| 13391 return true; | |
| 13392 } | |
| 13393 return visitNode(node); | |
| 13394 } | |
| 13395 | |
| 13396 @override | |
| 13397 bool visitRethrowExpression(RethrowExpression node) => visitNode(node); | |
| 13398 | |
| 13399 @override | |
| 13400 bool visitReturnStatement(ReturnStatement node) { | |
| 13401 if (identical(node.expression, _oldNode)) { | |
| 13402 node.expression = _newNode as Expression; | |
| 13403 return true; | |
| 13404 } | |
| 13405 return visitNode(node); | |
| 13406 } | |
| 13407 | |
| 13408 @override | |
| 13409 bool visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); | |
| 13410 | |
| 13411 @override | |
| 13412 bool visitShowCombinator(ShowCombinator node) { | |
| 13413 if (_replaceInList(node.shownNames)) { | |
| 13414 return true; | |
| 13415 } | |
| 13416 return visitNode(node); | |
| 13417 } | |
| 13418 | |
| 13419 @override | |
| 13420 bool visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 13421 if (identical(node.type, _oldNode)) { | |
| 13422 node.type = _newNode as TypeName; | |
| 13423 return true; | |
| 13424 } | |
| 13425 return visitNormalFormalParameter(node); | |
| 13426 } | |
| 13427 | |
| 13428 @override | |
| 13429 bool visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node); | |
| 13430 | |
| 13431 @override | |
| 13432 bool visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node); | |
| 13433 | |
| 13434 @override | |
| 13435 bool visitStringInterpolation(StringInterpolation node) { | |
| 13436 if (_replaceInList(node.elements)) { | |
| 13437 return true; | |
| 13438 } | |
| 13439 return visitNode(node); | |
| 13440 } | |
| 13441 | |
| 13442 @override | |
| 13443 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 13444 if (identical(node.constructorName, _oldNode)) { | |
| 13445 node.constructorName = _newNode as SimpleIdentifier; | |
| 13446 return true; | |
| 13447 } else if (identical(node.argumentList, _oldNode)) { | |
| 13448 node.argumentList = _newNode as ArgumentList; | |
| 13449 return true; | |
| 13450 } | |
| 13451 return visitNode(node); | |
| 13452 } | |
| 13453 | |
| 13454 @override | |
| 13455 bool visitSuperExpression(SuperExpression node) => visitNode(node); | |
| 13456 | |
| 13457 @override | |
| 13458 bool visitSwitchCase(SwitchCase node) { | |
| 13459 if (identical(node.expression, _oldNode)) { | |
| 13460 node.expression = _newNode as Expression; | |
| 13461 return true; | |
| 13462 } | |
| 13463 return visitSwitchMember(node); | |
| 13464 } | |
| 13465 | |
| 13466 @override | |
| 13467 bool visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node); | |
| 13468 | |
| 13469 bool visitSwitchMember(SwitchMember node) { | |
| 13470 if (_replaceInList(node.labels)) { | |
| 13471 return true; | |
| 13472 } else if (_replaceInList(node.statements)) { | |
| 13473 return true; | |
| 13474 } | |
| 13475 return visitNode(node); | |
| 13476 } | |
| 13477 | |
| 13478 @override | |
| 13479 bool visitSwitchStatement(SwitchStatement node) { | |
| 13480 if (identical(node.expression, _oldNode)) { | |
| 13481 node.expression = _newNode as Expression; | |
| 13482 return true; | |
| 13483 } else if (_replaceInList(node.members)) { | |
| 13484 return true; | |
| 13485 } | |
| 13486 return visitNode(node); | |
| 13487 } | |
| 13488 | |
| 13489 @override | |
| 13490 bool visitSymbolLiteral(SymbolLiteral node) => visitNode(node); | |
| 13491 | |
| 13492 @override | |
| 13493 bool visitThisExpression(ThisExpression node) => visitNode(node); | |
| 13494 | |
| 13495 @override | |
| 13496 bool visitThrowExpression(ThrowExpression node) { | |
| 13497 if (identical(node.expression, _oldNode)) { | |
| 13498 node.expression = _newNode as Expression; | |
| 13499 return true; | |
| 13500 } | |
| 13501 return visitNode(node); | |
| 13502 } | |
| 13503 | |
| 13504 @override | |
| 13505 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 13506 if (identical(node.variables, _oldNode)) { | |
| 13507 node.variables = _newNode as VariableDeclarationList; | |
| 13508 return true; | |
| 13509 } | |
| 13510 return visitAnnotatedNode(node); | |
| 13511 } | |
| 13512 | |
| 13513 @override | |
| 13514 bool visitTryStatement(TryStatement node) { | |
| 13515 if (identical(node.body, _oldNode)) { | |
| 13516 node.body = _newNode as Block; | |
| 13517 return true; | |
| 13518 } else if (identical(node.finallyBlock, _oldNode)) { | |
| 13519 node.finallyBlock = _newNode as Block; | |
| 13520 return true; | |
| 13521 } else if (_replaceInList(node.catchClauses)) { | |
| 13522 return true; | |
| 13523 } | |
| 13524 return visitNode(node); | |
| 13525 } | |
| 13526 | |
| 13527 @override | |
| 13528 bool visitTypeArgumentList(TypeArgumentList node) { | |
| 13529 if (_replaceInList(node.arguments)) { | |
| 13530 return true; | |
| 13531 } | |
| 13532 return visitNode(node); | |
| 13533 } | |
| 13534 | |
| 13535 bool visitTypedLiteral(TypedLiteral node) { | |
| 13536 if (identical(node.typeArguments, _oldNode)) { | |
| 13537 node.typeArguments = _newNode as TypeArgumentList; | |
| 13538 return true; | |
| 13539 } | |
| 13540 return visitNode(node); | |
| 13541 } | |
| 13542 | |
| 13543 @override | |
| 13544 bool visitTypeName(TypeName node) { | |
| 13545 if (identical(node.name, _oldNode)) { | |
| 13546 node.name = _newNode as Identifier; | |
| 13547 return true; | |
| 13548 } else if (identical(node.typeArguments, _oldNode)) { | |
| 13549 node.typeArguments = _newNode as TypeArgumentList; | |
| 13550 return true; | |
| 13551 } | |
| 13552 return visitNode(node); | |
| 13553 } | |
| 13554 | |
| 13555 @override | |
| 13556 bool visitTypeParameter(TypeParameter node) { | |
| 13557 if (identical(node.name, _oldNode)) { | |
| 13558 node.name = _newNode as SimpleIdentifier; | |
| 13559 return true; | |
| 13560 } else if (identical(node.bound, _oldNode)) { | |
| 13561 node.bound = _newNode as TypeName; | |
| 13562 return true; | |
| 13563 } | |
| 13564 return visitNode(node); | |
| 13565 } | |
| 13566 | |
| 13567 @override | |
| 13568 bool visitTypeParameterList(TypeParameterList node) { | |
| 13569 if (_replaceInList(node.typeParameters)) { | |
| 13570 return true; | |
| 13571 } | |
| 13572 return visitNode(node); | |
| 13573 } | |
| 13574 | |
| 13575 bool visitUriBasedDirective(UriBasedDirective node) { | |
| 13576 if (identical(node.uri, _oldNode)) { | |
| 13577 node.uri = _newNode as StringLiteral; | |
| 13578 return true; | |
| 13579 } | |
| 13580 return visitAnnotatedNode(node); | |
| 13581 } | |
| 13582 | |
| 13583 @override | |
| 13584 bool visitVariableDeclaration(VariableDeclaration node) { | |
| 13585 if (identical(node.name, _oldNode)) { | |
| 13586 node.name = _newNode as SimpleIdentifier; | |
| 13587 return true; | |
| 13588 } else if (identical(node.initializer, _oldNode)) { | |
| 13589 node.initializer = _newNode as Expression; | |
| 13590 return true; | |
| 13591 } | |
| 13592 return visitAnnotatedNode(node); | |
| 13593 } | |
| 13594 | |
| 13595 @override | |
| 13596 bool visitVariableDeclarationList(VariableDeclarationList node) { | |
| 13597 if (identical(node.type, _oldNode)) { | |
| 13598 node.type = _newNode as TypeName; | |
| 13599 return true; | |
| 13600 } else if (_replaceInList(node.variables)) { | |
| 13601 return true; | |
| 13602 } | |
| 13603 return visitNode(node); | |
| 13604 } | |
| 13605 | |
| 13606 @override | |
| 13607 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 13608 if (identical(node.variables, _oldNode)) { | |
| 13609 node.variables = _newNode as VariableDeclarationList; | |
| 13610 return true; | |
| 13611 } | |
| 13612 return visitNode(node); | |
| 13613 } | |
| 13614 | |
| 13615 @override | |
| 13616 bool visitWhileStatement(WhileStatement node) { | |
| 13617 if (identical(node.condition, _oldNode)) { | |
| 13618 node.condition = _newNode as Expression; | |
| 13619 return true; | |
| 13620 } else if (identical(node.body, _oldNode)) { | |
| 13621 node.body = _newNode as Statement; | |
| 13622 return true; | |
| 13623 } | |
| 13624 return visitNode(node); | |
| 13625 } | |
| 13626 | |
| 13627 @override | |
| 13628 bool visitWithClause(WithClause node) { | |
| 13629 if (_replaceInList(node.mixinTypes)) { | |
| 13630 return true; | |
| 13631 } | |
| 13632 return visitNode(node); | |
| 13633 } | |
| 13634 | |
| 13635 @override | |
| 13636 bool visitYieldStatement(YieldStatement node) { | |
| 13637 if (identical(node.expression, _oldNode)) { | |
| 13638 node.expression = _newNode as Expression; | |
| 13639 return true; | |
| 13640 } | |
| 13641 return visitNode(node); | |
| 13642 } | |
| 13643 | |
| 13644 bool _replaceInList(NodeList list) { | |
| 13645 int count = list.length; | |
| 13646 for (int i = 0; i < count; i++) { | |
| 13647 if (identical(_oldNode, list[i])) { | |
| 13648 list[i] = _newNode; | |
| 13649 return true; | |
| 13650 } | |
| 13651 } | |
| 13652 return false; | |
| 13653 } | |
| 13654 | |
| 13655 /** | |
| 13656 * Replace the [oldNode] with the [newNode] in the AST structure containing | |
| 13657 * the old node. Return `true` if the replacement was successful. | |
| 13658 * | |
| 13659 * Throws an [IllegalArgumentException] if either node is `null`, if the old | |
| 13660 * node does not have a parent node, or if the AST structure has been | |
| 13661 * corrupted. | |
| 13662 */ | |
| 13663 static bool replace(AstNode oldNode, AstNode newNode) { | |
| 13664 if (oldNode == null || newNode == null) { | |
| 13665 throw new IllegalArgumentException( | |
| 13666 "The old and new nodes must be non-null"); | |
| 13667 } else if (identical(oldNode, newNode)) { | |
| 13668 return true; | |
| 13669 } | |
| 13670 AstNode parent = oldNode.parent; | |
| 13671 if (parent == null) { | |
| 13672 throw new IllegalArgumentException( | |
| 13673 "The old node is not a child of another node"); | |
| 13674 } | |
| 13675 NodeReplacer replacer = new NodeReplacer(oldNode, newNode); | |
| 13676 return parent.accept(replacer); | |
| 13677 } | |
| 13678 } | |
| 13679 | |
| 13680 /** | |
| 13681 * A formal parameter that is required (is not optional). | |
| 13682 * | |
| 13683 * > normalFormalParameter ::= | |
| 13684 * > [FunctionTypedFormalParameter] | |
| 13685 * > | [FieldFormalParameter] | |
| 13686 * > | [SimpleFormalParameter] | |
| 13687 */ | |
| 13688 abstract class NormalFormalParameter extends FormalParameter { | |
| 13689 /** | |
| 13690 * The documentation comment associated with this parameter, or `null` if this | |
| 13691 * parameter does not have a documentation comment associated with it. | |
| 13692 */ | |
| 13693 Comment _comment; | |
| 13694 | |
| 13695 /** | |
| 13696 * The annotations associated with this parameter. | |
| 13697 */ | |
| 13698 NodeList<Annotation> _metadata; | |
| 13699 | |
| 13700 /** | |
| 13701 * The name of the parameter being declared. | |
| 13702 */ | |
| 13703 SimpleIdentifier _identifier; | |
| 13704 | |
| 13705 /** | |
| 13706 * Initialize a newly created formal parameter. Either or both of the | |
| 13707 * [comment] and [metadata] can be `null` if the parameter does not have the | |
| 13708 * corresponding attribute. | |
| 13709 */ | |
| 13710 NormalFormalParameter( | |
| 13711 Comment comment, List<Annotation> metadata, SimpleIdentifier identifier) { | |
| 13712 _comment = _becomeParentOf(comment); | |
| 13713 _metadata = new NodeList<Annotation>(this, metadata); | |
| 13714 _identifier = _becomeParentOf(identifier); | |
| 13715 } | |
| 13716 | |
| 13717 /** | |
| 13718 * Return the documentation comment associated with this parameter, or `null` | |
| 13719 * if this parameter does not have a documentation comment associated with it. | |
| 13720 */ | |
| 13721 Comment get documentationComment => _comment; | |
| 13722 | |
| 13723 /** | |
| 13724 * Set the documentation comment associated with this parameter to the given | |
| 13725 * [comment]. | |
| 13726 */ | |
| 13727 void set documentationComment(Comment comment) { | |
| 13728 _comment = _becomeParentOf(comment); | |
| 13729 } | |
| 13730 | |
| 13731 @override | |
| 13732 SimpleIdentifier get identifier => _identifier; | |
| 13733 | |
| 13734 /** | |
| 13735 * Set the name of the parameter being declared to the given [identifier]. | |
| 13736 */ | |
| 13737 void set identifier(SimpleIdentifier identifier) { | |
| 13738 _identifier = _becomeParentOf(identifier); | |
| 13739 } | |
| 13740 | |
| 13741 @override | |
| 13742 ParameterKind get kind { | |
| 13743 AstNode parent = this.parent; | |
| 13744 if (parent is DefaultFormalParameter) { | |
| 13745 return parent.kind; | |
| 13746 } | |
| 13747 return ParameterKind.REQUIRED; | |
| 13748 } | |
| 13749 | |
| 13750 /** | |
| 13751 * Return the annotations associated with this parameter. | |
| 13752 */ | |
| 13753 NodeList<Annotation> get metadata => _metadata; | |
| 13754 | |
| 13755 /** | |
| 13756 * Set the metadata associated with this node to the given [metadata]. | |
| 13757 */ | |
| 13758 void set metadata(List<Annotation> metadata) { | |
| 13759 _metadata.clear(); | |
| 13760 _metadata.addAll(metadata); | |
| 13761 } | |
| 13762 | |
| 13763 /** | |
| 13764 * Return a list containing the comment and annotations associated with this | |
| 13765 * parameter, sorted in lexical order. | |
| 13766 */ | |
| 13767 List<AstNode> get sortedCommentAndAnnotations { | |
| 13768 return <AstNode>[] | |
| 13769 ..add(_comment) | |
| 13770 ..addAll(_metadata) | |
| 13771 ..sort(AstNode.LEXICAL_ORDER); | |
| 13772 } | |
| 13773 | |
| 13774 ChildEntities get _childEntities { | |
| 13775 ChildEntities result = new ChildEntities(); | |
| 13776 if (_commentIsBeforeAnnotations()) { | |
| 13777 result | |
| 13778 ..add(_comment) | |
| 13779 ..addAll(_metadata); | |
| 13780 } else { | |
| 13781 result.addAll(sortedCommentAndAnnotations); | |
| 13782 } | |
| 13783 return result; | |
| 13784 } | |
| 13785 | |
| 13786 @override | |
| 13787 void visitChildren(AstVisitor visitor) { | |
| 13788 // | |
| 13789 // Note that subclasses are responsible for visiting the identifier because | |
| 13790 // they often need to visit other nodes before visiting the identifier. | |
| 13791 // | |
| 13792 if (_commentIsBeforeAnnotations()) { | |
| 13793 _safelyVisitChild(_comment, visitor); | |
| 13794 _metadata.accept(visitor); | |
| 13795 } else { | |
| 13796 for (AstNode child in sortedCommentAndAnnotations) { | |
| 13797 child.accept(visitor); | |
| 13798 } | |
| 13799 } | |
| 13800 } | |
| 13801 | |
| 13802 /** | |
| 13803 * Return `true` if the comment is lexically before any annotations. | |
| 13804 */ | |
| 13805 bool _commentIsBeforeAnnotations() { | |
| 13806 if (_comment == null || _metadata.isEmpty) { | |
| 13807 return true; | |
| 13808 } | |
| 13809 Annotation firstAnnotation = _metadata[0]; | |
| 13810 return _comment.offset < firstAnnotation.offset; | |
| 13811 } | |
| 13812 } | |
| 13813 | |
| 13814 /** | |
| 13815 * A null literal expression. | |
| 13816 * | |
| 13817 * > nullLiteral ::= | |
| 13818 * > 'null' | |
| 13819 */ | |
| 13820 class NullLiteral extends Literal { | |
| 13821 /** | |
| 13822 * The token representing the literal. | |
| 13823 */ | |
| 13824 Token literal; | |
| 13825 | |
| 13826 /** | |
| 13827 * Initialize a newly created null literal. | |
| 13828 */ | |
| 13829 NullLiteral(this.literal); | |
| 13830 | |
| 13831 @override | |
| 13832 Token get beginToken => literal; | |
| 13833 | |
| 13834 @override | |
| 13835 Iterable get childEntities => new ChildEntities()..add(literal); | |
| 13836 | |
| 13837 @override | |
| 13838 Token get endToken => literal; | |
| 13839 | |
| 13840 @override | |
| 13841 accept(AstVisitor visitor) => visitor.visitNullLiteral(this); | |
| 13842 | |
| 13843 @override | |
| 13844 void visitChildren(AstVisitor visitor) { | |
| 13845 // There are no children to visit. | |
| 13846 } | |
| 13847 } | |
| 13848 | |
| 13849 /** | |
| 13850 * A parenthesized expression. | |
| 13851 * | |
| 13852 * > parenthesizedExpression ::= | |
| 13853 * > '(' [Expression] ')' | |
| 13854 */ | |
| 13855 class ParenthesizedExpression extends Expression { | |
| 13856 /** | |
| 13857 * The left parenthesis. | |
| 13858 */ | |
| 13859 Token leftParenthesis; | |
| 13860 | |
| 13861 /** | |
| 13862 * The expression within the parentheses. | |
| 13863 */ | |
| 13864 Expression _expression; | |
| 13865 | |
| 13866 /** | |
| 13867 * The right parenthesis. | |
| 13868 */ | |
| 13869 Token rightParenthesis; | |
| 13870 | |
| 13871 /** | |
| 13872 * Initialize a newly created parenthesized expression. | |
| 13873 */ | |
| 13874 ParenthesizedExpression( | |
| 13875 this.leftParenthesis, Expression expression, this.rightParenthesis) { | |
| 13876 _expression = _becomeParentOf(expression); | |
| 13877 } | |
| 13878 | |
| 13879 @override | |
| 13880 Token get beginToken => leftParenthesis; | |
| 13881 | |
| 13882 @override | |
| 13883 Iterable get childEntities => new ChildEntities() | |
| 13884 ..add(leftParenthesis) | |
| 13885 ..add(_expression) | |
| 13886 ..add(rightParenthesis); | |
| 13887 | |
| 13888 @override | |
| 13889 Token get endToken => rightParenthesis; | |
| 13890 | |
| 13891 /** | |
| 13892 * Return the expression within the parentheses. | |
| 13893 */ | |
| 13894 Expression get expression => _expression; | |
| 13895 | |
| 13896 /** | |
| 13897 * Set the expression within the parentheses to the given [expression]. | |
| 13898 */ | |
| 13899 void set expression(Expression expression) { | |
| 13900 _expression = _becomeParentOf(expression); | |
| 13901 } | |
| 13902 | |
| 13903 @override | |
| 13904 int get precedence => 15; | |
| 13905 | |
| 13906 @override | |
| 13907 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this); | |
| 13908 | |
| 13909 @override | |
| 13910 void visitChildren(AstVisitor visitor) { | |
| 13911 _safelyVisitChild(_expression, visitor); | |
| 13912 } | |
| 13913 } | |
| 13914 | |
| 13915 /** | |
| 13916 * A part directive. | |
| 13917 * | |
| 13918 * > partDirective ::= | |
| 13919 * > [Annotation] 'part' [StringLiteral] ';' | |
| 13920 */ | |
| 13921 class PartDirective extends UriBasedDirective { | |
| 13922 /** | |
| 13923 * The token representing the 'part' keyword. | |
| 13924 */ | |
| 13925 Token partKeyword; | |
| 13926 | |
| 13927 /** | |
| 13928 * The semicolon terminating the directive. | |
| 13929 */ | |
| 13930 Token semicolon; | |
| 13931 | |
| 13932 /** | |
| 13933 * Initialize a newly created part directive. Either or both of the [comment] | |
| 13934 * and [metadata] can be `null` if the directive does not have the | |
| 13935 * corresponding attribute. | |
| 13936 */ | |
| 13937 PartDirective(Comment comment, List<Annotation> metadata, this.partKeyword, | |
| 13938 StringLiteral partUri, this.semicolon) | |
| 13939 : super(comment, metadata, partUri); | |
| 13940 | |
| 13941 @override | |
| 13942 Iterable get childEntities => | |
| 13943 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon); | |
| 13944 | |
| 13945 @override | |
| 13946 Token get endToken => semicolon; | |
| 13947 | |
| 13948 @override | |
| 13949 Token get firstTokenAfterCommentAndMetadata => partKeyword; | |
| 13950 | |
| 13951 @override | |
| 13952 Token get keyword => partKeyword; | |
| 13953 | |
| 13954 /** | |
| 13955 * Return the token representing the 'part' token. | |
| 13956 */ | |
| 13957 @deprecated // Use "this.partKeyword" | |
| 13958 Token get partToken => partKeyword; | |
| 13959 | |
| 13960 /** | |
| 13961 * Set the token representing the 'part' token to the given [token]. | |
| 13962 */ | |
| 13963 @deprecated // Use "this.partKeyword" | |
| 13964 set partToken(Token token) { | |
| 13965 partKeyword = token; | |
| 13966 } | |
| 13967 | |
| 13968 @override | |
| 13969 CompilationUnitElement get uriElement => element as CompilationUnitElement; | |
| 13970 | |
| 13971 @override | |
| 13972 accept(AstVisitor visitor) => visitor.visitPartDirective(this); | |
| 13973 } | |
| 13974 | |
| 13975 /** | |
| 13976 * A part-of directive. | |
| 13977 * | |
| 13978 * > partOfDirective ::= | |
| 13979 * > [Annotation] 'part' 'of' [Identifier] ';' | |
| 13980 */ | |
| 13981 class PartOfDirective extends Directive { | |
| 13982 /** | |
| 13983 * The token representing the 'part' keyword. | |
| 13984 */ | |
| 13985 Token partKeyword; | |
| 13986 | |
| 13987 /** | |
| 13988 * The token representing the 'of' keyword. | |
| 13989 */ | |
| 13990 Token ofKeyword; | |
| 13991 | |
| 13992 /** | |
| 13993 * The name of the library that the containing compilation unit is part of. | |
| 13994 */ | |
| 13995 LibraryIdentifier _libraryName; | |
| 13996 | |
| 13997 /** | |
| 13998 * The semicolon terminating the directive. | |
| 13999 */ | |
| 14000 Token semicolon; | |
| 14001 | |
| 14002 /** | |
| 14003 * Initialize a newly created part-of directive. Either or both of the | |
| 14004 * [comment] and [metadata] can be `null` if the directive does not have the | |
| 14005 * corresponding attribute. | |
| 14006 */ | |
| 14007 PartOfDirective(Comment comment, List<Annotation> metadata, this.partKeyword, | |
| 14008 this.ofKeyword, LibraryIdentifier libraryName, this.semicolon) | |
| 14009 : super(comment, metadata) { | |
| 14010 _libraryName = _becomeParentOf(libraryName); | |
| 14011 } | |
| 14012 | |
| 14013 @override | |
| 14014 Iterable get childEntities => super._childEntities | |
| 14015 ..add(partKeyword) | |
| 14016 ..add(ofKeyword) | |
| 14017 ..add(_libraryName) | |
| 14018 ..add(semicolon); | |
| 14019 | |
| 14020 @override | |
| 14021 Token get endToken => semicolon; | |
| 14022 | |
| 14023 @override | |
| 14024 Token get firstTokenAfterCommentAndMetadata => partKeyword; | |
| 14025 | |
| 14026 @override | |
| 14027 Token get keyword => partKeyword; | |
| 14028 | |
| 14029 /** | |
| 14030 * Return the name of the library that the containing compilation unit is part | |
| 14031 * of. | |
| 14032 */ | |
| 14033 LibraryIdentifier get libraryName => _libraryName; | |
| 14034 | |
| 14035 /** | |
| 14036 * Set the name of the library that the containing compilation unit is part of | |
| 14037 * to the given [libraryName]. | |
| 14038 */ | |
| 14039 void set libraryName(LibraryIdentifier libraryName) { | |
| 14040 _libraryName = _becomeParentOf(libraryName); | |
| 14041 } | |
| 14042 | |
| 14043 /** | |
| 14044 * Return the token representing the 'of' token. | |
| 14045 */ | |
| 14046 @deprecated // Use "this.ofKeyword" | |
| 14047 Token get ofToken => ofKeyword; | |
| 14048 | |
| 14049 /** | |
| 14050 * Set the token representing the 'of' token to the given [token]. | |
| 14051 */ | |
| 14052 @deprecated // Use "this.ofKeyword" | |
| 14053 set ofToken(Token token) { | |
| 14054 ofKeyword = token; | |
| 14055 } | |
| 14056 | |
| 14057 /** | |
| 14058 * Return the token representing the 'part' token. | |
| 14059 */ | |
| 14060 @deprecated // Use "this.partKeyword" | |
| 14061 Token get partToken => partKeyword; | |
| 14062 | |
| 14063 /** | |
| 14064 * Set the token representing the 'part' token to the given [token]. | |
| 14065 */ | |
| 14066 @deprecated // Use "this.partKeyword" | |
| 14067 set partToken(Token token) { | |
| 14068 partKeyword = token; | |
| 14069 } | |
| 14070 | |
| 14071 @override | |
| 14072 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this); | |
| 14073 | |
| 14074 @override | |
| 14075 void visitChildren(AstVisitor visitor) { | |
| 14076 super.visitChildren(visitor); | |
| 14077 _safelyVisitChild(_libraryName, visitor); | |
| 14078 } | |
| 14079 } | |
| 14080 | |
| 14081 /** | |
| 14082 * A postfix unary expression. | |
| 14083 * | |
| 14084 * > postfixExpression ::= | |
| 14085 * > [Expression] [Token] | |
| 14086 */ | |
| 14087 class PostfixExpression extends Expression { | |
| 14088 /** | |
| 14089 * The expression computing the operand for the operator. | |
| 14090 */ | |
| 14091 Expression _operand; | |
| 14092 | |
| 14093 /** | |
| 14094 * The postfix operator being applied to the operand. | |
| 14095 */ | |
| 14096 Token operator; | |
| 14097 | |
| 14098 /** | |
| 14099 * The element associated with this the operator based on the propagated type | |
| 14100 * of the operand, or `null` if the AST structure has not been resolved, if | |
| 14101 * the operator is not user definable, or if the operator could not be | |
| 14102 * resolved. | |
| 14103 */ | |
| 14104 MethodElement propagatedElement; | |
| 14105 | |
| 14106 /** | |
| 14107 * The element associated with the operator based on the static type of the | |
| 14108 * operand, or `null` if the AST structure has not been resolved, if the | |
| 14109 * operator is not user definable, or if the operator could not be resolved. | |
| 14110 */ | |
| 14111 MethodElement staticElement; | |
| 14112 | |
| 14113 /** | |
| 14114 * Initialize a newly created postfix expression. | |
| 14115 */ | |
| 14116 PostfixExpression(Expression operand, this.operator) { | |
| 14117 _operand = _becomeParentOf(operand); | |
| 14118 } | |
| 14119 | |
| 14120 @override | |
| 14121 Token get beginToken => _operand.beginToken; | |
| 14122 | |
| 14123 /** | |
| 14124 * Return the best element available for this operator. If resolution was able | |
| 14125 * to find a better element based on type propagation, that element will be | |
| 14126 * returned. Otherwise, the element found using the result of static analysis | |
| 14127 * will be returned. If resolution has not been performed, then `null` will be | |
| 14128 * returned. | |
| 14129 */ | |
| 14130 MethodElement get bestElement { | |
| 14131 MethodElement element = propagatedElement; | |
| 14132 if (element == null) { | |
| 14133 element = staticElement; | |
| 14134 } | |
| 14135 return element; | |
| 14136 } | |
| 14137 | |
| 14138 @override | |
| 14139 Iterable get childEntities => | |
| 14140 new ChildEntities()..add(_operand)..add(operator); | |
| 14141 | |
| 14142 @override | |
| 14143 Token get endToken => operator; | |
| 14144 | |
| 14145 /** | |
| 14146 * Return the expression computing the operand for the operator. | |
| 14147 */ | |
| 14148 Expression get operand => _operand; | |
| 14149 | |
| 14150 /** | |
| 14151 * Set the expression computing the operand for the operator to the given | |
| 14152 * [expression]. | |
| 14153 */ | |
| 14154 void set operand(Expression expression) { | |
| 14155 _operand = _becomeParentOf(expression); | |
| 14156 } | |
| 14157 | |
| 14158 @override | |
| 14159 int get precedence => 15; | |
| 14160 | |
| 14161 /** | |
| 14162 * If the AST structure has been resolved, and the function being invoked is | |
| 14163 * known based on propagated type information, then return the parameter | |
| 14164 * element representing the parameter to which the value of the operand will | |
| 14165 * be bound. Otherwise, return `null`. | |
| 14166 */ | |
| 14167 @deprecated // Use "expression.propagatedParameterElement" | |
| 14168 ParameterElement get propagatedParameterElementForOperand { | |
| 14169 return _propagatedParameterElementForOperand; | |
| 14170 } | |
| 14171 | |
| 14172 /** | |
| 14173 * If the AST structure has been resolved, and the function being invoked is | |
| 14174 * known based on static type information, then return the parameter element | |
| 14175 * representing the parameter to which the value of the operand will be bound. | |
| 14176 * Otherwise, return `null`. | |
| 14177 */ | |
| 14178 @deprecated // Use "expression.propagatedParameterElement" | |
| 14179 ParameterElement get staticParameterElementForOperand { | |
| 14180 return _staticParameterElementForOperand; | |
| 14181 } | |
| 14182 | |
| 14183 /** | |
| 14184 * If the AST structure has been resolved, and the function being invoked is | |
| 14185 * known based on propagated type information, then return the parameter | |
| 14186 * element representing the parameter to which the value of the operand will | |
| 14187 * be bound. Otherwise, return `null`. | |
| 14188 */ | |
| 14189 ParameterElement get _propagatedParameterElementForOperand { | |
| 14190 if (propagatedElement == null) { | |
| 14191 return null; | |
| 14192 } | |
| 14193 List<ParameterElement> parameters = propagatedElement.parameters; | |
| 14194 if (parameters.length < 1) { | |
| 14195 return null; | |
| 14196 } | |
| 14197 return parameters[0]; | |
| 14198 } | |
| 14199 | |
| 14200 /** | |
| 14201 * If the AST structure has been resolved, and the function being invoked is | |
| 14202 * known based on static type information, then return the parameter element | |
| 14203 * representing the parameter to which the value of the operand will be bound. | |
| 14204 * Otherwise, return `null`. | |
| 14205 */ | |
| 14206 ParameterElement get _staticParameterElementForOperand { | |
| 14207 if (staticElement == null) { | |
| 14208 return null; | |
| 14209 } | |
| 14210 List<ParameterElement> parameters = staticElement.parameters; | |
| 14211 if (parameters.length < 1) { | |
| 14212 return null; | |
| 14213 } | |
| 14214 return parameters[0]; | |
| 14215 } | |
| 14216 | |
| 14217 @override | |
| 14218 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this); | |
| 14219 | |
| 14220 @override | |
| 14221 void visitChildren(AstVisitor visitor) { | |
| 14222 _safelyVisitChild(_operand, visitor); | |
| 14223 } | |
| 14224 } | |
| 14225 | |
| 14226 /** | |
| 14227 * An identifier that is prefixed or an access to an object property where the | |
| 14228 * target of the property access is a simple identifier. | |
| 14229 * | |
| 14230 * > prefixedIdentifier ::= | |
| 14231 * > [SimpleIdentifier] '.' [SimpleIdentifier] | |
| 14232 */ | |
| 14233 class PrefixedIdentifier extends Identifier { | |
| 14234 /** | |
| 14235 * The prefix associated with the library in which the identifier is defined. | |
| 14236 */ | |
| 14237 SimpleIdentifier _prefix; | |
| 14238 | |
| 14239 /** | |
| 14240 * The period used to separate the prefix from the identifier. | |
| 14241 */ | |
| 14242 Token period; | |
| 14243 | |
| 14244 /** | |
| 14245 * The identifier being prefixed. | |
| 14246 */ | |
| 14247 SimpleIdentifier _identifier; | |
| 14248 | |
| 14249 /** | |
| 14250 * Initialize a newly created prefixed identifier. | |
| 14251 */ | |
| 14252 PrefixedIdentifier( | |
| 14253 SimpleIdentifier prefix, this.period, SimpleIdentifier identifier) { | |
| 14254 _prefix = _becomeParentOf(prefix); | |
| 14255 _identifier = _becomeParentOf(identifier); | |
| 14256 } | |
| 14257 | |
| 14258 @override | |
| 14259 Token get beginToken => _prefix.beginToken; | |
| 14260 | |
| 14261 @override | |
| 14262 Element get bestElement { | |
| 14263 if (_identifier == null) { | |
| 14264 return null; | |
| 14265 } | |
| 14266 return _identifier.bestElement; | |
| 14267 } | |
| 14268 | |
| 14269 @override | |
| 14270 Iterable get childEntities => | |
| 14271 new ChildEntities()..add(_prefix)..add(period)..add(_identifier); | |
| 14272 | |
| 14273 @override | |
| 14274 Token get endToken => _identifier.endToken; | |
| 14275 | |
| 14276 /** | |
| 14277 * Return the identifier being prefixed. | |
| 14278 */ | |
| 14279 SimpleIdentifier get identifier => _identifier; | |
| 14280 | |
| 14281 /** | |
| 14282 * Set the identifier being prefixed to the given [identifier]. | |
| 14283 */ | |
| 14284 void set identifier(SimpleIdentifier identifier) { | |
| 14285 _identifier = _becomeParentOf(identifier); | |
| 14286 } | |
| 14287 | |
| 14288 /** | |
| 14289 * Return `true` if this type is a deferred type. If the AST structure has not | |
| 14290 * been resolved, then return `false`. | |
| 14291 * | |
| 14292 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form | |
| 14293 * </i>p.T</i> where <i>p</i> is a deferred prefix. | |
| 14294 */ | |
| 14295 bool get isDeferred { | |
| 14296 Element element = _prefix.staticElement; | |
| 14297 if (element is! PrefixElement) { | |
| 14298 return false; | |
| 14299 } | |
| 14300 PrefixElement prefixElement = element as PrefixElement; | |
| 14301 List<ImportElement> imports = | |
| 14302 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement); | |
| 14303 if (imports.length != 1) { | |
| 14304 return false; | |
| 14305 } | |
| 14306 return imports[0].isDeferred; | |
| 14307 } | |
| 14308 | |
| 14309 @override | |
| 14310 String get name => "${_prefix.name}.${_identifier.name}"; | |
| 14311 | |
| 14312 @override | |
| 14313 int get precedence => 15; | |
| 14314 | |
| 14315 /** | |
| 14316 * Return the prefix associated with the library in which the identifier is | |
| 14317 * defined. | |
| 14318 */ | |
| 14319 SimpleIdentifier get prefix => _prefix; | |
| 14320 | |
| 14321 /** | |
| 14322 * Set the prefix associated with the library in which the identifier is | |
| 14323 * defined to the given [identifier]. | |
| 14324 */ | |
| 14325 void set prefix(SimpleIdentifier identifier) { | |
| 14326 _prefix = _becomeParentOf(identifier); | |
| 14327 } | |
| 14328 | |
| 14329 @override | |
| 14330 Element get propagatedElement { | |
| 14331 if (_identifier == null) { | |
| 14332 return null; | |
| 14333 } | |
| 14334 return _identifier.propagatedElement; | |
| 14335 } | |
| 14336 | |
| 14337 @override | |
| 14338 Element get staticElement { | |
| 14339 if (_identifier == null) { | |
| 14340 return null; | |
| 14341 } | |
| 14342 return _identifier.staticElement; | |
| 14343 } | |
| 14344 | |
| 14345 @override | |
| 14346 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this); | |
| 14347 | |
| 14348 @override | |
| 14349 void visitChildren(AstVisitor visitor) { | |
| 14350 _safelyVisitChild(_prefix, visitor); | |
| 14351 _safelyVisitChild(_identifier, visitor); | |
| 14352 } | |
| 14353 } | |
| 14354 | |
| 14355 /** | |
| 14356 * A prefix unary expression. | |
| 14357 * | |
| 14358 * > prefixExpression ::= | |
| 14359 * > [Token] [Expression] | |
| 14360 */ | |
| 14361 class PrefixExpression extends Expression { | |
| 14362 /** | |
| 14363 * The prefix operator being applied to the operand. | |
| 14364 */ | |
| 14365 Token operator; | |
| 14366 | |
| 14367 /** | |
| 14368 * The expression computing the operand for the operator. | |
| 14369 */ | |
| 14370 Expression _operand; | |
| 14371 | |
| 14372 /** | |
| 14373 * The element associated with the operator based on the static type of the | |
| 14374 * operand, or `null` if the AST structure has not been resolved, if the | |
| 14375 * operator is not user definable, or if the operator could not be resolved. | |
| 14376 */ | |
| 14377 MethodElement staticElement; | |
| 14378 | |
| 14379 /** | |
| 14380 * The element associated with the operator based on the propagated type of | |
| 14381 * the operand, or `null` if the AST structure has not been resolved, if the | |
| 14382 * operator is not user definable, or if the operator could not be resolved. | |
| 14383 */ | |
| 14384 MethodElement propagatedElement; | |
| 14385 | |
| 14386 /** | |
| 14387 * Initialize a newly created prefix expression. | |
| 14388 */ | |
| 14389 PrefixExpression(this.operator, Expression operand) { | |
| 14390 _operand = _becomeParentOf(operand); | |
| 14391 } | |
| 14392 | |
| 14393 @override | |
| 14394 Token get beginToken => operator; | |
| 14395 | |
| 14396 /** | |
| 14397 * Return the best element available for this operator. If resolution was able | |
| 14398 * to find a better element based on type propagation, that element will be | |
| 14399 * returned. Otherwise, the element found using the result of static analysis | |
| 14400 * will be returned. If resolution has not been performed, then `null` will be | |
| 14401 * returned. | |
| 14402 */ | |
| 14403 MethodElement get bestElement { | |
| 14404 MethodElement element = propagatedElement; | |
| 14405 if (element == null) { | |
| 14406 element = staticElement; | |
| 14407 } | |
| 14408 return element; | |
| 14409 } | |
| 14410 | |
| 14411 @override | |
| 14412 Iterable get childEntities => | |
| 14413 new ChildEntities()..add(operator)..add(_operand); | |
| 14414 | |
| 14415 @override | |
| 14416 Token get endToken => _operand.endToken; | |
| 14417 | |
| 14418 /** | |
| 14419 * Return the expression computing the operand for the operator. | |
| 14420 */ | |
| 14421 Expression get operand => _operand; | |
| 14422 | |
| 14423 /** | |
| 14424 * Set the expression computing the operand for the operator to the given | |
| 14425 * [expression]. | |
| 14426 */ | |
| 14427 void set operand(Expression expression) { | |
| 14428 _operand = _becomeParentOf(expression); | |
| 14429 } | |
| 14430 | |
| 14431 @override | |
| 14432 int get precedence => 14; | |
| 14433 | |
| 14434 /** | |
| 14435 * If the AST structure has been resolved, and the function being invoked is | |
| 14436 * known based on propagated type information, then return the parameter | |
| 14437 * element representing the parameter to which the value of the operand will | |
| 14438 * be bound. Otherwise, return `null`. | |
| 14439 */ | |
| 14440 @deprecated // Use "expression.propagatedParameterElement" | |
| 14441 ParameterElement get propagatedParameterElementForOperand { | |
| 14442 return _propagatedParameterElementForOperand; | |
| 14443 } | |
| 14444 | |
| 14445 /** | |
| 14446 * If the AST structure has been resolved, and the function being invoked is | |
| 14447 * known based on static type information, then return the parameter element | |
| 14448 * representing the parameter to which the value of the operand will be bound. | |
| 14449 * Otherwise, return `null`. | |
| 14450 */ | |
| 14451 @deprecated // Use "expression.propagatedParameterElement" | |
| 14452 ParameterElement get staticParameterElementForOperand { | |
| 14453 return _staticParameterElementForOperand; | |
| 14454 } | |
| 14455 | |
| 14456 /** | |
| 14457 * If the AST structure has been resolved, and the function being invoked is | |
| 14458 * known based on propagated type information, then return the parameter | |
| 14459 * element representing the parameter to which the value of the operand will | |
| 14460 * be bound. Otherwise, return `null`. | |
| 14461 */ | |
| 14462 ParameterElement get _propagatedParameterElementForOperand { | |
| 14463 if (propagatedElement == null) { | |
| 14464 return null; | |
| 14465 } | |
| 14466 List<ParameterElement> parameters = propagatedElement.parameters; | |
| 14467 if (parameters.length < 1) { | |
| 14468 return null; | |
| 14469 } | |
| 14470 return parameters[0]; | |
| 14471 } | |
| 14472 | |
| 14473 /** | |
| 14474 * If the AST structure has been resolved, and the function being invoked is | |
| 14475 * known based on static type information, then return the parameter element | |
| 14476 * representing the parameter to which the value of the operand will be bound. | |
| 14477 * Otherwise, return `null`. | |
| 14478 */ | |
| 14479 ParameterElement get _staticParameterElementForOperand { | |
| 14480 if (staticElement == null) { | |
| 14481 return null; | |
| 14482 } | |
| 14483 List<ParameterElement> parameters = staticElement.parameters; | |
| 14484 if (parameters.length < 1) { | |
| 14485 return null; | |
| 14486 } | |
| 14487 return parameters[0]; | |
| 14488 } | |
| 14489 | |
| 14490 @override | |
| 14491 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this); | |
| 14492 | |
| 14493 @override | |
| 14494 void visitChildren(AstVisitor visitor) { | |
| 14495 _safelyVisitChild(_operand, visitor); | |
| 14496 } | |
| 14497 } | |
| 14498 | |
| 14499 /** | |
| 14500 * The access of a property of an object. | |
| 14501 * | |
| 14502 * Note, however, that accesses to properties of objects can also be represented | |
| 14503 * as [PrefixedIdentifier] nodes in cases where the target is also a simple | |
| 14504 * identifier. | |
| 14505 * | |
| 14506 * > propertyAccess ::= | |
| 14507 * > [Expression] '.' [SimpleIdentifier] | |
| 14508 */ | |
| 14509 class PropertyAccess extends Expression { | |
| 14510 /** | |
| 14511 * The expression computing the object defining the property being accessed. | |
| 14512 */ | |
| 14513 Expression _target; | |
| 14514 | |
| 14515 /** | |
| 14516 * The property access operator. | |
| 14517 */ | |
| 14518 Token operator; | |
| 14519 | |
| 14520 /** | |
| 14521 * The name of the property being accessed. | |
| 14522 */ | |
| 14523 SimpleIdentifier _propertyName; | |
| 14524 | |
| 14525 /** | |
| 14526 * Initialize a newly created property access expression. | |
| 14527 */ | |
| 14528 PropertyAccess( | |
| 14529 Expression target, this.operator, SimpleIdentifier propertyName) { | |
| 14530 _target = _becomeParentOf(target); | |
| 14531 _propertyName = _becomeParentOf(propertyName); | |
| 14532 } | |
| 14533 | |
| 14534 @override | |
| 14535 Token get beginToken { | |
| 14536 if (_target != null) { | |
| 14537 return _target.beginToken; | |
| 14538 } | |
| 14539 return operator; | |
| 14540 } | |
| 14541 | |
| 14542 @override | |
| 14543 Iterable get childEntities => | |
| 14544 new ChildEntities()..add(_target)..add(operator)..add(_propertyName); | |
| 14545 | |
| 14546 @override | |
| 14547 Token get endToken => _propertyName.endToken; | |
| 14548 | |
| 14549 @override | |
| 14550 bool get isAssignable => true; | |
| 14551 | |
| 14552 /** | |
| 14553 * Return `true` if this expression is cascaded. If it is, then the target of | |
| 14554 * this expression is not stored locally but is stored in the nearest ancestor | |
| 14555 * that is a [CascadeExpression]. | |
| 14556 */ | |
| 14557 bool get isCascaded => | |
| 14558 operator != null && operator.type == TokenType.PERIOD_PERIOD; | |
| 14559 | |
| 14560 @override | |
| 14561 int get precedence => 15; | |
| 14562 | |
| 14563 /** | |
| 14564 * Return the name of the property being accessed. | |
| 14565 */ | |
| 14566 SimpleIdentifier get propertyName => _propertyName; | |
| 14567 | |
| 14568 /** | |
| 14569 * Set the name of the property being accessed to the given [identifier]. | |
| 14570 */ | |
| 14571 void set propertyName(SimpleIdentifier identifier) { | |
| 14572 _propertyName = _becomeParentOf(identifier); | |
| 14573 } | |
| 14574 | |
| 14575 /** | |
| 14576 * Return the expression used to compute the receiver of the invocation. If | |
| 14577 * this invocation is not part of a cascade expression, then this is the same | |
| 14578 * as [target]. If this invocation is part of a cascade expression, then the | |
| 14579 * target stored with the cascade expression is returned. | |
| 14580 */ | |
| 14581 Expression get realTarget { | |
| 14582 if (isCascaded) { | |
| 14583 AstNode ancestor = parent; | |
| 14584 while (ancestor is! CascadeExpression) { | |
| 14585 if (ancestor == null) { | |
| 14586 return _target; | |
| 14587 } | |
| 14588 ancestor = ancestor.parent; | |
| 14589 } | |
| 14590 return (ancestor as CascadeExpression).target; | |
| 14591 } | |
| 14592 return _target; | |
| 14593 } | |
| 14594 | |
| 14595 /** | |
| 14596 * Return the expression computing the object defining the property being | |
| 14597 * accessed, or `null` if this property access is part of a cascade expression
. | |
| 14598 * | |
| 14599 * Use [realTarget] to get the target independent of whether this is part of a | |
| 14600 * cascade expression. | |
| 14601 */ | |
| 14602 Expression get target => _target; | |
| 14603 | |
| 14604 /** | |
| 14605 * Set the expression computing the object defining the property being | |
| 14606 * accessed to the given [expression]. | |
| 14607 */ | |
| 14608 void set target(Expression expression) { | |
| 14609 _target = _becomeParentOf(expression); | |
| 14610 } | |
| 14611 | |
| 14612 @override | |
| 14613 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this); | |
| 14614 | |
| 14615 @override | |
| 14616 void visitChildren(AstVisitor visitor) { | |
| 14617 _safelyVisitChild(_target, visitor); | |
| 14618 _safelyVisitChild(_propertyName, visitor); | |
| 14619 } | |
| 14620 } | |
| 14621 | |
| 14622 /** | |
| 14623 * An AST visitor that will recursively visit all of the nodes in an AST | |
| 14624 * structure. For example, using an instance of this class to visit a [Block] | |
| 14625 * will also cause all of the statements in the block to be visited. | |
| 14626 * | |
| 14627 * Subclasses that override a visit method must either invoke the overridden | |
| 14628 * visit method or must explicitly ask the visited node to visit its children. | |
| 14629 * Failure to do so will cause the children of the visited node to not be | |
| 14630 * visited. | |
| 14631 */ | |
| 14632 class RecursiveAstVisitor<R> implements AstVisitor<R> { | |
| 14633 @override | |
| 14634 R visitAdjacentStrings(AdjacentStrings node) { | |
| 14635 node.visitChildren(this); | |
| 14636 return null; | |
| 14637 } | |
| 14638 | |
| 14639 @override | |
| 14640 R visitAnnotation(Annotation node) { | |
| 14641 node.visitChildren(this); | |
| 14642 return null; | |
| 14643 } | |
| 14644 | |
| 14645 @override | |
| 14646 R visitArgumentList(ArgumentList node) { | |
| 14647 node.visitChildren(this); | |
| 14648 return null; | |
| 14649 } | |
| 14650 | |
| 14651 @override | |
| 14652 R visitAsExpression(AsExpression node) { | |
| 14653 node.visitChildren(this); | |
| 14654 return null; | |
| 14655 } | |
| 14656 | |
| 14657 @override | |
| 14658 R visitAssertStatement(AssertStatement node) { | |
| 14659 node.visitChildren(this); | |
| 14660 return null; | |
| 14661 } | |
| 14662 | |
| 14663 @override | |
| 14664 R visitAssignmentExpression(AssignmentExpression node) { | |
| 14665 node.visitChildren(this); | |
| 14666 return null; | |
| 14667 } | |
| 14668 | |
| 14669 @override | |
| 14670 R visitAwaitExpression(AwaitExpression node) { | |
| 14671 node.visitChildren(this); | |
| 14672 return null; | |
| 14673 } | |
| 14674 | |
| 14675 @override | |
| 14676 R visitBinaryExpression(BinaryExpression node) { | |
| 14677 node.visitChildren(this); | |
| 14678 return null; | |
| 14679 } | |
| 14680 | |
| 14681 @override | |
| 14682 R visitBlock(Block node) { | |
| 14683 node.visitChildren(this); | |
| 14684 return null; | |
| 14685 } | |
| 14686 | |
| 14687 @override | |
| 14688 R visitBlockFunctionBody(BlockFunctionBody node) { | |
| 14689 node.visitChildren(this); | |
| 14690 return null; | |
| 14691 } | |
| 14692 | |
| 14693 @override | |
| 14694 R visitBooleanLiteral(BooleanLiteral node) { | |
| 14695 node.visitChildren(this); | |
| 14696 return null; | |
| 14697 } | |
| 14698 | |
| 14699 @override | |
| 14700 R visitBreakStatement(BreakStatement node) { | |
| 14701 node.visitChildren(this); | |
| 14702 return null; | |
| 14703 } | |
| 14704 | |
| 14705 @override | |
| 14706 R visitCascadeExpression(CascadeExpression node) { | |
| 14707 node.visitChildren(this); | |
| 14708 return null; | |
| 14709 } | |
| 14710 | |
| 14711 @override | |
| 14712 R visitCatchClause(CatchClause node) { | |
| 14713 node.visitChildren(this); | |
| 14714 return null; | |
| 14715 } | |
| 14716 | |
| 14717 @override | |
| 14718 R visitClassDeclaration(ClassDeclaration node) { | |
| 14719 node.visitChildren(this); | |
| 14720 return null; | |
| 14721 } | |
| 14722 | |
| 14723 @override | |
| 14724 R visitClassTypeAlias(ClassTypeAlias node) { | |
| 14725 node.visitChildren(this); | |
| 14726 return null; | |
| 14727 } | |
| 14728 | |
| 14729 @override | |
| 14730 R visitComment(Comment node) { | |
| 14731 node.visitChildren(this); | |
| 14732 return null; | |
| 14733 } | |
| 14734 | |
| 14735 @override | |
| 14736 R visitCommentReference(CommentReference node) { | |
| 14737 node.visitChildren(this); | |
| 14738 return null; | |
| 14739 } | |
| 14740 | |
| 14741 @override | |
| 14742 R visitCompilationUnit(CompilationUnit node) { | |
| 14743 node.visitChildren(this); | |
| 14744 return null; | |
| 14745 } | |
| 14746 | |
| 14747 @override | |
| 14748 R visitConditionalExpression(ConditionalExpression node) { | |
| 14749 node.visitChildren(this); | |
| 14750 return null; | |
| 14751 } | |
| 14752 | |
| 14753 @override | |
| 14754 R visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 14755 node.visitChildren(this); | |
| 14756 return null; | |
| 14757 } | |
| 14758 | |
| 14759 @override | |
| 14760 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 14761 node.visitChildren(this); | |
| 14762 return null; | |
| 14763 } | |
| 14764 | |
| 14765 @override | |
| 14766 R visitConstructorName(ConstructorName node) { | |
| 14767 node.visitChildren(this); | |
| 14768 return null; | |
| 14769 } | |
| 14770 | |
| 14771 @override | |
| 14772 R visitContinueStatement(ContinueStatement node) { | |
| 14773 node.visitChildren(this); | |
| 14774 return null; | |
| 14775 } | |
| 14776 | |
| 14777 @override | |
| 14778 R visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 14779 node.visitChildren(this); | |
| 14780 return null; | |
| 14781 } | |
| 14782 | |
| 14783 @override | |
| 14784 R visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 14785 node.visitChildren(this); | |
| 14786 return null; | |
| 14787 } | |
| 14788 | |
| 14789 @override | |
| 14790 R visitDoStatement(DoStatement node) { | |
| 14791 node.visitChildren(this); | |
| 14792 return null; | |
| 14793 } | |
| 14794 | |
| 14795 @override | |
| 14796 R visitDoubleLiteral(DoubleLiteral node) { | |
| 14797 node.visitChildren(this); | |
| 14798 return null; | |
| 14799 } | |
| 14800 | |
| 14801 @override | |
| 14802 R visitEmptyFunctionBody(EmptyFunctionBody node) { | |
| 14803 node.visitChildren(this); | |
| 14804 return null; | |
| 14805 } | |
| 14806 | |
| 14807 @override | |
| 14808 R visitEmptyStatement(EmptyStatement node) { | |
| 14809 node.visitChildren(this); | |
| 14810 return null; | |
| 14811 } | |
| 14812 | |
| 14813 @override | |
| 14814 R visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 14815 node.visitChildren(this); | |
| 14816 return null; | |
| 14817 } | |
| 14818 | |
| 14819 @override | |
| 14820 R visitEnumDeclaration(EnumDeclaration node) { | |
| 14821 node.visitChildren(this); | |
| 14822 return null; | |
| 14823 } | |
| 14824 | |
| 14825 @override | |
| 14826 R visitExportDirective(ExportDirective node) { | |
| 14827 node.visitChildren(this); | |
| 14828 return null; | |
| 14829 } | |
| 14830 | |
| 14831 @override | |
| 14832 R visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 14833 node.visitChildren(this); | |
| 14834 return null; | |
| 14835 } | |
| 14836 | |
| 14837 @override | |
| 14838 R visitExpressionStatement(ExpressionStatement node) { | |
| 14839 node.visitChildren(this); | |
| 14840 return null; | |
| 14841 } | |
| 14842 | |
| 14843 @override | |
| 14844 R visitExtendsClause(ExtendsClause node) { | |
| 14845 node.visitChildren(this); | |
| 14846 return null; | |
| 14847 } | |
| 14848 | |
| 14849 @override | |
| 14850 R visitFieldDeclaration(FieldDeclaration node) { | |
| 14851 node.visitChildren(this); | |
| 14852 return null; | |
| 14853 } | |
| 14854 | |
| 14855 @override | |
| 14856 R visitFieldFormalParameter(FieldFormalParameter node) { | |
| 14857 node.visitChildren(this); | |
| 14858 return null; | |
| 14859 } | |
| 14860 | |
| 14861 @override | |
| 14862 R visitForEachStatement(ForEachStatement node) { | |
| 14863 node.visitChildren(this); | |
| 14864 return null; | |
| 14865 } | |
| 14866 | |
| 14867 @override | |
| 14868 R visitFormalParameterList(FormalParameterList node) { | |
| 14869 node.visitChildren(this); | |
| 14870 return null; | |
| 14871 } | |
| 14872 | |
| 14873 @override | |
| 14874 R visitForStatement(ForStatement node) { | |
| 14875 node.visitChildren(this); | |
| 14876 return null; | |
| 14877 } | |
| 14878 | |
| 14879 @override | |
| 14880 R visitFunctionDeclaration(FunctionDeclaration node) { | |
| 14881 node.visitChildren(this); | |
| 14882 return null; | |
| 14883 } | |
| 14884 | |
| 14885 @override | |
| 14886 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 14887 node.visitChildren(this); | |
| 14888 return null; | |
| 14889 } | |
| 14890 | |
| 14891 @override | |
| 14892 R visitFunctionExpression(FunctionExpression node) { | |
| 14893 node.visitChildren(this); | |
| 14894 return null; | |
| 14895 } | |
| 14896 | |
| 14897 @override | |
| 14898 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 14899 node.visitChildren(this); | |
| 14900 return null; | |
| 14901 } | |
| 14902 | |
| 14903 @override | |
| 14904 R visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 14905 node.visitChildren(this); | |
| 14906 return null; | |
| 14907 } | |
| 14908 | |
| 14909 @override | |
| 14910 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 14911 node.visitChildren(this); | |
| 14912 return null; | |
| 14913 } | |
| 14914 | |
| 14915 @override | |
| 14916 R visitHideCombinator(HideCombinator node) { | |
| 14917 node.visitChildren(this); | |
| 14918 return null; | |
| 14919 } | |
| 14920 | |
| 14921 @override | |
| 14922 R visitIfStatement(IfStatement node) { | |
| 14923 node.visitChildren(this); | |
| 14924 return null; | |
| 14925 } | |
| 14926 | |
| 14927 @override | |
| 14928 R visitImplementsClause(ImplementsClause node) { | |
| 14929 node.visitChildren(this); | |
| 14930 return null; | |
| 14931 } | |
| 14932 | |
| 14933 @override | |
| 14934 R visitImportDirective(ImportDirective node) { | |
| 14935 node.visitChildren(this); | |
| 14936 return null; | |
| 14937 } | |
| 14938 | |
| 14939 @override | |
| 14940 R visitIndexExpression(IndexExpression node) { | |
| 14941 node.visitChildren(this); | |
| 14942 return null; | |
| 14943 } | |
| 14944 | |
| 14945 @override | |
| 14946 R visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 14947 node.visitChildren(this); | |
| 14948 return null; | |
| 14949 } | |
| 14950 | |
| 14951 @override | |
| 14952 R visitIntegerLiteral(IntegerLiteral node) { | |
| 14953 node.visitChildren(this); | |
| 14954 return null; | |
| 14955 } | |
| 14956 | |
| 14957 @override | |
| 14958 R visitInterpolationExpression(InterpolationExpression node) { | |
| 14959 node.visitChildren(this); | |
| 14960 return null; | |
| 14961 } | |
| 14962 | |
| 14963 @override | |
| 14964 R visitInterpolationString(InterpolationString node) { | |
| 14965 node.visitChildren(this); | |
| 14966 return null; | |
| 14967 } | |
| 14968 | |
| 14969 @override | |
| 14970 R visitIsExpression(IsExpression node) { | |
| 14971 node.visitChildren(this); | |
| 14972 return null; | |
| 14973 } | |
| 14974 | |
| 14975 @override | |
| 14976 R visitLabel(Label node) { | |
| 14977 node.visitChildren(this); | |
| 14978 return null; | |
| 14979 } | |
| 14980 | |
| 14981 @override | |
| 14982 R visitLabeledStatement(LabeledStatement node) { | |
| 14983 node.visitChildren(this); | |
| 14984 return null; | |
| 14985 } | |
| 14986 | |
| 14987 @override | |
| 14988 R visitLibraryDirective(LibraryDirective node) { | |
| 14989 node.visitChildren(this); | |
| 14990 return null; | |
| 14991 } | |
| 14992 | |
| 14993 @override | |
| 14994 R visitLibraryIdentifier(LibraryIdentifier node) { | |
| 14995 node.visitChildren(this); | |
| 14996 return null; | |
| 14997 } | |
| 14998 | |
| 14999 @override | |
| 15000 R visitListLiteral(ListLiteral node) { | |
| 15001 node.visitChildren(this); | |
| 15002 return null; | |
| 15003 } | |
| 15004 | |
| 15005 @override | |
| 15006 R visitMapLiteral(MapLiteral node) { | |
| 15007 node.visitChildren(this); | |
| 15008 return null; | |
| 15009 } | |
| 15010 | |
| 15011 @override | |
| 15012 R visitMapLiteralEntry(MapLiteralEntry node) { | |
| 15013 node.visitChildren(this); | |
| 15014 return null; | |
| 15015 } | |
| 15016 | |
| 15017 @override | |
| 15018 R visitMethodDeclaration(MethodDeclaration node) { | |
| 15019 node.visitChildren(this); | |
| 15020 return null; | |
| 15021 } | |
| 15022 | |
| 15023 @override | |
| 15024 R visitMethodInvocation(MethodInvocation node) { | |
| 15025 node.visitChildren(this); | |
| 15026 return null; | |
| 15027 } | |
| 15028 | |
| 15029 @override | |
| 15030 R visitNamedExpression(NamedExpression node) { | |
| 15031 node.visitChildren(this); | |
| 15032 return null; | |
| 15033 } | |
| 15034 | |
| 15035 @override | |
| 15036 R visitNativeClause(NativeClause node) { | |
| 15037 node.visitChildren(this); | |
| 15038 return null; | |
| 15039 } | |
| 15040 | |
| 15041 @override | |
| 15042 R visitNativeFunctionBody(NativeFunctionBody node) { | |
| 15043 node.visitChildren(this); | |
| 15044 return null; | |
| 15045 } | |
| 15046 | |
| 15047 @override | |
| 15048 R visitNullLiteral(NullLiteral node) { | |
| 15049 node.visitChildren(this); | |
| 15050 return null; | |
| 15051 } | |
| 15052 | |
| 15053 @override | |
| 15054 R visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 15055 node.visitChildren(this); | |
| 15056 return null; | |
| 15057 } | |
| 15058 | |
| 15059 @override | |
| 15060 R visitPartDirective(PartDirective node) { | |
| 15061 node.visitChildren(this); | |
| 15062 return null; | |
| 15063 } | |
| 15064 | |
| 15065 @override | |
| 15066 R visitPartOfDirective(PartOfDirective node) { | |
| 15067 node.visitChildren(this); | |
| 15068 return null; | |
| 15069 } | |
| 15070 | |
| 15071 @override | |
| 15072 R visitPostfixExpression(PostfixExpression node) { | |
| 15073 node.visitChildren(this); | |
| 15074 return null; | |
| 15075 } | |
| 15076 | |
| 15077 @override | |
| 15078 R visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 15079 node.visitChildren(this); | |
| 15080 return null; | |
| 15081 } | |
| 15082 | |
| 15083 @override | |
| 15084 R visitPrefixExpression(PrefixExpression node) { | |
| 15085 node.visitChildren(this); | |
| 15086 return null; | |
| 15087 } | |
| 15088 | |
| 15089 @override | |
| 15090 R visitPropertyAccess(PropertyAccess node) { | |
| 15091 node.visitChildren(this); | |
| 15092 return null; | |
| 15093 } | |
| 15094 | |
| 15095 @override | |
| 15096 R visitRedirectingConstructorInvocation( | |
| 15097 RedirectingConstructorInvocation node) { | |
| 15098 node.visitChildren(this); | |
| 15099 return null; | |
| 15100 } | |
| 15101 | |
| 15102 @override | |
| 15103 R visitRethrowExpression(RethrowExpression node) { | |
| 15104 node.visitChildren(this); | |
| 15105 return null; | |
| 15106 } | |
| 15107 | |
| 15108 @override | |
| 15109 R visitReturnStatement(ReturnStatement node) { | |
| 15110 node.visitChildren(this); | |
| 15111 return null; | |
| 15112 } | |
| 15113 | |
| 15114 @override | |
| 15115 R visitScriptTag(ScriptTag node) { | |
| 15116 node.visitChildren(this); | |
| 15117 return null; | |
| 15118 } | |
| 15119 | |
| 15120 @override | |
| 15121 R visitShowCombinator(ShowCombinator node) { | |
| 15122 node.visitChildren(this); | |
| 15123 return null; | |
| 15124 } | |
| 15125 | |
| 15126 @override | |
| 15127 R visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 15128 node.visitChildren(this); | |
| 15129 return null; | |
| 15130 } | |
| 15131 | |
| 15132 @override | |
| 15133 R visitSimpleIdentifier(SimpleIdentifier node) { | |
| 15134 node.visitChildren(this); | |
| 15135 return null; | |
| 15136 } | |
| 15137 | |
| 15138 @override | |
| 15139 R visitSimpleStringLiteral(SimpleStringLiteral node) { | |
| 15140 node.visitChildren(this); | |
| 15141 return null; | |
| 15142 } | |
| 15143 | |
| 15144 @override | |
| 15145 R visitStringInterpolation(StringInterpolation node) { | |
| 15146 node.visitChildren(this); | |
| 15147 return null; | |
| 15148 } | |
| 15149 | |
| 15150 @override | |
| 15151 R visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 15152 node.visitChildren(this); | |
| 15153 return null; | |
| 15154 } | |
| 15155 | |
| 15156 @override | |
| 15157 R visitSuperExpression(SuperExpression node) { | |
| 15158 node.visitChildren(this); | |
| 15159 return null; | |
| 15160 } | |
| 15161 | |
| 15162 @override | |
| 15163 R visitSwitchCase(SwitchCase node) { | |
| 15164 node.visitChildren(this); | |
| 15165 return null; | |
| 15166 } | |
| 15167 | |
| 15168 @override | |
| 15169 R visitSwitchDefault(SwitchDefault node) { | |
| 15170 node.visitChildren(this); | |
| 15171 return null; | |
| 15172 } | |
| 15173 | |
| 15174 @override | |
| 15175 R visitSwitchStatement(SwitchStatement node) { | |
| 15176 node.visitChildren(this); | |
| 15177 return null; | |
| 15178 } | |
| 15179 | |
| 15180 @override | |
| 15181 R visitSymbolLiteral(SymbolLiteral node) { | |
| 15182 node.visitChildren(this); | |
| 15183 return null; | |
| 15184 } | |
| 15185 | |
| 15186 @override | |
| 15187 R visitThisExpression(ThisExpression node) { | |
| 15188 node.visitChildren(this); | |
| 15189 return null; | |
| 15190 } | |
| 15191 | |
| 15192 @override | |
| 15193 R visitThrowExpression(ThrowExpression node) { | |
| 15194 node.visitChildren(this); | |
| 15195 return null; | |
| 15196 } | |
| 15197 | |
| 15198 @override | |
| 15199 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 15200 node.visitChildren(this); | |
| 15201 return null; | |
| 15202 } | |
| 15203 | |
| 15204 @override | |
| 15205 R visitTryStatement(TryStatement node) { | |
| 15206 node.visitChildren(this); | |
| 15207 return null; | |
| 15208 } | |
| 15209 | |
| 15210 @override | |
| 15211 R visitTypeArgumentList(TypeArgumentList node) { | |
| 15212 node.visitChildren(this); | |
| 15213 return null; | |
| 15214 } | |
| 15215 | |
| 15216 @override | |
| 15217 R visitTypeName(TypeName node) { | |
| 15218 node.visitChildren(this); | |
| 15219 return null; | |
| 15220 } | |
| 15221 | |
| 15222 @override | |
| 15223 R visitTypeParameter(TypeParameter node) { | |
| 15224 node.visitChildren(this); | |
| 15225 return null; | |
| 15226 } | |
| 15227 | |
| 15228 @override | |
| 15229 R visitTypeParameterList(TypeParameterList node) { | |
| 15230 node.visitChildren(this); | |
| 15231 return null; | |
| 15232 } | |
| 15233 | |
| 15234 @override | |
| 15235 R visitVariableDeclaration(VariableDeclaration node) { | |
| 15236 node.visitChildren(this); | |
| 15237 return null; | |
| 15238 } | |
| 15239 | |
| 15240 @override | |
| 15241 R visitVariableDeclarationList(VariableDeclarationList node) { | |
| 15242 node.visitChildren(this); | |
| 15243 return null; | |
| 15244 } | |
| 15245 | |
| 15246 @override | |
| 15247 R visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 15248 node.visitChildren(this); | |
| 15249 return null; | |
| 15250 } | |
| 15251 | |
| 15252 @override | |
| 15253 R visitWhileStatement(WhileStatement node) { | |
| 15254 node.visitChildren(this); | |
| 15255 return null; | |
| 15256 } | |
| 15257 | |
| 15258 @override | |
| 15259 R visitWithClause(WithClause node) { | |
| 15260 node.visitChildren(this); | |
| 15261 return null; | |
| 15262 } | |
| 15263 | |
| 15264 @override | |
| 15265 R visitYieldStatement(YieldStatement node) { | |
| 15266 node.visitChildren(this); | |
| 15267 return null; | |
| 15268 } | |
| 15269 } | |
| 15270 | |
| 15271 /** | |
| 15272 * The invocation of a constructor in the same class from within a constructor's | |
| 15273 * initialization list. | |
| 15274 * | |
| 15275 * > redirectingConstructorInvocation ::= | |
| 15276 * > 'this' ('.' identifier)? arguments | |
| 15277 */ | |
| 15278 class RedirectingConstructorInvocation extends ConstructorInitializer { | |
| 15279 /** | |
| 15280 * The token for the 'this' keyword. | |
| 15281 */ | |
| 15282 Token thisKeyword; | |
| 15283 | |
| 15284 /** | |
| 15285 * The token for the period before the name of the constructor that is being | |
| 15286 * invoked, or `null` if the unnamed constructor is being invoked. | |
| 15287 */ | |
| 15288 Token period; | |
| 15289 | |
| 15290 /** | |
| 15291 * The name of the constructor that is being invoked, or `null` if the unnamed | |
| 15292 * constructor is being invoked. | |
| 15293 */ | |
| 15294 SimpleIdentifier _constructorName; | |
| 15295 | |
| 15296 /** | |
| 15297 * The list of arguments to the constructor. | |
| 15298 */ | |
| 15299 ArgumentList _argumentList; | |
| 15300 | |
| 15301 /** | |
| 15302 * The element associated with the constructor based on static type | |
| 15303 * information, or `null` if the AST structure has not been resolved or if the | |
| 15304 * constructor could not be resolved. | |
| 15305 */ | |
| 15306 ConstructorElement staticElement; | |
| 15307 | |
| 15308 /** | |
| 15309 * Initialize a newly created redirecting invocation to invoke the constructor | |
| 15310 * with the given name with the given arguments. The [constructorName] can be | |
| 15311 * `null` if the constructor being invoked is the unnamed constructor. | |
| 15312 */ | |
| 15313 RedirectingConstructorInvocation(this.thisKeyword, this.period, | |
| 15314 SimpleIdentifier constructorName, ArgumentList argumentList) { | |
| 15315 _constructorName = _becomeParentOf(constructorName); | |
| 15316 _argumentList = _becomeParentOf(argumentList); | |
| 15317 } | |
| 15318 | |
| 15319 /** | |
| 15320 * Return the list of arguments to the constructor. | |
| 15321 */ | |
| 15322 ArgumentList get argumentList => _argumentList; | |
| 15323 | |
| 15324 /** | |
| 15325 * Set the list of arguments to the constructor to the given [argumentList]. | |
| 15326 */ | |
| 15327 void set argumentList(ArgumentList argumentList) { | |
| 15328 _argumentList = _becomeParentOf(argumentList); | |
| 15329 } | |
| 15330 | |
| 15331 @override | |
| 15332 Token get beginToken => thisKeyword; | |
| 15333 | |
| 15334 @override | |
| 15335 Iterable get childEntities => new ChildEntities() | |
| 15336 ..add(thisKeyword) | |
| 15337 ..add(period) | |
| 15338 ..add(_constructorName) | |
| 15339 ..add(_argumentList); | |
| 15340 | |
| 15341 /** | |
| 15342 * Return the name of the constructor that is being invoked, or `null` if the | |
| 15343 * unnamed constructor is being invoked. | |
| 15344 */ | |
| 15345 SimpleIdentifier get constructorName => _constructorName; | |
| 15346 | |
| 15347 /** | |
| 15348 * Set the name of the constructor that is being invoked to the given | |
| 15349 * [identifier]. | |
| 15350 */ | |
| 15351 void set constructorName(SimpleIdentifier identifier) { | |
| 15352 _constructorName = _becomeParentOf(identifier); | |
| 15353 } | |
| 15354 | |
| 15355 @override | |
| 15356 Token get endToken => _argumentList.endToken; | |
| 15357 | |
| 15358 /** | |
| 15359 * Return the token for the 'this' keyword. | |
| 15360 */ | |
| 15361 @deprecated // Use "this.thisKeyword" | |
| 15362 Token get keyword => thisKeyword; | |
| 15363 | |
| 15364 /** | |
| 15365 * Set the token for the 'this' keyword to the given [token]. | |
| 15366 */ | |
| 15367 @deprecated // Use "this.thisKeyword" | |
| 15368 set keyword(Token token) { | |
| 15369 thisKeyword = token; | |
| 15370 } | |
| 15371 | |
| 15372 @override | |
| 15373 accept(AstVisitor visitor) => | |
| 15374 visitor.visitRedirectingConstructorInvocation(this); | |
| 15375 | |
| 15376 @override | |
| 15377 void visitChildren(AstVisitor visitor) { | |
| 15378 _safelyVisitChild(_constructorName, visitor); | |
| 15379 _safelyVisitChild(_argumentList, visitor); | |
| 15380 } | |
| 15381 } | |
| 15382 | |
| 15383 /** | |
| 15384 * A rethrow expression. | |
| 15385 * | |
| 15386 * > rethrowExpression ::= | |
| 15387 * > 'rethrow' | |
| 15388 */ | |
| 15389 class RethrowExpression extends Expression { | |
| 15390 /** | |
| 15391 * The token representing the 'rethrow' keyword. | |
| 15392 */ | |
| 15393 Token rethrowKeyword; | |
| 15394 | |
| 15395 /** | |
| 15396 * Initialize a newly created rethrow expression. | |
| 15397 */ | |
| 15398 RethrowExpression(this.rethrowKeyword); | |
| 15399 | |
| 15400 @override | |
| 15401 Token get beginToken => rethrowKeyword; | |
| 15402 | |
| 15403 @override | |
| 15404 Iterable get childEntities => new ChildEntities()..add(rethrowKeyword); | |
| 15405 | |
| 15406 @override | |
| 15407 Token get endToken => rethrowKeyword; | |
| 15408 | |
| 15409 /** | |
| 15410 * Return the token representing the 'rethrow' keyword. | |
| 15411 */ | |
| 15412 @deprecated // Use "this.rethrowKeyword" | |
| 15413 Token get keyword => rethrowKeyword; | |
| 15414 | |
| 15415 /** | |
| 15416 * Set the token representing the 'rethrow' keyword to the given [token]. | |
| 15417 */ | |
| 15418 @deprecated // Use "this.rethrowKeyword" | |
| 15419 set keyword(Token token) { | |
| 15420 rethrowKeyword = token; | |
| 15421 } | |
| 15422 | |
| 15423 @override | |
| 15424 int get precedence => 0; | |
| 15425 | |
| 15426 @override | |
| 15427 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this); | |
| 15428 | |
| 15429 @override | |
| 15430 void visitChildren(AstVisitor visitor) { | |
| 15431 // There are no children to visit. | |
| 15432 } | |
| 15433 } | |
| 15434 | |
| 15435 /** | |
| 15436 * A return statement. | |
| 15437 * | |
| 15438 * > returnStatement ::= | |
| 15439 * > 'return' [Expression]? ';' | |
| 15440 */ | |
| 15441 class ReturnStatement extends Statement { | |
| 15442 /** | |
| 15443 * The token representing the 'return' keyword. | |
| 15444 */ | |
| 15445 Token returnKeyword; | |
| 15446 | |
| 15447 /** | |
| 15448 * The expression computing the value to be returned, or `null` if no explicit | |
| 15449 * value was provided. | |
| 15450 */ | |
| 15451 Expression _expression; | |
| 15452 | |
| 15453 /** | |
| 15454 * The semicolon terminating the statement. | |
| 15455 */ | |
| 15456 Token semicolon; | |
| 15457 | |
| 15458 /** | |
| 15459 * Initialize a newly created return statement. The [expression] can be `null` | |
| 15460 * if no explicit value was provided. | |
| 15461 */ | |
| 15462 ReturnStatement(this.returnKeyword, Expression expression, this.semicolon) { | |
| 15463 _expression = _becomeParentOf(expression); | |
| 15464 } | |
| 15465 | |
| 15466 @override | |
| 15467 Token get beginToken => returnKeyword; | |
| 15468 | |
| 15469 @override | |
| 15470 Iterable get childEntities => | |
| 15471 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon); | |
| 15472 | |
| 15473 @override | |
| 15474 Token get endToken => semicolon; | |
| 15475 | |
| 15476 /** | |
| 15477 * Return the expression computing the value to be returned, or `null` if no | |
| 15478 * explicit value was provided. | |
| 15479 */ | |
| 15480 Expression get expression => _expression; | |
| 15481 | |
| 15482 /** | |
| 15483 * Set the expression computing the value to be returned to the given | |
| 15484 * [expression]. | |
| 15485 */ | |
| 15486 void set expression(Expression expression) { | |
| 15487 _expression = _becomeParentOf(expression); | |
| 15488 } | |
| 15489 | |
| 15490 /** | |
| 15491 * Return the token representing the 'return' keyword. | |
| 15492 */ | |
| 15493 @deprecated // Use "this.returnKeyword" | |
| 15494 Token get keyword => returnKeyword; | |
| 15495 | |
| 15496 /** | |
| 15497 * Set the token representing the 'return' keyword to the given [token]. | |
| 15498 */ | |
| 15499 @deprecated // Use "this.returnKeyword" | |
| 15500 set keyword(Token token) { | |
| 15501 returnKeyword = token; | |
| 15502 } | |
| 15503 | |
| 15504 @override | |
| 15505 accept(AstVisitor visitor) => visitor.visitReturnStatement(this); | |
| 15506 | |
| 15507 @override | |
| 15508 void visitChildren(AstVisitor visitor) { | |
| 15509 _safelyVisitChild(_expression, visitor); | |
| 15510 } | |
| 15511 } | |
| 15512 | |
| 15513 /** | |
| 15514 * Traverse the AST from initial child node to successive parents, building a | |
| 15515 * collection of local variable and parameter names visible to the initial child | |
| 15516 * node. In case of name shadowing, the first name seen is the most specific one | |
| 15517 * so names are not redefined. | |
| 15518 * | |
| 15519 * Completion test code coverage is 95%. The two basic blocks that are not | |
| 15520 * executed cannot be executed. They are included for future reference. | |
| 15521 */ | |
| 15522 class ScopedNameFinder extends GeneralizingAstVisitor<Object> { | |
| 15523 Declaration _declarationNode; | |
| 15524 | |
| 15525 AstNode _immediateChild; | |
| 15526 | |
| 15527 Map<String, SimpleIdentifier> _locals = | |
| 15528 new HashMap<String, SimpleIdentifier>(); | |
| 15529 | |
| 15530 final int _position; | |
| 15531 | |
| 15532 bool _referenceIsWithinLocalFunction = false; | |
| 15533 | |
| 15534 ScopedNameFinder(this._position); | |
| 15535 | |
| 15536 Declaration get declaration => _declarationNode; | |
| 15537 | |
| 15538 Map<String, SimpleIdentifier> get locals => _locals; | |
| 15539 | |
| 15540 @override | |
| 15541 Object visitBlock(Block node) { | |
| 15542 _checkStatements(node.statements); | |
| 15543 return super.visitBlock(node); | |
| 15544 } | |
| 15545 | |
| 15546 @override | |
| 15547 Object visitCatchClause(CatchClause node) { | |
| 15548 _addToScope(node.exceptionParameter); | |
| 15549 _addToScope(node.stackTraceParameter); | |
| 15550 return super.visitCatchClause(node); | |
| 15551 } | |
| 15552 | |
| 15553 @override | |
| 15554 Object visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 15555 if (!identical(_immediateChild, node.parameters)) { | |
| 15556 _addParameters(node.parameters.parameters); | |
| 15557 } | |
| 15558 _declarationNode = node; | |
| 15559 return null; | |
| 15560 } | |
| 15561 | |
| 15562 @override | |
| 15563 Object visitFieldDeclaration(FieldDeclaration node) { | |
| 15564 _declarationNode = node; | |
| 15565 return null; | |
| 15566 } | |
| 15567 | |
| 15568 @override | |
| 15569 Object visitForEachStatement(ForEachStatement node) { | |
| 15570 DeclaredIdentifier loopVariable = node.loopVariable; | |
| 15571 if (loopVariable != null) { | |
| 15572 _addToScope(loopVariable.identifier); | |
| 15573 } | |
| 15574 return super.visitForEachStatement(node); | |
| 15575 } | |
| 15576 | |
| 15577 @override | |
| 15578 Object visitForStatement(ForStatement node) { | |
| 15579 if (!identical(_immediateChild, node.variables) && node.variables != null) { | |
| 15580 _addVariables(node.variables.variables); | |
| 15581 } | |
| 15582 return super.visitForStatement(node); | |
| 15583 } | |
| 15584 | |
| 15585 @override | |
| 15586 Object visitFunctionDeclaration(FunctionDeclaration node) { | |
| 15587 if (node.parent is! FunctionDeclarationStatement) { | |
| 15588 _declarationNode = node; | |
| 15589 return null; | |
| 15590 } | |
| 15591 return super.visitFunctionDeclaration(node); | |
| 15592 } | |
| 15593 | |
| 15594 @override | |
| 15595 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 15596 _referenceIsWithinLocalFunction = true; | |
| 15597 return super.visitFunctionDeclarationStatement(node); | |
| 15598 } | |
| 15599 | |
| 15600 @override | |
| 15601 Object visitFunctionExpression(FunctionExpression node) { | |
| 15602 if (node.parameters != null && | |
| 15603 !identical(_immediateChild, node.parameters)) { | |
| 15604 _addParameters(node.parameters.parameters); | |
| 15605 } | |
| 15606 return super.visitFunctionExpression(node); | |
| 15607 } | |
| 15608 | |
| 15609 @override | |
| 15610 Object visitMethodDeclaration(MethodDeclaration node) { | |
| 15611 _declarationNode = node; | |
| 15612 if (node.parameters == null) { | |
| 15613 return null; | |
| 15614 } | |
| 15615 if (!identical(_immediateChild, node.parameters)) { | |
| 15616 _addParameters(node.parameters.parameters); | |
| 15617 } | |
| 15618 return null; | |
| 15619 } | |
| 15620 | |
| 15621 @override | |
| 15622 Object visitNode(AstNode node) { | |
| 15623 _immediateChild = node; | |
| 15624 AstNode parent = node.parent; | |
| 15625 if (parent != null) { | |
| 15626 parent.accept(this); | |
| 15627 } | |
| 15628 return null; | |
| 15629 } | |
| 15630 | |
| 15631 @override | |
| 15632 Object visitSwitchMember(SwitchMember node) { | |
| 15633 _checkStatements(node.statements); | |
| 15634 return super.visitSwitchMember(node); | |
| 15635 } | |
| 15636 | |
| 15637 @override | |
| 15638 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 15639 _declarationNode = node; | |
| 15640 return null; | |
| 15641 } | |
| 15642 | |
| 15643 @override | |
| 15644 Object visitTypeAlias(TypeAlias node) { | |
| 15645 _declarationNode = node; | |
| 15646 return null; | |
| 15647 } | |
| 15648 | |
| 15649 void _addParameters(NodeList<FormalParameter> vars) { | |
| 15650 for (FormalParameter var2 in vars) { | |
| 15651 _addToScope(var2.identifier); | |
| 15652 } | |
| 15653 } | |
| 15654 | |
| 15655 void _addToScope(SimpleIdentifier identifier) { | |
| 15656 if (identifier != null && _isInRange(identifier)) { | |
| 15657 String name = identifier.name; | |
| 15658 if (!_locals.containsKey(name)) { | |
| 15659 _locals[name] = identifier; | |
| 15660 } | |
| 15661 } | |
| 15662 } | |
| 15663 | |
| 15664 void _addVariables(NodeList<VariableDeclaration> variables) { | |
| 15665 for (VariableDeclaration variable in variables) { | |
| 15666 _addToScope(variable.name); | |
| 15667 } | |
| 15668 } | |
| 15669 | |
| 15670 /** | |
| 15671 * Check the given list of [statements] for any that come before the immediate | |
| 15672 * child and that define a name that would be visible to the immediate child. | |
| 15673 */ | |
| 15674 void _checkStatements(List<Statement> statements) { | |
| 15675 for (Statement statement in statements) { | |
| 15676 if (identical(statement, _immediateChild)) { | |
| 15677 return; | |
| 15678 } | |
| 15679 if (statement is VariableDeclarationStatement) { | |
| 15680 _addVariables(statement.variables.variables); | |
| 15681 } else if (statement is FunctionDeclarationStatement && | |
| 15682 !_referenceIsWithinLocalFunction) { | |
| 15683 _addToScope(statement.functionDeclaration.name); | |
| 15684 } | |
| 15685 } | |
| 15686 } | |
| 15687 | |
| 15688 bool _isInRange(AstNode node) { | |
| 15689 if (_position < 0) { | |
| 15690 // if source position is not set then all nodes are in range | |
| 15691 return true; | |
| 15692 // not reached | |
| 15693 } | |
| 15694 return node.end < _position; | |
| 15695 } | |
| 15696 } | |
| 15697 | |
| 15698 /** | |
| 15699 * A script tag that can optionally occur at the beginning of a compilation unit
. | |
| 15700 * | |
| 15701 * > scriptTag ::= | |
| 15702 * > '#!' (~NEWLINE)* NEWLINE | |
| 15703 */ | |
| 15704 class ScriptTag extends AstNode { | |
| 15705 /** | |
| 15706 * The token representing this script tag. | |
| 15707 */ | |
| 15708 Token scriptTag; | |
| 15709 | |
| 15710 /** | |
| 15711 * Initialize a newly created script tag. | |
| 15712 */ | |
| 15713 ScriptTag(this.scriptTag); | |
| 15714 | |
| 15715 @override | |
| 15716 Token get beginToken => scriptTag; | |
| 15717 | |
| 15718 @override | |
| 15719 Iterable get childEntities => new ChildEntities()..add(scriptTag); | |
| 15720 | |
| 15721 @override | |
| 15722 Token get endToken => scriptTag; | |
| 15723 | |
| 15724 @override | |
| 15725 accept(AstVisitor visitor) => visitor.visitScriptTag(this); | |
| 15726 | |
| 15727 @override | |
| 15728 void visitChildren(AstVisitor visitor) { | |
| 15729 // There are no children to visit. | |
| 15730 } | |
| 15731 } | |
| 15732 | |
| 15733 /** | |
| 15734 * A combinator that restricts the names being imported to those in a given list
. | |
| 15735 * | |
| 15736 * > showCombinator ::= | |
| 15737 * > 'show' [SimpleIdentifier] (',' [SimpleIdentifier])* | |
| 15738 */ | |
| 15739 class ShowCombinator extends Combinator { | |
| 15740 /** | |
| 15741 * The list of names from the library that are made visible by this combinator
. | |
| 15742 */ | |
| 15743 NodeList<SimpleIdentifier> _shownNames; | |
| 15744 | |
| 15745 /** | |
| 15746 * Initialize a newly created import show combinator. | |
| 15747 */ | |
| 15748 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames) | |
| 15749 : super(keyword) { | |
| 15750 _shownNames = new NodeList<SimpleIdentifier>(this, shownNames); | |
| 15751 } | |
| 15752 | |
| 15753 /** | |
| 15754 * TODO(paulberry): add commas. | |
| 15755 */ | |
| 15756 @override | |
| 15757 Iterable get childEntities => new ChildEntities() | |
| 15758 ..add(keyword) | |
| 15759 ..addAll(_shownNames); | |
| 15760 | |
| 15761 @override | |
| 15762 Token get endToken => _shownNames.endToken; | |
| 15763 | |
| 15764 /** | |
| 15765 * Return the list of names from the library that are made visible by this | |
| 15766 * combinator. | |
| 15767 */ | |
| 15768 NodeList<SimpleIdentifier> get shownNames => _shownNames; | |
| 15769 | |
| 15770 @override | |
| 15771 accept(AstVisitor visitor) => visitor.visitShowCombinator(this); | |
| 15772 | |
| 15773 @override | |
| 15774 void visitChildren(AstVisitor visitor) { | |
| 15775 _shownNames.accept(visitor); | |
| 15776 } | |
| 15777 } | |
| 15778 | |
| 15779 /** | |
| 15780 * An AST visitor that will do nothing when visiting an AST node. It is intended | |
| 15781 * to be a superclass for classes that use the visitor pattern primarily as a | |
| 15782 * dispatch mechanism (and hence don't need to recursively visit a whole | |
| 15783 * structure) and that only need to visit a small number of node types. | |
| 15784 */ | |
| 15785 class SimpleAstVisitor<R> implements AstVisitor<R> { | |
| 15786 @override | |
| 15787 R visitAdjacentStrings(AdjacentStrings node) => null; | |
| 15788 | |
| 15789 @override | |
| 15790 R visitAnnotation(Annotation node) => null; | |
| 15791 | |
| 15792 @override | |
| 15793 R visitArgumentList(ArgumentList node) => null; | |
| 15794 | |
| 15795 @override | |
| 15796 R visitAsExpression(AsExpression node) => null; | |
| 15797 | |
| 15798 @override | |
| 15799 R visitAssertStatement(AssertStatement node) => null; | |
| 15800 | |
| 15801 @override | |
| 15802 R visitAssignmentExpression(AssignmentExpression node) => null; | |
| 15803 | |
| 15804 @override | |
| 15805 R visitAwaitExpression(AwaitExpression node) => null; | |
| 15806 | |
| 15807 @override | |
| 15808 R visitBinaryExpression(BinaryExpression node) => null; | |
| 15809 | |
| 15810 @override | |
| 15811 R visitBlock(Block node) => null; | |
| 15812 | |
| 15813 @override | |
| 15814 R visitBlockFunctionBody(BlockFunctionBody node) => null; | |
| 15815 | |
| 15816 @override | |
| 15817 R visitBooleanLiteral(BooleanLiteral node) => null; | |
| 15818 | |
| 15819 @override | |
| 15820 R visitBreakStatement(BreakStatement node) => null; | |
| 15821 | |
| 15822 @override | |
| 15823 R visitCascadeExpression(CascadeExpression node) => null; | |
| 15824 | |
| 15825 @override | |
| 15826 R visitCatchClause(CatchClause node) => null; | |
| 15827 | |
| 15828 @override | |
| 15829 R visitClassDeclaration(ClassDeclaration node) => null; | |
| 15830 | |
| 15831 @override | |
| 15832 R visitClassTypeAlias(ClassTypeAlias node) => null; | |
| 15833 | |
| 15834 @override | |
| 15835 R visitComment(Comment node) => null; | |
| 15836 | |
| 15837 @override | |
| 15838 R visitCommentReference(CommentReference node) => null; | |
| 15839 | |
| 15840 @override | |
| 15841 R visitCompilationUnit(CompilationUnit node) => null; | |
| 15842 | |
| 15843 @override | |
| 15844 R visitConditionalExpression(ConditionalExpression node) => null; | |
| 15845 | |
| 15846 @override | |
| 15847 R visitConstructorDeclaration(ConstructorDeclaration node) => null; | |
| 15848 | |
| 15849 @override | |
| 15850 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => null; | |
| 15851 | |
| 15852 @override | |
| 15853 R visitConstructorName(ConstructorName node) => null; | |
| 15854 | |
| 15855 @override | |
| 15856 R visitContinueStatement(ContinueStatement node) => null; | |
| 15857 | |
| 15858 @override | |
| 15859 R visitDeclaredIdentifier(DeclaredIdentifier node) => null; | |
| 15860 | |
| 15861 @override | |
| 15862 R visitDefaultFormalParameter(DefaultFormalParameter node) => null; | |
| 15863 | |
| 15864 @override | |
| 15865 R visitDoStatement(DoStatement node) => null; | |
| 15866 | |
| 15867 @override | |
| 15868 R visitDoubleLiteral(DoubleLiteral node) => null; | |
| 15869 | |
| 15870 @override | |
| 15871 R visitEmptyFunctionBody(EmptyFunctionBody node) => null; | |
| 15872 | |
| 15873 @override | |
| 15874 R visitEmptyStatement(EmptyStatement node) => null; | |
| 15875 | |
| 15876 @override | |
| 15877 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => null; | |
| 15878 | |
| 15879 @override | |
| 15880 R visitEnumDeclaration(EnumDeclaration node) => null; | |
| 15881 | |
| 15882 @override | |
| 15883 R visitExportDirective(ExportDirective node) => null; | |
| 15884 | |
| 15885 @override | |
| 15886 R visitExpressionFunctionBody(ExpressionFunctionBody node) => null; | |
| 15887 | |
| 15888 @override | |
| 15889 R visitExpressionStatement(ExpressionStatement node) => null; | |
| 15890 | |
| 15891 @override | |
| 15892 R visitExtendsClause(ExtendsClause node) => null; | |
| 15893 | |
| 15894 @override | |
| 15895 R visitFieldDeclaration(FieldDeclaration node) => null; | |
| 15896 | |
| 15897 @override | |
| 15898 R visitFieldFormalParameter(FieldFormalParameter node) => null; | |
| 15899 | |
| 15900 @override | |
| 15901 R visitForEachStatement(ForEachStatement node) => null; | |
| 15902 | |
| 15903 @override | |
| 15904 R visitFormalParameterList(FormalParameterList node) => null; | |
| 15905 | |
| 15906 @override | |
| 15907 R visitForStatement(ForStatement node) => null; | |
| 15908 | |
| 15909 @override | |
| 15910 R visitFunctionDeclaration(FunctionDeclaration node) => null; | |
| 15911 | |
| 15912 @override | |
| 15913 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => | |
| 15914 null; | |
| 15915 | |
| 15916 @override | |
| 15917 R visitFunctionExpression(FunctionExpression node) => null; | |
| 15918 | |
| 15919 @override | |
| 15920 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => | |
| 15921 null; | |
| 15922 | |
| 15923 @override | |
| 15924 R visitFunctionTypeAlias(FunctionTypeAlias node) => null; | |
| 15925 | |
| 15926 @override | |
| 15927 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => | |
| 15928 null; | |
| 15929 | |
| 15930 @override | |
| 15931 R visitHideCombinator(HideCombinator node) => null; | |
| 15932 | |
| 15933 @override | |
| 15934 R visitIfStatement(IfStatement node) => null; | |
| 15935 | |
| 15936 @override | |
| 15937 R visitImplementsClause(ImplementsClause node) => null; | |
| 15938 | |
| 15939 @override | |
| 15940 R visitImportDirective(ImportDirective node) => null; | |
| 15941 | |
| 15942 @override | |
| 15943 R visitIndexExpression(IndexExpression node) => null; | |
| 15944 | |
| 15945 @override | |
| 15946 R visitInstanceCreationExpression(InstanceCreationExpression node) => null; | |
| 15947 | |
| 15948 @override | |
| 15949 R visitIntegerLiteral(IntegerLiteral node) => null; | |
| 15950 | |
| 15951 @override | |
| 15952 R visitInterpolationExpression(InterpolationExpression node) => null; | |
| 15953 | |
| 15954 @override | |
| 15955 R visitInterpolationString(InterpolationString node) => null; | |
| 15956 | |
| 15957 @override | |
| 15958 R visitIsExpression(IsExpression node) => null; | |
| 15959 | |
| 15960 @override | |
| 15961 R visitLabel(Label node) => null; | |
| 15962 | |
| 15963 @override | |
| 15964 R visitLabeledStatement(LabeledStatement node) => null; | |
| 15965 | |
| 15966 @override | |
| 15967 R visitLibraryDirective(LibraryDirective node) => null; | |
| 15968 | |
| 15969 @override | |
| 15970 R visitLibraryIdentifier(LibraryIdentifier node) => null; | |
| 15971 | |
| 15972 @override | |
| 15973 R visitListLiteral(ListLiteral node) => null; | |
| 15974 | |
| 15975 @override | |
| 15976 R visitMapLiteral(MapLiteral node) => null; | |
| 15977 | |
| 15978 @override | |
| 15979 R visitMapLiteralEntry(MapLiteralEntry node) => null; | |
| 15980 | |
| 15981 @override | |
| 15982 R visitMethodDeclaration(MethodDeclaration node) => null; | |
| 15983 | |
| 15984 @override | |
| 15985 R visitMethodInvocation(MethodInvocation node) => null; | |
| 15986 | |
| 15987 @override | |
| 15988 R visitNamedExpression(NamedExpression node) => null; | |
| 15989 | |
| 15990 @override | |
| 15991 R visitNativeClause(NativeClause node) => null; | |
| 15992 | |
| 15993 @override | |
| 15994 R visitNativeFunctionBody(NativeFunctionBody node) => null; | |
| 15995 | |
| 15996 @override | |
| 15997 R visitNullLiteral(NullLiteral node) => null; | |
| 15998 | |
| 15999 @override | |
| 16000 R visitParenthesizedExpression(ParenthesizedExpression node) => null; | |
| 16001 | |
| 16002 @override | |
| 16003 R visitPartDirective(PartDirective node) => null; | |
| 16004 | |
| 16005 @override | |
| 16006 R visitPartOfDirective(PartOfDirective node) => null; | |
| 16007 | |
| 16008 @override | |
| 16009 R visitPostfixExpression(PostfixExpression node) => null; | |
| 16010 | |
| 16011 @override | |
| 16012 R visitPrefixedIdentifier(PrefixedIdentifier node) => null; | |
| 16013 | |
| 16014 @override | |
| 16015 R visitPrefixExpression(PrefixExpression node) => null; | |
| 16016 | |
| 16017 @override | |
| 16018 R visitPropertyAccess(PropertyAccess node) => null; | |
| 16019 | |
| 16020 @override | |
| 16021 R visitRedirectingConstructorInvocation( | |
| 16022 RedirectingConstructorInvocation node) => null; | |
| 16023 | |
| 16024 @override | |
| 16025 R visitRethrowExpression(RethrowExpression node) => null; | |
| 16026 | |
| 16027 @override | |
| 16028 R visitReturnStatement(ReturnStatement node) => null; | |
| 16029 | |
| 16030 @override | |
| 16031 R visitScriptTag(ScriptTag node) => null; | |
| 16032 | |
| 16033 @override | |
| 16034 R visitShowCombinator(ShowCombinator node) => null; | |
| 16035 | |
| 16036 @override | |
| 16037 R visitSimpleFormalParameter(SimpleFormalParameter node) => null; | |
| 16038 | |
| 16039 @override | |
| 16040 R visitSimpleIdentifier(SimpleIdentifier node) => null; | |
| 16041 | |
| 16042 @override | |
| 16043 R visitSimpleStringLiteral(SimpleStringLiteral node) => null; | |
| 16044 | |
| 16045 @override | |
| 16046 R visitStringInterpolation(StringInterpolation node) => null; | |
| 16047 | |
| 16048 @override | |
| 16049 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => null; | |
| 16050 | |
| 16051 @override | |
| 16052 R visitSuperExpression(SuperExpression node) => null; | |
| 16053 | |
| 16054 @override | |
| 16055 R visitSwitchCase(SwitchCase node) => null; | |
| 16056 | |
| 16057 @override | |
| 16058 R visitSwitchDefault(SwitchDefault node) => null; | |
| 16059 | |
| 16060 @override | |
| 16061 R visitSwitchStatement(SwitchStatement node) => null; | |
| 16062 | |
| 16063 @override | |
| 16064 R visitSymbolLiteral(SymbolLiteral node) => null; | |
| 16065 | |
| 16066 @override | |
| 16067 R visitThisExpression(ThisExpression node) => null; | |
| 16068 | |
| 16069 @override | |
| 16070 R visitThrowExpression(ThrowExpression node) => null; | |
| 16071 | |
| 16072 @override | |
| 16073 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => null; | |
| 16074 | |
| 16075 @override | |
| 16076 R visitTryStatement(TryStatement node) => null; | |
| 16077 | |
| 16078 @override | |
| 16079 R visitTypeArgumentList(TypeArgumentList node) => null; | |
| 16080 | |
| 16081 @override | |
| 16082 R visitTypeName(TypeName node) => null; | |
| 16083 | |
| 16084 @override | |
| 16085 R visitTypeParameter(TypeParameter node) => null; | |
| 16086 | |
| 16087 @override | |
| 16088 R visitTypeParameterList(TypeParameterList node) => null; | |
| 16089 | |
| 16090 @override | |
| 16091 R visitVariableDeclaration(VariableDeclaration node) => null; | |
| 16092 | |
| 16093 @override | |
| 16094 R visitVariableDeclarationList(VariableDeclarationList node) => null; | |
| 16095 | |
| 16096 @override | |
| 16097 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => | |
| 16098 null; | |
| 16099 | |
| 16100 @override | |
| 16101 R visitWhileStatement(WhileStatement node) => null; | |
| 16102 | |
| 16103 @override | |
| 16104 R visitWithClause(WithClause node) => null; | |
| 16105 | |
| 16106 @override | |
| 16107 R visitYieldStatement(YieldStatement node) => null; | |
| 16108 } | |
| 16109 | |
| 16110 /** | |
| 16111 * A simple formal parameter. | |
| 16112 * | |
| 16113 * > simpleFormalParameter ::= | |
| 16114 * > ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier] | |
| 16115 */ | |
| 16116 class SimpleFormalParameter extends NormalFormalParameter { | |
| 16117 /** | |
| 16118 * The token representing either the 'final', 'const' or 'var' keyword, or | |
| 16119 * `null` if no keyword was used. | |
| 16120 */ | |
| 16121 Token keyword; | |
| 16122 | |
| 16123 /** | |
| 16124 * The name of the declared type of the parameter, or `null` if the parameter | |
| 16125 * does not have a declared type. | |
| 16126 */ | |
| 16127 TypeName _type; | |
| 16128 | |
| 16129 /** | |
| 16130 * Initialize a newly created formal parameter. Either or both of the | |
| 16131 * [comment] and [metadata] can be `null` if the parameter does not have the | |
| 16132 * corresponding attribute. The [keyword] can be `null` if a type was | |
| 16133 * specified. The [type] must be `null` if the keyword is 'var'. | |
| 16134 */ | |
| 16135 SimpleFormalParameter(Comment comment, List<Annotation> metadata, | |
| 16136 this.keyword, TypeName type, SimpleIdentifier identifier) | |
| 16137 : super(comment, metadata, identifier) { | |
| 16138 _type = _becomeParentOf(type); | |
| 16139 } | |
| 16140 | |
| 16141 @override | |
| 16142 Token get beginToken { | |
| 16143 NodeList<Annotation> metadata = this.metadata; | |
| 16144 if (!metadata.isEmpty) { | |
| 16145 return metadata.beginToken; | |
| 16146 } else if (keyword != null) { | |
| 16147 return keyword; | |
| 16148 } else if (_type != null) { | |
| 16149 return _type.beginToken; | |
| 16150 } | |
| 16151 return identifier.beginToken; | |
| 16152 } | |
| 16153 | |
| 16154 @override | |
| 16155 Iterable get childEntities => | |
| 16156 super._childEntities..add(keyword)..add(_type)..add(identifier); | |
| 16157 | |
| 16158 @override | |
| 16159 Token get endToken => identifier.endToken; | |
| 16160 | |
| 16161 @override | |
| 16162 bool get isConst => (keyword is KeywordToken) && | |
| 16163 (keyword as KeywordToken).keyword == Keyword.CONST; | |
| 16164 | |
| 16165 @override | |
| 16166 bool get isFinal => (keyword is KeywordToken) && | |
| 16167 (keyword as KeywordToken).keyword == Keyword.FINAL; | |
| 16168 | |
| 16169 /** | |
| 16170 * Return the name of the declared type of the parameter, or `null` if the | |
| 16171 * parameter does not have a declared type. | |
| 16172 */ | |
| 16173 TypeName get type => _type; | |
| 16174 | |
| 16175 /** | |
| 16176 * Set the name of the declared type of the parameter to the given [typeName]. | |
| 16177 */ | |
| 16178 void set type(TypeName typeName) { | |
| 16179 _type = _becomeParentOf(typeName); | |
| 16180 } | |
| 16181 | |
| 16182 @override | |
| 16183 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this); | |
| 16184 | |
| 16185 @override | |
| 16186 void visitChildren(AstVisitor visitor) { | |
| 16187 super.visitChildren(visitor); | |
| 16188 _safelyVisitChild(_type, visitor); | |
| 16189 _safelyVisitChild(identifier, visitor); | |
| 16190 } | |
| 16191 } | |
| 16192 | |
| 16193 /** | |
| 16194 * A simple identifier. | |
| 16195 * | |
| 16196 * > simpleIdentifier ::= | |
| 16197 * > initialCharacter internalCharacter* | |
| 16198 * > | |
| 16199 * > initialCharacter ::= '_' | '$' | letter | |
| 16200 * > | |
| 16201 * > internalCharacter ::= '_' | '$' | letter | digit | |
| 16202 */ | |
| 16203 class SimpleIdentifier extends Identifier { | |
| 16204 /** | |
| 16205 * The token representing the identifier. | |
| 16206 */ | |
| 16207 Token token; | |
| 16208 | |
| 16209 /** | |
| 16210 * The element associated with this identifier based on static type | |
| 16211 * information, or `null` if the AST structure has not been resolved or if | |
| 16212 * this identifier could not be resolved. | |
| 16213 */ | |
| 16214 Element _staticElement; | |
| 16215 | |
| 16216 /** | |
| 16217 * The element associated with this identifier based on propagated type | |
| 16218 * information, or `null` if the AST structure has not been resolved or if | |
| 16219 * this identifier could not be resolved. | |
| 16220 */ | |
| 16221 Element _propagatedElement; | |
| 16222 | |
| 16223 /** | |
| 16224 * If this expression is both in a getter and setter context, the | |
| 16225 * [AuxiliaryElements] will be set to hold onto the static and propagated | |
| 16226 * information. The auxiliary element will hold onto the elements from the | |
| 16227 * getter context. | |
| 16228 */ | |
| 16229 AuxiliaryElements auxiliaryElements = null; | |
| 16230 | |
| 16231 /** | |
| 16232 * Initialize a newly created identifier. | |
| 16233 */ | |
| 16234 SimpleIdentifier(this.token); | |
| 16235 | |
| 16236 @override | |
| 16237 Token get beginToken => token; | |
| 16238 | |
| 16239 @override | |
| 16240 Element get bestElement { | |
| 16241 if (_propagatedElement == null) { | |
| 16242 return _staticElement; | |
| 16243 } | |
| 16244 return _propagatedElement; | |
| 16245 } | |
| 16246 | |
| 16247 @override | |
| 16248 Iterable get childEntities => new ChildEntities()..add(token); | |
| 16249 | |
| 16250 @override | |
| 16251 Token get endToken => token; | |
| 16252 | |
| 16253 /** | |
| 16254 * Returns `true` if this identifier is the "name" part of a prefixed | |
| 16255 * identifier or a method invocation. | |
| 16256 */ | |
| 16257 bool get isQualified { | |
| 16258 AstNode parent = this.parent; | |
| 16259 if (parent is PrefixedIdentifier) { | |
| 16260 return identical(parent.identifier, this); | |
| 16261 } | |
| 16262 if (parent is PropertyAccess) { | |
| 16263 return identical(parent.propertyName, this); | |
| 16264 } | |
| 16265 if (parent is MethodInvocation) { | |
| 16266 MethodInvocation invocation = parent; | |
| 16267 return identical(invocation.methodName, this) && | |
| 16268 invocation.realTarget != null; | |
| 16269 } | |
| 16270 return false; | |
| 16271 } | |
| 16272 | |
| 16273 @override | |
| 16274 bool get isSynthetic => token.isSynthetic; | |
| 16275 | |
| 16276 @override | |
| 16277 String get name => token.lexeme; | |
| 16278 | |
| 16279 @override | |
| 16280 int get precedence => 16; | |
| 16281 | |
| 16282 @override | |
| 16283 Element get propagatedElement => _propagatedElement; | |
| 16284 | |
| 16285 /** | |
| 16286 * Set the element associated with this identifier based on propagated type | |
| 16287 * information to the given [element]. | |
| 16288 */ | |
| 16289 void set propagatedElement(Element element) { | |
| 16290 _propagatedElement = _validateElement(element); | |
| 16291 } | |
| 16292 | |
| 16293 @override | |
| 16294 Element get staticElement => _staticElement; | |
| 16295 | |
| 16296 /** | |
| 16297 * Set the element associated with this identifier based on static type | |
| 16298 * information to the given [element]. | |
| 16299 */ | |
| 16300 void set staticElement(Element element) { | |
| 16301 _staticElement = _validateElement(element); | |
| 16302 } | |
| 16303 | |
| 16304 @override | |
| 16305 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this); | |
| 16306 | |
| 16307 /** | |
| 16308 * Return `true` if this identifier is the name being declared in a | |
| 16309 * declaration. | |
| 16310 */ | |
| 16311 bool inDeclarationContext() { | |
| 16312 // TODO(brianwilkerson) Convert this to a getter. | |
| 16313 AstNode parent = this.parent; | |
| 16314 if (parent is CatchClause) { | |
| 16315 CatchClause clause = parent; | |
| 16316 return identical(this, clause.exceptionParameter) || | |
| 16317 identical(this, clause.stackTraceParameter); | |
| 16318 } else if (parent is ClassDeclaration) { | |
| 16319 return identical(this, parent.name); | |
| 16320 } else if (parent is ClassTypeAlias) { | |
| 16321 return identical(this, parent.name); | |
| 16322 } else if (parent is ConstructorDeclaration) { | |
| 16323 return identical(this, parent.name); | |
| 16324 } else if (parent is DeclaredIdentifier) { | |
| 16325 return identical(this, parent.identifier); | |
| 16326 } else if (parent is EnumDeclaration) { | |
| 16327 return identical(this, parent.name); | |
| 16328 } else if (parent is EnumConstantDeclaration) { | |
| 16329 return identical(this, parent.name); | |
| 16330 } else if (parent is FunctionDeclaration) { | |
| 16331 return identical(this, parent.name); | |
| 16332 } else if (parent is FunctionTypeAlias) { | |
| 16333 return identical(this, parent.name); | |
| 16334 } else if (parent is ImportDirective) { | |
| 16335 return identical(this, parent.prefix); | |
| 16336 } else if (parent is Label) { | |
| 16337 return identical(this, parent.label) && | |
| 16338 (parent.parent is LabeledStatement); | |
| 16339 } else if (parent is MethodDeclaration) { | |
| 16340 return identical(this, parent.name); | |
| 16341 } else if (parent is FunctionTypedFormalParameter || | |
| 16342 parent is SimpleFormalParameter) { | |
| 16343 return identical(this, (parent as NormalFormalParameter).identifier); | |
| 16344 } else if (parent is TypeParameter) { | |
| 16345 return identical(this, parent.name); | |
| 16346 } else if (parent is VariableDeclaration) { | |
| 16347 return identical(this, parent.name); | |
| 16348 } | |
| 16349 return false; | |
| 16350 } | |
| 16351 | |
| 16352 /** | |
| 16353 * Return `true` if this expression is computing a right-hand value. | |
| 16354 * | |
| 16355 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor | |
| 16356 * are they mutually exclusive. In other words, it is possible for both | |
| 16357 * methods to return `true` when invoked on the same node. | |
| 16358 */ | |
| 16359 bool inGetterContext() { | |
| 16360 // TODO(brianwilkerson) Convert this to a getter. | |
| 16361 AstNode parent = this.parent; | |
| 16362 AstNode target = this; | |
| 16363 // skip prefix | |
| 16364 if (parent is PrefixedIdentifier) { | |
| 16365 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | |
| 16366 if (identical(prefixed.prefix, this)) { | |
| 16367 return true; | |
| 16368 } | |
| 16369 parent = prefixed.parent; | |
| 16370 target = prefixed; | |
| 16371 } else if (parent is PropertyAccess) { | |
| 16372 PropertyAccess access = parent as PropertyAccess; | |
| 16373 if (identical(access.target, this)) { | |
| 16374 return true; | |
| 16375 } | |
| 16376 parent = access.parent; | |
| 16377 target = access; | |
| 16378 } | |
| 16379 // skip label | |
| 16380 if (parent is Label) { | |
| 16381 return false; | |
| 16382 } | |
| 16383 // analyze usage | |
| 16384 if (parent is AssignmentExpression) { | |
| 16385 if (identical(parent.leftHandSide, target) && | |
| 16386 parent.operator.type == TokenType.EQ) { | |
| 16387 return false; | |
| 16388 } | |
| 16389 } | |
| 16390 if (parent is ForEachStatement) { | |
| 16391 if (identical(parent.identifier, target)) { | |
| 16392 return false; | |
| 16393 } | |
| 16394 } | |
| 16395 return true; | |
| 16396 } | |
| 16397 | |
| 16398 /** | |
| 16399 * Return `true` if this expression is computing a left-hand value. | |
| 16400 * | |
| 16401 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor | |
| 16402 * are they mutually exclusive. In other words, it is possible for both | |
| 16403 * methods to return `true` when invoked on the same node. | |
| 16404 */ | |
| 16405 bool inSetterContext() { | |
| 16406 // TODO(brianwilkerson) Convert this to a getter. | |
| 16407 AstNode parent = this.parent; | |
| 16408 AstNode target = this; | |
| 16409 // skip prefix | |
| 16410 if (parent is PrefixedIdentifier) { | |
| 16411 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | |
| 16412 // if this is the prefix, then return false | |
| 16413 if (identical(prefixed.prefix, this)) { | |
| 16414 return false; | |
| 16415 } | |
| 16416 parent = prefixed.parent; | |
| 16417 target = prefixed; | |
| 16418 } else if (parent is PropertyAccess) { | |
| 16419 PropertyAccess access = parent as PropertyAccess; | |
| 16420 if (identical(access.target, this)) { | |
| 16421 return false; | |
| 16422 } | |
| 16423 parent = access.parent; | |
| 16424 target = access; | |
| 16425 } | |
| 16426 // analyze usage | |
| 16427 if (parent is PrefixExpression) { | |
| 16428 return parent.operator.type.isIncrementOperator; | |
| 16429 } else if (parent is PostfixExpression) { | |
| 16430 return true; | |
| 16431 } else if (parent is AssignmentExpression) { | |
| 16432 return identical(parent.leftHandSide, target); | |
| 16433 } else if (parent is ForEachStatement) { | |
| 16434 return identical(parent.identifier, target); | |
| 16435 } | |
| 16436 return false; | |
| 16437 } | |
| 16438 | |
| 16439 @override | |
| 16440 void visitChildren(AstVisitor visitor) { | |
| 16441 // There are no children to visit. | |
| 16442 } | |
| 16443 | |
| 16444 /** | |
| 16445 * Return the given element if it is valid, or report the problem and return | |
| 16446 * `null` if it is not appropriate. | |
| 16447 * | |
| 16448 * The [parent] is the parent of the element, used for reporting when there is | |
| 16449 * a problem. | |
| 16450 * The [isValid] is `true` if the element is appropriate. | |
| 16451 * The [element] is the element to be associated with this identifier. | |
| 16452 */ | |
| 16453 Element _returnOrReportElement( | |
| 16454 AstNode parent, bool isValid, Element element) { | |
| 16455 if (!isValid) { | |
| 16456 AnalysisEngine.instance.logger.logInformation( | |
| 16457 "Internal error: attempting to set the name of a ${parent.runtimeType}
to a ${element.runtimeType}", | |
| 16458 new CaughtException(new AnalysisException(), null)); | |
| 16459 return null; | |
| 16460 } | |
| 16461 return element; | |
| 16462 } | |
| 16463 | |
| 16464 /** | |
| 16465 * Return the given [element] if it is an appropriate element based on the | |
| 16466 * parent of this identifier, or `null` if it is not appropriate. | |
| 16467 */ | |
| 16468 Element _validateElement(Element element) { | |
| 16469 if (element == null) { | |
| 16470 return null; | |
| 16471 } | |
| 16472 AstNode parent = this.parent; | |
| 16473 if (parent is ClassDeclaration && identical(parent.name, this)) { | |
| 16474 return _returnOrReportElement(parent, element is ClassElement, element); | |
| 16475 } else if (parent is ClassTypeAlias && identical(parent.name, this)) { | |
| 16476 return _returnOrReportElement(parent, element is ClassElement, element); | |
| 16477 } else if (parent is DeclaredIdentifier && | |
| 16478 identical(parent.identifier, this)) { | |
| 16479 return _returnOrReportElement( | |
| 16480 parent, element is LocalVariableElement, element); | |
| 16481 } else if (parent is FormalParameter && | |
| 16482 identical(parent.identifier, this)) { | |
| 16483 return _returnOrReportElement( | |
| 16484 parent, element is ParameterElement, element); | |
| 16485 } else if (parent is FunctionDeclaration && identical(parent.name, this)) { | |
| 16486 return _returnOrReportElement( | |
| 16487 parent, element is ExecutableElement, element); | |
| 16488 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) { | |
| 16489 return _returnOrReportElement( | |
| 16490 parent, element is FunctionTypeAliasElement, element); | |
| 16491 } else if (parent is MethodDeclaration && identical(parent.name, this)) { | |
| 16492 return _returnOrReportElement( | |
| 16493 parent, element is ExecutableElement, element); | |
| 16494 } else if (parent is TypeParameter && identical(parent.name, this)) { | |
| 16495 return _returnOrReportElement( | |
| 16496 parent, element is TypeParameterElement, element); | |
| 16497 } else if (parent is VariableDeclaration && identical(parent.name, this)) { | |
| 16498 return _returnOrReportElement( | |
| 16499 parent, element is VariableElement, element); | |
| 16500 } | |
| 16501 return element; | |
| 16502 } | |
| 16503 } | |
| 16504 | |
| 16505 /** | |
| 16506 * A string literal expression that does not contain any interpolations. | |
| 16507 * | |
| 16508 * > simpleStringLiteral ::= | |
| 16509 * > rawStringLiteral | |
| 16510 * > | basicStringLiteral | |
| 16511 * > | |
| 16512 * > rawStringLiteral ::= | |
| 16513 * > 'r' basicStringLiteral | |
| 16514 * > | |
| 16515 * > simpleStringLiteral ::= | |
| 16516 * > multiLineStringLiteral | |
| 16517 * > | singleLineStringLiteral | |
| 16518 * > | |
| 16519 * > multiLineStringLiteral ::= | |
| 16520 * > "'''" characters "'''" | |
| 16521 * > | '"""' characters '"""' | |
| 16522 * > | |
| 16523 * > singleLineStringLiteral ::= | |
| 16524 * > "'" characters "'" | |
| 16525 * > | '"' characters '"' | |
| 16526 */ | |
| 16527 class SimpleStringLiteral extends SingleStringLiteral { | |
| 16528 /** | |
| 16529 * The token representing the literal. | |
| 16530 */ | |
| 16531 Token literal; | |
| 16532 | |
| 16533 /** | |
| 16534 * The value of the literal. | |
| 16535 */ | |
| 16536 String _value; | |
| 16537 | |
| 16538 /** | |
| 16539 * The toolkit specific element associated with this literal, or `null`. | |
| 16540 */ | |
| 16541 @deprecated // No replacement | |
| 16542 Element toolkitElement; | |
| 16543 | |
| 16544 /** | |
| 16545 * Initialize a newly created simple string literal. | |
| 16546 */ | |
| 16547 SimpleStringLiteral(this.literal, String value) { | |
| 16548 _value = StringUtilities.intern(value); | |
| 16549 } | |
| 16550 | |
| 16551 @override | |
| 16552 Token get beginToken => literal; | |
| 16553 | |
| 16554 @override | |
| 16555 Iterable get childEntities => new ChildEntities()..add(literal); | |
| 16556 | |
| 16557 @override | |
| 16558 int get contentsEnd => offset + _helper.end; | |
| 16559 | |
| 16560 @override | |
| 16561 int get contentsOffset => offset + _helper.start; | |
| 16562 | |
| 16563 @override | |
| 16564 Token get endToken => literal; | |
| 16565 | |
| 16566 @override | |
| 16567 bool get isMultiline => _helper.isMultiline; | |
| 16568 | |
| 16569 @override | |
| 16570 bool get isRaw => _helper.isRaw; | |
| 16571 | |
| 16572 @override | |
| 16573 bool get isSingleQuoted => _helper.isSingleQuoted; | |
| 16574 | |
| 16575 @override | |
| 16576 bool get isSynthetic => literal.isSynthetic; | |
| 16577 | |
| 16578 /** | |
| 16579 * Return the value of the literal. | |
| 16580 */ | |
| 16581 String get value => _value; | |
| 16582 | |
| 16583 /** | |
| 16584 * Set the value of the literal to the given [string]. | |
| 16585 */ | |
| 16586 void set value(String string) { | |
| 16587 _value = StringUtilities.intern(_value); | |
| 16588 } | |
| 16589 | |
| 16590 StringLexemeHelper get _helper { | |
| 16591 return new StringLexemeHelper(literal.lexeme, true, true); | |
| 16592 } | |
| 16593 | |
| 16594 @override | |
| 16595 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this); | |
| 16596 | |
| 16597 @override | |
| 16598 void visitChildren(AstVisitor visitor) { | |
| 16599 // There are no children to visit. | |
| 16600 } | |
| 16601 | |
| 16602 @override | |
| 16603 void _appendStringValue(StringBuffer buffer) { | |
| 16604 buffer.write(value); | |
| 16605 } | |
| 16606 } | |
| 16607 | |
| 16608 /** | |
| 16609 * A single string literal expression. | |
| 16610 * | |
| 16611 * > singleStringLiteral ::= | |
| 16612 * > [SimpleStringLiteral] | |
| 16613 * > | [StringInterpolation] | |
| 16614 */ | |
| 16615 abstract class SingleStringLiteral extends StringLiteral { | |
| 16616 /** | |
| 16617 * Return the offset of the after-last contents character. | |
| 16618 */ | |
| 16619 int get contentsEnd; | |
| 16620 | |
| 16621 /** | |
| 16622 * Return the offset of the first contents character. | |
| 16623 * If the string is multiline, then leading whitespaces are skipped. | |
| 16624 */ | |
| 16625 int get contentsOffset; | |
| 16626 | |
| 16627 /** | |
| 16628 * Return `true` if this string literal is a multi-line string. | |
| 16629 */ | |
| 16630 bool get isMultiline; | |
| 16631 | |
| 16632 /** | |
| 16633 * Return `true` if this string literal is a raw string. | |
| 16634 */ | |
| 16635 bool get isRaw; | |
| 16636 | |
| 16637 /** | |
| 16638 * Return `true` if this string literal uses single qoutes (' or '''). | |
| 16639 * Return `false` if this string literal uses double qoutes (" or """). | |
| 16640 */ | |
| 16641 bool get isSingleQuoted; | |
| 16642 } | |
| 16643 | |
| 16644 /** | |
| 16645 * A node that represents a statement. | |
| 16646 * | |
| 16647 * > statement ::= | |
| 16648 * > [Block] | |
| 16649 * > | [VariableDeclarationStatement] | |
| 16650 * > | [ForStatement] | |
| 16651 * > | [ForEachStatement] | |
| 16652 * > | [WhileStatement] | |
| 16653 * > | [DoStatement] | |
| 16654 * > | [SwitchStatement] | |
| 16655 * > | [IfStatement] | |
| 16656 * > | [TryStatement] | |
| 16657 * > | [BreakStatement] | |
| 16658 * > | [ContinueStatement] | |
| 16659 * > | [ReturnStatement] | |
| 16660 * > | [ExpressionStatement] | |
| 16661 * > | [FunctionDeclarationStatement] | |
| 16662 */ | |
| 16663 abstract class Statement extends AstNode { | |
| 16664 /** | |
| 16665 * If this is a labeled statement, return the unlabeled portion of the | |
| 16666 * statement. Otherwise return the statement itself. | |
| 16667 */ | |
| 16668 Statement get unlabeled => this; | |
| 16669 } | |
| 16670 | |
| 16671 /** | |
| 16672 * A string interpolation literal. | |
| 16673 * | |
| 16674 * > stringInterpolation ::= | |
| 16675 * > ''' [InterpolationElement]* ''' | |
| 16676 * > | '"' [InterpolationElement]* '"' | |
| 16677 */ | |
| 16678 class StringInterpolation extends SingleStringLiteral { | |
| 16679 /** | |
| 16680 * The elements that will be composed to produce the resulting string. | |
| 16681 */ | |
| 16682 NodeList<InterpolationElement> _elements; | |
| 16683 | |
| 16684 /** | |
| 16685 * Initialize a newly created string interpolation expression. | |
| 16686 */ | |
| 16687 StringInterpolation(List<InterpolationElement> elements) { | |
| 16688 _elements = new NodeList<InterpolationElement>(this, elements); | |
| 16689 } | |
| 16690 | |
| 16691 @override | |
| 16692 Token get beginToken => _elements.beginToken; | |
| 16693 | |
| 16694 @override | |
| 16695 Iterable get childEntities => new ChildEntities()..addAll(_elements); | |
| 16696 | |
| 16697 @override | |
| 16698 int get contentsEnd { | |
| 16699 InterpolationString element = _elements.last; | |
| 16700 return element.contentsEnd; | |
| 16701 } | |
| 16702 | |
| 16703 @override | |
| 16704 int get contentsOffset { | |
| 16705 InterpolationString element = _elements.first; | |
| 16706 return element.contentsOffset; | |
| 16707 } | |
| 16708 | |
| 16709 /** | |
| 16710 * Return the elements that will be composed to produce the resulting string. | |
| 16711 */ | |
| 16712 NodeList<InterpolationElement> get elements => _elements; | |
| 16713 | |
| 16714 @override | |
| 16715 Token get endToken => _elements.endToken; | |
| 16716 | |
| 16717 @override | |
| 16718 bool get isMultiline => _firstHelper.isMultiline; | |
| 16719 | |
| 16720 @override | |
| 16721 bool get isRaw => false; | |
| 16722 | |
| 16723 @override | |
| 16724 bool get isSingleQuoted => _firstHelper.isSingleQuoted; | |
| 16725 | |
| 16726 StringLexemeHelper get _firstHelper { | |
| 16727 InterpolationString lastString = _elements.first; | |
| 16728 String lexeme = lastString.contents.lexeme; | |
| 16729 return new StringLexemeHelper(lexeme, true, false); | |
| 16730 } | |
| 16731 | |
| 16732 @override | |
| 16733 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this); | |
| 16734 | |
| 16735 @override | |
| 16736 void visitChildren(AstVisitor visitor) { | |
| 16737 _elements.accept(visitor); | |
| 16738 } | |
| 16739 | |
| 16740 @override | |
| 16741 void _appendStringValue(StringBuffer buffer) { | |
| 16742 throw new IllegalArgumentException(); | |
| 16743 } | |
| 16744 } | |
| 16745 | |
| 16746 /** | |
| 16747 * A helper for analyzing string lexemes. | |
| 16748 */ | |
| 16749 class StringLexemeHelper { | |
| 16750 final String lexeme; | |
| 16751 final bool isFirst; | |
| 16752 final bool isLast; | |
| 16753 | |
| 16754 bool isRaw = false; | |
| 16755 bool isSingleQuoted = false; | |
| 16756 bool isMultiline = false; | |
| 16757 int start = 0; | |
| 16758 int end; | |
| 16759 | |
| 16760 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) { | |
| 16761 if (isFirst) { | |
| 16762 isRaw = StringUtilities.startsWithChar(lexeme, 0x72); | |
| 16763 if (isRaw) { | |
| 16764 start++; | |
| 16765 } | |
| 16766 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) { | |
| 16767 isSingleQuoted = true; | |
| 16768 isMultiline = true; | |
| 16769 start += 3; | |
| 16770 start = _trimInitialWhitespace(start); | |
| 16771 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) { | |
| 16772 isSingleQuoted = false; | |
| 16773 isMultiline = true; | |
| 16774 start += 3; | |
| 16775 start = _trimInitialWhitespace(start); | |
| 16776 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) { | |
| 16777 isSingleQuoted = true; | |
| 16778 isMultiline = false; | |
| 16779 start++; | |
| 16780 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) { | |
| 16781 isSingleQuoted = false; | |
| 16782 isMultiline = false; | |
| 16783 start++; | |
| 16784 } | |
| 16785 } | |
| 16786 end = lexeme.length; | |
| 16787 if (isLast) { | |
| 16788 if (start + 3 <= end && | |
| 16789 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || | |
| 16790 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) { | |
| 16791 end -= 3; | |
| 16792 } else if (start + 1 <= end && | |
| 16793 (StringUtilities.endsWithChar(lexeme, 0x22) || | |
| 16794 StringUtilities.endsWithChar(lexeme, 0x27))) { | |
| 16795 end -= 1; | |
| 16796 } | |
| 16797 } | |
| 16798 } | |
| 16799 | |
| 16800 /** | |
| 16801 * Given the [lexeme] for a multi-line string whose content begins at the | |
| 16802 * given [start] index, return the index of the first character that is | |
| 16803 * included in the value of the string. According to the specification: | |
| 16804 * | |
| 16805 * If the first line of a multiline string consists solely of the whitespace | |
| 16806 * characters defined by the production WHITESPACE 20.1), possibly prefixed | |
| 16807 * by \, then that line is ignored, including the new line at its end. | |
| 16808 */ | |
| 16809 int _trimInitialWhitespace(int start) { | |
| 16810 int length = lexeme.length; | |
| 16811 int index = start; | |
| 16812 while (index < length) { | |
| 16813 int currentChar = lexeme.codeUnitAt(index); | |
| 16814 if (currentChar == 0x0D) { | |
| 16815 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) { | |
| 16816 return index + 2; | |
| 16817 } | |
| 16818 return index + 1; | |
| 16819 } else if (currentChar == 0x0A) { | |
| 16820 return index + 1; | |
| 16821 } else if (currentChar == 0x5C) { | |
| 16822 if (index + 1 >= length) { | |
| 16823 return start; | |
| 16824 } | |
| 16825 currentChar = lexeme.codeUnitAt(index + 1); | |
| 16826 if (currentChar != 0x0D && | |
| 16827 currentChar != 0x0A && | |
| 16828 currentChar != 0x09 && | |
| 16829 currentChar != 0x20) { | |
| 16830 return start; | |
| 16831 } | |
| 16832 } else if (currentChar != 0x09 && currentChar != 0x20) { | |
| 16833 return start; | |
| 16834 } | |
| 16835 index++; | |
| 16836 } | |
| 16837 return start; | |
| 16838 } | |
| 16839 } | |
| 16840 | |
| 16841 /** | |
| 16842 * A string literal expression. | |
| 16843 * | |
| 16844 * > stringLiteral ::= | |
| 16845 * > [SimpleStringLiteral] | |
| 16846 * > | [AdjacentStrings] | |
| 16847 * > | [StringInterpolation] | |
| 16848 */ | |
| 16849 abstract class StringLiteral extends Literal { | |
| 16850 /** | |
| 16851 * Return the value of the string literal, or `null` if the string is not a | |
| 16852 * constant string without any string interpolation. | |
| 16853 */ | |
| 16854 String get stringValue { | |
| 16855 StringBuffer buffer = new StringBuffer(); | |
| 16856 try { | |
| 16857 _appendStringValue(buffer); | |
| 16858 } on IllegalArgumentException { | |
| 16859 return null; | |
| 16860 } | |
| 16861 return buffer.toString(); | |
| 16862 } | |
| 16863 | |
| 16864 /** | |
| 16865 * Append the value of this string literal to the given [buffer]. Throw an | |
| 16866 * [IllegalArgumentException] if the string is not a constant string without | |
| 16867 * any string interpolation. | |
| 16868 */ | |
| 16869 @deprecated // Use "this.stringValue" | |
| 16870 void appendStringValue(StringBuffer buffer) => _appendStringValue(buffer); | |
| 16871 | |
| 16872 /** | |
| 16873 * Append the value of this string literal to the given [buffer]. Throw an | |
| 16874 * [IllegalArgumentException] if the string is not a constant string without | |
| 16875 * any string interpolation. | |
| 16876 */ | |
| 16877 void _appendStringValue(StringBuffer buffer); | |
| 16878 } | |
| 16879 | |
| 16880 /** | |
| 16881 * The invocation of a superclass' constructor from within a constructor's | |
| 16882 * initialization list. | |
| 16883 * | |
| 16884 * > superInvocation ::= | |
| 16885 * > 'super' ('.' [SimpleIdentifier])? [ArgumentList] | |
| 16886 */ | |
| 16887 class SuperConstructorInvocation extends ConstructorInitializer { | |
| 16888 /** | |
| 16889 * The token for the 'super' keyword. | |
| 16890 */ | |
| 16891 Token superKeyword; | |
| 16892 | |
| 16893 /** | |
| 16894 * The token for the period before the name of the constructor that is being | |
| 16895 * invoked, or `null` if the unnamed constructor is being invoked. | |
| 16896 */ | |
| 16897 Token period; | |
| 16898 | |
| 16899 /** | |
| 16900 * The name of the constructor that is being invoked, or `null` if the unnamed | |
| 16901 * constructor is being invoked. | |
| 16902 */ | |
| 16903 SimpleIdentifier _constructorName; | |
| 16904 | |
| 16905 /** | |
| 16906 * The list of arguments to the constructor. | |
| 16907 */ | |
| 16908 ArgumentList _argumentList; | |
| 16909 | |
| 16910 /** | |
| 16911 * The element associated with the constructor based on static type | |
| 16912 * information, or `null` if the AST structure has not been resolved or if the | |
| 16913 * constructor could not be resolved. | |
| 16914 */ | |
| 16915 ConstructorElement staticElement; | |
| 16916 | |
| 16917 /** | |
| 16918 * Initialize a newly created super invocation to invoke the inherited | |
| 16919 * constructor with the given name with the given arguments. The [period] and | |
| 16920 * [constructorName] can be `null` if the constructor being invoked is the | |
| 16921 * unnamed constructor. | |
| 16922 */ | |
| 16923 SuperConstructorInvocation(this.superKeyword, this.period, | |
| 16924 SimpleIdentifier constructorName, ArgumentList argumentList) { | |
| 16925 _constructorName = _becomeParentOf(constructorName); | |
| 16926 _argumentList = _becomeParentOf(argumentList); | |
| 16927 } | |
| 16928 | |
| 16929 /** | |
| 16930 * Return the list of arguments to the constructor. | |
| 16931 */ | |
| 16932 ArgumentList get argumentList => _argumentList; | |
| 16933 | |
| 16934 /** | |
| 16935 * Set the list of arguments to the constructor to the given [argumentList]. | |
| 16936 */ | |
| 16937 void set argumentList(ArgumentList argumentList) { | |
| 16938 _argumentList = _becomeParentOf(argumentList); | |
| 16939 } | |
| 16940 | |
| 16941 @override | |
| 16942 Token get beginToken => superKeyword; | |
| 16943 | |
| 16944 @override | |
| 16945 Iterable get childEntities => new ChildEntities() | |
| 16946 ..add(superKeyword) | |
| 16947 ..add(period) | |
| 16948 ..add(_constructorName) | |
| 16949 ..add(_argumentList); | |
| 16950 | |
| 16951 /** | |
| 16952 * Return the name of the constructor that is being invoked, or `null` if the | |
| 16953 * unnamed constructor is being invoked. | |
| 16954 */ | |
| 16955 SimpleIdentifier get constructorName => _constructorName; | |
| 16956 | |
| 16957 /** | |
| 16958 * Set the name of the constructor that is being invoked to the given | |
| 16959 * [identifier]. | |
| 16960 */ | |
| 16961 void set constructorName(SimpleIdentifier identifier) { | |
| 16962 _constructorName = _becomeParentOf(identifier); | |
| 16963 } | |
| 16964 | |
| 16965 @override | |
| 16966 Token get endToken => _argumentList.endToken; | |
| 16967 | |
| 16968 /** | |
| 16969 * Return the token for the 'super' keyword. | |
| 16970 */ | |
| 16971 @deprecated // Use "this.superKeyword" | |
| 16972 Token get keyword => superKeyword; | |
| 16973 | |
| 16974 /** | |
| 16975 * Set the token for the 'super' keyword to the given [token]. | |
| 16976 */ | |
| 16977 @deprecated // Use "this.superKeyword" | |
| 16978 set keyword(Token token) { | |
| 16979 superKeyword = token; | |
| 16980 } | |
| 16981 | |
| 16982 @override | |
| 16983 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this); | |
| 16984 | |
| 16985 @override | |
| 16986 void visitChildren(AstVisitor visitor) { | |
| 16987 _safelyVisitChild(_constructorName, visitor); | |
| 16988 _safelyVisitChild(_argumentList, visitor); | |
| 16989 } | |
| 16990 } | |
| 16991 | |
| 16992 /** | |
| 16993 * A super expression. | |
| 16994 * | |
| 16995 * > superExpression ::= | |
| 16996 * > 'super' | |
| 16997 */ | |
| 16998 class SuperExpression extends Expression { | |
| 16999 /** | |
| 17000 * The token representing the 'super' keyword. | |
| 17001 */ | |
| 17002 Token superKeyword; | |
| 17003 | |
| 17004 /** | |
| 17005 * Initialize a newly created super expression. | |
| 17006 */ | |
| 17007 SuperExpression(this.superKeyword); | |
| 17008 | |
| 17009 @override | |
| 17010 Token get beginToken => superKeyword; | |
| 17011 | |
| 17012 @override | |
| 17013 Iterable get childEntities => new ChildEntities()..add(superKeyword); | |
| 17014 | |
| 17015 @override | |
| 17016 Token get endToken => superKeyword; | |
| 17017 | |
| 17018 /** | |
| 17019 * Return the token for the 'super' keyword. | |
| 17020 */ | |
| 17021 @deprecated // Use "this.superKeyword" | |
| 17022 Token get keyword => superKeyword; | |
| 17023 | |
| 17024 /** | |
| 17025 * Set the token for the 'super' keyword to the given [token]. | |
| 17026 */ | |
| 17027 @deprecated // Use "this.superKeyword" | |
| 17028 set keyword(Token token) { | |
| 17029 superKeyword = token; | |
| 17030 } | |
| 17031 | |
| 17032 @override | |
| 17033 int get precedence => 16; | |
| 17034 | |
| 17035 @override | |
| 17036 accept(AstVisitor visitor) => visitor.visitSuperExpression(this); | |
| 17037 | |
| 17038 @override | |
| 17039 void visitChildren(AstVisitor visitor) { | |
| 17040 // There are no children to visit. | |
| 17041 } | |
| 17042 } | |
| 17043 | |
| 17044 /** | |
| 17045 * A case in a switch statement. | |
| 17046 * | |
| 17047 * > switchCase ::= | |
| 17048 * > [SimpleIdentifier]* 'case' [Expression] ':' [Statement]* | |
| 17049 */ | |
| 17050 class SwitchCase extends SwitchMember { | |
| 17051 /** | |
| 17052 * The expression controlling whether the statements will be executed. | |
| 17053 */ | |
| 17054 Expression _expression; | |
| 17055 | |
| 17056 /** | |
| 17057 * Initialize a newly created switch case. The list of [labels] can be `null` | |
| 17058 * if there are no labels. | |
| 17059 */ | |
| 17060 SwitchCase(List<Label> labels, Token keyword, Expression expression, | |
| 17061 Token colon, List<Statement> statements) | |
| 17062 : super(labels, keyword, colon, statements) { | |
| 17063 _expression = _becomeParentOf(expression); | |
| 17064 } | |
| 17065 | |
| 17066 @override | |
| 17067 Iterable get childEntities => new ChildEntities() | |
| 17068 ..addAll(labels) | |
| 17069 ..add(keyword) | |
| 17070 ..add(_expression) | |
| 17071 ..add(colon) | |
| 17072 ..addAll(statements); | |
| 17073 | |
| 17074 /** | |
| 17075 * Return the expression controlling whether the statements will be executed. | |
| 17076 */ | |
| 17077 Expression get expression => _expression; | |
| 17078 | |
| 17079 /** | |
| 17080 * Set the expression controlling whether the statements will be executed to | |
| 17081 * the given [expression]. | |
| 17082 */ | |
| 17083 void set expression(Expression expression) { | |
| 17084 _expression = _becomeParentOf(expression); | |
| 17085 } | |
| 17086 | |
| 17087 @override | |
| 17088 accept(AstVisitor visitor) => visitor.visitSwitchCase(this); | |
| 17089 | |
| 17090 @override | |
| 17091 void visitChildren(AstVisitor visitor) { | |
| 17092 labels.accept(visitor); | |
| 17093 _safelyVisitChild(_expression, visitor); | |
| 17094 statements.accept(visitor); | |
| 17095 } | |
| 17096 } | |
| 17097 | |
| 17098 /** | |
| 17099 * The default case in a switch statement. | |
| 17100 * | |
| 17101 * > switchDefault ::= | |
| 17102 * > [SimpleIdentifier]* 'default' ':' [Statement]* | |
| 17103 */ | |
| 17104 class SwitchDefault extends SwitchMember { | |
| 17105 /** | |
| 17106 * Initialize a newly created switch default. The list of [labels] can be | |
| 17107 * `null` if there are no labels. | |
| 17108 */ | |
| 17109 SwitchDefault(List<Label> labels, Token keyword, Token colon, | |
| 17110 List<Statement> statements) | |
| 17111 : super(labels, keyword, colon, statements); | |
| 17112 | |
| 17113 @override | |
| 17114 Iterable get childEntities => new ChildEntities() | |
| 17115 ..addAll(labels) | |
| 17116 ..add(keyword) | |
| 17117 ..add(colon) | |
| 17118 ..addAll(statements); | |
| 17119 | |
| 17120 @override | |
| 17121 accept(AstVisitor visitor) => visitor.visitSwitchDefault(this); | |
| 17122 | |
| 17123 @override | |
| 17124 void visitChildren(AstVisitor visitor) { | |
| 17125 labels.accept(visitor); | |
| 17126 statements.accept(visitor); | |
| 17127 } | |
| 17128 } | |
| 17129 | |
| 17130 /** | |
| 17131 * An element within a switch statement. | |
| 17132 * | |
| 17133 * > switchMember ::= | |
| 17134 * > switchCase | |
| 17135 * > | switchDefault | |
| 17136 */ | |
| 17137 abstract class SwitchMember extends AstNode { | |
| 17138 /** | |
| 17139 * The labels associated with the switch member. | |
| 17140 */ | |
| 17141 NodeList<Label> _labels; | |
| 17142 | |
| 17143 /** | |
| 17144 * The token representing the 'case' or 'default' keyword. | |
| 17145 */ | |
| 17146 Token keyword; | |
| 17147 | |
| 17148 /** | |
| 17149 * The colon separating the keyword or the expression from the statements. | |
| 17150 */ | |
| 17151 Token colon; | |
| 17152 | |
| 17153 /** | |
| 17154 * The statements that will be executed if this switch member is selected. | |
| 17155 */ | |
| 17156 NodeList<Statement> _statements; | |
| 17157 | |
| 17158 /** | |
| 17159 * Initialize a newly created switch member. The list of [labels] can be | |
| 17160 * `null` if there are no labels. | |
| 17161 */ | |
| 17162 SwitchMember(List<Label> labels, this.keyword, this.colon, | |
| 17163 List<Statement> statements) { | |
| 17164 _labels = new NodeList<Label>(this, labels); | |
| 17165 _statements = new NodeList<Statement>(this, statements); | |
| 17166 } | |
| 17167 | |
| 17168 @override | |
| 17169 Token get beginToken { | |
| 17170 if (!_labels.isEmpty) { | |
| 17171 return _labels.beginToken; | |
| 17172 } | |
| 17173 return keyword; | |
| 17174 } | |
| 17175 | |
| 17176 @override | |
| 17177 Token get endToken { | |
| 17178 if (!_statements.isEmpty) { | |
| 17179 return _statements.endToken; | |
| 17180 } | |
| 17181 return colon; | |
| 17182 } | |
| 17183 | |
| 17184 /** | |
| 17185 * Return the labels associated with the switch member. | |
| 17186 */ | |
| 17187 NodeList<Label> get labels => _labels; | |
| 17188 | |
| 17189 /** | |
| 17190 * Return the statements that will be executed if this switch member is | |
| 17191 * selected. | |
| 17192 */ | |
| 17193 NodeList<Statement> get statements => _statements; | |
| 17194 } | |
| 17195 | |
| 17196 /** | |
| 17197 * A switch statement. | |
| 17198 * | |
| 17199 * > switchStatement ::= | |
| 17200 * > 'switch' '(' [Expression] ')' '{' [SwitchCase]* [SwitchDefault]? '}' | |
| 17201 */ | |
| 17202 class SwitchStatement extends Statement { | |
| 17203 /** | |
| 17204 * The token representing the 'switch' keyword. | |
| 17205 */ | |
| 17206 Token switchKeyword; | |
| 17207 | |
| 17208 /** | |
| 17209 * The left parenthesis. | |
| 17210 */ | |
| 17211 Token leftParenthesis; | |
| 17212 | |
| 17213 /** | |
| 17214 * The expression used to determine which of the switch members will be | |
| 17215 * selected. | |
| 17216 */ | |
| 17217 Expression _expression; | |
| 17218 | |
| 17219 /** | |
| 17220 * The right parenthesis. | |
| 17221 */ | |
| 17222 Token rightParenthesis; | |
| 17223 | |
| 17224 /** | |
| 17225 * The left curly bracket. | |
| 17226 */ | |
| 17227 Token leftBracket; | |
| 17228 | |
| 17229 /** | |
| 17230 * The switch members that can be selected by the expression. | |
| 17231 */ | |
| 17232 NodeList<SwitchMember> _members; | |
| 17233 | |
| 17234 /** | |
| 17235 * The right curly bracket. | |
| 17236 */ | |
| 17237 Token rightBracket; | |
| 17238 | |
| 17239 /** | |
| 17240 * Initialize a newly created switch statement. The list of [members] can be | |
| 17241 * `null` if there are no switch members. | |
| 17242 */ | |
| 17243 SwitchStatement(this.switchKeyword, this.leftParenthesis, | |
| 17244 Expression expression, this.rightParenthesis, this.leftBracket, | |
| 17245 List<SwitchMember> members, this.rightBracket) { | |
| 17246 _expression = _becomeParentOf(expression); | |
| 17247 _members = new NodeList<SwitchMember>(this, members); | |
| 17248 } | |
| 17249 | |
| 17250 @override | |
| 17251 Token get beginToken => switchKeyword; | |
| 17252 | |
| 17253 @override | |
| 17254 Iterable get childEntities => new ChildEntities() | |
| 17255 ..add(switchKeyword) | |
| 17256 ..add(leftParenthesis) | |
| 17257 ..add(_expression) | |
| 17258 ..add(rightParenthesis) | |
| 17259 ..add(leftBracket) | |
| 17260 ..addAll(_members) | |
| 17261 ..add(rightBracket); | |
| 17262 | |
| 17263 @override | |
| 17264 Token get endToken => rightBracket; | |
| 17265 | |
| 17266 /** | |
| 17267 * Return the expression used to determine which of the switch members will be | |
| 17268 * selected. | |
| 17269 */ | |
| 17270 Expression get expression => _expression; | |
| 17271 | |
| 17272 /** | |
| 17273 * Set the expression used to determine which of the switch members will be | |
| 17274 * selected to the given [expression]. | |
| 17275 */ | |
| 17276 void set expression(Expression expression) { | |
| 17277 _expression = _becomeParentOf(expression); | |
| 17278 } | |
| 17279 | |
| 17280 /** | |
| 17281 * Return the token representing the 'switch' keyword. | |
| 17282 */ | |
| 17283 @deprecated // Use "this.switchKeyword" | |
| 17284 Token get keyword => switchKeyword; | |
| 17285 | |
| 17286 /** | |
| 17287 * Set the token representing the 'switch' keyword to the given [token]. | |
| 17288 */ | |
| 17289 @deprecated // Use "this.switchKeyword" | |
| 17290 set keyword(Token token) { | |
| 17291 switchKeyword = token; | |
| 17292 } | |
| 17293 | |
| 17294 /** | |
| 17295 * Return the switch members that can be selected by the expression. | |
| 17296 */ | |
| 17297 NodeList<SwitchMember> get members => _members; | |
| 17298 | |
| 17299 @override | |
| 17300 accept(AstVisitor visitor) => visitor.visitSwitchStatement(this); | |
| 17301 | |
| 17302 @override | |
| 17303 void visitChildren(AstVisitor visitor) { | |
| 17304 _safelyVisitChild(_expression, visitor); | |
| 17305 _members.accept(visitor); | |
| 17306 } | |
| 17307 } | |
| 17308 | |
| 17309 /** | |
| 17310 * A symbol literal expression. | |
| 17311 * | |
| 17312 * > symbolLiteral ::= | |
| 17313 * > '#' (operator | (identifier ('.' identifier)*)) | |
| 17314 */ | |
| 17315 class SymbolLiteral extends Literal { | |
| 17316 /** | |
| 17317 * The token introducing the literal. | |
| 17318 */ | |
| 17319 Token poundSign; | |
| 17320 | |
| 17321 /** | |
| 17322 * The components of the literal. | |
| 17323 */ | |
| 17324 final List<Token> components; | |
| 17325 | |
| 17326 /** | |
| 17327 * Initialize a newly created symbol literal. | |
| 17328 */ | |
| 17329 SymbolLiteral(this.poundSign, this.components); | |
| 17330 | |
| 17331 @override | |
| 17332 Token get beginToken => poundSign; | |
| 17333 | |
| 17334 /** | |
| 17335 * TODO(paulberry): add "." tokens. | |
| 17336 */ | |
| 17337 @override | |
| 17338 Iterable get childEntities => new ChildEntities() | |
| 17339 ..add(poundSign) | |
| 17340 ..addAll(components); | |
| 17341 | |
| 17342 @override | |
| 17343 Token get endToken => components[components.length - 1]; | |
| 17344 | |
| 17345 @override | |
| 17346 accept(AstVisitor visitor) => visitor.visitSymbolLiteral(this); | |
| 17347 | |
| 17348 @override | |
| 17349 void visitChildren(AstVisitor visitor) { | |
| 17350 // There are no children to visit. | |
| 17351 } | |
| 17352 } | |
| 17353 | |
| 17354 /** | |
| 17355 * A this expression. | |
| 17356 * | |
| 17357 * > thisExpression ::= | |
| 17358 * > 'this' | |
| 17359 */ | |
| 17360 class ThisExpression extends Expression { | |
| 17361 /** | |
| 17362 * The token representing the 'this' keyword. | |
| 17363 */ | |
| 17364 Token thisKeyword; | |
| 17365 | |
| 17366 /** | |
| 17367 * Initialize a newly created this expression. | |
| 17368 */ | |
| 17369 ThisExpression(this.thisKeyword); | |
| 17370 | |
| 17371 @override | |
| 17372 Token get beginToken => thisKeyword; | |
| 17373 | |
| 17374 @override | |
| 17375 Iterable get childEntities => new ChildEntities()..add(thisKeyword); | |
| 17376 | |
| 17377 @override | |
| 17378 Token get endToken => thisKeyword; | |
| 17379 | |
| 17380 /** | |
| 17381 * Return the token representing the 'this' keyword. | |
| 17382 */ | |
| 17383 @deprecated // Use "this.thisKeyword" | |
| 17384 Token get keyword => thisKeyword; | |
| 17385 | |
| 17386 /** | |
| 17387 * Set the token representing the 'this' keyword to the given [token]. | |
| 17388 */ | |
| 17389 @deprecated // Use "this.thisKeyword" | |
| 17390 set keyword(Token token) { | |
| 17391 thisKeyword = token; | |
| 17392 } | |
| 17393 | |
| 17394 @override | |
| 17395 int get precedence => 16; | |
| 17396 | |
| 17397 @override | |
| 17398 accept(AstVisitor visitor) => visitor.visitThisExpression(this); | |
| 17399 | |
| 17400 @override | |
| 17401 void visitChildren(AstVisitor visitor) { | |
| 17402 // There are no children to visit. | |
| 17403 } | |
| 17404 } | |
| 17405 | |
| 17406 /** | |
| 17407 * A throw expression. | |
| 17408 * | |
| 17409 * > throwExpression ::= | |
| 17410 * > 'throw' [Expression] | |
| 17411 */ | |
| 17412 class ThrowExpression extends Expression { | |
| 17413 /** | |
| 17414 * The token representing the 'throw' keyword. | |
| 17415 */ | |
| 17416 Token throwKeyword; | |
| 17417 | |
| 17418 /** | |
| 17419 * The expression computing the exception to be thrown. | |
| 17420 */ | |
| 17421 Expression _expression; | |
| 17422 | |
| 17423 /** | |
| 17424 * Initialize a newly created throw expression. | |
| 17425 */ | |
| 17426 ThrowExpression(this.throwKeyword, Expression expression) { | |
| 17427 _expression = _becomeParentOf(expression); | |
| 17428 } | |
| 17429 | |
| 17430 @override | |
| 17431 Token get beginToken => throwKeyword; | |
| 17432 | |
| 17433 @override | |
| 17434 Iterable get childEntities => | |
| 17435 new ChildEntities()..add(throwKeyword)..add(_expression); | |
| 17436 | |
| 17437 @override | |
| 17438 Token get endToken { | |
| 17439 if (_expression != null) { | |
| 17440 return _expression.endToken; | |
| 17441 } | |
| 17442 return throwKeyword; | |
| 17443 } | |
| 17444 | |
| 17445 /** | |
| 17446 * Return the expression computing the exception to be thrown. | |
| 17447 */ | |
| 17448 Expression get expression => _expression; | |
| 17449 | |
| 17450 /** | |
| 17451 * Set the expression computing the exception to be thrown to the given | |
| 17452 * [expression]. | |
| 17453 */ | |
| 17454 void set expression(Expression expression) { | |
| 17455 _expression = _becomeParentOf(expression); | |
| 17456 } | |
| 17457 | |
| 17458 /** | |
| 17459 * Return the token representing the 'throw' keyword. | |
| 17460 */ | |
| 17461 @deprecated // Use "this.throwKeyword" | |
| 17462 Token get keyword => throwKeyword; | |
| 17463 | |
| 17464 /** | |
| 17465 * Set the token representing the 'throw' keyword to the given [token]. | |
| 17466 */ | |
| 17467 @deprecated // Use "this.throwKeyword" | |
| 17468 set keyword(Token token) { | |
| 17469 throwKeyword = token; | |
| 17470 } | |
| 17471 | |
| 17472 @override | |
| 17473 int get precedence => 0; | |
| 17474 | |
| 17475 @override | |
| 17476 accept(AstVisitor visitor) => visitor.visitThrowExpression(this); | |
| 17477 | |
| 17478 @override | |
| 17479 void visitChildren(AstVisitor visitor) { | |
| 17480 _safelyVisitChild(_expression, visitor); | |
| 17481 } | |
| 17482 } | |
| 17483 | |
| 17484 /** | |
| 17485 * The declaration of one or more top-level variables of the same type. | |
| 17486 * | |
| 17487 * > topLevelVariableDeclaration ::= | |
| 17488 * > ('final' | 'const') type? staticFinalDeclarationList ';' | |
| 17489 * > | variableDeclaration ';' | |
| 17490 */ | |
| 17491 class TopLevelVariableDeclaration extends CompilationUnitMember { | |
| 17492 /** | |
| 17493 * The top-level variables being declared. | |
| 17494 */ | |
| 17495 VariableDeclarationList _variableList; | |
| 17496 | |
| 17497 /** | |
| 17498 * The semicolon terminating the declaration. | |
| 17499 */ | |
| 17500 Token semicolon; | |
| 17501 | |
| 17502 /** | |
| 17503 * Initialize a newly created top-level variable declaration. Either or both | |
| 17504 * of the [comment] and [metadata] can be `null` if the variable does not have | |
| 17505 * the corresponding attribute. | |
| 17506 */ | |
| 17507 TopLevelVariableDeclaration(Comment comment, List<Annotation> metadata, | |
| 17508 VariableDeclarationList variableList, this.semicolon) | |
| 17509 : super(comment, metadata) { | |
| 17510 _variableList = _becomeParentOf(variableList); | |
| 17511 } | |
| 17512 | |
| 17513 @override | |
| 17514 Iterable get childEntities => | |
| 17515 super._childEntities..add(_variableList)..add(semicolon); | |
| 17516 | |
| 17517 @override | |
| 17518 Element get element => null; | |
| 17519 | |
| 17520 @override | |
| 17521 Token get endToken => semicolon; | |
| 17522 | |
| 17523 @override | |
| 17524 Token get firstTokenAfterCommentAndMetadata => _variableList.beginToken; | |
| 17525 | |
| 17526 /** | |
| 17527 * Return the top-level variables being declared. | |
| 17528 */ | |
| 17529 VariableDeclarationList get variables => _variableList; | |
| 17530 | |
| 17531 /** | |
| 17532 * Set the top-level variables being declared to the given list of | |
| 17533 * [variables]. | |
| 17534 */ | |
| 17535 void set variables(VariableDeclarationList variables) { | |
| 17536 _variableList = _becomeParentOf(variables); | |
| 17537 } | |
| 17538 | |
| 17539 @override | |
| 17540 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this); | |
| 17541 | |
| 17542 @override | |
| 17543 void visitChildren(AstVisitor visitor) { | |
| 17544 super.visitChildren(visitor); | |
| 17545 _safelyVisitChild(_variableList, visitor); | |
| 17546 } | |
| 17547 } | |
| 17548 | |
| 17549 /** | |
| 17550 * A visitor used to write a source representation of a visited AST node (and | |
| 17551 * all of it's children) to a writer. | |
| 17552 */ | |
| 17553 class ToSourceVisitor implements AstVisitor<Object> { | |
| 17554 /** | |
| 17555 * The writer to which the source is to be written. | |
| 17556 */ | |
| 17557 final PrintWriter _writer; | |
| 17558 | |
| 17559 /** | |
| 17560 * Initialize a newly created visitor to write source code representing the | |
| 17561 * visited nodes to the given [writer]. | |
| 17562 */ | |
| 17563 ToSourceVisitor(this._writer); | |
| 17564 | |
| 17565 @override | |
| 17566 Object visitAdjacentStrings(AdjacentStrings node) { | |
| 17567 _visitNodeListWithSeparator(node.strings, " "); | |
| 17568 return null; | |
| 17569 } | |
| 17570 | |
| 17571 @override | |
| 17572 Object visitAnnotation(Annotation node) { | |
| 17573 _writer.print('@'); | |
| 17574 _visitNode(node.name); | |
| 17575 _visitNodeWithPrefix(".", node.constructorName); | |
| 17576 _visitNode(node.arguments); | |
| 17577 return null; | |
| 17578 } | |
| 17579 | |
| 17580 @override | |
| 17581 Object visitArgumentList(ArgumentList node) { | |
| 17582 _writer.print('('); | |
| 17583 _visitNodeListWithSeparator(node.arguments, ", "); | |
| 17584 _writer.print(')'); | |
| 17585 return null; | |
| 17586 } | |
| 17587 | |
| 17588 @override | |
| 17589 Object visitAsExpression(AsExpression node) { | |
| 17590 _visitNode(node.expression); | |
| 17591 _writer.print(" as "); | |
| 17592 _visitNode(node.type); | |
| 17593 return null; | |
| 17594 } | |
| 17595 | |
| 17596 @override | |
| 17597 Object visitAssertStatement(AssertStatement node) { | |
| 17598 _writer.print("assert ("); | |
| 17599 _visitNode(node.condition); | |
| 17600 _writer.print(");"); | |
| 17601 return null; | |
| 17602 } | |
| 17603 | |
| 17604 @override | |
| 17605 Object visitAssignmentExpression(AssignmentExpression node) { | |
| 17606 _visitNode(node.leftHandSide); | |
| 17607 _writer.print(' '); | |
| 17608 _writer.print(node.operator.lexeme); | |
| 17609 _writer.print(' '); | |
| 17610 _visitNode(node.rightHandSide); | |
| 17611 return null; | |
| 17612 } | |
| 17613 | |
| 17614 @override | |
| 17615 Object visitAwaitExpression(AwaitExpression node) { | |
| 17616 _writer.print("await "); | |
| 17617 _visitNode(node.expression); | |
| 17618 _writer.print(";"); | |
| 17619 return null; | |
| 17620 } | |
| 17621 | |
| 17622 @override | |
| 17623 Object visitBinaryExpression(BinaryExpression node) { | |
| 17624 _visitNode(node.leftOperand); | |
| 17625 _writer.print(' '); | |
| 17626 _writer.print(node.operator.lexeme); | |
| 17627 _writer.print(' '); | |
| 17628 _visitNode(node.rightOperand); | |
| 17629 return null; | |
| 17630 } | |
| 17631 | |
| 17632 @override | |
| 17633 Object visitBlock(Block node) { | |
| 17634 _writer.print('{'); | |
| 17635 _visitNodeListWithSeparator(node.statements, " "); | |
| 17636 _writer.print('}'); | |
| 17637 return null; | |
| 17638 } | |
| 17639 | |
| 17640 @override | |
| 17641 Object visitBlockFunctionBody(BlockFunctionBody node) { | |
| 17642 Token keyword = node.keyword; | |
| 17643 if (keyword != null) { | |
| 17644 _writer.print(keyword.lexeme); | |
| 17645 if (node.star != null) { | |
| 17646 _writer.print('*'); | |
| 17647 } | |
| 17648 _writer.print(' '); | |
| 17649 } | |
| 17650 _visitNode(node.block); | |
| 17651 return null; | |
| 17652 } | |
| 17653 | |
| 17654 @override | |
| 17655 Object visitBooleanLiteral(BooleanLiteral node) { | |
| 17656 _writer.print(node.literal.lexeme); | |
| 17657 return null; | |
| 17658 } | |
| 17659 | |
| 17660 @override | |
| 17661 Object visitBreakStatement(BreakStatement node) { | |
| 17662 _writer.print("break"); | |
| 17663 _visitNodeWithPrefix(" ", node.label); | |
| 17664 _writer.print(";"); | |
| 17665 return null; | |
| 17666 } | |
| 17667 | |
| 17668 @override | |
| 17669 Object visitCascadeExpression(CascadeExpression node) { | |
| 17670 _visitNode(node.target); | |
| 17671 _visitNodeList(node.cascadeSections); | |
| 17672 return null; | |
| 17673 } | |
| 17674 | |
| 17675 @override | |
| 17676 Object visitCatchClause(CatchClause node) { | |
| 17677 _visitNodeWithPrefix("on ", node.exceptionType); | |
| 17678 if (node.catchKeyword != null) { | |
| 17679 if (node.exceptionType != null) { | |
| 17680 _writer.print(' '); | |
| 17681 } | |
| 17682 _writer.print("catch ("); | |
| 17683 _visitNode(node.exceptionParameter); | |
| 17684 _visitNodeWithPrefix(", ", node.stackTraceParameter); | |
| 17685 _writer.print(") "); | |
| 17686 } else { | |
| 17687 _writer.print(" "); | |
| 17688 } | |
| 17689 _visitNode(node.body); | |
| 17690 return null; | |
| 17691 } | |
| 17692 | |
| 17693 @override | |
| 17694 Object visitClassDeclaration(ClassDeclaration node) { | |
| 17695 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17696 _visitTokenWithSuffix(node.abstractKeyword, " "); | |
| 17697 _writer.print("class "); | |
| 17698 _visitNode(node.name); | |
| 17699 _visitNode(node.typeParameters); | |
| 17700 _visitNodeWithPrefix(" ", node.extendsClause); | |
| 17701 _visitNodeWithPrefix(" ", node.withClause); | |
| 17702 _visitNodeWithPrefix(" ", node.implementsClause); | |
| 17703 _writer.print(" {"); | |
| 17704 _visitNodeListWithSeparator(node.members, " "); | |
| 17705 _writer.print("}"); | |
| 17706 return null; | |
| 17707 } | |
| 17708 | |
| 17709 @override | |
| 17710 Object visitClassTypeAlias(ClassTypeAlias node) { | |
| 17711 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17712 if (node.abstractKeyword != null) { | |
| 17713 _writer.print("abstract "); | |
| 17714 } | |
| 17715 _writer.print("class "); | |
| 17716 _visitNode(node.name); | |
| 17717 _visitNode(node.typeParameters); | |
| 17718 _writer.print(" = "); | |
| 17719 _visitNode(node.superclass); | |
| 17720 _visitNodeWithPrefix(" ", node.withClause); | |
| 17721 _visitNodeWithPrefix(" ", node.implementsClause); | |
| 17722 _writer.print(";"); | |
| 17723 return null; | |
| 17724 } | |
| 17725 | |
| 17726 @override | |
| 17727 Object visitComment(Comment node) => null; | |
| 17728 | |
| 17729 @override | |
| 17730 Object visitCommentReference(CommentReference node) => null; | |
| 17731 | |
| 17732 @override | |
| 17733 Object visitCompilationUnit(CompilationUnit node) { | |
| 17734 ScriptTag scriptTag = node.scriptTag; | |
| 17735 NodeList<Directive> directives = node.directives; | |
| 17736 _visitNode(scriptTag); | |
| 17737 String prefix = scriptTag == null ? "" : " "; | |
| 17738 _visitNodeListWithSeparatorAndPrefix(prefix, directives, " "); | |
| 17739 prefix = scriptTag == null && directives.isEmpty ? "" : " "; | |
| 17740 _visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, " "); | |
| 17741 return null; | |
| 17742 } | |
| 17743 | |
| 17744 @override | |
| 17745 Object visitConditionalExpression(ConditionalExpression node) { | |
| 17746 _visitNode(node.condition); | |
| 17747 _writer.print(" ? "); | |
| 17748 _visitNode(node.thenExpression); | |
| 17749 _writer.print(" : "); | |
| 17750 _visitNode(node.elseExpression); | |
| 17751 return null; | |
| 17752 } | |
| 17753 | |
| 17754 @override | |
| 17755 Object visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 17756 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17757 _visitTokenWithSuffix(node.externalKeyword, " "); | |
| 17758 _visitTokenWithSuffix(node.constKeyword, " "); | |
| 17759 _visitTokenWithSuffix(node.factoryKeyword, " "); | |
| 17760 _visitNode(node.returnType); | |
| 17761 _visitNodeWithPrefix(".", node.name); | |
| 17762 _visitNode(node.parameters); | |
| 17763 _visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", "); | |
| 17764 _visitNodeWithPrefix(" = ", node.redirectedConstructor); | |
| 17765 _visitFunctionWithPrefix(" ", node.body); | |
| 17766 return null; | |
| 17767 } | |
| 17768 | |
| 17769 @override | |
| 17770 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 17771 _visitTokenWithSuffix(node.thisKeyword, "."); | |
| 17772 _visitNode(node.fieldName); | |
| 17773 _writer.print(" = "); | |
| 17774 _visitNode(node.expression); | |
| 17775 return null; | |
| 17776 } | |
| 17777 | |
| 17778 @override | |
| 17779 Object visitConstructorName(ConstructorName node) { | |
| 17780 _visitNode(node.type); | |
| 17781 _visitNodeWithPrefix(".", node.name); | |
| 17782 return null; | |
| 17783 } | |
| 17784 | |
| 17785 @override | |
| 17786 Object visitContinueStatement(ContinueStatement node) { | |
| 17787 _writer.print("continue"); | |
| 17788 _visitNodeWithPrefix(" ", node.label); | |
| 17789 _writer.print(";"); | |
| 17790 return null; | |
| 17791 } | |
| 17792 | |
| 17793 @override | |
| 17794 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 17795 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17796 _visitTokenWithSuffix(node.keyword, " "); | |
| 17797 _visitNodeWithSuffix(node.type, " "); | |
| 17798 _visitNode(node.identifier); | |
| 17799 return null; | |
| 17800 } | |
| 17801 | |
| 17802 @override | |
| 17803 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 17804 _visitNode(node.parameter); | |
| 17805 if (node.separator != null) { | |
| 17806 _writer.print(" "); | |
| 17807 _writer.print(node.separator.lexeme); | |
| 17808 _visitNodeWithPrefix(" ", node.defaultValue); | |
| 17809 } | |
| 17810 return null; | |
| 17811 } | |
| 17812 | |
| 17813 @override | |
| 17814 Object visitDoStatement(DoStatement node) { | |
| 17815 _writer.print("do "); | |
| 17816 _visitNode(node.body); | |
| 17817 _writer.print(" while ("); | |
| 17818 _visitNode(node.condition); | |
| 17819 _writer.print(");"); | |
| 17820 return null; | |
| 17821 } | |
| 17822 | |
| 17823 @override | |
| 17824 Object visitDoubleLiteral(DoubleLiteral node) { | |
| 17825 _writer.print(node.literal.lexeme); | |
| 17826 return null; | |
| 17827 } | |
| 17828 | |
| 17829 @override | |
| 17830 Object visitEmptyFunctionBody(EmptyFunctionBody node) { | |
| 17831 _writer.print(';'); | |
| 17832 return null; | |
| 17833 } | |
| 17834 | |
| 17835 @override | |
| 17836 Object visitEmptyStatement(EmptyStatement node) { | |
| 17837 _writer.print(';'); | |
| 17838 return null; | |
| 17839 } | |
| 17840 | |
| 17841 @override | |
| 17842 Object visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 17843 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17844 _visitNode(node.name); | |
| 17845 return null; | |
| 17846 } | |
| 17847 | |
| 17848 @override | |
| 17849 Object visitEnumDeclaration(EnumDeclaration node) { | |
| 17850 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17851 _writer.print("enum "); | |
| 17852 _visitNode(node.name); | |
| 17853 _writer.print(" {"); | |
| 17854 _visitNodeListWithSeparator(node.constants, ", "); | |
| 17855 _writer.print("}"); | |
| 17856 return null; | |
| 17857 } | |
| 17858 | |
| 17859 @override | |
| 17860 Object visitExportDirective(ExportDirective node) { | |
| 17861 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17862 _writer.print("export "); | |
| 17863 _visitNode(node.uri); | |
| 17864 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " "); | |
| 17865 _writer.print(';'); | |
| 17866 return null; | |
| 17867 } | |
| 17868 | |
| 17869 @override | |
| 17870 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 17871 Token keyword = node.keyword; | |
| 17872 if (keyword != null) { | |
| 17873 _writer.print(keyword.lexeme); | |
| 17874 _writer.print(' '); | |
| 17875 } | |
| 17876 _writer.print("=> "); | |
| 17877 _visitNode(node.expression); | |
| 17878 if (node.semicolon != null) { | |
| 17879 _writer.print(';'); | |
| 17880 } | |
| 17881 return null; | |
| 17882 } | |
| 17883 | |
| 17884 @override | |
| 17885 Object visitExpressionStatement(ExpressionStatement node) { | |
| 17886 _visitNode(node.expression); | |
| 17887 _writer.print(';'); | |
| 17888 return null; | |
| 17889 } | |
| 17890 | |
| 17891 @override | |
| 17892 Object visitExtendsClause(ExtendsClause node) { | |
| 17893 _writer.print("extends "); | |
| 17894 _visitNode(node.superclass); | |
| 17895 return null; | |
| 17896 } | |
| 17897 | |
| 17898 @override | |
| 17899 Object visitFieldDeclaration(FieldDeclaration node) { | |
| 17900 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17901 _visitTokenWithSuffix(node.staticKeyword, " "); | |
| 17902 _visitNode(node.fields); | |
| 17903 _writer.print(";"); | |
| 17904 return null; | |
| 17905 } | |
| 17906 | |
| 17907 @override | |
| 17908 Object visitFieldFormalParameter(FieldFormalParameter node) { | |
| 17909 _visitTokenWithSuffix(node.keyword, " "); | |
| 17910 _visitNodeWithSuffix(node.type, " "); | |
| 17911 _writer.print("this."); | |
| 17912 _visitNode(node.identifier); | |
| 17913 _visitNode(node.typeParameters); | |
| 17914 _visitNode(node.parameters); | |
| 17915 return null; | |
| 17916 } | |
| 17917 | |
| 17918 @override | |
| 17919 Object visitForEachStatement(ForEachStatement node) { | |
| 17920 DeclaredIdentifier loopVariable = node.loopVariable; | |
| 17921 if (node.awaitKeyword != null) { | |
| 17922 _writer.print("await "); | |
| 17923 } | |
| 17924 _writer.print("for ("); | |
| 17925 if (loopVariable == null) { | |
| 17926 _visitNode(node.identifier); | |
| 17927 } else { | |
| 17928 _visitNode(loopVariable); | |
| 17929 } | |
| 17930 _writer.print(" in "); | |
| 17931 _visitNode(node.iterable); | |
| 17932 _writer.print(") "); | |
| 17933 _visitNode(node.body); | |
| 17934 return null; | |
| 17935 } | |
| 17936 | |
| 17937 @override | |
| 17938 Object visitFormalParameterList(FormalParameterList node) { | |
| 17939 String groupEnd = null; | |
| 17940 _writer.print('('); | |
| 17941 NodeList<FormalParameter> parameters = node.parameters; | |
| 17942 int size = parameters.length; | |
| 17943 for (int i = 0; i < size; i++) { | |
| 17944 FormalParameter parameter = parameters[i]; | |
| 17945 if (i > 0) { | |
| 17946 _writer.print(", "); | |
| 17947 } | |
| 17948 if (groupEnd == null && parameter is DefaultFormalParameter) { | |
| 17949 if (parameter.kind == ParameterKind.NAMED) { | |
| 17950 groupEnd = "}"; | |
| 17951 _writer.print('{'); | |
| 17952 } else { | |
| 17953 groupEnd = "]"; | |
| 17954 _writer.print('['); | |
| 17955 } | |
| 17956 } | |
| 17957 parameter.accept(this); | |
| 17958 } | |
| 17959 if (groupEnd != null) { | |
| 17960 _writer.print(groupEnd); | |
| 17961 } | |
| 17962 _writer.print(')'); | |
| 17963 return null; | |
| 17964 } | |
| 17965 | |
| 17966 @override | |
| 17967 Object visitForStatement(ForStatement node) { | |
| 17968 Expression initialization = node.initialization; | |
| 17969 _writer.print("for ("); | |
| 17970 if (initialization != null) { | |
| 17971 _visitNode(initialization); | |
| 17972 } else { | |
| 17973 _visitNode(node.variables); | |
| 17974 } | |
| 17975 _writer.print(";"); | |
| 17976 _visitNodeWithPrefix(" ", node.condition); | |
| 17977 _writer.print(";"); | |
| 17978 _visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", "); | |
| 17979 _writer.print(") "); | |
| 17980 _visitNode(node.body); | |
| 17981 return null; | |
| 17982 } | |
| 17983 | |
| 17984 @override | |
| 17985 Object visitFunctionDeclaration(FunctionDeclaration node) { | |
| 17986 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 17987 _visitNodeWithSuffix(node.returnType, " "); | |
| 17988 _visitTokenWithSuffix(node.propertyKeyword, " "); | |
| 17989 _visitNode(node.name); | |
| 17990 _visitNode(node.functionExpression); | |
| 17991 return null; | |
| 17992 } | |
| 17993 | |
| 17994 @override | |
| 17995 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 17996 _visitNode(node.functionDeclaration); | |
| 17997 return null; | |
| 17998 } | |
| 17999 | |
| 18000 @override | |
| 18001 Object visitFunctionExpression(FunctionExpression node) { | |
| 18002 _visitNode(node.typeParameters); | |
| 18003 _visitNode(node.parameters); | |
| 18004 _writer.print(' '); | |
| 18005 _visitNode(node.body); | |
| 18006 return null; | |
| 18007 } | |
| 18008 | |
| 18009 @override | |
| 18010 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 18011 _visitNode(node.function); | |
| 18012 _visitNode(node.typeArguments); | |
| 18013 _visitNode(node.argumentList); | |
| 18014 return null; | |
| 18015 } | |
| 18016 | |
| 18017 @override | |
| 18018 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 18019 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18020 _writer.print("typedef "); | |
| 18021 _visitNodeWithSuffix(node.returnType, " "); | |
| 18022 _visitNode(node.name); | |
| 18023 _visitNode(node.typeParameters); | |
| 18024 _visitNode(node.parameters); | |
| 18025 _writer.print(";"); | |
| 18026 return null; | |
| 18027 } | |
| 18028 | |
| 18029 @override | |
| 18030 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 18031 _visitNodeWithSuffix(node.returnType, " "); | |
| 18032 _visitNode(node.identifier); | |
| 18033 _visitNode(node.typeParameters); | |
| 18034 _visitNode(node.parameters); | |
| 18035 return null; | |
| 18036 } | |
| 18037 | |
| 18038 @override | |
| 18039 Object visitHideCombinator(HideCombinator node) { | |
| 18040 _writer.print("hide "); | |
| 18041 _visitNodeListWithSeparator(node.hiddenNames, ", "); | |
| 18042 return null; | |
| 18043 } | |
| 18044 | |
| 18045 @override | |
| 18046 Object visitIfStatement(IfStatement node) { | |
| 18047 _writer.print("if ("); | |
| 18048 _visitNode(node.condition); | |
| 18049 _writer.print(") "); | |
| 18050 _visitNode(node.thenStatement); | |
| 18051 _visitNodeWithPrefix(" else ", node.elseStatement); | |
| 18052 return null; | |
| 18053 } | |
| 18054 | |
| 18055 @override | |
| 18056 Object visitImplementsClause(ImplementsClause node) { | |
| 18057 _writer.print("implements "); | |
| 18058 _visitNodeListWithSeparator(node.interfaces, ", "); | |
| 18059 return null; | |
| 18060 } | |
| 18061 | |
| 18062 @override | |
| 18063 Object visitImportDirective(ImportDirective node) { | |
| 18064 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18065 _writer.print("import "); | |
| 18066 _visitNode(node.uri); | |
| 18067 if (node.deferredKeyword != null) { | |
| 18068 _writer.print(" deferred"); | |
| 18069 } | |
| 18070 _visitNodeWithPrefix(" as ", node.prefix); | |
| 18071 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " "); | |
| 18072 _writer.print(';'); | |
| 18073 return null; | |
| 18074 } | |
| 18075 | |
| 18076 @override | |
| 18077 Object visitIndexExpression(IndexExpression node) { | |
| 18078 if (node.isCascaded) { | |
| 18079 _writer.print(".."); | |
| 18080 } else { | |
| 18081 _visitNode(node.target); | |
| 18082 } | |
| 18083 _writer.print('['); | |
| 18084 _visitNode(node.index); | |
| 18085 _writer.print(']'); | |
| 18086 return null; | |
| 18087 } | |
| 18088 | |
| 18089 @override | |
| 18090 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 18091 _visitTokenWithSuffix(node.keyword, " "); | |
| 18092 _visitNode(node.constructorName); | |
| 18093 _visitNode(node.argumentList); | |
| 18094 return null; | |
| 18095 } | |
| 18096 | |
| 18097 @override | |
| 18098 Object visitIntegerLiteral(IntegerLiteral node) { | |
| 18099 _writer.print(node.literal.lexeme); | |
| 18100 return null; | |
| 18101 } | |
| 18102 | |
| 18103 @override | |
| 18104 Object visitInterpolationExpression(InterpolationExpression node) { | |
| 18105 if (node.rightBracket != null) { | |
| 18106 _writer.print("\${"); | |
| 18107 _visitNode(node.expression); | |
| 18108 _writer.print("}"); | |
| 18109 } else { | |
| 18110 _writer.print("\$"); | |
| 18111 _visitNode(node.expression); | |
| 18112 } | |
| 18113 return null; | |
| 18114 } | |
| 18115 | |
| 18116 @override | |
| 18117 Object visitInterpolationString(InterpolationString node) { | |
| 18118 _writer.print(node.contents.lexeme); | |
| 18119 return null; | |
| 18120 } | |
| 18121 | |
| 18122 @override | |
| 18123 Object visitIsExpression(IsExpression node) { | |
| 18124 _visitNode(node.expression); | |
| 18125 if (node.notOperator == null) { | |
| 18126 _writer.print(" is "); | |
| 18127 } else { | |
| 18128 _writer.print(" is! "); | |
| 18129 } | |
| 18130 _visitNode(node.type); | |
| 18131 return null; | |
| 18132 } | |
| 18133 | |
| 18134 @override | |
| 18135 Object visitLabel(Label node) { | |
| 18136 _visitNode(node.label); | |
| 18137 _writer.print(":"); | |
| 18138 return null; | |
| 18139 } | |
| 18140 | |
| 18141 @override | |
| 18142 Object visitLabeledStatement(LabeledStatement node) { | |
| 18143 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); | |
| 18144 _visitNode(node.statement); | |
| 18145 return null; | |
| 18146 } | |
| 18147 | |
| 18148 @override | |
| 18149 Object visitLibraryDirective(LibraryDirective node) { | |
| 18150 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18151 _writer.print("library "); | |
| 18152 _visitNode(node.name); | |
| 18153 _writer.print(';'); | |
| 18154 return null; | |
| 18155 } | |
| 18156 | |
| 18157 @override | |
| 18158 Object visitLibraryIdentifier(LibraryIdentifier node) { | |
| 18159 _writer.print(node.name); | |
| 18160 return null; | |
| 18161 } | |
| 18162 | |
| 18163 @override | |
| 18164 Object visitListLiteral(ListLiteral node) { | |
| 18165 if (node.constKeyword != null) { | |
| 18166 _writer.print(node.constKeyword.lexeme); | |
| 18167 _writer.print(' '); | |
| 18168 } | |
| 18169 _visitNodeWithSuffix(node.typeArguments, " "); | |
| 18170 _writer.print("["); | |
| 18171 _visitNodeListWithSeparator(node.elements, ", "); | |
| 18172 _writer.print("]"); | |
| 18173 return null; | |
| 18174 } | |
| 18175 | |
| 18176 @override | |
| 18177 Object visitMapLiteral(MapLiteral node) { | |
| 18178 if (node.constKeyword != null) { | |
| 18179 _writer.print(node.constKeyword.lexeme); | |
| 18180 _writer.print(' '); | |
| 18181 } | |
| 18182 _visitNodeWithSuffix(node.typeArguments, " "); | |
| 18183 _writer.print("{"); | |
| 18184 _visitNodeListWithSeparator(node.entries, ", "); | |
| 18185 _writer.print("}"); | |
| 18186 return null; | |
| 18187 } | |
| 18188 | |
| 18189 @override | |
| 18190 Object visitMapLiteralEntry(MapLiteralEntry node) { | |
| 18191 _visitNode(node.key); | |
| 18192 _writer.print(" : "); | |
| 18193 _visitNode(node.value); | |
| 18194 return null; | |
| 18195 } | |
| 18196 | |
| 18197 @override | |
| 18198 Object visitMethodDeclaration(MethodDeclaration node) { | |
| 18199 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18200 _visitTokenWithSuffix(node.externalKeyword, " "); | |
| 18201 _visitTokenWithSuffix(node.modifierKeyword, " "); | |
| 18202 _visitNodeWithSuffix(node.returnType, " "); | |
| 18203 _visitTokenWithSuffix(node.propertyKeyword, " "); | |
| 18204 _visitTokenWithSuffix(node.operatorKeyword, " "); | |
| 18205 _visitNode(node.name); | |
| 18206 if (!node.isGetter) { | |
| 18207 _visitNode(node.typeParameters); | |
| 18208 _visitNode(node.parameters); | |
| 18209 } | |
| 18210 _visitFunctionWithPrefix(" ", node.body); | |
| 18211 return null; | |
| 18212 } | |
| 18213 | |
| 18214 @override | |
| 18215 Object visitMethodInvocation(MethodInvocation node) { | |
| 18216 if (node.isCascaded) { | |
| 18217 _writer.print(".."); | |
| 18218 } else { | |
| 18219 if (node.target != null) { | |
| 18220 node.target.accept(this); | |
| 18221 _writer.print(node.operator.lexeme); | |
| 18222 } | |
| 18223 } | |
| 18224 _visitNode(node.methodName); | |
| 18225 _visitNode(node.typeArguments); | |
| 18226 _visitNode(node.argumentList); | |
| 18227 return null; | |
| 18228 } | |
| 18229 | |
| 18230 @override | |
| 18231 Object visitNamedExpression(NamedExpression node) { | |
| 18232 _visitNode(node.name); | |
| 18233 _visitNodeWithPrefix(" ", node.expression); | |
| 18234 return null; | |
| 18235 } | |
| 18236 | |
| 18237 @override | |
| 18238 Object visitNativeClause(NativeClause node) { | |
| 18239 _writer.print("native "); | |
| 18240 _visitNode(node.name); | |
| 18241 return null; | |
| 18242 } | |
| 18243 | |
| 18244 @override | |
| 18245 Object visitNativeFunctionBody(NativeFunctionBody node) { | |
| 18246 _writer.print("native "); | |
| 18247 _visitNode(node.stringLiteral); | |
| 18248 _writer.print(';'); | |
| 18249 return null; | |
| 18250 } | |
| 18251 | |
| 18252 @override | |
| 18253 Object visitNullLiteral(NullLiteral node) { | |
| 18254 _writer.print("null"); | |
| 18255 return null; | |
| 18256 } | |
| 18257 | |
| 18258 @override | |
| 18259 Object visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 18260 _writer.print('('); | |
| 18261 _visitNode(node.expression); | |
| 18262 _writer.print(')'); | |
| 18263 return null; | |
| 18264 } | |
| 18265 | |
| 18266 @override | |
| 18267 Object visitPartDirective(PartDirective node) { | |
| 18268 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18269 _writer.print("part "); | |
| 18270 _visitNode(node.uri); | |
| 18271 _writer.print(';'); | |
| 18272 return null; | |
| 18273 } | |
| 18274 | |
| 18275 @override | |
| 18276 Object visitPartOfDirective(PartOfDirective node) { | |
| 18277 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18278 _writer.print("part of "); | |
| 18279 _visitNode(node.libraryName); | |
| 18280 _writer.print(';'); | |
| 18281 return null; | |
| 18282 } | |
| 18283 | |
| 18284 @override | |
| 18285 Object visitPostfixExpression(PostfixExpression node) { | |
| 18286 _visitNode(node.operand); | |
| 18287 _writer.print(node.operator.lexeme); | |
| 18288 return null; | |
| 18289 } | |
| 18290 | |
| 18291 @override | |
| 18292 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 18293 _visitNode(node.prefix); | |
| 18294 _writer.print('.'); | |
| 18295 _visitNode(node.identifier); | |
| 18296 return null; | |
| 18297 } | |
| 18298 | |
| 18299 @override | |
| 18300 Object visitPrefixExpression(PrefixExpression node) { | |
| 18301 _writer.print(node.operator.lexeme); | |
| 18302 _visitNode(node.operand); | |
| 18303 return null; | |
| 18304 } | |
| 18305 | |
| 18306 @override | |
| 18307 Object visitPropertyAccess(PropertyAccess node) { | |
| 18308 if (node.isCascaded) { | |
| 18309 _writer.print(".."); | |
| 18310 } else { | |
| 18311 _visitNode(node.target); | |
| 18312 _writer.print(node.operator.lexeme); | |
| 18313 } | |
| 18314 _visitNode(node.propertyName); | |
| 18315 return null; | |
| 18316 } | |
| 18317 | |
| 18318 @override | |
| 18319 Object visitRedirectingConstructorInvocation( | |
| 18320 RedirectingConstructorInvocation node) { | |
| 18321 _writer.print("this"); | |
| 18322 _visitNodeWithPrefix(".", node.constructorName); | |
| 18323 _visitNode(node.argumentList); | |
| 18324 return null; | |
| 18325 } | |
| 18326 | |
| 18327 @override | |
| 18328 Object visitRethrowExpression(RethrowExpression node) { | |
| 18329 _writer.print("rethrow"); | |
| 18330 return null; | |
| 18331 } | |
| 18332 | |
| 18333 @override | |
| 18334 Object visitReturnStatement(ReturnStatement node) { | |
| 18335 Expression expression = node.expression; | |
| 18336 if (expression == null) { | |
| 18337 _writer.print("return;"); | |
| 18338 } else { | |
| 18339 _writer.print("return "); | |
| 18340 expression.accept(this); | |
| 18341 _writer.print(";"); | |
| 18342 } | |
| 18343 return null; | |
| 18344 } | |
| 18345 | |
| 18346 @override | |
| 18347 Object visitScriptTag(ScriptTag node) { | |
| 18348 _writer.print(node.scriptTag.lexeme); | |
| 18349 return null; | |
| 18350 } | |
| 18351 | |
| 18352 @override | |
| 18353 Object visitShowCombinator(ShowCombinator node) { | |
| 18354 _writer.print("show "); | |
| 18355 _visitNodeListWithSeparator(node.shownNames, ", "); | |
| 18356 return null; | |
| 18357 } | |
| 18358 | |
| 18359 @override | |
| 18360 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 18361 _visitTokenWithSuffix(node.keyword, " "); | |
| 18362 _visitNodeWithSuffix(node.type, " "); | |
| 18363 _visitNode(node.identifier); | |
| 18364 return null; | |
| 18365 } | |
| 18366 | |
| 18367 @override | |
| 18368 Object visitSimpleIdentifier(SimpleIdentifier node) { | |
| 18369 _writer.print(node.token.lexeme); | |
| 18370 return null; | |
| 18371 } | |
| 18372 | |
| 18373 @override | |
| 18374 Object visitSimpleStringLiteral(SimpleStringLiteral node) { | |
| 18375 _writer.print(node.literal.lexeme); | |
| 18376 return null; | |
| 18377 } | |
| 18378 | |
| 18379 @override | |
| 18380 Object visitStringInterpolation(StringInterpolation node) { | |
| 18381 _visitNodeList(node.elements); | |
| 18382 return null; | |
| 18383 } | |
| 18384 | |
| 18385 @override | |
| 18386 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 18387 _writer.print("super"); | |
| 18388 _visitNodeWithPrefix(".", node.constructorName); | |
| 18389 _visitNode(node.argumentList); | |
| 18390 return null; | |
| 18391 } | |
| 18392 | |
| 18393 @override | |
| 18394 Object visitSuperExpression(SuperExpression node) { | |
| 18395 _writer.print("super"); | |
| 18396 return null; | |
| 18397 } | |
| 18398 | |
| 18399 @override | |
| 18400 Object visitSwitchCase(SwitchCase node) { | |
| 18401 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); | |
| 18402 _writer.print("case "); | |
| 18403 _visitNode(node.expression); | |
| 18404 _writer.print(": "); | |
| 18405 _visitNodeListWithSeparator(node.statements, " "); | |
| 18406 return null; | |
| 18407 } | |
| 18408 | |
| 18409 @override | |
| 18410 Object visitSwitchDefault(SwitchDefault node) { | |
| 18411 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); | |
| 18412 _writer.print("default: "); | |
| 18413 _visitNodeListWithSeparator(node.statements, " "); | |
| 18414 return null; | |
| 18415 } | |
| 18416 | |
| 18417 @override | |
| 18418 Object visitSwitchStatement(SwitchStatement node) { | |
| 18419 _writer.print("switch ("); | |
| 18420 _visitNode(node.expression); | |
| 18421 _writer.print(") {"); | |
| 18422 _visitNodeListWithSeparator(node.members, " "); | |
| 18423 _writer.print("}"); | |
| 18424 return null; | |
| 18425 } | |
| 18426 | |
| 18427 @override | |
| 18428 Object visitSymbolLiteral(SymbolLiteral node) { | |
| 18429 _writer.print("#"); | |
| 18430 List<Token> components = node.components; | |
| 18431 for (int i = 0; i < components.length; i++) { | |
| 18432 if (i > 0) { | |
| 18433 _writer.print("."); | |
| 18434 } | |
| 18435 _writer.print(components[i].lexeme); | |
| 18436 } | |
| 18437 return null; | |
| 18438 } | |
| 18439 | |
| 18440 @override | |
| 18441 Object visitThisExpression(ThisExpression node) { | |
| 18442 _writer.print("this"); | |
| 18443 return null; | |
| 18444 } | |
| 18445 | |
| 18446 @override | |
| 18447 Object visitThrowExpression(ThrowExpression node) { | |
| 18448 _writer.print("throw "); | |
| 18449 _visitNode(node.expression); | |
| 18450 return null; | |
| 18451 } | |
| 18452 | |
| 18453 @override | |
| 18454 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 18455 _visitNodeWithSuffix(node.variables, ";"); | |
| 18456 return null; | |
| 18457 } | |
| 18458 | |
| 18459 @override | |
| 18460 Object visitTryStatement(TryStatement node) { | |
| 18461 _writer.print("try "); | |
| 18462 _visitNode(node.body); | |
| 18463 _visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " "); | |
| 18464 _visitNodeWithPrefix(" finally ", node.finallyBlock); | |
| 18465 return null; | |
| 18466 } | |
| 18467 | |
| 18468 @override | |
| 18469 Object visitTypeArgumentList(TypeArgumentList node) { | |
| 18470 _writer.print('<'); | |
| 18471 _visitNodeListWithSeparator(node.arguments, ", "); | |
| 18472 _writer.print('>'); | |
| 18473 return null; | |
| 18474 } | |
| 18475 | |
| 18476 @override | |
| 18477 Object visitTypeName(TypeName node) { | |
| 18478 _visitNode(node.name); | |
| 18479 _visitNode(node.typeArguments); | |
| 18480 return null; | |
| 18481 } | |
| 18482 | |
| 18483 @override | |
| 18484 Object visitTypeParameter(TypeParameter node) { | |
| 18485 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18486 _visitNode(node.name); | |
| 18487 _visitNodeWithPrefix(" extends ", node.bound); | |
| 18488 return null; | |
| 18489 } | |
| 18490 | |
| 18491 @override | |
| 18492 Object visitTypeParameterList(TypeParameterList node) { | |
| 18493 _writer.print('<'); | |
| 18494 _visitNodeListWithSeparator(node.typeParameters, ", "); | |
| 18495 _writer.print('>'); | |
| 18496 return null; | |
| 18497 } | |
| 18498 | |
| 18499 @override | |
| 18500 Object visitVariableDeclaration(VariableDeclaration node) { | |
| 18501 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18502 _visitNode(node.name); | |
| 18503 _visitNodeWithPrefix(" = ", node.initializer); | |
| 18504 return null; | |
| 18505 } | |
| 18506 | |
| 18507 @override | |
| 18508 Object visitVariableDeclarationList(VariableDeclarationList node) { | |
| 18509 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); | |
| 18510 _visitTokenWithSuffix(node.keyword, " "); | |
| 18511 _visitNodeWithSuffix(node.type, " "); | |
| 18512 _visitNodeListWithSeparator(node.variables, ", "); | |
| 18513 return null; | |
| 18514 } | |
| 18515 | |
| 18516 @override | |
| 18517 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 18518 _visitNode(node.variables); | |
| 18519 _writer.print(";"); | |
| 18520 return null; | |
| 18521 } | |
| 18522 | |
| 18523 @override | |
| 18524 Object visitWhileStatement(WhileStatement node) { | |
| 18525 _writer.print("while ("); | |
| 18526 _visitNode(node.condition); | |
| 18527 _writer.print(") "); | |
| 18528 _visitNode(node.body); | |
| 18529 return null; | |
| 18530 } | |
| 18531 | |
| 18532 @override | |
| 18533 Object visitWithClause(WithClause node) { | |
| 18534 _writer.print("with "); | |
| 18535 _visitNodeListWithSeparator(node.mixinTypes, ", "); | |
| 18536 return null; | |
| 18537 } | |
| 18538 | |
| 18539 @override | |
| 18540 Object visitYieldStatement(YieldStatement node) { | |
| 18541 if (node.star != null) { | |
| 18542 _writer.print("yield* "); | |
| 18543 } else { | |
| 18544 _writer.print("yield "); | |
| 18545 } | |
| 18546 _visitNode(node.expression); | |
| 18547 _writer.print(";"); | |
| 18548 return null; | |
| 18549 } | |
| 18550 | |
| 18551 /** | |
| 18552 * Visit the given function [body], printing the [prefix] before if the body | |
| 18553 * is not empty. | |
| 18554 */ | |
| 18555 void _visitFunctionWithPrefix(String prefix, FunctionBody body) { | |
| 18556 if (body is! EmptyFunctionBody) { | |
| 18557 _writer.print(prefix); | |
| 18558 } | |
| 18559 _visitNode(body); | |
| 18560 } | |
| 18561 | |
| 18562 /** | |
| 18563 * Safely visit the given [node]. | |
| 18564 */ | |
| 18565 void _visitNode(AstNode node) { | |
| 18566 if (node != null) { | |
| 18567 node.accept(this); | |
| 18568 } | |
| 18569 } | |
| 18570 | |
| 18571 /** | |
| 18572 * Print a list of [nodes] without any separation. | |
| 18573 */ | |
| 18574 void _visitNodeList(NodeList<AstNode> nodes) { | |
| 18575 _visitNodeListWithSeparator(nodes, ""); | |
| 18576 } | |
| 18577 | |
| 18578 /** | |
| 18579 * Print a list of [nodes], separated by the given [separator]. | |
| 18580 */ | |
| 18581 void _visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) { | |
| 18582 if (nodes != null) { | |
| 18583 int size = nodes.length; | |
| 18584 for (int i = 0; i < size; i++) { | |
| 18585 if (i > 0) { | |
| 18586 _writer.print(separator); | |
| 18587 } | |
| 18588 nodes[i].accept(this); | |
| 18589 } | |
| 18590 } | |
| 18591 } | |
| 18592 | |
| 18593 /** | |
| 18594 * Print a list of [nodes], prefixed by the given [prefix] if the list is not | |
| 18595 * empty, and separated by the given [separator]. | |
| 18596 */ | |
| 18597 void _visitNodeListWithSeparatorAndPrefix( | |
| 18598 String prefix, NodeList<AstNode> nodes, String separator) { | |
| 18599 if (nodes != null) { | |
| 18600 int size = nodes.length; | |
| 18601 if (size > 0) { | |
| 18602 _writer.print(prefix); | |
| 18603 for (int i = 0; i < size; i++) { | |
| 18604 if (i > 0) { | |
| 18605 _writer.print(separator); | |
| 18606 } | |
| 18607 nodes[i].accept(this); | |
| 18608 } | |
| 18609 } | |
| 18610 } | |
| 18611 } | |
| 18612 | |
| 18613 /** | |
| 18614 * Print a list of [nodes], separated by the given [separator], followed by | |
| 18615 * the given [suffix] if the list is not empty. | |
| 18616 */ | |
| 18617 void _visitNodeListWithSeparatorAndSuffix( | |
| 18618 NodeList<AstNode> nodes, String separator, String suffix) { | |
| 18619 if (nodes != null) { | |
| 18620 int size = nodes.length; | |
| 18621 if (size > 0) { | |
| 18622 for (int i = 0; i < size; i++) { | |
| 18623 if (i > 0) { | |
| 18624 _writer.print(separator); | |
| 18625 } | |
| 18626 nodes[i].accept(this); | |
| 18627 } | |
| 18628 _writer.print(suffix); | |
| 18629 } | |
| 18630 } | |
| 18631 } | |
| 18632 | |
| 18633 /** | |
| 18634 * Safely visit the given [node], printing the [prefix] before the node if it | |
| 18635 * is non-`null`. | |
| 18636 */ | |
| 18637 void _visitNodeWithPrefix(String prefix, AstNode node) { | |
| 18638 if (node != null) { | |
| 18639 _writer.print(prefix); | |
| 18640 node.accept(this); | |
| 18641 } | |
| 18642 } | |
| 18643 | |
| 18644 /** | |
| 18645 * Safely visit the given [node], printing the [suffix] after the node if it | |
| 18646 * is non-`null`. | |
| 18647 */ | |
| 18648 void _visitNodeWithSuffix(AstNode node, String suffix) { | |
| 18649 if (node != null) { | |
| 18650 node.accept(this); | |
| 18651 _writer.print(suffix); | |
| 18652 } | |
| 18653 } | |
| 18654 | |
| 18655 /** | |
| 18656 * Safely visit the given [token], printing the [suffix] after the token if it | |
| 18657 * is non-`null`. | |
| 18658 */ | |
| 18659 void _visitTokenWithSuffix(Token token, String suffix) { | |
| 18660 if (token != null) { | |
| 18661 _writer.print(token.lexeme); | |
| 18662 _writer.print(suffix); | |
| 18663 } | |
| 18664 } | |
| 18665 } | |
| 18666 | |
| 18667 /** | |
| 18668 * A try statement. | |
| 18669 * | |
| 18670 * > tryStatement ::= | |
| 18671 * > 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause) | |
| 18672 * > | |
| 18673 * > finallyClause ::= | |
| 18674 * > 'finally' [Block] | |
| 18675 */ | |
| 18676 class TryStatement extends Statement { | |
| 18677 /** | |
| 18678 * The token representing the 'try' keyword. | |
| 18679 */ | |
| 18680 Token tryKeyword; | |
| 18681 | |
| 18682 /** | |
| 18683 * The body of the statement. | |
| 18684 */ | |
| 18685 Block _body; | |
| 18686 | |
| 18687 /** | |
| 18688 * The catch clauses contained in the try statement. | |
| 18689 */ | |
| 18690 NodeList<CatchClause> _catchClauses; | |
| 18691 | |
| 18692 /** | |
| 18693 * The token representing the 'finally' keyword, or `null` if the statement | |
| 18694 * does not contain a finally clause. | |
| 18695 */ | |
| 18696 Token finallyKeyword; | |
| 18697 | |
| 18698 /** | |
| 18699 * The finally block contained in the try statement, or `null` if the | |
| 18700 * statement does not contain a finally clause. | |
| 18701 */ | |
| 18702 Block _finallyBlock; | |
| 18703 | |
| 18704 /** | |
| 18705 * Initialize a newly created try statement. The list of [catchClauses] can be | |
| 18706 * `null` if there are no catch clauses. The [finallyKeyword] and | |
| 18707 * [finallyBlock] can be `null` if there is no finally clause. | |
| 18708 */ | |
| 18709 TryStatement(this.tryKeyword, Block body, List<CatchClause> catchClauses, | |
| 18710 this.finallyKeyword, Block finallyBlock) { | |
| 18711 _body = _becomeParentOf(body); | |
| 18712 _catchClauses = new NodeList<CatchClause>(this, catchClauses); | |
| 18713 _finallyBlock = _becomeParentOf(finallyBlock); | |
| 18714 } | |
| 18715 | |
| 18716 @override | |
| 18717 Token get beginToken => tryKeyword; | |
| 18718 | |
| 18719 /** | |
| 18720 * Return the body of the statement. | |
| 18721 */ | |
| 18722 Block get body => _body; | |
| 18723 | |
| 18724 /** | |
| 18725 * Set the body of the statement to the given [block]. | |
| 18726 */ | |
| 18727 void set body(Block block) { | |
| 18728 _body = _becomeParentOf(block); | |
| 18729 } | |
| 18730 | |
| 18731 /** | |
| 18732 * Return the catch clauses contained in the try statement. | |
| 18733 */ | |
| 18734 NodeList<CatchClause> get catchClauses => _catchClauses; | |
| 18735 | |
| 18736 @override | |
| 18737 Iterable get childEntities => new ChildEntities() | |
| 18738 ..add(tryKeyword) | |
| 18739 ..add(_body) | |
| 18740 ..addAll(_catchClauses) | |
| 18741 ..add(finallyKeyword) | |
| 18742 ..add(_finallyBlock); | |
| 18743 | |
| 18744 @override | |
| 18745 Token get endToken { | |
| 18746 if (_finallyBlock != null) { | |
| 18747 return _finallyBlock.endToken; | |
| 18748 } else if (finallyKeyword != null) { | |
| 18749 return finallyKeyword; | |
| 18750 } else if (!_catchClauses.isEmpty) { | |
| 18751 return _catchClauses.endToken; | |
| 18752 } | |
| 18753 return _body.endToken; | |
| 18754 } | |
| 18755 | |
| 18756 /** | |
| 18757 * Return the finally block contained in the try statement, or `null` if the | |
| 18758 * statement does not contain a finally clause. | |
| 18759 */ | |
| 18760 Block get finallyBlock => _finallyBlock; | |
| 18761 | |
| 18762 /** | |
| 18763 * Set the finally block contained in the try statement to the given [block]. | |
| 18764 */ | |
| 18765 void set finallyBlock(Block block) { | |
| 18766 _finallyBlock = _becomeParentOf(block); | |
| 18767 } | |
| 18768 | |
| 18769 @override | |
| 18770 accept(AstVisitor visitor) => visitor.visitTryStatement(this); | |
| 18771 | |
| 18772 @override | |
| 18773 void visitChildren(AstVisitor visitor) { | |
| 18774 _safelyVisitChild(_body, visitor); | |
| 18775 _catchClauses.accept(visitor); | |
| 18776 _safelyVisitChild(_finallyBlock, visitor); | |
| 18777 } | |
| 18778 } | |
| 18779 | |
| 18780 /** | |
| 18781 * The declaration of a type alias. | |
| 18782 * | |
| 18783 * > typeAlias ::= | |
| 18784 * > 'typedef' typeAliasBody | |
| 18785 * > | |
| 18786 * > typeAliasBody ::= | |
| 18787 * > classTypeAlias | |
| 18788 * > | functionTypeAlias | |
| 18789 */ | |
| 18790 abstract class TypeAlias extends NamedCompilationUnitMember { | |
| 18791 /** | |
| 18792 * The token representing the 'typedef' keyword. | |
| 18793 */ | |
| 18794 Token typedefKeyword; | |
| 18795 | |
| 18796 /** | |
| 18797 * The semicolon terminating the declaration. | |
| 18798 */ | |
| 18799 Token semicolon; | |
| 18800 | |
| 18801 /** | |
| 18802 * Initialize a newly created type alias. Either or both of the [comment] and | |
| 18803 * [metadata] can be `null` if the declaration does not have the corresponding | |
| 18804 * attribute. | |
| 18805 */ | |
| 18806 TypeAlias(Comment comment, List<Annotation> metadata, this.typedefKeyword, | |
| 18807 SimpleIdentifier name, this.semicolon) | |
| 18808 : super(comment, metadata, name); | |
| 18809 | |
| 18810 @override | |
| 18811 Token get endToken => semicolon; | |
| 18812 | |
| 18813 @override | |
| 18814 Token get firstTokenAfterCommentAndMetadata => typedefKeyword; | |
| 18815 | |
| 18816 /** | |
| 18817 * Return the token representing the 'typedef' keyword. | |
| 18818 */ | |
| 18819 @deprecated // Use "this.typedefKeyword" | |
| 18820 Token get keyword => typedefKeyword; | |
| 18821 | |
| 18822 /** | |
| 18823 * Set the token representing the 'typedef' keyword to the given [token]. | |
| 18824 */ | |
| 18825 @deprecated // Use "this.typedefKeyword" | |
| 18826 set keyword(Token token) { | |
| 18827 typedefKeyword = token; | |
| 18828 } | |
| 18829 } | |
| 18830 | |
| 18831 /** | |
| 18832 * A list of type arguments. | |
| 18833 * | |
| 18834 * > typeArguments ::= | |
| 18835 * > '<' typeName (',' typeName)* '>' | |
| 18836 */ | |
| 18837 class TypeArgumentList extends AstNode { | |
| 18838 /** | |
| 18839 * The left bracket. | |
| 18840 */ | |
| 18841 Token leftBracket; | |
| 18842 | |
| 18843 /** | |
| 18844 * The type arguments associated with the type. | |
| 18845 */ | |
| 18846 NodeList<TypeName> _arguments; | |
| 18847 | |
| 18848 /** | |
| 18849 * The right bracket. | |
| 18850 */ | |
| 18851 Token rightBracket; | |
| 18852 | |
| 18853 /** | |
| 18854 * Initialize a newly created list of type arguments. | |
| 18855 */ | |
| 18856 TypeArgumentList( | |
| 18857 this.leftBracket, List<TypeName> arguments, this.rightBracket) { | |
| 18858 _arguments = new NodeList<TypeName>(this, arguments); | |
| 18859 } | |
| 18860 | |
| 18861 /** | |
| 18862 * Return the type arguments associated with the type. | |
| 18863 */ | |
| 18864 NodeList<TypeName> get arguments => _arguments; | |
| 18865 | |
| 18866 @override | |
| 18867 Token get beginToken => leftBracket; | |
| 18868 | |
| 18869 /** | |
| 18870 * TODO(paulberry): Add commas. | |
| 18871 */ | |
| 18872 @override | |
| 18873 Iterable get childEntities => new ChildEntities() | |
| 18874 ..add(leftBracket) | |
| 18875 ..addAll(_arguments) | |
| 18876 ..add(rightBracket); | |
| 18877 | |
| 18878 @override | |
| 18879 Token get endToken => rightBracket; | |
| 18880 | |
| 18881 @override | |
| 18882 accept(AstVisitor visitor) => visitor.visitTypeArgumentList(this); | |
| 18883 | |
| 18884 @override | |
| 18885 void visitChildren(AstVisitor visitor) { | |
| 18886 _arguments.accept(visitor); | |
| 18887 } | |
| 18888 } | |
| 18889 | |
| 18890 /** | |
| 18891 * A literal that has a type associated with it. | |
| 18892 * | |
| 18893 * > typedLiteral ::= | |
| 18894 * > [ListLiteral] | |
| 18895 * > | [MapLiteral] | |
| 18896 */ | |
| 18897 abstract class TypedLiteral extends Literal { | |
| 18898 /** | |
| 18899 * The token representing the 'const' keyword, or `null` if the literal is not | |
| 18900 * a constant. | |
| 18901 */ | |
| 18902 Token constKeyword; | |
| 18903 | |
| 18904 /** | |
| 18905 * The type argument associated with this literal, or `null` if no type | |
| 18906 * arguments were declared. | |
| 18907 */ | |
| 18908 TypeArgumentList _typeArguments; | |
| 18909 | |
| 18910 /** | |
| 18911 * Initialize a newly created typed literal. The [constKeyword] can be `null`\ | |
| 18912 * if the literal is not a constant. The [typeArguments] can be `null` if no | |
| 18913 * type arguments were declared. | |
| 18914 */ | |
| 18915 TypedLiteral(this.constKeyword, TypeArgumentList typeArguments) { | |
| 18916 _typeArguments = _becomeParentOf(typeArguments); | |
| 18917 } | |
| 18918 | |
| 18919 /** | |
| 18920 * Return the type argument associated with this literal, or `null` if no type | |
| 18921 * arguments were declared. | |
| 18922 */ | |
| 18923 TypeArgumentList get typeArguments => _typeArguments; | |
| 18924 | |
| 18925 /** | |
| 18926 * Set the type argument associated with this literal to the given | |
| 18927 * [typeArguments]. | |
| 18928 */ | |
| 18929 void set typeArguments(TypeArgumentList typeArguments) { | |
| 18930 _typeArguments = _becomeParentOf(typeArguments); | |
| 18931 } | |
| 18932 | |
| 18933 ChildEntities get _childEntities => | |
| 18934 new ChildEntities()..add(constKeyword)..add(_typeArguments); | |
| 18935 | |
| 18936 @override | |
| 18937 void visitChildren(AstVisitor visitor) { | |
| 18938 _safelyVisitChild(_typeArguments, visitor); | |
| 18939 } | |
| 18940 } | |
| 18941 | |
| 18942 /** | |
| 18943 * The name of a type, which can optionally include type arguments. | |
| 18944 * | |
| 18945 * > typeName ::= | |
| 18946 * > [Identifier] typeArguments? | |
| 18947 */ | |
| 18948 class TypeName extends AstNode { | |
| 18949 /** | |
| 18950 * The name of the type. | |
| 18951 */ | |
| 18952 Identifier _name; | |
| 18953 | |
| 18954 /** | |
| 18955 * The type arguments associated with the type, or `null` if there are no type | |
| 18956 * arguments. | |
| 18957 */ | |
| 18958 TypeArgumentList _typeArguments; | |
| 18959 | |
| 18960 /** | |
| 18961 * The type being named, or `null` if the AST structure has not been resolved. | |
| 18962 */ | |
| 18963 DartType type; | |
| 18964 | |
| 18965 /** | |
| 18966 * Initialize a newly created type name. The [typeArguments] can be `null` if | |
| 18967 * there are no type arguments. | |
| 18968 */ | |
| 18969 TypeName(Identifier name, TypeArgumentList typeArguments) { | |
| 18970 _name = _becomeParentOf(name); | |
| 18971 _typeArguments = _becomeParentOf(typeArguments); | |
| 18972 } | |
| 18973 | |
| 18974 @override | |
| 18975 Token get beginToken => _name.beginToken; | |
| 18976 | |
| 18977 @override | |
| 18978 Iterable get childEntities => | |
| 18979 new ChildEntities()..add(_name)..add(_typeArguments); | |
| 18980 | |
| 18981 @override | |
| 18982 Token get endToken { | |
| 18983 if (_typeArguments != null) { | |
| 18984 return _typeArguments.endToken; | |
| 18985 } | |
| 18986 return _name.endToken; | |
| 18987 } | |
| 18988 | |
| 18989 /** | |
| 18990 * Return `true` if this type is a deferred type. | |
| 18991 * | |
| 18992 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form | |
| 18993 * </i>p.T</i> where <i>p</i> is a deferred prefix. | |
| 18994 */ | |
| 18995 bool get isDeferred { | |
| 18996 Identifier identifier = name; | |
| 18997 if (identifier is! PrefixedIdentifier) { | |
| 18998 return false; | |
| 18999 } | |
| 19000 return (identifier as PrefixedIdentifier).isDeferred; | |
| 19001 } | |
| 19002 | |
| 19003 @override | |
| 19004 bool get isSynthetic => _name.isSynthetic && _typeArguments == null; | |
| 19005 | |
| 19006 /** | |
| 19007 * Return the name of the type. | |
| 19008 */ | |
| 19009 Identifier get name => _name; | |
| 19010 | |
| 19011 /** | |
| 19012 * Set the name of the type to the given [identifier]. | |
| 19013 */ | |
| 19014 void set name(Identifier identifier) { | |
| 19015 _name = _becomeParentOf(identifier); | |
| 19016 } | |
| 19017 | |
| 19018 /** | |
| 19019 * Return the type arguments associated with the type, or `null` if there are | |
| 19020 * no type arguments. | |
| 19021 */ | |
| 19022 TypeArgumentList get typeArguments => _typeArguments; | |
| 19023 | |
| 19024 /** | |
| 19025 * Set the type arguments associated with the type to the given | |
| 19026 * [typeArguments]. | |
| 19027 */ | |
| 19028 void set typeArguments(TypeArgumentList typeArguments) { | |
| 19029 _typeArguments = _becomeParentOf(typeArguments); | |
| 19030 } | |
| 19031 | |
| 19032 @override | |
| 19033 accept(AstVisitor visitor) => visitor.visitTypeName(this); | |
| 19034 | |
| 19035 @override | |
| 19036 void visitChildren(AstVisitor visitor) { | |
| 19037 _safelyVisitChild(_name, visitor); | |
| 19038 _safelyVisitChild(_typeArguments, visitor); | |
| 19039 } | |
| 19040 } | |
| 19041 | |
| 19042 /** | |
| 19043 * A type parameter. | |
| 19044 * | |
| 19045 * > typeParameter ::= | |
| 19046 * > [SimpleIdentifier] ('extends' [TypeName])? | |
| 19047 */ | |
| 19048 class TypeParameter extends Declaration { | |
| 19049 /** | |
| 19050 * The name of the type parameter. | |
| 19051 */ | |
| 19052 SimpleIdentifier _name; | |
| 19053 | |
| 19054 /** | |
| 19055 * The token representing the 'extends' keyword, or `null` if there is no | |
| 19056 * explicit upper bound. | |
| 19057 */ | |
| 19058 Token extendsKeyword; | |
| 19059 | |
| 19060 /** | |
| 19061 * The name of the upper bound for legal arguments, or `null` if there is no | |
| 19062 * explicit upper bound. | |
| 19063 */ | |
| 19064 TypeName _bound; | |
| 19065 | |
| 19066 /** | |
| 19067 * Initialize a newly created type parameter. Either or both of the [comment] | |
| 19068 * and [metadata] can be `null` if the parameter does not have the | |
| 19069 * corresponding attribute. The [extendsKeyword] and [bound] can be `null` if | |
| 19070 * the parameter does not have an upper bound. | |
| 19071 */ | |
| 19072 TypeParameter(Comment comment, List<Annotation> metadata, | |
| 19073 SimpleIdentifier name, this.extendsKeyword, TypeName bound) | |
| 19074 : super(comment, metadata) { | |
| 19075 _name = _becomeParentOf(name); | |
| 19076 _bound = _becomeParentOf(bound); | |
| 19077 } | |
| 19078 | |
| 19079 /** | |
| 19080 * Return the name of the upper bound for legal arguments, or `null` if there | |
| 19081 * is no explicit upper bound. | |
| 19082 */ | |
| 19083 TypeName get bound => _bound; | |
| 19084 | |
| 19085 /** | |
| 19086 * Set the name of the upper bound for legal arguments to the given | |
| 19087 * [typeName]. | |
| 19088 */ | |
| 19089 void set bound(TypeName typeName) { | |
| 19090 _bound = _becomeParentOf(typeName); | |
| 19091 } | |
| 19092 | |
| 19093 @override | |
| 19094 Iterable get childEntities => | |
| 19095 super._childEntities..add(_name)..add(extendsKeyword)..add(_bound); | |
| 19096 | |
| 19097 @override | |
| 19098 TypeParameterElement get element => | |
| 19099 _name != null ? (_name.staticElement as TypeParameterElement) : null; | |
| 19100 | |
| 19101 @override | |
| 19102 Token get endToken { | |
| 19103 if (_bound == null) { | |
| 19104 return _name.endToken; | |
| 19105 } | |
| 19106 return _bound.endToken; | |
| 19107 } | |
| 19108 | |
| 19109 @override | |
| 19110 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; | |
| 19111 | |
| 19112 /** | |
| 19113 * Return the token representing the 'extends' keyword, or `null` if there is | |
| 19114 * no explicit upper bound. | |
| 19115 */ | |
| 19116 @deprecated // Use "this.extendsKeyword" | |
| 19117 Token get keyword => extendsKeyword; | |
| 19118 | |
| 19119 /** | |
| 19120 * Set the token representing the 'extends' keyword to the given [token]. | |
| 19121 */ | |
| 19122 @deprecated // Use "this.extendsKeyword" | |
| 19123 set keyword(Token token) { | |
| 19124 extendsKeyword = token; | |
| 19125 } | |
| 19126 | |
| 19127 /** | |
| 19128 * Return the name of the type parameter. | |
| 19129 */ | |
| 19130 SimpleIdentifier get name => _name; | |
| 19131 | |
| 19132 /** | |
| 19133 * Set the name of the type parameter to the given [identifier]. | |
| 19134 */ | |
| 19135 void set name(SimpleIdentifier identifier) { | |
| 19136 _name = _becomeParentOf(identifier); | |
| 19137 } | |
| 19138 | |
| 19139 @override | |
| 19140 accept(AstVisitor visitor) => visitor.visitTypeParameter(this); | |
| 19141 | |
| 19142 @override | |
| 19143 void visitChildren(AstVisitor visitor) { | |
| 19144 super.visitChildren(visitor); | |
| 19145 _safelyVisitChild(_name, visitor); | |
| 19146 _safelyVisitChild(_bound, visitor); | |
| 19147 } | |
| 19148 } | |
| 19149 | |
| 19150 /** | |
| 19151 * Type parameters within a declaration. | |
| 19152 * | |
| 19153 * > typeParameterList ::= | |
| 19154 * > '<' [TypeParameter] (',' [TypeParameter])* '>' | |
| 19155 */ | |
| 19156 class TypeParameterList extends AstNode { | |
| 19157 /** | |
| 19158 * The left angle bracket. | |
| 19159 */ | |
| 19160 final Token leftBracket; | |
| 19161 | |
| 19162 /** | |
| 19163 * The type parameters in the list. | |
| 19164 */ | |
| 19165 NodeList<TypeParameter> _typeParameters; | |
| 19166 | |
| 19167 /** | |
| 19168 * The right angle bracket. | |
| 19169 */ | |
| 19170 final Token rightBracket; | |
| 19171 | |
| 19172 /** | |
| 19173 * Initialize a newly created list of type parameters. | |
| 19174 */ | |
| 19175 TypeParameterList( | |
| 19176 this.leftBracket, List<TypeParameter> typeParameters, this.rightBracket) { | |
| 19177 _typeParameters = new NodeList<TypeParameter>(this, typeParameters); | |
| 19178 } | |
| 19179 | |
| 19180 @override | |
| 19181 Token get beginToken => leftBracket; | |
| 19182 | |
| 19183 @override | |
| 19184 Iterable get childEntities => new ChildEntities() | |
| 19185 ..add(leftBracket) | |
| 19186 ..addAll(_typeParameters) | |
| 19187 ..add(rightBracket); | |
| 19188 | |
| 19189 @override | |
| 19190 Token get endToken => rightBracket; | |
| 19191 | |
| 19192 /** | |
| 19193 * Return the type parameters for the type. | |
| 19194 */ | |
| 19195 NodeList<TypeParameter> get typeParameters => _typeParameters; | |
| 19196 | |
| 19197 @override | |
| 19198 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this); | |
| 19199 | |
| 19200 @override | |
| 19201 void visitChildren(AstVisitor visitor) { | |
| 19202 _typeParameters.accept(visitor); | |
| 19203 } | |
| 19204 } | |
| 19205 | |
| 19206 /** | |
| 19207 * An AST visitor that will recursively visit all of the nodes in an AST | |
| 19208 * structure (like instances of the class [RecursiveAstVisitor]). In addition, | |
| 19209 * every node will also be visited by using a single unified [visitNode] method. | |
| 19210 * | |
| 19211 * Subclasses that override a visit method must either invoke the overridden | |
| 19212 * visit method or explicitly invoke the more general [visitNode] method. | |
| 19213 * Failure to do so will cause the children of the visited node to not be | |
| 19214 * visited. | |
| 19215 */ | |
| 19216 class UnifyingAstVisitor<R> implements AstVisitor<R> { | |
| 19217 @override | |
| 19218 R visitAdjacentStrings(AdjacentStrings node) => visitNode(node); | |
| 19219 | |
| 19220 @override | |
| 19221 R visitAnnotation(Annotation node) => visitNode(node); | |
| 19222 | |
| 19223 @override | |
| 19224 R visitArgumentList(ArgumentList node) => visitNode(node); | |
| 19225 | |
| 19226 @override | |
| 19227 R visitAsExpression(AsExpression node) => visitNode(node); | |
| 19228 | |
| 19229 @override | |
| 19230 R visitAssertStatement(AssertStatement node) => visitNode(node); | |
| 19231 | |
| 19232 @override | |
| 19233 R visitAssignmentExpression(AssignmentExpression node) => visitNode(node); | |
| 19234 | |
| 19235 @override | |
| 19236 R visitAwaitExpression(AwaitExpression node) => visitNode(node); | |
| 19237 | |
| 19238 @override | |
| 19239 R visitBinaryExpression(BinaryExpression node) => visitNode(node); | |
| 19240 | |
| 19241 @override | |
| 19242 R visitBlock(Block node) => visitNode(node); | |
| 19243 | |
| 19244 @override | |
| 19245 R visitBlockFunctionBody(BlockFunctionBody node) => visitNode(node); | |
| 19246 | |
| 19247 @override | |
| 19248 R visitBooleanLiteral(BooleanLiteral node) => visitNode(node); | |
| 19249 | |
| 19250 @override | |
| 19251 R visitBreakStatement(BreakStatement node) => visitNode(node); | |
| 19252 | |
| 19253 @override | |
| 19254 R visitCascadeExpression(CascadeExpression node) => visitNode(node); | |
| 19255 | |
| 19256 @override | |
| 19257 R visitCatchClause(CatchClause node) => visitNode(node); | |
| 19258 | |
| 19259 @override | |
| 19260 R visitClassDeclaration(ClassDeclaration node) => visitNode(node); | |
| 19261 | |
| 19262 @override | |
| 19263 R visitClassTypeAlias(ClassTypeAlias node) => visitNode(node); | |
| 19264 | |
| 19265 @override | |
| 19266 R visitComment(Comment node) => visitNode(node); | |
| 19267 | |
| 19268 @override | |
| 19269 R visitCommentReference(CommentReference node) => visitNode(node); | |
| 19270 | |
| 19271 @override | |
| 19272 R visitCompilationUnit(CompilationUnit node) => visitNode(node); | |
| 19273 | |
| 19274 @override | |
| 19275 R visitConditionalExpression(ConditionalExpression node) => visitNode(node); | |
| 19276 | |
| 19277 @override | |
| 19278 R visitConstructorDeclaration(ConstructorDeclaration node) => visitNode(node); | |
| 19279 | |
| 19280 @override | |
| 19281 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => | |
| 19282 visitNode(node); | |
| 19283 | |
| 19284 @override | |
| 19285 R visitConstructorName(ConstructorName node) => visitNode(node); | |
| 19286 | |
| 19287 @override | |
| 19288 R visitContinueStatement(ContinueStatement node) => visitNode(node); | |
| 19289 | |
| 19290 @override | |
| 19291 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitNode(node); | |
| 19292 | |
| 19293 @override | |
| 19294 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitNode(node); | |
| 19295 | |
| 19296 @override | |
| 19297 R visitDoStatement(DoStatement node) => visitNode(node); | |
| 19298 | |
| 19299 @override | |
| 19300 R visitDoubleLiteral(DoubleLiteral node) => visitNode(node); | |
| 19301 | |
| 19302 @override | |
| 19303 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node); | |
| 19304 | |
| 19305 @override | |
| 19306 R visitEmptyStatement(EmptyStatement node) => visitNode(node); | |
| 19307 | |
| 19308 @override | |
| 19309 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => | |
| 19310 visitNode(node); | |
| 19311 | |
| 19312 @override | |
| 19313 R visitEnumDeclaration(EnumDeclaration node) => visitNode(node); | |
| 19314 | |
| 19315 @override | |
| 19316 R visitExportDirective(ExportDirective node) => visitNode(node); | |
| 19317 | |
| 19318 @override | |
| 19319 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitNode(node); | |
| 19320 | |
| 19321 @override | |
| 19322 R visitExpressionStatement(ExpressionStatement node) => visitNode(node); | |
| 19323 | |
| 19324 @override | |
| 19325 R visitExtendsClause(ExtendsClause node) => visitNode(node); | |
| 19326 | |
| 19327 @override | |
| 19328 R visitFieldDeclaration(FieldDeclaration node) => visitNode(node); | |
| 19329 | |
| 19330 @override | |
| 19331 R visitFieldFormalParameter(FieldFormalParameter node) => visitNode(node); | |
| 19332 | |
| 19333 @override | |
| 19334 R visitForEachStatement(ForEachStatement node) => visitNode(node); | |
| 19335 | |
| 19336 @override | |
| 19337 R visitFormalParameterList(FormalParameterList node) => visitNode(node); | |
| 19338 | |
| 19339 @override | |
| 19340 R visitForStatement(ForStatement node) => visitNode(node); | |
| 19341 | |
| 19342 @override | |
| 19343 R visitFunctionDeclaration(FunctionDeclaration node) => visitNode(node); | |
| 19344 | |
| 19345 @override | |
| 19346 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => | |
| 19347 visitNode(node); | |
| 19348 | |
| 19349 @override | |
| 19350 R visitFunctionExpression(FunctionExpression node) => visitNode(node); | |
| 19351 | |
| 19352 @override | |
| 19353 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => | |
| 19354 visitNode(node); | |
| 19355 | |
| 19356 @override | |
| 19357 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitNode(node); | |
| 19358 | |
| 19359 @override | |
| 19360 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => | |
| 19361 visitNode(node); | |
| 19362 | |
| 19363 @override | |
| 19364 R visitHideCombinator(HideCombinator node) => visitNode(node); | |
| 19365 | |
| 19366 @override | |
| 19367 R visitIfStatement(IfStatement node) => visitNode(node); | |
| 19368 | |
| 19369 @override | |
| 19370 R visitImplementsClause(ImplementsClause node) => visitNode(node); | |
| 19371 | |
| 19372 @override | |
| 19373 R visitImportDirective(ImportDirective node) => visitNode(node); | |
| 19374 | |
| 19375 @override | |
| 19376 R visitIndexExpression(IndexExpression node) => visitNode(node); | |
| 19377 | |
| 19378 @override | |
| 19379 R visitInstanceCreationExpression(InstanceCreationExpression node) => | |
| 19380 visitNode(node); | |
| 19381 | |
| 19382 @override | |
| 19383 R visitIntegerLiteral(IntegerLiteral node) => visitNode(node); | |
| 19384 | |
| 19385 @override | |
| 19386 R visitInterpolationExpression(InterpolationExpression node) => | |
| 19387 visitNode(node); | |
| 19388 | |
| 19389 @override | |
| 19390 R visitInterpolationString(InterpolationString node) => visitNode(node); | |
| 19391 | |
| 19392 @override | |
| 19393 R visitIsExpression(IsExpression node) => visitNode(node); | |
| 19394 | |
| 19395 @override | |
| 19396 R visitLabel(Label node) => visitNode(node); | |
| 19397 | |
| 19398 @override | |
| 19399 R visitLabeledStatement(LabeledStatement node) => visitNode(node); | |
| 19400 | |
| 19401 @override | |
| 19402 R visitLibraryDirective(LibraryDirective node) => visitNode(node); | |
| 19403 | |
| 19404 @override | |
| 19405 R visitLibraryIdentifier(LibraryIdentifier node) => visitNode(node); | |
| 19406 | |
| 19407 @override | |
| 19408 R visitListLiteral(ListLiteral node) => visitNode(node); | |
| 19409 | |
| 19410 @override | |
| 19411 R visitMapLiteral(MapLiteral node) => visitNode(node); | |
| 19412 | |
| 19413 @override | |
| 19414 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node); | |
| 19415 | |
| 19416 @override | |
| 19417 R visitMethodDeclaration(MethodDeclaration node) => visitNode(node); | |
| 19418 | |
| 19419 @override | |
| 19420 R visitMethodInvocation(MethodInvocation node) => visitNode(node); | |
| 19421 | |
| 19422 @override | |
| 19423 R visitNamedExpression(NamedExpression node) => visitNode(node); | |
| 19424 | |
| 19425 @override | |
| 19426 R visitNativeClause(NativeClause node) => visitNode(node); | |
| 19427 | |
| 19428 @override | |
| 19429 R visitNativeFunctionBody(NativeFunctionBody node) => visitNode(node); | |
| 19430 | |
| 19431 R visitNode(AstNode node) { | |
| 19432 node.visitChildren(this); | |
| 19433 return null; | |
| 19434 } | |
| 19435 | |
| 19436 @override | |
| 19437 R visitNullLiteral(NullLiteral node) => visitNode(node); | |
| 19438 | |
| 19439 @override | |
| 19440 R visitParenthesizedExpression(ParenthesizedExpression node) => | |
| 19441 visitNode(node); | |
| 19442 | |
| 19443 @override | |
| 19444 R visitPartDirective(PartDirective node) => visitNode(node); | |
| 19445 | |
| 19446 @override | |
| 19447 R visitPartOfDirective(PartOfDirective node) => visitNode(node); | |
| 19448 | |
| 19449 @override | |
| 19450 R visitPostfixExpression(PostfixExpression node) => visitNode(node); | |
| 19451 | |
| 19452 @override | |
| 19453 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitNode(node); | |
| 19454 | |
| 19455 @override | |
| 19456 R visitPrefixExpression(PrefixExpression node) => visitNode(node); | |
| 19457 | |
| 19458 @override | |
| 19459 R visitPropertyAccess(PropertyAccess node) => visitNode(node); | |
| 19460 | |
| 19461 @override | |
| 19462 R visitRedirectingConstructorInvocation( | |
| 19463 RedirectingConstructorInvocation node) => visitNode(node); | |
| 19464 | |
| 19465 @override | |
| 19466 R visitRethrowExpression(RethrowExpression node) => visitNode(node); | |
| 19467 | |
| 19468 @override | |
| 19469 R visitReturnStatement(ReturnStatement node) => visitNode(node); | |
| 19470 | |
| 19471 @override | |
| 19472 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); | |
| 19473 | |
| 19474 @override | |
| 19475 R visitShowCombinator(ShowCombinator node) => visitNode(node); | |
| 19476 | |
| 19477 @override | |
| 19478 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNode(node); | |
| 19479 | |
| 19480 @override | |
| 19481 R visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node); | |
| 19482 | |
| 19483 @override | |
| 19484 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node); | |
| 19485 | |
| 19486 @override | |
| 19487 R visitStringInterpolation(StringInterpolation node) => visitNode(node); | |
| 19488 | |
| 19489 @override | |
| 19490 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => | |
| 19491 visitNode(node); | |
| 19492 | |
| 19493 @override | |
| 19494 R visitSuperExpression(SuperExpression node) => visitNode(node); | |
| 19495 | |
| 19496 @override | |
| 19497 R visitSwitchCase(SwitchCase node) => visitNode(node); | |
| 19498 | |
| 19499 @override | |
| 19500 R visitSwitchDefault(SwitchDefault node) => visitNode(node); | |
| 19501 | |
| 19502 @override | |
| 19503 R visitSwitchStatement(SwitchStatement node) => visitNode(node); | |
| 19504 | |
| 19505 @override | |
| 19506 R visitSymbolLiteral(SymbolLiteral node) => visitNode(node); | |
| 19507 | |
| 19508 @override | |
| 19509 R visitThisExpression(ThisExpression node) => visitNode(node); | |
| 19510 | |
| 19511 @override | |
| 19512 R visitThrowExpression(ThrowExpression node) => visitNode(node); | |
| 19513 | |
| 19514 @override | |
| 19515 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => | |
| 19516 visitNode(node); | |
| 19517 | |
| 19518 @override | |
| 19519 R visitTryStatement(TryStatement node) => visitNode(node); | |
| 19520 | |
| 19521 @override | |
| 19522 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node); | |
| 19523 | |
| 19524 @override | |
| 19525 R visitTypeName(TypeName node) => visitNode(node); | |
| 19526 | |
| 19527 @override | |
| 19528 R visitTypeParameter(TypeParameter node) => visitNode(node); | |
| 19529 | |
| 19530 @override | |
| 19531 R visitTypeParameterList(TypeParameterList node) => visitNode(node); | |
| 19532 | |
| 19533 @override | |
| 19534 R visitVariableDeclaration(VariableDeclaration node) => visitNode(node); | |
| 19535 | |
| 19536 @override | |
| 19537 R visitVariableDeclarationList(VariableDeclarationList node) => | |
| 19538 visitNode(node); | |
| 19539 | |
| 19540 @override | |
| 19541 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => | |
| 19542 visitNode(node); | |
| 19543 | |
| 19544 @override | |
| 19545 R visitWhileStatement(WhileStatement node) => visitNode(node); | |
| 19546 | |
| 19547 @override | |
| 19548 R visitWithClause(WithClause node) => visitNode(node); | |
| 19549 | |
| 19550 @override | |
| 19551 R visitYieldStatement(YieldStatement node) => visitNode(node); | |
| 19552 } | |
| 19553 | |
| 19554 /** | |
| 19555 * A directive that references a URI. | |
| 19556 * | |
| 19557 * > uriBasedDirective ::= | |
| 19558 * > [ExportDirective] | |
| 19559 * > | [ImportDirective] | |
| 19560 * > | [PartDirective] | |
| 19561 */ | |
| 19562 abstract class UriBasedDirective extends Directive { | |
| 19563 /** | |
| 19564 * The prefix of a URI using the `dart-ext` scheme to reference a native code | |
| 19565 * library. | |
| 19566 */ | |
| 19567 static String _DART_EXT_SCHEME = "dart-ext:"; | |
| 19568 | |
| 19569 /** | |
| 19570 * The URI referenced by this directive. | |
| 19571 */ | |
| 19572 StringLiteral _uri; | |
| 19573 | |
| 19574 /** | |
| 19575 * The content of the URI. | |
| 19576 */ | |
| 19577 String uriContent; | |
| 19578 | |
| 19579 /** | |
| 19580 * The source to which the URI was resolved. | |
| 19581 */ | |
| 19582 Source source; | |
| 19583 | |
| 19584 /** | |
| 19585 * Initialize a newly create URI-based directive. Either or both of the | |
| 19586 * [comment] and [metadata] can be `null` if the directive does not have the | |
| 19587 * corresponding attribute. | |
| 19588 */ | |
| 19589 UriBasedDirective( | |
| 19590 Comment comment, List<Annotation> metadata, StringLiteral uri) | |
| 19591 : super(comment, metadata) { | |
| 19592 _uri = _becomeParentOf(uri); | |
| 19593 } | |
| 19594 | |
| 19595 /** | |
| 19596 * Return the URI referenced by this directive. | |
| 19597 */ | |
| 19598 StringLiteral get uri => _uri; | |
| 19599 | |
| 19600 /** | |
| 19601 * Set the URI referenced by this directive to the given [uri]. | |
| 19602 */ | |
| 19603 void set uri(StringLiteral uri) { | |
| 19604 _uri = _becomeParentOf(uri); | |
| 19605 } | |
| 19606 | |
| 19607 /** | |
| 19608 * Return the element associated with the URI of this directive, or `null` if | |
| 19609 * the AST structure has not been resolved or if the URI could not be | |
| 19610 * resolved. Examples of the latter case include a directive that contains an | |
| 19611 * invalid URL or a URL that does not exist. | |
| 19612 */ | |
| 19613 Element get uriElement; | |
| 19614 | |
| 19615 /** | |
| 19616 * Validate this directive, but do not check for existence. Return a code | |
| 19617 * indicating the problem if there is one, or `null` no problem | |
| 19618 */ | |
| 19619 UriValidationCode validate() { | |
| 19620 StringLiteral uriLiteral = uri; | |
| 19621 if (uriLiteral is StringInterpolation) { | |
| 19622 return UriValidationCode.URI_WITH_INTERPOLATION; | |
| 19623 } | |
| 19624 String uriContent = this.uriContent; | |
| 19625 if (uriContent == null) { | |
| 19626 return UriValidationCode.INVALID_URI; | |
| 19627 } | |
| 19628 if (this is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME)) { | |
| 19629 return UriValidationCode.URI_WITH_DART_EXT_SCHEME; | |
| 19630 } | |
| 19631 try { | |
| 19632 parseUriWithException(Uri.encodeFull(uriContent)); | |
| 19633 } on URISyntaxException { | |
| 19634 return UriValidationCode.INVALID_URI; | |
| 19635 } | |
| 19636 return null; | |
| 19637 } | |
| 19638 | |
| 19639 @override | |
| 19640 void visitChildren(AstVisitor visitor) { | |
| 19641 super.visitChildren(visitor); | |
| 19642 _safelyVisitChild(_uri, visitor); | |
| 19643 } | |
| 19644 } | |
| 19645 | |
| 19646 /** | |
| 19647 * Validation codes returned by [UriBasedDirective.validate]. | |
| 19648 */ | |
| 19649 class UriValidationCode { | |
| 19650 static const UriValidationCode INVALID_URI = | |
| 19651 const UriValidationCode('INVALID_URI'); | |
| 19652 | |
| 19653 static const UriValidationCode URI_WITH_INTERPOLATION = | |
| 19654 const UriValidationCode('URI_WITH_INTERPOLATION'); | |
| 19655 | |
| 19656 static const UriValidationCode URI_WITH_DART_EXT_SCHEME = | |
| 19657 const UriValidationCode('URI_WITH_DART_EXT_SCHEME'); | |
| 19658 | |
| 19659 /** | |
| 19660 * The name of the validation code. | |
| 19661 */ | |
| 19662 final String name; | |
| 19663 | |
| 19664 /** | |
| 19665 * Initialize a newly created validation code to have the given [name]. | |
| 19666 */ | |
| 19667 const UriValidationCode(this.name); | |
| 19668 | |
| 19669 @override | |
| 19670 String toString() => name; | |
| 19671 } | |
| 19672 | |
| 19673 /** | |
| 19674 * An identifier that has an initial value associated with it. Instances of this | |
| 19675 * class are always children of the class [VariableDeclarationList]. | |
| 19676 * | |
| 19677 * > variableDeclaration ::= | |
| 19678 * > [SimpleIdentifier] ('=' [Expression])? | |
| 19679 * | |
| 19680 * TODO(paulberry): the grammar does not allow metadata to be associated with | |
| 19681 * a VariableDeclaration, and currently we don't record comments for it either. | |
| 19682 * Consider changing the class hierarchy so that [VariableDeclaration] does not | |
| 19683 * extend [Declaration]. | |
| 19684 */ | |
| 19685 class VariableDeclaration extends Declaration { | |
| 19686 /** | |
| 19687 * The name of the variable being declared. | |
| 19688 */ | |
| 19689 SimpleIdentifier _name; | |
| 19690 | |
| 19691 /** | |
| 19692 * The equal sign separating the variable name from the initial value, or | |
| 19693 * `null` if the initial value was not specified. | |
| 19694 */ | |
| 19695 Token equals; | |
| 19696 | |
| 19697 /** | |
| 19698 * The expression used to compute the initial value for the variable, or | |
| 19699 * `null` if the initial value was not specified. | |
| 19700 */ | |
| 19701 Expression _initializer; | |
| 19702 | |
| 19703 /** | |
| 19704 * Initialize a newly created variable declaration. The [equals] and | |
| 19705 * [initializer] can be `null` if there is no initializer. | |
| 19706 */ | |
| 19707 VariableDeclaration( | |
| 19708 SimpleIdentifier name, this.equals, Expression initializer) | |
| 19709 : super(null, null) { | |
| 19710 _name = _becomeParentOf(name); | |
| 19711 _initializer = _becomeParentOf(initializer); | |
| 19712 } | |
| 19713 | |
| 19714 @override | |
| 19715 Iterable get childEntities => | |
| 19716 super._childEntities..add(_name)..add(equals)..add(_initializer); | |
| 19717 | |
| 19718 /** | |
| 19719 * This overridden implementation of getDocumentationComment() looks in the | |
| 19720 * grandparent node for dartdoc comments if no documentation is specifically | |
| 19721 * available on the node. | |
| 19722 */ | |
| 19723 @override | |
| 19724 Comment get documentationComment { | |
| 19725 Comment comment = super.documentationComment; | |
| 19726 if (comment == null) { | |
| 19727 if (parent != null && parent.parent != null) { | |
| 19728 AstNode node = parent.parent; | |
| 19729 if (node is AnnotatedNode) { | |
| 19730 return node.documentationComment; | |
| 19731 } | |
| 19732 } | |
| 19733 } | |
| 19734 return comment; | |
| 19735 } | |
| 19736 | |
| 19737 @override | |
| 19738 VariableElement get element => | |
| 19739 _name != null ? (_name.staticElement as VariableElement) : null; | |
| 19740 | |
| 19741 @override | |
| 19742 Token get endToken { | |
| 19743 if (_initializer != null) { | |
| 19744 return _initializer.endToken; | |
| 19745 } | |
| 19746 return _name.endToken; | |
| 19747 } | |
| 19748 | |
| 19749 @override | |
| 19750 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; | |
| 19751 | |
| 19752 /** | |
| 19753 * Return the expression used to compute the initial value for the variable, | |
| 19754 * or `null` if the initial value was not specified. | |
| 19755 */ | |
| 19756 Expression get initializer => _initializer; | |
| 19757 | |
| 19758 /** | |
| 19759 * Set the expression used to compute the initial value for the variable to | |
| 19760 * the given [expression]. | |
| 19761 */ | |
| 19762 void set initializer(Expression expression) { | |
| 19763 _initializer = _becomeParentOf(expression); | |
| 19764 } | |
| 19765 | |
| 19766 /** | |
| 19767 * Return `true` if this variable was declared with the 'const' modifier. | |
| 19768 */ | |
| 19769 bool get isConst { | |
| 19770 AstNode parent = this.parent; | |
| 19771 return parent is VariableDeclarationList && parent.isConst; | |
| 19772 } | |
| 19773 | |
| 19774 /** | |
| 19775 * Return `true` if this variable was declared with the 'final' modifier. | |
| 19776 * Variables that are declared with the 'const' modifier will return `false` | |
| 19777 * even though they are implicitly final. | |
| 19778 */ | |
| 19779 bool get isFinal { | |
| 19780 AstNode parent = this.parent; | |
| 19781 return parent is VariableDeclarationList && parent.isFinal; | |
| 19782 } | |
| 19783 | |
| 19784 /** | |
| 19785 * Return the name of the variable being declared. | |
| 19786 */ | |
| 19787 SimpleIdentifier get name => _name; | |
| 19788 | |
| 19789 /** | |
| 19790 * Set the name of the variable being declared to the given [identifier]. | |
| 19791 */ | |
| 19792 void set name(SimpleIdentifier identifier) { | |
| 19793 _name = _becomeParentOf(identifier); | |
| 19794 } | |
| 19795 | |
| 19796 @override | |
| 19797 accept(AstVisitor visitor) => visitor.visitVariableDeclaration(this); | |
| 19798 | |
| 19799 @override | |
| 19800 void visitChildren(AstVisitor visitor) { | |
| 19801 super.visitChildren(visitor); | |
| 19802 _safelyVisitChild(_name, visitor); | |
| 19803 _safelyVisitChild(_initializer, visitor); | |
| 19804 } | |
| 19805 } | |
| 19806 | |
| 19807 /** | |
| 19808 * The declaration of one or more variables of the same type. | |
| 19809 * | |
| 19810 * > variableDeclarationList ::= | |
| 19811 * > finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])* | |
| 19812 * > | |
| 19813 * > finalConstVarOrType ::= | |
| 19814 * > | 'final' [TypeName]? | |
| 19815 * > | 'const' [TypeName]? | |
| 19816 * > | 'var' | |
| 19817 * > | [TypeName] | |
| 19818 */ | |
| 19819 class VariableDeclarationList extends AnnotatedNode { | |
| 19820 /** | |
| 19821 * The token representing the 'final', 'const' or 'var' keyword, or `null` if | |
| 19822 * no keyword was included. | |
| 19823 */ | |
| 19824 Token keyword; | |
| 19825 | |
| 19826 /** | |
| 19827 * The type of the variables being declared, or `null` if no type was provided
. | |
| 19828 */ | |
| 19829 TypeName _type; | |
| 19830 | |
| 19831 /** | |
| 19832 * A list containing the individual variables being declared. | |
| 19833 */ | |
| 19834 NodeList<VariableDeclaration> _variables; | |
| 19835 | |
| 19836 /** | |
| 19837 * Initialize a newly created variable declaration list. Either or both of the | |
| 19838 * [comment] and [metadata] can be `null` if the variable list does not have | |
| 19839 * the corresponding attribute. The [keyword] can be `null` if a type was | |
| 19840 * specified. The [type] must be `null` if the keyword is 'var'. | |
| 19841 */ | |
| 19842 VariableDeclarationList(Comment comment, List<Annotation> metadata, | |
| 19843 this.keyword, TypeName type, List<VariableDeclaration> variables) | |
| 19844 : super(comment, metadata) { | |
| 19845 _type = _becomeParentOf(type); | |
| 19846 _variables = new NodeList<VariableDeclaration>(this, variables); | |
| 19847 } | |
| 19848 | |
| 19849 /** | |
| 19850 * TODO(paulberry): include commas. | |
| 19851 */ | |
| 19852 @override | |
| 19853 Iterable get childEntities => super._childEntities | |
| 19854 ..add(keyword) | |
| 19855 ..add(_type) | |
| 19856 ..addAll(_variables); | |
| 19857 | |
| 19858 @override | |
| 19859 Token get endToken => _variables.endToken; | |
| 19860 | |
| 19861 @override | |
| 19862 Token get firstTokenAfterCommentAndMetadata { | |
| 19863 if (keyword != null) { | |
| 19864 return keyword; | |
| 19865 } else if (_type != null) { | |
| 19866 return _type.beginToken; | |
| 19867 } | |
| 19868 return _variables.beginToken; | |
| 19869 } | |
| 19870 | |
| 19871 /** | |
| 19872 * Return `true` if the variables in this list were declared with the 'const' | |
| 19873 * modifier. | |
| 19874 */ | |
| 19875 bool get isConst => keyword is KeywordToken && | |
| 19876 (keyword as KeywordToken).keyword == Keyword.CONST; | |
| 19877 | |
| 19878 /** | |
| 19879 * Return `true` if the variables in this list were declared with the 'final' | |
| 19880 * modifier. Variables that are declared with the 'const' modifier will return | |
| 19881 * `false` even though they are implicitly final. (In other words, this is a | |
| 19882 * syntactic check rather than a semantic check.) | |
| 19883 */ | |
| 19884 bool get isFinal => keyword is KeywordToken && | |
| 19885 (keyword as KeywordToken).keyword == Keyword.FINAL; | |
| 19886 | |
| 19887 /** | |
| 19888 * Return the type of the variables being declared, or `null` if no type was | |
| 19889 * provided. | |
| 19890 */ | |
| 19891 TypeName get type => _type; | |
| 19892 | |
| 19893 /** | |
| 19894 * Set the type of the variables being declared to the given [typeName]. | |
| 19895 */ | |
| 19896 void set type(TypeName typeName) { | |
| 19897 _type = _becomeParentOf(typeName); | |
| 19898 } | |
| 19899 | |
| 19900 /** | |
| 19901 * Return a list containing the individual variables being declared. | |
| 19902 */ | |
| 19903 NodeList<VariableDeclaration> get variables => _variables; | |
| 19904 | |
| 19905 @override | |
| 19906 accept(AstVisitor visitor) => visitor.visitVariableDeclarationList(this); | |
| 19907 | |
| 19908 @override | |
| 19909 void visitChildren(AstVisitor visitor) { | |
| 19910 super.visitChildren(visitor); | |
| 19911 _safelyVisitChild(_type, visitor); | |
| 19912 _variables.accept(visitor); | |
| 19913 } | |
| 19914 } | |
| 19915 | |
| 19916 /** | |
| 19917 * A list of variables that are being declared in a context where a statement is | |
| 19918 * required. | |
| 19919 * | |
| 19920 * > variableDeclarationStatement ::= | |
| 19921 * > [VariableDeclarationList] ';' | |
| 19922 */ | |
| 19923 class VariableDeclarationStatement extends Statement { | |
| 19924 /** | |
| 19925 * The variables being declared. | |
| 19926 */ | |
| 19927 VariableDeclarationList _variableList; | |
| 19928 | |
| 19929 /** | |
| 19930 * The semicolon terminating the statement. | |
| 19931 */ | |
| 19932 Token semicolon; | |
| 19933 | |
| 19934 /** | |
| 19935 * Initialize a newly created variable declaration statement. | |
| 19936 */ | |
| 19937 VariableDeclarationStatement( | |
| 19938 VariableDeclarationList variableList, this.semicolon) { | |
| 19939 _variableList = _becomeParentOf(variableList); | |
| 19940 } | |
| 19941 | |
| 19942 @override | |
| 19943 Token get beginToken => _variableList.beginToken; | |
| 19944 | |
| 19945 @override | |
| 19946 Iterable get childEntities => | |
| 19947 new ChildEntities()..add(_variableList)..add(semicolon); | |
| 19948 | |
| 19949 @override | |
| 19950 Token get endToken => semicolon; | |
| 19951 | |
| 19952 /** | |
| 19953 * Return the variables being declared. | |
| 19954 */ | |
| 19955 VariableDeclarationList get variables => _variableList; | |
| 19956 | |
| 19957 /** | |
| 19958 * Set the variables being declared to the given list of [variables]. | |
| 19959 */ | |
| 19960 void set variables(VariableDeclarationList variables) { | |
| 19961 _variableList = _becomeParentOf(variables); | |
| 19962 } | |
| 19963 | |
| 19964 @override | |
| 19965 accept(AstVisitor visitor) => visitor.visitVariableDeclarationStatement(this); | |
| 19966 | |
| 19967 @override | |
| 19968 void visitChildren(AstVisitor visitor) { | |
| 19969 _safelyVisitChild(_variableList, visitor); | |
| 19970 } | |
| 19971 } | |
| 19972 | |
| 19973 /** | |
| 19974 * A while statement. | |
| 19975 * | |
| 19976 * > whileStatement ::= | |
| 19977 * > 'while' '(' [Expression] ')' [Statement] | |
| 19978 */ | |
| 19979 class WhileStatement extends Statement { | |
| 19980 /** | |
| 19981 * The token representing the 'while' keyword. | |
| 19982 */ | |
| 19983 Token whileKeyword; | |
| 19984 | |
| 19985 /** | |
| 19986 * The left parenthesis. | |
| 19987 */ | |
| 19988 Token leftParenthesis; | |
| 19989 | |
| 19990 /** | |
| 19991 * The expression used to determine whether to execute the body of the loop. | |
| 19992 */ | |
| 19993 Expression _condition; | |
| 19994 | |
| 19995 /** | |
| 19996 * The right parenthesis. | |
| 19997 */ | |
| 19998 Token rightParenthesis; | |
| 19999 | |
| 20000 /** | |
| 20001 * The body of the loop. | |
| 20002 */ | |
| 20003 Statement _body; | |
| 20004 | |
| 20005 /** | |
| 20006 * Initialize a newly created while statement. | |
| 20007 */ | |
| 20008 WhileStatement(this.whileKeyword, this.leftParenthesis, Expression condition, | |
| 20009 this.rightParenthesis, Statement body) { | |
| 20010 _condition = _becomeParentOf(condition); | |
| 20011 _body = _becomeParentOf(body); | |
| 20012 } | |
| 20013 | |
| 20014 @override | |
| 20015 Token get beginToken => whileKeyword; | |
| 20016 | |
| 20017 /** | |
| 20018 * Return the body of the loop. | |
| 20019 */ | |
| 20020 Statement get body => _body; | |
| 20021 | |
| 20022 /** | |
| 20023 * Set the body of the loop to the given [statement]. | |
| 20024 */ | |
| 20025 void set body(Statement statement) { | |
| 20026 _body = _becomeParentOf(statement); | |
| 20027 } | |
| 20028 | |
| 20029 @override | |
| 20030 Iterable get childEntities => new ChildEntities() | |
| 20031 ..add(whileKeyword) | |
| 20032 ..add(leftParenthesis) | |
| 20033 ..add(_condition) | |
| 20034 ..add(rightParenthesis) | |
| 20035 ..add(_body); | |
| 20036 | |
| 20037 /** | |
| 20038 * Return the expression used to determine whether to execute the body of the | |
| 20039 * loop. | |
| 20040 */ | |
| 20041 Expression get condition => _condition; | |
| 20042 | |
| 20043 /** | |
| 20044 * Set the expression used to determine whether to execute the body of the | |
| 20045 * loop to the given [expression]. | |
| 20046 */ | |
| 20047 void set condition(Expression expression) { | |
| 20048 _condition = _becomeParentOf(expression); | |
| 20049 } | |
| 20050 | |
| 20051 @override | |
| 20052 Token get endToken => _body.endToken; | |
| 20053 | |
| 20054 /** | |
| 20055 * Return the token representing the 'while' keyword. | |
| 20056 */ | |
| 20057 @deprecated // Use "this.whileKeyword" | |
| 20058 Token get keyword => whileKeyword; | |
| 20059 | |
| 20060 /** | |
| 20061 * Set the token representing the 'while' keyword to the given [token]. | |
| 20062 */ | |
| 20063 @deprecated // Use "this.whileKeyword" | |
| 20064 set keyword(Token token) { | |
| 20065 whileKeyword = token; | |
| 20066 } | |
| 20067 | |
| 20068 @override | |
| 20069 accept(AstVisitor visitor) => visitor.visitWhileStatement(this); | |
| 20070 | |
| 20071 @override | |
| 20072 void visitChildren(AstVisitor visitor) { | |
| 20073 _safelyVisitChild(_condition, visitor); | |
| 20074 _safelyVisitChild(_body, visitor); | |
| 20075 } | |
| 20076 } | |
| 20077 | |
| 20078 /** | |
| 20079 * The with clause in a class declaration. | |
| 20080 * | |
| 20081 * > withClause ::= | |
| 20082 * > 'with' [TypeName] (',' [TypeName])* | |
| 20083 */ | |
| 20084 class WithClause extends AstNode { | |
| 20085 /** | |
| 20086 * The token representing the 'with' keyword. | |
| 20087 */ | |
| 20088 Token withKeyword; | |
| 20089 | |
| 20090 /** | |
| 20091 * The names of the mixins that were specified. | |
| 20092 */ | |
| 20093 NodeList<TypeName> _mixinTypes; | |
| 20094 | |
| 20095 /** | |
| 20096 * Initialize a newly created with clause. | |
| 20097 */ | |
| 20098 WithClause(this.withKeyword, List<TypeName> mixinTypes) { | |
| 20099 _mixinTypes = new NodeList<TypeName>(this, mixinTypes); | |
| 20100 } | |
| 20101 | |
| 20102 @override | |
| 20103 Token get beginToken => withKeyword; | |
| 20104 | |
| 20105 /** | |
| 20106 * TODO(paulberry): add commas. | |
| 20107 */ | |
| 20108 @override | |
| 20109 Iterable get childEntities => new ChildEntities() | |
| 20110 ..add(withKeyword) | |
| 20111 ..addAll(_mixinTypes); | |
| 20112 | |
| 20113 @override | |
| 20114 Token get endToken => _mixinTypes.endToken; | |
| 20115 | |
| 20116 /** | |
| 20117 * Set the token representing the 'with' keyword to the given [token]. | |
| 20118 */ | |
| 20119 @deprecated // Use "this.withKeyword" | |
| 20120 void set mixinKeyword(Token token) { | |
| 20121 this.withKeyword = token; | |
| 20122 } | |
| 20123 | |
| 20124 /** | |
| 20125 * Return the names of the mixins that were specified. | |
| 20126 */ | |
| 20127 NodeList<TypeName> get mixinTypes => _mixinTypes; | |
| 20128 | |
| 20129 @override | |
| 20130 accept(AstVisitor visitor) => visitor.visitWithClause(this); | |
| 20131 | |
| 20132 @override | |
| 20133 void visitChildren(AstVisitor visitor) { | |
| 20134 _mixinTypes.accept(visitor); | |
| 20135 } | |
| 20136 } | |
| 20137 | |
| 20138 /** | |
| 20139 * A yield statement. | |
| 20140 * | |
| 20141 * > yieldStatement ::= | |
| 20142 * > 'yield' '*'? [Expression] ‘;’ | |
| 20143 */ | |
| 20144 class YieldStatement extends Statement { | |
| 20145 /** | |
| 20146 * The 'yield' keyword. | |
| 20147 */ | |
| 20148 Token yieldKeyword; | |
| 20149 | |
| 20150 /** | |
| 20151 * The star optionally following the 'yield' keyword. | |
| 20152 */ | |
| 20153 Token star; | |
| 20154 | |
| 20155 /** | |
| 20156 * The expression whose value will be yielded. | |
| 20157 */ | |
| 20158 Expression _expression; | |
| 20159 | |
| 20160 /** | |
| 20161 * The semicolon following the expression. | |
| 20162 */ | |
| 20163 Token semicolon; | |
| 20164 | |
| 20165 /** | |
| 20166 * Initialize a newly created yield expression. The [star] can be `null` if no | |
| 20167 * star was provided. | |
| 20168 */ | |
| 20169 YieldStatement( | |
| 20170 this.yieldKeyword, this.star, Expression expression, this.semicolon) { | |
| 20171 _expression = _becomeParentOf(expression); | |
| 20172 } | |
| 20173 | |
| 20174 @override | |
| 20175 Token get beginToken { | |
| 20176 if (yieldKeyword != null) { | |
| 20177 return yieldKeyword; | |
| 20178 } | |
| 20179 return _expression.beginToken; | |
| 20180 } | |
| 20181 | |
| 20182 @override | |
| 20183 Iterable get childEntities => new ChildEntities() | |
| 20184 ..add(yieldKeyword) | |
| 20185 ..add(star) | |
| 20186 ..add(_expression) | |
| 20187 ..add(semicolon); | |
| 20188 | |
| 20189 @override | |
| 20190 Token get endToken { | |
| 20191 if (semicolon != null) { | |
| 20192 return semicolon; | |
| 20193 } | |
| 20194 return _expression.endToken; | |
| 20195 } | |
| 20196 | |
| 20197 /** | |
| 20198 * Return the expression whose value will be yielded. | |
| 20199 */ | |
| 20200 Expression get expression => _expression; | |
| 20201 | |
| 20202 /** | |
| 20203 * Set the expression whose value will be yielded to the given [expression]. | |
| 20204 */ | |
| 20205 void set expression(Expression expression) { | |
| 20206 _expression = _becomeParentOf(expression); | |
| 20207 } | |
| 20208 | |
| 20209 @override | |
| 20210 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); | |
| 20211 | |
| 20212 @override | |
| 20213 void visitChildren(AstVisitor visitor) { | |
| 20214 _safelyVisitChild(_expression, visitor); | |
| 20215 } | |
| 20216 } | |
| OLD | NEW |