| 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 library analyzer.src.dart.ast.ast; |
| 6 |
| 7 import 'dart:collection'; |
| 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/syntactic_entity.dart'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/exception/exception.dart'; |
| 15 import 'package:analyzer/src/dart/ast/token.dart'; |
| 16 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 17 import 'package:analyzer/src/dart/element/element.dart'; |
| 18 import 'package:analyzer/src/dart/element/type.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; |
| 20 import 'package:analyzer/src/generated/java_core.dart'; |
| 21 import 'package:analyzer/src/generated/java_engine.dart'; |
| 22 import 'package:analyzer/src/generated/parser.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; |
| 24 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 25 |
| 26 /** |
| 27 * Two or more string literals that are implicitly concatenated because of being |
| 28 * adjacent (separated only by whitespace). |
| 29 * |
| 30 * While the grammar only allows adjacent strings when all of the strings are of |
| 31 * the same kind (single line or multi-line), this class doesn't enforce that |
| 32 * restriction. |
| 33 * |
| 34 * adjacentStrings ::= |
| 35 * [StringLiteral] [StringLiteral]+ |
| 36 */ |
| 37 class AdjacentStringsImpl extends StringLiteralImpl implements AdjacentStrings { |
| 38 /** |
| 39 * The strings that are implicitly concatenated. |
| 40 */ |
| 41 NodeList<StringLiteral> _strings; |
| 42 |
| 43 /** |
| 44 * Initialize a newly created list of adjacent strings. To be syntactically |
| 45 * valid, the list of [strings] must contain at least two elements. |
| 46 */ |
| 47 AdjacentStringsImpl(List<StringLiteral> strings) { |
| 48 _strings = new NodeListImpl<StringLiteral>(this, strings); |
| 49 } |
| 50 |
| 51 @override |
| 52 Token get beginToken => _strings.beginToken; |
| 53 |
| 54 @override |
| 55 Iterable<SyntacticEntity> get childEntities => |
| 56 new ChildEntities()..addAll(_strings); |
| 57 |
| 58 @override |
| 59 Token get endToken => _strings.endToken; |
| 60 |
| 61 @override |
| 62 NodeList<StringLiteral> get strings => _strings; |
| 63 |
| 64 @override |
| 65 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 66 visitor.visitAdjacentStrings(this); |
| 67 |
| 68 @override |
| 69 void visitChildren(AstVisitor visitor) { |
| 70 _strings.accept(visitor); |
| 71 } |
| 72 |
| 73 @override |
| 74 void _appendStringValue(StringBuffer buffer) { |
| 75 int length = strings.length; |
| 76 for (int i = 0; i < length; i++) { |
| 77 StringLiteralImpl stringLiteral = strings[i]; |
| 78 stringLiteral._appendStringValue(buffer); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 /** |
| 84 * An AST node that can be annotated with both a documentation comment and a |
| 85 * list of annotations. |
| 86 */ |
| 87 abstract class AnnotatedNodeImpl extends AstNodeImpl implements AnnotatedNode { |
| 88 /** |
| 89 * The documentation comment associated with this node, or `null` if this node |
| 90 * does not have a documentation comment associated with it. |
| 91 */ |
| 92 Comment _comment; |
| 93 |
| 94 /** |
| 95 * The annotations associated with this node. |
| 96 */ |
| 97 NodeList<Annotation> _metadata; |
| 98 |
| 99 /** |
| 100 * Initialize a newly created annotated node. Either or both of the [comment] |
| 101 * and [metadata] can be `null` if the node does not have the corresponding |
| 102 * attribute. |
| 103 */ |
| 104 AnnotatedNodeImpl(CommentImpl comment, List<Annotation> metadata) { |
| 105 _comment = _becomeParentOf(comment); |
| 106 _metadata = new NodeListImpl<Annotation>(this, metadata); |
| 107 } |
| 108 |
| 109 @override |
| 110 Token get beginToken { |
| 111 if (_comment == null) { |
| 112 if (_metadata.isEmpty) { |
| 113 return firstTokenAfterCommentAndMetadata; |
| 114 } |
| 115 return _metadata.beginToken; |
| 116 } else if (_metadata.isEmpty) { |
| 117 return _comment.beginToken; |
| 118 } |
| 119 Token commentToken = _comment.beginToken; |
| 120 Token metadataToken = _metadata.beginToken; |
| 121 if (commentToken.offset < metadataToken.offset) { |
| 122 return commentToken; |
| 123 } |
| 124 return metadataToken; |
| 125 } |
| 126 |
| 127 @override |
| 128 Comment get documentationComment => _comment; |
| 129 |
| 130 @override |
| 131 void set documentationComment(Comment comment) { |
| 132 _comment = _becomeParentOf(comment as AstNodeImpl); |
| 133 } |
| 134 |
| 135 @override |
| 136 NodeList<Annotation> get metadata => _metadata; |
| 137 |
| 138 @override |
| 139 List<AstNode> get sortedCommentAndAnnotations { |
| 140 return <AstNode>[] |
| 141 ..add(_comment) |
| 142 ..addAll(_metadata) |
| 143 ..sort(AstNode.LEXICAL_ORDER); |
| 144 } |
| 145 |
| 146 /** |
| 147 * Return a holder of child entities that subclasses can add to. |
| 148 */ |
| 149 ChildEntities get _childEntities { |
| 150 ChildEntities result = new ChildEntities(); |
| 151 if (_commentIsBeforeAnnotations()) { |
| 152 result |
| 153 ..add(_comment) |
| 154 ..addAll(_metadata); |
| 155 } else { |
| 156 result.addAll(sortedCommentAndAnnotations); |
| 157 } |
| 158 return result; |
| 159 } |
| 160 |
| 161 @override |
| 162 void visitChildren(AstVisitor visitor) { |
| 163 if (_commentIsBeforeAnnotations()) { |
| 164 _comment?.accept(visitor); |
| 165 _metadata.accept(visitor); |
| 166 } else { |
| 167 List<AstNode> children = sortedCommentAndAnnotations; |
| 168 int length = children.length; |
| 169 for (int i = 0; i < length; i++) { |
| 170 children[i].accept(visitor); |
| 171 } |
| 172 } |
| 173 } |
| 174 |
| 175 /** |
| 176 * Return `true` if there are no annotations before the comment. Note that a |
| 177 * result of `true` does not imply that there is a comment, nor that there are |
| 178 * annotations associated with this node. |
| 179 */ |
| 180 bool _commentIsBeforeAnnotations() { |
| 181 if (_comment == null || _metadata.isEmpty) { |
| 182 return true; |
| 183 } |
| 184 Annotation firstAnnotation = _metadata[0]; |
| 185 return _comment.offset < firstAnnotation.offset; |
| 186 } |
| 187 } |
| 188 |
| 189 /** |
| 190 * An annotation that can be associated with an AST node. |
| 191 * |
| 192 * metadata ::= |
| 193 * annotation* |
| 194 * |
| 195 * annotation ::= |
| 196 * '@' [Identifier] ('.' [SimpleIdentifier])? [ArgumentList]? |
| 197 */ |
| 198 class AnnotationImpl extends AstNodeImpl implements Annotation { |
| 199 /** |
| 200 * The at sign that introduced the annotation. |
| 201 */ |
| 202 @override |
| 203 Token atSign; |
| 204 |
| 205 /** |
| 206 * The name of the class defining the constructor that is being invoked or the |
| 207 * name of the field that is being referenced. |
| 208 */ |
| 209 Identifier _name; |
| 210 |
| 211 /** |
| 212 * The period before the constructor name, or `null` if this annotation is not |
| 213 * the invocation of a named constructor. |
| 214 */ |
| 215 @override |
| 216 Token period; |
| 217 |
| 218 /** |
| 219 * The name of the constructor being invoked, or `null` if this annotation is |
| 220 * not the invocation of a named constructor. |
| 221 */ |
| 222 SimpleIdentifier _constructorName; |
| 223 |
| 224 /** |
| 225 * The arguments to the constructor being invoked, or `null` if this |
| 226 * annotation is not the invocation of a constructor. |
| 227 */ |
| 228 ArgumentList _arguments; |
| 229 |
| 230 /** |
| 231 * The element associated with this annotation, or `null` if the AST structure |
| 232 * has not been resolved or if this annotation could not be resolved. |
| 233 */ |
| 234 Element _element; |
| 235 |
| 236 /** |
| 237 * The element annotation representing this annotation in the element model. |
| 238 */ |
| 239 @override |
| 240 ElementAnnotation elementAnnotation; |
| 241 |
| 242 /** |
| 243 * Initialize a newly created annotation. Both the [period] and the |
| 244 * [constructorName] can be `null` if the annotation is not referencing a |
| 245 * named constructor. The [arguments] can be `null` if the annotation is not |
| 246 * referencing a constructor. |
| 247 */ |
| 248 AnnotationImpl(this.atSign, IdentifierImpl name, this.period, |
| 249 SimpleIdentifierImpl constructorName, ArgumentListImpl arguments) { |
| 250 _name = _becomeParentOf(name); |
| 251 _constructorName = _becomeParentOf(constructorName); |
| 252 _arguments = _becomeParentOf(arguments); |
| 253 } |
| 254 |
| 255 @override |
| 256 ArgumentList get arguments => _arguments; |
| 257 |
| 258 @override |
| 259 void set arguments(ArgumentList arguments) { |
| 260 _arguments = _becomeParentOf(arguments as AstNodeImpl); |
| 261 } |
| 262 |
| 263 @override |
| 264 Token get beginToken => atSign; |
| 265 |
| 266 @override |
| 267 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 268 ..add(atSign) |
| 269 ..add(_name) |
| 270 ..add(period) |
| 271 ..add(_constructorName) |
| 272 ..add(_arguments); |
| 273 |
| 274 @override |
| 275 SimpleIdentifier get constructorName => _constructorName; |
| 276 |
| 277 @override |
| 278 void set constructorName(SimpleIdentifier name) { |
| 279 _constructorName = _becomeParentOf(name as AstNodeImpl); |
| 280 } |
| 281 |
| 282 @override |
| 283 Element get element { |
| 284 if (_element != null) { |
| 285 return _element; |
| 286 } else if (_constructorName == null && _name != null) { |
| 287 return _name.staticElement; |
| 288 } |
| 289 return null; |
| 290 } |
| 291 |
| 292 @override |
| 293 void set element(Element element) { |
| 294 _element = element; |
| 295 } |
| 296 |
| 297 @override |
| 298 Token get endToken { |
| 299 if (_arguments != null) { |
| 300 return _arguments.endToken; |
| 301 } else if (_constructorName != null) { |
| 302 return _constructorName.endToken; |
| 303 } |
| 304 return _name.endToken; |
| 305 } |
| 306 |
| 307 @override |
| 308 Identifier get name => _name; |
| 309 |
| 310 @override |
| 311 void set name(Identifier name) { |
| 312 _name = _becomeParentOf(name as AstNodeImpl); |
| 313 } |
| 314 |
| 315 @override |
| 316 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 317 visitor.visitAnnotation(this); |
| 318 |
| 319 @override |
| 320 void visitChildren(AstVisitor visitor) { |
| 321 _name?.accept(visitor); |
| 322 _constructorName?.accept(visitor); |
| 323 _arguments?.accept(visitor); |
| 324 } |
| 325 } |
| 326 |
| 327 /** |
| 328 * A list of arguments in the invocation of an executable element (that is, a |
| 329 * function, method, or constructor). |
| 330 * |
| 331 * argumentList ::= |
| 332 * '(' arguments? ')' |
| 333 * |
| 334 * arguments ::= |
| 335 * [NamedExpression] (',' [NamedExpression])* |
| 336 * | [Expression] (',' [Expression])* (',' [NamedExpression])* |
| 337 */ |
| 338 class ArgumentListImpl extends AstNodeImpl implements ArgumentList { |
| 339 /** |
| 340 * The left parenthesis. |
| 341 */ |
| 342 @override |
| 343 Token leftParenthesis; |
| 344 |
| 345 /** |
| 346 * The expressions producing the values of the arguments. |
| 347 */ |
| 348 NodeList<Expression> _arguments; |
| 349 |
| 350 /** |
| 351 * The right parenthesis. |
| 352 */ |
| 353 @override |
| 354 Token rightParenthesis; |
| 355 |
| 356 /** |
| 357 * A list containing the elements representing the parameters corresponding to |
| 358 * each of the arguments in this list, or `null` if the AST has not been |
| 359 * resolved or if the function or method being invoked could not be determined |
| 360 * based on static type information. The list must be the same length as the |
| 361 * number of arguments, but can contain `null` entries if a given argument |
| 362 * does not correspond to a formal parameter. |
| 363 */ |
| 364 List<ParameterElement> _correspondingStaticParameters; |
| 365 |
| 366 /** |
| 367 * A list containing the elements representing the parameters corresponding to |
| 368 * each of the arguments in this list, or `null` if the AST has not been |
| 369 * resolved or if the function or method being invoked could not be determined |
| 370 * based on propagated type information. The list must be the same length as |
| 371 * the number of arguments, but can contain `null` entries if a given argument |
| 372 * does not correspond to a formal parameter. |
| 373 */ |
| 374 List<ParameterElement> _correspondingPropagatedParameters; |
| 375 |
| 376 /** |
| 377 * Initialize a newly created list of arguments. The list of [arguments] can |
| 378 * be `null` if there are no arguments. |
| 379 */ |
| 380 ArgumentListImpl( |
| 381 this.leftParenthesis, List<Expression> arguments, this.rightParenthesis) { |
| 382 _arguments = new NodeListImpl<Expression>(this, arguments); |
| 383 } |
| 384 |
| 385 @override |
| 386 NodeList<Expression> get arguments => _arguments; |
| 387 |
| 388 @override |
| 389 Token get beginToken => leftParenthesis; |
| 390 |
| 391 @override |
| 392 // TODO(paulberry): Add commas. |
| 393 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 394 ..add(leftParenthesis) |
| 395 ..addAll(_arguments) |
| 396 ..add(rightParenthesis); |
| 397 |
| 398 List<ParameterElement> get correspondingPropagatedParameters => |
| 399 _correspondingPropagatedParameters; |
| 400 |
| 401 @override |
| 402 void set correspondingPropagatedParameters( |
| 403 List<ParameterElement> parameters) { |
| 404 if (parameters != null && parameters.length != _arguments.length) { |
| 405 throw new ArgumentError( |
| 406 "Expected ${_arguments.length} parameters, not ${parameters.length}"); |
| 407 } |
| 408 _correspondingPropagatedParameters = parameters; |
| 409 } |
| 410 |
| 411 List<ParameterElement> get correspondingStaticParameters => |
| 412 _correspondingStaticParameters; |
| 413 |
| 414 @override |
| 415 void set correspondingStaticParameters(List<ParameterElement> parameters) { |
| 416 if (parameters != null && parameters.length != _arguments.length) { |
| 417 throw new ArgumentError( |
| 418 "Expected ${_arguments.length} parameters, not ${parameters.length}"); |
| 419 } |
| 420 _correspondingStaticParameters = parameters; |
| 421 } |
| 422 |
| 423 @override |
| 424 Token get endToken => rightParenthesis; |
| 425 |
| 426 @override |
| 427 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 428 visitor.visitArgumentList(this); |
| 429 |
| 430 @override |
| 431 void visitChildren(AstVisitor visitor) { |
| 432 _arguments.accept(visitor); |
| 433 } |
| 434 |
| 435 /** |
| 436 * If |
| 437 * * the given [expression] is a child of this list, |
| 438 * * the AST structure has been resolved, |
| 439 * * the function being invoked is known based on propagated type information, |
| 440 * and |
| 441 * * the expression corresponds to one of the parameters of the function being |
| 442 * invoked, |
| 443 * then return the parameter element representing the parameter to which the |
| 444 * value of the given expression will be bound. Otherwise, return `null`. |
| 445 */ |
| 446 ParameterElement _getPropagatedParameterElementFor(Expression expression) { |
| 447 if (_correspondingPropagatedParameters == null || |
| 448 _correspondingPropagatedParameters.length != _arguments.length) { |
| 449 // Either the AST structure has not been resolved, the invocation of which |
| 450 // this list is a part could not be resolved, or the argument list was |
| 451 // modified after the parameters were set. |
| 452 return null; |
| 453 } |
| 454 int index = _arguments.indexOf(expression); |
| 455 if (index < 0) { |
| 456 // The expression isn't a child of this node. |
| 457 return null; |
| 458 } |
| 459 return _correspondingPropagatedParameters[index]; |
| 460 } |
| 461 |
| 462 /** |
| 463 * If |
| 464 * * the given [expression] is a child of this list, |
| 465 * * the AST structure has been resolved, |
| 466 * * the function being invoked is known based on static type information, and |
| 467 * * the expression corresponds to one of the parameters of the function being |
| 468 * invoked, |
| 469 * then return the parameter element representing the parameter to which the |
| 470 * value of the given expression will be bound. Otherwise, return `null`. |
| 471 */ |
| 472 ParameterElement _getStaticParameterElementFor(Expression expression) { |
| 473 if (_correspondingStaticParameters == null || |
| 474 _correspondingStaticParameters.length != _arguments.length) { |
| 475 // Either the AST structure has not been resolved, the invocation of which |
| 476 // this list is a part could not be resolved, or the argument list was |
| 477 // modified after the parameters were set. |
| 478 return null; |
| 479 } |
| 480 int index = _arguments.indexOf(expression); |
| 481 if (index < 0) { |
| 482 // The expression isn't a child of this node. |
| 483 return null; |
| 484 } |
| 485 return _correspondingStaticParameters[index]; |
| 486 } |
| 487 } |
| 488 |
| 489 /** |
| 490 * An as expression. |
| 491 * |
| 492 * asExpression ::= |
| 493 * [Expression] 'as' [TypeName] |
| 494 */ |
| 495 class AsExpressionImpl extends ExpressionImpl implements AsExpression { |
| 496 /** |
| 497 * The expression used to compute the value being cast. |
| 498 */ |
| 499 Expression _expression; |
| 500 |
| 501 /** |
| 502 * The 'as' operator. |
| 503 */ |
| 504 @override |
| 505 Token asOperator; |
| 506 |
| 507 /** |
| 508 * The name of the type being cast to. |
| 509 */ |
| 510 TypeName _type; |
| 511 |
| 512 /** |
| 513 * Initialize a newly created as expression. |
| 514 */ |
| 515 AsExpressionImpl( |
| 516 ExpressionImpl expression, this.asOperator, TypeNameImpl type) { |
| 517 _expression = _becomeParentOf(expression); |
| 518 _type = _becomeParentOf(type); |
| 519 } |
| 520 |
| 521 @override |
| 522 Token get beginToken => _expression.beginToken; |
| 523 |
| 524 @override |
| 525 Iterable<SyntacticEntity> get childEntities => |
| 526 new ChildEntities()..add(_expression)..add(asOperator)..add(_type); |
| 527 |
| 528 @override |
| 529 Token get endToken => _type.endToken; |
| 530 |
| 531 @override |
| 532 Expression get expression => _expression; |
| 533 |
| 534 @override |
| 535 void set expression(Expression expression) { |
| 536 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 537 } |
| 538 |
| 539 @override |
| 540 int get precedence => 7; |
| 541 |
| 542 @override |
| 543 TypeName get type => _type; |
| 544 |
| 545 @override |
| 546 void set type(TypeName name) { |
| 547 _type = _becomeParentOf(name as AstNodeImpl); |
| 548 } |
| 549 |
| 550 @override |
| 551 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 552 visitor.visitAsExpression(this); |
| 553 |
| 554 @override |
| 555 void visitChildren(AstVisitor visitor) { |
| 556 _expression?.accept(visitor); |
| 557 _type?.accept(visitor); |
| 558 } |
| 559 } |
| 560 |
| 561 /** |
| 562 * An assert statement. |
| 563 * |
| 564 * assertStatement ::= |
| 565 * 'assert' '(' [Expression] ')' ';' |
| 566 */ |
| 567 class AssertStatementImpl extends StatementImpl implements AssertStatement { |
| 568 /** |
| 569 * The token representing the 'assert' keyword. |
| 570 */ |
| 571 @override |
| 572 Token assertKeyword; |
| 573 |
| 574 /** |
| 575 * The left parenthesis. |
| 576 */ |
| 577 @override |
| 578 Token leftParenthesis; |
| 579 |
| 580 /** |
| 581 * The condition that is being asserted to be `true`. |
| 582 */ |
| 583 Expression _condition; |
| 584 |
| 585 /** |
| 586 * The comma, if a message expression was supplied. Otherwise `null`. |
| 587 */ |
| 588 @override |
| 589 Token comma; |
| 590 |
| 591 /** |
| 592 * The message to report if the assertion fails. `null` if no message was |
| 593 * supplied. |
| 594 */ |
| 595 Expression _message; |
| 596 |
| 597 /** |
| 598 * The right parenthesis. |
| 599 */ |
| 600 @override |
| 601 Token rightParenthesis; |
| 602 |
| 603 /** |
| 604 * The semicolon terminating the statement. |
| 605 */ |
| 606 @override |
| 607 Token semicolon; |
| 608 |
| 609 /** |
| 610 * Initialize a newly created assert statement. |
| 611 */ |
| 612 AssertStatementImpl( |
| 613 this.assertKeyword, |
| 614 this.leftParenthesis, |
| 615 ExpressionImpl condition, |
| 616 this.comma, |
| 617 ExpressionImpl message, |
| 618 this.rightParenthesis, |
| 619 this.semicolon) { |
| 620 _condition = _becomeParentOf(condition); |
| 621 _message = _becomeParentOf(message); |
| 622 } |
| 623 |
| 624 @override |
| 625 Token get beginToken => assertKeyword; |
| 626 |
| 627 @override |
| 628 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 629 ..add(assertKeyword) |
| 630 ..add(leftParenthesis) |
| 631 ..add(_condition) |
| 632 ..add(comma) |
| 633 ..add(_message) |
| 634 ..add(rightParenthesis) |
| 635 ..add(semicolon); |
| 636 |
| 637 @override |
| 638 Expression get condition => _condition; |
| 639 |
| 640 @override |
| 641 void set condition(Expression condition) { |
| 642 _condition = _becomeParentOf(condition as AstNodeImpl); |
| 643 } |
| 644 |
| 645 @override |
| 646 Token get endToken => semicolon; |
| 647 |
| 648 @override |
| 649 Expression get message => _message; |
| 650 |
| 651 @override |
| 652 void set message(Expression expression) { |
| 653 _message = _becomeParentOf(expression as AstNodeImpl); |
| 654 } |
| 655 |
| 656 @override |
| 657 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 658 visitor.visitAssertStatement(this); |
| 659 |
| 660 @override |
| 661 void visitChildren(AstVisitor visitor) { |
| 662 _condition?.accept(visitor); |
| 663 message?.accept(visitor); |
| 664 } |
| 665 } |
| 666 |
| 667 /** |
| 668 * An assignment expression. |
| 669 * |
| 670 * assignmentExpression ::= |
| 671 * [Expression] operator [Expression] |
| 672 */ |
| 673 class AssignmentExpressionImpl extends ExpressionImpl |
| 674 implements AssignmentExpression { |
| 675 /** |
| 676 * The expression used to compute the left hand side. |
| 677 */ |
| 678 Expression _leftHandSide; |
| 679 |
| 680 /** |
| 681 * The assignment operator being applied. |
| 682 */ |
| 683 @override |
| 684 Token operator; |
| 685 |
| 686 /** |
| 687 * The expression used to compute the right hand side. |
| 688 */ |
| 689 Expression _rightHandSide; |
| 690 |
| 691 /** |
| 692 * The element associated with the operator based on the static type of the |
| 693 * left-hand-side, or `null` if the AST structure has not been resolved, if |
| 694 * the operator is not a compound operator, or if the operator could not be |
| 695 * resolved. |
| 696 */ |
| 697 @override |
| 698 MethodElement staticElement; |
| 699 |
| 700 /** |
| 701 * The element associated with the operator based on the propagated type of |
| 702 * the left-hand-side, or `null` if the AST structure has not been resolved, |
| 703 * if the operator is not a compound operator, or if the operator could not be |
| 704 * resolved. |
| 705 */ |
| 706 @override |
| 707 MethodElement propagatedElement; |
| 708 |
| 709 /** |
| 710 * Initialize a newly created assignment expression. |
| 711 */ |
| 712 AssignmentExpressionImpl(ExpressionImpl leftHandSide, this.operator, |
| 713 ExpressionImpl rightHandSide) { |
| 714 if (leftHandSide == null || rightHandSide == null) { |
| 715 String message; |
| 716 if (leftHandSide == null) { |
| 717 if (rightHandSide == null) { |
| 718 message = "Both the left-hand and right-hand sides are null"; |
| 719 } else { |
| 720 message = "The left-hand size is null"; |
| 721 } |
| 722 } else { |
| 723 message = "The right-hand size is null"; |
| 724 } |
| 725 AnalysisEngine.instance.logger.logError( |
| 726 message, new CaughtException(new AnalysisException(message), null)); |
| 727 } |
| 728 _leftHandSide = _becomeParentOf(leftHandSide); |
| 729 _rightHandSide = _becomeParentOf(rightHandSide); |
| 730 } |
| 731 |
| 732 @override |
| 733 Token get beginToken => _leftHandSide.beginToken; |
| 734 |
| 735 @override |
| 736 MethodElement get bestElement { |
| 737 MethodElement element = propagatedElement; |
| 738 if (element == null) { |
| 739 element = staticElement; |
| 740 } |
| 741 return element; |
| 742 } |
| 743 |
| 744 @override |
| 745 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 746 ..add(_leftHandSide) |
| 747 ..add(operator) |
| 748 ..add(_rightHandSide); |
| 749 |
| 750 @override |
| 751 Token get endToken => _rightHandSide.endToken; |
| 752 |
| 753 @override |
| 754 Expression get leftHandSide => _leftHandSide; |
| 755 |
| 756 @override |
| 757 void set leftHandSide(Expression expression) { |
| 758 _leftHandSide = _becomeParentOf(expression as AstNodeImpl); |
| 759 } |
| 760 |
| 761 @override |
| 762 int get precedence => 1; |
| 763 |
| 764 @override |
| 765 Expression get rightHandSide => _rightHandSide; |
| 766 |
| 767 @override |
| 768 void set rightHandSide(Expression expression) { |
| 769 _rightHandSide = _becomeParentOf(expression as AstNodeImpl); |
| 770 } |
| 771 |
| 772 /** |
| 773 * If the AST structure has been resolved, and the function being invoked is |
| 774 * known based on propagated type information, then return the parameter |
| 775 * element representing the parameter to which the value of the right operand |
| 776 * will be bound. Otherwise, return `null`. |
| 777 */ |
| 778 ParameterElement get _propagatedParameterElementForRightHandSide { |
| 779 ExecutableElement executableElement = null; |
| 780 if (propagatedElement != null) { |
| 781 executableElement = propagatedElement; |
| 782 } else { |
| 783 Expression left = _leftHandSide; |
| 784 if (left is Identifier) { |
| 785 Element leftElement = left.propagatedElement; |
| 786 if (leftElement is ExecutableElement) { |
| 787 executableElement = leftElement; |
| 788 } |
| 789 } else if (left is PropertyAccess) { |
| 790 Element leftElement = left.propertyName.propagatedElement; |
| 791 if (leftElement is ExecutableElement) { |
| 792 executableElement = leftElement; |
| 793 } |
| 794 } |
| 795 } |
| 796 if (executableElement == null) { |
| 797 return null; |
| 798 } |
| 799 List<ParameterElement> parameters = executableElement.parameters; |
| 800 if (parameters.length < 1) { |
| 801 return null; |
| 802 } |
| 803 return parameters[0]; |
| 804 } |
| 805 |
| 806 /** |
| 807 * If the AST structure has been resolved, and the function being invoked is |
| 808 * known based on static type information, then return the parameter element |
| 809 * representing the parameter to which the value of the right operand will be |
| 810 * bound. Otherwise, return `null`. |
| 811 */ |
| 812 ParameterElement get _staticParameterElementForRightHandSide { |
| 813 ExecutableElement executableElement = null; |
| 814 if (staticElement != null) { |
| 815 executableElement = staticElement; |
| 816 } else { |
| 817 Expression left = _leftHandSide; |
| 818 if (left is Identifier) { |
| 819 Element leftElement = left.staticElement; |
| 820 if (leftElement is ExecutableElement) { |
| 821 executableElement = leftElement; |
| 822 } |
| 823 } else if (left is PropertyAccess) { |
| 824 Element leftElement = left.propertyName.staticElement; |
| 825 if (leftElement is ExecutableElement) { |
| 826 executableElement = leftElement; |
| 827 } |
| 828 } |
| 829 } |
| 830 if (executableElement == null) { |
| 831 return null; |
| 832 } |
| 833 List<ParameterElement> parameters = executableElement.parameters; |
| 834 if (parameters.length < 1) { |
| 835 return null; |
| 836 } |
| 837 return parameters[0]; |
| 838 } |
| 839 |
| 840 @override |
| 841 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 842 visitor.visitAssignmentExpression(this); |
| 843 |
| 844 @override |
| 845 void visitChildren(AstVisitor visitor) { |
| 846 _leftHandSide?.accept(visitor); |
| 847 _rightHandSide?.accept(visitor); |
| 848 } |
| 849 } |
| 850 |
| 851 /** |
| 852 * A node in the AST structure for a Dart program. |
| 853 */ |
| 854 abstract class AstNodeImpl implements AstNode { |
| 855 /** |
| 856 * The parent of the node, or `null` if the node is the root of an AST |
| 857 * structure. |
| 858 */ |
| 859 AstNode _parent; |
| 860 |
| 861 /** |
| 862 * A table mapping the names of properties to their values, or `null` if this |
| 863 * node does not have any properties associated with it. |
| 864 */ |
| 865 Map<String, Object> _propertyMap; |
| 866 |
| 867 @override |
| 868 int get end => offset + length; |
| 869 |
| 870 @override |
| 871 bool get isSynthetic => false; |
| 872 |
| 873 @override |
| 874 int get length { |
| 875 Token beginToken = this.beginToken; |
| 876 Token endToken = this.endToken; |
| 877 if (beginToken == null || endToken == null) { |
| 878 return -1; |
| 879 } |
| 880 return endToken.offset + endToken.length - beginToken.offset; |
| 881 } |
| 882 |
| 883 @override |
| 884 int get offset { |
| 885 Token beginToken = this.beginToken; |
| 886 if (beginToken == null) { |
| 887 return -1; |
| 888 } |
| 889 return beginToken.offset; |
| 890 } |
| 891 |
| 892 @override |
| 893 AstNode get parent => _parent; |
| 894 |
| 895 @override |
| 896 AstNode get root { |
| 897 AstNode root = this; |
| 898 AstNode parent = this.parent; |
| 899 while (parent != null) { |
| 900 root = parent; |
| 901 parent = root.parent; |
| 902 } |
| 903 return root; |
| 904 } |
| 905 |
| 906 @override |
| 907 AstNode/*=E*/ getAncestor/*<E extends AstNode>*/( |
| 908 Predicate<AstNode> predicate) { |
| 909 // TODO(brianwilkerson) It is a bug that this method can return `this`. |
| 910 AstNode node = this; |
| 911 while (node != null && !predicate(node)) { |
| 912 node = node.parent; |
| 913 } |
| 914 return node as AstNode/*=E*/; |
| 915 } |
| 916 |
| 917 @override |
| 918 Object/*=E*/ getProperty/*<E>*/(String name) { |
| 919 if (_propertyMap == null) { |
| 920 return null; |
| 921 } |
| 922 return _propertyMap[name] as Object/*=E*/; |
| 923 } |
| 924 |
| 925 @override |
| 926 void setProperty(String name, Object value) { |
| 927 if (value == null) { |
| 928 if (_propertyMap != null) { |
| 929 _propertyMap.remove(name); |
| 930 if (_propertyMap.isEmpty) { |
| 931 _propertyMap = null; |
| 932 } |
| 933 } |
| 934 } else { |
| 935 if (_propertyMap == null) { |
| 936 _propertyMap = new HashMap<String, Object>(); |
| 937 } |
| 938 _propertyMap[name] = value; |
| 939 } |
| 940 } |
| 941 |
| 942 @override |
| 943 String toSource() { |
| 944 PrintStringWriter writer = new PrintStringWriter(); |
| 945 accept(new ToSourceVisitor(writer)); |
| 946 return writer.toString(); |
| 947 } |
| 948 |
| 949 @override |
| 950 String toString() => toSource(); |
| 951 |
| 952 /** |
| 953 * Make this node the parent of the given [child] node. Return the child node. |
| 954 */ |
| 955 AstNode _becomeParentOf(AstNodeImpl child) { |
| 956 if (child != null) { |
| 957 child._parent = this; |
| 958 } |
| 959 return child; |
| 960 } |
| 961 } |
| 962 |
| 963 /** |
| 964 * An await expression. |
| 965 * |
| 966 * awaitExpression ::= |
| 967 * 'await' [Expression] |
| 968 */ |
| 969 class AwaitExpressionImpl extends ExpressionImpl implements AwaitExpression { |
| 970 /** |
| 971 * The 'await' keyword. |
| 972 */ |
| 973 @override |
| 974 Token awaitKeyword; |
| 975 |
| 976 /** |
| 977 * The expression whose value is being waited on. |
| 978 */ |
| 979 Expression _expression; |
| 980 |
| 981 /** |
| 982 * Initialize a newly created await expression. |
| 983 */ |
| 984 AwaitExpressionImpl(this.awaitKeyword, ExpressionImpl expression) { |
| 985 _expression = _becomeParentOf(expression); |
| 986 } |
| 987 |
| 988 @override |
| 989 Token get beginToken { |
| 990 if (awaitKeyword != null) { |
| 991 return awaitKeyword; |
| 992 } |
| 993 return _expression.beginToken; |
| 994 } |
| 995 |
| 996 @override |
| 997 Iterable<SyntacticEntity> get childEntities => |
| 998 new ChildEntities()..add(awaitKeyword)..add(_expression); |
| 999 |
| 1000 @override |
| 1001 Token get endToken => _expression.endToken; |
| 1002 |
| 1003 @override |
| 1004 Expression get expression => _expression; |
| 1005 |
| 1006 @override |
| 1007 void set expression(Expression expression) { |
| 1008 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 1009 } |
| 1010 |
| 1011 @override |
| 1012 int get precedence => 0; |
| 1013 |
| 1014 @override |
| 1015 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1016 visitor.visitAwaitExpression(this); |
| 1017 |
| 1018 @override |
| 1019 void visitChildren(AstVisitor visitor) { |
| 1020 _expression?.accept(visitor); |
| 1021 } |
| 1022 } |
| 1023 |
| 1024 /** |
| 1025 * A binary (infix) expression. |
| 1026 * |
| 1027 * binaryExpression ::= |
| 1028 * [Expression] [Token] [Expression] |
| 1029 */ |
| 1030 class BinaryExpressionImpl extends ExpressionImpl implements BinaryExpression { |
| 1031 /** |
| 1032 * The expression used to compute the left operand. |
| 1033 */ |
| 1034 Expression _leftOperand; |
| 1035 |
| 1036 /** |
| 1037 * The binary operator being applied. |
| 1038 */ |
| 1039 @override |
| 1040 Token operator; |
| 1041 |
| 1042 /** |
| 1043 * The expression used to compute the right operand. |
| 1044 */ |
| 1045 Expression _rightOperand; |
| 1046 |
| 1047 /** |
| 1048 * The element associated with the operator based on the static type of the |
| 1049 * left operand, or `null` if the AST structure has not been resolved, if the |
| 1050 * operator is not user definable, or if the operator could not be resolved. |
| 1051 */ |
| 1052 @override |
| 1053 MethodElement staticElement; |
| 1054 |
| 1055 /** |
| 1056 * The element associated with the operator based on the propagated type of |
| 1057 * the left operand, or `null` if the AST structure has not been resolved, if |
| 1058 * the operator is not user definable, or if the operator could not be |
| 1059 * resolved. |
| 1060 */ |
| 1061 @override |
| 1062 MethodElement propagatedElement; |
| 1063 |
| 1064 /** |
| 1065 * Initialize a newly created binary expression. |
| 1066 */ |
| 1067 BinaryExpressionImpl( |
| 1068 ExpressionImpl leftOperand, this.operator, ExpressionImpl rightOperand) { |
| 1069 _leftOperand = _becomeParentOf(leftOperand); |
| 1070 _rightOperand = _becomeParentOf(rightOperand); |
| 1071 } |
| 1072 |
| 1073 @override |
| 1074 Token get beginToken => _leftOperand.beginToken; |
| 1075 |
| 1076 @override |
| 1077 MethodElement get bestElement { |
| 1078 MethodElement element = propagatedElement; |
| 1079 if (element == null) { |
| 1080 element = staticElement; |
| 1081 } |
| 1082 return element; |
| 1083 } |
| 1084 |
| 1085 @override |
| 1086 Iterable<SyntacticEntity> get childEntities => |
| 1087 new ChildEntities()..add(_leftOperand)..add(operator)..add(_rightOperand); |
| 1088 |
| 1089 @override |
| 1090 Token get endToken => _rightOperand.endToken; |
| 1091 |
| 1092 @override |
| 1093 Expression get leftOperand => _leftOperand; |
| 1094 |
| 1095 @override |
| 1096 void set leftOperand(Expression expression) { |
| 1097 _leftOperand = _becomeParentOf(expression as AstNodeImpl); |
| 1098 } |
| 1099 |
| 1100 @override |
| 1101 int get precedence => operator.type.precedence; |
| 1102 |
| 1103 @override |
| 1104 Expression get rightOperand => _rightOperand; |
| 1105 |
| 1106 @override |
| 1107 void set rightOperand(Expression expression) { |
| 1108 _rightOperand = _becomeParentOf(expression as AstNodeImpl); |
| 1109 } |
| 1110 |
| 1111 /** |
| 1112 * If the AST structure has been resolved, and the function being invoked is |
| 1113 * known based on propagated type information, then return the parameter |
| 1114 * element representing the parameter to which the value of the right operand |
| 1115 * will be bound. Otherwise, return `null`. |
| 1116 */ |
| 1117 ParameterElement get _propagatedParameterElementForRightOperand { |
| 1118 if (propagatedElement == null) { |
| 1119 return null; |
| 1120 } |
| 1121 List<ParameterElement> parameters = propagatedElement.parameters; |
| 1122 if (parameters.length < 1) { |
| 1123 return null; |
| 1124 } |
| 1125 return parameters[0]; |
| 1126 } |
| 1127 |
| 1128 /** |
| 1129 * If the AST structure has been resolved, and the function being invoked is |
| 1130 * known based on static type information, then return the parameter element |
| 1131 * representing the parameter to which the value of the right operand will be |
| 1132 * bound. Otherwise, return `null`. |
| 1133 */ |
| 1134 ParameterElement get _staticParameterElementForRightOperand { |
| 1135 if (staticElement == null) { |
| 1136 return null; |
| 1137 } |
| 1138 List<ParameterElement> parameters = staticElement.parameters; |
| 1139 if (parameters.length < 1) { |
| 1140 return null; |
| 1141 } |
| 1142 return parameters[0]; |
| 1143 } |
| 1144 |
| 1145 @override |
| 1146 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1147 visitor.visitBinaryExpression(this); |
| 1148 |
| 1149 @override |
| 1150 void visitChildren(AstVisitor visitor) { |
| 1151 _leftOperand?.accept(visitor); |
| 1152 _rightOperand?.accept(visitor); |
| 1153 } |
| 1154 } |
| 1155 |
| 1156 /** |
| 1157 * A function body that consists of a block of statements. |
| 1158 * |
| 1159 * blockFunctionBody ::= |
| 1160 * ('async' | 'async' '*' | 'sync' '*')? [Block] |
| 1161 */ |
| 1162 class BlockFunctionBodyImpl extends FunctionBodyImpl |
| 1163 implements BlockFunctionBody { |
| 1164 /** |
| 1165 * The token representing the 'async' or 'sync' keyword, or `null` if there is |
| 1166 * no such keyword. |
| 1167 */ |
| 1168 @override |
| 1169 Token keyword; |
| 1170 |
| 1171 /** |
| 1172 * The star optionally following the 'async' or 'sync' keyword, or `null` if |
| 1173 * there is wither no such keyword or no star. |
| 1174 */ |
| 1175 @override |
| 1176 Token star; |
| 1177 |
| 1178 /** |
| 1179 * The block representing the body of the function. |
| 1180 */ |
| 1181 Block _block; |
| 1182 |
| 1183 /** |
| 1184 * Initialize a newly created function body consisting of a block of |
| 1185 * statements. The [keyword] can be `null` if there is no keyword specified |
| 1186 * for the block. The [star] can be `null` if there is no star following the |
| 1187 * keyword (and must be `null` if there is no keyword). |
| 1188 */ |
| 1189 BlockFunctionBodyImpl(this.keyword, this.star, BlockImpl block) { |
| 1190 _block = _becomeParentOf(block); |
| 1191 } |
| 1192 |
| 1193 @override |
| 1194 Token get beginToken { |
| 1195 if (keyword != null) { |
| 1196 return keyword; |
| 1197 } |
| 1198 return _block.beginToken; |
| 1199 } |
| 1200 |
| 1201 @override |
| 1202 Block get block => _block; |
| 1203 |
| 1204 @override |
| 1205 void set block(Block block) { |
| 1206 _block = _becomeParentOf(block as AstNodeImpl); |
| 1207 } |
| 1208 |
| 1209 @override |
| 1210 Iterable<SyntacticEntity> get childEntities => |
| 1211 new ChildEntities()..add(keyword)..add(star)..add(_block); |
| 1212 |
| 1213 @override |
| 1214 Token get endToken => _block.endToken; |
| 1215 |
| 1216 @override |
| 1217 bool get isAsynchronous => keyword != null && keyword.lexeme == Parser.ASYNC; |
| 1218 |
| 1219 @override |
| 1220 bool get isGenerator => star != null; |
| 1221 |
| 1222 @override |
| 1223 bool get isSynchronous => keyword == null || keyword.lexeme != Parser.ASYNC; |
| 1224 |
| 1225 @override |
| 1226 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1227 visitor.visitBlockFunctionBody(this); |
| 1228 |
| 1229 @override |
| 1230 void visitChildren(AstVisitor visitor) { |
| 1231 _block?.accept(visitor); |
| 1232 } |
| 1233 } |
| 1234 |
| 1235 /** |
| 1236 * A sequence of statements. |
| 1237 * |
| 1238 * block ::= |
| 1239 * '{' statement* '}' |
| 1240 */ |
| 1241 class BlockImpl extends StatementImpl implements Block { |
| 1242 /** |
| 1243 * The left curly bracket. |
| 1244 */ |
| 1245 @override |
| 1246 Token leftBracket; |
| 1247 |
| 1248 /** |
| 1249 * The statements contained in the block. |
| 1250 */ |
| 1251 NodeList<Statement> _statements; |
| 1252 |
| 1253 /** |
| 1254 * The right curly bracket. |
| 1255 */ |
| 1256 @override |
| 1257 Token rightBracket; |
| 1258 |
| 1259 /** |
| 1260 * Initialize a newly created block of code. |
| 1261 */ |
| 1262 BlockImpl(this.leftBracket, List<Statement> statements, this.rightBracket) { |
| 1263 _statements = new NodeListImpl<Statement>(this, statements); |
| 1264 } |
| 1265 |
| 1266 @override |
| 1267 Token get beginToken => leftBracket; |
| 1268 |
| 1269 @override |
| 1270 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 1271 ..add(leftBracket) |
| 1272 ..addAll(_statements) |
| 1273 ..add(rightBracket); |
| 1274 |
| 1275 @override |
| 1276 Token get endToken => rightBracket; |
| 1277 |
| 1278 @override |
| 1279 NodeList<Statement> get statements => _statements; |
| 1280 |
| 1281 @override |
| 1282 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1283 visitor.visitBlock(this); |
| 1284 |
| 1285 @override |
| 1286 void visitChildren(AstVisitor visitor) { |
| 1287 _statements.accept(visitor); |
| 1288 } |
| 1289 } |
| 1290 |
| 1291 /** |
| 1292 * A boolean literal expression. |
| 1293 * |
| 1294 * booleanLiteral ::= |
| 1295 * 'false' | 'true' |
| 1296 */ |
| 1297 class BooleanLiteralImpl extends LiteralImpl implements BooleanLiteral { |
| 1298 /** |
| 1299 * The token representing the literal. |
| 1300 */ |
| 1301 @override |
| 1302 Token literal; |
| 1303 |
| 1304 /** |
| 1305 * The value of the literal. |
| 1306 */ |
| 1307 @override |
| 1308 bool value = false; |
| 1309 |
| 1310 /** |
| 1311 * Initialize a newly created boolean literal. |
| 1312 */ |
| 1313 BooleanLiteralImpl(this.literal, this.value); |
| 1314 |
| 1315 @override |
| 1316 Token get beginToken => literal; |
| 1317 |
| 1318 @override |
| 1319 Iterable<SyntacticEntity> get childEntities => |
| 1320 new ChildEntities()..add(literal); |
| 1321 |
| 1322 @override |
| 1323 Token get endToken => literal; |
| 1324 |
| 1325 @override |
| 1326 bool get isSynthetic => literal.isSynthetic; |
| 1327 |
| 1328 @override |
| 1329 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1330 visitor.visitBooleanLiteral(this); |
| 1331 |
| 1332 @override |
| 1333 void visitChildren(AstVisitor visitor) { |
| 1334 // There are no children to visit. |
| 1335 } |
| 1336 } |
| 1337 |
| 1338 /** |
| 1339 * A break statement. |
| 1340 * |
| 1341 * breakStatement ::= |
| 1342 * 'break' [SimpleIdentifier]? ';' |
| 1343 */ |
| 1344 class BreakStatementImpl extends StatementImpl implements BreakStatement { |
| 1345 /** |
| 1346 * The token representing the 'break' keyword. |
| 1347 */ |
| 1348 @override |
| 1349 Token breakKeyword; |
| 1350 |
| 1351 /** |
| 1352 * The label associated with the statement, or `null` if there is no label. |
| 1353 */ |
| 1354 SimpleIdentifier _label; |
| 1355 |
| 1356 /** |
| 1357 * The semicolon terminating the statement. |
| 1358 */ |
| 1359 @override |
| 1360 Token semicolon; |
| 1361 |
| 1362 /** |
| 1363 * The AstNode which this break statement is breaking from. This will be |
| 1364 * either a [Statement] (in the case of breaking out of a loop), a |
| 1365 * [SwitchMember] (in the case of a labeled break statement whose label |
| 1366 * matches a label on a switch case in an enclosing switch statement), or |
| 1367 * `null` if the AST has not yet been resolved or if the target could not be |
| 1368 * resolved. Note that if the source code has errors, the target might be |
| 1369 * invalid (e.g. trying to break to a switch case). |
| 1370 */ |
| 1371 @override |
| 1372 AstNode target; |
| 1373 |
| 1374 /** |
| 1375 * Initialize a newly created break statement. The [label] can be `null` if |
| 1376 * there is no label associated with the statement. |
| 1377 */ |
| 1378 BreakStatementImpl( |
| 1379 this.breakKeyword, SimpleIdentifierImpl label, this.semicolon) { |
| 1380 _label = _becomeParentOf(label); |
| 1381 } |
| 1382 |
| 1383 @override |
| 1384 Token get beginToken => breakKeyword; |
| 1385 |
| 1386 @override |
| 1387 Iterable<SyntacticEntity> get childEntities => |
| 1388 new ChildEntities()..add(breakKeyword)..add(_label)..add(semicolon); |
| 1389 |
| 1390 @override |
| 1391 Token get endToken => semicolon; |
| 1392 |
| 1393 @override |
| 1394 SimpleIdentifier get label => _label; |
| 1395 |
| 1396 @override |
| 1397 void set label(SimpleIdentifier identifier) { |
| 1398 _label = _becomeParentOf(identifier as AstNodeImpl); |
| 1399 } |
| 1400 |
| 1401 @override |
| 1402 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1403 visitor.visitBreakStatement(this); |
| 1404 |
| 1405 @override |
| 1406 void visitChildren(AstVisitor visitor) { |
| 1407 _label?.accept(visitor); |
| 1408 } |
| 1409 } |
| 1410 |
| 1411 /** |
| 1412 * A sequence of cascaded expressions: expressions that share a common target. |
| 1413 * There are three kinds of expressions that can be used in a cascade |
| 1414 * expression: [IndexExpression], [MethodInvocation] and [PropertyAccess]. |
| 1415 * |
| 1416 * cascadeExpression ::= |
| 1417 * [Expression] cascadeSection* |
| 1418 * |
| 1419 * cascadeSection ::= |
| 1420 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* |
| 1421 * (assignmentOperator expressionWithoutCascade)? |
| 1422 * |
| 1423 * cascadeSelector ::= |
| 1424 * '[ ' expression '] ' |
| 1425 * | identifier |
| 1426 */ |
| 1427 class CascadeExpressionImpl extends ExpressionImpl |
| 1428 implements CascadeExpression { |
| 1429 /** |
| 1430 * The target of the cascade sections. |
| 1431 */ |
| 1432 Expression _target; |
| 1433 |
| 1434 /** |
| 1435 * The cascade sections sharing the common target. |
| 1436 */ |
| 1437 NodeList<Expression> _cascadeSections; |
| 1438 |
| 1439 /** |
| 1440 * Initialize a newly created cascade expression. The list of |
| 1441 * [cascadeSections] must contain at least one element. |
| 1442 */ |
| 1443 CascadeExpressionImpl( |
| 1444 ExpressionImpl target, List<Expression> cascadeSections) { |
| 1445 _target = _becomeParentOf(target); |
| 1446 _cascadeSections = new NodeListImpl<Expression>(this, cascadeSections); |
| 1447 } |
| 1448 |
| 1449 @override |
| 1450 Token get beginToken => _target.beginToken; |
| 1451 |
| 1452 @override |
| 1453 NodeList<Expression> get cascadeSections => _cascadeSections; |
| 1454 |
| 1455 @override |
| 1456 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 1457 ..add(_target) |
| 1458 ..addAll(_cascadeSections); |
| 1459 |
| 1460 @override |
| 1461 Token get endToken => _cascadeSections.endToken; |
| 1462 |
| 1463 @override |
| 1464 int get precedence => 2; |
| 1465 |
| 1466 @override |
| 1467 Expression get target => _target; |
| 1468 |
| 1469 @override |
| 1470 void set target(Expression target) { |
| 1471 _target = _becomeParentOf(target as AstNodeImpl); |
| 1472 } |
| 1473 |
| 1474 @override |
| 1475 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1476 visitor.visitCascadeExpression(this); |
| 1477 |
| 1478 @override |
| 1479 void visitChildren(AstVisitor visitor) { |
| 1480 _target?.accept(visitor); |
| 1481 _cascadeSections.accept(visitor); |
| 1482 } |
| 1483 } |
| 1484 |
| 1485 /** |
| 1486 * A catch clause within a try statement. |
| 1487 * |
| 1488 * onPart ::= |
| 1489 * catchPart [Block] |
| 1490 * | 'on' type catchPart? [Block] |
| 1491 * |
| 1492 * catchPart ::= |
| 1493 * 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')' |
| 1494 */ |
| 1495 class CatchClauseImpl extends AstNodeImpl implements CatchClause { |
| 1496 /** |
| 1497 * The token representing the 'on' keyword, or `null` if there is no 'on' |
| 1498 * keyword. |
| 1499 */ |
| 1500 @override |
| 1501 Token onKeyword; |
| 1502 |
| 1503 /** |
| 1504 * The type of exceptions caught by this catch clause, or `null` if this catch |
| 1505 * clause catches every type of exception. |
| 1506 */ |
| 1507 TypeName _exceptionType; |
| 1508 |
| 1509 /** |
| 1510 * The token representing the 'catch' keyword, or `null` if there is no |
| 1511 * 'catch' keyword. |
| 1512 */ |
| 1513 @override |
| 1514 Token catchKeyword; |
| 1515 |
| 1516 /** |
| 1517 * The left parenthesis, or `null` if there is no 'catch' keyword. |
| 1518 */ |
| 1519 @override |
| 1520 Token leftParenthesis; |
| 1521 |
| 1522 /** |
| 1523 * The parameter whose value will be the exception that was thrown, or `null` |
| 1524 * if there is no 'catch' keyword. |
| 1525 */ |
| 1526 SimpleIdentifier _exceptionParameter; |
| 1527 |
| 1528 /** |
| 1529 * The comma separating the exception parameter from the stack trace |
| 1530 * parameter, or `null` if there is no stack trace parameter. |
| 1531 */ |
| 1532 @override |
| 1533 Token comma; |
| 1534 |
| 1535 /** |
| 1536 * The parameter whose value will be the stack trace associated with the |
| 1537 * exception, or `null` if there is no stack trace parameter. |
| 1538 */ |
| 1539 SimpleIdentifier _stackTraceParameter; |
| 1540 |
| 1541 /** |
| 1542 * The right parenthesis, or `null` if there is no 'catch' keyword. |
| 1543 */ |
| 1544 @override |
| 1545 Token rightParenthesis; |
| 1546 |
| 1547 /** |
| 1548 * The body of the catch block. |
| 1549 */ |
| 1550 Block _body; |
| 1551 |
| 1552 /** |
| 1553 * Initialize a newly created catch clause. The [onKeyword] and |
| 1554 * [exceptionType] can be `null` if the clause will catch all exceptions. The |
| 1555 * [comma] and [stackTraceParameter] can be `null` if the stack trace |
| 1556 * parameter is not defined. |
| 1557 */ |
| 1558 CatchClauseImpl( |
| 1559 this.onKeyword, |
| 1560 TypeNameImpl exceptionType, |
| 1561 this.catchKeyword, |
| 1562 this.leftParenthesis, |
| 1563 SimpleIdentifierImpl exceptionParameter, |
| 1564 this.comma, |
| 1565 SimpleIdentifierImpl stackTraceParameter, |
| 1566 this.rightParenthesis, |
| 1567 BlockImpl body) { |
| 1568 _exceptionType = _becomeParentOf(exceptionType); |
| 1569 _exceptionParameter = _becomeParentOf(exceptionParameter); |
| 1570 _stackTraceParameter = _becomeParentOf(stackTraceParameter); |
| 1571 _body = _becomeParentOf(body); |
| 1572 } |
| 1573 |
| 1574 @override |
| 1575 Token get beginToken { |
| 1576 if (onKeyword != null) { |
| 1577 return onKeyword; |
| 1578 } |
| 1579 return catchKeyword; |
| 1580 } |
| 1581 |
| 1582 @override |
| 1583 Block get body => _body; |
| 1584 |
| 1585 @override |
| 1586 void set body(Block block) { |
| 1587 _body = _becomeParentOf(block as AstNodeImpl); |
| 1588 } |
| 1589 |
| 1590 @override |
| 1591 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 1592 ..add(onKeyword) |
| 1593 ..add(_exceptionType) |
| 1594 ..add(catchKeyword) |
| 1595 ..add(leftParenthesis) |
| 1596 ..add(_exceptionParameter) |
| 1597 ..add(comma) |
| 1598 ..add(_stackTraceParameter) |
| 1599 ..add(rightParenthesis) |
| 1600 ..add(_body); |
| 1601 |
| 1602 @override |
| 1603 Token get endToken => _body.endToken; |
| 1604 |
| 1605 @override |
| 1606 SimpleIdentifier get exceptionParameter => _exceptionParameter; |
| 1607 |
| 1608 @override |
| 1609 void set exceptionParameter(SimpleIdentifier parameter) { |
| 1610 _exceptionParameter = _becomeParentOf(parameter as AstNodeImpl); |
| 1611 } |
| 1612 |
| 1613 @override |
| 1614 TypeName get exceptionType => _exceptionType; |
| 1615 |
| 1616 @override |
| 1617 void set exceptionType(TypeName exceptionType) { |
| 1618 _exceptionType = _becomeParentOf(exceptionType as AstNodeImpl); |
| 1619 } |
| 1620 |
| 1621 @override |
| 1622 SimpleIdentifier get stackTraceParameter => _stackTraceParameter; |
| 1623 |
| 1624 @override |
| 1625 void set stackTraceParameter(SimpleIdentifier parameter) { |
| 1626 _stackTraceParameter = _becomeParentOf(parameter as AstNodeImpl); |
| 1627 } |
| 1628 |
| 1629 @override |
| 1630 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1631 visitor.visitCatchClause(this); |
| 1632 |
| 1633 @override |
| 1634 void visitChildren(AstVisitor visitor) { |
| 1635 _exceptionType?.accept(visitor); |
| 1636 _exceptionParameter?.accept(visitor); |
| 1637 _stackTraceParameter?.accept(visitor); |
| 1638 _body?.accept(visitor); |
| 1639 } |
| 1640 } |
| 1641 |
| 1642 /** |
| 1643 * Helper class to allow iteration of child entities of an AST node. |
| 1644 */ |
| 1645 class ChildEntities extends Object |
| 1646 with IterableMixin<SyntacticEntity> |
| 1647 implements Iterable<SyntacticEntity> { |
| 1648 /** |
| 1649 * The list of child entities to be iterated over. |
| 1650 */ |
| 1651 List<SyntacticEntity> _entities = []; |
| 1652 |
| 1653 @override |
| 1654 Iterator<SyntacticEntity> get iterator => _entities.iterator; |
| 1655 |
| 1656 /** |
| 1657 * Add an AST node or token as the next child entity, if it is not null. |
| 1658 */ |
| 1659 void add(SyntacticEntity entity) { |
| 1660 if (entity != null) { |
| 1661 _entities.add(entity); |
| 1662 } |
| 1663 } |
| 1664 |
| 1665 /** |
| 1666 * Add the given items as the next child entities, if [items] is not null. |
| 1667 */ |
| 1668 void addAll(Iterable<SyntacticEntity> items) { |
| 1669 if (items != null) { |
| 1670 _entities.addAll(items); |
| 1671 } |
| 1672 } |
| 1673 } |
| 1674 |
| 1675 /** |
| 1676 * The declaration of a class. |
| 1677 * |
| 1678 * classDeclaration ::= |
| 1679 * 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]? |
| 1680 * ([ExtendsClause] [WithClause]?)? |
| 1681 * [ImplementsClause]? |
| 1682 * '{' [ClassMember]* '}' |
| 1683 */ |
| 1684 class ClassDeclarationImpl extends NamedCompilationUnitMemberImpl |
| 1685 implements ClassDeclaration { |
| 1686 /** |
| 1687 * The 'abstract' keyword, or `null` if the keyword was absent. |
| 1688 */ |
| 1689 @override |
| 1690 Token abstractKeyword; |
| 1691 |
| 1692 /** |
| 1693 * The token representing the 'class' keyword. |
| 1694 */ |
| 1695 @override |
| 1696 Token classKeyword; |
| 1697 |
| 1698 /** |
| 1699 * The type parameters for the class, or `null` if the class does not have any |
| 1700 * type parameters. |
| 1701 */ |
| 1702 TypeParameterList _typeParameters; |
| 1703 |
| 1704 /** |
| 1705 * The extends clause for the class, or `null` if the class does not extend |
| 1706 * any other class. |
| 1707 */ |
| 1708 ExtendsClause _extendsClause; |
| 1709 |
| 1710 /** |
| 1711 * The with clause for the class, or `null` if the class does not have a with |
| 1712 * clause. |
| 1713 */ |
| 1714 WithClause _withClause; |
| 1715 |
| 1716 /** |
| 1717 * The implements clause for the class, or `null` if the class does not |
| 1718 * implement any interfaces. |
| 1719 */ |
| 1720 ImplementsClause _implementsClause; |
| 1721 |
| 1722 /** |
| 1723 * The native clause for the class, or `null` if the class does not have a |
| 1724 * native clause. |
| 1725 */ |
| 1726 NativeClause _nativeClause; |
| 1727 |
| 1728 /** |
| 1729 * The left curly bracket. |
| 1730 */ |
| 1731 @override |
| 1732 Token leftBracket; |
| 1733 |
| 1734 /** |
| 1735 * The members defined by the class. |
| 1736 */ |
| 1737 NodeList<ClassMember> _members; |
| 1738 |
| 1739 /** |
| 1740 * The right curly bracket. |
| 1741 */ |
| 1742 @override |
| 1743 Token rightBracket; |
| 1744 |
| 1745 /** |
| 1746 * Initialize a newly created class declaration. Either or both of the |
| 1747 * [comment] and [metadata] can be `null` if the class does not have the |
| 1748 * corresponding attribute. The [abstractKeyword] can be `null` if the class |
| 1749 * is not abstract. The [typeParameters] can be `null` if the class does not |
| 1750 * have any type parameters. Any or all of the [extendsClause], [withClause], |
| 1751 * and [implementsClause] can be `null` if the class does not have the |
| 1752 * corresponding clause. The list of [members] can be `null` if the class does |
| 1753 * not have any members. |
| 1754 */ |
| 1755 ClassDeclarationImpl( |
| 1756 Comment comment, |
| 1757 List<Annotation> metadata, |
| 1758 this.abstractKeyword, |
| 1759 this.classKeyword, |
| 1760 SimpleIdentifierImpl name, |
| 1761 TypeParameterListImpl typeParameters, |
| 1762 ExtendsClauseImpl extendsClause, |
| 1763 WithClauseImpl withClause, |
| 1764 ImplementsClauseImpl implementsClause, |
| 1765 this.leftBracket, |
| 1766 List<ClassMember> members, |
| 1767 this.rightBracket) |
| 1768 : super(comment, metadata, name) { |
| 1769 _typeParameters = _becomeParentOf(typeParameters); |
| 1770 _extendsClause = _becomeParentOf(extendsClause); |
| 1771 _withClause = _becomeParentOf(withClause); |
| 1772 _implementsClause = _becomeParentOf(implementsClause); |
| 1773 _members = new NodeListImpl<ClassMember>(this, members); |
| 1774 } |
| 1775 |
| 1776 @override |
| 1777 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 1778 ..add(abstractKeyword) |
| 1779 ..add(classKeyword) |
| 1780 ..add(_name) |
| 1781 ..add(_typeParameters) |
| 1782 ..add(_extendsClause) |
| 1783 ..add(_withClause) |
| 1784 ..add(_implementsClause) |
| 1785 ..add(_nativeClause) |
| 1786 ..add(leftBracket) |
| 1787 ..addAll(members) |
| 1788 ..add(rightBracket); |
| 1789 |
| 1790 @override |
| 1791 ClassElement get element => _name?.staticElement as ClassElement; |
| 1792 |
| 1793 @override |
| 1794 Token get endToken => rightBracket; |
| 1795 |
| 1796 @override |
| 1797 ExtendsClause get extendsClause => _extendsClause; |
| 1798 |
| 1799 @override |
| 1800 void set extendsClause(ExtendsClause extendsClause) { |
| 1801 _extendsClause = _becomeParentOf(extendsClause as AstNodeImpl); |
| 1802 } |
| 1803 |
| 1804 @override |
| 1805 Token get firstTokenAfterCommentAndMetadata { |
| 1806 if (abstractKeyword != null) { |
| 1807 return abstractKeyword; |
| 1808 } |
| 1809 return classKeyword; |
| 1810 } |
| 1811 |
| 1812 @override |
| 1813 ImplementsClause get implementsClause => _implementsClause; |
| 1814 |
| 1815 @override |
| 1816 void set implementsClause(ImplementsClause implementsClause) { |
| 1817 _implementsClause = _becomeParentOf(implementsClause as AstNodeImpl); |
| 1818 } |
| 1819 |
| 1820 @override |
| 1821 bool get isAbstract => abstractKeyword != null; |
| 1822 |
| 1823 @override |
| 1824 NodeList<ClassMember> get members => _members; |
| 1825 |
| 1826 @override |
| 1827 NativeClause get nativeClause => _nativeClause; |
| 1828 |
| 1829 @override |
| 1830 void set nativeClause(NativeClause nativeClause) { |
| 1831 _nativeClause = _becomeParentOf(nativeClause as AstNodeImpl); |
| 1832 } |
| 1833 |
| 1834 @override |
| 1835 TypeParameterList get typeParameters => _typeParameters; |
| 1836 |
| 1837 @override |
| 1838 void set typeParameters(TypeParameterList typeParameters) { |
| 1839 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 1840 } |
| 1841 |
| 1842 @override |
| 1843 WithClause get withClause => _withClause; |
| 1844 |
| 1845 @override |
| 1846 void set withClause(WithClause withClause) { |
| 1847 _withClause = _becomeParentOf(withClause as AstNodeImpl); |
| 1848 } |
| 1849 |
| 1850 @override |
| 1851 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1852 visitor.visitClassDeclaration(this); |
| 1853 |
| 1854 @override |
| 1855 ConstructorDeclaration getConstructor(String name) { |
| 1856 int length = _members.length; |
| 1857 for (int i = 0; i < length; i++) { |
| 1858 ClassMember classMember = _members[i]; |
| 1859 if (classMember is ConstructorDeclaration) { |
| 1860 ConstructorDeclaration constructor = classMember; |
| 1861 SimpleIdentifier constructorName = constructor.name; |
| 1862 if (name == null && constructorName == null) { |
| 1863 return constructor; |
| 1864 } |
| 1865 if (constructorName != null && constructorName.name == name) { |
| 1866 return constructor; |
| 1867 } |
| 1868 } |
| 1869 } |
| 1870 return null; |
| 1871 } |
| 1872 |
| 1873 @override |
| 1874 VariableDeclaration getField(String name) { |
| 1875 int memberLength = _members.length; |
| 1876 for (int i = 0; i < memberLength; i++) { |
| 1877 ClassMember classMember = _members[i]; |
| 1878 if (classMember is FieldDeclaration) { |
| 1879 FieldDeclaration fieldDeclaration = classMember; |
| 1880 NodeList<VariableDeclaration> fields = |
| 1881 fieldDeclaration.fields.variables; |
| 1882 int fieldLength = fields.length; |
| 1883 for (int i = 0; i < fieldLength; i++) { |
| 1884 VariableDeclaration field = fields[i]; |
| 1885 SimpleIdentifier fieldName = field.name; |
| 1886 if (fieldName != null && name == fieldName.name) { |
| 1887 return field; |
| 1888 } |
| 1889 } |
| 1890 } |
| 1891 } |
| 1892 return null; |
| 1893 } |
| 1894 |
| 1895 @override |
| 1896 MethodDeclaration getMethod(String name) { |
| 1897 int length = _members.length; |
| 1898 for (int i = 0; i < length; i++) { |
| 1899 ClassMember classMember = _members[i]; |
| 1900 if (classMember is MethodDeclaration) { |
| 1901 MethodDeclaration method = classMember; |
| 1902 SimpleIdentifier methodName = method.name; |
| 1903 if (methodName != null && name == methodName.name) { |
| 1904 return method; |
| 1905 } |
| 1906 } |
| 1907 } |
| 1908 return null; |
| 1909 } |
| 1910 |
| 1911 @override |
| 1912 void visitChildren(AstVisitor visitor) { |
| 1913 super.visitChildren(visitor); |
| 1914 _name?.accept(visitor); |
| 1915 _typeParameters?.accept(visitor); |
| 1916 _extendsClause?.accept(visitor); |
| 1917 _withClause?.accept(visitor); |
| 1918 _implementsClause?.accept(visitor); |
| 1919 _nativeClause?.accept(visitor); |
| 1920 members.accept(visitor); |
| 1921 } |
| 1922 } |
| 1923 |
| 1924 /** |
| 1925 * A node that declares a name within the scope of a class. |
| 1926 */ |
| 1927 abstract class ClassMemberImpl extends DeclarationImpl implements ClassMember { |
| 1928 /** |
| 1929 * Initialize a newly created member of a class. Either or both of the |
| 1930 * [comment] and [metadata] can be `null` if the member does not have the |
| 1931 * corresponding attribute. |
| 1932 */ |
| 1933 ClassMemberImpl(Comment comment, List<Annotation> metadata) |
| 1934 : super(comment, metadata); |
| 1935 } |
| 1936 |
| 1937 /** |
| 1938 * A class type alias. |
| 1939 * |
| 1940 * classTypeAlias ::= |
| 1941 * [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplicati
on |
| 1942 * |
| 1943 * mixinApplication ::= |
| 1944 * [TypeName] [WithClause] [ImplementsClause]? ';' |
| 1945 */ |
| 1946 class ClassTypeAliasImpl extends TypeAliasImpl implements ClassTypeAlias { |
| 1947 /** |
| 1948 * The type parameters for the class, or `null` if the class does not have any |
| 1949 * type parameters. |
| 1950 */ |
| 1951 TypeParameterList _typeParameters; |
| 1952 |
| 1953 /** |
| 1954 * The token for the '=' separating the name from the definition. |
| 1955 */ |
| 1956 @override |
| 1957 Token equals; |
| 1958 |
| 1959 /** |
| 1960 * The token for the 'abstract' keyword, or `null` if this is not defining an |
| 1961 * abstract class. |
| 1962 */ |
| 1963 @override |
| 1964 Token abstractKeyword; |
| 1965 |
| 1966 /** |
| 1967 * The name of the superclass of the class being declared. |
| 1968 */ |
| 1969 TypeName _superclass; |
| 1970 |
| 1971 /** |
| 1972 * The with clause for this class. |
| 1973 */ |
| 1974 WithClause _withClause; |
| 1975 |
| 1976 /** |
| 1977 * The implements clause for this class, or `null` if there is no implements |
| 1978 * clause. |
| 1979 */ |
| 1980 ImplementsClause _implementsClause; |
| 1981 |
| 1982 /** |
| 1983 * Initialize a newly created class type alias. Either or both of the |
| 1984 * [comment] and [metadata] can be `null` if the class type alias does not |
| 1985 * have the corresponding attribute. The [typeParameters] can be `null` if the |
| 1986 * class does not have any type parameters. The [abstractKeyword] can be |
| 1987 * `null` if the class is not abstract. The [implementsClause] can be `null` |
| 1988 * if the class does not implement any interfaces. |
| 1989 */ |
| 1990 ClassTypeAliasImpl( |
| 1991 CommentImpl comment, |
| 1992 List<Annotation> metadata, |
| 1993 Token keyword, |
| 1994 SimpleIdentifierImpl name, |
| 1995 TypeParameterListImpl typeParameters, |
| 1996 this.equals, |
| 1997 this.abstractKeyword, |
| 1998 TypeNameImpl superclass, |
| 1999 WithClauseImpl withClause, |
| 2000 ImplementsClauseImpl implementsClause, |
| 2001 Token semicolon) |
| 2002 : super(comment, metadata, keyword, name, semicolon) { |
| 2003 _typeParameters = _becomeParentOf(typeParameters); |
| 2004 _superclass = _becomeParentOf(superclass); |
| 2005 _withClause = _becomeParentOf(withClause); |
| 2006 _implementsClause = _becomeParentOf(implementsClause); |
| 2007 } |
| 2008 |
| 2009 @override |
| 2010 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 2011 ..add(typedefKeyword) |
| 2012 ..add(_name) |
| 2013 ..add(_typeParameters) |
| 2014 ..add(equals) |
| 2015 ..add(abstractKeyword) |
| 2016 ..add(_superclass) |
| 2017 ..add(_withClause) |
| 2018 ..add(_implementsClause) |
| 2019 ..add(semicolon); |
| 2020 |
| 2021 @override |
| 2022 ClassElement get element => _name?.staticElement as ClassElement; |
| 2023 |
| 2024 @override |
| 2025 Token get firstTokenAfterCommentAndMetadata { |
| 2026 if (abstractKeyword != null) { |
| 2027 return abstractKeyword; |
| 2028 } |
| 2029 return typedefKeyword; |
| 2030 } |
| 2031 |
| 2032 @override |
| 2033 ImplementsClause get implementsClause => _implementsClause; |
| 2034 |
| 2035 @override |
| 2036 void set implementsClause(ImplementsClause implementsClause) { |
| 2037 _implementsClause = _becomeParentOf(implementsClause as AstNodeImpl); |
| 2038 } |
| 2039 |
| 2040 @override |
| 2041 bool get isAbstract => abstractKeyword != null; |
| 2042 |
| 2043 @override |
| 2044 TypeName get superclass => _superclass; |
| 2045 |
| 2046 @override |
| 2047 void set superclass(TypeName superclass) { |
| 2048 _superclass = _becomeParentOf(superclass as AstNodeImpl); |
| 2049 } |
| 2050 |
| 2051 @override |
| 2052 TypeParameterList get typeParameters => _typeParameters; |
| 2053 |
| 2054 @override |
| 2055 void set typeParameters(TypeParameterList typeParameters) { |
| 2056 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 2057 } |
| 2058 |
| 2059 @override |
| 2060 WithClause get withClause => _withClause; |
| 2061 |
| 2062 @override |
| 2063 void set withClause(WithClause withClause) { |
| 2064 _withClause = _becomeParentOf(withClause as AstNodeImpl); |
| 2065 } |
| 2066 |
| 2067 @override |
| 2068 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2069 visitor.visitClassTypeAlias(this); |
| 2070 |
| 2071 @override |
| 2072 void visitChildren(AstVisitor visitor) { |
| 2073 super.visitChildren(visitor); |
| 2074 _name?.accept(visitor); |
| 2075 _typeParameters?.accept(visitor); |
| 2076 _superclass?.accept(visitor); |
| 2077 _withClause?.accept(visitor); |
| 2078 _implementsClause?.accept(visitor); |
| 2079 } |
| 2080 } |
| 2081 |
| 2082 /** |
| 2083 * A combinator associated with an import or export directive. |
| 2084 * |
| 2085 * combinator ::= |
| 2086 * [HideCombinator] |
| 2087 * | [ShowCombinator] |
| 2088 */ |
| 2089 abstract class CombinatorImpl extends AstNodeImpl implements Combinator { |
| 2090 /** |
| 2091 * The 'hide' or 'show' keyword specifying what kind of processing is to be |
| 2092 * done on the names. |
| 2093 */ |
| 2094 @override |
| 2095 Token keyword; |
| 2096 |
| 2097 /** |
| 2098 * Initialize a newly created combinator. |
| 2099 */ |
| 2100 CombinatorImpl(this.keyword); |
| 2101 |
| 2102 @override |
| 2103 Token get beginToken => keyword; |
| 2104 } |
| 2105 |
| 2106 /** |
| 2107 * A comment within the source code. |
| 2108 * |
| 2109 * comment ::= |
| 2110 * endOfLineComment |
| 2111 * | blockComment |
| 2112 * | documentationComment |
| 2113 * |
| 2114 * endOfLineComment ::= |
| 2115 * '//' (CHARACTER - EOL)* EOL |
| 2116 * |
| 2117 * blockComment ::= |
| 2118 * '/ *' CHARACTER* '*/' |
| 2119 * |
| 2120 * documentationComment ::= |
| 2121 * '/ **' (CHARACTER | [CommentReference])* '*/' |
| 2122 * | ('///' (CHARACTER - EOL)* EOL)+ |
| 2123 */ |
| 2124 class CommentImpl extends AstNodeImpl implements Comment { |
| 2125 /** |
| 2126 * The tokens representing the comment. |
| 2127 */ |
| 2128 @override |
| 2129 final List<Token> tokens; |
| 2130 |
| 2131 /** |
| 2132 * The type of the comment. |
| 2133 */ |
| 2134 final CommentType _type; |
| 2135 |
| 2136 /** |
| 2137 * The references embedded within the documentation comment. This list will be |
| 2138 * empty unless this is a documentation comment that has references embedded |
| 2139 * within it. |
| 2140 */ |
| 2141 NodeList<CommentReference> _references; |
| 2142 |
| 2143 /** |
| 2144 * Initialize a newly created comment. The list of [tokens] must contain at |
| 2145 * least one token. The [_type] is the type of the comment. The list of |
| 2146 * [references] can be empty if the comment does not contain any embedded |
| 2147 * references. |
| 2148 */ |
| 2149 CommentImpl(this.tokens, this._type, List<CommentReference> references) { |
| 2150 _references = new NodeListImpl<CommentReference>(this, references); |
| 2151 } |
| 2152 |
| 2153 @override |
| 2154 Token get beginToken => tokens[0]; |
| 2155 |
| 2156 @override |
| 2157 Iterable<SyntacticEntity> get childEntities => |
| 2158 new ChildEntities()..addAll(tokens); |
| 2159 |
| 2160 @override |
| 2161 Token get endToken => tokens[tokens.length - 1]; |
| 2162 |
| 2163 @override |
| 2164 bool get isBlock => _type == CommentType.BLOCK; |
| 2165 |
| 2166 @override |
| 2167 bool get isDocumentation => _type == CommentType.DOCUMENTATION; |
| 2168 |
| 2169 @override |
| 2170 bool get isEndOfLine => _type == CommentType.END_OF_LINE; |
| 2171 |
| 2172 @override |
| 2173 NodeList<CommentReference> get references => _references; |
| 2174 |
| 2175 @override |
| 2176 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2177 visitor.visitComment(this); |
| 2178 |
| 2179 @override |
| 2180 void visitChildren(AstVisitor visitor) { |
| 2181 _references.accept(visitor); |
| 2182 } |
| 2183 |
| 2184 /** |
| 2185 * Create a block comment consisting of the given [tokens]. |
| 2186 */ |
| 2187 static Comment createBlockComment(List<Token> tokens) => |
| 2188 new CommentImpl(tokens, CommentType.BLOCK, null); |
| 2189 |
| 2190 /** |
| 2191 * Create a documentation comment consisting of the given [tokens]. |
| 2192 */ |
| 2193 static Comment createDocumentationComment(List<Token> tokens) => |
| 2194 new CommentImpl( |
| 2195 tokens, CommentType.DOCUMENTATION, new List<CommentReference>()); |
| 2196 |
| 2197 /** |
| 2198 * Create a documentation comment consisting of the given [tokens] and having |
| 2199 * the given [references] embedded within it. |
| 2200 */ |
| 2201 static Comment createDocumentationCommentWithReferences( |
| 2202 List<Token> tokens, List<CommentReference> references) => |
| 2203 new CommentImpl(tokens, CommentType.DOCUMENTATION, references); |
| 2204 |
| 2205 /** |
| 2206 * Create an end-of-line comment consisting of the given [tokens]. |
| 2207 */ |
| 2208 static Comment createEndOfLineComment(List<Token> tokens) => |
| 2209 new CommentImpl(tokens, CommentType.END_OF_LINE, null); |
| 2210 } |
| 2211 |
| 2212 /** |
| 2213 * A reference to a Dart element that is found within a documentation comment. |
| 2214 * |
| 2215 * commentReference ::= |
| 2216 * '[' 'new'? [Identifier] ']' |
| 2217 */ |
| 2218 class CommentReferenceImpl extends AstNodeImpl implements CommentReference { |
| 2219 /** |
| 2220 * The token representing the 'new' keyword, or `null` if there was no 'new' |
| 2221 * keyword. |
| 2222 */ |
| 2223 @override |
| 2224 Token newKeyword; |
| 2225 |
| 2226 /** |
| 2227 * The identifier being referenced. |
| 2228 */ |
| 2229 Identifier _identifier; |
| 2230 |
| 2231 /** |
| 2232 * Initialize a newly created reference to a Dart element. The [newKeyword] |
| 2233 * can be `null` if the reference is not to a constructor. |
| 2234 */ |
| 2235 CommentReferenceImpl(this.newKeyword, IdentifierImpl identifier) { |
| 2236 _identifier = _becomeParentOf(identifier); |
| 2237 } |
| 2238 |
| 2239 @override |
| 2240 Token get beginToken => _identifier.beginToken; |
| 2241 |
| 2242 @override |
| 2243 Iterable<SyntacticEntity> get childEntities => |
| 2244 new ChildEntities()..add(newKeyword)..add(_identifier); |
| 2245 |
| 2246 @override |
| 2247 Token get endToken => _identifier.endToken; |
| 2248 |
| 2249 @override |
| 2250 Identifier get identifier => _identifier; |
| 2251 |
| 2252 @override |
| 2253 void set identifier(Identifier identifier) { |
| 2254 _identifier = _becomeParentOf(identifier as AstNodeImpl); |
| 2255 } |
| 2256 |
| 2257 @override |
| 2258 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2259 visitor.visitCommentReference(this); |
| 2260 |
| 2261 @override |
| 2262 void visitChildren(AstVisitor visitor) { |
| 2263 _identifier?.accept(visitor); |
| 2264 } |
| 2265 } |
| 2266 |
| 2267 /** |
| 2268 * The possible types of comments that are recognized by the parser. |
| 2269 */ |
| 2270 class CommentType { |
| 2271 /** |
| 2272 * A block comment. |
| 2273 */ |
| 2274 static const CommentType BLOCK = const CommentType('BLOCK'); |
| 2275 |
| 2276 /** |
| 2277 * A documentation comment. |
| 2278 */ |
| 2279 static const CommentType DOCUMENTATION = const CommentType('DOCUMENTATION'); |
| 2280 |
| 2281 /** |
| 2282 * An end-of-line comment. |
| 2283 */ |
| 2284 static const CommentType END_OF_LINE = const CommentType('END_OF_LINE'); |
| 2285 |
| 2286 /** |
| 2287 * The name of the comment type. |
| 2288 */ |
| 2289 final String name; |
| 2290 |
| 2291 /** |
| 2292 * Initialize a newly created comment type to have the given [name]. |
| 2293 */ |
| 2294 const CommentType(this.name); |
| 2295 |
| 2296 @override |
| 2297 String toString() => name; |
| 2298 } |
| 2299 |
| 2300 /** |
| 2301 * A compilation unit. |
| 2302 * |
| 2303 * While the grammar restricts the order of the directives and declarations |
| 2304 * within a compilation unit, this class does not enforce those restrictions. |
| 2305 * In particular, the children of a compilation unit will be visited in lexical |
| 2306 * order even if lexical order does not conform to the restrictions of the |
| 2307 * grammar. |
| 2308 * |
| 2309 * compilationUnit ::= |
| 2310 * directives declarations |
| 2311 * |
| 2312 * directives ::= |
| 2313 * [ScriptTag]? [LibraryDirective]? namespaceDirective* [PartDirective]* |
| 2314 * | [PartOfDirective] |
| 2315 * |
| 2316 * namespaceDirective ::= |
| 2317 * [ImportDirective] |
| 2318 * | [ExportDirective] |
| 2319 * |
| 2320 * declarations ::= |
| 2321 * [CompilationUnitMember]* |
| 2322 */ |
| 2323 class CompilationUnitImpl extends AstNodeImpl implements CompilationUnit { |
| 2324 /** |
| 2325 * The first token in the token stream that was parsed to form this |
| 2326 * compilation unit. |
| 2327 */ |
| 2328 @override |
| 2329 Token beginToken; |
| 2330 |
| 2331 /** |
| 2332 * The script tag at the beginning of the compilation unit, or `null` if there |
| 2333 * is no script tag in this compilation unit. |
| 2334 */ |
| 2335 ScriptTag _scriptTag; |
| 2336 |
| 2337 /** |
| 2338 * The directives contained in this compilation unit. |
| 2339 */ |
| 2340 NodeList<Directive> _directives; |
| 2341 |
| 2342 /** |
| 2343 * The declarations contained in this compilation unit. |
| 2344 */ |
| 2345 NodeList<CompilationUnitMember> _declarations; |
| 2346 |
| 2347 /** |
| 2348 * The last token in the token stream that was parsed to form this compilation |
| 2349 * unit. This token should always have a type of [TokenType.EOF]. |
| 2350 */ |
| 2351 @override |
| 2352 Token endToken; |
| 2353 |
| 2354 /** |
| 2355 * The element associated with this compilation unit, or `null` if the AST |
| 2356 * structure has not been resolved. |
| 2357 */ |
| 2358 @override |
| 2359 CompilationUnitElement element; |
| 2360 |
| 2361 /** |
| 2362 * The line information for this compilation unit. |
| 2363 */ |
| 2364 @override |
| 2365 LineInfo lineInfo; |
| 2366 |
| 2367 /** |
| 2368 * Initialize a newly created compilation unit to have the given directives |
| 2369 * and declarations. The [scriptTag] can be `null` if there is no script tag |
| 2370 * in the compilation unit. The list of [directives] can be `null` if there |
| 2371 * are no directives in the compilation unit. The list of [declarations] can |
| 2372 * be `null` if there are no declarations in the compilation unit. |
| 2373 */ |
| 2374 CompilationUnitImpl( |
| 2375 this.beginToken, |
| 2376 ScriptTagImpl scriptTag, |
| 2377 List<Directive> directives, |
| 2378 List<CompilationUnitMember> declarations, |
| 2379 this.endToken) { |
| 2380 _scriptTag = _becomeParentOf(scriptTag); |
| 2381 _directives = new NodeListImpl<Directive>(this, directives); |
| 2382 _declarations = new NodeListImpl<CompilationUnitMember>(this, declarations); |
| 2383 } |
| 2384 |
| 2385 @override |
| 2386 Iterable<SyntacticEntity> get childEntities { |
| 2387 ChildEntities result = new ChildEntities()..add(_scriptTag); |
| 2388 if (_directivesAreBeforeDeclarations) { |
| 2389 result..addAll(_directives)..addAll(_declarations); |
| 2390 } else { |
| 2391 result.addAll(sortedDirectivesAndDeclarations); |
| 2392 } |
| 2393 return result; |
| 2394 } |
| 2395 |
| 2396 @override |
| 2397 NodeList<CompilationUnitMember> get declarations => _declarations; |
| 2398 |
| 2399 @override |
| 2400 NodeList<Directive> get directives => _directives; |
| 2401 |
| 2402 @override |
| 2403 int get length { |
| 2404 Token endToken = this.endToken; |
| 2405 if (endToken == null) { |
| 2406 return 0; |
| 2407 } |
| 2408 return endToken.offset + endToken.length; |
| 2409 } |
| 2410 |
| 2411 @override |
| 2412 int get offset => 0; |
| 2413 |
| 2414 @override |
| 2415 ScriptTag get scriptTag => _scriptTag; |
| 2416 |
| 2417 @override |
| 2418 void set scriptTag(ScriptTag scriptTag) { |
| 2419 _scriptTag = _becomeParentOf(scriptTag as AstNodeImpl); |
| 2420 } |
| 2421 |
| 2422 @override |
| 2423 List<AstNode> get sortedDirectivesAndDeclarations { |
| 2424 return <AstNode>[] |
| 2425 ..addAll(_directives) |
| 2426 ..addAll(_declarations) |
| 2427 ..sort(AstNode.LEXICAL_ORDER); |
| 2428 } |
| 2429 |
| 2430 /** |
| 2431 * Return `true` if all of the directives are lexically before any |
| 2432 * declarations. |
| 2433 */ |
| 2434 bool get _directivesAreBeforeDeclarations { |
| 2435 if (_directives.isEmpty || _declarations.isEmpty) { |
| 2436 return true; |
| 2437 } |
| 2438 Directive lastDirective = _directives[_directives.length - 1]; |
| 2439 CompilationUnitMember firstDeclaration = _declarations[0]; |
| 2440 return lastDirective.offset < firstDeclaration.offset; |
| 2441 } |
| 2442 |
| 2443 @override |
| 2444 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2445 visitor.visitCompilationUnit(this); |
| 2446 |
| 2447 @override |
| 2448 void visitChildren(AstVisitor visitor) { |
| 2449 _scriptTag?.accept(visitor); |
| 2450 if (_directivesAreBeforeDeclarations) { |
| 2451 _directives.accept(visitor); |
| 2452 _declarations.accept(visitor); |
| 2453 } else { |
| 2454 int length = sortedDirectivesAndDeclarations.length; |
| 2455 for (int i = 0; i < length; i++) { |
| 2456 AstNode child = sortedDirectivesAndDeclarations[i]; |
| 2457 child.accept(visitor); |
| 2458 } |
| 2459 } |
| 2460 } |
| 2461 } |
| 2462 |
| 2463 /** |
| 2464 * A node that declares one or more names within the scope of a compilation |
| 2465 * unit. |
| 2466 * |
| 2467 * compilationUnitMember ::= |
| 2468 * [ClassDeclaration] |
| 2469 * | [TypeAlias] |
| 2470 * | [FunctionDeclaration] |
| 2471 * | [MethodDeclaration] |
| 2472 * | [VariableDeclaration] |
| 2473 * | [VariableDeclaration] |
| 2474 */ |
| 2475 abstract class CompilationUnitMemberImpl extends DeclarationImpl |
| 2476 implements CompilationUnitMember { |
| 2477 /** |
| 2478 * Initialize a newly created generic compilation unit member. Either or both |
| 2479 * of the [comment] and [metadata] can be `null` if the member does not have |
| 2480 * the corresponding attribute. |
| 2481 */ |
| 2482 CompilationUnitMemberImpl(Comment comment, List<Annotation> metadata) |
| 2483 : super(comment, metadata); |
| 2484 } |
| 2485 |
| 2486 /** |
| 2487 * A conditional expression. |
| 2488 * |
| 2489 * conditionalExpression ::= |
| 2490 * [Expression] '?' [Expression] ':' [Expression] |
| 2491 */ |
| 2492 class ConditionalExpressionImpl extends ExpressionImpl |
| 2493 implements ConditionalExpression { |
| 2494 /** |
| 2495 * The condition used to determine which of the expressions is executed next. |
| 2496 */ |
| 2497 Expression _condition; |
| 2498 |
| 2499 /** |
| 2500 * The token used to separate the condition from the then expression. |
| 2501 */ |
| 2502 @override |
| 2503 Token question; |
| 2504 |
| 2505 /** |
| 2506 * The expression that is executed if the condition evaluates to `true`. |
| 2507 */ |
| 2508 Expression _thenExpression; |
| 2509 |
| 2510 /** |
| 2511 * The token used to separate the then expression from the else expression. |
| 2512 */ |
| 2513 @override |
| 2514 Token colon; |
| 2515 |
| 2516 /** |
| 2517 * The expression that is executed if the condition evaluates to `false`. |
| 2518 */ |
| 2519 Expression _elseExpression; |
| 2520 |
| 2521 /** |
| 2522 * Initialize a newly created conditional expression. |
| 2523 */ |
| 2524 ConditionalExpressionImpl( |
| 2525 ExpressionImpl condition, |
| 2526 this.question, |
| 2527 ExpressionImpl thenExpression, |
| 2528 this.colon, |
| 2529 ExpressionImpl elseExpression) { |
| 2530 _condition = _becomeParentOf(condition); |
| 2531 _thenExpression = _becomeParentOf(thenExpression); |
| 2532 _elseExpression = _becomeParentOf(elseExpression); |
| 2533 } |
| 2534 |
| 2535 @override |
| 2536 Token get beginToken => _condition.beginToken; |
| 2537 |
| 2538 @override |
| 2539 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 2540 ..add(_condition) |
| 2541 ..add(question) |
| 2542 ..add(_thenExpression) |
| 2543 ..add(colon) |
| 2544 ..add(_elseExpression); |
| 2545 |
| 2546 @override |
| 2547 Expression get condition => _condition; |
| 2548 |
| 2549 @override |
| 2550 void set condition(Expression expression) { |
| 2551 _condition = _becomeParentOf(expression as AstNodeImpl); |
| 2552 } |
| 2553 |
| 2554 @override |
| 2555 Expression get elseExpression => _elseExpression; |
| 2556 |
| 2557 @override |
| 2558 void set elseExpression(Expression expression) { |
| 2559 _elseExpression = _becomeParentOf(expression as AstNodeImpl); |
| 2560 } |
| 2561 |
| 2562 @override |
| 2563 Token get endToken => _elseExpression.endToken; |
| 2564 |
| 2565 @override |
| 2566 int get precedence => 3; |
| 2567 |
| 2568 @override |
| 2569 Expression get thenExpression => _thenExpression; |
| 2570 |
| 2571 @override |
| 2572 void set thenExpression(Expression expression) { |
| 2573 _thenExpression = _becomeParentOf(expression as AstNodeImpl); |
| 2574 } |
| 2575 |
| 2576 @override |
| 2577 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2578 visitor.visitConditionalExpression(this); |
| 2579 |
| 2580 @override |
| 2581 void visitChildren(AstVisitor visitor) { |
| 2582 _condition?.accept(visitor); |
| 2583 _thenExpression?.accept(visitor); |
| 2584 _elseExpression?.accept(visitor); |
| 2585 } |
| 2586 } |
| 2587 |
| 2588 /** |
| 2589 * A configuration in either an import or export directive. |
| 2590 * |
| 2591 * configuration ::= |
| 2592 * 'if' '(' test ')' uri |
| 2593 * |
| 2594 * test ::= |
| 2595 * dottedName ('==' stringLiteral)? |
| 2596 * |
| 2597 * dottedName ::= |
| 2598 * identifier ('.' identifier)* |
| 2599 */ |
| 2600 class ConfigurationImpl extends AstNodeImpl implements Configuration { |
| 2601 @override |
| 2602 Token ifKeyword; |
| 2603 |
| 2604 @override |
| 2605 Token leftParenthesis; |
| 2606 |
| 2607 DottedName _name; |
| 2608 |
| 2609 @override |
| 2610 Token equalToken; |
| 2611 |
| 2612 StringLiteral _value; |
| 2613 |
| 2614 @override |
| 2615 Token rightParenthesis; |
| 2616 |
| 2617 StringLiteral _uri; |
| 2618 |
| 2619 @override |
| 2620 Source uriSource; |
| 2621 |
| 2622 ConfigurationImpl( |
| 2623 this.ifKeyword, |
| 2624 this.leftParenthesis, |
| 2625 DottedNameImpl name, |
| 2626 this.equalToken, |
| 2627 StringLiteralImpl value, |
| 2628 this.rightParenthesis, |
| 2629 StringLiteralImpl libraryUri) { |
| 2630 _name = _becomeParentOf(name); |
| 2631 _value = _becomeParentOf(value); |
| 2632 _uri = _becomeParentOf(libraryUri); |
| 2633 } |
| 2634 |
| 2635 @override |
| 2636 Token get beginToken => ifKeyword; |
| 2637 |
| 2638 @override |
| 2639 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 2640 ..add(ifKeyword) |
| 2641 ..add(leftParenthesis) |
| 2642 ..add(_name) |
| 2643 ..add(equalToken) |
| 2644 ..add(_value) |
| 2645 ..add(rightParenthesis) |
| 2646 ..add(_uri); |
| 2647 |
| 2648 @override |
| 2649 Token get endToken => _uri.endToken; |
| 2650 |
| 2651 @deprecated |
| 2652 @override |
| 2653 StringLiteral get libraryUri => _uri; |
| 2654 |
| 2655 @deprecated |
| 2656 @override |
| 2657 void set libraryUri(StringLiteral libraryUri) { |
| 2658 _uri = _becomeParentOf(libraryUri as AstNodeImpl); |
| 2659 } |
| 2660 |
| 2661 @override |
| 2662 DottedName get name => _name; |
| 2663 |
| 2664 @override |
| 2665 void set name(DottedName name) { |
| 2666 _name = _becomeParentOf(name as AstNodeImpl); |
| 2667 } |
| 2668 |
| 2669 @override |
| 2670 StringLiteral get uri => _uri; |
| 2671 |
| 2672 @override |
| 2673 void set uri(StringLiteral uri) { |
| 2674 _uri = _becomeParentOf(uri as AstNodeImpl); |
| 2675 } |
| 2676 |
| 2677 @override |
| 2678 StringLiteral get value => _value; |
| 2679 |
| 2680 @override |
| 2681 void set value(StringLiteral value) { |
| 2682 _value = _becomeParentOf(value as AstNodeImpl); |
| 2683 } |
| 2684 |
| 2685 @override |
| 2686 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2687 visitor.visitConfiguration(this); |
| 2688 |
| 2689 @override |
| 2690 void visitChildren(AstVisitor visitor) { |
| 2691 _name?.accept(visitor); |
| 2692 _value?.accept(visitor); |
| 2693 _uri?.accept(visitor); |
| 2694 } |
| 2695 } |
| 2696 |
| 2697 /** |
| 2698 * A constructor declaration. |
| 2699 * |
| 2700 * constructorDeclaration ::= |
| 2701 * constructorSignature [FunctionBody]? |
| 2702 * | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier]
)? arguments |
| 2703 * |
| 2704 * constructorSignature ::= |
| 2705 * 'external'? constructorName formalParameterList initializerList? |
| 2706 * | 'external'? 'factory' factoryName formalParameterList initializerList? |
| 2707 * | 'external'? 'const' constructorName formalParameterList initializerLi
st? |
| 2708 * |
| 2709 * constructorName ::= |
| 2710 * [SimpleIdentifier] ('.' [SimpleIdentifier])? |
| 2711 * |
| 2712 * factoryName ::= |
| 2713 * [Identifier] ('.' [SimpleIdentifier])? |
| 2714 * |
| 2715 * initializerList ::= |
| 2716 * ':' [ConstructorInitializer] (',' [ConstructorInitializer])* |
| 2717 */ |
| 2718 class ConstructorDeclarationImpl extends ClassMemberImpl |
| 2719 implements ConstructorDeclaration { |
| 2720 /** |
| 2721 * The token for the 'external' keyword, or `null` if the constructor is not |
| 2722 * external. |
| 2723 */ |
| 2724 @override |
| 2725 Token externalKeyword; |
| 2726 |
| 2727 /** |
| 2728 * The token for the 'const' keyword, or `null` if the constructor is not a |
| 2729 * const constructor. |
| 2730 */ |
| 2731 @override |
| 2732 Token constKeyword; |
| 2733 |
| 2734 /** |
| 2735 * The token for the 'factory' keyword, or `null` if the constructor is not a |
| 2736 * factory constructor. |
| 2737 */ |
| 2738 @override |
| 2739 Token factoryKeyword; |
| 2740 |
| 2741 /** |
| 2742 * The type of object being created. This can be different than the type in |
| 2743 * which the constructor is being declared if the constructor is the |
| 2744 * implementation of a factory constructor. |
| 2745 */ |
| 2746 Identifier _returnType; |
| 2747 |
| 2748 /** |
| 2749 * The token for the period before the constructor name, or `null` if the |
| 2750 * constructor being declared is unnamed. |
| 2751 */ |
| 2752 @override |
| 2753 Token period; |
| 2754 |
| 2755 /** |
| 2756 * The name of the constructor, or `null` if the constructor being declared is |
| 2757 * unnamed. |
| 2758 */ |
| 2759 SimpleIdentifier _name; |
| 2760 |
| 2761 /** |
| 2762 * The parameters associated with the constructor. |
| 2763 */ |
| 2764 FormalParameterList _parameters; |
| 2765 |
| 2766 /** |
| 2767 * The token for the separator (colon or equals) before the initializer list |
| 2768 * or redirection, or `null` if there are no initializers. |
| 2769 */ |
| 2770 @override |
| 2771 Token separator; |
| 2772 |
| 2773 /** |
| 2774 * The initializers associated with the constructor. |
| 2775 */ |
| 2776 NodeList<ConstructorInitializer> _initializers; |
| 2777 |
| 2778 /** |
| 2779 * The name of the constructor to which this constructor will be redirected, |
| 2780 * or `null` if this is not a redirecting factory constructor. |
| 2781 */ |
| 2782 ConstructorName _redirectedConstructor; |
| 2783 |
| 2784 /** |
| 2785 * The body of the constructor, or `null` if the constructor does not have a |
| 2786 * body. |
| 2787 */ |
| 2788 FunctionBody _body; |
| 2789 |
| 2790 /** |
| 2791 * The element associated with this constructor, or `null` if the AST |
| 2792 * structure has not been resolved or if this constructor could not be |
| 2793 * resolved. |
| 2794 */ |
| 2795 @override |
| 2796 ConstructorElement element; |
| 2797 |
| 2798 /** |
| 2799 * Initialize a newly created constructor declaration. The [externalKeyword] |
| 2800 * can be `null` if the constructor is not external. Either or both of the |
| 2801 * [comment] and [metadata] can be `null` if the constructor does not have the |
| 2802 * corresponding attribute. The [constKeyword] can be `null` if the |
| 2803 * constructor cannot be used to create a constant. The [factoryKeyword] can |
| 2804 * be `null` if the constructor is not a factory. The [period] and [name] can |
| 2805 * both be `null` if the constructor is not a named constructor. The |
| 2806 * [separator] can be `null` if the constructor does not have any initializers |
| 2807 * and does not redirect to a different constructor. The list of |
| 2808 * [initializers] can be `null` if the constructor does not have any |
| 2809 * initializers. The [redirectedConstructor] can be `null` if the constructor |
| 2810 * does not redirect to a different constructor. The [body] can be `null` if |
| 2811 * the constructor does not have a body. |
| 2812 */ |
| 2813 ConstructorDeclarationImpl( |
| 2814 CommentImpl comment, |
| 2815 List<Annotation> metadata, |
| 2816 this.externalKeyword, |
| 2817 this.constKeyword, |
| 2818 this.factoryKeyword, |
| 2819 IdentifierImpl returnType, |
| 2820 this.period, |
| 2821 SimpleIdentifierImpl name, |
| 2822 FormalParameterListImpl parameters, |
| 2823 this.separator, |
| 2824 List<ConstructorInitializer> initializers, |
| 2825 ConstructorNameImpl redirectedConstructor, |
| 2826 FunctionBodyImpl body) |
| 2827 : super(comment, metadata) { |
| 2828 _returnType = _becomeParentOf(returnType); |
| 2829 _name = _becomeParentOf(name); |
| 2830 _parameters = _becomeParentOf(parameters); |
| 2831 _initializers = |
| 2832 new NodeListImpl<ConstructorInitializer>(this, initializers); |
| 2833 _redirectedConstructor = _becomeParentOf(redirectedConstructor); |
| 2834 _body = _becomeParentOf(body); |
| 2835 } |
| 2836 |
| 2837 @override |
| 2838 FunctionBody get body => _body; |
| 2839 |
| 2840 @override |
| 2841 void set body(FunctionBody functionBody) { |
| 2842 _body = _becomeParentOf(functionBody as AstNodeImpl); |
| 2843 } |
| 2844 |
| 2845 @override |
| 2846 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 2847 ..add(externalKeyword) |
| 2848 ..add(constKeyword) |
| 2849 ..add(factoryKeyword) |
| 2850 ..add(_returnType) |
| 2851 ..add(period) |
| 2852 ..add(_name) |
| 2853 ..add(_parameters) |
| 2854 ..add(separator) |
| 2855 ..addAll(initializers) |
| 2856 ..add(_redirectedConstructor) |
| 2857 ..add(_body); |
| 2858 |
| 2859 @override |
| 2860 Token get endToken { |
| 2861 if (_body != null) { |
| 2862 return _body.endToken; |
| 2863 } else if (!_initializers.isEmpty) { |
| 2864 return _initializers.endToken; |
| 2865 } |
| 2866 return _parameters.endToken; |
| 2867 } |
| 2868 |
| 2869 @override |
| 2870 Token get firstTokenAfterCommentAndMetadata { |
| 2871 Token leftMost = |
| 2872 Token.lexicallyFirst([externalKeyword, constKeyword, factoryKeyword]); |
| 2873 if (leftMost != null) { |
| 2874 return leftMost; |
| 2875 } |
| 2876 return _returnType.beginToken; |
| 2877 } |
| 2878 |
| 2879 @override |
| 2880 NodeList<ConstructorInitializer> get initializers => _initializers; |
| 2881 |
| 2882 @override |
| 2883 SimpleIdentifier get name => _name; |
| 2884 |
| 2885 @override |
| 2886 void set name(SimpleIdentifier identifier) { |
| 2887 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 2888 } |
| 2889 |
| 2890 @override |
| 2891 FormalParameterList get parameters => _parameters; |
| 2892 |
| 2893 @override |
| 2894 void set parameters(FormalParameterList parameters) { |
| 2895 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 2896 } |
| 2897 |
| 2898 @override |
| 2899 ConstructorName get redirectedConstructor => _redirectedConstructor; |
| 2900 |
| 2901 @override |
| 2902 void set redirectedConstructor(ConstructorName redirectedConstructor) { |
| 2903 _redirectedConstructor = |
| 2904 _becomeParentOf(redirectedConstructor as AstNodeImpl); |
| 2905 } |
| 2906 |
| 2907 @override |
| 2908 Identifier get returnType => _returnType; |
| 2909 |
| 2910 @override |
| 2911 void set returnType(Identifier typeName) { |
| 2912 _returnType = _becomeParentOf(typeName as AstNodeImpl); |
| 2913 } |
| 2914 |
| 2915 @override |
| 2916 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2917 visitor.visitConstructorDeclaration(this); |
| 2918 |
| 2919 @override |
| 2920 void visitChildren(AstVisitor visitor) { |
| 2921 super.visitChildren(visitor); |
| 2922 _returnType?.accept(visitor); |
| 2923 _name?.accept(visitor); |
| 2924 _parameters?.accept(visitor); |
| 2925 _initializers.accept(visitor); |
| 2926 _redirectedConstructor?.accept(visitor); |
| 2927 _body?.accept(visitor); |
| 2928 } |
| 2929 } |
| 2930 |
| 2931 /** |
| 2932 * The initialization of a field within a constructor's initialization list. |
| 2933 * |
| 2934 * fieldInitializer ::= |
| 2935 * ('this' '.')? [SimpleIdentifier] '=' [Expression] |
| 2936 */ |
| 2937 class ConstructorFieldInitializerImpl extends ConstructorInitializerImpl |
| 2938 implements ConstructorFieldInitializer { |
| 2939 /** |
| 2940 * The token for the 'this' keyword, or `null` if there is no 'this' keyword. |
| 2941 */ |
| 2942 @override |
| 2943 Token thisKeyword; |
| 2944 |
| 2945 /** |
| 2946 * The token for the period after the 'this' keyword, or `null` if there is no |
| 2947 * 'this' keyword. |
| 2948 */ |
| 2949 @override |
| 2950 Token period; |
| 2951 |
| 2952 /** |
| 2953 * The name of the field being initialized. |
| 2954 */ |
| 2955 SimpleIdentifier _fieldName; |
| 2956 |
| 2957 /** |
| 2958 * The token for the equal sign between the field name and the expression. |
| 2959 */ |
| 2960 @override |
| 2961 Token equals; |
| 2962 |
| 2963 /** |
| 2964 * The expression computing the value to which the field will be initialized. |
| 2965 */ |
| 2966 Expression _expression; |
| 2967 |
| 2968 /** |
| 2969 * Initialize a newly created field initializer to initialize the field with |
| 2970 * the given name to the value of the given expression. The [thisKeyword] and |
| 2971 * [period] can be `null` if the 'this' keyword was not specified. |
| 2972 */ |
| 2973 ConstructorFieldInitializerImpl(this.thisKeyword, this.period, |
| 2974 SimpleIdentifierImpl fieldName, this.equals, ExpressionImpl expression) { |
| 2975 _fieldName = _becomeParentOf(fieldName); |
| 2976 _expression = _becomeParentOf(expression); |
| 2977 } |
| 2978 |
| 2979 @override |
| 2980 Token get beginToken { |
| 2981 if (thisKeyword != null) { |
| 2982 return thisKeyword; |
| 2983 } |
| 2984 return _fieldName.beginToken; |
| 2985 } |
| 2986 |
| 2987 @override |
| 2988 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 2989 ..add(thisKeyword) |
| 2990 ..add(period) |
| 2991 ..add(_fieldName) |
| 2992 ..add(equals) |
| 2993 ..add(_expression); |
| 2994 |
| 2995 @override |
| 2996 Token get endToken => _expression.endToken; |
| 2997 |
| 2998 @override |
| 2999 Expression get expression => _expression; |
| 3000 |
| 3001 @override |
| 3002 void set expression(Expression expression) { |
| 3003 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 3004 } |
| 3005 |
| 3006 @override |
| 3007 SimpleIdentifier get fieldName => _fieldName; |
| 3008 |
| 3009 @override |
| 3010 void set fieldName(SimpleIdentifier identifier) { |
| 3011 _fieldName = _becomeParentOf(identifier as AstNodeImpl); |
| 3012 } |
| 3013 |
| 3014 @override |
| 3015 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3016 visitor.visitConstructorFieldInitializer(this); |
| 3017 |
| 3018 @override |
| 3019 void visitChildren(AstVisitor visitor) { |
| 3020 _fieldName?.accept(visitor); |
| 3021 _expression?.accept(visitor); |
| 3022 } |
| 3023 } |
| 3024 |
| 3025 /** |
| 3026 * A node that can occur in the initializer list of a constructor declaration. |
| 3027 * |
| 3028 * constructorInitializer ::= |
| 3029 * [SuperConstructorInvocation] |
| 3030 * | [ConstructorFieldInitializer] |
| 3031 * | [RedirectingConstructorInvocation] |
| 3032 */ |
| 3033 abstract class ConstructorInitializerImpl extends AstNodeImpl |
| 3034 implements ConstructorInitializer {} |
| 3035 |
| 3036 /** |
| 3037 * The name of the constructor. |
| 3038 * |
| 3039 * constructorName ::= |
| 3040 * type ('.' identifier)? |
| 3041 */ |
| 3042 class ConstructorNameImpl extends AstNodeImpl implements ConstructorName { |
| 3043 /** |
| 3044 * The name of the type defining the constructor. |
| 3045 */ |
| 3046 TypeName _type; |
| 3047 |
| 3048 /** |
| 3049 * The token for the period before the constructor name, or `null` if the |
| 3050 * specified constructor is the unnamed constructor. |
| 3051 */ |
| 3052 @override |
| 3053 Token period; |
| 3054 |
| 3055 /** |
| 3056 * The name of the constructor, or `null` if the specified constructor is the |
| 3057 * unnamed constructor. |
| 3058 */ |
| 3059 SimpleIdentifier _name; |
| 3060 |
| 3061 /** |
| 3062 * The element associated with this constructor name based on static type |
| 3063 * information, or `null` if the AST structure has not been resolved or if |
| 3064 * this constructor name could not be resolved. |
| 3065 */ |
| 3066 @override |
| 3067 ConstructorElement staticElement; |
| 3068 |
| 3069 /** |
| 3070 * Initialize a newly created constructor name. The [period] and [name] can be |
| 3071 * `null` if the constructor being named is the unnamed constructor. |
| 3072 */ |
| 3073 ConstructorNameImpl( |
| 3074 TypeNameImpl type, this.period, SimpleIdentifierImpl name) { |
| 3075 _type = _becomeParentOf(type); |
| 3076 _name = _becomeParentOf(name); |
| 3077 } |
| 3078 |
| 3079 @override |
| 3080 Token get beginToken => _type.beginToken; |
| 3081 |
| 3082 @override |
| 3083 Iterable<SyntacticEntity> get childEntities => |
| 3084 new ChildEntities()..add(_type)..add(period)..add(_name); |
| 3085 |
| 3086 @override |
| 3087 Token get endToken { |
| 3088 if (_name != null) { |
| 3089 return _name.endToken; |
| 3090 } |
| 3091 return _type.endToken; |
| 3092 } |
| 3093 |
| 3094 @override |
| 3095 SimpleIdentifier get name => _name; |
| 3096 |
| 3097 @override |
| 3098 void set name(SimpleIdentifier name) { |
| 3099 _name = _becomeParentOf(name as AstNodeImpl); |
| 3100 } |
| 3101 |
| 3102 @override |
| 3103 TypeName get type => _type; |
| 3104 |
| 3105 @override |
| 3106 void set type(TypeName type) { |
| 3107 _type = _becomeParentOf(type as AstNodeImpl); |
| 3108 } |
| 3109 |
| 3110 @override |
| 3111 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3112 visitor.visitConstructorName(this); |
| 3113 |
| 3114 @override |
| 3115 void visitChildren(AstVisitor visitor) { |
| 3116 _type?.accept(visitor); |
| 3117 _name?.accept(visitor); |
| 3118 } |
| 3119 } |
| 3120 |
| 3121 /** |
| 3122 * A continue statement. |
| 3123 * |
| 3124 * continueStatement ::= |
| 3125 * 'continue' [SimpleIdentifier]? ';' |
| 3126 */ |
| 3127 class ContinueStatementImpl extends StatementImpl implements ContinueStatement { |
| 3128 /** |
| 3129 * The token representing the 'continue' keyword. |
| 3130 */ |
| 3131 @override |
| 3132 Token continueKeyword; |
| 3133 |
| 3134 /** |
| 3135 * The label associated with the statement, or `null` if there is no label. |
| 3136 */ |
| 3137 SimpleIdentifier _label; |
| 3138 |
| 3139 /** |
| 3140 * The semicolon terminating the statement. |
| 3141 */ |
| 3142 @override |
| 3143 Token semicolon; |
| 3144 |
| 3145 /** |
| 3146 * The AstNode which this continue statement is continuing to. This will be |
| 3147 * either a Statement (in the case of continuing a loop) or a SwitchMember |
| 3148 * (in the case of continuing from one switch case to another). Null if the |
| 3149 * AST has not yet been resolved or if the target could not be resolved. |
| 3150 * Note that if the source code has errors, the target may be invalid (e.g. |
| 3151 * the target may be in an enclosing function). |
| 3152 */ |
| 3153 AstNode target; |
| 3154 |
| 3155 /** |
| 3156 * Initialize a newly created continue statement. The [label] can be `null` if |
| 3157 * there is no label associated with the statement. |
| 3158 */ |
| 3159 ContinueStatementImpl( |
| 3160 this.continueKeyword, SimpleIdentifierImpl label, this.semicolon) { |
| 3161 _label = _becomeParentOf(label); |
| 3162 } |
| 3163 |
| 3164 @override |
| 3165 Token get beginToken => continueKeyword; |
| 3166 |
| 3167 @override |
| 3168 Iterable<SyntacticEntity> get childEntities => |
| 3169 new ChildEntities()..add(continueKeyword)..add(_label)..add(semicolon); |
| 3170 |
| 3171 @override |
| 3172 Token get endToken => semicolon; |
| 3173 |
| 3174 @override |
| 3175 SimpleIdentifier get label => _label; |
| 3176 |
| 3177 @override |
| 3178 void set label(SimpleIdentifier identifier) { |
| 3179 _label = _becomeParentOf(identifier as AstNodeImpl); |
| 3180 } |
| 3181 |
| 3182 @override |
| 3183 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3184 visitor.visitContinueStatement(this); |
| 3185 |
| 3186 @override |
| 3187 void visitChildren(AstVisitor visitor) { |
| 3188 _label?.accept(visitor); |
| 3189 } |
| 3190 } |
| 3191 |
| 3192 /** |
| 3193 * A node that represents the declaration of one or more names. Each declared |
| 3194 * name is visible within a name scope. |
| 3195 */ |
| 3196 abstract class DeclarationImpl extends AnnotatedNodeImpl |
| 3197 implements Declaration { |
| 3198 /** |
| 3199 * Initialize a newly created declaration. Either or both of the [comment] and |
| 3200 * [metadata] can be `null` if the declaration does not have the corresponding |
| 3201 * attribute. |
| 3202 */ |
| 3203 DeclarationImpl(Comment comment, List<Annotation> metadata) |
| 3204 : super(comment, metadata); |
| 3205 } |
| 3206 |
| 3207 /** |
| 3208 * The declaration of a single identifier. |
| 3209 * |
| 3210 * declaredIdentifier ::= |
| 3211 * [Annotation] finalConstVarOrType [SimpleIdentifier] |
| 3212 */ |
| 3213 class DeclaredIdentifierImpl extends DeclarationImpl |
| 3214 implements DeclaredIdentifier { |
| 3215 /** |
| 3216 * The token representing either the 'final', 'const' or 'var' keyword, or |
| 3217 * `null` if no keyword was used. |
| 3218 */ |
| 3219 @override |
| 3220 Token keyword; |
| 3221 |
| 3222 /** |
| 3223 * The name of the declared type of the parameter, or `null` if the parameter |
| 3224 * does not have a declared type. |
| 3225 */ |
| 3226 TypeName _type; |
| 3227 |
| 3228 /** |
| 3229 * The name of the variable being declared. |
| 3230 */ |
| 3231 SimpleIdentifier _identifier; |
| 3232 |
| 3233 /** |
| 3234 * Initialize a newly created formal parameter. Either or both of the |
| 3235 * [comment] and [metadata] can be `null` if the declaration does not have the |
| 3236 * corresponding attribute. The [keyword] can be `null` if a type name is |
| 3237 * given. The [type] must be `null` if the keyword is 'var'. |
| 3238 */ |
| 3239 DeclaredIdentifierImpl(CommentImpl comment, List<Annotation> metadata, |
| 3240 this.keyword, TypeNameImpl type, SimpleIdentifierImpl identifier) |
| 3241 : super(comment, metadata) { |
| 3242 _type = _becomeParentOf(type); |
| 3243 _identifier = _becomeParentOf(identifier); |
| 3244 } |
| 3245 |
| 3246 @override |
| 3247 Iterable<SyntacticEntity> get childEntities => |
| 3248 super._childEntities..add(keyword)..add(_type)..add(_identifier); |
| 3249 |
| 3250 @override |
| 3251 LocalVariableElement get element { |
| 3252 if (_identifier == null) { |
| 3253 return null; |
| 3254 } |
| 3255 return _identifier.staticElement as LocalVariableElement; |
| 3256 } |
| 3257 |
| 3258 @override |
| 3259 Token get endToken => _identifier.endToken; |
| 3260 |
| 3261 @override |
| 3262 Token get firstTokenAfterCommentAndMetadata { |
| 3263 if (keyword != null) { |
| 3264 return keyword; |
| 3265 } else if (_type != null) { |
| 3266 return _type.beginToken; |
| 3267 } |
| 3268 return _identifier.beginToken; |
| 3269 } |
| 3270 |
| 3271 @override |
| 3272 SimpleIdentifier get identifier => _identifier; |
| 3273 |
| 3274 @override |
| 3275 void set identifier(SimpleIdentifier identifier) { |
| 3276 _identifier = _becomeParentOf(identifier as AstNodeImpl); |
| 3277 } |
| 3278 |
| 3279 @override |
| 3280 bool get isConst => keyword?.keyword == Keyword.CONST; |
| 3281 |
| 3282 @override |
| 3283 bool get isFinal => keyword?.keyword == Keyword.FINAL; |
| 3284 |
| 3285 @override |
| 3286 TypeName get type => _type; |
| 3287 |
| 3288 @override |
| 3289 void set type(TypeName typeName) { |
| 3290 _type = _becomeParentOf(typeName as AstNodeImpl); |
| 3291 } |
| 3292 |
| 3293 @override |
| 3294 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3295 visitor.visitDeclaredIdentifier(this); |
| 3296 |
| 3297 @override |
| 3298 void visitChildren(AstVisitor visitor) { |
| 3299 super.visitChildren(visitor); |
| 3300 _type?.accept(visitor); |
| 3301 _identifier?.accept(visitor); |
| 3302 } |
| 3303 } |
| 3304 |
| 3305 /** |
| 3306 * A simple identifier that declares a name. |
| 3307 */ |
| 3308 // TODO(rnystrom): Consider making this distinct from [SimpleIdentifier] and |
| 3309 // get rid of all of the: |
| 3310 // |
| 3311 // if (node.inDeclarationContext()) { ... } |
| 3312 // |
| 3313 // code and instead visit this separately. A declaration is semantically pretty |
| 3314 // different from a use, so using the same node type doesn't seem to buy us |
| 3315 // much. |
| 3316 class DeclaredSimpleIdentifier extends SimpleIdentifierImpl { |
| 3317 DeclaredSimpleIdentifier(Token token) : super(token); |
| 3318 |
| 3319 @override |
| 3320 bool inDeclarationContext() => true; |
| 3321 } |
| 3322 |
| 3323 /** |
| 3324 * A formal parameter with a default value. There are two kinds of parameters |
| 3325 * that are both represented by this class: named formal parameters and |
| 3326 * positional formal parameters. |
| 3327 * |
| 3328 * defaultFormalParameter ::= |
| 3329 * [NormalFormalParameter] ('=' [Expression])? |
| 3330 * |
| 3331 * defaultNamedParameter ::= |
| 3332 * [NormalFormalParameter] (':' [Expression])? |
| 3333 */ |
| 3334 class DefaultFormalParameterImpl extends FormalParameterImpl |
| 3335 implements DefaultFormalParameter { |
| 3336 /** |
| 3337 * The formal parameter with which the default value is associated. |
| 3338 */ |
| 3339 NormalFormalParameter _parameter; |
| 3340 |
| 3341 /** |
| 3342 * The kind of this parameter. |
| 3343 */ |
| 3344 @override |
| 3345 ParameterKind kind; |
| 3346 |
| 3347 /** |
| 3348 * The token separating the parameter from the default value, or `null` if |
| 3349 * there is no default value. |
| 3350 */ |
| 3351 @override |
| 3352 Token separator; |
| 3353 |
| 3354 /** |
| 3355 * The expression computing the default value for the parameter, or `null` if |
| 3356 * there is no default value. |
| 3357 */ |
| 3358 Expression _defaultValue; |
| 3359 |
| 3360 /** |
| 3361 * Initialize a newly created default formal parameter. The [separator] and |
| 3362 * [defaultValue] can be `null` if there is no default value. |
| 3363 */ |
| 3364 DefaultFormalParameterImpl(NormalFormalParameterImpl parameter, this.kind, |
| 3365 this.separator, ExpressionImpl defaultValue) { |
| 3366 _parameter = _becomeParentOf(parameter); |
| 3367 _defaultValue = _becomeParentOf(defaultValue); |
| 3368 } |
| 3369 |
| 3370 @override |
| 3371 Token get beginToken => _parameter.beginToken; |
| 3372 |
| 3373 @override |
| 3374 Iterable<SyntacticEntity> get childEntities => |
| 3375 new ChildEntities()..add(_parameter)..add(separator)..add(_defaultValue); |
| 3376 |
| 3377 @override |
| 3378 Expression get defaultValue => _defaultValue; |
| 3379 |
| 3380 @override |
| 3381 void set defaultValue(Expression expression) { |
| 3382 _defaultValue = _becomeParentOf(expression as AstNodeImpl); |
| 3383 } |
| 3384 |
| 3385 @override |
| 3386 Token get endToken { |
| 3387 if (_defaultValue != null) { |
| 3388 return _defaultValue.endToken; |
| 3389 } |
| 3390 return _parameter.endToken; |
| 3391 } |
| 3392 |
| 3393 @override |
| 3394 SimpleIdentifier get identifier => _parameter.identifier; |
| 3395 |
| 3396 @override |
| 3397 bool get isConst => _parameter != null && _parameter.isConst; |
| 3398 |
| 3399 @override |
| 3400 bool get isFinal => _parameter != null && _parameter.isFinal; |
| 3401 |
| 3402 @override |
| 3403 NodeList<Annotation> get metadata => _parameter.metadata; |
| 3404 |
| 3405 @override |
| 3406 NormalFormalParameter get parameter => _parameter; |
| 3407 |
| 3408 @override |
| 3409 void set parameter(NormalFormalParameter formalParameter) { |
| 3410 _parameter = _becomeParentOf(formalParameter as AstNodeImpl); |
| 3411 } |
| 3412 |
| 3413 @override |
| 3414 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3415 visitor.visitDefaultFormalParameter(this); |
| 3416 |
| 3417 @override |
| 3418 void visitChildren(AstVisitor visitor) { |
| 3419 _parameter?.accept(visitor); |
| 3420 _defaultValue?.accept(visitor); |
| 3421 } |
| 3422 } |
| 3423 |
| 3424 /** |
| 3425 * A node that represents a directive. |
| 3426 * |
| 3427 * directive ::= |
| 3428 * [ExportDirective] |
| 3429 * | [ImportDirective] |
| 3430 * | [LibraryDirective] |
| 3431 * | [PartDirective] |
| 3432 * | [PartOfDirective] |
| 3433 */ |
| 3434 abstract class DirectiveImpl extends AnnotatedNodeImpl implements Directive { |
| 3435 /** |
| 3436 * The element associated with this directive, or `null` if the AST structure |
| 3437 * has not been resolved or if this directive could not be resolved. |
| 3438 */ |
| 3439 Element _element; |
| 3440 |
| 3441 /** |
| 3442 * Initialize a newly create directive. Either or both of the [comment] and |
| 3443 * [metadata] can be `null` if the directive does not have the corresponding |
| 3444 * attribute. |
| 3445 */ |
| 3446 DirectiveImpl(Comment comment, List<Annotation> metadata) |
| 3447 : super(comment, metadata); |
| 3448 |
| 3449 @override |
| 3450 Element get element => _element; |
| 3451 |
| 3452 /** |
| 3453 * Set the element associated with this directive to be the given [element]. |
| 3454 */ |
| 3455 void set element(Element element) { |
| 3456 _element = element; |
| 3457 } |
| 3458 } |
| 3459 |
| 3460 /** |
| 3461 * A do statement. |
| 3462 * |
| 3463 * doStatement ::= |
| 3464 * 'do' [Statement] 'while' '(' [Expression] ')' ';' |
| 3465 */ |
| 3466 class DoStatementImpl extends StatementImpl implements DoStatement { |
| 3467 /** |
| 3468 * The token representing the 'do' keyword. |
| 3469 */ |
| 3470 @override |
| 3471 Token doKeyword; |
| 3472 |
| 3473 /** |
| 3474 * The body of the loop. |
| 3475 */ |
| 3476 Statement _body; |
| 3477 |
| 3478 /** |
| 3479 * The token representing the 'while' keyword. |
| 3480 */ |
| 3481 @override |
| 3482 Token whileKeyword; |
| 3483 |
| 3484 /** |
| 3485 * The left parenthesis. |
| 3486 */ |
| 3487 Token leftParenthesis; |
| 3488 |
| 3489 /** |
| 3490 * The condition that determines when the loop will terminate. |
| 3491 */ |
| 3492 Expression _condition; |
| 3493 |
| 3494 /** |
| 3495 * The right parenthesis. |
| 3496 */ |
| 3497 @override |
| 3498 Token rightParenthesis; |
| 3499 |
| 3500 /** |
| 3501 * The semicolon terminating the statement. |
| 3502 */ |
| 3503 @override |
| 3504 Token semicolon; |
| 3505 |
| 3506 /** |
| 3507 * Initialize a newly created do loop. |
| 3508 */ |
| 3509 DoStatementImpl( |
| 3510 this.doKeyword, |
| 3511 StatementImpl body, |
| 3512 this.whileKeyword, |
| 3513 this.leftParenthesis, |
| 3514 ExpressionImpl condition, |
| 3515 this.rightParenthesis, |
| 3516 this.semicolon) { |
| 3517 _body = _becomeParentOf(body); |
| 3518 _condition = _becomeParentOf(condition); |
| 3519 } |
| 3520 |
| 3521 @override |
| 3522 Token get beginToken => doKeyword; |
| 3523 |
| 3524 @override |
| 3525 Statement get body => _body; |
| 3526 |
| 3527 @override |
| 3528 void set body(Statement statement) { |
| 3529 _body = _becomeParentOf(statement as AstNodeImpl); |
| 3530 } |
| 3531 |
| 3532 @override |
| 3533 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 3534 ..add(doKeyword) |
| 3535 ..add(_body) |
| 3536 ..add(whileKeyword) |
| 3537 ..add(leftParenthesis) |
| 3538 ..add(_condition) |
| 3539 ..add(rightParenthesis) |
| 3540 ..add(semicolon); |
| 3541 |
| 3542 @override |
| 3543 Expression get condition => _condition; |
| 3544 |
| 3545 @override |
| 3546 void set condition(Expression expression) { |
| 3547 _condition = _becomeParentOf(expression as AstNodeImpl); |
| 3548 } |
| 3549 |
| 3550 @override |
| 3551 Token get endToken => semicolon; |
| 3552 |
| 3553 @override |
| 3554 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3555 visitor.visitDoStatement(this); |
| 3556 |
| 3557 @override |
| 3558 void visitChildren(AstVisitor visitor) { |
| 3559 _body?.accept(visitor); |
| 3560 _condition?.accept(visitor); |
| 3561 } |
| 3562 } |
| 3563 |
| 3564 /** |
| 3565 * A dotted name, used in a configuration within an import or export directive. |
| 3566 * |
| 3567 * dottedName ::= |
| 3568 * [SimpleIdentifier] ('.' [SimpleIdentifier])* |
| 3569 */ |
| 3570 class DottedNameImpl extends AstNodeImpl implements DottedName { |
| 3571 /** |
| 3572 * The components of the identifier. |
| 3573 */ |
| 3574 NodeList<SimpleIdentifier> _components; |
| 3575 |
| 3576 /** |
| 3577 * Initialize a newly created dotted name. |
| 3578 */ |
| 3579 DottedNameImpl(List<SimpleIdentifier> components) { |
| 3580 _components = new NodeListImpl<SimpleIdentifier>(this, components); |
| 3581 } |
| 3582 |
| 3583 @override |
| 3584 Token get beginToken => _components.beginToken; |
| 3585 |
| 3586 @override |
| 3587 // TODO(paulberry): add "." tokens. |
| 3588 Iterable<SyntacticEntity> get childEntities => |
| 3589 new ChildEntities()..addAll(_components); |
| 3590 |
| 3591 @override |
| 3592 NodeList<SimpleIdentifier> get components => _components; |
| 3593 |
| 3594 @override |
| 3595 Token get endToken => _components.endToken; |
| 3596 |
| 3597 @override |
| 3598 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3599 visitor.visitDottedName(this); |
| 3600 |
| 3601 @override |
| 3602 void visitChildren(AstVisitor visitor) { |
| 3603 _components.accept(visitor); |
| 3604 } |
| 3605 } |
| 3606 |
| 3607 /** |
| 3608 * A floating point literal expression. |
| 3609 * |
| 3610 * doubleLiteral ::= |
| 3611 * decimalDigit+ ('.' decimalDigit*)? exponent? |
| 3612 * | '.' decimalDigit+ exponent? |
| 3613 * |
| 3614 * exponent ::= |
| 3615 * ('e' | 'E') ('+' | '-')? decimalDigit+ |
| 3616 */ |
| 3617 class DoubleLiteralImpl extends LiteralImpl implements DoubleLiteral { |
| 3618 /** |
| 3619 * The token representing the literal. |
| 3620 */ |
| 3621 @override |
| 3622 Token literal; |
| 3623 |
| 3624 /** |
| 3625 * The value of the literal. |
| 3626 */ |
| 3627 @override |
| 3628 double value; |
| 3629 |
| 3630 /** |
| 3631 * Initialize a newly created floating point literal. |
| 3632 */ |
| 3633 DoubleLiteralImpl(this.literal, this.value); |
| 3634 |
| 3635 @override |
| 3636 Token get beginToken => literal; |
| 3637 |
| 3638 @override |
| 3639 Iterable<SyntacticEntity> get childEntities => |
| 3640 new ChildEntities()..add(literal); |
| 3641 |
| 3642 @override |
| 3643 Token get endToken => literal; |
| 3644 |
| 3645 @override |
| 3646 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3647 visitor.visitDoubleLiteral(this); |
| 3648 |
| 3649 @override |
| 3650 void visitChildren(AstVisitor visitor) { |
| 3651 // There are no children to visit. |
| 3652 } |
| 3653 } |
| 3654 |
| 3655 /** |
| 3656 * An empty function body, which can only appear in constructors or abstract |
| 3657 * methods. |
| 3658 * |
| 3659 * emptyFunctionBody ::= |
| 3660 * ';' |
| 3661 */ |
| 3662 class EmptyFunctionBodyImpl extends FunctionBodyImpl |
| 3663 implements EmptyFunctionBody { |
| 3664 /** |
| 3665 * The token representing the semicolon that marks the end of the function |
| 3666 * body. |
| 3667 */ |
| 3668 @override |
| 3669 Token semicolon; |
| 3670 |
| 3671 /** |
| 3672 * Initialize a newly created function body. |
| 3673 */ |
| 3674 EmptyFunctionBodyImpl(this.semicolon); |
| 3675 |
| 3676 @override |
| 3677 Token get beginToken => semicolon; |
| 3678 |
| 3679 @override |
| 3680 Iterable<SyntacticEntity> get childEntities => |
| 3681 new ChildEntities()..add(semicolon); |
| 3682 |
| 3683 @override |
| 3684 Token get endToken => semicolon; |
| 3685 |
| 3686 @override |
| 3687 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3688 visitor.visitEmptyFunctionBody(this); |
| 3689 |
| 3690 @override |
| 3691 void visitChildren(AstVisitor visitor) { |
| 3692 // Empty function bodies have no children. |
| 3693 } |
| 3694 } |
| 3695 |
| 3696 /** |
| 3697 * An empty statement. |
| 3698 * |
| 3699 * emptyStatement ::= |
| 3700 * ';' |
| 3701 */ |
| 3702 class EmptyStatementImpl extends StatementImpl implements EmptyStatement { |
| 3703 /** |
| 3704 * The semicolon terminating the statement. |
| 3705 */ |
| 3706 Token semicolon; |
| 3707 |
| 3708 /** |
| 3709 * Initialize a newly created empty statement. |
| 3710 */ |
| 3711 EmptyStatementImpl(this.semicolon); |
| 3712 |
| 3713 @override |
| 3714 Token get beginToken => semicolon; |
| 3715 |
| 3716 @override |
| 3717 Iterable<SyntacticEntity> get childEntities => |
| 3718 new ChildEntities()..add(semicolon); |
| 3719 |
| 3720 @override |
| 3721 Token get endToken => semicolon; |
| 3722 |
| 3723 @override |
| 3724 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3725 visitor.visitEmptyStatement(this); |
| 3726 |
| 3727 @override |
| 3728 void visitChildren(AstVisitor visitor) { |
| 3729 // There are no children to visit. |
| 3730 } |
| 3731 } |
| 3732 |
| 3733 /** |
| 3734 * The declaration of an enum constant. |
| 3735 */ |
| 3736 class EnumConstantDeclarationImpl extends DeclarationImpl |
| 3737 implements EnumConstantDeclaration { |
| 3738 /** |
| 3739 * The name of the constant. |
| 3740 */ |
| 3741 SimpleIdentifier _name; |
| 3742 |
| 3743 /** |
| 3744 * Initialize a newly created enum constant declaration. Either or both of the |
| 3745 * [comment] and [metadata] can be `null` if the constant does not have the |
| 3746 * corresponding attribute. (Technically, enum constants cannot have metadata, |
| 3747 * but we allow it for consistency.) |
| 3748 */ |
| 3749 EnumConstantDeclarationImpl( |
| 3750 CommentImpl comment, List<Annotation> metadata, SimpleIdentifierImpl name) |
| 3751 : super(comment, metadata) { |
| 3752 _name = _becomeParentOf(name); |
| 3753 } |
| 3754 |
| 3755 @override |
| 3756 Iterable<SyntacticEntity> get childEntities => |
| 3757 super._childEntities..add(_name); |
| 3758 |
| 3759 @override |
| 3760 FieldElement get element => _name?.staticElement as FieldElement; |
| 3761 |
| 3762 @override |
| 3763 Token get endToken => _name.endToken; |
| 3764 |
| 3765 @override |
| 3766 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 3767 |
| 3768 @override |
| 3769 SimpleIdentifier get name => _name; |
| 3770 |
| 3771 @override |
| 3772 void set name(SimpleIdentifier name) { |
| 3773 _name = _becomeParentOf(name as AstNodeImpl); |
| 3774 } |
| 3775 |
| 3776 @override |
| 3777 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3778 visitor.visitEnumConstantDeclaration(this); |
| 3779 |
| 3780 @override |
| 3781 void visitChildren(AstVisitor visitor) { |
| 3782 super.visitChildren(visitor); |
| 3783 _name?.accept(visitor); |
| 3784 } |
| 3785 } |
| 3786 |
| 3787 /** |
| 3788 * The declaration of an enumeration. |
| 3789 * |
| 3790 * enumType ::= |
| 3791 * metadata 'enum' [SimpleIdentifier] '{' [SimpleIdentifier] (',' [Simple
Identifier])* (',')? '}' |
| 3792 */ |
| 3793 class EnumDeclarationImpl extends NamedCompilationUnitMemberImpl |
| 3794 implements EnumDeclaration { |
| 3795 /** |
| 3796 * The 'enum' keyword. |
| 3797 */ |
| 3798 @override |
| 3799 Token enumKeyword; |
| 3800 |
| 3801 /** |
| 3802 * The left curly bracket. |
| 3803 */ |
| 3804 @override |
| 3805 Token leftBracket; |
| 3806 |
| 3807 /** |
| 3808 * The enumeration constants being declared. |
| 3809 */ |
| 3810 NodeList<EnumConstantDeclaration> _constants; |
| 3811 |
| 3812 /** |
| 3813 * The right curly bracket. |
| 3814 */ |
| 3815 @override |
| 3816 Token rightBracket; |
| 3817 |
| 3818 /** |
| 3819 * Initialize a newly created enumeration declaration. Either or both of the |
| 3820 * [comment] and [metadata] can be `null` if the declaration does not have the |
| 3821 * corresponding attribute. The list of [constants] must contain at least one |
| 3822 * value. |
| 3823 */ |
| 3824 EnumDeclarationImpl( |
| 3825 Comment comment, |
| 3826 List<Annotation> metadata, |
| 3827 this.enumKeyword, |
| 3828 SimpleIdentifier name, |
| 3829 this.leftBracket, |
| 3830 List<EnumConstantDeclaration> constants, |
| 3831 this.rightBracket) |
| 3832 : super(comment, metadata, name) { |
| 3833 _constants = new NodeListImpl<EnumConstantDeclaration>(this, constants); |
| 3834 } |
| 3835 |
| 3836 @override |
| 3837 // TODO(brianwilkerson) Add commas? |
| 3838 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 3839 ..add(enumKeyword) |
| 3840 ..add(_name) |
| 3841 ..add(leftBracket) |
| 3842 ..addAll(_constants) |
| 3843 ..add(rightBracket); |
| 3844 |
| 3845 @override |
| 3846 NodeList<EnumConstantDeclaration> get constants => _constants; |
| 3847 |
| 3848 @override |
| 3849 ClassElement get element => _name?.staticElement as ClassElement; |
| 3850 |
| 3851 @override |
| 3852 Token get endToken => rightBracket; |
| 3853 |
| 3854 @override |
| 3855 Token get firstTokenAfterCommentAndMetadata => enumKeyword; |
| 3856 |
| 3857 @override |
| 3858 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3859 visitor.visitEnumDeclaration(this); |
| 3860 |
| 3861 @override |
| 3862 void visitChildren(AstVisitor visitor) { |
| 3863 super.visitChildren(visitor); |
| 3864 _name?.accept(visitor); |
| 3865 _constants.accept(visitor); |
| 3866 } |
| 3867 } |
| 3868 |
| 3869 /** |
| 3870 * Ephemeral identifiers are created as needed to mimic the presence of an empty |
| 3871 * identifier. |
| 3872 */ |
| 3873 class EphemeralIdentifier extends SimpleIdentifierImpl { |
| 3874 EphemeralIdentifier(AstNode parent, int location) |
| 3875 : super(new StringToken(TokenType.IDENTIFIER, "", location)) { |
| 3876 (parent as AstNodeImpl)._becomeParentOf(this); |
| 3877 } |
| 3878 } |
| 3879 |
| 3880 /** |
| 3881 * An export directive. |
| 3882 * |
| 3883 * exportDirective ::= |
| 3884 * [Annotation] 'export' [StringLiteral] [Combinator]* ';' |
| 3885 */ |
| 3886 class ExportDirectiveImpl extends NamespaceDirectiveImpl |
| 3887 implements ExportDirective { |
| 3888 /** |
| 3889 * Initialize a newly created export directive. Either or both of the |
| 3890 * [comment] and [metadata] can be `null` if the directive does not have the |
| 3891 * corresponding attribute. The list of [combinators] can be `null` if there |
| 3892 * are no combinators. |
| 3893 */ |
| 3894 ExportDirectiveImpl( |
| 3895 Comment comment, |
| 3896 List<Annotation> metadata, |
| 3897 Token keyword, |
| 3898 StringLiteral libraryUri, |
| 3899 List<Configuration> configurations, |
| 3900 List<Combinator> combinators, |
| 3901 Token semicolon) |
| 3902 : super(comment, metadata, keyword, libraryUri, configurations, |
| 3903 combinators, semicolon); |
| 3904 |
| 3905 @override |
| 3906 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 3907 ..add(_uri) |
| 3908 ..addAll(combinators) |
| 3909 ..add(semicolon); |
| 3910 |
| 3911 @override |
| 3912 ExportElement get element => super.element as ExportElement; |
| 3913 |
| 3914 @override |
| 3915 LibraryElement get uriElement { |
| 3916 if (element != null) { |
| 3917 return element.exportedLibrary; |
| 3918 } |
| 3919 return null; |
| 3920 } |
| 3921 |
| 3922 @override |
| 3923 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 3924 visitor.visitExportDirective(this); |
| 3925 |
| 3926 @override |
| 3927 void visitChildren(AstVisitor visitor) { |
| 3928 super.visitChildren(visitor); |
| 3929 combinators.accept(visitor); |
| 3930 } |
| 3931 } |
| 3932 |
| 3933 /** |
| 3934 * A function body consisting of a single expression. |
| 3935 * |
| 3936 * expressionFunctionBody ::= |
| 3937 * 'async'? '=>' [Expression] ';' |
| 3938 */ |
| 3939 class ExpressionFunctionBodyImpl extends FunctionBodyImpl |
| 3940 implements ExpressionFunctionBody { |
| 3941 /** |
| 3942 * The token representing the 'async' keyword, or `null` if there is no such |
| 3943 * keyword. |
| 3944 */ |
| 3945 @override |
| 3946 Token keyword; |
| 3947 |
| 3948 /** |
| 3949 * The token introducing the expression that represents the body of the |
| 3950 * function. |
| 3951 */ |
| 3952 @override |
| 3953 Token functionDefinition; |
| 3954 |
| 3955 /** |
| 3956 * The expression representing the body of the function. |
| 3957 */ |
| 3958 Expression _expression; |
| 3959 |
| 3960 /** |
| 3961 * The semicolon terminating the statement. |
| 3962 */ |
| 3963 @override |
| 3964 Token semicolon; |
| 3965 |
| 3966 /** |
| 3967 * Initialize a newly created function body consisting of a block of |
| 3968 * statements. The [keyword] can be `null` if the function body is not an |
| 3969 * async function body. |
| 3970 */ |
| 3971 ExpressionFunctionBodyImpl(this.keyword, this.functionDefinition, |
| 3972 ExpressionImpl expression, this.semicolon) { |
| 3973 _expression = _becomeParentOf(expression); |
| 3974 } |
| 3975 |
| 3976 @override |
| 3977 Token get beginToken { |
| 3978 if (keyword != null) { |
| 3979 return keyword; |
| 3980 } |
| 3981 return functionDefinition; |
| 3982 } |
| 3983 |
| 3984 @override |
| 3985 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 3986 ..add(keyword) |
| 3987 ..add(functionDefinition) |
| 3988 ..add(_expression) |
| 3989 ..add(semicolon); |
| 3990 |
| 3991 @override |
| 3992 Token get endToken { |
| 3993 if (semicolon != null) { |
| 3994 return semicolon; |
| 3995 } |
| 3996 return _expression.endToken; |
| 3997 } |
| 3998 |
| 3999 @override |
| 4000 Expression get expression => _expression; |
| 4001 |
| 4002 @override |
| 4003 void set expression(Expression expression) { |
| 4004 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 4005 } |
| 4006 |
| 4007 @override |
| 4008 bool get isAsynchronous => keyword != null; |
| 4009 |
| 4010 @override |
| 4011 bool get isSynchronous => keyword == null; |
| 4012 |
| 4013 @override |
| 4014 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4015 visitor.visitExpressionFunctionBody(this); |
| 4016 |
| 4017 @override |
| 4018 void visitChildren(AstVisitor visitor) { |
| 4019 _expression?.accept(visitor); |
| 4020 } |
| 4021 } |
| 4022 |
| 4023 /** |
| 4024 * A node that represents an expression. |
| 4025 * |
| 4026 * expression ::= |
| 4027 * [AssignmentExpression] |
| 4028 * | [ConditionalExpression] cascadeSection* |
| 4029 * | [ThrowExpression] |
| 4030 */ |
| 4031 abstract class ExpressionImpl extends AstNodeImpl implements Expression { |
| 4032 /** |
| 4033 * The static type of this expression, or `null` if the AST structure has not |
| 4034 * been resolved. |
| 4035 */ |
| 4036 @override |
| 4037 DartType staticType; |
| 4038 |
| 4039 /** |
| 4040 * The propagated type of this expression, or `null` if type propagation has |
| 4041 * not been performed on the AST structure. |
| 4042 */ |
| 4043 @override |
| 4044 DartType propagatedType; |
| 4045 |
| 4046 /** |
| 4047 * Return the best parameter element information available for this |
| 4048 * expression. If type propagation was able to find a better parameter element |
| 4049 * than static analysis, that type will be returned. Otherwise, the result of |
| 4050 * static analysis will be returned. |
| 4051 */ |
| 4052 ParameterElement get bestParameterElement { |
| 4053 ParameterElement propagatedElement = propagatedParameterElement; |
| 4054 if (propagatedElement != null) { |
| 4055 return propagatedElement; |
| 4056 } |
| 4057 return staticParameterElement; |
| 4058 } |
| 4059 |
| 4060 @override |
| 4061 DartType get bestType { |
| 4062 if (propagatedType != null) { |
| 4063 return propagatedType; |
| 4064 } else if (staticType != null) { |
| 4065 return staticType; |
| 4066 } |
| 4067 return DynamicTypeImpl.instance; |
| 4068 } |
| 4069 |
| 4070 @override |
| 4071 bool get isAssignable => false; |
| 4072 |
| 4073 @override |
| 4074 ParameterElement get propagatedParameterElement { |
| 4075 AstNode parent = this.parent; |
| 4076 if (parent is ArgumentListImpl) { |
| 4077 return parent._getPropagatedParameterElementFor(this); |
| 4078 } else if (parent is IndexExpressionImpl) { |
| 4079 if (identical(parent.index, this)) { |
| 4080 return parent._propagatedParameterElementForIndex; |
| 4081 } |
| 4082 } else if (parent is BinaryExpressionImpl) { |
| 4083 if (identical(parent.rightOperand, this)) { |
| 4084 return parent._propagatedParameterElementForRightOperand; |
| 4085 } |
| 4086 } else if (parent is AssignmentExpressionImpl) { |
| 4087 if (identical(parent.rightHandSide, this)) { |
| 4088 return parent._propagatedParameterElementForRightHandSide; |
| 4089 } |
| 4090 } else if (parent is PrefixExpressionImpl) { |
| 4091 return parent._propagatedParameterElementForOperand; |
| 4092 } else if (parent is PostfixExpressionImpl) { |
| 4093 return parent._propagatedParameterElementForOperand; |
| 4094 } |
| 4095 return null; |
| 4096 } |
| 4097 |
| 4098 @override |
| 4099 ParameterElement get staticParameterElement { |
| 4100 AstNode parent = this.parent; |
| 4101 if (parent is ArgumentListImpl) { |
| 4102 return parent._getStaticParameterElementFor(this); |
| 4103 } else if (parent is IndexExpressionImpl) { |
| 4104 if (identical(parent.index, this)) { |
| 4105 return parent._staticParameterElementForIndex; |
| 4106 } |
| 4107 } else if (parent is BinaryExpressionImpl) { |
| 4108 if (identical(parent.rightOperand, this)) { |
| 4109 return parent._staticParameterElementForRightOperand; |
| 4110 } |
| 4111 } else if (parent is AssignmentExpressionImpl) { |
| 4112 if (identical(parent.rightHandSide, this)) { |
| 4113 return parent._staticParameterElementForRightHandSide; |
| 4114 } |
| 4115 } else if (parent is PrefixExpressionImpl) { |
| 4116 return parent._staticParameterElementForOperand; |
| 4117 } else if (parent is PostfixExpressionImpl) { |
| 4118 return parent._staticParameterElementForOperand; |
| 4119 } |
| 4120 return null; |
| 4121 } |
| 4122 |
| 4123 @override |
| 4124 Expression get unParenthesized => this; |
| 4125 } |
| 4126 |
| 4127 /** |
| 4128 * An expression used as a statement. |
| 4129 * |
| 4130 * expressionStatement ::= |
| 4131 * [Expression]? ';' |
| 4132 */ |
| 4133 class ExpressionStatementImpl extends StatementImpl |
| 4134 implements ExpressionStatement { |
| 4135 /** |
| 4136 * The expression that comprises the statement. |
| 4137 */ |
| 4138 Expression _expression; |
| 4139 |
| 4140 /** |
| 4141 * The semicolon terminating the statement, or `null` if the expression is a |
| 4142 * function expression and therefore isn't followed by a semicolon. |
| 4143 */ |
| 4144 @override |
| 4145 Token semicolon; |
| 4146 |
| 4147 /** |
| 4148 * Initialize a newly created expression statement. |
| 4149 */ |
| 4150 ExpressionStatementImpl(ExpressionImpl expression, this.semicolon) { |
| 4151 _expression = _becomeParentOf(expression); |
| 4152 } |
| 4153 |
| 4154 @override |
| 4155 Token get beginToken => _expression.beginToken; |
| 4156 |
| 4157 @override |
| 4158 Iterable<SyntacticEntity> get childEntities => |
| 4159 new ChildEntities()..add(_expression)..add(semicolon); |
| 4160 |
| 4161 @override |
| 4162 Token get endToken { |
| 4163 if (semicolon != null) { |
| 4164 return semicolon; |
| 4165 } |
| 4166 return _expression.endToken; |
| 4167 } |
| 4168 |
| 4169 @override |
| 4170 Expression get expression => _expression; |
| 4171 |
| 4172 @override |
| 4173 void set expression(Expression expression) { |
| 4174 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 4175 } |
| 4176 |
| 4177 @override |
| 4178 bool get isSynthetic => _expression.isSynthetic && semicolon.isSynthetic; |
| 4179 |
| 4180 @override |
| 4181 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4182 visitor.visitExpressionStatement(this); |
| 4183 |
| 4184 @override |
| 4185 void visitChildren(AstVisitor visitor) { |
| 4186 _expression?.accept(visitor); |
| 4187 } |
| 4188 } |
| 4189 |
| 4190 /** |
| 4191 * The "extends" clause in a class declaration. |
| 4192 * |
| 4193 * extendsClause ::= |
| 4194 * 'extends' [TypeName] |
| 4195 */ |
| 4196 class ExtendsClauseImpl extends AstNodeImpl implements ExtendsClause { |
| 4197 /** |
| 4198 * The token representing the 'extends' keyword. |
| 4199 */ |
| 4200 @override |
| 4201 Token extendsKeyword; |
| 4202 |
| 4203 /** |
| 4204 * The name of the class that is being extended. |
| 4205 */ |
| 4206 TypeName _superclass; |
| 4207 |
| 4208 /** |
| 4209 * Initialize a newly created extends clause. |
| 4210 */ |
| 4211 ExtendsClauseImpl(this.extendsKeyword, TypeNameImpl superclass) { |
| 4212 _superclass = _becomeParentOf(superclass); |
| 4213 } |
| 4214 |
| 4215 @override |
| 4216 Token get beginToken => extendsKeyword; |
| 4217 |
| 4218 @override |
| 4219 Iterable<SyntacticEntity> get childEntities => |
| 4220 new ChildEntities()..add(extendsKeyword)..add(_superclass); |
| 4221 |
| 4222 @override |
| 4223 Token get endToken => _superclass.endToken; |
| 4224 |
| 4225 @override |
| 4226 TypeName get superclass => _superclass; |
| 4227 |
| 4228 @override |
| 4229 void set superclass(TypeName name) { |
| 4230 _superclass = _becomeParentOf(name as AstNodeImpl); |
| 4231 } |
| 4232 |
| 4233 @override |
| 4234 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4235 visitor.visitExtendsClause(this); |
| 4236 |
| 4237 @override |
| 4238 void visitChildren(AstVisitor visitor) { |
| 4239 _superclass?.accept(visitor); |
| 4240 } |
| 4241 } |
| 4242 |
| 4243 /** |
| 4244 * The declaration of one or more fields of the same type. |
| 4245 * |
| 4246 * fieldDeclaration ::= |
| 4247 * 'static'? [VariableDeclarationList] ';' |
| 4248 */ |
| 4249 class FieldDeclarationImpl extends ClassMemberImpl implements FieldDeclaration { |
| 4250 /** |
| 4251 * The token representing the 'static' keyword, or `null` if the fields are |
| 4252 * not static. |
| 4253 */ |
| 4254 @override |
| 4255 Token staticKeyword; |
| 4256 |
| 4257 /** |
| 4258 * The fields being declared. |
| 4259 */ |
| 4260 VariableDeclarationList _fieldList; |
| 4261 |
| 4262 /** |
| 4263 * The semicolon terminating the declaration. |
| 4264 */ |
| 4265 @override |
| 4266 Token semicolon; |
| 4267 |
| 4268 /** |
| 4269 * Initialize a newly created field declaration. Either or both of the |
| 4270 * [comment] and [metadata] can be `null` if the declaration does not have the |
| 4271 * corresponding attribute. The [staticKeyword] can be `null` if the field is |
| 4272 * not a static field. |
| 4273 */ |
| 4274 FieldDeclarationImpl(CommentImpl comment, List<Annotation> metadata, |
| 4275 this.staticKeyword, VariableDeclarationListImpl fieldList, this.semicolon) |
| 4276 : super(comment, metadata) { |
| 4277 _fieldList = _becomeParentOf(fieldList); |
| 4278 } |
| 4279 |
| 4280 @override |
| 4281 Iterable<SyntacticEntity> get childEntities => |
| 4282 super._childEntities..add(staticKeyword)..add(_fieldList)..add(semicolon); |
| 4283 |
| 4284 @override |
| 4285 Token get covariantKeyword => null; |
| 4286 |
| 4287 @override |
| 4288 Element get element => null; |
| 4289 |
| 4290 @override |
| 4291 Token get endToken => semicolon; |
| 4292 |
| 4293 @override |
| 4294 VariableDeclarationList get fields => _fieldList; |
| 4295 |
| 4296 @override |
| 4297 void set fields(VariableDeclarationList fields) { |
| 4298 _fieldList = _becomeParentOf(fields as AstNodeImpl); |
| 4299 } |
| 4300 |
| 4301 @override |
| 4302 Token get firstTokenAfterCommentAndMetadata { |
| 4303 if (staticKeyword != null) { |
| 4304 return staticKeyword; |
| 4305 } |
| 4306 return _fieldList.beginToken; |
| 4307 } |
| 4308 |
| 4309 @override |
| 4310 bool get isStatic => staticKeyword != null; |
| 4311 |
| 4312 @override |
| 4313 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4314 visitor.visitFieldDeclaration(this); |
| 4315 |
| 4316 @override |
| 4317 void visitChildren(AstVisitor visitor) { |
| 4318 super.visitChildren(visitor); |
| 4319 _fieldList?.accept(visitor); |
| 4320 } |
| 4321 } |
| 4322 |
| 4323 /** |
| 4324 * A field formal parameter. |
| 4325 * |
| 4326 * fieldFormalParameter ::= |
| 4327 * ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])? |
| 4328 * 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterLi
st])? |
| 4329 */ |
| 4330 class FieldFormalParameterImpl extends NormalFormalParameterImpl |
| 4331 implements FieldFormalParameter { |
| 4332 /** |
| 4333 * The token representing either the 'final', 'const' or 'var' keyword, or |
| 4334 * `null` if no keyword was used. |
| 4335 */ |
| 4336 @override |
| 4337 Token keyword; |
| 4338 |
| 4339 /** |
| 4340 * The name of the declared type of the parameter, or `null` if the parameter |
| 4341 * does not have a declared type. |
| 4342 */ |
| 4343 TypeName _type; |
| 4344 |
| 4345 /** |
| 4346 * The token representing the 'this' keyword. |
| 4347 */ |
| 4348 @override |
| 4349 Token thisKeyword; |
| 4350 |
| 4351 /** |
| 4352 * The token representing the period. |
| 4353 */ |
| 4354 @override |
| 4355 Token period; |
| 4356 |
| 4357 /** |
| 4358 * The type parameters associated with the method, or `null` if the method is |
| 4359 * not a generic method. |
| 4360 */ |
| 4361 TypeParameterList _typeParameters; |
| 4362 |
| 4363 /** |
| 4364 * The parameters of the function-typed parameter, or `null` if this is not a |
| 4365 * function-typed field formal parameter. |
| 4366 */ |
| 4367 FormalParameterList _parameters; |
| 4368 |
| 4369 /** |
| 4370 * Initialize a newly created formal parameter. Either or both of the |
| 4371 * [comment] and [metadata] can be `null` if the parameter does not have the |
| 4372 * corresponding attribute. The [keyword] can be `null` if there is a type. |
| 4373 * The [type] must be `null` if the keyword is 'var'. The [thisKeyword] and |
| 4374 * [period] can be `null` if the keyword 'this' was not provided. The |
| 4375 * [parameters] can be `null` if this is not a function-typed field formal |
| 4376 * parameter. |
| 4377 */ |
| 4378 FieldFormalParameterImpl( |
| 4379 CommentImpl comment, |
| 4380 List<Annotation> metadata, |
| 4381 this.keyword, |
| 4382 TypeNameImpl type, |
| 4383 this.thisKeyword, |
| 4384 this.period, |
| 4385 SimpleIdentifierImpl identifier, |
| 4386 TypeParameterListImpl typeParameters, |
| 4387 FormalParameterListImpl parameters) |
| 4388 : super(comment, metadata, identifier) { |
| 4389 _type = _becomeParentOf(type); |
| 4390 _typeParameters = _becomeParentOf(typeParameters); |
| 4391 _parameters = _becomeParentOf(parameters); |
| 4392 } |
| 4393 |
| 4394 @override |
| 4395 Token get beginToken { |
| 4396 if (keyword != null) { |
| 4397 return keyword; |
| 4398 } else if (_type != null) { |
| 4399 return _type.beginToken; |
| 4400 } |
| 4401 return thisKeyword; |
| 4402 } |
| 4403 |
| 4404 @override |
| 4405 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 4406 ..add(keyword) |
| 4407 ..add(_type) |
| 4408 ..add(thisKeyword) |
| 4409 ..add(period) |
| 4410 ..add(identifier) |
| 4411 ..add(_parameters); |
| 4412 |
| 4413 @override |
| 4414 Token get endToken { |
| 4415 if (_parameters != null) { |
| 4416 return _parameters.endToken; |
| 4417 } |
| 4418 return identifier.endToken; |
| 4419 } |
| 4420 |
| 4421 @override |
| 4422 bool get isConst => keyword?.keyword == Keyword.CONST; |
| 4423 |
| 4424 @override |
| 4425 bool get isFinal => keyword?.keyword == Keyword.FINAL; |
| 4426 |
| 4427 @override |
| 4428 FormalParameterList get parameters => _parameters; |
| 4429 |
| 4430 @override |
| 4431 void set parameters(FormalParameterList parameters) { |
| 4432 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 4433 } |
| 4434 |
| 4435 @override |
| 4436 TypeName get type => _type; |
| 4437 |
| 4438 @override |
| 4439 void set type(TypeName typeName) { |
| 4440 _type = _becomeParentOf(typeName as AstNodeImpl); |
| 4441 } |
| 4442 |
| 4443 @override |
| 4444 TypeParameterList get typeParameters => _typeParameters; |
| 4445 |
| 4446 @override |
| 4447 void set typeParameters(TypeParameterList typeParameters) { |
| 4448 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 4449 } |
| 4450 |
| 4451 @override |
| 4452 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4453 visitor.visitFieldFormalParameter(this); |
| 4454 |
| 4455 @override |
| 4456 void visitChildren(AstVisitor visitor) { |
| 4457 super.visitChildren(visitor); |
| 4458 _type?.accept(visitor); |
| 4459 identifier?.accept(visitor); |
| 4460 _typeParameters?.accept(visitor); |
| 4461 _parameters?.accept(visitor); |
| 4462 } |
| 4463 } |
| 4464 |
| 4465 /** |
| 4466 * A for-each statement. |
| 4467 * |
| 4468 * forEachStatement ::= |
| 4469 * 'await'? 'for' '(' [DeclaredIdentifier] 'in' [Expression] ')' [Block] |
| 4470 * | 'await'? 'for' '(' [SimpleIdentifier] 'in' [Expression] ')' [Block] |
| 4471 */ |
| 4472 class ForEachStatementImpl extends StatementImpl implements ForEachStatement { |
| 4473 /** |
| 4474 * The token representing the 'await' keyword, or `null` if there is no |
| 4475 * 'await' keyword. |
| 4476 */ |
| 4477 @override |
| 4478 Token awaitKeyword; |
| 4479 |
| 4480 /** |
| 4481 * The token representing the 'for' keyword. |
| 4482 */ |
| 4483 @override |
| 4484 Token forKeyword; |
| 4485 |
| 4486 /** |
| 4487 * The left parenthesis. |
| 4488 */ |
| 4489 @override |
| 4490 Token leftParenthesis; |
| 4491 |
| 4492 /** |
| 4493 * The declaration of the loop variable, or `null` if the loop variable is a |
| 4494 * simple identifier. |
| 4495 */ |
| 4496 DeclaredIdentifier _loopVariable; |
| 4497 |
| 4498 /** |
| 4499 * The loop variable, or `null` if the loop variable is declared in the 'for'. |
| 4500 */ |
| 4501 SimpleIdentifier _identifier; |
| 4502 |
| 4503 /** |
| 4504 * The token representing the 'in' keyword. |
| 4505 */ |
| 4506 @override |
| 4507 Token inKeyword; |
| 4508 |
| 4509 /** |
| 4510 * The expression evaluated to produce the iterator. |
| 4511 */ |
| 4512 Expression _iterable; |
| 4513 |
| 4514 /** |
| 4515 * The right parenthesis. |
| 4516 */ |
| 4517 @override |
| 4518 Token rightParenthesis; |
| 4519 |
| 4520 /** |
| 4521 * The body of the loop. |
| 4522 */ |
| 4523 Statement _body; |
| 4524 |
| 4525 /** |
| 4526 * Initialize a newly created for-each statement whose loop control variable |
| 4527 * is declared internally (in the for-loop part). The [awaitKeyword] can be |
| 4528 * `null` if this is not an asynchronous for loop. |
| 4529 */ |
| 4530 ForEachStatementImpl.withDeclaration( |
| 4531 this.awaitKeyword, |
| 4532 this.forKeyword, |
| 4533 this.leftParenthesis, |
| 4534 DeclaredIdentifierImpl loopVariable, |
| 4535 this.inKeyword, |
| 4536 ExpressionImpl iterator, |
| 4537 this.rightParenthesis, |
| 4538 StatementImpl body) { |
| 4539 _loopVariable = _becomeParentOf(loopVariable); |
| 4540 _iterable = _becomeParentOf(iterator); |
| 4541 _body = _becomeParentOf(body); |
| 4542 } |
| 4543 |
| 4544 /** |
| 4545 * Initialize a newly created for-each statement whose loop control variable |
| 4546 * is declared outside the for loop. The [awaitKeyword] can be `null` if this |
| 4547 * is not an asynchronous for loop. |
| 4548 */ |
| 4549 ForEachStatementImpl.withReference( |
| 4550 this.awaitKeyword, |
| 4551 this.forKeyword, |
| 4552 this.leftParenthesis, |
| 4553 SimpleIdentifierImpl identifier, |
| 4554 this.inKeyword, |
| 4555 ExpressionImpl iterator, |
| 4556 this.rightParenthesis, |
| 4557 StatementImpl body) { |
| 4558 _identifier = _becomeParentOf(identifier); |
| 4559 _iterable = _becomeParentOf(iterator); |
| 4560 _body = _becomeParentOf(body); |
| 4561 } |
| 4562 |
| 4563 @override |
| 4564 Token get beginToken => forKeyword; |
| 4565 |
| 4566 @override |
| 4567 Statement get body => _body; |
| 4568 |
| 4569 @override |
| 4570 void set body(Statement statement) { |
| 4571 _body = _becomeParentOf(statement as AstNodeImpl); |
| 4572 } |
| 4573 |
| 4574 @override |
| 4575 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 4576 ..add(awaitKeyword) |
| 4577 ..add(forKeyword) |
| 4578 ..add(leftParenthesis) |
| 4579 ..add(_loopVariable) |
| 4580 ..add(_identifier) |
| 4581 ..add(inKeyword) |
| 4582 ..add(_iterable) |
| 4583 ..add(rightParenthesis) |
| 4584 ..add(_body); |
| 4585 |
| 4586 @override |
| 4587 Token get endToken => _body.endToken; |
| 4588 |
| 4589 @override |
| 4590 SimpleIdentifier get identifier => _identifier; |
| 4591 |
| 4592 @override |
| 4593 void set identifier(SimpleIdentifier identifier) { |
| 4594 _identifier = _becomeParentOf(identifier as AstNodeImpl); |
| 4595 } |
| 4596 |
| 4597 @override |
| 4598 Expression get iterable => _iterable; |
| 4599 |
| 4600 @override |
| 4601 void set iterable(Expression expression) { |
| 4602 _iterable = _becomeParentOf(expression as AstNodeImpl); |
| 4603 } |
| 4604 |
| 4605 @override |
| 4606 DeclaredIdentifier get loopVariable => _loopVariable; |
| 4607 |
| 4608 @override |
| 4609 void set loopVariable(DeclaredIdentifier variable) { |
| 4610 _loopVariable = _becomeParentOf(variable as AstNodeImpl); |
| 4611 } |
| 4612 |
| 4613 @override |
| 4614 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4615 visitor.visitForEachStatement(this); |
| 4616 |
| 4617 @override |
| 4618 void visitChildren(AstVisitor visitor) { |
| 4619 _loopVariable?.accept(visitor); |
| 4620 _identifier?.accept(visitor); |
| 4621 _iterable?.accept(visitor); |
| 4622 _body?.accept(visitor); |
| 4623 } |
| 4624 } |
| 4625 |
| 4626 /** |
| 4627 * A node representing a parameter to a function. |
| 4628 * |
| 4629 * formalParameter ::= |
| 4630 * [NormalFormalParameter] |
| 4631 * | [DefaultFormalParameter] |
| 4632 */ |
| 4633 abstract class FormalParameterImpl extends AstNodeImpl |
| 4634 implements FormalParameter { |
| 4635 @override |
| 4636 Token get covariantKeyword => null; |
| 4637 |
| 4638 @override |
| 4639 ParameterElement get element { |
| 4640 SimpleIdentifier identifier = this.identifier; |
| 4641 if (identifier == null) { |
| 4642 return null; |
| 4643 } |
| 4644 return identifier.staticElement as ParameterElement; |
| 4645 } |
| 4646 } |
| 4647 |
| 4648 /** |
| 4649 * The formal parameter list of a method declaration, function declaration, or |
| 4650 * function type alias. |
| 4651 * |
| 4652 * While the grammar requires all optional formal parameters to follow all of |
| 4653 * the normal formal parameters and at most one grouping of optional formal |
| 4654 * parameters, this class does not enforce those constraints. All parameters are |
| 4655 * flattened into a single list, which can have any or all kinds of parameters |
| 4656 * (normal, named, and positional) in any order. |
| 4657 * |
| 4658 * formalParameterList ::= |
| 4659 * '(' ')' |
| 4660 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' |
| 4661 * | '(' optionalFormalParameters ')' |
| 4662 * |
| 4663 * normalFormalParameters ::= |
| 4664 * [NormalFormalParameter] (',' [NormalFormalParameter])* |
| 4665 * |
| 4666 * optionalFormalParameters ::= |
| 4667 * optionalPositionalFormalParameters |
| 4668 * | namedFormalParameters |
| 4669 * |
| 4670 * optionalPositionalFormalParameters ::= |
| 4671 * '[' [DefaultFormalParameter] (',' [DefaultFormalParameter])* ']' |
| 4672 * |
| 4673 * namedFormalParameters ::= |
| 4674 * '{' [DefaultFormalParameter] (',' [DefaultFormalParameter])* '}' |
| 4675 */ |
| 4676 class FormalParameterListImpl extends AstNodeImpl |
| 4677 implements FormalParameterList { |
| 4678 /** |
| 4679 * The left parenthesis. |
| 4680 */ |
| 4681 @override |
| 4682 Token leftParenthesis; |
| 4683 |
| 4684 /** |
| 4685 * The parameters associated with the method. |
| 4686 */ |
| 4687 NodeList<FormalParameter> _parameters; |
| 4688 |
| 4689 /** |
| 4690 * The left square bracket ('[') or left curly brace ('{') introducing the |
| 4691 * optional parameters, or `null` if there are no optional parameters. |
| 4692 */ |
| 4693 @override |
| 4694 Token leftDelimiter; |
| 4695 |
| 4696 /** |
| 4697 * The right square bracket (']') or right curly brace ('}') terminating the |
| 4698 * optional parameters, or `null` if there are no optional parameters. |
| 4699 */ |
| 4700 @override |
| 4701 Token rightDelimiter; |
| 4702 |
| 4703 /** |
| 4704 * The right parenthesis. |
| 4705 */ |
| 4706 @override |
| 4707 Token rightParenthesis; |
| 4708 |
| 4709 /** |
| 4710 * Initialize a newly created parameter list. The list of [parameters] can be |
| 4711 * `null` if there are no parameters. The [leftDelimiter] and [rightDelimiter] |
| 4712 * can be `null` if there are no optional parameters. |
| 4713 */ |
| 4714 FormalParameterListImpl( |
| 4715 this.leftParenthesis, |
| 4716 List<FormalParameter> parameters, |
| 4717 this.leftDelimiter, |
| 4718 this.rightDelimiter, |
| 4719 this.rightParenthesis) { |
| 4720 _parameters = new NodeListImpl<FormalParameter>(this, parameters); |
| 4721 } |
| 4722 |
| 4723 @override |
| 4724 Token get beginToken => leftParenthesis; |
| 4725 |
| 4726 @override |
| 4727 Iterable<SyntacticEntity> get childEntities { |
| 4728 // TODO(paulberry): include commas. |
| 4729 ChildEntities result = new ChildEntities()..add(leftParenthesis); |
| 4730 bool leftDelimiterNeeded = leftDelimiter != null; |
| 4731 int length = _parameters.length; |
| 4732 for (int i = 0; i < length; i++) { |
| 4733 FormalParameter parameter = _parameters[i]; |
| 4734 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) { |
| 4735 result.add(leftDelimiter); |
| 4736 leftDelimiterNeeded = false; |
| 4737 } |
| 4738 result.add(parameter); |
| 4739 } |
| 4740 return result..add(rightDelimiter)..add(rightParenthesis); |
| 4741 } |
| 4742 |
| 4743 @override |
| 4744 Token get endToken => rightParenthesis; |
| 4745 |
| 4746 @override |
| 4747 List<ParameterElement> get parameterElements { |
| 4748 int count = _parameters.length; |
| 4749 List<ParameterElement> types = new List<ParameterElement>(count); |
| 4750 for (int i = 0; i < count; i++) { |
| 4751 types[i] = _parameters[i].element; |
| 4752 } |
| 4753 return types; |
| 4754 } |
| 4755 |
| 4756 @override |
| 4757 NodeList<FormalParameter> get parameters => _parameters; |
| 4758 |
| 4759 @override |
| 4760 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4761 visitor.visitFormalParameterList(this); |
| 4762 |
| 4763 @override |
| 4764 void visitChildren(AstVisitor visitor) { |
| 4765 _parameters.accept(visitor); |
| 4766 } |
| 4767 } |
| 4768 |
| 4769 /** |
| 4770 * A for statement. |
| 4771 * |
| 4772 * forStatement ::= |
| 4773 * 'for' '(' forLoopParts ')' [Statement] |
| 4774 * |
| 4775 * forLoopParts ::= |
| 4776 * forInitializerStatement ';' [Expression]? ';' [Expression]? |
| 4777 * |
| 4778 * forInitializerStatement ::= |
| 4779 * [DefaultFormalParameter] |
| 4780 * | [Expression]? |
| 4781 */ |
| 4782 class ForStatementImpl extends StatementImpl implements ForStatement { |
| 4783 /** |
| 4784 * The token representing the 'for' keyword. |
| 4785 */ |
| 4786 @override |
| 4787 Token forKeyword; |
| 4788 |
| 4789 /** |
| 4790 * The left parenthesis. |
| 4791 */ |
| 4792 @override |
| 4793 Token leftParenthesis; |
| 4794 |
| 4795 /** |
| 4796 * The declaration of the loop variables, or `null` if there are no variables. |
| 4797 * Note that a for statement cannot have both a variable list and an |
| 4798 * initialization expression, but can validly have neither. |
| 4799 */ |
| 4800 VariableDeclarationList _variableList; |
| 4801 |
| 4802 /** |
| 4803 * The initialization expression, or `null` if there is no initialization |
| 4804 * expression. Note that a for statement cannot have both a variable list and |
| 4805 * an initialization expression, but can validly have neither. |
| 4806 */ |
| 4807 Expression _initialization; |
| 4808 |
| 4809 /** |
| 4810 * The semicolon separating the initializer and the condition. |
| 4811 */ |
| 4812 @override |
| 4813 Token leftSeparator; |
| 4814 |
| 4815 /** |
| 4816 * The condition used to determine when to terminate the loop, or `null` if |
| 4817 * there is no condition. |
| 4818 */ |
| 4819 Expression _condition; |
| 4820 |
| 4821 /** |
| 4822 * The semicolon separating the condition and the updater. |
| 4823 */ |
| 4824 @override |
| 4825 Token rightSeparator; |
| 4826 |
| 4827 /** |
| 4828 * The list of expressions run after each execution of the loop body. |
| 4829 */ |
| 4830 NodeList<Expression> _updaters; |
| 4831 |
| 4832 /** |
| 4833 * The right parenthesis. |
| 4834 */ |
| 4835 @override |
| 4836 Token rightParenthesis; |
| 4837 |
| 4838 /** |
| 4839 * The body of the loop. |
| 4840 */ |
| 4841 Statement _body; |
| 4842 |
| 4843 /** |
| 4844 * Initialize a newly created for statement. Either the [variableList] or the |
| 4845 * [initialization] must be `null`. Either the [condition] and the list of |
| 4846 * [updaters] can be `null` if the loop does not have the corresponding |
| 4847 * attribute. |
| 4848 */ |
| 4849 ForStatementImpl( |
| 4850 this.forKeyword, |
| 4851 this.leftParenthesis, |
| 4852 VariableDeclarationListImpl variableList, |
| 4853 ExpressionImpl initialization, |
| 4854 this.leftSeparator, |
| 4855 ExpressionImpl condition, |
| 4856 this.rightSeparator, |
| 4857 List<Expression> updaters, |
| 4858 this.rightParenthesis, |
| 4859 StatementImpl body) { |
| 4860 _variableList = _becomeParentOf(variableList); |
| 4861 _initialization = _becomeParentOf(initialization); |
| 4862 _condition = _becomeParentOf(condition); |
| 4863 _updaters = new NodeListImpl<Expression>(this, updaters); |
| 4864 _body = _becomeParentOf(body); |
| 4865 } |
| 4866 |
| 4867 @override |
| 4868 Token get beginToken => forKeyword; |
| 4869 |
| 4870 @override |
| 4871 Statement get body => _body; |
| 4872 |
| 4873 @override |
| 4874 void set body(Statement statement) { |
| 4875 _body = _becomeParentOf(statement as AstNodeImpl); |
| 4876 } |
| 4877 |
| 4878 @override |
| 4879 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 4880 ..add(forKeyword) |
| 4881 ..add(leftParenthesis) |
| 4882 ..add(_variableList) |
| 4883 ..add(_initialization) |
| 4884 ..add(leftSeparator) |
| 4885 ..add(_condition) |
| 4886 ..add(rightSeparator) |
| 4887 ..addAll(_updaters) |
| 4888 ..add(rightParenthesis) |
| 4889 ..add(_body); |
| 4890 |
| 4891 @override |
| 4892 Expression get condition => _condition; |
| 4893 |
| 4894 @override |
| 4895 void set condition(Expression expression) { |
| 4896 _condition = _becomeParentOf(expression as AstNodeImpl); |
| 4897 } |
| 4898 |
| 4899 @override |
| 4900 Token get endToken => _body.endToken; |
| 4901 |
| 4902 @override |
| 4903 Expression get initialization => _initialization; |
| 4904 |
| 4905 @override |
| 4906 void set initialization(Expression initialization) { |
| 4907 _initialization = _becomeParentOf(initialization as AstNodeImpl); |
| 4908 } |
| 4909 |
| 4910 @override |
| 4911 NodeList<Expression> get updaters => _updaters; |
| 4912 |
| 4913 @override |
| 4914 VariableDeclarationList get variables => _variableList; |
| 4915 |
| 4916 @override |
| 4917 void set variables(VariableDeclarationList variableList) { |
| 4918 _variableList = _becomeParentOf(variableList as AstNodeImpl); |
| 4919 } |
| 4920 |
| 4921 @override |
| 4922 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 4923 visitor.visitForStatement(this); |
| 4924 |
| 4925 @override |
| 4926 void visitChildren(AstVisitor visitor) { |
| 4927 _variableList?.accept(visitor); |
| 4928 _initialization?.accept(visitor); |
| 4929 _condition?.accept(visitor); |
| 4930 _updaters.accept(visitor); |
| 4931 _body?.accept(visitor); |
| 4932 } |
| 4933 } |
| 4934 |
| 4935 /** |
| 4936 * A node representing the body of a function or method. |
| 4937 * |
| 4938 * functionBody ::= |
| 4939 * [BlockFunctionBody] |
| 4940 * | [EmptyFunctionBody] |
| 4941 * | [ExpressionFunctionBody] |
| 4942 */ |
| 4943 abstract class FunctionBodyImpl extends AstNodeImpl implements FunctionBody { |
| 4944 /** |
| 4945 * Additional information about local variables and parameters that are |
| 4946 * declared within this function body or any enclosing function body. `null` |
| 4947 * if resolution has not yet been performed. |
| 4948 */ |
| 4949 LocalVariableInfo localVariableInfo; |
| 4950 |
| 4951 /** |
| 4952 * Return `true` if this function body is asynchronous. |
| 4953 */ |
| 4954 @override |
| 4955 bool get isAsynchronous => false; |
| 4956 |
| 4957 /** |
| 4958 * Return `true` if this function body is a generator. |
| 4959 */ |
| 4960 @override |
| 4961 bool get isGenerator => false; |
| 4962 |
| 4963 /** |
| 4964 * Return `true` if this function body is synchronous. |
| 4965 */ |
| 4966 @override |
| 4967 bool get isSynchronous => true; |
| 4968 |
| 4969 /** |
| 4970 * Return the token representing the 'async' or 'sync' keyword, or `null` if |
| 4971 * there is no such keyword. |
| 4972 */ |
| 4973 @override |
| 4974 Token get keyword => null; |
| 4975 |
| 4976 /** |
| 4977 * Return the star following the 'async' or 'sync' keyword, or `null` if there |
| 4978 * is no star. |
| 4979 */ |
| 4980 @override |
| 4981 Token get star => null; |
| 4982 |
| 4983 @override |
| 4984 bool isPotentiallyMutatedInClosure(VariableElement variable) { |
| 4985 if (localVariableInfo == null) { |
| 4986 throw new StateError('Resolution has not yet been performed'); |
| 4987 } |
| 4988 return localVariableInfo.potentiallyMutatedInClosure.contains(variable); |
| 4989 } |
| 4990 |
| 4991 @override |
| 4992 bool isPotentiallyMutatedInScope(VariableElement variable) { |
| 4993 if (localVariableInfo == null) { |
| 4994 throw new StateError('Resolution has not yet been performed'); |
| 4995 } |
| 4996 return localVariableInfo.potentiallyMutatedInScope.contains(variable); |
| 4997 } |
| 4998 } |
| 4999 |
| 5000 /** |
| 5001 * A top-level declaration. |
| 5002 * |
| 5003 * functionDeclaration ::= |
| 5004 * 'external' functionSignature |
| 5005 * | functionSignature [FunctionBody] |
| 5006 * |
| 5007 * functionSignature ::= |
| 5008 * [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList] |
| 5009 */ |
| 5010 class FunctionDeclarationImpl extends NamedCompilationUnitMemberImpl |
| 5011 implements FunctionDeclaration { |
| 5012 /** |
| 5013 * The token representing the 'external' keyword, or `null` if this is not an |
| 5014 * external function. |
| 5015 */ |
| 5016 @override |
| 5017 Token externalKeyword; |
| 5018 |
| 5019 /** |
| 5020 * The return type of the function, or `null` if no return type was declared. |
| 5021 */ |
| 5022 TypeName _returnType; |
| 5023 |
| 5024 /** |
| 5025 * The token representing the 'get' or 'set' keyword, or `null` if this is a |
| 5026 * function declaration rather than a property declaration. |
| 5027 */ |
| 5028 @override |
| 5029 Token propertyKeyword; |
| 5030 |
| 5031 /** |
| 5032 * The function expression being wrapped. |
| 5033 */ |
| 5034 FunctionExpression _functionExpression; |
| 5035 |
| 5036 /** |
| 5037 * Initialize a newly created function declaration. Either or both of the |
| 5038 * [comment] and [metadata] can be `null` if the function does not have the |
| 5039 * corresponding attribute. The [externalKeyword] can be `null` if the |
| 5040 * function is not an external function. The [returnType] can be `null` if no |
| 5041 * return type was specified. The [propertyKeyword] can be `null` if the |
| 5042 * function is neither a getter or a setter. |
| 5043 */ |
| 5044 FunctionDeclarationImpl( |
| 5045 CommentImpl comment, |
| 5046 List<Annotation> metadata, |
| 5047 this.externalKeyword, |
| 5048 TypeNameImpl returnType, |
| 5049 this.propertyKeyword, |
| 5050 SimpleIdentifierImpl name, |
| 5051 FunctionExpressionImpl functionExpression) |
| 5052 : super(comment, metadata, name) { |
| 5053 _returnType = _becomeParentOf(returnType); |
| 5054 _functionExpression = _becomeParentOf(functionExpression); |
| 5055 } |
| 5056 |
| 5057 @override |
| 5058 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 5059 ..add(externalKeyword) |
| 5060 ..add(_returnType) |
| 5061 ..add(propertyKeyword) |
| 5062 ..add(_name) |
| 5063 ..add(_functionExpression); |
| 5064 |
| 5065 @override |
| 5066 ExecutableElement get element => _name?.staticElement as ExecutableElement; |
| 5067 |
| 5068 @override |
| 5069 Token get endToken => _functionExpression.endToken; |
| 5070 |
| 5071 @override |
| 5072 Token get firstTokenAfterCommentAndMetadata { |
| 5073 if (externalKeyword != null) { |
| 5074 return externalKeyword; |
| 5075 } else if (_returnType != null) { |
| 5076 return _returnType.beginToken; |
| 5077 } else if (propertyKeyword != null) { |
| 5078 return propertyKeyword; |
| 5079 } else if (_name != null) { |
| 5080 return _name.beginToken; |
| 5081 } |
| 5082 return _functionExpression.beginToken; |
| 5083 } |
| 5084 |
| 5085 @override |
| 5086 FunctionExpression get functionExpression => _functionExpression; |
| 5087 |
| 5088 @override |
| 5089 void set functionExpression(FunctionExpression functionExpression) { |
| 5090 _functionExpression = _becomeParentOf(functionExpression as AstNodeImpl); |
| 5091 } |
| 5092 |
| 5093 @override |
| 5094 bool get isGetter => propertyKeyword?.keyword == Keyword.GET; |
| 5095 |
| 5096 @override |
| 5097 bool get isSetter => propertyKeyword?.keyword == Keyword.SET; |
| 5098 |
| 5099 @override |
| 5100 TypeName get returnType => _returnType; |
| 5101 |
| 5102 @override |
| 5103 void set returnType(TypeName returnType) { |
| 5104 _returnType = _becomeParentOf(returnType as AstNodeImpl); |
| 5105 } |
| 5106 |
| 5107 @override |
| 5108 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5109 visitor.visitFunctionDeclaration(this); |
| 5110 |
| 5111 @override |
| 5112 void visitChildren(AstVisitor visitor) { |
| 5113 super.visitChildren(visitor); |
| 5114 _returnType?.accept(visitor); |
| 5115 _name?.accept(visitor); |
| 5116 _functionExpression?.accept(visitor); |
| 5117 } |
| 5118 } |
| 5119 |
| 5120 /** |
| 5121 * A [FunctionDeclaration] used as a statement. |
| 5122 */ |
| 5123 class FunctionDeclarationStatementImpl extends StatementImpl |
| 5124 implements FunctionDeclarationStatement { |
| 5125 /** |
| 5126 * The function declaration being wrapped. |
| 5127 */ |
| 5128 FunctionDeclaration _functionDeclaration; |
| 5129 |
| 5130 /** |
| 5131 * Initialize a newly created function declaration statement. |
| 5132 */ |
| 5133 FunctionDeclarationStatementImpl(FunctionDeclaration functionDeclaration) { |
| 5134 _functionDeclaration = _becomeParentOf(functionDeclaration as AstNodeImpl); |
| 5135 } |
| 5136 |
| 5137 @override |
| 5138 Token get beginToken => _functionDeclaration.beginToken; |
| 5139 |
| 5140 @override |
| 5141 Iterable<SyntacticEntity> get childEntities => |
| 5142 new ChildEntities()..add(_functionDeclaration); |
| 5143 |
| 5144 @override |
| 5145 Token get endToken => _functionDeclaration.endToken; |
| 5146 |
| 5147 @override |
| 5148 FunctionDeclaration get functionDeclaration => _functionDeclaration; |
| 5149 |
| 5150 @override |
| 5151 void set functionDeclaration(FunctionDeclaration functionDeclaration) { |
| 5152 _functionDeclaration = _becomeParentOf(functionDeclaration as AstNodeImpl); |
| 5153 } |
| 5154 |
| 5155 @override |
| 5156 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5157 visitor.visitFunctionDeclarationStatement(this); |
| 5158 |
| 5159 @override |
| 5160 void visitChildren(AstVisitor visitor) { |
| 5161 _functionDeclaration?.accept(visitor); |
| 5162 } |
| 5163 } |
| 5164 |
| 5165 /** |
| 5166 * A function expression. |
| 5167 * |
| 5168 * functionExpression ::= |
| 5169 * [TypeParameterList]? [FormalParameterList] [FunctionBody] |
| 5170 */ |
| 5171 class FunctionExpressionImpl extends ExpressionImpl |
| 5172 implements FunctionExpression { |
| 5173 /** |
| 5174 * The type parameters associated with the method, or `null` if the method is |
| 5175 * not a generic method. |
| 5176 */ |
| 5177 TypeParameterList _typeParameters; |
| 5178 |
| 5179 /** |
| 5180 * The parameters associated with the function. |
| 5181 */ |
| 5182 FormalParameterList _parameters; |
| 5183 |
| 5184 /** |
| 5185 * The body of the function, or `null` if this is an external function. |
| 5186 */ |
| 5187 FunctionBody _body; |
| 5188 |
| 5189 /** |
| 5190 * The element associated with the function, or `null` if the AST structure |
| 5191 * has not been resolved. |
| 5192 */ |
| 5193 @override |
| 5194 ExecutableElement element; |
| 5195 |
| 5196 /** |
| 5197 * Initialize a newly created function declaration. |
| 5198 */ |
| 5199 FunctionExpressionImpl(TypeParameterListImpl typeParameters, |
| 5200 FormalParameterListImpl parameters, FunctionBodyImpl body) { |
| 5201 _typeParameters = _becomeParentOf(typeParameters); |
| 5202 _parameters = _becomeParentOf(parameters); |
| 5203 _body = _becomeParentOf(body); |
| 5204 } |
| 5205 |
| 5206 @override |
| 5207 Token get beginToken { |
| 5208 if (_typeParameters != null) { |
| 5209 return _typeParameters.beginToken; |
| 5210 } else if (_parameters != null) { |
| 5211 return _parameters.beginToken; |
| 5212 } else if (_body != null) { |
| 5213 return _body.beginToken; |
| 5214 } |
| 5215 // This should never be reached because external functions must be named, |
| 5216 // hence either the body or the name should be non-null. |
| 5217 throw new StateError("Non-external functions must have a body"); |
| 5218 } |
| 5219 |
| 5220 @override |
| 5221 FunctionBody get body => _body; |
| 5222 |
| 5223 @override |
| 5224 void set body(FunctionBody functionBody) { |
| 5225 _body = _becomeParentOf(functionBody as AstNodeImpl); |
| 5226 } |
| 5227 |
| 5228 @override |
| 5229 Iterable<SyntacticEntity> get childEntities => |
| 5230 new ChildEntities()..add(_parameters)..add(_body); |
| 5231 |
| 5232 @override |
| 5233 Token get endToken { |
| 5234 if (_body != null) { |
| 5235 return _body.endToken; |
| 5236 } else if (_parameters != null) { |
| 5237 return _parameters.endToken; |
| 5238 } |
| 5239 // This should never be reached because external functions must be named, |
| 5240 // hence either the body or the name should be non-null. |
| 5241 throw new StateError("Non-external functions must have a body"); |
| 5242 } |
| 5243 |
| 5244 @override |
| 5245 FormalParameterList get parameters => _parameters; |
| 5246 |
| 5247 @override |
| 5248 void set parameters(FormalParameterList parameters) { |
| 5249 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 5250 } |
| 5251 |
| 5252 @override |
| 5253 int get precedence => 16; |
| 5254 |
| 5255 @override |
| 5256 TypeParameterList get typeParameters => _typeParameters; |
| 5257 |
| 5258 @override |
| 5259 void set typeParameters(TypeParameterList typeParameters) { |
| 5260 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 5261 } |
| 5262 |
| 5263 @override |
| 5264 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5265 visitor.visitFunctionExpression(this); |
| 5266 |
| 5267 @override |
| 5268 void visitChildren(AstVisitor visitor) { |
| 5269 _typeParameters?.accept(visitor); |
| 5270 _parameters?.accept(visitor); |
| 5271 _body?.accept(visitor); |
| 5272 } |
| 5273 } |
| 5274 |
| 5275 /** |
| 5276 * The invocation of a function resulting from evaluating an expression. |
| 5277 * Invocations of methods and other forms of functions are represented by |
| 5278 * [MethodInvocation] nodes. Invocations of getters and setters are represented |
| 5279 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. |
| 5280 * |
| 5281 * functionExpressionInvocation ::= |
| 5282 * [Expression] [TypeArgumentList]? [ArgumentList] |
| 5283 */ |
| 5284 class FunctionExpressionInvocationImpl extends InvocationExpressionImpl |
| 5285 implements FunctionExpressionInvocation { |
| 5286 /** |
| 5287 * The expression producing the function being invoked. |
| 5288 */ |
| 5289 Expression _function; |
| 5290 |
| 5291 /** |
| 5292 * The element associated with the function being invoked based on static type |
| 5293 * information, or `null` if the AST structure has not been resolved or the |
| 5294 * function could not be resolved. |
| 5295 */ |
| 5296 @override |
| 5297 ExecutableElement staticElement; |
| 5298 |
| 5299 /** |
| 5300 * The element associated with the function being invoked based on propagated |
| 5301 * type information, or `null` if the AST structure has not been resolved or |
| 5302 * the function could not be resolved. |
| 5303 */ |
| 5304 @override |
| 5305 ExecutableElement propagatedElement; |
| 5306 |
| 5307 /** |
| 5308 * Initialize a newly created function expression invocation. |
| 5309 */ |
| 5310 FunctionExpressionInvocationImpl(ExpressionImpl function, |
| 5311 TypeArgumentListImpl typeArguments, ArgumentListImpl argumentList) |
| 5312 : super(typeArguments, argumentList) { |
| 5313 _function = _becomeParentOf(function); |
| 5314 } |
| 5315 |
| 5316 @override |
| 5317 Token get beginToken => _function.beginToken; |
| 5318 |
| 5319 @override |
| 5320 ExecutableElement get bestElement { |
| 5321 ExecutableElement element = propagatedElement; |
| 5322 if (element == null) { |
| 5323 element = staticElement; |
| 5324 } |
| 5325 return element; |
| 5326 } |
| 5327 |
| 5328 @override |
| 5329 Iterable<SyntacticEntity> get childEntities => |
| 5330 new ChildEntities()..add(_function)..add(_argumentList); |
| 5331 |
| 5332 @override |
| 5333 Token get endToken => _argumentList.endToken; |
| 5334 |
| 5335 @override |
| 5336 Expression get function => _function; |
| 5337 |
| 5338 @override |
| 5339 void set function(Expression expression) { |
| 5340 _function = _becomeParentOf(expression as AstNodeImpl); |
| 5341 } |
| 5342 |
| 5343 @override |
| 5344 int get precedence => 15; |
| 5345 |
| 5346 @override |
| 5347 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5348 visitor.visitFunctionExpressionInvocation(this); |
| 5349 |
| 5350 @override |
| 5351 void visitChildren(AstVisitor visitor) { |
| 5352 _function?.accept(visitor); |
| 5353 _typeArguments?.accept(visitor); |
| 5354 _argumentList?.accept(visitor); |
| 5355 } |
| 5356 } |
| 5357 |
| 5358 /** |
| 5359 * A function type alias. |
| 5360 * |
| 5361 * functionTypeAlias ::= |
| 5362 * functionPrefix [TypeParameterList]? [FormalParameterList] ';' |
| 5363 * |
| 5364 * functionPrefix ::= |
| 5365 * [TypeName]? [SimpleIdentifier] |
| 5366 */ |
| 5367 class FunctionTypeAliasImpl extends TypeAliasImpl implements FunctionTypeAlias { |
| 5368 /** |
| 5369 * The name of the return type of the function type being defined, or `null` |
| 5370 * if no return type was given. |
| 5371 */ |
| 5372 TypeName _returnType; |
| 5373 |
| 5374 /** |
| 5375 * The type parameters for the function type, or `null` if the function type |
| 5376 * does not have any type parameters. |
| 5377 */ |
| 5378 TypeParameterList _typeParameters; |
| 5379 |
| 5380 /** |
| 5381 * The parameters associated with the function type. |
| 5382 */ |
| 5383 FormalParameterList _parameters; |
| 5384 |
| 5385 /** |
| 5386 * Initialize a newly created function type alias. Either or both of the |
| 5387 * [comment] and [metadata] can be `null` if the function does not have the |
| 5388 * corresponding attribute. The [returnType] can be `null` if no return type |
| 5389 * was specified. The [typeParameters] can be `null` if the function has no |
| 5390 * type parameters. |
| 5391 */ |
| 5392 FunctionTypeAliasImpl( |
| 5393 CommentImpl comment, |
| 5394 List<Annotation> metadata, |
| 5395 Token keyword, |
| 5396 TypeNameImpl returnType, |
| 5397 SimpleIdentifierImpl name, |
| 5398 TypeParameterListImpl typeParameters, |
| 5399 FormalParameterListImpl parameters, |
| 5400 Token semicolon) |
| 5401 : super(comment, metadata, keyword, name, semicolon) { |
| 5402 _returnType = _becomeParentOf(returnType); |
| 5403 _typeParameters = _becomeParentOf(typeParameters); |
| 5404 _parameters = _becomeParentOf(parameters); |
| 5405 } |
| 5406 |
| 5407 @override |
| 5408 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 5409 ..add(typedefKeyword) |
| 5410 ..add(_returnType) |
| 5411 ..add(_name) |
| 5412 ..add(_typeParameters) |
| 5413 ..add(_parameters) |
| 5414 ..add(semicolon); |
| 5415 |
| 5416 @override |
| 5417 FunctionTypeAliasElement get element => |
| 5418 _name?.staticElement as FunctionTypeAliasElement; |
| 5419 |
| 5420 @override |
| 5421 FormalParameterList get parameters => _parameters; |
| 5422 |
| 5423 @override |
| 5424 void set parameters(FormalParameterList parameters) { |
| 5425 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 5426 } |
| 5427 |
| 5428 @override |
| 5429 TypeName get returnType => _returnType; |
| 5430 |
| 5431 @override |
| 5432 void set returnType(TypeName typeName) { |
| 5433 _returnType = _becomeParentOf(typeName as AstNodeImpl); |
| 5434 } |
| 5435 |
| 5436 @override |
| 5437 TypeParameterList get typeParameters => _typeParameters; |
| 5438 |
| 5439 @override |
| 5440 void set typeParameters(TypeParameterList typeParameters) { |
| 5441 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 5442 } |
| 5443 |
| 5444 @override |
| 5445 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5446 visitor.visitFunctionTypeAlias(this); |
| 5447 |
| 5448 @override |
| 5449 void visitChildren(AstVisitor visitor) { |
| 5450 super.visitChildren(visitor); |
| 5451 _returnType?.accept(visitor); |
| 5452 _name?.accept(visitor); |
| 5453 _typeParameters?.accept(visitor); |
| 5454 _parameters?.accept(visitor); |
| 5455 } |
| 5456 } |
| 5457 |
| 5458 /** |
| 5459 * A function-typed formal parameter. |
| 5460 * |
| 5461 * functionSignature ::= |
| 5462 * [TypeName]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterLi
st] |
| 5463 */ |
| 5464 class FunctionTypedFormalParameterImpl extends NormalFormalParameterImpl |
| 5465 implements FunctionTypedFormalParameter { |
| 5466 /** |
| 5467 * The return type of the function, or `null` if the function does not have a |
| 5468 * return type. |
| 5469 */ |
| 5470 TypeName _returnType; |
| 5471 |
| 5472 /** |
| 5473 * The type parameters associated with the function, or `null` if the function |
| 5474 * is not a generic function. |
| 5475 */ |
| 5476 TypeParameterList _typeParameters; |
| 5477 |
| 5478 /** |
| 5479 * The parameters of the function-typed parameter. |
| 5480 */ |
| 5481 FormalParameterList _parameters; |
| 5482 |
| 5483 @override |
| 5484 Token question; |
| 5485 |
| 5486 /** |
| 5487 * Initialize a newly created formal parameter. Either or both of the |
| 5488 * [comment] and [metadata] can be `null` if the parameter does not have the |
| 5489 * corresponding attribute. The [returnType] can be `null` if no return type |
| 5490 * was specified. |
| 5491 */ |
| 5492 FunctionTypedFormalParameterImpl( |
| 5493 CommentImpl comment, |
| 5494 List<Annotation> metadata, |
| 5495 TypeNameImpl returnType, |
| 5496 SimpleIdentifierImpl identifier, |
| 5497 TypeParameterListImpl typeParameters, |
| 5498 FormalParameterListImpl parameters, |
| 5499 this.question) |
| 5500 : super(comment, metadata, identifier) { |
| 5501 _returnType = _becomeParentOf(returnType); |
| 5502 _typeParameters = _becomeParentOf(typeParameters); |
| 5503 _parameters = _becomeParentOf(parameters); |
| 5504 } |
| 5505 |
| 5506 @override |
| 5507 Token get beginToken { |
| 5508 if (_returnType != null) { |
| 5509 return _returnType.beginToken; |
| 5510 } |
| 5511 return identifier.beginToken; |
| 5512 } |
| 5513 |
| 5514 @override |
| 5515 Iterable<SyntacticEntity> get childEntities => |
| 5516 super._childEntities..add(_returnType)..add(identifier)..add(parameters); |
| 5517 |
| 5518 @override |
| 5519 Token get endToken => _parameters.endToken; |
| 5520 |
| 5521 @override |
| 5522 bool get isConst => false; |
| 5523 |
| 5524 @override |
| 5525 bool get isFinal => false; |
| 5526 |
| 5527 @override |
| 5528 FormalParameterList get parameters => _parameters; |
| 5529 |
| 5530 @override |
| 5531 void set parameters(FormalParameterList parameters) { |
| 5532 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 5533 } |
| 5534 |
| 5535 @override |
| 5536 TypeName get returnType => _returnType; |
| 5537 |
| 5538 @override |
| 5539 void set returnType(TypeName type) { |
| 5540 _returnType = _becomeParentOf(type as AstNodeImpl); |
| 5541 } |
| 5542 |
| 5543 @override |
| 5544 TypeParameterList get typeParameters => _typeParameters; |
| 5545 |
| 5546 @override |
| 5547 void set typeParameters(TypeParameterList typeParameters) { |
| 5548 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 5549 } |
| 5550 |
| 5551 @override |
| 5552 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5553 visitor.visitFunctionTypedFormalParameter(this); |
| 5554 |
| 5555 @override |
| 5556 void visitChildren(AstVisitor visitor) { |
| 5557 super.visitChildren(visitor); |
| 5558 _returnType?.accept(visitor); |
| 5559 identifier?.accept(visitor); |
| 5560 _typeParameters?.accept(visitor); |
| 5561 _parameters?.accept(visitor); |
| 5562 } |
| 5563 } |
| 5564 |
| 5565 /** |
| 5566 * A combinator that restricts the names being imported to those that are not in |
| 5567 * a given list. |
| 5568 * |
| 5569 * hideCombinator ::= |
| 5570 * 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])* |
| 5571 */ |
| 5572 class HideCombinatorImpl extends CombinatorImpl implements HideCombinator { |
| 5573 /** |
| 5574 * The list of names from the library that are hidden by this combinator. |
| 5575 */ |
| 5576 NodeList<SimpleIdentifier> _hiddenNames; |
| 5577 |
| 5578 /** |
| 5579 * Initialize a newly created import show combinator. |
| 5580 */ |
| 5581 HideCombinatorImpl(Token keyword, List<SimpleIdentifier> hiddenNames) |
| 5582 : super(keyword) { |
| 5583 _hiddenNames = new NodeListImpl<SimpleIdentifier>(this, hiddenNames); |
| 5584 } |
| 5585 |
| 5586 @override |
| 5587 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 5588 ..add(keyword) |
| 5589 ..addAll(_hiddenNames); |
| 5590 |
| 5591 @override |
| 5592 Token get endToken => _hiddenNames.endToken; |
| 5593 |
| 5594 @override |
| 5595 NodeList<SimpleIdentifier> get hiddenNames => _hiddenNames; |
| 5596 |
| 5597 @override |
| 5598 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5599 visitor.visitHideCombinator(this); |
| 5600 |
| 5601 @override |
| 5602 void visitChildren(AstVisitor visitor) { |
| 5603 _hiddenNames.accept(visitor); |
| 5604 } |
| 5605 } |
| 5606 |
| 5607 /** |
| 5608 * A node that represents an identifier. |
| 5609 * |
| 5610 * identifier ::= |
| 5611 * [SimpleIdentifier] |
| 5612 * | [PrefixedIdentifier] |
| 5613 */ |
| 5614 abstract class IdentifierImpl extends ExpressionImpl implements Identifier { |
| 5615 /** |
| 5616 * Return the best element available for this operator. If resolution was able |
| 5617 * to find a better element based on type propagation, that element will be |
| 5618 * returned. Otherwise, the element found using the result of static analysis |
| 5619 * will be returned. If resolution has not been performed, then `null` will be |
| 5620 * returned. |
| 5621 */ |
| 5622 Element get bestElement; |
| 5623 |
| 5624 @override |
| 5625 bool get isAssignable => true; |
| 5626 } |
| 5627 |
| 5628 /** |
| 5629 * An if statement. |
| 5630 * |
| 5631 * ifStatement ::= |
| 5632 * 'if' '(' [Expression] ')' [Statement] ('else' [Statement])? |
| 5633 */ |
| 5634 class IfStatementImpl extends StatementImpl implements IfStatement { |
| 5635 /** |
| 5636 * The token representing the 'if' keyword. |
| 5637 */ |
| 5638 @override |
| 5639 Token ifKeyword; |
| 5640 |
| 5641 /** |
| 5642 * The left parenthesis. |
| 5643 */ |
| 5644 @override |
| 5645 Token leftParenthesis; |
| 5646 |
| 5647 /** |
| 5648 * The condition used to determine which of the statements is executed next. |
| 5649 */ |
| 5650 Expression _condition; |
| 5651 |
| 5652 /** |
| 5653 * The right parenthesis. |
| 5654 */ |
| 5655 @override |
| 5656 Token rightParenthesis; |
| 5657 |
| 5658 /** |
| 5659 * The statement that is executed if the condition evaluates to `true`. |
| 5660 */ |
| 5661 Statement _thenStatement; |
| 5662 |
| 5663 /** |
| 5664 * The token representing the 'else' keyword, or `null` if there is no else |
| 5665 * statement. |
| 5666 */ |
| 5667 @override |
| 5668 Token elseKeyword; |
| 5669 |
| 5670 /** |
| 5671 * The statement that is executed if the condition evaluates to `false`, or |
| 5672 * `null` if there is no else statement. |
| 5673 */ |
| 5674 Statement _elseStatement; |
| 5675 |
| 5676 /** |
| 5677 * Initialize a newly created if statement. The [elseKeyword] and |
| 5678 * [elseStatement] can be `null` if there is no else clause. |
| 5679 */ |
| 5680 IfStatementImpl( |
| 5681 this.ifKeyword, |
| 5682 this.leftParenthesis, |
| 5683 ExpressionImpl condition, |
| 5684 this.rightParenthesis, |
| 5685 StatementImpl thenStatement, |
| 5686 this.elseKeyword, |
| 5687 StatementImpl elseStatement) { |
| 5688 _condition = _becomeParentOf(condition); |
| 5689 _thenStatement = _becomeParentOf(thenStatement); |
| 5690 _elseStatement = _becomeParentOf(elseStatement); |
| 5691 } |
| 5692 |
| 5693 @override |
| 5694 Token get beginToken => ifKeyword; |
| 5695 |
| 5696 @override |
| 5697 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 5698 ..add(ifKeyword) |
| 5699 ..add(leftParenthesis) |
| 5700 ..add(_condition) |
| 5701 ..add(rightParenthesis) |
| 5702 ..add(_thenStatement) |
| 5703 ..add(elseKeyword) |
| 5704 ..add(_elseStatement); |
| 5705 |
| 5706 @override |
| 5707 Expression get condition => _condition; |
| 5708 |
| 5709 @override |
| 5710 void set condition(Expression expression) { |
| 5711 _condition = _becomeParentOf(expression as AstNodeImpl); |
| 5712 } |
| 5713 |
| 5714 @override |
| 5715 Statement get elseStatement => _elseStatement; |
| 5716 |
| 5717 @override |
| 5718 void set elseStatement(Statement statement) { |
| 5719 _elseStatement = _becomeParentOf(statement as AstNodeImpl); |
| 5720 } |
| 5721 |
| 5722 @override |
| 5723 Token get endToken { |
| 5724 if (_elseStatement != null) { |
| 5725 return _elseStatement.endToken; |
| 5726 } |
| 5727 return _thenStatement.endToken; |
| 5728 } |
| 5729 |
| 5730 @override |
| 5731 Statement get thenStatement => _thenStatement; |
| 5732 |
| 5733 @override |
| 5734 void set thenStatement(Statement statement) { |
| 5735 _thenStatement = _becomeParentOf(statement as AstNodeImpl); |
| 5736 } |
| 5737 |
| 5738 @override |
| 5739 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5740 visitor.visitIfStatement(this); |
| 5741 |
| 5742 @override |
| 5743 void visitChildren(AstVisitor visitor) { |
| 5744 _condition?.accept(visitor); |
| 5745 _thenStatement?.accept(visitor); |
| 5746 _elseStatement?.accept(visitor); |
| 5747 } |
| 5748 } |
| 5749 |
| 5750 /** |
| 5751 * The "implements" clause in an class declaration. |
| 5752 * |
| 5753 * implementsClause ::= |
| 5754 * 'implements' [TypeName] (',' [TypeName])* |
| 5755 */ |
| 5756 class ImplementsClauseImpl extends AstNodeImpl implements ImplementsClause { |
| 5757 /** |
| 5758 * The token representing the 'implements' keyword. |
| 5759 */ |
| 5760 @override |
| 5761 Token implementsKeyword; |
| 5762 |
| 5763 /** |
| 5764 * The interfaces that are being implemented. |
| 5765 */ |
| 5766 NodeList<TypeName> _interfaces; |
| 5767 |
| 5768 /** |
| 5769 * Initialize a newly created implements clause. |
| 5770 */ |
| 5771 ImplementsClauseImpl(this.implementsKeyword, List<TypeName> interfaces) { |
| 5772 _interfaces = new NodeListImpl<TypeName>(this, interfaces); |
| 5773 } |
| 5774 |
| 5775 @override |
| 5776 Token get beginToken => implementsKeyword; |
| 5777 |
| 5778 @override |
| 5779 // TODO(paulberry): add commas. |
| 5780 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 5781 ..add(implementsKeyword) |
| 5782 ..addAll(interfaces); |
| 5783 |
| 5784 @override |
| 5785 Token get endToken => _interfaces.endToken; |
| 5786 |
| 5787 @override |
| 5788 NodeList<TypeName> get interfaces => _interfaces; |
| 5789 |
| 5790 @override |
| 5791 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5792 visitor.visitImplementsClause(this); |
| 5793 |
| 5794 @override |
| 5795 void visitChildren(AstVisitor visitor) { |
| 5796 _interfaces.accept(visitor); |
| 5797 } |
| 5798 } |
| 5799 |
| 5800 /** |
| 5801 * An import directive. |
| 5802 * |
| 5803 * importDirective ::= |
| 5804 * [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]*
';' |
| 5805 * | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Comb
inator]* ';' |
| 5806 */ |
| 5807 class ImportDirectiveImpl extends NamespaceDirectiveImpl |
| 5808 implements ImportDirective { |
| 5809 /** |
| 5810 * The token representing the 'deferred' keyword, or `null` if the imported is |
| 5811 * not deferred. |
| 5812 */ |
| 5813 Token deferredKeyword; |
| 5814 |
| 5815 /** |
| 5816 * The token representing the 'as' keyword, or `null` if the imported names ar
e |
| 5817 * not prefixed. |
| 5818 */ |
| 5819 @override |
| 5820 Token asKeyword; |
| 5821 |
| 5822 /** |
| 5823 * The prefix to be used with the imported names, or `null` if the imported |
| 5824 * names are not prefixed. |
| 5825 */ |
| 5826 SimpleIdentifier _prefix; |
| 5827 |
| 5828 /** |
| 5829 * Initialize a newly created import directive. Either or both of the |
| 5830 * [comment] and [metadata] can be `null` if the function does not have the |
| 5831 * corresponding attribute. The [deferredKeyword] can be `null` if the import |
| 5832 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import |
| 5833 * does not specify a prefix. The list of [combinators] can be `null` if there |
| 5834 * are no combinators. |
| 5835 */ |
| 5836 ImportDirectiveImpl( |
| 5837 CommentImpl comment, |
| 5838 List<Annotation> metadata, |
| 5839 Token keyword, |
| 5840 StringLiteralImpl libraryUri, |
| 5841 List<Configuration> configurations, |
| 5842 this.deferredKeyword, |
| 5843 this.asKeyword, |
| 5844 SimpleIdentifierImpl prefix, |
| 5845 List<Combinator> combinators, |
| 5846 Token semicolon) |
| 5847 : super(comment, metadata, keyword, libraryUri, configurations, |
| 5848 combinators, semicolon) { |
| 5849 _prefix = _becomeParentOf(prefix); |
| 5850 } |
| 5851 |
| 5852 @override |
| 5853 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 5854 ..add(_uri) |
| 5855 ..add(deferredKeyword) |
| 5856 ..add(asKeyword) |
| 5857 ..add(_prefix) |
| 5858 ..addAll(combinators) |
| 5859 ..add(semicolon); |
| 5860 |
| 5861 @override |
| 5862 ImportElement get element => super.element as ImportElement; |
| 5863 |
| 5864 @override |
| 5865 SimpleIdentifier get prefix => _prefix; |
| 5866 |
| 5867 @override |
| 5868 void set prefix(SimpleIdentifier identifier) { |
| 5869 _prefix = _becomeParentOf(identifier as AstNodeImpl); |
| 5870 } |
| 5871 |
| 5872 @override |
| 5873 LibraryElement get uriElement { |
| 5874 ImportElement element = this.element; |
| 5875 if (element == null) { |
| 5876 return null; |
| 5877 } |
| 5878 return element.importedLibrary; |
| 5879 } |
| 5880 |
| 5881 @override |
| 5882 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 5883 visitor.visitImportDirective(this); |
| 5884 |
| 5885 @override |
| 5886 void visitChildren(AstVisitor visitor) { |
| 5887 super.visitChildren(visitor); |
| 5888 _prefix?.accept(visitor); |
| 5889 combinators.accept(visitor); |
| 5890 } |
| 5891 } |
| 5892 |
| 5893 /** |
| 5894 * An index expression. |
| 5895 * |
| 5896 * indexExpression ::= |
| 5897 * [Expression] '[' [Expression] ']' |
| 5898 */ |
| 5899 class IndexExpressionImpl extends ExpressionImpl implements IndexExpression { |
| 5900 /** |
| 5901 * The expression used to compute the object being indexed, or `null` if this |
| 5902 * index expression is part of a cascade expression. |
| 5903 */ |
| 5904 Expression _target; |
| 5905 |
| 5906 /** |
| 5907 * The period ("..") before a cascaded index expression, or `null` if this |
| 5908 * index expression is not part of a cascade expression. |
| 5909 */ |
| 5910 @override |
| 5911 Token period; |
| 5912 |
| 5913 /** |
| 5914 * The left square bracket. |
| 5915 */ |
| 5916 @override |
| 5917 Token leftBracket; |
| 5918 |
| 5919 /** |
| 5920 * The expression used to compute the index. |
| 5921 */ |
| 5922 Expression _index; |
| 5923 |
| 5924 /** |
| 5925 * The right square bracket. |
| 5926 */ |
| 5927 @override |
| 5928 Token rightBracket; |
| 5929 |
| 5930 /** |
| 5931 * The element associated with the operator based on the static type of the |
| 5932 * target, or `null` if the AST structure has not been resolved or if the |
| 5933 * operator could not be resolved. |
| 5934 */ |
| 5935 @override |
| 5936 MethodElement staticElement; |
| 5937 |
| 5938 /** |
| 5939 * The element associated with the operator based on the propagated type of |
| 5940 * the target, or `null` if the AST structure has not been resolved or if the |
| 5941 * operator could not be resolved. |
| 5942 */ |
| 5943 |
| 5944 @override |
| 5945 MethodElement propagatedElement; |
| 5946 |
| 5947 /** |
| 5948 * If this expression is both in a getter and setter context, the |
| 5949 * [AuxiliaryElements] will be set to hold onto the static and propagated |
| 5950 * information. The auxiliary element will hold onto the elements from the |
| 5951 * getter context. |
| 5952 */ |
| 5953 AuxiliaryElements auxiliaryElements = null; |
| 5954 |
| 5955 /** |
| 5956 * Initialize a newly created index expression. |
| 5957 */ |
| 5958 IndexExpressionImpl.forCascade( |
| 5959 this.period, this.leftBracket, ExpressionImpl index, this.rightBracket) { |
| 5960 _index = _becomeParentOf(index); |
| 5961 } |
| 5962 |
| 5963 /** |
| 5964 * Initialize a newly created index expression. |
| 5965 */ |
| 5966 IndexExpressionImpl.forTarget(ExpressionImpl target, this.leftBracket, |
| 5967 ExpressionImpl index, this.rightBracket) { |
| 5968 _target = _becomeParentOf(target); |
| 5969 _index = _becomeParentOf(index); |
| 5970 } |
| 5971 |
| 5972 @override |
| 5973 Token get beginToken { |
| 5974 if (_target != null) { |
| 5975 return _target.beginToken; |
| 5976 } |
| 5977 return period; |
| 5978 } |
| 5979 |
| 5980 @override |
| 5981 MethodElement get bestElement { |
| 5982 MethodElement element = propagatedElement; |
| 5983 if (element == null) { |
| 5984 element = staticElement; |
| 5985 } |
| 5986 return element; |
| 5987 } |
| 5988 |
| 5989 @override |
| 5990 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 5991 ..add(_target) |
| 5992 ..add(period) |
| 5993 ..add(leftBracket) |
| 5994 ..add(_index) |
| 5995 ..add(rightBracket); |
| 5996 |
| 5997 @override |
| 5998 Token get endToken => rightBracket; |
| 5999 |
| 6000 @override |
| 6001 Expression get index => _index; |
| 6002 |
| 6003 @override |
| 6004 void set index(Expression expression) { |
| 6005 _index = _becomeParentOf(expression as AstNodeImpl); |
| 6006 } |
| 6007 |
| 6008 @override |
| 6009 bool get isAssignable => true; |
| 6010 |
| 6011 @override |
| 6012 bool get isCascaded => period != null; |
| 6013 |
| 6014 @override |
| 6015 int get precedence => 15; |
| 6016 |
| 6017 @override |
| 6018 Expression get realTarget { |
| 6019 if (isCascaded) { |
| 6020 AstNode ancestor = parent; |
| 6021 while (ancestor is! CascadeExpression) { |
| 6022 if (ancestor == null) { |
| 6023 return _target; |
| 6024 } |
| 6025 ancestor = ancestor.parent; |
| 6026 } |
| 6027 return (ancestor as CascadeExpression).target; |
| 6028 } |
| 6029 return _target; |
| 6030 } |
| 6031 |
| 6032 @override |
| 6033 Expression get target => _target; |
| 6034 |
| 6035 @override |
| 6036 void set target(Expression expression) { |
| 6037 _target = _becomeParentOf(expression as AstNodeImpl); |
| 6038 } |
| 6039 |
| 6040 /** |
| 6041 * If the AST structure has been resolved, and the function being invoked is |
| 6042 * known based on propagated type information, then return the parameter |
| 6043 * element representing the parameter to which the value of the index |
| 6044 * expression will be bound. Otherwise, return `null`. |
| 6045 */ |
| 6046 ParameterElement get _propagatedParameterElementForIndex { |
| 6047 if (propagatedElement == null) { |
| 6048 return null; |
| 6049 } |
| 6050 List<ParameterElement> parameters = propagatedElement.parameters; |
| 6051 if (parameters.length < 1) { |
| 6052 return null; |
| 6053 } |
| 6054 return parameters[0]; |
| 6055 } |
| 6056 |
| 6057 /** |
| 6058 * If the AST structure has been resolved, and the function being invoked is |
| 6059 * known based on static type information, then return the parameter element |
| 6060 * representing the parameter to which the value of the index expression will |
| 6061 * be bound. Otherwise, return `null`. |
| 6062 */ |
| 6063 ParameterElement get _staticParameterElementForIndex { |
| 6064 if (staticElement == null) { |
| 6065 return null; |
| 6066 } |
| 6067 List<ParameterElement> parameters = staticElement.parameters; |
| 6068 if (parameters.length < 1) { |
| 6069 return null; |
| 6070 } |
| 6071 return parameters[0]; |
| 6072 } |
| 6073 |
| 6074 @override |
| 6075 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6076 visitor.visitIndexExpression(this); |
| 6077 |
| 6078 @override |
| 6079 bool inGetterContext() { |
| 6080 // TODO(brianwilkerson) Convert this to a getter. |
| 6081 AstNode parent = this.parent; |
| 6082 if (parent is AssignmentExpression) { |
| 6083 AssignmentExpression assignment = parent; |
| 6084 if (identical(assignment.leftHandSide, this) && |
| 6085 assignment.operator.type == TokenType.EQ) { |
| 6086 return false; |
| 6087 } |
| 6088 } |
| 6089 return true; |
| 6090 } |
| 6091 |
| 6092 @override |
| 6093 bool inSetterContext() { |
| 6094 // TODO(brianwilkerson) Convert this to a getter. |
| 6095 AstNode parent = this.parent; |
| 6096 if (parent is PrefixExpression) { |
| 6097 return parent.operator.type.isIncrementOperator; |
| 6098 } else if (parent is PostfixExpression) { |
| 6099 return true; |
| 6100 } else if (parent is AssignmentExpression) { |
| 6101 return identical(parent.leftHandSide, this); |
| 6102 } |
| 6103 return false; |
| 6104 } |
| 6105 |
| 6106 @override |
| 6107 void visitChildren(AstVisitor visitor) { |
| 6108 _target?.accept(visitor); |
| 6109 _index?.accept(visitor); |
| 6110 } |
| 6111 } |
| 6112 |
| 6113 /** |
| 6114 * An instance creation expression. |
| 6115 * |
| 6116 * newExpression ::= |
| 6117 * ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList] |
| 6118 */ |
| 6119 class InstanceCreationExpressionImpl extends ExpressionImpl |
| 6120 implements InstanceCreationExpression { |
| 6121 /** |
| 6122 * The 'new' or 'const' keyword used to indicate how an object should be |
| 6123 * created. |
| 6124 */ |
| 6125 @override |
| 6126 Token keyword; |
| 6127 |
| 6128 /** |
| 6129 * The name of the constructor to be invoked. |
| 6130 */ |
| 6131 ConstructorName _constructorName; |
| 6132 |
| 6133 /** |
| 6134 * The list of arguments to the constructor. |
| 6135 */ |
| 6136 ArgumentList _argumentList; |
| 6137 |
| 6138 /** |
| 6139 * The element associated with the constructor based on static type |
| 6140 * information, or `null` if the AST structure has not been resolved or if the |
| 6141 * constructor could not be resolved. |
| 6142 */ |
| 6143 @override |
| 6144 ConstructorElement staticElement; |
| 6145 |
| 6146 /** |
| 6147 * Initialize a newly created instance creation expression. |
| 6148 */ |
| 6149 InstanceCreationExpressionImpl(this.keyword, |
| 6150 ConstructorNameImpl constructorName, ArgumentListImpl argumentList) { |
| 6151 _constructorName = _becomeParentOf(constructorName); |
| 6152 _argumentList = _becomeParentOf(argumentList); |
| 6153 } |
| 6154 |
| 6155 @override |
| 6156 ArgumentList get argumentList => _argumentList; |
| 6157 |
| 6158 @override |
| 6159 void set argumentList(ArgumentList argumentList) { |
| 6160 _argumentList = _becomeParentOf(argumentList as AstNodeImpl); |
| 6161 } |
| 6162 |
| 6163 @override |
| 6164 Token get beginToken => keyword; |
| 6165 |
| 6166 @override |
| 6167 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 6168 ..add(keyword) |
| 6169 ..add(_constructorName) |
| 6170 ..add(_argumentList); |
| 6171 |
| 6172 @override |
| 6173 ConstructorName get constructorName => _constructorName; |
| 6174 |
| 6175 @override |
| 6176 void set constructorName(ConstructorName name) { |
| 6177 _constructorName = _becomeParentOf(name as AstNodeImpl); |
| 6178 } |
| 6179 |
| 6180 @override |
| 6181 Token get endToken => _argumentList.endToken; |
| 6182 |
| 6183 @override |
| 6184 bool get isConst => keyword?.keyword == Keyword.CONST; |
| 6185 |
| 6186 @override |
| 6187 int get precedence => 16; |
| 6188 |
| 6189 @override |
| 6190 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6191 visitor.visitInstanceCreationExpression(this); |
| 6192 |
| 6193 @override |
| 6194 void visitChildren(AstVisitor visitor) { |
| 6195 _constructorName?.accept(visitor); |
| 6196 _argumentList?.accept(visitor); |
| 6197 } |
| 6198 } |
| 6199 |
| 6200 /** |
| 6201 * An integer literal expression. |
| 6202 * |
| 6203 * integerLiteral ::= |
| 6204 * decimalIntegerLiteral |
| 6205 * | hexadecimalIntegerLiteral |
| 6206 * |
| 6207 * decimalIntegerLiteral ::= |
| 6208 * decimalDigit+ |
| 6209 * |
| 6210 * hexadecimalIntegerLiteral ::= |
| 6211 * '0x' hexadecimalDigit+ |
| 6212 * | '0X' hexadecimalDigit+ |
| 6213 */ |
| 6214 class IntegerLiteralImpl extends LiteralImpl implements IntegerLiteral { |
| 6215 /** |
| 6216 * The token representing the literal. |
| 6217 */ |
| 6218 @override |
| 6219 Token literal; |
| 6220 |
| 6221 /** |
| 6222 * The value of the literal. |
| 6223 */ |
| 6224 @override |
| 6225 int value = 0; |
| 6226 |
| 6227 /** |
| 6228 * Initialize a newly created integer literal. |
| 6229 */ |
| 6230 IntegerLiteralImpl(this.literal, this.value); |
| 6231 |
| 6232 @override |
| 6233 Token get beginToken => literal; |
| 6234 |
| 6235 @override |
| 6236 Iterable<SyntacticEntity> get childEntities => |
| 6237 new ChildEntities()..add(literal); |
| 6238 |
| 6239 @override |
| 6240 Token get endToken => literal; |
| 6241 |
| 6242 @override |
| 6243 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6244 visitor.visitIntegerLiteral(this); |
| 6245 |
| 6246 @override |
| 6247 void visitChildren(AstVisitor visitor) { |
| 6248 // There are no children to visit. |
| 6249 } |
| 6250 } |
| 6251 |
| 6252 /** |
| 6253 * A node within a [StringInterpolation]. |
| 6254 * |
| 6255 * interpolationElement ::= |
| 6256 * [InterpolationExpression] |
| 6257 * | [InterpolationString] |
| 6258 */ |
| 6259 abstract class InterpolationElementImpl extends AstNodeImpl |
| 6260 implements InterpolationElement {} |
| 6261 |
| 6262 /** |
| 6263 * An expression embedded in a string interpolation. |
| 6264 * |
| 6265 * interpolationExpression ::= |
| 6266 * '$' [SimpleIdentifier] |
| 6267 * | '$' '{' [Expression] '}' |
| 6268 */ |
| 6269 class InterpolationExpressionImpl extends InterpolationElementImpl |
| 6270 implements InterpolationExpression { |
| 6271 /** |
| 6272 * The token used to introduce the interpolation expression; either '$' if the |
| 6273 * expression is a simple identifier or '${' if the expression is a full |
| 6274 * expression. |
| 6275 */ |
| 6276 @override |
| 6277 Token leftBracket; |
| 6278 |
| 6279 /** |
| 6280 * The expression to be evaluated for the value to be converted into a string. |
| 6281 */ |
| 6282 Expression _expression; |
| 6283 |
| 6284 /** |
| 6285 * The right curly bracket, or `null` if the expression is an identifier |
| 6286 * without brackets. |
| 6287 */ |
| 6288 @override |
| 6289 Token rightBracket; |
| 6290 |
| 6291 /** |
| 6292 * Initialize a newly created interpolation expression. |
| 6293 */ |
| 6294 InterpolationExpressionImpl( |
| 6295 this.leftBracket, ExpressionImpl expression, this.rightBracket) { |
| 6296 _expression = _becomeParentOf(expression); |
| 6297 } |
| 6298 |
| 6299 @override |
| 6300 Token get beginToken => leftBracket; |
| 6301 |
| 6302 @override |
| 6303 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 6304 ..add(leftBracket) |
| 6305 ..add(_expression) |
| 6306 ..add(rightBracket); |
| 6307 |
| 6308 @override |
| 6309 Token get endToken { |
| 6310 if (rightBracket != null) { |
| 6311 return rightBracket; |
| 6312 } |
| 6313 return _expression.endToken; |
| 6314 } |
| 6315 |
| 6316 @override |
| 6317 Expression get expression => _expression; |
| 6318 |
| 6319 @override |
| 6320 void set expression(Expression expression) { |
| 6321 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 6322 } |
| 6323 |
| 6324 @override |
| 6325 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6326 visitor.visitInterpolationExpression(this); |
| 6327 |
| 6328 @override |
| 6329 void visitChildren(AstVisitor visitor) { |
| 6330 _expression?.accept(visitor); |
| 6331 } |
| 6332 } |
| 6333 |
| 6334 /** |
| 6335 * A non-empty substring of an interpolated string. |
| 6336 * |
| 6337 * interpolationString ::= |
| 6338 * characters |
| 6339 */ |
| 6340 class InterpolationStringImpl extends InterpolationElementImpl |
| 6341 implements InterpolationString { |
| 6342 /** |
| 6343 * The characters that will be added to the string. |
| 6344 */ |
| 6345 @override |
| 6346 Token contents; |
| 6347 |
| 6348 /** |
| 6349 * The value of the literal. |
| 6350 */ |
| 6351 @override |
| 6352 String value; |
| 6353 |
| 6354 /** |
| 6355 * Initialize a newly created string of characters that are part of a string |
| 6356 * interpolation. |
| 6357 */ |
| 6358 InterpolationStringImpl(this.contents, this.value); |
| 6359 |
| 6360 @override |
| 6361 Token get beginToken => contents; |
| 6362 |
| 6363 @override |
| 6364 Iterable<SyntacticEntity> get childEntities => |
| 6365 new ChildEntities()..add(contents); |
| 6366 |
| 6367 @override |
| 6368 int get contentsEnd { |
| 6369 String lexeme = contents.lexeme; |
| 6370 return offset + new StringLexemeHelper(lexeme, true, true).end; |
| 6371 } |
| 6372 |
| 6373 @override |
| 6374 int get contentsOffset { |
| 6375 int offset = contents.offset; |
| 6376 String lexeme = contents.lexeme; |
| 6377 return offset + new StringLexemeHelper(lexeme, true, true).start; |
| 6378 } |
| 6379 |
| 6380 @override |
| 6381 Token get endToken => contents; |
| 6382 |
| 6383 @override |
| 6384 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6385 visitor.visitInterpolationString(this); |
| 6386 |
| 6387 @override |
| 6388 void visitChildren(AstVisitor visitor) {} |
| 6389 } |
| 6390 |
| 6391 /** |
| 6392 * Common base class for [FunctionExpressionInvocationImpl] and |
| 6393 * [MethodInvocationImpl]. |
| 6394 */ |
| 6395 abstract class InvocationExpressionImpl extends ExpressionImpl |
| 6396 implements InvocationExpression { |
| 6397 /** |
| 6398 * The list of arguments to the function. |
| 6399 */ |
| 6400 ArgumentList _argumentList; |
| 6401 |
| 6402 /** |
| 6403 * The type arguments to be applied to the method being invoked, or `null` if |
| 6404 * no type arguments were provided. |
| 6405 */ |
| 6406 TypeArgumentList _typeArguments; |
| 6407 |
| 6408 @override |
| 6409 DartType propagatedInvokeType; |
| 6410 |
| 6411 @override |
| 6412 DartType staticInvokeType; |
| 6413 |
| 6414 /** |
| 6415 * Initialize a newly created invocation. |
| 6416 */ |
| 6417 InvocationExpressionImpl( |
| 6418 TypeArgumentListImpl typeArguments, ArgumentListImpl argumentList) { |
| 6419 _typeArguments = _becomeParentOf(typeArguments); |
| 6420 _argumentList = _becomeParentOf(argumentList); |
| 6421 } |
| 6422 |
| 6423 @override |
| 6424 ArgumentList get argumentList => _argumentList; |
| 6425 |
| 6426 void set argumentList(ArgumentList argumentList) { |
| 6427 _argumentList = _becomeParentOf(argumentList as AstNodeImpl); |
| 6428 } |
| 6429 |
| 6430 @override |
| 6431 TypeArgumentList get typeArguments => _typeArguments; |
| 6432 |
| 6433 void set typeArguments(TypeArgumentList typeArguments) { |
| 6434 _typeArguments = _becomeParentOf(typeArguments as AstNodeImpl); |
| 6435 } |
| 6436 } |
| 6437 |
| 6438 /** |
| 6439 * An is expression. |
| 6440 * |
| 6441 * isExpression ::= |
| 6442 * [Expression] 'is' '!'? [TypeName] |
| 6443 */ |
| 6444 class IsExpressionImpl extends ExpressionImpl implements IsExpression { |
| 6445 /** |
| 6446 * The expression used to compute the value whose type is being tested. |
| 6447 */ |
| 6448 Expression _expression; |
| 6449 |
| 6450 /** |
| 6451 * The is operator. |
| 6452 */ |
| 6453 @override |
| 6454 Token isOperator; |
| 6455 |
| 6456 /** |
| 6457 * The not operator, or `null` if the sense of the test is not negated. |
| 6458 */ |
| 6459 @override |
| 6460 Token notOperator; |
| 6461 |
| 6462 /** |
| 6463 * The name of the type being tested for. |
| 6464 */ |
| 6465 TypeName _type; |
| 6466 |
| 6467 /** |
| 6468 * Initialize a newly created is expression. The [notOperator] can be `null` |
| 6469 * if the sense of the test is not negated. |
| 6470 */ |
| 6471 IsExpressionImpl(ExpressionImpl expression, this.isOperator, this.notOperator, |
| 6472 TypeNameImpl type) { |
| 6473 _expression = _becomeParentOf(expression); |
| 6474 _type = _becomeParentOf(type); |
| 6475 } |
| 6476 |
| 6477 @override |
| 6478 Token get beginToken => _expression.beginToken; |
| 6479 |
| 6480 @override |
| 6481 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 6482 ..add(_expression) |
| 6483 ..add(isOperator) |
| 6484 ..add(notOperator) |
| 6485 ..add(_type); |
| 6486 |
| 6487 @override |
| 6488 Token get endToken => _type.endToken; |
| 6489 |
| 6490 @override |
| 6491 Expression get expression => _expression; |
| 6492 |
| 6493 @override |
| 6494 void set expression(Expression expression) { |
| 6495 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 6496 } |
| 6497 |
| 6498 @override |
| 6499 int get precedence => 7; |
| 6500 |
| 6501 @override |
| 6502 TypeName get type => _type; |
| 6503 |
| 6504 @override |
| 6505 void set type(TypeName name) { |
| 6506 _type = _becomeParentOf(name as AstNodeImpl); |
| 6507 } |
| 6508 |
| 6509 @override |
| 6510 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6511 visitor.visitIsExpression(this); |
| 6512 |
| 6513 @override |
| 6514 void visitChildren(AstVisitor visitor) { |
| 6515 _expression?.accept(visitor); |
| 6516 _type?.accept(visitor); |
| 6517 } |
| 6518 } |
| 6519 |
| 6520 /** |
| 6521 * A statement that has a label associated with them. |
| 6522 * |
| 6523 * labeledStatement ::= |
| 6524 * [Label]+ [Statement] |
| 6525 */ |
| 6526 class LabeledStatementImpl extends StatementImpl implements LabeledStatement { |
| 6527 /** |
| 6528 * The labels being associated with the statement. |
| 6529 */ |
| 6530 NodeList<Label> _labels; |
| 6531 |
| 6532 /** |
| 6533 * The statement with which the labels are being associated. |
| 6534 */ |
| 6535 Statement _statement; |
| 6536 |
| 6537 /** |
| 6538 * Initialize a newly created labeled statement. |
| 6539 */ |
| 6540 LabeledStatementImpl(List<Label> labels, StatementImpl statement) { |
| 6541 _labels = new NodeListImpl<Label>(this, labels); |
| 6542 _statement = _becomeParentOf(statement); |
| 6543 } |
| 6544 |
| 6545 @override |
| 6546 Token get beginToken { |
| 6547 if (!_labels.isEmpty) { |
| 6548 return _labels.beginToken; |
| 6549 } |
| 6550 return _statement.beginToken; |
| 6551 } |
| 6552 |
| 6553 @override |
| 6554 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 6555 ..addAll(_labels) |
| 6556 ..add(_statement); |
| 6557 |
| 6558 @override |
| 6559 Token get endToken => _statement.endToken; |
| 6560 |
| 6561 @override |
| 6562 NodeList<Label> get labels => _labels; |
| 6563 |
| 6564 @override |
| 6565 Statement get statement => _statement; |
| 6566 |
| 6567 @override |
| 6568 void set statement(Statement statement) { |
| 6569 _statement = _becomeParentOf(statement as AstNodeImpl); |
| 6570 } |
| 6571 |
| 6572 @override |
| 6573 Statement get unlabeled => _statement.unlabeled; |
| 6574 |
| 6575 @override |
| 6576 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6577 visitor.visitLabeledStatement(this); |
| 6578 |
| 6579 @override |
| 6580 void visitChildren(AstVisitor visitor) { |
| 6581 _labels.accept(visitor); |
| 6582 _statement?.accept(visitor); |
| 6583 } |
| 6584 } |
| 6585 |
| 6586 /** |
| 6587 * A label on either a [LabeledStatement] or a [NamedExpression]. |
| 6588 * |
| 6589 * label ::= |
| 6590 * [SimpleIdentifier] ':' |
| 6591 */ |
| 6592 class LabelImpl extends AstNodeImpl implements Label { |
| 6593 /** |
| 6594 * The label being associated with the statement. |
| 6595 */ |
| 6596 SimpleIdentifier _label; |
| 6597 |
| 6598 /** |
| 6599 * The colon that separates the label from the statement. |
| 6600 */ |
| 6601 @override |
| 6602 Token colon; |
| 6603 |
| 6604 /** |
| 6605 * Initialize a newly created label. |
| 6606 */ |
| 6607 LabelImpl(SimpleIdentifierImpl label, this.colon) { |
| 6608 _label = _becomeParentOf(label); |
| 6609 } |
| 6610 |
| 6611 @override |
| 6612 Token get beginToken => _label.beginToken; |
| 6613 |
| 6614 @override |
| 6615 Iterable<SyntacticEntity> get childEntities => |
| 6616 new ChildEntities()..add(_label)..add(colon); |
| 6617 |
| 6618 @override |
| 6619 Token get endToken => colon; |
| 6620 |
| 6621 @override |
| 6622 SimpleIdentifier get label => _label; |
| 6623 |
| 6624 @override |
| 6625 void set label(SimpleIdentifier label) { |
| 6626 _label = _becomeParentOf(label as AstNodeImpl); |
| 6627 } |
| 6628 |
| 6629 @override |
| 6630 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6631 visitor.visitLabel(this); |
| 6632 |
| 6633 @override |
| 6634 void visitChildren(AstVisitor visitor) { |
| 6635 _label?.accept(visitor); |
| 6636 } |
| 6637 } |
| 6638 |
| 6639 /** |
| 6640 * A library directive. |
| 6641 * |
| 6642 * libraryDirective ::= |
| 6643 * [Annotation] 'library' [Identifier] ';' |
| 6644 */ |
| 6645 class LibraryDirectiveImpl extends DirectiveImpl implements LibraryDirective { |
| 6646 /** |
| 6647 * The token representing the 'library' keyword. |
| 6648 */ |
| 6649 @override |
| 6650 Token libraryKeyword; |
| 6651 |
| 6652 /** |
| 6653 * The name of the library being defined. |
| 6654 */ |
| 6655 LibraryIdentifier _name; |
| 6656 |
| 6657 /** |
| 6658 * The semicolon terminating the directive. |
| 6659 */ |
| 6660 @override |
| 6661 Token semicolon; |
| 6662 |
| 6663 /** |
| 6664 * Initialize a newly created library directive. Either or both of the |
| 6665 * [comment] and [metadata] can be `null` if the directive does not have the |
| 6666 * corresponding attribute. |
| 6667 */ |
| 6668 LibraryDirectiveImpl(CommentImpl comment, List<Annotation> metadata, |
| 6669 this.libraryKeyword, LibraryIdentifierImpl name, this.semicolon) |
| 6670 : super(comment, metadata) { |
| 6671 _name = _becomeParentOf(name); |
| 6672 } |
| 6673 |
| 6674 @override |
| 6675 Iterable<SyntacticEntity> get childEntities => |
| 6676 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon); |
| 6677 |
| 6678 @override |
| 6679 Token get endToken => semicolon; |
| 6680 |
| 6681 @override |
| 6682 Token get firstTokenAfterCommentAndMetadata => libraryKeyword; |
| 6683 |
| 6684 @override |
| 6685 Token get keyword => libraryKeyword; |
| 6686 |
| 6687 @override |
| 6688 LibraryIdentifier get name => _name; |
| 6689 |
| 6690 @override |
| 6691 void set name(LibraryIdentifier name) { |
| 6692 _name = _becomeParentOf(name as AstNodeImpl); |
| 6693 } |
| 6694 |
| 6695 @override |
| 6696 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6697 visitor.visitLibraryDirective(this); |
| 6698 |
| 6699 @override |
| 6700 void visitChildren(AstVisitor visitor) { |
| 6701 super.visitChildren(visitor); |
| 6702 _name?.accept(visitor); |
| 6703 } |
| 6704 } |
| 6705 |
| 6706 /** |
| 6707 * The identifier for a library. |
| 6708 * |
| 6709 * libraryIdentifier ::= |
| 6710 * [SimpleIdentifier] ('.' [SimpleIdentifier])* |
| 6711 */ |
| 6712 class LibraryIdentifierImpl extends IdentifierImpl |
| 6713 implements LibraryIdentifier { |
| 6714 /** |
| 6715 * The components of the identifier. |
| 6716 */ |
| 6717 NodeList<SimpleIdentifier> _components; |
| 6718 |
| 6719 /** |
| 6720 * Initialize a newly created prefixed identifier. |
| 6721 */ |
| 6722 LibraryIdentifierImpl(List<SimpleIdentifier> components) { |
| 6723 _components = new NodeListImpl<SimpleIdentifier>(this, components); |
| 6724 } |
| 6725 |
| 6726 @override |
| 6727 Token get beginToken => _components.beginToken; |
| 6728 |
| 6729 @override |
| 6730 Element get bestElement => staticElement; |
| 6731 |
| 6732 @override |
| 6733 // TODO(paulberry): add "." tokens. |
| 6734 Iterable<SyntacticEntity> get childEntities => |
| 6735 new ChildEntities()..addAll(_components); |
| 6736 |
| 6737 @override |
| 6738 NodeList<SimpleIdentifier> get components => _components; |
| 6739 |
| 6740 @override |
| 6741 Token get endToken => _components.endToken; |
| 6742 |
| 6743 @override |
| 6744 String get name { |
| 6745 StringBuffer buffer = new StringBuffer(); |
| 6746 bool needsPeriod = false; |
| 6747 int length = _components.length; |
| 6748 for (int i = 0; i < length; i++) { |
| 6749 SimpleIdentifier identifier = _components[i]; |
| 6750 if (needsPeriod) { |
| 6751 buffer.write("."); |
| 6752 } else { |
| 6753 needsPeriod = true; |
| 6754 } |
| 6755 buffer.write(identifier.name); |
| 6756 } |
| 6757 return buffer.toString(); |
| 6758 } |
| 6759 |
| 6760 @override |
| 6761 int get precedence => 15; |
| 6762 |
| 6763 @override |
| 6764 Element get propagatedElement => null; |
| 6765 |
| 6766 @override |
| 6767 Element get staticElement => null; |
| 6768 |
| 6769 @override |
| 6770 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6771 visitor.visitLibraryIdentifier(this); |
| 6772 |
| 6773 @override |
| 6774 void visitChildren(AstVisitor visitor) { |
| 6775 _components.accept(visitor); |
| 6776 } |
| 6777 } |
| 6778 |
| 6779 /** |
| 6780 * A list literal. |
| 6781 * |
| 6782 * listLiteral ::= |
| 6783 * 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']' |
| 6784 */ |
| 6785 class ListLiteralImpl extends TypedLiteralImpl implements ListLiteral { |
| 6786 /** |
| 6787 * The left square bracket. |
| 6788 */ |
| 6789 @override |
| 6790 Token leftBracket; |
| 6791 |
| 6792 /** |
| 6793 * The expressions used to compute the elements of the list. |
| 6794 */ |
| 6795 NodeList<Expression> _elements; |
| 6796 |
| 6797 /** |
| 6798 * The right square bracket. |
| 6799 */ |
| 6800 @override |
| 6801 Token rightBracket; |
| 6802 |
| 6803 /** |
| 6804 * Initialize a newly created list literal. The [constKeyword] can be `null` |
| 6805 * if the literal is not a constant. The [typeArguments] can be `null` if no |
| 6806 * type arguments were declared. The list of [elements] can be `null` if the |
| 6807 * list is empty. |
| 6808 */ |
| 6809 ListLiteralImpl(Token constKeyword, TypeArgumentList typeArguments, |
| 6810 this.leftBracket, List<Expression> elements, this.rightBracket) |
| 6811 : super(constKeyword, typeArguments) { |
| 6812 _elements = new NodeListImpl<Expression>(this, elements); |
| 6813 } |
| 6814 |
| 6815 @override |
| 6816 Token get beginToken { |
| 6817 if (constKeyword != null) { |
| 6818 return constKeyword; |
| 6819 } |
| 6820 TypeArgumentList typeArguments = this.typeArguments; |
| 6821 if (typeArguments != null) { |
| 6822 return typeArguments.beginToken; |
| 6823 } |
| 6824 return leftBracket; |
| 6825 } |
| 6826 |
| 6827 @override |
| 6828 // TODO(paulberry): add commas. |
| 6829 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 6830 ..add(leftBracket) |
| 6831 ..addAll(_elements) |
| 6832 ..add(rightBracket); |
| 6833 |
| 6834 @override |
| 6835 NodeList<Expression> get elements => _elements; |
| 6836 |
| 6837 @override |
| 6838 Token get endToken => rightBracket; |
| 6839 |
| 6840 @override |
| 6841 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6842 visitor.visitListLiteral(this); |
| 6843 |
| 6844 @override |
| 6845 void visitChildren(AstVisitor visitor) { |
| 6846 super.visitChildren(visitor); |
| 6847 _elements.accept(visitor); |
| 6848 } |
| 6849 } |
| 6850 |
| 6851 /** |
| 6852 * A node that represents a literal expression. |
| 6853 * |
| 6854 * literal ::= |
| 6855 * [BooleanLiteral] |
| 6856 * | [DoubleLiteral] |
| 6857 * | [IntegerLiteral] |
| 6858 * | [ListLiteral] |
| 6859 * | [MapLiteral] |
| 6860 * | [NullLiteral] |
| 6861 * | [StringLiteral] |
| 6862 */ |
| 6863 abstract class LiteralImpl extends ExpressionImpl implements Literal { |
| 6864 @override |
| 6865 int get precedence => 16; |
| 6866 } |
| 6867 |
| 6868 /** |
| 6869 * Additional information about local variables within a function or method |
| 6870 * produced at resolution time. |
| 6871 */ |
| 6872 class LocalVariableInfo { |
| 6873 /** |
| 6874 * The set of local variables and parameters that are potentially mutated |
| 6875 * within a local function other than the function in which they are declared. |
| 6876 */ |
| 6877 final Set<VariableElement> potentiallyMutatedInClosure = |
| 6878 new Set<VariableElement>(); |
| 6879 |
| 6880 /** |
| 6881 * The set of local variables and parameters that are potentiall mutated |
| 6882 * within the scope of their declarations. |
| 6883 */ |
| 6884 final Set<VariableElement> potentiallyMutatedInScope = |
| 6885 new Set<VariableElement>(); |
| 6886 } |
| 6887 |
| 6888 /** |
| 6889 * A single key/value pair in a map literal. |
| 6890 * |
| 6891 * mapLiteralEntry ::= |
| 6892 * [Expression] ':' [Expression] |
| 6893 */ |
| 6894 class MapLiteralEntryImpl extends AstNodeImpl implements MapLiteralEntry { |
| 6895 /** |
| 6896 * The expression computing the key with which the value will be associated. |
| 6897 */ |
| 6898 Expression _key; |
| 6899 |
| 6900 /** |
| 6901 * The colon that separates the key from the value. |
| 6902 */ |
| 6903 @override |
| 6904 Token separator; |
| 6905 |
| 6906 /** |
| 6907 * The expression computing the value that will be associated with the key. |
| 6908 */ |
| 6909 Expression _value; |
| 6910 |
| 6911 /** |
| 6912 * Initialize a newly created map literal entry. |
| 6913 */ |
| 6914 MapLiteralEntryImpl( |
| 6915 ExpressionImpl key, this.separator, ExpressionImpl value) { |
| 6916 _key = _becomeParentOf(key); |
| 6917 _value = _becomeParentOf(value); |
| 6918 } |
| 6919 |
| 6920 @override |
| 6921 Token get beginToken => _key.beginToken; |
| 6922 |
| 6923 @override |
| 6924 Iterable<SyntacticEntity> get childEntities => |
| 6925 new ChildEntities()..add(_key)..add(separator)..add(_value); |
| 6926 |
| 6927 @override |
| 6928 Token get endToken => _value.endToken; |
| 6929 |
| 6930 @override |
| 6931 Expression get key => _key; |
| 6932 |
| 6933 @override |
| 6934 void set key(Expression string) { |
| 6935 _key = _becomeParentOf(string as AstNodeImpl); |
| 6936 } |
| 6937 |
| 6938 @override |
| 6939 Expression get value => _value; |
| 6940 |
| 6941 @override |
| 6942 void set value(Expression expression) { |
| 6943 _value = _becomeParentOf(expression as AstNodeImpl); |
| 6944 } |
| 6945 |
| 6946 @override |
| 6947 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 6948 visitor.visitMapLiteralEntry(this); |
| 6949 |
| 6950 @override |
| 6951 void visitChildren(AstVisitor visitor) { |
| 6952 _key?.accept(visitor); |
| 6953 _value?.accept(visitor); |
| 6954 } |
| 6955 } |
| 6956 |
| 6957 /** |
| 6958 * A literal map. |
| 6959 * |
| 6960 * mapLiteral ::= |
| 6961 * 'const'? ('<' [TypeName] (',' [TypeName])* '>')? |
| 6962 * '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}' |
| 6963 */ |
| 6964 class MapLiteralImpl extends TypedLiteralImpl implements MapLiteral { |
| 6965 /** |
| 6966 * The left curly bracket. |
| 6967 */ |
| 6968 @override |
| 6969 Token leftBracket; |
| 6970 |
| 6971 /** |
| 6972 * The entries in the map. |
| 6973 */ |
| 6974 NodeList<MapLiteralEntry> _entries; |
| 6975 |
| 6976 /** |
| 6977 * The right curly bracket. |
| 6978 */ |
| 6979 @override |
| 6980 Token rightBracket; |
| 6981 |
| 6982 /** |
| 6983 * Initialize a newly created map literal. The [constKeyword] can be `null` if |
| 6984 * the literal is not a constant. The [typeArguments] can be `null` if no type |
| 6985 * arguments were declared. The [entries] can be `null` if the map is empty. |
| 6986 */ |
| 6987 MapLiteralImpl(Token constKeyword, TypeArgumentList typeArguments, |
| 6988 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket) |
| 6989 : super(constKeyword, typeArguments) { |
| 6990 _entries = new NodeListImpl<MapLiteralEntry>(this, entries); |
| 6991 } |
| 6992 |
| 6993 @override |
| 6994 Token get beginToken { |
| 6995 if (constKeyword != null) { |
| 6996 return constKeyword; |
| 6997 } |
| 6998 TypeArgumentList typeArguments = this.typeArguments; |
| 6999 if (typeArguments != null) { |
| 7000 return typeArguments.beginToken; |
| 7001 } |
| 7002 return leftBracket; |
| 7003 } |
| 7004 |
| 7005 @override |
| 7006 // TODO(paulberry): add commas. |
| 7007 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 7008 ..add(leftBracket) |
| 7009 ..addAll(entries) |
| 7010 ..add(rightBracket); |
| 7011 |
| 7012 @override |
| 7013 Token get endToken => rightBracket; |
| 7014 |
| 7015 @override |
| 7016 NodeList<MapLiteralEntry> get entries => _entries; |
| 7017 |
| 7018 @override |
| 7019 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7020 visitor.visitMapLiteral(this); |
| 7021 |
| 7022 @override |
| 7023 void visitChildren(AstVisitor visitor) { |
| 7024 super.visitChildren(visitor); |
| 7025 _entries.accept(visitor); |
| 7026 } |
| 7027 } |
| 7028 |
| 7029 /** |
| 7030 * A method declaration. |
| 7031 * |
| 7032 * methodDeclaration ::= |
| 7033 * methodSignature [FunctionBody] |
| 7034 * |
| 7035 * methodSignature ::= |
| 7036 * 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')? |
| 7037 * methodName [TypeParameterList] [FormalParameterList] |
| 7038 * |
| 7039 * methodName ::= |
| 7040 * [SimpleIdentifier] |
| 7041 * | 'operator' [SimpleIdentifier] |
| 7042 */ |
| 7043 class MethodDeclarationImpl extends ClassMemberImpl |
| 7044 implements MethodDeclaration { |
| 7045 /** |
| 7046 * The token for the 'external' keyword, or `null` if the constructor is not |
| 7047 * external. |
| 7048 */ |
| 7049 @override |
| 7050 Token externalKeyword; |
| 7051 |
| 7052 /** |
| 7053 * The token representing the 'abstract' or 'static' keyword, or `null` if |
| 7054 * neither modifier was specified. |
| 7055 */ |
| 7056 @override |
| 7057 Token modifierKeyword; |
| 7058 |
| 7059 /** |
| 7060 * The return type of the method, or `null` if no return type was declared. |
| 7061 */ |
| 7062 TypeName _returnType; |
| 7063 |
| 7064 /** |
| 7065 * The token representing the 'get' or 'set' keyword, or `null` if this is a |
| 7066 * method declaration rather than a property declaration. |
| 7067 */ |
| 7068 @override |
| 7069 Token propertyKeyword; |
| 7070 |
| 7071 /** |
| 7072 * The token representing the 'operator' keyword, or `null` if this method |
| 7073 * does not declare an operator. |
| 7074 */ |
| 7075 @override |
| 7076 Token operatorKeyword; |
| 7077 |
| 7078 /** |
| 7079 * The name of the method. |
| 7080 */ |
| 7081 SimpleIdentifier _name; |
| 7082 |
| 7083 /** |
| 7084 * The type parameters associated with the method, or `null` if the method is |
| 7085 * not a generic method. |
| 7086 */ |
| 7087 TypeParameterList _typeParameters; |
| 7088 |
| 7089 /** |
| 7090 * The parameters associated with the method, or `null` if this method |
| 7091 * declares a getter. |
| 7092 */ |
| 7093 FormalParameterList _parameters; |
| 7094 |
| 7095 /** |
| 7096 * The body of the method. |
| 7097 */ |
| 7098 FunctionBody _body; |
| 7099 |
| 7100 /** |
| 7101 * Initialize a newly created method declaration. Either or both of the |
| 7102 * [comment] and [metadata] can be `null` if the declaration does not have the |
| 7103 * corresponding attribute. The [externalKeyword] can be `null` if the method |
| 7104 * is not external. The [modifierKeyword] can be `null` if the method is |
| 7105 * neither abstract nor static. The [returnType] can be `null` if no return |
| 7106 * type was specified. The [propertyKeyword] can be `null` if the method is |
| 7107 * neither a getter or a setter. The [operatorKeyword] can be `null` if the |
| 7108 * method does not implement an operator. The [parameters] must be `null` if |
| 7109 * this method declares a getter. |
| 7110 */ |
| 7111 MethodDeclarationImpl( |
| 7112 CommentImpl comment, |
| 7113 List<Annotation> metadata, |
| 7114 this.externalKeyword, |
| 7115 this.modifierKeyword, |
| 7116 TypeNameImpl returnType, |
| 7117 this.propertyKeyword, |
| 7118 this.operatorKeyword, |
| 7119 SimpleIdentifierImpl name, |
| 7120 TypeParameterListImpl typeParameters, |
| 7121 FormalParameterListImpl parameters, |
| 7122 FunctionBodyImpl body) |
| 7123 : super(comment, metadata) { |
| 7124 _returnType = _becomeParentOf(returnType); |
| 7125 _name = _becomeParentOf(name); |
| 7126 _typeParameters = _becomeParentOf(typeParameters); |
| 7127 _parameters = _becomeParentOf(parameters); |
| 7128 _body = _becomeParentOf(body); |
| 7129 } |
| 7130 |
| 7131 @override |
| 7132 FunctionBody get body => _body; |
| 7133 |
| 7134 @override |
| 7135 void set body(FunctionBody functionBody) { |
| 7136 _body = _becomeParentOf(functionBody as AstNodeImpl); |
| 7137 } |
| 7138 |
| 7139 @override |
| 7140 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 7141 ..add(externalKeyword) |
| 7142 ..add(modifierKeyword) |
| 7143 ..add(_returnType) |
| 7144 ..add(propertyKeyword) |
| 7145 ..add(operatorKeyword) |
| 7146 ..add(_name) |
| 7147 ..add(_parameters) |
| 7148 ..add(_body); |
| 7149 |
| 7150 /** |
| 7151 * Return the element associated with this method, or `null` if the AST |
| 7152 * structure has not been resolved. The element can either be a |
| 7153 * [MethodElement], if this represents the declaration of a normal method, or |
| 7154 * a [PropertyAccessorElement] if this represents the declaration of either a |
| 7155 * getter or a setter. |
| 7156 */ |
| 7157 @override |
| 7158 ExecutableElement get element => _name?.staticElement as ExecutableElement; |
| 7159 |
| 7160 @override |
| 7161 Token get endToken => _body.endToken; |
| 7162 |
| 7163 @override |
| 7164 Token get firstTokenAfterCommentAndMetadata { |
| 7165 if (externalKeyword != null) { |
| 7166 return externalKeyword; |
| 7167 } else if (modifierKeyword != null) { |
| 7168 return modifierKeyword; |
| 7169 } else if (_returnType != null) { |
| 7170 return _returnType.beginToken; |
| 7171 } else if (propertyKeyword != null) { |
| 7172 return propertyKeyword; |
| 7173 } else if (operatorKeyword != null) { |
| 7174 return operatorKeyword; |
| 7175 } |
| 7176 return _name.beginToken; |
| 7177 } |
| 7178 |
| 7179 @override |
| 7180 bool get isAbstract { |
| 7181 FunctionBody body = _body; |
| 7182 return externalKeyword == null && |
| 7183 (body is EmptyFunctionBody && !body.semicolon.isSynthetic); |
| 7184 } |
| 7185 |
| 7186 @override |
| 7187 bool get isGetter => propertyKeyword?.keyword == Keyword.GET; |
| 7188 |
| 7189 @override |
| 7190 bool get isOperator => operatorKeyword != null; |
| 7191 |
| 7192 @override |
| 7193 bool get isSetter => propertyKeyword?.keyword == Keyword.SET; |
| 7194 |
| 7195 @override |
| 7196 bool get isStatic => modifierKeyword?.keyword == Keyword.STATIC; |
| 7197 |
| 7198 @override |
| 7199 SimpleIdentifier get name => _name; |
| 7200 |
| 7201 @override |
| 7202 void set name(SimpleIdentifier identifier) { |
| 7203 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 7204 } |
| 7205 |
| 7206 @override |
| 7207 FormalParameterList get parameters => _parameters; |
| 7208 |
| 7209 @override |
| 7210 void set parameters(FormalParameterList parameters) { |
| 7211 _parameters = _becomeParentOf(parameters as AstNodeImpl); |
| 7212 } |
| 7213 |
| 7214 @override |
| 7215 TypeName get returnType => _returnType; |
| 7216 |
| 7217 @override |
| 7218 void set returnType(TypeName typeName) { |
| 7219 _returnType = _becomeParentOf(typeName as AstNodeImpl); |
| 7220 } |
| 7221 |
| 7222 @override |
| 7223 TypeParameterList get typeParameters => _typeParameters; |
| 7224 |
| 7225 @override |
| 7226 void set typeParameters(TypeParameterList typeParameters) { |
| 7227 _typeParameters = _becomeParentOf(typeParameters as AstNodeImpl); |
| 7228 } |
| 7229 |
| 7230 @override |
| 7231 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7232 visitor.visitMethodDeclaration(this); |
| 7233 |
| 7234 @override |
| 7235 void visitChildren(AstVisitor visitor) { |
| 7236 super.visitChildren(visitor); |
| 7237 _returnType?.accept(visitor); |
| 7238 _name?.accept(visitor); |
| 7239 _typeParameters?.accept(visitor); |
| 7240 _parameters?.accept(visitor); |
| 7241 _body?.accept(visitor); |
| 7242 } |
| 7243 } |
| 7244 |
| 7245 /** |
| 7246 * The invocation of either a function or a method. Invocations of functions |
| 7247 * resulting from evaluating an expression are represented by |
| 7248 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are |
| 7249 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes. |
| 7250 * |
| 7251 * methodInvocation ::= |
| 7252 * ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLi
st] |
| 7253 */ |
| 7254 class MethodInvocationImpl extends InvocationExpressionImpl |
| 7255 implements MethodInvocation { |
| 7256 /** |
| 7257 * The expression producing the object on which the method is defined, or |
| 7258 * `null` if there is no target (that is, the target is implicitly `this`). |
| 7259 */ |
| 7260 Expression _target; |
| 7261 |
| 7262 /** |
| 7263 * The operator that separates the target from the method name, or `null` |
| 7264 * if there is no target. In an ordinary method invocation this will be a |
| 7265 * period ('.'). In a cascade section this will be the cascade operator |
| 7266 * ('..'). |
| 7267 */ |
| 7268 @override |
| 7269 Token operator; |
| 7270 |
| 7271 /** |
| 7272 * The name of the method being invoked. |
| 7273 */ |
| 7274 SimpleIdentifier _methodName; |
| 7275 |
| 7276 /** |
| 7277 * Initialize a newly created method invocation. The [target] and [operator] |
| 7278 * can be `null` if there is no target. |
| 7279 */ |
| 7280 MethodInvocationImpl( |
| 7281 ExpressionImpl target, |
| 7282 this.operator, |
| 7283 SimpleIdentifierImpl methodName, |
| 7284 TypeArgumentListImpl typeArguments, |
| 7285 ArgumentListImpl argumentList) |
| 7286 : super(typeArguments, argumentList) { |
| 7287 _target = _becomeParentOf(target); |
| 7288 _methodName = _becomeParentOf(methodName); |
| 7289 } |
| 7290 |
| 7291 @override |
| 7292 Token get beginToken { |
| 7293 if (_target != null) { |
| 7294 return _target.beginToken; |
| 7295 } else if (operator != null) { |
| 7296 return operator; |
| 7297 } |
| 7298 return _methodName.beginToken; |
| 7299 } |
| 7300 |
| 7301 @override |
| 7302 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 7303 ..add(_target) |
| 7304 ..add(operator) |
| 7305 ..add(_methodName) |
| 7306 ..add(_argumentList); |
| 7307 |
| 7308 @override |
| 7309 Token get endToken => _argumentList.endToken; |
| 7310 |
| 7311 @override |
| 7312 Expression get function => methodName; |
| 7313 |
| 7314 @override |
| 7315 bool get isCascaded => |
| 7316 operator != null && operator.type == TokenType.PERIOD_PERIOD; |
| 7317 |
| 7318 @override |
| 7319 SimpleIdentifier get methodName => _methodName; |
| 7320 |
| 7321 @override |
| 7322 void set methodName(SimpleIdentifier identifier) { |
| 7323 _methodName = _becomeParentOf(identifier as AstNodeImpl); |
| 7324 } |
| 7325 |
| 7326 @override |
| 7327 int get precedence => 15; |
| 7328 |
| 7329 @override |
| 7330 Expression get realTarget { |
| 7331 if (isCascaded) { |
| 7332 AstNode ancestor = parent; |
| 7333 while (ancestor is! CascadeExpression) { |
| 7334 if (ancestor == null) { |
| 7335 return _target; |
| 7336 } |
| 7337 ancestor = ancestor.parent; |
| 7338 } |
| 7339 return (ancestor as CascadeExpression).target; |
| 7340 } |
| 7341 return _target; |
| 7342 } |
| 7343 |
| 7344 @override |
| 7345 Expression get target => _target; |
| 7346 |
| 7347 @override |
| 7348 void set target(Expression expression) { |
| 7349 _target = _becomeParentOf(expression as AstNodeImpl); |
| 7350 } |
| 7351 |
| 7352 @override |
| 7353 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7354 visitor.visitMethodInvocation(this); |
| 7355 |
| 7356 @override |
| 7357 void visitChildren(AstVisitor visitor) { |
| 7358 _target?.accept(visitor); |
| 7359 _methodName?.accept(visitor); |
| 7360 _typeArguments?.accept(visitor); |
| 7361 _argumentList?.accept(visitor); |
| 7362 } |
| 7363 } |
| 7364 |
| 7365 /** |
| 7366 * A node that declares a single name within the scope of a compilation unit. |
| 7367 */ |
| 7368 abstract class NamedCompilationUnitMemberImpl extends CompilationUnitMemberImpl |
| 7369 implements NamedCompilationUnitMember { |
| 7370 /** |
| 7371 * The name of the member being declared. |
| 7372 */ |
| 7373 SimpleIdentifier _name; |
| 7374 |
| 7375 /** |
| 7376 * Initialize a newly created compilation unit member with the given [name]. |
| 7377 * Either or both of the [comment] and [metadata] can be `null` if the member |
| 7378 * does not have the corresponding attribute. |
| 7379 */ |
| 7380 NamedCompilationUnitMemberImpl( |
| 7381 CommentImpl comment, List<Annotation> metadata, SimpleIdentifierImpl name) |
| 7382 : super(comment, metadata) { |
| 7383 _name = _becomeParentOf(name); |
| 7384 } |
| 7385 |
| 7386 @override |
| 7387 SimpleIdentifier get name => _name; |
| 7388 |
| 7389 @override |
| 7390 void set name(SimpleIdentifier identifier) { |
| 7391 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 7392 } |
| 7393 } |
| 7394 |
| 7395 /** |
| 7396 * An expression that has a name associated with it. They are used in method |
| 7397 * invocations when there are named parameters. |
| 7398 * |
| 7399 * namedExpression ::= |
| 7400 * [Label] [Expression] |
| 7401 */ |
| 7402 class NamedExpressionImpl extends ExpressionImpl implements NamedExpression { |
| 7403 /** |
| 7404 * The name associated with the expression. |
| 7405 */ |
| 7406 Label _name; |
| 7407 |
| 7408 /** |
| 7409 * The expression with which the name is associated. |
| 7410 */ |
| 7411 Expression _expression; |
| 7412 |
| 7413 /** |
| 7414 * Initialize a newly created named expression.. |
| 7415 */ |
| 7416 NamedExpressionImpl(LabelImpl name, ExpressionImpl expression) { |
| 7417 _name = _becomeParentOf(name); |
| 7418 _expression = _becomeParentOf(expression); |
| 7419 } |
| 7420 |
| 7421 @override |
| 7422 Token get beginToken => _name.beginToken; |
| 7423 |
| 7424 @override |
| 7425 Iterable<SyntacticEntity> get childEntities => |
| 7426 new ChildEntities()..add(_name)..add(_expression); |
| 7427 |
| 7428 @override |
| 7429 ParameterElement get element { |
| 7430 Element element = _name.label.staticElement; |
| 7431 if (element is ParameterElement) { |
| 7432 return element; |
| 7433 } |
| 7434 return null; |
| 7435 } |
| 7436 |
| 7437 @override |
| 7438 Token get endToken => _expression.endToken; |
| 7439 |
| 7440 @override |
| 7441 Expression get expression => _expression; |
| 7442 |
| 7443 @override |
| 7444 void set expression(Expression expression) { |
| 7445 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 7446 } |
| 7447 |
| 7448 @override |
| 7449 Label get name => _name; |
| 7450 |
| 7451 @override |
| 7452 void set name(Label identifier) { |
| 7453 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 7454 } |
| 7455 |
| 7456 @override |
| 7457 int get precedence => 0; |
| 7458 |
| 7459 @override |
| 7460 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7461 visitor.visitNamedExpression(this); |
| 7462 |
| 7463 @override |
| 7464 void visitChildren(AstVisitor visitor) { |
| 7465 _name?.accept(visitor); |
| 7466 _expression?.accept(visitor); |
| 7467 } |
| 7468 } |
| 7469 |
| 7470 /** |
| 7471 * A node that represents a directive that impacts the namespace of a library. |
| 7472 * |
| 7473 * directive ::= |
| 7474 * [ExportDirective] |
| 7475 * | [ImportDirective] |
| 7476 */ |
| 7477 abstract class NamespaceDirectiveImpl extends UriBasedDirectiveImpl |
| 7478 implements NamespaceDirective { |
| 7479 /** |
| 7480 * The token representing the 'import' or 'export' keyword. |
| 7481 */ |
| 7482 @override |
| 7483 Token keyword; |
| 7484 |
| 7485 /** |
| 7486 * The configurations used to control which library will actually be loaded at |
| 7487 * run-time. |
| 7488 */ |
| 7489 NodeList<Configuration> _configurations; |
| 7490 |
| 7491 /** |
| 7492 * The combinators used to control which names are imported or exported. |
| 7493 */ |
| 7494 NodeList<Combinator> _combinators; |
| 7495 |
| 7496 /** |
| 7497 * The semicolon terminating the directive. |
| 7498 */ |
| 7499 @override |
| 7500 Token semicolon; |
| 7501 |
| 7502 @override |
| 7503 String selectedUriContent; |
| 7504 |
| 7505 @override |
| 7506 Source selectedSource; |
| 7507 |
| 7508 /** |
| 7509 * Initialize a newly created namespace directive. Either or both of the |
| 7510 * [comment] and [metadata] can be `null` if the directive does not have the |
| 7511 * corresponding attribute. The list of [combinators] can be `null` if there |
| 7512 * are no combinators. |
| 7513 */ |
| 7514 NamespaceDirectiveImpl( |
| 7515 Comment comment, |
| 7516 List<Annotation> metadata, |
| 7517 this.keyword, |
| 7518 StringLiteral libraryUri, |
| 7519 List<Configuration> configurations, |
| 7520 List<Combinator> combinators, |
| 7521 this.semicolon) |
| 7522 : super(comment, metadata, libraryUri) { |
| 7523 _configurations = new NodeListImpl<Configuration>(this, configurations); |
| 7524 _combinators = new NodeListImpl<Combinator>(this, combinators); |
| 7525 } |
| 7526 |
| 7527 @override |
| 7528 NodeList<Combinator> get combinators => _combinators; |
| 7529 |
| 7530 @override |
| 7531 NodeList<Configuration> get configurations => _configurations; |
| 7532 |
| 7533 @override |
| 7534 Token get endToken => semicolon; |
| 7535 |
| 7536 @override |
| 7537 Token get firstTokenAfterCommentAndMetadata => keyword; |
| 7538 |
| 7539 @deprecated |
| 7540 @override |
| 7541 Source get source => selectedSource; |
| 7542 |
| 7543 @deprecated |
| 7544 @override |
| 7545 void set source(Source source) { |
| 7546 selectedSource = source; |
| 7547 } |
| 7548 |
| 7549 @override |
| 7550 LibraryElement get uriElement; |
| 7551 } |
| 7552 |
| 7553 /** |
| 7554 * The "native" clause in an class declaration. |
| 7555 * |
| 7556 * nativeClause ::= |
| 7557 * 'native' [StringLiteral] |
| 7558 */ |
| 7559 class NativeClauseImpl extends AstNodeImpl implements NativeClause { |
| 7560 /** |
| 7561 * The token representing the 'native' keyword. |
| 7562 */ |
| 7563 @override |
| 7564 Token nativeKeyword; |
| 7565 |
| 7566 /** |
| 7567 * The name of the native object that implements the class. |
| 7568 */ |
| 7569 StringLiteral _name; |
| 7570 |
| 7571 /** |
| 7572 * Initialize a newly created native clause. |
| 7573 */ |
| 7574 NativeClauseImpl(this.nativeKeyword, StringLiteralImpl name) { |
| 7575 _name = _becomeParentOf(name); |
| 7576 } |
| 7577 |
| 7578 @override |
| 7579 Token get beginToken => nativeKeyword; |
| 7580 |
| 7581 @override |
| 7582 Iterable<SyntacticEntity> get childEntities => |
| 7583 new ChildEntities()..add(nativeKeyword)..add(_name); |
| 7584 |
| 7585 @override |
| 7586 Token get endToken => _name.endToken; |
| 7587 |
| 7588 @override |
| 7589 StringLiteral get name => _name; |
| 7590 |
| 7591 @override |
| 7592 void set name(StringLiteral name) { |
| 7593 _name = _becomeParentOf(name as AstNodeImpl); |
| 7594 } |
| 7595 |
| 7596 @override |
| 7597 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7598 visitor.visitNativeClause(this); |
| 7599 |
| 7600 @override |
| 7601 void visitChildren(AstVisitor visitor) { |
| 7602 _name?.accept(visitor); |
| 7603 } |
| 7604 } |
| 7605 |
| 7606 /** |
| 7607 * A function body that consists of a native keyword followed by a string |
| 7608 * literal. |
| 7609 * |
| 7610 * nativeFunctionBody ::= |
| 7611 * 'native' [SimpleStringLiteral] ';' |
| 7612 */ |
| 7613 class NativeFunctionBodyImpl extends FunctionBodyImpl |
| 7614 implements NativeFunctionBody { |
| 7615 /** |
| 7616 * The token representing 'native' that marks the start of the function body. |
| 7617 */ |
| 7618 @override |
| 7619 Token nativeKeyword; |
| 7620 |
| 7621 /** |
| 7622 * The string literal, after the 'native' token. |
| 7623 */ |
| 7624 StringLiteral _stringLiteral; |
| 7625 |
| 7626 /** |
| 7627 * The token representing the semicolon that marks the end of the function |
| 7628 * body. |
| 7629 */ |
| 7630 @override |
| 7631 Token semicolon; |
| 7632 |
| 7633 /** |
| 7634 * Initialize a newly created function body consisting of the 'native' token, |
| 7635 * a string literal, and a semicolon. |
| 7636 */ |
| 7637 NativeFunctionBodyImpl( |
| 7638 this.nativeKeyword, StringLiteralImpl stringLiteral, this.semicolon) { |
| 7639 _stringLiteral = _becomeParentOf(stringLiteral); |
| 7640 } |
| 7641 |
| 7642 @override |
| 7643 Token get beginToken => nativeKeyword; |
| 7644 |
| 7645 @override |
| 7646 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 7647 ..add(nativeKeyword) |
| 7648 ..add(_stringLiteral) |
| 7649 ..add(semicolon); |
| 7650 |
| 7651 @override |
| 7652 Token get endToken => semicolon; |
| 7653 |
| 7654 @override |
| 7655 StringLiteral get stringLiteral => _stringLiteral; |
| 7656 |
| 7657 @override |
| 7658 void set stringLiteral(StringLiteral stringLiteral) { |
| 7659 _stringLiteral = _becomeParentOf(stringLiteral as AstNodeImpl); |
| 7660 } |
| 7661 |
| 7662 @override |
| 7663 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7664 visitor.visitNativeFunctionBody(this); |
| 7665 |
| 7666 @override |
| 7667 void visitChildren(AstVisitor visitor) { |
| 7668 _stringLiteral?.accept(visitor); |
| 7669 } |
| 7670 } |
| 7671 |
| 7672 /** |
| 7673 * A list of AST nodes that have a common parent. |
| 7674 */ |
| 7675 class NodeListImpl<E extends AstNode> extends Object |
| 7676 with ListMixin<E> |
| 7677 implements NodeList<E> { |
| 7678 /** |
| 7679 * The node that is the parent of each of the elements in the list. |
| 7680 */ |
| 7681 AstNodeImpl _owner; |
| 7682 |
| 7683 /** |
| 7684 * The elements contained in the list. |
| 7685 */ |
| 7686 List<E> _elements = <E>[]; |
| 7687 |
| 7688 /** |
| 7689 * Initialize a newly created list of nodes such that all of the nodes that |
| 7690 * are added to the list will have their parent set to the given [owner]. The |
| 7691 * list will initially be populated with the given [elements]. |
| 7692 */ |
| 7693 NodeListImpl(this._owner, [List<E> elements]) { |
| 7694 addAll(elements); |
| 7695 } |
| 7696 |
| 7697 @override |
| 7698 Token get beginToken { |
| 7699 if (_elements.length == 0) { |
| 7700 return null; |
| 7701 } |
| 7702 return _elements[0].beginToken; |
| 7703 } |
| 7704 |
| 7705 @override |
| 7706 Token get endToken { |
| 7707 int length = _elements.length; |
| 7708 if (length == 0) { |
| 7709 return null; |
| 7710 } |
| 7711 return _elements[length - 1].endToken; |
| 7712 } |
| 7713 |
| 7714 int get length => _elements.length; |
| 7715 |
| 7716 @deprecated // Never intended for public use. |
| 7717 @override |
| 7718 void set length(int newLength) { |
| 7719 throw new UnsupportedError("Cannot resize NodeList."); |
| 7720 } |
| 7721 |
| 7722 @override |
| 7723 AstNode get owner => _owner; |
| 7724 |
| 7725 @override |
| 7726 void set owner(AstNode value) { |
| 7727 _owner = value as AstNodeImpl; |
| 7728 } |
| 7729 |
| 7730 E operator [](int index) { |
| 7731 if (index < 0 || index >= _elements.length) { |
| 7732 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
| 7733 } |
| 7734 return _elements[index]; |
| 7735 } |
| 7736 |
| 7737 void operator []=(int index, E node) { |
| 7738 if (index < 0 || index >= _elements.length) { |
| 7739 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
| 7740 } |
| 7741 _owner._becomeParentOf(node as AstNodeImpl); |
| 7742 _elements[index] = node; |
| 7743 } |
| 7744 |
| 7745 @override |
| 7746 accept(AstVisitor visitor) { |
| 7747 int length = _elements.length; |
| 7748 for (var i = 0; i < length; i++) { |
| 7749 _elements[i].accept(visitor); |
| 7750 } |
| 7751 } |
| 7752 |
| 7753 @override |
| 7754 void add(E node) { |
| 7755 insert(length, node); |
| 7756 } |
| 7757 |
| 7758 @override |
| 7759 bool addAll(Iterable<E> nodes) { |
| 7760 if (nodes != null && !nodes.isEmpty) { |
| 7761 if (nodes is List<E>) { |
| 7762 int length = nodes.length; |
| 7763 for (int i = 0; i < length; i++) { |
| 7764 E node = nodes[i]; |
| 7765 _elements.add(node); |
| 7766 _owner._becomeParentOf(node as AstNodeImpl); |
| 7767 } |
| 7768 } else { |
| 7769 for (E node in nodes) { |
| 7770 _elements.add(node); |
| 7771 _owner._becomeParentOf(node as AstNodeImpl); |
| 7772 } |
| 7773 } |
| 7774 return true; |
| 7775 } |
| 7776 return false; |
| 7777 } |
| 7778 |
| 7779 @override |
| 7780 void clear() { |
| 7781 _elements = <E>[]; |
| 7782 } |
| 7783 |
| 7784 @override |
| 7785 void insert(int index, E node) { |
| 7786 int length = _elements.length; |
| 7787 if (index < 0 || index > length) { |
| 7788 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
| 7789 } |
| 7790 _owner._becomeParentOf(node as AstNodeImpl); |
| 7791 if (length == 0) { |
| 7792 _elements.add(node); |
| 7793 } else { |
| 7794 _elements.insert(index, node); |
| 7795 } |
| 7796 } |
| 7797 |
| 7798 @override |
| 7799 E removeAt(int index) { |
| 7800 if (index < 0 || index >= _elements.length) { |
| 7801 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
| 7802 } |
| 7803 E removedNode = _elements[index]; |
| 7804 _elements.removeAt(index); |
| 7805 return removedNode; |
| 7806 } |
| 7807 } |
| 7808 |
| 7809 /** |
| 7810 * A formal parameter that is required (is not optional). |
| 7811 * |
| 7812 * normalFormalParameter ::= |
| 7813 * [FunctionTypedFormalParameter] |
| 7814 * | [FieldFormalParameter] |
| 7815 * | [SimpleFormalParameter] |
| 7816 */ |
| 7817 abstract class NormalFormalParameterImpl extends FormalParameterImpl |
| 7818 implements NormalFormalParameter { |
| 7819 /** |
| 7820 * The documentation comment associated with this parameter, or `null` if this |
| 7821 * parameter does not have a documentation comment associated with it. |
| 7822 */ |
| 7823 Comment _comment; |
| 7824 |
| 7825 /** |
| 7826 * The annotations associated with this parameter. |
| 7827 */ |
| 7828 NodeList<Annotation> _metadata; |
| 7829 |
| 7830 /** |
| 7831 * The name of the parameter being declared. |
| 7832 */ |
| 7833 SimpleIdentifier _identifier; |
| 7834 |
| 7835 /** |
| 7836 * Initialize a newly created formal parameter. Either or both of the |
| 7837 * [comment] and [metadata] can be `null` if the parameter does not have the |
| 7838 * corresponding attribute. |
| 7839 */ |
| 7840 NormalFormalParameterImpl(CommentImpl comment, List<Annotation> metadata, |
| 7841 SimpleIdentifierImpl identifier) { |
| 7842 _comment = _becomeParentOf(comment); |
| 7843 _metadata = new NodeListImpl<Annotation>(this, metadata); |
| 7844 _identifier = _becomeParentOf(identifier); |
| 7845 } |
| 7846 |
| 7847 @override |
| 7848 Comment get documentationComment => _comment; |
| 7849 |
| 7850 @override |
| 7851 void set documentationComment(Comment comment) { |
| 7852 _comment = _becomeParentOf(comment as AstNodeImpl); |
| 7853 } |
| 7854 |
| 7855 @override |
| 7856 SimpleIdentifier get identifier => _identifier; |
| 7857 |
| 7858 @override |
| 7859 void set identifier(SimpleIdentifier identifier) { |
| 7860 _identifier = _becomeParentOf(identifier as AstNodeImpl); |
| 7861 } |
| 7862 |
| 7863 @override |
| 7864 ParameterKind get kind { |
| 7865 AstNode parent = this.parent; |
| 7866 if (parent is DefaultFormalParameter) { |
| 7867 return parent.kind; |
| 7868 } |
| 7869 return ParameterKind.REQUIRED; |
| 7870 } |
| 7871 |
| 7872 @override |
| 7873 NodeList<Annotation> get metadata => _metadata; |
| 7874 |
| 7875 @override |
| 7876 void set metadata(List<Annotation> metadata) { |
| 7877 _metadata.clear(); |
| 7878 _metadata.addAll(metadata); |
| 7879 } |
| 7880 |
| 7881 @override |
| 7882 List<AstNode> get sortedCommentAndAnnotations { |
| 7883 return <AstNode>[] |
| 7884 ..add(_comment) |
| 7885 ..addAll(_metadata) |
| 7886 ..sort(AstNode.LEXICAL_ORDER); |
| 7887 } |
| 7888 |
| 7889 ChildEntities get _childEntities { |
| 7890 ChildEntities result = new ChildEntities(); |
| 7891 if (_commentIsBeforeAnnotations()) { |
| 7892 result |
| 7893 ..add(_comment) |
| 7894 ..addAll(_metadata); |
| 7895 } else { |
| 7896 result.addAll(sortedCommentAndAnnotations); |
| 7897 } |
| 7898 return result; |
| 7899 } |
| 7900 |
| 7901 @override |
| 7902 void visitChildren(AstVisitor visitor) { |
| 7903 // |
| 7904 // Note that subclasses are responsible for visiting the identifier because |
| 7905 // they often need to visit other nodes before visiting the identifier. |
| 7906 // |
| 7907 if (_commentIsBeforeAnnotations()) { |
| 7908 _comment?.accept(visitor); |
| 7909 _metadata.accept(visitor); |
| 7910 } else { |
| 7911 List<AstNode> children = sortedCommentAndAnnotations; |
| 7912 int length = children.length; |
| 7913 for (int i = 0; i < length; i++) { |
| 7914 children[i].accept(visitor); |
| 7915 } |
| 7916 } |
| 7917 } |
| 7918 |
| 7919 /** |
| 7920 * Return `true` if the comment is lexically before any annotations. |
| 7921 */ |
| 7922 bool _commentIsBeforeAnnotations() { |
| 7923 if (_comment == null || _metadata.isEmpty) { |
| 7924 return true; |
| 7925 } |
| 7926 Annotation firstAnnotation = _metadata[0]; |
| 7927 return _comment.offset < firstAnnotation.offset; |
| 7928 } |
| 7929 } |
| 7930 |
| 7931 /** |
| 7932 * A null literal expression. |
| 7933 * |
| 7934 * nullLiteral ::= |
| 7935 * 'null' |
| 7936 */ |
| 7937 class NullLiteralImpl extends LiteralImpl implements NullLiteral { |
| 7938 /** |
| 7939 * The token representing the literal. |
| 7940 */ |
| 7941 Token literal; |
| 7942 |
| 7943 /** |
| 7944 * Initialize a newly created null literal. |
| 7945 */ |
| 7946 NullLiteralImpl(this.literal); |
| 7947 |
| 7948 @override |
| 7949 Token get beginToken => literal; |
| 7950 |
| 7951 @override |
| 7952 Iterable<SyntacticEntity> get childEntities => |
| 7953 new ChildEntities()..add(literal); |
| 7954 |
| 7955 @override |
| 7956 Token get endToken => literal; |
| 7957 |
| 7958 @override |
| 7959 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 7960 visitor.visitNullLiteral(this); |
| 7961 |
| 7962 @override |
| 7963 void visitChildren(AstVisitor visitor) { |
| 7964 // There are no children to visit. |
| 7965 } |
| 7966 } |
| 7967 |
| 7968 /** |
| 7969 * A parenthesized expression. |
| 7970 * |
| 7971 * parenthesizedExpression ::= |
| 7972 * '(' [Expression] ')' |
| 7973 */ |
| 7974 class ParenthesizedExpressionImpl extends ExpressionImpl |
| 7975 implements ParenthesizedExpression { |
| 7976 /** |
| 7977 * The left parenthesis. |
| 7978 */ |
| 7979 Token leftParenthesis; |
| 7980 |
| 7981 /** |
| 7982 * The expression within the parentheses. |
| 7983 */ |
| 7984 Expression _expression; |
| 7985 |
| 7986 /** |
| 7987 * The right parenthesis. |
| 7988 */ |
| 7989 Token rightParenthesis; |
| 7990 |
| 7991 /** |
| 7992 * Initialize a newly created parenthesized expression. |
| 7993 */ |
| 7994 ParenthesizedExpressionImpl( |
| 7995 this.leftParenthesis, ExpressionImpl expression, this.rightParenthesis) { |
| 7996 _expression = _becomeParentOf(expression); |
| 7997 } |
| 7998 |
| 7999 @override |
| 8000 Token get beginToken => leftParenthesis; |
| 8001 |
| 8002 @override |
| 8003 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 8004 ..add(leftParenthesis) |
| 8005 ..add(_expression) |
| 8006 ..add(rightParenthesis); |
| 8007 |
| 8008 @override |
| 8009 Token get endToken => rightParenthesis; |
| 8010 |
| 8011 @override |
| 8012 Expression get expression => _expression; |
| 8013 |
| 8014 @override |
| 8015 void set expression(Expression expression) { |
| 8016 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 8017 } |
| 8018 |
| 8019 @override |
| 8020 int get precedence => 15; |
| 8021 |
| 8022 @override |
| 8023 Expression get unParenthesized { |
| 8024 // This is somewhat inefficient, but it avoids a stack overflow in the |
| 8025 // degenerate case. |
| 8026 Expression expression = _expression; |
| 8027 while (expression is ParenthesizedExpressionImpl) { |
| 8028 expression = (expression as ParenthesizedExpressionImpl)._expression; |
| 8029 } |
| 8030 return expression; |
| 8031 } |
| 8032 |
| 8033 @override |
| 8034 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8035 visitor.visitParenthesizedExpression(this); |
| 8036 |
| 8037 @override |
| 8038 void visitChildren(AstVisitor visitor) { |
| 8039 _expression?.accept(visitor); |
| 8040 } |
| 8041 } |
| 8042 |
| 8043 /** |
| 8044 * A part directive. |
| 8045 * |
| 8046 * partDirective ::= |
| 8047 * [Annotation] 'part' [StringLiteral] ';' |
| 8048 */ |
| 8049 class PartDirectiveImpl extends UriBasedDirectiveImpl implements PartDirective { |
| 8050 /** |
| 8051 * The token representing the 'part' keyword. |
| 8052 */ |
| 8053 @override |
| 8054 Token partKeyword; |
| 8055 |
| 8056 /** |
| 8057 * The semicolon terminating the directive. |
| 8058 */ |
| 8059 @override |
| 8060 Token semicolon; |
| 8061 |
| 8062 /** |
| 8063 * Initialize a newly created part directive. Either or both of the [comment] |
| 8064 * and [metadata] can be `null` if the directive does not have the |
| 8065 * corresponding attribute. |
| 8066 */ |
| 8067 PartDirectiveImpl(Comment comment, List<Annotation> metadata, |
| 8068 this.partKeyword, StringLiteral partUri, this.semicolon) |
| 8069 : super(comment, metadata, partUri); |
| 8070 |
| 8071 @override |
| 8072 Iterable<SyntacticEntity> get childEntities => |
| 8073 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon); |
| 8074 |
| 8075 @override |
| 8076 Token get endToken => semicolon; |
| 8077 |
| 8078 @override |
| 8079 Token get firstTokenAfterCommentAndMetadata => partKeyword; |
| 8080 |
| 8081 @override |
| 8082 Token get keyword => partKeyword; |
| 8083 |
| 8084 @override |
| 8085 CompilationUnitElement get uriElement => element as CompilationUnitElement; |
| 8086 |
| 8087 @override |
| 8088 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8089 visitor.visitPartDirective(this); |
| 8090 } |
| 8091 |
| 8092 /** |
| 8093 * A part-of directive. |
| 8094 * |
| 8095 * partOfDirective ::= |
| 8096 * [Annotation] 'part' 'of' [Identifier] ';' |
| 8097 */ |
| 8098 class PartOfDirectiveImpl extends DirectiveImpl implements PartOfDirective { |
| 8099 /** |
| 8100 * The token representing the 'part' keyword. |
| 8101 */ |
| 8102 @override |
| 8103 Token partKeyword; |
| 8104 |
| 8105 /** |
| 8106 * The token representing the 'of' keyword. |
| 8107 */ |
| 8108 @override |
| 8109 Token ofKeyword; |
| 8110 |
| 8111 /** |
| 8112 * The name of the library that the containing compilation unit is part of. |
| 8113 */ |
| 8114 LibraryIdentifier _libraryName; |
| 8115 |
| 8116 /** |
| 8117 * The semicolon terminating the directive. |
| 8118 */ |
| 8119 @override |
| 8120 Token semicolon; |
| 8121 |
| 8122 /** |
| 8123 * Initialize a newly created part-of directive. Either or both of the |
| 8124 * [comment] and [metadata] can be `null` if the directive does not have the |
| 8125 * corresponding attribute. |
| 8126 */ |
| 8127 PartOfDirectiveImpl( |
| 8128 CommentImpl comment, |
| 8129 List<Annotation> metadata, |
| 8130 this.partKeyword, |
| 8131 this.ofKeyword, |
| 8132 LibraryIdentifierImpl libraryName, |
| 8133 this.semicolon) |
| 8134 : super(comment, metadata) { |
| 8135 _libraryName = _becomeParentOf(libraryName); |
| 8136 } |
| 8137 |
| 8138 @override |
| 8139 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 8140 ..add(partKeyword) |
| 8141 ..add(ofKeyword) |
| 8142 ..add(_libraryName) |
| 8143 ..add(semicolon); |
| 8144 |
| 8145 @override |
| 8146 Token get endToken => semicolon; |
| 8147 |
| 8148 @override |
| 8149 Token get firstTokenAfterCommentAndMetadata => partKeyword; |
| 8150 |
| 8151 @override |
| 8152 Token get keyword => partKeyword; |
| 8153 |
| 8154 @override |
| 8155 LibraryIdentifier get libraryName => _libraryName; |
| 8156 |
| 8157 @override |
| 8158 void set libraryName(LibraryIdentifier libraryName) { |
| 8159 _libraryName = _becomeParentOf(libraryName as AstNodeImpl); |
| 8160 } |
| 8161 |
| 8162 @override |
| 8163 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8164 visitor.visitPartOfDirective(this); |
| 8165 |
| 8166 @override |
| 8167 void visitChildren(AstVisitor visitor) { |
| 8168 super.visitChildren(visitor); |
| 8169 _libraryName?.accept(visitor); |
| 8170 } |
| 8171 } |
| 8172 |
| 8173 /** |
| 8174 * A postfix unary expression. |
| 8175 * |
| 8176 * postfixExpression ::= |
| 8177 * [Expression] [Token] |
| 8178 */ |
| 8179 class PostfixExpressionImpl extends ExpressionImpl |
| 8180 implements PostfixExpression { |
| 8181 /** |
| 8182 * The expression computing the operand for the operator. |
| 8183 */ |
| 8184 Expression _operand; |
| 8185 |
| 8186 /** |
| 8187 * The postfix operator being applied to the operand. |
| 8188 */ |
| 8189 @override |
| 8190 Token operator; |
| 8191 |
| 8192 /** |
| 8193 * The element associated with this the operator based on the propagated type |
| 8194 * of the operand, or `null` if the AST structure has not been resolved, if |
| 8195 * the operator is not user definable, or if the operator could not be |
| 8196 * resolved. |
| 8197 */ |
| 8198 @override |
| 8199 MethodElement propagatedElement; |
| 8200 |
| 8201 /** |
| 8202 * The element associated with the operator based on the static type of the |
| 8203 * operand, or `null` if the AST structure has not been resolved, if the |
| 8204 * operator is not user definable, or if the operator could not be resolved. |
| 8205 */ |
| 8206 @override |
| 8207 MethodElement staticElement; |
| 8208 |
| 8209 /** |
| 8210 * Initialize a newly created postfix expression. |
| 8211 */ |
| 8212 PostfixExpressionImpl(ExpressionImpl operand, this.operator) { |
| 8213 _operand = _becomeParentOf(operand); |
| 8214 } |
| 8215 |
| 8216 @override |
| 8217 Token get beginToken => _operand.beginToken; |
| 8218 |
| 8219 @override |
| 8220 MethodElement get bestElement { |
| 8221 MethodElement element = propagatedElement; |
| 8222 if (element == null) { |
| 8223 element = staticElement; |
| 8224 } |
| 8225 return element; |
| 8226 } |
| 8227 |
| 8228 @override |
| 8229 Iterable<SyntacticEntity> get childEntities => |
| 8230 new ChildEntities()..add(_operand)..add(operator); |
| 8231 |
| 8232 @override |
| 8233 Token get endToken => operator; |
| 8234 |
| 8235 @override |
| 8236 Expression get operand => _operand; |
| 8237 |
| 8238 @override |
| 8239 void set operand(Expression expression) { |
| 8240 _operand = _becomeParentOf(expression as AstNodeImpl); |
| 8241 } |
| 8242 |
| 8243 @override |
| 8244 int get precedence => 15; |
| 8245 |
| 8246 /** |
| 8247 * If the AST structure has been resolved, and the function being invoked is |
| 8248 * known based on propagated type information, then return the parameter |
| 8249 * element representing the parameter to which the value of the operand will |
| 8250 * be bound. Otherwise, return `null`. |
| 8251 */ |
| 8252 ParameterElement get _propagatedParameterElementForOperand { |
| 8253 if (propagatedElement == null) { |
| 8254 return null; |
| 8255 } |
| 8256 List<ParameterElement> parameters = propagatedElement.parameters; |
| 8257 if (parameters.length < 1) { |
| 8258 return null; |
| 8259 } |
| 8260 return parameters[0]; |
| 8261 } |
| 8262 |
| 8263 /** |
| 8264 * If the AST structure has been resolved, and the function being invoked is |
| 8265 * known based on static type information, then return the parameter element |
| 8266 * representing the parameter to which the value of the operand will be bound. |
| 8267 * Otherwise, return `null`. |
| 8268 */ |
| 8269 ParameterElement get _staticParameterElementForOperand { |
| 8270 if (staticElement == null) { |
| 8271 return null; |
| 8272 } |
| 8273 List<ParameterElement> parameters = staticElement.parameters; |
| 8274 if (parameters.length < 1) { |
| 8275 return null; |
| 8276 } |
| 8277 return parameters[0]; |
| 8278 } |
| 8279 |
| 8280 @override |
| 8281 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8282 visitor.visitPostfixExpression(this); |
| 8283 |
| 8284 @override |
| 8285 void visitChildren(AstVisitor visitor) { |
| 8286 _operand?.accept(visitor); |
| 8287 } |
| 8288 } |
| 8289 |
| 8290 /** |
| 8291 * An identifier that is prefixed or an access to an object property where the |
| 8292 * target of the property access is a simple identifier. |
| 8293 * |
| 8294 * prefixedIdentifier ::= |
| 8295 * [SimpleIdentifier] '.' [SimpleIdentifier] |
| 8296 */ |
| 8297 class PrefixedIdentifierImpl extends IdentifierImpl |
| 8298 implements PrefixedIdentifier { |
| 8299 /** |
| 8300 * The prefix associated with the library in which the identifier is defined. |
| 8301 */ |
| 8302 SimpleIdentifier _prefix; |
| 8303 |
| 8304 /** |
| 8305 * The period used to separate the prefix from the identifier. |
| 8306 */ |
| 8307 Token period; |
| 8308 |
| 8309 /** |
| 8310 * The identifier being prefixed. |
| 8311 */ |
| 8312 SimpleIdentifier _identifier; |
| 8313 |
| 8314 /** |
| 8315 * Initialize a newly created prefixed identifier. |
| 8316 */ |
| 8317 PrefixedIdentifierImpl(SimpleIdentifierImpl prefix, this.period, |
| 8318 SimpleIdentifierImpl identifier) { |
| 8319 _prefix = _becomeParentOf(prefix); |
| 8320 _identifier = _becomeParentOf(identifier); |
| 8321 } |
| 8322 |
| 8323 /** |
| 8324 * Initialize a newly created prefixed identifier that does not take ownership |
| 8325 * of the components. The resulting node is only for temporary use, such as by |
| 8326 * resolution. |
| 8327 */ |
| 8328 PrefixedIdentifierImpl.temp(this._prefix, this._identifier) : period = null; |
| 8329 |
| 8330 @override |
| 8331 Token get beginToken => _prefix.beginToken; |
| 8332 |
| 8333 @override |
| 8334 Element get bestElement { |
| 8335 if (_identifier == null) { |
| 8336 return null; |
| 8337 } |
| 8338 return _identifier.bestElement; |
| 8339 } |
| 8340 |
| 8341 @override |
| 8342 Iterable<SyntacticEntity> get childEntities => |
| 8343 new ChildEntities()..add(_prefix)..add(period)..add(_identifier); |
| 8344 |
| 8345 @override |
| 8346 Token get endToken => _identifier.endToken; |
| 8347 |
| 8348 @override |
| 8349 SimpleIdentifier get identifier => _identifier; |
| 8350 |
| 8351 @override |
| 8352 void set identifier(SimpleIdentifier identifier) { |
| 8353 _identifier = _becomeParentOf(identifier as AstNodeImpl); |
| 8354 } |
| 8355 |
| 8356 @override |
| 8357 bool get isDeferred { |
| 8358 Element element = _prefix.staticElement; |
| 8359 if (element is PrefixElement) { |
| 8360 List<ImportElement> imports = |
| 8361 element.enclosingElement.getImportsWithPrefix(element); |
| 8362 if (imports.length != 1) { |
| 8363 return false; |
| 8364 } |
| 8365 return imports[0].isDeferred; |
| 8366 } |
| 8367 return false; |
| 8368 } |
| 8369 |
| 8370 @override |
| 8371 String get name => "${_prefix.name}.${_identifier.name}"; |
| 8372 |
| 8373 @override |
| 8374 int get precedence => 15; |
| 8375 |
| 8376 @override |
| 8377 SimpleIdentifier get prefix => _prefix; |
| 8378 |
| 8379 @override |
| 8380 void set prefix(SimpleIdentifier identifier) { |
| 8381 _prefix = _becomeParentOf(identifier as AstNodeImpl); |
| 8382 } |
| 8383 |
| 8384 @override |
| 8385 Element get propagatedElement { |
| 8386 if (_identifier == null) { |
| 8387 return null; |
| 8388 } |
| 8389 return _identifier.propagatedElement; |
| 8390 } |
| 8391 |
| 8392 @override |
| 8393 Element get staticElement { |
| 8394 if (_identifier == null) { |
| 8395 return null; |
| 8396 } |
| 8397 return _identifier.staticElement; |
| 8398 } |
| 8399 |
| 8400 @override |
| 8401 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8402 visitor.visitPrefixedIdentifier(this); |
| 8403 |
| 8404 @override |
| 8405 void visitChildren(AstVisitor visitor) { |
| 8406 _prefix?.accept(visitor); |
| 8407 _identifier?.accept(visitor); |
| 8408 } |
| 8409 } |
| 8410 |
| 8411 /** |
| 8412 * A prefix unary expression. |
| 8413 * |
| 8414 * prefixExpression ::= |
| 8415 * [Token] [Expression] |
| 8416 */ |
| 8417 class PrefixExpressionImpl extends ExpressionImpl implements PrefixExpression { |
| 8418 /** |
| 8419 * The prefix operator being applied to the operand. |
| 8420 */ |
| 8421 Token operator; |
| 8422 |
| 8423 /** |
| 8424 * The expression computing the operand for the operator. |
| 8425 */ |
| 8426 Expression _operand; |
| 8427 |
| 8428 /** |
| 8429 * The element associated with the operator based on the static type of the |
| 8430 * operand, or `null` if the AST structure has not been resolved, if the |
| 8431 * operator is not user definable, or if the operator could not be resolved. |
| 8432 */ |
| 8433 MethodElement staticElement; |
| 8434 |
| 8435 /** |
| 8436 * The element associated with the operator based on the propagated type of |
| 8437 * the operand, or `null` if the AST structure has not been resolved, if the |
| 8438 * operator is not user definable, or if the operator could not be resolved. |
| 8439 */ |
| 8440 MethodElement propagatedElement; |
| 8441 |
| 8442 /** |
| 8443 * Initialize a newly created prefix expression. |
| 8444 */ |
| 8445 PrefixExpressionImpl(this.operator, ExpressionImpl operand) { |
| 8446 _operand = _becomeParentOf(operand); |
| 8447 } |
| 8448 |
| 8449 @override |
| 8450 Token get beginToken => operator; |
| 8451 |
| 8452 @override |
| 8453 MethodElement get bestElement { |
| 8454 MethodElement element = propagatedElement; |
| 8455 if (element == null) { |
| 8456 element = staticElement; |
| 8457 } |
| 8458 return element; |
| 8459 } |
| 8460 |
| 8461 @override |
| 8462 Iterable<SyntacticEntity> get childEntities => |
| 8463 new ChildEntities()..add(operator)..add(_operand); |
| 8464 |
| 8465 @override |
| 8466 Token get endToken => _operand.endToken; |
| 8467 |
| 8468 @override |
| 8469 Expression get operand => _operand; |
| 8470 |
| 8471 @override |
| 8472 void set operand(Expression expression) { |
| 8473 _operand = _becomeParentOf(expression as AstNodeImpl); |
| 8474 } |
| 8475 |
| 8476 @override |
| 8477 int get precedence => 14; |
| 8478 |
| 8479 /** |
| 8480 * If the AST structure has been resolved, and the function being invoked is |
| 8481 * known based on propagated type information, then return the parameter |
| 8482 * element representing the parameter to which the value of the operand will |
| 8483 * be bound. Otherwise, return `null`. |
| 8484 */ |
| 8485 ParameterElement get _propagatedParameterElementForOperand { |
| 8486 if (propagatedElement == null) { |
| 8487 return null; |
| 8488 } |
| 8489 List<ParameterElement> parameters = propagatedElement.parameters; |
| 8490 if (parameters.length < 1) { |
| 8491 return null; |
| 8492 } |
| 8493 return parameters[0]; |
| 8494 } |
| 8495 |
| 8496 /** |
| 8497 * If the AST structure has been resolved, and the function being invoked is |
| 8498 * known based on static type information, then return the parameter element |
| 8499 * representing the parameter to which the value of the operand will be bound. |
| 8500 * Otherwise, return `null`. |
| 8501 */ |
| 8502 ParameterElement get _staticParameterElementForOperand { |
| 8503 if (staticElement == null) { |
| 8504 return null; |
| 8505 } |
| 8506 List<ParameterElement> parameters = staticElement.parameters; |
| 8507 if (parameters.length < 1) { |
| 8508 return null; |
| 8509 } |
| 8510 return parameters[0]; |
| 8511 } |
| 8512 |
| 8513 @override |
| 8514 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8515 visitor.visitPrefixExpression(this); |
| 8516 |
| 8517 @override |
| 8518 void visitChildren(AstVisitor visitor) { |
| 8519 _operand?.accept(visitor); |
| 8520 } |
| 8521 } |
| 8522 |
| 8523 /** |
| 8524 * The access of a property of an object. |
| 8525 * |
| 8526 * Note, however, that accesses to properties of objects can also be represented |
| 8527 * as [PrefixedIdentifier] nodes in cases where the target is also a simple |
| 8528 * identifier. |
| 8529 * |
| 8530 * propertyAccess ::= |
| 8531 * [Expression] '.' [SimpleIdentifier] |
| 8532 */ |
| 8533 class PropertyAccessImpl extends ExpressionImpl implements PropertyAccess { |
| 8534 /** |
| 8535 * The expression computing the object defining the property being accessed. |
| 8536 */ |
| 8537 Expression _target; |
| 8538 |
| 8539 /** |
| 8540 * The property access operator. |
| 8541 */ |
| 8542 Token operator; |
| 8543 |
| 8544 /** |
| 8545 * The name of the property being accessed. |
| 8546 */ |
| 8547 SimpleIdentifier _propertyName; |
| 8548 |
| 8549 /** |
| 8550 * Initialize a newly created property access expression. |
| 8551 */ |
| 8552 PropertyAccessImpl( |
| 8553 ExpressionImpl target, this.operator, SimpleIdentifierImpl propertyName) { |
| 8554 _target = _becomeParentOf(target); |
| 8555 _propertyName = _becomeParentOf(propertyName); |
| 8556 } |
| 8557 |
| 8558 @override |
| 8559 Token get beginToken { |
| 8560 if (_target != null) { |
| 8561 return _target.beginToken; |
| 8562 } |
| 8563 return operator; |
| 8564 } |
| 8565 |
| 8566 @override |
| 8567 Iterable<SyntacticEntity> get childEntities => |
| 8568 new ChildEntities()..add(_target)..add(operator)..add(_propertyName); |
| 8569 |
| 8570 @override |
| 8571 Token get endToken => _propertyName.endToken; |
| 8572 |
| 8573 @override |
| 8574 bool get isAssignable => true; |
| 8575 |
| 8576 @override |
| 8577 bool get isCascaded => |
| 8578 operator != null && operator.type == TokenType.PERIOD_PERIOD; |
| 8579 |
| 8580 @override |
| 8581 int get precedence => 15; |
| 8582 |
| 8583 @override |
| 8584 SimpleIdentifier get propertyName => _propertyName; |
| 8585 |
| 8586 @override |
| 8587 void set propertyName(SimpleIdentifier identifier) { |
| 8588 _propertyName = _becomeParentOf(identifier as AstNodeImpl); |
| 8589 } |
| 8590 |
| 8591 @override |
| 8592 Expression get realTarget { |
| 8593 if (isCascaded) { |
| 8594 AstNode ancestor = parent; |
| 8595 while (ancestor is! CascadeExpression) { |
| 8596 if (ancestor == null) { |
| 8597 return _target; |
| 8598 } |
| 8599 ancestor = ancestor.parent; |
| 8600 } |
| 8601 return (ancestor as CascadeExpression).target; |
| 8602 } |
| 8603 return _target; |
| 8604 } |
| 8605 |
| 8606 @override |
| 8607 Expression get target => _target; |
| 8608 |
| 8609 @override |
| 8610 void set target(Expression expression) { |
| 8611 _target = _becomeParentOf(expression as AstNodeImpl); |
| 8612 } |
| 8613 |
| 8614 @override |
| 8615 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8616 visitor.visitPropertyAccess(this); |
| 8617 |
| 8618 @override |
| 8619 void visitChildren(AstVisitor visitor) { |
| 8620 _target?.accept(visitor); |
| 8621 _propertyName?.accept(visitor); |
| 8622 } |
| 8623 } |
| 8624 |
| 8625 /** |
| 8626 * The invocation of a constructor in the same class from within a constructor's |
| 8627 * initialization list. |
| 8628 * |
| 8629 * redirectingConstructorInvocation ::= |
| 8630 * 'this' ('.' identifier)? arguments |
| 8631 */ |
| 8632 class RedirectingConstructorInvocationImpl extends ConstructorInitializerImpl |
| 8633 implements RedirectingConstructorInvocation { |
| 8634 /** |
| 8635 * The token for the 'this' keyword. |
| 8636 */ |
| 8637 Token thisKeyword; |
| 8638 |
| 8639 /** |
| 8640 * The token for the period before the name of the constructor that is being |
| 8641 * invoked, or `null` if the unnamed constructor is being invoked. |
| 8642 */ |
| 8643 Token period; |
| 8644 |
| 8645 /** |
| 8646 * The name of the constructor that is being invoked, or `null` if the unnamed |
| 8647 * constructor is being invoked. |
| 8648 */ |
| 8649 SimpleIdentifier _constructorName; |
| 8650 |
| 8651 /** |
| 8652 * The list of arguments to the constructor. |
| 8653 */ |
| 8654 ArgumentList _argumentList; |
| 8655 |
| 8656 /** |
| 8657 * The element associated with the constructor based on static type |
| 8658 * information, or `null` if the AST structure has not been resolved or if the |
| 8659 * constructor could not be resolved. |
| 8660 */ |
| 8661 ConstructorElement staticElement; |
| 8662 |
| 8663 /** |
| 8664 * Initialize a newly created redirecting invocation to invoke the constructor |
| 8665 * with the given name with the given arguments. The [constructorName] can be |
| 8666 * `null` if the constructor being invoked is the unnamed constructor. |
| 8667 */ |
| 8668 RedirectingConstructorInvocationImpl(this.thisKeyword, this.period, |
| 8669 SimpleIdentifierImpl constructorName, ArgumentListImpl argumentList) { |
| 8670 _constructorName = _becomeParentOf(constructorName); |
| 8671 _argumentList = _becomeParentOf(argumentList); |
| 8672 } |
| 8673 |
| 8674 @override |
| 8675 ArgumentList get argumentList => _argumentList; |
| 8676 |
| 8677 @override |
| 8678 void set argumentList(ArgumentList argumentList) { |
| 8679 _argumentList = _becomeParentOf(argumentList as AstNodeImpl); |
| 8680 } |
| 8681 |
| 8682 @override |
| 8683 Token get beginToken => thisKeyword; |
| 8684 |
| 8685 @override |
| 8686 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 8687 ..add(thisKeyword) |
| 8688 ..add(period) |
| 8689 ..add(_constructorName) |
| 8690 ..add(_argumentList); |
| 8691 |
| 8692 @override |
| 8693 SimpleIdentifier get constructorName => _constructorName; |
| 8694 |
| 8695 @override |
| 8696 void set constructorName(SimpleIdentifier identifier) { |
| 8697 _constructorName = _becomeParentOf(identifier as AstNodeImpl); |
| 8698 } |
| 8699 |
| 8700 @override |
| 8701 Token get endToken => _argumentList.endToken; |
| 8702 |
| 8703 @override |
| 8704 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8705 visitor.visitRedirectingConstructorInvocation(this); |
| 8706 |
| 8707 @override |
| 8708 void visitChildren(AstVisitor visitor) { |
| 8709 _constructorName?.accept(visitor); |
| 8710 _argumentList?.accept(visitor); |
| 8711 } |
| 8712 } |
| 8713 |
| 8714 /** |
| 8715 * A rethrow expression. |
| 8716 * |
| 8717 * rethrowExpression ::= |
| 8718 * 'rethrow' |
| 8719 */ |
| 8720 class RethrowExpressionImpl extends ExpressionImpl |
| 8721 implements RethrowExpression { |
| 8722 /** |
| 8723 * The token representing the 'rethrow' keyword. |
| 8724 */ |
| 8725 Token rethrowKeyword; |
| 8726 |
| 8727 /** |
| 8728 * Initialize a newly created rethrow expression. |
| 8729 */ |
| 8730 RethrowExpressionImpl(this.rethrowKeyword); |
| 8731 |
| 8732 @override |
| 8733 Token get beginToken => rethrowKeyword; |
| 8734 |
| 8735 @override |
| 8736 Iterable<SyntacticEntity> get childEntities => |
| 8737 new ChildEntities()..add(rethrowKeyword); |
| 8738 |
| 8739 @override |
| 8740 Token get endToken => rethrowKeyword; |
| 8741 |
| 8742 @override |
| 8743 int get precedence => 0; |
| 8744 |
| 8745 @override |
| 8746 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8747 visitor.visitRethrowExpression(this); |
| 8748 |
| 8749 @override |
| 8750 void visitChildren(AstVisitor visitor) { |
| 8751 // There are no children to visit. |
| 8752 } |
| 8753 } |
| 8754 |
| 8755 /** |
| 8756 * A return statement. |
| 8757 * |
| 8758 * returnStatement ::= |
| 8759 * 'return' [Expression]? ';' |
| 8760 */ |
| 8761 class ReturnStatementImpl extends StatementImpl implements ReturnStatement { |
| 8762 /** |
| 8763 * The token representing the 'return' keyword. |
| 8764 */ |
| 8765 Token returnKeyword; |
| 8766 |
| 8767 /** |
| 8768 * The expression computing the value to be returned, or `null` if no explicit |
| 8769 * value was provided. |
| 8770 */ |
| 8771 Expression _expression; |
| 8772 |
| 8773 /** |
| 8774 * The semicolon terminating the statement. |
| 8775 */ |
| 8776 Token semicolon; |
| 8777 |
| 8778 /** |
| 8779 * Initialize a newly created return statement. The [expression] can be `null` |
| 8780 * if no explicit value was provided. |
| 8781 */ |
| 8782 ReturnStatementImpl( |
| 8783 this.returnKeyword, ExpressionImpl expression, this.semicolon) { |
| 8784 _expression = _becomeParentOf(expression); |
| 8785 } |
| 8786 |
| 8787 @override |
| 8788 Token get beginToken => returnKeyword; |
| 8789 |
| 8790 @override |
| 8791 Iterable<SyntacticEntity> get childEntities => |
| 8792 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon); |
| 8793 |
| 8794 @override |
| 8795 Token get endToken => semicolon; |
| 8796 |
| 8797 @override |
| 8798 Expression get expression => _expression; |
| 8799 |
| 8800 @override |
| 8801 void set expression(Expression expression) { |
| 8802 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 8803 } |
| 8804 |
| 8805 @override |
| 8806 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8807 visitor.visitReturnStatement(this); |
| 8808 |
| 8809 @override |
| 8810 void visitChildren(AstVisitor visitor) { |
| 8811 _expression?.accept(visitor); |
| 8812 } |
| 8813 } |
| 8814 |
| 8815 /** |
| 8816 * A script tag that can optionally occur at the beginning of a compilation unit
. |
| 8817 * |
| 8818 * scriptTag ::= |
| 8819 * '#!' (~NEWLINE)* NEWLINE |
| 8820 */ |
| 8821 class ScriptTagImpl extends AstNodeImpl implements ScriptTag { |
| 8822 /** |
| 8823 * The token representing this script tag. |
| 8824 */ |
| 8825 Token scriptTag; |
| 8826 |
| 8827 /** |
| 8828 * Initialize a newly created script tag. |
| 8829 */ |
| 8830 ScriptTagImpl(this.scriptTag); |
| 8831 |
| 8832 @override |
| 8833 Token get beginToken => scriptTag; |
| 8834 |
| 8835 @override |
| 8836 Iterable<SyntacticEntity> get childEntities => |
| 8837 new ChildEntities()..add(scriptTag); |
| 8838 |
| 8839 @override |
| 8840 Token get endToken => scriptTag; |
| 8841 |
| 8842 @override |
| 8843 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8844 visitor.visitScriptTag(this); |
| 8845 |
| 8846 @override |
| 8847 void visitChildren(AstVisitor visitor) { |
| 8848 // There are no children to visit. |
| 8849 } |
| 8850 } |
| 8851 |
| 8852 /** |
| 8853 * A combinator that restricts the names being imported to those in a given list
. |
| 8854 * |
| 8855 * showCombinator ::= |
| 8856 * 'show' [SimpleIdentifier] (',' [SimpleIdentifier])* |
| 8857 */ |
| 8858 class ShowCombinatorImpl extends CombinatorImpl implements ShowCombinator { |
| 8859 /** |
| 8860 * The list of names from the library that are made visible by this combinator
. |
| 8861 */ |
| 8862 NodeList<SimpleIdentifier> _shownNames; |
| 8863 |
| 8864 /** |
| 8865 * Initialize a newly created import show combinator. |
| 8866 */ |
| 8867 ShowCombinatorImpl(Token keyword, List<SimpleIdentifier> shownNames) |
| 8868 : super(keyword) { |
| 8869 _shownNames = new NodeListImpl<SimpleIdentifier>(this, shownNames); |
| 8870 } |
| 8871 |
| 8872 @override |
| 8873 // TODO(paulberry): add commas. |
| 8874 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 8875 ..add(keyword) |
| 8876 ..addAll(_shownNames); |
| 8877 |
| 8878 @override |
| 8879 Token get endToken => _shownNames.endToken; |
| 8880 |
| 8881 @override |
| 8882 NodeList<SimpleIdentifier> get shownNames => _shownNames; |
| 8883 |
| 8884 @override |
| 8885 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8886 visitor.visitShowCombinator(this); |
| 8887 |
| 8888 @override |
| 8889 void visitChildren(AstVisitor visitor) { |
| 8890 _shownNames.accept(visitor); |
| 8891 } |
| 8892 } |
| 8893 |
| 8894 /** |
| 8895 * A simple formal parameter. |
| 8896 * |
| 8897 * simpleFormalParameter ::= |
| 8898 * ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier] |
| 8899 */ |
| 8900 class SimpleFormalParameterImpl extends NormalFormalParameterImpl |
| 8901 implements SimpleFormalParameter { |
| 8902 /** |
| 8903 * The token representing either the 'final', 'const' or 'var' keyword, or |
| 8904 * `null` if no keyword was used. |
| 8905 */ |
| 8906 Token keyword; |
| 8907 |
| 8908 /** |
| 8909 * The name of the declared type of the parameter, or `null` if the parameter |
| 8910 * does not have a declared type. |
| 8911 */ |
| 8912 TypeName _type; |
| 8913 |
| 8914 /** |
| 8915 * Initialize a newly created formal parameter. Either or both of the |
| 8916 * [comment] and [metadata] can be `null` if the parameter does not have the |
| 8917 * corresponding attribute. The [keyword] can be `null` if a type was |
| 8918 * specified. The [type] must be `null` if the keyword is 'var'. |
| 8919 */ |
| 8920 SimpleFormalParameterImpl(CommentImpl comment, List<Annotation> metadata, |
| 8921 this.keyword, TypeNameImpl type, SimpleIdentifierImpl identifier) |
| 8922 : super(comment, metadata, identifier) { |
| 8923 _type = _becomeParentOf(type); |
| 8924 } |
| 8925 |
| 8926 @override |
| 8927 Token get beginToken { |
| 8928 NodeList<Annotation> metadata = this.metadata; |
| 8929 if (!metadata.isEmpty) { |
| 8930 return metadata.beginToken; |
| 8931 } else if (keyword != null) { |
| 8932 return keyword; |
| 8933 } else if (_type != null) { |
| 8934 return _type.beginToken; |
| 8935 } |
| 8936 return identifier.beginToken; |
| 8937 } |
| 8938 |
| 8939 @override |
| 8940 Iterable<SyntacticEntity> get childEntities => |
| 8941 super._childEntities..add(keyword)..add(_type)..add(identifier); |
| 8942 |
| 8943 @override |
| 8944 Token get endToken => identifier.endToken; |
| 8945 |
| 8946 @override |
| 8947 bool get isConst => keyword?.keyword == Keyword.CONST; |
| 8948 |
| 8949 @override |
| 8950 bool get isFinal => keyword?.keyword == Keyword.FINAL; |
| 8951 |
| 8952 @override |
| 8953 TypeName get type => _type; |
| 8954 |
| 8955 @override |
| 8956 void set type(TypeName typeName) { |
| 8957 _type = _becomeParentOf(typeName as AstNodeImpl); |
| 8958 } |
| 8959 |
| 8960 @override |
| 8961 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8962 visitor.visitSimpleFormalParameter(this); |
| 8963 |
| 8964 @override |
| 8965 void visitChildren(AstVisitor visitor) { |
| 8966 super.visitChildren(visitor); |
| 8967 _type?.accept(visitor); |
| 8968 identifier?.accept(visitor); |
| 8969 } |
| 8970 } |
| 8971 |
| 8972 /** |
| 8973 * A simple identifier. |
| 8974 * |
| 8975 * simpleIdentifier ::= |
| 8976 * initialCharacter internalCharacter* |
| 8977 * |
| 8978 * initialCharacter ::= '_' | '$' | letter |
| 8979 * |
| 8980 * internalCharacter ::= '_' | '$' | letter | digit |
| 8981 */ |
| 8982 class SimpleIdentifierImpl extends IdentifierImpl implements SimpleIdentifier { |
| 8983 /** |
| 8984 * The token representing the identifier. |
| 8985 */ |
| 8986 Token token; |
| 8987 |
| 8988 /** |
| 8989 * The element associated with this identifier based on static type |
| 8990 * information, or `null` if the AST structure has not been resolved or if |
| 8991 * this identifier could not be resolved. |
| 8992 */ |
| 8993 Element _staticElement; |
| 8994 |
| 8995 /** |
| 8996 * The element associated with this identifier based on propagated type |
| 8997 * information, or `null` if the AST structure has not been resolved or if |
| 8998 * this identifier could not be resolved. |
| 8999 */ |
| 9000 Element _propagatedElement; |
| 9001 |
| 9002 /** |
| 9003 * If this expression is both in a getter and setter context, the |
| 9004 * [AuxiliaryElements] will be set to hold onto the static and propagated |
| 9005 * information. The auxiliary element will hold onto the elements from the |
| 9006 * getter context. |
| 9007 */ |
| 9008 AuxiliaryElements auxiliaryElements = null; |
| 9009 |
| 9010 /** |
| 9011 * Initialize a newly created identifier. |
| 9012 */ |
| 9013 SimpleIdentifierImpl(this.token); |
| 9014 |
| 9015 @override |
| 9016 Token get beginToken => token; |
| 9017 |
| 9018 @override |
| 9019 Element get bestElement { |
| 9020 if (_propagatedElement == null) { |
| 9021 return _staticElement; |
| 9022 } |
| 9023 return _propagatedElement; |
| 9024 } |
| 9025 |
| 9026 @override |
| 9027 Iterable<SyntacticEntity> get childEntities => |
| 9028 new ChildEntities()..add(token); |
| 9029 |
| 9030 @override |
| 9031 Token get endToken => token; |
| 9032 |
| 9033 @override |
| 9034 bool get isQualified { |
| 9035 AstNode parent = this.parent; |
| 9036 if (parent is PrefixedIdentifier) { |
| 9037 return identical(parent.identifier, this); |
| 9038 } else if (parent is PropertyAccess) { |
| 9039 return identical(parent.propertyName, this); |
| 9040 } else if (parent is MethodInvocation) { |
| 9041 MethodInvocation invocation = parent; |
| 9042 return identical(invocation.methodName, this) && |
| 9043 invocation.realTarget != null; |
| 9044 } |
| 9045 return false; |
| 9046 } |
| 9047 |
| 9048 @override |
| 9049 bool get isSynthetic => token.isSynthetic; |
| 9050 |
| 9051 @override |
| 9052 String get name => token.lexeme; |
| 9053 |
| 9054 @override |
| 9055 int get precedence => 16; |
| 9056 |
| 9057 @override |
| 9058 Element get propagatedElement => _propagatedElement; |
| 9059 |
| 9060 @override |
| 9061 void set propagatedElement(Element element) { |
| 9062 _propagatedElement = element; |
| 9063 } |
| 9064 |
| 9065 @override |
| 9066 Element get staticElement => _staticElement; |
| 9067 |
| 9068 @override |
| 9069 void set staticElement(Element element) { |
| 9070 _staticElement = element; |
| 9071 } |
| 9072 |
| 9073 @override |
| 9074 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9075 visitor.visitSimpleIdentifier(this); |
| 9076 |
| 9077 @override |
| 9078 bool inDeclarationContext() => false; |
| 9079 |
| 9080 @override |
| 9081 bool inGetterContext() { |
| 9082 // TODO(brianwilkerson) Convert this to a getter. |
| 9083 AstNode initialParent = this.parent; |
| 9084 AstNode parent = initialParent; |
| 9085 AstNode target = this; |
| 9086 // skip prefix |
| 9087 if (initialParent is PrefixedIdentifier) { |
| 9088 if (identical(initialParent.prefix, this)) { |
| 9089 return true; |
| 9090 } |
| 9091 parent = initialParent.parent; |
| 9092 target = initialParent; |
| 9093 } else if (initialParent is PropertyAccess) { |
| 9094 if (identical(initialParent.target, this)) { |
| 9095 return true; |
| 9096 } |
| 9097 parent = initialParent.parent; |
| 9098 target = initialParent; |
| 9099 } |
| 9100 // skip label |
| 9101 if (parent is Label) { |
| 9102 return false; |
| 9103 } |
| 9104 // analyze usage |
| 9105 if (parent is AssignmentExpression) { |
| 9106 if (identical(parent.leftHandSide, target) && |
| 9107 parent.operator.type == TokenType.EQ) { |
| 9108 return false; |
| 9109 } |
| 9110 } |
| 9111 if (parent is ConstructorFieldInitializer && |
| 9112 identical(parent.fieldName, target)) { |
| 9113 return false; |
| 9114 } |
| 9115 if (parent is ForEachStatement) { |
| 9116 if (identical(parent.identifier, target)) { |
| 9117 return false; |
| 9118 } |
| 9119 } |
| 9120 return true; |
| 9121 } |
| 9122 |
| 9123 @override |
| 9124 bool inSetterContext() { |
| 9125 // TODO(brianwilkerson) Convert this to a getter. |
| 9126 AstNode initialParent = this.parent; |
| 9127 AstNode parent = initialParent; |
| 9128 AstNode target = this; |
| 9129 // skip prefix |
| 9130 if (initialParent is PrefixedIdentifier) { |
| 9131 // if this is the prefix, then return false |
| 9132 if (identical(initialParent.prefix, this)) { |
| 9133 return false; |
| 9134 } |
| 9135 parent = initialParent.parent; |
| 9136 target = initialParent; |
| 9137 } else if (initialParent is PropertyAccess) { |
| 9138 if (identical(initialParent.target, this)) { |
| 9139 return false; |
| 9140 } |
| 9141 parent = initialParent.parent; |
| 9142 target = initialParent; |
| 9143 } |
| 9144 // analyze usage |
| 9145 if (parent is PrefixExpression) { |
| 9146 return parent.operator.type.isIncrementOperator; |
| 9147 } else if (parent is PostfixExpression) { |
| 9148 return true; |
| 9149 } else if (parent is AssignmentExpression) { |
| 9150 return identical(parent.leftHandSide, target); |
| 9151 } else if (parent is ForEachStatement) { |
| 9152 return identical(parent.identifier, target); |
| 9153 } |
| 9154 return false; |
| 9155 } |
| 9156 |
| 9157 @override |
| 9158 void visitChildren(AstVisitor visitor) { |
| 9159 // There are no children to visit. |
| 9160 } |
| 9161 } |
| 9162 |
| 9163 /** |
| 9164 * A string literal expression that does not contain any interpolations. |
| 9165 * |
| 9166 * simpleStringLiteral ::= |
| 9167 * rawStringLiteral |
| 9168 * | basicStringLiteral |
| 9169 * |
| 9170 * rawStringLiteral ::= |
| 9171 * 'r' basicStringLiteral |
| 9172 * |
| 9173 * simpleStringLiteral ::= |
| 9174 * multiLineStringLiteral |
| 9175 * | singleLineStringLiteral |
| 9176 * |
| 9177 * multiLineStringLiteral ::= |
| 9178 * "'''" characters "'''" |
| 9179 * | '"""' characters '"""' |
| 9180 * |
| 9181 * singleLineStringLiteral ::= |
| 9182 * "'" characters "'" |
| 9183 * | '"' characters '"' |
| 9184 */ |
| 9185 class SimpleStringLiteralImpl extends SingleStringLiteralImpl |
| 9186 implements SimpleStringLiteral { |
| 9187 /** |
| 9188 * The token representing the literal. |
| 9189 */ |
| 9190 Token literal; |
| 9191 |
| 9192 /** |
| 9193 * The value of the literal. |
| 9194 */ |
| 9195 String _value; |
| 9196 |
| 9197 /** |
| 9198 * Initialize a newly created simple string literal. |
| 9199 */ |
| 9200 SimpleStringLiteralImpl(this.literal, String value) { |
| 9201 _value = StringUtilities.intern(value); |
| 9202 } |
| 9203 |
| 9204 @override |
| 9205 Token get beginToken => literal; |
| 9206 |
| 9207 @override |
| 9208 Iterable<SyntacticEntity> get childEntities => |
| 9209 new ChildEntities()..add(literal); |
| 9210 |
| 9211 @override |
| 9212 int get contentsEnd => offset + _helper.end; |
| 9213 |
| 9214 @override |
| 9215 int get contentsOffset => offset + _helper.start; |
| 9216 |
| 9217 @override |
| 9218 Token get endToken => literal; |
| 9219 |
| 9220 @override |
| 9221 bool get isMultiline => _helper.isMultiline; |
| 9222 |
| 9223 @override |
| 9224 bool get isRaw => _helper.isRaw; |
| 9225 |
| 9226 @override |
| 9227 bool get isSingleQuoted => _helper.isSingleQuoted; |
| 9228 |
| 9229 @override |
| 9230 bool get isSynthetic => literal.isSynthetic; |
| 9231 |
| 9232 @override |
| 9233 String get value => _value; |
| 9234 |
| 9235 @override |
| 9236 void set value(String string) { |
| 9237 _value = StringUtilities.intern(_value); |
| 9238 } |
| 9239 |
| 9240 StringLexemeHelper get _helper { |
| 9241 return new StringLexemeHelper(literal.lexeme, true, true); |
| 9242 } |
| 9243 |
| 9244 @override |
| 9245 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9246 visitor.visitSimpleStringLiteral(this); |
| 9247 |
| 9248 @override |
| 9249 void visitChildren(AstVisitor visitor) { |
| 9250 // There are no children to visit. |
| 9251 } |
| 9252 |
| 9253 @override |
| 9254 void _appendStringValue(StringBuffer buffer) { |
| 9255 buffer.write(value); |
| 9256 } |
| 9257 } |
| 9258 |
| 9259 /** |
| 9260 * A single string literal expression. |
| 9261 * |
| 9262 * singleStringLiteral ::= |
| 9263 * [SimpleStringLiteral] |
| 9264 * | [StringInterpolation] |
| 9265 */ |
| 9266 abstract class SingleStringLiteralImpl extends StringLiteralImpl |
| 9267 implements SingleStringLiteral {} |
| 9268 |
| 9269 /** |
| 9270 * A node that represents a statement. |
| 9271 * |
| 9272 * statement ::= |
| 9273 * [Block] |
| 9274 * | [VariableDeclarationStatement] |
| 9275 * | [ForStatement] |
| 9276 * | [ForEachStatement] |
| 9277 * | [WhileStatement] |
| 9278 * | [DoStatement] |
| 9279 * | [SwitchStatement] |
| 9280 * | [IfStatement] |
| 9281 * | [TryStatement] |
| 9282 * | [BreakStatement] |
| 9283 * | [ContinueStatement] |
| 9284 * | [ReturnStatement] |
| 9285 * | [ExpressionStatement] |
| 9286 * | [FunctionDeclarationStatement] |
| 9287 */ |
| 9288 abstract class StatementImpl extends AstNodeImpl implements Statement { |
| 9289 @override |
| 9290 Statement get unlabeled => this; |
| 9291 } |
| 9292 |
| 9293 /** |
| 9294 * A string interpolation literal. |
| 9295 * |
| 9296 * stringInterpolation ::= |
| 9297 * ''' [InterpolationElement]* ''' |
| 9298 * | '"' [InterpolationElement]* '"' |
| 9299 */ |
| 9300 class StringInterpolationImpl extends SingleStringLiteralImpl |
| 9301 implements StringInterpolation { |
| 9302 /** |
| 9303 * The elements that will be composed to produce the resulting string. |
| 9304 */ |
| 9305 NodeList<InterpolationElement> _elements; |
| 9306 |
| 9307 /** |
| 9308 * Initialize a newly created string interpolation expression. |
| 9309 */ |
| 9310 StringInterpolationImpl(List<InterpolationElement> elements) { |
| 9311 _elements = new NodeListImpl<InterpolationElement>(this, elements); |
| 9312 } |
| 9313 |
| 9314 @override |
| 9315 Token get beginToken => _elements.beginToken; |
| 9316 |
| 9317 @override |
| 9318 Iterable<SyntacticEntity> get childEntities => |
| 9319 new ChildEntities()..addAll(_elements); |
| 9320 |
| 9321 @override |
| 9322 int get contentsEnd { |
| 9323 InterpolationString element = _elements.last; |
| 9324 return element.contentsEnd; |
| 9325 } |
| 9326 |
| 9327 @override |
| 9328 int get contentsOffset { |
| 9329 InterpolationString element = _elements.first; |
| 9330 return element.contentsOffset; |
| 9331 } |
| 9332 |
| 9333 /** |
| 9334 * Return the elements that will be composed to produce the resulting string. |
| 9335 */ |
| 9336 NodeList<InterpolationElement> get elements => _elements; |
| 9337 |
| 9338 @override |
| 9339 Token get endToken => _elements.endToken; |
| 9340 |
| 9341 @override |
| 9342 bool get isMultiline => _firstHelper.isMultiline; |
| 9343 |
| 9344 @override |
| 9345 bool get isRaw => false; |
| 9346 |
| 9347 @override |
| 9348 bool get isSingleQuoted => _firstHelper.isSingleQuoted; |
| 9349 |
| 9350 StringLexemeHelper get _firstHelper { |
| 9351 InterpolationString lastString = _elements.first; |
| 9352 String lexeme = lastString.contents.lexeme; |
| 9353 return new StringLexemeHelper(lexeme, true, false); |
| 9354 } |
| 9355 |
| 9356 @override |
| 9357 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9358 visitor.visitStringInterpolation(this); |
| 9359 |
| 9360 @override |
| 9361 void visitChildren(AstVisitor visitor) { |
| 9362 _elements.accept(visitor); |
| 9363 } |
| 9364 |
| 9365 @override |
| 9366 void _appendStringValue(StringBuffer buffer) { |
| 9367 throw new ArgumentError(); |
| 9368 } |
| 9369 } |
| 9370 |
| 9371 /** |
| 9372 * A helper for analyzing string lexemes. |
| 9373 */ |
| 9374 class StringLexemeHelper { |
| 9375 final String lexeme; |
| 9376 final bool isFirst; |
| 9377 final bool isLast; |
| 9378 |
| 9379 bool isRaw = false; |
| 9380 bool isSingleQuoted = false; |
| 9381 bool isMultiline = false; |
| 9382 int start = 0; |
| 9383 int end; |
| 9384 |
| 9385 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) { |
| 9386 if (isFirst) { |
| 9387 isRaw = StringUtilities.startsWithChar(lexeme, 0x72); |
| 9388 if (isRaw) { |
| 9389 start++; |
| 9390 } |
| 9391 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) { |
| 9392 isSingleQuoted = true; |
| 9393 isMultiline = true; |
| 9394 start += 3; |
| 9395 start = _trimInitialWhitespace(start); |
| 9396 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) { |
| 9397 isSingleQuoted = false; |
| 9398 isMultiline = true; |
| 9399 start += 3; |
| 9400 start = _trimInitialWhitespace(start); |
| 9401 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) { |
| 9402 isSingleQuoted = true; |
| 9403 isMultiline = false; |
| 9404 start++; |
| 9405 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) { |
| 9406 isSingleQuoted = false; |
| 9407 isMultiline = false; |
| 9408 start++; |
| 9409 } |
| 9410 } |
| 9411 end = lexeme.length; |
| 9412 if (isLast) { |
| 9413 if (start + 3 <= end && |
| 9414 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || |
| 9415 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) { |
| 9416 end -= 3; |
| 9417 } else if (start + 1 <= end && |
| 9418 (StringUtilities.endsWithChar(lexeme, 0x22) || |
| 9419 StringUtilities.endsWithChar(lexeme, 0x27))) { |
| 9420 end -= 1; |
| 9421 } |
| 9422 } |
| 9423 } |
| 9424 |
| 9425 /** |
| 9426 * Given the [lexeme] for a multi-line string whose content begins at the |
| 9427 * given [start] index, return the index of the first character that is |
| 9428 * included in the value of the string. According to the specification: |
| 9429 * |
| 9430 * If the first line of a multiline string consists solely of the whitespace |
| 9431 * characters defined by the production WHITESPACE 20.1), possibly prefixed |
| 9432 * by \, then that line is ignored, including the new line at its end. |
| 9433 */ |
| 9434 int _trimInitialWhitespace(int start) { |
| 9435 int length = lexeme.length; |
| 9436 int index = start; |
| 9437 while (index < length) { |
| 9438 int currentChar = lexeme.codeUnitAt(index); |
| 9439 if (currentChar == 0x0D) { |
| 9440 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) { |
| 9441 return index + 2; |
| 9442 } |
| 9443 return index + 1; |
| 9444 } else if (currentChar == 0x0A) { |
| 9445 return index + 1; |
| 9446 } else if (currentChar == 0x5C) { |
| 9447 if (index + 1 >= length) { |
| 9448 return start; |
| 9449 } |
| 9450 currentChar = lexeme.codeUnitAt(index + 1); |
| 9451 if (currentChar != 0x0D && |
| 9452 currentChar != 0x0A && |
| 9453 currentChar != 0x09 && |
| 9454 currentChar != 0x20) { |
| 9455 return start; |
| 9456 } |
| 9457 } else if (currentChar != 0x09 && currentChar != 0x20) { |
| 9458 return start; |
| 9459 } |
| 9460 index++; |
| 9461 } |
| 9462 return start; |
| 9463 } |
| 9464 } |
| 9465 |
| 9466 /** |
| 9467 * A string literal expression. |
| 9468 * |
| 9469 * stringLiteral ::= |
| 9470 * [SimpleStringLiteral] |
| 9471 * | [AdjacentStrings] |
| 9472 * | [StringInterpolation] |
| 9473 */ |
| 9474 abstract class StringLiteralImpl extends LiteralImpl implements StringLiteral { |
| 9475 @override |
| 9476 String get stringValue { |
| 9477 StringBuffer buffer = new StringBuffer(); |
| 9478 try { |
| 9479 _appendStringValue(buffer); |
| 9480 } on ArgumentError { |
| 9481 return null; |
| 9482 } |
| 9483 return buffer.toString(); |
| 9484 } |
| 9485 |
| 9486 /** |
| 9487 * Append the value of this string literal to the given [buffer]. Throw an |
| 9488 * [ArgumentError] if the string is not a constant string without any |
| 9489 * string interpolation. |
| 9490 */ |
| 9491 void _appendStringValue(StringBuffer buffer); |
| 9492 } |
| 9493 |
| 9494 /** |
| 9495 * The invocation of a superclass' constructor from within a constructor's |
| 9496 * initialization list. |
| 9497 * |
| 9498 * superInvocation ::= |
| 9499 * 'super' ('.' [SimpleIdentifier])? [ArgumentList] |
| 9500 */ |
| 9501 class SuperConstructorInvocationImpl extends ConstructorInitializerImpl |
| 9502 implements SuperConstructorInvocation { |
| 9503 /** |
| 9504 * The token for the 'super' keyword. |
| 9505 */ |
| 9506 Token superKeyword; |
| 9507 |
| 9508 /** |
| 9509 * The token for the period before the name of the constructor that is being |
| 9510 * invoked, or `null` if the unnamed constructor is being invoked. |
| 9511 */ |
| 9512 Token period; |
| 9513 |
| 9514 /** |
| 9515 * The name of the constructor that is being invoked, or `null` if the unnamed |
| 9516 * constructor is being invoked. |
| 9517 */ |
| 9518 SimpleIdentifier _constructorName; |
| 9519 |
| 9520 /** |
| 9521 * The list of arguments to the constructor. |
| 9522 */ |
| 9523 ArgumentList _argumentList; |
| 9524 |
| 9525 /** |
| 9526 * The element associated with the constructor based on static type |
| 9527 * information, or `null` if the AST structure has not been resolved or if the |
| 9528 * constructor could not be resolved. |
| 9529 */ |
| 9530 ConstructorElement staticElement; |
| 9531 |
| 9532 /** |
| 9533 * Initialize a newly created super invocation to invoke the inherited |
| 9534 * constructor with the given name with the given arguments. The [period] and |
| 9535 * [constructorName] can be `null` if the constructor being invoked is the |
| 9536 * unnamed constructor. |
| 9537 */ |
| 9538 SuperConstructorInvocationImpl(this.superKeyword, this.period, |
| 9539 SimpleIdentifierImpl constructorName, ArgumentListImpl argumentList) { |
| 9540 _constructorName = _becomeParentOf(constructorName); |
| 9541 _argumentList = _becomeParentOf(argumentList); |
| 9542 } |
| 9543 |
| 9544 @override |
| 9545 ArgumentList get argumentList => _argumentList; |
| 9546 |
| 9547 @override |
| 9548 void set argumentList(ArgumentList argumentList) { |
| 9549 _argumentList = _becomeParentOf(argumentList as AstNodeImpl); |
| 9550 } |
| 9551 |
| 9552 @override |
| 9553 Token get beginToken => superKeyword; |
| 9554 |
| 9555 @override |
| 9556 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 9557 ..add(superKeyword) |
| 9558 ..add(period) |
| 9559 ..add(_constructorName) |
| 9560 ..add(_argumentList); |
| 9561 |
| 9562 @override |
| 9563 SimpleIdentifier get constructorName => _constructorName; |
| 9564 |
| 9565 @override |
| 9566 void set constructorName(SimpleIdentifier identifier) { |
| 9567 _constructorName = _becomeParentOf(identifier as AstNodeImpl); |
| 9568 } |
| 9569 |
| 9570 @override |
| 9571 Token get endToken => _argumentList.endToken; |
| 9572 |
| 9573 @override |
| 9574 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9575 visitor.visitSuperConstructorInvocation(this); |
| 9576 |
| 9577 @override |
| 9578 void visitChildren(AstVisitor visitor) { |
| 9579 _constructorName?.accept(visitor); |
| 9580 _argumentList?.accept(visitor); |
| 9581 } |
| 9582 } |
| 9583 |
| 9584 /** |
| 9585 * A super expression. |
| 9586 * |
| 9587 * superExpression ::= |
| 9588 * 'super' |
| 9589 */ |
| 9590 class SuperExpressionImpl extends ExpressionImpl implements SuperExpression { |
| 9591 /** |
| 9592 * The token representing the 'super' keyword. |
| 9593 */ |
| 9594 Token superKeyword; |
| 9595 |
| 9596 /** |
| 9597 * Initialize a newly created super expression. |
| 9598 */ |
| 9599 SuperExpressionImpl(this.superKeyword); |
| 9600 |
| 9601 @override |
| 9602 Token get beginToken => superKeyword; |
| 9603 |
| 9604 @override |
| 9605 Iterable<SyntacticEntity> get childEntities => |
| 9606 new ChildEntities()..add(superKeyword); |
| 9607 |
| 9608 @override |
| 9609 Token get endToken => superKeyword; |
| 9610 |
| 9611 @override |
| 9612 int get precedence => 16; |
| 9613 |
| 9614 @override |
| 9615 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9616 visitor.visitSuperExpression(this); |
| 9617 |
| 9618 @override |
| 9619 void visitChildren(AstVisitor visitor) { |
| 9620 // There are no children to visit. |
| 9621 } |
| 9622 } |
| 9623 |
| 9624 /** |
| 9625 * A case in a switch statement. |
| 9626 * |
| 9627 * switchCase ::= |
| 9628 * [SimpleIdentifier]* 'case' [Expression] ':' [Statement]* |
| 9629 */ |
| 9630 class SwitchCaseImpl extends SwitchMemberImpl implements SwitchCase { |
| 9631 /** |
| 9632 * The expression controlling whether the statements will be executed. |
| 9633 */ |
| 9634 Expression _expression; |
| 9635 |
| 9636 /** |
| 9637 * Initialize a newly created switch case. The list of [labels] can be `null` |
| 9638 * if there are no labels. |
| 9639 */ |
| 9640 SwitchCaseImpl(List<Label> labels, Token keyword, ExpressionImpl expression, |
| 9641 Token colon, List<Statement> statements) |
| 9642 : super(labels, keyword, colon, statements) { |
| 9643 _expression = _becomeParentOf(expression); |
| 9644 } |
| 9645 |
| 9646 @override |
| 9647 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 9648 ..addAll(labels) |
| 9649 ..add(keyword) |
| 9650 ..add(_expression) |
| 9651 ..add(colon) |
| 9652 ..addAll(statements); |
| 9653 |
| 9654 @override |
| 9655 Expression get expression => _expression; |
| 9656 |
| 9657 @override |
| 9658 void set expression(Expression expression) { |
| 9659 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 9660 } |
| 9661 |
| 9662 @override |
| 9663 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9664 visitor.visitSwitchCase(this); |
| 9665 |
| 9666 @override |
| 9667 void visitChildren(AstVisitor visitor) { |
| 9668 labels.accept(visitor); |
| 9669 _expression?.accept(visitor); |
| 9670 statements.accept(visitor); |
| 9671 } |
| 9672 } |
| 9673 |
| 9674 /** |
| 9675 * The default case in a switch statement. |
| 9676 * |
| 9677 * switchDefault ::= |
| 9678 * [SimpleIdentifier]* 'default' ':' [Statement]* |
| 9679 */ |
| 9680 class SwitchDefaultImpl extends SwitchMemberImpl implements SwitchDefault { |
| 9681 /** |
| 9682 * Initialize a newly created switch default. The list of [labels] can be |
| 9683 * `null` if there are no labels. |
| 9684 */ |
| 9685 SwitchDefaultImpl(List<Label> labels, Token keyword, Token colon, |
| 9686 List<Statement> statements) |
| 9687 : super(labels, keyword, colon, statements); |
| 9688 |
| 9689 @override |
| 9690 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 9691 ..addAll(labels) |
| 9692 ..add(keyword) |
| 9693 ..add(colon) |
| 9694 ..addAll(statements); |
| 9695 |
| 9696 @override |
| 9697 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9698 visitor.visitSwitchDefault(this); |
| 9699 |
| 9700 @override |
| 9701 void visitChildren(AstVisitor visitor) { |
| 9702 labels.accept(visitor); |
| 9703 statements.accept(visitor); |
| 9704 } |
| 9705 } |
| 9706 |
| 9707 /** |
| 9708 * An element within a switch statement. |
| 9709 * |
| 9710 * switchMember ::= |
| 9711 * switchCase |
| 9712 * | switchDefault |
| 9713 */ |
| 9714 abstract class SwitchMemberImpl extends AstNodeImpl implements SwitchMember { |
| 9715 /** |
| 9716 * The labels associated with the switch member. |
| 9717 */ |
| 9718 NodeList<Label> _labels; |
| 9719 |
| 9720 /** |
| 9721 * The token representing the 'case' or 'default' keyword. |
| 9722 */ |
| 9723 Token keyword; |
| 9724 |
| 9725 /** |
| 9726 * The colon separating the keyword or the expression from the statements. |
| 9727 */ |
| 9728 Token colon; |
| 9729 |
| 9730 /** |
| 9731 * The statements that will be executed if this switch member is selected. |
| 9732 */ |
| 9733 NodeList<Statement> _statements; |
| 9734 |
| 9735 /** |
| 9736 * Initialize a newly created switch member. The list of [labels] can be |
| 9737 * `null` if there are no labels. |
| 9738 */ |
| 9739 SwitchMemberImpl(List<Label> labels, this.keyword, this.colon, |
| 9740 List<Statement> statements) { |
| 9741 _labels = new NodeListImpl<Label>(this, labels); |
| 9742 _statements = new NodeListImpl<Statement>(this, statements); |
| 9743 } |
| 9744 |
| 9745 @override |
| 9746 Token get beginToken { |
| 9747 if (!_labels.isEmpty) { |
| 9748 return _labels.beginToken; |
| 9749 } |
| 9750 return keyword; |
| 9751 } |
| 9752 |
| 9753 @override |
| 9754 Token get endToken { |
| 9755 if (!_statements.isEmpty) { |
| 9756 return _statements.endToken; |
| 9757 } |
| 9758 return colon; |
| 9759 } |
| 9760 |
| 9761 @override |
| 9762 NodeList<Label> get labels => _labels; |
| 9763 |
| 9764 @override |
| 9765 NodeList<Statement> get statements => _statements; |
| 9766 } |
| 9767 |
| 9768 /** |
| 9769 * A switch statement. |
| 9770 * |
| 9771 * switchStatement ::= |
| 9772 * 'switch' '(' [Expression] ')' '{' [SwitchCase]* [SwitchDefault]? '}' |
| 9773 */ |
| 9774 class SwitchStatementImpl extends StatementImpl implements SwitchStatement { |
| 9775 /** |
| 9776 * The token representing the 'switch' keyword. |
| 9777 */ |
| 9778 Token switchKeyword; |
| 9779 |
| 9780 /** |
| 9781 * The left parenthesis. |
| 9782 */ |
| 9783 Token leftParenthesis; |
| 9784 |
| 9785 /** |
| 9786 * The expression used to determine which of the switch members will be |
| 9787 * selected. |
| 9788 */ |
| 9789 Expression _expression; |
| 9790 |
| 9791 /** |
| 9792 * The right parenthesis. |
| 9793 */ |
| 9794 Token rightParenthesis; |
| 9795 |
| 9796 /** |
| 9797 * The left curly bracket. |
| 9798 */ |
| 9799 Token leftBracket; |
| 9800 |
| 9801 /** |
| 9802 * The switch members that can be selected by the expression. |
| 9803 */ |
| 9804 NodeList<SwitchMember> _members; |
| 9805 |
| 9806 /** |
| 9807 * The right curly bracket. |
| 9808 */ |
| 9809 Token rightBracket; |
| 9810 |
| 9811 /** |
| 9812 * Initialize a newly created switch statement. The list of [members] can be |
| 9813 * `null` if there are no switch members. |
| 9814 */ |
| 9815 SwitchStatementImpl( |
| 9816 this.switchKeyword, |
| 9817 this.leftParenthesis, |
| 9818 ExpressionImpl expression, |
| 9819 this.rightParenthesis, |
| 9820 this.leftBracket, |
| 9821 List<SwitchMember> members, |
| 9822 this.rightBracket) { |
| 9823 _expression = _becomeParentOf(expression); |
| 9824 _members = new NodeListImpl<SwitchMember>(this, members); |
| 9825 } |
| 9826 |
| 9827 @override |
| 9828 Token get beginToken => switchKeyword; |
| 9829 |
| 9830 @override |
| 9831 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 9832 ..add(switchKeyword) |
| 9833 ..add(leftParenthesis) |
| 9834 ..add(_expression) |
| 9835 ..add(rightParenthesis) |
| 9836 ..add(leftBracket) |
| 9837 ..addAll(_members) |
| 9838 ..add(rightBracket); |
| 9839 |
| 9840 @override |
| 9841 Token get endToken => rightBracket; |
| 9842 |
| 9843 @override |
| 9844 Expression get expression => _expression; |
| 9845 |
| 9846 @override |
| 9847 void set expression(Expression expression) { |
| 9848 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 9849 } |
| 9850 |
| 9851 @override |
| 9852 NodeList<SwitchMember> get members => _members; |
| 9853 |
| 9854 @override |
| 9855 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9856 visitor.visitSwitchStatement(this); |
| 9857 |
| 9858 @override |
| 9859 void visitChildren(AstVisitor visitor) { |
| 9860 _expression?.accept(visitor); |
| 9861 _members.accept(visitor); |
| 9862 } |
| 9863 } |
| 9864 |
| 9865 /** |
| 9866 * A symbol literal expression. |
| 9867 * |
| 9868 * symbolLiteral ::= |
| 9869 * '#' (operator | (identifier ('.' identifier)*)) |
| 9870 */ |
| 9871 class SymbolLiteralImpl extends LiteralImpl implements SymbolLiteral { |
| 9872 /** |
| 9873 * The token introducing the literal. |
| 9874 */ |
| 9875 Token poundSign; |
| 9876 |
| 9877 /** |
| 9878 * The components of the literal. |
| 9879 */ |
| 9880 final List<Token> components; |
| 9881 |
| 9882 /** |
| 9883 * Initialize a newly created symbol literal. |
| 9884 */ |
| 9885 SymbolLiteralImpl(this.poundSign, this.components); |
| 9886 |
| 9887 @override |
| 9888 Token get beginToken => poundSign; |
| 9889 |
| 9890 @override |
| 9891 // TODO(paulberry): add "." tokens. |
| 9892 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 9893 ..add(poundSign) |
| 9894 ..addAll(components); |
| 9895 |
| 9896 @override |
| 9897 Token get endToken => components[components.length - 1]; |
| 9898 |
| 9899 @override |
| 9900 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9901 visitor.visitSymbolLiteral(this); |
| 9902 |
| 9903 @override |
| 9904 void visitChildren(AstVisitor visitor) { |
| 9905 // There are no children to visit. |
| 9906 } |
| 9907 } |
| 9908 |
| 9909 /** |
| 9910 * A this expression. |
| 9911 * |
| 9912 * thisExpression ::= |
| 9913 * 'this' |
| 9914 */ |
| 9915 class ThisExpressionImpl extends ExpressionImpl implements ThisExpression { |
| 9916 /** |
| 9917 * The token representing the 'this' keyword. |
| 9918 */ |
| 9919 Token thisKeyword; |
| 9920 |
| 9921 /** |
| 9922 * Initialize a newly created this expression. |
| 9923 */ |
| 9924 ThisExpressionImpl(this.thisKeyword); |
| 9925 |
| 9926 @override |
| 9927 Token get beginToken => thisKeyword; |
| 9928 |
| 9929 @override |
| 9930 Iterable<SyntacticEntity> get childEntities => |
| 9931 new ChildEntities()..add(thisKeyword); |
| 9932 |
| 9933 @override |
| 9934 Token get endToken => thisKeyword; |
| 9935 |
| 9936 @override |
| 9937 int get precedence => 16; |
| 9938 |
| 9939 @override |
| 9940 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 9941 visitor.visitThisExpression(this); |
| 9942 |
| 9943 @override |
| 9944 void visitChildren(AstVisitor visitor) { |
| 9945 // There are no children to visit. |
| 9946 } |
| 9947 } |
| 9948 |
| 9949 /** |
| 9950 * A throw expression. |
| 9951 * |
| 9952 * throwExpression ::= |
| 9953 * 'throw' [Expression] |
| 9954 */ |
| 9955 class ThrowExpressionImpl extends ExpressionImpl implements ThrowExpression { |
| 9956 /** |
| 9957 * The token representing the 'throw' keyword. |
| 9958 */ |
| 9959 Token throwKeyword; |
| 9960 |
| 9961 /** |
| 9962 * The expression computing the exception to be thrown. |
| 9963 */ |
| 9964 Expression _expression; |
| 9965 |
| 9966 /** |
| 9967 * Initialize a newly created throw expression. |
| 9968 */ |
| 9969 ThrowExpressionImpl(this.throwKeyword, ExpressionImpl expression) { |
| 9970 _expression = _becomeParentOf(expression); |
| 9971 } |
| 9972 |
| 9973 @override |
| 9974 Token get beginToken => throwKeyword; |
| 9975 |
| 9976 @override |
| 9977 Iterable<SyntacticEntity> get childEntities => |
| 9978 new ChildEntities()..add(throwKeyword)..add(_expression); |
| 9979 |
| 9980 @override |
| 9981 Token get endToken { |
| 9982 if (_expression != null) { |
| 9983 return _expression.endToken; |
| 9984 } |
| 9985 return throwKeyword; |
| 9986 } |
| 9987 |
| 9988 @override |
| 9989 Expression get expression => _expression; |
| 9990 |
| 9991 @override |
| 9992 void set expression(Expression expression) { |
| 9993 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 9994 } |
| 9995 |
| 9996 @override |
| 9997 int get precedence => 0; |
| 9998 |
| 9999 @override |
| 10000 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10001 visitor.visitThrowExpression(this); |
| 10002 |
| 10003 @override |
| 10004 void visitChildren(AstVisitor visitor) { |
| 10005 _expression?.accept(visitor); |
| 10006 } |
| 10007 } |
| 10008 |
| 10009 /** |
| 10010 * The declaration of one or more top-level variables of the same type. |
| 10011 * |
| 10012 * topLevelVariableDeclaration ::= |
| 10013 * ('final' | 'const') type? staticFinalDeclarationList ';' |
| 10014 * | variableDeclaration ';' |
| 10015 */ |
| 10016 class TopLevelVariableDeclarationImpl extends CompilationUnitMemberImpl |
| 10017 implements TopLevelVariableDeclaration { |
| 10018 /** |
| 10019 * The top-level variables being declared. |
| 10020 */ |
| 10021 VariableDeclarationList _variableList; |
| 10022 |
| 10023 /** |
| 10024 * The semicolon terminating the declaration. |
| 10025 */ |
| 10026 Token semicolon; |
| 10027 |
| 10028 /** |
| 10029 * Initialize a newly created top-level variable declaration. Either or both |
| 10030 * of the [comment] and [metadata] can be `null` if the variable does not have |
| 10031 * the corresponding attribute. |
| 10032 */ |
| 10033 TopLevelVariableDeclarationImpl( |
| 10034 CommentImpl comment, |
| 10035 List<Annotation> metadata, |
| 10036 VariableDeclarationListImpl variableList, |
| 10037 this.semicolon) |
| 10038 : super(comment, metadata) { |
| 10039 _variableList = _becomeParentOf(variableList); |
| 10040 } |
| 10041 |
| 10042 @override |
| 10043 Iterable<SyntacticEntity> get childEntities => |
| 10044 super._childEntities..add(_variableList)..add(semicolon); |
| 10045 |
| 10046 @override |
| 10047 Element get element => null; |
| 10048 |
| 10049 @override |
| 10050 Token get endToken => semicolon; |
| 10051 |
| 10052 @override |
| 10053 Token get firstTokenAfterCommentAndMetadata => _variableList.beginToken; |
| 10054 |
| 10055 @override |
| 10056 VariableDeclarationList get variables => _variableList; |
| 10057 |
| 10058 @override |
| 10059 void set variables(VariableDeclarationList variables) { |
| 10060 _variableList = _becomeParentOf(variables as AstNodeImpl); |
| 10061 } |
| 10062 |
| 10063 @override |
| 10064 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10065 visitor.visitTopLevelVariableDeclaration(this); |
| 10066 |
| 10067 @override |
| 10068 void visitChildren(AstVisitor visitor) { |
| 10069 super.visitChildren(visitor); |
| 10070 _variableList?.accept(visitor); |
| 10071 } |
| 10072 } |
| 10073 |
| 10074 /** |
| 10075 * A try statement. |
| 10076 * |
| 10077 * tryStatement ::= |
| 10078 * 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause) |
| 10079 * |
| 10080 * finallyClause ::= |
| 10081 * 'finally' [Block] |
| 10082 */ |
| 10083 class TryStatementImpl extends StatementImpl implements TryStatement { |
| 10084 /** |
| 10085 * The token representing the 'try' keyword. |
| 10086 */ |
| 10087 Token tryKeyword; |
| 10088 |
| 10089 /** |
| 10090 * The body of the statement. |
| 10091 */ |
| 10092 Block _body; |
| 10093 |
| 10094 /** |
| 10095 * The catch clauses contained in the try statement. |
| 10096 */ |
| 10097 NodeList<CatchClause> _catchClauses; |
| 10098 |
| 10099 /** |
| 10100 * The token representing the 'finally' keyword, or `null` if the statement |
| 10101 * does not contain a finally clause. |
| 10102 */ |
| 10103 Token finallyKeyword; |
| 10104 |
| 10105 /** |
| 10106 * The finally block contained in the try statement, or `null` if the |
| 10107 * statement does not contain a finally clause. |
| 10108 */ |
| 10109 Block _finallyBlock; |
| 10110 |
| 10111 /** |
| 10112 * Initialize a newly created try statement. The list of [catchClauses] can be |
| 10113 * `null` if there are no catch clauses. The [finallyKeyword] and |
| 10114 * [finallyBlock] can be `null` if there is no finally clause. |
| 10115 */ |
| 10116 TryStatementImpl( |
| 10117 this.tryKeyword, |
| 10118 BlockImpl body, |
| 10119 List<CatchClause> catchClauses, |
| 10120 this.finallyKeyword, |
| 10121 BlockImpl finallyBlock) { |
| 10122 _body = _becomeParentOf(body); |
| 10123 _catchClauses = new NodeListImpl<CatchClause>(this, catchClauses); |
| 10124 _finallyBlock = _becomeParentOf(finallyBlock); |
| 10125 } |
| 10126 |
| 10127 @override |
| 10128 Token get beginToken => tryKeyword; |
| 10129 |
| 10130 @override |
| 10131 Block get body => _body; |
| 10132 |
| 10133 @override |
| 10134 void set body(Block block) { |
| 10135 _body = _becomeParentOf(block as AstNodeImpl); |
| 10136 } |
| 10137 |
| 10138 @override |
| 10139 NodeList<CatchClause> get catchClauses => _catchClauses; |
| 10140 |
| 10141 @override |
| 10142 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 10143 ..add(tryKeyword) |
| 10144 ..add(_body) |
| 10145 ..addAll(_catchClauses) |
| 10146 ..add(finallyKeyword) |
| 10147 ..add(_finallyBlock); |
| 10148 |
| 10149 @override |
| 10150 Token get endToken { |
| 10151 if (_finallyBlock != null) { |
| 10152 return _finallyBlock.endToken; |
| 10153 } else if (finallyKeyword != null) { |
| 10154 return finallyKeyword; |
| 10155 } else if (!_catchClauses.isEmpty) { |
| 10156 return _catchClauses.endToken; |
| 10157 } |
| 10158 return _body.endToken; |
| 10159 } |
| 10160 |
| 10161 @override |
| 10162 Block get finallyBlock => _finallyBlock; |
| 10163 |
| 10164 @override |
| 10165 void set finallyBlock(Block block) { |
| 10166 _finallyBlock = _becomeParentOf(block as AstNodeImpl); |
| 10167 } |
| 10168 |
| 10169 @override |
| 10170 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10171 visitor.visitTryStatement(this); |
| 10172 |
| 10173 @override |
| 10174 void visitChildren(AstVisitor visitor) { |
| 10175 _body?.accept(visitor); |
| 10176 _catchClauses.accept(visitor); |
| 10177 _finallyBlock?.accept(visitor); |
| 10178 } |
| 10179 } |
| 10180 |
| 10181 /** |
| 10182 * The declaration of a type alias. |
| 10183 * |
| 10184 * typeAlias ::= |
| 10185 * 'typedef' typeAliasBody |
| 10186 * |
| 10187 * typeAliasBody ::= |
| 10188 * classTypeAlias |
| 10189 * | functionTypeAlias |
| 10190 */ |
| 10191 abstract class TypeAliasImpl extends NamedCompilationUnitMemberImpl |
| 10192 implements TypeAlias { |
| 10193 /** |
| 10194 * The token representing the 'typedef' keyword. |
| 10195 */ |
| 10196 Token typedefKeyword; |
| 10197 |
| 10198 /** |
| 10199 * The semicolon terminating the declaration. |
| 10200 */ |
| 10201 Token semicolon; |
| 10202 |
| 10203 /** |
| 10204 * Initialize a newly created type alias. Either or both of the [comment] and |
| 10205 * [metadata] can be `null` if the declaration does not have the corresponding |
| 10206 * attribute. |
| 10207 */ |
| 10208 TypeAliasImpl(Comment comment, List<Annotation> metadata, this.typedefKeyword, |
| 10209 SimpleIdentifier name, this.semicolon) |
| 10210 : super(comment, metadata, name); |
| 10211 |
| 10212 @override |
| 10213 Token get endToken => semicolon; |
| 10214 |
| 10215 @override |
| 10216 Token get firstTokenAfterCommentAndMetadata => typedefKeyword; |
| 10217 } |
| 10218 |
| 10219 /** |
| 10220 * A list of type arguments. |
| 10221 * |
| 10222 * typeArguments ::= |
| 10223 * '<' typeName (',' typeName)* '>' |
| 10224 */ |
| 10225 class TypeArgumentListImpl extends AstNodeImpl implements TypeArgumentList { |
| 10226 /** |
| 10227 * The left bracket. |
| 10228 */ |
| 10229 Token leftBracket; |
| 10230 |
| 10231 /** |
| 10232 * The type arguments associated with the type. |
| 10233 */ |
| 10234 NodeList<TypeName> _arguments; |
| 10235 |
| 10236 /** |
| 10237 * The right bracket. |
| 10238 */ |
| 10239 Token rightBracket; |
| 10240 |
| 10241 /** |
| 10242 * Initialize a newly created list of type arguments. |
| 10243 */ |
| 10244 TypeArgumentListImpl( |
| 10245 this.leftBracket, List<TypeName> arguments, this.rightBracket) { |
| 10246 _arguments = new NodeListImpl<TypeName>(this, arguments); |
| 10247 } |
| 10248 |
| 10249 @override |
| 10250 NodeList<TypeName> get arguments => _arguments; |
| 10251 |
| 10252 @override |
| 10253 Token get beginToken => leftBracket; |
| 10254 |
| 10255 @override |
| 10256 // TODO(paulberry): Add commas. |
| 10257 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 10258 ..add(leftBracket) |
| 10259 ..addAll(_arguments) |
| 10260 ..add(rightBracket); |
| 10261 |
| 10262 @override |
| 10263 Token get endToken => rightBracket; |
| 10264 |
| 10265 @override |
| 10266 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10267 visitor.visitTypeArgumentList(this); |
| 10268 |
| 10269 @override |
| 10270 void visitChildren(AstVisitor visitor) { |
| 10271 _arguments.accept(visitor); |
| 10272 } |
| 10273 } |
| 10274 |
| 10275 /** |
| 10276 * A literal that has a type associated with it. |
| 10277 * |
| 10278 * typedLiteral ::= |
| 10279 * [ListLiteral] |
| 10280 * | [MapLiteral] |
| 10281 */ |
| 10282 abstract class TypedLiteralImpl extends LiteralImpl implements TypedLiteral { |
| 10283 /** |
| 10284 * The token representing the 'const' keyword, or `null` if the literal is not |
| 10285 * a constant. |
| 10286 */ |
| 10287 Token constKeyword; |
| 10288 |
| 10289 /** |
| 10290 * The type argument associated with this literal, or `null` if no type |
| 10291 * arguments were declared. |
| 10292 */ |
| 10293 TypeArgumentList _typeArguments; |
| 10294 |
| 10295 /** |
| 10296 * Initialize a newly created typed literal. The [constKeyword] can be `null`\ |
| 10297 * if the literal is not a constant. The [typeArguments] can be `null` if no |
| 10298 * type arguments were declared. |
| 10299 */ |
| 10300 TypedLiteralImpl(this.constKeyword, TypeArgumentListImpl typeArguments) { |
| 10301 _typeArguments = _becomeParentOf(typeArguments); |
| 10302 } |
| 10303 |
| 10304 @override |
| 10305 TypeArgumentList get typeArguments => _typeArguments; |
| 10306 |
| 10307 @override |
| 10308 void set typeArguments(TypeArgumentList typeArguments) { |
| 10309 _typeArguments = _becomeParentOf(typeArguments as AstNodeImpl); |
| 10310 } |
| 10311 |
| 10312 ChildEntities get _childEntities => |
| 10313 new ChildEntities()..add(constKeyword)..add(_typeArguments); |
| 10314 |
| 10315 @override |
| 10316 void visitChildren(AstVisitor visitor) { |
| 10317 _typeArguments?.accept(visitor); |
| 10318 } |
| 10319 } |
| 10320 |
| 10321 /** |
| 10322 * The name of a type, which can optionally include type arguments. |
| 10323 * |
| 10324 * typeName ::= |
| 10325 * [Identifier] typeArguments? |
| 10326 */ |
| 10327 class TypeNameImpl extends AstNodeImpl implements TypeName { |
| 10328 /** |
| 10329 * The name of the type. |
| 10330 */ |
| 10331 Identifier _name; |
| 10332 |
| 10333 /** |
| 10334 * The type arguments associated with the type, or `null` if there are no type |
| 10335 * arguments. |
| 10336 */ |
| 10337 TypeArgumentList _typeArguments; |
| 10338 |
| 10339 @override |
| 10340 Token question; |
| 10341 |
| 10342 /** |
| 10343 * The type being named, or `null` if the AST structure has not been resolved. |
| 10344 */ |
| 10345 DartType type; |
| 10346 |
| 10347 /** |
| 10348 * Initialize a newly created type name. The [typeArguments] can be `null` if |
| 10349 * there are no type arguments. |
| 10350 */ |
| 10351 TypeNameImpl( |
| 10352 IdentifierImpl name, TypeArgumentListImpl typeArguments, this.question) { |
| 10353 _name = _becomeParentOf(name); |
| 10354 _typeArguments = _becomeParentOf(typeArguments); |
| 10355 } |
| 10356 |
| 10357 @override |
| 10358 Token get beginToken => _name.beginToken; |
| 10359 |
| 10360 @override |
| 10361 Iterable<SyntacticEntity> get childEntities => |
| 10362 new ChildEntities()..add(_name)..add(_typeArguments); |
| 10363 |
| 10364 @override |
| 10365 Token get endToken { |
| 10366 if (_typeArguments != null) { |
| 10367 return _typeArguments.endToken; |
| 10368 } |
| 10369 return _name.endToken; |
| 10370 } |
| 10371 |
| 10372 @override |
| 10373 bool get isDeferred { |
| 10374 Identifier identifier = name; |
| 10375 if (identifier is! PrefixedIdentifier) { |
| 10376 return false; |
| 10377 } |
| 10378 return (identifier as PrefixedIdentifier).isDeferred; |
| 10379 } |
| 10380 |
| 10381 @override |
| 10382 bool get isSynthetic => _name.isSynthetic && _typeArguments == null; |
| 10383 |
| 10384 @override |
| 10385 Identifier get name => _name; |
| 10386 |
| 10387 @override |
| 10388 void set name(Identifier identifier) { |
| 10389 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 10390 } |
| 10391 |
| 10392 @override |
| 10393 TypeArgumentList get typeArguments => _typeArguments; |
| 10394 |
| 10395 @override |
| 10396 void set typeArguments(TypeArgumentList typeArguments) { |
| 10397 _typeArguments = _becomeParentOf(typeArguments as AstNodeImpl); |
| 10398 } |
| 10399 |
| 10400 @override |
| 10401 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10402 visitor.visitTypeName(this); |
| 10403 |
| 10404 @override |
| 10405 void visitChildren(AstVisitor visitor) { |
| 10406 _name?.accept(visitor); |
| 10407 _typeArguments?.accept(visitor); |
| 10408 } |
| 10409 } |
| 10410 |
| 10411 /** |
| 10412 * A type parameter. |
| 10413 * |
| 10414 * typeParameter ::= |
| 10415 * [SimpleIdentifier] ('extends' [TypeName])? |
| 10416 */ |
| 10417 class TypeParameterImpl extends DeclarationImpl implements TypeParameter { |
| 10418 /** |
| 10419 * The name of the type parameter. |
| 10420 */ |
| 10421 SimpleIdentifier _name; |
| 10422 |
| 10423 /** |
| 10424 * The token representing the 'extends' keyword, or `null` if there is no |
| 10425 * explicit upper bound. |
| 10426 */ |
| 10427 Token extendsKeyword; |
| 10428 |
| 10429 /** |
| 10430 * The name of the upper bound for legal arguments, or `null` if there is no |
| 10431 * explicit upper bound. |
| 10432 */ |
| 10433 TypeName _bound; |
| 10434 |
| 10435 /** |
| 10436 * Initialize a newly created type parameter. Either or both of the [comment] |
| 10437 * and [metadata] can be `null` if the parameter does not have the |
| 10438 * corresponding attribute. The [extendsKeyword] and [bound] can be `null` if |
| 10439 * the parameter does not have an upper bound. |
| 10440 */ |
| 10441 TypeParameterImpl(CommentImpl comment, List<Annotation> metadata, |
| 10442 SimpleIdentifierImpl name, this.extendsKeyword, TypeNameImpl bound) |
| 10443 : super(comment, metadata) { |
| 10444 _name = _becomeParentOf(name); |
| 10445 _bound = _becomeParentOf(bound); |
| 10446 } |
| 10447 |
| 10448 @override |
| 10449 TypeName get bound => _bound; |
| 10450 |
| 10451 @override |
| 10452 void set bound(TypeName typeName) { |
| 10453 _bound = _becomeParentOf(typeName as AstNodeImpl); |
| 10454 } |
| 10455 |
| 10456 @override |
| 10457 Iterable<SyntacticEntity> get childEntities => |
| 10458 super._childEntities..add(_name)..add(extendsKeyword)..add(_bound); |
| 10459 |
| 10460 @override |
| 10461 TypeParameterElement get element => |
| 10462 _name?.staticElement as TypeParameterElement; |
| 10463 |
| 10464 @override |
| 10465 Token get endToken { |
| 10466 if (_bound == null) { |
| 10467 return _name.endToken; |
| 10468 } |
| 10469 return _bound.endToken; |
| 10470 } |
| 10471 |
| 10472 @override |
| 10473 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 10474 |
| 10475 @override |
| 10476 SimpleIdentifier get name => _name; |
| 10477 |
| 10478 @override |
| 10479 void set name(SimpleIdentifier identifier) { |
| 10480 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 10481 } |
| 10482 |
| 10483 @override |
| 10484 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10485 visitor.visitTypeParameter(this); |
| 10486 |
| 10487 @override |
| 10488 void visitChildren(AstVisitor visitor) { |
| 10489 super.visitChildren(visitor); |
| 10490 _name?.accept(visitor); |
| 10491 _bound?.accept(visitor); |
| 10492 } |
| 10493 } |
| 10494 |
| 10495 /** |
| 10496 * Type parameters within a declaration. |
| 10497 * |
| 10498 * typeParameterList ::= |
| 10499 * '<' [TypeParameter] (',' [TypeParameter])* '>' |
| 10500 */ |
| 10501 class TypeParameterListImpl extends AstNodeImpl implements TypeParameterList { |
| 10502 /** |
| 10503 * The left angle bracket. |
| 10504 */ |
| 10505 final Token leftBracket; |
| 10506 |
| 10507 /** |
| 10508 * The type parameters in the list. |
| 10509 */ |
| 10510 NodeList<TypeParameter> _typeParameters; |
| 10511 |
| 10512 /** |
| 10513 * The right angle bracket. |
| 10514 */ |
| 10515 final Token rightBracket; |
| 10516 |
| 10517 /** |
| 10518 * Initialize a newly created list of type parameters. |
| 10519 */ |
| 10520 TypeParameterListImpl( |
| 10521 this.leftBracket, List<TypeParameter> typeParameters, this.rightBracket) { |
| 10522 _typeParameters = new NodeListImpl<TypeParameter>(this, typeParameters); |
| 10523 } |
| 10524 |
| 10525 @override |
| 10526 Token get beginToken => leftBracket; |
| 10527 |
| 10528 @override |
| 10529 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 10530 ..add(leftBracket) |
| 10531 ..addAll(_typeParameters) |
| 10532 ..add(rightBracket); |
| 10533 |
| 10534 @override |
| 10535 Token get endToken => rightBracket; |
| 10536 |
| 10537 @override |
| 10538 NodeList<TypeParameter> get typeParameters => _typeParameters; |
| 10539 |
| 10540 @override |
| 10541 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10542 visitor.visitTypeParameterList(this); |
| 10543 |
| 10544 @override |
| 10545 void visitChildren(AstVisitor visitor) { |
| 10546 _typeParameters.accept(visitor); |
| 10547 } |
| 10548 } |
| 10549 |
| 10550 /** |
| 10551 * A directive that references a URI. |
| 10552 * |
| 10553 * uriBasedDirective ::= |
| 10554 * [ExportDirective] |
| 10555 * | [ImportDirective] |
| 10556 * | [PartDirective] |
| 10557 */ |
| 10558 abstract class UriBasedDirectiveImpl extends DirectiveImpl |
| 10559 implements UriBasedDirective { |
| 10560 /** |
| 10561 * The prefix of a URI using the `dart-ext` scheme to reference a native code |
| 10562 * library. |
| 10563 */ |
| 10564 static String _DART_EXT_SCHEME = "dart-ext:"; |
| 10565 |
| 10566 /** |
| 10567 * The URI referenced by this directive. |
| 10568 */ |
| 10569 StringLiteral _uri; |
| 10570 |
| 10571 @override |
| 10572 String uriContent; |
| 10573 |
| 10574 @override |
| 10575 Source uriSource; |
| 10576 |
| 10577 /** |
| 10578 * Initialize a newly create URI-based directive. Either or both of the |
| 10579 * [comment] and [metadata] can be `null` if the directive does not have the |
| 10580 * corresponding attribute. |
| 10581 */ |
| 10582 UriBasedDirectiveImpl( |
| 10583 CommentImpl comment, List<Annotation> metadata, StringLiteralImpl uri) |
| 10584 : super(comment, metadata) { |
| 10585 _uri = _becomeParentOf(uri); |
| 10586 } |
| 10587 |
| 10588 @deprecated |
| 10589 @override |
| 10590 Source get source => uriSource; |
| 10591 |
| 10592 @deprecated |
| 10593 @override |
| 10594 void set source(Source source) { |
| 10595 uriSource = source; |
| 10596 } |
| 10597 |
| 10598 @override |
| 10599 StringLiteral get uri => _uri; |
| 10600 |
| 10601 @override |
| 10602 void set uri(StringLiteral uri) { |
| 10603 _uri = _becomeParentOf(uri as AstNodeImpl); |
| 10604 } |
| 10605 |
| 10606 UriValidationCode validate() { |
| 10607 return validateUri(this is ImportDirective, uri, uriContent); |
| 10608 } |
| 10609 |
| 10610 @override |
| 10611 void visitChildren(AstVisitor visitor) { |
| 10612 super.visitChildren(visitor); |
| 10613 _uri?.accept(visitor); |
| 10614 } |
| 10615 |
| 10616 /** |
| 10617 * Validate this directive, but do not check for existence. Return a code |
| 10618 * indicating the problem if there is one, or `null` no problem. |
| 10619 */ |
| 10620 static UriValidationCode validateUri( |
| 10621 bool isImport, StringLiteral uriLiteral, String uriContent) { |
| 10622 if (uriLiteral is StringInterpolation) { |
| 10623 return UriValidationCode.URI_WITH_INTERPOLATION; |
| 10624 } |
| 10625 if (uriContent == null) { |
| 10626 return UriValidationCode.INVALID_URI; |
| 10627 } |
| 10628 if (isImport && uriContent.startsWith(_DART_EXT_SCHEME)) { |
| 10629 return UriValidationCode.URI_WITH_DART_EXT_SCHEME; |
| 10630 } |
| 10631 Uri uri; |
| 10632 try { |
| 10633 uri = Uri.parse(Uri.encodeFull(uriContent)); |
| 10634 } on FormatException { |
| 10635 return UriValidationCode.INVALID_URI; |
| 10636 } |
| 10637 if (uri.path.isEmpty) { |
| 10638 return UriValidationCode.INVALID_URI; |
| 10639 } |
| 10640 return null; |
| 10641 } |
| 10642 } |
| 10643 |
| 10644 /** |
| 10645 * Validation codes returned by [UriBasedDirective.validate]. |
| 10646 */ |
| 10647 class UriValidationCode { |
| 10648 static const UriValidationCode INVALID_URI = |
| 10649 const UriValidationCode('INVALID_URI'); |
| 10650 |
| 10651 static const UriValidationCode URI_WITH_INTERPOLATION = |
| 10652 const UriValidationCode('URI_WITH_INTERPOLATION'); |
| 10653 |
| 10654 static const UriValidationCode URI_WITH_DART_EXT_SCHEME = |
| 10655 const UriValidationCode('URI_WITH_DART_EXT_SCHEME'); |
| 10656 |
| 10657 /** |
| 10658 * The name of the validation code. |
| 10659 */ |
| 10660 final String name; |
| 10661 |
| 10662 /** |
| 10663 * Initialize a newly created validation code to have the given [name]. |
| 10664 */ |
| 10665 const UriValidationCode(this.name); |
| 10666 |
| 10667 @override |
| 10668 String toString() => name; |
| 10669 } |
| 10670 |
| 10671 /** |
| 10672 * An identifier that has an initial value associated with it. Instances of this |
| 10673 * class are always children of the class [VariableDeclarationList]. |
| 10674 * |
| 10675 * variableDeclaration ::= |
| 10676 * [SimpleIdentifier] ('=' [Expression])? |
| 10677 * |
| 10678 * TODO(paulberry): the grammar does not allow metadata to be associated with |
| 10679 * a VariableDeclaration, and currently we don't record comments for it either. |
| 10680 * Consider changing the class hierarchy so that [VariableDeclaration] does not |
| 10681 * extend [Declaration]. |
| 10682 */ |
| 10683 class VariableDeclarationImpl extends DeclarationImpl |
| 10684 implements VariableDeclaration { |
| 10685 /** |
| 10686 * The name of the variable being declared. |
| 10687 */ |
| 10688 SimpleIdentifier _name; |
| 10689 |
| 10690 /** |
| 10691 * The equal sign separating the variable name from the initial value, or |
| 10692 * `null` if the initial value was not specified. |
| 10693 */ |
| 10694 Token equals; |
| 10695 |
| 10696 /** |
| 10697 * The expression used to compute the initial value for the variable, or |
| 10698 * `null` if the initial value was not specified. |
| 10699 */ |
| 10700 Expression _initializer; |
| 10701 |
| 10702 /** |
| 10703 * Initialize a newly created variable declaration. The [equals] and |
| 10704 * [initializer] can be `null` if there is no initializer. |
| 10705 */ |
| 10706 VariableDeclarationImpl( |
| 10707 SimpleIdentifierImpl name, this.equals, ExpressionImpl initializer) |
| 10708 : super(null, null) { |
| 10709 _name = _becomeParentOf(name); |
| 10710 _initializer = _becomeParentOf(initializer); |
| 10711 } |
| 10712 |
| 10713 @override |
| 10714 Iterable<SyntacticEntity> get childEntities => |
| 10715 super._childEntities..add(_name)..add(equals)..add(_initializer); |
| 10716 |
| 10717 /** |
| 10718 * This overridden implementation of [documentationComment] looks in the |
| 10719 * grandparent node for Dartdoc comments if no documentation is specifically |
| 10720 * available on the node. |
| 10721 */ |
| 10722 @override |
| 10723 Comment get documentationComment { |
| 10724 Comment comment = super.documentationComment; |
| 10725 if (comment == null) { |
| 10726 AstNode node = parent?.parent; |
| 10727 if (node is AnnotatedNode) { |
| 10728 return node.documentationComment; |
| 10729 } |
| 10730 } |
| 10731 return comment; |
| 10732 } |
| 10733 |
| 10734 @override |
| 10735 VariableElement get element => _name?.staticElement as VariableElement; |
| 10736 |
| 10737 @override |
| 10738 Token get endToken { |
| 10739 if (_initializer != null) { |
| 10740 return _initializer.endToken; |
| 10741 } |
| 10742 return _name.endToken; |
| 10743 } |
| 10744 |
| 10745 @override |
| 10746 Token get firstTokenAfterCommentAndMetadata => _name.beginToken; |
| 10747 |
| 10748 @override |
| 10749 Expression get initializer => _initializer; |
| 10750 |
| 10751 @override |
| 10752 void set initializer(Expression expression) { |
| 10753 _initializer = _becomeParentOf(expression as AstNodeImpl); |
| 10754 } |
| 10755 |
| 10756 @override |
| 10757 bool get isConst { |
| 10758 AstNode parent = this.parent; |
| 10759 return parent is VariableDeclarationList && parent.isConst; |
| 10760 } |
| 10761 |
| 10762 @override |
| 10763 bool get isFinal { |
| 10764 AstNode parent = this.parent; |
| 10765 return parent is VariableDeclarationList && parent.isFinal; |
| 10766 } |
| 10767 |
| 10768 @override |
| 10769 SimpleIdentifier get name => _name; |
| 10770 |
| 10771 @override |
| 10772 void set name(SimpleIdentifier identifier) { |
| 10773 _name = _becomeParentOf(identifier as AstNodeImpl); |
| 10774 } |
| 10775 |
| 10776 @override |
| 10777 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10778 visitor.visitVariableDeclaration(this); |
| 10779 |
| 10780 @override |
| 10781 void visitChildren(AstVisitor visitor) { |
| 10782 super.visitChildren(visitor); |
| 10783 _name?.accept(visitor); |
| 10784 _initializer?.accept(visitor); |
| 10785 } |
| 10786 } |
| 10787 |
| 10788 /** |
| 10789 * The declaration of one or more variables of the same type. |
| 10790 * |
| 10791 * variableDeclarationList ::= |
| 10792 * finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])* |
| 10793 * |
| 10794 * finalConstVarOrType ::= |
| 10795 * | 'final' [TypeName]? |
| 10796 * | 'const' [TypeName]? |
| 10797 * | 'var' |
| 10798 * | [TypeName] |
| 10799 */ |
| 10800 class VariableDeclarationListImpl extends AnnotatedNodeImpl |
| 10801 implements VariableDeclarationList { |
| 10802 /** |
| 10803 * The token representing the 'final', 'const' or 'var' keyword, or `null` if |
| 10804 * no keyword was included. |
| 10805 */ |
| 10806 Token keyword; |
| 10807 |
| 10808 /** |
| 10809 * The type of the variables being declared, or `null` if no type was provided
. |
| 10810 */ |
| 10811 TypeName _type; |
| 10812 |
| 10813 /** |
| 10814 * A list containing the individual variables being declared. |
| 10815 */ |
| 10816 NodeList<VariableDeclaration> _variables; |
| 10817 |
| 10818 /** |
| 10819 * Initialize a newly created variable declaration list. Either or both of the |
| 10820 * [comment] and [metadata] can be `null` if the variable list does not have |
| 10821 * the corresponding attribute. The [keyword] can be `null` if a type was |
| 10822 * specified. The [type] must be `null` if the keyword is 'var'. |
| 10823 */ |
| 10824 VariableDeclarationListImpl(CommentImpl comment, List<Annotation> metadata, |
| 10825 this.keyword, TypeNameImpl type, List<VariableDeclaration> variables) |
| 10826 : super(comment, metadata) { |
| 10827 _type = _becomeParentOf(type); |
| 10828 _variables = new NodeListImpl<VariableDeclaration>(this, variables); |
| 10829 } |
| 10830 |
| 10831 @override |
| 10832 // TODO(paulberry): include commas. |
| 10833 Iterable<SyntacticEntity> get childEntities => super._childEntities |
| 10834 ..add(keyword) |
| 10835 ..add(_type) |
| 10836 ..addAll(_variables); |
| 10837 |
| 10838 @override |
| 10839 Token get endToken => _variables.endToken; |
| 10840 |
| 10841 @override |
| 10842 Token get firstTokenAfterCommentAndMetadata { |
| 10843 if (keyword != null) { |
| 10844 return keyword; |
| 10845 } else if (_type != null) { |
| 10846 return _type.beginToken; |
| 10847 } |
| 10848 return _variables.beginToken; |
| 10849 } |
| 10850 |
| 10851 @override |
| 10852 bool get isConst => keyword?.keyword == Keyword.CONST; |
| 10853 |
| 10854 @override |
| 10855 bool get isFinal => keyword?.keyword == Keyword.FINAL; |
| 10856 |
| 10857 @override |
| 10858 TypeName get type => _type; |
| 10859 |
| 10860 @override |
| 10861 void set type(TypeName typeName) { |
| 10862 _type = _becomeParentOf(typeName as AstNodeImpl); |
| 10863 } |
| 10864 |
| 10865 @override |
| 10866 NodeList<VariableDeclaration> get variables => _variables; |
| 10867 |
| 10868 @override |
| 10869 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10870 visitor.visitVariableDeclarationList(this); |
| 10871 |
| 10872 @override |
| 10873 void visitChildren(AstVisitor visitor) { |
| 10874 super.visitChildren(visitor); |
| 10875 _type?.accept(visitor); |
| 10876 _variables.accept(visitor); |
| 10877 } |
| 10878 } |
| 10879 |
| 10880 /** |
| 10881 * A list of variables that are being declared in a context where a statement is |
| 10882 * required. |
| 10883 * |
| 10884 * variableDeclarationStatement ::= |
| 10885 * [VariableDeclarationList] ';' |
| 10886 */ |
| 10887 class VariableDeclarationStatementImpl extends StatementImpl |
| 10888 implements VariableDeclarationStatement { |
| 10889 /** |
| 10890 * The variables being declared. |
| 10891 */ |
| 10892 VariableDeclarationList _variableList; |
| 10893 |
| 10894 /** |
| 10895 * The semicolon terminating the statement. |
| 10896 */ |
| 10897 Token semicolon; |
| 10898 |
| 10899 /** |
| 10900 * Initialize a newly created variable declaration statement. |
| 10901 */ |
| 10902 VariableDeclarationStatementImpl( |
| 10903 VariableDeclarationListImpl variableList, this.semicolon) { |
| 10904 _variableList = _becomeParentOf(variableList); |
| 10905 } |
| 10906 |
| 10907 @override |
| 10908 Token get beginToken => _variableList.beginToken; |
| 10909 |
| 10910 @override |
| 10911 Iterable<SyntacticEntity> get childEntities => |
| 10912 new ChildEntities()..add(_variableList)..add(semicolon); |
| 10913 |
| 10914 @override |
| 10915 Token get endToken => semicolon; |
| 10916 |
| 10917 @override |
| 10918 VariableDeclarationList get variables => _variableList; |
| 10919 |
| 10920 @override |
| 10921 void set variables(VariableDeclarationList variables) { |
| 10922 _variableList = _becomeParentOf(variables as AstNodeImpl); |
| 10923 } |
| 10924 |
| 10925 @override |
| 10926 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10927 visitor.visitVariableDeclarationStatement(this); |
| 10928 |
| 10929 @override |
| 10930 void visitChildren(AstVisitor visitor) { |
| 10931 _variableList?.accept(visitor); |
| 10932 } |
| 10933 } |
| 10934 |
| 10935 /** |
| 10936 * A while statement. |
| 10937 * |
| 10938 * whileStatement ::= |
| 10939 * 'while' '(' [Expression] ')' [Statement] |
| 10940 */ |
| 10941 class WhileStatementImpl extends StatementImpl implements WhileStatement { |
| 10942 /** |
| 10943 * The token representing the 'while' keyword. |
| 10944 */ |
| 10945 Token whileKeyword; |
| 10946 |
| 10947 /** |
| 10948 * The left parenthesis. |
| 10949 */ |
| 10950 Token leftParenthesis; |
| 10951 |
| 10952 /** |
| 10953 * The expression used to determine whether to execute the body of the loop. |
| 10954 */ |
| 10955 Expression _condition; |
| 10956 |
| 10957 /** |
| 10958 * The right parenthesis. |
| 10959 */ |
| 10960 Token rightParenthesis; |
| 10961 |
| 10962 /** |
| 10963 * The body of the loop. |
| 10964 */ |
| 10965 Statement _body; |
| 10966 |
| 10967 /** |
| 10968 * Initialize a newly created while statement. |
| 10969 */ |
| 10970 WhileStatementImpl(this.whileKeyword, this.leftParenthesis, |
| 10971 ExpressionImpl condition, this.rightParenthesis, StatementImpl body) { |
| 10972 _condition = _becomeParentOf(condition); |
| 10973 _body = _becomeParentOf(body); |
| 10974 } |
| 10975 |
| 10976 @override |
| 10977 Token get beginToken => whileKeyword; |
| 10978 |
| 10979 @override |
| 10980 Statement get body => _body; |
| 10981 |
| 10982 @override |
| 10983 void set body(Statement statement) { |
| 10984 _body = _becomeParentOf(statement as AstNodeImpl); |
| 10985 } |
| 10986 |
| 10987 @override |
| 10988 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 10989 ..add(whileKeyword) |
| 10990 ..add(leftParenthesis) |
| 10991 ..add(_condition) |
| 10992 ..add(rightParenthesis) |
| 10993 ..add(_body); |
| 10994 |
| 10995 @override |
| 10996 Expression get condition => _condition; |
| 10997 |
| 10998 @override |
| 10999 void set condition(Expression expression) { |
| 11000 _condition = _becomeParentOf(expression as AstNodeImpl); |
| 11001 } |
| 11002 |
| 11003 @override |
| 11004 Token get endToken => _body.endToken; |
| 11005 |
| 11006 @override |
| 11007 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 11008 visitor.visitWhileStatement(this); |
| 11009 |
| 11010 @override |
| 11011 void visitChildren(AstVisitor visitor) { |
| 11012 _condition?.accept(visitor); |
| 11013 _body?.accept(visitor); |
| 11014 } |
| 11015 } |
| 11016 |
| 11017 /** |
| 11018 * The with clause in a class declaration. |
| 11019 * |
| 11020 * withClause ::= |
| 11021 * 'with' [TypeName] (',' [TypeName])* |
| 11022 */ |
| 11023 class WithClauseImpl extends AstNodeImpl implements WithClause { |
| 11024 /** |
| 11025 * The token representing the 'with' keyword. |
| 11026 */ |
| 11027 Token withKeyword; |
| 11028 |
| 11029 /** |
| 11030 * The names of the mixins that were specified. |
| 11031 */ |
| 11032 NodeList<TypeName> _mixinTypes; |
| 11033 |
| 11034 /** |
| 11035 * Initialize a newly created with clause. |
| 11036 */ |
| 11037 WithClauseImpl(this.withKeyword, List<TypeName> mixinTypes) { |
| 11038 _mixinTypes = new NodeListImpl<TypeName>(this, mixinTypes); |
| 11039 } |
| 11040 |
| 11041 @override |
| 11042 Token get beginToken => withKeyword; |
| 11043 |
| 11044 @override |
| 11045 // TODO(paulberry): add commas. |
| 11046 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 11047 ..add(withKeyword) |
| 11048 ..addAll(_mixinTypes); |
| 11049 |
| 11050 @override |
| 11051 Token get endToken => _mixinTypes.endToken; |
| 11052 |
| 11053 @override |
| 11054 NodeList<TypeName> get mixinTypes => _mixinTypes; |
| 11055 |
| 11056 @override |
| 11057 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 11058 visitor.visitWithClause(this); |
| 11059 |
| 11060 @override |
| 11061 void visitChildren(AstVisitor visitor) { |
| 11062 _mixinTypes.accept(visitor); |
| 11063 } |
| 11064 } |
| 11065 |
| 11066 /** |
| 11067 * A yield statement. |
| 11068 * |
| 11069 * yieldStatement ::= |
| 11070 * 'yield' '*'? [Expression] ‘;’ |
| 11071 */ |
| 11072 class YieldStatementImpl extends StatementImpl implements YieldStatement { |
| 11073 /** |
| 11074 * The 'yield' keyword. |
| 11075 */ |
| 11076 Token yieldKeyword; |
| 11077 |
| 11078 /** |
| 11079 * The star optionally following the 'yield' keyword. |
| 11080 */ |
| 11081 Token star; |
| 11082 |
| 11083 /** |
| 11084 * The expression whose value will be yielded. |
| 11085 */ |
| 11086 Expression _expression; |
| 11087 |
| 11088 /** |
| 11089 * The semicolon following the expression. |
| 11090 */ |
| 11091 Token semicolon; |
| 11092 |
| 11093 /** |
| 11094 * Initialize a newly created yield expression. The [star] can be `null` if no |
| 11095 * star was provided. |
| 11096 */ |
| 11097 YieldStatementImpl( |
| 11098 this.yieldKeyword, this.star, ExpressionImpl expression, this.semicolon) { |
| 11099 _expression = _becomeParentOf(expression); |
| 11100 } |
| 11101 |
| 11102 @override |
| 11103 Token get beginToken { |
| 11104 if (yieldKeyword != null) { |
| 11105 return yieldKeyword; |
| 11106 } |
| 11107 return _expression.beginToken; |
| 11108 } |
| 11109 |
| 11110 @override |
| 11111 Iterable<SyntacticEntity> get childEntities => new ChildEntities() |
| 11112 ..add(yieldKeyword) |
| 11113 ..add(star) |
| 11114 ..add(_expression) |
| 11115 ..add(semicolon); |
| 11116 |
| 11117 @override |
| 11118 Token get endToken { |
| 11119 if (semicolon != null) { |
| 11120 return semicolon; |
| 11121 } |
| 11122 return _expression.endToken; |
| 11123 } |
| 11124 |
| 11125 @override |
| 11126 Expression get expression => _expression; |
| 11127 |
| 11128 @override |
| 11129 void set expression(Expression expression) { |
| 11130 _expression = _becomeParentOf(expression as AstNodeImpl); |
| 11131 } |
| 11132 |
| 11133 @override |
| 11134 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 11135 visitor.visitYieldStatement(this); |
| 11136 |
| 11137 @override |
| 11138 void visitChildren(AstVisitor visitor) { |
| 11139 _expression?.accept(visitor); |
| 11140 } |
| 11141 } |
| OLD | NEW |