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 import 'java_core.dart'; |
| 12 import 'java_engine.dart'; |
| 13 import 'source.dart' show LineInfo, Source; |
| 14 import 'scanner.dart'; |
| 15 import 'engine.dart' show AnalysisEngine; |
| 16 import 'utilities_dart.dart'; |
| 17 import 'utilities_collection.dart' show TokenMap; |
| 18 import 'element.dart'; |
| 19 import 'constant.dart'; |
| 20 import 'parser.dart'; |
| 21 |
| 22 /** |
| 23 * Instances of the class `AdjacentStrings` represents two or more string litera
ls that are |
| 24 * implicitly concatenated because of being adjacent (separated only by whitespa
ce). |
| 25 * |
| 26 * While the grammar only allows adjacent strings when all of the strings are of
the same kind |
| 27 * (single line or multi-line), this class doesn't enforce that restriction. |
| 28 * |
| 29 * <pre> |
| 30 * adjacentStrings ::= |
| 31 * [StringLiteral] [StringLiteral]+ |
| 32 * </pre> |
| 33 */ |
| 34 class AdjacentStrings extends StringLiteral { |
| 35 /** |
| 36 * The strings that are implicitly concatenated. |
| 37 */ |
| 38 NodeList<StringLiteral> _strings; |
| 39 |
| 40 /** |
| 41 * Initialize a newly created list of adjacent strings. |
| 42 * |
| 43 * @param strings the strings that are implicitly concatenated |
| 44 */ |
| 45 AdjacentStrings(List<StringLiteral> strings) { |
| 46 this._strings = new NodeList<StringLiteral>(this); |
| 47 this._strings.addAll(strings); |
| 48 } |
| 49 |
| 50 @override |
| 51 accept(AstVisitor visitor) => visitor.visitAdjacentStrings(this); |
| 52 |
| 53 @override |
| 54 Token get beginToken => _strings.beginToken; |
| 55 |
| 56 @override |
| 57 Token get endToken => _strings.endToken; |
| 58 |
| 59 /** |
| 60 * Return the strings that are implicitly concatenated. |
| 61 * |
| 62 * @return the strings that are implicitly concatenated |
| 63 */ |
| 64 NodeList<StringLiteral> get strings => _strings; |
| 65 |
| 66 @override |
| 67 void visitChildren(AstVisitor visitor) { |
| 68 _strings.accept(visitor); |
| 69 } |
| 70 |
| 71 @override |
| 72 void appendStringValue(JavaStringBuilder builder) { |
| 73 for (StringLiteral stringLiteral in strings) { |
| 74 stringLiteral.appendStringValue(builder); |
| 75 } |
| 76 } |
| 77 } |
| 78 |
| 79 /** |
| 80 * The abstract class `AnnotatedNode` defines the behavior of nodes that can be
annotated with |
| 81 * both a comment and metadata. |
| 82 */ |
| 83 abstract class AnnotatedNode extends AstNode { |
| 84 /** |
| 85 * The documentation comment associated with this node, or `null` if this node
does not have |
| 86 * a documentation comment associated with it. |
| 87 */ |
| 88 Comment _comment; |
| 89 |
| 90 /** |
| 91 * The annotations associated with this node. |
| 92 */ |
| 93 NodeList<Annotation> _metadata; |
| 94 |
| 95 /** |
| 96 * Initialize a newly created node. |
| 97 * |
| 98 * @param comment the documentation comment associated with this node |
| 99 * @param metadata the annotations associated with this node |
| 100 */ |
| 101 AnnotatedNode(Comment comment, List<Annotation> metadata) { |
| 102 this._metadata = new NodeList<Annotation>(this); |
| 103 this._comment = becomeParentOf(comment); |
| 104 this._metadata.addAll(metadata); |
| 105 } |
| 106 |
| 107 @override |
| 108 Token get beginToken { |
| 109 if (_comment == null) { |
| 110 if (_metadata.isEmpty) { |
| 111 return firstTokenAfterCommentAndMetadata; |
| 112 } else { |
| 113 return _metadata.beginToken; |
| 114 } |
| 115 } else if (_metadata.isEmpty) { |
| 116 return _comment.beginToken; |
| 117 } |
| 118 Token commentToken = _comment.beginToken; |
| 119 Token metadataToken = _metadata.beginToken; |
| 120 if (commentToken.offset < metadataToken.offset) { |
| 121 return commentToken; |
| 122 } |
| 123 return metadataToken; |
| 124 } |
| 125 |
| 126 /** |
| 127 * Return the documentation comment associated with this node, or `null` if th
is node does |
| 128 * not have a documentation comment associated with it. |
| 129 * |
| 130 * @return the documentation comment associated with this node |
| 131 */ |
| 132 Comment get documentationComment => _comment; |
| 133 |
| 134 /** |
| 135 * Return the annotations associated with this node. |
| 136 * |
| 137 * @return the annotations associated with this node |
| 138 */ |
| 139 NodeList<Annotation> get metadata => _metadata; |
| 140 |
| 141 /** |
| 142 * Set the documentation comment associated with this node to the given commen
t. |
| 143 * |
| 144 * @param comment the documentation comment to be associated with this node |
| 145 */ |
| 146 void set documentationComment(Comment comment) { |
| 147 this._comment = becomeParentOf(comment); |
| 148 } |
| 149 |
| 150 /** |
| 151 * Set the metadata associated with this node to the given metadata. |
| 152 * |
| 153 * @param metadata the metadata to be associated with this node |
| 154 */ |
| 155 void set metadata(List<Annotation> metadata) { |
| 156 this._metadata.clear(); |
| 157 this._metadata.addAll(metadata); |
| 158 } |
| 159 |
| 160 @override |
| 161 void visitChildren(AstVisitor visitor) { |
| 162 if (_commentIsBeforeAnnotations()) { |
| 163 safelyVisitChild(_comment, visitor); |
| 164 _metadata.accept(visitor); |
| 165 } else { |
| 166 for (AstNode child in sortedCommentAndAnnotations) { |
| 167 child.accept(visitor); |
| 168 } |
| 169 } |
| 170 } |
| 171 |
| 172 /** |
| 173 * Return the first token following the comment and metadata. |
| 174 * |
| 175 * @return the first token following the comment and metadata |
| 176 */ |
| 177 Token get firstTokenAfterCommentAndMetadata; |
| 178 |
| 179 /** |
| 180 * Return `true` if the comment is lexically before any annotations. |
| 181 * |
| 182 * @return `true` if the comment is lexically before any annotations |
| 183 */ |
| 184 bool _commentIsBeforeAnnotations() { |
| 185 if (_comment == null || _metadata.isEmpty) { |
| 186 return true; |
| 187 } |
| 188 Annotation firstAnnotation = _metadata[0]; |
| 189 return _comment.offset < firstAnnotation.offset; |
| 190 } |
| 191 |
| 192 /** |
| 193 * Return an array containing the comment and annotations associated with this
node, sorted in |
| 194 * lexical order. |
| 195 * |
| 196 * @return the comment and annotations associated with this node in the order
in which they |
| 197 * appeared in the original source |
| 198 */ |
| 199 List<AstNode> get sortedCommentAndAnnotations { |
| 200 List<AstNode> childList = new List<AstNode>(); |
| 201 childList.add(_comment); |
| 202 childList.addAll(_metadata); |
| 203 List<AstNode> children = new List.from(childList); |
| 204 children.sort(AstNode.LEXICAL_ORDER); |
| 205 return children; |
| 206 } |
| 207 } |
| 208 |
| 209 /** |
| 210 * Instances of the class `Annotation` represent an annotation that can be assoc
iated with an |
| 211 * AST node. |
| 212 * |
| 213 * <pre> |
| 214 * metadata ::= |
| 215 * annotation* |
| 216 * |
| 217 * annotation ::= |
| 218 * '@' [Identifier] ('.' [SimpleIdentifier])? [ArgumentList]? |
| 219 * </pre> |
| 220 */ |
| 221 class Annotation extends AstNode { |
| 222 /** |
| 223 * The at sign that introduced the annotation. |
| 224 */ |
| 225 Token atSign; |
| 226 |
| 227 /** |
| 228 * The name of the class defining the constructor that is being invoked or the
name of the field |
| 229 * that is being referenced. |
| 230 */ |
| 231 Identifier _name; |
| 232 |
| 233 /** |
| 234 * The period before the constructor name, or `null` if this annotation is not
the |
| 235 * invocation of a named constructor. |
| 236 */ |
| 237 Token period; |
| 238 |
| 239 /** |
| 240 * The name of the constructor being invoked, or `null` if this annotation is
not the |
| 241 * invocation of a named constructor. |
| 242 */ |
| 243 SimpleIdentifier _constructorName; |
| 244 |
| 245 /** |
| 246 * The arguments to the constructor being invoked, or `null` if this annotatio
n is not the |
| 247 * invocation of a constructor. |
| 248 */ |
| 249 ArgumentList _arguments; |
| 250 |
| 251 /** |
| 252 * The element associated with this annotation, or `null` if the AST structure
has not been |
| 253 * resolved or if this annotation could not be resolved. |
| 254 */ |
| 255 Element _element; |
| 256 |
| 257 /** |
| 258 * The element annotation representing this annotation in the element model. |
| 259 */ |
| 260 ElementAnnotation elementAnnotation; |
| 261 |
| 262 /** |
| 263 * Initialize a newly created annotation. |
| 264 * |
| 265 * @param atSign the at sign that introduced the annotation |
| 266 * @param name the name of the class defining the constructor that is being in
voked or the name of |
| 267 * the field that is being referenced |
| 268 * @param period the period before the constructor name, or `null` if this ann
otation is not |
| 269 * the invocation of a named constructor |
| 270 * @param constructorName the name of the constructor being invoked, or `null`
if this |
| 271 * annotation is not the invocation of a named constructor |
| 272 * @param arguments the arguments to the constructor being invoked, or `null`
if this |
| 273 * annotation is not the invocation of a constructor |
| 274 */ |
| 275 Annotation(this.atSign, Identifier name, this.period, SimpleIdentifier constru
ctorName, ArgumentList arguments) { |
| 276 this._name = becomeParentOf(name); |
| 277 this._constructorName = becomeParentOf(constructorName); |
| 278 this._arguments = becomeParentOf(arguments); |
| 279 } |
| 280 |
| 281 @override |
| 282 accept(AstVisitor visitor) => visitor.visitAnnotation(this); |
| 283 |
| 284 /** |
| 285 * Return the arguments to the constructor being invoked, or `null` if this an
notation is |
| 286 * not the invocation of a constructor. |
| 287 * |
| 288 * @return the arguments to the constructor being invoked |
| 289 */ |
| 290 ArgumentList get arguments => _arguments; |
| 291 |
| 292 @override |
| 293 Token get beginToken => atSign; |
| 294 |
| 295 /** |
| 296 * Return the name of the constructor being invoked, or `null` if this annotat
ion is not the |
| 297 * invocation of a named constructor. |
| 298 * |
| 299 * @return the name of the constructor being invoked |
| 300 */ |
| 301 SimpleIdentifier get constructorName => _constructorName; |
| 302 |
| 303 /** |
| 304 * Return the element associated with this annotation, or `null` if the AST st
ructure has |
| 305 * not been resolved or if this annotation could not be resolved. |
| 306 * |
| 307 * @return the element associated with this annotation |
| 308 */ |
| 309 Element get element { |
| 310 if (_element != null) { |
| 311 return _element; |
| 312 } |
| 313 if (_name != null) { |
| 314 return _name.staticElement; |
| 315 } |
| 316 return null; |
| 317 } |
| 318 |
| 319 @override |
| 320 Token get endToken { |
| 321 if (_arguments != null) { |
| 322 return _arguments.endToken; |
| 323 } else if (_constructorName != null) { |
| 324 return _constructorName.endToken; |
| 325 } |
| 326 return _name.endToken; |
| 327 } |
| 328 |
| 329 /** |
| 330 * Return the name of the class defining the constructor that is being invoked
or the name of the |
| 331 * field that is being referenced. |
| 332 * |
| 333 * @return the name of the constructor being invoked or the name of the field
being referenced |
| 334 */ |
| 335 Identifier get name => _name; |
| 336 |
| 337 /** |
| 338 * Set the arguments to the constructor being invoked to the given arguments. |
| 339 * |
| 340 * @param arguments the arguments to the constructor being invoked |
| 341 */ |
| 342 void set arguments(ArgumentList arguments) { |
| 343 this._arguments = becomeParentOf(arguments); |
| 344 } |
| 345 |
| 346 /** |
| 347 * Set the name of the constructor being invoked to the given name. |
| 348 * |
| 349 * @param constructorName the name of the constructor being invoked |
| 350 */ |
| 351 void set constructorName(SimpleIdentifier constructorName) { |
| 352 this._constructorName = becomeParentOf(constructorName); |
| 353 } |
| 354 |
| 355 /** |
| 356 * Set the element associated with this annotation based. |
| 357 * |
| 358 * @param element the element to be associated with this identifier |
| 359 */ |
| 360 void set element(Element element) { |
| 361 this._element = element; |
| 362 } |
| 363 |
| 364 /** |
| 365 * Set the name of the class defining the constructor that is being invoked or
the name of the |
| 366 * field that is being referenced to the given name. |
| 367 * |
| 368 * @param name the name of the constructor being invoked or the name of the fi
eld being referenced |
| 369 */ |
| 370 void set name(Identifier name) { |
| 371 this._name = becomeParentOf(name); |
| 372 } |
| 373 |
| 374 @override |
| 375 void visitChildren(AstVisitor visitor) { |
| 376 safelyVisitChild(_name, visitor); |
| 377 safelyVisitChild(_constructorName, visitor); |
| 378 safelyVisitChild(_arguments, visitor); |
| 379 } |
| 380 } |
| 381 |
| 382 /** |
| 383 * Instances of the class `ArgumentList` represent a list of arguments in the in
vocation of a |
| 384 * executable element: a function, method, or constructor. |
| 385 * |
| 386 * <pre> |
| 387 * argumentList ::= |
| 388 * '(' arguments? ')' |
| 389 * |
| 390 * arguments ::= |
| 391 * [NamedExpression] (',' [NamedExpression])* |
| 392 * | [Expression] (',' [NamedExpression])* |
| 393 * </pre> |
| 394 */ |
| 395 class ArgumentList extends AstNode { |
| 396 /** |
| 397 * The left parenthesis. |
| 398 */ |
| 399 Token _leftParenthesis; |
| 400 |
| 401 /** |
| 402 * The expressions producing the values of the arguments. |
| 403 */ |
| 404 NodeList<Expression> _arguments; |
| 405 |
| 406 /** |
| 407 * The right parenthesis. |
| 408 */ |
| 409 Token _rightParenthesis; |
| 410 |
| 411 /** |
| 412 * An array containing the elements representing the parameters corresponding
to each of the |
| 413 * arguments in this list, or `null` if the AST has not been resolved or if th
e function or |
| 414 * method being invoked could not be determined based on static type informati
on. The array must |
| 415 * be the same length as the number of arguments, but can contain `null` entri
es if a given |
| 416 * argument does not correspond to a formal parameter. |
| 417 */ |
| 418 List<ParameterElement> _correspondingStaticParameters; |
| 419 |
| 420 /** |
| 421 * An array containing the elements representing the parameters corresponding
to each of the |
| 422 * arguments in this list, or `null` if the AST has not been resolved or if th
e function or |
| 423 * method being invoked could not be determined based on propagated type infor
mation. The array |
| 424 * must be the same length as the number of arguments, but can contain `null`
entries if a |
| 425 * given argument does not correspond to a formal parameter. |
| 426 */ |
| 427 List<ParameterElement> _correspondingPropagatedParameters; |
| 428 |
| 429 /** |
| 430 * Initialize a newly created list of arguments. |
| 431 * |
| 432 * @param leftParenthesis the left parenthesis |
| 433 * @param arguments the expressions producing the values of the arguments |
| 434 * @param rightParenthesis the right parenthesis |
| 435 */ |
| 436 ArgumentList(Token leftParenthesis, List<Expression> arguments, Token rightPar
enthesis) { |
| 437 this._arguments = new NodeList<Expression>(this); |
| 438 this._leftParenthesis = leftParenthesis; |
| 439 this._arguments.addAll(arguments); |
| 440 this._rightParenthesis = rightParenthesis; |
| 441 } |
| 442 |
| 443 @override |
| 444 accept(AstVisitor visitor) => visitor.visitArgumentList(this); |
| 445 |
| 446 /** |
| 447 * Return the expressions producing the values of the arguments. Although the
language requires |
| 448 * that positional arguments appear before named arguments, this class allows
them to be |
| 449 * intermixed. |
| 450 * |
| 451 * @return the expressions producing the values of the arguments |
| 452 */ |
| 453 NodeList<Expression> get arguments => _arguments; |
| 454 |
| 455 @override |
| 456 Token get beginToken => _leftParenthesis; |
| 457 |
| 458 @override |
| 459 Token get endToken => _rightParenthesis; |
| 460 |
| 461 /** |
| 462 * Return the left parenthesis. |
| 463 * |
| 464 * @return the left parenthesis |
| 465 */ |
| 466 Token get leftParenthesis => _leftParenthesis; |
| 467 |
| 468 /** |
| 469 * Return the right parenthesis. |
| 470 * |
| 471 * @return the right parenthesis |
| 472 */ |
| 473 Token get rightParenthesis => _rightParenthesis; |
| 474 |
| 475 /** |
| 476 * Set the parameter elements corresponding to each of the arguments in this l
ist to the given |
| 477 * array of parameters. The array of parameters must be the same length as the
number of |
| 478 * arguments, but can contain `null` entries if a given argument does not corr
espond to a |
| 479 * formal parameter. |
| 480 * |
| 481 * @param parameters the parameter elements corresponding to the arguments |
| 482 */ |
| 483 void set correspondingPropagatedParameters(List<ParameterElement> parameters)
{ |
| 484 if (parameters.length != _arguments.length) { |
| 485 throw new IllegalArgumentException("Expected ${_arguments.length} paramete
rs, not ${parameters.length}"); |
| 486 } |
| 487 _correspondingPropagatedParameters = parameters; |
| 488 } |
| 489 |
| 490 /** |
| 491 * Set the parameter elements corresponding to each of the arguments in this l
ist to the given |
| 492 * array of parameters. The array of parameters must be the same length as the
number of |
| 493 * arguments, but can contain `null` entries if a given argument does not corr
espond to a |
| 494 * formal parameter. |
| 495 * |
| 496 * @param parameters the parameter elements corresponding to the arguments |
| 497 */ |
| 498 void set correspondingStaticParameters(List<ParameterElement> parameters) { |
| 499 if (parameters.length != _arguments.length) { |
| 500 throw new IllegalArgumentException("Expected ${_arguments.length} paramete
rs, not ${parameters.length}"); |
| 501 } |
| 502 _correspondingStaticParameters = parameters; |
| 503 } |
| 504 |
| 505 /** |
| 506 * Set the left parenthesis to the given token. |
| 507 * |
| 508 * @param parenthesis the left parenthesis |
| 509 */ |
| 510 void set leftParenthesis(Token parenthesis) { |
| 511 _leftParenthesis = parenthesis; |
| 512 } |
| 513 |
| 514 /** |
| 515 * Set the right parenthesis to the given token. |
| 516 * |
| 517 * @param parenthesis the right parenthesis |
| 518 */ |
| 519 void set rightParenthesis(Token parenthesis) { |
| 520 _rightParenthesis = parenthesis; |
| 521 } |
| 522 |
| 523 @override |
| 524 void visitChildren(AstVisitor visitor) { |
| 525 _arguments.accept(visitor); |
| 526 } |
| 527 |
| 528 /** |
| 529 * If the given expression is a child of this list, and the AST structure has
been resolved, and |
| 530 * the function being invoked is known based on propagated type information, a
nd the expression |
| 531 * corresponds to one of the parameters of the function being invoked, then re
turn the parameter |
| 532 * element representing the parameter to which the value of the given expressi
on will be bound. |
| 533 * Otherwise, return `null`. |
| 534 * |
| 535 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 536 * |
| 537 * @param expression the expression corresponding to the parameter to be retur
ned |
| 538 * @return the parameter element representing the parameter to which the value
of the expression |
| 539 * will be bound |
| 540 */ |
| 541 ParameterElement getPropagatedParameterElementFor(Expression expression) { |
| 542 if (_correspondingPropagatedParameters == null) { |
| 543 // Either the AST structure has not been resolved or the invocation of whi
ch this list is a |
| 544 // part could not be resolved. |
| 545 return null; |
| 546 } |
| 547 int index = _arguments.indexOf(expression); |
| 548 if (index < 0) { |
| 549 // The expression isn't a child of this node. |
| 550 return null; |
| 551 } |
| 552 return _correspondingPropagatedParameters[index]; |
| 553 } |
| 554 |
| 555 /** |
| 556 * If the given expression is a child of this list, and the AST structure has
been resolved, and |
| 557 * the function being invoked is known based on static type information, and t
he expression |
| 558 * corresponds to one of the parameters of the function being invoked, then re
turn the parameter |
| 559 * element representing the parameter to which the value of the given expressi
on will be bound. |
| 560 * Otherwise, return `null`. |
| 561 * |
| 562 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 563 * |
| 564 * @param expression the expression corresponding to the parameter to be retur
ned |
| 565 * @return the parameter element representing the parameter to which the value
of the expression |
| 566 * will be bound |
| 567 */ |
| 568 ParameterElement getStaticParameterElementFor(Expression expression) { |
| 569 if (_correspondingStaticParameters == null) { |
| 570 // Either the AST structure has not been resolved or the invocation of whi
ch this list is a |
| 571 // part could not be resolved. |
| 572 return null; |
| 573 } |
| 574 int index = _arguments.indexOf(expression); |
| 575 if (index < 0) { |
| 576 // The expression isn't a child of this node. |
| 577 return null; |
| 578 } |
| 579 return _correspondingStaticParameters[index]; |
| 580 } |
| 581 } |
| 582 |
| 583 /** |
| 584 * Instances of the class `AsExpression` represent an 'as' expression. |
| 585 * |
| 586 * <pre> |
| 587 * asExpression ::= |
| 588 * [Expression] 'as' [TypeName] |
| 589 * </pre> |
| 590 */ |
| 591 class AsExpression extends Expression { |
| 592 /** |
| 593 * The expression used to compute the value being cast. |
| 594 */ |
| 595 Expression _expression; |
| 596 |
| 597 /** |
| 598 * The as operator. |
| 599 */ |
| 600 Token asOperator; |
| 601 |
| 602 /** |
| 603 * The name of the type being cast to. |
| 604 */ |
| 605 TypeName _type; |
| 606 |
| 607 /** |
| 608 * Initialize a newly created as expression. |
| 609 * |
| 610 * @param expression the expression used to compute the value being cast |
| 611 * @param isOperator the is operator |
| 612 * @param type the name of the type being cast to |
| 613 */ |
| 614 AsExpression(Expression expression, Token isOperator, TypeName type) { |
| 615 this._expression = becomeParentOf(expression); |
| 616 this.asOperator = isOperator; |
| 617 this._type = becomeParentOf(type); |
| 618 } |
| 619 |
| 620 @override |
| 621 accept(AstVisitor visitor) => visitor.visitAsExpression(this); |
| 622 |
| 623 @override |
| 624 Token get beginToken => _expression.beginToken; |
| 625 |
| 626 @override |
| 627 Token get endToken => _type.endToken; |
| 628 |
| 629 /** |
| 630 * Return the expression used to compute the value being cast. |
| 631 * |
| 632 * @return the expression used to compute the value being cast |
| 633 */ |
| 634 Expression get expression => _expression; |
| 635 |
| 636 @override |
| 637 int get precedence => 7; |
| 638 |
| 639 /** |
| 640 * Return the name of the type being cast to. |
| 641 * |
| 642 * @return the name of the type being cast to |
| 643 */ |
| 644 TypeName get type => _type; |
| 645 |
| 646 /** |
| 647 * Set the expression used to compute the value being cast to the given expres
sion. |
| 648 * |
| 649 * @param expression the expression used to compute the value being cast |
| 650 */ |
| 651 void set expression(Expression expression) { |
| 652 this._expression = becomeParentOf(expression); |
| 653 } |
| 654 |
| 655 /** |
| 656 * Set the name of the type being cast to to the given name. |
| 657 * |
| 658 * @param name the name of the type being cast to |
| 659 */ |
| 660 void set type(TypeName name) { |
| 661 this._type = becomeParentOf(name); |
| 662 } |
| 663 |
| 664 @override |
| 665 void visitChildren(AstVisitor visitor) { |
| 666 safelyVisitChild(_expression, visitor); |
| 667 safelyVisitChild(_type, visitor); |
| 668 } |
| 669 } |
| 670 |
| 671 /** |
| 672 * Instances of the class `AssertStatement` represent an assert statement. |
| 673 * |
| 674 * <pre> |
| 675 * assertStatement ::= |
| 676 * 'assert' '(' [Expression] ')' ';' |
| 677 * </pre> |
| 678 */ |
| 679 class AssertStatement extends Statement { |
| 680 /** |
| 681 * The token representing the 'assert' keyword. |
| 682 */ |
| 683 Token keyword; |
| 684 |
| 685 /** |
| 686 * The left parenthesis. |
| 687 */ |
| 688 Token leftParenthesis; |
| 689 |
| 690 /** |
| 691 * The condition that is being asserted to be `true`. |
| 692 */ |
| 693 Expression _condition; |
| 694 |
| 695 /** |
| 696 * The right parenthesis. |
| 697 */ |
| 698 Token rightParenthesis; |
| 699 |
| 700 /** |
| 701 * The semicolon terminating the statement. |
| 702 */ |
| 703 Token semicolon; |
| 704 |
| 705 /** |
| 706 * Initialize a newly created assert statement. |
| 707 * |
| 708 * @param keyword the token representing the 'assert' keyword |
| 709 * @param leftParenthesis the left parenthesis |
| 710 * @param condition the condition that is being asserted to be `true` |
| 711 * @param rightParenthesis the right parenthesis |
| 712 * @param semicolon the semicolon terminating the statement |
| 713 */ |
| 714 AssertStatement(this.keyword, this.leftParenthesis, Expression condition, this
.rightParenthesis, this.semicolon) { |
| 715 this._condition = becomeParentOf(condition); |
| 716 } |
| 717 |
| 718 @override |
| 719 accept(AstVisitor visitor) => visitor.visitAssertStatement(this); |
| 720 |
| 721 @override |
| 722 Token get beginToken => keyword; |
| 723 |
| 724 /** |
| 725 * Return the condition that is being asserted to be `true`. |
| 726 * |
| 727 * @return the condition that is being asserted to be `true` |
| 728 */ |
| 729 Expression get condition => _condition; |
| 730 |
| 731 @override |
| 732 Token get endToken => semicolon; |
| 733 |
| 734 /** |
| 735 * Set the condition that is being asserted to be `true` to the given expressi
on. |
| 736 * |
| 737 * @param the condition that is being asserted to be `true` |
| 738 */ |
| 739 void set condition(Expression condition) { |
| 740 this._condition = becomeParentOf(condition); |
| 741 } |
| 742 |
| 743 @override |
| 744 void visitChildren(AstVisitor visitor) { |
| 745 safelyVisitChild(_condition, visitor); |
| 746 } |
| 747 } |
| 748 |
| 749 /** |
| 750 * Instances of the class `AssignmentExpression` represent an assignment express
ion. |
| 751 * |
| 752 * <pre> |
| 753 * assignmentExpression ::= |
| 754 * [Expression] [Token] [Expression] |
| 755 * </pre> |
| 756 */ |
| 757 class AssignmentExpression extends Expression { |
| 758 /** |
| 759 * The expression used to compute the left hand side. |
| 760 */ |
| 761 Expression _leftHandSide; |
| 762 |
| 763 /** |
| 764 * The assignment operator being applied. |
| 765 */ |
| 766 Token operator; |
| 767 |
| 768 /** |
| 769 * The expression used to compute the right hand side. |
| 770 */ |
| 771 Expression _rightHandSide; |
| 772 |
| 773 /** |
| 774 * The element associated with the operator based on the static type of the le
ft-hand-side, or |
| 775 * `null` if the AST structure has not been resolved, if the operator is not a
compound |
| 776 * operator, or if the operator could not be resolved. |
| 777 */ |
| 778 MethodElement _staticElement; |
| 779 |
| 780 /** |
| 781 * The element associated with the operator based on the propagated type of th
e left-hand-side, or |
| 782 * `null` if the AST structure has not been resolved, if the operator is not a
compound |
| 783 * operator, or if the operator could not be resolved. |
| 784 */ |
| 785 MethodElement _propagatedElement; |
| 786 |
| 787 /** |
| 788 * Initialize a newly created assignment expression. |
| 789 * |
| 790 * @param leftHandSide the expression used to compute the left hand side |
| 791 * @param operator the assignment operator being applied |
| 792 * @param rightHandSide the expression used to compute the right hand side |
| 793 */ |
| 794 AssignmentExpression(Expression leftHandSide, this.operator, Expression rightH
andSide) { |
| 795 if (leftHandSide == null || rightHandSide == null) { |
| 796 String message; |
| 797 if (leftHandSide == null) { |
| 798 if (rightHandSide == null) { |
| 799 message = "Both the left-hand and right-hand sides are null"; |
| 800 } else { |
| 801 message = "The left-hand size is null"; |
| 802 } |
| 803 } else { |
| 804 message = "The right-hand size is null"; |
| 805 } |
| 806 AnalysisEngine.instance.logger.logError2(message, new JavaException(messag
e)); |
| 807 } |
| 808 this._leftHandSide = becomeParentOf(leftHandSide); |
| 809 this._rightHandSide = becomeParentOf(rightHandSide); |
| 810 } |
| 811 |
| 812 @override |
| 813 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this); |
| 814 |
| 815 @override |
| 816 Token get beginToken => _leftHandSide.beginToken; |
| 817 |
| 818 /** |
| 819 * Return the best element available for this operator. If resolution was able
to find a better |
| 820 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 821 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 822 * then `null` will be returned. |
| 823 * |
| 824 * @return the best element available for this operator |
| 825 */ |
| 826 MethodElement get bestElement { |
| 827 MethodElement element = propagatedElement; |
| 828 if (element == null) { |
| 829 element = staticElement; |
| 830 } |
| 831 return element; |
| 832 } |
| 833 |
| 834 @override |
| 835 Token get endToken => _rightHandSide.endToken; |
| 836 |
| 837 /** |
| 838 * Set the expression used to compute the left hand side to the given expressi
on. |
| 839 * |
| 840 * @return the expression used to compute the left hand side |
| 841 */ |
| 842 Expression get leftHandSide => _leftHandSide; |
| 843 |
| 844 @override |
| 845 int get precedence => 1; |
| 846 |
| 847 /** |
| 848 * Return the element associated with the operator based on the propagated typ
e of the |
| 849 * left-hand-side, or `null` if the AST structure has not been resolved, if th
e operator is |
| 850 * not a compound operator, or if the operator could not be resolved. One exam
ple of the latter |
| 851 * case is an operator that is not defined for the type of the left-hand opera
nd. |
| 852 * |
| 853 * @return the element associated with the operator |
| 854 */ |
| 855 MethodElement get propagatedElement => _propagatedElement; |
| 856 |
| 857 /** |
| 858 * Return the expression used to compute the right hand side. |
| 859 * |
| 860 * @return the expression used to compute the right hand side |
| 861 */ |
| 862 Expression get rightHandSide => _rightHandSide; |
| 863 |
| 864 /** |
| 865 * Return the element associated with the operator based on the static type of
the left-hand-side, |
| 866 * or `null` if the AST structure has not been resolved, if the operator is no
t a compound |
| 867 * operator, or if the operator could not be resolved. One example of the latt
er case is an |
| 868 * operator that is not defined for the type of the left-hand operand. |
| 869 * |
| 870 * @return the element associated with the operator |
| 871 */ |
| 872 MethodElement get staticElement => _staticElement; |
| 873 |
| 874 /** |
| 875 * Return the expression used to compute the left hand side. |
| 876 * |
| 877 * @param expression the expression used to compute the left hand side |
| 878 */ |
| 879 void set leftHandSide(Expression expression) { |
| 880 _leftHandSide = becomeParentOf(expression); |
| 881 } |
| 882 |
| 883 /** |
| 884 * Set the element associated with the operator based on the propagated type o
f the left-hand-side |
| 885 * to the given element. |
| 886 * |
| 887 * @param element the element to be associated with the operator |
| 888 */ |
| 889 void set propagatedElement(MethodElement element) { |
| 890 _propagatedElement = element; |
| 891 } |
| 892 |
| 893 /** |
| 894 * Set the expression used to compute the left hand side to the given expressi
on. |
| 895 * |
| 896 * @param expression the expression used to compute the left hand side |
| 897 */ |
| 898 void set rightHandSide(Expression expression) { |
| 899 _rightHandSide = becomeParentOf(expression); |
| 900 } |
| 901 |
| 902 /** |
| 903 * Set the element associated with the operator based on the static type of th
e left-hand-side to |
| 904 * the given element. |
| 905 * |
| 906 * @param element the static element to be associated with the operator |
| 907 */ |
| 908 void set staticElement(MethodElement element) { |
| 909 _staticElement = element; |
| 910 } |
| 911 |
| 912 @override |
| 913 void visitChildren(AstVisitor visitor) { |
| 914 safelyVisitChild(_leftHandSide, visitor); |
| 915 safelyVisitChild(_rightHandSide, visitor); |
| 916 } |
| 917 |
| 918 /** |
| 919 * If the AST structure has been resolved, and the function being invoked is k
nown based on |
| 920 * propagated type information, then return the parameter element representing
the parameter to |
| 921 * which the value of the right operand will be bound. Otherwise, return `null
`. |
| 922 * |
| 923 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 924 * |
| 925 * @return the parameter element representing the parameter to which the value
of the right |
| 926 * operand will be bound |
| 927 */ |
| 928 ParameterElement get propagatedParameterElementForRightHandSide { |
| 929 if (_propagatedElement == null) { |
| 930 return null; |
| 931 } |
| 932 List<ParameterElement> parameters = _propagatedElement.parameters; |
| 933 if (parameters.length < 1) { |
| 934 return null; |
| 935 } |
| 936 return parameters[0]; |
| 937 } |
| 938 |
| 939 /** |
| 940 * If the AST structure has been resolved, and the function being invoked is k
nown based on static |
| 941 * type information, then return the parameter element representing the parame
ter to which the |
| 942 * value of the right operand will be bound. Otherwise, return `null`. |
| 943 * |
| 944 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 945 * |
| 946 * @return the parameter element representing the parameter to which the value
of the right |
| 947 * operand will be bound |
| 948 */ |
| 949 ParameterElement get staticParameterElementForRightHandSide { |
| 950 if (_staticElement == null) { |
| 951 return null; |
| 952 } |
| 953 List<ParameterElement> parameters = _staticElement.parameters; |
| 954 if (parameters.length < 1) { |
| 955 return null; |
| 956 } |
| 957 return parameters[0]; |
| 958 } |
| 959 } |
| 960 |
| 961 /** |
| 962 * Instances of the class `AstCloner` implement an object that will clone any AS
T structure |
| 963 * that it visits. The cloner will only clone the structure, it will not preserv
e any resolution |
| 964 * results or properties associated with the nodes. |
| 965 */ |
| 966 class AstCloner implements AstVisitor<AstNode> { |
| 967 List cloneNodeList(NodeList nodes) { |
| 968 int count = nodes.length; |
| 969 List clonedNodes = new List(); |
| 970 for (int i = 0; i < count; i++) { |
| 971 clonedNodes.add((nodes[i]).accept(this) as AstNode); |
| 972 } |
| 973 return clonedNodes; |
| 974 } |
| 975 |
| 976 @override |
| 977 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) => new AdjacentStri
ngs(cloneNodeList(node.strings)); |
| 978 |
| 979 @override |
| 980 Annotation visitAnnotation(Annotation node) => new Annotation(node.atSign, clo
neNode(node.name), node.period, cloneNode(node.constructorName), cloneNode(node.
arguments)); |
| 981 |
| 982 @override |
| 983 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(node.lef
tParenthesis, cloneNodeList(node.arguments), node.rightParenthesis); |
| 984 |
| 985 @override |
| 986 AsExpression visitAsExpression(AsExpression node) => new AsExpression(cloneNod
e(node.expression), node.asOperator, cloneNode(node.type)); |
| 987 |
| 988 @override |
| 989 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(node
.keyword, node.leftParenthesis, cloneNode(node.condition), node.rightParenthesis
, node.semicolon); |
| 990 |
| 991 @override |
| 992 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) => n
ew AssignmentExpression(cloneNode(node.leftHandSide), node.operator, cloneNode(n
ode.rightHandSide)); |
| 993 |
| 994 @override |
| 995 AwaitExpression visitAwaitExpression(AwaitExpression node) => new AwaitExpress
ion(node.awaitKeyword, node.expression); |
| 996 |
| 997 @override |
| 998 BinaryExpression visitBinaryExpression(BinaryExpression node) => new BinaryExp
ression(cloneNode(node.leftOperand), node.operator, cloneNode(node.rightOperand)
); |
| 999 |
| 1000 @override |
| 1001 Block visitBlock(Block node) => new Block(node.leftBracket, cloneNodeList(node
.statements), node.rightBracket); |
| 1002 |
| 1003 @override |
| 1004 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) => new BlockF
unctionBody(node.keyword, node.star, cloneNode(node.block)); |
| 1005 |
| 1006 @override |
| 1007 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) => new BooleanLiteral(
node.literal, node.value); |
| 1008 |
| 1009 @override |
| 1010 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
node.keyword, cloneNode(node.label), node.semicolon); |
| 1011 |
| 1012 @override |
| 1013 CascadeExpression visitCascadeExpression(CascadeExpression node) => new Cascad
eExpression(cloneNode(node.target), cloneNodeList(node.cascadeSections)); |
| 1014 |
| 1015 @override |
| 1016 CatchClause visitCatchClause(CatchClause node) => new CatchClause(node.onKeywo
rd, cloneNode(node.exceptionType), node.catchKeyword, node.leftParenthesis, clon
eNode(node.exceptionParameter), node.comma, cloneNode(node.stackTraceParameter),
node.rightParenthesis, cloneNode(node.body)); |
| 1017 |
| 1018 @override |
| 1019 ClassDeclaration visitClassDeclaration(ClassDeclaration node) { |
| 1020 ClassDeclaration copy = new ClassDeclaration(cloneNode(node.documentationCom
ment), cloneNodeList(node.metadata), node.abstractKeyword, node.classKeyword, cl
oneNode(node.name), cloneNode(node.typeParameters), cloneNode(node.extendsClause
), cloneNode(node.withClause), cloneNode(node.implementsClause), node.leftBracke
t, cloneNodeList(node.members), node.rightBracket); |
| 1021 copy.nativeClause = cloneNode(node.nativeClause); |
| 1022 return copy; |
| 1023 } |
| 1024 |
| 1025 @override |
| 1026 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
cloneNode(node.documentationComment), cloneNodeList(node.metadata), node.keyword
, cloneNode(node.name), cloneNode(node.typeParameters), node.equals, node.abstra
ctKeyword, cloneNode(node.superclass), cloneNode(node.withClause), cloneNode(nod
e.implementsClause), node.semicolon); |
| 1027 |
| 1028 @override |
| 1029 Comment visitComment(Comment node) { |
| 1030 if (node.isDocumentation) { |
| 1031 return Comment.createDocumentationCommentWithReferences(node.tokens, clone
NodeList(node.references)); |
| 1032 } else if (node.isBlock) { |
| 1033 return Comment.createBlockComment(node.tokens); |
| 1034 } |
| 1035 return Comment.createEndOfLineComment(node.tokens); |
| 1036 } |
| 1037 |
| 1038 @override |
| 1039 CommentReference visitCommentReference(CommentReference node) => new CommentRe
ference(node.newKeyword, cloneNode(node.identifier)); |
| 1040 |
| 1041 @override |
| 1042 CompilationUnit visitCompilationUnit(CompilationUnit node) { |
| 1043 CompilationUnit clone = new CompilationUnit(node.beginToken, cloneNode(node.
scriptTag), cloneNodeList(node.directives), cloneNodeList(node.declarations), no
de.endToken); |
| 1044 clone.lineInfo = node.lineInfo; |
| 1045 return clone; |
| 1046 } |
| 1047 |
| 1048 @override |
| 1049 ConditionalExpression visitConditionalExpression(ConditionalExpression node) =
> new ConditionalExpression(cloneNode(node.condition), node.question, cloneNode(
node.thenExpression), node.colon, cloneNode(node.elseExpression)); |
| 1050 |
| 1051 @override |
| 1052 ConstructorDeclaration visitConstructorDeclaration(ConstructorDeclaration node
) => new ConstructorDeclaration(cloneNode(node.documentationComment), cloneNodeL
ist(node.metadata), node.externalKeyword, node.constKeyword, node.factoryKeyword
, cloneNode(node.returnType), node.period, cloneNode(node.name), cloneNode(node.
parameters), node.separator, cloneNodeList(node.initializers), cloneNode(node.re
directedConstructor), cloneNode(node.body)); |
| 1053 |
| 1054 @override |
| 1055 ConstructorFieldInitializer visitConstructorFieldInitializer(ConstructorFieldI
nitializer node) => new ConstructorFieldInitializer(node.keyword, node.period, c
loneNode(node.fieldName), node.equals, cloneNode(node.expression)); |
| 1056 |
| 1057 @override |
| 1058 ConstructorName visitConstructorName(ConstructorName node) => new ConstructorN
ame(cloneNode(node.type), node.period, cloneNode(node.name)); |
| 1059 |
| 1060 @override |
| 1061 ContinueStatement visitContinueStatement(ContinueStatement node) => new Contin
ueStatement(node.keyword, cloneNode(node.label), node.semicolon); |
| 1062 |
| 1063 @override |
| 1064 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) => new Dec
laredIdentifier(cloneNode(node.documentationComment), cloneNodeList(node.metadat
a), node.keyword, cloneNode(node.type), cloneNode(node.identifier)); |
| 1065 |
| 1066 @override |
| 1067 DefaultFormalParameter visitDefaultFormalParameter(DefaultFormalParameter node
) => new DefaultFormalParameter(cloneNode(node.parameter), node.kind, node.separ
ator, cloneNode(node.defaultValue)); |
| 1068 |
| 1069 @override |
| 1070 DoStatement visitDoStatement(DoStatement node) => new DoStatement(node.doKeywo
rd, cloneNode(node.body), node.whileKeyword, node.leftParenthesis, cloneNode(nod
e.condition), node.rightParenthesis, node.semicolon); |
| 1071 |
| 1072 @override |
| 1073 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) => new DoubleLiteral(node
.literal, node.value); |
| 1074 |
| 1075 @override |
| 1076 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) => new EmptyF
unctionBody(node.semicolon); |
| 1077 |
| 1078 @override |
| 1079 EmptyStatement visitEmptyStatement(EmptyStatement node) => new EmptyStatement(
node.semicolon); |
| 1080 |
| 1081 @override |
| 1082 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) => new Enum
ConstantDeclaration(cloneNode(node.documentationComment), cloneNodeList(node.met
adata), cloneNode(node.name)); |
| 1083 |
| 1084 @override |
| 1085 EnumDeclaration visitEnumDeclaration(EnumDeclaration node) => new EnumDeclarat
ion(cloneNode(node.documentationComment), cloneNodeList(node.metadata), node.key
word, cloneNode(node.name), node.leftBracket, cloneNodeList(node.constants), nod
e.rightBracket); |
| 1086 |
| 1087 @override |
| 1088 ExportDirective visitExportDirective(ExportDirective node) { |
| 1089 ExportDirective directive = new ExportDirective(cloneNode(node.documentation
Comment), cloneNodeList(node.metadata), node.keyword, cloneNode(node.uri), clone
NodeList(node.combinators), node.semicolon); |
| 1090 directive.source = node.source; |
| 1091 directive.uriContent = node.uriContent; |
| 1092 return directive; |
| 1093 } |
| 1094 |
| 1095 @override |
| 1096 ExpressionFunctionBody visitExpressionFunctionBody(ExpressionFunctionBody node
) => new ExpressionFunctionBody(node.keyword, node.functionDefinition, cloneNode
(node.expression), node.semicolon); |
| 1097 |
| 1098 @override |
| 1099 ExpressionStatement visitExpressionStatement(ExpressionStatement node) => new
ExpressionStatement(cloneNode(node.expression), node.semicolon); |
| 1100 |
| 1101 @override |
| 1102 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(node
.keyword, cloneNode(node.superclass)); |
| 1103 |
| 1104 @override |
| 1105 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) => new FieldDecl
aration(cloneNode(node.documentationComment), cloneNodeList(node.metadata), node
.staticKeyword, cloneNode(node.fields), node.semicolon); |
| 1106 |
| 1107 @override |
| 1108 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) => n
ew FieldFormalParameter(cloneNode(node.documentationComment), cloneNodeList(node
.metadata), node.keyword, cloneNode(node.type), node.thisToken, node.period, clo
neNode(node.identifier), cloneNode(node.parameters)); |
| 1109 |
| 1110 @override |
| 1111 ForEachStatement visitForEachStatement(ForEachStatement node) { |
| 1112 DeclaredIdentifier loopVariable = node.loopVariable; |
| 1113 if (loopVariable == null) { |
| 1114 return new ForEachStatement.con2(node.awaitKeyword, node.forKeyword, node.
leftParenthesis, cloneNode(node.identifier), node.inKeyword, cloneNode(node.iter
ator), node.rightParenthesis, cloneNode(node.body)); |
| 1115 } |
| 1116 return new ForEachStatement.con1(node.awaitKeyword, node.forKeyword, node.le
ftParenthesis, cloneNode(loopVariable), node.inKeyword, cloneNode(node.iterator)
, node.rightParenthesis, cloneNode(node.body)); |
| 1117 } |
| 1118 |
| 1119 @override |
| 1120 FormalParameterList visitFormalParameterList(FormalParameterList node) => new
FormalParameterList(node.leftParenthesis, cloneNodeList(node.parameters), node.l
eftDelimiter, node.rightDelimiter, node.rightParenthesis); |
| 1121 |
| 1122 @override |
| 1123 ForStatement visitForStatement(ForStatement node) => new ForStatement(node.for
Keyword, node.leftParenthesis, cloneNode(node.variables), cloneNode(node.initial
ization), node.leftSeparator, cloneNode(node.condition), node.rightSeparator, cl
oneNodeList(node.updaters), node.rightParenthesis, cloneNode(node.body)); |
| 1124 |
| 1125 @override |
| 1126 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) => new
FunctionDeclaration(cloneNode(node.documentationComment), cloneNodeList(node.met
adata), node.externalKeyword, cloneNode(node.returnType), node.propertyKeyword,
cloneNode(node.name), cloneNode(node.functionExpression)); |
| 1127 |
| 1128 @override |
| 1129 FunctionDeclarationStatement visitFunctionDeclarationStatement(FunctionDeclara
tionStatement node) => new FunctionDeclarationStatement(cloneNode(node.functionD
eclaration)); |
| 1130 |
| 1131 @override |
| 1132 FunctionExpression visitFunctionExpression(FunctionExpression node) => new Fun
ctionExpression(cloneNode(node.parameters), cloneNode(node.body)); |
| 1133 |
| 1134 @override |
| 1135 FunctionExpressionInvocation visitFunctionExpressionInvocation(FunctionExpress
ionInvocation node) => new FunctionExpressionInvocation(cloneNode(node.function)
, cloneNode(node.argumentList)); |
| 1136 |
| 1137 @override |
| 1138 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) => new Functi
onTypeAlias(cloneNode(node.documentationComment), cloneNodeList(node.metadata),
node.keyword, cloneNode(node.returnType), cloneNode(node.name), cloneNode(node.t
ypeParameters), cloneNode(node.parameters), node.semicolon); |
| 1139 |
| 1140 @override |
| 1141 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(FunctionTypedFo
rmalParameter node) => new FunctionTypedFormalParameter(cloneNode(node.documenta
tionComment), cloneNodeList(node.metadata), cloneNode(node.returnType), cloneNod
e(node.identifier), cloneNode(node.parameters)); |
| 1142 |
| 1143 @override |
| 1144 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
node.keyword, cloneNodeList(node.hiddenNames)); |
| 1145 |
| 1146 @override |
| 1147 IfStatement visitIfStatement(IfStatement node) => new IfStatement(node.ifKeywo
rd, node.leftParenthesis, cloneNode(node.condition), node.rightParenthesis, clon
eNode(node.thenStatement), node.elseKeyword, cloneNode(node.elseStatement)); |
| 1148 |
| 1149 @override |
| 1150 ImplementsClause visitImplementsClause(ImplementsClause node) => new Implement
sClause(node.keyword, cloneNodeList(node.interfaces)); |
| 1151 |
| 1152 @override |
| 1153 ImportDirective visitImportDirective(ImportDirective node) { |
| 1154 ImportDirective directive = new ImportDirective(cloneNode(node.documentation
Comment), cloneNodeList(node.metadata), node.keyword, cloneNode(node.uri), node.
deferredToken, node.asToken, cloneNode(node.prefix), cloneNodeList(node.combinat
ors), node.semicolon); |
| 1155 directive.source = node.source; |
| 1156 directive.uriContent = node.uriContent; |
| 1157 return directive; |
| 1158 } |
| 1159 |
| 1160 @override |
| 1161 IndexExpression visitIndexExpression(IndexExpression node) { |
| 1162 Token period = node.period; |
| 1163 if (period == null) { |
| 1164 return new IndexExpression.forTarget(cloneNode(node.target), node.leftBrac
ket, cloneNode(node.index), node.rightBracket); |
| 1165 } else { |
| 1166 return new IndexExpression.forCascade(period, node.leftBracket, cloneNode(
node.index), node.rightBracket); |
| 1167 } |
| 1168 } |
| 1169 |
| 1170 @override |
| 1171 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp
ression node) => new InstanceCreationExpression(node.keyword, cloneNode(node.con
structorName), cloneNode(node.argumentList)); |
| 1172 |
| 1173 @override |
| 1174 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) => new IntegerLiteral(
node.literal, node.value); |
| 1175 |
| 1176 @override |
| 1177 InterpolationExpression visitInterpolationExpression(InterpolationExpression n
ode) => new InterpolationExpression(node.leftBracket, cloneNode(node.expression)
, node.rightBracket); |
| 1178 |
| 1179 @override |
| 1180 InterpolationString visitInterpolationString(InterpolationString node) => new
InterpolationString(node.contents, node.value); |
| 1181 |
| 1182 @override |
| 1183 IsExpression visitIsExpression(IsExpression node) => new IsExpression(cloneNod
e(node.expression), node.isOperator, node.notOperator, cloneNode(node.type)); |
| 1184 |
| 1185 @override |
| 1186 Label visitLabel(Label node) => new Label(cloneNode(node.label), node.colon); |
| 1187 |
| 1188 @override |
| 1189 LabeledStatement visitLabeledStatement(LabeledStatement node) => new LabeledSt
atement(cloneNodeList(node.labels), cloneNode(node.statement)); |
| 1190 |
| 1191 @override |
| 1192 LibraryDirective visitLibraryDirective(LibraryDirective node) => new LibraryDi
rective(cloneNode(node.documentationComment), cloneNodeList(node.metadata), node
.libraryToken, cloneNode(node.name), node.semicolon); |
| 1193 |
| 1194 @override |
| 1195 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) => new Librar
yIdentifier(cloneNodeList(node.components)); |
| 1196 |
| 1197 @override |
| 1198 ListLiteral visitListLiteral(ListLiteral node) => new ListLiteral(node.constKe
yword, cloneNode(node.typeArguments), node.leftBracket, cloneNodeList(node.eleme
nts), node.rightBracket); |
| 1199 |
| 1200 @override |
| 1201 MapLiteral visitMapLiteral(MapLiteral node) => new MapLiteral(node.constKeywor
d, cloneNode(node.typeArguments), node.leftBracket, cloneNodeList(node.entries),
node.rightBracket); |
| 1202 |
| 1203 @override |
| 1204 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) => new MapLiteralEn
try(cloneNode(node.key), node.separator, cloneNode(node.value)); |
| 1205 |
| 1206 @override |
| 1207 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) => new Method
Declaration(cloneNode(node.documentationComment), cloneNodeList(node.metadata),
node.externalKeyword, node.modifierKeyword, cloneNode(node.returnType), node.pro
pertyKeyword, node.operatorKeyword, cloneNode(node.name), cloneNode(node.paramet
ers), cloneNode(node.body)); |
| 1208 |
| 1209 @override |
| 1210 MethodInvocation visitMethodInvocation(MethodInvocation node) => new MethodInv
ocation(cloneNode(node.target), node.period, cloneNode(node.methodName), cloneNo
de(node.argumentList)); |
| 1211 |
| 1212 @override |
| 1213 NamedExpression visitNamedExpression(NamedExpression node) => new NamedExpress
ion(cloneNode(node.name), cloneNode(node.expression)); |
| 1214 |
| 1215 @override |
| 1216 AstNode visitNativeClause(NativeClause node) => new NativeClause(node.keyword,
cloneNode(node.name)); |
| 1217 |
| 1218 @override |
| 1219 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) => new Nat
iveFunctionBody(node.nativeToken, cloneNode(node.stringLiteral), node.semicolon)
; |
| 1220 |
| 1221 @override |
| 1222 NullLiteral visitNullLiteral(NullLiteral node) => new NullLiteral(node.literal
); |
| 1223 |
| 1224 @override |
| 1225 ParenthesizedExpression visitParenthesizedExpression(ParenthesizedExpression n
ode) => new ParenthesizedExpression(node.leftParenthesis, cloneNode(node.express
ion), node.rightParenthesis); |
| 1226 |
| 1227 @override |
| 1228 PartDirective visitPartDirective(PartDirective node) { |
| 1229 PartDirective directive = new PartDirective(cloneNode(node.documentationComm
ent), cloneNodeList(node.metadata), node.partToken, cloneNode(node.uri), node.se
micolon); |
| 1230 directive.source = node.source; |
| 1231 directive.uriContent = node.uriContent; |
| 1232 return directive; |
| 1233 } |
| 1234 |
| 1235 @override |
| 1236 PartOfDirective visitPartOfDirective(PartOfDirective node) => new PartOfDirect
ive(cloneNode(node.documentationComment), cloneNodeList(node.metadata), node.par
tToken, node.ofToken, cloneNode(node.libraryName), node.semicolon); |
| 1237 |
| 1238 @override |
| 1239 PostfixExpression visitPostfixExpression(PostfixExpression node) => new Postfi
xExpression(cloneNode(node.operand), node.operator); |
| 1240 |
| 1241 @override |
| 1242 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) => new Pre
fixedIdentifier(cloneNode(node.prefix), node.period, cloneNode(node.identifier))
; |
| 1243 |
| 1244 @override |
| 1245 PrefixExpression visitPrefixExpression(PrefixExpression node) => new PrefixExp
ression(node.operator, cloneNode(node.operand)); |
| 1246 |
| 1247 @override |
| 1248 PropertyAccess visitPropertyAccess(PropertyAccess node) => new PropertyAccess(
cloneNode(node.target), node.operator, cloneNode(node.propertyName)); |
| 1249 |
| 1250 @override |
| 1251 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(Redirec
tingConstructorInvocation node) => new RedirectingConstructorInvocation(node.key
word, node.period, cloneNode(node.constructorName), cloneNode(node.argumentList)
); |
| 1252 |
| 1253 @override |
| 1254 RethrowExpression visitRethrowExpression(RethrowExpression node) => new Rethro
wExpression(node.keyword); |
| 1255 |
| 1256 @override |
| 1257 ReturnStatement visitReturnStatement(ReturnStatement node) => new ReturnStatem
ent(node.keyword, cloneNode(node.expression), node.semicolon); |
| 1258 |
| 1259 @override |
| 1260 ScriptTag visitScriptTag(ScriptTag node) => new ScriptTag(node.scriptTag); |
| 1261 |
| 1262 @override |
| 1263 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
node.keyword, cloneNodeList(node.shownNames)); |
| 1264 |
| 1265 @override |
| 1266 SimpleFormalParameter visitSimpleFormalParameter(SimpleFormalParameter node) =
> new SimpleFormalParameter(cloneNode(node.documentationComment), cloneNodeList(
node.metadata), node.keyword, cloneNode(node.type), cloneNode(node.identifier)); |
| 1267 |
| 1268 @override |
| 1269 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) => new SimpleIde
ntifier(node.token); |
| 1270 |
| 1271 @override |
| 1272 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) => new
SimpleStringLiteral(node.literal, node.value); |
| 1273 |
| 1274 @override |
| 1275 StringInterpolation visitStringInterpolation(StringInterpolation node) => new
StringInterpolation(cloneNodeList(node.elements)); |
| 1276 |
| 1277 @override |
| 1278 SuperConstructorInvocation visitSuperConstructorInvocation(SuperConstructorInv
ocation node) => new SuperConstructorInvocation(node.keyword, node.period, clone
Node(node.constructorName), cloneNode(node.argumentList)); |
| 1279 |
| 1280 @override |
| 1281 SuperExpression visitSuperExpression(SuperExpression node) => new SuperExpress
ion(node.keyword); |
| 1282 |
| 1283 @override |
| 1284 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(cloneNodeList(no
de.labels), node.keyword, cloneNode(node.expression), node.colon, cloneNodeList(
node.statements)); |
| 1285 |
| 1286 @override |
| 1287 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(clon
eNodeList(node.labels), node.keyword, node.colon, cloneNodeList(node.statements)
); |
| 1288 |
| 1289 @override |
| 1290 SwitchStatement visitSwitchStatement(SwitchStatement node) => new SwitchStatem
ent(node.keyword, node.leftParenthesis, cloneNode(node.expression), node.rightPa
renthesis, node.leftBracket, cloneNodeList(node.members), node.rightBracket); |
| 1291 |
| 1292 @override |
| 1293 SymbolLiteral visitSymbolLiteral(SymbolLiteral node) => new SymbolLiteral(node
.poundSign, node.components); |
| 1294 |
| 1295 @override |
| 1296 ThisExpression visitThisExpression(ThisExpression node) => new ThisExpression(
node.keyword); |
| 1297 |
| 1298 @override |
| 1299 ThrowExpression visitThrowExpression(ThrowExpression node) => new ThrowExpress
ion(node.keyword, cloneNode(node.expression)); |
| 1300 |
| 1301 @override |
| 1302 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(TopLevelVariableD
eclaration node) => new TopLevelVariableDeclaration(cloneNode(node.documentation
Comment), cloneNodeList(node.metadata), cloneNode(node.variables), node.semicolo
n); |
| 1303 |
| 1304 @override |
| 1305 TryStatement visitTryStatement(TryStatement node) => new TryStatement(node.try
Keyword, cloneNode(node.body), cloneNodeList(node.catchClauses), node.finallyKey
word, cloneNode(node.finallyBlock)); |
| 1306 |
| 1307 @override |
| 1308 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) => new TypeArgum
entList(node.leftBracket, cloneNodeList(node.arguments), node.rightBracket); |
| 1309 |
| 1310 @override |
| 1311 TypeName visitTypeName(TypeName node) => new TypeName(cloneNode(node.name), cl
oneNode(node.typeArguments)); |
| 1312 |
| 1313 @override |
| 1314 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(clon
eNode(node.documentationComment), cloneNodeList(node.metadata), cloneNode(node.n
ame), node.keyword, cloneNode(node.bound)); |
| 1315 |
| 1316 @override |
| 1317 TypeParameterList visitTypeParameterList(TypeParameterList node) => new TypePa
rameterList(node.leftBracket, cloneNodeList(node.typeParameters), node.rightBrac
ket); |
| 1318 |
| 1319 @override |
| 1320 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) => new
VariableDeclaration(null, cloneNodeList(node.metadata), cloneNode(node.name), no
de.equals, cloneNode(node.initializer)); |
| 1321 |
| 1322 @override |
| 1323 VariableDeclarationList visitVariableDeclarationList(VariableDeclarationList n
ode) => new VariableDeclarationList(null, cloneNodeList(node.metadata), node.key
word, cloneNode(node.type), cloneNodeList(node.variables)); |
| 1324 |
| 1325 @override |
| 1326 VariableDeclarationStatement visitVariableDeclarationStatement(VariableDeclara
tionStatement node) => new VariableDeclarationStatement(cloneNode(node.variables
), node.semicolon); |
| 1327 |
| 1328 @override |
| 1329 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
node.keyword, node.leftParenthesis, cloneNode(node.condition), node.rightParenth
esis, cloneNode(node.body)); |
| 1330 |
| 1331 @override |
| 1332 WithClause visitWithClause(WithClause node) => new WithClause(node.withKeyword
, cloneNodeList(node.mixinTypes)); |
| 1333 |
| 1334 @override |
| 1335 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
node.yieldKeyword, node.star, node.expression, node.semicolon); |
| 1336 |
| 1337 AstNode cloneNode(AstNode node) { |
| 1338 if (node == null) { |
| 1339 return null; |
| 1340 } |
| 1341 return node.accept(this) as AstNode; |
| 1342 } |
| 1343 } |
| 1344 |
| 1345 /** |
| 1346 * Instances of the class `AstComparator` compare the structure of two ASTNodes
to see whether |
| 1347 * they are equal. |
| 1348 */ |
| 1349 class AstComparator implements AstVisitor<bool> { |
| 1350 /** |
| 1351 * Return `true` if the two AST nodes are equal. |
| 1352 * |
| 1353 * @param first the first node being compared |
| 1354 * @param second the second node being compared |
| 1355 * @return `true` if the two AST nodes are equal |
| 1356 */ |
| 1357 static bool equalNodes(AstNode first, AstNode second) { |
| 1358 AstComparator comparator = new AstComparator(); |
| 1359 return comparator._isEqualNodes(first, second); |
| 1360 } |
| 1361 |
| 1362 /** |
| 1363 * The AST node with which the node being visited is to be compared. This is o
nly valid at the |
| 1364 * beginning of each visit method (until [isEqualNodes] is invoked). |
| 1365 */ |
| 1366 AstNode _other; |
| 1367 |
| 1368 @override |
| 1369 bool visitAdjacentStrings(AdjacentStrings node) { |
| 1370 AdjacentStrings other = this._other as AdjacentStrings; |
| 1371 return _isEqualNodeLists(node.strings, other.strings); |
| 1372 } |
| 1373 |
| 1374 @override |
| 1375 bool visitAnnotation(Annotation node) { |
| 1376 Annotation other = this._other as Annotation; |
| 1377 return _isEqualTokens(node.atSign, other.atSign) && _isEqualNodes(node.name,
other.name) && _isEqualTokens(node.period, other.period) && _isEqualNodes(node.
constructorName, other.constructorName) && _isEqualNodes(node.arguments, other.a
rguments); |
| 1378 } |
| 1379 |
| 1380 @override |
| 1381 bool visitArgumentList(ArgumentList node) { |
| 1382 ArgumentList other = this._other as ArgumentList; |
| 1383 return _isEqualTokens(node.leftParenthesis, other.leftParenthesis) && _isEqu
alNodeLists(node.arguments, other.arguments) && _isEqualTokens(node.rightParenth
esis, other.rightParenthesis); |
| 1384 } |
| 1385 |
| 1386 @override |
| 1387 bool visitAsExpression(AsExpression node) { |
| 1388 AsExpression other = this._other as AsExpression; |
| 1389 return _isEqualNodes(node.expression, other.expression) && _isEqualTokens(no
de.asOperator, other.asOperator) && _isEqualNodes(node.type, other.type); |
| 1390 } |
| 1391 |
| 1392 @override |
| 1393 bool visitAssertStatement(AssertStatement node) { |
| 1394 AssertStatement other = this._other as AssertStatement; |
| 1395 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.le
ftParenthesis, other.leftParenthesis) && _isEqualNodes(node.condition, other.con
dition) && _isEqualTokens(node.rightParenthesis, other.rightParenthesis) && _isE
qualTokens(node.semicolon, other.semicolon); |
| 1396 } |
| 1397 |
| 1398 @override |
| 1399 bool visitAssignmentExpression(AssignmentExpression node) { |
| 1400 AssignmentExpression other = this._other as AssignmentExpression; |
| 1401 return _isEqualNodes(node.leftHandSide, other.leftHandSide) && _isEqualToken
s(node.operator, other.operator) && _isEqualNodes(node.rightHandSide, other.righ
tHandSide); |
| 1402 } |
| 1403 |
| 1404 @override |
| 1405 bool visitAwaitExpression(AwaitExpression node) { |
| 1406 AwaitExpression other = this._other as AwaitExpression; |
| 1407 return _isEqualTokens(node.awaitKeyword, other.awaitKeyword) && _isEqualNode
s(node.expression, other.expression); |
| 1408 } |
| 1409 |
| 1410 @override |
| 1411 bool visitBinaryExpression(BinaryExpression node) { |
| 1412 BinaryExpression other = this._other as BinaryExpression; |
| 1413 return _isEqualNodes(node.leftOperand, other.leftOperand) && _isEqualTokens(
node.operator, other.operator) && _isEqualNodes(node.rightOperand, other.rightOp
erand); |
| 1414 } |
| 1415 |
| 1416 @override |
| 1417 bool visitBlock(Block node) { |
| 1418 Block other = this._other as Block; |
| 1419 return _isEqualTokens(node.leftBracket, other.leftBracket) && _isEqualNodeLi
sts(node.statements, other.statements) && _isEqualTokens(node.rightBracket, othe
r.rightBracket); |
| 1420 } |
| 1421 |
| 1422 @override |
| 1423 bool visitBlockFunctionBody(BlockFunctionBody node) { |
| 1424 BlockFunctionBody other = this._other as BlockFunctionBody; |
| 1425 return _isEqualNodes(node.block, other.block); |
| 1426 } |
| 1427 |
| 1428 @override |
| 1429 bool visitBooleanLiteral(BooleanLiteral node) { |
| 1430 BooleanLiteral other = this._other as BooleanLiteral; |
| 1431 return _isEqualTokens(node.literal, other.literal) && node.value == other.va
lue; |
| 1432 } |
| 1433 |
| 1434 @override |
| 1435 bool visitBreakStatement(BreakStatement node) { |
| 1436 BreakStatement other = this._other as BreakStatement; |
| 1437 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.lab
el, other.label) && _isEqualTokens(node.semicolon, other.semicolon); |
| 1438 } |
| 1439 |
| 1440 @override |
| 1441 bool visitCascadeExpression(CascadeExpression node) { |
| 1442 CascadeExpression other = this._other as CascadeExpression; |
| 1443 return _isEqualNodes(node.target, other.target) && _isEqualNodeLists(node.ca
scadeSections, other.cascadeSections); |
| 1444 } |
| 1445 |
| 1446 @override |
| 1447 bool visitCatchClause(CatchClause node) { |
| 1448 CatchClause other = this._other as CatchClause; |
| 1449 return _isEqualTokens(node.onKeyword, other.onKeyword) && _isEqualNodes(node
.exceptionType, other.exceptionType) && _isEqualTokens(node.catchKeyword, other.
catchKeyword) && _isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
_isEqualNodes(node.exceptionParameter, other.exceptionParameter) && _isEqualToke
ns(node.comma, other.comma) && _isEqualNodes(node.stackTraceParameter, other.sta
ckTraceParameter) && _isEqualTokens(node.rightParenthesis, other.rightParenthesi
s) && _isEqualNodes(node.body, other.body); |
| 1450 } |
| 1451 |
| 1452 @override |
| 1453 bool visitClassDeclaration(ClassDeclaration node) { |
| 1454 ClassDeclaration other = this._other as ClassDeclaration; |
| 1455 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.abstr
actKeyword, other.abstractKeyword) && _isEqualTokens(node.classKeyword, other.cl
assKeyword) && _isEqualNodes(node.name, other.name) && _isEqualNodes(node.typePa
rameters, other.typeParameters) && _isEqualNodes(node.extendsClause, other.exten
dsClause) && _isEqualNodes(node.withClause, other.withClause) && _isEqualNodes(n
ode.implementsClause, other.implementsClause) && _isEqualTokens(node.leftBracket
, other.leftBracket) && _isEqualNodeLists(node.members, other.members) && _isEqu
alTokens(node.rightBracket, other.rightBracket); |
| 1456 } |
| 1457 |
| 1458 @override |
| 1459 bool visitClassTypeAlias(ClassTypeAlias node) { |
| 1460 ClassTypeAlias other = this._other as ClassTypeAlias; |
| 1461 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.name, other.name) && _isEqualNodes(node
.typeParameters, other.typeParameters) && _isEqualTokens(node.equals, other.equa
ls) && _isEqualTokens(node.abstractKeyword, other.abstractKeyword) && _isEqualNo
des(node.superclass, other.superclass) && _isEqualNodes(node.withClause, other.w
ithClause) && _isEqualNodes(node.implementsClause, other.implementsClause) && _i
sEqualTokens(node.semicolon, other.semicolon); |
| 1462 } |
| 1463 |
| 1464 @override |
| 1465 bool visitComment(Comment node) { |
| 1466 Comment other = this._other as Comment; |
| 1467 return _isEqualNodeLists(node.references, other.references); |
| 1468 } |
| 1469 |
| 1470 @override |
| 1471 bool visitCommentReference(CommentReference node) { |
| 1472 CommentReference other = this._other as CommentReference; |
| 1473 return _isEqualTokens(node.newKeyword, other.newKeyword) && _isEqualNodes(no
de.identifier, other.identifier); |
| 1474 } |
| 1475 |
| 1476 @override |
| 1477 bool visitCompilationUnit(CompilationUnit node) { |
| 1478 CompilationUnit other = this._other as CompilationUnit; |
| 1479 return _isEqualTokens(node.beginToken, other.beginToken) && _isEqualNodes(no
de.scriptTag, other.scriptTag) && _isEqualNodeLists(node.directives, other.direc
tives) && _isEqualNodeLists(node.declarations, other.declarations) && _isEqualTo
kens(node.endToken, other.endToken); |
| 1480 } |
| 1481 |
| 1482 @override |
| 1483 bool visitConditionalExpression(ConditionalExpression node) { |
| 1484 ConditionalExpression other = this._other as ConditionalExpression; |
| 1485 return _isEqualNodes(node.condition, other.condition) && _isEqualTokens(node
.question, other.question) && _isEqualNodes(node.thenExpression, other.thenExpre
ssion) && _isEqualTokens(node.colon, other.colon) && _isEqualNodes(node.elseExpr
ession, other.elseExpression); |
| 1486 } |
| 1487 |
| 1488 @override |
| 1489 bool visitConstructorDeclaration(ConstructorDeclaration node) { |
| 1490 ConstructorDeclaration other = this._other as ConstructorDeclaration; |
| 1491 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.exter
nalKeyword, other.externalKeyword) && _isEqualTokens(node.constKeyword, other.co
nstKeyword) && _isEqualTokens(node.factoryKeyword, other.factoryKeyword) && _isE
qualNodes(node.returnType, other.returnType) && _isEqualTokens(node.period, othe
r.period) && _isEqualNodes(node.name, other.name) && _isEqualNodes(node.paramete
rs, other.parameters) && _isEqualTokens(node.separator, other.separator) && _isE
qualNodeLists(node.initializers, other.initializers) && _isEqualNodes(node.redir
ectedConstructor, other.redirectedConstructor) && _isEqualNodes(node.body, other
.body); |
| 1492 } |
| 1493 |
| 1494 @override |
| 1495 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 1496 ConstructorFieldInitializer other = this._other as ConstructorFieldInitializ
er; |
| 1497 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.pe
riod, other.period) && _isEqualNodes(node.fieldName, other.fieldName) && _isEqua
lTokens(node.equals, other.equals) && _isEqualNodes(node.expression, other.expre
ssion); |
| 1498 } |
| 1499 |
| 1500 @override |
| 1501 bool visitConstructorName(ConstructorName node) { |
| 1502 ConstructorName other = this._other as ConstructorName; |
| 1503 return _isEqualNodes(node.type, other.type) && _isEqualTokens(node.period, o
ther.period) && _isEqualNodes(node.name, other.name); |
| 1504 } |
| 1505 |
| 1506 @override |
| 1507 bool visitContinueStatement(ContinueStatement node) { |
| 1508 ContinueStatement other = this._other as ContinueStatement; |
| 1509 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.lab
el, other.label) && _isEqualTokens(node.semicolon, other.semicolon); |
| 1510 } |
| 1511 |
| 1512 @override |
| 1513 bool visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 1514 DeclaredIdentifier other = this._other as DeclaredIdentifier; |
| 1515 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.type, other.type) && _isEqualNodes(node
.identifier, other.identifier); |
| 1516 } |
| 1517 |
| 1518 @override |
| 1519 bool visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 1520 DefaultFormalParameter other = this._other as DefaultFormalParameter; |
| 1521 return _isEqualNodes(node.parameter, other.parameter) && node.kind == other.
kind && _isEqualTokens(node.separator, other.separator) && _isEqualNodes(node.de
faultValue, other.defaultValue); |
| 1522 } |
| 1523 |
| 1524 @override |
| 1525 bool visitDoStatement(DoStatement node) { |
| 1526 DoStatement other = this._other as DoStatement; |
| 1527 return _isEqualTokens(node.doKeyword, other.doKeyword) && _isEqualNodes(node
.body, other.body) && _isEqualTokens(node.whileKeyword, other.whileKeyword) && _
isEqualTokens(node.leftParenthesis, other.leftParenthesis) && _isEqualNodes(node
.condition, other.condition) && _isEqualTokens(node.rightParenthesis, other.righ
tParenthesis) && _isEqualTokens(node.semicolon, other.semicolon); |
| 1528 } |
| 1529 |
| 1530 @override |
| 1531 bool visitDoubleLiteral(DoubleLiteral node) { |
| 1532 DoubleLiteral other = this._other as DoubleLiteral; |
| 1533 return _isEqualTokens(node.literal, other.literal) && node.value == other.va
lue; |
| 1534 } |
| 1535 |
| 1536 @override |
| 1537 bool visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 1538 EmptyFunctionBody other = this._other as EmptyFunctionBody; |
| 1539 return _isEqualTokens(node.semicolon, other.semicolon); |
| 1540 } |
| 1541 |
| 1542 @override |
| 1543 bool visitEmptyStatement(EmptyStatement node) { |
| 1544 EmptyStatement other = this._other as EmptyStatement; |
| 1545 return _isEqualTokens(node.semicolon, other.semicolon); |
| 1546 } |
| 1547 |
| 1548 @override |
| 1549 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) { |
| 1550 EnumConstantDeclaration other = this._other as EnumConstantDeclaration; |
| 1551 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualNodes(node.name,
other.name); |
| 1552 } |
| 1553 |
| 1554 @override |
| 1555 bool visitEnumDeclaration(EnumDeclaration node) { |
| 1556 EnumDeclaration other = this._other as EnumDeclaration; |
| 1557 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.name, other.name) && _isEqualTokens(nod
e.leftBracket, other.leftBracket) && _isEqualNodeLists(node.constants, other.con
stants) && _isEqualTokens(node.rightBracket, other.rightBracket); |
| 1558 } |
| 1559 |
| 1560 @override |
| 1561 bool visitExportDirective(ExportDirective node) { |
| 1562 ExportDirective other = this._other as ExportDirective; |
| 1563 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.uri, other.uri) && _isEqualNodeLists(no
de.combinators, other.combinators) && _isEqualTokens(node.semicolon, other.semic
olon); |
| 1564 } |
| 1565 |
| 1566 @override |
| 1567 bool visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 1568 ExpressionFunctionBody other = this._other as ExpressionFunctionBody; |
| 1569 return _isEqualTokens(node.functionDefinition, other.functionDefinition) &&
_isEqualNodes(node.expression, other.expression) && _isEqualTokens(node.semicolo
n, other.semicolon); |
| 1570 } |
| 1571 |
| 1572 @override |
| 1573 bool visitExpressionStatement(ExpressionStatement node) { |
| 1574 ExpressionStatement other = this._other as ExpressionStatement; |
| 1575 return _isEqualNodes(node.expression, other.expression) && _isEqualTokens(no
de.semicolon, other.semicolon); |
| 1576 } |
| 1577 |
| 1578 @override |
| 1579 bool visitExtendsClause(ExtendsClause node) { |
| 1580 ExtendsClause other = this._other as ExtendsClause; |
| 1581 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.sup
erclass, other.superclass); |
| 1582 } |
| 1583 |
| 1584 @override |
| 1585 bool visitFieldDeclaration(FieldDeclaration node) { |
| 1586 FieldDeclaration other = this._other as FieldDeclaration; |
| 1587 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.stati
cKeyword, other.staticKeyword) && _isEqualNodes(node.fields, other.fields) && _i
sEqualTokens(node.semicolon, other.semicolon); |
| 1588 } |
| 1589 |
| 1590 @override |
| 1591 bool visitFieldFormalParameter(FieldFormalParameter node) { |
| 1592 FieldFormalParameter other = this._other as FieldFormalParameter; |
| 1593 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.type, other.type) && _isEqualTokens(nod
e.thisToken, other.thisToken) && _isEqualTokens(node.period, other.period) && _i
sEqualNodes(node.identifier, other.identifier); |
| 1594 } |
| 1595 |
| 1596 @override |
| 1597 bool visitForEachStatement(ForEachStatement node) { |
| 1598 ForEachStatement other = this._other as ForEachStatement; |
| 1599 return _isEqualTokens(node.forKeyword, other.forKeyword) && _isEqualTokens(n
ode.leftParenthesis, other.leftParenthesis) && _isEqualNodes(node.loopVariable,
other.loopVariable) && _isEqualTokens(node.inKeyword, other.inKeyword) && _isEqu
alNodes(node.iterator, other.iterator) && _isEqualTokens(node.rightParenthesis,
other.rightParenthesis) && _isEqualNodes(node.body, other.body); |
| 1600 } |
| 1601 |
| 1602 @override |
| 1603 bool visitFormalParameterList(FormalParameterList node) { |
| 1604 FormalParameterList other = this._other as FormalParameterList; |
| 1605 return _isEqualTokens(node.leftParenthesis, other.leftParenthesis) && _isEqu
alNodeLists(node.parameters, other.parameters) && _isEqualTokens(node.leftDelimi
ter, other.leftDelimiter) && _isEqualTokens(node.rightDelimiter, other.rightDeli
miter) && _isEqualTokens(node.rightParenthesis, other.rightParenthesis); |
| 1606 } |
| 1607 |
| 1608 @override |
| 1609 bool visitForStatement(ForStatement node) { |
| 1610 ForStatement other = this._other as ForStatement; |
| 1611 return _isEqualTokens(node.forKeyword, other.forKeyword) && _isEqualTokens(n
ode.leftParenthesis, other.leftParenthesis) && _isEqualNodes(node.variables, oth
er.variables) && _isEqualNodes(node.initialization, other.initialization) && _is
EqualTokens(node.leftSeparator, other.leftSeparator) && _isEqualNodes(node.condi
tion, other.condition) && _isEqualTokens(node.rightSeparator, other.rightSeparat
or) && _isEqualNodeLists(node.updaters, other.updaters) && _isEqualTokens(node.r
ightParenthesis, other.rightParenthesis) && _isEqualNodes(node.body, other.body)
; |
| 1612 } |
| 1613 |
| 1614 @override |
| 1615 bool visitFunctionDeclaration(FunctionDeclaration node) { |
| 1616 FunctionDeclaration other = this._other as FunctionDeclaration; |
| 1617 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.exter
nalKeyword, other.externalKeyword) && _isEqualNodes(node.returnType, other.retur
nType) && _isEqualTokens(node.propertyKeyword, other.propertyKeyword) && _isEqua
lNodes(node.name, other.name) && _isEqualNodes(node.functionExpression, other.fu
nctionExpression); |
| 1618 } |
| 1619 |
| 1620 @override |
| 1621 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 1622 FunctionDeclarationStatement other = this._other as FunctionDeclarationState
ment; |
| 1623 return _isEqualNodes(node.functionDeclaration, other.functionDeclaration); |
| 1624 } |
| 1625 |
| 1626 @override |
| 1627 bool visitFunctionExpression(FunctionExpression node) { |
| 1628 FunctionExpression other = this._other as FunctionExpression; |
| 1629 return _isEqualNodes(node.parameters, other.parameters) && _isEqualNodes(nod
e.body, other.body); |
| 1630 } |
| 1631 |
| 1632 @override |
| 1633 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 1634 FunctionExpressionInvocation other = this._other as FunctionExpressionInvoca
tion; |
| 1635 return _isEqualNodes(node.function, other.function) && _isEqualNodes(node.ar
gumentList, other.argumentList); |
| 1636 } |
| 1637 |
| 1638 @override |
| 1639 bool visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 1640 FunctionTypeAlias other = this._other as FunctionTypeAlias; |
| 1641 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.returnType, other.returnType) && _isEqu
alNodes(node.name, other.name) && _isEqualNodes(node.typeParameters, other.typeP
arameters) && _isEqualNodes(node.parameters, other.parameters) && _isEqualTokens
(node.semicolon, other.semicolon); |
| 1642 } |
| 1643 |
| 1644 @override |
| 1645 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 1646 FunctionTypedFormalParameter other = this._other as FunctionTypedFormalParam
eter; |
| 1647 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualNodes(node.return
Type, other.returnType) && _isEqualNodes(node.identifier, other.identifier) && _
isEqualNodes(node.parameters, other.parameters); |
| 1648 } |
| 1649 |
| 1650 @override |
| 1651 bool visitHideCombinator(HideCombinator node) { |
| 1652 HideCombinator other = this._other as HideCombinator; |
| 1653 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodeLists(node
.hiddenNames, other.hiddenNames); |
| 1654 } |
| 1655 |
| 1656 @override |
| 1657 bool visitIfStatement(IfStatement node) { |
| 1658 IfStatement other = this._other as IfStatement; |
| 1659 return _isEqualTokens(node.ifKeyword, other.ifKeyword) && _isEqualTokens(nod
e.leftParenthesis, other.leftParenthesis) && _isEqualNodes(node.condition, other
.condition) && _isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
_isEqualNodes(node.thenStatement, other.thenStatement) && _isEqualTokens(node.el
seKeyword, other.elseKeyword) && _isEqualNodes(node.elseStatement, other.elseSta
tement); |
| 1660 } |
| 1661 |
| 1662 @override |
| 1663 bool visitImplementsClause(ImplementsClause node) { |
| 1664 ImplementsClause other = this._other as ImplementsClause; |
| 1665 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodeLists(node
.interfaces, other.interfaces); |
| 1666 } |
| 1667 |
| 1668 @override |
| 1669 bool visitImportDirective(ImportDirective node) { |
| 1670 ImportDirective other = this._other as ImportDirective; |
| 1671 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.uri, other.uri) && _isEqualTokens(node.
asToken, other.asToken) && _isEqualNodes(node.prefix, other.prefix) && _isEqualN
odeLists(node.combinators, other.combinators) && _isEqualTokens(node.semicolon,
other.semicolon); |
| 1672 } |
| 1673 |
| 1674 @override |
| 1675 bool visitIndexExpression(IndexExpression node) { |
| 1676 IndexExpression other = this._other as IndexExpression; |
| 1677 return _isEqualNodes(node.target, other.target) && _isEqualTokens(node.leftB
racket, other.leftBracket) && _isEqualNodes(node.index, other.index) && _isEqual
Tokens(node.rightBracket, other.rightBracket); |
| 1678 } |
| 1679 |
| 1680 @override |
| 1681 bool visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 1682 InstanceCreationExpression other = this._other as InstanceCreationExpression
; |
| 1683 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.con
structorName, other.constructorName) && _isEqualNodes(node.argumentList, other.a
rgumentList); |
| 1684 } |
| 1685 |
| 1686 @override |
| 1687 bool visitIntegerLiteral(IntegerLiteral node) { |
| 1688 IntegerLiteral other = this._other as IntegerLiteral; |
| 1689 return _isEqualTokens(node.literal, other.literal) && (node.value == other.v
alue); |
| 1690 } |
| 1691 |
| 1692 @override |
| 1693 bool visitInterpolationExpression(InterpolationExpression node) { |
| 1694 InterpolationExpression other = this._other as InterpolationExpression; |
| 1695 return _isEqualTokens(node.leftBracket, other.leftBracket) && _isEqualNodes(
node.expression, other.expression) && _isEqualTokens(node.rightBracket, other.ri
ghtBracket); |
| 1696 } |
| 1697 |
| 1698 @override |
| 1699 bool visitInterpolationString(InterpolationString node) { |
| 1700 InterpolationString other = this._other as InterpolationString; |
| 1701 return _isEqualTokens(node.contents, other.contents) && node.value == other.
value; |
| 1702 } |
| 1703 |
| 1704 @override |
| 1705 bool visitIsExpression(IsExpression node) { |
| 1706 IsExpression other = this._other as IsExpression; |
| 1707 return _isEqualNodes(node.expression, other.expression) && _isEqualTokens(no
de.isOperator, other.isOperator) && _isEqualTokens(node.notOperator, other.notOp
erator) && _isEqualNodes(node.type, other.type); |
| 1708 } |
| 1709 |
| 1710 @override |
| 1711 bool visitLabel(Label node) { |
| 1712 Label other = this._other as Label; |
| 1713 return _isEqualNodes(node.label, other.label) && _isEqualTokens(node.colon,
other.colon); |
| 1714 } |
| 1715 |
| 1716 @override |
| 1717 bool visitLabeledStatement(LabeledStatement node) { |
| 1718 LabeledStatement other = this._other as LabeledStatement; |
| 1719 return _isEqualNodeLists(node.labels, other.labels) && _isEqualNodes(node.st
atement, other.statement); |
| 1720 } |
| 1721 |
| 1722 @override |
| 1723 bool visitLibraryDirective(LibraryDirective node) { |
| 1724 LibraryDirective other = this._other as LibraryDirective; |
| 1725 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.libra
ryToken, other.libraryToken) && _isEqualNodes(node.name, other.name) && _isEqual
Tokens(node.semicolon, other.semicolon); |
| 1726 } |
| 1727 |
| 1728 @override |
| 1729 bool visitLibraryIdentifier(LibraryIdentifier node) { |
| 1730 LibraryIdentifier other = this._other as LibraryIdentifier; |
| 1731 return _isEqualNodeLists(node.components, other.components); |
| 1732 } |
| 1733 |
| 1734 @override |
| 1735 bool visitListLiteral(ListLiteral node) { |
| 1736 ListLiteral other = this._other as ListLiteral; |
| 1737 return _isEqualTokens(node.constKeyword, other.constKeyword) && _isEqualNode
s(node.typeArguments, other.typeArguments) && _isEqualTokens(node.leftBracket, o
ther.leftBracket) && _isEqualNodeLists(node.elements, other.elements) && _isEqua
lTokens(node.rightBracket, other.rightBracket); |
| 1738 } |
| 1739 |
| 1740 @override |
| 1741 bool visitMapLiteral(MapLiteral node) { |
| 1742 MapLiteral other = this._other as MapLiteral; |
| 1743 return _isEqualTokens(node.constKeyword, other.constKeyword) && _isEqualNode
s(node.typeArguments, other.typeArguments) && _isEqualTokens(node.leftBracket, o
ther.leftBracket) && _isEqualNodeLists(node.entries, other.entries) && _isEqualT
okens(node.rightBracket, other.rightBracket); |
| 1744 } |
| 1745 |
| 1746 @override |
| 1747 bool visitMapLiteralEntry(MapLiteralEntry node) { |
| 1748 MapLiteralEntry other = this._other as MapLiteralEntry; |
| 1749 return _isEqualNodes(node.key, other.key) && _isEqualTokens(node.separator,
other.separator) && _isEqualNodes(node.value, other.value); |
| 1750 } |
| 1751 |
| 1752 @override |
| 1753 bool visitMethodDeclaration(MethodDeclaration node) { |
| 1754 MethodDeclaration other = this._other as MethodDeclaration; |
| 1755 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.exter
nalKeyword, other.externalKeyword) && _isEqualTokens(node.modifierKeyword, other
.modifierKeyword) && _isEqualNodes(node.returnType, other.returnType) && _isEqua
lTokens(node.propertyKeyword, other.propertyKeyword) && _isEqualTokens(node.prop
ertyKeyword, other.propertyKeyword) && _isEqualNodes(node.name, other.name) && _
isEqualNodes(node.parameters, other.parameters) && _isEqualNodes(node.body, othe
r.body); |
| 1756 } |
| 1757 |
| 1758 @override |
| 1759 bool visitMethodInvocation(MethodInvocation node) { |
| 1760 MethodInvocation other = this._other as MethodInvocation; |
| 1761 return _isEqualNodes(node.target, other.target) && _isEqualTokens(node.perio
d, other.period) && _isEqualNodes(node.methodName, other.methodName) && _isEqual
Nodes(node.argumentList, other.argumentList); |
| 1762 } |
| 1763 |
| 1764 @override |
| 1765 bool visitNamedExpression(NamedExpression node) { |
| 1766 NamedExpression other = this._other as NamedExpression; |
| 1767 return _isEqualNodes(node.name, other.name) && _isEqualNodes(node.expression
, other.expression); |
| 1768 } |
| 1769 |
| 1770 @override |
| 1771 bool visitNativeClause(NativeClause node) { |
| 1772 NativeClause other = this._other as NativeClause; |
| 1773 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.nam
e, other.name); |
| 1774 } |
| 1775 |
| 1776 @override |
| 1777 bool visitNativeFunctionBody(NativeFunctionBody node) { |
| 1778 NativeFunctionBody other = this._other as NativeFunctionBody; |
| 1779 return _isEqualTokens(node.nativeToken, other.nativeToken) && _isEqualNodes(
node.stringLiteral, other.stringLiteral) && _isEqualTokens(node.semicolon, other
.semicolon); |
| 1780 } |
| 1781 |
| 1782 @override |
| 1783 bool visitNullLiteral(NullLiteral node) { |
| 1784 NullLiteral other = this._other as NullLiteral; |
| 1785 return _isEqualTokens(node.literal, other.literal); |
| 1786 } |
| 1787 |
| 1788 @override |
| 1789 bool visitParenthesizedExpression(ParenthesizedExpression node) { |
| 1790 ParenthesizedExpression other = this._other as ParenthesizedExpression; |
| 1791 return _isEqualTokens(node.leftParenthesis, other.leftParenthesis) && _isEqu
alNodes(node.expression, other.expression) && _isEqualTokens(node.rightParenthes
is, other.rightParenthesis); |
| 1792 } |
| 1793 |
| 1794 @override |
| 1795 bool visitPartDirective(PartDirective node) { |
| 1796 PartDirective other = this._other as PartDirective; |
| 1797 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.partT
oken, other.partToken) && _isEqualNodes(node.uri, other.uri) && _isEqualTokens(n
ode.semicolon, other.semicolon); |
| 1798 } |
| 1799 |
| 1800 @override |
| 1801 bool visitPartOfDirective(PartOfDirective node) { |
| 1802 PartOfDirective other = this._other as PartOfDirective; |
| 1803 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.partT
oken, other.partToken) && _isEqualTokens(node.ofToken, other.ofToken) && _isEqua
lNodes(node.libraryName, other.libraryName) && _isEqualTokens(node.semicolon, ot
her.semicolon); |
| 1804 } |
| 1805 |
| 1806 @override |
| 1807 bool visitPostfixExpression(PostfixExpression node) { |
| 1808 PostfixExpression other = this._other as PostfixExpression; |
| 1809 return _isEqualNodes(node.operand, other.operand) && _isEqualTokens(node.ope
rator, other.operator); |
| 1810 } |
| 1811 |
| 1812 @override |
| 1813 bool visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 1814 PrefixedIdentifier other = this._other as PrefixedIdentifier; |
| 1815 return _isEqualNodes(node.prefix, other.prefix) && _isEqualTokens(node.perio
d, other.period) && _isEqualNodes(node.identifier, other.identifier); |
| 1816 } |
| 1817 |
| 1818 @override |
| 1819 bool visitPrefixExpression(PrefixExpression node) { |
| 1820 PrefixExpression other = this._other as PrefixExpression; |
| 1821 return _isEqualTokens(node.operator, other.operator) && _isEqualNodes(node.o
perand, other.operand); |
| 1822 } |
| 1823 |
| 1824 @override |
| 1825 bool visitPropertyAccess(PropertyAccess node) { |
| 1826 PropertyAccess other = this._other as PropertyAccess; |
| 1827 return _isEqualNodes(node.target, other.target) && _isEqualTokens(node.opera
tor, other.operator) && _isEqualNodes(node.propertyName, other.propertyName); |
| 1828 } |
| 1829 |
| 1830 @override |
| 1831 bool visitRedirectingConstructorInvocation(RedirectingConstructorInvocation no
de) { |
| 1832 RedirectingConstructorInvocation other = this._other as RedirectingConstruct
orInvocation; |
| 1833 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.pe
riod, other.period) && _isEqualNodes(node.constructorName, other.constructorName
) && _isEqualNodes(node.argumentList, other.argumentList); |
| 1834 } |
| 1835 |
| 1836 @override |
| 1837 bool visitRethrowExpression(RethrowExpression node) { |
| 1838 RethrowExpression other = this._other as RethrowExpression; |
| 1839 return _isEqualTokens(node.keyword, other.keyword); |
| 1840 } |
| 1841 |
| 1842 @override |
| 1843 bool visitReturnStatement(ReturnStatement node) { |
| 1844 ReturnStatement other = this._other as ReturnStatement; |
| 1845 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.exp
ression, other.expression) && _isEqualTokens(node.semicolon, other.semicolon); |
| 1846 } |
| 1847 |
| 1848 @override |
| 1849 bool visitScriptTag(ScriptTag node) { |
| 1850 ScriptTag other = this._other as ScriptTag; |
| 1851 return _isEqualTokens(node.scriptTag, other.scriptTag); |
| 1852 } |
| 1853 |
| 1854 @override |
| 1855 bool visitShowCombinator(ShowCombinator node) { |
| 1856 ShowCombinator other = this._other as ShowCombinator; |
| 1857 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodeLists(node
.shownNames, other.shownNames); |
| 1858 } |
| 1859 |
| 1860 @override |
| 1861 bool visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 1862 SimpleFormalParameter other = this._other as SimpleFormalParameter; |
| 1863 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.type, other.type) && _isEqualNodes(node
.identifier, other.identifier); |
| 1864 } |
| 1865 |
| 1866 @override |
| 1867 bool visitSimpleIdentifier(SimpleIdentifier node) { |
| 1868 SimpleIdentifier other = this._other as SimpleIdentifier; |
| 1869 return _isEqualTokens(node.token, other.token); |
| 1870 } |
| 1871 |
| 1872 @override |
| 1873 bool visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 1874 SimpleStringLiteral other = this._other as SimpleStringLiteral; |
| 1875 return _isEqualTokens(node.literal, other.literal) && (node.value == other.v
alue); |
| 1876 } |
| 1877 |
| 1878 @override |
| 1879 bool visitStringInterpolation(StringInterpolation node) { |
| 1880 StringInterpolation other = this._other as StringInterpolation; |
| 1881 return _isEqualNodeLists(node.elements, other.elements); |
| 1882 } |
| 1883 |
| 1884 @override |
| 1885 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 1886 SuperConstructorInvocation other = this._other as SuperConstructorInvocation
; |
| 1887 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.pe
riod, other.period) && _isEqualNodes(node.constructorName, other.constructorName
) && _isEqualNodes(node.argumentList, other.argumentList); |
| 1888 } |
| 1889 |
| 1890 @override |
| 1891 bool visitSuperExpression(SuperExpression node) { |
| 1892 SuperExpression other = this._other as SuperExpression; |
| 1893 return _isEqualTokens(node.keyword, other.keyword); |
| 1894 } |
| 1895 |
| 1896 @override |
| 1897 bool visitSwitchCase(SwitchCase node) { |
| 1898 SwitchCase other = this._other as SwitchCase; |
| 1899 return _isEqualNodeLists(node.labels, other.labels) && _isEqualTokens(node.k
eyword, other.keyword) && _isEqualNodes(node.expression, other.expression) && _i
sEqualTokens(node.colon, other.colon) && _isEqualNodeLists(node.statements, othe
r.statements); |
| 1900 } |
| 1901 |
| 1902 @override |
| 1903 bool visitSwitchDefault(SwitchDefault node) { |
| 1904 SwitchDefault other = this._other as SwitchDefault; |
| 1905 return _isEqualNodeLists(node.labels, other.labels) && _isEqualTokens(node.k
eyword, other.keyword) && _isEqualTokens(node.colon, other.colon) && _isEqualNod
eLists(node.statements, other.statements); |
| 1906 } |
| 1907 |
| 1908 @override |
| 1909 bool visitSwitchStatement(SwitchStatement node) { |
| 1910 SwitchStatement other = this._other as SwitchStatement; |
| 1911 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.le
ftParenthesis, other.leftParenthesis) && _isEqualNodes(node.expression, other.ex
pression) && _isEqualTokens(node.rightParenthesis, other.rightParenthesis) && _i
sEqualTokens(node.leftBracket, other.leftBracket) && _isEqualNodeLists(node.memb
ers, other.members) && _isEqualTokens(node.rightBracket, other.rightBracket); |
| 1912 } |
| 1913 |
| 1914 @override |
| 1915 bool visitSymbolLiteral(SymbolLiteral node) { |
| 1916 SymbolLiteral other = this._other as SymbolLiteral; |
| 1917 return _isEqualTokens(node.poundSign, other.poundSign) && _isEqualTokenLists
(node.components, other.components); |
| 1918 } |
| 1919 |
| 1920 @override |
| 1921 bool visitThisExpression(ThisExpression node) { |
| 1922 ThisExpression other = this._other as ThisExpression; |
| 1923 return _isEqualTokens(node.keyword, other.keyword); |
| 1924 } |
| 1925 |
| 1926 @override |
| 1927 bool visitThrowExpression(ThrowExpression node) { |
| 1928 ThrowExpression other = this._other as ThrowExpression; |
| 1929 return _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node.exp
ression, other.expression); |
| 1930 } |
| 1931 |
| 1932 @override |
| 1933 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 1934 TopLevelVariableDeclaration other = this._other as TopLevelVariableDeclarati
on; |
| 1935 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualNodes(node.variab
les, other.variables) && _isEqualTokens(node.semicolon, other.semicolon); |
| 1936 } |
| 1937 |
| 1938 @override |
| 1939 bool visitTryStatement(TryStatement node) { |
| 1940 TryStatement other = this._other as TryStatement; |
| 1941 return _isEqualTokens(node.tryKeyword, other.tryKeyword) && _isEqualNodes(no
de.body, other.body) && _isEqualNodeLists(node.catchClauses, other.catchClauses)
&& _isEqualTokens(node.finallyKeyword, other.finallyKeyword) && _isEqualNodes(n
ode.finallyBlock, other.finallyBlock); |
| 1942 } |
| 1943 |
| 1944 @override |
| 1945 bool visitTypeArgumentList(TypeArgumentList node) { |
| 1946 TypeArgumentList other = this._other as TypeArgumentList; |
| 1947 return _isEqualTokens(node.leftBracket, other.leftBracket) && _isEqualNodeLi
sts(node.arguments, other.arguments) && _isEqualTokens(node.rightBracket, other.
rightBracket); |
| 1948 } |
| 1949 |
| 1950 @override |
| 1951 bool visitTypeName(TypeName node) { |
| 1952 TypeName other = this._other as TypeName; |
| 1953 return _isEqualNodes(node.name, other.name) && _isEqualNodes(node.typeArgume
nts, other.typeArguments); |
| 1954 } |
| 1955 |
| 1956 @override |
| 1957 bool visitTypeParameter(TypeParameter node) { |
| 1958 TypeParameter other = this._other as TypeParameter; |
| 1959 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualNodes(node.name,
other.name) && _isEqualTokens(node.keyword, other.keyword) && _isEqualNodes(node
.bound, other.bound); |
| 1960 } |
| 1961 |
| 1962 @override |
| 1963 bool visitTypeParameterList(TypeParameterList node) { |
| 1964 TypeParameterList other = this._other as TypeParameterList; |
| 1965 return _isEqualTokens(node.leftBracket, other.leftBracket) && _isEqualNodeLi
sts(node.typeParameters, other.typeParameters) && _isEqualTokens(node.rightBrack
et, other.rightBracket); |
| 1966 } |
| 1967 |
| 1968 @override |
| 1969 bool visitVariableDeclaration(VariableDeclaration node) { |
| 1970 VariableDeclaration other = this._other as VariableDeclaration; |
| 1971 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualNodes(node.name,
other.name) && _isEqualTokens(node.equals, other.equals) && _isEqualNodes(node.i
nitializer, other.initializer); |
| 1972 } |
| 1973 |
| 1974 @override |
| 1975 bool visitVariableDeclarationList(VariableDeclarationList node) { |
| 1976 VariableDeclarationList other = this._other as VariableDeclarationList; |
| 1977 return _isEqualNodes(node.documentationComment, other.documentationComment)
&& _isEqualNodeLists(node.metadata, other.metadata) && _isEqualTokens(node.keywo
rd, other.keyword) && _isEqualNodes(node.type, other.type) && _isEqualNodeLists(
node.variables, other.variables); |
| 1978 } |
| 1979 |
| 1980 @override |
| 1981 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 1982 VariableDeclarationStatement other = this._other as VariableDeclarationState
ment; |
| 1983 return _isEqualNodes(node.variables, other.variables) && _isEqualTokens(node
.semicolon, other.semicolon); |
| 1984 } |
| 1985 |
| 1986 @override |
| 1987 bool visitWhileStatement(WhileStatement node) { |
| 1988 WhileStatement other = this._other as WhileStatement; |
| 1989 return _isEqualTokens(node.keyword, other.keyword) && _isEqualTokens(node.le
ftParenthesis, other.leftParenthesis) && _isEqualNodes(node.condition, other.con
dition) && _isEqualTokens(node.rightParenthesis, other.rightParenthesis) && _isE
qualNodes(node.body, other.body); |
| 1990 } |
| 1991 |
| 1992 @override |
| 1993 bool visitWithClause(WithClause node) { |
| 1994 WithClause other = this._other as WithClause; |
| 1995 return _isEqualTokens(node.withKeyword, other.withKeyword) && _isEqualNodeLi
sts(node.mixinTypes, other.mixinTypes); |
| 1996 } |
| 1997 |
| 1998 @override |
| 1999 bool visitYieldStatement(YieldStatement node) { |
| 2000 YieldStatement other = this._other as YieldStatement; |
| 2001 return _isEqualTokens(node.yieldKeyword, other.yieldKeyword) && _isEqualNode
s(node.expression, other.expression) && _isEqualTokens(node.semicolon, other.sem
icolon); |
| 2002 } |
| 2003 |
| 2004 /** |
| 2005 * Return `true` if the given lists of AST nodes have the same size and corres
ponding |
| 2006 * elements are equal. |
| 2007 * |
| 2008 * @param first the first node being compared |
| 2009 * @param second the second node being compared |
| 2010 * @return `true` if the given AST nodes have the same size and corresponding
elements are |
| 2011 * equal |
| 2012 */ |
| 2013 bool _isEqualNodeLists(NodeList first, NodeList second) { |
| 2014 if (first == null) { |
| 2015 return second == null; |
| 2016 } else if (second == null) { |
| 2017 return false; |
| 2018 } |
| 2019 int size = first.length; |
| 2020 if (second.length != size) { |
| 2021 return false; |
| 2022 } |
| 2023 for (int i = 0; i < size; i++) { |
| 2024 if (!_isEqualNodes(first[i], second[i])) { |
| 2025 return false; |
| 2026 } |
| 2027 } |
| 2028 return true; |
| 2029 } |
| 2030 |
| 2031 /** |
| 2032 * Return `true` if the given AST nodes have the same structure. |
| 2033 * |
| 2034 * @param first the first node being compared |
| 2035 * @param second the second node being compared |
| 2036 * @return `true` if the given AST nodes have the same structure |
| 2037 */ |
| 2038 bool _isEqualNodes(AstNode first, AstNode second) { |
| 2039 if (first == null) { |
| 2040 return second == null; |
| 2041 } else if (second == null) { |
| 2042 return false; |
| 2043 } else if (first.runtimeType != second.runtimeType) { |
| 2044 return false; |
| 2045 } |
| 2046 _other = second; |
| 2047 return first.accept(this); |
| 2048 } |
| 2049 |
| 2050 /** |
| 2051 * Return `true` if the given arrays of tokens have the same length and corres
ponding |
| 2052 * elements are equal. |
| 2053 * |
| 2054 * @param first the first node being compared |
| 2055 * @param second the second node being compared |
| 2056 * @return `true` if the given arrays of tokens have the same length and corre
sponding |
| 2057 * elements are equal |
| 2058 */ |
| 2059 bool _isEqualTokenLists(List<Token> first, List<Token> second) { |
| 2060 int length = first.length; |
| 2061 if (second.length != length) { |
| 2062 return false; |
| 2063 } |
| 2064 for (int i = 0; i < length; i++) { |
| 2065 if (!_isEqualTokens(first[i], second[i])) { |
| 2066 return false; |
| 2067 } |
| 2068 } |
| 2069 return true; |
| 2070 } |
| 2071 |
| 2072 /** |
| 2073 * Return `true` if the given tokens have the same structure. |
| 2074 * |
| 2075 * @param first the first node being compared |
| 2076 * @param second the second node being compared |
| 2077 * @return `true` if the given tokens have the same structure |
| 2078 */ |
| 2079 bool _isEqualTokens(Token first, Token second) { |
| 2080 if (first == null) { |
| 2081 return second == null; |
| 2082 } else if (second == null) { |
| 2083 return false; |
| 2084 } else if (identical(first, second)) { |
| 2085 return true; |
| 2086 } |
| 2087 return first.offset == second.offset && first.length == second.length && fir
st.lexeme == second.lexeme; |
| 2088 } |
| 2089 } |
| 2090 |
| 2091 /** |
| 2092 * The abstract class `AstNode` defines the behavior common to all nodes in the
AST structure |
| 2093 * for a Dart program. |
| 2094 */ |
| 2095 abstract class AstNode { |
| 2096 /** |
| 2097 * An empty array of ast nodes. |
| 2098 */ |
| 2099 static List<AstNode> EMPTY_ARRAY = new List<AstNode>(0); |
| 2100 |
| 2101 /** |
| 2102 * The parent of the node, or `null` if the node is the root of an AST structu
re. |
| 2103 */ |
| 2104 AstNode _parent; |
| 2105 |
| 2106 /** |
| 2107 * A table mapping the names of properties to their values, or `null` if this
node does not |
| 2108 * have any properties associated with it. |
| 2109 */ |
| 2110 Map<String, Object> _propertyMap; |
| 2111 |
| 2112 /** |
| 2113 * A comparator that can be used to sort AST nodes in lexical order. In other
words, |
| 2114 * `compare` will return a negative value if the offset of the first node is l
ess than the |
| 2115 * offset of the second node, zero (0) if the nodes have the same offset, and
a positive value if |
| 2116 * if the offset of the first node is greater than the offset of the second no
de. |
| 2117 */ |
| 2118 static Comparator<AstNode> LEXICAL_ORDER = (AstNode first, AstNode second) =>
second.offset - first.offset; |
| 2119 |
| 2120 /** |
| 2121 * Use the given visitor to visit this node. |
| 2122 * |
| 2123 * @param visitor the visitor that will visit this node |
| 2124 * @return the value returned by the visitor as a result of visiting this node |
| 2125 */ |
| 2126 accept(AstVisitor visitor); |
| 2127 |
| 2128 /** |
| 2129 * Return the node of the given class that most immediately encloses this node
, or `null` if |
| 2130 * there is no enclosing node of the given class. |
| 2131 * |
| 2132 * @param nodeClass the class of the node to be returned |
| 2133 * @return the node of the given type that encloses this node |
| 2134 */ |
| 2135 AstNode getAncestor(Predicate<AstNode> predicate) { |
| 2136 AstNode node = this; |
| 2137 while (node != null && !predicate(node)) { |
| 2138 node = node.parent; |
| 2139 } |
| 2140 return node; |
| 2141 } |
| 2142 |
| 2143 /** |
| 2144 * Return the first token included in this node's source range. |
| 2145 * |
| 2146 * @return the first token included in this node's source range |
| 2147 */ |
| 2148 Token get beginToken; |
| 2149 |
| 2150 /** |
| 2151 * Return the offset of the character immediately following the last character
of this node's |
| 2152 * source range. This is equivalent to `node.getOffset() + node.getLength()`.
For a |
| 2153 * compilation unit this will be equal to the length of the unit's source. For
synthetic nodes |
| 2154 * this will be equivalent to the node's offset (because the length is zero (0
) by definition). |
| 2155 * |
| 2156 * @return the offset of the character just past the node's source range |
| 2157 */ |
| 2158 int get end => offset + length; |
| 2159 |
| 2160 /** |
| 2161 * Return the last token included in this node's source range. |
| 2162 * |
| 2163 * @return the last token included in this node's source range |
| 2164 */ |
| 2165 Token get endToken; |
| 2166 |
| 2167 /** |
| 2168 * Return the number of characters in the node's source range. |
| 2169 * |
| 2170 * @return the number of characters in the node's source range |
| 2171 */ |
| 2172 int get length { |
| 2173 Token beginToken = this.beginToken; |
| 2174 Token endToken = this.endToken; |
| 2175 if (beginToken == null || endToken == null) { |
| 2176 return -1; |
| 2177 } |
| 2178 return endToken.offset + endToken.length - beginToken.offset; |
| 2179 } |
| 2180 |
| 2181 /** |
| 2182 * Return the offset from the beginning of the file to the first character in
the node's source |
| 2183 * range. |
| 2184 * |
| 2185 * @return the offset from the beginning of the file to the first character in
the node's source |
| 2186 * range |
| 2187 */ |
| 2188 int get offset { |
| 2189 Token beginToken = this.beginToken; |
| 2190 if (beginToken == null) { |
| 2191 return -1; |
| 2192 } |
| 2193 return beginToken.offset; |
| 2194 } |
| 2195 |
| 2196 /** |
| 2197 * Return this node's parent node, or `null` if this node is the root of an AS
T structure. |
| 2198 * |
| 2199 * Note that the relationship between an AST node and its parent node may chan
ge over the lifetime |
| 2200 * of a node. |
| 2201 * |
| 2202 * @return the parent of this node, or `null` if none |
| 2203 */ |
| 2204 AstNode get parent => _parent; |
| 2205 |
| 2206 /** |
| 2207 * Return the value of the property with the given name, or `null` if this nod
e does not |
| 2208 * have a property with the given name. |
| 2209 * |
| 2210 * @return the value of the property with the given name |
| 2211 */ |
| 2212 Object getProperty(String propertyName) { |
| 2213 if (_propertyMap == null) { |
| 2214 return null; |
| 2215 } |
| 2216 return _propertyMap[propertyName]; |
| 2217 } |
| 2218 |
| 2219 /** |
| 2220 * Return the node at the root of this node's AST structure. Note that this me
thod's performance |
| 2221 * is linear with respect to the depth of the node in the AST structure (O(dep
th)). |
| 2222 * |
| 2223 * @return the node at the root of this node's AST structure |
| 2224 */ |
| 2225 AstNode get root { |
| 2226 AstNode root = this; |
| 2227 AstNode parent = this.parent; |
| 2228 while (parent != null) { |
| 2229 root = parent; |
| 2230 parent = root.parent; |
| 2231 } |
| 2232 return root; |
| 2233 } |
| 2234 |
| 2235 /** |
| 2236 * Return `true` if this node is a synthetic node. A synthetic node is a node
that was |
| 2237 * introduced by the parser in order to recover from an error in the code. Syn
thetic nodes always |
| 2238 * have a length of zero (`0`). |
| 2239 * |
| 2240 * @return `true` if this node is a synthetic node |
| 2241 */ |
| 2242 bool get isSynthetic => false; |
| 2243 |
| 2244 /** |
| 2245 * Set the value of the property with the given name to the given value. If th
e value is |
| 2246 * `null`, the property will effectively be removed. |
| 2247 * |
| 2248 * @param propertyName the name of the property whose value is to be set |
| 2249 * @param propertyValue the new value of the property |
| 2250 */ |
| 2251 void setProperty(String propertyName, Object propertyValue) { |
| 2252 if (propertyValue == null) { |
| 2253 if (_propertyMap != null) { |
| 2254 _propertyMap.remove(propertyName); |
| 2255 if (_propertyMap.isEmpty) { |
| 2256 _propertyMap = null; |
| 2257 } |
| 2258 } |
| 2259 } else { |
| 2260 if (_propertyMap == null) { |
| 2261 _propertyMap = new HashMap<String, Object>(); |
| 2262 } |
| 2263 _propertyMap[propertyName] = propertyValue; |
| 2264 } |
| 2265 } |
| 2266 |
| 2267 /** |
| 2268 * Return a textual description of this node in a form approximating valid sou
rce. The returned |
| 2269 * string will not be valid source primarily in the case where the node itself
is not well-formed. |
| 2270 * |
| 2271 * @return the source code equivalent of this node |
| 2272 */ |
| 2273 String toSource() { |
| 2274 PrintStringWriter writer = new PrintStringWriter(); |
| 2275 accept(new ToSourceVisitor(writer)); |
| 2276 return writer.toString(); |
| 2277 } |
| 2278 |
| 2279 @override |
| 2280 String toString() => toSource(); |
| 2281 |
| 2282 /** |
| 2283 * Use the given visitor to visit all of the children of this node. The childr
en will be visited |
| 2284 * in source order. |
| 2285 * |
| 2286 * @param visitor the visitor that will be used to visit the children of this
node |
| 2287 */ |
| 2288 void visitChildren(AstVisitor visitor); |
| 2289 |
| 2290 /** |
| 2291 * Make this node the parent of the given child node. |
| 2292 * |
| 2293 * @param child the node that will become a child of this node |
| 2294 * @return the node that was made a child of this node |
| 2295 */ |
| 2296 AstNode becomeParentOf(AstNode child) { |
| 2297 if (child != null) { |
| 2298 AstNode node = child; |
| 2299 node.parent = this; |
| 2300 } |
| 2301 return child; |
| 2302 } |
| 2303 |
| 2304 /** |
| 2305 * If the given child is not `null`, use the given visitor to visit it. |
| 2306 * |
| 2307 * @param child the child to be visited |
| 2308 * @param visitor the visitor that will be used to visit the child |
| 2309 */ |
| 2310 void safelyVisitChild(AstNode child, AstVisitor visitor) { |
| 2311 if (child != null) { |
| 2312 child.accept(visitor); |
| 2313 } |
| 2314 } |
| 2315 |
| 2316 /** |
| 2317 * Set the parent of this node to the given node. |
| 2318 * |
| 2319 * @param newParent the node that is to be made the parent of this node |
| 2320 */ |
| 2321 void set parent(AstNode newParent) { |
| 2322 _parent = newParent; |
| 2323 } |
| 2324 } |
| 2325 |
| 2326 /** |
| 2327 * The interface `AstVisitor` defines the behavior of objects that can be used t
o visit an AST |
| 2328 * structure. |
| 2329 */ |
| 2330 abstract class AstVisitor<R> { |
| 2331 R visitAdjacentStrings(AdjacentStrings node); |
| 2332 |
| 2333 R visitAnnotation(Annotation node); |
| 2334 |
| 2335 R visitArgumentList(ArgumentList node); |
| 2336 |
| 2337 R visitAsExpression(AsExpression node); |
| 2338 |
| 2339 R visitAssertStatement(AssertStatement assertStatement); |
| 2340 |
| 2341 R visitAssignmentExpression(AssignmentExpression node); |
| 2342 |
| 2343 R visitAwaitExpression(AwaitExpression node); |
| 2344 |
| 2345 R visitBinaryExpression(BinaryExpression node); |
| 2346 |
| 2347 R visitBlock(Block node); |
| 2348 |
| 2349 R visitBlockFunctionBody(BlockFunctionBody node); |
| 2350 |
| 2351 R visitBooleanLiteral(BooleanLiteral node); |
| 2352 |
| 2353 R visitBreakStatement(BreakStatement node); |
| 2354 |
| 2355 R visitCascadeExpression(CascadeExpression node); |
| 2356 |
| 2357 R visitCatchClause(CatchClause node); |
| 2358 |
| 2359 R visitClassDeclaration(ClassDeclaration node); |
| 2360 |
| 2361 R visitClassTypeAlias(ClassTypeAlias node); |
| 2362 |
| 2363 R visitComment(Comment node); |
| 2364 |
| 2365 R visitCommentReference(CommentReference node); |
| 2366 |
| 2367 R visitCompilationUnit(CompilationUnit node); |
| 2368 |
| 2369 R visitConditionalExpression(ConditionalExpression node); |
| 2370 |
| 2371 R visitConstructorDeclaration(ConstructorDeclaration node); |
| 2372 |
| 2373 R visitConstructorFieldInitializer(ConstructorFieldInitializer node); |
| 2374 |
| 2375 R visitConstructorName(ConstructorName node); |
| 2376 |
| 2377 R visitContinueStatement(ContinueStatement node); |
| 2378 |
| 2379 R visitDeclaredIdentifier(DeclaredIdentifier node); |
| 2380 |
| 2381 R visitDefaultFormalParameter(DefaultFormalParameter node); |
| 2382 |
| 2383 R visitDoStatement(DoStatement node); |
| 2384 |
| 2385 R visitDoubleLiteral(DoubleLiteral node); |
| 2386 |
| 2387 R visitEmptyFunctionBody(EmptyFunctionBody node); |
| 2388 |
| 2389 R visitEmptyStatement(EmptyStatement node); |
| 2390 |
| 2391 R visitEnumConstantDeclaration(EnumConstantDeclaration node); |
| 2392 |
| 2393 R visitEnumDeclaration(EnumDeclaration node); |
| 2394 |
| 2395 R visitExportDirective(ExportDirective node); |
| 2396 |
| 2397 R visitExpressionFunctionBody(ExpressionFunctionBody node); |
| 2398 |
| 2399 R visitExpressionStatement(ExpressionStatement node); |
| 2400 |
| 2401 R visitExtendsClause(ExtendsClause node); |
| 2402 |
| 2403 R visitFieldDeclaration(FieldDeclaration node); |
| 2404 |
| 2405 R visitFieldFormalParameter(FieldFormalParameter node); |
| 2406 |
| 2407 R visitForEachStatement(ForEachStatement node); |
| 2408 |
| 2409 R visitFormalParameterList(FormalParameterList node); |
| 2410 |
| 2411 R visitForStatement(ForStatement node); |
| 2412 |
| 2413 R visitFunctionDeclaration(FunctionDeclaration node); |
| 2414 |
| 2415 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node); |
| 2416 |
| 2417 R visitFunctionExpression(FunctionExpression node); |
| 2418 |
| 2419 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node); |
| 2420 |
| 2421 R visitFunctionTypeAlias(FunctionTypeAlias functionTypeAlias); |
| 2422 |
| 2423 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node); |
| 2424 |
| 2425 R visitHideCombinator(HideCombinator node); |
| 2426 |
| 2427 R visitIfStatement(IfStatement node); |
| 2428 |
| 2429 R visitImplementsClause(ImplementsClause node); |
| 2430 |
| 2431 R visitImportDirective(ImportDirective node); |
| 2432 |
| 2433 R visitIndexExpression(IndexExpression node); |
| 2434 |
| 2435 R visitInstanceCreationExpression(InstanceCreationExpression node); |
| 2436 |
| 2437 R visitIntegerLiteral(IntegerLiteral node); |
| 2438 |
| 2439 R visitInterpolationExpression(InterpolationExpression node); |
| 2440 |
| 2441 R visitInterpolationString(InterpolationString node); |
| 2442 |
| 2443 R visitIsExpression(IsExpression node); |
| 2444 |
| 2445 R visitLabel(Label node); |
| 2446 |
| 2447 R visitLabeledStatement(LabeledStatement node); |
| 2448 |
| 2449 R visitLibraryDirective(LibraryDirective node); |
| 2450 |
| 2451 R visitLibraryIdentifier(LibraryIdentifier node); |
| 2452 |
| 2453 R visitListLiteral(ListLiteral node); |
| 2454 |
| 2455 R visitMapLiteral(MapLiteral node); |
| 2456 |
| 2457 R visitMapLiteralEntry(MapLiteralEntry node); |
| 2458 |
| 2459 R visitMethodDeclaration(MethodDeclaration node); |
| 2460 |
| 2461 R visitMethodInvocation(MethodInvocation node); |
| 2462 |
| 2463 R visitNamedExpression(NamedExpression node); |
| 2464 |
| 2465 R visitNativeClause(NativeClause node); |
| 2466 |
| 2467 R visitNativeFunctionBody(NativeFunctionBody node); |
| 2468 |
| 2469 R visitNullLiteral(NullLiteral node); |
| 2470 |
| 2471 R visitParenthesizedExpression(ParenthesizedExpression node); |
| 2472 |
| 2473 R visitPartDirective(PartDirective node); |
| 2474 |
| 2475 R visitPartOfDirective(PartOfDirective node); |
| 2476 |
| 2477 R visitPostfixExpression(PostfixExpression node); |
| 2478 |
| 2479 R visitPrefixedIdentifier(PrefixedIdentifier node); |
| 2480 |
| 2481 R visitPrefixExpression(PrefixExpression node); |
| 2482 |
| 2483 R visitPropertyAccess(PropertyAccess node); |
| 2484 |
| 2485 R visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node)
; |
| 2486 |
| 2487 R visitRethrowExpression(RethrowExpression node); |
| 2488 |
| 2489 R visitReturnStatement(ReturnStatement node); |
| 2490 |
| 2491 R visitScriptTag(ScriptTag node); |
| 2492 |
| 2493 R visitShowCombinator(ShowCombinator node); |
| 2494 |
| 2495 R visitSimpleFormalParameter(SimpleFormalParameter node); |
| 2496 |
| 2497 R visitSimpleIdentifier(SimpleIdentifier node); |
| 2498 |
| 2499 R visitSimpleStringLiteral(SimpleStringLiteral node); |
| 2500 |
| 2501 R visitStringInterpolation(StringInterpolation node); |
| 2502 |
| 2503 R visitSuperConstructorInvocation(SuperConstructorInvocation node); |
| 2504 |
| 2505 R visitSuperExpression(SuperExpression node); |
| 2506 |
| 2507 R visitSwitchCase(SwitchCase node); |
| 2508 |
| 2509 R visitSwitchDefault(SwitchDefault node); |
| 2510 |
| 2511 R visitSwitchStatement(SwitchStatement node); |
| 2512 |
| 2513 R visitSymbolLiteral(SymbolLiteral node); |
| 2514 |
| 2515 R visitThisExpression(ThisExpression node); |
| 2516 |
| 2517 R visitThrowExpression(ThrowExpression node); |
| 2518 |
| 2519 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node); |
| 2520 |
| 2521 R visitTryStatement(TryStatement node); |
| 2522 |
| 2523 R visitTypeArgumentList(TypeArgumentList node); |
| 2524 |
| 2525 R visitTypeName(TypeName node); |
| 2526 |
| 2527 R visitTypeParameter(TypeParameter node); |
| 2528 |
| 2529 R visitTypeParameterList(TypeParameterList node); |
| 2530 |
| 2531 R visitVariableDeclaration(VariableDeclaration node); |
| 2532 |
| 2533 R visitVariableDeclarationList(VariableDeclarationList node); |
| 2534 |
| 2535 R visitVariableDeclarationStatement(VariableDeclarationStatement node); |
| 2536 |
| 2537 R visitWhileStatement(WhileStatement node); |
| 2538 |
| 2539 R visitWithClause(WithClause node); |
| 2540 |
| 2541 R visitYieldStatement(YieldStatement node); |
| 2542 } |
| 2543 |
| 2544 /** |
| 2545 * Instances of the class `AwaitExpression` implement an await expression. |
| 2546 */ |
| 2547 class AwaitExpression extends Expression { |
| 2548 /** |
| 2549 * The 'await' keyword. |
| 2550 */ |
| 2551 Token awaitKeyword; |
| 2552 |
| 2553 /** |
| 2554 * The expression whose value is being waited on. |
| 2555 */ |
| 2556 Expression _expression; |
| 2557 |
| 2558 /** |
| 2559 * Initialize a newly created await expression. |
| 2560 * |
| 2561 * @param awaitKeyword the 'await' keyword |
| 2562 * @param expression the expression whose value is being waited on |
| 2563 */ |
| 2564 AwaitExpression(this.awaitKeyword, Expression expression) { |
| 2565 this._expression = becomeParentOf(expression); |
| 2566 } |
| 2567 |
| 2568 @override |
| 2569 accept(AstVisitor visitor) => visitor.visitAwaitExpression(this); |
| 2570 |
| 2571 @override |
| 2572 Token get beginToken { |
| 2573 if (awaitKeyword != null) { |
| 2574 return awaitKeyword; |
| 2575 } |
| 2576 return _expression.beginToken; |
| 2577 } |
| 2578 |
| 2579 @override |
| 2580 Token get endToken => _expression.endToken; |
| 2581 |
| 2582 /** |
| 2583 * Return the expression whose value is being waited on. |
| 2584 * |
| 2585 * @return the expression whose value is being waited on |
| 2586 */ |
| 2587 Expression get expression => _expression; |
| 2588 |
| 2589 @override |
| 2590 int get precedence => 0; |
| 2591 |
| 2592 /** |
| 2593 * Set the expression whose value is being waited on to the given expression. |
| 2594 * |
| 2595 * @param expression the expression whose value is being waited on |
| 2596 */ |
| 2597 void set expression(Expression expression) { |
| 2598 this._expression = becomeParentOf(expression); |
| 2599 } |
| 2600 |
| 2601 @override |
| 2602 void visitChildren(AstVisitor visitor) { |
| 2603 safelyVisitChild(_expression, visitor); |
| 2604 } |
| 2605 } |
| 2606 |
| 2607 /** |
| 2608 * Instances of the class `BinaryExpression` represent a binary (infix) expressi
on. |
| 2609 * |
| 2610 * <pre> |
| 2611 * binaryExpression ::= |
| 2612 * [Expression] [Token] [Expression] |
| 2613 * </pre> |
| 2614 */ |
| 2615 class BinaryExpression extends Expression { |
| 2616 /** |
| 2617 * The expression used to compute the left operand. |
| 2618 */ |
| 2619 Expression _leftOperand; |
| 2620 |
| 2621 /** |
| 2622 * The binary operator being applied. |
| 2623 */ |
| 2624 Token operator; |
| 2625 |
| 2626 /** |
| 2627 * The expression used to compute the right operand. |
| 2628 */ |
| 2629 Expression _rightOperand; |
| 2630 |
| 2631 /** |
| 2632 * The element associated with the operator based on the static type of the le
ft operand, or |
| 2633 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 2634 * or if the operator could not be resolved. |
| 2635 */ |
| 2636 MethodElement _staticElement; |
| 2637 |
| 2638 /** |
| 2639 * The element associated with the operator based on the propagated type of th
e left operand, or |
| 2640 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 2641 * or if the operator could not be resolved. |
| 2642 */ |
| 2643 MethodElement _propagatedElement; |
| 2644 |
| 2645 /** |
| 2646 * Initialize a newly created binary expression. |
| 2647 * |
| 2648 * @param leftOperand the expression used to compute the left operand |
| 2649 * @param operator the binary operator being applied |
| 2650 * @param rightOperand the expression used to compute the right operand |
| 2651 */ |
| 2652 BinaryExpression(Expression leftOperand, this.operator, Expression rightOperan
d) { |
| 2653 this._leftOperand = becomeParentOf(leftOperand); |
| 2654 this._rightOperand = becomeParentOf(rightOperand); |
| 2655 } |
| 2656 |
| 2657 @override |
| 2658 accept(AstVisitor visitor) => visitor.visitBinaryExpression(this); |
| 2659 |
| 2660 @override |
| 2661 Token get beginToken => _leftOperand.beginToken; |
| 2662 |
| 2663 /** |
| 2664 * Return the best element available for this operator. If resolution was able
to find a better |
| 2665 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 2666 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 2667 * then `null` will be returned. |
| 2668 * |
| 2669 * @return the best element available for this operator |
| 2670 */ |
| 2671 MethodElement get bestElement { |
| 2672 MethodElement element = propagatedElement; |
| 2673 if (element == null) { |
| 2674 element = staticElement; |
| 2675 } |
| 2676 return element; |
| 2677 } |
| 2678 |
| 2679 @override |
| 2680 Token get endToken => _rightOperand.endToken; |
| 2681 |
| 2682 /** |
| 2683 * Return the expression used to compute the left operand. |
| 2684 * |
| 2685 * @return the expression used to compute the left operand |
| 2686 */ |
| 2687 Expression get leftOperand => _leftOperand; |
| 2688 |
| 2689 @override |
| 2690 int get precedence => operator.type.precedence; |
| 2691 |
| 2692 /** |
| 2693 * Return the element associated with the operator based on the propagated typ
e of the left |
| 2694 * operand, or `null` if the AST structure has not been resolved, if the opera
tor is not |
| 2695 * user definable, or if the operator could not be resolved. One example of th
e latter case is an |
| 2696 * operator that is not defined for the type of the left-hand operand. |
| 2697 * |
| 2698 * @return the element associated with the operator |
| 2699 */ |
| 2700 MethodElement get propagatedElement => _propagatedElement; |
| 2701 |
| 2702 /** |
| 2703 * Return the expression used to compute the right operand. |
| 2704 * |
| 2705 * @return the expression used to compute the right operand |
| 2706 */ |
| 2707 Expression get rightOperand => _rightOperand; |
| 2708 |
| 2709 /** |
| 2710 * Return the element associated with the operator based on the static type of
the left operand, |
| 2711 * or `null` if the AST structure has not been resolved, if the operator is no
t user |
| 2712 * definable, or if the operator could not be resolved. One example of the lat
ter case is an |
| 2713 * operator that is not defined for the type of the left operand. |
| 2714 * |
| 2715 * @return the element associated with the operator |
| 2716 */ |
| 2717 MethodElement get staticElement => _staticElement; |
| 2718 |
| 2719 /** |
| 2720 * Set the expression used to compute the left operand to the given expression
. |
| 2721 * |
| 2722 * @param expression the expression used to compute the left operand |
| 2723 */ |
| 2724 void set leftOperand(Expression expression) { |
| 2725 _leftOperand = becomeParentOf(expression); |
| 2726 } |
| 2727 |
| 2728 /** |
| 2729 * Set the element associated with the operator based on the propagated type o
f the left operand |
| 2730 * to the given element. |
| 2731 * |
| 2732 * @param element the element to be associated with the operator |
| 2733 */ |
| 2734 void set propagatedElement(MethodElement element) { |
| 2735 _propagatedElement = element; |
| 2736 } |
| 2737 |
| 2738 /** |
| 2739 * Set the expression used to compute the right operand to the given expressio
n. |
| 2740 * |
| 2741 * @param expression the expression used to compute the right operand |
| 2742 */ |
| 2743 void set rightOperand(Expression expression) { |
| 2744 _rightOperand = becomeParentOf(expression); |
| 2745 } |
| 2746 |
| 2747 /** |
| 2748 * Set the element associated with the operator based on the static type of th
e left operand to |
| 2749 * the given element. |
| 2750 * |
| 2751 * @param element the static element to be associated with the operator |
| 2752 */ |
| 2753 void set staticElement(MethodElement element) { |
| 2754 _staticElement = element; |
| 2755 } |
| 2756 |
| 2757 @override |
| 2758 void visitChildren(AstVisitor visitor) { |
| 2759 safelyVisitChild(_leftOperand, visitor); |
| 2760 safelyVisitChild(_rightOperand, visitor); |
| 2761 } |
| 2762 |
| 2763 /** |
| 2764 * If the AST structure has been resolved, and the function being invoked is k
nown based on |
| 2765 * propagated type information, then return the parameter element representing
the parameter to |
| 2766 * which the value of the right operand will be bound. Otherwise, return `null
`. |
| 2767 * |
| 2768 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 2769 * |
| 2770 * @return the parameter element representing the parameter to which the value
of the right |
| 2771 * operand will be bound |
| 2772 */ |
| 2773 ParameterElement get propagatedParameterElementForRightOperand { |
| 2774 if (_propagatedElement == null) { |
| 2775 return null; |
| 2776 } |
| 2777 List<ParameterElement> parameters = _propagatedElement.parameters; |
| 2778 if (parameters.length < 1) { |
| 2779 return null; |
| 2780 } |
| 2781 return parameters[0]; |
| 2782 } |
| 2783 |
| 2784 /** |
| 2785 * If the AST structure has been resolved, and the function being invoked is k
nown based on static |
| 2786 * type information, then return the parameter element representing the parame
ter to which the |
| 2787 * value of the right operand will be bound. Otherwise, return `null`. |
| 2788 * |
| 2789 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 2790 * |
| 2791 * @return the parameter element representing the parameter to which the value
of the right |
| 2792 * operand will be bound |
| 2793 */ |
| 2794 ParameterElement get staticParameterElementForRightOperand { |
| 2795 if (_staticElement == null) { |
| 2796 return null; |
| 2797 } |
| 2798 List<ParameterElement> parameters = _staticElement.parameters; |
| 2799 if (parameters.length < 1) { |
| 2800 return null; |
| 2801 } |
| 2802 return parameters[0]; |
| 2803 } |
| 2804 } |
| 2805 |
| 2806 /** |
| 2807 * Instances of the class `Block` represent a sequence of statements. |
| 2808 * |
| 2809 * <pre> |
| 2810 * block ::= |
| 2811 * '{' statement* '}' |
| 2812 * </pre> |
| 2813 */ |
| 2814 class Block extends Statement { |
| 2815 /** |
| 2816 * The left curly bracket. |
| 2817 */ |
| 2818 Token leftBracket; |
| 2819 |
| 2820 /** |
| 2821 * The statements contained in the block. |
| 2822 */ |
| 2823 NodeList<Statement> _statements; |
| 2824 |
| 2825 /** |
| 2826 * The right curly bracket. |
| 2827 */ |
| 2828 Token rightBracket; |
| 2829 |
| 2830 /** |
| 2831 * Initialize a newly created block of code. |
| 2832 * |
| 2833 * @param leftBracket the left curly bracket |
| 2834 * @param statements the statements contained in the block |
| 2835 * @param rightBracket the right curly bracket |
| 2836 */ |
| 2837 Block(this.leftBracket, List<Statement> statements, this.rightBracket) { |
| 2838 this._statements = new NodeList<Statement>(this); |
| 2839 this._statements.addAll(statements); |
| 2840 } |
| 2841 |
| 2842 @override |
| 2843 accept(AstVisitor visitor) => visitor.visitBlock(this); |
| 2844 |
| 2845 @override |
| 2846 Token get beginToken => leftBracket; |
| 2847 |
| 2848 @override |
| 2849 Token get endToken => rightBracket; |
| 2850 |
| 2851 /** |
| 2852 * Return the statements contained in the block. |
| 2853 * |
| 2854 * @return the statements contained in the block |
| 2855 */ |
| 2856 NodeList<Statement> get statements => _statements; |
| 2857 |
| 2858 @override |
| 2859 void visitChildren(AstVisitor visitor) { |
| 2860 _statements.accept(visitor); |
| 2861 } |
| 2862 } |
| 2863 |
| 2864 /** |
| 2865 * Instances of the class `BlockFunctionBody` represent a function body that con
sists of a |
| 2866 * block of statements. |
| 2867 * |
| 2868 * <pre> |
| 2869 * blockFunctionBody ::= |
| 2870 * ('async' | 'async' '*' | 'sync' '*')? [Block] |
| 2871 * </pre> |
| 2872 */ |
| 2873 class BlockFunctionBody extends FunctionBody { |
| 2874 /** |
| 2875 * The token representing the 'async' or 'sync' keyword, or `null` if there is
no such |
| 2876 * keyword. |
| 2877 */ |
| 2878 Token keyword; |
| 2879 |
| 2880 /** |
| 2881 * The star optionally following the 'async' or following the 'sync' keyword. |
| 2882 */ |
| 2883 Token star; |
| 2884 |
| 2885 /** |
| 2886 * The block representing the body of the function. |
| 2887 */ |
| 2888 Block _block; |
| 2889 |
| 2890 /** |
| 2891 * Initialize a newly created function body consisting of a block of statement
s. |
| 2892 * |
| 2893 * @param keyword the token representing the 'async' or 'sync' keyword |
| 2894 * @param star the star following the 'async' or 'sync' keyword |
| 2895 * @param block the block representing the body of the function |
| 2896 */ |
| 2897 BlockFunctionBody(this.keyword, this.star, Block block) { |
| 2898 this._block = becomeParentOf(block); |
| 2899 } |
| 2900 |
| 2901 @override |
| 2902 accept(AstVisitor visitor) => visitor.visitBlockFunctionBody(this); |
| 2903 |
| 2904 @override |
| 2905 Token get beginToken => _block.beginToken; |
| 2906 |
| 2907 /** |
| 2908 * Return the block representing the body of the function. |
| 2909 * |
| 2910 * @return the block representing the body of the function |
| 2911 */ |
| 2912 Block get block => _block; |
| 2913 |
| 2914 @override |
| 2915 Token get endToken => _block.endToken; |
| 2916 |
| 2917 @override |
| 2918 bool get isAsynchronous { |
| 2919 if (keyword == null) { |
| 2920 return false; |
| 2921 } |
| 2922 String keywordValue = keyword.lexeme; |
| 2923 return keywordValue == Parser.ASYNC; |
| 2924 } |
| 2925 |
| 2926 @override |
| 2927 bool get isGenerator => star != null; |
| 2928 |
| 2929 @override |
| 2930 bool get isSynchronous => keyword == null || keyword.lexeme != Parser.ASYNC; |
| 2931 |
| 2932 /** |
| 2933 * Set the block representing the body of the function to the given block. |
| 2934 * |
| 2935 * @param block the block representing the body of the function |
| 2936 */ |
| 2937 void set block(Block block) { |
| 2938 this._block = becomeParentOf(block); |
| 2939 } |
| 2940 |
| 2941 @override |
| 2942 void visitChildren(AstVisitor visitor) { |
| 2943 safelyVisitChild(_block, visitor); |
| 2944 } |
| 2945 } |
| 2946 |
| 2947 /** |
| 2948 * Instances of the class `BooleanLiteral` represent a boolean literal expressio
n. |
| 2949 * |
| 2950 * <pre> |
| 2951 * booleanLiteral ::= |
| 2952 * 'false' | 'true' |
| 2953 * </pre> |
| 2954 */ |
| 2955 class BooleanLiteral extends Literal { |
| 2956 /** |
| 2957 * The token representing the literal. |
| 2958 */ |
| 2959 Token literal; |
| 2960 |
| 2961 /** |
| 2962 * The value of the literal. |
| 2963 */ |
| 2964 bool value = false; |
| 2965 |
| 2966 /** |
| 2967 * Initialize a newly created boolean literal. |
| 2968 * |
| 2969 * @param literal the token representing the literal |
| 2970 * @param value the value of the literal |
| 2971 */ |
| 2972 BooleanLiteral(this.literal, this.value); |
| 2973 |
| 2974 @override |
| 2975 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this); |
| 2976 |
| 2977 @override |
| 2978 Token get beginToken => literal; |
| 2979 |
| 2980 @override |
| 2981 Token get endToken => literal; |
| 2982 |
| 2983 @override |
| 2984 bool get isSynthetic => literal.isSynthetic; |
| 2985 |
| 2986 @override |
| 2987 void visitChildren(AstVisitor visitor) { |
| 2988 } |
| 2989 } |
| 2990 |
| 2991 /** |
| 2992 * Instances of the class `BreadthFirstVisitor` implement an AST visitor that wi
ll recursively |
| 2993 * visit all of the nodes in an AST structure, similar to [GeneralizingAstVisito
r]. This |
| 2994 * visitor uses a breadth-first ordering rather than the depth-first ordering of |
| 2995 * [GeneralizingAstVisitor]. |
| 2996 * |
| 2997 * Subclasses that override a visit method must either invoke the overridden vis
it method or |
| 2998 * explicitly invoke the more general visit method. Failure to do so will cause
the visit methods |
| 2999 * for superclasses of the node to not be invoked and will cause the children of
the visited node to |
| 3000 * not be visited. |
| 3001 * |
| 3002 * In addition, subclasses should <b>not</b> explicitly visit the children of a
node, but should |
| 3003 * ensure that the method [visitNode] is used to visit the children (either dire
ctly |
| 3004 * or indirectly). Failure to do will break the order in which nodes are visited
. |
| 3005 */ |
| 3006 class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> { |
| 3007 /** |
| 3008 * A queue holding the nodes that have not yet been visited in the order in wh
ich they ought to be |
| 3009 * visited. |
| 3010 */ |
| 3011 Queue<AstNode> _queue = new Queue<AstNode>(); |
| 3012 |
| 3013 /** |
| 3014 * A visitor, used to visit the children of the current node, that will add th
e nodes it visits to |
| 3015 * the [queue]. |
| 3016 */ |
| 3017 GeneralizingAstVisitor<Object> _childVisitor; |
| 3018 |
| 3019 /** |
| 3020 * Visit all nodes in the tree starting at the given `root` node, in breadth-f
irst order. |
| 3021 * |
| 3022 * @param root the root of the AST structure to be visited |
| 3023 */ |
| 3024 void visitAllNodes(AstNode root) { |
| 3025 _queue.add(root); |
| 3026 while (!_queue.isEmpty) { |
| 3027 AstNode next = _queue.removeFirst(); |
| 3028 next.accept(this); |
| 3029 } |
| 3030 } |
| 3031 |
| 3032 @override |
| 3033 R visitNode(AstNode node) { |
| 3034 node.visitChildren(_childVisitor); |
| 3035 return null; |
| 3036 } |
| 3037 |
| 3038 BreadthFirstVisitor() { |
| 3039 this._childVisitor = new GeneralizingAstVisitor_BreadthFirstVisitor(this); |
| 3040 } |
| 3041 } |
| 3042 |
| 3043 /** |
| 3044 * Instances of the class `BreakStatement` represent a break statement. |
| 3045 * |
| 3046 * <pre> |
| 3047 * breakStatement ::= |
| 3048 * 'break' [SimpleIdentifier]? ';' |
| 3049 * </pre> |
| 3050 */ |
| 3051 class BreakStatement extends Statement { |
| 3052 /** |
| 3053 * The token representing the 'break' keyword. |
| 3054 */ |
| 3055 Token keyword; |
| 3056 |
| 3057 /** |
| 3058 * The label associated with the statement, or `null` if there is no label. |
| 3059 */ |
| 3060 SimpleIdentifier _label; |
| 3061 |
| 3062 /** |
| 3063 * The semicolon terminating the statement. |
| 3064 */ |
| 3065 Token semicolon; |
| 3066 |
| 3067 /** |
| 3068 * Initialize a newly created break statement. |
| 3069 * |
| 3070 * @param keyword the token representing the 'break' keyword |
| 3071 * @param label the label associated with the statement |
| 3072 * @param semicolon the semicolon terminating the statement |
| 3073 */ |
| 3074 BreakStatement(this.keyword, SimpleIdentifier label, this.semicolon) { |
| 3075 this._label = becomeParentOf(label); |
| 3076 } |
| 3077 |
| 3078 @override |
| 3079 accept(AstVisitor visitor) => visitor.visitBreakStatement(this); |
| 3080 |
| 3081 @override |
| 3082 Token get beginToken => keyword; |
| 3083 |
| 3084 @override |
| 3085 Token get endToken => semicolon; |
| 3086 |
| 3087 /** |
| 3088 * Return the label associated with the statement, or `null` if there is no la
bel. |
| 3089 * |
| 3090 * @return the label associated with the statement |
| 3091 */ |
| 3092 SimpleIdentifier get label => _label; |
| 3093 |
| 3094 /** |
| 3095 * Set the label associated with the statement to the given identifier. |
| 3096 * |
| 3097 * @param identifier the label associated with the statement |
| 3098 */ |
| 3099 void set label(SimpleIdentifier identifier) { |
| 3100 _label = becomeParentOf(identifier); |
| 3101 } |
| 3102 |
| 3103 @override |
| 3104 void visitChildren(AstVisitor visitor) { |
| 3105 safelyVisitChild(_label, visitor); |
| 3106 } |
| 3107 } |
| 3108 |
| 3109 /** |
| 3110 * Instances of the class `CascadeExpression` represent a sequence of cascaded e
xpressions: |
| 3111 * expressions that share a common target. There are three kinds of expressions
that can be used in |
| 3112 * a cascade expression: [IndexExpression], [MethodInvocation] and |
| 3113 * [PropertyAccess]. |
| 3114 * |
| 3115 * <pre> |
| 3116 * cascadeExpression ::= |
| 3117 * [Expression] cascadeSection* |
| 3118 * |
| 3119 * cascadeSection ::= |
| 3120 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* (assi
gnmentOperator expressionWithoutCascade)? |
| 3121 * |
| 3122 * cascadeSelector ::= |
| 3123 * '[ ' expression '] ' |
| 3124 * | identifier |
| 3125 * </pre> |
| 3126 */ |
| 3127 class CascadeExpression extends Expression { |
| 3128 /** |
| 3129 * The target of the cascade sections. |
| 3130 */ |
| 3131 Expression _target; |
| 3132 |
| 3133 /** |
| 3134 * The cascade sections sharing the common target. |
| 3135 */ |
| 3136 NodeList<Expression> _cascadeSections; |
| 3137 |
| 3138 /** |
| 3139 * Initialize a newly created cascade expression. |
| 3140 * |
| 3141 * @param target the target of the cascade sections |
| 3142 * @param cascadeSections the cascade sections sharing the common target |
| 3143 */ |
| 3144 CascadeExpression(Expression target, List<Expression> cascadeSections) { |
| 3145 this._cascadeSections = new NodeList<Expression>(this); |
| 3146 this._target = becomeParentOf(target); |
| 3147 this._cascadeSections.addAll(cascadeSections); |
| 3148 } |
| 3149 |
| 3150 @override |
| 3151 accept(AstVisitor visitor) => visitor.visitCascadeExpression(this); |
| 3152 |
| 3153 @override |
| 3154 Token get beginToken => _target.beginToken; |
| 3155 |
| 3156 /** |
| 3157 * Return the cascade sections sharing the common target. |
| 3158 * |
| 3159 * @return the cascade sections sharing the common target |
| 3160 */ |
| 3161 NodeList<Expression> get cascadeSections => _cascadeSections; |
| 3162 |
| 3163 @override |
| 3164 Token get endToken => _cascadeSections.endToken; |
| 3165 |
| 3166 @override |
| 3167 int get precedence => 2; |
| 3168 |
| 3169 /** |
| 3170 * Return the target of the cascade sections. |
| 3171 * |
| 3172 * @return the target of the cascade sections |
| 3173 */ |
| 3174 Expression get target => _target; |
| 3175 |
| 3176 /** |
| 3177 * Set the target of the cascade sections to the given expression. |
| 3178 * |
| 3179 * @param target the target of the cascade sections |
| 3180 */ |
| 3181 void set target(Expression target) { |
| 3182 this._target = becomeParentOf(target); |
| 3183 } |
| 3184 |
| 3185 @override |
| 3186 void visitChildren(AstVisitor visitor) { |
| 3187 safelyVisitChild(_target, visitor); |
| 3188 _cascadeSections.accept(visitor); |
| 3189 } |
| 3190 } |
| 3191 |
| 3192 /** |
| 3193 * Instances of the class `CatchClause` represent a catch clause within a try st
atement. |
| 3194 * |
| 3195 * <pre> |
| 3196 * onPart ::= |
| 3197 * catchPart [Block] |
| 3198 * | 'on' type catchPart? [Block] |
| 3199 * |
| 3200 * catchPart ::= |
| 3201 * 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')' |
| 3202 * </pre> |
| 3203 */ |
| 3204 class CatchClause extends AstNode { |
| 3205 /** |
| 3206 * The token representing the 'on' keyword, or `null` if there is no 'on' keyw
ord. |
| 3207 */ |
| 3208 Token onKeyword; |
| 3209 |
| 3210 /** |
| 3211 * The type of exceptions caught by this catch clause, or `null` if this catch
clause |
| 3212 * catches every type of exception. |
| 3213 */ |
| 3214 TypeName _exceptionType; |
| 3215 |
| 3216 /** |
| 3217 * The token representing the 'catch' keyword, or `null` if there is no 'catch
' keyword. |
| 3218 */ |
| 3219 Token catchKeyword; |
| 3220 |
| 3221 /** |
| 3222 * The left parenthesis. |
| 3223 */ |
| 3224 Token _leftParenthesis; |
| 3225 |
| 3226 /** |
| 3227 * The parameter whose value will be the exception that was thrown. |
| 3228 */ |
| 3229 SimpleIdentifier _exceptionParameter; |
| 3230 |
| 3231 /** |
| 3232 * The comma separating the exception parameter from the stack trace parameter
, or `null` if |
| 3233 * there is no stack trace parameter. |
| 3234 */ |
| 3235 Token comma; |
| 3236 |
| 3237 /** |
| 3238 * The parameter whose value will be the stack trace associated with the excep
tion, or |
| 3239 * `null` if there is no stack trace parameter. |
| 3240 */ |
| 3241 SimpleIdentifier _stackTraceParameter; |
| 3242 |
| 3243 /** |
| 3244 * The right parenthesis. |
| 3245 */ |
| 3246 Token _rightParenthesis; |
| 3247 |
| 3248 /** |
| 3249 * The body of the catch block. |
| 3250 */ |
| 3251 Block _body; |
| 3252 |
| 3253 /** |
| 3254 * Initialize a newly created catch clause. |
| 3255 * |
| 3256 * @param onKeyword the token representing the 'on' keyword |
| 3257 * @param exceptionType the type of exceptions caught by this catch clause |
| 3258 * @param leftParenthesis the left parenthesis |
| 3259 * @param exceptionParameter the parameter whose value will be the exception t
hat was thrown |
| 3260 * @param comma the comma separating the exception parameter from the stack tr
ace parameter |
| 3261 * @param stackTraceParameter the parameter whose value will be the stack trac
e associated with |
| 3262 * the exception |
| 3263 * @param rightParenthesis the right parenthesis |
| 3264 * @param body the body of the catch block |
| 3265 */ |
| 3266 CatchClause(this.onKeyword, TypeName exceptionType, this.catchKeyword, Token l
eftParenthesis, SimpleIdentifier exceptionParameter, this.comma, SimpleIdentifie
r stackTraceParameter, Token rightParenthesis, Block body) { |
| 3267 this._exceptionType = becomeParentOf(exceptionType); |
| 3268 this._leftParenthesis = leftParenthesis; |
| 3269 this._exceptionParameter = becomeParentOf(exceptionParameter); |
| 3270 this._stackTraceParameter = becomeParentOf(stackTraceParameter); |
| 3271 this._rightParenthesis = rightParenthesis; |
| 3272 this._body = becomeParentOf(body); |
| 3273 } |
| 3274 |
| 3275 @override |
| 3276 accept(AstVisitor visitor) => visitor.visitCatchClause(this); |
| 3277 |
| 3278 @override |
| 3279 Token get beginToken { |
| 3280 if (onKeyword != null) { |
| 3281 return onKeyword; |
| 3282 } |
| 3283 return catchKeyword; |
| 3284 } |
| 3285 |
| 3286 /** |
| 3287 * Return the body of the catch block. |
| 3288 * |
| 3289 * @return the body of the catch block |
| 3290 */ |
| 3291 Block get body => _body; |
| 3292 |
| 3293 @override |
| 3294 Token get endToken => _body.endToken; |
| 3295 |
| 3296 /** |
| 3297 * Return the parameter whose value will be the exception that was thrown. |
| 3298 * |
| 3299 * @return the parameter whose value will be the exception that was thrown |
| 3300 */ |
| 3301 SimpleIdentifier get exceptionParameter => _exceptionParameter; |
| 3302 |
| 3303 /** |
| 3304 * Return the type of exceptions caught by this catch clause, or `null` if thi
s catch clause |
| 3305 * catches every type of exception. |
| 3306 * |
| 3307 * @return the type of exceptions caught by this catch clause |
| 3308 */ |
| 3309 TypeName get exceptionType => _exceptionType; |
| 3310 |
| 3311 /** |
| 3312 * Return the left parenthesis. |
| 3313 * |
| 3314 * @return the left parenthesis |
| 3315 */ |
| 3316 Token get leftParenthesis => _leftParenthesis; |
| 3317 |
| 3318 /** |
| 3319 * Return the right parenthesis. |
| 3320 * |
| 3321 * @return the right parenthesis |
| 3322 */ |
| 3323 Token get rightParenthesis => _rightParenthesis; |
| 3324 |
| 3325 /** |
| 3326 * Return the parameter whose value will be the stack trace associated with th
e exception, or |
| 3327 * `null` if there is no stack trace parameter. |
| 3328 * |
| 3329 * @return the parameter whose value will be the stack trace associated with t
he exception |
| 3330 */ |
| 3331 SimpleIdentifier get stackTraceParameter => _stackTraceParameter; |
| 3332 |
| 3333 /** |
| 3334 * Set the body of the catch block to the given block. |
| 3335 * |
| 3336 * @param block the body of the catch block |
| 3337 */ |
| 3338 void set body(Block block) { |
| 3339 _body = becomeParentOf(block); |
| 3340 } |
| 3341 |
| 3342 /** |
| 3343 * Set the parameter whose value will be the exception that was thrown to the
given parameter. |
| 3344 * |
| 3345 * @param parameter the parameter whose value will be the exception that was t
hrown |
| 3346 */ |
| 3347 void set exceptionParameter(SimpleIdentifier parameter) { |
| 3348 _exceptionParameter = becomeParentOf(parameter); |
| 3349 } |
| 3350 |
| 3351 /** |
| 3352 * Set the type of exceptions caught by this catch clause to the given type. |
| 3353 * |
| 3354 * @param exceptionType the type of exceptions caught by this catch clause |
| 3355 */ |
| 3356 void set exceptionType(TypeName exceptionType) { |
| 3357 this._exceptionType = becomeParentOf(exceptionType); |
| 3358 } |
| 3359 |
| 3360 /** |
| 3361 * Set the left parenthesis to the given token. |
| 3362 * |
| 3363 * @param parenthesis the left parenthesis |
| 3364 */ |
| 3365 void set leftParenthesis(Token parenthesis) { |
| 3366 _leftParenthesis = parenthesis; |
| 3367 } |
| 3368 |
| 3369 /** |
| 3370 * Set the right parenthesis to the given token. |
| 3371 * |
| 3372 * @param parenthesis the right parenthesis |
| 3373 */ |
| 3374 void set rightParenthesis(Token parenthesis) { |
| 3375 _rightParenthesis = parenthesis; |
| 3376 } |
| 3377 |
| 3378 /** |
| 3379 * Set the parameter whose value will be the stack trace associated with the e
xception to the |
| 3380 * given parameter. |
| 3381 * |
| 3382 * @param parameter the parameter whose value will be the stack trace associat
ed with the |
| 3383 * exception |
| 3384 */ |
| 3385 void set stackTraceParameter(SimpleIdentifier parameter) { |
| 3386 _stackTraceParameter = becomeParentOf(parameter); |
| 3387 } |
| 3388 |
| 3389 @override |
| 3390 void visitChildren(AstVisitor visitor) { |
| 3391 safelyVisitChild(_exceptionType, visitor); |
| 3392 safelyVisitChild(_exceptionParameter, visitor); |
| 3393 safelyVisitChild(_stackTraceParameter, visitor); |
| 3394 safelyVisitChild(_body, visitor); |
| 3395 } |
| 3396 } |
| 3397 |
| 3398 /** |
| 3399 * Instances of the class `ClassDeclaration` represent the declaration of a clas
s. |
| 3400 * |
| 3401 * <pre> |
| 3402 * classDeclaration ::= |
| 3403 * 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]? |
| 3404 * ([ExtendsClause] [WithClause]?)? |
| 3405 * [ImplementsClause]? |
| 3406 * '{' [ClassMember]* '}' |
| 3407 * </pre> |
| 3408 */ |
| 3409 class ClassDeclaration extends CompilationUnitMember { |
| 3410 /** |
| 3411 * The 'abstract' keyword, or `null` if the keyword was absent. |
| 3412 */ |
| 3413 Token abstractKeyword; |
| 3414 |
| 3415 /** |
| 3416 * The token representing the 'class' keyword. |
| 3417 */ |
| 3418 Token classKeyword; |
| 3419 |
| 3420 /** |
| 3421 * The name of the class being declared. |
| 3422 */ |
| 3423 SimpleIdentifier _name; |
| 3424 |
| 3425 /** |
| 3426 * The type parameters for the class, or `null` if the class does not have any
type |
| 3427 * parameters. |
| 3428 */ |
| 3429 TypeParameterList _typeParameters; |
| 3430 |
| 3431 /** |
| 3432 * The extends clause for the class, or `null` if the class does not extend an
y other class. |
| 3433 */ |
| 3434 ExtendsClause _extendsClause; |
| 3435 |
| 3436 /** |
| 3437 * The with clause for the class, or `null` if the class does not have a with
clause. |
| 3438 */ |
| 3439 WithClause _withClause; |
| 3440 |
| 3441 /** |
| 3442 * The implements clause for the class, or `null` if the class does not implem
ent any |
| 3443 * interfaces. |
| 3444 */ |
| 3445 ImplementsClause _implementsClause; |
| 3446 |
| 3447 /** |
| 3448 * The native clause for the class, or `null` if the class does not have a nat
ive clause. |
| 3449 */ |
| 3450 NativeClause _nativeClause; |
| 3451 |
| 3452 /** |
| 3453 * The left curly bracket. |
| 3454 */ |
| 3455 Token leftBracket; |
| 3456 |
| 3457 /** |
| 3458 * The members defined by the class. |
| 3459 */ |
| 3460 NodeList<ClassMember> _members; |
| 3461 |
| 3462 /** |
| 3463 * The right curly bracket. |
| 3464 */ |
| 3465 Token rightBracket; |
| 3466 |
| 3467 /** |
| 3468 * Initialize a newly created class declaration. |
| 3469 * |
| 3470 * @param comment the documentation comment associated with this class |
| 3471 * @param metadata the annotations associated with this class |
| 3472 * @param abstractKeyword the 'abstract' keyword, or `null` if the keyword was
absent |
| 3473 * @param classKeyword the token representing the 'class' keyword |
| 3474 * @param name the name of the class being declared |
| 3475 * @param typeParameters the type parameters for the class |
| 3476 * @param extendsClause the extends clause for the class |
| 3477 * @param withClause the with clause for the class |
| 3478 * @param implementsClause the implements clause for the class |
| 3479 * @param leftBracket the left curly bracket |
| 3480 * @param members the members defined by the class |
| 3481 * @param rightBracket the right curly bracket |
| 3482 */ |
| 3483 ClassDeclaration(Comment comment, List<Annotation> metadata, this.abstractKeyw
ord, this.classKeyword, SimpleIdentifier name, TypeParameterList typeParameters,
ExtendsClause extendsClause, WithClause withClause, ImplementsClause implements
Clause, this.leftBracket, List<ClassMember> members, this.rightBracket) : super(
comment, metadata) { |
| 3484 this._members = new NodeList<ClassMember>(this); |
| 3485 this._name = becomeParentOf(name); |
| 3486 this._typeParameters = becomeParentOf(typeParameters); |
| 3487 this._extendsClause = becomeParentOf(extendsClause); |
| 3488 this._withClause = becomeParentOf(withClause); |
| 3489 this._implementsClause = becomeParentOf(implementsClause); |
| 3490 this._members.addAll(members); |
| 3491 } |
| 3492 |
| 3493 @override |
| 3494 accept(AstVisitor visitor) => visitor.visitClassDeclaration(this); |
| 3495 |
| 3496 /** |
| 3497 * Return the constructor declared in the class with the given name. |
| 3498 * |
| 3499 * @param name the name of the constructor to find, `null` for default |
| 3500 * @return the found constructor or `null` if not found |
| 3501 */ |
| 3502 ConstructorDeclaration getConstructor(String name) { |
| 3503 for (ClassMember classMember in _members) { |
| 3504 if (classMember is ConstructorDeclaration) { |
| 3505 ConstructorDeclaration constructor = classMember; |
| 3506 SimpleIdentifier constructorName = constructor.name; |
| 3507 if (name == null && constructorName == null) { |
| 3508 return constructor; |
| 3509 } |
| 3510 if (constructorName != null && constructorName.name == name) { |
| 3511 return constructor; |
| 3512 } |
| 3513 } |
| 3514 } |
| 3515 return null; |
| 3516 } |
| 3517 |
| 3518 @override |
| 3519 ClassElement get element => _name != null ? (_name.staticElement as ClassEleme
nt) : null; |
| 3520 |
| 3521 @override |
| 3522 Token get endToken => rightBracket; |
| 3523 |
| 3524 /** |
| 3525 * Return the extends clause for this class, or `null` if the class does not e
xtend any |
| 3526 * other class. |
| 3527 * |
| 3528 * @return the extends clause for this class |
| 3529 */ |
| 3530 ExtendsClause get extendsClause => _extendsClause; |
| 3531 |
| 3532 /** |
| 3533 * Return the field declared in the class with the given name. |
| 3534 * |
| 3535 * @param name the name of the field to find |
| 3536 * @return the found field or `null` if not found |
| 3537 */ |
| 3538 VariableDeclaration getField(String name) { |
| 3539 for (ClassMember classMember in _members) { |
| 3540 if (classMember is FieldDeclaration) { |
| 3541 FieldDeclaration fieldDeclaration = classMember; |
| 3542 NodeList<VariableDeclaration> fields = fieldDeclaration.fields.variables
; |
| 3543 for (VariableDeclaration field in fields) { |
| 3544 SimpleIdentifier fieldName = field.name; |
| 3545 if (fieldName != null && name == fieldName.name) { |
| 3546 return field; |
| 3547 } |
| 3548 } |
| 3549 } |
| 3550 } |
| 3551 return null; |
| 3552 } |
| 3553 |
| 3554 /** |
| 3555 * Return the implements clause for the class, or `null` if the class does not
implement any |
| 3556 * interfaces. |
| 3557 * |
| 3558 * @return the implements clause for the class |
| 3559 */ |
| 3560 ImplementsClause get implementsClause => _implementsClause; |
| 3561 |
| 3562 /** |
| 3563 * Return the members defined by the class. |
| 3564 * |
| 3565 * @return the members defined by the class |
| 3566 */ |
| 3567 NodeList<ClassMember> get members => _members; |
| 3568 |
| 3569 /** |
| 3570 * Return the method declared in the class with the given name. |
| 3571 * |
| 3572 * @param name the name of the method to find |
| 3573 * @return the found method or `null` if not found |
| 3574 */ |
| 3575 MethodDeclaration getMethod(String name) { |
| 3576 for (ClassMember classMember in _members) { |
| 3577 if (classMember is MethodDeclaration) { |
| 3578 MethodDeclaration method = classMember; |
| 3579 SimpleIdentifier methodName = method.name; |
| 3580 if (methodName != null && name == methodName.name) { |
| 3581 return method; |
| 3582 } |
| 3583 } |
| 3584 } |
| 3585 return null; |
| 3586 } |
| 3587 |
| 3588 /** |
| 3589 * Return the name of the class being declared. |
| 3590 * |
| 3591 * @return the name of the class being declared |
| 3592 */ |
| 3593 SimpleIdentifier get name => _name; |
| 3594 |
| 3595 /** |
| 3596 * Return the native clause for this class, or `null` if the class does not ha
ve a native |
| 3597 * cluse. |
| 3598 * |
| 3599 * @return the native clause for this class |
| 3600 */ |
| 3601 NativeClause get nativeClause => _nativeClause; |
| 3602 |
| 3603 /** |
| 3604 * Return the type parameters for the class, or `null` if the class does not h
ave any type |
| 3605 * parameters. |
| 3606 * |
| 3607 * @return the type parameters for the class |
| 3608 */ |
| 3609 TypeParameterList get typeParameters => _typeParameters; |
| 3610 |
| 3611 /** |
| 3612 * Return the with clause for the class, or `null` if the class does not have
a with clause. |
| 3613 * |
| 3614 * @return the with clause for the class |
| 3615 */ |
| 3616 WithClause get withClause => _withClause; |
| 3617 |
| 3618 /** |
| 3619 * Return `true` if this class is declared to be an abstract class. |
| 3620 * |
| 3621 * @return `true` if this class is declared to be an abstract class |
| 3622 */ |
| 3623 bool get isAbstract => abstractKeyword != null; |
| 3624 |
| 3625 /** |
| 3626 * Set the extends clause for this class to the given clause. |
| 3627 * |
| 3628 * @param extendsClause the extends clause for this class |
| 3629 */ |
| 3630 void set extendsClause(ExtendsClause extendsClause) { |
| 3631 this._extendsClause = becomeParentOf(extendsClause); |
| 3632 } |
| 3633 |
| 3634 /** |
| 3635 * Set the implements clause for the class to the given clause. |
| 3636 * |
| 3637 * @param implementsClause the implements clause for the class |
| 3638 */ |
| 3639 void set implementsClause(ImplementsClause implementsClause) { |
| 3640 this._implementsClause = becomeParentOf(implementsClause); |
| 3641 } |
| 3642 |
| 3643 /** |
| 3644 * Set the name of the class being declared to the given identifier. |
| 3645 * |
| 3646 * @param identifier the name of the class being declared |
| 3647 */ |
| 3648 void set name(SimpleIdentifier identifier) { |
| 3649 _name = becomeParentOf(identifier); |
| 3650 } |
| 3651 |
| 3652 /** |
| 3653 * Set the native clause for this class to the given clause. |
| 3654 * |
| 3655 * @param nativeClause the native clause for this class |
| 3656 */ |
| 3657 void set nativeClause(NativeClause nativeClause) { |
| 3658 this._nativeClause = becomeParentOf(nativeClause); |
| 3659 } |
| 3660 |
| 3661 /** |
| 3662 * Set the type parameters for the class to the given list of type parameters. |
| 3663 * |
| 3664 * @param typeParameters the type parameters for the class |
| 3665 */ |
| 3666 void set typeParameters(TypeParameterList typeParameters) { |
| 3667 this._typeParameters = becomeParentOf(typeParameters); |
| 3668 } |
| 3669 |
| 3670 /** |
| 3671 * Set the with clause for the class to the given clause. |
| 3672 * |
| 3673 * @param withClause the with clause for the class |
| 3674 */ |
| 3675 void set withClause(WithClause withClause) { |
| 3676 this._withClause = becomeParentOf(withClause); |
| 3677 } |
| 3678 |
| 3679 @override |
| 3680 void visitChildren(AstVisitor visitor) { |
| 3681 super.visitChildren(visitor); |
| 3682 safelyVisitChild(_name, visitor); |
| 3683 safelyVisitChild(_typeParameters, visitor); |
| 3684 safelyVisitChild(_extendsClause, visitor); |
| 3685 safelyVisitChild(_withClause, visitor); |
| 3686 safelyVisitChild(_implementsClause, visitor); |
| 3687 safelyVisitChild(_nativeClause, visitor); |
| 3688 members.accept(visitor); |
| 3689 } |
| 3690 |
| 3691 @override |
| 3692 Token get firstTokenAfterCommentAndMetadata { |
| 3693 if (abstractKeyword != null) { |
| 3694 return abstractKeyword; |
| 3695 } |
| 3696 return classKeyword; |
| 3697 } |
| 3698 } |
| 3699 |
| 3700 /** |
| 3701 * The abstract class `ClassMember` defines the behavior common to nodes that de
clare a name |
| 3702 * within the scope of a class. |
| 3703 */ |
| 3704 abstract class ClassMember extends Declaration { |
| 3705 /** |
| 3706 * Initialize a newly created member of a class. |
| 3707 * |
| 3708 * @param comment the documentation comment associated with this member |
| 3709 * @param metadata the annotations associated with this member |
| 3710 */ |
| 3711 ClassMember(Comment comment, List<Annotation> metadata) : super(comment, metad
ata); |
| 3712 } |
| 3713 |
| 3714 /** |
| 3715 * Instances of the class `ClassTypeAlias` represent a class type alias. |
| 3716 * |
| 3717 * <pre> |
| 3718 * classTypeAlias ::= |
| 3719 * [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplication |
| 3720 * |
| 3721 * mixinApplication ::= |
| 3722 * [TypeName] [WithClause] [ImplementsClause]? ';' |
| 3723 * </pre> |
| 3724 */ |
| 3725 class ClassTypeAlias extends TypeAlias { |
| 3726 /** |
| 3727 * The name of the class being declared. |
| 3728 */ |
| 3729 SimpleIdentifier _name; |
| 3730 |
| 3731 /** |
| 3732 * The type parameters for the class, or `null` if the class does not have any
type |
| 3733 * parameters. |
| 3734 */ |
| 3735 TypeParameterList _typeParameters; |
| 3736 |
| 3737 /** |
| 3738 * The token for the '=' separating the name from the definition. |
| 3739 */ |
| 3740 Token equals; |
| 3741 |
| 3742 /** |
| 3743 * The token for the 'abstract' keyword, or `null` if this is not defining an
abstract |
| 3744 * class. |
| 3745 */ |
| 3746 Token abstractKeyword; |
| 3747 |
| 3748 /** |
| 3749 * The name of the superclass of the class being declared. |
| 3750 */ |
| 3751 TypeName _superclass; |
| 3752 |
| 3753 /** |
| 3754 * The with clause for this class. |
| 3755 */ |
| 3756 WithClause _withClause; |
| 3757 |
| 3758 /** |
| 3759 * The implements clause for this class, or `null` if there is no implements c
lause. |
| 3760 */ |
| 3761 ImplementsClause _implementsClause; |
| 3762 |
| 3763 /** |
| 3764 * Initialize a newly created class type alias. |
| 3765 * |
| 3766 * @param comment the documentation comment associated with this type alias |
| 3767 * @param metadata the annotations associated with this type alias |
| 3768 * @param keyword the token representing the 'typedef' keyword |
| 3769 * @param name the name of the class being declared |
| 3770 * @param typeParameters the type parameters for the class |
| 3771 * @param equals the token for the '=' separating the name from the definition |
| 3772 * @param abstractKeyword the token for the 'abstract' keyword |
| 3773 * @param superclass the name of the superclass of the class being declared |
| 3774 * @param withClause the with clause for this class |
| 3775 * @param implementsClause the implements clause for this class |
| 3776 * @param semicolon the semicolon terminating the declaration |
| 3777 */ |
| 3778 ClassTypeAlias(Comment comment, List<Annotation> metadata, Token keyword, Simp
leIdentifier name, TypeParameterList typeParameters, this.equals, this.abstractK
eyword, TypeName superclass, WithClause withClause, ImplementsClause implementsC
lause, Token semicolon) : super(comment, metadata, keyword, semicolon) { |
| 3779 this._name = becomeParentOf(name); |
| 3780 this._typeParameters = becomeParentOf(typeParameters); |
| 3781 this._superclass = becomeParentOf(superclass); |
| 3782 this._withClause = becomeParentOf(withClause); |
| 3783 this._implementsClause = becomeParentOf(implementsClause); |
| 3784 } |
| 3785 |
| 3786 @override |
| 3787 accept(AstVisitor visitor) => visitor.visitClassTypeAlias(this); |
| 3788 |
| 3789 @override |
| 3790 ClassElement get element => _name != null ? (_name.staticElement as ClassEleme
nt) : null; |
| 3791 |
| 3792 /** |
| 3793 * Return the implements clause for this class, or `null` if there is no imple
ments clause. |
| 3794 * |
| 3795 * @return the implements clause for this class |
| 3796 */ |
| 3797 ImplementsClause get implementsClause => _implementsClause; |
| 3798 |
| 3799 /** |
| 3800 * Return the name of the class being declared. |
| 3801 * |
| 3802 * @return the name of the class being declared |
| 3803 */ |
| 3804 SimpleIdentifier get name => _name; |
| 3805 |
| 3806 /** |
| 3807 * Return the name of the superclass of the class being declared. |
| 3808 * |
| 3809 * @return the name of the superclass of the class being declared |
| 3810 */ |
| 3811 TypeName get superclass => _superclass; |
| 3812 |
| 3813 /** |
| 3814 * Return the type parameters for the class, or `null` if the class does not h
ave any type |
| 3815 * parameters. |
| 3816 * |
| 3817 * @return the type parameters for the class |
| 3818 */ |
| 3819 TypeParameterList get typeParameters => _typeParameters; |
| 3820 |
| 3821 /** |
| 3822 * Return the with clause for this class. |
| 3823 * |
| 3824 * @return the with clause for this class |
| 3825 */ |
| 3826 WithClause get withClause => _withClause; |
| 3827 |
| 3828 /** |
| 3829 * Return `true` if this class is declared to be an abstract class. |
| 3830 * |
| 3831 * @return `true` if this class is declared to be an abstract class |
| 3832 */ |
| 3833 bool get isAbstract => abstractKeyword != null; |
| 3834 |
| 3835 /** |
| 3836 * Set the implements clause for this class to the given implements clause. |
| 3837 * |
| 3838 * @param implementsClause the implements clause for this class |
| 3839 */ |
| 3840 void set implementsClause(ImplementsClause implementsClause) { |
| 3841 this._implementsClause = becomeParentOf(implementsClause); |
| 3842 } |
| 3843 |
| 3844 /** |
| 3845 * Set the name of the class being declared to the given identifier. |
| 3846 * |
| 3847 * @param name the name of the class being declared |
| 3848 */ |
| 3849 void set name(SimpleIdentifier name) { |
| 3850 this._name = becomeParentOf(name); |
| 3851 } |
| 3852 |
| 3853 /** |
| 3854 * Set the name of the superclass of the class being declared to the given nam
e. |
| 3855 * |
| 3856 * @param superclass the name of the superclass of the class being declared |
| 3857 */ |
| 3858 void set superclass(TypeName superclass) { |
| 3859 this._superclass = becomeParentOf(superclass); |
| 3860 } |
| 3861 |
| 3862 /** |
| 3863 * Set the type parameters for the class to the given list of parameters. |
| 3864 * |
| 3865 * @param typeParameters the type parameters for the class |
| 3866 */ |
| 3867 void set typeParameters(TypeParameterList typeParameters) { |
| 3868 this._typeParameters = becomeParentOf(typeParameters); |
| 3869 } |
| 3870 |
| 3871 /** |
| 3872 * Set the with clause for this class to the given with clause. |
| 3873 * |
| 3874 * @param withClause the with clause for this class |
| 3875 */ |
| 3876 void set withClause(WithClause withClause) { |
| 3877 this._withClause = becomeParentOf(withClause); |
| 3878 } |
| 3879 |
| 3880 @override |
| 3881 void visitChildren(AstVisitor visitor) { |
| 3882 super.visitChildren(visitor); |
| 3883 safelyVisitChild(_name, visitor); |
| 3884 safelyVisitChild(_typeParameters, visitor); |
| 3885 safelyVisitChild(_superclass, visitor); |
| 3886 safelyVisitChild(_withClause, visitor); |
| 3887 safelyVisitChild(_implementsClause, visitor); |
| 3888 } |
| 3889 } |
| 3890 |
| 3891 /** |
| 3892 * Instances of the class `Combinator` represent the combinator associated with
an import |
| 3893 * directive. |
| 3894 * |
| 3895 * <pre> |
| 3896 * combinator ::= |
| 3897 * [HideCombinator] |
| 3898 * | [ShowCombinator] |
| 3899 * </pre> |
| 3900 */ |
| 3901 abstract class Combinator extends AstNode { |
| 3902 /** |
| 3903 * The keyword specifying what kind of processing is to be done on the importe
d names. |
| 3904 */ |
| 3905 Token keyword; |
| 3906 |
| 3907 /** |
| 3908 * Initialize a newly created import combinator. |
| 3909 * |
| 3910 * @param keyword the keyword specifying what kind of processing is to be done
on the imported |
| 3911 * names |
| 3912 */ |
| 3913 Combinator(this.keyword); |
| 3914 |
| 3915 @override |
| 3916 Token get beginToken => keyword; |
| 3917 } |
| 3918 |
| 3919 /** |
| 3920 * Instances of the class `Comment` represent a comment within the source code. |
| 3921 * |
| 3922 * <pre> |
| 3923 * comment ::= |
| 3924 * endOfLineComment |
| 3925 * | blockComment |
| 3926 * | documentationComment |
| 3927 * |
| 3928 * endOfLineComment ::= |
| 3929 * '//' (CHARACTER - EOL)* EOL |
| 3930 * |
| 3931 * blockComment ::= |
| 3932 * '/ *' CHARACTER* '*/' |
| 3933 * |
| 3934 * documentationComment ::= |
| 3935 * '/ **' (CHARACTER | [CommentReference])* '*/' |
| 3936 * | ('///' (CHARACTER - EOL)* EOL)+ |
| 3937 * </pre> |
| 3938 */ |
| 3939 class Comment extends AstNode { |
| 3940 /** |
| 3941 * Create a block comment. |
| 3942 * |
| 3943 * @param tokens the tokens representing the comment |
| 3944 * @return the block comment that was created |
| 3945 */ |
| 3946 static Comment createBlockComment(List<Token> tokens) => new Comment(tokens, C
ommentType.BLOCK, null); |
| 3947 |
| 3948 /** |
| 3949 * Create a documentation comment. |
| 3950 * |
| 3951 * @param tokens the tokens representing the comment |
| 3952 * @return the documentation comment that was created |
| 3953 */ |
| 3954 static Comment createDocumentationComment(List<Token> tokens) => new Comment(t
okens, CommentType.DOCUMENTATION, new List<CommentReference>()); |
| 3955 |
| 3956 /** |
| 3957 * Create a documentation comment. |
| 3958 * |
| 3959 * @param tokens the tokens representing the comment |
| 3960 * @param references the references embedded within the documentation comment |
| 3961 * @return the documentation comment that was created |
| 3962 */ |
| 3963 static Comment createDocumentationCommentWithReferences(List<Token> tokens, Li
st<CommentReference> references) => new Comment(tokens, CommentType.DOCUMENTATIO
N, references); |
| 3964 |
| 3965 /** |
| 3966 * Create an end-of-line comment. |
| 3967 * |
| 3968 * @param tokens the tokens representing the comment |
| 3969 * @return the end-of-line comment that was created |
| 3970 */ |
| 3971 static Comment createEndOfLineComment(List<Token> tokens) => new Comment(token
s, CommentType.END_OF_LINE, null); |
| 3972 |
| 3973 /** |
| 3974 * The tokens representing the comment. |
| 3975 */ |
| 3976 final List<Token> tokens; |
| 3977 |
| 3978 /** |
| 3979 * The type of the comment. |
| 3980 */ |
| 3981 final CommentType _type; |
| 3982 |
| 3983 /** |
| 3984 * The references embedded within the documentation comment. This list will be
empty unless this |
| 3985 * is a documentation comment that has references embedded within it. |
| 3986 */ |
| 3987 NodeList<CommentReference> _references; |
| 3988 |
| 3989 /** |
| 3990 * Initialize a newly created comment. |
| 3991 * |
| 3992 * @param tokens the tokens representing the comment |
| 3993 * @param type the type of the comment |
| 3994 * @param references the references embedded within the documentation comment |
| 3995 */ |
| 3996 Comment(this.tokens, this._type, List<CommentReference> references) { |
| 3997 this._references = new NodeList<CommentReference>(this); |
| 3998 this._references.addAll(references); |
| 3999 } |
| 4000 |
| 4001 @override |
| 4002 accept(AstVisitor visitor) => visitor.visitComment(this); |
| 4003 |
| 4004 @override |
| 4005 Token get beginToken => tokens[0]; |
| 4006 |
| 4007 @override |
| 4008 Token get endToken => tokens[tokens.length - 1]; |
| 4009 |
| 4010 /** |
| 4011 * Return the references embedded within the documentation comment. |
| 4012 * |
| 4013 * @return the references embedded within the documentation comment |
| 4014 */ |
| 4015 NodeList<CommentReference> get references => _references; |
| 4016 |
| 4017 /** |
| 4018 * Return `true` if this is a block comment. |
| 4019 * |
| 4020 * @return `true` if this is a block comment |
| 4021 */ |
| 4022 bool get isBlock => _type == CommentType.BLOCK; |
| 4023 |
| 4024 /** |
| 4025 * Return `true` if this is a documentation comment. |
| 4026 * |
| 4027 * @return `true` if this is a documentation comment |
| 4028 */ |
| 4029 bool get isDocumentation => _type == CommentType.DOCUMENTATION; |
| 4030 |
| 4031 /** |
| 4032 * Return `true` if this is an end-of-line comment. |
| 4033 * |
| 4034 * @return `true` if this is an end-of-line comment |
| 4035 */ |
| 4036 bool get isEndOfLine => _type == CommentType.END_OF_LINE; |
| 4037 |
| 4038 @override |
| 4039 void visitChildren(AstVisitor visitor) { |
| 4040 _references.accept(visitor); |
| 4041 } |
| 4042 } |
| 4043 |
| 4044 /** |
| 4045 * Instances of the class `CommentReference` represent a reference to a Dart ele
ment that is |
| 4046 * found within a documentation comment. |
| 4047 * |
| 4048 * <pre> |
| 4049 * commentReference ::= |
| 4050 * '[' 'new'? [Identifier] ']' |
| 4051 * </pre> |
| 4052 */ |
| 4053 class CommentReference extends AstNode { |
| 4054 /** |
| 4055 * The token representing the 'new' keyword, or `null` if there was no 'new' k
eyword. |
| 4056 */ |
| 4057 Token newKeyword; |
| 4058 |
| 4059 /** |
| 4060 * The identifier being referenced. |
| 4061 */ |
| 4062 Identifier _identifier; |
| 4063 |
| 4064 /** |
| 4065 * Initialize a newly created reference to a Dart element. |
| 4066 * |
| 4067 * @param newKeyword the token representing the 'new' keyword |
| 4068 * @param identifier the identifier being referenced |
| 4069 */ |
| 4070 CommentReference(this.newKeyword, Identifier identifier) { |
| 4071 this._identifier = becomeParentOf(identifier); |
| 4072 } |
| 4073 |
| 4074 @override |
| 4075 accept(AstVisitor visitor) => visitor.visitCommentReference(this); |
| 4076 |
| 4077 @override |
| 4078 Token get beginToken => _identifier.beginToken; |
| 4079 |
| 4080 @override |
| 4081 Token get endToken => _identifier.endToken; |
| 4082 |
| 4083 /** |
| 4084 * Return the identifier being referenced. |
| 4085 * |
| 4086 * @return the identifier being referenced |
| 4087 */ |
| 4088 Identifier get identifier => _identifier; |
| 4089 |
| 4090 /** |
| 4091 * Set the identifier being referenced to the given identifier. |
| 4092 * |
| 4093 * @param identifier the identifier being referenced |
| 4094 */ |
| 4095 void set identifier(Identifier identifier) { |
| 4096 this._identifier = becomeParentOf(identifier); |
| 4097 } |
| 4098 |
| 4099 @override |
| 4100 void visitChildren(AstVisitor visitor) { |
| 4101 safelyVisitChild(_identifier, visitor); |
| 4102 } |
| 4103 } |
| 4104 |
| 4105 /** |
| 4106 * The enumeration `CommentType` encodes all the different types of comments tha
t are |
| 4107 * recognized by the parser. |
| 4108 */ |
| 4109 class CommentType extends Enum<CommentType> { |
| 4110 /** |
| 4111 * An end-of-line comment. |
| 4112 */ |
| 4113 static const CommentType END_OF_LINE = const CommentType('END_OF_LINE', 0); |
| 4114 |
| 4115 /** |
| 4116 * A block comment. |
| 4117 */ |
| 4118 static const CommentType BLOCK = const CommentType('BLOCK', 1); |
| 4119 |
| 4120 /** |
| 4121 * A documentation comment. |
| 4122 */ |
| 4123 static const CommentType DOCUMENTATION = const CommentType('DOCUMENTATION', 2)
; |
| 4124 |
| 4125 static const List<CommentType> values = const [END_OF_LINE, BLOCK, DOCUMENTATI
ON]; |
| 4126 |
| 4127 const CommentType(String name, int ordinal) : super(name, ordinal); |
| 4128 } |
| 4129 |
| 4130 /** |
| 4131 * Instances of the class `CompilationUnit` represent a compilation unit. |
| 4132 * |
| 4133 * While the grammar restricts the order of the directives and declarations with
in a compilation |
| 4134 * unit, this class does not enforce those restrictions. In particular, the chil
dren of a |
| 4135 * compilation unit will be visited in lexical order even if lexical order does
not conform to the |
| 4136 * restrictions of the grammar. |
| 4137 * |
| 4138 * <pre> |
| 4139 * compilationUnit ::= |
| 4140 * directives declarations |
| 4141 * |
| 4142 * directives ::= |
| 4143 * [ScriptTag]? [LibraryDirective]? namespaceDirective* [PartDirective]* |
| 4144 * | [PartOfDirective] |
| 4145 * |
| 4146 * namespaceDirective ::= |
| 4147 * [ImportDirective] |
| 4148 * | [ExportDirective] |
| 4149 * |
| 4150 * declarations ::= |
| 4151 * [CompilationUnitMember]* |
| 4152 * </pre> |
| 4153 */ |
| 4154 class CompilationUnit extends AstNode { |
| 4155 /** |
| 4156 * The first token in the token stream that was parsed to form this compilatio
n unit. |
| 4157 */ |
| 4158 final Token beginToken; |
| 4159 |
| 4160 /** |
| 4161 * The script tag at the beginning of the compilation unit, or `null` if there
is no script |
| 4162 * tag in this compilation unit. |
| 4163 */ |
| 4164 ScriptTag _scriptTag; |
| 4165 |
| 4166 /** |
| 4167 * The directives contained in this compilation unit. |
| 4168 */ |
| 4169 NodeList<Directive> _directives; |
| 4170 |
| 4171 /** |
| 4172 * The declarations contained in this compilation unit. |
| 4173 */ |
| 4174 NodeList<CompilationUnitMember> _declarations; |
| 4175 |
| 4176 /** |
| 4177 * The last token in the token stream that was parsed to form this compilation
unit. This token |
| 4178 * should always have a type of [TokenType.EOF]. |
| 4179 */ |
| 4180 final Token endToken; |
| 4181 |
| 4182 /** |
| 4183 * The element associated with this compilation unit, or `null` if the AST str
ucture has not |
| 4184 * been resolved. |
| 4185 */ |
| 4186 CompilationUnitElement element; |
| 4187 |
| 4188 /** |
| 4189 * The line information for this compilation unit. |
| 4190 */ |
| 4191 LineInfo lineInfo; |
| 4192 |
| 4193 /** |
| 4194 * Initialize a newly created compilation unit to have the given directives an
d declarations. |
| 4195 * |
| 4196 * @param beginToken the first token in the token stream |
| 4197 * @param scriptTag the script tag at the beginning of the compilation unit |
| 4198 * @param directives the directives contained in this compilation unit |
| 4199 * @param declarations the declarations contained in this compilation unit |
| 4200 * @param endToken the last token in the token stream |
| 4201 */ |
| 4202 CompilationUnit(this.beginToken, ScriptTag scriptTag, List<Directive> directiv
es, List<CompilationUnitMember> declarations, this.endToken) { |
| 4203 this._directives = new NodeList<Directive>(this); |
| 4204 this._declarations = new NodeList<CompilationUnitMember>(this); |
| 4205 this._scriptTag = becomeParentOf(scriptTag); |
| 4206 this._directives.addAll(directives); |
| 4207 this._declarations.addAll(declarations); |
| 4208 } |
| 4209 |
| 4210 @override |
| 4211 accept(AstVisitor visitor) => visitor.visitCompilationUnit(this); |
| 4212 |
| 4213 /** |
| 4214 * Return the declarations contained in this compilation unit. |
| 4215 * |
| 4216 * @return the declarations contained in this compilation unit |
| 4217 */ |
| 4218 NodeList<CompilationUnitMember> get declarations => _declarations; |
| 4219 |
| 4220 /** |
| 4221 * Return the directives contained in this compilation unit. |
| 4222 * |
| 4223 * @return the directives contained in this compilation unit |
| 4224 */ |
| 4225 NodeList<Directive> get directives => _directives; |
| 4226 |
| 4227 @override |
| 4228 int get length { |
| 4229 Token endToken = this.endToken; |
| 4230 if (endToken == null) { |
| 4231 return 0; |
| 4232 } |
| 4233 return endToken.offset + endToken.length; |
| 4234 } |
| 4235 |
| 4236 @override |
| 4237 int get offset => 0; |
| 4238 |
| 4239 /** |
| 4240 * Return the script tag at the beginning of the compilation unit, or `null` i
f there is no |
| 4241 * script tag in this compilation unit. |
| 4242 * |
| 4243 * @return the script tag at the beginning of the compilation unit |
| 4244 */ |
| 4245 ScriptTag get scriptTag => _scriptTag; |
| 4246 |
| 4247 /** |
| 4248 * Set the script tag at the beginning of the compilation unit to the given sc
ript tag. |
| 4249 * |
| 4250 * @param scriptTag the script tag at the beginning of the compilation unit |
| 4251 */ |
| 4252 void set scriptTag(ScriptTag scriptTag) { |
| 4253 this._scriptTag = becomeParentOf(scriptTag); |
| 4254 } |
| 4255 |
| 4256 @override |
| 4257 void visitChildren(AstVisitor visitor) { |
| 4258 safelyVisitChild(_scriptTag, visitor); |
| 4259 if (_directivesAreBeforeDeclarations()) { |
| 4260 _directives.accept(visitor); |
| 4261 _declarations.accept(visitor); |
| 4262 } else { |
| 4263 for (AstNode child in sortedDirectivesAndDeclarations) { |
| 4264 child.accept(visitor); |
| 4265 } |
| 4266 } |
| 4267 } |
| 4268 |
| 4269 /** |
| 4270 * Return `true` if all of the directives are lexically before any declaration
s. |
| 4271 * |
| 4272 * @return `true` if all of the directives are lexically before any declaratio
ns |
| 4273 */ |
| 4274 bool _directivesAreBeforeDeclarations() { |
| 4275 if (_directives.isEmpty || _declarations.isEmpty) { |
| 4276 return true; |
| 4277 } |
| 4278 Directive lastDirective = _directives[_directives.length - 1]; |
| 4279 CompilationUnitMember firstDeclaration = _declarations[0]; |
| 4280 return lastDirective.offset < firstDeclaration.offset; |
| 4281 } |
| 4282 |
| 4283 /** |
| 4284 * Return an array containing all of the directives and declarations in this c
ompilation unit, |
| 4285 * sorted in lexical order. |
| 4286 * |
| 4287 * @return the directives and declarations in this compilation unit in the ord
er in which they |
| 4288 * appeared in the original source |
| 4289 */ |
| 4290 List<AstNode> get sortedDirectivesAndDeclarations { |
| 4291 List<AstNode> childList = new List<AstNode>(); |
| 4292 childList.addAll(_directives); |
| 4293 childList.addAll(_declarations); |
| 4294 List<AstNode> children = new List.from(childList); |
| 4295 children.sort(AstNode.LEXICAL_ORDER); |
| 4296 return children; |
| 4297 } |
| 4298 } |
| 4299 |
| 4300 /** |
| 4301 * Instances of the class `CompilationUnitMember` defines the behavior common to
nodes that |
| 4302 * declare a name within the scope of a compilation unit. |
| 4303 * |
| 4304 * <pre> |
| 4305 * compilationUnitMember ::= |
| 4306 * [ClassDeclaration] |
| 4307 * | [TypeAlias] |
| 4308 * | [FunctionDeclaration] |
| 4309 * | [MethodDeclaration] |
| 4310 * | [VariableDeclaration] |
| 4311 * | [VariableDeclaration] |
| 4312 * </pre> |
| 4313 */ |
| 4314 abstract class CompilationUnitMember extends Declaration { |
| 4315 /** |
| 4316 * Initialize a newly created generic compilation unit member. |
| 4317 * |
| 4318 * @param comment the documentation comment associated with this member |
| 4319 * @param metadata the annotations associated with this member |
| 4320 */ |
| 4321 CompilationUnitMember(Comment comment, List<Annotation> metadata) : super(comm
ent, metadata); |
| 4322 } |
| 4323 |
| 4324 /** |
| 4325 * Instances of the class `ConditionalExpression` represent a conditional expres
sion. |
| 4326 * |
| 4327 * <pre> |
| 4328 * conditionalExpression ::= |
| 4329 * [Expression] '?' [Expression] ':' [Expression] |
| 4330 * </pre> |
| 4331 */ |
| 4332 class ConditionalExpression extends Expression { |
| 4333 /** |
| 4334 * The condition used to determine which of the expressions is executed next. |
| 4335 */ |
| 4336 Expression _condition; |
| 4337 |
| 4338 /** |
| 4339 * The token used to separate the condition from the then expression. |
| 4340 */ |
| 4341 Token question; |
| 4342 |
| 4343 /** |
| 4344 * The expression that is executed if the condition evaluates to `true`. |
| 4345 */ |
| 4346 Expression _thenExpression; |
| 4347 |
| 4348 /** |
| 4349 * The token used to separate the then expression from the else expression. |
| 4350 */ |
| 4351 Token colon; |
| 4352 |
| 4353 /** |
| 4354 * The expression that is executed if the condition evaluates to `false`. |
| 4355 */ |
| 4356 Expression _elseExpression; |
| 4357 |
| 4358 /** |
| 4359 * Initialize a newly created conditional expression. |
| 4360 * |
| 4361 * @param condition the condition used to determine which expression is execut
ed next |
| 4362 * @param question the token used to separate the condition from the then expr
ession |
| 4363 * @param thenExpression the expression that is executed if the condition eval
uates to |
| 4364 * `true` |
| 4365 * @param colon the token used to separate the then expression from the else e
xpression |
| 4366 * @param elseExpression the expression that is executed if the condition eval
uates to |
| 4367 * `false` |
| 4368 */ |
| 4369 ConditionalExpression(Expression condition, this.question, Expression thenExpr
ession, this.colon, Expression elseExpression) { |
| 4370 this._condition = becomeParentOf(condition); |
| 4371 this._thenExpression = becomeParentOf(thenExpression); |
| 4372 this._elseExpression = becomeParentOf(elseExpression); |
| 4373 } |
| 4374 |
| 4375 @override |
| 4376 accept(AstVisitor visitor) => visitor.visitConditionalExpression(this); |
| 4377 |
| 4378 @override |
| 4379 Token get beginToken => _condition.beginToken; |
| 4380 |
| 4381 /** |
| 4382 * Return the condition used to determine which of the expressions is executed
next. |
| 4383 * |
| 4384 * @return the condition used to determine which expression is executed next |
| 4385 */ |
| 4386 Expression get condition => _condition; |
| 4387 |
| 4388 /** |
| 4389 * Return the expression that is executed if the condition evaluates to `false
`. |
| 4390 * |
| 4391 * @return the expression that is executed if the condition evaluates to `fals
e` |
| 4392 */ |
| 4393 Expression get elseExpression => _elseExpression; |
| 4394 |
| 4395 @override |
| 4396 Token get endToken => _elseExpression.endToken; |
| 4397 |
| 4398 @override |
| 4399 int get precedence => 3; |
| 4400 |
| 4401 /** |
| 4402 * Return the expression that is executed if the condition evaluates to `true`
. |
| 4403 * |
| 4404 * @return the expression that is executed if the condition evaluates to `true
` |
| 4405 */ |
| 4406 Expression get thenExpression => _thenExpression; |
| 4407 |
| 4408 /** |
| 4409 * Set the condition used to determine which of the expressions is executed ne
xt to the given |
| 4410 * expression. |
| 4411 * |
| 4412 * @param expression the condition used to determine which expression is execu
ted next |
| 4413 */ |
| 4414 void set condition(Expression expression) { |
| 4415 _condition = becomeParentOf(expression); |
| 4416 } |
| 4417 |
| 4418 /** |
| 4419 * Set the expression that is executed if the condition evaluates to `false` t
o the given |
| 4420 * expression. |
| 4421 * |
| 4422 * @param expression the expression that is executed if the condition evaluate
s to `false` |
| 4423 */ |
| 4424 void set elseExpression(Expression expression) { |
| 4425 _elseExpression = becomeParentOf(expression); |
| 4426 } |
| 4427 |
| 4428 /** |
| 4429 * Set the expression that is executed if the condition evaluates to `true` to
the given |
| 4430 * expression. |
| 4431 * |
| 4432 * @param expression the expression that is executed if the condition evaluate
s to `true` |
| 4433 */ |
| 4434 void set thenExpression(Expression expression) { |
| 4435 _thenExpression = becomeParentOf(expression); |
| 4436 } |
| 4437 |
| 4438 @override |
| 4439 void visitChildren(AstVisitor visitor) { |
| 4440 safelyVisitChild(_condition, visitor); |
| 4441 safelyVisitChild(_thenExpression, visitor); |
| 4442 safelyVisitChild(_elseExpression, visitor); |
| 4443 } |
| 4444 } |
| 4445 |
| 4446 /** |
| 4447 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p
roduce their |
| 4448 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant |
| 4449 * expression is one of the following: |
| 4450 * * A literal number. |
| 4451 * * A literal boolean. |
| 4452 * * A literal string where any interpolated expression is a compile-time consta
nt that evaluates |
| 4453 * to a numeric, string or boolean value or to `null`. |
| 4454 * * `null`. |
| 4455 * * A reference to a static constant variable. |
| 4456 * * An identifier expression that denotes a constant variable, a class or a typ
e parameter. |
| 4457 * * A constant constructor invocation. |
| 4458 * * A constant list literal. |
| 4459 * * A constant map literal. |
| 4460 * * A simple or qualified identifier denoting a top-level function or a static
method. |
| 4461 * * A parenthesized expression `(e)` where `e` is a constant expression. |
| 4462 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, |
| 4463 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a |
| 4464 * numeric, string or boolean value or to `null`. |
| 4465 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where |
| 4466 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean value
or |
| 4467 * to `null`. |
| 4468 * * An expression of one of the forms `~e`, `e1 ^ e2`, `e1 & e2`, |
| 4469 * `e1 | e2`, `e1 >> e2` or `e1 << e2`, where `e`, `e1` and `e2` |
| 4470 * are constant expressions that evaluate to an integer value or to `null`. |
| 4471 * * An expression of one of the forms `-e`, `e1 + e2`, `e1 - e2`, |
| 4472 * `e1 * e2`, `e1 / e2`, `e1 ~/ e2`, `e1 > e2`, `e1 < e2`, |
| 4473 * `e1 >= e2`, `e1 <= e2` or `e1 % e2`, where `e`, `e1` and `e2` |
| 4474 * are constant expressions that evaluate to a numeric value or to `null`. |
| 4475 * </blockquote> The values returned by instances of this class are therefore `n
ull` and |
| 4476 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and |
| 4477 * `DartObject`. |
| 4478 * |
| 4479 * In addition, this class defines several values that can be returned to indica
te various |
| 4480 * conditions encountered during evaluation. These are documented with the stati
c field that define |
| 4481 * those values. |
| 4482 */ |
| 4483 class ConstantEvaluator extends GeneralizingAstVisitor<Object> { |
| 4484 /** |
| 4485 * The value returned for expressions (or non-expression nodes) that are not c
ompile-time constant |
| 4486 * expressions. |
| 4487 */ |
| 4488 static Object NOT_A_CONSTANT = new Object(); |
| 4489 |
| 4490 @override |
| 4491 Object visitAdjacentStrings(AdjacentStrings node) { |
| 4492 JavaStringBuilder builder = new JavaStringBuilder(); |
| 4493 for (StringLiteral string in node.strings) { |
| 4494 Object value = string.accept(this); |
| 4495 if (identical(value, NOT_A_CONSTANT)) { |
| 4496 return value; |
| 4497 } |
| 4498 builder.append(value); |
| 4499 } |
| 4500 return builder.toString(); |
| 4501 } |
| 4502 |
| 4503 @override |
| 4504 Object visitBinaryExpression(BinaryExpression node) { |
| 4505 Object leftOperand = node.leftOperand.accept(this); |
| 4506 if (identical(leftOperand, NOT_A_CONSTANT)) { |
| 4507 return leftOperand; |
| 4508 } |
| 4509 Object rightOperand = node.rightOperand.accept(this); |
| 4510 if (identical(rightOperand, NOT_A_CONSTANT)) { |
| 4511 return rightOperand; |
| 4512 } |
| 4513 while (true) { |
| 4514 if (node.operator.type == TokenType.AMPERSAND) { |
| 4515 // integer or {@code null} |
| 4516 if (leftOperand is int && rightOperand is int) { |
| 4517 return leftOperand & rightOperand; |
| 4518 } |
| 4519 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) { |
| 4520 // boolean or {@code null} |
| 4521 if (leftOperand is bool && rightOperand is bool) { |
| 4522 return leftOperand && rightOperand; |
| 4523 } |
| 4524 } else if (node.operator.type == TokenType.BANG_EQ) { |
| 4525 // numeric, string, boolean, or {@code null} |
| 4526 if (leftOperand is bool && rightOperand is bool) { |
| 4527 return leftOperand != rightOperand; |
| 4528 } else if (leftOperand is int && rightOperand is int) { |
| 4529 return leftOperand != rightOperand; |
| 4530 } else if (leftOperand is double && rightOperand is double) { |
| 4531 return leftOperand != rightOperand; |
| 4532 } else if (leftOperand is String && rightOperand is String) { |
| 4533 return leftOperand != rightOperand; |
| 4534 } |
| 4535 } else if (node.operator.type == TokenType.BAR) { |
| 4536 // integer or {@code null} |
| 4537 if (leftOperand is int && rightOperand is int) { |
| 4538 return leftOperand | rightOperand; |
| 4539 } |
| 4540 } else if (node.operator.type == TokenType.BAR_BAR) { |
| 4541 // boolean or {@code null} |
| 4542 if (leftOperand is bool && rightOperand is bool) { |
| 4543 return leftOperand || rightOperand; |
| 4544 } |
| 4545 } else if (node.operator.type == TokenType.CARET) { |
| 4546 // integer or {@code null} |
| 4547 if (leftOperand is int && rightOperand is int) { |
| 4548 return leftOperand ^ rightOperand; |
| 4549 } |
| 4550 } else if (node.operator.type == TokenType.EQ_EQ) { |
| 4551 // numeric, string, boolean, or {@code null} |
| 4552 if (leftOperand is bool && rightOperand is bool) { |
| 4553 return leftOperand == rightOperand; |
| 4554 } else if (leftOperand is int && rightOperand is int) { |
| 4555 return leftOperand == rightOperand; |
| 4556 } else if (leftOperand is double && rightOperand is double) { |
| 4557 return leftOperand == rightOperand; |
| 4558 } else if (leftOperand is String && rightOperand is String) { |
| 4559 return leftOperand == rightOperand; |
| 4560 } |
| 4561 } else if (node.operator.type == TokenType.GT) { |
| 4562 // numeric or {@code null} |
| 4563 if (leftOperand is int && rightOperand is int) { |
| 4564 return leftOperand.compareTo(rightOperand) > 0; |
| 4565 } else if (leftOperand is double && rightOperand is double) { |
| 4566 return leftOperand.compareTo(rightOperand) > 0; |
| 4567 } |
| 4568 } else if (node.operator.type == TokenType.GT_EQ) { |
| 4569 // numeric or {@code null} |
| 4570 if (leftOperand is int && rightOperand is int) { |
| 4571 return leftOperand.compareTo(rightOperand) >= 0; |
| 4572 } else if (leftOperand is double && rightOperand is double) { |
| 4573 return leftOperand.compareTo(rightOperand) >= 0; |
| 4574 } |
| 4575 } else if (node.operator.type == TokenType.GT_GT) { |
| 4576 // integer or {@code null} |
| 4577 if (leftOperand is int && rightOperand is int) { |
| 4578 return leftOperand >> rightOperand; |
| 4579 } |
| 4580 } else if (node.operator.type == TokenType.LT) { |
| 4581 // numeric or {@code null} |
| 4582 if (leftOperand is int && rightOperand is int) { |
| 4583 return leftOperand.compareTo(rightOperand) < 0; |
| 4584 } else if (leftOperand is double && rightOperand is double) { |
| 4585 return leftOperand.compareTo(rightOperand) < 0; |
| 4586 } |
| 4587 } else if (node.operator.type == TokenType.LT_EQ) { |
| 4588 // numeric or {@code null} |
| 4589 if (leftOperand is int && rightOperand is int) { |
| 4590 return leftOperand.compareTo(rightOperand) <= 0; |
| 4591 } else if (leftOperand is double && rightOperand is double) { |
| 4592 return leftOperand.compareTo(rightOperand) <= 0; |
| 4593 } |
| 4594 } else if (node.operator.type == TokenType.LT_LT) { |
| 4595 // integer or {@code null} |
| 4596 if (leftOperand is int && rightOperand is int) { |
| 4597 return leftOperand << rightOperand; |
| 4598 } |
| 4599 } else if (node.operator.type == TokenType.MINUS) { |
| 4600 // numeric or {@code null} |
| 4601 if (leftOperand is int && rightOperand is int) { |
| 4602 return leftOperand - rightOperand; |
| 4603 } else if (leftOperand is double && rightOperand is double) { |
| 4604 return leftOperand - rightOperand; |
| 4605 } |
| 4606 } else if (node.operator.type == TokenType.PERCENT) { |
| 4607 // numeric or {@code null} |
| 4608 if (leftOperand is int && rightOperand is int) { |
| 4609 return leftOperand.remainder(rightOperand); |
| 4610 } else if (leftOperand is double && rightOperand is double) { |
| 4611 return leftOperand % rightOperand; |
| 4612 } |
| 4613 } else if (node.operator.type == TokenType.PLUS) { |
| 4614 // numeric or {@code null} |
| 4615 if (leftOperand is int && rightOperand is int) { |
| 4616 return leftOperand + rightOperand; |
| 4617 } else if (leftOperand is double && rightOperand is double) { |
| 4618 return leftOperand + rightOperand; |
| 4619 } |
| 4620 } else if (node.operator.type == TokenType.STAR) { |
| 4621 // numeric or {@code null} |
| 4622 if (leftOperand is int && rightOperand is int) { |
| 4623 return leftOperand * rightOperand; |
| 4624 } else if (leftOperand is double && rightOperand is double) { |
| 4625 return leftOperand * rightOperand; |
| 4626 } |
| 4627 } else if (node.operator.type == TokenType.SLASH) { |
| 4628 // numeric or {@code null} |
| 4629 if (leftOperand is int && rightOperand is int) { |
| 4630 if (rightOperand != 0) { |
| 4631 return leftOperand ~/ rightOperand; |
| 4632 } else { |
| 4633 return leftOperand.toDouble() / rightOperand.toDouble(); |
| 4634 } |
| 4635 } else if (leftOperand is double && rightOperand is double) { |
| 4636 return leftOperand / rightOperand; |
| 4637 } |
| 4638 } else if (node.operator.type == TokenType.TILDE_SLASH) { |
| 4639 // numeric or {@code null} |
| 4640 if (leftOperand is int && rightOperand is int) { |
| 4641 if (rightOperand != 0) { |
| 4642 return leftOperand ~/ rightOperand; |
| 4643 } else { |
| 4644 return 0; |
| 4645 } |
| 4646 } else if (leftOperand is double && rightOperand is double) { |
| 4647 return leftOperand ~/ rightOperand; |
| 4648 } |
| 4649 } else { |
| 4650 } |
| 4651 break; |
| 4652 } |
| 4653 // TODO(brianwilkerson) This doesn't handle numeric conversions. |
| 4654 return visitExpression(node); |
| 4655 } |
| 4656 |
| 4657 @override |
| 4658 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false; |
| 4659 |
| 4660 @override |
| 4661 Object visitDoubleLiteral(DoubleLiteral node) => node.value; |
| 4662 |
| 4663 @override |
| 4664 Object visitIntegerLiteral(IntegerLiteral node) => node.value; |
| 4665 |
| 4666 @override |
| 4667 Object visitInterpolationExpression(InterpolationExpression node) { |
| 4668 Object value = node.expression.accept(this); |
| 4669 if (value == null || value is bool || value is String || value is int || val
ue is double) { |
| 4670 return value; |
| 4671 } |
| 4672 return NOT_A_CONSTANT; |
| 4673 } |
| 4674 |
| 4675 @override |
| 4676 Object visitInterpolationString(InterpolationString node) => node.value; |
| 4677 |
| 4678 @override |
| 4679 Object visitListLiteral(ListLiteral node) { |
| 4680 List<Object> list = new List<Object>(); |
| 4681 for (Expression element in node.elements) { |
| 4682 Object value = element.accept(this); |
| 4683 if (identical(value, NOT_A_CONSTANT)) { |
| 4684 return value; |
| 4685 } |
| 4686 list.add(value); |
| 4687 } |
| 4688 return list; |
| 4689 } |
| 4690 |
| 4691 @override |
| 4692 Object visitMapLiteral(MapLiteral node) { |
| 4693 HashMap<String, Object> map = new HashMap<String, Object>(); |
| 4694 for (MapLiteralEntry entry in node.entries) { |
| 4695 Object key = entry.key.accept(this); |
| 4696 Object value = entry.value.accept(this); |
| 4697 if (key is! String || identical(value, NOT_A_CONSTANT)) { |
| 4698 return NOT_A_CONSTANT; |
| 4699 } |
| 4700 map[(key as String)] = value; |
| 4701 } |
| 4702 return map; |
| 4703 } |
| 4704 |
| 4705 @override |
| 4706 Object visitMethodInvocation(MethodInvocation node) => visitNode(node); |
| 4707 |
| 4708 @override |
| 4709 Object visitNode(AstNode node) => NOT_A_CONSTANT; |
| 4710 |
| 4711 @override |
| 4712 Object visitNullLiteral(NullLiteral node) => null; |
| 4713 |
| 4714 @override |
| 4715 Object visitParenthesizedExpression(ParenthesizedExpression node) => node.expr
ession.accept(this); |
| 4716 |
| 4717 @override |
| 4718 Object visitPrefixedIdentifier(PrefixedIdentifier node) => _getConstantValue(n
ull); |
| 4719 |
| 4720 @override |
| 4721 Object visitPrefixExpression(PrefixExpression node) { |
| 4722 Object operand = node.operand.accept(this); |
| 4723 if (identical(operand, NOT_A_CONSTANT)) { |
| 4724 return operand; |
| 4725 } |
| 4726 while (true) { |
| 4727 if (node.operator.type == TokenType.BANG) { |
| 4728 if (identical(operand, true)) { |
| 4729 return false; |
| 4730 } else if (identical(operand, false)) { |
| 4731 return true; |
| 4732 } |
| 4733 } else if (node.operator.type == TokenType.TILDE) { |
| 4734 if (operand is int) { |
| 4735 return ~operand; |
| 4736 } |
| 4737 } else if (node.operator.type == TokenType.MINUS) { |
| 4738 if (operand == null) { |
| 4739 return null; |
| 4740 } else if (operand is int) { |
| 4741 return -operand; |
| 4742 } else if (operand is double) { |
| 4743 return -operand; |
| 4744 } |
| 4745 } else { |
| 4746 } |
| 4747 break; |
| 4748 } |
| 4749 return NOT_A_CONSTANT; |
| 4750 } |
| 4751 |
| 4752 @override |
| 4753 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null); |
| 4754 |
| 4755 @override |
| 4756 Object visitSimpleIdentifier(SimpleIdentifier node) => _getConstantValue(null)
; |
| 4757 |
| 4758 @override |
| 4759 Object visitSimpleStringLiteral(SimpleStringLiteral node) => node.value; |
| 4760 |
| 4761 @override |
| 4762 Object visitStringInterpolation(StringInterpolation node) { |
| 4763 JavaStringBuilder builder = new JavaStringBuilder(); |
| 4764 for (InterpolationElement element in node.elements) { |
| 4765 Object value = element.accept(this); |
| 4766 if (identical(value, NOT_A_CONSTANT)) { |
| 4767 return value; |
| 4768 } |
| 4769 builder.append(value); |
| 4770 } |
| 4771 return builder.toString(); |
| 4772 } |
| 4773 |
| 4774 @override |
| 4775 Object visitSymbolLiteral(SymbolLiteral node) { |
| 4776 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String. |
| 4777 JavaStringBuilder builder = new JavaStringBuilder(); |
| 4778 for (Token component in node.components) { |
| 4779 if (builder.length > 0) { |
| 4780 builder.appendChar(0x2E); |
| 4781 } |
| 4782 builder.append(component.lexeme); |
| 4783 } |
| 4784 return builder.toString(); |
| 4785 } |
| 4786 |
| 4787 /** |
| 4788 * Return the constant value of the static constant represented by the given e
lement. |
| 4789 * |
| 4790 * @param element the element whose value is to be returned |
| 4791 * @return the constant value of the static constant |
| 4792 */ |
| 4793 Object _getConstantValue(Element element) { |
| 4794 // TODO(brianwilkerson) Implement this |
| 4795 if (element is FieldElement) { |
| 4796 FieldElement field = element; |
| 4797 if (field.isStatic && field.isConst) { |
| 4798 } |
| 4799 } |
| 4800 return NOT_A_CONSTANT; |
| 4801 } |
| 4802 } |
| 4803 |
| 4804 /** |
| 4805 * Instances of the class `ConstructorDeclaration` represent a constructor decla
ration. |
| 4806 * |
| 4807 * <pre> |
| 4808 * constructorDeclaration ::= |
| 4809 * constructorSignature [FunctionBody]? |
| 4810 * | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier])?
arguments |
| 4811 * |
| 4812 * constructorSignature ::= |
| 4813 * 'external'? constructorName formalParameterList initializerList? |
| 4814 * | 'external'? 'factory' factoryName formalParameterList initializerList? |
| 4815 * | 'external'? 'const' constructorName formalParameterList initializerList? |
| 4816 * |
| 4817 * constructorName ::= |
| 4818 * [SimpleIdentifier] ('.' [SimpleIdentifier])? |
| 4819 * |
| 4820 * factoryName ::= |
| 4821 * [Identifier] ('.' [SimpleIdentifier])? |
| 4822 * |
| 4823 * initializerList ::= |
| 4824 * ':' [ConstructorInitializer] (',' [ConstructorInitializer])* |
| 4825 * </pre> |
| 4826 */ |
| 4827 class ConstructorDeclaration extends ClassMember { |
| 4828 /** |
| 4829 * The token for the 'external' keyword, or `null` if the constructor is not e
xternal. |
| 4830 */ |
| 4831 Token externalKeyword; |
| 4832 |
| 4833 /** |
| 4834 * The token for the 'const' keyword, or `null` if the constructor is not a co
nst |
| 4835 * constructor. |
| 4836 */ |
| 4837 Token constKeyword; |
| 4838 |
| 4839 /** |
| 4840 * The token for the 'factory' keyword, or `null` if the constructor is not a
factory |
| 4841 * constructor. |
| 4842 */ |
| 4843 Token factoryKeyword; |
| 4844 |
| 4845 /** |
| 4846 * The type of object being created. This can be different than the type in wh
ich the constructor |
| 4847 * is being declared if the constructor is the implementation of a factory con
structor. |
| 4848 */ |
| 4849 Identifier _returnType; |
| 4850 |
| 4851 /** |
| 4852 * The token for the period before the constructor name, or `null` if the cons
tructor being |
| 4853 * declared is unnamed. |
| 4854 */ |
| 4855 Token period; |
| 4856 |
| 4857 /** |
| 4858 * The name of the constructor, or `null` if the constructor being declared is
unnamed. |
| 4859 */ |
| 4860 SimpleIdentifier _name; |
| 4861 |
| 4862 /** |
| 4863 * The parameters associated with the constructor. |
| 4864 */ |
| 4865 FormalParameterList _parameters; |
| 4866 |
| 4867 /** |
| 4868 * The token for the separator (colon or equals) before the initializer list o
r redirection, or |
| 4869 * `null` if there are no initializers. |
| 4870 */ |
| 4871 Token separator; |
| 4872 |
| 4873 /** |
| 4874 * The initializers associated with the constructor. |
| 4875 */ |
| 4876 NodeList<ConstructorInitializer> _initializers; |
| 4877 |
| 4878 /** |
| 4879 * The name of the constructor to which this constructor will be redirected, o
r `null` if |
| 4880 * this is not a redirecting factory constructor. |
| 4881 */ |
| 4882 ConstructorName _redirectedConstructor; |
| 4883 |
| 4884 /** |
| 4885 * The body of the constructor, or `null` if the constructor does not have a b
ody. |
| 4886 */ |
| 4887 FunctionBody _body; |
| 4888 |
| 4889 /** |
| 4890 * The element associated with this constructor, or `null` if the AST structur
e has not been |
| 4891 * resolved or if this constructor could not be resolved. |
| 4892 */ |
| 4893 ConstructorElement element; |
| 4894 |
| 4895 /** |
| 4896 * Initialize a newly created constructor declaration. |
| 4897 * |
| 4898 * @param externalKeyword the token for the 'external' keyword |
| 4899 * @param comment the documentation comment associated with this constructor |
| 4900 * @param metadata the annotations associated with this constructor |
| 4901 * @param constKeyword the token for the 'const' keyword |
| 4902 * @param factoryKeyword the token for the 'factory' keyword |
| 4903 * @param returnType the return type of the constructor |
| 4904 * @param period the token for the period before the constructor name |
| 4905 * @param name the name of the constructor |
| 4906 * @param parameters the parameters associated with the constructor |
| 4907 * @param separator the token for the colon or equals before the initializers |
| 4908 * @param initializers the initializers associated with the constructor |
| 4909 * @param redirectedConstructor the name of the constructor to which this cons
tructor will be |
| 4910 * redirected |
| 4911 * @param body the body of the constructor |
| 4912 */ |
| 4913 ConstructorDeclaration(Comment comment, List<Annotation> metadata, this.extern
alKeyword, this.constKeyword, this.factoryKeyword, Identifier returnType, this.p
eriod, SimpleIdentifier name, FormalParameterList parameters, this.separator, Li
st<ConstructorInitializer> initializers, ConstructorName redirectedConstructor,
FunctionBody body) : super(comment, metadata) { |
| 4914 this._initializers = new NodeList<ConstructorInitializer>(this); |
| 4915 this._returnType = becomeParentOf(returnType); |
| 4916 this._name = becomeParentOf(name); |
| 4917 this._parameters = becomeParentOf(parameters); |
| 4918 this._initializers.addAll(initializers); |
| 4919 this._redirectedConstructor = becomeParentOf(redirectedConstructor); |
| 4920 this._body = becomeParentOf(body); |
| 4921 } |
| 4922 |
| 4923 @override |
| 4924 accept(AstVisitor visitor) => visitor.visitConstructorDeclaration(this); |
| 4925 |
| 4926 /** |
| 4927 * Return the body of the constructor, or `null` if the constructor does not h
ave a body. |
| 4928 * |
| 4929 * @return the body of the constructor |
| 4930 */ |
| 4931 FunctionBody get body => _body; |
| 4932 |
| 4933 @override |
| 4934 Token get endToken { |
| 4935 if (_body != null) { |
| 4936 return _body.endToken; |
| 4937 } else if (!_initializers.isEmpty) { |
| 4938 return _initializers.endToken; |
| 4939 } |
| 4940 return _parameters.endToken; |
| 4941 } |
| 4942 |
| 4943 /** |
| 4944 * Return the initializers associated with the constructor. |
| 4945 * |
| 4946 * @return the initializers associated with the constructor |
| 4947 */ |
| 4948 NodeList<ConstructorInitializer> get initializers => _initializers; |
| 4949 |
| 4950 /** |
| 4951 * Return the name of the constructor, or `null` if the constructor being decl
ared is |
| 4952 * unnamed. |
| 4953 * |
| 4954 * @return the name of the constructor |
| 4955 */ |
| 4956 SimpleIdentifier get name => _name; |
| 4957 |
| 4958 /** |
| 4959 * Return the parameters associated with the constructor. |
| 4960 * |
| 4961 * @return the parameters associated with the constructor |
| 4962 */ |
| 4963 FormalParameterList get parameters => _parameters; |
| 4964 |
| 4965 /** |
| 4966 * Return the name of the constructor to which this constructor will be redire
cted, or |
| 4967 * `null` if this is not a redirecting factory constructor. |
| 4968 * |
| 4969 * @return the name of the constructor to which this constructor will be redir
ected |
| 4970 */ |
| 4971 ConstructorName get redirectedConstructor => _redirectedConstructor; |
| 4972 |
| 4973 /** |
| 4974 * Return the type of object being created. This can be different than the typ
e in which the |
| 4975 * constructor is being declared if the constructor is the implementation of a
factory |
| 4976 * constructor. |
| 4977 * |
| 4978 * @return the type of object being created |
| 4979 */ |
| 4980 Identifier get returnType => _returnType; |
| 4981 |
| 4982 /** |
| 4983 * Set the body of the constructor to the given function body. |
| 4984 * |
| 4985 * @param functionBody the body of the constructor |
| 4986 */ |
| 4987 void set body(FunctionBody functionBody) { |
| 4988 _body = becomeParentOf(functionBody); |
| 4989 } |
| 4990 |
| 4991 /** |
| 4992 * Set the name of the constructor to the given identifier. |
| 4993 * |
| 4994 * @param identifier the name of the constructor |
| 4995 */ |
| 4996 void set name(SimpleIdentifier identifier) { |
| 4997 _name = becomeParentOf(identifier); |
| 4998 } |
| 4999 |
| 5000 /** |
| 5001 * Set the parameters associated with the constructor to the given list of par
ameters. |
| 5002 * |
| 5003 * @param parameters the parameters associated with the constructor |
| 5004 */ |
| 5005 void set parameters(FormalParameterList parameters) { |
| 5006 this._parameters = becomeParentOf(parameters); |
| 5007 } |
| 5008 |
| 5009 /** |
| 5010 * Set the name of the constructor to which this constructor will be redirecte
d to the given |
| 5011 * constructor name. |
| 5012 * |
| 5013 * @param redirectedConstructor the name of the constructor to which this cons
tructor will be |
| 5014 * redirected |
| 5015 */ |
| 5016 void set redirectedConstructor(ConstructorName redirectedConstructor) { |
| 5017 this._redirectedConstructor = becomeParentOf(redirectedConstructor); |
| 5018 } |
| 5019 |
| 5020 /** |
| 5021 * Set the type of object being created to the given type name. |
| 5022 * |
| 5023 * @param typeName the type of object being created |
| 5024 */ |
| 5025 void set returnType(Identifier typeName) { |
| 5026 _returnType = becomeParentOf(typeName); |
| 5027 } |
| 5028 |
| 5029 @override |
| 5030 void visitChildren(AstVisitor visitor) { |
| 5031 super.visitChildren(visitor); |
| 5032 safelyVisitChild(_returnType, visitor); |
| 5033 safelyVisitChild(_name, visitor); |
| 5034 safelyVisitChild(_parameters, visitor); |
| 5035 _initializers.accept(visitor); |
| 5036 safelyVisitChild(_redirectedConstructor, visitor); |
| 5037 safelyVisitChild(_body, visitor); |
| 5038 } |
| 5039 |
| 5040 @override |
| 5041 Token get firstTokenAfterCommentAndMetadata { |
| 5042 Token leftMost = _leftMost([externalKeyword, constKeyword, factoryKeyword]); |
| 5043 if (leftMost != null) { |
| 5044 return leftMost; |
| 5045 } |
| 5046 return _returnType.beginToken; |
| 5047 } |
| 5048 |
| 5049 /** |
| 5050 * Return the left-most of the given tokens, or `null` if there are no tokens
given or if |
| 5051 * all of the given tokens are `null`. |
| 5052 * |
| 5053 * @param tokens the tokens being compared to find the left-most token |
| 5054 * @return the left-most of the given tokens |
| 5055 */ |
| 5056 Token _leftMost(List<Token> tokens) { |
| 5057 Token leftMost = null; |
| 5058 int offset = 2147483647; |
| 5059 for (Token token in tokens) { |
| 5060 if (token != null && token.offset < offset) { |
| 5061 leftMost = token; |
| 5062 } |
| 5063 } |
| 5064 return leftMost; |
| 5065 } |
| 5066 } |
| 5067 |
| 5068 /** |
| 5069 * Instances of the class `ConstructorFieldInitializer` represent the initializa
tion of a |
| 5070 * field within a constructor's initialization list. |
| 5071 * |
| 5072 * <pre> |
| 5073 * fieldInitializer ::= |
| 5074 * ('this' '.')? [SimpleIdentifier] '=' [Expression] |
| 5075 * </pre> |
| 5076 */ |
| 5077 class ConstructorFieldInitializer extends ConstructorInitializer { |
| 5078 /** |
| 5079 * The token for the 'this' keyword, or `null` if there is no 'this' keyword. |
| 5080 */ |
| 5081 Token keyword; |
| 5082 |
| 5083 /** |
| 5084 * The token for the period after the 'this' keyword, or `null` if there is no
'this' |
| 5085 * keyword. |
| 5086 */ |
| 5087 Token period; |
| 5088 |
| 5089 /** |
| 5090 * The name of the field being initialized. |
| 5091 */ |
| 5092 SimpleIdentifier _fieldName; |
| 5093 |
| 5094 /** |
| 5095 * The token for the equal sign between the field name and the expression. |
| 5096 */ |
| 5097 Token equals; |
| 5098 |
| 5099 /** |
| 5100 * The expression computing the value to which the field will be initialized. |
| 5101 */ |
| 5102 Expression _expression; |
| 5103 |
| 5104 /** |
| 5105 * Initialize a newly created field initializer to initialize the field with t
he given name to the |
| 5106 * value of the given expression. |
| 5107 * |
| 5108 * @param keyword the token for the 'this' keyword |
| 5109 * @param period the token for the period after the 'this' keyword |
| 5110 * @param fieldName the name of the field being initialized |
| 5111 * @param equals the token for the equal sign between the field name and the e
xpression |
| 5112 * @param expression the expression computing the value to which the field wil
l be initialized |
| 5113 */ |
| 5114 ConstructorFieldInitializer(this.keyword, this.period, SimpleIdentifier fieldN
ame, this.equals, Expression expression) { |
| 5115 this._fieldName = becomeParentOf(fieldName); |
| 5116 this._expression = becomeParentOf(expression); |
| 5117 } |
| 5118 |
| 5119 @override |
| 5120 accept(AstVisitor visitor) => visitor.visitConstructorFieldInitializer(this); |
| 5121 |
| 5122 @override |
| 5123 Token get beginToken { |
| 5124 if (keyword != null) { |
| 5125 return keyword; |
| 5126 } |
| 5127 return _fieldName.beginToken; |
| 5128 } |
| 5129 |
| 5130 @override |
| 5131 Token get endToken => _expression.endToken; |
| 5132 |
| 5133 /** |
| 5134 * Return the expression computing the value to which the field will be initia
lized. |
| 5135 * |
| 5136 * @return the expression computing the value to which the field will be initi
alized |
| 5137 */ |
| 5138 Expression get expression => _expression; |
| 5139 |
| 5140 /** |
| 5141 * Return the name of the field being initialized. |
| 5142 * |
| 5143 * @return the name of the field being initialized |
| 5144 */ |
| 5145 SimpleIdentifier get fieldName => _fieldName; |
| 5146 |
| 5147 /** |
| 5148 * Set the expression computing the value to which the field will be initializ
ed to the given |
| 5149 * expression. |
| 5150 * |
| 5151 * @param expression the expression computing the value to which the field wil
l be initialized |
| 5152 */ |
| 5153 void set expression(Expression expression) { |
| 5154 this._expression = becomeParentOf(expression); |
| 5155 } |
| 5156 |
| 5157 /** |
| 5158 * Set the name of the field being initialized to the given identifier. |
| 5159 * |
| 5160 * @param identifier the name of the field being initialized |
| 5161 */ |
| 5162 void set fieldName(SimpleIdentifier identifier) { |
| 5163 _fieldName = becomeParentOf(identifier); |
| 5164 } |
| 5165 |
| 5166 @override |
| 5167 void visitChildren(AstVisitor visitor) { |
| 5168 safelyVisitChild(_fieldName, visitor); |
| 5169 safelyVisitChild(_expression, visitor); |
| 5170 } |
| 5171 } |
| 5172 |
| 5173 /** |
| 5174 * Instances of the class `ConstructorInitializer` defines the behavior of nodes
that can |
| 5175 * occur in the initializer list of a constructor declaration. |
| 5176 * |
| 5177 * <pre> |
| 5178 * constructorInitializer ::= |
| 5179 * [SuperConstructorInvocation] |
| 5180 * | [ConstructorFieldInitializer] |
| 5181 * </pre> |
| 5182 */ |
| 5183 abstract class ConstructorInitializer extends AstNode { |
| 5184 } |
| 5185 |
| 5186 /** |
| 5187 * Instances of the class `ConstructorName` represent the name of the constructo
r. |
| 5188 * |
| 5189 * <pre> |
| 5190 * constructorName: |
| 5191 * type ('.' identifier)? |
| 5192 * </pre> |
| 5193 */ |
| 5194 class ConstructorName extends AstNode { |
| 5195 /** |
| 5196 * The name of the type defining the constructor. |
| 5197 */ |
| 5198 TypeName _type; |
| 5199 |
| 5200 /** |
| 5201 * The token for the period before the constructor name, or `null` if the spec
ified |
| 5202 * constructor is the unnamed constructor. |
| 5203 */ |
| 5204 Token period; |
| 5205 |
| 5206 /** |
| 5207 * The name of the constructor, or `null` if the specified constructor is the
unnamed |
| 5208 * constructor. |
| 5209 */ |
| 5210 SimpleIdentifier _name; |
| 5211 |
| 5212 /** |
| 5213 * The element associated with this constructor name based on static type info
rmation, or |
| 5214 * `null` if the AST structure has not been resolved or if this constructor na
me could not |
| 5215 * be resolved. |
| 5216 */ |
| 5217 ConstructorElement _staticElement; |
| 5218 |
| 5219 /** |
| 5220 * Initialize a newly created constructor name. |
| 5221 * |
| 5222 * @param type the name of the type defining the constructor |
| 5223 * @param period the token for the period before the constructor name |
| 5224 * @param name the name of the constructor |
| 5225 */ |
| 5226 ConstructorName(TypeName type, this.period, SimpleIdentifier name) { |
| 5227 this._type = becomeParentOf(type); |
| 5228 this._name = becomeParentOf(name); |
| 5229 } |
| 5230 |
| 5231 @override |
| 5232 accept(AstVisitor visitor) => visitor.visitConstructorName(this); |
| 5233 |
| 5234 @override |
| 5235 Token get beginToken => _type.beginToken; |
| 5236 |
| 5237 @override |
| 5238 Token get endToken { |
| 5239 if (_name != null) { |
| 5240 return _name.endToken; |
| 5241 } |
| 5242 return _type.endToken; |
| 5243 } |
| 5244 |
| 5245 /** |
| 5246 * Return the name of the constructor, or `null` if the specified constructor
is the unnamed |
| 5247 * constructor. |
| 5248 * |
| 5249 * @return the name of the constructor |
| 5250 */ |
| 5251 SimpleIdentifier get name => _name; |
| 5252 |
| 5253 /** |
| 5254 * Return the element associated with this constructor name based on static ty
pe information, or |
| 5255 * `null` if the AST structure has not been resolved or if this constructor na
me could not |
| 5256 * be resolved. |
| 5257 * |
| 5258 * @return the element associated with this constructor name |
| 5259 */ |
| 5260 ConstructorElement get staticElement => _staticElement; |
| 5261 |
| 5262 /** |
| 5263 * Return the name of the type defining the constructor. |
| 5264 * |
| 5265 * @return the name of the type defining the constructor |
| 5266 */ |
| 5267 TypeName get type => _type; |
| 5268 |
| 5269 /** |
| 5270 * Set the name of the constructor to the given name. |
| 5271 * |
| 5272 * @param name the name of the constructor |
| 5273 */ |
| 5274 void set name(SimpleIdentifier name) { |
| 5275 this._name = becomeParentOf(name); |
| 5276 } |
| 5277 |
| 5278 /** |
| 5279 * Set the element associated with this constructor name based on static type
information to the |
| 5280 * given element. |
| 5281 * |
| 5282 * @param element the element to be associated with this constructor name |
| 5283 */ |
| 5284 void set staticElement(ConstructorElement element) { |
| 5285 _staticElement = element; |
| 5286 } |
| 5287 |
| 5288 /** |
| 5289 * Set the name of the type defining the constructor to the given type name. |
| 5290 * |
| 5291 * @param type the name of the type defining the constructor |
| 5292 */ |
| 5293 void set type(TypeName type) { |
| 5294 this._type = becomeParentOf(type); |
| 5295 } |
| 5296 |
| 5297 @override |
| 5298 void visitChildren(AstVisitor visitor) { |
| 5299 safelyVisitChild(_type, visitor); |
| 5300 safelyVisitChild(_name, visitor); |
| 5301 } |
| 5302 } |
| 5303 |
| 5304 /** |
| 5305 * Instances of the class `ContinueStatement` represent a continue statement. |
| 5306 * |
| 5307 * <pre> |
| 5308 * continueStatement ::= |
| 5309 * 'continue' [SimpleIdentifier]? ';' |
| 5310 * </pre> |
| 5311 */ |
| 5312 class ContinueStatement extends Statement { |
| 5313 /** |
| 5314 * The token representing the 'continue' keyword. |
| 5315 */ |
| 5316 Token keyword; |
| 5317 |
| 5318 /** |
| 5319 * The label associated with the statement, or `null` if there is no label. |
| 5320 */ |
| 5321 SimpleIdentifier _label; |
| 5322 |
| 5323 /** |
| 5324 * The semicolon terminating the statement. |
| 5325 */ |
| 5326 Token semicolon; |
| 5327 |
| 5328 /** |
| 5329 * Initialize a newly created continue statement. |
| 5330 * |
| 5331 * @param keyword the token representing the 'continue' keyword |
| 5332 * @param label the label associated with the statement |
| 5333 * @param semicolon the semicolon terminating the statement |
| 5334 */ |
| 5335 ContinueStatement(this.keyword, SimpleIdentifier label, this.semicolon) { |
| 5336 this._label = becomeParentOf(label); |
| 5337 } |
| 5338 |
| 5339 @override |
| 5340 accept(AstVisitor visitor) => visitor.visitContinueStatement(this); |
| 5341 |
| 5342 @override |
| 5343 Token get beginToken => keyword; |
| 5344 |
| 5345 @override |
| 5346 Token get endToken => semicolon; |
| 5347 |
| 5348 /** |
| 5349 * Return the label associated with the statement, or `null` if there is no la
bel. |
| 5350 * |
| 5351 * @return the label associated with the statement |
| 5352 */ |
| 5353 SimpleIdentifier get label => _label; |
| 5354 |
| 5355 /** |
| 5356 * Set the label associated with the statement to the given label. |
| 5357 * |
| 5358 * @param identifier the label associated with the statement |
| 5359 */ |
| 5360 void set label(SimpleIdentifier identifier) { |
| 5361 _label = becomeParentOf(identifier); |
| 5362 } |
| 5363 |
| 5364 @override |
| 5365 void visitChildren(AstVisitor visitor) { |
| 5366 safelyVisitChild(_label, visitor); |
| 5367 } |
| 5368 } |
| 5369 |
| 5370 /** |
| 5371 * The abstract class `Declaration` defines the behavior common to nodes that re
present the |
| 5372 * declaration of a name. Each declared name is visible within a name scope. |
| 5373 */ |
| 5374 abstract class Declaration extends AnnotatedNode { |
| 5375 /** |
| 5376 * Initialize a newly created declaration. |
| 5377 * |
| 5378 * @param comment the documentation comment associated with this declaration |
| 5379 * @param metadata the annotations associated with this declaration |
| 5380 */ |
| 5381 Declaration(Comment comment, List<Annotation> metadata) : super(comment, metad
ata); |
| 5382 |
| 5383 /** |
| 5384 * Return the element associated with this declaration, or `null` if either th
is node |
| 5385 * corresponds to a list of declarations or if the AST structure has not been
resolved. |
| 5386 * |
| 5387 * @return the element associated with this declaration |
| 5388 */ |
| 5389 Element get element; |
| 5390 } |
| 5391 |
| 5392 /** |
| 5393 * Instances of the class `DeclaredIdentifier` represent the declaration of a si
ngle |
| 5394 * identifier. |
| 5395 * |
| 5396 * <pre> |
| 5397 * declaredIdentifier ::= |
| 5398 * ([Annotation] finalConstVarOrType [SimpleIdentifier] |
| 5399 * </pre> |
| 5400 */ |
| 5401 class DeclaredIdentifier extends Declaration { |
| 5402 /** |
| 5403 * The token representing either the 'final', 'const' or 'var' keyword, or `nu
ll` if no |
| 5404 * keyword was used. |
| 5405 */ |
| 5406 Token keyword; |
| 5407 |
| 5408 /** |
| 5409 * The name of the declared type of the parameter, or `null` if the parameter
does not have |
| 5410 * a declared type. |
| 5411 */ |
| 5412 TypeName _type; |
| 5413 |
| 5414 /** |
| 5415 * The name of the variable being declared. |
| 5416 */ |
| 5417 SimpleIdentifier _identifier; |
| 5418 |
| 5419 /** |
| 5420 * Initialize a newly created formal parameter. |
| 5421 * |
| 5422 * @param comment the documentation comment associated with this parameter |
| 5423 * @param metadata the annotations associated with this parameter |
| 5424 * @param keyword the token representing either the 'final', 'const' or 'var'
keyword |
| 5425 * @param type the name of the declared type of the parameter |
| 5426 * @param identifier the name of the parameter being declared |
| 5427 */ |
| 5428 DeclaredIdentifier(Comment comment, List<Annotation> metadata, this.keyword, T
ypeName type, SimpleIdentifier identifier) : super(comment, metadata) { |
| 5429 this._type = becomeParentOf(type); |
| 5430 this._identifier = becomeParentOf(identifier); |
| 5431 } |
| 5432 |
| 5433 @override |
| 5434 accept(AstVisitor visitor) => visitor.visitDeclaredIdentifier(this); |
| 5435 |
| 5436 @override |
| 5437 LocalVariableElement get element { |
| 5438 SimpleIdentifier identifier = this.identifier; |
| 5439 if (identifier == null) { |
| 5440 return null; |
| 5441 } |
| 5442 return identifier.staticElement as LocalVariableElement; |
| 5443 } |
| 5444 |
| 5445 @override |
| 5446 Token get endToken => _identifier.endToken; |
| 5447 |
| 5448 /** |
| 5449 * Return the name of the variable being declared. |
| 5450 * |
| 5451 * @return the name of the variable being declared |
| 5452 */ |
| 5453 SimpleIdentifier get identifier => _identifier; |
| 5454 |
| 5455 /** |
| 5456 * Return the name of the declared type of the parameter, or `null` if the par
ameter does |
| 5457 * not have a declared type. |
| 5458 * |
| 5459 * @return the name of the declared type of the parameter |
| 5460 */ |
| 5461 TypeName get type => _type; |
| 5462 |
| 5463 /** |
| 5464 * Return `true` if this variable was declared with the 'const' modifier. |
| 5465 * |
| 5466 * @return `true` if this variable was declared with the 'const' modifier |
| 5467 */ |
| 5468 bool get isConst => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.CONST; |
| 5469 |
| 5470 /** |
| 5471 * Return `true` if this variable was declared with the 'final' modifier. Vari
ables that are |
| 5472 * declared with the 'const' modifier will return `false` even though they are
implicitly |
| 5473 * final. |
| 5474 * |
| 5475 * @return `true` if this variable was declared with the 'final' modifier |
| 5476 */ |
| 5477 bool get isFinal => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.FINAL; |
| 5478 |
| 5479 /** |
| 5480 * Set the name of the variable being declared to the given name. |
| 5481 * |
| 5482 * @param identifier the new name of the variable being declared |
| 5483 */ |
| 5484 void set identifier(SimpleIdentifier identifier) { |
| 5485 this._identifier = becomeParentOf(identifier); |
| 5486 } |
| 5487 |
| 5488 /** |
| 5489 * Set the name of the declared type of the parameter to the given type name. |
| 5490 * |
| 5491 * @param typeName the name of the declared type of the parameter |
| 5492 */ |
| 5493 void set type(TypeName typeName) { |
| 5494 _type = becomeParentOf(typeName); |
| 5495 } |
| 5496 |
| 5497 @override |
| 5498 void visitChildren(AstVisitor visitor) { |
| 5499 super.visitChildren(visitor); |
| 5500 safelyVisitChild(_type, visitor); |
| 5501 safelyVisitChild(_identifier, visitor); |
| 5502 } |
| 5503 |
| 5504 @override |
| 5505 Token get firstTokenAfterCommentAndMetadata { |
| 5506 if (keyword != null) { |
| 5507 return keyword; |
| 5508 } else if (_type != null) { |
| 5509 return _type.beginToken; |
| 5510 } |
| 5511 return _identifier.beginToken; |
| 5512 } |
| 5513 } |
| 5514 |
| 5515 /** |
| 5516 * Instances of the class `DefaultFormalParameter` represent a formal parameter
with a default |
| 5517 * value. There are two kinds of parameters that are both represented by this cl
ass: named formal |
| 5518 * parameters and positional formal parameters. |
| 5519 * |
| 5520 * <pre> |
| 5521 * defaultFormalParameter ::= |
| 5522 * [NormalFormalParameter] ('=' [Expression])? |
| 5523 * |
| 5524 * defaultNamedParameter ::= |
| 5525 * [NormalFormalParameter] (':' [Expression])? |
| 5526 * </pre> |
| 5527 */ |
| 5528 class DefaultFormalParameter extends FormalParameter { |
| 5529 /** |
| 5530 * The formal parameter with which the default value is associated. |
| 5531 */ |
| 5532 NormalFormalParameter _parameter; |
| 5533 |
| 5534 /** |
| 5535 * The kind of this parameter. |
| 5536 */ |
| 5537 ParameterKind kind; |
| 5538 |
| 5539 /** |
| 5540 * The token separating the parameter from the default value, or `null` if the
re is no |
| 5541 * default value. |
| 5542 */ |
| 5543 Token separator; |
| 5544 |
| 5545 /** |
| 5546 * The expression computing the default value for the parameter, or `null` if
there is no |
| 5547 * default value. |
| 5548 */ |
| 5549 Expression _defaultValue; |
| 5550 |
| 5551 /** |
| 5552 * Initialize a newly created default formal parameter. |
| 5553 * |
| 5554 * @param parameter the formal parameter with which the default value is assoc
iated |
| 5555 * @param kind the kind of this parameter |
| 5556 * @param separator the token separating the parameter from the default value |
| 5557 * @param defaultValue the expression computing the default value for the para
meter |
| 5558 */ |
| 5559 DefaultFormalParameter(NormalFormalParameter parameter, this.kind, this.separa
tor, Expression defaultValue) { |
| 5560 this._parameter = becomeParentOf(parameter); |
| 5561 this._defaultValue = becomeParentOf(defaultValue); |
| 5562 } |
| 5563 |
| 5564 @override |
| 5565 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this); |
| 5566 |
| 5567 @override |
| 5568 Token get beginToken => _parameter.beginToken; |
| 5569 |
| 5570 /** |
| 5571 * Return the expression computing the default value for the parameter, or `nu
ll` if there |
| 5572 * is no default value. |
| 5573 * |
| 5574 * @return the expression computing the default value for the parameter |
| 5575 */ |
| 5576 Expression get defaultValue => _defaultValue; |
| 5577 |
| 5578 @override |
| 5579 Token get endToken { |
| 5580 if (_defaultValue != null) { |
| 5581 return _defaultValue.endToken; |
| 5582 } |
| 5583 return _parameter.endToken; |
| 5584 } |
| 5585 |
| 5586 @override |
| 5587 SimpleIdentifier get identifier => _parameter.identifier; |
| 5588 |
| 5589 /** |
| 5590 * Return the formal parameter with which the default value is associated. |
| 5591 * |
| 5592 * @return the formal parameter with which the default value is associated |
| 5593 */ |
| 5594 NormalFormalParameter get parameter => _parameter; |
| 5595 |
| 5596 @override |
| 5597 bool get isConst => _parameter != null && _parameter.isConst; |
| 5598 |
| 5599 @override |
| 5600 bool get isFinal => _parameter != null && _parameter.isFinal; |
| 5601 |
| 5602 /** |
| 5603 * Set the expression computing the default value for the parameter to the giv
en expression. |
| 5604 * |
| 5605 * @param expression the expression computing the default value for the parame
ter |
| 5606 */ |
| 5607 void set defaultValue(Expression expression) { |
| 5608 _defaultValue = becomeParentOf(expression); |
| 5609 } |
| 5610 |
| 5611 /** |
| 5612 * Set the formal parameter with which the default value is associated to the
given parameter. |
| 5613 * |
| 5614 * @param formalParameter the formal parameter with which the default value is
associated |
| 5615 */ |
| 5616 void set parameter(NormalFormalParameter formalParameter) { |
| 5617 _parameter = becomeParentOf(formalParameter); |
| 5618 } |
| 5619 |
| 5620 @override |
| 5621 void visitChildren(AstVisitor visitor) { |
| 5622 safelyVisitChild(_parameter, visitor); |
| 5623 safelyVisitChild(_defaultValue, visitor); |
| 5624 } |
| 5625 } |
| 5626 |
| 5627 /** |
| 5628 * This recursive Ast visitor is used to run over [Expression]s to determine if
the expression |
| 5629 * is composed by at least one deferred [PrefixedIdentifier]. |
| 5630 * |
| 5631 * @see PrefixedIdentifier#isDeferred() |
| 5632 */ |
| 5633 class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<Object> { |
| 5634 bool _result = false; |
| 5635 |
| 5636 /** |
| 5637 * Return the result, `true` if the visitor found a [PrefixedIdentifier] that
returned |
| 5638 * `true` to the [PrefixedIdentifier#isDeferred] query. |
| 5639 * |
| 5640 * @return `true` if the visitor found a [PrefixedIdentifier] that returned |
| 5641 * `true` to the [PrefixedIdentifier#isDeferred] query |
| 5642 */ |
| 5643 bool get result => _result; |
| 5644 |
| 5645 @override |
| 5646 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 5647 // If result is already true, skip. |
| 5648 if (!_result) { |
| 5649 // Set result to true if isDeferred() is true |
| 5650 if (node.isDeferred) { |
| 5651 _result = true; |
| 5652 } |
| 5653 } |
| 5654 return null; |
| 5655 } |
| 5656 } |
| 5657 |
| 5658 /** |
| 5659 * The abstract class `Directive` defines the behavior common to nodes that repr
esent a |
| 5660 * directive. |
| 5661 * |
| 5662 * <pre> |
| 5663 * directive ::= |
| 5664 * [ExportDirective] |
| 5665 * | [ImportDirective] |
| 5666 * | [LibraryDirective] |
| 5667 * | [PartDirective] |
| 5668 * | [PartOfDirective] |
| 5669 * </pre> |
| 5670 */ |
| 5671 abstract class Directive extends AnnotatedNode { |
| 5672 /** |
| 5673 * The element associated with this directive, or `null` if the AST structure
has not been |
| 5674 * resolved or if this directive could not be resolved. |
| 5675 */ |
| 5676 Element _element; |
| 5677 |
| 5678 /** |
| 5679 * Initialize a newly create directive. |
| 5680 * |
| 5681 * @param comment the documentation comment associated with this directive |
| 5682 * @param metadata the annotations associated with the directive |
| 5683 */ |
| 5684 Directive(Comment comment, List<Annotation> metadata) : super(comment, metadat
a); |
| 5685 |
| 5686 /** |
| 5687 * Return the element associated with this directive, or `null` if the AST str
ucture has not |
| 5688 * been resolved or if this directive could not be resolved. Examples of the l
atter case include a |
| 5689 * directive that contains an invalid URL or a URL that does not exist. |
| 5690 * |
| 5691 * @return the element associated with this directive |
| 5692 */ |
| 5693 Element get element => _element; |
| 5694 |
| 5695 /** |
| 5696 * Return the token representing the keyword that introduces this directive ('
import', 'export', |
| 5697 * 'library' or 'part'). |
| 5698 * |
| 5699 * @return the token representing the keyword that introduces this directive |
| 5700 */ |
| 5701 Token get keyword; |
| 5702 |
| 5703 /** |
| 5704 * Set the element associated with this directive to the given element. |
| 5705 * |
| 5706 * @param element the element associated with this directive |
| 5707 */ |
| 5708 void set element(Element element) { |
| 5709 this._element = element; |
| 5710 } |
| 5711 } |
| 5712 |
| 5713 /** |
| 5714 * Instances of the class `DoStatement` represent a do statement. |
| 5715 * |
| 5716 * <pre> |
| 5717 * doStatement ::= |
| 5718 * 'do' [Statement] 'while' '(' [Expression] ')' ';' |
| 5719 * </pre> |
| 5720 */ |
| 5721 class DoStatement extends Statement { |
| 5722 /** |
| 5723 * The token representing the 'do' keyword. |
| 5724 */ |
| 5725 Token doKeyword; |
| 5726 |
| 5727 /** |
| 5728 * The body of the loop. |
| 5729 */ |
| 5730 Statement _body; |
| 5731 |
| 5732 /** |
| 5733 * The token representing the 'while' keyword. |
| 5734 */ |
| 5735 Token whileKeyword; |
| 5736 |
| 5737 /** |
| 5738 * The left parenthesis. |
| 5739 */ |
| 5740 Token _leftParenthesis; |
| 5741 |
| 5742 /** |
| 5743 * The condition that determines when the loop will terminate. |
| 5744 */ |
| 5745 Expression _condition; |
| 5746 |
| 5747 /** |
| 5748 * The right parenthesis. |
| 5749 */ |
| 5750 Token _rightParenthesis; |
| 5751 |
| 5752 /** |
| 5753 * The semicolon terminating the statement. |
| 5754 */ |
| 5755 Token semicolon; |
| 5756 |
| 5757 /** |
| 5758 * Initialize a newly created do loop. |
| 5759 * |
| 5760 * @param doKeyword the token representing the 'do' keyword |
| 5761 * @param body the body of the loop |
| 5762 * @param whileKeyword the token representing the 'while' keyword |
| 5763 * @param leftParenthesis the left parenthesis |
| 5764 * @param condition the condition that determines when the loop will terminate |
| 5765 * @param rightParenthesis the right parenthesis |
| 5766 * @param semicolon the semicolon terminating the statement |
| 5767 */ |
| 5768 DoStatement(this.doKeyword, Statement body, this.whileKeyword, Token leftParen
thesis, Expression condition, Token rightParenthesis, this.semicolon) { |
| 5769 this._body = becomeParentOf(body); |
| 5770 this._leftParenthesis = leftParenthesis; |
| 5771 this._condition = becomeParentOf(condition); |
| 5772 this._rightParenthesis = rightParenthesis; |
| 5773 } |
| 5774 |
| 5775 @override |
| 5776 accept(AstVisitor visitor) => visitor.visitDoStatement(this); |
| 5777 |
| 5778 @override |
| 5779 Token get beginToken => doKeyword; |
| 5780 |
| 5781 /** |
| 5782 * Return the body of the loop. |
| 5783 * |
| 5784 * @return the body of the loop |
| 5785 */ |
| 5786 Statement get body => _body; |
| 5787 |
| 5788 /** |
| 5789 * Return the condition that determines when the loop will terminate. |
| 5790 * |
| 5791 * @return the condition that determines when the loop will terminate |
| 5792 */ |
| 5793 Expression get condition => _condition; |
| 5794 |
| 5795 @override |
| 5796 Token get endToken => semicolon; |
| 5797 |
| 5798 /** |
| 5799 * Return the left parenthesis. |
| 5800 * |
| 5801 * @return the left parenthesis |
| 5802 */ |
| 5803 Token get leftParenthesis => _leftParenthesis; |
| 5804 |
| 5805 /** |
| 5806 * Return the right parenthesis. |
| 5807 * |
| 5808 * @return the right parenthesis |
| 5809 */ |
| 5810 Token get rightParenthesis => _rightParenthesis; |
| 5811 |
| 5812 /** |
| 5813 * Set the body of the loop to the given statement. |
| 5814 * |
| 5815 * @param statement the body of the loop |
| 5816 */ |
| 5817 void set body(Statement statement) { |
| 5818 _body = becomeParentOf(statement); |
| 5819 } |
| 5820 |
| 5821 /** |
| 5822 * Set the condition that determines when the loop will terminate to the given
expression. |
| 5823 * |
| 5824 * @param expression the condition that determines when the loop will terminat
e |
| 5825 */ |
| 5826 void set condition(Expression expression) { |
| 5827 _condition = becomeParentOf(expression); |
| 5828 } |
| 5829 |
| 5830 /** |
| 5831 * Set the left parenthesis to the given token. |
| 5832 * |
| 5833 * @param parenthesis the left parenthesis |
| 5834 */ |
| 5835 void set leftParenthesis(Token parenthesis) { |
| 5836 _leftParenthesis = parenthesis; |
| 5837 } |
| 5838 |
| 5839 /** |
| 5840 * Set the right parenthesis to the given token. |
| 5841 * |
| 5842 * @param parenthesis the right parenthesis |
| 5843 */ |
| 5844 void set rightParenthesis(Token parenthesis) { |
| 5845 _rightParenthesis = parenthesis; |
| 5846 } |
| 5847 |
| 5848 @override |
| 5849 void visitChildren(AstVisitor visitor) { |
| 5850 safelyVisitChild(_body, visitor); |
| 5851 safelyVisitChild(_condition, visitor); |
| 5852 } |
| 5853 } |
| 5854 |
| 5855 /** |
| 5856 * Instances of the class `DoubleLiteral` represent a floating point literal exp
ression. |
| 5857 * |
| 5858 * <pre> |
| 5859 * doubleLiteral ::= |
| 5860 * decimalDigit+ ('.' decimalDigit*)? exponent? |
| 5861 * | '.' decimalDigit+ exponent? |
| 5862 * |
| 5863 * exponent ::= |
| 5864 * ('e' | 'E') ('+' | '-')? decimalDigit+ |
| 5865 * </pre> |
| 5866 */ |
| 5867 class DoubleLiteral extends Literal { |
| 5868 /** |
| 5869 * The token representing the literal. |
| 5870 */ |
| 5871 Token literal; |
| 5872 |
| 5873 /** |
| 5874 * The value of the literal. |
| 5875 */ |
| 5876 double value = 0.0; |
| 5877 |
| 5878 /** |
| 5879 * Initialize a newly created floating point literal. |
| 5880 * |
| 5881 * @param literal the token representing the literal |
| 5882 * @param value the value of the literal |
| 5883 */ |
| 5884 DoubleLiteral(this.literal, this.value); |
| 5885 |
| 5886 @override |
| 5887 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this); |
| 5888 |
| 5889 @override |
| 5890 Token get beginToken => literal; |
| 5891 |
| 5892 @override |
| 5893 Token get endToken => literal; |
| 5894 |
| 5895 @override |
| 5896 void visitChildren(AstVisitor visitor) { |
| 5897 } |
| 5898 } |
| 5899 |
| 5900 /** |
| 5901 * Instances of the class `ElementLocator` locate the [Element] |
| 5902 * associated with a given [AstNode]. |
| 5903 */ |
| 5904 class ElementLocator { |
| 5905 /** |
| 5906 * Locate the [Element] associated with the given [AstNode]. |
| 5907 * |
| 5908 * @param node the node (not `null`) |
| 5909 * @return the associated element, or `null` if none is found |
| 5910 */ |
| 5911 static Element locate(AstNode node) { |
| 5912 ElementLocator_ElementMapper mapper = new ElementLocator_ElementMapper(); |
| 5913 return node.accept(mapper); |
| 5914 } |
| 5915 |
| 5916 /** |
| 5917 * Locate the [Element] associated with the given [AstNode] and offset. |
| 5918 * |
| 5919 * @param node the node (not `null`) |
| 5920 * @param offset the offset relative to source |
| 5921 * @return the associated element, or `null` if none is found |
| 5922 */ |
| 5923 static Element locateWithOffset(AstNode node, int offset) { |
| 5924 if (node == null) { |
| 5925 return null; |
| 5926 } |
| 5927 // try to get Element from node |
| 5928 { |
| 5929 Element nodeElement = locate(node); |
| 5930 if (nodeElement != null) { |
| 5931 return nodeElement; |
| 5932 } |
| 5933 } |
| 5934 // try to get Angular specific Element |
| 5935 { |
| 5936 Element element = null; |
| 5937 if (element != null) { |
| 5938 return element; |
| 5939 } |
| 5940 } |
| 5941 // try to get Polymer specific Element |
| 5942 { |
| 5943 Element element = null; |
| 5944 if (element != null) { |
| 5945 return element; |
| 5946 } |
| 5947 } |
| 5948 // no Element |
| 5949 return null; |
| 5950 } |
| 5951 } |
| 5952 |
| 5953 /** |
| 5954 * Visitor that maps nodes to elements. |
| 5955 */ |
| 5956 class ElementLocator_ElementMapper extends GeneralizingAstVisitor<Element> { |
| 5957 @override |
| 5958 Element visitAnnotation(Annotation node) => node.element; |
| 5959 |
| 5960 @override |
| 5961 Element visitAssignmentExpression(AssignmentExpression node) => node.bestEleme
nt; |
| 5962 |
| 5963 @override |
| 5964 Element visitBinaryExpression(BinaryExpression node) => node.bestElement; |
| 5965 |
| 5966 @override |
| 5967 Element visitClassDeclaration(ClassDeclaration node) => node.element; |
| 5968 |
| 5969 @override |
| 5970 Element visitCompilationUnit(CompilationUnit node) => node.element; |
| 5971 |
| 5972 @override |
| 5973 Element visitConstructorDeclaration(ConstructorDeclaration node) => node.eleme
nt; |
| 5974 |
| 5975 @override |
| 5976 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element; |
| 5977 |
| 5978 @override |
| 5979 Element visitIdentifier(Identifier node) { |
| 5980 AstNode parent = node.parent; |
| 5981 // Type name in Annotation |
| 5982 if (parent is Annotation) { |
| 5983 Annotation annotation = parent; |
| 5984 if (identical(annotation.name, node) && annotation.constructorName == null
) { |
| 5985 return annotation.element; |
| 5986 } |
| 5987 } |
| 5988 // Type name in InstanceCreationExpression |
| 5989 { |
| 5990 AstNode typeNameCandidate = parent; |
| 5991 // new prefix.node[.constructorName]() |
| 5992 if (typeNameCandidate is PrefixedIdentifier) { |
| 5993 PrefixedIdentifier prefixedIdentifier = typeNameCandidate as PrefixedIde
ntifier; |
| 5994 if (identical(prefixedIdentifier.identifier, node)) { |
| 5995 typeNameCandidate = prefixedIdentifier.parent; |
| 5996 } |
| 5997 } |
| 5998 // new typeName[.constructorName]() |
| 5999 if (typeNameCandidate is TypeName) { |
| 6000 TypeName typeName = typeNameCandidate as TypeName; |
| 6001 if (typeName.parent is ConstructorName) { |
| 6002 ConstructorName constructorName = typeName.parent as ConstructorName; |
| 6003 return constructorName.staticElement; |
| 6004 } |
| 6005 } |
| 6006 } |
| 6007 // Extra work to map Constructor Declarations to their associated Constructo
r Elements |
| 6008 if (parent is ConstructorDeclaration) { |
| 6009 ConstructorDeclaration decl = parent; |
| 6010 Identifier returnType = decl.returnType; |
| 6011 if (identical(returnType, node)) { |
| 6012 SimpleIdentifier name = decl.name; |
| 6013 if (name != null) { |
| 6014 return name.bestElement; |
| 6015 } |
| 6016 Element element = node.bestElement; |
| 6017 if (element is ClassElement) { |
| 6018 return element.unnamedConstructor; |
| 6019 } |
| 6020 } |
| 6021 } |
| 6022 if (parent is LibraryIdentifier) { |
| 6023 AstNode grandParent = parent.parent; |
| 6024 if (grandParent is PartOfDirective) { |
| 6025 Element element = grandParent.element; |
| 6026 if (element is LibraryElement) { |
| 6027 return element.definingCompilationUnit; |
| 6028 } |
| 6029 } |
| 6030 } |
| 6031 return node.bestElement; |
| 6032 } |
| 6033 |
| 6034 @override |
| 6035 Element visitImportDirective(ImportDirective node) => node.element; |
| 6036 |
| 6037 @override |
| 6038 Element visitIndexExpression(IndexExpression node) => node.bestElement; |
| 6039 |
| 6040 @override |
| 6041 Element visitInstanceCreationExpression(InstanceCreationExpression node) => no
de.staticElement; |
| 6042 |
| 6043 @override |
| 6044 Element visitLibraryDirective(LibraryDirective node) => node.element; |
| 6045 |
| 6046 @override |
| 6047 Element visitMethodDeclaration(MethodDeclaration node) => node.element; |
| 6048 |
| 6049 @override |
| 6050 Element visitMethodInvocation(MethodInvocation node) => node.methodName.bestEl
ement; |
| 6051 |
| 6052 @override |
| 6053 Element visitPostfixExpression(PostfixExpression node) => node.bestElement; |
| 6054 |
| 6055 @override |
| 6056 Element visitPrefixedIdentifier(PrefixedIdentifier node) => node.bestElement; |
| 6057 |
| 6058 @override |
| 6059 Element visitPrefixExpression(PrefixExpression node) => node.bestElement; |
| 6060 |
| 6061 @override |
| 6062 Element visitStringLiteral(StringLiteral node) { |
| 6063 AstNode parent = node.parent; |
| 6064 if (parent is UriBasedDirective) { |
| 6065 return parent.uriElement; |
| 6066 } |
| 6067 return null; |
| 6068 } |
| 6069 |
| 6070 @override |
| 6071 Element visitVariableDeclaration(VariableDeclaration node) => node.element; |
| 6072 } |
| 6073 |
| 6074 /** |
| 6075 * Instances of the class `EmptyFunctionBody` represent an empty function body,
which can only |
| 6076 * appear in constructors or abstract methods. |
| 6077 * |
| 6078 * <pre> |
| 6079 * emptyFunctionBody ::= |
| 6080 * ';' |
| 6081 * </pre> |
| 6082 */ |
| 6083 class EmptyFunctionBody extends FunctionBody { |
| 6084 /** |
| 6085 * The token representing the semicolon that marks the end of the function bod
y. |
| 6086 */ |
| 6087 Token semicolon; |
| 6088 |
| 6089 /** |
| 6090 * Initialize a newly created function body. |
| 6091 * |
| 6092 * @param semicolon the token representing the semicolon that marks the end of
the function body |
| 6093 */ |
| 6094 EmptyFunctionBody(this.semicolon); |
| 6095 |
| 6096 @override |
| 6097 accept(AstVisitor visitor) => visitor.visitEmptyFunctionBody(this); |
| 6098 |
| 6099 @override |
| 6100 Token get beginToken => semicolon; |
| 6101 |
| 6102 @override |
| 6103 Token get endToken => semicolon; |
| 6104 |
| 6105 @override |
| 6106 void visitChildren(AstVisitor visitor) { |
| 6107 } |
| 6108 } |
| 6109 |
| 6110 /** |
| 6111 * Instances of the class `EmptyStatement` represent an empty statement. |
| 6112 * |
| 6113 * <pre> |
| 6114 * emptyStatement ::= |
| 6115 * ';' |
| 6116 * </pre> |
| 6117 */ |
| 6118 class EmptyStatement extends Statement { |
| 6119 /** |
| 6120 * The semicolon terminating the statement. |
| 6121 */ |
| 6122 Token semicolon; |
| 6123 |
| 6124 /** |
| 6125 * Initialize a newly created empty statement. |
| 6126 * |
| 6127 * @param semicolon the semicolon terminating the statement |
| 6128 */ |
| 6129 EmptyStatement(this.semicolon); |
| 6130 |
| 6131 @override |
| 6132 accept(AstVisitor visitor) => visitor.visitEmptyStatement(this); |
| 6133 |
| 6134 @override |
| 6135 Token get beginToken => semicolon; |
| 6136 |
| 6137 @override |
| 6138 Token get endToken => semicolon; |
| 6139 |
| 6140 @override |
| 6141 void visitChildren(AstVisitor visitor) { |
| 6142 } |
| 6143 } |
| 6144 |
| 6145 /** |
| 6146 * Instances of the class `EnumConstantDeclaration` represent the declaration of
an enum |
| 6147 * constant. |
| 6148 */ |
| 6149 class EnumConstantDeclaration extends Declaration { |
| 6150 /** |
| 6151 * The name of the constant. |
| 6152 */ |
| 6153 SimpleIdentifier _name; |
| 6154 |
| 6155 /** |
| 6156 * Initialize a newly created enum constant declaration. |
| 6157 * |
| 6158 * @param comment the documentation comment associated with this declaration |
| 6159 * @param metadata the annotations associated with this declaration |
| 6160 * @param name the name of the constant |
| 6161 */ |
| 6162 EnumConstantDeclaration(Comment comment, List<Annotation> metadata, SimpleIden
tifier name) : super(comment, metadata) { |
| 6163 this._name = becomeParentOf(name); |
| 6164 } |
| 6165 |
| 6166 @override |
| 6167 accept(AstVisitor visitor) => visitor.visitEnumConstantDeclaration(this); |
| 6168 |
| 6169 @override |
| 6170 FieldElement get element => _name == null ? null : (_name.staticElement as Fie
ldElement); |
| 6171 |
| 6172 @override |
| 6173 Token get endToken => _name.endToken; |
| 6174 |
| 6175 /** |
| 6176 * Return the name of the constant. |
| 6177 * |
| 6178 * @return the name of the constant |
| 6179 */ |
| 6180 SimpleIdentifier get name => _name; |
| 6181 |
| 6182 /** |
| 6183 * Set the name of the constant to the given name. |
| 6184 * |
| 6185 * @param name the name of the constant |
| 6186 */ |
| 6187 void set name(SimpleIdentifier name) { |
| 6188 this._name = becomeParentOf(name); |
| 6189 } |
| 6190 |
| 6191 @override |
| 6192 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 6193 } |
| 6194 |
| 6195 /** |
| 6196 * Instances of the class `EnumDeclaration` represent the declaration of an enum
eration. |
| 6197 * |
| 6198 * <pre> |
| 6199 * enumType ::= |
| 6200 * metadata 'enum' [SimpleIdentifier] '{' [SimpleIdentifier] (',' [SimpleIde
ntifier])* (',')? '}' |
| 6201 * </pre> |
| 6202 */ |
| 6203 class EnumDeclaration extends CompilationUnitMember { |
| 6204 /** |
| 6205 * The 'enum' keyword. |
| 6206 */ |
| 6207 Token keyword; |
| 6208 |
| 6209 /** |
| 6210 * The name of the enumeration. |
| 6211 */ |
| 6212 SimpleIdentifier _name; |
| 6213 |
| 6214 /** |
| 6215 * The left curly bracket. |
| 6216 */ |
| 6217 Token leftBracket; |
| 6218 |
| 6219 /** |
| 6220 * The enumeration constants being declared. |
| 6221 */ |
| 6222 NodeList<EnumConstantDeclaration> _constants; |
| 6223 |
| 6224 /** |
| 6225 * The right curly bracket. |
| 6226 */ |
| 6227 Token rightBracket; |
| 6228 |
| 6229 /** |
| 6230 * Initialize a newly created enumeration declaration. |
| 6231 * |
| 6232 * @param comment the documentation comment associated with this member |
| 6233 * @param metadata the annotations associated with this member |
| 6234 * @param keyword the 'enum' keyword |
| 6235 * @param name the name of the enumeration |
| 6236 * @param leftBracket the left curly bracket |
| 6237 * @param constants the enumeration constants being declared |
| 6238 * @param rightBracket the right curly bracket |
| 6239 */ |
| 6240 EnumDeclaration(Comment comment, List<Annotation> metadata, this.keyword, Simp
leIdentifier name, this.leftBracket, List<EnumConstantDeclaration> constants, th
is.rightBracket) : super(comment, metadata) { |
| 6241 this._constants = new NodeList<EnumConstantDeclaration>(this); |
| 6242 this._name = becomeParentOf(name); |
| 6243 this._constants.addAll(constants); |
| 6244 } |
| 6245 |
| 6246 @override |
| 6247 accept(AstVisitor visitor) => visitor.visitEnumDeclaration(this); |
| 6248 |
| 6249 /** |
| 6250 * Return the enumeration constants being declared. |
| 6251 * |
| 6252 * @return the enumeration constants being declared |
| 6253 */ |
| 6254 NodeList<EnumConstantDeclaration> get constants => _constants; |
| 6255 |
| 6256 @override |
| 6257 ClassElement get element => _name != null ? (_name.staticElement as ClassEleme
nt) : null; |
| 6258 |
| 6259 @override |
| 6260 Token get endToken => rightBracket; |
| 6261 |
| 6262 /** |
| 6263 * Return the name of the enumeration. |
| 6264 * |
| 6265 * @return the name of the enumeration |
| 6266 */ |
| 6267 SimpleIdentifier get name => _name; |
| 6268 |
| 6269 /** |
| 6270 * set the name of the enumeration to the given identifier. |
| 6271 * |
| 6272 * @param name the name of the enumeration |
| 6273 */ |
| 6274 void set name(SimpleIdentifier name) { |
| 6275 this._name = becomeParentOf(name); |
| 6276 } |
| 6277 |
| 6278 @override |
| 6279 Token get firstTokenAfterCommentAndMetadata => keyword; |
| 6280 } |
| 6281 |
| 6282 /** |
| 6283 * Ephemeral identifiers are created as needed to mimic the presence of an empty
identifier. |
| 6284 */ |
| 6285 class EphemeralIdentifier extends SimpleIdentifier { |
| 6286 EphemeralIdentifier(AstNode parent, int location) : super(new StringToken(Toke
nType.IDENTIFIER, "", location)) { |
| 6287 parent.becomeParentOf(this); |
| 6288 } |
| 6289 } |
| 6290 |
| 6291 /** |
| 6292 * Instances of the class `ExportDirective` represent an export directive. |
| 6293 * |
| 6294 * <pre> |
| 6295 * exportDirective ::= |
| 6296 * [Annotation] 'export' [StringLiteral] [Combinator]* ';' |
| 6297 * </pre> |
| 6298 */ |
| 6299 class ExportDirective extends NamespaceDirective { |
| 6300 /** |
| 6301 * Initialize a newly created export directive. |
| 6302 * |
| 6303 * @param comment the documentation comment associated with this directive |
| 6304 * @param metadata the annotations associated with the directive |
| 6305 * @param keyword the token representing the 'export' keyword |
| 6306 * @param libraryUri the URI of the library being exported |
| 6307 * @param combinators the combinators used to control which names are exported |
| 6308 * @param semicolon the semicolon terminating the directive |
| 6309 */ |
| 6310 ExportDirective(Comment comment, List<Annotation> metadata, Token keyword, Str
ingLiteral libraryUri, List<Combinator> combinators, Token semicolon) : super(co
mment, metadata, keyword, libraryUri, combinators, semicolon); |
| 6311 |
| 6312 @override |
| 6313 accept(AstVisitor visitor) => visitor.visitExportDirective(this); |
| 6314 |
| 6315 @override |
| 6316 ExportElement get element => super.element as ExportElement; |
| 6317 |
| 6318 @override |
| 6319 LibraryElement get uriElement { |
| 6320 ExportElement exportElement = element; |
| 6321 if (exportElement != null) { |
| 6322 return exportElement.exportedLibrary; |
| 6323 } |
| 6324 return null; |
| 6325 } |
| 6326 |
| 6327 @override |
| 6328 void visitChildren(AstVisitor visitor) { |
| 6329 super.visitChildren(visitor); |
| 6330 combinators.accept(visitor); |
| 6331 } |
| 6332 } |
| 6333 |
| 6334 /** |
| 6335 * Instances of the class `Expression` defines the behavior common to nodes that
represent an |
| 6336 * expression. |
| 6337 * |
| 6338 * <pre> |
| 6339 * expression ::= |
| 6340 * [AssignmentExpression] |
| 6341 * | [ConditionalExpression] cascadeSection* |
| 6342 * | [ThrowExpression] |
| 6343 * </pre> |
| 6344 */ |
| 6345 abstract class Expression extends AstNode { |
| 6346 /** |
| 6347 * An empty array of expressions. |
| 6348 */ |
| 6349 static List<Expression> EMPTY_ARRAY = new List<Expression>(0); |
| 6350 |
| 6351 /** |
| 6352 * The static type of this expression, or `null` if the AST structure has not
been resolved. |
| 6353 */ |
| 6354 DartType staticType; |
| 6355 |
| 6356 /** |
| 6357 * The propagated type of this expression, or `null` if type propagation has n
ot been |
| 6358 * performed on the AST structure. |
| 6359 */ |
| 6360 DartType propagatedType; |
| 6361 |
| 6362 /** |
| 6363 * Return the best parameter element information available for this expression
. If type |
| 6364 * propagation was able to find a better parameter element than static analysi
s, that type will be |
| 6365 * returned. Otherwise, the result of static analysis will be returned. |
| 6366 * |
| 6367 * @return the parameter element representing the parameter to which the value
of this expression |
| 6368 * will be bound |
| 6369 */ |
| 6370 ParameterElement get bestParameterElement { |
| 6371 ParameterElement propagatedElement = propagatedParameterElement; |
| 6372 if (propagatedElement != null) { |
| 6373 return propagatedElement; |
| 6374 } |
| 6375 return staticParameterElement; |
| 6376 } |
| 6377 |
| 6378 /** |
| 6379 * Return the best type information available for this expression. If type pro
pagation was able to |
| 6380 * find a better type than static analysis, that type will be returned. Otherw
ise, the result of |
| 6381 * static analysis will be returned. If no type analysis has been performed, t
hen the type |
| 6382 * 'dynamic' will be returned. |
| 6383 * |
| 6384 * @return the best type information available for this expression |
| 6385 */ |
| 6386 DartType get bestType { |
| 6387 if (propagatedType != null) { |
| 6388 return propagatedType; |
| 6389 } else if (staticType != null) { |
| 6390 return staticType; |
| 6391 } |
| 6392 return DynamicTypeImpl.instance; |
| 6393 } |
| 6394 |
| 6395 /** |
| 6396 * Return the precedence of this expression. The precedence is a positive inte
ger value that |
| 6397 * defines how the source code is parsed into an AST. For example `a * b + c`
is parsed as |
| 6398 * `(a * b) + c` because the precedence of `*` is greater than the precedence
of |
| 6399 * `+`. |
| 6400 * |
| 6401 * You should not assume that returned values will stay the same, they might c
hange as result of |
| 6402 * specification change. Only relative order should be used. |
| 6403 * |
| 6404 * @return the precedence of this expression |
| 6405 */ |
| 6406 int get precedence; |
| 6407 |
| 6408 /** |
| 6409 * If this expression is an argument to an invocation, and the AST structure h
as been resolved, |
| 6410 * and the function being invoked is known based on propagated type informatio
n, and this |
| 6411 * expression corresponds to one of the parameters of the function being invok
ed, then return the |
| 6412 * parameter element representing the parameter to which the value of this exp
ression will be |
| 6413 * bound. Otherwise, return `null`. |
| 6414 * |
| 6415 * @return the parameter element representing the parameter to which the value
of this expression |
| 6416 * will be bound |
| 6417 */ |
| 6418 ParameterElement get propagatedParameterElement { |
| 6419 AstNode parent = this.parent; |
| 6420 if (parent is ArgumentList) { |
| 6421 return parent.getPropagatedParameterElementFor(this); |
| 6422 } else if (parent is IndexExpression) { |
| 6423 IndexExpression indexExpression = parent; |
| 6424 if (identical(indexExpression.index, this)) { |
| 6425 return indexExpression.propagatedParameterElementForIndex; |
| 6426 } |
| 6427 } else if (parent is BinaryExpression) { |
| 6428 BinaryExpression binaryExpression = parent; |
| 6429 if (identical(binaryExpression.rightOperand, this)) { |
| 6430 return binaryExpression.propagatedParameterElementForRightOperand; |
| 6431 } |
| 6432 } else if (parent is AssignmentExpression) { |
| 6433 AssignmentExpression assignmentExpression = parent; |
| 6434 if (identical(assignmentExpression.rightHandSide, this)) { |
| 6435 return assignmentExpression.propagatedParameterElementForRightHandSide; |
| 6436 } |
| 6437 } else if (parent is PrefixExpression) { |
| 6438 return parent.propagatedParameterElementForOperand; |
| 6439 } else if (parent is PostfixExpression) { |
| 6440 return parent.propagatedParameterElementForOperand; |
| 6441 } |
| 6442 return null; |
| 6443 } |
| 6444 |
| 6445 /** |
| 6446 * If this expression is an argument to an invocation, and the AST structure h
as been resolved, |
| 6447 * and the function being invoked is known based on static type information, a
nd this expression |
| 6448 * corresponds to one of the parameters of the function being invoked, then re
turn the parameter |
| 6449 * element representing the parameter to which the value of this expression wi
ll be bound. |
| 6450 * Otherwise, return `null`. |
| 6451 * |
| 6452 * @return the parameter element representing the parameter to which the value
of this expression |
| 6453 * will be bound |
| 6454 */ |
| 6455 ParameterElement get staticParameterElement { |
| 6456 AstNode parent = this.parent; |
| 6457 if (parent is ArgumentList) { |
| 6458 return parent.getStaticParameterElementFor(this); |
| 6459 } else if (parent is IndexExpression) { |
| 6460 IndexExpression indexExpression = parent; |
| 6461 if (identical(indexExpression.index, this)) { |
| 6462 return indexExpression.staticParameterElementForIndex; |
| 6463 } |
| 6464 } else if (parent is BinaryExpression) { |
| 6465 BinaryExpression binaryExpression = parent; |
| 6466 if (identical(binaryExpression.rightOperand, this)) { |
| 6467 return binaryExpression.staticParameterElementForRightOperand; |
| 6468 } |
| 6469 } else if (parent is AssignmentExpression) { |
| 6470 AssignmentExpression assignmentExpression = parent; |
| 6471 if (identical(assignmentExpression.rightHandSide, this)) { |
| 6472 return assignmentExpression.staticParameterElementForRightHandSide; |
| 6473 } |
| 6474 } else if (parent is PrefixExpression) { |
| 6475 return parent.staticParameterElementForOperand; |
| 6476 } else if (parent is PostfixExpression) { |
| 6477 return parent.staticParameterElementForOperand; |
| 6478 } |
| 6479 return null; |
| 6480 } |
| 6481 |
| 6482 /** |
| 6483 * Return `true` if this expression is syntactically valid for the LHS of an |
| 6484 * [AssignmentExpression]. |
| 6485 * |
| 6486 * @return `true` if this expression matches the `assignableExpression` produc
tion |
| 6487 */ |
| 6488 bool get isAssignable => false; |
| 6489 } |
| 6490 |
| 6491 /** |
| 6492 * Instances of the class `ExpressionFunctionBody` represent a function body con
sisting of a |
| 6493 * single expression. |
| 6494 * |
| 6495 * <pre> |
| 6496 * expressionFunctionBody ::= |
| 6497 * 'async'? '=>' [Expression] ';' |
| 6498 * </pre> |
| 6499 */ |
| 6500 class ExpressionFunctionBody extends FunctionBody { |
| 6501 /** |
| 6502 * The token representing the 'async' keyword, or `null` if there is no such k
eyword. |
| 6503 */ |
| 6504 Token keyword; |
| 6505 |
| 6506 /** |
| 6507 * The token introducing the expression that represents the body of the functi
on. |
| 6508 */ |
| 6509 Token functionDefinition; |
| 6510 |
| 6511 /** |
| 6512 * The expression representing the body of the function. |
| 6513 */ |
| 6514 Expression _expression; |
| 6515 |
| 6516 /** |
| 6517 * The semicolon terminating the statement. |
| 6518 */ |
| 6519 Token semicolon; |
| 6520 |
| 6521 /** |
| 6522 * Initialize a newly created function body consisting of a block of statement
s. |
| 6523 * |
| 6524 * @param keyword the token representing the 'async' keyword |
| 6525 * @param functionDefinition the token introducing the expression that represe
nts the body of the |
| 6526 * function |
| 6527 * @param expression the expression representing the body of the function |
| 6528 * @param semicolon the semicolon terminating the statement |
| 6529 */ |
| 6530 ExpressionFunctionBody(this.keyword, this.functionDefinition, Expression expre
ssion, this.semicolon) { |
| 6531 this._expression = becomeParentOf(expression); |
| 6532 } |
| 6533 |
| 6534 @override |
| 6535 accept(AstVisitor visitor) => visitor.visitExpressionFunctionBody(this); |
| 6536 |
| 6537 @override |
| 6538 Token get beginToken => functionDefinition; |
| 6539 |
| 6540 @override |
| 6541 Token get endToken { |
| 6542 if (semicolon != null) { |
| 6543 return semicolon; |
| 6544 } |
| 6545 return _expression.endToken; |
| 6546 } |
| 6547 |
| 6548 /** |
| 6549 * Return the expression representing the body of the function. |
| 6550 * |
| 6551 * @return the expression representing the body of the function |
| 6552 */ |
| 6553 Expression get expression => _expression; |
| 6554 |
| 6555 @override |
| 6556 bool get isAsynchronous => keyword != null; |
| 6557 |
| 6558 @override |
| 6559 bool get isSynchronous => keyword == null; |
| 6560 |
| 6561 /** |
| 6562 * Set the expression representing the body of the function to the given expre
ssion. |
| 6563 * |
| 6564 * @param expression the expression representing the body of the function |
| 6565 */ |
| 6566 void set expression(Expression expression) { |
| 6567 this._expression = becomeParentOf(expression); |
| 6568 } |
| 6569 |
| 6570 @override |
| 6571 void visitChildren(AstVisitor visitor) { |
| 6572 safelyVisitChild(_expression, visitor); |
| 6573 } |
| 6574 } |
| 6575 |
| 6576 /** |
| 6577 * Instances of the class `ExpressionStatement` wrap an expression as a statemen
t. |
| 6578 * |
| 6579 * <pre> |
| 6580 * expressionStatement ::= |
| 6581 * [Expression]? ';' |
| 6582 * </pre> |
| 6583 */ |
| 6584 class ExpressionStatement extends Statement { |
| 6585 /** |
| 6586 * The expression that comprises the statement. |
| 6587 */ |
| 6588 Expression _expression; |
| 6589 |
| 6590 /** |
| 6591 * The semicolon terminating the statement, or `null` if the expression is a f
unction |
| 6592 * expression and therefore isn't followed by a semicolon. |
| 6593 */ |
| 6594 Token semicolon; |
| 6595 |
| 6596 /** |
| 6597 * Initialize a newly created expression statement. |
| 6598 * |
| 6599 * @param expression the expression that comprises the statement |
| 6600 * @param semicolon the semicolon terminating the statement |
| 6601 */ |
| 6602 ExpressionStatement(Expression expression, this.semicolon) { |
| 6603 this._expression = becomeParentOf(expression); |
| 6604 } |
| 6605 |
| 6606 @override |
| 6607 accept(AstVisitor visitor) => visitor.visitExpressionStatement(this); |
| 6608 |
| 6609 @override |
| 6610 Token get beginToken => _expression.beginToken; |
| 6611 |
| 6612 @override |
| 6613 Token get endToken { |
| 6614 if (semicolon != null) { |
| 6615 return semicolon; |
| 6616 } |
| 6617 return _expression.endToken; |
| 6618 } |
| 6619 |
| 6620 /** |
| 6621 * Return the expression that comprises the statement. |
| 6622 * |
| 6623 * @return the expression that comprises the statement |
| 6624 */ |
| 6625 Expression get expression => _expression; |
| 6626 |
| 6627 @override |
| 6628 bool get isSynthetic => _expression.isSynthetic && semicolon.isSynthetic; |
| 6629 |
| 6630 /** |
| 6631 * Set the expression that comprises the statement to the given expression. |
| 6632 * |
| 6633 * @param expression the expression that comprises the statement |
| 6634 */ |
| 6635 void set expression(Expression expression) { |
| 6636 this._expression = becomeParentOf(expression); |
| 6637 } |
| 6638 |
| 6639 @override |
| 6640 void visitChildren(AstVisitor visitor) { |
| 6641 safelyVisitChild(_expression, visitor); |
| 6642 } |
| 6643 } |
| 6644 |
| 6645 /** |
| 6646 * Instances of the class `ExtendsClause` represent the "extends" clause in a cl
ass |
| 6647 * declaration. |
| 6648 * |
| 6649 * <pre> |
| 6650 * extendsClause ::= |
| 6651 * 'extends' [TypeName] |
| 6652 * </pre> |
| 6653 */ |
| 6654 class ExtendsClause extends AstNode { |
| 6655 /** |
| 6656 * The token representing the 'extends' keyword. |
| 6657 */ |
| 6658 Token keyword; |
| 6659 |
| 6660 /** |
| 6661 * The name of the class that is being extended. |
| 6662 */ |
| 6663 TypeName _superclass; |
| 6664 |
| 6665 /** |
| 6666 * Initialize a newly created extends clause. |
| 6667 * |
| 6668 * @param keyword the token representing the 'extends' keyword |
| 6669 * @param superclass the name of the class that is being extended |
| 6670 */ |
| 6671 ExtendsClause(this.keyword, TypeName superclass) { |
| 6672 this._superclass = becomeParentOf(superclass); |
| 6673 } |
| 6674 |
| 6675 @override |
| 6676 accept(AstVisitor visitor) => visitor.visitExtendsClause(this); |
| 6677 |
| 6678 @override |
| 6679 Token get beginToken => keyword; |
| 6680 |
| 6681 @override |
| 6682 Token get endToken => _superclass.endToken; |
| 6683 |
| 6684 /** |
| 6685 * Return the name of the class that is being extended. |
| 6686 * |
| 6687 * @return the name of the class that is being extended |
| 6688 */ |
| 6689 TypeName get superclass => _superclass; |
| 6690 |
| 6691 /** |
| 6692 * Set the name of the class that is being extended to the given name. |
| 6693 * |
| 6694 * @param name the name of the class that is being extended |
| 6695 */ |
| 6696 void set superclass(TypeName name) { |
| 6697 _superclass = becomeParentOf(name); |
| 6698 } |
| 6699 |
| 6700 @override |
| 6701 void visitChildren(AstVisitor visitor) { |
| 6702 safelyVisitChild(_superclass, visitor); |
| 6703 } |
| 6704 } |
| 6705 |
| 6706 /** |
| 6707 * Instances of the class `FieldDeclaration` represent the declaration of one or
more fields |
| 6708 * of the same type. |
| 6709 * |
| 6710 * <pre> |
| 6711 * fieldDeclaration ::= |
| 6712 * 'static'? [VariableDeclarationList] ';' |
| 6713 * </pre> |
| 6714 */ |
| 6715 class FieldDeclaration extends ClassMember { |
| 6716 /** |
| 6717 * The token representing the 'static' keyword, or `null` if the fields are no
t static. |
| 6718 */ |
| 6719 Token staticKeyword; |
| 6720 |
| 6721 /** |
| 6722 * The fields being declared. |
| 6723 */ |
| 6724 VariableDeclarationList _fieldList; |
| 6725 |
| 6726 /** |
| 6727 * The semicolon terminating the declaration. |
| 6728 */ |
| 6729 Token semicolon; |
| 6730 |
| 6731 /** |
| 6732 * Initialize a newly created field declaration. |
| 6733 * |
| 6734 * @param comment the documentation comment associated with this field |
| 6735 * @param metadata the annotations associated with this field |
| 6736 * @param staticKeyword the token representing the 'static' keyword |
| 6737 * @param fieldList the fields being declared |
| 6738 * @param semicolon the semicolon terminating the declaration |
| 6739 */ |
| 6740 FieldDeclaration(Comment comment, List<Annotation> metadata, this.staticKeywor
d, VariableDeclarationList fieldList, this.semicolon) : super(comment, metadata)
{ |
| 6741 this._fieldList = becomeParentOf(fieldList); |
| 6742 } |
| 6743 |
| 6744 @override |
| 6745 accept(AstVisitor visitor) => visitor.visitFieldDeclaration(this); |
| 6746 |
| 6747 @override |
| 6748 Element get element => null; |
| 6749 |
| 6750 @override |
| 6751 Token get endToken => semicolon; |
| 6752 |
| 6753 /** |
| 6754 * Return the fields being declared. |
| 6755 * |
| 6756 * @return the fields being declared |
| 6757 */ |
| 6758 VariableDeclarationList get fields => _fieldList; |
| 6759 |
| 6760 /** |
| 6761 * Return `true` if the fields are static. |
| 6762 * |
| 6763 * @return `true` if the fields are declared to be static |
| 6764 */ |
| 6765 bool get isStatic => staticKeyword != null; |
| 6766 |
| 6767 /** |
| 6768 * Set the fields being declared to the given list of variables. |
| 6769 * |
| 6770 * @param fieldList the fields being declared |
| 6771 */ |
| 6772 void set fields(VariableDeclarationList fieldList) { |
| 6773 this._fieldList = becomeParentOf(fieldList); |
| 6774 } |
| 6775 |
| 6776 @override |
| 6777 void visitChildren(AstVisitor visitor) { |
| 6778 super.visitChildren(visitor); |
| 6779 safelyVisitChild(_fieldList, visitor); |
| 6780 } |
| 6781 |
| 6782 @override |
| 6783 Token get firstTokenAfterCommentAndMetadata { |
| 6784 if (staticKeyword != null) { |
| 6785 return staticKeyword; |
| 6786 } |
| 6787 return _fieldList.beginToken; |
| 6788 } |
| 6789 } |
| 6790 |
| 6791 /** |
| 6792 * Instances of the class `FieldFormalParameter` represent a field formal parame
ter. |
| 6793 * |
| 6794 * <pre> |
| 6795 * fieldFormalParameter ::= |
| 6796 * ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])? 'this' '.
' [SimpleIdentifier] [FormalParameterList]? |
| 6797 * </pre> |
| 6798 */ |
| 6799 class FieldFormalParameter extends NormalFormalParameter { |
| 6800 /** |
| 6801 * The token representing either the 'final', 'const' or 'var' keyword, or `nu
ll` if no |
| 6802 * keyword was used. |
| 6803 */ |
| 6804 Token keyword; |
| 6805 |
| 6806 /** |
| 6807 * The name of the declared type of the parameter, or `null` if the parameter
does not have |
| 6808 * a declared type. |
| 6809 */ |
| 6810 TypeName _type; |
| 6811 |
| 6812 /** |
| 6813 * The token representing the 'this' keyword. |
| 6814 */ |
| 6815 Token thisToken; |
| 6816 |
| 6817 /** |
| 6818 * The token representing the period. |
| 6819 */ |
| 6820 Token period; |
| 6821 |
| 6822 /** |
| 6823 * The parameters of the function-typed parameter, or `null` if this is not a
function-typed |
| 6824 * field formal parameter. |
| 6825 */ |
| 6826 FormalParameterList _parameters; |
| 6827 |
| 6828 /** |
| 6829 * Initialize a newly created formal parameter. |
| 6830 * |
| 6831 * @param comment the documentation comment associated with this parameter |
| 6832 * @param metadata the annotations associated with this parameter |
| 6833 * @param keyword the token representing either the 'final', 'const' or 'var'
keyword |
| 6834 * @param type the name of the declared type of the parameter |
| 6835 * @param thisToken the token representing the 'this' keyword |
| 6836 * @param period the token representing the period |
| 6837 * @param identifier the name of the parameter being declared |
| 6838 * @param parameters the parameters of the function-typed parameter, or `null`
if this is |
| 6839 * not a function-typed field formal parameter |
| 6840 */ |
| 6841 FieldFormalParameter(Comment comment, List<Annotation> metadata, this.keyword,
TypeName type, this.thisToken, this.period, SimpleIdentifier identifier, Formal
ParameterList parameters) : super(comment, metadata, identifier) { |
| 6842 this._type = becomeParentOf(type); |
| 6843 this._parameters = becomeParentOf(parameters); |
| 6844 } |
| 6845 |
| 6846 @override |
| 6847 accept(AstVisitor visitor) => visitor.visitFieldFormalParameter(this); |
| 6848 |
| 6849 @override |
| 6850 Token get beginToken { |
| 6851 if (keyword != null) { |
| 6852 return keyword; |
| 6853 } else if (_type != null) { |
| 6854 return _type.beginToken; |
| 6855 } |
| 6856 return thisToken; |
| 6857 } |
| 6858 |
| 6859 @override |
| 6860 Token get endToken => identifier.endToken; |
| 6861 |
| 6862 /** |
| 6863 * Return the parameters of the function-typed parameter, or `null` if this is
not a |
| 6864 * function-typed field formal parameter. |
| 6865 * |
| 6866 * @return the parameters of the function-typed parameter |
| 6867 */ |
| 6868 FormalParameterList get parameters => _parameters; |
| 6869 |
| 6870 /** |
| 6871 * Return the name of the declared type of the parameter, or `null` if the par
ameter does |
| 6872 * not have a declared type. Note that if this is a function-typed field forma
l parameter this is |
| 6873 * the return type of the function. |
| 6874 * |
| 6875 * @return the name of the declared type of the parameter |
| 6876 */ |
| 6877 TypeName get type => _type; |
| 6878 |
| 6879 @override |
| 6880 bool get isConst => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.CONST; |
| 6881 |
| 6882 @override |
| 6883 bool get isFinal => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.FINAL; |
| 6884 |
| 6885 /** |
| 6886 * Set the parameters of the function-typed parameter to the given parameters. |
| 6887 * |
| 6888 * @param parameters the parameters of the function-typed parameter |
| 6889 */ |
| 6890 void set parameters(FormalParameterList parameters) { |
| 6891 this._parameters = becomeParentOf(parameters); |
| 6892 } |
| 6893 |
| 6894 /** |
| 6895 * Set the name of the declared type of the parameter to the given type name. |
| 6896 * |
| 6897 * @param typeName the name of the declared type of the parameter |
| 6898 */ |
| 6899 void set type(TypeName typeName) { |
| 6900 _type = becomeParentOf(typeName); |
| 6901 } |
| 6902 |
| 6903 @override |
| 6904 void visitChildren(AstVisitor visitor) { |
| 6905 super.visitChildren(visitor); |
| 6906 safelyVisitChild(_type, visitor); |
| 6907 safelyVisitChild(identifier, visitor); |
| 6908 safelyVisitChild(_parameters, visitor); |
| 6909 } |
| 6910 } |
| 6911 |
| 6912 /** |
| 6913 * Instances of the class `ForEachStatement` represent a for-each statement. |
| 6914 * |
| 6915 * <pre> |
| 6916 * forEachStatement ::= |
| 6917 * 'await'? 'for' '(' [DeclaredIdentifier] 'in' [Expression] ')' [Block] |
| 6918 * | 'await'? 'for' '(' [SimpleIdentifier] 'in' [Expression] ')' [Block] |
| 6919 * </pre> |
| 6920 */ |
| 6921 class ForEachStatement extends Statement { |
| 6922 /** |
| 6923 * The token representing the 'await' keyword, or `null` if there is no 'await
' keyword. |
| 6924 */ |
| 6925 Token awaitKeyword; |
| 6926 |
| 6927 /** |
| 6928 * The token representing the 'for' keyword. |
| 6929 */ |
| 6930 Token forKeyword; |
| 6931 |
| 6932 /** |
| 6933 * The left parenthesis. |
| 6934 */ |
| 6935 Token leftParenthesis; |
| 6936 |
| 6937 /** |
| 6938 * The declaration of the loop variable, or `null` if the loop variable is a s
imple |
| 6939 * identifier. |
| 6940 */ |
| 6941 DeclaredIdentifier _loopVariable; |
| 6942 |
| 6943 /** |
| 6944 * The loop variable, or `null` if the loop variable is declared in the 'for'. |
| 6945 */ |
| 6946 SimpleIdentifier _identifier; |
| 6947 |
| 6948 /** |
| 6949 * The token representing the 'in' keyword. |
| 6950 */ |
| 6951 Token inKeyword; |
| 6952 |
| 6953 /** |
| 6954 * The expression evaluated to produce the iterator. |
| 6955 */ |
| 6956 Expression _iterator; |
| 6957 |
| 6958 /** |
| 6959 * The right parenthesis. |
| 6960 */ |
| 6961 Token rightParenthesis; |
| 6962 |
| 6963 /** |
| 6964 * The body of the loop. |
| 6965 */ |
| 6966 Statement _body; |
| 6967 |
| 6968 /** |
| 6969 * Initialize a newly created for-each statement. |
| 6970 * |
| 6971 * @param awaitKeyword the token representing the 'await' keyword |
| 6972 * @param forKeyword the token representing the 'for' keyword |
| 6973 * @param leftParenthesis the left parenthesis |
| 6974 * @param loopVariable the declaration of the loop variable |
| 6975 * @param iterator the expression evaluated to produce the iterator |
| 6976 * @param rightParenthesis the right parenthesis |
| 6977 * @param body the body of the loop |
| 6978 */ |
| 6979 ForEachStatement.con1(this.awaitKeyword, this.forKeyword, this.leftParenthesis
, DeclaredIdentifier loopVariable, this.inKeyword, Expression iterator, this.rig
htParenthesis, Statement body) { |
| 6980 this._loopVariable = becomeParentOf(loopVariable); |
| 6981 this._iterator = becomeParentOf(iterator); |
| 6982 this._body = becomeParentOf(body); |
| 6983 } |
| 6984 |
| 6985 /** |
| 6986 * Initialize a newly created for-each statement. |
| 6987 * |
| 6988 * @param awaitKeyword the token representing the 'await' keyword |
| 6989 * @param forKeyword the token representing the 'for' keyword |
| 6990 * @param leftParenthesis the left parenthesis |
| 6991 * @param identifier the loop variable |
| 6992 * @param iterator the expression evaluated to produce the iterator |
| 6993 * @param rightParenthesis the right parenthesis |
| 6994 * @param body the body of the loop |
| 6995 */ |
| 6996 ForEachStatement.con2(this.awaitKeyword, this.forKeyword, this.leftParenthesis
, SimpleIdentifier identifier, this.inKeyword, Expression iterator, this.rightPa
renthesis, Statement body) { |
| 6997 this._identifier = becomeParentOf(identifier); |
| 6998 this._iterator = becomeParentOf(iterator); |
| 6999 this._body = becomeParentOf(body); |
| 7000 } |
| 7001 |
| 7002 @override |
| 7003 accept(AstVisitor visitor) => visitor.visitForEachStatement(this); |
| 7004 |
| 7005 @override |
| 7006 Token get beginToken => forKeyword; |
| 7007 |
| 7008 /** |
| 7009 * Return the body of the loop. |
| 7010 * |
| 7011 * @return the body of the loop |
| 7012 */ |
| 7013 Statement get body => _body; |
| 7014 |
| 7015 @override |
| 7016 Token get endToken => _body.endToken; |
| 7017 |
| 7018 /** |
| 7019 * Return the loop variable, or `null` if the loop variable is declared in the
'for'. |
| 7020 * |
| 7021 * @return the loop variable |
| 7022 */ |
| 7023 SimpleIdentifier get identifier => _identifier; |
| 7024 |
| 7025 /** |
| 7026 * Return the expression evaluated to produce the iterator. |
| 7027 * |
| 7028 * @return the expression evaluated to produce the iterator |
| 7029 */ |
| 7030 Expression get iterator => _iterator; |
| 7031 |
| 7032 /** |
| 7033 * Return the declaration of the loop variable, or `null` if the loop variable
is a simple |
| 7034 * identifier. |
| 7035 * |
| 7036 * @return the declaration of the loop variable |
| 7037 */ |
| 7038 DeclaredIdentifier get loopVariable => _loopVariable; |
| 7039 |
| 7040 /** |
| 7041 * Set the body of the loop to the given block. |
| 7042 * |
| 7043 * @param body the body of the loop |
| 7044 */ |
| 7045 void set body(Statement body) { |
| 7046 this._body = becomeParentOf(body); |
| 7047 } |
| 7048 |
| 7049 /** |
| 7050 * Set the loop variable to the given variable. |
| 7051 * |
| 7052 * @param identifier the loop variable |
| 7053 */ |
| 7054 void set identifier(SimpleIdentifier identifier) { |
| 7055 this._identifier = becomeParentOf(identifier); |
| 7056 } |
| 7057 |
| 7058 /** |
| 7059 * Set the expression evaluated to produce the iterator to the given expressio
n. |
| 7060 * |
| 7061 * @param expression the expression evaluated to produce the iterator |
| 7062 */ |
| 7063 void set iterator(Expression expression) { |
| 7064 _iterator = becomeParentOf(expression); |
| 7065 } |
| 7066 |
| 7067 /** |
| 7068 * Set the declaration of the loop variable to the given variable. |
| 7069 * |
| 7070 * @param variable the declaration of the loop variable |
| 7071 */ |
| 7072 void set loopVariable(DeclaredIdentifier variable) { |
| 7073 _loopVariable = becomeParentOf(variable); |
| 7074 } |
| 7075 |
| 7076 @override |
| 7077 void visitChildren(AstVisitor visitor) { |
| 7078 safelyVisitChild(_loopVariable, visitor); |
| 7079 safelyVisitChild(_identifier, visitor); |
| 7080 safelyVisitChild(_iterator, visitor); |
| 7081 safelyVisitChild(_body, visitor); |
| 7082 } |
| 7083 } |
| 7084 |
| 7085 /** |
| 7086 * Instances of the class `ForStatement` represent a for statement. |
| 7087 * |
| 7088 * <pre> |
| 7089 * forStatement ::= |
| 7090 * 'for' '(' forLoopParts ')' [Statement] |
| 7091 * |
| 7092 * forLoopParts ::= |
| 7093 * forInitializerStatement ';' [Expression]? ';' [Expression]? |
| 7094 * |
| 7095 * forInitializerStatement ::= |
| 7096 * [DefaultFormalParameter] |
| 7097 * | [Expression]? |
| 7098 * </pre> |
| 7099 */ |
| 7100 class ForStatement extends Statement { |
| 7101 /** |
| 7102 * The token representing the 'for' keyword. |
| 7103 */ |
| 7104 Token forKeyword; |
| 7105 |
| 7106 /** |
| 7107 * The left parenthesis. |
| 7108 */ |
| 7109 Token leftParenthesis; |
| 7110 |
| 7111 /** |
| 7112 * The declaration of the loop variables, or `null` if there are no variables.
Note that a |
| 7113 * for statement cannot have both a variable list and an initialization expres
sion, but can |
| 7114 * validly have neither. |
| 7115 */ |
| 7116 VariableDeclarationList _variableList; |
| 7117 |
| 7118 /** |
| 7119 * The initialization expression, or `null` if there is no initialization expr
ession. Note |
| 7120 * that a for statement cannot have both a variable list and an initialization
expression, but can |
| 7121 * validly have neither. |
| 7122 */ |
| 7123 Expression _initialization; |
| 7124 |
| 7125 /** |
| 7126 * The semicolon separating the initializer and the condition. |
| 7127 */ |
| 7128 Token leftSeparator; |
| 7129 |
| 7130 /** |
| 7131 * The condition used to determine when to terminate the loop, or `null` if th
ere is no |
| 7132 * condition. |
| 7133 */ |
| 7134 Expression _condition; |
| 7135 |
| 7136 /** |
| 7137 * The semicolon separating the condition and the updater. |
| 7138 */ |
| 7139 Token rightSeparator; |
| 7140 |
| 7141 /** |
| 7142 * The list of expressions run after each execution of the loop body. |
| 7143 */ |
| 7144 NodeList<Expression> _updaters; |
| 7145 |
| 7146 /** |
| 7147 * The right parenthesis. |
| 7148 */ |
| 7149 Token rightParenthesis; |
| 7150 |
| 7151 /** |
| 7152 * The body of the loop. |
| 7153 */ |
| 7154 Statement _body; |
| 7155 |
| 7156 /** |
| 7157 * Initialize a newly created for statement. |
| 7158 * |
| 7159 * @param forKeyword the token representing the 'for' keyword |
| 7160 * @param leftParenthesis the left parenthesis |
| 7161 * @param variableList the declaration of the loop variables |
| 7162 * @param initialization the initialization expression |
| 7163 * @param leftSeparator the semicolon separating the initializer and the condi
tion |
| 7164 * @param condition the condition used to determine when to terminate the loop |
| 7165 * @param rightSeparator the semicolon separating the condition and the update
r |
| 7166 * @param updaters the list of expressions run after each execution of the loo
p body |
| 7167 * @param rightParenthesis the right parenthesis |
| 7168 * @param body the body of the loop |
| 7169 */ |
| 7170 ForStatement(this.forKeyword, this.leftParenthesis, VariableDeclarationList va
riableList, Expression initialization, this.leftSeparator, Expression condition,
this.rightSeparator, List<Expression> updaters, this.rightParenthesis, Statemen
t body) { |
| 7171 this._updaters = new NodeList<Expression>(this); |
| 7172 this._variableList = becomeParentOf(variableList); |
| 7173 this._initialization = becomeParentOf(initialization); |
| 7174 this._condition = becomeParentOf(condition); |
| 7175 this._updaters.addAll(updaters); |
| 7176 this._body = becomeParentOf(body); |
| 7177 } |
| 7178 |
| 7179 @override |
| 7180 accept(AstVisitor visitor) => visitor.visitForStatement(this); |
| 7181 |
| 7182 @override |
| 7183 Token get beginToken => forKeyword; |
| 7184 |
| 7185 /** |
| 7186 * Return the body of the loop. |
| 7187 * |
| 7188 * @return the body of the loop |
| 7189 */ |
| 7190 Statement get body => _body; |
| 7191 |
| 7192 /** |
| 7193 * Return the condition used to determine when to terminate the loop, or `null
` if there is |
| 7194 * no condition. |
| 7195 * |
| 7196 * @return the condition used to determine when to terminate the loop |
| 7197 */ |
| 7198 Expression get condition => _condition; |
| 7199 |
| 7200 @override |
| 7201 Token get endToken => _body.endToken; |
| 7202 |
| 7203 /** |
| 7204 * Return the initialization expression, or `null` if there is no initializati
on expression. |
| 7205 * |
| 7206 * @return the initialization expression |
| 7207 */ |
| 7208 Expression get initialization => _initialization; |
| 7209 |
| 7210 /** |
| 7211 * Return the list of expressions run after each execution of the loop body. |
| 7212 * |
| 7213 * @return the list of expressions run after each execution of the loop body |
| 7214 */ |
| 7215 NodeList<Expression> get updaters => _updaters; |
| 7216 |
| 7217 /** |
| 7218 * Return the declaration of the loop variables, or `null` if there are no var
iables. |
| 7219 * |
| 7220 * @return the declaration of the loop variables, or `null` if there are no va
riables |
| 7221 */ |
| 7222 VariableDeclarationList get variables => _variableList; |
| 7223 |
| 7224 /** |
| 7225 * Set the body of the loop to the given statement. |
| 7226 * |
| 7227 * @param body the body of the loop |
| 7228 */ |
| 7229 void set body(Statement body) { |
| 7230 this._body = becomeParentOf(body); |
| 7231 } |
| 7232 |
| 7233 /** |
| 7234 * Set the condition used to determine when to terminate the loop to the given
expression. |
| 7235 * |
| 7236 * @param expression the condition used to determine when to terminate the loo
p |
| 7237 */ |
| 7238 void set condition(Expression expression) { |
| 7239 _condition = becomeParentOf(expression); |
| 7240 } |
| 7241 |
| 7242 /** |
| 7243 * Set the initialization expression to the given expression. |
| 7244 * |
| 7245 * @param initialization the initialization expression |
| 7246 */ |
| 7247 void set initialization(Expression initialization) { |
| 7248 this._initialization = becomeParentOf(initialization); |
| 7249 } |
| 7250 |
| 7251 /** |
| 7252 * Set the declaration of the loop variables to the given parameter. |
| 7253 * |
| 7254 * @param variableList the declaration of the loop variables |
| 7255 */ |
| 7256 void set variables(VariableDeclarationList variableList) { |
| 7257 this._variableList = becomeParentOf(variableList); |
| 7258 } |
| 7259 |
| 7260 @override |
| 7261 void visitChildren(AstVisitor visitor) { |
| 7262 safelyVisitChild(_variableList, visitor); |
| 7263 safelyVisitChild(_initialization, visitor); |
| 7264 safelyVisitChild(_condition, visitor); |
| 7265 _updaters.accept(visitor); |
| 7266 safelyVisitChild(_body, visitor); |
| 7267 } |
| 7268 } |
| 7269 |
| 7270 /** |
| 7271 * The abstract class `FormalParameter` defines the behavior of objects represen
ting a |
| 7272 * parameter to a function. |
| 7273 * |
| 7274 * <pre> |
| 7275 * formalParameter ::= |
| 7276 * [NormalFormalParameter] |
| 7277 * | [DefaultFormalParameter] |
| 7278 * | [DefaultFormalParameter] |
| 7279 * </pre> |
| 7280 */ |
| 7281 abstract class FormalParameter extends AstNode { |
| 7282 /** |
| 7283 * Return the element representing this parameter, or `null` if this parameter
has not been |
| 7284 * resolved. |
| 7285 * |
| 7286 * @return the element representing this parameter |
| 7287 */ |
| 7288 ParameterElement get element { |
| 7289 SimpleIdentifier identifier = this.identifier; |
| 7290 if (identifier == null) { |
| 7291 return null; |
| 7292 } |
| 7293 return identifier.staticElement as ParameterElement; |
| 7294 } |
| 7295 |
| 7296 /** |
| 7297 * Return the name of the parameter being declared. |
| 7298 * |
| 7299 * @return the name of the parameter being declared |
| 7300 */ |
| 7301 SimpleIdentifier get identifier; |
| 7302 |
| 7303 /** |
| 7304 * Return the kind of this parameter. |
| 7305 * |
| 7306 * @return the kind of this parameter |
| 7307 */ |
| 7308 ParameterKind get kind; |
| 7309 |
| 7310 /** |
| 7311 * Return `true` if this parameter was declared with the 'const' modifier. |
| 7312 * |
| 7313 * @return `true` if this parameter was declared with the 'const' modifier |
| 7314 */ |
| 7315 bool get isConst; |
| 7316 |
| 7317 /** |
| 7318 * Return `true` if this parameter was declared with the 'final' modifier. Par
ameters that |
| 7319 * are declared with the 'const' modifier will return `false` even though they
are |
| 7320 * implicitly final. |
| 7321 * |
| 7322 * @return `true` if this parameter was declared with the 'final' modifier |
| 7323 */ |
| 7324 bool get isFinal; |
| 7325 } |
| 7326 |
| 7327 /** |
| 7328 * Instances of the class `FormalParameterList` represent the formal parameter l
ist of a |
| 7329 * method declaration, function declaration, or function type alias. |
| 7330 * |
| 7331 * While the grammar requires all optional formal parameters to follow all of th
e normal formal |
| 7332 * parameters and at most one grouping of optional formal parameters, this class
does not enforce |
| 7333 * those constraints. All parameters are flattened into a single list, which can
have any or all |
| 7334 * kinds of parameters (normal, named, and positional) in any order. |
| 7335 * |
| 7336 * <pre> |
| 7337 * formalParameterList ::= |
| 7338 * '(' ')' |
| 7339 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' |
| 7340 * | '(' optionalFormalParameters ')' |
| 7341 * |
| 7342 * normalFormalParameters ::= |
| 7343 * [NormalFormalParameter] (',' [NormalFormalParameter])* |
| 7344 * |
| 7345 * optionalFormalParameters ::= |
| 7346 * optionalPositionalFormalParameters |
| 7347 * | namedFormalParameters |
| 7348 * |
| 7349 * optionalPositionalFormalParameters ::= |
| 7350 * '[' [DefaultFormalParameter] (',' [DefaultFormalParameter])* ']' |
| 7351 * |
| 7352 * namedFormalParameters ::= |
| 7353 * '{' [DefaultFormalParameter] (',' [DefaultFormalParameter])* '}' |
| 7354 * </pre> |
| 7355 */ |
| 7356 class FormalParameterList extends AstNode { |
| 7357 /** |
| 7358 * The left parenthesis. |
| 7359 */ |
| 7360 Token _leftParenthesis; |
| 7361 |
| 7362 /** |
| 7363 * The parameters associated with the method. |
| 7364 */ |
| 7365 NodeList<FormalParameter> _parameters; |
| 7366 |
| 7367 /** |
| 7368 * The left square bracket ('[') or left curly brace ('{') introducing the opt
ional parameters, or |
| 7369 * `null` if there are no optional parameters. |
| 7370 */ |
| 7371 Token _leftDelimiter; |
| 7372 |
| 7373 /** |
| 7374 * The right square bracket (']') or right curly brace ('}') introducing the o
ptional parameters, |
| 7375 * or `null` if there are no optional parameters. |
| 7376 */ |
| 7377 Token _rightDelimiter; |
| 7378 |
| 7379 /** |
| 7380 * The right parenthesis. |
| 7381 */ |
| 7382 Token _rightParenthesis; |
| 7383 |
| 7384 /** |
| 7385 * Initialize a newly created parameter list. |
| 7386 * |
| 7387 * @param leftParenthesis the left parenthesis |
| 7388 * @param parameters the parameters associated with the method |
| 7389 * @param leftDelimiter the left delimiter introducing the optional parameters |
| 7390 * @param rightDelimiter the right delimiter introducing the optional paramete
rs |
| 7391 * @param rightParenthesis the right parenthesis |
| 7392 */ |
| 7393 FormalParameterList(Token leftParenthesis, List<FormalParameter> parameters, T
oken leftDelimiter, Token rightDelimiter, Token rightParenthesis) { |
| 7394 this._parameters = new NodeList<FormalParameter>(this); |
| 7395 this._leftParenthesis = leftParenthesis; |
| 7396 this._parameters.addAll(parameters); |
| 7397 this._leftDelimiter = leftDelimiter; |
| 7398 this._rightDelimiter = rightDelimiter; |
| 7399 this._rightParenthesis = rightParenthesis; |
| 7400 } |
| 7401 |
| 7402 @override |
| 7403 accept(AstVisitor visitor) => visitor.visitFormalParameterList(this); |
| 7404 |
| 7405 @override |
| 7406 Token get beginToken => _leftParenthesis; |
| 7407 |
| 7408 @override |
| 7409 Token get endToken => _rightParenthesis; |
| 7410 |
| 7411 /** |
| 7412 * Return the left square bracket ('[') or left curly brace ('{') introducing
the optional |
| 7413 * parameters, or `null` if there are no optional parameters. |
| 7414 * |
| 7415 * @return the left square bracket ('[') or left curly brace ('{') introducing
the optional |
| 7416 * parameters |
| 7417 */ |
| 7418 Token get leftDelimiter => _leftDelimiter; |
| 7419 |
| 7420 /** |
| 7421 * Return the left parenthesis. |
| 7422 * |
| 7423 * @return the left parenthesis |
| 7424 */ |
| 7425 Token get leftParenthesis => _leftParenthesis; |
| 7426 |
| 7427 /** |
| 7428 * Return an array containing the elements representing the parameters in this
list. The array |
| 7429 * will contain `null`s if the parameters in this list have not been resolved. |
| 7430 * |
| 7431 * @return the elements representing the parameters in this list |
| 7432 */ |
| 7433 List<ParameterElement> get parameterElements { |
| 7434 int count = _parameters.length; |
| 7435 List<ParameterElement> types = new List<ParameterElement>(count); |
| 7436 for (int i = 0; i < count; i++) { |
| 7437 types[i] = _parameters[i].element; |
| 7438 } |
| 7439 return types; |
| 7440 } |
| 7441 |
| 7442 /** |
| 7443 * Return the parameters associated with the method. |
| 7444 * |
| 7445 * @return the parameters associated with the method |
| 7446 */ |
| 7447 NodeList<FormalParameter> get parameters => _parameters; |
| 7448 |
| 7449 /** |
| 7450 * Return the right square bracket (']') or right curly brace ('}') introducin
g the optional |
| 7451 * parameters, or `null` if there are no optional parameters. |
| 7452 * |
| 7453 * @return the right square bracket (']') or right curly brace ('}') introduci
ng the optional |
| 7454 * parameters |
| 7455 */ |
| 7456 Token get rightDelimiter => _rightDelimiter; |
| 7457 |
| 7458 /** |
| 7459 * Return the right parenthesis. |
| 7460 * |
| 7461 * @return the right parenthesis |
| 7462 */ |
| 7463 Token get rightParenthesis => _rightParenthesis; |
| 7464 |
| 7465 /** |
| 7466 * Set the left square bracket ('[') or left curly brace ('{') introducing the
optional parameters |
| 7467 * to the given token. |
| 7468 * |
| 7469 * @param bracket the left delimiter introducing the optional parameters |
| 7470 */ |
| 7471 void set leftDelimiter(Token bracket) { |
| 7472 _leftDelimiter = bracket; |
| 7473 } |
| 7474 |
| 7475 /** |
| 7476 * Set the left parenthesis to the given token. |
| 7477 * |
| 7478 * @param parenthesis the left parenthesis |
| 7479 */ |
| 7480 void set leftParenthesis(Token parenthesis) { |
| 7481 _leftParenthesis = parenthesis; |
| 7482 } |
| 7483 |
| 7484 /** |
| 7485 * Set the right square bracket (']') or right curly brace ('}') introducing t
he optional |
| 7486 * parameters to the given token. |
| 7487 * |
| 7488 * @param bracket the right delimiter introducing the optional parameters |
| 7489 */ |
| 7490 void set rightDelimiter(Token bracket) { |
| 7491 _rightDelimiter = bracket; |
| 7492 } |
| 7493 |
| 7494 /** |
| 7495 * Set the right parenthesis to the given token. |
| 7496 * |
| 7497 * @param parenthesis the right parenthesis |
| 7498 */ |
| 7499 void set rightParenthesis(Token parenthesis) { |
| 7500 _rightParenthesis = parenthesis; |
| 7501 } |
| 7502 |
| 7503 @override |
| 7504 void visitChildren(AstVisitor visitor) { |
| 7505 _parameters.accept(visitor); |
| 7506 } |
| 7507 } |
| 7508 |
| 7509 /** |
| 7510 * The abstract class `FunctionBody` defines the behavior common to objects repr
esenting the |
| 7511 * body of a function or method. |
| 7512 * |
| 7513 * <pre> |
| 7514 * functionBody ::= |
| 7515 * [BlockFunctionBody] |
| 7516 * | [EmptyFunctionBody] |
| 7517 * | [ExpressionFunctionBody] |
| 7518 * </pre> |
| 7519 */ |
| 7520 abstract class FunctionBody extends AstNode { |
| 7521 /** |
| 7522 * Return `true` if this function body is asynchronous. |
| 7523 * |
| 7524 * @return `true` if this function body is asynchronous |
| 7525 */ |
| 7526 bool get isAsynchronous => false; |
| 7527 |
| 7528 /** |
| 7529 * Return `true` if this function body is a generator. |
| 7530 * |
| 7531 * @return `true` if this function body is a generator |
| 7532 */ |
| 7533 bool get isGenerator => false; |
| 7534 |
| 7535 /** |
| 7536 * Return `true` if this function body is synchronous. |
| 7537 * |
| 7538 * @return `true` if this function body is synchronous |
| 7539 */ |
| 7540 bool get isSynchronous => true; |
| 7541 } |
| 7542 |
| 7543 /** |
| 7544 * Instances of the class `FunctionDeclaration` wrap a [FunctionExpression] as a
top-level declaration. |
| 7545 * |
| 7546 * <pre> |
| 7547 * functionDeclaration ::= |
| 7548 * 'external' functionSignature |
| 7549 * | functionSignature [FunctionBody] |
| 7550 * |
| 7551 * functionSignature ::= |
| 7552 * [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList] |
| 7553 * </pre> |
| 7554 */ |
| 7555 class FunctionDeclaration extends CompilationUnitMember { |
| 7556 /** |
| 7557 * The token representing the 'external' keyword, or `null` if this is not an
external |
| 7558 * function. |
| 7559 */ |
| 7560 Token externalKeyword; |
| 7561 |
| 7562 /** |
| 7563 * The return type of the function, or `null` if no return type was declared. |
| 7564 */ |
| 7565 TypeName _returnType; |
| 7566 |
| 7567 /** |
| 7568 * The token representing the 'get' or 'set' keyword, or `null` if this is a f
unction |
| 7569 * declaration rather than a property declaration. |
| 7570 */ |
| 7571 Token propertyKeyword; |
| 7572 |
| 7573 /** |
| 7574 * The name of the function, or `null` if the function is not named. |
| 7575 */ |
| 7576 SimpleIdentifier _name; |
| 7577 |
| 7578 /** |
| 7579 * The function expression being wrapped. |
| 7580 */ |
| 7581 FunctionExpression _functionExpression; |
| 7582 |
| 7583 /** |
| 7584 * Initialize a newly created function declaration. |
| 7585 * |
| 7586 * @param comment the documentation comment associated with this function |
| 7587 * @param metadata the annotations associated with this function |
| 7588 * @param externalKeyword the token representing the 'external' keyword |
| 7589 * @param returnType the return type of the function |
| 7590 * @param propertyKeyword the token representing the 'get' or 'set' keyword |
| 7591 * @param name the name of the function |
| 7592 * @param functionExpression the function expression being wrapped |
| 7593 */ |
| 7594 FunctionDeclaration(Comment comment, List<Annotation> metadata, this.externalK
eyword, TypeName returnType, this.propertyKeyword, SimpleIdentifier name, Functi
onExpression functionExpression) : super(comment, metadata) { |
| 7595 this._returnType = becomeParentOf(returnType); |
| 7596 this._name = becomeParentOf(name); |
| 7597 this._functionExpression = becomeParentOf(functionExpression); |
| 7598 } |
| 7599 |
| 7600 @override |
| 7601 accept(AstVisitor visitor) => visitor.visitFunctionDeclaration(this); |
| 7602 |
| 7603 @override |
| 7604 ExecutableElement get element => _name != null ? (_name.staticElement as Execu
tableElement) : null; |
| 7605 |
| 7606 @override |
| 7607 Token get endToken => _functionExpression.endToken; |
| 7608 |
| 7609 /** |
| 7610 * Return the function expression being wrapped. |
| 7611 * |
| 7612 * @return the function expression being wrapped |
| 7613 */ |
| 7614 FunctionExpression get functionExpression => _functionExpression; |
| 7615 |
| 7616 /** |
| 7617 * Return the name of the function, or `null` if the function is not named. |
| 7618 * |
| 7619 * @return the name of the function |
| 7620 */ |
| 7621 SimpleIdentifier get name => _name; |
| 7622 |
| 7623 /** |
| 7624 * Return the return type of the function, or `null` if no return type was dec
lared. |
| 7625 * |
| 7626 * @return the return type of the function |
| 7627 */ |
| 7628 TypeName get returnType => _returnType; |
| 7629 |
| 7630 /** |
| 7631 * Return `true` if this function declares a getter. |
| 7632 * |
| 7633 * @return `true` if this function declares a getter |
| 7634 */ |
| 7635 bool get isGetter => propertyKeyword != null && (propertyKeyword as KeywordTok
en).keyword == Keyword.GET; |
| 7636 |
| 7637 /** |
| 7638 * Return `true` if this function declares a setter. |
| 7639 * |
| 7640 * @return `true` if this function declares a setter |
| 7641 */ |
| 7642 bool get isSetter => propertyKeyword != null && (propertyKeyword as KeywordTok
en).keyword == Keyword.SET; |
| 7643 |
| 7644 /** |
| 7645 * Set the function expression being wrapped to the given function expression. |
| 7646 * |
| 7647 * @param functionExpression the function expression being wrapped |
| 7648 */ |
| 7649 void set functionExpression(FunctionExpression functionExpression) { |
| 7650 this._functionExpression = becomeParentOf(functionExpression); |
| 7651 } |
| 7652 |
| 7653 /** |
| 7654 * Set the name of the function to the given identifier. |
| 7655 * |
| 7656 * @param identifier the name of the function |
| 7657 */ |
| 7658 void set name(SimpleIdentifier identifier) { |
| 7659 this._name = becomeParentOf(identifier); |
| 7660 } |
| 7661 |
| 7662 /** |
| 7663 * Set the return type of the function to the given name. |
| 7664 * |
| 7665 * @param returnType the return type of the function |
| 7666 */ |
| 7667 void set returnType(TypeName returnType) { |
| 7668 this._returnType = becomeParentOf(returnType); |
| 7669 } |
| 7670 |
| 7671 @override |
| 7672 void visitChildren(AstVisitor visitor) { |
| 7673 super.visitChildren(visitor); |
| 7674 safelyVisitChild(_returnType, visitor); |
| 7675 safelyVisitChild(_name, visitor); |
| 7676 safelyVisitChild(_functionExpression, visitor); |
| 7677 } |
| 7678 |
| 7679 @override |
| 7680 Token get firstTokenAfterCommentAndMetadata { |
| 7681 if (externalKeyword != null) { |
| 7682 return externalKeyword; |
| 7683 } |
| 7684 if (_returnType != null) { |
| 7685 return _returnType.beginToken; |
| 7686 } else if (propertyKeyword != null) { |
| 7687 return propertyKeyword; |
| 7688 } else if (_name != null) { |
| 7689 return _name.beginToken; |
| 7690 } |
| 7691 return _functionExpression.beginToken; |
| 7692 } |
| 7693 } |
| 7694 |
| 7695 /** |
| 7696 * Instances of the class `FunctionDeclarationStatement` wrap a [FunctionDeclara
tion |
| 7697 ] as a statement. |
| 7698 */ |
| 7699 class FunctionDeclarationStatement extends Statement { |
| 7700 /** |
| 7701 * The function declaration being wrapped. |
| 7702 */ |
| 7703 FunctionDeclaration _functionDeclaration; |
| 7704 |
| 7705 /** |
| 7706 * Initialize a newly created function declaration statement. |
| 7707 * |
| 7708 * @param functionDeclaration the the function declaration being wrapped |
| 7709 */ |
| 7710 FunctionDeclarationStatement(FunctionDeclaration functionDeclaration) { |
| 7711 this._functionDeclaration = becomeParentOf(functionDeclaration); |
| 7712 } |
| 7713 |
| 7714 @override |
| 7715 accept(AstVisitor visitor) => visitor.visitFunctionDeclarationStatement(this); |
| 7716 |
| 7717 @override |
| 7718 Token get beginToken => _functionDeclaration.beginToken; |
| 7719 |
| 7720 @override |
| 7721 Token get endToken => _functionDeclaration.endToken; |
| 7722 |
| 7723 /** |
| 7724 * Return the function declaration being wrapped. |
| 7725 * |
| 7726 * @return the function declaration being wrapped |
| 7727 */ |
| 7728 FunctionDeclaration get functionDeclaration => _functionDeclaration; |
| 7729 |
| 7730 /** |
| 7731 * Set the function declaration being wrapped to the given function declaratio
n. |
| 7732 * |
| 7733 * @param functionDeclaration the function declaration being wrapped |
| 7734 */ |
| 7735 void set functionDeclaration(FunctionDeclaration functionDeclaration) { |
| 7736 this._functionDeclaration = becomeParentOf(functionDeclaration); |
| 7737 } |
| 7738 |
| 7739 @override |
| 7740 void visitChildren(AstVisitor visitor) { |
| 7741 safelyVisitChild(_functionDeclaration, visitor); |
| 7742 } |
| 7743 } |
| 7744 |
| 7745 /** |
| 7746 * Instances of the class `FunctionExpression` represent a function expression. |
| 7747 * |
| 7748 * <pre> |
| 7749 * functionExpression ::= |
| 7750 * [FormalParameterList] [FunctionBody] |
| 7751 * </pre> |
| 7752 */ |
| 7753 class FunctionExpression extends Expression { |
| 7754 /** |
| 7755 * The parameters associated with the function. |
| 7756 */ |
| 7757 FormalParameterList _parameters; |
| 7758 |
| 7759 /** |
| 7760 * The body of the function, or `null` if this is an external function. |
| 7761 */ |
| 7762 FunctionBody _body; |
| 7763 |
| 7764 /** |
| 7765 * The element associated with the function, or `null` if the AST structure ha
s not been |
| 7766 * resolved. |
| 7767 */ |
| 7768 ExecutableElement element; |
| 7769 |
| 7770 /** |
| 7771 * Initialize a newly created function declaration. |
| 7772 * |
| 7773 * @param parameters the parameters associated with the function |
| 7774 * @param body the body of the function |
| 7775 */ |
| 7776 FunctionExpression(FormalParameterList parameters, FunctionBody body) { |
| 7777 this._parameters = becomeParentOf(parameters); |
| 7778 this._body = becomeParentOf(body); |
| 7779 } |
| 7780 |
| 7781 @override |
| 7782 accept(AstVisitor visitor) => visitor.visitFunctionExpression(this); |
| 7783 |
| 7784 @override |
| 7785 Token get beginToken { |
| 7786 if (_parameters != null) { |
| 7787 return _parameters.beginToken; |
| 7788 } else if (_body != null) { |
| 7789 return _body.beginToken; |
| 7790 } |
| 7791 // This should never be reached because external functions must be named, he
nce either the body |
| 7792 // or the name should be non-null. |
| 7793 throw new IllegalStateException("Non-external functions must have a body"); |
| 7794 } |
| 7795 |
| 7796 /** |
| 7797 * Return the body of the function, or `null` if this is an external function. |
| 7798 * |
| 7799 * @return the body of the function |
| 7800 */ |
| 7801 FunctionBody get body => _body; |
| 7802 |
| 7803 @override |
| 7804 Token get endToken { |
| 7805 if (_body != null) { |
| 7806 return _body.endToken; |
| 7807 } else if (_parameters != null) { |
| 7808 return _parameters.endToken; |
| 7809 } |
| 7810 // This should never be reached because external functions must be named, he
nce either the body |
| 7811 // or the name should be non-null. |
| 7812 throw new IllegalStateException("Non-external functions must have a body"); |
| 7813 } |
| 7814 |
| 7815 /** |
| 7816 * Return the parameters associated with the function. |
| 7817 * |
| 7818 * @return the parameters associated with the function |
| 7819 */ |
| 7820 FormalParameterList get parameters => _parameters; |
| 7821 |
| 7822 @override |
| 7823 int get precedence => 16; |
| 7824 |
| 7825 /** |
| 7826 * Set the body of the function to the given function body. |
| 7827 * |
| 7828 * @param functionBody the body of the function |
| 7829 */ |
| 7830 void set body(FunctionBody functionBody) { |
| 7831 _body = becomeParentOf(functionBody); |
| 7832 } |
| 7833 |
| 7834 /** |
| 7835 * Set the parameters associated with the function to the given list of parame
ters. |
| 7836 * |
| 7837 * @param parameters the parameters associated with the function |
| 7838 */ |
| 7839 void set parameters(FormalParameterList parameters) { |
| 7840 this._parameters = becomeParentOf(parameters); |
| 7841 } |
| 7842 |
| 7843 @override |
| 7844 void visitChildren(AstVisitor visitor) { |
| 7845 safelyVisitChild(_parameters, visitor); |
| 7846 safelyVisitChild(_body, visitor); |
| 7847 } |
| 7848 } |
| 7849 |
| 7850 /** |
| 7851 * Instances of the class `FunctionExpressionInvocation` represent the invocatio
n of a |
| 7852 * function resulting from evaluating an expression. Invocations of methods and
other forms of |
| 7853 * functions are represented by [MethodInvocation] nodes. Invocations of |
| 7854 * getters and setters are represented by either [PrefixedIdentifier] or |
| 7855 * [PropertyAccess] nodes. |
| 7856 * |
| 7857 * <pre> |
| 7858 * functionExpressionInvoction ::= |
| 7859 * [Expression] [ArgumentList] |
| 7860 * </pre> |
| 7861 */ |
| 7862 class FunctionExpressionInvocation extends Expression { |
| 7863 /** |
| 7864 * The expression producing the function being invoked. |
| 7865 */ |
| 7866 Expression _function; |
| 7867 |
| 7868 /** |
| 7869 * The list of arguments to the function. |
| 7870 */ |
| 7871 ArgumentList _argumentList; |
| 7872 |
| 7873 /** |
| 7874 * The element associated with the function being invoked based on static type
information, or |
| 7875 * `null` if the AST structure has not been resolved or the function could not
be resolved. |
| 7876 */ |
| 7877 ExecutableElement staticElement; |
| 7878 |
| 7879 /** |
| 7880 * The element associated with the function being invoked based on propagated
type information, or |
| 7881 * `null` if the AST structure has not been resolved or the function could not
be resolved. |
| 7882 */ |
| 7883 ExecutableElement _propagatedElement; |
| 7884 |
| 7885 /** |
| 7886 * Initialize a newly created function expression invocation. |
| 7887 * |
| 7888 * @param function the expression producing the function being invoked |
| 7889 * @param argumentList the list of arguments to the method |
| 7890 */ |
| 7891 FunctionExpressionInvocation(Expression function, ArgumentList argumentList) { |
| 7892 this._function = becomeParentOf(function); |
| 7893 this._argumentList = becomeParentOf(argumentList); |
| 7894 } |
| 7895 |
| 7896 @override |
| 7897 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this); |
| 7898 |
| 7899 /** |
| 7900 * Return the list of arguments to the method. |
| 7901 * |
| 7902 * @return the list of arguments to the method |
| 7903 */ |
| 7904 ArgumentList get argumentList => _argumentList; |
| 7905 |
| 7906 @override |
| 7907 Token get beginToken => _function.beginToken; |
| 7908 |
| 7909 /** |
| 7910 * Return the best element available for the function being invoked. If resolu
tion was able to |
| 7911 * find a better element based on type propagation, that element will be retur
ned. Otherwise, the |
| 7912 * element found using the result of static analysis will be returned. If reso
lution has not been |
| 7913 * performed, then `null` will be returned. |
| 7914 * |
| 7915 * @return the best element available for this function |
| 7916 */ |
| 7917 ExecutableElement get bestElement { |
| 7918 ExecutableElement element = propagatedElement; |
| 7919 if (element == null) { |
| 7920 element = staticElement; |
| 7921 } |
| 7922 return element; |
| 7923 } |
| 7924 |
| 7925 @override |
| 7926 Token get endToken => _argumentList.endToken; |
| 7927 |
| 7928 /** |
| 7929 * Return the expression producing the function being invoked. |
| 7930 * |
| 7931 * @return the expression producing the function being invoked |
| 7932 */ |
| 7933 Expression get function => _function; |
| 7934 |
| 7935 @override |
| 7936 int get precedence => 15; |
| 7937 |
| 7938 /** |
| 7939 * Return the element associated with the function being invoked based on prop
agated type |
| 7940 * information, or `null` if the AST structure has not been resolved or the fu
nction could |
| 7941 * not be resolved. One common example of the latter case is an expression who
se value can change |
| 7942 * over time. |
| 7943 * |
| 7944 * @return the element associated with the function being invoked |
| 7945 */ |
| 7946 ExecutableElement get propagatedElement => _propagatedElement; |
| 7947 |
| 7948 /** |
| 7949 * Set the list of arguments to the method to the given list. |
| 7950 * |
| 7951 * @param argumentList the list of arguments to the method |
| 7952 */ |
| 7953 void set argumentList(ArgumentList argumentList) { |
| 7954 this._argumentList = becomeParentOf(argumentList); |
| 7955 } |
| 7956 |
| 7957 /** |
| 7958 * Set the expression producing the function being invoked to the given expres
sion. |
| 7959 * |
| 7960 * @param function the expression producing the function being invoked |
| 7961 */ |
| 7962 void set function(Expression function) { |
| 7963 this._function = becomeParentOf(function); |
| 7964 } |
| 7965 |
| 7966 /** |
| 7967 * Set the element associated with the function being invoked based on propaga
ted type information |
| 7968 * to the given element. |
| 7969 * |
| 7970 * @param element the element to be associated with the function being invoked |
| 7971 */ |
| 7972 void set propagatedElement(ExecutableElement element) { |
| 7973 _propagatedElement = element; |
| 7974 } |
| 7975 |
| 7976 @override |
| 7977 void visitChildren(AstVisitor visitor) { |
| 7978 safelyVisitChild(_function, visitor); |
| 7979 safelyVisitChild(_argumentList, visitor); |
| 7980 } |
| 7981 } |
| 7982 |
| 7983 /** |
| 7984 * Instances of the class `FunctionTypeAlias` represent a function type alias. |
| 7985 * |
| 7986 * <pre> |
| 7987 * functionTypeAlias ::= |
| 7988 * functionPrefix [TypeParameterList]? [FormalParameterList] ';' |
| 7989 * |
| 7990 * functionPrefix ::= |
| 7991 * [TypeName]? [SimpleIdentifier] |
| 7992 * </pre> |
| 7993 */ |
| 7994 class FunctionTypeAlias extends TypeAlias { |
| 7995 /** |
| 7996 * The name of the return type of the function type being defined, or `null` i
f no return |
| 7997 * type was given. |
| 7998 */ |
| 7999 TypeName _returnType; |
| 8000 |
| 8001 /** |
| 8002 * The name of the function type being declared. |
| 8003 */ |
| 8004 SimpleIdentifier _name; |
| 8005 |
| 8006 /** |
| 8007 * The type parameters for the function type, or `null` if the function type d
oes not have |
| 8008 * any type parameters. |
| 8009 */ |
| 8010 TypeParameterList _typeParameters; |
| 8011 |
| 8012 /** |
| 8013 * The parameters associated with the function type. |
| 8014 */ |
| 8015 FormalParameterList _parameters; |
| 8016 |
| 8017 /** |
| 8018 * Initialize a newly created function type alias. |
| 8019 * |
| 8020 * @param comment the documentation comment associated with this type alias |
| 8021 * @param metadata the annotations associated with this type alias |
| 8022 * @param keyword the token representing the 'typedef' keyword |
| 8023 * @param returnType the name of the return type of the function type being de
fined |
| 8024 * @param name the name of the type being declared |
| 8025 * @param typeParameters the type parameters for the type |
| 8026 * @param parameters the parameters associated with the function |
| 8027 * @param semicolon the semicolon terminating the declaration |
| 8028 */ |
| 8029 FunctionTypeAlias(Comment comment, List<Annotation> metadata, Token keyword, T
ypeName returnType, SimpleIdentifier name, TypeParameterList typeParameters, For
malParameterList parameters, Token semicolon) : super(comment, metadata, keyword
, semicolon) { |
| 8030 this._returnType = becomeParentOf(returnType); |
| 8031 this._name = becomeParentOf(name); |
| 8032 this._typeParameters = becomeParentOf(typeParameters); |
| 8033 this._parameters = becomeParentOf(parameters); |
| 8034 } |
| 8035 |
| 8036 @override |
| 8037 accept(AstVisitor visitor) => visitor.visitFunctionTypeAlias(this); |
| 8038 |
| 8039 @override |
| 8040 FunctionTypeAliasElement get element => _name != null ? (_name.staticElement a
s FunctionTypeAliasElement) : null; |
| 8041 |
| 8042 /** |
| 8043 * Return the name of the function type being declared. |
| 8044 * |
| 8045 * @return the name of the function type being declared |
| 8046 */ |
| 8047 SimpleIdentifier get name => _name; |
| 8048 |
| 8049 /** |
| 8050 * Return the parameters associated with the function type. |
| 8051 * |
| 8052 * @return the parameters associated with the function type |
| 8053 */ |
| 8054 FormalParameterList get parameters => _parameters; |
| 8055 |
| 8056 /** |
| 8057 * Return the name of the return type of the function type being defined, or `
null` if no |
| 8058 * return type was given. |
| 8059 * |
| 8060 * @return the name of the return type of the function type being defined |
| 8061 */ |
| 8062 TypeName get returnType => _returnType; |
| 8063 |
| 8064 /** |
| 8065 * Return the type parameters for the function type, or `null` if the function
type does not |
| 8066 * have any type parameters. |
| 8067 * |
| 8068 * @return the type parameters for the function type |
| 8069 */ |
| 8070 TypeParameterList get typeParameters => _typeParameters; |
| 8071 |
| 8072 /** |
| 8073 * Set the name of the function type being declared to the given identifier. |
| 8074 * |
| 8075 * @param name the name of the function type being declared |
| 8076 */ |
| 8077 void set name(SimpleIdentifier name) { |
| 8078 this._name = becomeParentOf(name); |
| 8079 } |
| 8080 |
| 8081 /** |
| 8082 * Set the parameters associated with the function type to the given list of p
arameters. |
| 8083 * |
| 8084 * @param parameters the parameters associated with the function type |
| 8085 */ |
| 8086 void set parameters(FormalParameterList parameters) { |
| 8087 this._parameters = becomeParentOf(parameters); |
| 8088 } |
| 8089 |
| 8090 /** |
| 8091 * Set the name of the return type of the function type being defined to the g
iven type name. |
| 8092 * |
| 8093 * @param typeName the name of the return type of the function type being defi
ned |
| 8094 */ |
| 8095 void set returnType(TypeName typeName) { |
| 8096 _returnType = becomeParentOf(typeName); |
| 8097 } |
| 8098 |
| 8099 /** |
| 8100 * Set the type parameters for the function type to the given list of paramete
rs. |
| 8101 * |
| 8102 * @param typeParameters the type parameters for the function type |
| 8103 */ |
| 8104 void set typeParameters(TypeParameterList typeParameters) { |
| 8105 this._typeParameters = becomeParentOf(typeParameters); |
| 8106 } |
| 8107 |
| 8108 @override |
| 8109 void visitChildren(AstVisitor visitor) { |
| 8110 super.visitChildren(visitor); |
| 8111 safelyVisitChild(_returnType, visitor); |
| 8112 safelyVisitChild(_name, visitor); |
| 8113 safelyVisitChild(_typeParameters, visitor); |
| 8114 safelyVisitChild(_parameters, visitor); |
| 8115 } |
| 8116 } |
| 8117 |
| 8118 /** |
| 8119 * Instances of the class `FunctionTypedFormalParameter` represent a function-ty
ped formal |
| 8120 * parameter. |
| 8121 * |
| 8122 * <pre> |
| 8123 * functionSignature ::= |
| 8124 * [TypeName]? [SimpleIdentifier] [FormalParameterList] |
| 8125 * </pre> |
| 8126 */ |
| 8127 class FunctionTypedFormalParameter extends NormalFormalParameter { |
| 8128 /** |
| 8129 * The return type of the function, or `null` if the function does not have a
return type. |
| 8130 */ |
| 8131 TypeName _returnType; |
| 8132 |
| 8133 /** |
| 8134 * The parameters of the function-typed parameter. |
| 8135 */ |
| 8136 FormalParameterList _parameters; |
| 8137 |
| 8138 /** |
| 8139 * Initialize a newly created formal parameter. |
| 8140 * |
| 8141 * @param comment the documentation comment associated with this parameter |
| 8142 * @param metadata the annotations associated with this parameter |
| 8143 * @param returnType the return type of the function, or `null` if the functio
n does not |
| 8144 * have a return type |
| 8145 * @param identifier the name of the function-typed parameter |
| 8146 * @param parameters the parameters of the function-typed parameter |
| 8147 */ |
| 8148 FunctionTypedFormalParameter(Comment comment, List<Annotation> metadata, TypeN
ame returnType, SimpleIdentifier identifier, FormalParameterList parameters) : s
uper(comment, metadata, identifier) { |
| 8149 this._returnType = becomeParentOf(returnType); |
| 8150 this._parameters = becomeParentOf(parameters); |
| 8151 } |
| 8152 |
| 8153 @override |
| 8154 accept(AstVisitor visitor) => visitor.visitFunctionTypedFormalParameter(this); |
| 8155 |
| 8156 @override |
| 8157 Token get beginToken { |
| 8158 if (_returnType != null) { |
| 8159 return _returnType.beginToken; |
| 8160 } |
| 8161 return identifier.beginToken; |
| 8162 } |
| 8163 |
| 8164 @override |
| 8165 Token get endToken => _parameters.endToken; |
| 8166 |
| 8167 /** |
| 8168 * Return the parameters of the function-typed parameter. |
| 8169 * |
| 8170 * @return the parameters of the function-typed parameter |
| 8171 */ |
| 8172 FormalParameterList get parameters => _parameters; |
| 8173 |
| 8174 /** |
| 8175 * Return the return type of the function, or `null` if the function does not
have a return |
| 8176 * type. |
| 8177 * |
| 8178 * @return the return type of the function |
| 8179 */ |
| 8180 TypeName get returnType => _returnType; |
| 8181 |
| 8182 @override |
| 8183 bool get isConst => false; |
| 8184 |
| 8185 @override |
| 8186 bool get isFinal => false; |
| 8187 |
| 8188 /** |
| 8189 * Set the parameters of the function-typed parameter to the given parameters. |
| 8190 * |
| 8191 * @param parameters the parameters of the function-typed parameter |
| 8192 */ |
| 8193 void set parameters(FormalParameterList parameters) { |
| 8194 this._parameters = becomeParentOf(parameters); |
| 8195 } |
| 8196 |
| 8197 /** |
| 8198 * Set the return type of the function to the given type. |
| 8199 * |
| 8200 * @param returnType the return type of the function |
| 8201 */ |
| 8202 void set returnType(TypeName returnType) { |
| 8203 this._returnType = becomeParentOf(returnType); |
| 8204 } |
| 8205 |
| 8206 @override |
| 8207 void visitChildren(AstVisitor visitor) { |
| 8208 super.visitChildren(visitor); |
| 8209 safelyVisitChild(_returnType, visitor); |
| 8210 safelyVisitChild(identifier, visitor); |
| 8211 safelyVisitChild(_parameters, visitor); |
| 8212 } |
| 8213 } |
| 8214 |
| 8215 /** |
| 8216 * Instances of the class `GeneralizingAstVisitor` implement an AST visitor that
will |
| 8217 * recursively visit all of the nodes in an AST structure (like instances of the
class |
| 8218 * [RecursiveAstVisitor]). In addition, when a node of a specific type is visite
d not only |
| 8219 * will the visit method for that specific type of node be invoked, but addition
al methods for the |
| 8220 * superclasses of that node will also be invoked. For example, using an instanc
e of this class to |
| 8221 * visit a [Block] will cause the method [visitBlock] to be invoked but will |
| 8222 * also cause the methods [visitStatement] and [visitNode] to be |
| 8223 * subsequently invoked. This allows visitors to be written that visit all state
ments without |
| 8224 * needing to override the visit method for each of the specific subclasses of [
Statement]. |
| 8225 * |
| 8226 * Subclasses that override a visit method must either invoke the overridden vis
it method or |
| 8227 * explicitly invoke the more general visit method. Failure to do so will cause
the visit methods |
| 8228 * for superclasses of the node to not be invoked and will cause the children of
the visited node to |
| 8229 * not be visited. |
| 8230 */ |
| 8231 class GeneralizingAstVisitor<R> implements AstVisitor<R> { |
| 8232 @override |
| 8233 R visitAdjacentStrings(AdjacentStrings node) => visitStringLiteral(node); |
| 8234 |
| 8235 R visitAnnotatedNode(AnnotatedNode node) => visitNode(node); |
| 8236 |
| 8237 @override |
| 8238 R visitAnnotation(Annotation node) => visitNode(node); |
| 8239 |
| 8240 @override |
| 8241 R visitArgumentList(ArgumentList node) => visitNode(node); |
| 8242 |
| 8243 @override |
| 8244 R visitAsExpression(AsExpression node) => visitExpression(node); |
| 8245 |
| 8246 @override |
| 8247 R visitAssertStatement(AssertStatement node) => visitStatement(node); |
| 8248 |
| 8249 @override |
| 8250 R visitAssignmentExpression(AssignmentExpression node) => visitExpression(node
); |
| 8251 |
| 8252 @override |
| 8253 R visitAwaitExpression(AwaitExpression node) => visitExpression(node); |
| 8254 |
| 8255 @override |
| 8256 R visitBinaryExpression(BinaryExpression node) => visitExpression(node); |
| 8257 |
| 8258 @override |
| 8259 R visitBlock(Block node) => visitStatement(node); |
| 8260 |
| 8261 @override |
| 8262 R visitBlockFunctionBody(BlockFunctionBody node) => visitFunctionBody(node); |
| 8263 |
| 8264 @override |
| 8265 R visitBooleanLiteral(BooleanLiteral node) => visitLiteral(node); |
| 8266 |
| 8267 @override |
| 8268 R visitBreakStatement(BreakStatement node) => visitStatement(node); |
| 8269 |
| 8270 @override |
| 8271 R visitCascadeExpression(CascadeExpression node) => visitExpression(node); |
| 8272 |
| 8273 @override |
| 8274 R visitCatchClause(CatchClause node) => visitNode(node); |
| 8275 |
| 8276 @override |
| 8277 R visitClassDeclaration(ClassDeclaration node) => visitCompilationUnitMember(n
ode); |
| 8278 |
| 8279 R visitClassMember(ClassMember node) => visitDeclaration(node); |
| 8280 |
| 8281 @override |
| 8282 R visitClassTypeAlias(ClassTypeAlias node) => visitTypeAlias(node); |
| 8283 |
| 8284 R visitCombinator(Combinator node) => visitNode(node); |
| 8285 |
| 8286 @override |
| 8287 R visitComment(Comment node) => visitNode(node); |
| 8288 |
| 8289 @override |
| 8290 R visitCommentReference(CommentReference node) => visitNode(node); |
| 8291 |
| 8292 @override |
| 8293 R visitCompilationUnit(CompilationUnit node) => visitNode(node); |
| 8294 |
| 8295 R visitCompilationUnitMember(CompilationUnitMember node) => visitDeclaration(n
ode); |
| 8296 |
| 8297 @override |
| 8298 R visitConditionalExpression(ConditionalExpression node) => visitExpression(no
de); |
| 8299 |
| 8300 @override |
| 8301 R visitConstructorDeclaration(ConstructorDeclaration node) => visitClassMember
(node); |
| 8302 |
| 8303 @override |
| 8304 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => visitC
onstructorInitializer(node); |
| 8305 |
| 8306 R visitConstructorInitializer(ConstructorInitializer node) => visitNode(node); |
| 8307 |
| 8308 @override |
| 8309 R visitConstructorName(ConstructorName node) => visitNode(node); |
| 8310 |
| 8311 @override |
| 8312 R visitContinueStatement(ContinueStatement node) => visitStatement(node); |
| 8313 |
| 8314 R visitDeclaration(Declaration node) => visitAnnotatedNode(node); |
| 8315 |
| 8316 @override |
| 8317 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitDeclaration(node); |
| 8318 |
| 8319 @override |
| 8320 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitFormalParam
eter(node); |
| 8321 |
| 8322 R visitDirective(Directive node) => visitAnnotatedNode(node); |
| 8323 |
| 8324 @override |
| 8325 R visitDoStatement(DoStatement node) => visitStatement(node); |
| 8326 |
| 8327 @override |
| 8328 R visitDoubleLiteral(DoubleLiteral node) => visitLiteral(node); |
| 8329 |
| 8330 @override |
| 8331 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitFunctionBody(node); |
| 8332 |
| 8333 @override |
| 8334 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); |
| 8335 |
| 8336 @override |
| 8337 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => visitDeclarati
on(node); |
| 8338 |
| 8339 @override |
| 8340 R visitEnumDeclaration(EnumDeclaration node) => visitCompilationUnitMember(nod
e); |
| 8341 |
| 8342 @override |
| 8343 R visitExportDirective(ExportDirective node) => visitNamespaceDirective(node); |
| 8344 |
| 8345 R visitExpression(Expression node) => visitNode(node); |
| 8346 |
| 8347 @override |
| 8348 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitFunctionBod
y(node); |
| 8349 |
| 8350 @override |
| 8351 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); |
| 8352 |
| 8353 @override |
| 8354 R visitExtendsClause(ExtendsClause node) => visitNode(node); |
| 8355 |
| 8356 @override |
| 8357 R visitFieldDeclaration(FieldDeclaration node) => visitClassMember(node); |
| 8358 |
| 8359 @override |
| 8360 R visitFieldFormalParameter(FieldFormalParameter node) => visitNormalFormalPar
ameter(node); |
| 8361 |
| 8362 @override |
| 8363 R visitForEachStatement(ForEachStatement node) => visitStatement(node); |
| 8364 |
| 8365 R visitFormalParameter(FormalParameter node) => visitNode(node); |
| 8366 |
| 8367 @override |
| 8368 R visitFormalParameterList(FormalParameterList node) => visitNode(node); |
| 8369 |
| 8370 @override |
| 8371 R visitForStatement(ForStatement node) => visitStatement(node); |
| 8372 |
| 8373 R visitFunctionBody(FunctionBody node) => visitNode(node); |
| 8374 |
| 8375 @override |
| 8376 R visitFunctionDeclaration(FunctionDeclaration node) => visitCompilationUnitMe
mber(node); |
| 8377 |
| 8378 @override |
| 8379 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => visi
tStatement(node); |
| 8380 |
| 8381 @override |
| 8382 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); |
| 8383 |
| 8384 @override |
| 8385 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => visi
tExpression(node); |
| 8386 |
| 8387 @override |
| 8388 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitTypeAlias(node); |
| 8389 |
| 8390 @override |
| 8391 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => visi
tNormalFormalParameter(node); |
| 8392 |
| 8393 @override |
| 8394 R visitHideCombinator(HideCombinator node) => visitCombinator(node); |
| 8395 |
| 8396 R visitIdentifier(Identifier node) => visitExpression(node); |
| 8397 |
| 8398 @override |
| 8399 R visitIfStatement(IfStatement node) => visitStatement(node); |
| 8400 |
| 8401 @override |
| 8402 R visitImplementsClause(ImplementsClause node) => visitNode(node); |
| 8403 |
| 8404 @override |
| 8405 R visitImportDirective(ImportDirective node) => visitNamespaceDirective(node); |
| 8406 |
| 8407 @override |
| 8408 R visitIndexExpression(IndexExpression node) => visitExpression(node); |
| 8409 |
| 8410 @override |
| 8411 R visitInstanceCreationExpression(InstanceCreationExpression node) => visitExp
ression(node); |
| 8412 |
| 8413 @override |
| 8414 R visitIntegerLiteral(IntegerLiteral node) => visitLiteral(node); |
| 8415 |
| 8416 R visitInterpolationElement(InterpolationElement node) => visitNode(node); |
| 8417 |
| 8418 @override |
| 8419 R visitInterpolationExpression(InterpolationExpression node) => visitInterpola
tionElement(node); |
| 8420 |
| 8421 @override |
| 8422 R visitInterpolationString(InterpolationString node) => visitInterpolationElem
ent(node); |
| 8423 |
| 8424 @override |
| 8425 R visitIsExpression(IsExpression node) => visitExpression(node); |
| 8426 |
| 8427 @override |
| 8428 R visitLabel(Label node) => visitNode(node); |
| 8429 |
| 8430 @override |
| 8431 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); |
| 8432 |
| 8433 @override |
| 8434 R visitLibraryDirective(LibraryDirective node) => visitDirective(node); |
| 8435 |
| 8436 @override |
| 8437 R visitLibraryIdentifier(LibraryIdentifier node) => visitIdentifier(node); |
| 8438 |
| 8439 @override |
| 8440 R visitListLiteral(ListLiteral node) => visitTypedLiteral(node); |
| 8441 |
| 8442 R visitLiteral(Literal node) => visitExpression(node); |
| 8443 |
| 8444 @override |
| 8445 R visitMapLiteral(MapLiteral node) => visitTypedLiteral(node); |
| 8446 |
| 8447 @override |
| 8448 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node); |
| 8449 |
| 8450 @override |
| 8451 R visitMethodDeclaration(MethodDeclaration node) => visitClassMember(node); |
| 8452 |
| 8453 @override |
| 8454 R visitMethodInvocation(MethodInvocation node) => visitExpression(node); |
| 8455 |
| 8456 @override |
| 8457 R visitNamedExpression(NamedExpression node) => visitExpression(node); |
| 8458 |
| 8459 R visitNamespaceDirective(NamespaceDirective node) => visitUriBasedDirective(n
ode); |
| 8460 |
| 8461 @override |
| 8462 R visitNativeClause(NativeClause node) => visitNode(node); |
| 8463 |
| 8464 @override |
| 8465 R visitNativeFunctionBody(NativeFunctionBody node) => visitFunctionBody(node); |
| 8466 |
| 8467 R visitNode(AstNode node) { |
| 8468 node.visitChildren(this); |
| 8469 return null; |
| 8470 } |
| 8471 |
| 8472 R visitNormalFormalParameter(NormalFormalParameter node) => visitFormalParamet
er(node); |
| 8473 |
| 8474 @override |
| 8475 R visitNullLiteral(NullLiteral node) => visitLiteral(node); |
| 8476 |
| 8477 @override |
| 8478 R visitParenthesizedExpression(ParenthesizedExpression node) => visitExpressio
n(node); |
| 8479 |
| 8480 @override |
| 8481 R visitPartDirective(PartDirective node) => visitUriBasedDirective(node); |
| 8482 |
| 8483 @override |
| 8484 R visitPartOfDirective(PartOfDirective node) => visitDirective(node); |
| 8485 |
| 8486 @override |
| 8487 R visitPostfixExpression(PostfixExpression node) => visitExpression(node); |
| 8488 |
| 8489 @override |
| 8490 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitIdentifier(node); |
| 8491 |
| 8492 @override |
| 8493 R visitPrefixExpression(PrefixExpression node) => visitExpression(node); |
| 8494 |
| 8495 @override |
| 8496 R visitPropertyAccess(PropertyAccess node) => visitExpression(node); |
| 8497 |
| 8498 @override |
| 8499 R visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node)
=> visitConstructorInitializer(node); |
| 8500 |
| 8501 @override |
| 8502 R visitRethrowExpression(RethrowExpression node) => visitExpression(node); |
| 8503 |
| 8504 @override |
| 8505 R visitReturnStatement(ReturnStatement node) => visitStatement(node); |
| 8506 |
| 8507 @override |
| 8508 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); |
| 8509 |
| 8510 @override |
| 8511 R visitShowCombinator(ShowCombinator node) => visitCombinator(node); |
| 8512 |
| 8513 @override |
| 8514 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNormalFormalP
arameter(node); |
| 8515 |
| 8516 @override |
| 8517 R visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node); |
| 8518 |
| 8519 @override |
| 8520 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitStringLiteral(nod
e); |
| 8521 |
| 8522 R visitStatement(Statement node) => visitNode(node); |
| 8523 |
| 8524 @override |
| 8525 R visitStringInterpolation(StringInterpolation node) => visitStringLiteral(nod
e); |
| 8526 |
| 8527 R visitStringLiteral(StringLiteral node) => visitLiteral(node); |
| 8528 |
| 8529 @override |
| 8530 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => visitCon
structorInitializer(node); |
| 8531 |
| 8532 @override |
| 8533 R visitSuperExpression(SuperExpression node) => visitExpression(node); |
| 8534 |
| 8535 @override |
| 8536 R visitSwitchCase(SwitchCase node) => visitSwitchMember(node); |
| 8537 |
| 8538 @override |
| 8539 R visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node); |
| 8540 |
| 8541 R visitSwitchMember(SwitchMember node) => visitNode(node); |
| 8542 |
| 8543 @override |
| 8544 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); |
| 8545 |
| 8546 @override |
| 8547 R visitSymbolLiteral(SymbolLiteral node) => visitLiteral(node); |
| 8548 |
| 8549 @override |
| 8550 R visitThisExpression(ThisExpression node) => visitExpression(node); |
| 8551 |
| 8552 @override |
| 8553 R visitThrowExpression(ThrowExpression node) => visitExpression(node); |
| 8554 |
| 8555 @override |
| 8556 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => visitC
ompilationUnitMember(node); |
| 8557 |
| 8558 @override |
| 8559 R visitTryStatement(TryStatement node) => visitStatement(node); |
| 8560 |
| 8561 R visitTypeAlias(TypeAlias node) => visitCompilationUnitMember(node); |
| 8562 |
| 8563 @override |
| 8564 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node); |
| 8565 |
| 8566 R visitTypedLiteral(TypedLiteral node) => visitLiteral(node); |
| 8567 |
| 8568 @override |
| 8569 R visitTypeName(TypeName node) => visitNode(node); |
| 8570 |
| 8571 @override |
| 8572 R visitTypeParameter(TypeParameter node) => visitNode(node); |
| 8573 |
| 8574 @override |
| 8575 R visitTypeParameterList(TypeParameterList node) => visitNode(node); |
| 8576 |
| 8577 R visitUriBasedDirective(UriBasedDirective node) => visitDirective(node); |
| 8578 |
| 8579 @override |
| 8580 R visitVariableDeclaration(VariableDeclaration node) => visitDeclaration(node)
; |
| 8581 |
| 8582 @override |
| 8583 R visitVariableDeclarationList(VariableDeclarationList node) => visitNode(node
); |
| 8584 |
| 8585 @override |
| 8586 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => visi
tStatement(node); |
| 8587 |
| 8588 @override |
| 8589 R visitWhileStatement(WhileStatement node) => visitStatement(node); |
| 8590 |
| 8591 @override |
| 8592 R visitWithClause(WithClause node) => visitNode(node); |
| 8593 |
| 8594 @override |
| 8595 R visitYieldStatement(YieldStatement node) => visitStatement(node); |
| 8596 } |
| 8597 |
| 8598 class GeneralizingAstVisitor_BreadthFirstVisitor extends GeneralizingAstVisitor<
Object> { |
| 8599 final BreadthFirstVisitor BreadthFirstVisitor_this; |
| 8600 |
| 8601 GeneralizingAstVisitor_BreadthFirstVisitor(this.BreadthFirstVisitor_this) : su
per(); |
| 8602 |
| 8603 @override |
| 8604 Object visitNode(AstNode node) { |
| 8605 BreadthFirstVisitor_this._queue.add(node); |
| 8606 return null; |
| 8607 } |
| 8608 } |
| 8609 |
| 8610 /** |
| 8611 * Instances of the class `HideCombinator` represent a combinator that restricts
the names |
| 8612 * being imported to those that are not in a given list. |
| 8613 * |
| 8614 * <pre> |
| 8615 * hideCombinator ::= |
| 8616 * 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])* |
| 8617 * </pre> |
| 8618 */ |
| 8619 class HideCombinator extends Combinator { |
| 8620 /** |
| 8621 * The list of names from the library that are hidden by this combinator. |
| 8622 */ |
| 8623 NodeList<SimpleIdentifier> _hiddenNames; |
| 8624 |
| 8625 /** |
| 8626 * Initialize a newly created import show combinator. |
| 8627 * |
| 8628 * @param keyword the comma introducing the combinator |
| 8629 * @param hiddenNames the list of names from the library that are hidden by th
is combinator |
| 8630 */ |
| 8631 HideCombinator(Token keyword, List<SimpleIdentifier> hiddenNames) : super(keyw
ord) { |
| 8632 this._hiddenNames = new NodeList<SimpleIdentifier>(this); |
| 8633 this._hiddenNames.addAll(hiddenNames); |
| 8634 } |
| 8635 |
| 8636 @override |
| 8637 accept(AstVisitor visitor) => visitor.visitHideCombinator(this); |
| 8638 |
| 8639 @override |
| 8640 Token get endToken => _hiddenNames.endToken; |
| 8641 |
| 8642 /** |
| 8643 * Return the list of names from the library that are hidden by this combinato
r. |
| 8644 * |
| 8645 * @return the list of names from the library that are hidden by this combinat
or |
| 8646 */ |
| 8647 NodeList<SimpleIdentifier> get hiddenNames => _hiddenNames; |
| 8648 |
| 8649 @override |
| 8650 void visitChildren(AstVisitor visitor) { |
| 8651 _hiddenNames.accept(visitor); |
| 8652 } |
| 8653 } |
| 8654 |
| 8655 /** |
| 8656 * The abstract class `Identifier` defines the behavior common to nodes that rep
resent an |
| 8657 * identifier. |
| 8658 * |
| 8659 * <pre> |
| 8660 * identifier ::= |
| 8661 * [SimpleIdentifier] |
| 8662 * | [PrefixedIdentifier] |
| 8663 * </pre> |
| 8664 */ |
| 8665 abstract class Identifier extends Expression { |
| 8666 /** |
| 8667 * Return `true` if the given name is visible only within the library in which
it is |
| 8668 * declared. |
| 8669 * |
| 8670 * @param name the name being tested |
| 8671 * @return `true` if the given name is private |
| 8672 */ |
| 8673 static bool isPrivateName(String name) => StringUtilities.startsWithChar(name,
0x5F); |
| 8674 |
| 8675 /** |
| 8676 * Return the best element available for this operator. If resolution was able
to find a better |
| 8677 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 8678 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 8679 * then `null` will be returned. |
| 8680 * |
| 8681 * @return the best element available for this operator |
| 8682 */ |
| 8683 Element get bestElement; |
| 8684 |
| 8685 /** |
| 8686 * Return the lexical representation of the identifier. |
| 8687 * |
| 8688 * @return the lexical representation of the identifier |
| 8689 */ |
| 8690 String get name; |
| 8691 |
| 8692 /** |
| 8693 * Return the element associated with this identifier based on propagated type
information, or |
| 8694 * `null` if the AST structure has not been resolved or if this identifier cou
ld not be |
| 8695 * resolved. One example of the latter case is an identifier that is not defin
ed within the scope |
| 8696 * in which it appears. |
| 8697 * |
| 8698 * @return the element associated with this identifier |
| 8699 */ |
| 8700 Element get propagatedElement; |
| 8701 |
| 8702 /** |
| 8703 * Return the element associated with this identifier based on static type inf
ormation, or |
| 8704 * `null` if the AST structure has not been resolved or if this identifier cou
ld not be |
| 8705 * resolved. One example of the latter case is an identifier that is not defin
ed within the scope |
| 8706 * in which it appears |
| 8707 * |
| 8708 * @return the element associated with the operator |
| 8709 */ |
| 8710 Element get staticElement; |
| 8711 |
| 8712 @override |
| 8713 bool get isAssignable => true; |
| 8714 } |
| 8715 |
| 8716 /** |
| 8717 * Instances of the class `IfStatement` represent an if statement. |
| 8718 * |
| 8719 * <pre> |
| 8720 * ifStatement ::= |
| 8721 * 'if' '(' [Expression] ')' [Statement] ('else' [Statement])? |
| 8722 * </pre> |
| 8723 */ |
| 8724 class IfStatement extends Statement { |
| 8725 /** |
| 8726 * The token representing the 'if' keyword. |
| 8727 */ |
| 8728 Token ifKeyword; |
| 8729 |
| 8730 /** |
| 8731 * The left parenthesis. |
| 8732 */ |
| 8733 Token leftParenthesis; |
| 8734 |
| 8735 /** |
| 8736 * The condition used to determine which of the statements is executed next. |
| 8737 */ |
| 8738 Expression _condition; |
| 8739 |
| 8740 /** |
| 8741 * The right parenthesis. |
| 8742 */ |
| 8743 Token rightParenthesis; |
| 8744 |
| 8745 /** |
| 8746 * The statement that is executed if the condition evaluates to `true`. |
| 8747 */ |
| 8748 Statement _thenStatement; |
| 8749 |
| 8750 /** |
| 8751 * The token representing the 'else' keyword, or `null` if there is no else st
atement. |
| 8752 */ |
| 8753 Token elseKeyword; |
| 8754 |
| 8755 /** |
| 8756 * The statement that is executed if the condition evaluates to `false`, or `n
ull` if |
| 8757 * there is no else statement. |
| 8758 */ |
| 8759 Statement _elseStatement; |
| 8760 |
| 8761 /** |
| 8762 * Initialize a newly created if statement. |
| 8763 * |
| 8764 * @param ifKeyword the token representing the 'if' keyword |
| 8765 * @param leftParenthesis the left parenthesis |
| 8766 * @param condition the condition used to determine which of the statements is
executed next |
| 8767 * @param rightParenthesis the right parenthesis |
| 8768 * @param thenStatement the statement that is executed if the condition evalua
tes to `true` |
| 8769 * @param elseKeyword the token representing the 'else' keyword |
| 8770 * @param elseStatement the statement that is executed if the condition evalua
tes to `false` |
| 8771 */ |
| 8772 IfStatement(this.ifKeyword, this.leftParenthesis, Expression condition, this.r
ightParenthesis, Statement thenStatement, this.elseKeyword, Statement elseStatem
ent) { |
| 8773 this._condition = becomeParentOf(condition); |
| 8774 this._thenStatement = becomeParentOf(thenStatement); |
| 8775 this._elseStatement = becomeParentOf(elseStatement); |
| 8776 } |
| 8777 |
| 8778 @override |
| 8779 accept(AstVisitor visitor) => visitor.visitIfStatement(this); |
| 8780 |
| 8781 @override |
| 8782 Token get beginToken => ifKeyword; |
| 8783 |
| 8784 /** |
| 8785 * Return the condition used to determine which of the statements is executed
next. |
| 8786 * |
| 8787 * @return the condition used to determine which statement is executed next |
| 8788 */ |
| 8789 Expression get condition => _condition; |
| 8790 |
| 8791 /** |
| 8792 * Return the statement that is executed if the condition evaluates to `false`
, or |
| 8793 * `null` if there is no else statement. |
| 8794 * |
| 8795 * @return the statement that is executed if the condition evaluates to `false
` |
| 8796 */ |
| 8797 Statement get elseStatement => _elseStatement; |
| 8798 |
| 8799 @override |
| 8800 Token get endToken { |
| 8801 if (_elseStatement != null) { |
| 8802 return _elseStatement.endToken; |
| 8803 } |
| 8804 return _thenStatement.endToken; |
| 8805 } |
| 8806 |
| 8807 /** |
| 8808 * Return the statement that is executed if the condition evaluates to `true`. |
| 8809 * |
| 8810 * @return the statement that is executed if the condition evaluates to `true` |
| 8811 */ |
| 8812 Statement get thenStatement => _thenStatement; |
| 8813 |
| 8814 /** |
| 8815 * Set the condition used to determine which of the statements is executed nex
t to the given |
| 8816 * expression. |
| 8817 * |
| 8818 * @param expression the condition used to determine which statement is execut
ed next |
| 8819 */ |
| 8820 void set condition(Expression expression) { |
| 8821 _condition = becomeParentOf(expression); |
| 8822 } |
| 8823 |
| 8824 /** |
| 8825 * Set the statement that is executed if the condition evaluates to `false` to
the given |
| 8826 * statement. |
| 8827 * |
| 8828 * @param statement the statement that is executed if the condition evaluates
to `false` |
| 8829 */ |
| 8830 void set elseStatement(Statement statement) { |
| 8831 _elseStatement = becomeParentOf(statement); |
| 8832 } |
| 8833 |
| 8834 /** |
| 8835 * Set the statement that is executed if the condition evaluates to `true` to
the given |
| 8836 * statement. |
| 8837 * |
| 8838 * @param statement the statement that is executed if the condition evaluates
to `true` |
| 8839 */ |
| 8840 void set thenStatement(Statement statement) { |
| 8841 _thenStatement = becomeParentOf(statement); |
| 8842 } |
| 8843 |
| 8844 @override |
| 8845 void visitChildren(AstVisitor visitor) { |
| 8846 safelyVisitChild(_condition, visitor); |
| 8847 safelyVisitChild(_thenStatement, visitor); |
| 8848 safelyVisitChild(_elseStatement, visitor); |
| 8849 } |
| 8850 } |
| 8851 |
| 8852 /** |
| 8853 * Instances of the class `ImplementsClause` represent the "implements" clause i
n an class |
| 8854 * declaration. |
| 8855 * |
| 8856 * <pre> |
| 8857 * implementsClause ::= |
| 8858 * 'implements' [TypeName] (',' [TypeName])* |
| 8859 * </pre> |
| 8860 */ |
| 8861 class ImplementsClause extends AstNode { |
| 8862 /** |
| 8863 * The token representing the 'implements' keyword. |
| 8864 */ |
| 8865 Token keyword; |
| 8866 |
| 8867 /** |
| 8868 * The interfaces that are being implemented. |
| 8869 */ |
| 8870 NodeList<TypeName> _interfaces; |
| 8871 |
| 8872 /** |
| 8873 * Initialize a newly created implements clause. |
| 8874 * |
| 8875 * @param keyword the token representing the 'implements' keyword |
| 8876 * @param interfaces the interfaces that are being implemented |
| 8877 */ |
| 8878 ImplementsClause(this.keyword, List<TypeName> interfaces) { |
| 8879 this._interfaces = new NodeList<TypeName>(this); |
| 8880 this._interfaces.addAll(interfaces); |
| 8881 } |
| 8882 |
| 8883 @override |
| 8884 accept(AstVisitor visitor) => visitor.visitImplementsClause(this); |
| 8885 |
| 8886 @override |
| 8887 Token get beginToken => keyword; |
| 8888 |
| 8889 @override |
| 8890 Token get endToken => _interfaces.endToken; |
| 8891 |
| 8892 /** |
| 8893 * Return the list of the interfaces that are being implemented. |
| 8894 * |
| 8895 * @return the list of the interfaces that are being implemented |
| 8896 */ |
| 8897 NodeList<TypeName> get interfaces => _interfaces; |
| 8898 |
| 8899 @override |
| 8900 void visitChildren(AstVisitor visitor) { |
| 8901 _interfaces.accept(visitor); |
| 8902 } |
| 8903 } |
| 8904 |
| 8905 /** |
| 8906 * Instances of the class `ImportDirective` represent an import directive. |
| 8907 * |
| 8908 * <pre> |
| 8909 * importDirective ::= |
| 8910 * [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* ';
' |
| 8911 * | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combina
tor]* ';' |
| 8912 * </pre> |
| 8913 */ |
| 8914 class ImportDirective extends NamespaceDirective { |
| 8915 static Comparator<ImportDirective> COMPARATOR = (ImportDirective import1, Impo
rtDirective import2) { |
| 8916 // |
| 8917 // uri |
| 8918 // |
| 8919 StringLiteral uri1 = import1.uri; |
| 8920 StringLiteral uri2 = import2.uri; |
| 8921 String uriStr1 = uri1.stringValue; |
| 8922 String uriStr2 = uri2.stringValue; |
| 8923 if (uriStr1 != null || uriStr2 != null) { |
| 8924 if (uriStr1 == null) { |
| 8925 return -1; |
| 8926 } else if (uriStr2 == null) { |
| 8927 return 1; |
| 8928 } else { |
| 8929 int compare = uriStr1.compareTo(uriStr2); |
| 8930 if (compare != 0) { |
| 8931 return compare; |
| 8932 } |
| 8933 } |
| 8934 } |
| 8935 // |
| 8936 // as |
| 8937 // |
| 8938 SimpleIdentifier prefix1 = import1.prefix; |
| 8939 SimpleIdentifier prefix2 = import2.prefix; |
| 8940 String prefixStr1 = prefix1 != null ? prefix1.name : null; |
| 8941 String prefixStr2 = prefix2 != null ? prefix2.name : null; |
| 8942 if (prefixStr1 != null || prefixStr2 != null) { |
| 8943 if (prefixStr1 == null) { |
| 8944 return -1; |
| 8945 } else if (prefixStr2 == null) { |
| 8946 return 1; |
| 8947 } else { |
| 8948 int compare = prefixStr1.compareTo(prefixStr2); |
| 8949 if (compare != 0) { |
| 8950 return compare; |
| 8951 } |
| 8952 } |
| 8953 } |
| 8954 // |
| 8955 // hides and shows |
| 8956 // |
| 8957 NodeList<Combinator> combinators1 = import1.combinators; |
| 8958 List<String> allHides1 = new List<String>(); |
| 8959 List<String> allShows1 = new List<String>(); |
| 8960 for (Combinator combinator in combinators1) { |
| 8961 if (combinator is HideCombinator) { |
| 8962 NodeList<SimpleIdentifier> hides = combinator.hiddenNames; |
| 8963 for (SimpleIdentifier simpleIdentifier in hides) { |
| 8964 allHides1.add(simpleIdentifier.name); |
| 8965 } |
| 8966 } else { |
| 8967 NodeList<SimpleIdentifier> shows = (combinator as ShowCombinator).shownN
ames; |
| 8968 for (SimpleIdentifier simpleIdentifier in shows) { |
| 8969 allShows1.add(simpleIdentifier.name); |
| 8970 } |
| 8971 } |
| 8972 } |
| 8973 NodeList<Combinator> combinators2 = import2.combinators; |
| 8974 List<String> allHides2 = new List<String>(); |
| 8975 List<String> allShows2 = new List<String>(); |
| 8976 for (Combinator combinator in combinators2) { |
| 8977 if (combinator is HideCombinator) { |
| 8978 NodeList<SimpleIdentifier> hides = combinator.hiddenNames; |
| 8979 for (SimpleIdentifier simpleIdentifier in hides) { |
| 8980 allHides2.add(simpleIdentifier.name); |
| 8981 } |
| 8982 } else { |
| 8983 NodeList<SimpleIdentifier> shows = (combinator as ShowCombinator).shownN
ames; |
| 8984 for (SimpleIdentifier simpleIdentifier in shows) { |
| 8985 allShows2.add(simpleIdentifier.name); |
| 8986 } |
| 8987 } |
| 8988 } |
| 8989 // test lengths of combinator lists first |
| 8990 if (allHides1.length != allHides2.length) { |
| 8991 return allHides1.length - allHides2.length; |
| 8992 } |
| 8993 if (allShows1.length != allShows2.length) { |
| 8994 return allShows1.length - allShows2.length; |
| 8995 } |
| 8996 // next ensure that the lists are equivalent |
| 8997 if (!javaCollectionContainsAll(allHides1, allHides2)) { |
| 8998 return -1; |
| 8999 } |
| 9000 if (!javaCollectionContainsAll(allShows1, allShows2)) { |
| 9001 return -1; |
| 9002 } |
| 9003 return 0; |
| 9004 }; |
| 9005 |
| 9006 /** |
| 9007 * The token representing the 'deferred' token, or `null` if the imported is n
ot deferred. |
| 9008 */ |
| 9009 Token deferredToken; |
| 9010 |
| 9011 /** |
| 9012 * The token representing the 'as' token, or `null` if the imported names are
not prefixed. |
| 9013 */ |
| 9014 Token asToken; |
| 9015 |
| 9016 /** |
| 9017 * The prefix to be used with the imported names, or `null` if the imported na
mes are not |
| 9018 * prefixed. |
| 9019 */ |
| 9020 SimpleIdentifier _prefix; |
| 9021 |
| 9022 /** |
| 9023 * Initialize a newly created import directive. |
| 9024 * |
| 9025 * @param comment the documentation comment associated with this directive |
| 9026 * @param metadata the annotations associated with the directive |
| 9027 * @param keyword the token representing the 'import' keyword |
| 9028 * @param libraryUri the URI of the library being imported |
| 9029 * @param deferredToken the token representing the 'deferred' token |
| 9030 * @param asToken the token representing the 'as' token |
| 9031 * @param prefix the prefix to be used with the imported names |
| 9032 * @param combinators the combinators used to control how names are imported |
| 9033 * @param semicolon the semicolon terminating the directive |
| 9034 */ |
| 9035 ImportDirective(Comment comment, List<Annotation> metadata, Token keyword, Str
ingLiteral libraryUri, this.deferredToken, this.asToken, SimpleIdentifier prefix
, List<Combinator> combinators, Token semicolon) : super(comment, metadata, keyw
ord, libraryUri, combinators, semicolon) { |
| 9036 this._prefix = becomeParentOf(prefix); |
| 9037 } |
| 9038 |
| 9039 @override |
| 9040 accept(AstVisitor visitor) => visitor.visitImportDirective(this); |
| 9041 |
| 9042 @override |
| 9043 ImportElement get element => super.element as ImportElement; |
| 9044 |
| 9045 /** |
| 9046 * Return the prefix to be used with the imported names, or `null` if the impo
rted names are |
| 9047 * not prefixed. |
| 9048 * |
| 9049 * @return the prefix to be used with the imported names |
| 9050 */ |
| 9051 SimpleIdentifier get prefix => _prefix; |
| 9052 |
| 9053 @override |
| 9054 LibraryElement get uriElement { |
| 9055 ImportElement element = this.element; |
| 9056 if (element == null) { |
| 9057 return null; |
| 9058 } |
| 9059 return element.importedLibrary; |
| 9060 } |
| 9061 |
| 9062 /** |
| 9063 * Set the prefix to be used with the imported names to the given identifier. |
| 9064 * |
| 9065 * @param prefix the prefix to be used with the imported names |
| 9066 */ |
| 9067 void set prefix(SimpleIdentifier prefix) { |
| 9068 this._prefix = becomeParentOf(prefix); |
| 9069 } |
| 9070 |
| 9071 @override |
| 9072 void visitChildren(AstVisitor visitor) { |
| 9073 super.visitChildren(visitor); |
| 9074 safelyVisitChild(_prefix, visitor); |
| 9075 combinators.accept(visitor); |
| 9076 } |
| 9077 } |
| 9078 |
| 9079 /** |
| 9080 * Instances of the class `IncrementalAstCloner` implement an object that will c
lone any AST |
| 9081 * structure that it visits. The cloner will clone the structure, replacing the
specified ASTNode |
| 9082 * with a new ASTNode, mapping the old token stream to a new token stream, and p
reserving resolution |
| 9083 * results. |
| 9084 */ |
| 9085 class IncrementalAstCloner implements AstVisitor<AstNode> { |
| 9086 /** |
| 9087 * The node to be replaced during the cloning process. |
| 9088 */ |
| 9089 final AstNode _oldNode; |
| 9090 |
| 9091 /** |
| 9092 * The replacement node used during the cloning process. |
| 9093 */ |
| 9094 final AstNode _newNode; |
| 9095 |
| 9096 /** |
| 9097 * A mapping of old tokens to new tokens used during the cloning process. |
| 9098 */ |
| 9099 final TokenMap _tokenMap; |
| 9100 |
| 9101 /** |
| 9102 * Construct a new instance that will replace `oldNode` with `newNode` in the
process |
| 9103 * of cloning an existing AST structure. |
| 9104 * |
| 9105 * @param oldNode the node to be replaced |
| 9106 * @param newNode the replacement node |
| 9107 * @param tokenMap a mapping of old tokens to new tokens (not `null`) |
| 9108 */ |
| 9109 IncrementalAstCloner(this._oldNode, this._newNode, this._tokenMap); |
| 9110 |
| 9111 @override |
| 9112 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) => new AdjacentStri
ngs(_cloneNodeList(node.strings)); |
| 9113 |
| 9114 @override |
| 9115 Annotation visitAnnotation(Annotation node) { |
| 9116 Annotation copy = new Annotation(_mapToken(node.atSign), _cloneNode(node.nam
e), _mapToken(node.period), _cloneNode(node.constructorName), _cloneNode(node.ar
guments)); |
| 9117 copy.element = node.element; |
| 9118 return copy; |
| 9119 } |
| 9120 |
| 9121 @override |
| 9122 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(_mapToke
n(node.leftParenthesis), _cloneNodeList(node.arguments), _mapToken(node.rightPar
enthesis)); |
| 9123 |
| 9124 @override |
| 9125 AsExpression visitAsExpression(AsExpression node) { |
| 9126 AsExpression copy = new AsExpression(_cloneNode(node.expression), _mapToken(
node.asOperator), _cloneNode(node.type)); |
| 9127 copy.propagatedType = node.propagatedType; |
| 9128 copy.staticType = node.staticType; |
| 9129 return copy; |
| 9130 } |
| 9131 |
| 9132 @override |
| 9133 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(_map
Token(node.keyword), _mapToken(node.leftParenthesis), _cloneNode(node.condition)
, _mapToken(node.rightParenthesis), _mapToken(node.semicolon)); |
| 9134 |
| 9135 @override |
| 9136 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) { |
| 9137 AssignmentExpression copy = new AssignmentExpression(_cloneNode(node.leftHan
dSide), _mapToken(node.operator), _cloneNode(node.rightHandSide)); |
| 9138 copy.propagatedElement = node.propagatedElement; |
| 9139 copy.propagatedType = node.propagatedType; |
| 9140 copy.staticElement = node.staticElement; |
| 9141 copy.staticType = node.staticType; |
| 9142 return copy; |
| 9143 } |
| 9144 |
| 9145 @override |
| 9146 AwaitExpression visitAwaitExpression(AwaitExpression node) => new AwaitExpress
ion(_mapToken(node.awaitKeyword), _cloneNode(node.expression)); |
| 9147 |
| 9148 @override |
| 9149 BinaryExpression visitBinaryExpression(BinaryExpression node) { |
| 9150 BinaryExpression copy = new BinaryExpression(_cloneNode(node.leftOperand), _
mapToken(node.operator), _cloneNode(node.rightOperand)); |
| 9151 copy.propagatedElement = node.propagatedElement; |
| 9152 copy.propagatedType = node.propagatedType; |
| 9153 copy.staticElement = node.staticElement; |
| 9154 copy.staticType = node.staticType; |
| 9155 return copy; |
| 9156 } |
| 9157 |
| 9158 @override |
| 9159 Block visitBlock(Block node) => new Block(_mapToken(node.leftBracket), _cloneN
odeList(node.statements), _mapToken(node.rightBracket)); |
| 9160 |
| 9161 @override |
| 9162 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) => new BlockF
unctionBody(_mapToken(node.keyword), _mapToken(node.star), _cloneNode(node.block
)); |
| 9163 |
| 9164 @override |
| 9165 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) { |
| 9166 BooleanLiteral copy = new BooleanLiteral(_mapToken(node.literal), node.value
); |
| 9167 copy.propagatedType = node.propagatedType; |
| 9168 copy.staticType = node.staticType; |
| 9169 return copy; |
| 9170 } |
| 9171 |
| 9172 @override |
| 9173 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
_mapToken(node.keyword), _cloneNode(node.label), _mapToken(node.semicolon)); |
| 9174 |
| 9175 @override |
| 9176 CascadeExpression visitCascadeExpression(CascadeExpression node) { |
| 9177 CascadeExpression copy = new CascadeExpression(_cloneNode(node.target), _clo
neNodeList(node.cascadeSections)); |
| 9178 copy.propagatedType = node.propagatedType; |
| 9179 copy.staticType = node.staticType; |
| 9180 return copy; |
| 9181 } |
| 9182 |
| 9183 @override |
| 9184 CatchClause visitCatchClause(CatchClause node) => new CatchClause(_mapToken(no
de.onKeyword), _cloneNode(node.exceptionType), _mapToken(node.catchKeyword), _ma
pToken(node.leftParenthesis), _cloneNode(node.exceptionParameter), _mapToken(nod
e.comma), _cloneNode(node.stackTraceParameter), _mapToken(node.rightParenthesis)
, _cloneNode(node.body)); |
| 9185 |
| 9186 @override |
| 9187 ClassDeclaration visitClassDeclaration(ClassDeclaration node) { |
| 9188 ClassDeclaration copy = new ClassDeclaration(_cloneNode(node.documentationCo
mment), _cloneNodeList(node.metadata), _mapToken(node.abstractKeyword), _mapToke
n(node.classKeyword), _cloneNode(node.name), _cloneNode(node.typeParameters), _c
loneNode(node.extendsClause), _cloneNode(node.withClause), _cloneNode(node.imple
mentsClause), _mapToken(node.leftBracket), _cloneNodeList(node.members), _mapTok
en(node.rightBracket)); |
| 9189 copy.nativeClause = _cloneNode(node.nativeClause); |
| 9190 return copy; |
| 9191 } |
| 9192 |
| 9193 @override |
| 9194 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
_cloneNode(node.documentationComment), _cloneNodeList(node.metadata), _mapToken(
node.keyword), _cloneNode(node.name), _cloneNode(node.typeParameters), _mapToken
(node.equals), _mapToken(node.abstractKeyword), _cloneNode(node.superclass), _cl
oneNode(node.withClause), _cloneNode(node.implementsClause), _mapToken(node.semi
colon)); |
| 9195 |
| 9196 @override |
| 9197 Comment visitComment(Comment node) { |
| 9198 if (node.isDocumentation) { |
| 9199 return Comment.createDocumentationCommentWithReferences(_mapTokens(node.to
kens), _cloneNodeList(node.references)); |
| 9200 } else if (node.isBlock) { |
| 9201 return Comment.createBlockComment(_mapTokens(node.tokens)); |
| 9202 } |
| 9203 return Comment.createEndOfLineComment(_mapTokens(node.tokens)); |
| 9204 } |
| 9205 |
| 9206 @override |
| 9207 CommentReference visitCommentReference(CommentReference node) => new CommentRe
ference(_mapToken(node.newKeyword), _cloneNode(node.identifier)); |
| 9208 |
| 9209 @override |
| 9210 CompilationUnit visitCompilationUnit(CompilationUnit node) { |
| 9211 CompilationUnit copy = new CompilationUnit(_mapToken(node.beginToken), _clon
eNode(node.scriptTag), _cloneNodeList(node.directives), _cloneNodeList(node.decl
arations), _mapToken(node.endToken)); |
| 9212 copy.lineInfo = node.lineInfo; |
| 9213 copy.element = node.element; |
| 9214 return copy; |
| 9215 } |
| 9216 |
| 9217 @override |
| 9218 ConditionalExpression visitConditionalExpression(ConditionalExpression node) { |
| 9219 ConditionalExpression copy = new ConditionalExpression(_cloneNode(node.condi
tion), _mapToken(node.question), _cloneNode(node.thenExpression), _mapToken(node
.colon), _cloneNode(node.elseExpression)); |
| 9220 copy.propagatedType = node.propagatedType; |
| 9221 copy.staticType = node.staticType; |
| 9222 return copy; |
| 9223 } |
| 9224 |
| 9225 @override |
| 9226 ConstructorDeclaration visitConstructorDeclaration(ConstructorDeclaration node
) { |
| 9227 ConstructorDeclaration copy = new ConstructorDeclaration(_cloneNode(node.doc
umentationComment), _cloneNodeList(node.metadata), _mapToken(node.externalKeywor
d), _mapToken(node.constKeyword), _mapToken(node.factoryKeyword), _cloneNode(nod
e.returnType), _mapToken(node.period), _cloneNode(node.name), _cloneNode(node.pa
rameters), _mapToken(node.separator), _cloneNodeList(node.initializers), _cloneN
ode(node.redirectedConstructor), _cloneNode(node.body)); |
| 9228 copy.element = node.element; |
| 9229 return copy; |
| 9230 } |
| 9231 |
| 9232 @override |
| 9233 ConstructorFieldInitializer visitConstructorFieldInitializer(ConstructorFieldI
nitializer node) => new ConstructorFieldInitializer(_mapToken(node.keyword), _ma
pToken(node.period), _cloneNode(node.fieldName), _mapToken(node.equals), _cloneN
ode(node.expression)); |
| 9234 |
| 9235 @override |
| 9236 ConstructorName visitConstructorName(ConstructorName node) { |
| 9237 ConstructorName copy = new ConstructorName(_cloneNode(node.type), _mapToken(
node.period), _cloneNode(node.name)); |
| 9238 copy.staticElement = node.staticElement; |
| 9239 return copy; |
| 9240 } |
| 9241 |
| 9242 @override |
| 9243 ContinueStatement visitContinueStatement(ContinueStatement node) => new Contin
ueStatement(_mapToken(node.keyword), _cloneNode(node.label), _mapToken(node.semi
colon)); |
| 9244 |
| 9245 @override |
| 9246 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) => new Dec
laredIdentifier(_cloneNode(node.documentationComment), _cloneNodeList(node.metad
ata), _mapToken(node.keyword), _cloneNode(node.type), _cloneNode(node.identifier
)); |
| 9247 |
| 9248 @override |
| 9249 DefaultFormalParameter visitDefaultFormalParameter(DefaultFormalParameter node
) => new DefaultFormalParameter(_cloneNode(node.parameter), node.kind, _mapToken
(node.separator), _cloneNode(node.defaultValue)); |
| 9250 |
| 9251 @override |
| 9252 DoStatement visitDoStatement(DoStatement node) => new DoStatement(_mapToken(no
de.doKeyword), _cloneNode(node.body), _mapToken(node.whileKeyword), _mapToken(no
de.leftParenthesis), _cloneNode(node.condition), _mapToken(node.rightParenthesis
), _mapToken(node.semicolon)); |
| 9253 |
| 9254 @override |
| 9255 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) { |
| 9256 DoubleLiteral copy = new DoubleLiteral(_mapToken(node.literal), node.value); |
| 9257 copy.propagatedType = node.propagatedType; |
| 9258 copy.staticType = node.staticType; |
| 9259 return copy; |
| 9260 } |
| 9261 |
| 9262 @override |
| 9263 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) => new EmptyF
unctionBody(_mapToken(node.semicolon)); |
| 9264 |
| 9265 @override |
| 9266 EmptyStatement visitEmptyStatement(EmptyStatement node) => new EmptyStatement(
_mapToken(node.semicolon)); |
| 9267 |
| 9268 @override |
| 9269 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) => new Enum
ConstantDeclaration(_cloneNode(node.documentationComment), _cloneNodeList(node.m
etadata), _cloneNode(node.name)); |
| 9270 |
| 9271 @override |
| 9272 AstNode visitEnumDeclaration(EnumDeclaration node) => new EnumDeclaration(_clo
neNode(node.documentationComment), _cloneNodeList(node.metadata), _mapToken(node
.keyword), _cloneNode(node.name), _mapToken(node.leftBracket), _cloneNodeList(no
de.constants), _mapToken(node.rightBracket)); |
| 9273 |
| 9274 @override |
| 9275 ExportDirective visitExportDirective(ExportDirective node) { |
| 9276 ExportDirective copy = new ExportDirective(_cloneNode(node.documentationComm
ent), _cloneNodeList(node.metadata), _mapToken(node.keyword), _cloneNode(node.ur
i), _cloneNodeList(node.combinators), _mapToken(node.semicolon)); |
| 9277 copy.element = node.element; |
| 9278 return copy; |
| 9279 } |
| 9280 |
| 9281 @override |
| 9282 ExpressionFunctionBody visitExpressionFunctionBody(ExpressionFunctionBody node
) => new ExpressionFunctionBody(_mapToken(node.keyword), _mapToken(node.function
Definition), _cloneNode(node.expression), _mapToken(node.semicolon)); |
| 9283 |
| 9284 @override |
| 9285 ExpressionStatement visitExpressionStatement(ExpressionStatement node) => new
ExpressionStatement(_cloneNode(node.expression), _mapToken(node.semicolon)); |
| 9286 |
| 9287 @override |
| 9288 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(_map
Token(node.keyword), _cloneNode(node.superclass)); |
| 9289 |
| 9290 @override |
| 9291 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) => new FieldDecl
aration(_cloneNode(node.documentationComment), _cloneNodeList(node.metadata), _m
apToken(node.staticKeyword), _cloneNode(node.fields), _mapToken(node.semicolon))
; |
| 9292 |
| 9293 @override |
| 9294 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) => n
ew FieldFormalParameter(_cloneNode(node.documentationComment), _cloneNodeList(no
de.metadata), _mapToken(node.keyword), _cloneNode(node.type), _mapToken(node.thi
sToken), _mapToken(node.period), _cloneNode(node.identifier), _cloneNode(node.pa
rameters)); |
| 9295 |
| 9296 @override |
| 9297 ForEachStatement visitForEachStatement(ForEachStatement node) { |
| 9298 DeclaredIdentifier loopVariable = node.loopVariable; |
| 9299 if (loopVariable == null) { |
| 9300 return new ForEachStatement.con2(_mapToken(node.awaitKeyword), _mapToken(n
ode.forKeyword), _mapToken(node.leftParenthesis), _cloneNode(node.identifier), _
mapToken(node.inKeyword), _cloneNode(node.iterator), _mapToken(node.rightParenth
esis), _cloneNode(node.body)); |
| 9301 } |
| 9302 return new ForEachStatement.con1(_mapToken(node.awaitKeyword), _mapToken(nod
e.forKeyword), _mapToken(node.leftParenthesis), _cloneNode(loopVariable), _mapTo
ken(node.inKeyword), _cloneNode(node.iterator), _mapToken(node.rightParenthesis)
, _cloneNode(node.body)); |
| 9303 } |
| 9304 |
| 9305 @override |
| 9306 FormalParameterList visitFormalParameterList(FormalParameterList node) => new
FormalParameterList(_mapToken(node.leftParenthesis), _cloneNodeList(node.paramet
ers), _mapToken(node.leftDelimiter), _mapToken(node.rightDelimiter), _mapToken(n
ode.rightParenthesis)); |
| 9307 |
| 9308 @override |
| 9309 ForStatement visitForStatement(ForStatement node) => new ForStatement(_mapToke
n(node.forKeyword), _mapToken(node.leftParenthesis), _cloneNode(node.variables),
_cloneNode(node.initialization), _mapToken(node.leftSeparator), _cloneNode(node
.condition), _mapToken(node.rightSeparator), _cloneNodeList(node.updaters), _map
Token(node.rightParenthesis), _cloneNode(node.body)); |
| 9310 |
| 9311 @override |
| 9312 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) => new
FunctionDeclaration(_cloneNode(node.documentationComment), _cloneNodeList(node.m
etadata), _mapToken(node.externalKeyword), _cloneNode(node.returnType), _mapToke
n(node.propertyKeyword), _cloneNode(node.name), _cloneNode(node.functionExpressi
on)); |
| 9313 |
| 9314 @override |
| 9315 FunctionDeclarationStatement visitFunctionDeclarationStatement(FunctionDeclara
tionStatement node) => new FunctionDeclarationStatement(_cloneNode(node.function
Declaration)); |
| 9316 |
| 9317 @override |
| 9318 FunctionExpression visitFunctionExpression(FunctionExpression node) { |
| 9319 FunctionExpression copy = new FunctionExpression(_cloneNode(node.parameters)
, _cloneNode(node.body)); |
| 9320 copy.element = node.element; |
| 9321 copy.propagatedType = node.propagatedType; |
| 9322 copy.staticType = node.staticType; |
| 9323 return copy; |
| 9324 } |
| 9325 |
| 9326 @override |
| 9327 FunctionExpressionInvocation visitFunctionExpressionInvocation(FunctionExpress
ionInvocation node) { |
| 9328 FunctionExpressionInvocation copy = new FunctionExpressionInvocation(_cloneN
ode(node.function), _cloneNode(node.argumentList)); |
| 9329 copy.propagatedElement = node.propagatedElement; |
| 9330 copy.propagatedType = node.propagatedType; |
| 9331 copy.staticElement = node.staticElement; |
| 9332 copy.staticType = node.staticType; |
| 9333 return copy; |
| 9334 } |
| 9335 |
| 9336 @override |
| 9337 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) => new Functi
onTypeAlias(_cloneNode(node.documentationComment), _cloneNodeList(node.metadata)
, _mapToken(node.keyword), _cloneNode(node.returnType), _cloneNode(node.name), _
cloneNode(node.typeParameters), _cloneNode(node.parameters), _mapToken(node.semi
colon)); |
| 9338 |
| 9339 @override |
| 9340 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(FunctionTypedFo
rmalParameter node) => new FunctionTypedFormalParameter(_cloneNode(node.document
ationComment), _cloneNodeList(node.metadata), _cloneNode(node.returnType), _clon
eNode(node.identifier), _cloneNode(node.parameters)); |
| 9341 |
| 9342 @override |
| 9343 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
_mapToken(node.keyword), _cloneNodeList(node.hiddenNames)); |
| 9344 |
| 9345 @override |
| 9346 IfStatement visitIfStatement(IfStatement node) => new IfStatement(_mapToken(no
de.ifKeyword), _mapToken(node.leftParenthesis), _cloneNode(node.condition), _map
Token(node.rightParenthesis), _cloneNode(node.thenStatement), _mapToken(node.els
eKeyword), _cloneNode(node.elseStatement)); |
| 9347 |
| 9348 @override |
| 9349 ImplementsClause visitImplementsClause(ImplementsClause node) => new Implement
sClause(_mapToken(node.keyword), _cloneNodeList(node.interfaces)); |
| 9350 |
| 9351 @override |
| 9352 ImportDirective visitImportDirective(ImportDirective node) => new ImportDirect
ive(_cloneNode(node.documentationComment), _cloneNodeList(node.metadata), _mapTo
ken(node.keyword), _cloneNode(node.uri), _mapToken(node.deferredToken), _mapToke
n(node.asToken), _cloneNode(node.prefix), _cloneNodeList(node.combinators), _map
Token(node.semicolon)); |
| 9353 |
| 9354 @override |
| 9355 IndexExpression visitIndexExpression(IndexExpression node) { |
| 9356 Token period = _mapToken(node.period); |
| 9357 IndexExpression copy; |
| 9358 if (period == null) { |
| 9359 copy = new IndexExpression.forTarget(_cloneNode(node.target), _mapToken(no
de.leftBracket), _cloneNode(node.index), _mapToken(node.rightBracket)); |
| 9360 } else { |
| 9361 copy = new IndexExpression.forCascade(period, _mapToken(node.leftBracket),
_cloneNode(node.index), _mapToken(node.rightBracket)); |
| 9362 } |
| 9363 copy.auxiliaryElements = node.auxiliaryElements; |
| 9364 copy.propagatedElement = node.propagatedElement; |
| 9365 copy.propagatedType = node.propagatedType; |
| 9366 copy.staticElement = node.staticElement; |
| 9367 copy.staticType = node.staticType; |
| 9368 return copy; |
| 9369 } |
| 9370 |
| 9371 @override |
| 9372 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp
ression node) { |
| 9373 InstanceCreationExpression copy = new InstanceCreationExpression(_mapToken(n
ode.keyword), _cloneNode(node.constructorName), _cloneNode(node.argumentList)); |
| 9374 copy.propagatedType = node.propagatedType; |
| 9375 copy.staticElement = node.staticElement; |
| 9376 copy.staticType = node.staticType; |
| 9377 return copy; |
| 9378 } |
| 9379 |
| 9380 @override |
| 9381 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) { |
| 9382 IntegerLiteral copy = new IntegerLiteral(_mapToken(node.literal), node.value
); |
| 9383 copy.propagatedType = node.propagatedType; |
| 9384 copy.staticType = node.staticType; |
| 9385 return copy; |
| 9386 } |
| 9387 |
| 9388 @override |
| 9389 InterpolationExpression visitInterpolationExpression(InterpolationExpression n
ode) => new InterpolationExpression(_mapToken(node.leftBracket), _cloneNode(node
.expression), _mapToken(node.rightBracket)); |
| 9390 |
| 9391 @override |
| 9392 InterpolationString visitInterpolationString(InterpolationString node) => new
InterpolationString(_mapToken(node.contents), node.value); |
| 9393 |
| 9394 @override |
| 9395 IsExpression visitIsExpression(IsExpression node) { |
| 9396 IsExpression copy = new IsExpression(_cloneNode(node.expression), _mapToken(
node.isOperator), _mapToken(node.notOperator), _cloneNode(node.type)); |
| 9397 copy.propagatedType = node.propagatedType; |
| 9398 copy.staticType = node.staticType; |
| 9399 return copy; |
| 9400 } |
| 9401 |
| 9402 @override |
| 9403 Label visitLabel(Label node) => new Label(_cloneNode(node.label), _mapToken(no
de.colon)); |
| 9404 |
| 9405 @override |
| 9406 LabeledStatement visitLabeledStatement(LabeledStatement node) => new LabeledSt
atement(_cloneNodeList(node.labels), _cloneNode(node.statement)); |
| 9407 |
| 9408 @override |
| 9409 LibraryDirective visitLibraryDirective(LibraryDirective node) => new LibraryDi
rective(_cloneNode(node.documentationComment), _cloneNodeList(node.metadata), _m
apToken(node.libraryToken), _cloneNode(node.name), _mapToken(node.semicolon)); |
| 9410 |
| 9411 @override |
| 9412 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) { |
| 9413 LibraryIdentifier copy = new LibraryIdentifier(_cloneNodeList(node.component
s)); |
| 9414 copy.propagatedType = node.propagatedType; |
| 9415 copy.staticType = node.staticType; |
| 9416 return copy; |
| 9417 } |
| 9418 |
| 9419 @override |
| 9420 ListLiteral visitListLiteral(ListLiteral node) { |
| 9421 ListLiteral copy = new ListLiteral(_mapToken(node.constKeyword), _cloneNode(
node.typeArguments), _mapToken(node.leftBracket), _cloneNodeList(node.elements),
_mapToken(node.rightBracket)); |
| 9422 copy.propagatedType = node.propagatedType; |
| 9423 copy.staticType = node.staticType; |
| 9424 return copy; |
| 9425 } |
| 9426 |
| 9427 @override |
| 9428 MapLiteral visitMapLiteral(MapLiteral node) { |
| 9429 MapLiteral copy = new MapLiteral(_mapToken(node.constKeyword), _cloneNode(no
de.typeArguments), _mapToken(node.leftBracket), _cloneNodeList(node.entries), _m
apToken(node.rightBracket)); |
| 9430 copy.propagatedType = node.propagatedType; |
| 9431 copy.staticType = node.staticType; |
| 9432 return copy; |
| 9433 } |
| 9434 |
| 9435 @override |
| 9436 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) => new MapLiteralEn
try(_cloneNode(node.key), _mapToken(node.separator), _cloneNode(node.value)); |
| 9437 |
| 9438 @override |
| 9439 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) => new Method
Declaration(_cloneNode(node.documentationComment), _cloneNodeList(node.metadata)
, _mapToken(node.externalKeyword), _mapToken(node.modifierKeyword), _cloneNode(n
ode.returnType), _mapToken(node.propertyKeyword), _mapToken(node.operatorKeyword
), _cloneNode(node.name), _cloneNode(node.parameters), _cloneNode(node.body)); |
| 9440 |
| 9441 @override |
| 9442 MethodInvocation visitMethodInvocation(MethodInvocation node) { |
| 9443 MethodInvocation copy = new MethodInvocation(_cloneNode(node.target), _mapTo
ken(node.period), _cloneNode(node.methodName), _cloneNode(node.argumentList)); |
| 9444 copy.propagatedType = node.propagatedType; |
| 9445 copy.staticType = node.staticType; |
| 9446 return copy; |
| 9447 } |
| 9448 |
| 9449 @override |
| 9450 NamedExpression visitNamedExpression(NamedExpression node) { |
| 9451 NamedExpression copy = new NamedExpression(_cloneNode(node.name), _cloneNode
(node.expression)); |
| 9452 copy.propagatedType = node.propagatedType; |
| 9453 copy.staticType = node.staticType; |
| 9454 return copy; |
| 9455 } |
| 9456 |
| 9457 @override |
| 9458 AstNode visitNativeClause(NativeClause node) => new NativeClause(_mapToken(nod
e.keyword), _cloneNode(node.name)); |
| 9459 |
| 9460 @override |
| 9461 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) => new Nat
iveFunctionBody(_mapToken(node.nativeToken), _cloneNode(node.stringLiteral), _ma
pToken(node.semicolon)); |
| 9462 |
| 9463 @override |
| 9464 NullLiteral visitNullLiteral(NullLiteral node) { |
| 9465 NullLiteral copy = new NullLiteral(_mapToken(node.literal)); |
| 9466 copy.propagatedType = node.propagatedType; |
| 9467 copy.staticType = node.staticType; |
| 9468 return copy; |
| 9469 } |
| 9470 |
| 9471 @override |
| 9472 ParenthesizedExpression visitParenthesizedExpression(ParenthesizedExpression n
ode) { |
| 9473 ParenthesizedExpression copy = new ParenthesizedExpression(_mapToken(node.le
ftParenthesis), _cloneNode(node.expression), _mapToken(node.rightParenthesis)); |
| 9474 copy.propagatedType = node.propagatedType; |
| 9475 copy.staticType = node.staticType; |
| 9476 return copy; |
| 9477 } |
| 9478 |
| 9479 @override |
| 9480 PartDirective visitPartDirective(PartDirective node) { |
| 9481 PartDirective copy = new PartDirective(_cloneNode(node.documentationComment)
, _cloneNodeList(node.metadata), _mapToken(node.partToken), _cloneNode(node.uri)
, _mapToken(node.semicolon)); |
| 9482 copy.element = node.element; |
| 9483 return copy; |
| 9484 } |
| 9485 |
| 9486 @override |
| 9487 PartOfDirective visitPartOfDirective(PartOfDirective node) { |
| 9488 PartOfDirective copy = new PartOfDirective(_cloneNode(node.documentationComm
ent), _cloneNodeList(node.metadata), _mapToken(node.partToken), _mapToken(node.o
fToken), _cloneNode(node.libraryName), _mapToken(node.semicolon)); |
| 9489 copy.element = node.element; |
| 9490 return copy; |
| 9491 } |
| 9492 |
| 9493 @override |
| 9494 PostfixExpression visitPostfixExpression(PostfixExpression node) { |
| 9495 PostfixExpression copy = new PostfixExpression(_cloneNode(node.operand), _ma
pToken(node.operator)); |
| 9496 copy.propagatedElement = node.propagatedElement; |
| 9497 copy.propagatedType = node.propagatedType; |
| 9498 copy.staticElement = node.staticElement; |
| 9499 copy.staticType = node.staticType; |
| 9500 return copy; |
| 9501 } |
| 9502 |
| 9503 @override |
| 9504 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 9505 PrefixedIdentifier copy = new PrefixedIdentifier(_cloneNode(node.prefix), _m
apToken(node.period), _cloneNode(node.identifier)); |
| 9506 copy.propagatedType = node.propagatedType; |
| 9507 copy.staticType = node.staticType; |
| 9508 return copy; |
| 9509 } |
| 9510 |
| 9511 @override |
| 9512 PrefixExpression visitPrefixExpression(PrefixExpression node) { |
| 9513 PrefixExpression copy = new PrefixExpression(_mapToken(node.operator), _clon
eNode(node.operand)); |
| 9514 copy.propagatedElement = node.propagatedElement; |
| 9515 copy.propagatedType = node.propagatedType; |
| 9516 copy.staticElement = node.staticElement; |
| 9517 copy.staticType = node.staticType; |
| 9518 return copy; |
| 9519 } |
| 9520 |
| 9521 @override |
| 9522 PropertyAccess visitPropertyAccess(PropertyAccess node) { |
| 9523 PropertyAccess copy = new PropertyAccess(_cloneNode(node.target), _mapToken(
node.operator), _cloneNode(node.propertyName)); |
| 9524 copy.propagatedType = node.propagatedType; |
| 9525 copy.staticType = node.staticType; |
| 9526 return copy; |
| 9527 } |
| 9528 |
| 9529 @override |
| 9530 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(Redirec
tingConstructorInvocation node) { |
| 9531 RedirectingConstructorInvocation copy = new RedirectingConstructorInvocation
(_mapToken(node.keyword), _mapToken(node.period), _cloneNode(node.constructorNam
e), _cloneNode(node.argumentList)); |
| 9532 copy.staticElement = node.staticElement; |
| 9533 return copy; |
| 9534 } |
| 9535 |
| 9536 @override |
| 9537 RethrowExpression visitRethrowExpression(RethrowExpression node) { |
| 9538 RethrowExpression copy = new RethrowExpression(_mapToken(node.keyword)); |
| 9539 copy.propagatedType = node.propagatedType; |
| 9540 copy.staticType = node.staticType; |
| 9541 return copy; |
| 9542 } |
| 9543 |
| 9544 @override |
| 9545 ReturnStatement visitReturnStatement(ReturnStatement node) => new ReturnStatem
ent(_mapToken(node.keyword), _cloneNode(node.expression), _mapToken(node.semicol
on)); |
| 9546 |
| 9547 @override |
| 9548 ScriptTag visitScriptTag(ScriptTag node) => new ScriptTag(_mapToken(node.scrip
tTag)); |
| 9549 |
| 9550 @override |
| 9551 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
_mapToken(node.keyword), _cloneNodeList(node.shownNames)); |
| 9552 |
| 9553 @override |
| 9554 SimpleFormalParameter visitSimpleFormalParameter(SimpleFormalParameter node) =
> new SimpleFormalParameter(_cloneNode(node.documentationComment), _cloneNodeLis
t(node.metadata), _mapToken(node.keyword), _cloneNode(node.type), _cloneNode(nod
e.identifier)); |
| 9555 |
| 9556 @override |
| 9557 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) { |
| 9558 Token mappedToken = _mapToken(node.token); |
| 9559 if (mappedToken == null) { |
| 9560 // This only happens for SimpleIdentifiers created by the parser as part o
f scanning |
| 9561 // documentation comments (the tokens for those identifiers are not in the
original token |
| 9562 // stream and hence do not get copied). This extra check can be removed if
the scanner is |
| 9563 // changed to scan documentation comments for the parser. |
| 9564 mappedToken = node.token; |
| 9565 } |
| 9566 SimpleIdentifier copy = new SimpleIdentifier(mappedToken); |
| 9567 copy.auxiliaryElements = node.auxiliaryElements; |
| 9568 copy.propagatedElement = node.propagatedElement; |
| 9569 copy.propagatedType = node.propagatedType; |
| 9570 copy.staticElement = node.staticElement; |
| 9571 copy.staticType = node.staticType; |
| 9572 return copy; |
| 9573 } |
| 9574 |
| 9575 @override |
| 9576 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 9577 SimpleStringLiteral copy = new SimpleStringLiteral(_mapToken(node.literal),
node.value); |
| 9578 copy.propagatedType = node.propagatedType; |
| 9579 copy.staticType = node.staticType; |
| 9580 return copy; |
| 9581 } |
| 9582 |
| 9583 @override |
| 9584 StringInterpolation visitStringInterpolation(StringInterpolation node) { |
| 9585 StringInterpolation copy = new StringInterpolation(_cloneNodeList(node.eleme
nts)); |
| 9586 copy.propagatedType = node.propagatedType; |
| 9587 copy.staticType = node.staticType; |
| 9588 return copy; |
| 9589 } |
| 9590 |
| 9591 @override |
| 9592 SuperConstructorInvocation visitSuperConstructorInvocation(SuperConstructorInv
ocation node) { |
| 9593 SuperConstructorInvocation copy = new SuperConstructorInvocation(_mapToken(n
ode.keyword), _mapToken(node.period), _cloneNode(node.constructorName), _cloneNo
de(node.argumentList)); |
| 9594 copy.staticElement = node.staticElement; |
| 9595 return copy; |
| 9596 } |
| 9597 |
| 9598 @override |
| 9599 SuperExpression visitSuperExpression(SuperExpression node) { |
| 9600 SuperExpression copy = new SuperExpression(_mapToken(node.keyword)); |
| 9601 copy.propagatedType = node.propagatedType; |
| 9602 copy.staticType = node.staticType; |
| 9603 return copy; |
| 9604 } |
| 9605 |
| 9606 @override |
| 9607 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(_cloneNodeList(n
ode.labels), _mapToken(node.keyword), _cloneNode(node.expression), _mapToken(nod
e.colon), _cloneNodeList(node.statements)); |
| 9608 |
| 9609 @override |
| 9610 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(_clo
neNodeList(node.labels), _mapToken(node.keyword), _mapToken(node.colon), _cloneN
odeList(node.statements)); |
| 9611 |
| 9612 @override |
| 9613 SwitchStatement visitSwitchStatement(SwitchStatement node) => new SwitchStatem
ent(_mapToken(node.keyword), _mapToken(node.leftParenthesis), _cloneNode(node.ex
pression), _mapToken(node.rightParenthesis), _mapToken(node.leftBracket), _clone
NodeList(node.members), _mapToken(node.rightBracket)); |
| 9614 |
| 9615 @override |
| 9616 AstNode visitSymbolLiteral(SymbolLiteral node) { |
| 9617 SymbolLiteral copy = new SymbolLiteral(_mapToken(node.poundSign), _mapTokens
(node.components)); |
| 9618 copy.propagatedType = node.propagatedType; |
| 9619 copy.staticType = node.staticType; |
| 9620 return copy; |
| 9621 } |
| 9622 |
| 9623 @override |
| 9624 ThisExpression visitThisExpression(ThisExpression node) { |
| 9625 ThisExpression copy = new ThisExpression(_mapToken(node.keyword)); |
| 9626 copy.propagatedType = node.propagatedType; |
| 9627 copy.staticType = node.staticType; |
| 9628 return copy; |
| 9629 } |
| 9630 |
| 9631 @override |
| 9632 ThrowExpression visitThrowExpression(ThrowExpression node) { |
| 9633 ThrowExpression copy = new ThrowExpression(_mapToken(node.keyword), _cloneNo
de(node.expression)); |
| 9634 copy.propagatedType = node.propagatedType; |
| 9635 copy.staticType = node.staticType; |
| 9636 return copy; |
| 9637 } |
| 9638 |
| 9639 @override |
| 9640 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(TopLevelVariableD
eclaration node) => new TopLevelVariableDeclaration(_cloneNode(node.documentatio
nComment), _cloneNodeList(node.metadata), _cloneNode(node.variables), _mapToken(
node.semicolon)); |
| 9641 |
| 9642 @override |
| 9643 TryStatement visitTryStatement(TryStatement node) => new TryStatement(_mapToke
n(node.tryKeyword), _cloneNode(node.body), _cloneNodeList(node.catchClauses), _m
apToken(node.finallyKeyword), _cloneNode(node.finallyBlock)); |
| 9644 |
| 9645 @override |
| 9646 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) => new TypeArgum
entList(_mapToken(node.leftBracket), _cloneNodeList(node.arguments), _mapToken(n
ode.rightBracket)); |
| 9647 |
| 9648 @override |
| 9649 TypeName visitTypeName(TypeName node) { |
| 9650 TypeName copy = new TypeName(_cloneNode(node.name), _cloneNode(node.typeArgu
ments)); |
| 9651 copy.type = node.type; |
| 9652 return copy; |
| 9653 } |
| 9654 |
| 9655 @override |
| 9656 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(_clo
neNode(node.documentationComment), _cloneNodeList(node.metadata), _cloneNode(nod
e.name), _mapToken(node.keyword), _cloneNode(node.bound)); |
| 9657 |
| 9658 @override |
| 9659 TypeParameterList visitTypeParameterList(TypeParameterList node) => new TypePa
rameterList(_mapToken(node.leftBracket), _cloneNodeList(node.typeParameters), _m
apToken(node.rightBracket)); |
| 9660 |
| 9661 @override |
| 9662 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) => new
VariableDeclaration(null, _cloneNodeList(node.metadata), _cloneNode(node.name),
_mapToken(node.equals), _cloneNode(node.initializer)); |
| 9663 |
| 9664 @override |
| 9665 VariableDeclarationList visitVariableDeclarationList(VariableDeclarationList n
ode) => new VariableDeclarationList(null, _cloneNodeList(node.metadata), _mapTok
en(node.keyword), _cloneNode(node.type), _cloneNodeList(node.variables)); |
| 9666 |
| 9667 @override |
| 9668 VariableDeclarationStatement visitVariableDeclarationStatement(VariableDeclara
tionStatement node) => new VariableDeclarationStatement(_cloneNode(node.variable
s), _mapToken(node.semicolon)); |
| 9669 |
| 9670 @override |
| 9671 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
_mapToken(node.keyword), _mapToken(node.leftParenthesis), _cloneNode(node.condit
ion), _mapToken(node.rightParenthesis), _cloneNode(node.body)); |
| 9672 |
| 9673 @override |
| 9674 WithClause visitWithClause(WithClause node) => new WithClause(_mapToken(node.w
ithKeyword), _cloneNodeList(node.mixinTypes)); |
| 9675 |
| 9676 @override |
| 9677 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
_mapToken(node.yieldKeyword), _mapToken(node.star), _cloneNode(node.expression),
_mapToken(node.semicolon)); |
| 9678 |
| 9679 AstNode _cloneNode(AstNode node) { |
| 9680 if (node == null) { |
| 9681 return null; |
| 9682 } |
| 9683 if (identical(node, _oldNode)) { |
| 9684 return _newNode; |
| 9685 } |
| 9686 return node.accept(this) as AstNode; |
| 9687 } |
| 9688 |
| 9689 List _cloneNodeList(NodeList nodes) { |
| 9690 List clonedNodes = new List(); |
| 9691 for (AstNode node in nodes) { |
| 9692 clonedNodes.add(_cloneNode(node)); |
| 9693 } |
| 9694 return clonedNodes; |
| 9695 } |
| 9696 |
| 9697 Token _mapToken(Token oldToken) { |
| 9698 if (oldToken == null) { |
| 9699 return null; |
| 9700 } |
| 9701 return _tokenMap.get(oldToken); |
| 9702 } |
| 9703 |
| 9704 List<Token> _mapTokens(List<Token> oldTokens) { |
| 9705 List<Token> newTokens = new List<Token>(oldTokens.length); |
| 9706 for (int index = 0; index < newTokens.length; index++) { |
| 9707 newTokens[index] = _mapToken(oldTokens[index]); |
| 9708 } |
| 9709 return newTokens; |
| 9710 } |
| 9711 } |
| 9712 |
| 9713 /** |
| 9714 * Instances of the class `IndexExpression` represent an index expression. |
| 9715 * |
| 9716 * <pre> |
| 9717 * indexExpression ::= |
| 9718 * [Expression] '[' [Expression] ']' |
| 9719 * </pre> |
| 9720 */ |
| 9721 class IndexExpression extends Expression { |
| 9722 /** |
| 9723 * The expression used to compute the object being indexed, or `null` if this
index |
| 9724 * expression is part of a cascade expression. |
| 9725 */ |
| 9726 Expression _target; |
| 9727 |
| 9728 /** |
| 9729 * The period ("..") before a cascaded index expression, or `null` if this ind
ex expression |
| 9730 * is not part of a cascade expression. |
| 9731 */ |
| 9732 Token period; |
| 9733 |
| 9734 /** |
| 9735 * The left square bracket. |
| 9736 */ |
| 9737 Token _leftBracket; |
| 9738 |
| 9739 /** |
| 9740 * The expression used to compute the index. |
| 9741 */ |
| 9742 Expression _index; |
| 9743 |
| 9744 /** |
| 9745 * The right square bracket. |
| 9746 */ |
| 9747 Token _rightBracket; |
| 9748 |
| 9749 /** |
| 9750 * The element associated with the operator based on the static type of the ta
rget, or |
| 9751 * `null` if the AST structure has not been resolved or if the operator could
not be |
| 9752 * resolved. |
| 9753 */ |
| 9754 MethodElement _staticElement; |
| 9755 |
| 9756 /** |
| 9757 * The element associated with the operator based on the propagated type of th
e target, or |
| 9758 * `null` if the AST structure has not been resolved or if the operator could
not be |
| 9759 * resolved. |
| 9760 */ |
| 9761 MethodElement _propagatedElement; |
| 9762 |
| 9763 /** |
| 9764 * If this expression is both in a getter and setter context, the [AuxiliaryEl
ements] will |
| 9765 * be set to hold onto the static and propagated information. The auxiliary el
ement will hold onto |
| 9766 * the elements from the getter context. |
| 9767 */ |
| 9768 AuxiliaryElements auxiliaryElements = null; |
| 9769 |
| 9770 /** |
| 9771 * Initialize a newly created index expression. |
| 9772 * |
| 9773 * @param target the expression used to compute the object being indexed |
| 9774 * @param leftBracket the left square bracket |
| 9775 * @param index the expression used to compute the index |
| 9776 * @param rightBracket the right square bracket |
| 9777 */ |
| 9778 IndexExpression.forTarget(Expression target, Token leftBracket, Expression ind
ex, Token rightBracket) { |
| 9779 this._target = becomeParentOf(target); |
| 9780 this._leftBracket = leftBracket; |
| 9781 this._index = becomeParentOf(index); |
| 9782 this._rightBracket = rightBracket; |
| 9783 } |
| 9784 |
| 9785 /** |
| 9786 * Initialize a newly created index expression. |
| 9787 * |
| 9788 * @param period the period ("..") before a cascaded index expression |
| 9789 * @param leftBracket the left square bracket |
| 9790 * @param index the expression used to compute the index |
| 9791 * @param rightBracket the right square bracket |
| 9792 */ |
| 9793 IndexExpression.forCascade(this.period, Token leftBracket, Expression index, T
oken rightBracket) { |
| 9794 this._leftBracket = leftBracket; |
| 9795 this._index = becomeParentOf(index); |
| 9796 this._rightBracket = rightBracket; |
| 9797 } |
| 9798 |
| 9799 @override |
| 9800 accept(AstVisitor visitor) => visitor.visitIndexExpression(this); |
| 9801 |
| 9802 @override |
| 9803 Token get beginToken { |
| 9804 if (_target != null) { |
| 9805 return _target.beginToken; |
| 9806 } |
| 9807 return period; |
| 9808 } |
| 9809 |
| 9810 /** |
| 9811 * Return the best element available for this operator. If resolution was able
to find a better |
| 9812 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 9813 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 9814 * then `null` will be returned. |
| 9815 * |
| 9816 * @return the best element available for this operator |
| 9817 */ |
| 9818 MethodElement get bestElement { |
| 9819 MethodElement element = propagatedElement; |
| 9820 if (element == null) { |
| 9821 element = staticElement; |
| 9822 } |
| 9823 return element; |
| 9824 } |
| 9825 |
| 9826 @override |
| 9827 Token get endToken => _rightBracket; |
| 9828 |
| 9829 /** |
| 9830 * Return the expression used to compute the index. |
| 9831 * |
| 9832 * @return the expression used to compute the index |
| 9833 */ |
| 9834 Expression get index => _index; |
| 9835 |
| 9836 /** |
| 9837 * Return the left square bracket. |
| 9838 * |
| 9839 * @return the left square bracket |
| 9840 */ |
| 9841 Token get leftBracket => _leftBracket; |
| 9842 |
| 9843 @override |
| 9844 int get precedence => 15; |
| 9845 |
| 9846 /** |
| 9847 * Return the element associated with the operator based on the propagated typ
e of the target, or |
| 9848 * `null` if the AST structure has not been resolved or if the operator could
not be |
| 9849 * resolved. One example of the latter case is an operator that is not defined
for the type of the |
| 9850 * target. |
| 9851 * |
| 9852 * @return the element associated with this operator |
| 9853 */ |
| 9854 MethodElement get propagatedElement => _propagatedElement; |
| 9855 |
| 9856 /** |
| 9857 * Return the expression used to compute the object being indexed. If this ind
ex expression is not |
| 9858 * part of a cascade expression, then this is the same as [getTarget]. If this
index |
| 9859 * expression is part of a cascade expression, then the target expression stor
ed with the cascade |
| 9860 * expression is returned. |
| 9861 * |
| 9862 * @return the expression used to compute the object being indexed |
| 9863 * @see #getTarget() |
| 9864 */ |
| 9865 Expression get realTarget { |
| 9866 if (isCascaded) { |
| 9867 AstNode ancestor = parent; |
| 9868 while (ancestor is! CascadeExpression) { |
| 9869 if (ancestor == null) { |
| 9870 return _target; |
| 9871 } |
| 9872 ancestor = ancestor.parent; |
| 9873 } |
| 9874 return (ancestor as CascadeExpression).target; |
| 9875 } |
| 9876 return _target; |
| 9877 } |
| 9878 |
| 9879 /** |
| 9880 * Return the right square bracket. |
| 9881 * |
| 9882 * @return the right square bracket |
| 9883 */ |
| 9884 Token get rightBracket => _rightBracket; |
| 9885 |
| 9886 /** |
| 9887 * Return the element associated with the operator based on the static type of
the target, or |
| 9888 * `null` if the AST structure has not been resolved or if the operator could
not be |
| 9889 * resolved. One example of the latter case is an operator that is not defined
for the type of the |
| 9890 * target. |
| 9891 * |
| 9892 * @return the element associated with the operator |
| 9893 */ |
| 9894 MethodElement get staticElement => _staticElement; |
| 9895 |
| 9896 /** |
| 9897 * Return the expression used to compute the object being indexed, or `null` i
f this index |
| 9898 * expression is part of a cascade expression. |
| 9899 * |
| 9900 * @return the expression used to compute the object being indexed |
| 9901 * @see #getRealTarget() |
| 9902 */ |
| 9903 Expression get target => _target; |
| 9904 |
| 9905 /** |
| 9906 * Return `true` if this expression is computing a right-hand value. |
| 9907 * |
| 9908 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar
e |
| 9909 * they mutually exclusive. In other words, it is possible for both methods to
return `true` |
| 9910 * when invoked on the same node. |
| 9911 * |
| 9912 * @return `true` if this expression is in a context where the operator '[]' w
ill be invoked |
| 9913 */ |
| 9914 bool inGetterContext() { |
| 9915 AstNode parent = this.parent; |
| 9916 if (parent is AssignmentExpression) { |
| 9917 AssignmentExpression assignment = parent; |
| 9918 if (identical(assignment.leftHandSide, this) && assignment.operator.type =
= TokenType.EQ) { |
| 9919 return false; |
| 9920 } |
| 9921 } |
| 9922 return true; |
| 9923 } |
| 9924 |
| 9925 /** |
| 9926 * Return `true` if this expression is computing a left-hand value. |
| 9927 * |
| 9928 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar
e |
| 9929 * they mutually exclusive. In other words, it is possible for both methods to
return `true` |
| 9930 * when invoked on the same node. |
| 9931 * |
| 9932 * @return `true` if this expression is in a context where the operator '[]='
will be |
| 9933 * invoked |
| 9934 */ |
| 9935 bool inSetterContext() { |
| 9936 AstNode parent = this.parent; |
| 9937 if (parent is PrefixExpression) { |
| 9938 return parent.operator.type.isIncrementOperator; |
| 9939 } else if (parent is PostfixExpression) { |
| 9940 return true; |
| 9941 } else if (parent is AssignmentExpression) { |
| 9942 return identical(parent.leftHandSide, this); |
| 9943 } |
| 9944 return false; |
| 9945 } |
| 9946 |
| 9947 @override |
| 9948 bool get isAssignable => true; |
| 9949 |
| 9950 /** |
| 9951 * Return `true` if this expression is cascaded. If it is, then the target of
this |
| 9952 * expression is not stored locally but is stored in the nearest ancestor that
is a |
| 9953 * [CascadeExpression]. |
| 9954 * |
| 9955 * @return `true` if this expression is cascaded |
| 9956 */ |
| 9957 bool get isCascaded => period != null; |
| 9958 |
| 9959 /** |
| 9960 * Set the expression used to compute the index to the given expression. |
| 9961 * |
| 9962 * @param expression the expression used to compute the index |
| 9963 */ |
| 9964 void set index(Expression expression) { |
| 9965 _index = becomeParentOf(expression); |
| 9966 } |
| 9967 |
| 9968 /** |
| 9969 * Set the left square bracket to the given token. |
| 9970 * |
| 9971 * @param bracket the left square bracket |
| 9972 */ |
| 9973 void set leftBracket(Token bracket) { |
| 9974 _leftBracket = bracket; |
| 9975 } |
| 9976 |
| 9977 /** |
| 9978 * Set the element associated with the operator based on the propagated type o
f the target to the |
| 9979 * given element. |
| 9980 * |
| 9981 * @param element the element to be associated with this operator |
| 9982 */ |
| 9983 void set propagatedElement(MethodElement element) { |
| 9984 _propagatedElement = element; |
| 9985 } |
| 9986 |
| 9987 /** |
| 9988 * Set the right square bracket to the given token. |
| 9989 * |
| 9990 * @param bracket the right square bracket |
| 9991 */ |
| 9992 void set rightBracket(Token bracket) { |
| 9993 _rightBracket = bracket; |
| 9994 } |
| 9995 |
| 9996 /** |
| 9997 * Set the element associated with the operator based on the static type of th
e target to the |
| 9998 * given element. |
| 9999 * |
| 10000 * @param element the static element to be associated with the operator |
| 10001 */ |
| 10002 void set staticElement(MethodElement element) { |
| 10003 _staticElement = element; |
| 10004 } |
| 10005 |
| 10006 /** |
| 10007 * Set the expression used to compute the object being indexed to the given ex
pression. |
| 10008 * |
| 10009 * @param expression the expression used to compute the object being indexed |
| 10010 */ |
| 10011 void set target(Expression expression) { |
| 10012 _target = becomeParentOf(expression); |
| 10013 } |
| 10014 |
| 10015 @override |
| 10016 void visitChildren(AstVisitor visitor) { |
| 10017 safelyVisitChild(_target, visitor); |
| 10018 safelyVisitChild(_index, visitor); |
| 10019 } |
| 10020 |
| 10021 /** |
| 10022 * If the AST structure has been resolved, and the function being invoked is k
nown based on |
| 10023 * propagated type information, then return the parameter element representing
the parameter to |
| 10024 * which the value of the index expression will be bound. Otherwise, return `n
ull`. |
| 10025 * |
| 10026 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 10027 * |
| 10028 * @return the parameter element representing the parameter to which the value
of the index |
| 10029 * expression will be bound |
| 10030 */ |
| 10031 ParameterElement get propagatedParameterElementForIndex { |
| 10032 if (_propagatedElement == null) { |
| 10033 return null; |
| 10034 } |
| 10035 List<ParameterElement> parameters = _propagatedElement.parameters; |
| 10036 if (parameters.length < 1) { |
| 10037 return null; |
| 10038 } |
| 10039 return parameters[0]; |
| 10040 } |
| 10041 |
| 10042 /** |
| 10043 * If the AST structure has been resolved, and the function being invoked is k
nown based on static |
| 10044 * type information, then return the parameter element representing the parame
ter to which the |
| 10045 * value of the index expression will be bound. Otherwise, return `null`. |
| 10046 * |
| 10047 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 10048 * |
| 10049 * @return the parameter element representing the parameter to which the value
of the index |
| 10050 * expression will be bound |
| 10051 */ |
| 10052 ParameterElement get staticParameterElementForIndex { |
| 10053 if (_staticElement == null) { |
| 10054 return null; |
| 10055 } |
| 10056 List<ParameterElement> parameters = _staticElement.parameters; |
| 10057 if (parameters.length < 1) { |
| 10058 return null; |
| 10059 } |
| 10060 return parameters[0]; |
| 10061 } |
| 10062 } |
| 10063 |
| 10064 /** |
| 10065 * Instances of the class `InstanceCreationExpression` represent an instance cre
ation |
| 10066 * expression. |
| 10067 * |
| 10068 * <pre> |
| 10069 * newExpression ::= |
| 10070 * ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList] |
| 10071 * </pre> |
| 10072 */ |
| 10073 class InstanceCreationExpression extends Expression { |
| 10074 /** |
| 10075 * The keyword used to indicate how an object should be created. |
| 10076 */ |
| 10077 Token keyword; |
| 10078 |
| 10079 /** |
| 10080 * The name of the constructor to be invoked. |
| 10081 */ |
| 10082 ConstructorName _constructorName; |
| 10083 |
| 10084 /** |
| 10085 * The list of arguments to the constructor. |
| 10086 */ |
| 10087 ArgumentList _argumentList; |
| 10088 |
| 10089 /** |
| 10090 * The element associated with the constructor based on static type informatio
n, or `null` |
| 10091 * if the AST structure has not been resolved or if the constructor could not
be resolved. |
| 10092 */ |
| 10093 ConstructorElement staticElement; |
| 10094 |
| 10095 /** |
| 10096 * The result of evaluating this expression, if it is constant. |
| 10097 */ |
| 10098 EvaluationResultImpl _result; |
| 10099 |
| 10100 /** |
| 10101 * Initialize a newly created instance creation expression. |
| 10102 * |
| 10103 * @param keyword the keyword used to indicate how an object should be created |
| 10104 * @param constructorName the name of the constructor to be invoked |
| 10105 * @param argumentList the list of arguments to the constructor |
| 10106 */ |
| 10107 InstanceCreationExpression(this.keyword, ConstructorName constructorName, Argu
mentList argumentList) { |
| 10108 this._constructorName = becomeParentOf(constructorName); |
| 10109 this._argumentList = becomeParentOf(argumentList); |
| 10110 } |
| 10111 |
| 10112 @override |
| 10113 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this); |
| 10114 |
| 10115 /** |
| 10116 * Return the list of arguments to the constructor. |
| 10117 * |
| 10118 * @return the list of arguments to the constructor |
| 10119 */ |
| 10120 ArgumentList get argumentList => _argumentList; |
| 10121 |
| 10122 @override |
| 10123 Token get beginToken => keyword; |
| 10124 |
| 10125 /** |
| 10126 * Return the name of the constructor to be invoked. |
| 10127 * |
| 10128 * @return the name of the constructor to be invoked |
| 10129 */ |
| 10130 ConstructorName get constructorName => _constructorName; |
| 10131 |
| 10132 @override |
| 10133 Token get endToken => _argumentList.endToken; |
| 10134 |
| 10135 /** |
| 10136 * Return the result of evaluating this constant as a compile-time constant ex
pression, or |
| 10137 * `null` if this variable is not a 'const' expression or an error prevented t
he result from |
| 10138 * being computed. |
| 10139 * |
| 10140 * @return the result of evaluating this constant |
| 10141 */ |
| 10142 EvaluationResultImpl get evaluationResult => _result; |
| 10143 |
| 10144 @override |
| 10145 int get precedence => 15; |
| 10146 |
| 10147 /** |
| 10148 * Return `true` if this creation expression is used to invoke a constant cons
tructor. |
| 10149 * |
| 10150 * @return `true` if this creation expression is used to invoke a constant con
structor |
| 10151 */ |
| 10152 bool get isConst => keyword is KeywordToken && (keyword as KeywordToken).keywo
rd == Keyword.CONST; |
| 10153 |
| 10154 /** |
| 10155 * Set the list of arguments to the constructor to the given list. |
| 10156 * |
| 10157 * @param argumentList the list of arguments to the constructor |
| 10158 */ |
| 10159 void set argumentList(ArgumentList argumentList) { |
| 10160 this._argumentList = becomeParentOf(argumentList); |
| 10161 } |
| 10162 |
| 10163 /** |
| 10164 * Set the name of the constructor to be invoked to the given name. |
| 10165 * |
| 10166 * @param constructorName the name of the constructor to be invoked |
| 10167 */ |
| 10168 void set constructorName(ConstructorName constructorName) { |
| 10169 this._constructorName = becomeParentOf(constructorName); |
| 10170 } |
| 10171 |
| 10172 /** |
| 10173 * Set the result of evaluating this expression as a compile-time constant exp
ression to the given |
| 10174 * result. |
| 10175 * |
| 10176 * @param result the result of evaluating this expression |
| 10177 */ |
| 10178 void set evaluationResult(EvaluationResultImpl result) { |
| 10179 this._result = result; |
| 10180 } |
| 10181 |
| 10182 @override |
| 10183 void visitChildren(AstVisitor visitor) { |
| 10184 safelyVisitChild(_constructorName, visitor); |
| 10185 safelyVisitChild(_argumentList, visitor); |
| 10186 } |
| 10187 } |
| 10188 |
| 10189 /** |
| 10190 * Instances of the class `IntegerLiteral` represent an integer literal expressi
on. |
| 10191 * |
| 10192 * <pre> |
| 10193 * integerLiteral ::= |
| 10194 * decimalIntegerLiteral |
| 10195 * | hexidecimalIntegerLiteral |
| 10196 * |
| 10197 * decimalIntegerLiteral ::= |
| 10198 * decimalDigit+ |
| 10199 * |
| 10200 * hexidecimalIntegerLiteral ::= |
| 10201 * '0x' hexidecimalDigit+ |
| 10202 * | '0X' hexidecimalDigit+ |
| 10203 * </pre> |
| 10204 */ |
| 10205 class IntegerLiteral extends Literal { |
| 10206 /** |
| 10207 * The token representing the literal. |
| 10208 */ |
| 10209 Token literal; |
| 10210 |
| 10211 /** |
| 10212 * The value of the literal. |
| 10213 */ |
| 10214 int value = 0; |
| 10215 |
| 10216 /** |
| 10217 * Initialize a newly created integer literal. |
| 10218 * |
| 10219 * @param literal the token representing the literal |
| 10220 * @param value the value of the literal |
| 10221 */ |
| 10222 IntegerLiteral(this.literal, this.value); |
| 10223 |
| 10224 @override |
| 10225 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this); |
| 10226 |
| 10227 @override |
| 10228 Token get beginToken => literal; |
| 10229 |
| 10230 @override |
| 10231 Token get endToken => literal; |
| 10232 |
| 10233 @override |
| 10234 void visitChildren(AstVisitor visitor) { |
| 10235 } |
| 10236 } |
| 10237 |
| 10238 /** |
| 10239 * The abstract class `InterpolationElement` defines the behavior common to elem
ents within a |
| 10240 * [StringInterpolation]. |
| 10241 * |
| 10242 * <pre> |
| 10243 * interpolationElement ::= |
| 10244 * [InterpolationExpression] |
| 10245 * | [InterpolationString] |
| 10246 * </pre> |
| 10247 */ |
| 10248 abstract class InterpolationElement extends AstNode { |
| 10249 } |
| 10250 |
| 10251 /** |
| 10252 * Instances of the class `InterpolationExpression` represent an expression embe
dded in a |
| 10253 * string interpolation. |
| 10254 * |
| 10255 * <pre> |
| 10256 * interpolationExpression ::= |
| 10257 * '$' [SimpleIdentifier] |
| 10258 * | '$' '{' [Expression] '}' |
| 10259 * </pre> |
| 10260 */ |
| 10261 class InterpolationExpression extends InterpolationElement { |
| 10262 /** |
| 10263 * The token used to introduce the interpolation expression; either '$' if the
expression is a |
| 10264 * simple identifier or '${' if the expression is a full expression. |
| 10265 */ |
| 10266 Token leftBracket; |
| 10267 |
| 10268 /** |
| 10269 * The expression to be evaluated for the value to be converted into a string. |
| 10270 */ |
| 10271 Expression _expression; |
| 10272 |
| 10273 /** |
| 10274 * The right curly bracket, or `null` if the expression is an identifier witho
ut brackets. |
| 10275 */ |
| 10276 Token rightBracket; |
| 10277 |
| 10278 /** |
| 10279 * Initialize a newly created interpolation expression. |
| 10280 * |
| 10281 * @param leftBracket the left curly bracket |
| 10282 * @param expression the expression to be evaluated for the value to be conver
ted into a string |
| 10283 * @param rightBracket the right curly bracket |
| 10284 */ |
| 10285 InterpolationExpression(this.leftBracket, Expression expression, this.rightBra
cket) { |
| 10286 this._expression = becomeParentOf(expression); |
| 10287 } |
| 10288 |
| 10289 @override |
| 10290 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this); |
| 10291 |
| 10292 @override |
| 10293 Token get beginToken => leftBracket; |
| 10294 |
| 10295 @override |
| 10296 Token get endToken { |
| 10297 if (rightBracket != null) { |
| 10298 return rightBracket; |
| 10299 } |
| 10300 return _expression.endToken; |
| 10301 } |
| 10302 |
| 10303 /** |
| 10304 * Return the expression to be evaluated for the value to be converted into a
string. |
| 10305 * |
| 10306 * @return the expression to be evaluated for the value to be converted into a
string |
| 10307 */ |
| 10308 Expression get expression => _expression; |
| 10309 |
| 10310 /** |
| 10311 * Set the expression to be evaluated for the value to be converted into a str
ing to the given |
| 10312 * expression. |
| 10313 * |
| 10314 * @param expression the expression to be evaluated for the value to be conver
ted into a string |
| 10315 */ |
| 10316 void set expression(Expression expression) { |
| 10317 this._expression = becomeParentOf(expression); |
| 10318 } |
| 10319 |
| 10320 @override |
| 10321 void visitChildren(AstVisitor visitor) { |
| 10322 safelyVisitChild(_expression, visitor); |
| 10323 } |
| 10324 } |
| 10325 |
| 10326 /** |
| 10327 * Instances of the class `InterpolationString` represent a non-empty substring
of an |
| 10328 * interpolated string. |
| 10329 * |
| 10330 * <pre> |
| 10331 * interpolationString ::= |
| 10332 * characters |
| 10333 * </pre> |
| 10334 */ |
| 10335 class InterpolationString extends InterpolationElement { |
| 10336 /** |
| 10337 * The characters that will be added to the string. |
| 10338 */ |
| 10339 Token _contents; |
| 10340 |
| 10341 /** |
| 10342 * The value of the literal. |
| 10343 */ |
| 10344 String _value; |
| 10345 |
| 10346 /** |
| 10347 * Initialize a newly created string of characters that are part of a string i
nterpolation. |
| 10348 * |
| 10349 * @param the characters that will be added to the string |
| 10350 * @param value the value of the literal |
| 10351 */ |
| 10352 InterpolationString(Token contents, String value) { |
| 10353 this._contents = contents; |
| 10354 this._value = value; |
| 10355 } |
| 10356 |
| 10357 @override |
| 10358 accept(AstVisitor visitor) => visitor.visitInterpolationString(this); |
| 10359 |
| 10360 @override |
| 10361 Token get beginToken => _contents; |
| 10362 |
| 10363 /** |
| 10364 * Return the characters that will be added to the string. |
| 10365 * |
| 10366 * @return the characters that will be added to the string |
| 10367 */ |
| 10368 Token get contents => _contents; |
| 10369 |
| 10370 @override |
| 10371 Token get endToken => _contents; |
| 10372 |
| 10373 /** |
| 10374 * Return the value of the literal. |
| 10375 * |
| 10376 * @return the value of the literal |
| 10377 */ |
| 10378 String get value => _value; |
| 10379 |
| 10380 /** |
| 10381 * Set the characters that will be added to the string to those in the given s
tring. |
| 10382 * |
| 10383 * @param string the characters that will be added to the string |
| 10384 */ |
| 10385 void set contents(Token string) { |
| 10386 _contents = string; |
| 10387 } |
| 10388 |
| 10389 /** |
| 10390 * Set the value of the literal to the given string. |
| 10391 * |
| 10392 * @param string the value of the literal |
| 10393 */ |
| 10394 void set value(String string) { |
| 10395 _value = string; |
| 10396 } |
| 10397 |
| 10398 @override |
| 10399 void visitChildren(AstVisitor visitor) { |
| 10400 } |
| 10401 } |
| 10402 |
| 10403 /** |
| 10404 * Instances of the class `IsExpression` represent an is expression. |
| 10405 * |
| 10406 * <pre> |
| 10407 * isExpression ::= |
| 10408 * [Expression] 'is' '!'? [TypeName] |
| 10409 * </pre> |
| 10410 */ |
| 10411 class IsExpression extends Expression { |
| 10412 /** |
| 10413 * The expression used to compute the value whose type is being tested. |
| 10414 */ |
| 10415 Expression _expression; |
| 10416 |
| 10417 /** |
| 10418 * The is operator. |
| 10419 */ |
| 10420 Token isOperator; |
| 10421 |
| 10422 /** |
| 10423 * The not operator, or `null` if the sense of the test is not negated. |
| 10424 */ |
| 10425 Token notOperator; |
| 10426 |
| 10427 /** |
| 10428 * The name of the type being tested for. |
| 10429 */ |
| 10430 TypeName _type; |
| 10431 |
| 10432 /** |
| 10433 * Initialize a newly created is expression. |
| 10434 * |
| 10435 * @param expression the expression used to compute the value whose type is be
ing tested |
| 10436 * @param isOperator the is operator |
| 10437 * @param notOperator the not operator, or `null` if the sense of the test is
not negated |
| 10438 * @param type the name of the type being tested for |
| 10439 */ |
| 10440 IsExpression(Expression expression, this.isOperator, this.notOperator, TypeNam
e type) { |
| 10441 this._expression = becomeParentOf(expression); |
| 10442 this._type = becomeParentOf(type); |
| 10443 } |
| 10444 |
| 10445 @override |
| 10446 accept(AstVisitor visitor) => visitor.visitIsExpression(this); |
| 10447 |
| 10448 @override |
| 10449 Token get beginToken => _expression.beginToken; |
| 10450 |
| 10451 @override |
| 10452 Token get endToken => _type.endToken; |
| 10453 |
| 10454 /** |
| 10455 * Return the expression used to compute the value whose type is being tested. |
| 10456 * |
| 10457 * @return the expression used to compute the value whose type is being tested |
| 10458 */ |
| 10459 Expression get expression => _expression; |
| 10460 |
| 10461 @override |
| 10462 int get precedence => 7; |
| 10463 |
| 10464 /** |
| 10465 * Return the name of the type being tested for. |
| 10466 * |
| 10467 * @return the name of the type being tested for |
| 10468 */ |
| 10469 TypeName get type => _type; |
| 10470 |
| 10471 /** |
| 10472 * Set the expression used to compute the value whose type is being tested to
the given |
| 10473 * expression. |
| 10474 * |
| 10475 * @param expression the expression used to compute the value whose type is be
ing tested |
| 10476 */ |
| 10477 void set expression(Expression expression) { |
| 10478 this._expression = becomeParentOf(expression); |
| 10479 } |
| 10480 |
| 10481 /** |
| 10482 * Set the name of the type being tested for to the given name. |
| 10483 * |
| 10484 * @param name the name of the type being tested for |
| 10485 */ |
| 10486 void set type(TypeName name) { |
| 10487 this._type = becomeParentOf(name); |
| 10488 } |
| 10489 |
| 10490 @override |
| 10491 void visitChildren(AstVisitor visitor) { |
| 10492 safelyVisitChild(_expression, visitor); |
| 10493 safelyVisitChild(_type, visitor); |
| 10494 } |
| 10495 } |
| 10496 |
| 10497 /** |
| 10498 * Instances of the class `Label` represent a label. |
| 10499 * |
| 10500 * <pre> |
| 10501 * label ::= |
| 10502 * [SimpleIdentifier] ':' |
| 10503 * </pre> |
| 10504 */ |
| 10505 class Label extends AstNode { |
| 10506 /** |
| 10507 * The label being associated with the statement. |
| 10508 */ |
| 10509 SimpleIdentifier _label; |
| 10510 |
| 10511 /** |
| 10512 * The colon that separates the label from the statement. |
| 10513 */ |
| 10514 Token colon; |
| 10515 |
| 10516 /** |
| 10517 * Initialize a newly created label. |
| 10518 * |
| 10519 * @param label the label being applied |
| 10520 * @param colon the colon that separates the label from whatever follows |
| 10521 */ |
| 10522 Label(SimpleIdentifier label, this.colon) { |
| 10523 this._label = becomeParentOf(label); |
| 10524 } |
| 10525 |
| 10526 @override |
| 10527 accept(AstVisitor visitor) => visitor.visitLabel(this); |
| 10528 |
| 10529 @override |
| 10530 Token get beginToken => _label.beginToken; |
| 10531 |
| 10532 @override |
| 10533 Token get endToken => colon; |
| 10534 |
| 10535 /** |
| 10536 * Return the label being associated with the statement. |
| 10537 * |
| 10538 * @return the label being associated with the statement |
| 10539 */ |
| 10540 SimpleIdentifier get label => _label; |
| 10541 |
| 10542 /** |
| 10543 * Set the label being associated with the statement to the given label. |
| 10544 * |
| 10545 * @param label the label being associated with the statement |
| 10546 */ |
| 10547 void set label(SimpleIdentifier label) { |
| 10548 this._label = becomeParentOf(label); |
| 10549 } |
| 10550 |
| 10551 @override |
| 10552 void visitChildren(AstVisitor visitor) { |
| 10553 safelyVisitChild(_label, visitor); |
| 10554 } |
| 10555 } |
| 10556 |
| 10557 /** |
| 10558 * Instances of the class `LabeledStatement` represent a statement that has a la
bel associated |
| 10559 * with them. |
| 10560 * |
| 10561 * <pre> |
| 10562 * labeledStatement ::= |
| 10563 * [Label]+ [Statement] |
| 10564 * </pre> |
| 10565 */ |
| 10566 class LabeledStatement extends Statement { |
| 10567 /** |
| 10568 * The labels being associated with the statement. |
| 10569 */ |
| 10570 NodeList<Label> _labels; |
| 10571 |
| 10572 /** |
| 10573 * The statement with which the labels are being associated. |
| 10574 */ |
| 10575 Statement _statement; |
| 10576 |
| 10577 /** |
| 10578 * Initialize a newly created labeled statement. |
| 10579 * |
| 10580 * @param labels the labels being associated with the statement |
| 10581 * @param statement the statement with which the labels are being associated |
| 10582 */ |
| 10583 LabeledStatement(List<Label> labels, Statement statement) { |
| 10584 this._labels = new NodeList<Label>(this); |
| 10585 this._labels.addAll(labels); |
| 10586 this._statement = becomeParentOf(statement); |
| 10587 } |
| 10588 |
| 10589 @override |
| 10590 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this); |
| 10591 |
| 10592 @override |
| 10593 Token get beginToken { |
| 10594 if (!_labels.isEmpty) { |
| 10595 return _labels.beginToken; |
| 10596 } |
| 10597 return _statement.beginToken; |
| 10598 } |
| 10599 |
| 10600 @override |
| 10601 Token get endToken => _statement.endToken; |
| 10602 |
| 10603 /** |
| 10604 * Return the labels being associated with the statement. |
| 10605 * |
| 10606 * @return the labels being associated with the statement |
| 10607 */ |
| 10608 NodeList<Label> get labels => _labels; |
| 10609 |
| 10610 /** |
| 10611 * Return the statement with which the labels are being associated. |
| 10612 * |
| 10613 * @return the statement with which the labels are being associated |
| 10614 */ |
| 10615 Statement get statement => _statement; |
| 10616 |
| 10617 /** |
| 10618 * Set the statement with which the labels are being associated to the given s
tatement. |
| 10619 * |
| 10620 * @param statement the statement with which the labels are being associated |
| 10621 */ |
| 10622 void set statement(Statement statement) { |
| 10623 this._statement = becomeParentOf(statement); |
| 10624 } |
| 10625 |
| 10626 @override |
| 10627 void visitChildren(AstVisitor visitor) { |
| 10628 _labels.accept(visitor); |
| 10629 safelyVisitChild(_statement, visitor); |
| 10630 } |
| 10631 } |
| 10632 |
| 10633 /** |
| 10634 * Instances of the class `LibraryDirective` represent a library directive. |
| 10635 * |
| 10636 * <pre> |
| 10637 * libraryDirective ::= |
| 10638 * [Annotation] 'library' [Identifier] ';' |
| 10639 * </pre> |
| 10640 */ |
| 10641 class LibraryDirective extends Directive { |
| 10642 /** |
| 10643 * The token representing the 'library' token. |
| 10644 */ |
| 10645 Token libraryToken; |
| 10646 |
| 10647 /** |
| 10648 * The name of the library being defined. |
| 10649 */ |
| 10650 LibraryIdentifier _name; |
| 10651 |
| 10652 /** |
| 10653 * The semicolon terminating the directive. |
| 10654 */ |
| 10655 Token semicolon; |
| 10656 |
| 10657 /** |
| 10658 * Initialize a newly created library directive. |
| 10659 * |
| 10660 * @param comment the documentation comment associated with this directive |
| 10661 * @param metadata the annotations associated with the directive |
| 10662 * @param libraryToken the token representing the 'library' token |
| 10663 * @param name the name of the library being defined |
| 10664 * @param semicolon the semicolon terminating the directive |
| 10665 */ |
| 10666 LibraryDirective(Comment comment, List<Annotation> metadata, this.libraryToken
, LibraryIdentifier name, this.semicolon) : super(comment, metadata) { |
| 10667 this._name = becomeParentOf(name); |
| 10668 } |
| 10669 |
| 10670 @override |
| 10671 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this); |
| 10672 |
| 10673 @override |
| 10674 Token get endToken => semicolon; |
| 10675 |
| 10676 @override |
| 10677 Token get keyword => libraryToken; |
| 10678 |
| 10679 /** |
| 10680 * Return the name of the library being defined. |
| 10681 * |
| 10682 * @return the name of the library being defined |
| 10683 */ |
| 10684 LibraryIdentifier get name => _name; |
| 10685 |
| 10686 /** |
| 10687 * Set the name of the library being defined to the given name. |
| 10688 * |
| 10689 * @param name the name of the library being defined |
| 10690 */ |
| 10691 void set name(LibraryIdentifier name) { |
| 10692 this._name = becomeParentOf(name); |
| 10693 } |
| 10694 |
| 10695 @override |
| 10696 void visitChildren(AstVisitor visitor) { |
| 10697 super.visitChildren(visitor); |
| 10698 safelyVisitChild(_name, visitor); |
| 10699 } |
| 10700 |
| 10701 @override |
| 10702 Token get firstTokenAfterCommentAndMetadata => libraryToken; |
| 10703 } |
| 10704 |
| 10705 /** |
| 10706 * Instances of the class `LibraryIdentifier` represent the identifier for a lib
rary. |
| 10707 * |
| 10708 * <pre> |
| 10709 * libraryIdentifier ::= |
| 10710 * [SimpleIdentifier] ('.' [SimpleIdentifier])* |
| 10711 * </pre> |
| 10712 */ |
| 10713 class LibraryIdentifier extends Identifier { |
| 10714 /** |
| 10715 * The components of the identifier. |
| 10716 */ |
| 10717 NodeList<SimpleIdentifier> _components; |
| 10718 |
| 10719 /** |
| 10720 * Initialize a newly created prefixed identifier. |
| 10721 * |
| 10722 * @param components the components of the identifier |
| 10723 */ |
| 10724 LibraryIdentifier(List<SimpleIdentifier> components) { |
| 10725 this._components = new NodeList<SimpleIdentifier>(this); |
| 10726 this._components.addAll(components); |
| 10727 } |
| 10728 |
| 10729 @override |
| 10730 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this); |
| 10731 |
| 10732 @override |
| 10733 Token get beginToken => _components.beginToken; |
| 10734 |
| 10735 @override |
| 10736 Element get bestElement => staticElement; |
| 10737 |
| 10738 /** |
| 10739 * Return the components of the identifier. |
| 10740 * |
| 10741 * @return the components of the identifier |
| 10742 */ |
| 10743 NodeList<SimpleIdentifier> get components => _components; |
| 10744 |
| 10745 @override |
| 10746 Token get endToken => _components.endToken; |
| 10747 |
| 10748 @override |
| 10749 String get name { |
| 10750 JavaStringBuilder builder = new JavaStringBuilder(); |
| 10751 bool needsPeriod = false; |
| 10752 for (SimpleIdentifier identifier in _components) { |
| 10753 if (needsPeriod) { |
| 10754 builder.append("."); |
| 10755 } else { |
| 10756 needsPeriod = true; |
| 10757 } |
| 10758 builder.append(identifier.name); |
| 10759 } |
| 10760 return builder.toString(); |
| 10761 } |
| 10762 |
| 10763 @override |
| 10764 int get precedence => 15; |
| 10765 |
| 10766 @override |
| 10767 Element get propagatedElement => null; |
| 10768 |
| 10769 @override |
| 10770 Element get staticElement => null; |
| 10771 |
| 10772 @override |
| 10773 void visitChildren(AstVisitor visitor) { |
| 10774 _components.accept(visitor); |
| 10775 } |
| 10776 } |
| 10777 |
| 10778 /** |
| 10779 * Instances of the class `ListLiteral` represent a list literal. |
| 10780 * |
| 10781 * <pre> |
| 10782 * listLiteral ::= |
| 10783 * 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']' |
| 10784 * </pre> |
| 10785 */ |
| 10786 class ListLiteral extends TypedLiteral { |
| 10787 /** |
| 10788 * The left square bracket. |
| 10789 */ |
| 10790 Token _leftBracket; |
| 10791 |
| 10792 /** |
| 10793 * The expressions used to compute the elements of the list. |
| 10794 */ |
| 10795 NodeList<Expression> _elements; |
| 10796 |
| 10797 /** |
| 10798 * The right square bracket. |
| 10799 */ |
| 10800 Token _rightBracket; |
| 10801 |
| 10802 /** |
| 10803 * Initialize a newly created list literal. |
| 10804 * |
| 10805 * @param constKeyword the token representing the 'const' keyword |
| 10806 * @param typeArguments the type argument associated with this literal, or `nu
ll` if no type |
| 10807 * arguments were declared |
| 10808 * @param leftBracket the left square bracket |
| 10809 * @param elements the expressions used to compute the elements of the list |
| 10810 * @param rightBracket the right square bracket |
| 10811 */ |
| 10812 ListLiteral(Token constKeyword, TypeArgumentList typeArguments, Token leftBrac
ket, List<Expression> elements, Token rightBracket) : super(constKeyword, typeAr
guments) { |
| 10813 this._elements = new NodeList<Expression>(this); |
| 10814 this._leftBracket = leftBracket; |
| 10815 this._elements.addAll(elements); |
| 10816 this._rightBracket = rightBracket; |
| 10817 } |
| 10818 |
| 10819 @override |
| 10820 accept(AstVisitor visitor) => visitor.visitListLiteral(this); |
| 10821 |
| 10822 @override |
| 10823 Token get beginToken { |
| 10824 Token token = constKeyword; |
| 10825 if (token != null) { |
| 10826 return token; |
| 10827 } |
| 10828 TypeArgumentList typeArguments = this.typeArguments; |
| 10829 if (typeArguments != null) { |
| 10830 return typeArguments.beginToken; |
| 10831 } |
| 10832 return _leftBracket; |
| 10833 } |
| 10834 |
| 10835 /** |
| 10836 * Return the expressions used to compute the elements of the list. |
| 10837 * |
| 10838 * @return the expressions used to compute the elements of the list |
| 10839 */ |
| 10840 NodeList<Expression> get elements => _elements; |
| 10841 |
| 10842 @override |
| 10843 Token get endToken => _rightBracket; |
| 10844 |
| 10845 /** |
| 10846 * Return the left square bracket. |
| 10847 * |
| 10848 * @return the left square bracket |
| 10849 */ |
| 10850 Token get leftBracket => _leftBracket; |
| 10851 |
| 10852 /** |
| 10853 * Return the right square bracket. |
| 10854 * |
| 10855 * @return the right square bracket |
| 10856 */ |
| 10857 Token get rightBracket => _rightBracket; |
| 10858 |
| 10859 /** |
| 10860 * Set the left square bracket to the given token. |
| 10861 * |
| 10862 * @param bracket the left square bracket |
| 10863 */ |
| 10864 void set leftBracket(Token bracket) { |
| 10865 _leftBracket = bracket; |
| 10866 } |
| 10867 |
| 10868 /** |
| 10869 * Set the right square bracket to the given token. |
| 10870 * |
| 10871 * @param bracket the right square bracket |
| 10872 */ |
| 10873 void set rightBracket(Token bracket) { |
| 10874 _rightBracket = bracket; |
| 10875 } |
| 10876 |
| 10877 @override |
| 10878 void visitChildren(AstVisitor visitor) { |
| 10879 super.visitChildren(visitor); |
| 10880 _elements.accept(visitor); |
| 10881 } |
| 10882 } |
| 10883 |
| 10884 /** |
| 10885 * The abstract class `Literal` defines the behavior common to nodes that repres
ent a literal |
| 10886 * expression. |
| 10887 * |
| 10888 * <pre> |
| 10889 * literal ::= |
| 10890 * [BooleanLiteral] |
| 10891 * | [DoubleLiteral] |
| 10892 * | [IntegerLiteral] |
| 10893 * | [ListLiteral] |
| 10894 * | [MapLiteral] |
| 10895 * | [NullLiteral] |
| 10896 * | [StringLiteral] |
| 10897 * </pre> |
| 10898 */ |
| 10899 abstract class Literal extends Expression { |
| 10900 @override |
| 10901 int get precedence => 16; |
| 10902 } |
| 10903 |
| 10904 /** |
| 10905 * Instances of the class `MapLiteral` represent a literal map. |
| 10906 * |
| 10907 * <pre> |
| 10908 * mapLiteral ::= |
| 10909 * 'const'? ('<' [TypeName] (',' [TypeName])* '>')? '{' ([MapLiteralEntry] (
',' [MapLiteralEntry])* ','?)? '}' |
| 10910 * </pre> |
| 10911 */ |
| 10912 class MapLiteral extends TypedLiteral { |
| 10913 /** |
| 10914 * The left curly bracket. |
| 10915 */ |
| 10916 Token _leftBracket; |
| 10917 |
| 10918 /** |
| 10919 * The entries in the map. |
| 10920 */ |
| 10921 NodeList<MapLiteralEntry> _entries; |
| 10922 |
| 10923 /** |
| 10924 * The right curly bracket. |
| 10925 */ |
| 10926 Token _rightBracket; |
| 10927 |
| 10928 /** |
| 10929 * Initialize a newly created map literal. |
| 10930 * |
| 10931 * @param constKeyword the token representing the 'const' keyword |
| 10932 * @param typeArguments the type argument associated with this literal, or `nu
ll` if no type |
| 10933 * arguments were declared |
| 10934 * @param leftBracket the left curly bracket |
| 10935 * @param entries the entries in the map |
| 10936 * @param rightBracket the right curly bracket |
| 10937 */ |
| 10938 MapLiteral(Token constKeyword, TypeArgumentList typeArguments, Token leftBrack
et, List<MapLiteralEntry> entries, Token rightBracket) : super(constKeyword, typ
eArguments) { |
| 10939 this._entries = new NodeList<MapLiteralEntry>(this); |
| 10940 this._leftBracket = leftBracket; |
| 10941 this._entries.addAll(entries); |
| 10942 this._rightBracket = rightBracket; |
| 10943 } |
| 10944 |
| 10945 @override |
| 10946 accept(AstVisitor visitor) => visitor.visitMapLiteral(this); |
| 10947 |
| 10948 @override |
| 10949 Token get beginToken { |
| 10950 Token token = constKeyword; |
| 10951 if (token != null) { |
| 10952 return token; |
| 10953 } |
| 10954 TypeArgumentList typeArguments = this.typeArguments; |
| 10955 if (typeArguments != null) { |
| 10956 return typeArguments.beginToken; |
| 10957 } |
| 10958 return _leftBracket; |
| 10959 } |
| 10960 |
| 10961 @override |
| 10962 Token get endToken => _rightBracket; |
| 10963 |
| 10964 /** |
| 10965 * Return the entries in the map. |
| 10966 * |
| 10967 * @return the entries in the map |
| 10968 */ |
| 10969 NodeList<MapLiteralEntry> get entries => _entries; |
| 10970 |
| 10971 /** |
| 10972 * Return the left curly bracket. |
| 10973 * |
| 10974 * @return the left curly bracket |
| 10975 */ |
| 10976 Token get leftBracket => _leftBracket; |
| 10977 |
| 10978 /** |
| 10979 * Return the right curly bracket. |
| 10980 * |
| 10981 * @return the right curly bracket |
| 10982 */ |
| 10983 Token get rightBracket => _rightBracket; |
| 10984 |
| 10985 /** |
| 10986 * Set the left curly bracket to the given token. |
| 10987 * |
| 10988 * @param bracket the left curly bracket |
| 10989 */ |
| 10990 void set leftBracket(Token bracket) { |
| 10991 _leftBracket = bracket; |
| 10992 } |
| 10993 |
| 10994 /** |
| 10995 * Set the right curly bracket to the given token. |
| 10996 * |
| 10997 * @param bracket the right curly bracket |
| 10998 */ |
| 10999 void set rightBracket(Token bracket) { |
| 11000 _rightBracket = bracket; |
| 11001 } |
| 11002 |
| 11003 @override |
| 11004 void visitChildren(AstVisitor visitor) { |
| 11005 super.visitChildren(visitor); |
| 11006 _entries.accept(visitor); |
| 11007 } |
| 11008 } |
| 11009 |
| 11010 /** |
| 11011 * Instances of the class `MapLiteralEntry` represent a single key/value pair in
a map |
| 11012 * literal. |
| 11013 * |
| 11014 * <pre> |
| 11015 * mapLiteralEntry ::= |
| 11016 * [Expression] ':' [Expression] |
| 11017 * </pre> |
| 11018 */ |
| 11019 class MapLiteralEntry extends AstNode { |
| 11020 /** |
| 11021 * The expression computing the key with which the value will be associated. |
| 11022 */ |
| 11023 Expression _key; |
| 11024 |
| 11025 /** |
| 11026 * The colon that separates the key from the value. |
| 11027 */ |
| 11028 Token separator; |
| 11029 |
| 11030 /** |
| 11031 * The expression computing the value that will be associated with the key. |
| 11032 */ |
| 11033 Expression _value; |
| 11034 |
| 11035 /** |
| 11036 * Initialize a newly created map literal entry. |
| 11037 * |
| 11038 * @param key the expression computing the key with which the value will be as
sociated |
| 11039 * @param separator the colon that separates the key from the value |
| 11040 * @param value the expression computing the value that will be associated wit
h the key |
| 11041 */ |
| 11042 MapLiteralEntry(Expression key, this.separator, Expression value) { |
| 11043 this._key = becomeParentOf(key); |
| 11044 this._value = becomeParentOf(value); |
| 11045 } |
| 11046 |
| 11047 @override |
| 11048 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this); |
| 11049 |
| 11050 @override |
| 11051 Token get beginToken => _key.beginToken; |
| 11052 |
| 11053 @override |
| 11054 Token get endToken => _value.endToken; |
| 11055 |
| 11056 /** |
| 11057 * Return the expression computing the key with which the value will be associ
ated. |
| 11058 * |
| 11059 * @return the expression computing the key with which the value will be assoc
iated |
| 11060 */ |
| 11061 Expression get key => _key; |
| 11062 |
| 11063 /** |
| 11064 * Return the expression computing the value that will be associated with the
key. |
| 11065 * |
| 11066 * @return the expression computing the value that will be associated with the
key |
| 11067 */ |
| 11068 Expression get value => _value; |
| 11069 |
| 11070 /** |
| 11071 * Set the expression computing the key with which the value will be associate
d to the given |
| 11072 * string. |
| 11073 * |
| 11074 * @param string the expression computing the key with which the value will be
associated |
| 11075 */ |
| 11076 void set key(Expression string) { |
| 11077 _key = becomeParentOf(string); |
| 11078 } |
| 11079 |
| 11080 /** |
| 11081 * Set the expression computing the value that will be associated with the key
to the given |
| 11082 * expression. |
| 11083 * |
| 11084 * @param expression the expression computing the value that will be associate
d with the key |
| 11085 */ |
| 11086 void set value(Expression expression) { |
| 11087 _value = becomeParentOf(expression); |
| 11088 } |
| 11089 |
| 11090 @override |
| 11091 void visitChildren(AstVisitor visitor) { |
| 11092 safelyVisitChild(_key, visitor); |
| 11093 safelyVisitChild(_value, visitor); |
| 11094 } |
| 11095 } |
| 11096 |
| 11097 /** |
| 11098 * Instances of the class `MethodDeclaration` represent a method declaration. |
| 11099 * |
| 11100 * <pre> |
| 11101 * methodDeclaration ::= |
| 11102 * methodSignature [FunctionBody] |
| 11103 * |
| 11104 * methodSignature ::= |
| 11105 * 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')? methodName |
| 11106 * [FormalParameterList] |
| 11107 * |
| 11108 * methodName ::= |
| 11109 * [SimpleIdentifier] |
| 11110 * | 'operator' [SimpleIdentifier] |
| 11111 * </pre> |
| 11112 */ |
| 11113 class MethodDeclaration extends ClassMember { |
| 11114 /** |
| 11115 * The token for the 'external' keyword, or `null` if the constructor is not e
xternal. |
| 11116 */ |
| 11117 Token externalKeyword; |
| 11118 |
| 11119 /** |
| 11120 * The token representing the 'abstract' or 'static' keyword, or `null` if nei
ther modifier |
| 11121 * was specified. |
| 11122 */ |
| 11123 Token modifierKeyword; |
| 11124 |
| 11125 /** |
| 11126 * The return type of the method, or `null` if no return type was declared. |
| 11127 */ |
| 11128 TypeName _returnType; |
| 11129 |
| 11130 /** |
| 11131 * The token representing the 'get' or 'set' keyword, or `null` if this is a m
ethod |
| 11132 * declaration rather than a property declaration. |
| 11133 */ |
| 11134 Token propertyKeyword; |
| 11135 |
| 11136 /** |
| 11137 * The token representing the 'operator' keyword, or `null` if this method doe
s not declare |
| 11138 * an operator. |
| 11139 */ |
| 11140 Token operatorKeyword; |
| 11141 |
| 11142 /** |
| 11143 * The name of the method. |
| 11144 */ |
| 11145 SimpleIdentifier _name; |
| 11146 |
| 11147 /** |
| 11148 * The parameters associated with the method, or `null` if this method declare
s a getter. |
| 11149 */ |
| 11150 FormalParameterList _parameters; |
| 11151 |
| 11152 /** |
| 11153 * The body of the method. |
| 11154 */ |
| 11155 FunctionBody _body; |
| 11156 |
| 11157 /** |
| 11158 * Initialize a newly created method declaration. |
| 11159 * |
| 11160 * @param externalKeyword the token for the 'external' keyword |
| 11161 * @param comment the documentation comment associated with this method |
| 11162 * @param metadata the annotations associated with this method |
| 11163 * @param modifierKeyword the token representing the 'abstract' or 'static' ke
yword |
| 11164 * @param returnType the return type of the method |
| 11165 * @param propertyKeyword the token representing the 'get' or 'set' keyword |
| 11166 * @param operatorKeyword the token representing the 'operator' keyword |
| 11167 * @param name the name of the method |
| 11168 * @param parameters the parameters associated with the method, or `null` if t
his method |
| 11169 * declares a getter |
| 11170 * @param body the body of the method |
| 11171 */ |
| 11172 MethodDeclaration(Comment comment, List<Annotation> metadata, this.externalKey
word, this.modifierKeyword, TypeName returnType, this.propertyKeyword, this.oper
atorKeyword, SimpleIdentifier name, FormalParameterList parameters, FunctionBody
body) : super(comment, metadata) { |
| 11173 this._returnType = becomeParentOf(returnType); |
| 11174 this._name = becomeParentOf(name); |
| 11175 this._parameters = becomeParentOf(parameters); |
| 11176 this._body = becomeParentOf(body); |
| 11177 } |
| 11178 |
| 11179 @override |
| 11180 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this); |
| 11181 |
| 11182 /** |
| 11183 * Return the body of the method. |
| 11184 * |
| 11185 * @return the body of the method |
| 11186 */ |
| 11187 FunctionBody get body => _body; |
| 11188 |
| 11189 /** |
| 11190 * Return the element associated with this method, or `null` if the AST struct
ure has not |
| 11191 * been resolved. The element can either be a [MethodElement], if this represe
nts the |
| 11192 * declaration of a normal method, or a [PropertyAccessorElement] if this repr
esents the |
| 11193 * declaration of either a getter or a setter. |
| 11194 * |
| 11195 * @return the element associated with this method |
| 11196 */ |
| 11197 @override |
| 11198 ExecutableElement get element => _name != null ? (_name.staticElement as Execu
tableElement) : null; |
| 11199 |
| 11200 @override |
| 11201 Token get endToken => _body.endToken; |
| 11202 |
| 11203 /** |
| 11204 * Return the name of the method. |
| 11205 * |
| 11206 * @return the name of the method |
| 11207 */ |
| 11208 SimpleIdentifier get name => _name; |
| 11209 |
| 11210 /** |
| 11211 * Return the parameters associated with the method, or `null` if this method
declares a |
| 11212 * getter. |
| 11213 * |
| 11214 * @return the parameters associated with the method |
| 11215 */ |
| 11216 FormalParameterList get parameters => _parameters; |
| 11217 |
| 11218 /** |
| 11219 * Return the return type of the method, or `null` if no return type was decla
red. |
| 11220 * |
| 11221 * @return the return type of the method |
| 11222 */ |
| 11223 TypeName get returnType => _returnType; |
| 11224 |
| 11225 /** |
| 11226 * Return `true` if this method is declared to be an abstract method. |
| 11227 * |
| 11228 * @return `true` if this method is declared to be an abstract method |
| 11229 */ |
| 11230 bool get isAbstract => externalKeyword == null && (_body is EmptyFunctionBody)
; |
| 11231 |
| 11232 /** |
| 11233 * Return `true` if this method declares a getter. |
| 11234 * |
| 11235 * @return `true` if this method declares a getter |
| 11236 */ |
| 11237 bool get isGetter => propertyKeyword != null && (propertyKeyword as KeywordTok
en).keyword == Keyword.GET; |
| 11238 |
| 11239 /** |
| 11240 * Return `true` if this method declares an operator. |
| 11241 * |
| 11242 * @return `true` if this method declares an operator |
| 11243 */ |
| 11244 bool get isOperator => operatorKeyword != null; |
| 11245 |
| 11246 /** |
| 11247 * Return `true` if this method declares a setter. |
| 11248 * |
| 11249 * @return `true` if this method declares a setter |
| 11250 */ |
| 11251 bool get isSetter => propertyKeyword != null && (propertyKeyword as KeywordTok
en).keyword == Keyword.SET; |
| 11252 |
| 11253 /** |
| 11254 * Return `true` if this method is declared to be a static method. |
| 11255 * |
| 11256 * @return `true` if this method is declared to be a static method |
| 11257 */ |
| 11258 bool get isStatic => modifierKeyword != null && (modifierKeyword as KeywordTok
en).keyword == Keyword.STATIC; |
| 11259 |
| 11260 /** |
| 11261 * Set the body of the method to the given function body. |
| 11262 * |
| 11263 * @param functionBody the body of the method |
| 11264 */ |
| 11265 void set body(FunctionBody functionBody) { |
| 11266 _body = becomeParentOf(functionBody); |
| 11267 } |
| 11268 |
| 11269 /** |
| 11270 * Set the name of the method to the given identifier. |
| 11271 * |
| 11272 * @param identifier the name of the method |
| 11273 */ |
| 11274 void set name(SimpleIdentifier identifier) { |
| 11275 _name = becomeParentOf(identifier); |
| 11276 } |
| 11277 |
| 11278 /** |
| 11279 * Set the parameters associated with the method to the given list of paramete
rs. |
| 11280 * |
| 11281 * @param parameters the parameters associated with the method |
| 11282 */ |
| 11283 void set parameters(FormalParameterList parameters) { |
| 11284 this._parameters = becomeParentOf(parameters); |
| 11285 } |
| 11286 |
| 11287 /** |
| 11288 * Set the return type of the method to the given type name. |
| 11289 * |
| 11290 * @param typeName the return type of the method |
| 11291 */ |
| 11292 void set returnType(TypeName typeName) { |
| 11293 _returnType = becomeParentOf(typeName); |
| 11294 } |
| 11295 |
| 11296 @override |
| 11297 void visitChildren(AstVisitor visitor) { |
| 11298 super.visitChildren(visitor); |
| 11299 safelyVisitChild(_returnType, visitor); |
| 11300 safelyVisitChild(_name, visitor); |
| 11301 safelyVisitChild(_parameters, visitor); |
| 11302 safelyVisitChild(_body, visitor); |
| 11303 } |
| 11304 |
| 11305 @override |
| 11306 Token get firstTokenAfterCommentAndMetadata { |
| 11307 if (modifierKeyword != null) { |
| 11308 return modifierKeyword; |
| 11309 } else if (_returnType != null) { |
| 11310 return _returnType.beginToken; |
| 11311 } else if (propertyKeyword != null) { |
| 11312 return propertyKeyword; |
| 11313 } else if (operatorKeyword != null) { |
| 11314 return operatorKeyword; |
| 11315 } |
| 11316 return _name.beginToken; |
| 11317 } |
| 11318 } |
| 11319 |
| 11320 /** |
| 11321 * Instances of the class `MethodInvocation` represent the invocation of either
a function or |
| 11322 * a method. Invocations of functions resulting from evaluating an expression ar
e represented by |
| 11323 * [FunctionExpressionInvocation] nodes. Invocations of getters |
| 11324 * and setters are represented by either [PrefixedIdentifier] or |
| 11325 * [PropertyAccess] nodes. |
| 11326 * |
| 11327 * <pre> |
| 11328 * methodInvoction ::= |
| 11329 * ([Expression] '.')? [SimpleIdentifier] [ArgumentList] |
| 11330 * </pre> |
| 11331 */ |
| 11332 class MethodInvocation extends Expression { |
| 11333 /** |
| 11334 * The expression producing the object on which the method is defined, or `nul
l` if there is |
| 11335 * no target (that is, the target is implicitly `this`). |
| 11336 */ |
| 11337 Expression _target; |
| 11338 |
| 11339 /** |
| 11340 * The period that separates the target from the method name, or `null` if the
re is no |
| 11341 * target. |
| 11342 */ |
| 11343 Token period; |
| 11344 |
| 11345 /** |
| 11346 * The name of the method being invoked. |
| 11347 */ |
| 11348 SimpleIdentifier _methodName; |
| 11349 |
| 11350 /** |
| 11351 * The list of arguments to the method. |
| 11352 */ |
| 11353 ArgumentList _argumentList; |
| 11354 |
| 11355 /** |
| 11356 * Initialize a newly created method invocation. |
| 11357 * |
| 11358 * @param target the expression producing the object on which the method is de
fined |
| 11359 * @param period the period that separates the target from the method name |
| 11360 * @param methodName the name of the method being invoked |
| 11361 * @param argumentList the list of arguments to the method |
| 11362 */ |
| 11363 MethodInvocation(Expression target, this.period, SimpleIdentifier methodName,
ArgumentList argumentList) { |
| 11364 this._target = becomeParentOf(target); |
| 11365 this._methodName = becomeParentOf(methodName); |
| 11366 this._argumentList = becomeParentOf(argumentList); |
| 11367 } |
| 11368 |
| 11369 @override |
| 11370 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this); |
| 11371 |
| 11372 /** |
| 11373 * Return the list of arguments to the method. |
| 11374 * |
| 11375 * @return the list of arguments to the method |
| 11376 */ |
| 11377 ArgumentList get argumentList => _argumentList; |
| 11378 |
| 11379 @override |
| 11380 Token get beginToken { |
| 11381 if (_target != null) { |
| 11382 return _target.beginToken; |
| 11383 } else if (period != null) { |
| 11384 return period; |
| 11385 } |
| 11386 return _methodName.beginToken; |
| 11387 } |
| 11388 |
| 11389 @override |
| 11390 Token get endToken => _argumentList.endToken; |
| 11391 |
| 11392 /** |
| 11393 * Return the name of the method being invoked. |
| 11394 * |
| 11395 * @return the name of the method being invoked |
| 11396 */ |
| 11397 SimpleIdentifier get methodName => _methodName; |
| 11398 |
| 11399 @override |
| 11400 int get precedence => 15; |
| 11401 |
| 11402 /** |
| 11403 * Return the expression used to compute the receiver of the invocation. If th
is invocation is not |
| 11404 * part of a cascade expression, then this is the same as [getTarget]. If this
invocation |
| 11405 * is part of a cascade expression, then the target stored with the cascade ex
pression is |
| 11406 * returned. |
| 11407 * |
| 11408 * @return the expression used to compute the receiver of the invocation |
| 11409 * @see #getTarget() |
| 11410 */ |
| 11411 Expression get realTarget { |
| 11412 if (isCascaded) { |
| 11413 AstNode ancestor = parent; |
| 11414 while (ancestor is! CascadeExpression) { |
| 11415 if (ancestor == null) { |
| 11416 return _target; |
| 11417 } |
| 11418 ancestor = ancestor.parent; |
| 11419 } |
| 11420 return (ancestor as CascadeExpression).target; |
| 11421 } |
| 11422 return _target; |
| 11423 } |
| 11424 |
| 11425 /** |
| 11426 * Return the expression producing the object on which the method is defined,
or `null` if |
| 11427 * there is no target (that is, the target is implicitly `this`) or if this me
thod |
| 11428 * invocation is part of a cascade expression. |
| 11429 * |
| 11430 * @return the expression producing the object on which the method is defined |
| 11431 * @see #getRealTarget() |
| 11432 */ |
| 11433 Expression get target => _target; |
| 11434 |
| 11435 /** |
| 11436 * Return `true` if this expression is cascaded. If it is, then the target of
this |
| 11437 * expression is not stored locally but is stored in the nearest ancestor that
is a |
| 11438 * [CascadeExpression]. |
| 11439 * |
| 11440 * @return `true` if this expression is cascaded |
| 11441 */ |
| 11442 bool get isCascaded => period != null && period.type == TokenType.PERIOD_PERIO
D; |
| 11443 |
| 11444 /** |
| 11445 * Set the list of arguments to the method to the given list. |
| 11446 * |
| 11447 * @param argumentList the list of arguments to the method |
| 11448 */ |
| 11449 void set argumentList(ArgumentList argumentList) { |
| 11450 this._argumentList = becomeParentOf(argumentList); |
| 11451 } |
| 11452 |
| 11453 /** |
| 11454 * Set the name of the method being invoked to the given identifier. |
| 11455 * |
| 11456 * @param identifier the name of the method being invoked |
| 11457 */ |
| 11458 void set methodName(SimpleIdentifier identifier) { |
| 11459 _methodName = becomeParentOf(identifier); |
| 11460 } |
| 11461 |
| 11462 /** |
| 11463 * Set the expression producing the object on which the method is defined to t
he given expression. |
| 11464 * |
| 11465 * @param expression the expression producing the object on which the method i
s defined |
| 11466 */ |
| 11467 void set target(Expression expression) { |
| 11468 _target = becomeParentOf(expression); |
| 11469 } |
| 11470 |
| 11471 @override |
| 11472 void visitChildren(AstVisitor visitor) { |
| 11473 safelyVisitChild(_target, visitor); |
| 11474 safelyVisitChild(_methodName, visitor); |
| 11475 safelyVisitChild(_argumentList, visitor); |
| 11476 } |
| 11477 } |
| 11478 |
| 11479 /** |
| 11480 * Instances of the class `NamedExpression` represent an expression that has a n
ame associated |
| 11481 * with it. They are used in method invocations when there are named parameters. |
| 11482 * |
| 11483 * <pre> |
| 11484 * namedExpression ::= |
| 11485 * [Label] [Expression] |
| 11486 * </pre> |
| 11487 */ |
| 11488 class NamedExpression extends Expression { |
| 11489 /** |
| 11490 * The name associated with the expression. |
| 11491 */ |
| 11492 Label _name; |
| 11493 |
| 11494 /** |
| 11495 * The expression with which the name is associated. |
| 11496 */ |
| 11497 Expression _expression; |
| 11498 |
| 11499 /** |
| 11500 * Initialize a newly created named expression. |
| 11501 * |
| 11502 * @param name the name associated with the expression |
| 11503 * @param expression the expression with which the name is associated |
| 11504 */ |
| 11505 NamedExpression(Label name, Expression expression) { |
| 11506 this._name = becomeParentOf(name); |
| 11507 this._expression = becomeParentOf(expression); |
| 11508 } |
| 11509 |
| 11510 @override |
| 11511 accept(AstVisitor visitor) => visitor.visitNamedExpression(this); |
| 11512 |
| 11513 @override |
| 11514 Token get beginToken => _name.beginToken; |
| 11515 |
| 11516 /** |
| 11517 * Return the element representing the parameter being named by this expressio
n, or `null` |
| 11518 * if the AST structure has not been resolved or if there is no parameter with
the same name as |
| 11519 * this expression. |
| 11520 * |
| 11521 * @return the element representing the parameter being named by this expressi
on |
| 11522 */ |
| 11523 ParameterElement get element { |
| 11524 Element element = _name.label.staticElement; |
| 11525 if (element is ParameterElement) { |
| 11526 return element; |
| 11527 } |
| 11528 return null; |
| 11529 } |
| 11530 |
| 11531 @override |
| 11532 Token get endToken => _expression.endToken; |
| 11533 |
| 11534 /** |
| 11535 * Return the expression with which the name is associated. |
| 11536 * |
| 11537 * @return the expression with which the name is associated |
| 11538 */ |
| 11539 Expression get expression => _expression; |
| 11540 |
| 11541 /** |
| 11542 * Return the name associated with the expression. |
| 11543 * |
| 11544 * @return the name associated with the expression |
| 11545 */ |
| 11546 Label get name => _name; |
| 11547 |
| 11548 @override |
| 11549 int get precedence => 0; |
| 11550 |
| 11551 /** |
| 11552 * Set the expression with which the name is associated to the given expressio
n. |
| 11553 * |
| 11554 * @param expression the expression with which the name is associated |
| 11555 */ |
| 11556 void set expression(Expression expression) { |
| 11557 this._expression = becomeParentOf(expression); |
| 11558 } |
| 11559 |
| 11560 /** |
| 11561 * Set the name associated with the expression to the given identifier. |
| 11562 * |
| 11563 * @param identifier the name associated with the expression |
| 11564 */ |
| 11565 void set name(Label identifier) { |
| 11566 _name = becomeParentOf(identifier); |
| 11567 } |
| 11568 |
| 11569 @override |
| 11570 void visitChildren(AstVisitor visitor) { |
| 11571 safelyVisitChild(_name, visitor); |
| 11572 safelyVisitChild(_expression, visitor); |
| 11573 } |
| 11574 } |
| 11575 |
| 11576 /** |
| 11577 * The abstract class `NamespaceDirective` defines the behavior common to nodes
that represent |
| 11578 * a directive that impacts the namespace of a library. |
| 11579 * |
| 11580 * <pre> |
| 11581 * directive ::= |
| 11582 * [ExportDirective] |
| 11583 * | [ImportDirective] |
| 11584 * </pre> |
| 11585 */ |
| 11586 abstract class NamespaceDirective extends UriBasedDirective { |
| 11587 /** |
| 11588 * The token representing the 'import' or 'export' keyword. |
| 11589 */ |
| 11590 Token keyword; |
| 11591 |
| 11592 /** |
| 11593 * The combinators used to control which names are imported or exported. |
| 11594 */ |
| 11595 NodeList<Combinator> _combinators; |
| 11596 |
| 11597 /** |
| 11598 * The semicolon terminating the directive. |
| 11599 */ |
| 11600 Token semicolon; |
| 11601 |
| 11602 /** |
| 11603 * Initialize a newly created namespace directive. |
| 11604 * |
| 11605 * @param comment the documentation comment associated with this directive |
| 11606 * @param metadata the annotations associated with the directive |
| 11607 * @param keyword the token representing the 'import' or 'export' keyword |
| 11608 * @param libraryUri the URI of the library being imported or exported |
| 11609 * @param combinators the combinators used to control which names are imported
or exported |
| 11610 * @param semicolon the semicolon terminating the directive |
| 11611 */ |
| 11612 NamespaceDirective(Comment comment, List<Annotation> metadata, this.keyword, S
tringLiteral libraryUri, List<Combinator> combinators, this.semicolon) : super(c
omment, metadata, libraryUri) { |
| 11613 this._combinators = new NodeList<Combinator>(this); |
| 11614 this._combinators.addAll(combinators); |
| 11615 } |
| 11616 |
| 11617 /** |
| 11618 * Return the combinators used to control how names are imported or exported. |
| 11619 * |
| 11620 * @return the combinators used to control how names are imported or exported |
| 11621 */ |
| 11622 NodeList<Combinator> get combinators => _combinators; |
| 11623 |
| 11624 @override |
| 11625 Token get endToken => semicolon; |
| 11626 |
| 11627 @override |
| 11628 LibraryElement get uriElement; |
| 11629 |
| 11630 @override |
| 11631 Token get firstTokenAfterCommentAndMetadata => keyword; |
| 11632 } |
| 11633 |
| 11634 /** |
| 11635 * Instances of the class `NativeClause` represent the "native" clause in an cla
ss |
| 11636 * declaration. |
| 11637 * |
| 11638 * <pre> |
| 11639 * nativeClause ::= |
| 11640 * 'native' [StringLiteral] |
| 11641 * </pre> |
| 11642 */ |
| 11643 class NativeClause extends AstNode { |
| 11644 /** |
| 11645 * The token representing the 'native' keyword. |
| 11646 */ |
| 11647 Token keyword; |
| 11648 |
| 11649 /** |
| 11650 * The name of the native object that implements the class. |
| 11651 */ |
| 11652 StringLiteral _name; |
| 11653 |
| 11654 /** |
| 11655 * Initialize a newly created native clause. |
| 11656 * |
| 11657 * @param keyword the token representing the 'native' keyword |
| 11658 * @param name the name of the native object that implements the class. |
| 11659 */ |
| 11660 NativeClause(this.keyword, StringLiteral name) { |
| 11661 this._name = becomeParentOf(name); |
| 11662 } |
| 11663 |
| 11664 @override |
| 11665 accept(AstVisitor visitor) => visitor.visitNativeClause(this); |
| 11666 |
| 11667 @override |
| 11668 Token get beginToken => keyword; |
| 11669 |
| 11670 @override |
| 11671 Token get endToken => _name.endToken; |
| 11672 |
| 11673 /** |
| 11674 * Return the name of the native object that implements the class. |
| 11675 * |
| 11676 * @return the name of the native object that implements the class |
| 11677 */ |
| 11678 StringLiteral get name => _name; |
| 11679 |
| 11680 /** |
| 11681 * Sets the name of the native object that implements the class. |
| 11682 * |
| 11683 * @param name the name of the native object that implements the class. |
| 11684 */ |
| 11685 void set name(StringLiteral name) { |
| 11686 this._name = becomeParentOf(name); |
| 11687 } |
| 11688 |
| 11689 @override |
| 11690 void visitChildren(AstVisitor visitor) { |
| 11691 safelyVisitChild(_name, visitor); |
| 11692 } |
| 11693 } |
| 11694 |
| 11695 /** |
| 11696 * Instances of the class `NativeFunctionBody` represent a function body that co
nsists of a |
| 11697 * native keyword followed by a string literal. |
| 11698 * |
| 11699 * <pre> |
| 11700 * nativeFunctionBody ::= |
| 11701 * 'native' [SimpleStringLiteral] ';' |
| 11702 * </pre> |
| 11703 */ |
| 11704 class NativeFunctionBody extends FunctionBody { |
| 11705 /** |
| 11706 * The token representing 'native' that marks the start of the function body. |
| 11707 */ |
| 11708 final Token nativeToken; |
| 11709 |
| 11710 /** |
| 11711 * The string literal, after the 'native' token. |
| 11712 */ |
| 11713 StringLiteral _stringLiteral; |
| 11714 |
| 11715 /** |
| 11716 * The token representing the semicolon that marks the end of the function bod
y. |
| 11717 */ |
| 11718 final Token semicolon; |
| 11719 |
| 11720 /** |
| 11721 * Initialize a newly created function body consisting of the 'native' token,
a string literal, |
| 11722 * and a semicolon. |
| 11723 * |
| 11724 * @param nativeToken the token representing 'native' that marks the start of
the function body |
| 11725 * @param stringLiteral the string literal |
| 11726 * @param semicolon the token representing the semicolon that marks the end of
the function body |
| 11727 */ |
| 11728 NativeFunctionBody(this.nativeToken, StringLiteral stringLiteral, this.semicol
on) { |
| 11729 this._stringLiteral = becomeParentOf(stringLiteral); |
| 11730 } |
| 11731 |
| 11732 @override |
| 11733 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this); |
| 11734 |
| 11735 @override |
| 11736 Token get beginToken => nativeToken; |
| 11737 |
| 11738 @override |
| 11739 Token get endToken => semicolon; |
| 11740 |
| 11741 /** |
| 11742 * Return the string literal representing the string after the 'native' token. |
| 11743 * |
| 11744 * @return the string literal representing the string after the 'native' token |
| 11745 */ |
| 11746 StringLiteral get stringLiteral => _stringLiteral; |
| 11747 |
| 11748 /** |
| 11749 * Set the string literal representing the string after the 'native' token to
the given string. |
| 11750 * |
| 11751 * @param stringLiteral the string literal representing the string after the '
native' token |
| 11752 */ |
| 11753 void set stringLiteral(StringLiteral stringLiteral) { |
| 11754 this._stringLiteral = becomeParentOf(stringLiteral); |
| 11755 } |
| 11756 |
| 11757 @override |
| 11758 void visitChildren(AstVisitor visitor) { |
| 11759 safelyVisitChild(_stringLiteral, visitor); |
| 11760 } |
| 11761 } |
| 11762 |
| 11763 /** |
| 11764 * Instances of the class `NodeLocator` locate the [AstNode] associated with a |
| 11765 * source range, given the AST structure built from the source. More specificall
y, they will return |
| 11766 * the [AstNode] with the shortest length whose source range completely encompas
ses |
| 11767 * the specified range. |
| 11768 */ |
| 11769 class NodeLocator extends UnifyingAstVisitor<Object> { |
| 11770 /** |
| 11771 * The start offset of the range used to identify the node. |
| 11772 */ |
| 11773 int _startOffset = 0; |
| 11774 |
| 11775 /** |
| 11776 * The end offset of the range used to identify the node. |
| 11777 */ |
| 11778 int _endOffset = 0; |
| 11779 |
| 11780 /** |
| 11781 * The element that was found that corresponds to the given source range, or `
null` if there |
| 11782 * is no such element. |
| 11783 */ |
| 11784 AstNode _foundNode; |
| 11785 |
| 11786 /** |
| 11787 * Initialize a newly created locator to locate one or more [AstNode] by locat
ing |
| 11788 * the node within an AST structure that corresponds to the given offset in th
e source. |
| 11789 * |
| 11790 * @param offset the offset used to identify the node |
| 11791 */ |
| 11792 NodeLocator.con1(int offset) : this.con2(offset, offset); |
| 11793 |
| 11794 /** |
| 11795 * Initialize a newly created locator to locate one or more [AstNode] by locat
ing |
| 11796 * the node within an AST structure that corresponds to the given range of cha
racters in the |
| 11797 * source. |
| 11798 * |
| 11799 * @param start the start offset of the range used to identify the node |
| 11800 * @param end the end offset of the range used to identify the node |
| 11801 */ |
| 11802 NodeLocator.con2(int start, int end) { |
| 11803 this._startOffset = start; |
| 11804 this._endOffset = end; |
| 11805 } |
| 11806 |
| 11807 /** |
| 11808 * Return the node that was found that corresponds to the given source range,
or `null` if |
| 11809 * there is no such node. |
| 11810 * |
| 11811 * @return the node that was found |
| 11812 */ |
| 11813 AstNode get foundNode => _foundNode; |
| 11814 |
| 11815 /** |
| 11816 * Search within the given AST node for an identifier representing a [DartElem
ent] in the specified source range. Return the element that was found, or `null`
if |
| 11817 * no element was found. |
| 11818 * |
| 11819 * @param node the AST node within which to search |
| 11820 * @return the element that was found |
| 11821 */ |
| 11822 AstNode searchWithin(AstNode node) { |
| 11823 if (node == null) { |
| 11824 return null; |
| 11825 } |
| 11826 try { |
| 11827 node.accept(this); |
| 11828 } on NodeLocator_NodeFoundException catch (exception) { |
| 11829 } catch (exception) { |
| 11830 AnalysisEngine.instance.logger.logInformation2("Unable to locate element a
t offset (${_startOffset} - ${_endOffset})", exception); |
| 11831 return null; |
| 11832 } |
| 11833 return _foundNode; |
| 11834 } |
| 11835 |
| 11836 @override |
| 11837 Object visitNode(AstNode node) { |
| 11838 int start = node.offset; |
| 11839 int end = start + node.length; |
| 11840 if (end < _startOffset) { |
| 11841 return null; |
| 11842 } |
| 11843 if (start > _endOffset) { |
| 11844 return null; |
| 11845 } |
| 11846 try { |
| 11847 node.visitChildren(this); |
| 11848 } on NodeLocator_NodeFoundException catch (exception) { |
| 11849 throw exception; |
| 11850 } catch (exception) { |
| 11851 // Ignore the exception and proceed in order to visit the rest of the stru
cture. |
| 11852 AnalysisEngine.instance.logger.logInformation2("Exception caught while tra
versing an AST structure.", exception); |
| 11853 } |
| 11854 if (start <= _startOffset && _endOffset <= end) { |
| 11855 _foundNode = node; |
| 11856 throw new NodeLocator_NodeFoundException(); |
| 11857 } |
| 11858 return null; |
| 11859 } |
| 11860 } |
| 11861 |
| 11862 /** |
| 11863 * Instances of the class `NodeFoundException` are used to cancel visiting after
a node has |
| 11864 * been found. |
| 11865 */ |
| 11866 class NodeLocator_NodeFoundException extends RuntimeException { |
| 11867 static int _serialVersionUID = 1; |
| 11868 } |
| 11869 |
| 11870 /** |
| 11871 * Instances of the class `NodeReplacer` implement an object that will replace o
ne child node |
| 11872 * in an AST node with another node. |
| 11873 */ |
| 11874 class NodeReplacer implements AstVisitor<bool> { |
| 11875 /** |
| 11876 * Replace the old node with the new node in the AST structure containing the
old node. |
| 11877 * |
| 11878 * @param oldNode |
| 11879 * @param newNode |
| 11880 * @return `true` if the replacement was successful |
| 11881 * @throws IllegalArgumentException if either node is `null`, if the old node
does not have |
| 11882 * a parent node, or if the AST structure has been corrupted |
| 11883 */ |
| 11884 static bool replace(AstNode oldNode, AstNode newNode) { |
| 11885 if (oldNode == null || newNode == null) { |
| 11886 throw new IllegalArgumentException("The old and new nodes must be non-null
"); |
| 11887 } else if (identical(oldNode, newNode)) { |
| 11888 return true; |
| 11889 } |
| 11890 AstNode parent = oldNode.parent; |
| 11891 if (parent == null) { |
| 11892 throw new IllegalArgumentException("The old node is not a child of another
node"); |
| 11893 } |
| 11894 NodeReplacer replacer = new NodeReplacer(oldNode, newNode); |
| 11895 return parent.accept(replacer); |
| 11896 } |
| 11897 |
| 11898 final AstNode _oldNode; |
| 11899 |
| 11900 final AstNode _newNode; |
| 11901 |
| 11902 NodeReplacer(this._oldNode, this._newNode); |
| 11903 |
| 11904 @override |
| 11905 bool visitAdjacentStrings(AdjacentStrings node) { |
| 11906 if (_replaceInList(node.strings)) { |
| 11907 return true; |
| 11908 } |
| 11909 return visitNode(node); |
| 11910 } |
| 11911 |
| 11912 bool visitAnnotatedNode(AnnotatedNode node) { |
| 11913 if (identical(node.documentationComment, _oldNode)) { |
| 11914 node.documentationComment = _newNode as Comment; |
| 11915 return true; |
| 11916 } else if (_replaceInList(node.metadata)) { |
| 11917 return true; |
| 11918 } |
| 11919 return visitNode(node); |
| 11920 } |
| 11921 |
| 11922 @override |
| 11923 bool visitAnnotation(Annotation node) { |
| 11924 if (identical(node.arguments, _oldNode)) { |
| 11925 node.arguments = _newNode as ArgumentList; |
| 11926 return true; |
| 11927 } else if (identical(node.constructorName, _oldNode)) { |
| 11928 node.constructorName = _newNode as SimpleIdentifier; |
| 11929 return true; |
| 11930 } else if (identical(node.name, _oldNode)) { |
| 11931 node.name = _newNode as Identifier; |
| 11932 return true; |
| 11933 } |
| 11934 return visitNode(node); |
| 11935 } |
| 11936 |
| 11937 @override |
| 11938 bool visitArgumentList(ArgumentList node) { |
| 11939 if (_replaceInList(node.arguments)) { |
| 11940 return true; |
| 11941 } |
| 11942 return visitNode(node); |
| 11943 } |
| 11944 |
| 11945 @override |
| 11946 bool visitAsExpression(AsExpression node) { |
| 11947 if (identical(node.expression, _oldNode)) { |
| 11948 node.expression = _newNode as Expression; |
| 11949 return true; |
| 11950 } else if (identical(node.type, _oldNode)) { |
| 11951 node.type = _newNode as TypeName; |
| 11952 return true; |
| 11953 } |
| 11954 return visitNode(node); |
| 11955 } |
| 11956 |
| 11957 @override |
| 11958 bool visitAssertStatement(AssertStatement node) { |
| 11959 if (identical(node.condition, _oldNode)) { |
| 11960 node.condition = _newNode as Expression; |
| 11961 return true; |
| 11962 } |
| 11963 return visitNode(node); |
| 11964 } |
| 11965 |
| 11966 @override |
| 11967 bool visitAssignmentExpression(AssignmentExpression node) { |
| 11968 if (identical(node.leftHandSide, _oldNode)) { |
| 11969 node.leftHandSide = _newNode as Expression; |
| 11970 return true; |
| 11971 } else if (identical(node.rightHandSide, _oldNode)) { |
| 11972 node.rightHandSide = _newNode as Expression; |
| 11973 return true; |
| 11974 } |
| 11975 return visitNode(node); |
| 11976 } |
| 11977 |
| 11978 @override |
| 11979 bool visitAwaitExpression(AwaitExpression node) { |
| 11980 if (identical(node.expression, _oldNode)) { |
| 11981 node.expression = _newNode as Expression; |
| 11982 } |
| 11983 return visitNode(node); |
| 11984 } |
| 11985 |
| 11986 @override |
| 11987 bool visitBinaryExpression(BinaryExpression node) { |
| 11988 if (identical(node.leftOperand, _oldNode)) { |
| 11989 node.leftOperand = _newNode as Expression; |
| 11990 return true; |
| 11991 } else if (identical(node.rightOperand, _oldNode)) { |
| 11992 node.rightOperand = _newNode as Expression; |
| 11993 return true; |
| 11994 } |
| 11995 return visitNode(node); |
| 11996 } |
| 11997 |
| 11998 @override |
| 11999 bool visitBlock(Block node) { |
| 12000 if (_replaceInList(node.statements)) { |
| 12001 return true; |
| 12002 } |
| 12003 return visitNode(node); |
| 12004 } |
| 12005 |
| 12006 @override |
| 12007 bool visitBlockFunctionBody(BlockFunctionBody node) { |
| 12008 if (identical(node.block, _oldNode)) { |
| 12009 node.block = _newNode as Block; |
| 12010 return true; |
| 12011 } |
| 12012 return visitNode(node); |
| 12013 } |
| 12014 |
| 12015 @override |
| 12016 bool visitBooleanLiteral(BooleanLiteral node) => visitNode(node); |
| 12017 |
| 12018 @override |
| 12019 bool visitBreakStatement(BreakStatement node) { |
| 12020 if (identical(node.label, _oldNode)) { |
| 12021 node.label = _newNode as SimpleIdentifier; |
| 12022 return true; |
| 12023 } |
| 12024 return visitNode(node); |
| 12025 } |
| 12026 |
| 12027 @override |
| 12028 bool visitCascadeExpression(CascadeExpression node) { |
| 12029 if (identical(node.target, _oldNode)) { |
| 12030 node.target = _newNode as Expression; |
| 12031 return true; |
| 12032 } else if (_replaceInList(node.cascadeSections)) { |
| 12033 return true; |
| 12034 } |
| 12035 return visitNode(node); |
| 12036 } |
| 12037 |
| 12038 @override |
| 12039 bool visitCatchClause(CatchClause node) { |
| 12040 if (identical(node.exceptionType, _oldNode)) { |
| 12041 node.exceptionType = _newNode as TypeName; |
| 12042 return true; |
| 12043 } else if (identical(node.exceptionParameter, _oldNode)) { |
| 12044 node.exceptionParameter = _newNode as SimpleIdentifier; |
| 12045 return true; |
| 12046 } else if (identical(node.stackTraceParameter, _oldNode)) { |
| 12047 node.stackTraceParameter = _newNode as SimpleIdentifier; |
| 12048 return true; |
| 12049 } |
| 12050 return visitNode(node); |
| 12051 } |
| 12052 |
| 12053 @override |
| 12054 bool visitClassDeclaration(ClassDeclaration node) { |
| 12055 if (identical(node.name, _oldNode)) { |
| 12056 node.name = _newNode as SimpleIdentifier; |
| 12057 return true; |
| 12058 } else if (identical(node.typeParameters, _oldNode)) { |
| 12059 node.typeParameters = _newNode as TypeParameterList; |
| 12060 return true; |
| 12061 } else if (identical(node.extendsClause, _oldNode)) { |
| 12062 node.extendsClause = _newNode as ExtendsClause; |
| 12063 return true; |
| 12064 } else if (identical(node.withClause, _oldNode)) { |
| 12065 node.withClause = _newNode as WithClause; |
| 12066 return true; |
| 12067 } else if (identical(node.implementsClause, _oldNode)) { |
| 12068 node.implementsClause = _newNode as ImplementsClause; |
| 12069 return true; |
| 12070 } else if (identical(node.nativeClause, _oldNode)) { |
| 12071 node.nativeClause = _newNode as NativeClause; |
| 12072 return true; |
| 12073 } else if (_replaceInList(node.members)) { |
| 12074 return true; |
| 12075 } |
| 12076 return visitAnnotatedNode(node); |
| 12077 } |
| 12078 |
| 12079 @override |
| 12080 bool visitClassTypeAlias(ClassTypeAlias node) { |
| 12081 if (identical(node.name, _oldNode)) { |
| 12082 node.name = _newNode as SimpleIdentifier; |
| 12083 return true; |
| 12084 } else if (identical(node.typeParameters, _oldNode)) { |
| 12085 node.typeParameters = _newNode as TypeParameterList; |
| 12086 return true; |
| 12087 } else if (identical(node.superclass, _oldNode)) { |
| 12088 node.superclass = _newNode as TypeName; |
| 12089 return true; |
| 12090 } else if (identical(node.withClause, _oldNode)) { |
| 12091 node.withClause = _newNode as WithClause; |
| 12092 return true; |
| 12093 } else if (identical(node.implementsClause, _oldNode)) { |
| 12094 node.implementsClause = _newNode as ImplementsClause; |
| 12095 return true; |
| 12096 } |
| 12097 return visitAnnotatedNode(node); |
| 12098 } |
| 12099 |
| 12100 @override |
| 12101 bool visitComment(Comment node) { |
| 12102 if (_replaceInList(node.references)) { |
| 12103 return true; |
| 12104 } |
| 12105 return visitNode(node); |
| 12106 } |
| 12107 |
| 12108 @override |
| 12109 bool visitCommentReference(CommentReference node) { |
| 12110 if (identical(node.identifier, _oldNode)) { |
| 12111 node.identifier = _newNode as Identifier; |
| 12112 return true; |
| 12113 } |
| 12114 return visitNode(node); |
| 12115 } |
| 12116 |
| 12117 @override |
| 12118 bool visitCompilationUnit(CompilationUnit node) { |
| 12119 if (identical(node.scriptTag, _oldNode)) { |
| 12120 node.scriptTag = _newNode as ScriptTag; |
| 12121 return true; |
| 12122 } else if (_replaceInList(node.directives)) { |
| 12123 return true; |
| 12124 } else if (_replaceInList(node.declarations)) { |
| 12125 return true; |
| 12126 } |
| 12127 return visitNode(node); |
| 12128 } |
| 12129 |
| 12130 @override |
| 12131 bool visitConditionalExpression(ConditionalExpression node) { |
| 12132 if (identical(node.condition, _oldNode)) { |
| 12133 node.condition = _newNode as Expression; |
| 12134 return true; |
| 12135 } else if (identical(node.thenExpression, _oldNode)) { |
| 12136 node.thenExpression = _newNode as Expression; |
| 12137 return true; |
| 12138 } else if (identical(node.elseExpression, _oldNode)) { |
| 12139 node.elseExpression = _newNode as Expression; |
| 12140 return true; |
| 12141 } |
| 12142 return visitNode(node); |
| 12143 } |
| 12144 |
| 12145 @override |
| 12146 bool visitConstructorDeclaration(ConstructorDeclaration node) { |
| 12147 if (identical(node.returnType, _oldNode)) { |
| 12148 node.returnType = _newNode as Identifier; |
| 12149 return true; |
| 12150 } else if (identical(node.name, _oldNode)) { |
| 12151 node.name = _newNode as SimpleIdentifier; |
| 12152 return true; |
| 12153 } else if (identical(node.parameters, _oldNode)) { |
| 12154 node.parameters = _newNode as FormalParameterList; |
| 12155 return true; |
| 12156 } else if (identical(node.redirectedConstructor, _oldNode)) { |
| 12157 node.redirectedConstructor = _newNode as ConstructorName; |
| 12158 return true; |
| 12159 } else if (identical(node.body, _oldNode)) { |
| 12160 node.body = _newNode as FunctionBody; |
| 12161 return true; |
| 12162 } else if (_replaceInList(node.initializers)) { |
| 12163 return true; |
| 12164 } |
| 12165 return visitAnnotatedNode(node); |
| 12166 } |
| 12167 |
| 12168 @override |
| 12169 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 12170 if (identical(node.fieldName, _oldNode)) { |
| 12171 node.fieldName = _newNode as SimpleIdentifier; |
| 12172 return true; |
| 12173 } else if (identical(node.expression, _oldNode)) { |
| 12174 node.expression = _newNode as Expression; |
| 12175 return true; |
| 12176 } |
| 12177 return visitNode(node); |
| 12178 } |
| 12179 |
| 12180 @override |
| 12181 bool visitConstructorName(ConstructorName node) { |
| 12182 if (identical(node.type, _oldNode)) { |
| 12183 node.type = _newNode as TypeName; |
| 12184 return true; |
| 12185 } else if (identical(node.name, _oldNode)) { |
| 12186 node.name = _newNode as SimpleIdentifier; |
| 12187 return true; |
| 12188 } |
| 12189 return visitNode(node); |
| 12190 } |
| 12191 |
| 12192 @override |
| 12193 bool visitContinueStatement(ContinueStatement node) { |
| 12194 if (identical(node.label, _oldNode)) { |
| 12195 node.label = _newNode as SimpleIdentifier; |
| 12196 return true; |
| 12197 } |
| 12198 return visitNode(node); |
| 12199 } |
| 12200 |
| 12201 @override |
| 12202 bool visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 12203 if (identical(node.type, _oldNode)) { |
| 12204 node.type = _newNode as TypeName; |
| 12205 return true; |
| 12206 } else if (identical(node.identifier, _oldNode)) { |
| 12207 node.identifier = _newNode as SimpleIdentifier; |
| 12208 return true; |
| 12209 } |
| 12210 return visitAnnotatedNode(node); |
| 12211 } |
| 12212 |
| 12213 @override |
| 12214 bool visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 12215 if (identical(node.parameter, _oldNode)) { |
| 12216 node.parameter = _newNode as NormalFormalParameter; |
| 12217 return true; |
| 12218 } else if (identical(node.defaultValue, _oldNode)) { |
| 12219 node.defaultValue = _newNode as Expression; |
| 12220 return true; |
| 12221 } |
| 12222 return visitNode(node); |
| 12223 } |
| 12224 |
| 12225 @override |
| 12226 bool visitDoStatement(DoStatement node) { |
| 12227 if (identical(node.body, _oldNode)) { |
| 12228 node.body = _newNode as Statement; |
| 12229 return true; |
| 12230 } else if (identical(node.condition, _oldNode)) { |
| 12231 node.condition = _newNode as Expression; |
| 12232 return true; |
| 12233 } |
| 12234 return visitNode(node); |
| 12235 } |
| 12236 |
| 12237 @override |
| 12238 bool visitDoubleLiteral(DoubleLiteral node) => visitNode(node); |
| 12239 |
| 12240 @override |
| 12241 bool visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node); |
| 12242 |
| 12243 @override |
| 12244 bool visitEmptyStatement(EmptyStatement node) => visitNode(node); |
| 12245 |
| 12246 @override |
| 12247 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) { |
| 12248 if (identical(node.name, _oldNode)) { |
| 12249 node.name = _newNode as SimpleIdentifier; |
| 12250 return true; |
| 12251 } |
| 12252 return visitAnnotatedNode(node); |
| 12253 } |
| 12254 |
| 12255 @override |
| 12256 bool visitEnumDeclaration(EnumDeclaration node) { |
| 12257 if (identical(node.name, _oldNode)) { |
| 12258 node.name = _newNode as SimpleIdentifier; |
| 12259 return true; |
| 12260 } else if (_replaceInList(node.constants)) { |
| 12261 return true; |
| 12262 } |
| 12263 return visitAnnotatedNode(node); |
| 12264 } |
| 12265 |
| 12266 @override |
| 12267 bool visitExportDirective(ExportDirective node) => visitNamespaceDirective(nod
e); |
| 12268 |
| 12269 @override |
| 12270 bool visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 12271 if (identical(node.expression, _oldNode)) { |
| 12272 node.expression = _newNode as Expression; |
| 12273 return true; |
| 12274 } |
| 12275 return visitNode(node); |
| 12276 } |
| 12277 |
| 12278 @override |
| 12279 bool visitExpressionStatement(ExpressionStatement node) { |
| 12280 if (identical(node.expression, _oldNode)) { |
| 12281 node.expression = _newNode as Expression; |
| 12282 return true; |
| 12283 } |
| 12284 return visitNode(node); |
| 12285 } |
| 12286 |
| 12287 @override |
| 12288 bool visitExtendsClause(ExtendsClause node) { |
| 12289 if (identical(node.superclass, _oldNode)) { |
| 12290 node.superclass = _newNode as TypeName; |
| 12291 return true; |
| 12292 } |
| 12293 return visitNode(node); |
| 12294 } |
| 12295 |
| 12296 @override |
| 12297 bool visitFieldDeclaration(FieldDeclaration node) { |
| 12298 if (identical(node.fields, _oldNode)) { |
| 12299 node.fields = _newNode as VariableDeclarationList; |
| 12300 return true; |
| 12301 } |
| 12302 return visitAnnotatedNode(node); |
| 12303 } |
| 12304 |
| 12305 @override |
| 12306 bool visitFieldFormalParameter(FieldFormalParameter node) { |
| 12307 if (identical(node.type, _oldNode)) { |
| 12308 node.type = _newNode as TypeName; |
| 12309 return true; |
| 12310 } else if (identical(node.parameters, _oldNode)) { |
| 12311 node.parameters = _newNode as FormalParameterList; |
| 12312 return true; |
| 12313 } |
| 12314 return visitNormalFormalParameter(node); |
| 12315 } |
| 12316 |
| 12317 @override |
| 12318 bool visitForEachStatement(ForEachStatement node) { |
| 12319 if (identical(node.loopVariable, _oldNode)) { |
| 12320 node.loopVariable = _newNode as DeclaredIdentifier; |
| 12321 return true; |
| 12322 } else if (identical(node.identifier, _oldNode)) { |
| 12323 node.identifier = _newNode as SimpleIdentifier; |
| 12324 return true; |
| 12325 } else if (identical(node.iterator, _oldNode)) { |
| 12326 node.iterator = _newNode as Expression; |
| 12327 return true; |
| 12328 } else if (identical(node.body, _oldNode)) { |
| 12329 node.body = _newNode as Statement; |
| 12330 return true; |
| 12331 } |
| 12332 return visitNode(node); |
| 12333 } |
| 12334 |
| 12335 @override |
| 12336 bool visitFormalParameterList(FormalParameterList node) { |
| 12337 if (_replaceInList(node.parameters)) { |
| 12338 return true; |
| 12339 } |
| 12340 return visitNode(node); |
| 12341 } |
| 12342 |
| 12343 @override |
| 12344 bool visitForStatement(ForStatement node) { |
| 12345 if (identical(node.variables, _oldNode)) { |
| 12346 node.variables = _newNode as VariableDeclarationList; |
| 12347 return true; |
| 12348 } else if (identical(node.initialization, _oldNode)) { |
| 12349 node.initialization = _newNode as Expression; |
| 12350 return true; |
| 12351 } else if (identical(node.condition, _oldNode)) { |
| 12352 node.condition = _newNode as Expression; |
| 12353 return true; |
| 12354 } else if (identical(node.body, _oldNode)) { |
| 12355 node.body = _newNode as Statement; |
| 12356 return true; |
| 12357 } else if (_replaceInList(node.updaters)) { |
| 12358 return true; |
| 12359 } |
| 12360 return visitNode(node); |
| 12361 } |
| 12362 |
| 12363 @override |
| 12364 bool visitFunctionDeclaration(FunctionDeclaration node) { |
| 12365 if (identical(node.returnType, _oldNode)) { |
| 12366 node.returnType = _newNode as TypeName; |
| 12367 return true; |
| 12368 } else if (identical(node.name, _oldNode)) { |
| 12369 node.name = _newNode as SimpleIdentifier; |
| 12370 return true; |
| 12371 } else if (identical(node.functionExpression, _oldNode)) { |
| 12372 node.functionExpression = _newNode as FunctionExpression; |
| 12373 return true; |
| 12374 } |
| 12375 return visitAnnotatedNode(node); |
| 12376 } |
| 12377 |
| 12378 @override |
| 12379 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 12380 if (identical(node.functionDeclaration, _oldNode)) { |
| 12381 node.functionDeclaration = _newNode as FunctionDeclaration; |
| 12382 return true; |
| 12383 } |
| 12384 return visitNode(node); |
| 12385 } |
| 12386 |
| 12387 @override |
| 12388 bool visitFunctionExpression(FunctionExpression node) { |
| 12389 if (identical(node.parameters, _oldNode)) { |
| 12390 node.parameters = _newNode as FormalParameterList; |
| 12391 return true; |
| 12392 } else if (identical(node.body, _oldNode)) { |
| 12393 node.body = _newNode as FunctionBody; |
| 12394 return true; |
| 12395 } |
| 12396 return visitNode(node); |
| 12397 } |
| 12398 |
| 12399 @override |
| 12400 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 12401 if (identical(node.function, _oldNode)) { |
| 12402 node.function = _newNode as Expression; |
| 12403 return true; |
| 12404 } else if (identical(node.argumentList, _oldNode)) { |
| 12405 node.argumentList = _newNode as ArgumentList; |
| 12406 return true; |
| 12407 } |
| 12408 return visitNode(node); |
| 12409 } |
| 12410 |
| 12411 @override |
| 12412 bool visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 12413 if (identical(node.returnType, _oldNode)) { |
| 12414 node.returnType = _newNode as TypeName; |
| 12415 return true; |
| 12416 } else if (identical(node.name, _oldNode)) { |
| 12417 node.name = _newNode as SimpleIdentifier; |
| 12418 return true; |
| 12419 } else if (identical(node.typeParameters, _oldNode)) { |
| 12420 node.typeParameters = _newNode as TypeParameterList; |
| 12421 return true; |
| 12422 } else if (identical(node.parameters, _oldNode)) { |
| 12423 node.parameters = _newNode as FormalParameterList; |
| 12424 return true; |
| 12425 } |
| 12426 return visitAnnotatedNode(node); |
| 12427 } |
| 12428 |
| 12429 @override |
| 12430 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 12431 if (identical(node.returnType, _oldNode)) { |
| 12432 node.returnType = _newNode as TypeName; |
| 12433 return true; |
| 12434 } else if (identical(node.parameters, _oldNode)) { |
| 12435 node.parameters = _newNode as FormalParameterList; |
| 12436 return true; |
| 12437 } |
| 12438 return visitNormalFormalParameter(node); |
| 12439 } |
| 12440 |
| 12441 @override |
| 12442 bool visitHideCombinator(HideCombinator node) { |
| 12443 if (_replaceInList(node.hiddenNames)) { |
| 12444 return true; |
| 12445 } |
| 12446 return visitNode(node); |
| 12447 } |
| 12448 |
| 12449 @override |
| 12450 bool visitIfStatement(IfStatement node) { |
| 12451 if (identical(node.condition, _oldNode)) { |
| 12452 node.condition = _newNode as Expression; |
| 12453 return true; |
| 12454 } else if (identical(node.thenStatement, _oldNode)) { |
| 12455 node.thenStatement = _newNode as Statement; |
| 12456 return true; |
| 12457 } else if (identical(node.elseStatement, _oldNode)) { |
| 12458 node.elseStatement = _newNode as Statement; |
| 12459 return true; |
| 12460 } |
| 12461 return visitNode(node); |
| 12462 } |
| 12463 |
| 12464 @override |
| 12465 bool visitImplementsClause(ImplementsClause node) { |
| 12466 if (_replaceInList(node.interfaces)) { |
| 12467 return true; |
| 12468 } |
| 12469 return visitNode(node); |
| 12470 } |
| 12471 |
| 12472 @override |
| 12473 bool visitImportDirective(ImportDirective node) { |
| 12474 if (identical(node.prefix, _oldNode)) { |
| 12475 node.prefix = _newNode as SimpleIdentifier; |
| 12476 return true; |
| 12477 } |
| 12478 return visitNamespaceDirective(node); |
| 12479 } |
| 12480 |
| 12481 @override |
| 12482 bool visitIndexExpression(IndexExpression node) { |
| 12483 if (identical(node.target, _oldNode)) { |
| 12484 node.target = _newNode as Expression; |
| 12485 return true; |
| 12486 } else if (identical(node.index, _oldNode)) { |
| 12487 node.index = _newNode as Expression; |
| 12488 return true; |
| 12489 } |
| 12490 return visitNode(node); |
| 12491 } |
| 12492 |
| 12493 @override |
| 12494 bool visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 12495 if (identical(node.constructorName, _oldNode)) { |
| 12496 node.constructorName = _newNode as ConstructorName; |
| 12497 return true; |
| 12498 } else if (identical(node.argumentList, _oldNode)) { |
| 12499 node.argumentList = _newNode as ArgumentList; |
| 12500 return true; |
| 12501 } |
| 12502 return visitNode(node); |
| 12503 } |
| 12504 |
| 12505 @override |
| 12506 bool visitIntegerLiteral(IntegerLiteral node) => visitNode(node); |
| 12507 |
| 12508 @override |
| 12509 bool visitInterpolationExpression(InterpolationExpression node) { |
| 12510 if (identical(node.expression, _oldNode)) { |
| 12511 node.expression = _newNode as Expression; |
| 12512 return true; |
| 12513 } |
| 12514 return visitNode(node); |
| 12515 } |
| 12516 |
| 12517 @override |
| 12518 bool visitInterpolationString(InterpolationString node) => visitNode(node); |
| 12519 |
| 12520 @override |
| 12521 bool visitIsExpression(IsExpression node) { |
| 12522 if (identical(node.expression, _oldNode)) { |
| 12523 node.expression = _newNode as Expression; |
| 12524 return true; |
| 12525 } else if (identical(node.type, _oldNode)) { |
| 12526 node.type = _newNode as TypeName; |
| 12527 return true; |
| 12528 } |
| 12529 return visitNode(node); |
| 12530 } |
| 12531 |
| 12532 @override |
| 12533 bool visitLabel(Label node) { |
| 12534 if (identical(node.label, _oldNode)) { |
| 12535 node.label = _newNode as SimpleIdentifier; |
| 12536 return true; |
| 12537 } |
| 12538 return visitNode(node); |
| 12539 } |
| 12540 |
| 12541 @override |
| 12542 bool visitLabeledStatement(LabeledStatement node) { |
| 12543 if (identical(node.statement, _oldNode)) { |
| 12544 node.statement = _newNode as Statement; |
| 12545 return true; |
| 12546 } else if (_replaceInList(node.labels)) { |
| 12547 return true; |
| 12548 } |
| 12549 return visitNode(node); |
| 12550 } |
| 12551 |
| 12552 @override |
| 12553 bool visitLibraryDirective(LibraryDirective node) { |
| 12554 if (identical(node.name, _oldNode)) { |
| 12555 node.name = _newNode as LibraryIdentifier; |
| 12556 return true; |
| 12557 } |
| 12558 return visitAnnotatedNode(node); |
| 12559 } |
| 12560 |
| 12561 @override |
| 12562 bool visitLibraryIdentifier(LibraryIdentifier node) { |
| 12563 if (_replaceInList(node.components)) { |
| 12564 return true; |
| 12565 } |
| 12566 return visitNode(node); |
| 12567 } |
| 12568 |
| 12569 @override |
| 12570 bool visitListLiteral(ListLiteral node) { |
| 12571 if (_replaceInList(node.elements)) { |
| 12572 return true; |
| 12573 } |
| 12574 return visitTypedLiteral(node); |
| 12575 } |
| 12576 |
| 12577 @override |
| 12578 bool visitMapLiteral(MapLiteral node) { |
| 12579 if (_replaceInList(node.entries)) { |
| 12580 return true; |
| 12581 } |
| 12582 return visitTypedLiteral(node); |
| 12583 } |
| 12584 |
| 12585 @override |
| 12586 bool visitMapLiteralEntry(MapLiteralEntry node) { |
| 12587 if (identical(node.key, _oldNode)) { |
| 12588 node.key = _newNode as Expression; |
| 12589 return true; |
| 12590 } else if (identical(node.value, _oldNode)) { |
| 12591 node.value = _newNode as Expression; |
| 12592 return true; |
| 12593 } |
| 12594 return visitNode(node); |
| 12595 } |
| 12596 |
| 12597 @override |
| 12598 bool visitMethodDeclaration(MethodDeclaration node) { |
| 12599 if (identical(node.returnType, _oldNode)) { |
| 12600 node.returnType = _newNode as TypeName; |
| 12601 return true; |
| 12602 } else if (identical(node.name, _oldNode)) { |
| 12603 node.name = _newNode as SimpleIdentifier; |
| 12604 return true; |
| 12605 } else if (identical(node.parameters, _oldNode)) { |
| 12606 node.parameters = _newNode as FormalParameterList; |
| 12607 return true; |
| 12608 } else if (identical(node.body, _oldNode)) { |
| 12609 node.body = _newNode as FunctionBody; |
| 12610 return true; |
| 12611 } |
| 12612 return visitAnnotatedNode(node); |
| 12613 } |
| 12614 |
| 12615 @override |
| 12616 bool visitMethodInvocation(MethodInvocation node) { |
| 12617 if (identical(node.target, _oldNode)) { |
| 12618 node.target = _newNode as Expression; |
| 12619 return true; |
| 12620 } else if (identical(node.methodName, _oldNode)) { |
| 12621 node.methodName = _newNode as SimpleIdentifier; |
| 12622 return true; |
| 12623 } else if (identical(node.argumentList, _oldNode)) { |
| 12624 node.argumentList = _newNode as ArgumentList; |
| 12625 return true; |
| 12626 } |
| 12627 return visitNode(node); |
| 12628 } |
| 12629 |
| 12630 @override |
| 12631 bool visitNamedExpression(NamedExpression node) { |
| 12632 if (identical(node.name, _oldNode)) { |
| 12633 node.name = _newNode as Label; |
| 12634 return true; |
| 12635 } else if (identical(node.expression, _oldNode)) { |
| 12636 node.expression = _newNode as Expression; |
| 12637 return true; |
| 12638 } |
| 12639 return visitNode(node); |
| 12640 } |
| 12641 |
| 12642 bool visitNamespaceDirective(NamespaceDirective node) { |
| 12643 if (_replaceInList(node.combinators)) { |
| 12644 return true; |
| 12645 } |
| 12646 return visitUriBasedDirective(node); |
| 12647 } |
| 12648 |
| 12649 @override |
| 12650 bool visitNativeClause(NativeClause node) { |
| 12651 if (identical(node.name, _oldNode)) { |
| 12652 node.name = _newNode as StringLiteral; |
| 12653 return true; |
| 12654 } |
| 12655 return visitNode(node); |
| 12656 } |
| 12657 |
| 12658 @override |
| 12659 bool visitNativeFunctionBody(NativeFunctionBody node) { |
| 12660 if (identical(node.stringLiteral, _oldNode)) { |
| 12661 node.stringLiteral = _newNode as StringLiteral; |
| 12662 return true; |
| 12663 } |
| 12664 return visitNode(node); |
| 12665 } |
| 12666 |
| 12667 bool visitNode(AstNode node) { |
| 12668 throw new IllegalArgumentException("The old node is not a child of it's pare
nt"); |
| 12669 } |
| 12670 |
| 12671 bool visitNormalFormalParameter(NormalFormalParameter node) { |
| 12672 if (identical(node.documentationComment, _oldNode)) { |
| 12673 node.documentationComment = _newNode as Comment; |
| 12674 return true; |
| 12675 } else if (identical(node.identifier, _oldNode)) { |
| 12676 node.identifier = _newNode as SimpleIdentifier; |
| 12677 return true; |
| 12678 } else if (_replaceInList(node.metadata)) { |
| 12679 return true; |
| 12680 } |
| 12681 return visitNode(node); |
| 12682 } |
| 12683 |
| 12684 @override |
| 12685 bool visitNullLiteral(NullLiteral node) => visitNode(node); |
| 12686 |
| 12687 @override |
| 12688 bool visitParenthesizedExpression(ParenthesizedExpression node) { |
| 12689 if (identical(node.expression, _oldNode)) { |
| 12690 node.expression = _newNode as Expression; |
| 12691 return true; |
| 12692 } |
| 12693 return visitNode(node); |
| 12694 } |
| 12695 |
| 12696 @override |
| 12697 bool visitPartDirective(PartDirective node) => visitUriBasedDirective(node); |
| 12698 |
| 12699 @override |
| 12700 bool visitPartOfDirective(PartOfDirective node) { |
| 12701 if (identical(node.libraryName, _oldNode)) { |
| 12702 node.libraryName = _newNode as LibraryIdentifier; |
| 12703 return true; |
| 12704 } |
| 12705 return visitAnnotatedNode(node); |
| 12706 } |
| 12707 |
| 12708 @override |
| 12709 bool visitPostfixExpression(PostfixExpression node) { |
| 12710 if (identical(node.operand, _oldNode)) { |
| 12711 node.operand = _newNode as Expression; |
| 12712 return true; |
| 12713 } |
| 12714 return visitNode(node); |
| 12715 } |
| 12716 |
| 12717 @override |
| 12718 bool visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 12719 if (identical(node.prefix, _oldNode)) { |
| 12720 node.prefix = _newNode as SimpleIdentifier; |
| 12721 return true; |
| 12722 } else if (identical(node.identifier, _oldNode)) { |
| 12723 node.identifier = _newNode as SimpleIdentifier; |
| 12724 return true; |
| 12725 } |
| 12726 return visitNode(node); |
| 12727 } |
| 12728 |
| 12729 @override |
| 12730 bool visitPrefixExpression(PrefixExpression node) { |
| 12731 if (identical(node.operand, _oldNode)) { |
| 12732 node.operand = _newNode as Expression; |
| 12733 return true; |
| 12734 } |
| 12735 return visitNode(node); |
| 12736 } |
| 12737 |
| 12738 @override |
| 12739 bool visitPropertyAccess(PropertyAccess node) { |
| 12740 if (identical(node.target, _oldNode)) { |
| 12741 node.target = _newNode as Expression; |
| 12742 return true; |
| 12743 } else if (identical(node.propertyName, _oldNode)) { |
| 12744 node.propertyName = _newNode as SimpleIdentifier; |
| 12745 return true; |
| 12746 } |
| 12747 return visitNode(node); |
| 12748 } |
| 12749 |
| 12750 @override |
| 12751 bool visitRedirectingConstructorInvocation(RedirectingConstructorInvocation no
de) { |
| 12752 if (identical(node.constructorName, _oldNode)) { |
| 12753 node.constructorName = _newNode as SimpleIdentifier; |
| 12754 return true; |
| 12755 } else if (identical(node.argumentList, _oldNode)) { |
| 12756 node.argumentList = _newNode as ArgumentList; |
| 12757 return true; |
| 12758 } |
| 12759 return visitNode(node); |
| 12760 } |
| 12761 |
| 12762 @override |
| 12763 bool visitRethrowExpression(RethrowExpression node) => visitNode(node); |
| 12764 |
| 12765 @override |
| 12766 bool visitReturnStatement(ReturnStatement node) { |
| 12767 if (identical(node.expression, _oldNode)) { |
| 12768 node.expression = _newNode as Expression; |
| 12769 return true; |
| 12770 } |
| 12771 return visitNode(node); |
| 12772 } |
| 12773 |
| 12774 @override |
| 12775 bool visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); |
| 12776 |
| 12777 @override |
| 12778 bool visitShowCombinator(ShowCombinator node) { |
| 12779 if (_replaceInList(node.shownNames)) { |
| 12780 return true; |
| 12781 } |
| 12782 return visitNode(node); |
| 12783 } |
| 12784 |
| 12785 @override |
| 12786 bool visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 12787 if (identical(node.type, _oldNode)) { |
| 12788 node.type = _newNode as TypeName; |
| 12789 return true; |
| 12790 } |
| 12791 return visitNormalFormalParameter(node); |
| 12792 } |
| 12793 |
| 12794 @override |
| 12795 bool visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node); |
| 12796 |
| 12797 @override |
| 12798 bool visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node); |
| 12799 |
| 12800 @override |
| 12801 bool visitStringInterpolation(StringInterpolation node) { |
| 12802 if (_replaceInList(node.elements)) { |
| 12803 return true; |
| 12804 } |
| 12805 return visitNode(node); |
| 12806 } |
| 12807 |
| 12808 @override |
| 12809 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 12810 if (identical(node.constructorName, _oldNode)) { |
| 12811 node.constructorName = _newNode as SimpleIdentifier; |
| 12812 return true; |
| 12813 } else if (identical(node.argumentList, _oldNode)) { |
| 12814 node.argumentList = _newNode as ArgumentList; |
| 12815 return true; |
| 12816 } |
| 12817 return visitNode(node); |
| 12818 } |
| 12819 |
| 12820 @override |
| 12821 bool visitSuperExpression(SuperExpression node) => visitNode(node); |
| 12822 |
| 12823 @override |
| 12824 bool visitSwitchCase(SwitchCase node) { |
| 12825 if (identical(node.expression, _oldNode)) { |
| 12826 node.expression = _newNode as Expression; |
| 12827 return true; |
| 12828 } |
| 12829 return visitSwitchMember(node); |
| 12830 } |
| 12831 |
| 12832 @override |
| 12833 bool visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node); |
| 12834 |
| 12835 bool visitSwitchMember(SwitchMember node) { |
| 12836 if (_replaceInList(node.labels)) { |
| 12837 return true; |
| 12838 } else if (_replaceInList(node.statements)) { |
| 12839 return true; |
| 12840 } |
| 12841 return visitNode(node); |
| 12842 } |
| 12843 |
| 12844 @override |
| 12845 bool visitSwitchStatement(SwitchStatement node) { |
| 12846 if (identical(node.expression, _oldNode)) { |
| 12847 node.expression = _newNode as Expression; |
| 12848 return true; |
| 12849 } else if (_replaceInList(node.members)) { |
| 12850 return true; |
| 12851 } |
| 12852 return visitNode(node); |
| 12853 } |
| 12854 |
| 12855 @override |
| 12856 bool visitSymbolLiteral(SymbolLiteral node) => visitNode(node); |
| 12857 |
| 12858 @override |
| 12859 bool visitThisExpression(ThisExpression node) => visitNode(node); |
| 12860 |
| 12861 @override |
| 12862 bool visitThrowExpression(ThrowExpression node) { |
| 12863 if (identical(node.expression, _oldNode)) { |
| 12864 node.expression = _newNode as Expression; |
| 12865 return true; |
| 12866 } |
| 12867 return visitNode(node); |
| 12868 } |
| 12869 |
| 12870 @override |
| 12871 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 12872 if (identical(node.variables, _oldNode)) { |
| 12873 node.variables = _newNode as VariableDeclarationList; |
| 12874 return true; |
| 12875 } |
| 12876 return visitAnnotatedNode(node); |
| 12877 } |
| 12878 |
| 12879 @override |
| 12880 bool visitTryStatement(TryStatement node) { |
| 12881 if (identical(node.body, _oldNode)) { |
| 12882 node.body = _newNode as Block; |
| 12883 return true; |
| 12884 } else if (identical(node.finallyBlock, _oldNode)) { |
| 12885 node.finallyBlock = _newNode as Block; |
| 12886 return true; |
| 12887 } else if (_replaceInList(node.catchClauses)) { |
| 12888 return true; |
| 12889 } |
| 12890 return visitNode(node); |
| 12891 } |
| 12892 |
| 12893 @override |
| 12894 bool visitTypeArgumentList(TypeArgumentList node) { |
| 12895 if (_replaceInList(node.arguments)) { |
| 12896 return true; |
| 12897 } |
| 12898 return visitNode(node); |
| 12899 } |
| 12900 |
| 12901 bool visitTypedLiteral(TypedLiteral node) { |
| 12902 if (identical(node.typeArguments, _oldNode)) { |
| 12903 node.typeArguments = _newNode as TypeArgumentList; |
| 12904 return true; |
| 12905 } |
| 12906 return visitNode(node); |
| 12907 } |
| 12908 |
| 12909 @override |
| 12910 bool visitTypeName(TypeName node) { |
| 12911 if (identical(node.name, _oldNode)) { |
| 12912 node.name = _newNode as Identifier; |
| 12913 return true; |
| 12914 } else if (identical(node.typeArguments, _oldNode)) { |
| 12915 node.typeArguments = _newNode as TypeArgumentList; |
| 12916 return true; |
| 12917 } |
| 12918 return visitNode(node); |
| 12919 } |
| 12920 |
| 12921 @override |
| 12922 bool visitTypeParameter(TypeParameter node) { |
| 12923 if (identical(node.name, _oldNode)) { |
| 12924 node.name = _newNode as SimpleIdentifier; |
| 12925 return true; |
| 12926 } else if (identical(node.bound, _oldNode)) { |
| 12927 node.bound = _newNode as TypeName; |
| 12928 return true; |
| 12929 } |
| 12930 return visitNode(node); |
| 12931 } |
| 12932 |
| 12933 @override |
| 12934 bool visitTypeParameterList(TypeParameterList node) { |
| 12935 if (_replaceInList(node.typeParameters)) { |
| 12936 return true; |
| 12937 } |
| 12938 return visitNode(node); |
| 12939 } |
| 12940 |
| 12941 bool visitUriBasedDirective(UriBasedDirective node) { |
| 12942 if (identical(node.uri, _oldNode)) { |
| 12943 node.uri = _newNode as StringLiteral; |
| 12944 return true; |
| 12945 } |
| 12946 return visitAnnotatedNode(node); |
| 12947 } |
| 12948 |
| 12949 @override |
| 12950 bool visitVariableDeclaration(VariableDeclaration node) { |
| 12951 if (identical(node.name, _oldNode)) { |
| 12952 node.name = _newNode as SimpleIdentifier; |
| 12953 return true; |
| 12954 } else if (identical(node.initializer, _oldNode)) { |
| 12955 node.initializer = _newNode as Expression; |
| 12956 return true; |
| 12957 } |
| 12958 return visitAnnotatedNode(node); |
| 12959 } |
| 12960 |
| 12961 @override |
| 12962 bool visitVariableDeclarationList(VariableDeclarationList node) { |
| 12963 if (identical(node.type, _oldNode)) { |
| 12964 node.type = _newNode as TypeName; |
| 12965 return true; |
| 12966 } else if (_replaceInList(node.variables)) { |
| 12967 return true; |
| 12968 } |
| 12969 return visitNode(node); |
| 12970 } |
| 12971 |
| 12972 @override |
| 12973 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 12974 if (identical(node.variables, _oldNode)) { |
| 12975 node.variables = _newNode as VariableDeclarationList; |
| 12976 return true; |
| 12977 } |
| 12978 return visitNode(node); |
| 12979 } |
| 12980 |
| 12981 @override |
| 12982 bool visitWhileStatement(WhileStatement node) { |
| 12983 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 } |
| 12990 return visitNode(node); |
| 12991 } |
| 12992 |
| 12993 @override |
| 12994 bool visitWithClause(WithClause node) { |
| 12995 if (_replaceInList(node.mixinTypes)) { |
| 12996 return true; |
| 12997 } |
| 12998 return visitNode(node); |
| 12999 } |
| 13000 |
| 13001 @override |
| 13002 bool visitYieldStatement(YieldStatement node) { |
| 13003 if (identical(node.expression, _oldNode)) { |
| 13004 node.expression = _newNode as Expression; |
| 13005 } |
| 13006 return visitNode(node); |
| 13007 } |
| 13008 |
| 13009 bool _replaceInList(NodeList list) { |
| 13010 int count = list.length; |
| 13011 for (int i = 0; i < count; i++) { |
| 13012 if (identical(_oldNode, list[i])) { |
| 13013 javaListSet(list, i, _newNode); |
| 13014 return true; |
| 13015 } |
| 13016 } |
| 13017 return false; |
| 13018 } |
| 13019 } |
| 13020 |
| 13021 /** |
| 13022 * The abstract class `NormalFormalParameter` defines the behavior common to for
mal parameters |
| 13023 * that are required (are not optional). |
| 13024 * |
| 13025 * <pre> |
| 13026 * normalFormalParameter ::= |
| 13027 * [FunctionTypedFormalParameter] |
| 13028 * | [FieldFormalParameter] |
| 13029 * | [SimpleFormalParameter] |
| 13030 * </pre> |
| 13031 */ |
| 13032 abstract class NormalFormalParameter extends FormalParameter { |
| 13033 /** |
| 13034 * The documentation comment associated with this parameter, or `null` if this
parameter |
| 13035 * does not have a documentation comment associated with it. |
| 13036 */ |
| 13037 Comment _comment; |
| 13038 |
| 13039 /** |
| 13040 * The annotations associated with this parameter. |
| 13041 */ |
| 13042 NodeList<Annotation> _metadata; |
| 13043 |
| 13044 /** |
| 13045 * The name of the parameter being declared. |
| 13046 */ |
| 13047 SimpleIdentifier _identifier; |
| 13048 |
| 13049 /** |
| 13050 * Initialize a newly created formal parameter. |
| 13051 * |
| 13052 * @param comment the documentation comment associated with this parameter |
| 13053 * @param metadata the annotations associated with this parameter |
| 13054 * @param identifier the name of the parameter being declared |
| 13055 */ |
| 13056 NormalFormalParameter(Comment comment, List<Annotation> metadata, SimpleIdenti
fier identifier) { |
| 13057 this._metadata = new NodeList<Annotation>(this); |
| 13058 this._comment = becomeParentOf(comment); |
| 13059 this._metadata.addAll(metadata); |
| 13060 this._identifier = becomeParentOf(identifier); |
| 13061 } |
| 13062 |
| 13063 /** |
| 13064 * Return the documentation comment associated with this parameter, or `null`
if this |
| 13065 * parameter does not have a documentation comment associated with it. |
| 13066 * |
| 13067 * @return the documentation comment associated with this parameter |
| 13068 */ |
| 13069 Comment get documentationComment => _comment; |
| 13070 |
| 13071 @override |
| 13072 SimpleIdentifier get identifier => _identifier; |
| 13073 |
| 13074 @override |
| 13075 ParameterKind get kind { |
| 13076 AstNode parent = this.parent; |
| 13077 if (parent is DefaultFormalParameter) { |
| 13078 return parent.kind; |
| 13079 } |
| 13080 return ParameterKind.REQUIRED; |
| 13081 } |
| 13082 |
| 13083 /** |
| 13084 * Return the annotations associated with this parameter. |
| 13085 * |
| 13086 * @return the annotations associated with this parameter |
| 13087 */ |
| 13088 NodeList<Annotation> get metadata => _metadata; |
| 13089 |
| 13090 /** |
| 13091 * Set the documentation comment associated with this parameter to the given c
omment |
| 13092 * |
| 13093 * @param comment the documentation comment to be associated with this paramet
er |
| 13094 */ |
| 13095 void set documentationComment(Comment comment) { |
| 13096 this._comment = becomeParentOf(comment); |
| 13097 } |
| 13098 |
| 13099 /** |
| 13100 * Set the name of the parameter being declared to the given identifier. |
| 13101 * |
| 13102 * @param identifier the name of the parameter being declared |
| 13103 */ |
| 13104 void set identifier(SimpleIdentifier identifier) { |
| 13105 this._identifier = becomeParentOf(identifier); |
| 13106 } |
| 13107 |
| 13108 /** |
| 13109 * Set the metadata associated with this node to the given metadata. |
| 13110 * |
| 13111 * @param metadata the metadata to be associated with this node |
| 13112 */ |
| 13113 void set metadata(List<Annotation> metadata) { |
| 13114 this._metadata.clear(); |
| 13115 this._metadata.addAll(metadata); |
| 13116 } |
| 13117 |
| 13118 @override |
| 13119 void visitChildren(AstVisitor visitor) { |
| 13120 // |
| 13121 // Note that subclasses are responsible for visiting the identifier because
they often need to |
| 13122 // visit other nodes before visiting the identifier. |
| 13123 // |
| 13124 if (_commentIsBeforeAnnotations()) { |
| 13125 safelyVisitChild(_comment, visitor); |
| 13126 _metadata.accept(visitor); |
| 13127 } else { |
| 13128 for (AstNode child in sortedCommentAndAnnotations) { |
| 13129 child.accept(visitor); |
| 13130 } |
| 13131 } |
| 13132 } |
| 13133 |
| 13134 /** |
| 13135 * Return `true` if the comment is lexically before any annotations. |
| 13136 * |
| 13137 * @return `true` if the comment is lexically before any annotations |
| 13138 */ |
| 13139 bool _commentIsBeforeAnnotations() { |
| 13140 if (_comment == null || _metadata.isEmpty) { |
| 13141 return true; |
| 13142 } |
| 13143 Annotation firstAnnotation = _metadata[0]; |
| 13144 return _comment.offset < firstAnnotation.offset; |
| 13145 } |
| 13146 |
| 13147 /** |
| 13148 * Return an array containing the comment and annotations associated with this
parameter, sorted |
| 13149 * in lexical order. |
| 13150 * |
| 13151 * @return the comment and annotations associated with this parameter in the o
rder in which they |
| 13152 * appeared in the original source |
| 13153 */ |
| 13154 List<AstNode> get sortedCommentAndAnnotations { |
| 13155 List<AstNode> childList = new List<AstNode>(); |
| 13156 childList.add(_comment); |
| 13157 childList.addAll(_metadata); |
| 13158 List<AstNode> children = new List.from(childList); |
| 13159 children.sort(AstNode.LEXICAL_ORDER); |
| 13160 return children; |
| 13161 } |
| 13162 } |
| 13163 |
| 13164 /** |
| 13165 * Instances of the class `NullLiteral` represent a null literal expression. |
| 13166 * |
| 13167 * <pre> |
| 13168 * nullLiteral ::= |
| 13169 * 'null' |
| 13170 * </pre> |
| 13171 */ |
| 13172 class NullLiteral extends Literal { |
| 13173 /** |
| 13174 * The token representing the literal. |
| 13175 */ |
| 13176 Token literal; |
| 13177 |
| 13178 /** |
| 13179 * Initialize a newly created null literal. |
| 13180 * |
| 13181 * @param token the token representing the literal |
| 13182 */ |
| 13183 NullLiteral(Token token) { |
| 13184 this.literal = token; |
| 13185 } |
| 13186 |
| 13187 @override |
| 13188 accept(AstVisitor visitor) => visitor.visitNullLiteral(this); |
| 13189 |
| 13190 @override |
| 13191 Token get beginToken => literal; |
| 13192 |
| 13193 @override |
| 13194 Token get endToken => literal; |
| 13195 |
| 13196 @override |
| 13197 void visitChildren(AstVisitor visitor) { |
| 13198 } |
| 13199 } |
| 13200 |
| 13201 /** |
| 13202 * Instances of the class `ParenthesizedExpression` represent a parenthesized ex
pression. |
| 13203 * |
| 13204 * <pre> |
| 13205 * parenthesizedExpression ::= |
| 13206 * '(' [Expression] ')' |
| 13207 * </pre> |
| 13208 */ |
| 13209 class ParenthesizedExpression extends Expression { |
| 13210 /** |
| 13211 * The left parenthesis. |
| 13212 */ |
| 13213 Token _leftParenthesis; |
| 13214 |
| 13215 /** |
| 13216 * The expression within the parentheses. |
| 13217 */ |
| 13218 Expression _expression; |
| 13219 |
| 13220 /** |
| 13221 * The right parenthesis. |
| 13222 */ |
| 13223 Token _rightParenthesis; |
| 13224 |
| 13225 /** |
| 13226 * Initialize a newly created parenthesized expression. |
| 13227 * |
| 13228 * @param leftParenthesis the left parenthesis |
| 13229 * @param expression the expression within the parentheses |
| 13230 * @param rightParenthesis the right parenthesis |
| 13231 */ |
| 13232 ParenthesizedExpression(Token leftParenthesis, Expression expression, Token ri
ghtParenthesis) { |
| 13233 this._leftParenthesis = leftParenthesis; |
| 13234 this._expression = becomeParentOf(expression); |
| 13235 this._rightParenthesis = rightParenthesis; |
| 13236 } |
| 13237 |
| 13238 @override |
| 13239 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this); |
| 13240 |
| 13241 @override |
| 13242 Token get beginToken => _leftParenthesis; |
| 13243 |
| 13244 @override |
| 13245 Token get endToken => _rightParenthesis; |
| 13246 |
| 13247 /** |
| 13248 * Return the expression within the parentheses. |
| 13249 * |
| 13250 * @return the expression within the parentheses |
| 13251 */ |
| 13252 Expression get expression => _expression; |
| 13253 |
| 13254 /** |
| 13255 * Return the left parenthesis. |
| 13256 * |
| 13257 * @return the left parenthesis |
| 13258 */ |
| 13259 Token get leftParenthesis => _leftParenthesis; |
| 13260 |
| 13261 @override |
| 13262 int get precedence => 15; |
| 13263 |
| 13264 /** |
| 13265 * Return the right parenthesis. |
| 13266 * |
| 13267 * @return the right parenthesis |
| 13268 */ |
| 13269 Token get rightParenthesis => _rightParenthesis; |
| 13270 |
| 13271 /** |
| 13272 * Set the expression within the parentheses to the given expression. |
| 13273 * |
| 13274 * @param expression the expression within the parentheses |
| 13275 */ |
| 13276 void set expression(Expression expression) { |
| 13277 this._expression = becomeParentOf(expression); |
| 13278 } |
| 13279 |
| 13280 /** |
| 13281 * Set the left parenthesis to the given token. |
| 13282 * |
| 13283 * @param parenthesis the left parenthesis |
| 13284 */ |
| 13285 void set leftParenthesis(Token parenthesis) { |
| 13286 _leftParenthesis = parenthesis; |
| 13287 } |
| 13288 |
| 13289 /** |
| 13290 * Set the right parenthesis to the given token. |
| 13291 * |
| 13292 * @param parenthesis the right parenthesis |
| 13293 */ |
| 13294 void set rightParenthesis(Token parenthesis) { |
| 13295 _rightParenthesis = parenthesis; |
| 13296 } |
| 13297 |
| 13298 @override |
| 13299 void visitChildren(AstVisitor visitor) { |
| 13300 safelyVisitChild(_expression, visitor); |
| 13301 } |
| 13302 } |
| 13303 |
| 13304 /** |
| 13305 * Instances of the class `PartDirective` represent a part directive. |
| 13306 * |
| 13307 * <pre> |
| 13308 * partDirective ::= |
| 13309 * [Annotation] 'part' [StringLiteral] ';' |
| 13310 * </pre> |
| 13311 */ |
| 13312 class PartDirective extends UriBasedDirective { |
| 13313 /** |
| 13314 * The token representing the 'part' token. |
| 13315 */ |
| 13316 Token partToken; |
| 13317 |
| 13318 /** |
| 13319 * The semicolon terminating the directive. |
| 13320 */ |
| 13321 Token semicolon; |
| 13322 |
| 13323 /** |
| 13324 * Initialize a newly created part directive. |
| 13325 * |
| 13326 * @param comment the documentation comment associated with this directive |
| 13327 * @param metadata the annotations associated with the directive |
| 13328 * @param partToken the token representing the 'part' token |
| 13329 * @param partUri the URI of the part being included |
| 13330 * @param semicolon the semicolon terminating the directive |
| 13331 */ |
| 13332 PartDirective(Comment comment, List<Annotation> metadata, this.partToken, Stri
ngLiteral partUri, this.semicolon) : super(comment, metadata, partUri); |
| 13333 |
| 13334 @override |
| 13335 accept(AstVisitor visitor) => visitor.visitPartDirective(this); |
| 13336 |
| 13337 @override |
| 13338 Token get endToken => semicolon; |
| 13339 |
| 13340 @override |
| 13341 Token get keyword => partToken; |
| 13342 |
| 13343 @override |
| 13344 CompilationUnitElement get uriElement => element as CompilationUnitElement; |
| 13345 |
| 13346 @override |
| 13347 Token get firstTokenAfterCommentAndMetadata => partToken; |
| 13348 } |
| 13349 |
| 13350 /** |
| 13351 * Instances of the class `PartOfDirective` represent a part-of directive. |
| 13352 * |
| 13353 * <pre> |
| 13354 * partOfDirective ::= |
| 13355 * [Annotation] 'part' 'of' [Identifier] ';' |
| 13356 * </pre> |
| 13357 */ |
| 13358 class PartOfDirective extends Directive { |
| 13359 /** |
| 13360 * The token representing the 'part' token. |
| 13361 */ |
| 13362 Token partToken; |
| 13363 |
| 13364 /** |
| 13365 * The token representing the 'of' token. |
| 13366 */ |
| 13367 Token ofToken; |
| 13368 |
| 13369 /** |
| 13370 * The name of the library that the containing compilation unit is part of. |
| 13371 */ |
| 13372 LibraryIdentifier _libraryName; |
| 13373 |
| 13374 /** |
| 13375 * The semicolon terminating the directive. |
| 13376 */ |
| 13377 Token semicolon; |
| 13378 |
| 13379 /** |
| 13380 * Initialize a newly created part-of directive. |
| 13381 * |
| 13382 * @param comment the documentation comment associated with this directive |
| 13383 * @param metadata the annotations associated with the directive |
| 13384 * @param partToken the token representing the 'part' token |
| 13385 * @param ofToken the token representing the 'of' token |
| 13386 * @param libraryName the name of the library that the containing compilation
unit is part of |
| 13387 * @param semicolon the semicolon terminating the directive |
| 13388 */ |
| 13389 PartOfDirective(Comment comment, List<Annotation> metadata, this.partToken, th
is.ofToken, LibraryIdentifier libraryName, this.semicolon) : super(comment, meta
data) { |
| 13390 this._libraryName = becomeParentOf(libraryName); |
| 13391 } |
| 13392 |
| 13393 @override |
| 13394 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this); |
| 13395 |
| 13396 @override |
| 13397 Token get endToken => semicolon; |
| 13398 |
| 13399 @override |
| 13400 Token get keyword => partToken; |
| 13401 |
| 13402 /** |
| 13403 * Return the name of the library that the containing compilation unit is part
of. |
| 13404 * |
| 13405 * @return the name of the library that the containing compilation unit is par
t of |
| 13406 */ |
| 13407 LibraryIdentifier get libraryName => _libraryName; |
| 13408 |
| 13409 /** |
| 13410 * Set the name of the library that the containing compilation unit is part of
to the given name. |
| 13411 * |
| 13412 * @param libraryName the name of the library that the containing compilation
unit is part of |
| 13413 */ |
| 13414 void set libraryName(LibraryIdentifier libraryName) { |
| 13415 this._libraryName = becomeParentOf(libraryName); |
| 13416 } |
| 13417 |
| 13418 @override |
| 13419 void visitChildren(AstVisitor visitor) { |
| 13420 super.visitChildren(visitor); |
| 13421 safelyVisitChild(_libraryName, visitor); |
| 13422 } |
| 13423 |
| 13424 @override |
| 13425 Token get firstTokenAfterCommentAndMetadata => partToken; |
| 13426 } |
| 13427 |
| 13428 /** |
| 13429 * Instances of the class `PostfixExpression` represent a postfix unary expressi
on. |
| 13430 * |
| 13431 * <pre> |
| 13432 * postfixExpression ::= |
| 13433 * [Expression] [Token] |
| 13434 * </pre> |
| 13435 */ |
| 13436 class PostfixExpression extends Expression { |
| 13437 /** |
| 13438 * The expression computing the operand for the operator. |
| 13439 */ |
| 13440 Expression _operand; |
| 13441 |
| 13442 /** |
| 13443 * The postfix operator being applied to the operand. |
| 13444 */ |
| 13445 Token operator; |
| 13446 |
| 13447 /** |
| 13448 * The element associated with this the operator based on the propagated type
of the operand, or |
| 13449 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13450 * or if the operator could not be resolved. |
| 13451 */ |
| 13452 MethodElement _propagatedElement; |
| 13453 |
| 13454 /** |
| 13455 * The element associated with the operator based on the static type of the op
erand, or |
| 13456 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13457 * or if the operator could not be resolved. |
| 13458 */ |
| 13459 MethodElement _staticElement; |
| 13460 |
| 13461 /** |
| 13462 * Initialize a newly created postfix expression. |
| 13463 * |
| 13464 * @param operand the expression computing the operand for the operator |
| 13465 * @param operator the postfix operator being applied to the operand |
| 13466 */ |
| 13467 PostfixExpression(Expression operand, this.operator) { |
| 13468 this._operand = becomeParentOf(operand); |
| 13469 } |
| 13470 |
| 13471 @override |
| 13472 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this); |
| 13473 |
| 13474 @override |
| 13475 Token get beginToken => _operand.beginToken; |
| 13476 |
| 13477 /** |
| 13478 * Return the best element available for this operator. If resolution was able
to find a better |
| 13479 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 13480 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 13481 * then `null` will be returned. |
| 13482 * |
| 13483 * @return the best element available for this operator |
| 13484 */ |
| 13485 MethodElement get bestElement { |
| 13486 MethodElement element = propagatedElement; |
| 13487 if (element == null) { |
| 13488 element = staticElement; |
| 13489 } |
| 13490 return element; |
| 13491 } |
| 13492 |
| 13493 @override |
| 13494 Token get endToken => operator; |
| 13495 |
| 13496 /** |
| 13497 * Return the expression computing the operand for the operator. |
| 13498 * |
| 13499 * @return the expression computing the operand for the operator |
| 13500 */ |
| 13501 Expression get operand => _operand; |
| 13502 |
| 13503 @override |
| 13504 int get precedence => 15; |
| 13505 |
| 13506 /** |
| 13507 * Return the element associated with the operator based on the propagated typ
e of the operand, or |
| 13508 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13509 * or if the operator could not be resolved. One example of the latter case is
an operator that is |
| 13510 * not defined for the type of the operand. |
| 13511 * |
| 13512 * @return the element associated with the operator |
| 13513 */ |
| 13514 MethodElement get propagatedElement => _propagatedElement; |
| 13515 |
| 13516 /** |
| 13517 * Return the element associated with the operator based on the static type of
the operand, or |
| 13518 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13519 * or if the operator could not be resolved. One example of the latter case is
an operator that is |
| 13520 * not defined for the type of the operand. |
| 13521 * |
| 13522 * @return the element associated with the operator |
| 13523 */ |
| 13524 MethodElement get staticElement => _staticElement; |
| 13525 |
| 13526 /** |
| 13527 * Set the expression computing the operand for the operator to the given expr
ession. |
| 13528 * |
| 13529 * @param expression the expression computing the operand for the operator |
| 13530 */ |
| 13531 void set operand(Expression expression) { |
| 13532 _operand = becomeParentOf(expression); |
| 13533 } |
| 13534 |
| 13535 /** |
| 13536 * Set the element associated with the operator based on the propagated type o
f the operand to the |
| 13537 * given element. |
| 13538 * |
| 13539 * @param element the element to be associated with the operator |
| 13540 */ |
| 13541 void set propagatedElement(MethodElement element) { |
| 13542 _propagatedElement = element; |
| 13543 } |
| 13544 |
| 13545 /** |
| 13546 * Set the element associated with the operator based on the static type of th
e operand to the |
| 13547 * given element. |
| 13548 * |
| 13549 * @param element the element to be associated with the operator |
| 13550 */ |
| 13551 void set staticElement(MethodElement element) { |
| 13552 _staticElement = element; |
| 13553 } |
| 13554 |
| 13555 @override |
| 13556 void visitChildren(AstVisitor visitor) { |
| 13557 safelyVisitChild(_operand, visitor); |
| 13558 } |
| 13559 |
| 13560 /** |
| 13561 * If the AST structure has been resolved, and the function being invoked is k
nown based on |
| 13562 * propagated type information, then return the parameter element representing
the parameter to |
| 13563 * which the value of the operand will be bound. Otherwise, return `null`. |
| 13564 * |
| 13565 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 13566 * |
| 13567 * @return the parameter element representing the parameter to which the value
of the right |
| 13568 * operand will be bound |
| 13569 */ |
| 13570 ParameterElement get propagatedParameterElementForOperand { |
| 13571 if (_propagatedElement == null) { |
| 13572 return null; |
| 13573 } |
| 13574 List<ParameterElement> parameters = _propagatedElement.parameters; |
| 13575 if (parameters.length < 1) { |
| 13576 return null; |
| 13577 } |
| 13578 return parameters[0]; |
| 13579 } |
| 13580 |
| 13581 /** |
| 13582 * If the AST structure has been resolved, and the function being invoked is k
nown based on static |
| 13583 * type information, then return the parameter element representing the parame
ter to which the |
| 13584 * value of the operand will be bound. Otherwise, return `null`. |
| 13585 * |
| 13586 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 13587 * |
| 13588 * @return the parameter element representing the parameter to which the value
of the right |
| 13589 * operand will be bound |
| 13590 */ |
| 13591 ParameterElement get staticParameterElementForOperand { |
| 13592 if (_staticElement == null) { |
| 13593 return null; |
| 13594 } |
| 13595 List<ParameterElement> parameters = _staticElement.parameters; |
| 13596 if (parameters.length < 1) { |
| 13597 return null; |
| 13598 } |
| 13599 return parameters[0]; |
| 13600 } |
| 13601 } |
| 13602 |
| 13603 /** |
| 13604 * Instances of the class `PrefixExpression` represent a prefix unary expression
. |
| 13605 * |
| 13606 * <pre> |
| 13607 * prefixExpression ::= |
| 13608 * [Token] [Expression] |
| 13609 * </pre> |
| 13610 */ |
| 13611 class PrefixExpression extends Expression { |
| 13612 /** |
| 13613 * The prefix operator being applied to the operand. |
| 13614 */ |
| 13615 Token operator; |
| 13616 |
| 13617 /** |
| 13618 * The expression computing the operand for the operator. |
| 13619 */ |
| 13620 Expression _operand; |
| 13621 |
| 13622 /** |
| 13623 * The element associated with the operator based on the static type of the op
erand, or |
| 13624 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13625 * or if the operator could not be resolved. |
| 13626 */ |
| 13627 MethodElement _staticElement; |
| 13628 |
| 13629 /** |
| 13630 * The element associated with the operator based on the propagated type of th
e operand, or |
| 13631 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13632 * or if the operator could not be resolved. |
| 13633 */ |
| 13634 MethodElement _propagatedElement; |
| 13635 |
| 13636 /** |
| 13637 * Initialize a newly created prefix expression. |
| 13638 * |
| 13639 * @param operator the prefix operator being applied to the operand |
| 13640 * @param operand the expression computing the operand for the operator |
| 13641 */ |
| 13642 PrefixExpression(this.operator, Expression operand) { |
| 13643 this._operand = becomeParentOf(operand); |
| 13644 } |
| 13645 |
| 13646 @override |
| 13647 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this); |
| 13648 |
| 13649 @override |
| 13650 Token get beginToken => operator; |
| 13651 |
| 13652 /** |
| 13653 * Return the best element available for this operator. If resolution was able
to find a better |
| 13654 * element based on type propagation, that element will be returned. Otherwise
, the element found |
| 13655 * using the result of static analysis will be returned. If resolution has not
been performed, |
| 13656 * then `null` will be returned. |
| 13657 * |
| 13658 * @return the best element available for this operator |
| 13659 */ |
| 13660 MethodElement get bestElement { |
| 13661 MethodElement element = propagatedElement; |
| 13662 if (element == null) { |
| 13663 element = staticElement; |
| 13664 } |
| 13665 return element; |
| 13666 } |
| 13667 |
| 13668 @override |
| 13669 Token get endToken => _operand.endToken; |
| 13670 |
| 13671 /** |
| 13672 * Return the expression computing the operand for the operator. |
| 13673 * |
| 13674 * @return the expression computing the operand for the operator |
| 13675 */ |
| 13676 Expression get operand => _operand; |
| 13677 |
| 13678 @override |
| 13679 int get precedence => 14; |
| 13680 |
| 13681 /** |
| 13682 * Return the element associated with the operator based on the propagated typ
e of the operand, or |
| 13683 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13684 * or if the operator could not be resolved. One example of the latter case is
an operator that is |
| 13685 * not defined for the type of the operand. |
| 13686 * |
| 13687 * @return the element associated with the operator |
| 13688 */ |
| 13689 MethodElement get propagatedElement => _propagatedElement; |
| 13690 |
| 13691 /** |
| 13692 * Return the element associated with the operator based on the static type of
the operand, or |
| 13693 * `null` if the AST structure has not been resolved, if the operator is not u
ser definable, |
| 13694 * or if the operator could not be resolved. One example of the latter case is
an operator that is |
| 13695 * not defined for the type of the operand. |
| 13696 * |
| 13697 * @return the element associated with the operator |
| 13698 */ |
| 13699 MethodElement get staticElement => _staticElement; |
| 13700 |
| 13701 /** |
| 13702 * Set the expression computing the operand for the operator to the given expr
ession. |
| 13703 * |
| 13704 * @param expression the expression computing the operand for the operator |
| 13705 */ |
| 13706 void set operand(Expression expression) { |
| 13707 _operand = becomeParentOf(expression); |
| 13708 } |
| 13709 |
| 13710 /** |
| 13711 * Set the element associated with the operator based on the propagated type o
f the operand to the |
| 13712 * given element. |
| 13713 * |
| 13714 * @param element the element to be associated with the operator |
| 13715 */ |
| 13716 void set propagatedElement(MethodElement element) { |
| 13717 _propagatedElement = element; |
| 13718 } |
| 13719 |
| 13720 /** |
| 13721 * Set the element associated with the operator based on the static type of th
e operand to the |
| 13722 * given element. |
| 13723 * |
| 13724 * @param element the static element to be associated with the operator |
| 13725 */ |
| 13726 void set staticElement(MethodElement element) { |
| 13727 _staticElement = element; |
| 13728 } |
| 13729 |
| 13730 @override |
| 13731 void visitChildren(AstVisitor visitor) { |
| 13732 safelyVisitChild(_operand, visitor); |
| 13733 } |
| 13734 |
| 13735 /** |
| 13736 * If the AST structure has been resolved, and the function being invoked is k
nown based on |
| 13737 * propagated type information, then return the parameter element representing
the parameter to |
| 13738 * which the value of the operand will be bound. Otherwise, return `null`. |
| 13739 * |
| 13740 * This method is only intended to be used by [Expression#getPropagatedParamet
erElement]. |
| 13741 * |
| 13742 * @return the parameter element representing the parameter to which the value
of the right |
| 13743 * operand will be bound |
| 13744 */ |
| 13745 ParameterElement get propagatedParameterElementForOperand { |
| 13746 if (_propagatedElement == null) { |
| 13747 return null; |
| 13748 } |
| 13749 List<ParameterElement> parameters = _propagatedElement.parameters; |
| 13750 if (parameters.length < 1) { |
| 13751 return null; |
| 13752 } |
| 13753 return parameters[0]; |
| 13754 } |
| 13755 |
| 13756 /** |
| 13757 * If the AST structure has been resolved, and the function being invoked is k
nown based on static |
| 13758 * type information, then return the parameter element representing the parame
ter to which the |
| 13759 * value of the operand will be bound. Otherwise, return `null`. |
| 13760 * |
| 13761 * This method is only intended to be used by [Expression#getStaticParameterEl
ement]. |
| 13762 * |
| 13763 * @return the parameter element representing the parameter to which the value
of the right |
| 13764 * operand will be bound |
| 13765 */ |
| 13766 ParameterElement get staticParameterElementForOperand { |
| 13767 if (_staticElement == null) { |
| 13768 return null; |
| 13769 } |
| 13770 List<ParameterElement> parameters = _staticElement.parameters; |
| 13771 if (parameters.length < 1) { |
| 13772 return null; |
| 13773 } |
| 13774 return parameters[0]; |
| 13775 } |
| 13776 } |
| 13777 |
| 13778 /** |
| 13779 * Instances of the class `PrefixedIdentifier` represent either an identifier th
at is prefixed |
| 13780 * or an access to an object property where the target of the property access is
a simple |
| 13781 * identifier. |
| 13782 * |
| 13783 * <pre> |
| 13784 * prefixedIdentifier ::= |
| 13785 * [SimpleIdentifier] '.' [SimpleIdentifier] |
| 13786 * </pre> |
| 13787 */ |
| 13788 class PrefixedIdentifier extends Identifier { |
| 13789 /** |
| 13790 * The prefix associated with the library in which the identifier is defined. |
| 13791 */ |
| 13792 SimpleIdentifier _prefix; |
| 13793 |
| 13794 /** |
| 13795 * The period used to separate the prefix from the identifier. |
| 13796 */ |
| 13797 Token period; |
| 13798 |
| 13799 /** |
| 13800 * The identifier being prefixed. |
| 13801 */ |
| 13802 SimpleIdentifier _identifier; |
| 13803 |
| 13804 /** |
| 13805 * Initialize a newly created prefixed identifier. |
| 13806 * |
| 13807 * @param prefix the identifier being prefixed |
| 13808 * @param period the period used to separate the prefix from the identifier |
| 13809 * @param identifier the prefix associated with the library in which the ident
ifier is defined |
| 13810 */ |
| 13811 PrefixedIdentifier(SimpleIdentifier prefix, this.period, SimpleIdentifier iden
tifier) { |
| 13812 this._prefix = becomeParentOf(prefix); |
| 13813 this._identifier = becomeParentOf(identifier); |
| 13814 } |
| 13815 |
| 13816 @override |
| 13817 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this); |
| 13818 |
| 13819 @override |
| 13820 Token get beginToken => _prefix.beginToken; |
| 13821 |
| 13822 @override |
| 13823 Element get bestElement { |
| 13824 if (_identifier == null) { |
| 13825 return null; |
| 13826 } |
| 13827 return _identifier.bestElement; |
| 13828 } |
| 13829 |
| 13830 @override |
| 13831 Token get endToken => _identifier.endToken; |
| 13832 |
| 13833 /** |
| 13834 * Return the identifier being prefixed. |
| 13835 * |
| 13836 * @return the identifier being prefixed |
| 13837 */ |
| 13838 SimpleIdentifier get identifier => _identifier; |
| 13839 |
| 13840 @override |
| 13841 String get name => "${_prefix.name}.${_identifier.name}"; |
| 13842 |
| 13843 @override |
| 13844 int get precedence => 15; |
| 13845 |
| 13846 /** |
| 13847 * Return the prefix associated with the library in which the identifier is de
fined. |
| 13848 * |
| 13849 * @return the prefix associated with the library in which the identifier is d
efined |
| 13850 */ |
| 13851 SimpleIdentifier get prefix => _prefix; |
| 13852 |
| 13853 @override |
| 13854 Element get propagatedElement { |
| 13855 if (_identifier == null) { |
| 13856 return null; |
| 13857 } |
| 13858 return _identifier.propagatedElement; |
| 13859 } |
| 13860 |
| 13861 @override |
| 13862 Element get staticElement { |
| 13863 if (_identifier == null) { |
| 13864 return null; |
| 13865 } |
| 13866 return _identifier.staticElement; |
| 13867 } |
| 13868 |
| 13869 /** |
| 13870 * Return `true` if this type is a deferred type. |
| 13871 * |
| 13872 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form </i>p.
T</i> where <i>p</i> |
| 13873 * is a deferred prefix. |
| 13874 * |
| 13875 * @return `true` if this type is a deferred type |
| 13876 */ |
| 13877 bool get isDeferred { |
| 13878 Element element = _prefix.staticElement; |
| 13879 if (element is! PrefixElement) { |
| 13880 return false; |
| 13881 } |
| 13882 PrefixElement prefixElement = element as PrefixElement; |
| 13883 List<ImportElement> imports = prefixElement.enclosingElement.getImportsWithP
refix(prefixElement); |
| 13884 if (imports.length != 1) { |
| 13885 return false; |
| 13886 } |
| 13887 return imports[0].isDeferred; |
| 13888 } |
| 13889 |
| 13890 /** |
| 13891 * Set the identifier being prefixed to the given identifier. |
| 13892 * |
| 13893 * @param identifier the identifier being prefixed |
| 13894 */ |
| 13895 void set identifier(SimpleIdentifier identifier) { |
| 13896 this._identifier = becomeParentOf(identifier); |
| 13897 } |
| 13898 |
| 13899 /** |
| 13900 * Set the prefix associated with the library in which the identifier is defin
ed to the given |
| 13901 * identifier. |
| 13902 * |
| 13903 * @param identifier the prefix associated with the library in which the ident
ifier is defined |
| 13904 */ |
| 13905 void set prefix(SimpleIdentifier identifier) { |
| 13906 _prefix = becomeParentOf(identifier); |
| 13907 } |
| 13908 |
| 13909 @override |
| 13910 void visitChildren(AstVisitor visitor) { |
| 13911 safelyVisitChild(_prefix, visitor); |
| 13912 safelyVisitChild(_identifier, visitor); |
| 13913 } |
| 13914 } |
| 13915 |
| 13916 /** |
| 13917 * Instances of the class `PropertyAccess` represent the access of a property of
an object. |
| 13918 * |
| 13919 * Note, however, that accesses to properties of objects can also be represented
as |
| 13920 * [PrefixedIdentifier] nodes in cases where the target is also a simple |
| 13921 * identifier. |
| 13922 * |
| 13923 * <pre> |
| 13924 * propertyAccess ::= |
| 13925 * [Expression] '.' [SimpleIdentifier] |
| 13926 * </pre> |
| 13927 */ |
| 13928 class PropertyAccess extends Expression { |
| 13929 /** |
| 13930 * The expression computing the object defining the property being accessed. |
| 13931 */ |
| 13932 Expression _target; |
| 13933 |
| 13934 /** |
| 13935 * The property access operator. |
| 13936 */ |
| 13937 Token operator; |
| 13938 |
| 13939 /** |
| 13940 * The name of the property being accessed. |
| 13941 */ |
| 13942 SimpleIdentifier _propertyName; |
| 13943 |
| 13944 /** |
| 13945 * Initialize a newly created property access expression. |
| 13946 * |
| 13947 * @param target the expression computing the object defining the property bei
ng accessed |
| 13948 * @param operator the property access operator |
| 13949 * @param propertyName the name of the property being accessed |
| 13950 */ |
| 13951 PropertyAccess(Expression target, this.operator, SimpleIdentifier propertyName
) { |
| 13952 this._target = becomeParentOf(target); |
| 13953 this._propertyName = becomeParentOf(propertyName); |
| 13954 } |
| 13955 |
| 13956 @override |
| 13957 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this); |
| 13958 |
| 13959 @override |
| 13960 Token get beginToken { |
| 13961 if (_target != null) { |
| 13962 return _target.beginToken; |
| 13963 } |
| 13964 return operator; |
| 13965 } |
| 13966 |
| 13967 @override |
| 13968 Token get endToken => _propertyName.endToken; |
| 13969 |
| 13970 @override |
| 13971 int get precedence => 15; |
| 13972 |
| 13973 /** |
| 13974 * Return the name of the property being accessed. |
| 13975 * |
| 13976 * @return the name of the property being accessed |
| 13977 */ |
| 13978 SimpleIdentifier get propertyName => _propertyName; |
| 13979 |
| 13980 /** |
| 13981 * Return the expression used to compute the receiver of the invocation. If th
is invocation is not |
| 13982 * part of a cascade expression, then this is the same as [getTarget]. If this
invocation |
| 13983 * is part of a cascade expression, then the target stored with the cascade ex
pression is |
| 13984 * returned. |
| 13985 * |
| 13986 * @return the expression used to compute the receiver of the invocation |
| 13987 * @see #getTarget() |
| 13988 */ |
| 13989 Expression get realTarget { |
| 13990 if (isCascaded) { |
| 13991 AstNode ancestor = parent; |
| 13992 while (ancestor is! CascadeExpression) { |
| 13993 if (ancestor == null) { |
| 13994 return _target; |
| 13995 } |
| 13996 ancestor = ancestor.parent; |
| 13997 } |
| 13998 return (ancestor as CascadeExpression).target; |
| 13999 } |
| 14000 return _target; |
| 14001 } |
| 14002 |
| 14003 /** |
| 14004 * Return the expression computing the object defining the property being acce
ssed, or |
| 14005 * `null` if this property access is part of a cascade expression. |
| 14006 * |
| 14007 * @return the expression computing the object defining the property being acc
essed |
| 14008 * @see #getRealTarget() |
| 14009 */ |
| 14010 Expression get target => _target; |
| 14011 |
| 14012 @override |
| 14013 bool get isAssignable => true; |
| 14014 |
| 14015 /** |
| 14016 * Return `true` if this expression is cascaded. If it is, then the target of
this |
| 14017 * expression is not stored locally but is stored in the nearest ancestor that
is a |
| 14018 * [CascadeExpression]. |
| 14019 * |
| 14020 * @return `true` if this expression is cascaded |
| 14021 */ |
| 14022 bool get isCascaded => operator != null && operator.type == TokenType.PERIOD_P
ERIOD; |
| 14023 |
| 14024 /** |
| 14025 * Set the name of the property being accessed to the given identifier. |
| 14026 * |
| 14027 * @param identifier the name of the property being accessed |
| 14028 */ |
| 14029 void set propertyName(SimpleIdentifier identifier) { |
| 14030 _propertyName = becomeParentOf(identifier); |
| 14031 } |
| 14032 |
| 14033 /** |
| 14034 * Set the expression computing the object defining the property being accesse
d to the given |
| 14035 * expression. |
| 14036 * |
| 14037 * @param expression the expression computing the object defining the property
being accessed |
| 14038 */ |
| 14039 void set target(Expression expression) { |
| 14040 _target = becomeParentOf(expression); |
| 14041 } |
| 14042 |
| 14043 @override |
| 14044 void visitChildren(AstVisitor visitor) { |
| 14045 safelyVisitChild(_target, visitor); |
| 14046 safelyVisitChild(_propertyName, visitor); |
| 14047 } |
| 14048 } |
| 14049 |
| 14050 /** |
| 14051 * Instances of the class `RecursiveAstVisitor` implement an AST visitor that wi
ll recursively |
| 14052 * visit all of the nodes in an AST structure. For example, using an instance of
this class to visit |
| 14053 * a [Block] will also cause all of the statements in the block to be visited. |
| 14054 * |
| 14055 * Subclasses that override a visit method must either invoke the overridden vis
it method or must |
| 14056 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children |
| 14057 * of the visited node to not be visited. |
| 14058 */ |
| 14059 class RecursiveAstVisitor<R> implements AstVisitor<R> { |
| 14060 @override |
| 14061 R visitAdjacentStrings(AdjacentStrings node) { |
| 14062 node.visitChildren(this); |
| 14063 return null; |
| 14064 } |
| 14065 |
| 14066 @override |
| 14067 R visitAnnotation(Annotation node) { |
| 14068 node.visitChildren(this); |
| 14069 return null; |
| 14070 } |
| 14071 |
| 14072 @override |
| 14073 R visitArgumentList(ArgumentList node) { |
| 14074 node.visitChildren(this); |
| 14075 return null; |
| 14076 } |
| 14077 |
| 14078 @override |
| 14079 R visitAsExpression(AsExpression node) { |
| 14080 node.visitChildren(this); |
| 14081 return null; |
| 14082 } |
| 14083 |
| 14084 @override |
| 14085 R visitAssertStatement(AssertStatement node) { |
| 14086 node.visitChildren(this); |
| 14087 return null; |
| 14088 } |
| 14089 |
| 14090 @override |
| 14091 R visitAssignmentExpression(AssignmentExpression node) { |
| 14092 node.visitChildren(this); |
| 14093 return null; |
| 14094 } |
| 14095 |
| 14096 @override |
| 14097 R visitAwaitExpression(AwaitExpression node) { |
| 14098 node.visitChildren(this); |
| 14099 return null; |
| 14100 } |
| 14101 |
| 14102 @override |
| 14103 R visitBinaryExpression(BinaryExpression node) { |
| 14104 node.visitChildren(this); |
| 14105 return null; |
| 14106 } |
| 14107 |
| 14108 @override |
| 14109 R visitBlock(Block node) { |
| 14110 node.visitChildren(this); |
| 14111 return null; |
| 14112 } |
| 14113 |
| 14114 @override |
| 14115 R visitBlockFunctionBody(BlockFunctionBody node) { |
| 14116 node.visitChildren(this); |
| 14117 return null; |
| 14118 } |
| 14119 |
| 14120 @override |
| 14121 R visitBooleanLiteral(BooleanLiteral node) { |
| 14122 node.visitChildren(this); |
| 14123 return null; |
| 14124 } |
| 14125 |
| 14126 @override |
| 14127 R visitBreakStatement(BreakStatement node) { |
| 14128 node.visitChildren(this); |
| 14129 return null; |
| 14130 } |
| 14131 |
| 14132 @override |
| 14133 R visitCascadeExpression(CascadeExpression node) { |
| 14134 node.visitChildren(this); |
| 14135 return null; |
| 14136 } |
| 14137 |
| 14138 @override |
| 14139 R visitCatchClause(CatchClause node) { |
| 14140 node.visitChildren(this); |
| 14141 return null; |
| 14142 } |
| 14143 |
| 14144 @override |
| 14145 R visitClassDeclaration(ClassDeclaration node) { |
| 14146 node.visitChildren(this); |
| 14147 return null; |
| 14148 } |
| 14149 |
| 14150 @override |
| 14151 R visitClassTypeAlias(ClassTypeAlias node) { |
| 14152 node.visitChildren(this); |
| 14153 return null; |
| 14154 } |
| 14155 |
| 14156 @override |
| 14157 R visitComment(Comment node) { |
| 14158 node.visitChildren(this); |
| 14159 return null; |
| 14160 } |
| 14161 |
| 14162 @override |
| 14163 R visitCommentReference(CommentReference node) { |
| 14164 node.visitChildren(this); |
| 14165 return null; |
| 14166 } |
| 14167 |
| 14168 @override |
| 14169 R visitCompilationUnit(CompilationUnit node) { |
| 14170 node.visitChildren(this); |
| 14171 return null; |
| 14172 } |
| 14173 |
| 14174 @override |
| 14175 R visitConditionalExpression(ConditionalExpression node) { |
| 14176 node.visitChildren(this); |
| 14177 return null; |
| 14178 } |
| 14179 |
| 14180 @override |
| 14181 R visitConstructorDeclaration(ConstructorDeclaration node) { |
| 14182 node.visitChildren(this); |
| 14183 return null; |
| 14184 } |
| 14185 |
| 14186 @override |
| 14187 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 14188 node.visitChildren(this); |
| 14189 return null; |
| 14190 } |
| 14191 |
| 14192 @override |
| 14193 R visitConstructorName(ConstructorName node) { |
| 14194 node.visitChildren(this); |
| 14195 return null; |
| 14196 } |
| 14197 |
| 14198 @override |
| 14199 R visitContinueStatement(ContinueStatement node) { |
| 14200 node.visitChildren(this); |
| 14201 return null; |
| 14202 } |
| 14203 |
| 14204 @override |
| 14205 R visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 14206 node.visitChildren(this); |
| 14207 return null; |
| 14208 } |
| 14209 |
| 14210 @override |
| 14211 R visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 14212 node.visitChildren(this); |
| 14213 return null; |
| 14214 } |
| 14215 |
| 14216 @override |
| 14217 R visitDoStatement(DoStatement node) { |
| 14218 node.visitChildren(this); |
| 14219 return null; |
| 14220 } |
| 14221 |
| 14222 @override |
| 14223 R visitDoubleLiteral(DoubleLiteral node) { |
| 14224 node.visitChildren(this); |
| 14225 return null; |
| 14226 } |
| 14227 |
| 14228 @override |
| 14229 R visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 14230 node.visitChildren(this); |
| 14231 return null; |
| 14232 } |
| 14233 |
| 14234 @override |
| 14235 R visitEmptyStatement(EmptyStatement node) { |
| 14236 node.visitChildren(this); |
| 14237 return null; |
| 14238 } |
| 14239 |
| 14240 @override |
| 14241 R visitEnumConstantDeclaration(EnumConstantDeclaration node) { |
| 14242 node.visitChildren(this); |
| 14243 return null; |
| 14244 } |
| 14245 |
| 14246 @override |
| 14247 R visitEnumDeclaration(EnumDeclaration node) { |
| 14248 node.visitChildren(this); |
| 14249 return null; |
| 14250 } |
| 14251 |
| 14252 @override |
| 14253 R visitExportDirective(ExportDirective node) { |
| 14254 node.visitChildren(this); |
| 14255 return null; |
| 14256 } |
| 14257 |
| 14258 @override |
| 14259 R visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 14260 node.visitChildren(this); |
| 14261 return null; |
| 14262 } |
| 14263 |
| 14264 @override |
| 14265 R visitExpressionStatement(ExpressionStatement node) { |
| 14266 node.visitChildren(this); |
| 14267 return null; |
| 14268 } |
| 14269 |
| 14270 @override |
| 14271 R visitExtendsClause(ExtendsClause node) { |
| 14272 node.visitChildren(this); |
| 14273 return null; |
| 14274 } |
| 14275 |
| 14276 @override |
| 14277 R visitFieldDeclaration(FieldDeclaration node) { |
| 14278 node.visitChildren(this); |
| 14279 return null; |
| 14280 } |
| 14281 |
| 14282 @override |
| 14283 R visitFieldFormalParameter(FieldFormalParameter node) { |
| 14284 node.visitChildren(this); |
| 14285 return null; |
| 14286 } |
| 14287 |
| 14288 @override |
| 14289 R visitForEachStatement(ForEachStatement node) { |
| 14290 node.visitChildren(this); |
| 14291 return null; |
| 14292 } |
| 14293 |
| 14294 @override |
| 14295 R visitFormalParameterList(FormalParameterList node) { |
| 14296 node.visitChildren(this); |
| 14297 return null; |
| 14298 } |
| 14299 |
| 14300 @override |
| 14301 R visitForStatement(ForStatement node) { |
| 14302 node.visitChildren(this); |
| 14303 return null; |
| 14304 } |
| 14305 |
| 14306 @override |
| 14307 R visitFunctionDeclaration(FunctionDeclaration node) { |
| 14308 node.visitChildren(this); |
| 14309 return null; |
| 14310 } |
| 14311 |
| 14312 @override |
| 14313 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 14314 node.visitChildren(this); |
| 14315 return null; |
| 14316 } |
| 14317 |
| 14318 @override |
| 14319 R visitFunctionExpression(FunctionExpression node) { |
| 14320 node.visitChildren(this); |
| 14321 return null; |
| 14322 } |
| 14323 |
| 14324 @override |
| 14325 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 14326 node.visitChildren(this); |
| 14327 return null; |
| 14328 } |
| 14329 |
| 14330 @override |
| 14331 R visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 14332 node.visitChildren(this); |
| 14333 return null; |
| 14334 } |
| 14335 |
| 14336 @override |
| 14337 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 14338 node.visitChildren(this); |
| 14339 return null; |
| 14340 } |
| 14341 |
| 14342 @override |
| 14343 R visitHideCombinator(HideCombinator node) { |
| 14344 node.visitChildren(this); |
| 14345 return null; |
| 14346 } |
| 14347 |
| 14348 @override |
| 14349 R visitIfStatement(IfStatement node) { |
| 14350 node.visitChildren(this); |
| 14351 return null; |
| 14352 } |
| 14353 |
| 14354 @override |
| 14355 R visitImplementsClause(ImplementsClause node) { |
| 14356 node.visitChildren(this); |
| 14357 return null; |
| 14358 } |
| 14359 |
| 14360 @override |
| 14361 R visitImportDirective(ImportDirective node) { |
| 14362 node.visitChildren(this); |
| 14363 return null; |
| 14364 } |
| 14365 |
| 14366 @override |
| 14367 R visitIndexExpression(IndexExpression node) { |
| 14368 node.visitChildren(this); |
| 14369 return null; |
| 14370 } |
| 14371 |
| 14372 @override |
| 14373 R visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 14374 node.visitChildren(this); |
| 14375 return null; |
| 14376 } |
| 14377 |
| 14378 @override |
| 14379 R visitIntegerLiteral(IntegerLiteral node) { |
| 14380 node.visitChildren(this); |
| 14381 return null; |
| 14382 } |
| 14383 |
| 14384 @override |
| 14385 R visitInterpolationExpression(InterpolationExpression node) { |
| 14386 node.visitChildren(this); |
| 14387 return null; |
| 14388 } |
| 14389 |
| 14390 @override |
| 14391 R visitInterpolationString(InterpolationString node) { |
| 14392 node.visitChildren(this); |
| 14393 return null; |
| 14394 } |
| 14395 |
| 14396 @override |
| 14397 R visitIsExpression(IsExpression node) { |
| 14398 node.visitChildren(this); |
| 14399 return null; |
| 14400 } |
| 14401 |
| 14402 @override |
| 14403 R visitLabel(Label node) { |
| 14404 node.visitChildren(this); |
| 14405 return null; |
| 14406 } |
| 14407 |
| 14408 @override |
| 14409 R visitLabeledStatement(LabeledStatement node) { |
| 14410 node.visitChildren(this); |
| 14411 return null; |
| 14412 } |
| 14413 |
| 14414 @override |
| 14415 R visitLibraryDirective(LibraryDirective node) { |
| 14416 node.visitChildren(this); |
| 14417 return null; |
| 14418 } |
| 14419 |
| 14420 @override |
| 14421 R visitLibraryIdentifier(LibraryIdentifier node) { |
| 14422 node.visitChildren(this); |
| 14423 return null; |
| 14424 } |
| 14425 |
| 14426 @override |
| 14427 R visitListLiteral(ListLiteral node) { |
| 14428 node.visitChildren(this); |
| 14429 return null; |
| 14430 } |
| 14431 |
| 14432 @override |
| 14433 R visitMapLiteral(MapLiteral node) { |
| 14434 node.visitChildren(this); |
| 14435 return null; |
| 14436 } |
| 14437 |
| 14438 @override |
| 14439 R visitMapLiteralEntry(MapLiteralEntry node) { |
| 14440 node.visitChildren(this); |
| 14441 return null; |
| 14442 } |
| 14443 |
| 14444 @override |
| 14445 R visitMethodDeclaration(MethodDeclaration node) { |
| 14446 node.visitChildren(this); |
| 14447 return null; |
| 14448 } |
| 14449 |
| 14450 @override |
| 14451 R visitMethodInvocation(MethodInvocation node) { |
| 14452 node.visitChildren(this); |
| 14453 return null; |
| 14454 } |
| 14455 |
| 14456 @override |
| 14457 R visitNamedExpression(NamedExpression node) { |
| 14458 node.visitChildren(this); |
| 14459 return null; |
| 14460 } |
| 14461 |
| 14462 @override |
| 14463 R visitNativeClause(NativeClause node) { |
| 14464 node.visitChildren(this); |
| 14465 return null; |
| 14466 } |
| 14467 |
| 14468 @override |
| 14469 R visitNativeFunctionBody(NativeFunctionBody node) { |
| 14470 node.visitChildren(this); |
| 14471 return null; |
| 14472 } |
| 14473 |
| 14474 @override |
| 14475 R visitNullLiteral(NullLiteral node) { |
| 14476 node.visitChildren(this); |
| 14477 return null; |
| 14478 } |
| 14479 |
| 14480 @override |
| 14481 R visitParenthesizedExpression(ParenthesizedExpression node) { |
| 14482 node.visitChildren(this); |
| 14483 return null; |
| 14484 } |
| 14485 |
| 14486 @override |
| 14487 R visitPartDirective(PartDirective node) { |
| 14488 node.visitChildren(this); |
| 14489 return null; |
| 14490 } |
| 14491 |
| 14492 @override |
| 14493 R visitPartOfDirective(PartOfDirective node) { |
| 14494 node.visitChildren(this); |
| 14495 return null; |
| 14496 } |
| 14497 |
| 14498 @override |
| 14499 R visitPostfixExpression(PostfixExpression node) { |
| 14500 node.visitChildren(this); |
| 14501 return null; |
| 14502 } |
| 14503 |
| 14504 @override |
| 14505 R visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 14506 node.visitChildren(this); |
| 14507 return null; |
| 14508 } |
| 14509 |
| 14510 @override |
| 14511 R visitPrefixExpression(PrefixExpression node) { |
| 14512 node.visitChildren(this); |
| 14513 return null; |
| 14514 } |
| 14515 |
| 14516 @override |
| 14517 R visitPropertyAccess(PropertyAccess node) { |
| 14518 node.visitChildren(this); |
| 14519 return null; |
| 14520 } |
| 14521 |
| 14522 @override |
| 14523 R visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node)
{ |
| 14524 node.visitChildren(this); |
| 14525 return null; |
| 14526 } |
| 14527 |
| 14528 @override |
| 14529 R visitRethrowExpression(RethrowExpression node) { |
| 14530 node.visitChildren(this); |
| 14531 return null; |
| 14532 } |
| 14533 |
| 14534 @override |
| 14535 R visitReturnStatement(ReturnStatement node) { |
| 14536 node.visitChildren(this); |
| 14537 return null; |
| 14538 } |
| 14539 |
| 14540 @override |
| 14541 R visitScriptTag(ScriptTag node) { |
| 14542 node.visitChildren(this); |
| 14543 return null; |
| 14544 } |
| 14545 |
| 14546 @override |
| 14547 R visitShowCombinator(ShowCombinator node) { |
| 14548 node.visitChildren(this); |
| 14549 return null; |
| 14550 } |
| 14551 |
| 14552 @override |
| 14553 R visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 14554 node.visitChildren(this); |
| 14555 return null; |
| 14556 } |
| 14557 |
| 14558 @override |
| 14559 R visitSimpleIdentifier(SimpleIdentifier node) { |
| 14560 node.visitChildren(this); |
| 14561 return null; |
| 14562 } |
| 14563 |
| 14564 @override |
| 14565 R visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 14566 node.visitChildren(this); |
| 14567 return null; |
| 14568 } |
| 14569 |
| 14570 @override |
| 14571 R visitStringInterpolation(StringInterpolation node) { |
| 14572 node.visitChildren(this); |
| 14573 return null; |
| 14574 } |
| 14575 |
| 14576 @override |
| 14577 R visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 14578 node.visitChildren(this); |
| 14579 return null; |
| 14580 } |
| 14581 |
| 14582 @override |
| 14583 R visitSuperExpression(SuperExpression node) { |
| 14584 node.visitChildren(this); |
| 14585 return null; |
| 14586 } |
| 14587 |
| 14588 @override |
| 14589 R visitSwitchCase(SwitchCase node) { |
| 14590 node.visitChildren(this); |
| 14591 return null; |
| 14592 } |
| 14593 |
| 14594 @override |
| 14595 R visitSwitchDefault(SwitchDefault node) { |
| 14596 node.visitChildren(this); |
| 14597 return null; |
| 14598 } |
| 14599 |
| 14600 @override |
| 14601 R visitSwitchStatement(SwitchStatement node) { |
| 14602 node.visitChildren(this); |
| 14603 return null; |
| 14604 } |
| 14605 |
| 14606 @override |
| 14607 R visitSymbolLiteral(SymbolLiteral node) { |
| 14608 node.visitChildren(this); |
| 14609 return null; |
| 14610 } |
| 14611 |
| 14612 @override |
| 14613 R visitThisExpression(ThisExpression node) { |
| 14614 node.visitChildren(this); |
| 14615 return null; |
| 14616 } |
| 14617 |
| 14618 @override |
| 14619 R visitThrowExpression(ThrowExpression node) { |
| 14620 node.visitChildren(this); |
| 14621 return null; |
| 14622 } |
| 14623 |
| 14624 @override |
| 14625 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 14626 node.visitChildren(this); |
| 14627 return null; |
| 14628 } |
| 14629 |
| 14630 @override |
| 14631 R visitTryStatement(TryStatement node) { |
| 14632 node.visitChildren(this); |
| 14633 return null; |
| 14634 } |
| 14635 |
| 14636 @override |
| 14637 R visitTypeArgumentList(TypeArgumentList node) { |
| 14638 node.visitChildren(this); |
| 14639 return null; |
| 14640 } |
| 14641 |
| 14642 @override |
| 14643 R visitTypeName(TypeName node) { |
| 14644 node.visitChildren(this); |
| 14645 return null; |
| 14646 } |
| 14647 |
| 14648 @override |
| 14649 R visitTypeParameter(TypeParameter node) { |
| 14650 node.visitChildren(this); |
| 14651 return null; |
| 14652 } |
| 14653 |
| 14654 @override |
| 14655 R visitTypeParameterList(TypeParameterList node) { |
| 14656 node.visitChildren(this); |
| 14657 return null; |
| 14658 } |
| 14659 |
| 14660 @override |
| 14661 R visitVariableDeclaration(VariableDeclaration node) { |
| 14662 node.visitChildren(this); |
| 14663 return null; |
| 14664 } |
| 14665 |
| 14666 @override |
| 14667 R visitVariableDeclarationList(VariableDeclarationList node) { |
| 14668 node.visitChildren(this); |
| 14669 return null; |
| 14670 } |
| 14671 |
| 14672 @override |
| 14673 R visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 14674 node.visitChildren(this); |
| 14675 return null; |
| 14676 } |
| 14677 |
| 14678 @override |
| 14679 R visitWhileStatement(WhileStatement node) { |
| 14680 node.visitChildren(this); |
| 14681 return null; |
| 14682 } |
| 14683 |
| 14684 @override |
| 14685 R visitWithClause(WithClause node) { |
| 14686 node.visitChildren(this); |
| 14687 return null; |
| 14688 } |
| 14689 |
| 14690 @override |
| 14691 R visitYieldStatement(YieldStatement node) { |
| 14692 node.visitChildren(this); |
| 14693 return null; |
| 14694 } |
| 14695 } |
| 14696 |
| 14697 /** |
| 14698 * Instances of the class `RedirectingConstructorInvocation` represent the invoc
ation of a |
| 14699 * another constructor in the same class from within a constructor's initializat
ion list. |
| 14700 * |
| 14701 * <pre> |
| 14702 * redirectingConstructorInvocation ::= |
| 14703 * 'this' ('.' identifier)? arguments |
| 14704 * </pre> |
| 14705 */ |
| 14706 class RedirectingConstructorInvocation extends ConstructorInitializer { |
| 14707 /** |
| 14708 * The token for the 'this' keyword. |
| 14709 */ |
| 14710 Token keyword; |
| 14711 |
| 14712 /** |
| 14713 * The token for the period before the name of the constructor that is being i
nvoked, or |
| 14714 * `null` if the unnamed constructor is being invoked. |
| 14715 */ |
| 14716 Token period; |
| 14717 |
| 14718 /** |
| 14719 * The name of the constructor that is being invoked, or `null` if the unnamed
constructor |
| 14720 * is being invoked. |
| 14721 */ |
| 14722 SimpleIdentifier _constructorName; |
| 14723 |
| 14724 /** |
| 14725 * The list of arguments to the constructor. |
| 14726 */ |
| 14727 ArgumentList _argumentList; |
| 14728 |
| 14729 /** |
| 14730 * The element associated with the constructor based on static type informatio
n, or `null` |
| 14731 * if the AST structure has not been resolved or if the constructor could not
be resolved. |
| 14732 */ |
| 14733 ConstructorElement staticElement; |
| 14734 |
| 14735 /** |
| 14736 * Initialize a newly created redirecting invocation to invoke the constructor
with the given name |
| 14737 * with the given arguments. |
| 14738 * |
| 14739 * @param keyword the token for the 'this' keyword |
| 14740 * @param period the token for the period before the name of the constructor t
hat is being invoked |
| 14741 * @param constructorName the name of the constructor that is being invoked |
| 14742 * @param argumentList the list of arguments to the constructor |
| 14743 */ |
| 14744 RedirectingConstructorInvocation(this.keyword, this.period, SimpleIdentifier c
onstructorName, ArgumentList argumentList) { |
| 14745 this._constructorName = becomeParentOf(constructorName); |
| 14746 this._argumentList = becomeParentOf(argumentList); |
| 14747 } |
| 14748 |
| 14749 @override |
| 14750 accept(AstVisitor visitor) => visitor.visitRedirectingConstructorInvocation(th
is); |
| 14751 |
| 14752 /** |
| 14753 * Return the list of arguments to the constructor. |
| 14754 * |
| 14755 * @return the list of arguments to the constructor |
| 14756 */ |
| 14757 ArgumentList get argumentList => _argumentList; |
| 14758 |
| 14759 @override |
| 14760 Token get beginToken => keyword; |
| 14761 |
| 14762 /** |
| 14763 * Return the name of the constructor that is being invoked, or `null` if the
unnamed |
| 14764 * constructor is being invoked. |
| 14765 * |
| 14766 * @return the name of the constructor that is being invoked |
| 14767 */ |
| 14768 SimpleIdentifier get constructorName => _constructorName; |
| 14769 |
| 14770 @override |
| 14771 Token get endToken => _argumentList.endToken; |
| 14772 |
| 14773 /** |
| 14774 * Set the list of arguments to the constructor to the given list. |
| 14775 * |
| 14776 * @param argumentList the list of arguments to the constructor |
| 14777 */ |
| 14778 void set argumentList(ArgumentList argumentList) { |
| 14779 this._argumentList = becomeParentOf(argumentList); |
| 14780 } |
| 14781 |
| 14782 /** |
| 14783 * Set the name of the constructor that is being invoked to the given identifi
er. |
| 14784 * |
| 14785 * @param identifier the name of the constructor that is being invoked |
| 14786 */ |
| 14787 void set constructorName(SimpleIdentifier identifier) { |
| 14788 _constructorName = becomeParentOf(identifier); |
| 14789 } |
| 14790 |
| 14791 @override |
| 14792 void visitChildren(AstVisitor visitor) { |
| 14793 safelyVisitChild(_constructorName, visitor); |
| 14794 safelyVisitChild(_argumentList, visitor); |
| 14795 } |
| 14796 } |
| 14797 |
| 14798 /** |
| 14799 * Instances of the class `RethrowExpression` represent a rethrow expression. |
| 14800 * |
| 14801 * <pre> |
| 14802 * rethrowExpression ::= |
| 14803 * 'rethrow' |
| 14804 * </pre> |
| 14805 */ |
| 14806 class RethrowExpression extends Expression { |
| 14807 /** |
| 14808 * The token representing the 'rethrow' keyword. |
| 14809 */ |
| 14810 Token keyword; |
| 14811 |
| 14812 /** |
| 14813 * Initialize a newly created rethrow expression. |
| 14814 * |
| 14815 * @param keyword the token representing the 'rethrow' keyword |
| 14816 */ |
| 14817 RethrowExpression(this.keyword); |
| 14818 |
| 14819 @override |
| 14820 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this); |
| 14821 |
| 14822 @override |
| 14823 Token get beginToken => keyword; |
| 14824 |
| 14825 @override |
| 14826 Token get endToken => keyword; |
| 14827 |
| 14828 @override |
| 14829 int get precedence => 0; |
| 14830 |
| 14831 @override |
| 14832 void visitChildren(AstVisitor visitor) { |
| 14833 } |
| 14834 } |
| 14835 |
| 14836 /** |
| 14837 * Instances of the class `ReturnStatement` represent a return statement. |
| 14838 * |
| 14839 * <pre> |
| 14840 * returnStatement ::= |
| 14841 * 'return' [Expression]? ';' |
| 14842 * </pre> |
| 14843 */ |
| 14844 class ReturnStatement extends Statement { |
| 14845 /** |
| 14846 * The token representing the 'return' keyword. |
| 14847 */ |
| 14848 Token keyword; |
| 14849 |
| 14850 /** |
| 14851 * The expression computing the value to be returned, or `null` if no explicit
value was |
| 14852 * provided. |
| 14853 */ |
| 14854 Expression _expression; |
| 14855 |
| 14856 /** |
| 14857 * The semicolon terminating the statement. |
| 14858 */ |
| 14859 Token semicolon; |
| 14860 |
| 14861 /** |
| 14862 * Initialize a newly created return statement. |
| 14863 * |
| 14864 * @param keyword the token representing the 'return' keyword |
| 14865 * @param expression the expression computing the value to be returned |
| 14866 * @param semicolon the semicolon terminating the statement |
| 14867 */ |
| 14868 ReturnStatement(this.keyword, Expression expression, this.semicolon) { |
| 14869 this._expression = becomeParentOf(expression); |
| 14870 } |
| 14871 |
| 14872 @override |
| 14873 accept(AstVisitor visitor) => visitor.visitReturnStatement(this); |
| 14874 |
| 14875 @override |
| 14876 Token get beginToken => keyword; |
| 14877 |
| 14878 @override |
| 14879 Token get endToken => semicolon; |
| 14880 |
| 14881 /** |
| 14882 * Return the expression computing the value to be returned, or `null` if no e
xplicit value |
| 14883 * was provided. |
| 14884 * |
| 14885 * @return the expression computing the value to be returned |
| 14886 */ |
| 14887 Expression get expression => _expression; |
| 14888 |
| 14889 /** |
| 14890 * Set the expression computing the value to be returned to the given expressi
on. |
| 14891 * |
| 14892 * @param expression the expression computing the value to be returned |
| 14893 */ |
| 14894 void set expression(Expression expression) { |
| 14895 this._expression = becomeParentOf(expression); |
| 14896 } |
| 14897 |
| 14898 @override |
| 14899 void visitChildren(AstVisitor visitor) { |
| 14900 safelyVisitChild(_expression, visitor); |
| 14901 } |
| 14902 } |
| 14903 |
| 14904 /** |
| 14905 * Traverse the AST from initial child node to successive parents, building a co
llection of local |
| 14906 * variable and parameter names visible to the initial child node. In case of na
me shadowing, the |
| 14907 * first name seen is the most specific one so names are not redefined. |
| 14908 * |
| 14909 * Completion test code coverage is 95%. The two basic blocks that are not execu
ted cannot be |
| 14910 * executed. They are included for future reference. |
| 14911 */ |
| 14912 class ScopedNameFinder extends GeneralizingAstVisitor<Object> { |
| 14913 Declaration _declarationNode; |
| 14914 |
| 14915 AstNode _immediateChild; |
| 14916 |
| 14917 Map<String, SimpleIdentifier> _locals = new HashMap<String, SimpleIdentifier>(
); |
| 14918 |
| 14919 final int _position; |
| 14920 |
| 14921 bool _referenceIsWithinLocalFunction = false; |
| 14922 |
| 14923 ScopedNameFinder(this._position); |
| 14924 |
| 14925 Declaration get declaration => _declarationNode; |
| 14926 |
| 14927 Map<String, SimpleIdentifier> get locals => _locals; |
| 14928 |
| 14929 @override |
| 14930 Object visitBlock(Block node) { |
| 14931 _checkStatements(node.statements); |
| 14932 return super.visitBlock(node); |
| 14933 } |
| 14934 |
| 14935 @override |
| 14936 Object visitCatchClause(CatchClause node) { |
| 14937 _addToScope(node.exceptionParameter); |
| 14938 _addToScope(node.stackTraceParameter); |
| 14939 return super.visitCatchClause(node); |
| 14940 } |
| 14941 |
| 14942 @override |
| 14943 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 14944 if (!identical(_immediateChild, node.parameters)) { |
| 14945 _addParameters(node.parameters.parameters); |
| 14946 } |
| 14947 _declarationNode = node; |
| 14948 return null; |
| 14949 } |
| 14950 |
| 14951 @override |
| 14952 Object visitFieldDeclaration(FieldDeclaration node) { |
| 14953 _declarationNode = node; |
| 14954 return null; |
| 14955 } |
| 14956 |
| 14957 @override |
| 14958 Object visitForEachStatement(ForEachStatement node) { |
| 14959 DeclaredIdentifier loopVariable = node.loopVariable; |
| 14960 if (loopVariable != null) { |
| 14961 _addToScope(loopVariable.identifier); |
| 14962 } |
| 14963 return super.visitForEachStatement(node); |
| 14964 } |
| 14965 |
| 14966 @override |
| 14967 Object visitForStatement(ForStatement node) { |
| 14968 if (!identical(_immediateChild, node.variables) && node.variables != null) { |
| 14969 _addVariables(node.variables.variables); |
| 14970 } |
| 14971 return super.visitForStatement(node); |
| 14972 } |
| 14973 |
| 14974 @override |
| 14975 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 14976 if (node.parent is! FunctionDeclarationStatement) { |
| 14977 _declarationNode = node; |
| 14978 return null; |
| 14979 } |
| 14980 return super.visitFunctionDeclaration(node); |
| 14981 } |
| 14982 |
| 14983 @override |
| 14984 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 14985 _referenceIsWithinLocalFunction = true; |
| 14986 return super.visitFunctionDeclarationStatement(node); |
| 14987 } |
| 14988 |
| 14989 @override |
| 14990 Object visitFunctionExpression(FunctionExpression node) { |
| 14991 if (node.parameters != null && !identical(_immediateChild, node.parameters))
{ |
| 14992 _addParameters(node.parameters.parameters); |
| 14993 } |
| 14994 return super.visitFunctionExpression(node); |
| 14995 } |
| 14996 |
| 14997 @override |
| 14998 Object visitMethodDeclaration(MethodDeclaration node) { |
| 14999 _declarationNode = node; |
| 15000 if (node.parameters == null) { |
| 15001 return null; |
| 15002 } |
| 15003 if (!identical(_immediateChild, node.parameters)) { |
| 15004 _addParameters(node.parameters.parameters); |
| 15005 } |
| 15006 return null; |
| 15007 } |
| 15008 |
| 15009 @override |
| 15010 Object visitNode(AstNode node) { |
| 15011 _immediateChild = node; |
| 15012 AstNode parent = node.parent; |
| 15013 if (parent != null) { |
| 15014 parent.accept(this); |
| 15015 } |
| 15016 return null; |
| 15017 } |
| 15018 |
| 15019 @override |
| 15020 Object visitSwitchMember(SwitchMember node) { |
| 15021 _checkStatements(node.statements); |
| 15022 return super.visitSwitchMember(node); |
| 15023 } |
| 15024 |
| 15025 @override |
| 15026 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 15027 _declarationNode = node; |
| 15028 return null; |
| 15029 } |
| 15030 |
| 15031 @override |
| 15032 Object visitTypeAlias(TypeAlias node) { |
| 15033 _declarationNode = node; |
| 15034 return null; |
| 15035 } |
| 15036 |
| 15037 void _addParameters(NodeList<FormalParameter> vars) { |
| 15038 for (FormalParameter var2 in vars) { |
| 15039 _addToScope(var2.identifier); |
| 15040 } |
| 15041 } |
| 15042 |
| 15043 void _addToScope(SimpleIdentifier identifier) { |
| 15044 if (identifier != null && _isInRange(identifier)) { |
| 15045 String name = identifier.name; |
| 15046 if (!_locals.containsKey(name)) { |
| 15047 _locals[name] = identifier; |
| 15048 } |
| 15049 } |
| 15050 } |
| 15051 |
| 15052 void _addVariables(NodeList<VariableDeclaration> vars) { |
| 15053 for (VariableDeclaration var2 in vars) { |
| 15054 _addToScope(var2.name); |
| 15055 } |
| 15056 } |
| 15057 |
| 15058 /** |
| 15059 * Some statements define names that are visible downstream. There aren't many
of these. |
| 15060 * |
| 15061 * @param statements the list of statements to check for name definitions |
| 15062 */ |
| 15063 void _checkStatements(List<Statement> statements) { |
| 15064 for (Statement stmt in statements) { |
| 15065 if (identical(stmt, _immediateChild)) { |
| 15066 return; |
| 15067 } |
| 15068 if (stmt is VariableDeclarationStatement) { |
| 15069 _addVariables(stmt.variables.variables); |
| 15070 } else if (stmt is FunctionDeclarationStatement && !_referenceIsWithinLoca
lFunction) { |
| 15071 _addToScope(stmt.functionDeclaration.name); |
| 15072 } |
| 15073 } |
| 15074 } |
| 15075 |
| 15076 bool _isInRange(AstNode node) { |
| 15077 if (_position < 0) { |
| 15078 // if source position is not set then all nodes are in range |
| 15079 return true; |
| 15080 } |
| 15081 return node.end < _position; |
| 15082 } |
| 15083 } |
| 15084 |
| 15085 /** |
| 15086 * Instances of the class `ScriptTag` represent the script tag that can optional
ly occur at |
| 15087 * the beginning of a compilation unit. |
| 15088 * |
| 15089 * <pre> |
| 15090 * scriptTag ::= |
| 15091 * '#!' (~NEWLINE)* NEWLINE |
| 15092 * </pre> |
| 15093 */ |
| 15094 class ScriptTag extends AstNode { |
| 15095 /** |
| 15096 * The token representing this script tag. |
| 15097 */ |
| 15098 Token scriptTag; |
| 15099 |
| 15100 /** |
| 15101 * Initialize a newly created script tag. |
| 15102 * |
| 15103 * @param scriptTag the token representing this script tag |
| 15104 */ |
| 15105 ScriptTag(this.scriptTag); |
| 15106 |
| 15107 @override |
| 15108 accept(AstVisitor visitor) => visitor.visitScriptTag(this); |
| 15109 |
| 15110 @override |
| 15111 Token get beginToken => scriptTag; |
| 15112 |
| 15113 @override |
| 15114 Token get endToken => scriptTag; |
| 15115 |
| 15116 @override |
| 15117 void visitChildren(AstVisitor visitor) { |
| 15118 } |
| 15119 } |
| 15120 |
| 15121 /** |
| 15122 * Instances of the class `ShowCombinator` represent a combinator that restricts
the names |
| 15123 * being imported to those in a given list. |
| 15124 * |
| 15125 * <pre> |
| 15126 * showCombinator ::= |
| 15127 * 'show' [SimpleIdentifier] (',' [SimpleIdentifier])* |
| 15128 * </pre> |
| 15129 */ |
| 15130 class ShowCombinator extends Combinator { |
| 15131 /** |
| 15132 * The list of names from the library that are made visible by this combinator
. |
| 15133 */ |
| 15134 NodeList<SimpleIdentifier> _shownNames; |
| 15135 |
| 15136 /** |
| 15137 * Initialize a newly created import show combinator. |
| 15138 * |
| 15139 * @param keyword the comma introducing the combinator |
| 15140 * @param shownNames the list of names from the library that are made visible
by this combinator |
| 15141 */ |
| 15142 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames) : super(keywo
rd) { |
| 15143 this._shownNames = new NodeList<SimpleIdentifier>(this); |
| 15144 this._shownNames.addAll(shownNames); |
| 15145 } |
| 15146 |
| 15147 @override |
| 15148 accept(AstVisitor visitor) => visitor.visitShowCombinator(this); |
| 15149 |
| 15150 @override |
| 15151 Token get endToken => _shownNames.endToken; |
| 15152 |
| 15153 /** |
| 15154 * Return the list of names from the library that are made visible by this com
binator. |
| 15155 * |
| 15156 * @return the list of names from the library that are made visible by this co
mbinator |
| 15157 */ |
| 15158 NodeList<SimpleIdentifier> get shownNames => _shownNames; |
| 15159 |
| 15160 @override |
| 15161 void visitChildren(AstVisitor visitor) { |
| 15162 _shownNames.accept(visitor); |
| 15163 } |
| 15164 } |
| 15165 |
| 15166 /** |
| 15167 * Instances of the class `SimpleAstVisitor` implement an AST visitor that will
do nothing |
| 15168 * when visiting an AST node. It is intended to be a superclass for classes that
use the visitor |
| 15169 * pattern primarily as a dispatch mechanism (and hence don't need to recursivel
y visit a whole |
| 15170 * structure) and that only need to visit a small number of node types. |
| 15171 */ |
| 15172 class SimpleAstVisitor<R> implements AstVisitor<R> { |
| 15173 @override |
| 15174 R visitAdjacentStrings(AdjacentStrings node) => null; |
| 15175 |
| 15176 @override |
| 15177 R visitAnnotation(Annotation node) => null; |
| 15178 |
| 15179 @override |
| 15180 R visitArgumentList(ArgumentList node) => null; |
| 15181 |
| 15182 @override |
| 15183 R visitAsExpression(AsExpression node) => null; |
| 15184 |
| 15185 @override |
| 15186 R visitAssertStatement(AssertStatement node) => null; |
| 15187 |
| 15188 @override |
| 15189 R visitAssignmentExpression(AssignmentExpression node) => null; |
| 15190 |
| 15191 @override |
| 15192 R visitAwaitExpression(AwaitExpression node) => null; |
| 15193 |
| 15194 @override |
| 15195 R visitBinaryExpression(BinaryExpression node) => null; |
| 15196 |
| 15197 @override |
| 15198 R visitBlock(Block node) => null; |
| 15199 |
| 15200 @override |
| 15201 R visitBlockFunctionBody(BlockFunctionBody node) => null; |
| 15202 |
| 15203 @override |
| 15204 R visitBooleanLiteral(BooleanLiteral node) => null; |
| 15205 |
| 15206 @override |
| 15207 R visitBreakStatement(BreakStatement node) => null; |
| 15208 |
| 15209 @override |
| 15210 R visitCascadeExpression(CascadeExpression node) => null; |
| 15211 |
| 15212 @override |
| 15213 R visitCatchClause(CatchClause node) => null; |
| 15214 |
| 15215 @override |
| 15216 R visitClassDeclaration(ClassDeclaration node) => null; |
| 15217 |
| 15218 @override |
| 15219 R visitClassTypeAlias(ClassTypeAlias node) => null; |
| 15220 |
| 15221 @override |
| 15222 R visitComment(Comment node) => null; |
| 15223 |
| 15224 @override |
| 15225 R visitCommentReference(CommentReference node) => null; |
| 15226 |
| 15227 @override |
| 15228 R visitCompilationUnit(CompilationUnit node) => null; |
| 15229 |
| 15230 @override |
| 15231 R visitConditionalExpression(ConditionalExpression node) => null; |
| 15232 |
| 15233 @override |
| 15234 R visitConstructorDeclaration(ConstructorDeclaration node) => null; |
| 15235 |
| 15236 @override |
| 15237 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => null; |
| 15238 |
| 15239 @override |
| 15240 R visitConstructorName(ConstructorName node) => null; |
| 15241 |
| 15242 @override |
| 15243 R visitContinueStatement(ContinueStatement node) => null; |
| 15244 |
| 15245 @override |
| 15246 R visitDeclaredIdentifier(DeclaredIdentifier node) => null; |
| 15247 |
| 15248 @override |
| 15249 R visitDefaultFormalParameter(DefaultFormalParameter node) => null; |
| 15250 |
| 15251 @override |
| 15252 R visitDoStatement(DoStatement node) => null; |
| 15253 |
| 15254 @override |
| 15255 R visitDoubleLiteral(DoubleLiteral node) => null; |
| 15256 |
| 15257 @override |
| 15258 R visitEmptyFunctionBody(EmptyFunctionBody node) => null; |
| 15259 |
| 15260 @override |
| 15261 R visitEmptyStatement(EmptyStatement node) => null; |
| 15262 |
| 15263 @override |
| 15264 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => null; |
| 15265 |
| 15266 @override |
| 15267 R visitEnumDeclaration(EnumDeclaration node) => null; |
| 15268 |
| 15269 @override |
| 15270 R visitExportDirective(ExportDirective node) => null; |
| 15271 |
| 15272 @override |
| 15273 R visitExpressionFunctionBody(ExpressionFunctionBody node) => null; |
| 15274 |
| 15275 @override |
| 15276 R visitExpressionStatement(ExpressionStatement node) => null; |
| 15277 |
| 15278 @override |
| 15279 R visitExtendsClause(ExtendsClause node) => null; |
| 15280 |
| 15281 @override |
| 15282 R visitFieldDeclaration(FieldDeclaration node) => null; |
| 15283 |
| 15284 @override |
| 15285 R visitFieldFormalParameter(FieldFormalParameter node) => null; |
| 15286 |
| 15287 @override |
| 15288 R visitForEachStatement(ForEachStatement node) => null; |
| 15289 |
| 15290 @override |
| 15291 R visitFormalParameterList(FormalParameterList node) => null; |
| 15292 |
| 15293 @override |
| 15294 R visitForStatement(ForStatement node) => null; |
| 15295 |
| 15296 @override |
| 15297 R visitFunctionDeclaration(FunctionDeclaration node) => null; |
| 15298 |
| 15299 @override |
| 15300 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => null
; |
| 15301 |
| 15302 @override |
| 15303 R visitFunctionExpression(FunctionExpression node) => null; |
| 15304 |
| 15305 @override |
| 15306 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null
; |
| 15307 |
| 15308 @override |
| 15309 R visitFunctionTypeAlias(FunctionTypeAlias node) => null; |
| 15310 |
| 15311 @override |
| 15312 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => null
; |
| 15313 |
| 15314 @override |
| 15315 R visitHideCombinator(HideCombinator node) => null; |
| 15316 |
| 15317 @override |
| 15318 R visitIfStatement(IfStatement node) => null; |
| 15319 |
| 15320 @override |
| 15321 R visitImplementsClause(ImplementsClause node) => null; |
| 15322 |
| 15323 @override |
| 15324 R visitImportDirective(ImportDirective node) => null; |
| 15325 |
| 15326 @override |
| 15327 R visitIndexExpression(IndexExpression node) => null; |
| 15328 |
| 15329 @override |
| 15330 R visitInstanceCreationExpression(InstanceCreationExpression node) => null; |
| 15331 |
| 15332 @override |
| 15333 R visitIntegerLiteral(IntegerLiteral node) => null; |
| 15334 |
| 15335 @override |
| 15336 R visitInterpolationExpression(InterpolationExpression node) => null; |
| 15337 |
| 15338 @override |
| 15339 R visitInterpolationString(InterpolationString node) => null; |
| 15340 |
| 15341 @override |
| 15342 R visitIsExpression(IsExpression node) => null; |
| 15343 |
| 15344 @override |
| 15345 R visitLabel(Label node) => null; |
| 15346 |
| 15347 @override |
| 15348 R visitLabeledStatement(LabeledStatement node) => null; |
| 15349 |
| 15350 @override |
| 15351 R visitLibraryDirective(LibraryDirective node) => null; |
| 15352 |
| 15353 @override |
| 15354 R visitLibraryIdentifier(LibraryIdentifier node) => null; |
| 15355 |
| 15356 @override |
| 15357 R visitListLiteral(ListLiteral node) => null; |
| 15358 |
| 15359 @override |
| 15360 R visitMapLiteral(MapLiteral node) => null; |
| 15361 |
| 15362 @override |
| 15363 R visitMapLiteralEntry(MapLiteralEntry node) => null; |
| 15364 |
| 15365 @override |
| 15366 R visitMethodDeclaration(MethodDeclaration node) => null; |
| 15367 |
| 15368 @override |
| 15369 R visitMethodInvocation(MethodInvocation node) => null; |
| 15370 |
| 15371 @override |
| 15372 R visitNamedExpression(NamedExpression node) => null; |
| 15373 |
| 15374 @override |
| 15375 R visitNativeClause(NativeClause node) => null; |
| 15376 |
| 15377 @override |
| 15378 R visitNativeFunctionBody(NativeFunctionBody node) => null; |
| 15379 |
| 15380 @override |
| 15381 R visitNullLiteral(NullLiteral node) => null; |
| 15382 |
| 15383 @override |
| 15384 R visitParenthesizedExpression(ParenthesizedExpression node) => null; |
| 15385 |
| 15386 @override |
| 15387 R visitPartDirective(PartDirective node) => null; |
| 15388 |
| 15389 @override |
| 15390 R visitPartOfDirective(PartOfDirective node) => null; |
| 15391 |
| 15392 @override |
| 15393 R visitPostfixExpression(PostfixExpression node) => null; |
| 15394 |
| 15395 @override |
| 15396 R visitPrefixedIdentifier(PrefixedIdentifier node) => null; |
| 15397 |
| 15398 @override |
| 15399 R visitPrefixExpression(PrefixExpression node) => null; |
| 15400 |
| 15401 @override |
| 15402 R visitPropertyAccess(PropertyAccess node) => null; |
| 15403 |
| 15404 @override |
| 15405 R visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node)
=> null; |
| 15406 |
| 15407 @override |
| 15408 R visitRethrowExpression(RethrowExpression node) => null; |
| 15409 |
| 15410 @override |
| 15411 R visitReturnStatement(ReturnStatement node) => null; |
| 15412 |
| 15413 @override |
| 15414 R visitScriptTag(ScriptTag node) => null; |
| 15415 |
| 15416 @override |
| 15417 R visitShowCombinator(ShowCombinator node) => null; |
| 15418 |
| 15419 @override |
| 15420 R visitSimpleFormalParameter(SimpleFormalParameter node) => null; |
| 15421 |
| 15422 @override |
| 15423 R visitSimpleIdentifier(SimpleIdentifier node) => null; |
| 15424 |
| 15425 @override |
| 15426 R visitSimpleStringLiteral(SimpleStringLiteral node) => null; |
| 15427 |
| 15428 @override |
| 15429 R visitStringInterpolation(StringInterpolation node) => null; |
| 15430 |
| 15431 @override |
| 15432 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => null; |
| 15433 |
| 15434 @override |
| 15435 R visitSuperExpression(SuperExpression node) => null; |
| 15436 |
| 15437 @override |
| 15438 R visitSwitchCase(SwitchCase node) => null; |
| 15439 |
| 15440 @override |
| 15441 R visitSwitchDefault(SwitchDefault node) => null; |
| 15442 |
| 15443 @override |
| 15444 R visitSwitchStatement(SwitchStatement node) => null; |
| 15445 |
| 15446 @override |
| 15447 R visitSymbolLiteral(SymbolLiteral node) => null; |
| 15448 |
| 15449 @override |
| 15450 R visitThisExpression(ThisExpression node) => null; |
| 15451 |
| 15452 @override |
| 15453 R visitThrowExpression(ThrowExpression node) => null; |
| 15454 |
| 15455 @override |
| 15456 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => null; |
| 15457 |
| 15458 @override |
| 15459 R visitTryStatement(TryStatement node) => null; |
| 15460 |
| 15461 @override |
| 15462 R visitTypeArgumentList(TypeArgumentList node) => null; |
| 15463 |
| 15464 @override |
| 15465 R visitTypeName(TypeName node) => null; |
| 15466 |
| 15467 @override |
| 15468 R visitTypeParameter(TypeParameter node) => null; |
| 15469 |
| 15470 @override |
| 15471 R visitTypeParameterList(TypeParameterList node) => null; |
| 15472 |
| 15473 @override |
| 15474 R visitVariableDeclaration(VariableDeclaration node) => null; |
| 15475 |
| 15476 @override |
| 15477 R visitVariableDeclarationList(VariableDeclarationList node) => null; |
| 15478 |
| 15479 @override |
| 15480 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => null
; |
| 15481 |
| 15482 @override |
| 15483 R visitWhileStatement(WhileStatement node) => null; |
| 15484 |
| 15485 @override |
| 15486 R visitWithClause(WithClause node) => null; |
| 15487 |
| 15488 @override |
| 15489 R visitYieldStatement(YieldStatement node) => null; |
| 15490 } |
| 15491 |
| 15492 /** |
| 15493 * Instances of the class `SimpleFormalParameter` represent a simple formal para
meter. |
| 15494 * |
| 15495 * <pre> |
| 15496 * simpleFormalParameter ::= |
| 15497 * ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier] |
| 15498 * </pre> |
| 15499 */ |
| 15500 class SimpleFormalParameter extends NormalFormalParameter { |
| 15501 /** |
| 15502 * The token representing either the 'final', 'const' or 'var' keyword, or `nu
ll` if no |
| 15503 * keyword was used. |
| 15504 */ |
| 15505 Token keyword; |
| 15506 |
| 15507 /** |
| 15508 * The name of the declared type of the parameter, or `null` if the parameter
does not have |
| 15509 * a declared type. |
| 15510 */ |
| 15511 TypeName _type; |
| 15512 |
| 15513 /** |
| 15514 * Initialize a newly created formal parameter. |
| 15515 * |
| 15516 * @param comment the documentation comment associated with this parameter |
| 15517 * @param metadata the annotations associated with this parameter |
| 15518 * @param keyword the token representing either the 'final', 'const' or 'var'
keyword |
| 15519 * @param type the name of the declared type of the parameter |
| 15520 * @param identifier the name of the parameter being declared |
| 15521 */ |
| 15522 SimpleFormalParameter(Comment comment, List<Annotation> metadata, this.keyword
, TypeName type, SimpleIdentifier identifier) : super(comment, metadata, identif
ier) { |
| 15523 this._type = becomeParentOf(type); |
| 15524 } |
| 15525 |
| 15526 @override |
| 15527 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this); |
| 15528 |
| 15529 @override |
| 15530 Token get beginToken { |
| 15531 NodeList<Annotation> metadata = this.metadata; |
| 15532 if (!metadata.isEmpty) { |
| 15533 return metadata.beginToken; |
| 15534 } else if (keyword != null) { |
| 15535 return keyword; |
| 15536 } else if (_type != null) { |
| 15537 return _type.beginToken; |
| 15538 } |
| 15539 return identifier.beginToken; |
| 15540 } |
| 15541 |
| 15542 @override |
| 15543 Token get endToken => identifier.endToken; |
| 15544 |
| 15545 /** |
| 15546 * Return the name of the declared type of the parameter, or `null` if the par
ameter does |
| 15547 * not have a declared type. |
| 15548 * |
| 15549 * @return the name of the declared type of the parameter |
| 15550 */ |
| 15551 TypeName get type => _type; |
| 15552 |
| 15553 @override |
| 15554 bool get isConst => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.CONST; |
| 15555 |
| 15556 @override |
| 15557 bool get isFinal => (keyword is KeywordToken) && (keyword as KeywordToken).key
word == Keyword.FINAL; |
| 15558 |
| 15559 /** |
| 15560 * Set the name of the declared type of the parameter to the given type name. |
| 15561 * |
| 15562 * @param typeName the name of the declared type of the parameter |
| 15563 */ |
| 15564 void set type(TypeName typeName) { |
| 15565 _type = becomeParentOf(typeName); |
| 15566 } |
| 15567 |
| 15568 @override |
| 15569 void visitChildren(AstVisitor visitor) { |
| 15570 super.visitChildren(visitor); |
| 15571 safelyVisitChild(_type, visitor); |
| 15572 safelyVisitChild(identifier, visitor); |
| 15573 } |
| 15574 } |
| 15575 |
| 15576 /** |
| 15577 * Instances of the class `SimpleIdentifier` represent a simple identifier. |
| 15578 * |
| 15579 * <pre> |
| 15580 * simpleIdentifier ::= |
| 15581 * initialCharacter internalCharacter* |
| 15582 * |
| 15583 * initialCharacter ::= '_' | '$' | letter |
| 15584 * |
| 15585 * internalCharacter ::= '_' | '$' | letter | digit |
| 15586 * </pre> |
| 15587 */ |
| 15588 class SimpleIdentifier extends Identifier { |
| 15589 /** |
| 15590 * The token representing the identifier. |
| 15591 */ |
| 15592 Token token; |
| 15593 |
| 15594 /** |
| 15595 * The element associated with this identifier based on static type informatio
n, or `null` |
| 15596 * if the AST structure has not been resolved or if this identifier could not
be resolved. |
| 15597 */ |
| 15598 Element _staticElement; |
| 15599 |
| 15600 /** |
| 15601 * The element associated with this identifier based on propagated type inform
ation, or |
| 15602 * `null` if the AST structure has not been resolved or if this identifier cou
ld not be |
| 15603 * resolved. |
| 15604 */ |
| 15605 Element _propagatedElement; |
| 15606 |
| 15607 /** |
| 15608 * If this expression is both in a getter and setter context, the [AuxiliaryEl
ements] will |
| 15609 * be set to hold onto the static and propagated information. The auxiliary el
ement will hold onto |
| 15610 * the elements from the getter context. |
| 15611 */ |
| 15612 AuxiliaryElements auxiliaryElements = null; |
| 15613 |
| 15614 /** |
| 15615 * Initialize a newly created identifier. |
| 15616 * |
| 15617 * @param token the token representing the identifier |
| 15618 */ |
| 15619 SimpleIdentifier(this.token); |
| 15620 |
| 15621 @override |
| 15622 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this); |
| 15623 |
| 15624 @override |
| 15625 Token get beginToken => token; |
| 15626 |
| 15627 @override |
| 15628 Element get bestElement { |
| 15629 if (_propagatedElement == null) { |
| 15630 return _staticElement; |
| 15631 } |
| 15632 return _propagatedElement; |
| 15633 } |
| 15634 |
| 15635 @override |
| 15636 Token get endToken => token; |
| 15637 |
| 15638 @override |
| 15639 String get name => token.lexeme; |
| 15640 |
| 15641 @override |
| 15642 int get precedence => 16; |
| 15643 |
| 15644 @override |
| 15645 Element get propagatedElement => _propagatedElement; |
| 15646 |
| 15647 @override |
| 15648 Element get staticElement => _staticElement; |
| 15649 |
| 15650 /** |
| 15651 * Return `true` if this identifier is the name being declared in a declaratio
n. |
| 15652 * |
| 15653 * @return `true` if this identifier is the name being declared in a declarati
on |
| 15654 */ |
| 15655 bool inDeclarationContext() { |
| 15656 AstNode parent = this.parent; |
| 15657 if (parent is CatchClause) { |
| 15658 CatchClause clause = parent; |
| 15659 return identical(this, clause.exceptionParameter) || identical(this, claus
e.stackTraceParameter); |
| 15660 } else if (parent is ClassDeclaration) { |
| 15661 return identical(this, parent.name); |
| 15662 } else if (parent is ClassTypeAlias) { |
| 15663 return identical(this, parent.name); |
| 15664 } else if (parent is ConstructorDeclaration) { |
| 15665 return identical(this, parent.name); |
| 15666 } else if (parent is DeclaredIdentifier) { |
| 15667 return identical(this, parent.identifier); |
| 15668 } else if (parent is FunctionDeclaration) { |
| 15669 return identical(this, parent.name); |
| 15670 } else if (parent is FunctionTypeAlias) { |
| 15671 return identical(this, parent.name); |
| 15672 } else if (parent is Label) { |
| 15673 return identical(this, parent.label) && (parent.parent is LabeledStatement
); |
| 15674 } else if (parent is MethodDeclaration) { |
| 15675 return identical(this, parent.name); |
| 15676 } else if (parent is FunctionTypedFormalParameter || parent is SimpleFormalP
arameter) { |
| 15677 return identical(this, (parent as NormalFormalParameter).identifier); |
| 15678 } else if (parent is TypeParameter) { |
| 15679 return identical(this, parent.name); |
| 15680 } else if (parent is VariableDeclaration) { |
| 15681 return identical(this, parent.name); |
| 15682 } |
| 15683 return false; |
| 15684 } |
| 15685 |
| 15686 /** |
| 15687 * Return `true` if this expression is computing a right-hand value. |
| 15688 * |
| 15689 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar
e |
| 15690 * they mutually exclusive. In other words, it is possible for both methods to
return `true` |
| 15691 * when invoked on the same node. |
| 15692 * |
| 15693 * @return `true` if this expression is in a context where a getter will be in
voked |
| 15694 */ |
| 15695 bool inGetterContext() { |
| 15696 AstNode parent = this.parent; |
| 15697 AstNode target = this; |
| 15698 // skip prefix |
| 15699 if (parent is PrefixedIdentifier) { |
| 15700 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; |
| 15701 if (identical(prefixed.prefix, this)) { |
| 15702 return true; |
| 15703 } |
| 15704 parent = prefixed.parent; |
| 15705 target = prefixed; |
| 15706 } else if (parent is PropertyAccess) { |
| 15707 PropertyAccess access = parent as PropertyAccess; |
| 15708 if (identical(access.target, this)) { |
| 15709 return true; |
| 15710 } |
| 15711 parent = access.parent; |
| 15712 target = access; |
| 15713 } |
| 15714 // skip label |
| 15715 if (parent is Label) { |
| 15716 return false; |
| 15717 } |
| 15718 // analyze usage |
| 15719 if (parent is AssignmentExpression) { |
| 15720 AssignmentExpression expr = parent as AssignmentExpression; |
| 15721 if (identical(expr.leftHandSide, target) && expr.operator.type == TokenTyp
e.EQ) { |
| 15722 return false; |
| 15723 } |
| 15724 } |
| 15725 return true; |
| 15726 } |
| 15727 |
| 15728 /** |
| 15729 * Return `true` if this expression is computing a left-hand value. |
| 15730 * |
| 15731 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar
e |
| 15732 * they mutually exclusive. In other words, it is possible for both methods to
return `true` |
| 15733 * when invoked on the same node. |
| 15734 * |
| 15735 * @return `true` if this expression is in a context where a setter will be in
voked |
| 15736 */ |
| 15737 bool inSetterContext() { |
| 15738 AstNode parent = this.parent; |
| 15739 AstNode target = this; |
| 15740 // skip prefix |
| 15741 if (parent is PrefixedIdentifier) { |
| 15742 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; |
| 15743 // if this is the prefix, then return false |
| 15744 if (identical(prefixed.prefix, this)) { |
| 15745 return false; |
| 15746 } |
| 15747 parent = prefixed.parent; |
| 15748 target = prefixed; |
| 15749 } else if (parent is PropertyAccess) { |
| 15750 PropertyAccess access = parent as PropertyAccess; |
| 15751 if (identical(access.target, this)) { |
| 15752 return false; |
| 15753 } |
| 15754 parent = access.parent; |
| 15755 target = access; |
| 15756 } |
| 15757 // analyze usage |
| 15758 if (parent is PrefixExpression) { |
| 15759 return (parent as PrefixExpression).operator.type.isIncrementOperator; |
| 15760 } else if (parent is PostfixExpression) { |
| 15761 return true; |
| 15762 } else if (parent is AssignmentExpression) { |
| 15763 return identical((parent as AssignmentExpression).leftHandSide, target); |
| 15764 } |
| 15765 return false; |
| 15766 } |
| 15767 |
| 15768 /** |
| 15769 * Returns `true` if this identifier is the "name" part of a prefixed identifi
er or a method |
| 15770 * invocation. |
| 15771 * |
| 15772 * @return `true` if this identifier is the "name" part of a prefixed identifi
er or a method |
| 15773 * invocation |
| 15774 */ |
| 15775 bool get isQualified { |
| 15776 AstNode parent = this.parent; |
| 15777 if (parent is PrefixedIdentifier) { |
| 15778 return identical(parent.identifier, this); |
| 15779 } |
| 15780 if (parent is PropertyAccess) { |
| 15781 return identical(parent.propertyName, this); |
| 15782 } |
| 15783 if (parent is MethodInvocation) { |
| 15784 MethodInvocation invocation = parent; |
| 15785 return identical(invocation.methodName, this) && invocation.realTarget !=
null; |
| 15786 } |
| 15787 return false; |
| 15788 } |
| 15789 |
| 15790 @override |
| 15791 bool get isSynthetic => token.isSynthetic; |
| 15792 |
| 15793 /** |
| 15794 * Set the element associated with this identifier based on propagated type in
formation to the |
| 15795 * given element. |
| 15796 * |
| 15797 * @param element the element to be associated with this identifier |
| 15798 */ |
| 15799 void set propagatedElement(Element element) { |
| 15800 _propagatedElement = _validateElement(element); |
| 15801 } |
| 15802 |
| 15803 /** |
| 15804 * Set the element associated with this identifier based on static type inform
ation to the given |
| 15805 * element. |
| 15806 * |
| 15807 * @param element the element to be associated with this identifier |
| 15808 */ |
| 15809 void set staticElement(Element element) { |
| 15810 _staticElement = _validateElement(element); |
| 15811 } |
| 15812 |
| 15813 @override |
| 15814 void visitChildren(AstVisitor visitor) { |
| 15815 } |
| 15816 |
| 15817 /** |
| 15818 * Return the given element if it is valid, or report the problem and return `
null` if it is |
| 15819 * not appropriate. |
| 15820 * |
| 15821 * @param parent the parent of the element, used for reporting when there is a
problem |
| 15822 * @param isValid `true` if the element is appropriate |
| 15823 * @param element the element to be associated with this identifier |
| 15824 * @return the element to be associated with this identifier |
| 15825 */ |
| 15826 Element _returnOrReportElement(AstNode parent, bool isValid, Element element)
{ |
| 15827 if (!isValid) { |
| 15828 AnalysisEngine.instance.logger.logInformation2("Internal error: attempting
to set the name of a ${parent.runtimeType.toString()} to a ${element.runtimeTyp
e.toString()}", new JavaException()); |
| 15829 return null; |
| 15830 } |
| 15831 return element; |
| 15832 } |
| 15833 |
| 15834 /** |
| 15835 * Return the given element if it is an appropriate element based on the paren
t of this |
| 15836 * identifier, or `null` if it is not appropriate. |
| 15837 * |
| 15838 * @param element the element to be associated with this identifier |
| 15839 * @return the element to be associated with this identifier |
| 15840 */ |
| 15841 Element _validateElement(Element element) { |
| 15842 if (element == null) { |
| 15843 return null; |
| 15844 } |
| 15845 AstNode parent = this.parent; |
| 15846 if (parent is ClassDeclaration && identical(parent.name, this)) { |
| 15847 return _returnOrReportElement(parent, element is ClassElement, element); |
| 15848 } else if (parent is ClassTypeAlias && identical(parent.name, this)) { |
| 15849 return _returnOrReportElement(parent, element is ClassElement, element); |
| 15850 } else if (parent is DeclaredIdentifier && identical(parent.identifier, this
)) { |
| 15851 return _returnOrReportElement(parent, element is LocalVariableElement, ele
ment); |
| 15852 } else if (parent is FormalParameter && identical(parent.identifier, this))
{ |
| 15853 return _returnOrReportElement(parent, element is ParameterElement, element
); |
| 15854 } else if (parent is FunctionDeclaration && identical(parent.name, this)) { |
| 15855 return _returnOrReportElement(parent, element is ExecutableElement, elemen
t); |
| 15856 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) { |
| 15857 return _returnOrReportElement(parent, element is FunctionTypeAliasElement,
element); |
| 15858 } else if (parent is MethodDeclaration && identical(parent.name, this)) { |
| 15859 return _returnOrReportElement(parent, element is ExecutableElement, elemen
t); |
| 15860 } else if (parent is TypeParameter && identical(parent.name, this)) { |
| 15861 return _returnOrReportElement(parent, element is TypeParameterElement, ele
ment); |
| 15862 } else if (parent is VariableDeclaration && identical(parent.name, this)) { |
| 15863 return _returnOrReportElement(parent, element is VariableElement, element)
; |
| 15864 } |
| 15865 return element; |
| 15866 } |
| 15867 } |
| 15868 |
| 15869 /** |
| 15870 * Instances of the class `SimpleStringLiteral` represent a string literal expre
ssion that |
| 15871 * does not contain any interpolations. |
| 15872 * |
| 15873 * <pre> |
| 15874 * simpleStringLiteral ::= |
| 15875 * rawStringLiteral |
| 15876 * | basicStringLiteral |
| 15877 * |
| 15878 * rawStringLiteral ::= |
| 15879 * 'r' basicStringLiteral |
| 15880 * |
| 15881 * simpleStringLiteral ::= |
| 15882 * multiLineStringLiteral |
| 15883 * | singleLineStringLiteral |
| 15884 * |
| 15885 * multiLineStringLiteral ::= |
| 15886 * "'''" characters "'''" |
| 15887 * | '"""' characters '"""' |
| 15888 * |
| 15889 * singleLineStringLiteral ::= |
| 15890 * "'" characters "'" |
| 15891 * '"' characters '"' |
| 15892 * </pre> |
| 15893 */ |
| 15894 class SimpleStringLiteral extends StringLiteral { |
| 15895 /** |
| 15896 * The token representing the literal. |
| 15897 */ |
| 15898 Token literal; |
| 15899 |
| 15900 /** |
| 15901 * The value of the literal. |
| 15902 */ |
| 15903 String _value; |
| 15904 |
| 15905 /** |
| 15906 * The toolkit specific element associated with this literal, or `null`. |
| 15907 */ |
| 15908 Element _toolkitElement; |
| 15909 |
| 15910 /** |
| 15911 * Initialize a newly created simple string literal. |
| 15912 * |
| 15913 * @param literal the token representing the literal |
| 15914 * @param value the value of the literal |
| 15915 */ |
| 15916 SimpleStringLiteral(this.literal, String value) { |
| 15917 this._value = StringUtilities.intern(value); |
| 15918 } |
| 15919 |
| 15920 @override |
| 15921 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this); |
| 15922 |
| 15923 @override |
| 15924 Token get beginToken => literal; |
| 15925 |
| 15926 @override |
| 15927 Token get endToken => literal; |
| 15928 |
| 15929 /** |
| 15930 * Return the toolkit specific, non-Dart, element associated with this literal
, or `null`. |
| 15931 * |
| 15932 * @return the element associated with this literal |
| 15933 */ |
| 15934 Element get toolkitElement => _toolkitElement; |
| 15935 |
| 15936 /** |
| 15937 * Return the value of the literal. |
| 15938 * |
| 15939 * @return the value of the literal |
| 15940 */ |
| 15941 String get value => _value; |
| 15942 |
| 15943 /** |
| 15944 * Return the offset of the first value character. |
| 15945 * |
| 15946 * @return the offset of the first value character |
| 15947 */ |
| 15948 int get valueOffset { |
| 15949 int valueOffset = 0; |
| 15950 if (isRaw) { |
| 15951 valueOffset += 1; |
| 15952 } |
| 15953 if (isMultiline) { |
| 15954 valueOffset += 3; |
| 15955 } else { |
| 15956 valueOffset += 1; |
| 15957 } |
| 15958 return offset + valueOffset; |
| 15959 } |
| 15960 |
| 15961 /** |
| 15962 * Return `true` if this string literal is a multi-line string. |
| 15963 * |
| 15964 * @return `true` if this string literal is a multi-line string |
| 15965 */ |
| 15966 bool get isMultiline { |
| 15967 String lexeme = literal.lexeme; |
| 15968 if (lexeme.length < 6) { |
| 15969 return false; |
| 15970 } |
| 15971 return StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || StringUtilitie
s.endsWith3(lexeme, 0x27, 0x27, 0x27); |
| 15972 } |
| 15973 |
| 15974 /** |
| 15975 * Return `true` if this string literal is a raw string. |
| 15976 * |
| 15977 * @return `true` if this string literal is a raw string |
| 15978 */ |
| 15979 bool get isRaw => literal.lexeme.codeUnitAt(0) == 0x72; |
| 15980 |
| 15981 @override |
| 15982 bool get isSynthetic => literal.isSynthetic; |
| 15983 |
| 15984 /** |
| 15985 * Set the toolkit specific, non-Dart, element associated with this literal. |
| 15986 * |
| 15987 * @param element the toolkit specific element to be associated with this lite
ral |
| 15988 */ |
| 15989 void set toolkitElement(Element element) { |
| 15990 _toolkitElement = element; |
| 15991 } |
| 15992 |
| 15993 /** |
| 15994 * Set the value of the literal to the given string. |
| 15995 * |
| 15996 * @param string the value of the literal |
| 15997 */ |
| 15998 void set value(String string) { |
| 15999 _value = StringUtilities.intern(_value); |
| 16000 } |
| 16001 |
| 16002 @override |
| 16003 void visitChildren(AstVisitor visitor) { |
| 16004 } |
| 16005 |
| 16006 @override |
| 16007 void appendStringValue(JavaStringBuilder builder) { |
| 16008 builder.append(value); |
| 16009 } |
| 16010 } |
| 16011 |
| 16012 /** |
| 16013 * Instances of the class `Statement` defines the behavior common to nodes that
represent a |
| 16014 * statement. |
| 16015 * |
| 16016 * <pre> |
| 16017 * statement ::= |
| 16018 * [Block] |
| 16019 * | [VariableDeclarationStatement] |
| 16020 * | [ForStatement] |
| 16021 * | [ForEachStatement] |
| 16022 * | [WhileStatement] |
| 16023 * | [DoStatement] |
| 16024 * | [SwitchStatement] |
| 16025 * | [IfStatement] |
| 16026 * | [TryStatement] |
| 16027 * | [BreakStatement] |
| 16028 * | [ContinueStatement] |
| 16029 * | [ReturnStatement] |
| 16030 * | [ExpressionStatement] |
| 16031 * | [FunctionDeclarationStatement] |
| 16032 * </pre> |
| 16033 */ |
| 16034 abstract class Statement extends AstNode { |
| 16035 } |
| 16036 |
| 16037 /** |
| 16038 * Instances of the class `StringInterpolation` represent a string interpolation
literal. |
| 16039 * |
| 16040 * <pre> |
| 16041 * stringInterpolation ::= |
| 16042 * ''' [InterpolationElement]* ''' |
| 16043 * | '"' [InterpolationElement]* '"' |
| 16044 * </pre> |
| 16045 */ |
| 16046 class StringInterpolation extends StringLiteral { |
| 16047 /** |
| 16048 * The elements that will be composed to produce the resulting string. |
| 16049 */ |
| 16050 NodeList<InterpolationElement> _elements; |
| 16051 |
| 16052 /** |
| 16053 * Initialize a newly created string interpolation expression. |
| 16054 * |
| 16055 * @param elements the elements that will be composed to produce the resulting
string |
| 16056 */ |
| 16057 StringInterpolation(List<InterpolationElement> elements) { |
| 16058 this._elements = new NodeList<InterpolationElement>(this); |
| 16059 this._elements.addAll(elements); |
| 16060 } |
| 16061 |
| 16062 @override |
| 16063 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this); |
| 16064 |
| 16065 @override |
| 16066 Token get beginToken => _elements.beginToken; |
| 16067 |
| 16068 /** |
| 16069 * Return the elements that will be composed to produce the resulting string. |
| 16070 * |
| 16071 * @return the elements that will be composed to produce the resulting string |
| 16072 */ |
| 16073 NodeList<InterpolationElement> get elements => _elements; |
| 16074 |
| 16075 @override |
| 16076 Token get endToken => _elements.endToken; |
| 16077 |
| 16078 @override |
| 16079 void visitChildren(AstVisitor visitor) { |
| 16080 _elements.accept(visitor); |
| 16081 } |
| 16082 |
| 16083 @override |
| 16084 void appendStringValue(JavaStringBuilder builder) { |
| 16085 throw new IllegalArgumentException(); |
| 16086 } |
| 16087 } |
| 16088 |
| 16089 /** |
| 16090 * Instances of the class `StringLiteral` represent a string literal expression. |
| 16091 * |
| 16092 * <pre> |
| 16093 * stringLiteral ::= |
| 16094 * [SimpleStringLiteral] |
| 16095 * | [AdjacentStrings] |
| 16096 * | [StringInterpolation] |
| 16097 * </pre> |
| 16098 */ |
| 16099 abstract class StringLiteral extends Literal { |
| 16100 /** |
| 16101 * Return the value of the string literal, or `null` if the string is not a co
nstant string |
| 16102 * without any string interpolation. |
| 16103 * |
| 16104 * @return the value of the string literal |
| 16105 */ |
| 16106 String get stringValue { |
| 16107 JavaStringBuilder builder = new JavaStringBuilder(); |
| 16108 try { |
| 16109 appendStringValue(builder); |
| 16110 } on IllegalArgumentException catch (exception) { |
| 16111 return null; |
| 16112 } |
| 16113 return builder.toString(); |
| 16114 } |
| 16115 |
| 16116 /** |
| 16117 * Append the value of the given string literal to the given string builder. |
| 16118 * |
| 16119 * @param builder the builder to which the string's value is to be appended |
| 16120 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string |
| 16121 * interpolation |
| 16122 */ |
| 16123 void appendStringValue(JavaStringBuilder builder); |
| 16124 } |
| 16125 |
| 16126 /** |
| 16127 * Instances of the class `SuperConstructorInvocation` represent the invocation
of a |
| 16128 * superclass' constructor from within a constructor's initialization list. |
| 16129 * |
| 16130 * <pre> |
| 16131 * superInvocation ::= |
| 16132 * 'super' ('.' [SimpleIdentifier])? [ArgumentList] |
| 16133 * </pre> |
| 16134 */ |
| 16135 class SuperConstructorInvocation extends ConstructorInitializer { |
| 16136 /** |
| 16137 * The token for the 'super' keyword. |
| 16138 */ |
| 16139 Token keyword; |
| 16140 |
| 16141 /** |
| 16142 * The token for the period before the name of the constructor that is being i
nvoked, or |
| 16143 * `null` if the unnamed constructor is being invoked. |
| 16144 */ |
| 16145 Token period; |
| 16146 |
| 16147 /** |
| 16148 * The name of the constructor that is being invoked, or `null` if the unnamed
constructor |
| 16149 * is being invoked. |
| 16150 */ |
| 16151 SimpleIdentifier _constructorName; |
| 16152 |
| 16153 /** |
| 16154 * The list of arguments to the constructor. |
| 16155 */ |
| 16156 ArgumentList _argumentList; |
| 16157 |
| 16158 /** |
| 16159 * The element associated with the constructor based on static type informatio
n, or `null` |
| 16160 * if the AST structure has not been resolved or if the constructor could not
be resolved. |
| 16161 */ |
| 16162 ConstructorElement staticElement; |
| 16163 |
| 16164 /** |
| 16165 * Initialize a newly created super invocation to invoke the inherited constru
ctor with the given |
| 16166 * name with the given arguments. |
| 16167 * |
| 16168 * @param keyword the token for the 'super' keyword |
| 16169 * @param period the token for the period before the name of the constructor t
hat is being invoked |
| 16170 * @param constructorName the name of the constructor that is being invoked |
| 16171 * @param argumentList the list of arguments to the constructor |
| 16172 */ |
| 16173 SuperConstructorInvocation(this.keyword, this.period, SimpleIdentifier constru
ctorName, ArgumentList argumentList) { |
| 16174 this._constructorName = becomeParentOf(constructorName); |
| 16175 this._argumentList = becomeParentOf(argumentList); |
| 16176 } |
| 16177 |
| 16178 @override |
| 16179 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this); |
| 16180 |
| 16181 /** |
| 16182 * Return the list of arguments to the constructor. |
| 16183 * |
| 16184 * @return the list of arguments to the constructor |
| 16185 */ |
| 16186 ArgumentList get argumentList => _argumentList; |
| 16187 |
| 16188 @override |
| 16189 Token get beginToken => keyword; |
| 16190 |
| 16191 /** |
| 16192 * Return the name of the constructor that is being invoked, or `null` if the
unnamed |
| 16193 * constructor is being invoked. |
| 16194 * |
| 16195 * @return the name of the constructor that is being invoked |
| 16196 */ |
| 16197 SimpleIdentifier get constructorName => _constructorName; |
| 16198 |
| 16199 @override |
| 16200 Token get endToken => _argumentList.endToken; |
| 16201 |
| 16202 /** |
| 16203 * Set the list of arguments to the constructor to the given list. |
| 16204 * |
| 16205 * @param argumentList the list of arguments to the constructor |
| 16206 */ |
| 16207 void set argumentList(ArgumentList argumentList) { |
| 16208 this._argumentList = becomeParentOf(argumentList); |
| 16209 } |
| 16210 |
| 16211 /** |
| 16212 * Set the name of the constructor that is being invoked to the given identifi
er. |
| 16213 * |
| 16214 * @param identifier the name of the constructor that is being invoked |
| 16215 */ |
| 16216 void set constructorName(SimpleIdentifier identifier) { |
| 16217 _constructorName = becomeParentOf(identifier); |
| 16218 } |
| 16219 |
| 16220 @override |
| 16221 void visitChildren(AstVisitor visitor) { |
| 16222 safelyVisitChild(_constructorName, visitor); |
| 16223 safelyVisitChild(_argumentList, visitor); |
| 16224 } |
| 16225 } |
| 16226 |
| 16227 /** |
| 16228 * Instances of the class `SuperExpression` represent a super expression. |
| 16229 * |
| 16230 * <pre> |
| 16231 * superExpression ::= |
| 16232 * 'super' |
| 16233 * </pre> |
| 16234 */ |
| 16235 class SuperExpression extends Expression { |
| 16236 /** |
| 16237 * The token representing the keyword. |
| 16238 */ |
| 16239 Token keyword; |
| 16240 |
| 16241 /** |
| 16242 * Initialize a newly created super expression. |
| 16243 * |
| 16244 * @param keyword the token representing the keyword |
| 16245 */ |
| 16246 SuperExpression(this.keyword); |
| 16247 |
| 16248 @override |
| 16249 accept(AstVisitor visitor) => visitor.visitSuperExpression(this); |
| 16250 |
| 16251 @override |
| 16252 Token get beginToken => keyword; |
| 16253 |
| 16254 @override |
| 16255 Token get endToken => keyword; |
| 16256 |
| 16257 @override |
| 16258 int get precedence => 16; |
| 16259 |
| 16260 @override |
| 16261 void visitChildren(AstVisitor visitor) { |
| 16262 } |
| 16263 } |
| 16264 |
| 16265 /** |
| 16266 * Instances of the class `SwitchCase` represent the case in a switch statement. |
| 16267 * |
| 16268 * <pre> |
| 16269 * switchCase ::= |
| 16270 * [SimpleIdentifier]* 'case' [Expression] ':' [Statement]* |
| 16271 * </pre> |
| 16272 */ |
| 16273 class SwitchCase extends SwitchMember { |
| 16274 /** |
| 16275 * The expression controlling whether the statements will be executed. |
| 16276 */ |
| 16277 Expression _expression; |
| 16278 |
| 16279 /** |
| 16280 * Initialize a newly created switch case. |
| 16281 * |
| 16282 * @param labels the labels associated with the switch member |
| 16283 * @param keyword the token representing the 'case' or 'default' keyword |
| 16284 * @param expression the expression controlling whether the statements will be
executed |
| 16285 * @param colon the colon separating the keyword or the expression from the st
atements |
| 16286 * @param statements the statements that will be executed if this switch membe
r is selected |
| 16287 */ |
| 16288 SwitchCase(List<Label> labels, Token keyword, Expression expression, Token col
on, List<Statement> statements) : super(labels, keyword, colon, statements) { |
| 16289 this._expression = becomeParentOf(expression); |
| 16290 } |
| 16291 |
| 16292 @override |
| 16293 accept(AstVisitor visitor) => visitor.visitSwitchCase(this); |
| 16294 |
| 16295 /** |
| 16296 * Return the expression controlling whether the statements will be executed. |
| 16297 * |
| 16298 * @return the expression controlling whether the statements will be executed |
| 16299 */ |
| 16300 Expression get expression => _expression; |
| 16301 |
| 16302 /** |
| 16303 * Set the expression controlling whether the statements will be executed to t
he given expression. |
| 16304 * |
| 16305 * @param expression the expression controlling whether the statements will be
executed |
| 16306 */ |
| 16307 void set expression(Expression expression) { |
| 16308 this._expression = becomeParentOf(expression); |
| 16309 } |
| 16310 |
| 16311 @override |
| 16312 void visitChildren(AstVisitor visitor) { |
| 16313 labels.accept(visitor); |
| 16314 safelyVisitChild(_expression, visitor); |
| 16315 statements.accept(visitor); |
| 16316 } |
| 16317 } |
| 16318 |
| 16319 /** |
| 16320 * Instances of the class `SwitchDefault` represent the default case in a switch
statement. |
| 16321 * |
| 16322 * <pre> |
| 16323 * switchDefault ::= |
| 16324 * [SimpleIdentifier]* 'default' ':' [Statement]* |
| 16325 * </pre> |
| 16326 */ |
| 16327 class SwitchDefault extends SwitchMember { |
| 16328 /** |
| 16329 * Initialize a newly created switch default. |
| 16330 * |
| 16331 * @param labels the labels associated with the switch member |
| 16332 * @param keyword the token representing the 'case' or 'default' keyword |
| 16333 * @param colon the colon separating the keyword or the expression from the st
atements |
| 16334 * @param statements the statements that will be executed if this switch membe
r is selected |
| 16335 */ |
| 16336 SwitchDefault(List<Label> labels, Token keyword, Token colon, List<Statement>
statements) : super(labels, keyword, colon, statements); |
| 16337 |
| 16338 @override |
| 16339 accept(AstVisitor visitor) => visitor.visitSwitchDefault(this); |
| 16340 |
| 16341 @override |
| 16342 void visitChildren(AstVisitor visitor) { |
| 16343 labels.accept(visitor); |
| 16344 statements.accept(visitor); |
| 16345 } |
| 16346 } |
| 16347 |
| 16348 /** |
| 16349 * The abstract class `SwitchMember` defines the behavior common to objects repr
esenting |
| 16350 * elements within a switch statement. |
| 16351 * |
| 16352 * <pre> |
| 16353 * switchMember ::= |
| 16354 * switchCase |
| 16355 * | switchDefault |
| 16356 * </pre> |
| 16357 */ |
| 16358 abstract class SwitchMember extends AstNode { |
| 16359 /** |
| 16360 * The labels associated with the switch member. |
| 16361 */ |
| 16362 NodeList<Label> _labels; |
| 16363 |
| 16364 /** |
| 16365 * The token representing the 'case' or 'default' keyword. |
| 16366 */ |
| 16367 Token keyword; |
| 16368 |
| 16369 /** |
| 16370 * The colon separating the keyword or the expression from the statements. |
| 16371 */ |
| 16372 Token colon; |
| 16373 |
| 16374 /** |
| 16375 * The statements that will be executed if this switch member is selected. |
| 16376 */ |
| 16377 NodeList<Statement> _statements; |
| 16378 |
| 16379 /** |
| 16380 * Initialize a newly created switch member. |
| 16381 * |
| 16382 * @param labels the labels associated with the switch member |
| 16383 * @param keyword the token representing the 'case' or 'default' keyword |
| 16384 * @param colon the colon separating the keyword or the expression from the st
atements |
| 16385 * @param statements the statements that will be executed if this switch membe
r is selected |
| 16386 */ |
| 16387 SwitchMember(List<Label> labels, this.keyword, this.colon, List<Statement> sta
tements) { |
| 16388 this._labels = new NodeList<Label>(this); |
| 16389 this._statements = new NodeList<Statement>(this); |
| 16390 this._labels.addAll(labels); |
| 16391 this._statements.addAll(statements); |
| 16392 } |
| 16393 |
| 16394 @override |
| 16395 Token get beginToken { |
| 16396 if (!_labels.isEmpty) { |
| 16397 return _labels.beginToken; |
| 16398 } |
| 16399 return keyword; |
| 16400 } |
| 16401 |
| 16402 @override |
| 16403 Token get endToken { |
| 16404 if (!_statements.isEmpty) { |
| 16405 return _statements.endToken; |
| 16406 } |
| 16407 return colon; |
| 16408 } |
| 16409 |
| 16410 /** |
| 16411 * Return the labels associated with the switch member. |
| 16412 * |
| 16413 * @return the labels associated with the switch member |
| 16414 */ |
| 16415 NodeList<Label> get labels => _labels; |
| 16416 |
| 16417 /** |
| 16418 * Return the statements that will be executed if this switch member is select
ed. |
| 16419 * |
| 16420 * @return the statements that will be executed if this switch member is selec
ted |
| 16421 */ |
| 16422 NodeList<Statement> get statements => _statements; |
| 16423 } |
| 16424 |
| 16425 /** |
| 16426 * Instances of the class `SwitchStatement` represent a switch statement. |
| 16427 * |
| 16428 * <pre> |
| 16429 * switchStatement ::= |
| 16430 * 'switch' '(' [Expression] ')' '{' [SwitchCase]* [SwitchDefault]? '}' |
| 16431 * </pre> |
| 16432 */ |
| 16433 class SwitchStatement extends Statement { |
| 16434 /** |
| 16435 * The token representing the 'switch' keyword. |
| 16436 */ |
| 16437 Token keyword; |
| 16438 |
| 16439 /** |
| 16440 * The left parenthesis. |
| 16441 */ |
| 16442 Token leftParenthesis; |
| 16443 |
| 16444 /** |
| 16445 * The expression used to determine which of the switch members will be select
ed. |
| 16446 */ |
| 16447 Expression _expression; |
| 16448 |
| 16449 /** |
| 16450 * The right parenthesis. |
| 16451 */ |
| 16452 Token rightParenthesis; |
| 16453 |
| 16454 /** |
| 16455 * The left curly bracket. |
| 16456 */ |
| 16457 Token leftBracket; |
| 16458 |
| 16459 /** |
| 16460 * The switch members that can be selected by the expression. |
| 16461 */ |
| 16462 NodeList<SwitchMember> _members; |
| 16463 |
| 16464 /** |
| 16465 * The right curly bracket. |
| 16466 */ |
| 16467 Token rightBracket; |
| 16468 |
| 16469 /** |
| 16470 * Initialize a newly created switch statement. |
| 16471 * |
| 16472 * @param keyword the token representing the 'switch' keyword |
| 16473 * @param leftParenthesis the left parenthesis |
| 16474 * @param expression the expression used to determine which of the switch memb
ers will be selected |
| 16475 * @param rightParenthesis the right parenthesis |
| 16476 * @param leftBracket the left curly bracket |
| 16477 * @param members the switch members that can be selected by the expression |
| 16478 * @param rightBracket the right curly bracket |
| 16479 */ |
| 16480 SwitchStatement(this.keyword, this.leftParenthesis, Expression expression, thi
s.rightParenthesis, this.leftBracket, List<SwitchMember> members, this.rightBrac
ket) { |
| 16481 this._members = new NodeList<SwitchMember>(this); |
| 16482 this._expression = becomeParentOf(expression); |
| 16483 this._members.addAll(members); |
| 16484 } |
| 16485 |
| 16486 @override |
| 16487 accept(AstVisitor visitor) => visitor.visitSwitchStatement(this); |
| 16488 |
| 16489 @override |
| 16490 Token get beginToken => keyword; |
| 16491 |
| 16492 @override |
| 16493 Token get endToken => rightBracket; |
| 16494 |
| 16495 /** |
| 16496 * Return the expression used to determine which of the switch members will be
selected. |
| 16497 * |
| 16498 * @return the expression used to determine which of the switch members will b
e selected |
| 16499 */ |
| 16500 Expression get expression => _expression; |
| 16501 |
| 16502 /** |
| 16503 * Return the switch members that can be selected by the expression. |
| 16504 * |
| 16505 * @return the switch members that can be selected by the expression |
| 16506 */ |
| 16507 NodeList<SwitchMember> get members => _members; |
| 16508 |
| 16509 /** |
| 16510 * Set the expression used to determine which of the switch members will be se
lected to the given |
| 16511 * expression. |
| 16512 * |
| 16513 * @param expression the expression used to determine which of the switch memb
ers will be selected |
| 16514 */ |
| 16515 void set expression(Expression expression) { |
| 16516 this._expression = becomeParentOf(expression); |
| 16517 } |
| 16518 |
| 16519 @override |
| 16520 void visitChildren(AstVisitor visitor) { |
| 16521 safelyVisitChild(_expression, visitor); |
| 16522 _members.accept(visitor); |
| 16523 } |
| 16524 } |
| 16525 |
| 16526 /** |
| 16527 * Instances of the class `SymbolLiteral` represent a symbol literal expression. |
| 16528 * |
| 16529 * <pre> |
| 16530 * symbolLiteral ::= |
| 16531 * '#' (operator | (identifier ('.' identifier)*)) |
| 16532 * </pre> |
| 16533 */ |
| 16534 class SymbolLiteral extends Literal { |
| 16535 /** |
| 16536 * The token introducing the literal. |
| 16537 */ |
| 16538 Token poundSign; |
| 16539 |
| 16540 /** |
| 16541 * The components of the literal. |
| 16542 */ |
| 16543 final List<Token> components; |
| 16544 |
| 16545 /** |
| 16546 * Initialize a newly created symbol literal. |
| 16547 * |
| 16548 * @param poundSign the token introducing the literal |
| 16549 * @param components the components of the literal |
| 16550 */ |
| 16551 SymbolLiteral(this.poundSign, this.components); |
| 16552 |
| 16553 @override |
| 16554 accept(AstVisitor visitor) => visitor.visitSymbolLiteral(this); |
| 16555 |
| 16556 @override |
| 16557 Token get beginToken => poundSign; |
| 16558 |
| 16559 @override |
| 16560 Token get endToken => components[components.length - 1]; |
| 16561 |
| 16562 @override |
| 16563 void visitChildren(AstVisitor visitor) { |
| 16564 } |
| 16565 } |
| 16566 |
| 16567 /** |
| 16568 * Instances of the class `ThisExpression` represent a this expression. |
| 16569 * |
| 16570 * <pre> |
| 16571 * thisExpression ::= |
| 16572 * 'this' |
| 16573 * </pre> |
| 16574 */ |
| 16575 class ThisExpression extends Expression { |
| 16576 /** |
| 16577 * The token representing the keyword. |
| 16578 */ |
| 16579 Token keyword; |
| 16580 |
| 16581 /** |
| 16582 * Initialize a newly created this expression. |
| 16583 * |
| 16584 * @param keyword the token representing the keyword |
| 16585 */ |
| 16586 ThisExpression(this.keyword); |
| 16587 |
| 16588 @override |
| 16589 accept(AstVisitor visitor) => visitor.visitThisExpression(this); |
| 16590 |
| 16591 @override |
| 16592 Token get beginToken => keyword; |
| 16593 |
| 16594 @override |
| 16595 Token get endToken => keyword; |
| 16596 |
| 16597 @override |
| 16598 int get precedence => 16; |
| 16599 |
| 16600 @override |
| 16601 void visitChildren(AstVisitor visitor) { |
| 16602 } |
| 16603 } |
| 16604 |
| 16605 /** |
| 16606 * Instances of the class `ThrowExpression` represent a throw expression. |
| 16607 * |
| 16608 * <pre> |
| 16609 * throwExpression ::= |
| 16610 * 'throw' [Expression] |
| 16611 * </pre> |
| 16612 */ |
| 16613 class ThrowExpression extends Expression { |
| 16614 /** |
| 16615 * The token representing the 'throw' keyword. |
| 16616 */ |
| 16617 Token keyword; |
| 16618 |
| 16619 /** |
| 16620 * The expression computing the exception to be thrown. |
| 16621 */ |
| 16622 Expression _expression; |
| 16623 |
| 16624 /** |
| 16625 * Initialize a newly created throw expression. |
| 16626 * |
| 16627 * @param keyword the token representing the 'throw' keyword |
| 16628 * @param expression the expression computing the exception to be thrown |
| 16629 */ |
| 16630 ThrowExpression(this.keyword, Expression expression) { |
| 16631 this._expression = becomeParentOf(expression); |
| 16632 } |
| 16633 |
| 16634 @override |
| 16635 accept(AstVisitor visitor) => visitor.visitThrowExpression(this); |
| 16636 |
| 16637 @override |
| 16638 Token get beginToken => keyword; |
| 16639 |
| 16640 @override |
| 16641 Token get endToken { |
| 16642 if (_expression != null) { |
| 16643 return _expression.endToken; |
| 16644 } |
| 16645 return keyword; |
| 16646 } |
| 16647 |
| 16648 /** |
| 16649 * Return the expression computing the exception to be thrown. |
| 16650 * |
| 16651 * @return the expression computing the exception to be thrown |
| 16652 */ |
| 16653 Expression get expression => _expression; |
| 16654 |
| 16655 @override |
| 16656 int get precedence => 0; |
| 16657 |
| 16658 /** |
| 16659 * Set the expression computing the exception to be thrown to the given expres
sion. |
| 16660 * |
| 16661 * @param expression the expression computing the exception to be thrown |
| 16662 */ |
| 16663 void set expression(Expression expression) { |
| 16664 this._expression = becomeParentOf(expression); |
| 16665 } |
| 16666 |
| 16667 @override |
| 16668 void visitChildren(AstVisitor visitor) { |
| 16669 safelyVisitChild(_expression, visitor); |
| 16670 } |
| 16671 } |
| 16672 |
| 16673 /** |
| 16674 * Instances of the class `ToSourceVisitor` write a source representation of a v
isited AST |
| 16675 * node (and all of it's children) to a writer. |
| 16676 */ |
| 16677 class ToSourceVisitor implements AstVisitor<Object> { |
| 16678 /** |
| 16679 * The writer to which the source is to be written. |
| 16680 */ |
| 16681 final PrintWriter _writer; |
| 16682 |
| 16683 /** |
| 16684 * Initialize a newly created visitor to write source code representing the vi
sited nodes to the |
| 16685 * given writer. |
| 16686 * |
| 16687 * @param writer the writer to which the source is to be written |
| 16688 */ |
| 16689 ToSourceVisitor(this._writer); |
| 16690 |
| 16691 @override |
| 16692 Object visitAdjacentStrings(AdjacentStrings node) { |
| 16693 _visitNodeListWithSeparator(node.strings, " "); |
| 16694 return null; |
| 16695 } |
| 16696 |
| 16697 @override |
| 16698 Object visitAnnotation(Annotation node) { |
| 16699 _writer.print('@'); |
| 16700 _visitNode(node.name); |
| 16701 _visitNodeWithPrefix(".", node.constructorName); |
| 16702 _visitNode(node.arguments); |
| 16703 return null; |
| 16704 } |
| 16705 |
| 16706 @override |
| 16707 Object visitArgumentList(ArgumentList node) { |
| 16708 _writer.print('('); |
| 16709 _visitNodeListWithSeparator(node.arguments, ", "); |
| 16710 _writer.print(')'); |
| 16711 return null; |
| 16712 } |
| 16713 |
| 16714 @override |
| 16715 Object visitAsExpression(AsExpression node) { |
| 16716 _visitNode(node.expression); |
| 16717 _writer.print(" as "); |
| 16718 _visitNode(node.type); |
| 16719 return null; |
| 16720 } |
| 16721 |
| 16722 @override |
| 16723 Object visitAssertStatement(AssertStatement node) { |
| 16724 _writer.print("assert ("); |
| 16725 _visitNode(node.condition); |
| 16726 _writer.print(");"); |
| 16727 return null; |
| 16728 } |
| 16729 |
| 16730 @override |
| 16731 Object visitAssignmentExpression(AssignmentExpression node) { |
| 16732 _visitNode(node.leftHandSide); |
| 16733 _writer.print(' '); |
| 16734 _writer.print(node.operator.lexeme); |
| 16735 _writer.print(' '); |
| 16736 _visitNode(node.rightHandSide); |
| 16737 return null; |
| 16738 } |
| 16739 |
| 16740 @override |
| 16741 Object visitAwaitExpression(AwaitExpression node) { |
| 16742 _writer.print("await "); |
| 16743 _visitNode(node.expression); |
| 16744 _writer.print(";"); |
| 16745 return null; |
| 16746 } |
| 16747 |
| 16748 @override |
| 16749 Object visitBinaryExpression(BinaryExpression node) { |
| 16750 _visitNode(node.leftOperand); |
| 16751 _writer.print(' '); |
| 16752 _writer.print(node.operator.lexeme); |
| 16753 _writer.print(' '); |
| 16754 _visitNode(node.rightOperand); |
| 16755 return null; |
| 16756 } |
| 16757 |
| 16758 @override |
| 16759 Object visitBlock(Block node) { |
| 16760 _writer.print('{'); |
| 16761 _visitNodeListWithSeparator(node.statements, " "); |
| 16762 _writer.print('}'); |
| 16763 return null; |
| 16764 } |
| 16765 |
| 16766 @override |
| 16767 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 16768 Token keyword = node.keyword; |
| 16769 if (keyword != null) { |
| 16770 _writer.print(keyword.lexeme); |
| 16771 if (node.star != null) { |
| 16772 _writer.print('*'); |
| 16773 } |
| 16774 _writer.print(' '); |
| 16775 } |
| 16776 _visitNode(node.block); |
| 16777 return null; |
| 16778 } |
| 16779 |
| 16780 @override |
| 16781 Object visitBooleanLiteral(BooleanLiteral node) { |
| 16782 _writer.print(node.literal.lexeme); |
| 16783 return null; |
| 16784 } |
| 16785 |
| 16786 @override |
| 16787 Object visitBreakStatement(BreakStatement node) { |
| 16788 _writer.print("break"); |
| 16789 _visitNodeWithPrefix(" ", node.label); |
| 16790 _writer.print(";"); |
| 16791 return null; |
| 16792 } |
| 16793 |
| 16794 @override |
| 16795 Object visitCascadeExpression(CascadeExpression node) { |
| 16796 _visitNode(node.target); |
| 16797 _visitNodeList(node.cascadeSections); |
| 16798 return null; |
| 16799 } |
| 16800 |
| 16801 @override |
| 16802 Object visitCatchClause(CatchClause node) { |
| 16803 _visitNodeWithPrefix("on ", node.exceptionType); |
| 16804 if (node.catchKeyword != null) { |
| 16805 if (node.exceptionType != null) { |
| 16806 _writer.print(' '); |
| 16807 } |
| 16808 _writer.print("catch ("); |
| 16809 _visitNode(node.exceptionParameter); |
| 16810 _visitNodeWithPrefix(", ", node.stackTraceParameter); |
| 16811 _writer.print(") "); |
| 16812 } else { |
| 16813 _writer.print(" "); |
| 16814 } |
| 16815 _visitNode(node.body); |
| 16816 return null; |
| 16817 } |
| 16818 |
| 16819 @override |
| 16820 Object visitClassDeclaration(ClassDeclaration node) { |
| 16821 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16822 _visitTokenWithSuffix(node.abstractKeyword, " "); |
| 16823 _writer.print("class "); |
| 16824 _visitNode(node.name); |
| 16825 _visitNode(node.typeParameters); |
| 16826 _visitNodeWithPrefix(" ", node.extendsClause); |
| 16827 _visitNodeWithPrefix(" ", node.withClause); |
| 16828 _visitNodeWithPrefix(" ", node.implementsClause); |
| 16829 _writer.print(" {"); |
| 16830 _visitNodeListWithSeparator(node.members, " "); |
| 16831 _writer.print("}"); |
| 16832 return null; |
| 16833 } |
| 16834 |
| 16835 @override |
| 16836 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 16837 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16838 if (node.abstractKeyword != null) { |
| 16839 _writer.print("abstract "); |
| 16840 } |
| 16841 _writer.print("class "); |
| 16842 _visitNode(node.name); |
| 16843 _visitNode(node.typeParameters); |
| 16844 _writer.print(" = "); |
| 16845 _visitNode(node.superclass); |
| 16846 _visitNodeWithPrefix(" ", node.withClause); |
| 16847 _visitNodeWithPrefix(" ", node.implementsClause); |
| 16848 _writer.print(";"); |
| 16849 return null; |
| 16850 } |
| 16851 |
| 16852 @override |
| 16853 Object visitComment(Comment node) => null; |
| 16854 |
| 16855 @override |
| 16856 Object visitCommentReference(CommentReference node) => null; |
| 16857 |
| 16858 @override |
| 16859 Object visitCompilationUnit(CompilationUnit node) { |
| 16860 ScriptTag scriptTag = node.scriptTag; |
| 16861 NodeList<Directive> directives = node.directives; |
| 16862 _visitNode(scriptTag); |
| 16863 String prefix = scriptTag == null ? "" : " "; |
| 16864 _visitNodeListWithSeparatorAndPrefix(prefix, directives, " "); |
| 16865 prefix = scriptTag == null && directives.isEmpty ? "" : " "; |
| 16866 _visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, " "); |
| 16867 return null; |
| 16868 } |
| 16869 |
| 16870 @override |
| 16871 Object visitConditionalExpression(ConditionalExpression node) { |
| 16872 _visitNode(node.condition); |
| 16873 _writer.print(" ? "); |
| 16874 _visitNode(node.thenExpression); |
| 16875 _writer.print(" : "); |
| 16876 _visitNode(node.elseExpression); |
| 16877 return null; |
| 16878 } |
| 16879 |
| 16880 @override |
| 16881 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 16882 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16883 _visitTokenWithSuffix(node.externalKeyword, " "); |
| 16884 _visitTokenWithSuffix(node.constKeyword, " "); |
| 16885 _visitTokenWithSuffix(node.factoryKeyword, " "); |
| 16886 _visitNode(node.returnType); |
| 16887 _visitNodeWithPrefix(".", node.name); |
| 16888 _visitNode(node.parameters); |
| 16889 _visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", "); |
| 16890 _visitNodeWithPrefix(" = ", node.redirectedConstructor); |
| 16891 _visitFunctionWithPrefix(" ", node.body); |
| 16892 return null; |
| 16893 } |
| 16894 |
| 16895 @override |
| 16896 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 16897 _visitTokenWithSuffix(node.keyword, "."); |
| 16898 _visitNode(node.fieldName); |
| 16899 _writer.print(" = "); |
| 16900 _visitNode(node.expression); |
| 16901 return null; |
| 16902 } |
| 16903 |
| 16904 @override |
| 16905 Object visitConstructorName(ConstructorName node) { |
| 16906 _visitNode(node.type); |
| 16907 _visitNodeWithPrefix(".", node.name); |
| 16908 return null; |
| 16909 } |
| 16910 |
| 16911 @override |
| 16912 Object visitContinueStatement(ContinueStatement node) { |
| 16913 _writer.print("continue"); |
| 16914 _visitNodeWithPrefix(" ", node.label); |
| 16915 _writer.print(";"); |
| 16916 return null; |
| 16917 } |
| 16918 |
| 16919 @override |
| 16920 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 16921 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16922 _visitTokenWithSuffix(node.keyword, " "); |
| 16923 _visitNodeWithSuffix(node.type, " "); |
| 16924 _visitNode(node.identifier); |
| 16925 return null; |
| 16926 } |
| 16927 |
| 16928 @override |
| 16929 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 16930 _visitNode(node.parameter); |
| 16931 if (node.separator != null) { |
| 16932 _writer.print(" "); |
| 16933 _writer.print(node.separator.lexeme); |
| 16934 _visitNodeWithPrefix(" ", node.defaultValue); |
| 16935 } |
| 16936 return null; |
| 16937 } |
| 16938 |
| 16939 @override |
| 16940 Object visitDoStatement(DoStatement node) { |
| 16941 _writer.print("do "); |
| 16942 _visitNode(node.body); |
| 16943 _writer.print(" while ("); |
| 16944 _visitNode(node.condition); |
| 16945 _writer.print(");"); |
| 16946 return null; |
| 16947 } |
| 16948 |
| 16949 @override |
| 16950 Object visitDoubleLiteral(DoubleLiteral node) { |
| 16951 _writer.print(node.literal.lexeme); |
| 16952 return null; |
| 16953 } |
| 16954 |
| 16955 @override |
| 16956 Object visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 16957 _writer.print(';'); |
| 16958 return null; |
| 16959 } |
| 16960 |
| 16961 @override |
| 16962 Object visitEmptyStatement(EmptyStatement node) { |
| 16963 _writer.print(';'); |
| 16964 return null; |
| 16965 } |
| 16966 |
| 16967 @override |
| 16968 Object visitEnumConstantDeclaration(EnumConstantDeclaration node) { |
| 16969 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16970 _visitNode(node.name); |
| 16971 return null; |
| 16972 } |
| 16973 |
| 16974 @override |
| 16975 Object visitEnumDeclaration(EnumDeclaration node) { |
| 16976 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16977 _writer.print("enum "); |
| 16978 _visitNode(node.name); |
| 16979 _writer.print(" {"); |
| 16980 _visitNodeListWithSeparator(node.constants, ", "); |
| 16981 _writer.print("}"); |
| 16982 return null; |
| 16983 } |
| 16984 |
| 16985 @override |
| 16986 Object visitExportDirective(ExportDirective node) { |
| 16987 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 16988 _writer.print("export "); |
| 16989 _visitNode(node.uri); |
| 16990 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " "); |
| 16991 _writer.print(';'); |
| 16992 return null; |
| 16993 } |
| 16994 |
| 16995 @override |
| 16996 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 16997 Token keyword = node.keyword; |
| 16998 if (keyword != null) { |
| 16999 _writer.print(keyword.lexeme); |
| 17000 _writer.print(' '); |
| 17001 } |
| 17002 _writer.print("=> "); |
| 17003 _visitNode(node.expression); |
| 17004 if (node.semicolon != null) { |
| 17005 _writer.print(';'); |
| 17006 } |
| 17007 return null; |
| 17008 } |
| 17009 |
| 17010 @override |
| 17011 Object visitExpressionStatement(ExpressionStatement node) { |
| 17012 _visitNode(node.expression); |
| 17013 _writer.print(';'); |
| 17014 return null; |
| 17015 } |
| 17016 |
| 17017 @override |
| 17018 Object visitExtendsClause(ExtendsClause node) { |
| 17019 _writer.print("extends "); |
| 17020 _visitNode(node.superclass); |
| 17021 return null; |
| 17022 } |
| 17023 |
| 17024 @override |
| 17025 Object visitFieldDeclaration(FieldDeclaration node) { |
| 17026 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17027 _visitTokenWithSuffix(node.staticKeyword, " "); |
| 17028 _visitNode(node.fields); |
| 17029 _writer.print(";"); |
| 17030 return null; |
| 17031 } |
| 17032 |
| 17033 @override |
| 17034 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 17035 _visitTokenWithSuffix(node.keyword, " "); |
| 17036 _visitNodeWithSuffix(node.type, " "); |
| 17037 _writer.print("this."); |
| 17038 _visitNode(node.identifier); |
| 17039 _visitNode(node.parameters); |
| 17040 return null; |
| 17041 } |
| 17042 |
| 17043 @override |
| 17044 Object visitForEachStatement(ForEachStatement node) { |
| 17045 DeclaredIdentifier loopVariable = node.loopVariable; |
| 17046 if (node.awaitKeyword != null) { |
| 17047 _writer.print("await "); |
| 17048 } |
| 17049 _writer.print("for ("); |
| 17050 if (loopVariable == null) { |
| 17051 _visitNode(node.identifier); |
| 17052 } else { |
| 17053 _visitNode(loopVariable); |
| 17054 } |
| 17055 _writer.print(" in "); |
| 17056 _visitNode(node.iterator); |
| 17057 _writer.print(") "); |
| 17058 _visitNode(node.body); |
| 17059 return null; |
| 17060 } |
| 17061 |
| 17062 @override |
| 17063 Object visitFormalParameterList(FormalParameterList node) { |
| 17064 String groupEnd = null; |
| 17065 _writer.print('('); |
| 17066 NodeList<FormalParameter> parameters = node.parameters; |
| 17067 int size = parameters.length; |
| 17068 for (int i = 0; i < size; i++) { |
| 17069 FormalParameter parameter = parameters[i]; |
| 17070 if (i > 0) { |
| 17071 _writer.print(", "); |
| 17072 } |
| 17073 if (groupEnd == null && parameter is DefaultFormalParameter) { |
| 17074 if (parameter.kind == ParameterKind.NAMED) { |
| 17075 groupEnd = "}"; |
| 17076 _writer.print('{'); |
| 17077 } else { |
| 17078 groupEnd = "]"; |
| 17079 _writer.print('['); |
| 17080 } |
| 17081 } |
| 17082 parameter.accept(this); |
| 17083 } |
| 17084 if (groupEnd != null) { |
| 17085 _writer.print(groupEnd); |
| 17086 } |
| 17087 _writer.print(')'); |
| 17088 return null; |
| 17089 } |
| 17090 |
| 17091 @override |
| 17092 Object visitForStatement(ForStatement node) { |
| 17093 Expression initialization = node.initialization; |
| 17094 _writer.print("for ("); |
| 17095 if (initialization != null) { |
| 17096 _visitNode(initialization); |
| 17097 } else { |
| 17098 _visitNode(node.variables); |
| 17099 } |
| 17100 _writer.print(";"); |
| 17101 _visitNodeWithPrefix(" ", node.condition); |
| 17102 _writer.print(";"); |
| 17103 _visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", "); |
| 17104 _writer.print(") "); |
| 17105 _visitNode(node.body); |
| 17106 return null; |
| 17107 } |
| 17108 |
| 17109 @override |
| 17110 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 17111 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17112 _visitNodeWithSuffix(node.returnType, " "); |
| 17113 _visitTokenWithSuffix(node.propertyKeyword, " "); |
| 17114 _visitNode(node.name); |
| 17115 _visitNode(node.functionExpression); |
| 17116 return null; |
| 17117 } |
| 17118 |
| 17119 @override |
| 17120 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 17121 _visitNode(node.functionDeclaration); |
| 17122 return null; |
| 17123 } |
| 17124 |
| 17125 @override |
| 17126 Object visitFunctionExpression(FunctionExpression node) { |
| 17127 _visitNode(node.parameters); |
| 17128 _writer.print(' '); |
| 17129 _visitNode(node.body); |
| 17130 return null; |
| 17131 } |
| 17132 |
| 17133 @override |
| 17134 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 17135 _visitNode(node.function); |
| 17136 _visitNode(node.argumentList); |
| 17137 return null; |
| 17138 } |
| 17139 |
| 17140 @override |
| 17141 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 17142 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17143 _writer.print("typedef "); |
| 17144 _visitNodeWithSuffix(node.returnType, " "); |
| 17145 _visitNode(node.name); |
| 17146 _visitNode(node.typeParameters); |
| 17147 _visitNode(node.parameters); |
| 17148 _writer.print(";"); |
| 17149 return null; |
| 17150 } |
| 17151 |
| 17152 @override |
| 17153 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 17154 _visitNodeWithSuffix(node.returnType, " "); |
| 17155 _visitNode(node.identifier); |
| 17156 _visitNode(node.parameters); |
| 17157 return null; |
| 17158 } |
| 17159 |
| 17160 @override |
| 17161 Object visitHideCombinator(HideCombinator node) { |
| 17162 _writer.print("hide "); |
| 17163 _visitNodeListWithSeparator(node.hiddenNames, ", "); |
| 17164 return null; |
| 17165 } |
| 17166 |
| 17167 @override |
| 17168 Object visitIfStatement(IfStatement node) { |
| 17169 _writer.print("if ("); |
| 17170 _visitNode(node.condition); |
| 17171 _writer.print(") "); |
| 17172 _visitNode(node.thenStatement); |
| 17173 _visitNodeWithPrefix(" else ", node.elseStatement); |
| 17174 return null; |
| 17175 } |
| 17176 |
| 17177 @override |
| 17178 Object visitImplementsClause(ImplementsClause node) { |
| 17179 _writer.print("implements "); |
| 17180 _visitNodeListWithSeparator(node.interfaces, ", "); |
| 17181 return null; |
| 17182 } |
| 17183 |
| 17184 @override |
| 17185 Object visitImportDirective(ImportDirective node) { |
| 17186 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17187 _writer.print("import "); |
| 17188 _visitNode(node.uri); |
| 17189 if (node.deferredToken != null) { |
| 17190 _writer.print(" deferred"); |
| 17191 } |
| 17192 _visitNodeWithPrefix(" as ", node.prefix); |
| 17193 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " "); |
| 17194 _writer.print(';'); |
| 17195 return null; |
| 17196 } |
| 17197 |
| 17198 @override |
| 17199 Object visitIndexExpression(IndexExpression node) { |
| 17200 if (node.isCascaded) { |
| 17201 _writer.print(".."); |
| 17202 } else { |
| 17203 _visitNode(node.target); |
| 17204 } |
| 17205 _writer.print('['); |
| 17206 _visitNode(node.index); |
| 17207 _writer.print(']'); |
| 17208 return null; |
| 17209 } |
| 17210 |
| 17211 @override |
| 17212 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 17213 _visitTokenWithSuffix(node.keyword, " "); |
| 17214 _visitNode(node.constructorName); |
| 17215 _visitNode(node.argumentList); |
| 17216 return null; |
| 17217 } |
| 17218 |
| 17219 @override |
| 17220 Object visitIntegerLiteral(IntegerLiteral node) { |
| 17221 _writer.print(node.literal.lexeme); |
| 17222 return null; |
| 17223 } |
| 17224 |
| 17225 @override |
| 17226 Object visitInterpolationExpression(InterpolationExpression node) { |
| 17227 if (node.rightBracket != null) { |
| 17228 _writer.print("\${"); |
| 17229 _visitNode(node.expression); |
| 17230 _writer.print("}"); |
| 17231 } else { |
| 17232 _writer.print("\$"); |
| 17233 _visitNode(node.expression); |
| 17234 } |
| 17235 return null; |
| 17236 } |
| 17237 |
| 17238 @override |
| 17239 Object visitInterpolationString(InterpolationString node) { |
| 17240 _writer.print(node.contents.lexeme); |
| 17241 return null; |
| 17242 } |
| 17243 |
| 17244 @override |
| 17245 Object visitIsExpression(IsExpression node) { |
| 17246 _visitNode(node.expression); |
| 17247 if (node.notOperator == null) { |
| 17248 _writer.print(" is "); |
| 17249 } else { |
| 17250 _writer.print(" is! "); |
| 17251 } |
| 17252 _visitNode(node.type); |
| 17253 return null; |
| 17254 } |
| 17255 |
| 17256 @override |
| 17257 Object visitLabel(Label node) { |
| 17258 _visitNode(node.label); |
| 17259 _writer.print(":"); |
| 17260 return null; |
| 17261 } |
| 17262 |
| 17263 @override |
| 17264 Object visitLabeledStatement(LabeledStatement node) { |
| 17265 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); |
| 17266 _visitNode(node.statement); |
| 17267 return null; |
| 17268 } |
| 17269 |
| 17270 @override |
| 17271 Object visitLibraryDirective(LibraryDirective node) { |
| 17272 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17273 _writer.print("library "); |
| 17274 _visitNode(node.name); |
| 17275 _writer.print(';'); |
| 17276 return null; |
| 17277 } |
| 17278 |
| 17279 @override |
| 17280 Object visitLibraryIdentifier(LibraryIdentifier node) { |
| 17281 _writer.print(node.name); |
| 17282 return null; |
| 17283 } |
| 17284 |
| 17285 @override |
| 17286 Object visitListLiteral(ListLiteral node) { |
| 17287 if (node.constKeyword != null) { |
| 17288 _writer.print(node.constKeyword.lexeme); |
| 17289 _writer.print(' '); |
| 17290 } |
| 17291 _visitNodeWithSuffix(node.typeArguments, " "); |
| 17292 _writer.print("["); |
| 17293 _visitNodeListWithSeparator(node.elements, ", "); |
| 17294 _writer.print("]"); |
| 17295 return null; |
| 17296 } |
| 17297 |
| 17298 @override |
| 17299 Object visitMapLiteral(MapLiteral node) { |
| 17300 if (node.constKeyword != null) { |
| 17301 _writer.print(node.constKeyword.lexeme); |
| 17302 _writer.print(' '); |
| 17303 } |
| 17304 _visitNodeWithSuffix(node.typeArguments, " "); |
| 17305 _writer.print("{"); |
| 17306 _visitNodeListWithSeparator(node.entries, ", "); |
| 17307 _writer.print("}"); |
| 17308 return null; |
| 17309 } |
| 17310 |
| 17311 @override |
| 17312 Object visitMapLiteralEntry(MapLiteralEntry node) { |
| 17313 _visitNode(node.key); |
| 17314 _writer.print(" : "); |
| 17315 _visitNode(node.value); |
| 17316 return null; |
| 17317 } |
| 17318 |
| 17319 @override |
| 17320 Object visitMethodDeclaration(MethodDeclaration node) { |
| 17321 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17322 _visitTokenWithSuffix(node.externalKeyword, " "); |
| 17323 _visitTokenWithSuffix(node.modifierKeyword, " "); |
| 17324 _visitNodeWithSuffix(node.returnType, " "); |
| 17325 _visitTokenWithSuffix(node.propertyKeyword, " "); |
| 17326 _visitTokenWithSuffix(node.operatorKeyword, " "); |
| 17327 _visitNode(node.name); |
| 17328 if (!node.isGetter) { |
| 17329 _visitNode(node.parameters); |
| 17330 } |
| 17331 _visitFunctionWithPrefix(" ", node.body); |
| 17332 return null; |
| 17333 } |
| 17334 |
| 17335 @override |
| 17336 Object visitMethodInvocation(MethodInvocation node) { |
| 17337 if (node.isCascaded) { |
| 17338 _writer.print(".."); |
| 17339 } else { |
| 17340 _visitNodeWithSuffix(node.target, "."); |
| 17341 } |
| 17342 _visitNode(node.methodName); |
| 17343 _visitNode(node.argumentList); |
| 17344 return null; |
| 17345 } |
| 17346 |
| 17347 @override |
| 17348 Object visitNamedExpression(NamedExpression node) { |
| 17349 _visitNode(node.name); |
| 17350 _visitNodeWithPrefix(" ", node.expression); |
| 17351 return null; |
| 17352 } |
| 17353 |
| 17354 @override |
| 17355 Object visitNativeClause(NativeClause node) { |
| 17356 _writer.print("native "); |
| 17357 _visitNode(node.name); |
| 17358 return null; |
| 17359 } |
| 17360 |
| 17361 @override |
| 17362 Object visitNativeFunctionBody(NativeFunctionBody node) { |
| 17363 _writer.print("native "); |
| 17364 _visitNode(node.stringLiteral); |
| 17365 _writer.print(';'); |
| 17366 return null; |
| 17367 } |
| 17368 |
| 17369 @override |
| 17370 Object visitNullLiteral(NullLiteral node) { |
| 17371 _writer.print("null"); |
| 17372 return null; |
| 17373 } |
| 17374 |
| 17375 @override |
| 17376 Object visitParenthesizedExpression(ParenthesizedExpression node) { |
| 17377 _writer.print('('); |
| 17378 _visitNode(node.expression); |
| 17379 _writer.print(')'); |
| 17380 return null; |
| 17381 } |
| 17382 |
| 17383 @override |
| 17384 Object visitPartDirective(PartDirective node) { |
| 17385 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17386 _writer.print("part "); |
| 17387 _visitNode(node.uri); |
| 17388 _writer.print(';'); |
| 17389 return null; |
| 17390 } |
| 17391 |
| 17392 @override |
| 17393 Object visitPartOfDirective(PartOfDirective node) { |
| 17394 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17395 _writer.print("part of "); |
| 17396 _visitNode(node.libraryName); |
| 17397 _writer.print(';'); |
| 17398 return null; |
| 17399 } |
| 17400 |
| 17401 @override |
| 17402 Object visitPostfixExpression(PostfixExpression node) { |
| 17403 _visitNode(node.operand); |
| 17404 _writer.print(node.operator.lexeme); |
| 17405 return null; |
| 17406 } |
| 17407 |
| 17408 @override |
| 17409 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 17410 _visitNode(node.prefix); |
| 17411 _writer.print('.'); |
| 17412 _visitNode(node.identifier); |
| 17413 return null; |
| 17414 } |
| 17415 |
| 17416 @override |
| 17417 Object visitPrefixExpression(PrefixExpression node) { |
| 17418 _writer.print(node.operator.lexeme); |
| 17419 _visitNode(node.operand); |
| 17420 return null; |
| 17421 } |
| 17422 |
| 17423 @override |
| 17424 Object visitPropertyAccess(PropertyAccess node) { |
| 17425 if (node.isCascaded) { |
| 17426 _writer.print(".."); |
| 17427 } else { |
| 17428 _visitNode(node.target); |
| 17429 _writer.print('.'); |
| 17430 } |
| 17431 _visitNode(node.propertyName); |
| 17432 return null; |
| 17433 } |
| 17434 |
| 17435 @override |
| 17436 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation
node) { |
| 17437 _writer.print("this"); |
| 17438 _visitNodeWithPrefix(".", node.constructorName); |
| 17439 _visitNode(node.argumentList); |
| 17440 return null; |
| 17441 } |
| 17442 |
| 17443 @override |
| 17444 Object visitRethrowExpression(RethrowExpression node) { |
| 17445 _writer.print("rethrow"); |
| 17446 return null; |
| 17447 } |
| 17448 |
| 17449 @override |
| 17450 Object visitReturnStatement(ReturnStatement node) { |
| 17451 Expression expression = node.expression; |
| 17452 if (expression == null) { |
| 17453 _writer.print("return;"); |
| 17454 } else { |
| 17455 _writer.print("return "); |
| 17456 expression.accept(this); |
| 17457 _writer.print(";"); |
| 17458 } |
| 17459 return null; |
| 17460 } |
| 17461 |
| 17462 @override |
| 17463 Object visitScriptTag(ScriptTag node) { |
| 17464 _writer.print(node.scriptTag.lexeme); |
| 17465 return null; |
| 17466 } |
| 17467 |
| 17468 @override |
| 17469 Object visitShowCombinator(ShowCombinator node) { |
| 17470 _writer.print("show "); |
| 17471 _visitNodeListWithSeparator(node.shownNames, ", "); |
| 17472 return null; |
| 17473 } |
| 17474 |
| 17475 @override |
| 17476 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 17477 _visitTokenWithSuffix(node.keyword, " "); |
| 17478 _visitNodeWithSuffix(node.type, " "); |
| 17479 _visitNode(node.identifier); |
| 17480 return null; |
| 17481 } |
| 17482 |
| 17483 @override |
| 17484 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 17485 _writer.print(node.token.lexeme); |
| 17486 return null; |
| 17487 } |
| 17488 |
| 17489 @override |
| 17490 Object visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 17491 _writer.print(node.literal.lexeme); |
| 17492 return null; |
| 17493 } |
| 17494 |
| 17495 @override |
| 17496 Object visitStringInterpolation(StringInterpolation node) { |
| 17497 _visitNodeList(node.elements); |
| 17498 return null; |
| 17499 } |
| 17500 |
| 17501 @override |
| 17502 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 17503 _writer.print("super"); |
| 17504 _visitNodeWithPrefix(".", node.constructorName); |
| 17505 _visitNode(node.argumentList); |
| 17506 return null; |
| 17507 } |
| 17508 |
| 17509 @override |
| 17510 Object visitSuperExpression(SuperExpression node) { |
| 17511 _writer.print("super"); |
| 17512 return null; |
| 17513 } |
| 17514 |
| 17515 @override |
| 17516 Object visitSwitchCase(SwitchCase node) { |
| 17517 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); |
| 17518 _writer.print("case "); |
| 17519 _visitNode(node.expression); |
| 17520 _writer.print(": "); |
| 17521 _visitNodeListWithSeparator(node.statements, " "); |
| 17522 return null; |
| 17523 } |
| 17524 |
| 17525 @override |
| 17526 Object visitSwitchDefault(SwitchDefault node) { |
| 17527 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " "); |
| 17528 _writer.print("default: "); |
| 17529 _visitNodeListWithSeparator(node.statements, " "); |
| 17530 return null; |
| 17531 } |
| 17532 |
| 17533 @override |
| 17534 Object visitSwitchStatement(SwitchStatement node) { |
| 17535 _writer.print("switch ("); |
| 17536 _visitNode(node.expression); |
| 17537 _writer.print(") {"); |
| 17538 _visitNodeListWithSeparator(node.members, " "); |
| 17539 _writer.print("}"); |
| 17540 return null; |
| 17541 } |
| 17542 |
| 17543 @override |
| 17544 Object visitSymbolLiteral(SymbolLiteral node) { |
| 17545 _writer.print("#"); |
| 17546 List<Token> components = node.components; |
| 17547 for (int i = 0; i < components.length; i++) { |
| 17548 if (i > 0) { |
| 17549 _writer.print("."); |
| 17550 } |
| 17551 _writer.print(components[i].lexeme); |
| 17552 } |
| 17553 return null; |
| 17554 } |
| 17555 |
| 17556 @override |
| 17557 Object visitThisExpression(ThisExpression node) { |
| 17558 _writer.print("this"); |
| 17559 return null; |
| 17560 } |
| 17561 |
| 17562 @override |
| 17563 Object visitThrowExpression(ThrowExpression node) { |
| 17564 _writer.print("throw "); |
| 17565 _visitNode(node.expression); |
| 17566 return null; |
| 17567 } |
| 17568 |
| 17569 @override |
| 17570 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 17571 _visitNodeWithSuffix(node.variables, ";"); |
| 17572 return null; |
| 17573 } |
| 17574 |
| 17575 @override |
| 17576 Object visitTryStatement(TryStatement node) { |
| 17577 _writer.print("try "); |
| 17578 _visitNode(node.body); |
| 17579 _visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " "); |
| 17580 _visitNodeWithPrefix(" finally ", node.finallyBlock); |
| 17581 return null; |
| 17582 } |
| 17583 |
| 17584 @override |
| 17585 Object visitTypeArgumentList(TypeArgumentList node) { |
| 17586 _writer.print('<'); |
| 17587 _visitNodeListWithSeparator(node.arguments, ", "); |
| 17588 _writer.print('>'); |
| 17589 return null; |
| 17590 } |
| 17591 |
| 17592 @override |
| 17593 Object visitTypeName(TypeName node) { |
| 17594 _visitNode(node.name); |
| 17595 _visitNode(node.typeArguments); |
| 17596 return null; |
| 17597 } |
| 17598 |
| 17599 @override |
| 17600 Object visitTypeParameter(TypeParameter node) { |
| 17601 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17602 _visitNode(node.name); |
| 17603 _visitNodeWithPrefix(" extends ", node.bound); |
| 17604 return null; |
| 17605 } |
| 17606 |
| 17607 @override |
| 17608 Object visitTypeParameterList(TypeParameterList node) { |
| 17609 _writer.print('<'); |
| 17610 _visitNodeListWithSeparator(node.typeParameters, ", "); |
| 17611 _writer.print('>'); |
| 17612 return null; |
| 17613 } |
| 17614 |
| 17615 @override |
| 17616 Object visitVariableDeclaration(VariableDeclaration node) { |
| 17617 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17618 _visitNode(node.name); |
| 17619 _visitNodeWithPrefix(" = ", node.initializer); |
| 17620 return null; |
| 17621 } |
| 17622 |
| 17623 @override |
| 17624 Object visitVariableDeclarationList(VariableDeclarationList node) { |
| 17625 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " "); |
| 17626 _visitTokenWithSuffix(node.keyword, " "); |
| 17627 _visitNodeWithSuffix(node.type, " "); |
| 17628 _visitNodeListWithSeparator(node.variables, ", "); |
| 17629 return null; |
| 17630 } |
| 17631 |
| 17632 @override |
| 17633 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 17634 _visitNode(node.variables); |
| 17635 _writer.print(";"); |
| 17636 return null; |
| 17637 } |
| 17638 |
| 17639 @override |
| 17640 Object visitWhileStatement(WhileStatement node) { |
| 17641 _writer.print("while ("); |
| 17642 _visitNode(node.condition); |
| 17643 _writer.print(") "); |
| 17644 _visitNode(node.body); |
| 17645 return null; |
| 17646 } |
| 17647 |
| 17648 @override |
| 17649 Object visitWithClause(WithClause node) { |
| 17650 _writer.print("with "); |
| 17651 _visitNodeListWithSeparator(node.mixinTypes, ", "); |
| 17652 return null; |
| 17653 } |
| 17654 |
| 17655 @override |
| 17656 Object visitYieldStatement(YieldStatement node) { |
| 17657 if (node.star != null) { |
| 17658 _writer.print("yield* "); |
| 17659 } else { |
| 17660 _writer.print("yield "); |
| 17661 } |
| 17662 _visitNode(node.expression); |
| 17663 _writer.print(";"); |
| 17664 return null; |
| 17665 } |
| 17666 |
| 17667 /** |
| 17668 * Visit the given function body, printing the prefix before if given body is
not empty. |
| 17669 * |
| 17670 * @param prefix the prefix to be printed if there is a node to visit |
| 17671 * @param body the function body to be visited |
| 17672 */ |
| 17673 void _visitFunctionWithPrefix(String prefix, FunctionBody body) { |
| 17674 if (body is! EmptyFunctionBody) { |
| 17675 _writer.print(prefix); |
| 17676 } |
| 17677 _visitNode(body); |
| 17678 } |
| 17679 |
| 17680 /** |
| 17681 * Safely visit the given node. |
| 17682 * |
| 17683 * @param node the node to be visited |
| 17684 */ |
| 17685 void _visitNode(AstNode node) { |
| 17686 if (node != null) { |
| 17687 node.accept(this); |
| 17688 } |
| 17689 } |
| 17690 |
| 17691 /** |
| 17692 * Print a list of nodes without any separation. |
| 17693 * |
| 17694 * @param nodes the nodes to be printed |
| 17695 * @param separator the separator to be printed between adjacent nodes |
| 17696 */ |
| 17697 void _visitNodeList(NodeList<AstNode> nodes) { |
| 17698 _visitNodeListWithSeparator(nodes, ""); |
| 17699 } |
| 17700 |
| 17701 /** |
| 17702 * Print a list of nodes, separated by the given separator. |
| 17703 * |
| 17704 * @param nodes the nodes to be printed |
| 17705 * @param separator the separator to be printed between adjacent nodes |
| 17706 */ |
| 17707 void _visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) { |
| 17708 if (nodes != null) { |
| 17709 int size = nodes.length; |
| 17710 for (int i = 0; i < size; i++) { |
| 17711 if (i > 0) { |
| 17712 _writer.print(separator); |
| 17713 } |
| 17714 nodes[i].accept(this); |
| 17715 } |
| 17716 } |
| 17717 } |
| 17718 |
| 17719 /** |
| 17720 * Print a list of nodes, separated by the given separator. |
| 17721 * |
| 17722 * @param prefix the prefix to be printed if the list is not empty |
| 17723 * @param nodes the nodes to be printed |
| 17724 * @param separator the separator to be printed between adjacent nodes |
| 17725 */ |
| 17726 void _visitNodeListWithSeparatorAndPrefix(String prefix, NodeList<AstNode> nod
es, String separator) { |
| 17727 if (nodes != null) { |
| 17728 int size = nodes.length; |
| 17729 if (size > 0) { |
| 17730 _writer.print(prefix); |
| 17731 for (int i = 0; i < size; i++) { |
| 17732 if (i > 0) { |
| 17733 _writer.print(separator); |
| 17734 } |
| 17735 nodes[i].accept(this); |
| 17736 } |
| 17737 } |
| 17738 } |
| 17739 } |
| 17740 |
| 17741 /** |
| 17742 * Print a list of nodes, separated by the given separator. |
| 17743 * |
| 17744 * @param nodes the nodes to be printed |
| 17745 * @param separator the separator to be printed between adjacent nodes |
| 17746 * @param suffix the suffix to be printed if the list is not empty |
| 17747 */ |
| 17748 void _visitNodeListWithSeparatorAndSuffix(NodeList<AstNode> nodes, String sepa
rator, String suffix) { |
| 17749 if (nodes != null) { |
| 17750 int size = nodes.length; |
| 17751 if (size > 0) { |
| 17752 for (int i = 0; i < size; i++) { |
| 17753 if (i > 0) { |
| 17754 _writer.print(separator); |
| 17755 } |
| 17756 nodes[i].accept(this); |
| 17757 } |
| 17758 _writer.print(suffix); |
| 17759 } |
| 17760 } |
| 17761 } |
| 17762 |
| 17763 /** |
| 17764 * Safely visit the given node, printing the prefix before the node if it is n
on-`null`. |
| 17765 * |
| 17766 * @param prefix the prefix to be printed if there is a node to visit |
| 17767 * @param node the node to be visited |
| 17768 */ |
| 17769 void _visitNodeWithPrefix(String prefix, AstNode node) { |
| 17770 if (node != null) { |
| 17771 _writer.print(prefix); |
| 17772 node.accept(this); |
| 17773 } |
| 17774 } |
| 17775 |
| 17776 /** |
| 17777 * Safely visit the given node, printing the suffix after the node if it is no
n-`null`. |
| 17778 * |
| 17779 * @param suffix the suffix to be printed if there is a node to visit |
| 17780 * @param node the node to be visited |
| 17781 */ |
| 17782 void _visitNodeWithSuffix(AstNode node, String suffix) { |
| 17783 if (node != null) { |
| 17784 node.accept(this); |
| 17785 _writer.print(suffix); |
| 17786 } |
| 17787 } |
| 17788 |
| 17789 /** |
| 17790 * Safely visit the given node, printing the suffix after the node if it is no
n-`null`. |
| 17791 * |
| 17792 * @param suffix the suffix to be printed if there is a node to visit |
| 17793 * @param node the node to be visited |
| 17794 */ |
| 17795 void _visitTokenWithSuffix(Token token, String suffix) { |
| 17796 if (token != null) { |
| 17797 _writer.print(token.lexeme); |
| 17798 _writer.print(suffix); |
| 17799 } |
| 17800 } |
| 17801 } |
| 17802 |
| 17803 /** |
| 17804 * Instances of the class `TopLevelVariableDeclaration` represent the declaratio
n of one or |
| 17805 * more top-level variables of the same type. |
| 17806 * |
| 17807 * <pre> |
| 17808 * topLevelVariableDeclaration ::= |
| 17809 * ('final' | 'const') type? staticFinalDeclarationList ';' |
| 17810 * | variableDeclaration ';' |
| 17811 * </pre> |
| 17812 */ |
| 17813 class TopLevelVariableDeclaration extends CompilationUnitMember { |
| 17814 /** |
| 17815 * The top-level variables being declared. |
| 17816 */ |
| 17817 VariableDeclarationList _variableList; |
| 17818 |
| 17819 /** |
| 17820 * The semicolon terminating the declaration. |
| 17821 */ |
| 17822 Token semicolon; |
| 17823 |
| 17824 /** |
| 17825 * Initialize a newly created top-level variable declaration. |
| 17826 * |
| 17827 * @param comment the documentation comment associated with this variable |
| 17828 * @param metadata the annotations associated with this variable |
| 17829 * @param variableList the top-level variables being declared |
| 17830 * @param semicolon the semicolon terminating the declaration |
| 17831 */ |
| 17832 TopLevelVariableDeclaration(Comment comment, List<Annotation> metadata, Variab
leDeclarationList variableList, this.semicolon) : super(comment, metadata) { |
| 17833 this._variableList = becomeParentOf(variableList); |
| 17834 } |
| 17835 |
| 17836 @override |
| 17837 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this); |
| 17838 |
| 17839 @override |
| 17840 Element get element => null; |
| 17841 |
| 17842 @override |
| 17843 Token get endToken => semicolon; |
| 17844 |
| 17845 /** |
| 17846 * Return the top-level variables being declared. |
| 17847 * |
| 17848 * @return the top-level variables being declared |
| 17849 */ |
| 17850 VariableDeclarationList get variables => _variableList; |
| 17851 |
| 17852 /** |
| 17853 * Set the top-level variables being declared to the given list of variables. |
| 17854 * |
| 17855 * @param variableList the top-level variables being declared |
| 17856 */ |
| 17857 void set variables(VariableDeclarationList variableList) { |
| 17858 this._variableList = becomeParentOf(variableList); |
| 17859 } |
| 17860 |
| 17861 @override |
| 17862 void visitChildren(AstVisitor visitor) { |
| 17863 super.visitChildren(visitor); |
| 17864 safelyVisitChild(_variableList, visitor); |
| 17865 } |
| 17866 |
| 17867 @override |
| 17868 Token get firstTokenAfterCommentAndMetadata => _variableList.beginToken; |
| 17869 } |
| 17870 |
| 17871 /** |
| 17872 * Instances of the class `TryStatement` represent a try statement. |
| 17873 * |
| 17874 * <pre> |
| 17875 * tryStatement ::= |
| 17876 * 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause) |
| 17877 * |
| 17878 * finallyClause ::= |
| 17879 * 'finally' [Block] |
| 17880 * </pre> |
| 17881 */ |
| 17882 class TryStatement extends Statement { |
| 17883 /** |
| 17884 * The token representing the 'try' keyword. |
| 17885 */ |
| 17886 Token tryKeyword; |
| 17887 |
| 17888 /** |
| 17889 * The body of the statement. |
| 17890 */ |
| 17891 Block _body; |
| 17892 |
| 17893 /** |
| 17894 * The catch clauses contained in the try statement. |
| 17895 */ |
| 17896 NodeList<CatchClause> _catchClauses; |
| 17897 |
| 17898 /** |
| 17899 * The token representing the 'finally' keyword, or `null` if the statement do
es not contain |
| 17900 * a finally clause. |
| 17901 */ |
| 17902 Token finallyKeyword; |
| 17903 |
| 17904 /** |
| 17905 * The finally block contained in the try statement, or `null` if the statemen
t does not |
| 17906 * contain a finally clause. |
| 17907 */ |
| 17908 Block _finallyBlock; |
| 17909 |
| 17910 /** |
| 17911 * Initialize a newly created try statement. |
| 17912 * |
| 17913 * @param tryKeyword the token representing the 'try' keyword |
| 17914 * @param body the body of the statement |
| 17915 * @param catchClauses the catch clauses contained in the try statement |
| 17916 * @param finallyKeyword the token representing the 'finally' keyword |
| 17917 * @param finallyBlock the finally block contained in the try statement |
| 17918 */ |
| 17919 TryStatement(this.tryKeyword, Block body, List<CatchClause> catchClauses, this
.finallyKeyword, Block finallyBlock) { |
| 17920 this._catchClauses = new NodeList<CatchClause>(this); |
| 17921 this._body = becomeParentOf(body); |
| 17922 this._catchClauses.addAll(catchClauses); |
| 17923 this._finallyBlock = becomeParentOf(finallyBlock); |
| 17924 } |
| 17925 |
| 17926 @override |
| 17927 accept(AstVisitor visitor) => visitor.visitTryStatement(this); |
| 17928 |
| 17929 @override |
| 17930 Token get beginToken => tryKeyword; |
| 17931 |
| 17932 /** |
| 17933 * Return the body of the statement. |
| 17934 * |
| 17935 * @return the body of the statement |
| 17936 */ |
| 17937 Block get body => _body; |
| 17938 |
| 17939 /** |
| 17940 * Return the catch clauses contained in the try statement. |
| 17941 * |
| 17942 * @return the catch clauses contained in the try statement |
| 17943 */ |
| 17944 NodeList<CatchClause> get catchClauses => _catchClauses; |
| 17945 |
| 17946 @override |
| 17947 Token get endToken { |
| 17948 if (_finallyBlock != null) { |
| 17949 return _finallyBlock.endToken; |
| 17950 } else if (finallyKeyword != null) { |
| 17951 return finallyKeyword; |
| 17952 } else if (!_catchClauses.isEmpty) { |
| 17953 return _catchClauses.endToken; |
| 17954 } |
| 17955 return _body.endToken; |
| 17956 } |
| 17957 |
| 17958 /** |
| 17959 * Return the finally block contained in the try statement, or `null` if the s
tatement does |
| 17960 * not contain a finally clause. |
| 17961 * |
| 17962 * @return the finally block contained in the try statement |
| 17963 */ |
| 17964 Block get finallyBlock => _finallyBlock; |
| 17965 |
| 17966 /** |
| 17967 * Set the body of the statement to the given block. |
| 17968 * |
| 17969 * @param block the body of the statement |
| 17970 */ |
| 17971 void set body(Block block) { |
| 17972 _body = becomeParentOf(block); |
| 17973 } |
| 17974 |
| 17975 /** |
| 17976 * Set the finally block contained in the try statement to the given block. |
| 17977 * |
| 17978 * @param block the finally block contained in the try statement |
| 17979 */ |
| 17980 void set finallyBlock(Block block) { |
| 17981 _finallyBlock = becomeParentOf(block); |
| 17982 } |
| 17983 |
| 17984 @override |
| 17985 void visitChildren(AstVisitor visitor) { |
| 17986 safelyVisitChild(_body, visitor); |
| 17987 _catchClauses.accept(visitor); |
| 17988 safelyVisitChild(_finallyBlock, visitor); |
| 17989 } |
| 17990 } |
| 17991 |
| 17992 /** |
| 17993 * The abstract class `TypeAlias` defines the behavior common to declarations of
type aliases. |
| 17994 * |
| 17995 * <pre> |
| 17996 * typeAlias ::= |
| 17997 * 'typedef' typeAliasBody |
| 17998 * |
| 17999 * typeAliasBody ::= |
| 18000 * classTypeAlias |
| 18001 * | functionTypeAlias |
| 18002 * </pre> |
| 18003 */ |
| 18004 abstract class TypeAlias extends CompilationUnitMember { |
| 18005 /** |
| 18006 * The token representing the 'typedef' keyword. |
| 18007 */ |
| 18008 Token keyword; |
| 18009 |
| 18010 /** |
| 18011 * The semicolon terminating the declaration. |
| 18012 */ |
| 18013 Token semicolon; |
| 18014 |
| 18015 /** |
| 18016 * Initialize a newly created type alias. |
| 18017 * |
| 18018 * @param comment the documentation comment associated with this type alias |
| 18019 * @param metadata the annotations associated with this type alias |
| 18020 * @param keyword the token representing the 'typedef' keyword |
| 18021 * @param semicolon the semicolon terminating the declaration |
| 18022 */ |
| 18023 TypeAlias(Comment comment, List<Annotation> metadata, this.keyword, this.semic
olon) : super(comment, metadata); |
| 18024 |
| 18025 @override |
| 18026 Token get endToken => semicolon; |
| 18027 |
| 18028 @override |
| 18029 Token get firstTokenAfterCommentAndMetadata => keyword; |
| 18030 } |
| 18031 |
| 18032 /** |
| 18033 * Instances of the class `TypeArgumentList` represent a list of type arguments. |
| 18034 * |
| 18035 * <pre> |
| 18036 * typeArguments ::= |
| 18037 * '<' typeName (',' typeName)* '>' |
| 18038 * </pre> |
| 18039 */ |
| 18040 class TypeArgumentList extends AstNode { |
| 18041 /** |
| 18042 * The left bracket. |
| 18043 */ |
| 18044 Token leftBracket; |
| 18045 |
| 18046 /** |
| 18047 * The type arguments associated with the type. |
| 18048 */ |
| 18049 NodeList<TypeName> _arguments; |
| 18050 |
| 18051 /** |
| 18052 * The right bracket. |
| 18053 */ |
| 18054 Token rightBracket; |
| 18055 |
| 18056 /** |
| 18057 * Initialize a newly created list of type arguments. |
| 18058 * |
| 18059 * @param leftBracket the left bracket |
| 18060 * @param arguments the type arguments associated with the type |
| 18061 * @param rightBracket the right bracket |
| 18062 */ |
| 18063 TypeArgumentList(this.leftBracket, List<TypeName> arguments, this.rightBracket
) { |
| 18064 this._arguments = new NodeList<TypeName>(this); |
| 18065 this._arguments.addAll(arguments); |
| 18066 } |
| 18067 |
| 18068 @override |
| 18069 accept(AstVisitor visitor) => visitor.visitTypeArgumentList(this); |
| 18070 |
| 18071 /** |
| 18072 * Return the type arguments associated with the type. |
| 18073 * |
| 18074 * @return the type arguments associated with the type |
| 18075 */ |
| 18076 NodeList<TypeName> get arguments => _arguments; |
| 18077 |
| 18078 @override |
| 18079 Token get beginToken => leftBracket; |
| 18080 |
| 18081 @override |
| 18082 Token get endToken => rightBracket; |
| 18083 |
| 18084 @override |
| 18085 void visitChildren(AstVisitor visitor) { |
| 18086 _arguments.accept(visitor); |
| 18087 } |
| 18088 } |
| 18089 |
| 18090 /** |
| 18091 * Instances of the class `TypeName` represent the name of a type, which can opt
ionally |
| 18092 * include type arguments. |
| 18093 * |
| 18094 * <pre> |
| 18095 * typeName ::= |
| 18096 * [Identifier] typeArguments? |
| 18097 * </pre> |
| 18098 */ |
| 18099 class TypeName extends AstNode { |
| 18100 /** |
| 18101 * The name of the type. |
| 18102 */ |
| 18103 Identifier _name; |
| 18104 |
| 18105 /** |
| 18106 * The type arguments associated with the type, or `null` if there are no type
arguments. |
| 18107 */ |
| 18108 TypeArgumentList _typeArguments; |
| 18109 |
| 18110 /** |
| 18111 * The type being named, or `null` if the AST structure has not been resolved. |
| 18112 */ |
| 18113 DartType type; |
| 18114 |
| 18115 /** |
| 18116 * Initialize a newly created type name. |
| 18117 * |
| 18118 * @param name the name of the type |
| 18119 * @param typeArguments the type arguments associated with the type, or `null`
if there are |
| 18120 * no type arguments |
| 18121 */ |
| 18122 TypeName(Identifier name, TypeArgumentList typeArguments) { |
| 18123 this._name = becomeParentOf(name); |
| 18124 this._typeArguments = becomeParentOf(typeArguments); |
| 18125 } |
| 18126 |
| 18127 @override |
| 18128 accept(AstVisitor visitor) => visitor.visitTypeName(this); |
| 18129 |
| 18130 @override |
| 18131 Token get beginToken => _name.beginToken; |
| 18132 |
| 18133 @override |
| 18134 Token get endToken { |
| 18135 if (_typeArguments != null) { |
| 18136 return _typeArguments.endToken; |
| 18137 } |
| 18138 return _name.endToken; |
| 18139 } |
| 18140 |
| 18141 /** |
| 18142 * Return the name of the type. |
| 18143 * |
| 18144 * @return the name of the type |
| 18145 */ |
| 18146 Identifier get name => _name; |
| 18147 |
| 18148 /** |
| 18149 * Return the type arguments associated with the type, or `null` if there are
no type |
| 18150 * arguments. |
| 18151 * |
| 18152 * @return the type arguments associated with the type |
| 18153 */ |
| 18154 TypeArgumentList get typeArguments => _typeArguments; |
| 18155 |
| 18156 /** |
| 18157 * Return `true` if this type is a deferred type. |
| 18158 * |
| 18159 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form </i>p.
T</i> where <i>p</i> |
| 18160 * is a deferred prefix. |
| 18161 * |
| 18162 * @return `true` if this type is a deferred type |
| 18163 */ |
| 18164 bool get isDeferred { |
| 18165 Identifier identifier = name; |
| 18166 if (identifier is! PrefixedIdentifier) { |
| 18167 return false; |
| 18168 } |
| 18169 return (identifier as PrefixedIdentifier).isDeferred; |
| 18170 } |
| 18171 |
| 18172 @override |
| 18173 bool get isSynthetic => _name.isSynthetic && _typeArguments == null; |
| 18174 |
| 18175 /** |
| 18176 * Set the name of the type to the given identifier. |
| 18177 * |
| 18178 * @param identifier the name of the type |
| 18179 */ |
| 18180 void set name(Identifier identifier) { |
| 18181 _name = becomeParentOf(identifier); |
| 18182 } |
| 18183 |
| 18184 /** |
| 18185 * Set the type arguments associated with the type to the given type arguments
. |
| 18186 * |
| 18187 * @param typeArguments the type arguments associated with the type |
| 18188 */ |
| 18189 void set typeArguments(TypeArgumentList typeArguments) { |
| 18190 this._typeArguments = becomeParentOf(typeArguments); |
| 18191 } |
| 18192 |
| 18193 @override |
| 18194 void visitChildren(AstVisitor visitor) { |
| 18195 safelyVisitChild(_name, visitor); |
| 18196 safelyVisitChild(_typeArguments, visitor); |
| 18197 } |
| 18198 } |
| 18199 |
| 18200 /** |
| 18201 * Instances of the class `TypeParameter` represent a type parameter. |
| 18202 * |
| 18203 * <pre> |
| 18204 * typeParameter ::= |
| 18205 * [SimpleIdentifier] ('extends' [TypeName])? |
| 18206 * </pre> |
| 18207 */ |
| 18208 class TypeParameter extends Declaration { |
| 18209 /** |
| 18210 * The name of the type parameter. |
| 18211 */ |
| 18212 SimpleIdentifier _name; |
| 18213 |
| 18214 /** |
| 18215 * The token representing the 'extends' keyword, or `null` if there was no exp
licit upper |
| 18216 * bound. |
| 18217 */ |
| 18218 Token keyword; |
| 18219 |
| 18220 /** |
| 18221 * The name of the upper bound for legal arguments, or `null` if there was no
explicit upper |
| 18222 * bound. |
| 18223 */ |
| 18224 TypeName _bound; |
| 18225 |
| 18226 /** |
| 18227 * Initialize a newly created type parameter. |
| 18228 * |
| 18229 * @param comment the documentation comment associated with the type parameter |
| 18230 * @param metadata the annotations associated with the type parameter |
| 18231 * @param name the name of the type parameter |
| 18232 * @param keyword the token representing the 'extends' keyword |
| 18233 * @param bound the name of the upper bound for legal arguments |
| 18234 */ |
| 18235 TypeParameter(Comment comment, List<Annotation> metadata, SimpleIdentifier nam
e, this.keyword, TypeName bound) : super(comment, metadata) { |
| 18236 this._name = becomeParentOf(name); |
| 18237 this._bound = becomeParentOf(bound); |
| 18238 } |
| 18239 |
| 18240 @override |
| 18241 accept(AstVisitor visitor) => visitor.visitTypeParameter(this); |
| 18242 |
| 18243 /** |
| 18244 * Return the name of the upper bound for legal arguments, or `null` if there
was no |
| 18245 * explicit upper bound. |
| 18246 * |
| 18247 * @return the name of the upper bound for legal arguments |
| 18248 */ |
| 18249 TypeName get bound => _bound; |
| 18250 |
| 18251 @override |
| 18252 TypeParameterElement get element => _name != null ? (_name.staticElement as Ty
peParameterElement) : null; |
| 18253 |
| 18254 @override |
| 18255 Token get endToken { |
| 18256 if (_bound == null) { |
| 18257 return _name.endToken; |
| 18258 } |
| 18259 return _bound.endToken; |
| 18260 } |
| 18261 |
| 18262 /** |
| 18263 * Return the name of the type parameter. |
| 18264 * |
| 18265 * @return the name of the type parameter |
| 18266 */ |
| 18267 SimpleIdentifier get name => _name; |
| 18268 |
| 18269 /** |
| 18270 * Set the name of the upper bound for legal arguments to the given type name. |
| 18271 * |
| 18272 * @param typeName the name of the upper bound for legal arguments |
| 18273 */ |
| 18274 void set bound(TypeName typeName) { |
| 18275 _bound = becomeParentOf(typeName); |
| 18276 } |
| 18277 |
| 18278 /** |
| 18279 * Set the name of the type parameter to the given identifier. |
| 18280 * |
| 18281 * @param identifier the name of the type parameter |
| 18282 */ |
| 18283 void set name(SimpleIdentifier identifier) { |
| 18284 _name = becomeParentOf(identifier); |
| 18285 } |
| 18286 |
| 18287 @override |
| 18288 void visitChildren(AstVisitor visitor) { |
| 18289 super.visitChildren(visitor); |
| 18290 safelyVisitChild(_name, visitor); |
| 18291 safelyVisitChild(_bound, visitor); |
| 18292 } |
| 18293 |
| 18294 @override |
| 18295 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 18296 } |
| 18297 |
| 18298 /** |
| 18299 * Instances of the class `TypeParameterList` represent type parameters within a
declaration. |
| 18300 * |
| 18301 * <pre> |
| 18302 * typeParameterList ::= |
| 18303 * '<' [TypeParameter] (',' [TypeParameter])* '>' |
| 18304 * </pre> |
| 18305 */ |
| 18306 class TypeParameterList extends AstNode { |
| 18307 /** |
| 18308 * The left angle bracket. |
| 18309 */ |
| 18310 final Token leftBracket; |
| 18311 |
| 18312 /** |
| 18313 * The type parameters in the list. |
| 18314 */ |
| 18315 NodeList<TypeParameter> _typeParameters; |
| 18316 |
| 18317 /** |
| 18318 * The right angle bracket. |
| 18319 */ |
| 18320 final Token rightBracket; |
| 18321 |
| 18322 /** |
| 18323 * Initialize a newly created list of type parameters. |
| 18324 * |
| 18325 * @param leftBracket the left angle bracket |
| 18326 * @param typeParameters the type parameters in the list |
| 18327 * @param rightBracket the right angle bracket |
| 18328 */ |
| 18329 TypeParameterList(this.leftBracket, List<TypeParameter> typeParameters, this.r
ightBracket) { |
| 18330 this._typeParameters = new NodeList<TypeParameter>(this); |
| 18331 this._typeParameters.addAll(typeParameters); |
| 18332 } |
| 18333 |
| 18334 @override |
| 18335 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this); |
| 18336 |
| 18337 @override |
| 18338 Token get beginToken => leftBracket; |
| 18339 |
| 18340 @override |
| 18341 Token get endToken => rightBracket; |
| 18342 |
| 18343 /** |
| 18344 * Return the type parameters for the type. |
| 18345 * |
| 18346 * @return the type parameters for the type |
| 18347 */ |
| 18348 NodeList<TypeParameter> get typeParameters => _typeParameters; |
| 18349 |
| 18350 @override |
| 18351 void visitChildren(AstVisitor visitor) { |
| 18352 _typeParameters.accept(visitor); |
| 18353 } |
| 18354 } |
| 18355 |
| 18356 /** |
| 18357 * The abstract class `TypedLiteral` defines the behavior common to literals tha
t have a type |
| 18358 * associated with them. |
| 18359 * |
| 18360 * <pre> |
| 18361 * listLiteral ::= |
| 18362 * [ListLiteral] |
| 18363 * | [MapLiteral] |
| 18364 * </pre> |
| 18365 */ |
| 18366 abstract class TypedLiteral extends Literal { |
| 18367 /** |
| 18368 * The token representing the 'const' keyword, or `null` if the literal is not
a constant. |
| 18369 */ |
| 18370 Token constKeyword; |
| 18371 |
| 18372 /** |
| 18373 * The type argument associated with this literal, or `null` if no type argume
nts were |
| 18374 * declared. |
| 18375 */ |
| 18376 TypeArgumentList _typeArguments; |
| 18377 |
| 18378 /** |
| 18379 * Initialize a newly created typed literal. |
| 18380 * |
| 18381 * @param constKeyword the token representing the 'const' keyword |
| 18382 * @param typeArguments the type argument associated with this literal, or `nu
ll` if no type |
| 18383 * arguments were declared |
| 18384 */ |
| 18385 TypedLiteral(this.constKeyword, TypeArgumentList typeArguments) { |
| 18386 this._typeArguments = becomeParentOf(typeArguments); |
| 18387 } |
| 18388 |
| 18389 /** |
| 18390 * Return the type argument associated with this literal, or `null` if no type
arguments |
| 18391 * were declared. |
| 18392 * |
| 18393 * @return the type argument associated with this literal |
| 18394 */ |
| 18395 TypeArgumentList get typeArguments => _typeArguments; |
| 18396 |
| 18397 /** |
| 18398 * Set the type argument associated with this literal to the given arguments. |
| 18399 * |
| 18400 * @param typeArguments the type argument associated with this literal |
| 18401 */ |
| 18402 void set typeArguments(TypeArgumentList typeArguments) { |
| 18403 this._typeArguments = becomeParentOf(typeArguments); |
| 18404 } |
| 18405 |
| 18406 @override |
| 18407 void visitChildren(AstVisitor visitor) { |
| 18408 safelyVisitChild(_typeArguments, visitor); |
| 18409 } |
| 18410 } |
| 18411 |
| 18412 /** |
| 18413 * Instances of the class `UnifyingAstVisitor` implement an AST visitor that wil
l recursively |
| 18414 * visit all of the nodes in an AST structure (like instances of the class |
| 18415 * [RecursiveAstVisitor]). In addition, every node will also be visited by using
a single |
| 18416 * unified [visitNode] method. |
| 18417 * |
| 18418 * Subclasses that override a visit method must either invoke the overridden vis
it method or |
| 18419 * explicitly invoke the more general [visitNode] method. Failure to do so will |
| 18420 * cause the children of the visited node to not be visited. |
| 18421 */ |
| 18422 class UnifyingAstVisitor<R> implements AstVisitor<R> { |
| 18423 @override |
| 18424 R visitAdjacentStrings(AdjacentStrings node) => visitNode(node); |
| 18425 |
| 18426 @override |
| 18427 R visitAnnotation(Annotation node) => visitNode(node); |
| 18428 |
| 18429 @override |
| 18430 R visitArgumentList(ArgumentList node) => visitNode(node); |
| 18431 |
| 18432 @override |
| 18433 R visitAsExpression(AsExpression node) => visitNode(node); |
| 18434 |
| 18435 @override |
| 18436 R visitAssertStatement(AssertStatement node) => visitNode(node); |
| 18437 |
| 18438 @override |
| 18439 R visitAssignmentExpression(AssignmentExpression node) => visitNode(node); |
| 18440 |
| 18441 @override |
| 18442 R visitAwaitExpression(AwaitExpression node) => visitNode(node); |
| 18443 |
| 18444 @override |
| 18445 R visitBinaryExpression(BinaryExpression node) => visitNode(node); |
| 18446 |
| 18447 @override |
| 18448 R visitBlock(Block node) => visitNode(node); |
| 18449 |
| 18450 @override |
| 18451 R visitBlockFunctionBody(BlockFunctionBody node) => visitNode(node); |
| 18452 |
| 18453 @override |
| 18454 R visitBooleanLiteral(BooleanLiteral node) => visitNode(node); |
| 18455 |
| 18456 @override |
| 18457 R visitBreakStatement(BreakStatement node) => visitNode(node); |
| 18458 |
| 18459 @override |
| 18460 R visitCascadeExpression(CascadeExpression node) => visitNode(node); |
| 18461 |
| 18462 @override |
| 18463 R visitCatchClause(CatchClause node) => visitNode(node); |
| 18464 |
| 18465 @override |
| 18466 R visitClassDeclaration(ClassDeclaration node) => visitNode(node); |
| 18467 |
| 18468 @override |
| 18469 R visitClassTypeAlias(ClassTypeAlias node) => visitNode(node); |
| 18470 |
| 18471 @override |
| 18472 R visitComment(Comment node) => visitNode(node); |
| 18473 |
| 18474 @override |
| 18475 R visitCommentReference(CommentReference node) => visitNode(node); |
| 18476 |
| 18477 @override |
| 18478 R visitCompilationUnit(CompilationUnit node) => visitNode(node); |
| 18479 |
| 18480 @override |
| 18481 R visitConditionalExpression(ConditionalExpression node) => visitNode(node); |
| 18482 |
| 18483 @override |
| 18484 R visitConstructorDeclaration(ConstructorDeclaration node) => visitNode(node); |
| 18485 |
| 18486 @override |
| 18487 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => visitN
ode(node); |
| 18488 |
| 18489 @override |
| 18490 R visitConstructorName(ConstructorName node) => visitNode(node); |
| 18491 |
| 18492 @override |
| 18493 R visitContinueStatement(ContinueStatement node) => visitNode(node); |
| 18494 |
| 18495 @override |
| 18496 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitNode(node); |
| 18497 |
| 18498 @override |
| 18499 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitNode(node); |
| 18500 |
| 18501 @override |
| 18502 R visitDoStatement(DoStatement node) => visitNode(node); |
| 18503 |
| 18504 @override |
| 18505 R visitDoubleLiteral(DoubleLiteral node) => visitNode(node); |
| 18506 |
| 18507 @override |
| 18508 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node); |
| 18509 |
| 18510 @override |
| 18511 R visitEmptyStatement(EmptyStatement node) => visitNode(node); |
| 18512 |
| 18513 @override |
| 18514 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => visitNode(node
); |
| 18515 |
| 18516 @override |
| 18517 R visitEnumDeclaration(EnumDeclaration node) => visitNode(node); |
| 18518 |
| 18519 @override |
| 18520 R visitExportDirective(ExportDirective node) => visitNode(node); |
| 18521 |
| 18522 @override |
| 18523 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitNode(node); |
| 18524 |
| 18525 @override |
| 18526 R visitExpressionStatement(ExpressionStatement node) => visitNode(node); |
| 18527 |
| 18528 @override |
| 18529 R visitExtendsClause(ExtendsClause node) => visitNode(node); |
| 18530 |
| 18531 @override |
| 18532 R visitFieldDeclaration(FieldDeclaration node) => visitNode(node); |
| 18533 |
| 18534 @override |
| 18535 R visitFieldFormalParameter(FieldFormalParameter node) => visitNode(node); |
| 18536 |
| 18537 @override |
| 18538 R visitForEachStatement(ForEachStatement node) => visitNode(node); |
| 18539 |
| 18540 @override |
| 18541 R visitFormalParameterList(FormalParameterList node) => visitNode(node); |
| 18542 |
| 18543 @override |
| 18544 R visitForStatement(ForStatement node) => visitNode(node); |
| 18545 |
| 18546 @override |
| 18547 R visitFunctionDeclaration(FunctionDeclaration node) => visitNode(node); |
| 18548 |
| 18549 @override |
| 18550 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => visi
tNode(node); |
| 18551 |
| 18552 @override |
| 18553 R visitFunctionExpression(FunctionExpression node) => visitNode(node); |
| 18554 |
| 18555 @override |
| 18556 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => visi
tNode(node); |
| 18557 |
| 18558 @override |
| 18559 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitNode(node); |
| 18560 |
| 18561 @override |
| 18562 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) => visi
tNode(node); |
| 18563 |
| 18564 @override |
| 18565 R visitHideCombinator(HideCombinator node) => visitNode(node); |
| 18566 |
| 18567 @override |
| 18568 R visitIfStatement(IfStatement node) => visitNode(node); |
| 18569 |
| 18570 @override |
| 18571 R visitImplementsClause(ImplementsClause node) => visitNode(node); |
| 18572 |
| 18573 @override |
| 18574 R visitImportDirective(ImportDirective node) => visitNode(node); |
| 18575 |
| 18576 @override |
| 18577 R visitIndexExpression(IndexExpression node) => visitNode(node); |
| 18578 |
| 18579 @override |
| 18580 R visitInstanceCreationExpression(InstanceCreationExpression node) => visitNod
e(node); |
| 18581 |
| 18582 @override |
| 18583 R visitIntegerLiteral(IntegerLiteral node) => visitNode(node); |
| 18584 |
| 18585 @override |
| 18586 R visitInterpolationExpression(InterpolationExpression node) => visitNode(node
); |
| 18587 |
| 18588 @override |
| 18589 R visitInterpolationString(InterpolationString node) => visitNode(node); |
| 18590 |
| 18591 @override |
| 18592 R visitIsExpression(IsExpression node) => visitNode(node); |
| 18593 |
| 18594 @override |
| 18595 R visitLabel(Label node) => visitNode(node); |
| 18596 |
| 18597 @override |
| 18598 R visitLabeledStatement(LabeledStatement node) => visitNode(node); |
| 18599 |
| 18600 @override |
| 18601 R visitLibraryDirective(LibraryDirective node) => visitNode(node); |
| 18602 |
| 18603 @override |
| 18604 R visitLibraryIdentifier(LibraryIdentifier node) => visitNode(node); |
| 18605 |
| 18606 @override |
| 18607 R visitListLiteral(ListLiteral node) => visitNode(node); |
| 18608 |
| 18609 @override |
| 18610 R visitMapLiteral(MapLiteral node) => visitNode(node); |
| 18611 |
| 18612 @override |
| 18613 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node); |
| 18614 |
| 18615 @override |
| 18616 R visitMethodDeclaration(MethodDeclaration node) => visitNode(node); |
| 18617 |
| 18618 @override |
| 18619 R visitMethodInvocation(MethodInvocation node) => visitNode(node); |
| 18620 |
| 18621 @override |
| 18622 R visitNamedExpression(NamedExpression node) => visitNode(node); |
| 18623 |
| 18624 @override |
| 18625 R visitNativeClause(NativeClause node) => visitNode(node); |
| 18626 |
| 18627 @override |
| 18628 R visitNativeFunctionBody(NativeFunctionBody node) => visitNode(node); |
| 18629 |
| 18630 R visitNode(AstNode node) { |
| 18631 node.visitChildren(this); |
| 18632 return null; |
| 18633 } |
| 18634 |
| 18635 @override |
| 18636 R visitNullLiteral(NullLiteral node) => visitNode(node); |
| 18637 |
| 18638 @override |
| 18639 R visitParenthesizedExpression(ParenthesizedExpression node) => visitNode(node
); |
| 18640 |
| 18641 @override |
| 18642 R visitPartDirective(PartDirective node) => visitNode(node); |
| 18643 |
| 18644 @override |
| 18645 R visitPartOfDirective(PartOfDirective node) => visitNode(node); |
| 18646 |
| 18647 @override |
| 18648 R visitPostfixExpression(PostfixExpression node) => visitNode(node); |
| 18649 |
| 18650 @override |
| 18651 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitNode(node); |
| 18652 |
| 18653 @override |
| 18654 R visitPrefixExpression(PrefixExpression node) => visitNode(node); |
| 18655 |
| 18656 @override |
| 18657 R visitPropertyAccess(PropertyAccess node) => visitNode(node); |
| 18658 |
| 18659 @override |
| 18660 R visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node)
=> visitNode(node); |
| 18661 |
| 18662 @override |
| 18663 R visitRethrowExpression(RethrowExpression node) => visitNode(node); |
| 18664 |
| 18665 @override |
| 18666 R visitReturnStatement(ReturnStatement node) => visitNode(node); |
| 18667 |
| 18668 @override |
| 18669 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag); |
| 18670 |
| 18671 @override |
| 18672 R visitShowCombinator(ShowCombinator node) => visitNode(node); |
| 18673 |
| 18674 @override |
| 18675 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNode(node); |
| 18676 |
| 18677 @override |
| 18678 R visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node); |
| 18679 |
| 18680 @override |
| 18681 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node); |
| 18682 |
| 18683 @override |
| 18684 R visitStringInterpolation(StringInterpolation node) => visitNode(node); |
| 18685 |
| 18686 @override |
| 18687 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => visitNod
e(node); |
| 18688 |
| 18689 @override |
| 18690 R visitSuperExpression(SuperExpression node) => visitNode(node); |
| 18691 |
| 18692 @override |
| 18693 R visitSwitchCase(SwitchCase node) => visitNode(node); |
| 18694 |
| 18695 @override |
| 18696 R visitSwitchDefault(SwitchDefault node) => visitNode(node); |
| 18697 |
| 18698 @override |
| 18699 R visitSwitchStatement(SwitchStatement node) => visitNode(node); |
| 18700 |
| 18701 @override |
| 18702 R visitSymbolLiteral(SymbolLiteral node) => visitNode(node); |
| 18703 |
| 18704 @override |
| 18705 R visitThisExpression(ThisExpression node) => visitNode(node); |
| 18706 |
| 18707 @override |
| 18708 R visitThrowExpression(ThrowExpression node) => visitNode(node); |
| 18709 |
| 18710 @override |
| 18711 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => visitN
ode(node); |
| 18712 |
| 18713 @override |
| 18714 R visitTryStatement(TryStatement node) => visitNode(node); |
| 18715 |
| 18716 @override |
| 18717 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node); |
| 18718 |
| 18719 @override |
| 18720 R visitTypeName(TypeName node) => visitNode(node); |
| 18721 |
| 18722 @override |
| 18723 R visitTypeParameter(TypeParameter node) => visitNode(node); |
| 18724 |
| 18725 @override |
| 18726 R visitTypeParameterList(TypeParameterList node) => visitNode(node); |
| 18727 |
| 18728 @override |
| 18729 R visitVariableDeclaration(VariableDeclaration node) => visitNode(node); |
| 18730 |
| 18731 @override |
| 18732 R visitVariableDeclarationList(VariableDeclarationList node) => visitNode(node
); |
| 18733 |
| 18734 @override |
| 18735 R visitVariableDeclarationStatement(VariableDeclarationStatement node) => visi
tNode(node); |
| 18736 |
| 18737 @override |
| 18738 R visitWhileStatement(WhileStatement node) => visitNode(node); |
| 18739 |
| 18740 @override |
| 18741 R visitWithClause(WithClause node) => visitNode(node); |
| 18742 |
| 18743 @override |
| 18744 R visitYieldStatement(YieldStatement node) => visitNode(node); |
| 18745 } |
| 18746 |
| 18747 /** |
| 18748 * The abstract class `UriBasedDirective` defines the behavior common to nodes t
hat represent |
| 18749 * a directive that references a URI. |
| 18750 * |
| 18751 * <pre> |
| 18752 * uriBasedDirective ::= |
| 18753 * [ExportDirective] |
| 18754 * | [ImportDirective] |
| 18755 * | [PartDirective] |
| 18756 * </pre> |
| 18757 */ |
| 18758 abstract class UriBasedDirective extends Directive { |
| 18759 /** |
| 18760 * The URI referenced by this directive. |
| 18761 */ |
| 18762 StringLiteral _uri; |
| 18763 |
| 18764 /** |
| 18765 * The prefix of a URI using the `dart-ext` scheme to reference a native code
library. |
| 18766 */ |
| 18767 static String _DART_EXT_SCHEME = "dart-ext:"; |
| 18768 |
| 18769 /** |
| 18770 * The content of the URI. |
| 18771 */ |
| 18772 String uriContent; |
| 18773 |
| 18774 /** |
| 18775 * The source to which the URI was resolved. |
| 18776 */ |
| 18777 Source source; |
| 18778 |
| 18779 /** |
| 18780 * Initialize a newly create URI-based directive. |
| 18781 * |
| 18782 * @param comment the documentation comment associated with this directive |
| 18783 * @param metadata the annotations associated with the directive |
| 18784 * @param uri the URI referenced by this directive |
| 18785 */ |
| 18786 UriBasedDirective(Comment comment, List<Annotation> metadata, StringLiteral ur
i) : super(comment, metadata) { |
| 18787 this._uri = becomeParentOf(uri); |
| 18788 } |
| 18789 |
| 18790 /** |
| 18791 * Return the URI referenced by this directive. |
| 18792 * |
| 18793 * @return the URI referenced by this directive |
| 18794 */ |
| 18795 StringLiteral get uri => _uri; |
| 18796 |
| 18797 /** |
| 18798 * Return the element associated with the URI of this directive, or `null` if
the AST |
| 18799 * structure has not been resolved or if the URI could not be resolved. Exampl
es of the latter |
| 18800 * case include a directive that contains an invalid URL or a URL that does no
t exist. |
| 18801 * |
| 18802 * @return the element associated with this directive |
| 18803 */ |
| 18804 Element get uriElement; |
| 18805 |
| 18806 /** |
| 18807 * Set the URI referenced by this directive to the given URI. |
| 18808 * |
| 18809 * @param uri the URI referenced by this directive |
| 18810 */ |
| 18811 void set uri(StringLiteral uri) { |
| 18812 this._uri = becomeParentOf(uri); |
| 18813 } |
| 18814 |
| 18815 /** |
| 18816 * Validate the given directive, but do not check for existence. |
| 18817 * |
| 18818 * @return a code indicating the problem if there is one, or `null` no problem |
| 18819 */ |
| 18820 UriValidationCode validate() { |
| 18821 StringLiteral uriLiteral = uri; |
| 18822 if (uriLiteral is StringInterpolation) { |
| 18823 return UriValidationCode.URI_WITH_INTERPOLATION; |
| 18824 } |
| 18825 String uriContent = this.uriContent; |
| 18826 if (uriContent == null) { |
| 18827 return UriValidationCode.INVALID_URI; |
| 18828 } |
| 18829 if (this is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME)) { |
| 18830 return UriValidationCode.URI_WITH_DART_EXT_SCHEME; |
| 18831 } |
| 18832 try { |
| 18833 parseUriWithException(Uri.encodeFull(uriContent)); |
| 18834 } on URISyntaxException catch (exception) { |
| 18835 return UriValidationCode.INVALID_URI; |
| 18836 } |
| 18837 return null; |
| 18838 } |
| 18839 |
| 18840 @override |
| 18841 void visitChildren(AstVisitor visitor) { |
| 18842 super.visitChildren(visitor); |
| 18843 safelyVisitChild(_uri, visitor); |
| 18844 } |
| 18845 } |
| 18846 |
| 18847 /** |
| 18848 * Validation codes returned by [UriBasedDirective#validate]. |
| 18849 */ |
| 18850 class UriValidationCode extends Enum<UriValidationCode> { |
| 18851 static const UriValidationCode INVALID_URI = const UriValidationCode('INVALID_
URI', 0); |
| 18852 |
| 18853 static const UriValidationCode URI_WITH_INTERPOLATION = const UriValidationCod
e('URI_WITH_INTERPOLATION', 1); |
| 18854 |
| 18855 static const UriValidationCode URI_WITH_DART_EXT_SCHEME = const UriValidationC
ode('URI_WITH_DART_EXT_SCHEME', 2); |
| 18856 |
| 18857 static const List<UriValidationCode> values = const [ |
| 18858 INVALID_URI, |
| 18859 URI_WITH_INTERPOLATION, |
| 18860 URI_WITH_DART_EXT_SCHEME]; |
| 18861 |
| 18862 const UriValidationCode(String name, int ordinal) : super(name, ordinal); |
| 18863 } |
| 18864 |
| 18865 /** |
| 18866 * Instances of the class `VariableDeclaration` represent an identifier that has
an initial |
| 18867 * value associated with it. Instances of this class are always children of the
class |
| 18868 * [VariableDeclarationList]. |
| 18869 * |
| 18870 * <pre> |
| 18871 * variableDeclaration ::= |
| 18872 * [SimpleIdentifier] ('=' [Expression])? |
| 18873 * </pre> |
| 18874 */ |
| 18875 class VariableDeclaration extends Declaration { |
| 18876 /** |
| 18877 * The name of the variable being declared. |
| 18878 */ |
| 18879 SimpleIdentifier _name; |
| 18880 |
| 18881 /** |
| 18882 * The equal sign separating the variable name from the initial value, or `nul
l` if the |
| 18883 * initial value was not specified. |
| 18884 */ |
| 18885 Token equals; |
| 18886 |
| 18887 /** |
| 18888 * The expression used to compute the initial value for the variable, or `null
` if the |
| 18889 * initial value was not specified. |
| 18890 */ |
| 18891 Expression _initializer; |
| 18892 |
| 18893 /** |
| 18894 * Initialize a newly created variable declaration. |
| 18895 * |
| 18896 * @param comment the documentation comment associated with this declaration |
| 18897 * @param metadata the annotations associated with this member |
| 18898 * @param name the name of the variable being declared |
| 18899 * @param equals the equal sign separating the variable name from the initial
value |
| 18900 * @param initializer the expression used to compute the initial value for the
variable |
| 18901 */ |
| 18902 VariableDeclaration(Comment comment, List<Annotation> metadata, SimpleIdentifi
er name, this.equals, Expression initializer) : super(comment, metadata) { |
| 18903 this._name = becomeParentOf(name); |
| 18904 this._initializer = becomeParentOf(initializer); |
| 18905 } |
| 18906 |
| 18907 @override |
| 18908 accept(AstVisitor visitor) => visitor.visitVariableDeclaration(this); |
| 18909 |
| 18910 /** |
| 18911 * This overridden implementation of getDocumentationComment() looks in the gr
andparent node for |
| 18912 * dartdoc comments if no documentation is specifically available on the node. |
| 18913 */ |
| 18914 @override |
| 18915 Comment get documentationComment { |
| 18916 Comment comment = super.documentationComment; |
| 18917 if (comment == null) { |
| 18918 if (parent != null && parent.parent != null) { |
| 18919 AstNode node = parent.parent; |
| 18920 if (node is AnnotatedNode) { |
| 18921 return node.documentationComment; |
| 18922 } |
| 18923 } |
| 18924 } |
| 18925 return comment; |
| 18926 } |
| 18927 |
| 18928 @override |
| 18929 VariableElement get element => _name != null ? (_name.staticElement as Variabl
eElement) : null; |
| 18930 |
| 18931 @override |
| 18932 Token get endToken { |
| 18933 if (_initializer != null) { |
| 18934 return _initializer.endToken; |
| 18935 } |
| 18936 return _name.endToken; |
| 18937 } |
| 18938 |
| 18939 /** |
| 18940 * Return the expression used to compute the initial value for the variable, o
r `null` if |
| 18941 * the initial value was not specified. |
| 18942 * |
| 18943 * @return the expression used to compute the initial value for the variable |
| 18944 */ |
| 18945 Expression get initializer => _initializer; |
| 18946 |
| 18947 /** |
| 18948 * Return the name of the variable being declared. |
| 18949 * |
| 18950 * @return the name of the variable being declared |
| 18951 */ |
| 18952 SimpleIdentifier get name => _name; |
| 18953 |
| 18954 /** |
| 18955 * Return `true` if this variable was declared with the 'const' modifier. |
| 18956 * |
| 18957 * @return `true` if this variable was declared with the 'const' modifier |
| 18958 */ |
| 18959 bool get isConst { |
| 18960 AstNode parent = this.parent; |
| 18961 return parent is VariableDeclarationList && parent.isConst; |
| 18962 } |
| 18963 |
| 18964 /** |
| 18965 * Return `true` if this variable was declared with the 'final' modifier. Vari
ables that are |
| 18966 * declared with the 'const' modifier will return `false` even though they are
implicitly |
| 18967 * final. |
| 18968 * |
| 18969 * @return `true` if this variable was declared with the 'final' modifier |
| 18970 */ |
| 18971 bool get isFinal { |
| 18972 AstNode parent = this.parent; |
| 18973 return parent is VariableDeclarationList && parent.isFinal; |
| 18974 } |
| 18975 |
| 18976 /** |
| 18977 * Set the expression used to compute the initial value for the variable to th
e given expression. |
| 18978 * |
| 18979 * @param initializer the expression used to compute the initial value for the
variable |
| 18980 */ |
| 18981 void set initializer(Expression initializer) { |
| 18982 this._initializer = becomeParentOf(initializer); |
| 18983 } |
| 18984 |
| 18985 /** |
| 18986 * Set the name of the variable being declared to the given identifier. |
| 18987 * |
| 18988 * @param name the name of the variable being declared |
| 18989 */ |
| 18990 void set name(SimpleIdentifier name) { |
| 18991 this._name = becomeParentOf(name); |
| 18992 } |
| 18993 |
| 18994 @override |
| 18995 void visitChildren(AstVisitor visitor) { |
| 18996 super.visitChildren(visitor); |
| 18997 safelyVisitChild(_name, visitor); |
| 18998 safelyVisitChild(_initializer, visitor); |
| 18999 } |
| 19000 |
| 19001 @override |
| 19002 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 19003 } |
| 19004 |
| 19005 /** |
| 19006 * Instances of the class `VariableDeclarationList` represent the declaration of
one or more |
| 19007 * variables of the same type. |
| 19008 * |
| 19009 * <pre> |
| 19010 * variableDeclarationList ::= |
| 19011 * finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])* |
| 19012 * |
| 19013 * finalConstVarOrType ::= |
| 19014 * | 'final' [TypeName]? |
| 19015 * | 'const' [TypeName]? |
| 19016 * | 'var' |
| 19017 * | [TypeName] |
| 19018 * </pre> |
| 19019 */ |
| 19020 class VariableDeclarationList extends AnnotatedNode { |
| 19021 /** |
| 19022 * The token representing the 'final', 'const' or 'var' keyword, or `null` if
no keyword was |
| 19023 * included. |
| 19024 */ |
| 19025 Token keyword; |
| 19026 |
| 19027 /** |
| 19028 * The type of the variables being declared, or `null` if no type was provided
. |
| 19029 */ |
| 19030 TypeName _type; |
| 19031 |
| 19032 /** |
| 19033 * A list containing the individual variables being declared. |
| 19034 */ |
| 19035 NodeList<VariableDeclaration> _variables; |
| 19036 |
| 19037 /** |
| 19038 * Initialize a newly created variable declaration list. |
| 19039 * |
| 19040 * @param comment the documentation comment associated with this declaration l
ist |
| 19041 * @param metadata the annotations associated with this declaration list |
| 19042 * @param keyword the token representing the 'final', 'const' or 'var' keyword |
| 19043 * @param type the type of the variables being declared |
| 19044 * @param variables a list containing the individual variables being declared |
| 19045 */ |
| 19046 VariableDeclarationList(Comment comment, List<Annotation> metadata, this.keywo
rd, TypeName type, List<VariableDeclaration> variables) : super(comment, metadat
a) { |
| 19047 this._variables = new NodeList<VariableDeclaration>(this); |
| 19048 this._type = becomeParentOf(type); |
| 19049 this._variables.addAll(variables); |
| 19050 } |
| 19051 |
| 19052 @override |
| 19053 accept(AstVisitor visitor) => visitor.visitVariableDeclarationList(this); |
| 19054 |
| 19055 @override |
| 19056 Token get endToken => _variables.endToken; |
| 19057 |
| 19058 /** |
| 19059 * Return the type of the variables being declared, or `null` if no type was p
rovided. |
| 19060 * |
| 19061 * @return the type of the variables being declared |
| 19062 */ |
| 19063 TypeName get type => _type; |
| 19064 |
| 19065 /** |
| 19066 * Return a list containing the individual variables being declared. |
| 19067 * |
| 19068 * @return a list containing the individual variables being declared |
| 19069 */ |
| 19070 NodeList<VariableDeclaration> get variables => _variables; |
| 19071 |
| 19072 /** |
| 19073 * Return `true` if the variables in this list were declared with the 'const'
modifier. |
| 19074 * |
| 19075 * @return `true` if the variables in this list were declared with the 'const'
modifier |
| 19076 */ |
| 19077 bool get isConst => keyword is KeywordToken && (keyword as KeywordToken).keywo
rd == Keyword.CONST; |
| 19078 |
| 19079 /** |
| 19080 * Return `true` if the variables in this list were declared with the 'final'
modifier. |
| 19081 * Variables that are declared with the 'const' modifier will return `false` e
ven though |
| 19082 * they are implicitly final. |
| 19083 * |
| 19084 * @return `true` if the variables in this list were declared with the 'final'
modifier |
| 19085 */ |
| 19086 bool get isFinal => keyword is KeywordToken && (keyword as KeywordToken).keywo
rd == Keyword.FINAL; |
| 19087 |
| 19088 /** |
| 19089 * Set the type of the variables being declared to the given type name. |
| 19090 * |
| 19091 * @param typeName the type of the variables being declared |
| 19092 */ |
| 19093 void set type(TypeName typeName) { |
| 19094 _type = becomeParentOf(typeName); |
| 19095 } |
| 19096 |
| 19097 @override |
| 19098 void visitChildren(AstVisitor visitor) { |
| 19099 super.visitChildren(visitor); |
| 19100 safelyVisitChild(_type, visitor); |
| 19101 _variables.accept(visitor); |
| 19102 } |
| 19103 |
| 19104 @override |
| 19105 Token get firstTokenAfterCommentAndMetadata { |
| 19106 if (keyword != null) { |
| 19107 return keyword; |
| 19108 } else if (_type != null) { |
| 19109 return _type.beginToken; |
| 19110 } |
| 19111 return _variables.beginToken; |
| 19112 } |
| 19113 } |
| 19114 |
| 19115 /** |
| 19116 * Instances of the class `VariableDeclarationStatement` represent a list of var
iables that |
| 19117 * are being declared in a context where a statement is required. |
| 19118 * |
| 19119 * <pre> |
| 19120 * variableDeclarationStatement ::= |
| 19121 * [VariableDeclarationList] ';' |
| 19122 * </pre> |
| 19123 */ |
| 19124 class VariableDeclarationStatement extends Statement { |
| 19125 /** |
| 19126 * The variables being declared. |
| 19127 */ |
| 19128 VariableDeclarationList _variableList; |
| 19129 |
| 19130 /** |
| 19131 * The semicolon terminating the statement. |
| 19132 */ |
| 19133 Token semicolon; |
| 19134 |
| 19135 /** |
| 19136 * Initialize a newly created variable declaration statement. |
| 19137 * |
| 19138 * @param variableList the fields being declared |
| 19139 * @param semicolon the semicolon terminating the statement |
| 19140 */ |
| 19141 VariableDeclarationStatement(VariableDeclarationList variableList, this.semico
lon) { |
| 19142 this._variableList = becomeParentOf(variableList); |
| 19143 } |
| 19144 |
| 19145 @override |
| 19146 accept(AstVisitor visitor) => visitor.visitVariableDeclarationStatement(this); |
| 19147 |
| 19148 @override |
| 19149 Token get beginToken => _variableList.beginToken; |
| 19150 |
| 19151 @override |
| 19152 Token get endToken => semicolon; |
| 19153 |
| 19154 /** |
| 19155 * Return the variables being declared. |
| 19156 * |
| 19157 * @return the variables being declared |
| 19158 */ |
| 19159 VariableDeclarationList get variables => _variableList; |
| 19160 |
| 19161 /** |
| 19162 * Set the variables being declared to the given list of variables. |
| 19163 * |
| 19164 * @param variableList the variables being declared |
| 19165 */ |
| 19166 void set variables(VariableDeclarationList variableList) { |
| 19167 this._variableList = becomeParentOf(variableList); |
| 19168 } |
| 19169 |
| 19170 @override |
| 19171 void visitChildren(AstVisitor visitor) { |
| 19172 safelyVisitChild(_variableList, visitor); |
| 19173 } |
| 19174 } |
| 19175 |
| 19176 /** |
| 19177 * Instances of the class `WhileStatement` represent a while statement. |
| 19178 * |
| 19179 * <pre> |
| 19180 * whileStatement ::= |
| 19181 * 'while' '(' [Expression] ')' [Statement] |
| 19182 * </pre> |
| 19183 */ |
| 19184 class WhileStatement extends Statement { |
| 19185 /** |
| 19186 * The token representing the 'while' keyword. |
| 19187 */ |
| 19188 Token keyword; |
| 19189 |
| 19190 /** |
| 19191 * The left parenthesis. |
| 19192 */ |
| 19193 Token leftParenthesis; |
| 19194 |
| 19195 /** |
| 19196 * The expression used to determine whether to execute the body of the loop. |
| 19197 */ |
| 19198 Expression _condition; |
| 19199 |
| 19200 /** |
| 19201 * The right parenthesis. |
| 19202 */ |
| 19203 Token rightParenthesis; |
| 19204 |
| 19205 /** |
| 19206 * The body of the loop. |
| 19207 */ |
| 19208 Statement _body; |
| 19209 |
| 19210 /** |
| 19211 * Initialize a newly created while statement. |
| 19212 * |
| 19213 * @param keyword the token representing the 'while' keyword |
| 19214 * @param leftParenthesis the left parenthesis |
| 19215 * @param condition the expression used to determine whether to execute the bo
dy of the loop |
| 19216 * @param rightParenthesis the right parenthesis |
| 19217 * @param body the body of the loop |
| 19218 */ |
| 19219 WhileStatement(this.keyword, this.leftParenthesis, Expression condition, this.
rightParenthesis, Statement body) { |
| 19220 this._condition = becomeParentOf(condition); |
| 19221 this._body = becomeParentOf(body); |
| 19222 } |
| 19223 |
| 19224 @override |
| 19225 accept(AstVisitor visitor) => visitor.visitWhileStatement(this); |
| 19226 |
| 19227 @override |
| 19228 Token get beginToken => keyword; |
| 19229 |
| 19230 /** |
| 19231 * Return the body of the loop. |
| 19232 * |
| 19233 * @return the body of the loop |
| 19234 */ |
| 19235 Statement get body => _body; |
| 19236 |
| 19237 /** |
| 19238 * Return the expression used to determine whether to execute the body of the
loop. |
| 19239 * |
| 19240 * @return the expression used to determine whether to execute the body of the
loop |
| 19241 */ |
| 19242 Expression get condition => _condition; |
| 19243 |
| 19244 @override |
| 19245 Token get endToken => _body.endToken; |
| 19246 |
| 19247 /** |
| 19248 * Set the body of the loop to the given statement. |
| 19249 * |
| 19250 * @param statement the body of the loop |
| 19251 */ |
| 19252 void set body(Statement statement) { |
| 19253 _body = becomeParentOf(statement); |
| 19254 } |
| 19255 |
| 19256 /** |
| 19257 * Set the expression used to determine whether to execute the body of the loo
p to the given |
| 19258 * expression. |
| 19259 * |
| 19260 * @param expression the expression used to determine whether to execute the b
ody of the loop |
| 19261 */ |
| 19262 void set condition(Expression expression) { |
| 19263 _condition = becomeParentOf(expression); |
| 19264 } |
| 19265 |
| 19266 @override |
| 19267 void visitChildren(AstVisitor visitor) { |
| 19268 safelyVisitChild(_condition, visitor); |
| 19269 safelyVisitChild(_body, visitor); |
| 19270 } |
| 19271 } |
| 19272 |
| 19273 /** |
| 19274 * Instances of the class `WithClause` represent the with clause in a class decl
aration. |
| 19275 * |
| 19276 * <pre> |
| 19277 * withClause ::= |
| 19278 * 'with' [TypeName] (',' [TypeName])* |
| 19279 * </pre> |
| 19280 */ |
| 19281 class WithClause extends AstNode { |
| 19282 /** |
| 19283 * The token representing the 'with' keyword. |
| 19284 */ |
| 19285 Token _withKeyword; |
| 19286 |
| 19287 /** |
| 19288 * The names of the mixins that were specified. |
| 19289 */ |
| 19290 NodeList<TypeName> _mixinTypes; |
| 19291 |
| 19292 /** |
| 19293 * Initialize a newly created with clause. |
| 19294 * |
| 19295 * @param withKeyword the token representing the 'with' keyword |
| 19296 * @param mixinTypes the names of the mixins that were specified |
| 19297 */ |
| 19298 WithClause(Token withKeyword, List<TypeName> mixinTypes) { |
| 19299 this._mixinTypes = new NodeList<TypeName>(this); |
| 19300 this._withKeyword = withKeyword; |
| 19301 this._mixinTypes.addAll(mixinTypes); |
| 19302 } |
| 19303 |
| 19304 @override |
| 19305 accept(AstVisitor visitor) => visitor.visitWithClause(this); |
| 19306 |
| 19307 @override |
| 19308 Token get beginToken => _withKeyword; |
| 19309 |
| 19310 @override |
| 19311 Token get endToken => _mixinTypes.endToken; |
| 19312 |
| 19313 /** |
| 19314 * Return the names of the mixins that were specified. |
| 19315 * |
| 19316 * @return the names of the mixins that were specified |
| 19317 */ |
| 19318 NodeList<TypeName> get mixinTypes => _mixinTypes; |
| 19319 |
| 19320 /** |
| 19321 * Return the token representing the 'with' keyword. |
| 19322 * |
| 19323 * @return the token representing the 'with' keyword |
| 19324 */ |
| 19325 Token get withKeyword => _withKeyword; |
| 19326 |
| 19327 /** |
| 19328 * Set the token representing the 'with' keyword to the given token. |
| 19329 * |
| 19330 * @param withKeyword the token representing the 'with' keyword |
| 19331 */ |
| 19332 void set mixinKeyword(Token withKeyword) { |
| 19333 this._withKeyword = withKeyword; |
| 19334 } |
| 19335 |
| 19336 @override |
| 19337 void visitChildren(AstVisitor visitor) { |
| 19338 _mixinTypes.accept(visitor); |
| 19339 } |
| 19340 } |
| 19341 |
| 19342 /** |
| 19343 * Instances of the class `YieldStatement` implement a yield statement. |
| 19344 */ |
| 19345 class YieldStatement extends Statement { |
| 19346 /** |
| 19347 * The 'yield' keyword. |
| 19348 */ |
| 19349 Token yieldKeyword; |
| 19350 |
| 19351 /** |
| 19352 * The star optionally following the 'yield' keyword. |
| 19353 */ |
| 19354 Token star; |
| 19355 |
| 19356 /** |
| 19357 * The expression whose value will be yielded. |
| 19358 */ |
| 19359 Expression _expression; |
| 19360 |
| 19361 /** |
| 19362 * The semicolon following the expression. |
| 19363 */ |
| 19364 Token semicolon; |
| 19365 |
| 19366 /** |
| 19367 * Initialize a newly created yield expression. |
| 19368 * |
| 19369 * @param yieldKeyword the 'yield' keyword |
| 19370 * @param star the star following the 'yield' keyword |
| 19371 * @param expression the expression whose value will be yielded |
| 19372 * @param semicolon the semicolon following the expression |
| 19373 */ |
| 19374 YieldStatement(this.yieldKeyword, this.star, Expression expression, this.semic
olon) { |
| 19375 this._expression = becomeParentOf(expression); |
| 19376 } |
| 19377 |
| 19378 @override |
| 19379 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); |
| 19380 |
| 19381 @override |
| 19382 Token get beginToken { |
| 19383 if (yieldKeyword != null) { |
| 19384 return yieldKeyword; |
| 19385 } |
| 19386 return _expression.beginToken; |
| 19387 } |
| 19388 |
| 19389 @override |
| 19390 Token get endToken { |
| 19391 if (semicolon != null) { |
| 19392 return semicolon; |
| 19393 } |
| 19394 return _expression.endToken; |
| 19395 } |
| 19396 |
| 19397 /** |
| 19398 * Return the expression whose value will be yielded. |
| 19399 * |
| 19400 * @return the expression whose value will be yielded |
| 19401 */ |
| 19402 Expression get expression => _expression; |
| 19403 |
| 19404 /** |
| 19405 * Set the expression whose value will be yielded to the given expression. |
| 19406 * |
| 19407 * @param expression the expression whose value will be yielded |
| 19408 */ |
| 19409 void set expression(Expression expression) { |
| 19410 this._expression = becomeParentOf(expression); |
| 19411 } |
| 19412 |
| 19413 @override |
| 19414 void visitChildren(AstVisitor visitor) { |
| 19415 safelyVisitChild(_expression, visitor); |
| 19416 } |
| 19417 } |
| 19418 /** |
| 19419 * Instances of the class {@code NodeList} represent a list of AST nodes that ha
ve a common parent. |
| 19420 */ |
| 19421 class NodeList<E extends AstNode> extends Object with ListMixin<E> { |
| 19422 /** |
| 19423 * Create an empty list with the given owner. This is a convenience method tha
t allows the |
| 19424 * compiler to determine the correct value of the type argument [E] without ne
eding to |
| 19425 * explicitly specify it. |
| 19426 * |
| 19427 * @param owner the node that is the parent of each of the elements in the lis
t |
| 19428 * @return the list that was created |
| 19429 */ |
| 19430 static NodeList create(AstNode owner) => new NodeList(owner); |
| 19431 |
| 19432 /** |
| 19433 * The node that is the parent of each of the elements in the list. |
| 19434 */ |
| 19435 AstNode owner; |
| 19436 |
| 19437 /** |
| 19438 * The elements contained in the list. |
| 19439 */ |
| 19440 List<E> _elements = <E> []; |
| 19441 |
| 19442 /** |
| 19443 * Initialize a newly created list of nodes to be empty. |
| 19444 * |
| 19445 * @param owner the node that is the parent of each of the elements in the lis
t |
| 19446 */ |
| 19447 NodeList(this.owner); |
| 19448 |
| 19449 /** |
| 19450 * Use the given visitor to visit each of the nodes in this list. |
| 19451 * |
| 19452 * @param visitor the visitor to be used to visit the elements of this list |
| 19453 */ |
| 19454 accept(AstVisitor visitor) { |
| 19455 var length = _elements.length; |
| 19456 for (var i = 0; i < length; i++) { |
| 19457 _elements[i].accept(visitor); |
| 19458 } |
| 19459 } |
| 19460 void add(E node) { |
| 19461 insert(length, node); |
| 19462 } |
| 19463 void insert(int index, E node) { |
| 19464 int length = _elements.length; |
| 19465 if (index < 0 || index > length) { |
| 19466 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); |
| 19467 } |
| 19468 owner.becomeParentOf(node); |
| 19469 if (length == 0) { |
| 19470 _elements = <E> [node]; |
| 19471 } else { |
| 19472 _elements.insert(index, node); |
| 19473 } |
| 19474 } |
| 19475 bool addAll(Iterable<E> nodes) { |
| 19476 if (nodes != null && !nodes.isEmpty) { |
| 19477 _elements.addAll(nodes); |
| 19478 for (E node in nodes) { |
| 19479 owner.becomeParentOf(node); |
| 19480 } |
| 19481 return true; |
| 19482 } |
| 19483 return false; |
| 19484 } |
| 19485 E operator[](int index) { |
| 19486 if (index < 0 || index >= _elements.length) { |
| 19487 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); |
| 19488 } |
| 19489 return _elements[index] as E; |
| 19490 } |
| 19491 |
| 19492 /** |
| 19493 * Return the first token included in this node's source range. |
| 19494 * |
| 19495 * @return the first token included in this node's source range |
| 19496 */ |
| 19497 Token get beginToken { |
| 19498 if (_elements.length == 0) { |
| 19499 return null; |
| 19500 } |
| 19501 return _elements[0].beginToken; |
| 19502 } |
| 19503 |
| 19504 /** |
| 19505 * Return the last token included in this node list's source range. |
| 19506 * |
| 19507 * @return the last token included in this node list's source range |
| 19508 */ |
| 19509 Token get endToken { |
| 19510 if (_elements.length == 0) { |
| 19511 return null; |
| 19512 } |
| 19513 return _elements[_elements.length - 1].endToken; |
| 19514 } |
| 19515 E removeAt(int index) { |
| 19516 if (index < 0 || index >= _elements.length) { |
| 19517 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); |
| 19518 } |
| 19519 E removedNode = _elements[index] as E; |
| 19520 int length = _elements.length; |
| 19521 if (length == 1) { |
| 19522 _elements = AstNode.EMPTY_ARRAY; |
| 19523 return removedNode; |
| 19524 } |
| 19525 _elements.removeAt(index); |
| 19526 return removedNode; |
| 19527 } |
| 19528 void operator[]=(int index, E node) { |
| 19529 if (index < 0 || index >= _elements.length) { |
| 19530 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); |
| 19531 } |
| 19532 owner.becomeParentOf(node); |
| 19533 _elements[index] = node; |
| 19534 } |
| 19535 void clear() { |
| 19536 _elements = <E> []; |
| 19537 } |
| 19538 int get length => _elements.length; |
| 19539 void set length(int value) { |
| 19540 throw new UnsupportedError("Cannot resize NodeList."); |
| 19541 } |
| 19542 } |
OLD | NEW |