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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.ast; 5 /**
6 * This library is deprecated. Please convert all references to this library to
7 * reference one of the following public libraries:
8 * * package:analyzer/dart/ast/ast.dart
9 * * package:analyzer/dart/ast/visitor.dart
10 *
11 * If your code is using APIs not available in these public libraries, please
12 * contact the analyzer team to either find an alternate API or have the API you
13 * depend on added to the public API.
14 */
15 @deprecated
16 library analyzer.src.generated.ast;
6 17
7 import 'dart:collection'; 18 export 'package:analyzer/dart/ast/ast.dart';
8 19 export 'package:analyzer/dart/ast/visitor.dart';
9 import 'element.dart'; 20 export 'package:analyzer/src/dart/ast/utilities.dart';
10 import 'engine.dart' show AnalysisEngine;
11 import 'java_core.dart';
12 import 'java_engine.dart';
13 import 'parser.dart';
14 import 'scanner.dart';
15 import 'source.dart' show LineInfo, Source;
16 import 'utilities_collection.dart' show TokenMap;
17 import 'utilities_dart.dart';
18
19 /**
20 * Two or more string literals that are implicitly concatenated because of being
21 * adjacent (separated only by whitespace).
22 *
23 * While the grammar only allows adjacent strings when all of the strings are of
24 * the same kind (single line or multi-line), this class doesn't enforce that
25 * restriction.
26 *
27 * > adjacentStrings ::=
28 * > [StringLiteral] [StringLiteral]+
29 */
30 class AdjacentStrings extends StringLiteral {
31 /**
32 * The strings that are implicitly concatenated.
33 */
34 NodeList<StringLiteral> _strings;
35
36 /**
37 * Initialize a newly created list of adjacent strings. To be syntactically
38 * valid, the list of [strings] must contain at least two elements.
39 */
40 AdjacentStrings(List<StringLiteral> strings) {
41 _strings = new NodeList<StringLiteral>(this, strings);
42 }
43
44 @override
45 Token get beginToken => _strings.beginToken;
46
47 @override
48 Iterable get childEntities => new ChildEntities()..addAll(_strings);
49
50 @override
51 Token get endToken => _strings.endToken;
52
53 /**
54 * Return the strings that are implicitly concatenated.
55 */
56 NodeList<StringLiteral> get strings => _strings;
57
58 @override
59 accept(AstVisitor visitor) => visitor.visitAdjacentStrings(this);
60
61 @override
62 void visitChildren(AstVisitor visitor) {
63 _strings.accept(visitor);
64 }
65
66 @override
67 void _appendStringValue(StringBuffer buffer) {
68 for (StringLiteral stringLiteral in strings) {
69 stringLiteral._appendStringValue(buffer);
70 }
71 }
72 }
73
74 /**
75 * An AST node that can be annotated with both a documentation comment and a
76 * list of annotations.
77 */
78 abstract class AnnotatedNode extends AstNode {
79 /**
80 * The documentation comment associated with this node, or `null` if this node
81 * does not have a documentation comment associated with it.
82 */
83 Comment _comment;
84
85 /**
86 * The annotations associated with this node.
87 */
88 NodeList<Annotation> _metadata;
89
90 /**
91 * Initialize a newly created annotated node. Either or both of the [comment]
92 * and [metadata] can be `null` if the node does not have the corresponding
93 * attribute.
94 */
95 AnnotatedNode(Comment comment, List<Annotation> metadata) {
96 _comment = _becomeParentOf(comment);
97 _metadata = new NodeList<Annotation>(this, metadata);
98 }
99
100 @override
101 Token get beginToken {
102 if (_comment == null) {
103 if (_metadata.isEmpty) {
104 return firstTokenAfterCommentAndMetadata;
105 }
106 return _metadata.beginToken;
107 } else if (_metadata.isEmpty) {
108 return _comment.beginToken;
109 }
110 Token commentToken = _comment.beginToken;
111 Token metadataToken = _metadata.beginToken;
112 if (commentToken.offset < metadataToken.offset) {
113 return commentToken;
114 }
115 return metadataToken;
116 }
117
118 /**
119 * Return the documentation comment associated with this node, or `null` if
120 * this node does not have a documentation comment associated with it.
121 */
122 Comment get documentationComment => _comment;
123
124 /**
125 * Set the documentation comment associated with this node to the given
126 * [comment].
127 */
128 void set documentationComment(Comment comment) {
129 _comment = _becomeParentOf(comment);
130 }
131
132 /**
133 * Return the first token following the comment and metadata.
134 */
135 Token get firstTokenAfterCommentAndMetadata;
136
137 /**
138 * Return the annotations associated with this node.
139 */
140 NodeList<Annotation> get metadata => _metadata;
141
142 /**
143 * Set the metadata associated with this node to the given [metadata].
144 */
145 @deprecated // Directly modify the list returned by "this.metadata"
146 void set metadata(List<Annotation> metadata) {
147 _metadata.clear();
148 _metadata.addAll(metadata);
149 }
150
151 /**
152 * Return a list containing the comment and annotations associated with this
153 * node, sorted in lexical order.
154 */
155 List<AstNode> get sortedCommentAndAnnotations {
156 return <AstNode>[]
157 ..add(_comment)
158 ..addAll(_metadata)
159 ..sort(AstNode.LEXICAL_ORDER);
160 }
161
162 /**
163 * Return a holder of child entities that subclasses can add to.
164 */
165 ChildEntities get _childEntities {
166 ChildEntities result = new ChildEntities();
167 if (_commentIsBeforeAnnotations()) {
168 result
169 ..add(_comment)
170 ..addAll(_metadata);
171 } else {
172 result.addAll(sortedCommentAndAnnotations);
173 }
174 return result;
175 }
176
177 @override
178 void visitChildren(AstVisitor visitor) {
179 if (_commentIsBeforeAnnotations()) {
180 _safelyVisitChild(_comment, visitor);
181 _metadata.accept(visitor);
182 } else {
183 for (AstNode child in sortedCommentAndAnnotations) {
184 child.accept(visitor);
185 }
186 }
187 }
188
189 /**
190 * Return `true` if there are no annotations before the comment. Note that a
191 * result of `true` does not imply that there is a comment, nor that there are
192 * annotations associated with this node.
193 */
194 bool _commentIsBeforeAnnotations() {
195 // TODO(brianwilkerson) Convert this to a getter.
196 if (_comment == null || _metadata.isEmpty) {
197 return true;
198 }
199 Annotation firstAnnotation = _metadata[0];
200 return _comment.offset < firstAnnotation.offset;
201 }
202 }
203
204 /**
205 * An annotation that can be associated with an AST node.
206 *
207 * > metadata ::=
208 * > annotation*
209 * >
210 * > annotation ::=
211 * > '@' [Identifier] ('.' [SimpleIdentifier])? [ArgumentList]?
212 */
213 class Annotation extends AstNode {
214 /**
215 * The at sign that introduced the annotation.
216 */
217 Token atSign;
218
219 /**
220 * The name of the class defining the constructor that is being invoked or the
221 * name of the field that is being referenced.
222 */
223 Identifier _name;
224
225 /**
226 * The period before the constructor name, or `null` if this annotation is not
227 * the invocation of a named constructor.
228 */
229 Token period;
230
231 /**
232 * The name of the constructor being invoked, or `null` if this annotation is
233 * not the invocation of a named constructor.
234 */
235 SimpleIdentifier _constructorName;
236
237 /**
238 * The arguments to the constructor being invoked, or `null` if this
239 * annotation is not the invocation of a constructor.
240 */
241 ArgumentList _arguments;
242
243 /**
244 * The element associated with this annotation, or `null` if the AST structure
245 * has not been resolved or if this annotation could not be resolved.
246 */
247 Element _element;
248
249 /**
250 * The element annotation representing this annotation in the element model.
251 */
252 ElementAnnotation elementAnnotation;
253
254 /**
255 * Initialize a newly created annotation. Both the [period] and the
256 * [constructorName] can be `null` if the annotation is not referencing a
257 * named constructor. The [arguments] can be `null` if the annotation is not
258 * referencing a constructor.
259 */
260 Annotation(this.atSign, Identifier name, this.period,
261 SimpleIdentifier constructorName, ArgumentList arguments) {
262 _name = _becomeParentOf(name);
263 _constructorName = _becomeParentOf(constructorName);
264 _arguments = _becomeParentOf(arguments);
265 }
266
267 /**
268 * Return the arguments to the constructor being invoked, or `null` if this
269 * annotation is not the invocation of a constructor.
270 */
271 ArgumentList get arguments => _arguments;
272
273 /**
274 * Set the arguments to the constructor being invoked to the given arguments.
275 */
276 void set arguments(ArgumentList arguments) {
277 _arguments = _becomeParentOf(arguments);
278 }
279
280 @override
281 Token get beginToken => atSign;
282
283 @override
284 Iterable get childEntities => new ChildEntities()
285 ..add(atSign)
286 ..add(_name)
287 ..add(period)
288 ..add(_constructorName)
289 ..add(_arguments);
290
291 /**
292 * Return the name of the constructor being invoked, or `null` if this
293 * annotation is not the invocation of a named constructor.
294 */
295 SimpleIdentifier get constructorName => _constructorName;
296
297 /**
298 * Set the name of the constructor being invoked to the given [name].
299 */
300 void set constructorName(SimpleIdentifier name) {
301 _constructorName = _becomeParentOf(name);
302 }
303
304 /**
305 * Return the element associated with this annotation, or `null` if the AST
306 * structure has not been resolved or if this annotation could not be
307 * resolved.
308 */
309 Element get element {
310 if (_element != null) {
311 return _element;
312 } else if (_name != null) {
313 return _name.staticElement;
314 }
315 return null;
316 }
317
318 /**
319 * Set the element associated with this annotation to the given [element].
320 */
321 void set element(Element element) {
322 _element = element;
323 }
324
325 @override
326 Token get endToken {
327 if (_arguments != null) {
328 return _arguments.endToken;
329 } else if (_constructorName != null) {
330 return _constructorName.endToken;
331 }
332 return _name.endToken;
333 }
334
335 /**
336 * Return the name of the class defining the constructor that is being invoked
337 * or the name of the field that is being referenced.
338 */
339 Identifier get name => _name;
340
341 /**
342 * Set the name of the class defining the constructor that is being invoked or
343 * the name of the field that is being referenced to the given [name].
344 */
345 void set name(Identifier name) {
346 _name = _becomeParentOf(name);
347 }
348
349 @override
350 accept(AstVisitor visitor) => visitor.visitAnnotation(this);
351
352 @override
353 void visitChildren(AstVisitor visitor) {
354 _safelyVisitChild(_name, visitor);
355 _safelyVisitChild(_constructorName, visitor);
356 _safelyVisitChild(_arguments, visitor);
357 }
358 }
359
360 /**
361 * A list of arguments in the invocation of an executable element (that is, a
362 * function, method, or constructor).
363 *
364 * > argumentList ::=
365 * > '(' arguments? ')'
366 * >
367 * > arguments ::=
368 * > [NamedExpression] (',' [NamedExpression])*
369 * > | [Expression] (',' [Expression])* (',' [NamedExpression])*
370 */
371 class ArgumentList extends AstNode {
372 /**
373 * The left parenthesis.
374 */
375 Token leftParenthesis;
376
377 /**
378 * The expressions producing the values of the arguments.
379 */
380 NodeList<Expression> _arguments;
381
382 /**
383 * The right parenthesis.
384 */
385 Token rightParenthesis;
386
387 /**
388 * A list containing the elements representing the parameters corresponding to
389 * each of the arguments in this list, or `null` if the AST has not been
390 * resolved or if the function or method being invoked could not be determined
391 * based on static type information. The list must be the same length as the
392 * number of arguments, but can contain `null` entries if a given argument
393 * does not correspond to a formal parameter.
394 */
395 List<ParameterElement> _correspondingStaticParameters;
396
397 /**
398 * A list containing the elements representing the parameters corresponding to
399 * each of the arguments in this list, or `null` if the AST has not been
400 * resolved or if the function or method being invoked could not be determined
401 * based on propagated type information. The list must be the same length as
402 * the number of arguments, but can contain `null` entries if a given argument
403 * does not correspond to a formal parameter.
404 */
405 List<ParameterElement> _correspondingPropagatedParameters;
406
407 /**
408 * Initialize a newly created list of arguments. The list of [arguments] can
409 * be `null` if there are no arguments.
410 */
411 ArgumentList(
412 this.leftParenthesis, List<Expression> arguments, this.rightParenthesis) {
413 _arguments = new NodeList<Expression>(this, arguments);
414 }
415
416 /**
417 * Return the expressions producing the values of the arguments. Although the
418 * language requires that positional arguments appear before named arguments,
419 * this class allows them to be intermixed.
420 */
421 NodeList<Expression> get arguments => _arguments;
422
423 @override
424 Token get beginToken => leftParenthesis;
425
426 @override
427 // TODO(paulberry): Add commas.
428 Iterable get childEntities => new ChildEntities()
429 ..add(leftParenthesis)
430 ..addAll(_arguments)
431 ..add(rightParenthesis);
432
433 /**
434 * Set the parameter elements corresponding to each of the arguments in this
435 * list to the given list of [parameters]. The list of parameters must be the
436 * same length as the number of arguments, but can contain `null` entries if a
437 * given argument does not correspond to a formal parameter.
438 */
439 void set correspondingPropagatedParameters(
440 List<ParameterElement> parameters) {
441 if (parameters.length != _arguments.length) {
442 throw new IllegalArgumentException(
443 "Expected ${_arguments.length} parameters, not ${parameters.length}");
444 }
445 _correspondingPropagatedParameters = parameters;
446 }
447
448 /**
449 * Set the parameter elements corresponding to each of the arguments in this
450 * list to the given list of parameters. The list of parameters must be the
451 * same length as the number of arguments, but can contain `null` entries if a
452 * given argument does not correspond to a formal parameter.
453 */
454 void set correspondingStaticParameters(List<ParameterElement> parameters) {
455 if (parameters.length != _arguments.length) {
456 throw new IllegalArgumentException(
457 "Expected ${_arguments.length} parameters, not ${parameters.length}");
458 }
459 _correspondingStaticParameters = parameters;
460 }
461
462 @override
463 Token get endToken => rightParenthesis;
464
465 @override
466 accept(AstVisitor visitor) => visitor.visitArgumentList(this);
467
468 /**
469 * If
470 * * the given [expression] is a child of this list,
471 * * the AST structure has been resolved,
472 * * the function being invoked is known based on propagated type information,
473 * and
474 * * the expression corresponds to one of the parameters of the function being
475 * invoked,
476 * then return the parameter element representing the parameter to which the
477 * value of the given expression will be bound. Otherwise, return `null`.
478 */
479 @deprecated // Use "expression.propagatedParameterElement"
480 ParameterElement getPropagatedParameterElementFor(Expression expression) {
481 return _getPropagatedParameterElementFor(expression);
482 }
483
484 /**
485 * If
486 * * the given [expression] is a child of this list,
487 * * the AST structure has been resolved,
488 * * the function being invoked is known based on static type information, and
489 * * the expression corresponds to one of the parameters of the function being
490 * invoked,
491 * then return the parameter element representing the parameter to which the
492 * value of the given expression will be bound. Otherwise, return `null`.
493 */
494 @deprecated // Use "expression.staticParameterElement"
495 ParameterElement getStaticParameterElementFor(Expression expression) {
496 return _getStaticParameterElementFor(expression);
497 }
498
499 @override
500 void visitChildren(AstVisitor visitor) {
501 _arguments.accept(visitor);
502 }
503
504 /**
505 * If
506 * * the given [expression] is a child of this list,
507 * * the AST structure has been resolved,
508 * * the function being invoked is known based on propagated type information,
509 * and
510 * * the expression corresponds to one of the parameters of the function being
511 * invoked,
512 * then return the parameter element representing the parameter to which the
513 * value of the given expression will be bound. Otherwise, return `null`.
514 */
515 ParameterElement _getPropagatedParameterElementFor(Expression expression) {
516 if (_correspondingPropagatedParameters == null ||
517 _correspondingPropagatedParameters.length != _arguments.length) {
518 // Either the AST structure has not been resolved, the invocation of which
519 // this list is a part could not be resolved, or the argument list was
520 // modified after the parameters were set.
521 return null;
522 }
523 int index = _arguments.indexOf(expression);
524 if (index < 0) {
525 // The expression isn't a child of this node.
526 return null;
527 }
528 return _correspondingPropagatedParameters[index];
529 }
530
531 /**
532 * If
533 * * the given [expression] is a child of this list,
534 * * the AST structure has been resolved,
535 * * the function being invoked is known based on static type information, and
536 * * the expression corresponds to one of the parameters of the function being
537 * invoked,
538 * then return the parameter element representing the parameter to which the
539 * value of the given expression will be bound. Otherwise, return `null`.
540 */
541 ParameterElement _getStaticParameterElementFor(Expression expression) {
542 if (_correspondingStaticParameters == null ||
543 _correspondingStaticParameters.length != _arguments.length) {
544 // Either the AST structure has not been resolved, the invocation of which
545 // this list is a part could not be resolved, or the argument list was
546 // modified after the parameters were set.
547 return null;
548 }
549 int index = _arguments.indexOf(expression);
550 if (index < 0) {
551 // The expression isn't a child of this node.
552 return null;
553 }
554 return _correspondingStaticParameters[index];
555 }
556 }
557
558 /**
559 * An as expression.
560 *
561 * > asExpression ::=
562 * > [Expression] 'as' [TypeName]
563 */
564 class AsExpression extends Expression {
565 /**
566 * The expression used to compute the value being cast.
567 */
568 Expression _expression;
569
570 /**
571 * The 'as' operator.
572 */
573 Token asOperator;
574
575 /**
576 * The name of the type being cast to.
577 */
578 TypeName _type;
579
580 /**
581 * Initialize a newly created as expression.
582 */
583 AsExpression(Expression expression, this.asOperator, TypeName type) {
584 _expression = _becomeParentOf(expression);
585 _type = _becomeParentOf(type);
586 }
587
588 @override
589 Token get beginToken => _expression.beginToken;
590
591 @override
592 Iterable get childEntities =>
593 new ChildEntities()..add(_expression)..add(asOperator)..add(_type);
594
595 @override
596 Token get endToken => _type.endToken;
597
598 /**
599 * Return the expression used to compute the value being cast.
600 */
601 Expression get expression => _expression;
602
603 /**
604 * Set the expression used to compute the value being cast to the given
605 * [expression].
606 */
607 void set expression(Expression expression) {
608 _expression = _becomeParentOf(expression);
609 }
610
611 @override
612 int get precedence => 7;
613
614 /**
615 * Return the name of the type being cast to.
616 */
617 TypeName get type => _type;
618
619 /**
620 * Set the name of the type being cast to to the given [name].
621 */
622 void set type(TypeName name) {
623 _type = _becomeParentOf(name);
624 }
625
626 @override
627 accept(AstVisitor visitor) => visitor.visitAsExpression(this);
628
629 @override
630 void visitChildren(AstVisitor visitor) {
631 _safelyVisitChild(_expression, visitor);
632 _safelyVisitChild(_type, visitor);
633 }
634 }
635
636 /**
637 * An assert statement.
638 *
639 * > assertStatement ::=
640 * > 'assert' '(' [Expression] ')' ';'
641 */
642 class AssertStatement extends Statement {
643 /**
644 * The token representing the 'assert' keyword.
645 */
646 Token assertKeyword;
647
648 /**
649 * The left parenthesis.
650 */
651 Token leftParenthesis;
652
653 /**
654 * The condition that is being asserted to be `true`.
655 */
656 Expression _condition;
657
658 /**
659 * The right parenthesis.
660 */
661 Token rightParenthesis;
662
663 /**
664 * The semicolon terminating the statement.
665 */
666 Token semicolon;
667
668 /**
669 * Initialize a newly created assert statement.
670 */
671 AssertStatement(this.assertKeyword, this.leftParenthesis,
672 Expression condition, this.rightParenthesis, this.semicolon) {
673 _condition = _becomeParentOf(condition);
674 }
675
676 @override
677 Token get beginToken => assertKeyword;
678
679 @override
680 Iterable get childEntities => new ChildEntities()
681 ..add(assertKeyword)
682 ..add(leftParenthesis)
683 ..add(_condition)
684 ..add(rightParenthesis)
685 ..add(semicolon);
686
687 /**
688 * Return the condition that is being asserted to be `true`.
689 */
690 Expression get condition => _condition;
691
692 /**
693 * Set the condition that is being asserted to be `true` to the given
694 * [expression].
695 */
696 void set condition(Expression condition) {
697 _condition = _becomeParentOf(condition);
698 }
699
700 @override
701 Token get endToken => semicolon;
702
703 /**
704 * Return the token representing the 'assert' keyword.
705 */
706 @deprecated // Use "this.assertKeyword"
707 Token get keyword => assertKeyword;
708
709 /**
710 * Set the token representing the 'assert' keyword to the given [token].
711 */
712 @deprecated // Use "this.assertKeyword"
713 set keyword(Token token) {
714 assertKeyword = token;
715 }
716
717 @override
718 accept(AstVisitor visitor) => visitor.visitAssertStatement(this);
719
720 @override
721 void visitChildren(AstVisitor visitor) {
722 _safelyVisitChild(_condition, visitor);
723 }
724 }
725
726 /**
727 * An assignment expression.
728 *
729 * > assignmentExpression ::=
730 * > [Expression] operator [Expression]
731 */
732 class AssignmentExpression extends Expression {
733 /**
734 * The expression used to compute the left hand side.
735 */
736 Expression _leftHandSide;
737
738 /**
739 * The assignment operator being applied.
740 */
741 Token operator;
742
743 /**
744 * The expression used to compute the right hand side.
745 */
746 Expression _rightHandSide;
747
748 /**
749 * The element associated with the operator based on the static type of the
750 * left-hand-side, or `null` if the AST structure has not been resolved, if
751 * the operator is not a compound operator, or if the operator could not be
752 * resolved.
753 */
754 MethodElement staticElement;
755
756 /**
757 * The element associated with the operator based on the propagated type of
758 * the left-hand-side, or `null` if the AST structure has not been resolved,
759 * if the operator is not a compound operator, or if the operator could not be
760 * resolved.
761 */
762 MethodElement propagatedElement;
763
764 /**
765 * Initialize a newly created assignment expression.
766 */
767 AssignmentExpression(
768 Expression leftHandSide, this.operator, Expression rightHandSide) {
769 if (leftHandSide == null || rightHandSide == null) {
770 String message;
771 if (leftHandSide == null) {
772 if (rightHandSide == null) {
773 message = "Both the left-hand and right-hand sides are null";
774 } else {
775 message = "The left-hand size is null";
776 }
777 } else {
778 message = "The right-hand size is null";
779 }
780 AnalysisEngine.instance.logger.logError(
781 message, new CaughtException(new AnalysisException(message), null));
782 }
783 _leftHandSide = _becomeParentOf(leftHandSide);
784 _rightHandSide = _becomeParentOf(rightHandSide);
785 }
786
787 @override
788 Token get beginToken => _leftHandSide.beginToken;
789
790 /**
791 * Return the best element available for this operator. If resolution was able
792 * to find a better element based on type propagation, that element will be
793 * returned. Otherwise, the element found using the result of static analysis
794 * will be returned. If resolution has not been performed, then `null` will be
795 * returned.
796 */
797 MethodElement get bestElement {
798 MethodElement element = propagatedElement;
799 if (element == null) {
800 element = staticElement;
801 }
802 return element;
803 }
804
805 @override
806 Iterable get childEntities => new ChildEntities()
807 ..add(_leftHandSide)
808 ..add(operator)
809 ..add(_rightHandSide);
810
811 @override
812 Token get endToken => _rightHandSide.endToken;
813
814 /**
815 * Set the expression used to compute the left hand side to the given
816 * [expression].
817 */
818 Expression get leftHandSide => _leftHandSide;
819
820 /**
821 * Return the expression used to compute the left hand side.
822 */
823 void set leftHandSide(Expression expression) {
824 _leftHandSide = _becomeParentOf(expression);
825 }
826
827 @override
828 int get precedence => 1;
829
830 /**
831 * If the AST structure has been resolved, and the function being invoked is
832 * known based on propagated type information, then return the parameter
833 * element representing the parameter to which the value of the right operand
834 * will be bound. Otherwise, return `null`.
835 */
836 @deprecated // Use "expression.propagatedParameterElement"
837 ParameterElement get propagatedParameterElementForRightHandSide {
838 return _propagatedParameterElementForRightHandSide;
839 }
840
841 /**
842 * Return the expression used to compute the right hand side.
843 */
844 Expression get rightHandSide => _rightHandSide;
845
846 /**
847 * Set the expression used to compute the left hand side to the given
848 * [expression].
849 */
850 void set rightHandSide(Expression expression) {
851 _rightHandSide = _becomeParentOf(expression);
852 }
853
854 /**
855 * If the AST structure has been resolved, and the function being invoked is
856 * known based on static type information, then return the parameter element
857 * representing the parameter to which the value of the right operand will be
858 * bound. Otherwise, return `null`.
859 */
860 @deprecated // Use "expression.staticParameterElement"
861 ParameterElement get staticParameterElementForRightHandSide {
862 return _staticParameterElementForRightHandSide;
863 }
864
865 /**
866 * If the AST structure has been resolved, and the function being invoked is
867 * known based on propagated type information, then return the parameter
868 * element representing the parameter to which the value of the right operand
869 * will be bound. Otherwise, return `null`.
870 */
871 ParameterElement get _propagatedParameterElementForRightHandSide {
872 ExecutableElement executableElement = null;
873 if (propagatedElement != null) {
874 executableElement = propagatedElement;
875 } else {
876 if (_leftHandSide is Identifier) {
877 Identifier identifier = _leftHandSide as Identifier;
878 Element leftElement = identifier.propagatedElement;
879 if (leftElement is ExecutableElement) {
880 executableElement = leftElement;
881 }
882 }
883 if (_leftHandSide is PropertyAccess) {
884 SimpleIdentifier identifier =
885 (_leftHandSide as PropertyAccess).propertyName;
886 Element leftElement = identifier.propagatedElement;
887 if (leftElement is ExecutableElement) {
888 executableElement = leftElement;
889 }
890 }
891 }
892 if (executableElement == null) {
893 return null;
894 }
895 List<ParameterElement> parameters = executableElement.parameters;
896 if (parameters.length < 1) {
897 return null;
898 }
899 return parameters[0];
900 }
901
902 /**
903 * If the AST structure has been resolved, and the function being invoked is
904 * known based on static type information, then return the parameter element
905 * representing the parameter to which the value of the right operand will be
906 * bound. Otherwise, return `null`.
907 */
908 ParameterElement get _staticParameterElementForRightHandSide {
909 ExecutableElement executableElement = null;
910 if (staticElement != null) {
911 executableElement = staticElement;
912 } else {
913 if (_leftHandSide is Identifier) {
914 Element leftElement = (_leftHandSide as Identifier).staticElement;
915 if (leftElement is ExecutableElement) {
916 executableElement = leftElement;
917 }
918 }
919 if (_leftHandSide is PropertyAccess) {
920 Element leftElement =
921 (_leftHandSide as PropertyAccess).propertyName.staticElement;
922 if (leftElement is ExecutableElement) {
923 executableElement = leftElement;
924 }
925 }
926 }
927 if (executableElement == null) {
928 return null;
929 }
930 List<ParameterElement> parameters = executableElement.parameters;
931 if (parameters.length < 1) {
932 return null;
933 }
934 return parameters[0];
935 }
936
937 @override
938 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this);
939
940 @override
941 void visitChildren(AstVisitor visitor) {
942 _safelyVisitChild(_leftHandSide, visitor);
943 _safelyVisitChild(_rightHandSide, visitor);
944 }
945 }
946
947 /**
948 * An AST visitor that will clone any AST structure that it visits. The cloner
949 * will only clone the structure, it will not preserve any resolution results or
950 * properties associated with the nodes.
951 */
952 class AstCloner implements AstVisitor<AstNode> {
953 /**
954 * A flag indicating whether tokens should be cloned while cloning an AST
955 * structure.
956 */
957 final bool cloneTokens;
958
959 /**
960 * Initialize a newly created AST cloner to optionally clone tokens while
961 * cloning AST nodes if [cloneTokens] is `true`.
962 */
963 AstCloner(
964 [this.cloneTokens =
965 false]); // TODO(brianwilkerson) Change this to be a named parameter.
966
967 /**
968 * Return a clone of the given [node].
969 */
970 AstNode cloneNode(AstNode node) {
971 if (node == null) {
972 return null;
973 }
974 return node.accept(this) as AstNode;
975 }
976
977 /**
978 * Return a list containing cloned versions of the nodes in the given list of
979 * [nodes].
980 */
981 List<AstNode> cloneNodeList(NodeList nodes) {
982 int count = nodes.length;
983 List clonedNodes = new List();
984 for (int i = 0; i < count; i++) {
985 clonedNodes.add((nodes[i]).accept(this) as AstNode);
986 }
987 return clonedNodes;
988 }
989
990 /**
991 * Clone the given [token] if tokens are supposed to be cloned.
992 */
993 Token cloneToken(Token token) {
994 if (cloneTokens) {
995 return (token == null ? null : token.copy());
996 } else {
997 return token;
998 }
999 }
1000
1001 /**
1002 * Clone the given [tokens] if tokens are supposed to be cloned.
1003 */
1004 List<Token> cloneTokenList(List<Token> tokens) {
1005 if (cloneTokens) {
1006 return tokens.map((Token token) => token.copy()).toList();
1007 }
1008 return tokens;
1009 }
1010
1011 @override
1012 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
1013 new AdjacentStrings(cloneNodeList(node.strings));
1014
1015 @override
1016 Annotation visitAnnotation(Annotation node) => new Annotation(
1017 cloneToken(node.atSign),
1018 cloneNode(node.name),
1019 cloneToken(node.period),
1020 cloneNode(node.constructorName),
1021 cloneNode(node.arguments));
1022
1023 @override
1024 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
1025 cloneToken(node.leftParenthesis),
1026 cloneNodeList(node.arguments),
1027 cloneToken(node.rightParenthesis));
1028
1029 @override
1030 AsExpression visitAsExpression(AsExpression node) => new AsExpression(
1031 cloneNode(node.expression),
1032 cloneToken(node.asOperator),
1033 cloneNode(node.type));
1034
1035 @override
1036 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
1037 cloneToken(node.assertKeyword),
1038 cloneToken(node.leftParenthesis),
1039 cloneNode(node.condition),
1040 cloneToken(node.rightParenthesis),
1041 cloneToken(node.semicolon));
1042
1043 @override
1044 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) =>
1045 new AssignmentExpression(cloneNode(node.leftHandSide),
1046 cloneToken(node.operator), cloneNode(node.rightHandSide));
1047
1048 @override
1049 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
1050 new AwaitExpression(
1051 cloneToken(node.awaitKeyword), cloneNode(node.expression));
1052
1053 @override
1054 BinaryExpression visitBinaryExpression(BinaryExpression node) =>
1055 new BinaryExpression(cloneNode(node.leftOperand),
1056 cloneToken(node.operator), cloneNode(node.rightOperand));
1057
1058 @override
1059 Block visitBlock(Block node) => new Block(cloneToken(node.leftBracket),
1060 cloneNodeList(node.statements), cloneToken(node.rightBracket));
1061
1062 @override
1063 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) =>
1064 new BlockFunctionBody(cloneToken(node.keyword), cloneToken(node.star),
1065 cloneNode(node.block));
1066
1067 @override
1068 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) =>
1069 new BooleanLiteral(cloneToken(node.literal), node.value);
1070
1071 @override
1072 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
1073 cloneToken(node.breakKeyword),
1074 cloneNode(node.label),
1075 cloneToken(node.semicolon));
1076
1077 @override
1078 CascadeExpression visitCascadeExpression(CascadeExpression node) =>
1079 new CascadeExpression(
1080 cloneNode(node.target), cloneNodeList(node.cascadeSections));
1081
1082 @override
1083 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
1084 cloneToken(node.onKeyword),
1085 cloneNode(node.exceptionType),
1086 cloneToken(node.catchKeyword),
1087 cloneToken(node.leftParenthesis),
1088 cloneNode(node.exceptionParameter),
1089 cloneToken(node.comma),
1090 cloneNode(node.stackTraceParameter),
1091 cloneToken(node.rightParenthesis),
1092 cloneNode(node.body));
1093
1094 @override
1095 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
1096 ClassDeclaration copy = new ClassDeclaration(
1097 cloneNode(node.documentationComment),
1098 cloneNodeList(node.metadata),
1099 cloneToken(node.abstractKeyword),
1100 cloneToken(node.classKeyword),
1101 cloneNode(node.name),
1102 cloneNode(node.typeParameters),
1103 cloneNode(node.extendsClause),
1104 cloneNode(node.withClause),
1105 cloneNode(node.implementsClause),
1106 cloneToken(node.leftBracket),
1107 cloneNodeList(node.members),
1108 cloneToken(node.rightBracket));
1109 copy.nativeClause = cloneNode(node.nativeClause);
1110 return copy;
1111 }
1112
1113 @override
1114 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
1115 cloneNode(node.documentationComment),
1116 cloneNodeList(node.metadata),
1117 cloneToken(node.typedefKeyword),
1118 cloneNode(node.name),
1119 cloneNode(node.typeParameters),
1120 cloneToken(node.equals),
1121 cloneToken(node.abstractKeyword),
1122 cloneNode(node.superclass),
1123 cloneNode(node.withClause),
1124 cloneNode(node.implementsClause),
1125 cloneToken(node.semicolon));
1126
1127 @override
1128 Comment visitComment(Comment node) {
1129 if (node.isDocumentation) {
1130 return Comment.createDocumentationCommentWithReferences(
1131 cloneTokenList(node.tokens), cloneNodeList(node.references));
1132 } else if (node.isBlock) {
1133 return Comment.createBlockComment(cloneTokenList(node.tokens));
1134 }
1135 return Comment.createEndOfLineComment(cloneTokenList(node.tokens));
1136 }
1137
1138 @override
1139 CommentReference visitCommentReference(CommentReference node) =>
1140 new CommentReference(
1141 cloneToken(node.newKeyword), cloneNode(node.identifier));
1142
1143 @override
1144 CompilationUnit visitCompilationUnit(CompilationUnit node) {
1145 CompilationUnit clone = new CompilationUnit(
1146 cloneToken(node.beginToken),
1147 cloneNode(node.scriptTag),
1148 cloneNodeList(node.directives),
1149 cloneNodeList(node.declarations),
1150 cloneToken(node.endToken));
1151 clone.lineInfo = node.lineInfo;
1152 return clone;
1153 }
1154
1155 @override
1156 ConditionalExpression visitConditionalExpression(
1157 ConditionalExpression node) =>
1158 new ConditionalExpression(
1159 cloneNode(node.condition),
1160 cloneToken(node.question),
1161 cloneNode(node.thenExpression),
1162 cloneToken(node.colon),
1163 cloneNode(node.elseExpression));
1164
1165 @override
1166 ConstructorDeclaration visitConstructorDeclaration(
1167 ConstructorDeclaration node) =>
1168 new ConstructorDeclaration(
1169 cloneNode(node.documentationComment),
1170 cloneNodeList(node.metadata),
1171 cloneToken(node.externalKeyword),
1172 cloneToken(node.constKeyword),
1173 cloneToken(node.factoryKeyword),
1174 cloneNode(node.returnType),
1175 cloneToken(node.period),
1176 cloneNode(node.name),
1177 cloneNode(node.parameters),
1178 cloneToken(node.separator),
1179 cloneNodeList(node.initializers),
1180 cloneNode(node.redirectedConstructor),
1181 cloneNode(node.body));
1182
1183 @override
1184 ConstructorFieldInitializer visitConstructorFieldInitializer(
1185 ConstructorFieldInitializer node) =>
1186 new ConstructorFieldInitializer(
1187 cloneToken(node.thisKeyword),
1188 cloneToken(node.period),
1189 cloneNode(node.fieldName),
1190 cloneToken(node.equals),
1191 cloneNode(node.expression));
1192
1193 @override
1194 ConstructorName visitConstructorName(ConstructorName node) =>
1195 new ConstructorName(
1196 cloneNode(node.type), cloneToken(node.period), cloneNode(node.name));
1197
1198 @override
1199 ContinueStatement visitContinueStatement(ContinueStatement node) =>
1200 new ContinueStatement(cloneToken(node.continueKeyword),
1201 cloneNode(node.label), cloneToken(node.semicolon));
1202
1203 @override
1204 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
1205 new DeclaredIdentifier(
1206 cloneNode(node.documentationComment),
1207 cloneNodeList(node.metadata),
1208 cloneToken(node.keyword),
1209 cloneNode(node.type),
1210 cloneNode(node.identifier));
1211
1212 @override
1213 DefaultFormalParameter visitDefaultFormalParameter(
1214 DefaultFormalParameter node) =>
1215 new DefaultFormalParameter(cloneNode(node.parameter), node.kind,
1216 cloneToken(node.separator), cloneNode(node.defaultValue));
1217
1218 @override
1219 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
1220 cloneToken(node.doKeyword),
1221 cloneNode(node.body),
1222 cloneToken(node.whileKeyword),
1223 cloneToken(node.leftParenthesis),
1224 cloneNode(node.condition),
1225 cloneToken(node.rightParenthesis),
1226 cloneToken(node.semicolon));
1227
1228 @override
1229 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) =>
1230 new DoubleLiteral(cloneToken(node.literal), node.value);
1231
1232 @override
1233 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
1234 new EmptyFunctionBody(cloneToken(node.semicolon));
1235
1236 @override
1237 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
1238 new EmptyStatement(cloneToken(node.semicolon));
1239
1240 @override
1241 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
1242 new EnumConstantDeclaration(cloneNode(node.documentationComment),
1243 cloneNodeList(node.metadata), cloneNode(node.name));
1244
1245 @override
1246 EnumDeclaration visitEnumDeclaration(EnumDeclaration node) =>
1247 new EnumDeclaration(
1248 cloneNode(node.documentationComment),
1249 cloneNodeList(node.metadata),
1250 cloneToken(node.enumKeyword),
1251 cloneNode(node.name),
1252 cloneToken(node.leftBracket),
1253 cloneNodeList(node.constants),
1254 cloneToken(node.rightBracket));
1255
1256 @override
1257 ExportDirective visitExportDirective(ExportDirective node) {
1258 ExportDirective directive = new ExportDirective(
1259 cloneNode(node.documentationComment),
1260 cloneNodeList(node.metadata),
1261 cloneToken(node.keyword),
1262 cloneNode(node.uri),
1263 cloneNodeList(node.combinators),
1264 cloneToken(node.semicolon));
1265 directive.source = node.source;
1266 directive.uriContent = node.uriContent;
1267 return directive;
1268 }
1269
1270 @override
1271 ExpressionFunctionBody visitExpressionFunctionBody(
1272 ExpressionFunctionBody node) =>
1273 new ExpressionFunctionBody(
1274 cloneToken(node.keyword),
1275 cloneToken(node.functionDefinition),
1276 cloneNode(node.expression),
1277 cloneToken(node.semicolon));
1278
1279 @override
1280 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
1281 new ExpressionStatement(
1282 cloneNode(node.expression), cloneToken(node.semicolon));
1283
1284 @override
1285 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
1286 cloneToken(node.extendsKeyword), cloneNode(node.superclass));
1287
1288 @override
1289 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
1290 new FieldDeclaration(
1291 cloneNode(node.documentationComment),
1292 cloneNodeList(node.metadata),
1293 cloneToken(node.staticKeyword),
1294 cloneNode(node.fields),
1295 cloneToken(node.semicolon));
1296
1297 @override
1298 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
1299 new FieldFormalParameter(
1300 cloneNode(node.documentationComment),
1301 cloneNodeList(node.metadata),
1302 cloneToken(node.keyword),
1303 cloneNode(node.type),
1304 cloneToken(node.thisKeyword),
1305 cloneToken(node.period),
1306 cloneNode(node.identifier),
1307 cloneNode(node.typeParameters),
1308 cloneNode(node.parameters));
1309
1310 @override
1311 ForEachStatement visitForEachStatement(ForEachStatement node) {
1312 DeclaredIdentifier loopVariable = node.loopVariable;
1313 if (loopVariable == null) {
1314 return new ForEachStatement.withReference(
1315 cloneToken(node.awaitKeyword),
1316 cloneToken(node.forKeyword),
1317 cloneToken(node.leftParenthesis),
1318 cloneNode(node.identifier),
1319 cloneToken(node.inKeyword),
1320 cloneNode(node.iterable),
1321 cloneToken(node.rightParenthesis),
1322 cloneNode(node.body));
1323 }
1324 return new ForEachStatement.withDeclaration(
1325 cloneToken(node.awaitKeyword),
1326 cloneToken(node.forKeyword),
1327 cloneToken(node.leftParenthesis),
1328 cloneNode(loopVariable),
1329 cloneToken(node.inKeyword),
1330 cloneNode(node.iterable),
1331 cloneToken(node.rightParenthesis),
1332 cloneNode(node.body));
1333 }
1334
1335 @override
1336 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
1337 new FormalParameterList(
1338 cloneToken(node.leftParenthesis),
1339 cloneNodeList(node.parameters),
1340 cloneToken(node.leftDelimiter),
1341 cloneToken(node.rightDelimiter),
1342 cloneToken(node.rightParenthesis));
1343
1344 @override
1345 ForStatement visitForStatement(ForStatement node) => new ForStatement(
1346 cloneToken(node.forKeyword),
1347 cloneToken(node.leftParenthesis),
1348 cloneNode(node.variables),
1349 cloneNode(node.initialization),
1350 cloneToken(node.leftSeparator),
1351 cloneNode(node.condition),
1352 cloneToken(node.rightSeparator),
1353 cloneNodeList(node.updaters),
1354 cloneToken(node.rightParenthesis),
1355 cloneNode(node.body));
1356
1357 @override
1358 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
1359 new FunctionDeclaration(
1360 cloneNode(node.documentationComment),
1361 cloneNodeList(node.metadata),
1362 cloneToken(node.externalKeyword),
1363 cloneNode(node.returnType),
1364 cloneToken(node.propertyKeyword),
1365 cloneNode(node.name),
1366 cloneNode(node.functionExpression));
1367
1368 @override
1369 FunctionDeclarationStatement visitFunctionDeclarationStatement(
1370 FunctionDeclarationStatement node) =>
1371 new FunctionDeclarationStatement(cloneNode(node.functionDeclaration));
1372
1373 @override
1374 FunctionExpression visitFunctionExpression(FunctionExpression node) =>
1375 new FunctionExpression(cloneNode(node.typeParameters),
1376 cloneNode(node.parameters), cloneNode(node.body));
1377
1378 @override
1379 FunctionExpressionInvocation visitFunctionExpressionInvocation(
1380 FunctionExpressionInvocation node) =>
1381 new FunctionExpressionInvocation(cloneNode(node.function),
1382 cloneNode(node.typeArguments), cloneNode(node.argumentList));
1383
1384 @override
1385 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
1386 new FunctionTypeAlias(
1387 cloneNode(node.documentationComment),
1388 cloneNodeList(node.metadata),
1389 cloneToken(node.typedefKeyword),
1390 cloneNode(node.returnType),
1391 cloneNode(node.name),
1392 cloneNode(node.typeParameters),
1393 cloneNode(node.parameters),
1394 cloneToken(node.semicolon));
1395
1396 @override
1397 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
1398 FunctionTypedFormalParameter node) =>
1399 new FunctionTypedFormalParameter(
1400 cloneNode(node.documentationComment),
1401 cloneNodeList(node.metadata),
1402 cloneNode(node.returnType),
1403 cloneNode(node.identifier),
1404 cloneNode(node.typeParameters),
1405 cloneNode(node.parameters));
1406
1407 @override
1408 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
1409 cloneToken(node.keyword), cloneNodeList(node.hiddenNames));
1410
1411 @override
1412 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
1413 cloneToken(node.ifKeyword),
1414 cloneToken(node.leftParenthesis),
1415 cloneNode(node.condition),
1416 cloneToken(node.rightParenthesis),
1417 cloneNode(node.thenStatement),
1418 cloneToken(node.elseKeyword),
1419 cloneNode(node.elseStatement));
1420
1421 @override
1422 ImplementsClause visitImplementsClause(ImplementsClause node) =>
1423 new ImplementsClause(
1424 cloneToken(node.implementsKeyword), cloneNodeList(node.interfaces));
1425
1426 @override
1427 ImportDirective visitImportDirective(ImportDirective node) {
1428 ImportDirective directive = new ImportDirective(
1429 cloneNode(node.documentationComment),
1430 cloneNodeList(node.metadata),
1431 cloneToken(node.keyword),
1432 cloneNode(node.uri),
1433 cloneToken(node.deferredKeyword),
1434 cloneToken(node.asKeyword),
1435 cloneNode(node.prefix),
1436 cloneNodeList(node.combinators),
1437 cloneToken(node.semicolon));
1438 directive.source = node.source;
1439 directive.uriContent = node.uriContent;
1440 return directive;
1441 }
1442
1443 @override
1444 IndexExpression visitIndexExpression(IndexExpression node) {
1445 Token period = node.period;
1446 if (period == null) {
1447 return new IndexExpression.forTarget(
1448 cloneNode(node.target),
1449 cloneToken(node.leftBracket),
1450 cloneNode(node.index),
1451 cloneToken(node.rightBracket));
1452 } else {
1453 return new IndexExpression.forCascade(
1454 cloneToken(period),
1455 cloneToken(node.leftBracket),
1456 cloneNode(node.index),
1457 cloneToken(node.rightBracket));
1458 }
1459 }
1460
1461 @override
1462 InstanceCreationExpression visitInstanceCreationExpression(
1463 InstanceCreationExpression node) =>
1464 new InstanceCreationExpression(cloneToken(node.keyword),
1465 cloneNode(node.constructorName), cloneNode(node.argumentList));
1466
1467 @override
1468 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) =>
1469 new IntegerLiteral(cloneToken(node.literal), node.value);
1470
1471 @override
1472 InterpolationExpression visitInterpolationExpression(
1473 InterpolationExpression node) =>
1474 new InterpolationExpression(cloneToken(node.leftBracket),
1475 cloneNode(node.expression), cloneToken(node.rightBracket));
1476
1477 @override
1478 InterpolationString visitInterpolationString(InterpolationString node) =>
1479 new InterpolationString(cloneToken(node.contents), node.value);
1480
1481 @override
1482 IsExpression visitIsExpression(IsExpression node) => new IsExpression(
1483 cloneNode(node.expression),
1484 cloneToken(node.isOperator),
1485 cloneToken(node.notOperator),
1486 cloneNode(node.type));
1487
1488 @override
1489 Label visitLabel(Label node) =>
1490 new Label(cloneNode(node.label), cloneToken(node.colon));
1491
1492 @override
1493 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
1494 new LabeledStatement(
1495 cloneNodeList(node.labels), cloneNode(node.statement));
1496
1497 @override
1498 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
1499 new LibraryDirective(
1500 cloneNode(node.documentationComment),
1501 cloneNodeList(node.metadata),
1502 cloneToken(node.libraryKeyword),
1503 cloneNode(node.name),
1504 cloneToken(node.semicolon));
1505
1506 @override
1507 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) =>
1508 new LibraryIdentifier(cloneNodeList(node.components));
1509
1510 @override
1511 ListLiteral visitListLiteral(ListLiteral node) => new ListLiteral(
1512 cloneToken(node.constKeyword),
1513 cloneNode(node.typeArguments),
1514 cloneToken(node.leftBracket),
1515 cloneNodeList(node.elements),
1516 cloneToken(node.rightBracket));
1517
1518 @override
1519 MapLiteral visitMapLiteral(MapLiteral node) => new MapLiteral(
1520 cloneToken(node.constKeyword),
1521 cloneNode(node.typeArguments),
1522 cloneToken(node.leftBracket),
1523 cloneNodeList(node.entries),
1524 cloneToken(node.rightBracket));
1525
1526 @override
1527 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) =>
1528 new MapLiteralEntry(cloneNode(node.key), cloneToken(node.separator),
1529 cloneNode(node.value));
1530
1531 @override
1532 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
1533 new MethodDeclaration(
1534 cloneNode(node.documentationComment),
1535 cloneNodeList(node.metadata),
1536 cloneToken(node.externalKeyword),
1537 cloneToken(node.modifierKeyword),
1538 cloneNode(node.returnType),
1539 cloneToken(node.propertyKeyword),
1540 cloneToken(node.operatorKeyword),
1541 cloneNode(node.name),
1542 cloneNode(node.typeParameters),
1543 cloneNode(node.parameters),
1544 cloneNode(node.body));
1545
1546 @override
1547 MethodInvocation visitMethodInvocation(MethodInvocation node) =>
1548 new MethodInvocation(
1549 cloneNode(node.target),
1550 cloneToken(node.operator),
1551 cloneNode(node.methodName),
1552 cloneNode(node.typeArguments),
1553 cloneNode(node.argumentList));
1554
1555 @override
1556 NamedExpression visitNamedExpression(NamedExpression node) =>
1557 new NamedExpression(cloneNode(node.name), cloneNode(node.expression));
1558
1559 @override
1560 AstNode visitNativeClause(NativeClause node) =>
1561 new NativeClause(cloneToken(node.nativeKeyword), cloneNode(node.name));
1562
1563 @override
1564 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
1565 new NativeFunctionBody(cloneToken(node.nativeKeyword),
1566 cloneNode(node.stringLiteral), cloneToken(node.semicolon));
1567
1568 @override
1569 NullLiteral visitNullLiteral(NullLiteral node) =>
1570 new NullLiteral(cloneToken(node.literal));
1571
1572 @override
1573 ParenthesizedExpression visitParenthesizedExpression(
1574 ParenthesizedExpression node) =>
1575 new ParenthesizedExpression(cloneToken(node.leftParenthesis),
1576 cloneNode(node.expression), cloneToken(node.rightParenthesis));
1577
1578 @override
1579 PartDirective visitPartDirective(PartDirective node) {
1580 PartDirective directive = new PartDirective(
1581 cloneNode(node.documentationComment),
1582 cloneNodeList(node.metadata),
1583 cloneToken(node.partKeyword),
1584 cloneNode(node.uri),
1585 cloneToken(node.semicolon));
1586 directive.source = node.source;
1587 directive.uriContent = node.uriContent;
1588 return directive;
1589 }
1590
1591 @override
1592 PartOfDirective visitPartOfDirective(PartOfDirective node) =>
1593 new PartOfDirective(
1594 cloneNode(node.documentationComment),
1595 cloneNodeList(node.metadata),
1596 cloneToken(node.partKeyword),
1597 cloneToken(node.ofKeyword),
1598 cloneNode(node.libraryName),
1599 cloneToken(node.semicolon));
1600
1601 @override
1602 PostfixExpression visitPostfixExpression(PostfixExpression node) =>
1603 new PostfixExpression(cloneNode(node.operand), cloneToken(node.operator));
1604
1605 @override
1606 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) =>
1607 new PrefixedIdentifier(cloneNode(node.prefix), cloneToken(node.period),
1608 cloneNode(node.identifier));
1609
1610 @override
1611 PrefixExpression visitPrefixExpression(PrefixExpression node) =>
1612 new PrefixExpression(cloneToken(node.operator), cloneNode(node.operand));
1613
1614 @override
1615 PropertyAccess visitPropertyAccess(PropertyAccess node) => new PropertyAccess(
1616 cloneNode(node.target),
1617 cloneToken(node.operator),
1618 cloneNode(node.propertyName));
1619
1620 @override
1621 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
1622 RedirectingConstructorInvocation node) =>
1623 new RedirectingConstructorInvocation(
1624 cloneToken(node.thisKeyword),
1625 cloneToken(node.period),
1626 cloneNode(node.constructorName),
1627 cloneNode(node.argumentList));
1628
1629 @override
1630 RethrowExpression visitRethrowExpression(RethrowExpression node) =>
1631 new RethrowExpression(cloneToken(node.rethrowKeyword));
1632
1633 @override
1634 ReturnStatement visitReturnStatement(ReturnStatement node) =>
1635 new ReturnStatement(cloneToken(node.returnKeyword),
1636 cloneNode(node.expression), cloneToken(node.semicolon));
1637
1638 @override
1639 ScriptTag visitScriptTag(ScriptTag node) =>
1640 new ScriptTag(cloneToken(node.scriptTag));
1641
1642 @override
1643 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
1644 cloneToken(node.keyword), cloneNodeList(node.shownNames));
1645
1646 @override
1647 SimpleFormalParameter visitSimpleFormalParameter(
1648 SimpleFormalParameter node) =>
1649 new SimpleFormalParameter(
1650 cloneNode(node.documentationComment),
1651 cloneNodeList(node.metadata),
1652 cloneToken(node.keyword),
1653 cloneNode(node.type),
1654 cloneNode(node.identifier));
1655
1656 @override
1657 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) =>
1658 new SimpleIdentifier(cloneToken(node.token));
1659
1660 @override
1661 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) =>
1662 new SimpleStringLiteral(cloneToken(node.literal), node.value);
1663
1664 @override
1665 StringInterpolation visitStringInterpolation(StringInterpolation node) =>
1666 new StringInterpolation(cloneNodeList(node.elements));
1667
1668 @override
1669 SuperConstructorInvocation visitSuperConstructorInvocation(
1670 SuperConstructorInvocation node) =>
1671 new SuperConstructorInvocation(
1672 cloneToken(node.superKeyword),
1673 cloneToken(node.period),
1674 cloneNode(node.constructorName),
1675 cloneNode(node.argumentList));
1676
1677 @override
1678 SuperExpression visitSuperExpression(SuperExpression node) =>
1679 new SuperExpression(cloneToken(node.superKeyword));
1680
1681 @override
1682 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
1683 cloneNodeList(node.labels),
1684 cloneToken(node.keyword),
1685 cloneNode(node.expression),
1686 cloneToken(node.colon),
1687 cloneNodeList(node.statements));
1688
1689 @override
1690 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
1691 cloneNodeList(node.labels),
1692 cloneToken(node.keyword),
1693 cloneToken(node.colon),
1694 cloneNodeList(node.statements));
1695
1696 @override
1697 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
1698 new SwitchStatement(
1699 cloneToken(node.switchKeyword),
1700 cloneToken(node.leftParenthesis),
1701 cloneNode(node.expression),
1702 cloneToken(node.rightParenthesis),
1703 cloneToken(node.leftBracket),
1704 cloneNodeList(node.members),
1705 cloneToken(node.rightBracket));
1706
1707 @override
1708 SymbolLiteral visitSymbolLiteral(SymbolLiteral node) => new SymbolLiteral(
1709 cloneToken(node.poundSign), cloneTokenList(node.components));
1710
1711 @override
1712 ThisExpression visitThisExpression(ThisExpression node) =>
1713 new ThisExpression(cloneToken(node.thisKeyword));
1714
1715 @override
1716 ThrowExpression visitThrowExpression(ThrowExpression node) =>
1717 new ThrowExpression(
1718 cloneToken(node.throwKeyword), cloneNode(node.expression));
1719
1720 @override
1721 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
1722 TopLevelVariableDeclaration node) =>
1723 new TopLevelVariableDeclaration(
1724 cloneNode(node.documentationComment),
1725 cloneNodeList(node.metadata),
1726 cloneNode(node.variables),
1727 cloneToken(node.semicolon));
1728
1729 @override
1730 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
1731 cloneToken(node.tryKeyword),
1732 cloneNode(node.body),
1733 cloneNodeList(node.catchClauses),
1734 cloneToken(node.finallyKeyword),
1735 cloneNode(node.finallyBlock));
1736
1737 @override
1738 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
1739 new TypeArgumentList(cloneToken(node.leftBracket),
1740 cloneNodeList(node.arguments), cloneToken(node.rightBracket));
1741
1742 @override
1743 TypeName visitTypeName(TypeName node) =>
1744 new TypeName(cloneNode(node.name), cloneNode(node.typeArguments));
1745
1746 @override
1747 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
1748 cloneNode(node.documentationComment),
1749 cloneNodeList(node.metadata),
1750 cloneNode(node.name),
1751 cloneToken(node.extendsKeyword),
1752 cloneNode(node.bound));
1753
1754 @override
1755 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
1756 new TypeParameterList(cloneToken(node.leftBracket),
1757 cloneNodeList(node.typeParameters), cloneToken(node.rightBracket));
1758
1759 @override
1760 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
1761 new VariableDeclaration(cloneNode(node.name), cloneToken(node.equals),
1762 cloneNode(node.initializer));
1763
1764 @override
1765 VariableDeclarationList visitVariableDeclarationList(
1766 VariableDeclarationList node) =>
1767 new VariableDeclarationList(
1768 cloneNode(node.documentationComment),
1769 cloneNodeList(node.metadata),
1770 cloneToken(node.keyword),
1771 cloneNode(node.type),
1772 cloneNodeList(node.variables));
1773
1774 @override
1775 VariableDeclarationStatement visitVariableDeclarationStatement(
1776 VariableDeclarationStatement node) =>
1777 new VariableDeclarationStatement(
1778 cloneNode(node.variables), cloneToken(node.semicolon));
1779
1780 @override
1781 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
1782 cloneToken(node.whileKeyword),
1783 cloneToken(node.leftParenthesis),
1784 cloneNode(node.condition),
1785 cloneToken(node.rightParenthesis),
1786 cloneNode(node.body));
1787
1788 @override
1789 WithClause visitWithClause(WithClause node) => new WithClause(
1790 cloneToken(node.withKeyword), cloneNodeList(node.mixinTypes));
1791
1792 @override
1793 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
1794 cloneToken(node.yieldKeyword),
1795 cloneToken(node.star),
1796 cloneNode(node.expression),
1797 cloneToken(node.semicolon));
1798
1799 /**
1800 * Return a clone of the given [node].
1801 */
1802 static AstNode clone(AstNode node) {
1803 return node.accept(new AstCloner());
1804 }
1805 }
1806
1807 /**
1808 * An AstVisitor that compares the structure of two AstNodes to see whether they
1809 * are equal.
1810 */
1811 class AstComparator implements AstVisitor<bool> {
1812 /**
1813 * The AST node with which the node being visited is to be compared. This is
1814 * only valid at the beginning of each visit method (until [isEqualNodes] is
1815 * invoked).
1816 */
1817 AstNode _other;
1818
1819 /**
1820 * Return `true` if the [first] node and the [second] node have the same
1821 * structure.
1822 *
1823 * *Note:* This method is only visible for testing purposes and should not be
1824 * used by clients.
1825 */
1826 bool isEqualNodes(AstNode first, AstNode second) {
1827 if (first == null) {
1828 return second == null;
1829 } else if (second == null) {
1830 return false;
1831 } else if (first.runtimeType != second.runtimeType) {
1832 return false;
1833 }
1834 _other = second;
1835 return first.accept(this);
1836 }
1837
1838 /**
1839 * Return `true` if the [first] token and the [second] token have the same
1840 * structure.
1841 *
1842 * *Note:* This method is only visible for testing purposes and should not be
1843 * used by clients.
1844 */
1845 bool isEqualTokens(Token first, Token second) {
1846 if (first == null) {
1847 return second == null;
1848 } else if (second == null) {
1849 return false;
1850 } else if (identical(first, second)) {
1851 return true;
1852 }
1853 return first.offset == second.offset &&
1854 first.length == second.length &&
1855 first.lexeme == second.lexeme;
1856 }
1857
1858 @override
1859 bool visitAdjacentStrings(AdjacentStrings node) {
1860 AdjacentStrings other = _other as AdjacentStrings;
1861 return _isEqualNodeLists(node.strings, other.strings);
1862 }
1863
1864 @override
1865 bool visitAnnotation(Annotation node) {
1866 Annotation other = _other as Annotation;
1867 return isEqualTokens(node.atSign, other.atSign) &&
1868 isEqualNodes(node.name, other.name) &&
1869 isEqualTokens(node.period, other.period) &&
1870 isEqualNodes(node.constructorName, other.constructorName) &&
1871 isEqualNodes(node.arguments, other.arguments);
1872 }
1873
1874 @override
1875 bool visitArgumentList(ArgumentList node) {
1876 ArgumentList other = _other as ArgumentList;
1877 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1878 _isEqualNodeLists(node.arguments, other.arguments) &&
1879 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
1880 }
1881
1882 @override
1883 bool visitAsExpression(AsExpression node) {
1884 AsExpression other = _other as AsExpression;
1885 return isEqualNodes(node.expression, other.expression) &&
1886 isEqualTokens(node.asOperator, other.asOperator) &&
1887 isEqualNodes(node.type, other.type);
1888 }
1889
1890 @override
1891 bool visitAssertStatement(AssertStatement node) {
1892 AssertStatement other = _other as AssertStatement;
1893 return isEqualTokens(node.assertKeyword, other.assertKeyword) &&
1894 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1895 isEqualNodes(node.condition, other.condition) &&
1896 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1897 isEqualTokens(node.semicolon, other.semicolon);
1898 }
1899
1900 @override
1901 bool visitAssignmentExpression(AssignmentExpression node) {
1902 AssignmentExpression other = _other as AssignmentExpression;
1903 return isEqualNodes(node.leftHandSide, other.leftHandSide) &&
1904 isEqualTokens(node.operator, other.operator) &&
1905 isEqualNodes(node.rightHandSide, other.rightHandSide);
1906 }
1907
1908 @override
1909 bool visitAwaitExpression(AwaitExpression node) {
1910 AwaitExpression other = _other as AwaitExpression;
1911 return isEqualTokens(node.awaitKeyword, other.awaitKeyword) &&
1912 isEqualNodes(node.expression, other.expression);
1913 }
1914
1915 @override
1916 bool visitBinaryExpression(BinaryExpression node) {
1917 BinaryExpression other = _other as BinaryExpression;
1918 return isEqualNodes(node.leftOperand, other.leftOperand) &&
1919 isEqualTokens(node.operator, other.operator) &&
1920 isEqualNodes(node.rightOperand, other.rightOperand);
1921 }
1922
1923 @override
1924 bool visitBlock(Block node) {
1925 Block other = _other as Block;
1926 return isEqualTokens(node.leftBracket, other.leftBracket) &&
1927 _isEqualNodeLists(node.statements, other.statements) &&
1928 isEqualTokens(node.rightBracket, other.rightBracket);
1929 }
1930
1931 @override
1932 bool visitBlockFunctionBody(BlockFunctionBody node) {
1933 BlockFunctionBody other = _other as BlockFunctionBody;
1934 return isEqualNodes(node.block, other.block);
1935 }
1936
1937 @override
1938 bool visitBooleanLiteral(BooleanLiteral node) {
1939 BooleanLiteral other = _other as BooleanLiteral;
1940 return isEqualTokens(node.literal, other.literal) &&
1941 node.value == other.value;
1942 }
1943
1944 @override
1945 bool visitBreakStatement(BreakStatement node) {
1946 BreakStatement other = _other as BreakStatement;
1947 return isEqualTokens(node.breakKeyword, other.breakKeyword) &&
1948 isEqualNodes(node.label, other.label) &&
1949 isEqualTokens(node.semicolon, other.semicolon);
1950 }
1951
1952 @override
1953 bool visitCascadeExpression(CascadeExpression node) {
1954 CascadeExpression other = _other as CascadeExpression;
1955 return isEqualNodes(node.target, other.target) &&
1956 _isEqualNodeLists(node.cascadeSections, other.cascadeSections);
1957 }
1958
1959 @override
1960 bool visitCatchClause(CatchClause node) {
1961 CatchClause other = _other as CatchClause;
1962 return isEqualTokens(node.onKeyword, other.onKeyword) &&
1963 isEqualNodes(node.exceptionType, other.exceptionType) &&
1964 isEqualTokens(node.catchKeyword, other.catchKeyword) &&
1965 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1966 isEqualNodes(node.exceptionParameter, other.exceptionParameter) &&
1967 isEqualTokens(node.comma, other.comma) &&
1968 isEqualNodes(node.stackTraceParameter, other.stackTraceParameter) &&
1969 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1970 isEqualNodes(node.body, other.body);
1971 }
1972
1973 @override
1974 bool visitClassDeclaration(ClassDeclaration node) {
1975 ClassDeclaration other = _other as ClassDeclaration;
1976 return isEqualNodes(
1977 node.documentationComment, other.documentationComment) &&
1978 _isEqualNodeLists(node.metadata, other.metadata) &&
1979 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
1980 isEqualTokens(node.classKeyword, other.classKeyword) &&
1981 isEqualNodes(node.name, other.name) &&
1982 isEqualNodes(node.typeParameters, other.typeParameters) &&
1983 isEqualNodes(node.extendsClause, other.extendsClause) &&
1984 isEqualNodes(node.withClause, other.withClause) &&
1985 isEqualNodes(node.implementsClause, other.implementsClause) &&
1986 isEqualTokens(node.leftBracket, other.leftBracket) &&
1987 _isEqualNodeLists(node.members, other.members) &&
1988 isEqualTokens(node.rightBracket, other.rightBracket);
1989 }
1990
1991 @override
1992 bool visitClassTypeAlias(ClassTypeAlias node) {
1993 ClassTypeAlias other = _other as ClassTypeAlias;
1994 return isEqualNodes(
1995 node.documentationComment, other.documentationComment) &&
1996 _isEqualNodeLists(node.metadata, other.metadata) &&
1997 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
1998 isEqualNodes(node.name, other.name) &&
1999 isEqualNodes(node.typeParameters, other.typeParameters) &&
2000 isEqualTokens(node.equals, other.equals) &&
2001 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
2002 isEqualNodes(node.superclass, other.superclass) &&
2003 isEqualNodes(node.withClause, other.withClause) &&
2004 isEqualNodes(node.implementsClause, other.implementsClause) &&
2005 isEqualTokens(node.semicolon, other.semicolon);
2006 }
2007
2008 @override
2009 bool visitComment(Comment node) {
2010 Comment other = _other as Comment;
2011 return _isEqualNodeLists(node.references, other.references);
2012 }
2013
2014 @override
2015 bool visitCommentReference(CommentReference node) {
2016 CommentReference other = _other as CommentReference;
2017 return isEqualTokens(node.newKeyword, other.newKeyword) &&
2018 isEqualNodes(node.identifier, other.identifier);
2019 }
2020
2021 @override
2022 bool visitCompilationUnit(CompilationUnit node) {
2023 CompilationUnit other = _other as CompilationUnit;
2024 return isEqualTokens(node.beginToken, other.beginToken) &&
2025 isEqualNodes(node.scriptTag, other.scriptTag) &&
2026 _isEqualNodeLists(node.directives, other.directives) &&
2027 _isEqualNodeLists(node.declarations, other.declarations) &&
2028 isEqualTokens(node.endToken, other.endToken);
2029 }
2030
2031 @override
2032 bool visitConditionalExpression(ConditionalExpression node) {
2033 ConditionalExpression other = _other as ConditionalExpression;
2034 return isEqualNodes(node.condition, other.condition) &&
2035 isEqualTokens(node.question, other.question) &&
2036 isEqualNodes(node.thenExpression, other.thenExpression) &&
2037 isEqualTokens(node.colon, other.colon) &&
2038 isEqualNodes(node.elseExpression, other.elseExpression);
2039 }
2040
2041 @override
2042 bool visitConstructorDeclaration(ConstructorDeclaration node) {
2043 ConstructorDeclaration other = _other as ConstructorDeclaration;
2044 return isEqualNodes(
2045 node.documentationComment, other.documentationComment) &&
2046 _isEqualNodeLists(node.metadata, other.metadata) &&
2047 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2048 isEqualTokens(node.constKeyword, other.constKeyword) &&
2049 isEqualTokens(node.factoryKeyword, other.factoryKeyword) &&
2050 isEqualNodes(node.returnType, other.returnType) &&
2051 isEqualTokens(node.period, other.period) &&
2052 isEqualNodes(node.name, other.name) &&
2053 isEqualNodes(node.parameters, other.parameters) &&
2054 isEqualTokens(node.separator, other.separator) &&
2055 _isEqualNodeLists(node.initializers, other.initializers) &&
2056 isEqualNodes(node.redirectedConstructor, other.redirectedConstructor) &&
2057 isEqualNodes(node.body, other.body);
2058 }
2059
2060 @override
2061 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
2062 ConstructorFieldInitializer other = _other as ConstructorFieldInitializer;
2063 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2064 isEqualTokens(node.period, other.period) &&
2065 isEqualNodes(node.fieldName, other.fieldName) &&
2066 isEqualTokens(node.equals, other.equals) &&
2067 isEqualNodes(node.expression, other.expression);
2068 }
2069
2070 @override
2071 bool visitConstructorName(ConstructorName node) {
2072 ConstructorName other = _other as ConstructorName;
2073 return isEqualNodes(node.type, other.type) &&
2074 isEqualTokens(node.period, other.period) &&
2075 isEqualNodes(node.name, other.name);
2076 }
2077
2078 @override
2079 bool visitContinueStatement(ContinueStatement node) {
2080 ContinueStatement other = _other as ContinueStatement;
2081 return isEqualTokens(node.continueKeyword, other.continueKeyword) &&
2082 isEqualNodes(node.label, other.label) &&
2083 isEqualTokens(node.semicolon, other.semicolon);
2084 }
2085
2086 @override
2087 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
2088 DeclaredIdentifier other = _other as DeclaredIdentifier;
2089 return isEqualNodes(
2090 node.documentationComment, other.documentationComment) &&
2091 _isEqualNodeLists(node.metadata, other.metadata) &&
2092 isEqualTokens(node.keyword, other.keyword) &&
2093 isEqualNodes(node.type, other.type) &&
2094 isEqualNodes(node.identifier, other.identifier);
2095 }
2096
2097 @override
2098 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
2099 DefaultFormalParameter other = _other as DefaultFormalParameter;
2100 return isEqualNodes(node.parameter, other.parameter) &&
2101 node.kind == other.kind &&
2102 isEqualTokens(node.separator, other.separator) &&
2103 isEqualNodes(node.defaultValue, other.defaultValue);
2104 }
2105
2106 @override
2107 bool visitDoStatement(DoStatement node) {
2108 DoStatement other = _other as DoStatement;
2109 return isEqualTokens(node.doKeyword, other.doKeyword) &&
2110 isEqualNodes(node.body, other.body) &&
2111 isEqualTokens(node.whileKeyword, other.whileKeyword) &&
2112 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2113 isEqualNodes(node.condition, other.condition) &&
2114 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2115 isEqualTokens(node.semicolon, other.semicolon);
2116 }
2117
2118 @override
2119 bool visitDoubleLiteral(DoubleLiteral node) {
2120 DoubleLiteral other = _other as DoubleLiteral;
2121 return isEqualTokens(node.literal, other.literal) &&
2122 node.value == other.value;
2123 }
2124
2125 @override
2126 bool visitEmptyFunctionBody(EmptyFunctionBody node) {
2127 EmptyFunctionBody other = _other as EmptyFunctionBody;
2128 return isEqualTokens(node.semicolon, other.semicolon);
2129 }
2130
2131 @override
2132 bool visitEmptyStatement(EmptyStatement node) {
2133 EmptyStatement other = _other as EmptyStatement;
2134 return isEqualTokens(node.semicolon, other.semicolon);
2135 }
2136
2137 @override
2138 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
2139 EnumConstantDeclaration other = _other as EnumConstantDeclaration;
2140 return isEqualNodes(
2141 node.documentationComment, other.documentationComment) &&
2142 _isEqualNodeLists(node.metadata, other.metadata) &&
2143 isEqualNodes(node.name, other.name);
2144 }
2145
2146 @override
2147 bool visitEnumDeclaration(EnumDeclaration node) {
2148 EnumDeclaration other = _other as EnumDeclaration;
2149 return isEqualNodes(
2150 node.documentationComment, other.documentationComment) &&
2151 _isEqualNodeLists(node.metadata, other.metadata) &&
2152 isEqualTokens(node.enumKeyword, other.enumKeyword) &&
2153 isEqualNodes(node.name, other.name) &&
2154 isEqualTokens(node.leftBracket, other.leftBracket) &&
2155 _isEqualNodeLists(node.constants, other.constants) &&
2156 isEqualTokens(node.rightBracket, other.rightBracket);
2157 }
2158
2159 @override
2160 bool visitExportDirective(ExportDirective node) {
2161 ExportDirective other = _other as ExportDirective;
2162 return isEqualNodes(
2163 node.documentationComment, other.documentationComment) &&
2164 _isEqualNodeLists(node.metadata, other.metadata) &&
2165 isEqualTokens(node.keyword, other.keyword) &&
2166 isEqualNodes(node.uri, other.uri) &&
2167 _isEqualNodeLists(node.combinators, other.combinators) &&
2168 isEqualTokens(node.semicolon, other.semicolon);
2169 }
2170
2171 @override
2172 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
2173 ExpressionFunctionBody other = _other as ExpressionFunctionBody;
2174 return isEqualTokens(node.functionDefinition, other.functionDefinition) &&
2175 isEqualNodes(node.expression, other.expression) &&
2176 isEqualTokens(node.semicolon, other.semicolon);
2177 }
2178
2179 @override
2180 bool visitExpressionStatement(ExpressionStatement node) {
2181 ExpressionStatement other = _other as ExpressionStatement;
2182 return isEqualNodes(node.expression, other.expression) &&
2183 isEqualTokens(node.semicolon, other.semicolon);
2184 }
2185
2186 @override
2187 bool visitExtendsClause(ExtendsClause node) {
2188 ExtendsClause other = _other as ExtendsClause;
2189 return isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2190 isEqualNodes(node.superclass, other.superclass);
2191 }
2192
2193 @override
2194 bool visitFieldDeclaration(FieldDeclaration node) {
2195 FieldDeclaration other = _other as FieldDeclaration;
2196 return isEqualNodes(
2197 node.documentationComment, other.documentationComment) &&
2198 _isEqualNodeLists(node.metadata, other.metadata) &&
2199 isEqualTokens(node.staticKeyword, other.staticKeyword) &&
2200 isEqualNodes(node.fields, other.fields) &&
2201 isEqualTokens(node.semicolon, other.semicolon);
2202 }
2203
2204 @override
2205 bool visitFieldFormalParameter(FieldFormalParameter node) {
2206 FieldFormalParameter other = _other as FieldFormalParameter;
2207 return isEqualNodes(
2208 node.documentationComment, other.documentationComment) &&
2209 _isEqualNodeLists(node.metadata, other.metadata) &&
2210 isEqualTokens(node.keyword, other.keyword) &&
2211 isEqualNodes(node.type, other.type) &&
2212 isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2213 isEqualTokens(node.period, other.period) &&
2214 isEqualNodes(node.identifier, other.identifier);
2215 }
2216
2217 @override
2218 bool visitForEachStatement(ForEachStatement node) {
2219 ForEachStatement other = _other as ForEachStatement;
2220 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2221 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2222 isEqualNodes(node.loopVariable, other.loopVariable) &&
2223 isEqualTokens(node.inKeyword, other.inKeyword) &&
2224 isEqualNodes(node.iterable, other.iterable) &&
2225 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2226 isEqualNodes(node.body, other.body);
2227 }
2228
2229 @override
2230 bool visitFormalParameterList(FormalParameterList node) {
2231 FormalParameterList other = _other as FormalParameterList;
2232 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2233 _isEqualNodeLists(node.parameters, other.parameters) &&
2234 isEqualTokens(node.leftDelimiter, other.leftDelimiter) &&
2235 isEqualTokens(node.rightDelimiter, other.rightDelimiter) &&
2236 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2237 }
2238
2239 @override
2240 bool visitForStatement(ForStatement node) {
2241 ForStatement other = _other as ForStatement;
2242 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2243 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2244 isEqualNodes(node.variables, other.variables) &&
2245 isEqualNodes(node.initialization, other.initialization) &&
2246 isEqualTokens(node.leftSeparator, other.leftSeparator) &&
2247 isEqualNodes(node.condition, other.condition) &&
2248 isEqualTokens(node.rightSeparator, other.rightSeparator) &&
2249 _isEqualNodeLists(node.updaters, other.updaters) &&
2250 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2251 isEqualNodes(node.body, other.body);
2252 }
2253
2254 @override
2255 bool visitFunctionDeclaration(FunctionDeclaration node) {
2256 FunctionDeclaration other = _other as FunctionDeclaration;
2257 return isEqualNodes(
2258 node.documentationComment, other.documentationComment) &&
2259 _isEqualNodeLists(node.metadata, other.metadata) &&
2260 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2261 isEqualNodes(node.returnType, other.returnType) &&
2262 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2263 isEqualNodes(node.name, other.name) &&
2264 isEqualNodes(node.functionExpression, other.functionExpression);
2265 }
2266
2267 @override
2268 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
2269 FunctionDeclarationStatement other = _other as FunctionDeclarationStatement;
2270 return isEqualNodes(node.functionDeclaration, other.functionDeclaration);
2271 }
2272
2273 @override
2274 bool visitFunctionExpression(FunctionExpression node) {
2275 FunctionExpression other = _other as FunctionExpression;
2276 return isEqualNodes(node.parameters, other.parameters) &&
2277 isEqualNodes(node.body, other.body);
2278 }
2279
2280 @override
2281 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
2282 FunctionExpressionInvocation other = _other as FunctionExpressionInvocation;
2283 return isEqualNodes(node.function, other.function) &&
2284 isEqualNodes(node.argumentList, other.argumentList);
2285 }
2286
2287 @override
2288 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
2289 FunctionTypeAlias other = _other as FunctionTypeAlias;
2290 return isEqualNodes(
2291 node.documentationComment, other.documentationComment) &&
2292 _isEqualNodeLists(node.metadata, other.metadata) &&
2293 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
2294 isEqualNodes(node.returnType, other.returnType) &&
2295 isEqualNodes(node.name, other.name) &&
2296 isEqualNodes(node.typeParameters, other.typeParameters) &&
2297 isEqualNodes(node.parameters, other.parameters) &&
2298 isEqualTokens(node.semicolon, other.semicolon);
2299 }
2300
2301 @override
2302 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2303 FunctionTypedFormalParameter other = _other as FunctionTypedFormalParameter;
2304 return isEqualNodes(
2305 node.documentationComment, other.documentationComment) &&
2306 _isEqualNodeLists(node.metadata, other.metadata) &&
2307 isEqualNodes(node.returnType, other.returnType) &&
2308 isEqualNodes(node.identifier, other.identifier) &&
2309 isEqualNodes(node.parameters, other.parameters);
2310 }
2311
2312 @override
2313 bool visitHideCombinator(HideCombinator node) {
2314 HideCombinator other = _other as HideCombinator;
2315 return isEqualTokens(node.keyword, other.keyword) &&
2316 _isEqualNodeLists(node.hiddenNames, other.hiddenNames);
2317 }
2318
2319 @override
2320 bool visitIfStatement(IfStatement node) {
2321 IfStatement other = _other as IfStatement;
2322 return isEqualTokens(node.ifKeyword, other.ifKeyword) &&
2323 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2324 isEqualNodes(node.condition, other.condition) &&
2325 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2326 isEqualNodes(node.thenStatement, other.thenStatement) &&
2327 isEqualTokens(node.elseKeyword, other.elseKeyword) &&
2328 isEqualNodes(node.elseStatement, other.elseStatement);
2329 }
2330
2331 @override
2332 bool visitImplementsClause(ImplementsClause node) {
2333 ImplementsClause other = _other as ImplementsClause;
2334 return isEqualTokens(node.implementsKeyword, other.implementsKeyword) &&
2335 _isEqualNodeLists(node.interfaces, other.interfaces);
2336 }
2337
2338 @override
2339 bool visitImportDirective(ImportDirective node) {
2340 ImportDirective other = _other as ImportDirective;
2341 return isEqualNodes(
2342 node.documentationComment, other.documentationComment) &&
2343 _isEqualNodeLists(node.metadata, other.metadata) &&
2344 isEqualTokens(node.keyword, other.keyword) &&
2345 isEqualNodes(node.uri, other.uri) &&
2346 isEqualTokens(node.deferredKeyword, other.deferredKeyword) &&
2347 isEqualTokens(node.asKeyword, other.asKeyword) &&
2348 isEqualNodes(node.prefix, other.prefix) &&
2349 _isEqualNodeLists(node.combinators, other.combinators) &&
2350 isEqualTokens(node.semicolon, other.semicolon);
2351 }
2352
2353 @override
2354 bool visitIndexExpression(IndexExpression node) {
2355 IndexExpression other = _other as IndexExpression;
2356 return isEqualNodes(node.target, other.target) &&
2357 isEqualTokens(node.leftBracket, other.leftBracket) &&
2358 isEqualNodes(node.index, other.index) &&
2359 isEqualTokens(node.rightBracket, other.rightBracket);
2360 }
2361
2362 @override
2363 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
2364 InstanceCreationExpression other = _other as InstanceCreationExpression;
2365 return isEqualTokens(node.keyword, other.keyword) &&
2366 isEqualNodes(node.constructorName, other.constructorName) &&
2367 isEqualNodes(node.argumentList, other.argumentList);
2368 }
2369
2370 @override
2371 bool visitIntegerLiteral(IntegerLiteral node) {
2372 IntegerLiteral other = _other as IntegerLiteral;
2373 return isEqualTokens(node.literal, other.literal) &&
2374 (node.value == other.value);
2375 }
2376
2377 @override
2378 bool visitInterpolationExpression(InterpolationExpression node) {
2379 InterpolationExpression other = _other as InterpolationExpression;
2380 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2381 isEqualNodes(node.expression, other.expression) &&
2382 isEqualTokens(node.rightBracket, other.rightBracket);
2383 }
2384
2385 @override
2386 bool visitInterpolationString(InterpolationString node) {
2387 InterpolationString other = _other as InterpolationString;
2388 return isEqualTokens(node.contents, other.contents) &&
2389 node.value == other.value;
2390 }
2391
2392 @override
2393 bool visitIsExpression(IsExpression node) {
2394 IsExpression other = _other as IsExpression;
2395 return isEqualNodes(node.expression, other.expression) &&
2396 isEqualTokens(node.isOperator, other.isOperator) &&
2397 isEqualTokens(node.notOperator, other.notOperator) &&
2398 isEqualNodes(node.type, other.type);
2399 }
2400
2401 @override
2402 bool visitLabel(Label node) {
2403 Label other = _other as Label;
2404 return isEqualNodes(node.label, other.label) &&
2405 isEqualTokens(node.colon, other.colon);
2406 }
2407
2408 @override
2409 bool visitLabeledStatement(LabeledStatement node) {
2410 LabeledStatement other = _other as LabeledStatement;
2411 return _isEqualNodeLists(node.labels, other.labels) &&
2412 isEqualNodes(node.statement, other.statement);
2413 }
2414
2415 @override
2416 bool visitLibraryDirective(LibraryDirective node) {
2417 LibraryDirective other = _other as LibraryDirective;
2418 return isEqualNodes(
2419 node.documentationComment, other.documentationComment) &&
2420 _isEqualNodeLists(node.metadata, other.metadata) &&
2421 isEqualTokens(node.libraryKeyword, other.libraryKeyword) &&
2422 isEqualNodes(node.name, other.name) &&
2423 isEqualTokens(node.semicolon, other.semicolon);
2424 }
2425
2426 @override
2427 bool visitLibraryIdentifier(LibraryIdentifier node) {
2428 LibraryIdentifier other = _other as LibraryIdentifier;
2429 return _isEqualNodeLists(node.components, other.components);
2430 }
2431
2432 @override
2433 bool visitListLiteral(ListLiteral node) {
2434 ListLiteral other = _other as ListLiteral;
2435 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2436 isEqualNodes(node.typeArguments, other.typeArguments) &&
2437 isEqualTokens(node.leftBracket, other.leftBracket) &&
2438 _isEqualNodeLists(node.elements, other.elements) &&
2439 isEqualTokens(node.rightBracket, other.rightBracket);
2440 }
2441
2442 @override
2443 bool visitMapLiteral(MapLiteral node) {
2444 MapLiteral other = _other as MapLiteral;
2445 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2446 isEqualNodes(node.typeArguments, other.typeArguments) &&
2447 isEqualTokens(node.leftBracket, other.leftBracket) &&
2448 _isEqualNodeLists(node.entries, other.entries) &&
2449 isEqualTokens(node.rightBracket, other.rightBracket);
2450 }
2451
2452 @override
2453 bool visitMapLiteralEntry(MapLiteralEntry node) {
2454 MapLiteralEntry other = _other as MapLiteralEntry;
2455 return isEqualNodes(node.key, other.key) &&
2456 isEqualTokens(node.separator, other.separator) &&
2457 isEqualNodes(node.value, other.value);
2458 }
2459
2460 @override
2461 bool visitMethodDeclaration(MethodDeclaration node) {
2462 MethodDeclaration other = _other as MethodDeclaration;
2463 return isEqualNodes(
2464 node.documentationComment, other.documentationComment) &&
2465 _isEqualNodeLists(node.metadata, other.metadata) &&
2466 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2467 isEqualTokens(node.modifierKeyword, other.modifierKeyword) &&
2468 isEqualNodes(node.returnType, other.returnType) &&
2469 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2470 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2471 isEqualNodes(node.name, other.name) &&
2472 isEqualNodes(node.parameters, other.parameters) &&
2473 isEqualNodes(node.body, other.body);
2474 }
2475
2476 @override
2477 bool visitMethodInvocation(MethodInvocation node) {
2478 MethodInvocation other = _other as MethodInvocation;
2479 return isEqualNodes(node.target, other.target) &&
2480 isEqualTokens(node.operator, other.operator) &&
2481 isEqualNodes(node.methodName, other.methodName) &&
2482 isEqualNodes(node.argumentList, other.argumentList);
2483 }
2484
2485 @override
2486 bool visitNamedExpression(NamedExpression node) {
2487 NamedExpression other = _other as NamedExpression;
2488 return isEqualNodes(node.name, other.name) &&
2489 isEqualNodes(node.expression, other.expression);
2490 }
2491
2492 @override
2493 bool visitNativeClause(NativeClause node) {
2494 NativeClause other = _other as NativeClause;
2495 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2496 isEqualNodes(node.name, other.name);
2497 }
2498
2499 @override
2500 bool visitNativeFunctionBody(NativeFunctionBody node) {
2501 NativeFunctionBody other = _other as NativeFunctionBody;
2502 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2503 isEqualNodes(node.stringLiteral, other.stringLiteral) &&
2504 isEqualTokens(node.semicolon, other.semicolon);
2505 }
2506
2507 @override
2508 bool visitNullLiteral(NullLiteral node) {
2509 NullLiteral other = _other as NullLiteral;
2510 return isEqualTokens(node.literal, other.literal);
2511 }
2512
2513 @override
2514 bool visitParenthesizedExpression(ParenthesizedExpression node) {
2515 ParenthesizedExpression other = _other as ParenthesizedExpression;
2516 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2517 isEqualNodes(node.expression, other.expression) &&
2518 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2519 }
2520
2521 @override
2522 bool visitPartDirective(PartDirective node) {
2523 PartDirective other = _other as PartDirective;
2524 return isEqualNodes(
2525 node.documentationComment, other.documentationComment) &&
2526 _isEqualNodeLists(node.metadata, other.metadata) &&
2527 isEqualTokens(node.partKeyword, other.partKeyword) &&
2528 isEqualNodes(node.uri, other.uri) &&
2529 isEqualTokens(node.semicolon, other.semicolon);
2530 }
2531
2532 @override
2533 bool visitPartOfDirective(PartOfDirective node) {
2534 PartOfDirective other = _other as PartOfDirective;
2535 return isEqualNodes(
2536 node.documentationComment, other.documentationComment) &&
2537 _isEqualNodeLists(node.metadata, other.metadata) &&
2538 isEqualTokens(node.partKeyword, other.partKeyword) &&
2539 isEqualTokens(node.ofKeyword, other.ofKeyword) &&
2540 isEqualNodes(node.libraryName, other.libraryName) &&
2541 isEqualTokens(node.semicolon, other.semicolon);
2542 }
2543
2544 @override
2545 bool visitPostfixExpression(PostfixExpression node) {
2546 PostfixExpression other = _other as PostfixExpression;
2547 return isEqualNodes(node.operand, other.operand) &&
2548 isEqualTokens(node.operator, other.operator);
2549 }
2550
2551 @override
2552 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
2553 PrefixedIdentifier other = _other as PrefixedIdentifier;
2554 return isEqualNodes(node.prefix, other.prefix) &&
2555 isEqualTokens(node.period, other.period) &&
2556 isEqualNodes(node.identifier, other.identifier);
2557 }
2558
2559 @override
2560 bool visitPrefixExpression(PrefixExpression node) {
2561 PrefixExpression other = _other as PrefixExpression;
2562 return isEqualTokens(node.operator, other.operator) &&
2563 isEqualNodes(node.operand, other.operand);
2564 }
2565
2566 @override
2567 bool visitPropertyAccess(PropertyAccess node) {
2568 PropertyAccess other = _other as PropertyAccess;
2569 return isEqualNodes(node.target, other.target) &&
2570 isEqualTokens(node.operator, other.operator) &&
2571 isEqualNodes(node.propertyName, other.propertyName);
2572 }
2573
2574 @override
2575 bool visitRedirectingConstructorInvocation(
2576 RedirectingConstructorInvocation node) {
2577 RedirectingConstructorInvocation other =
2578 _other as RedirectingConstructorInvocation;
2579 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2580 isEqualTokens(node.period, other.period) &&
2581 isEqualNodes(node.constructorName, other.constructorName) &&
2582 isEqualNodes(node.argumentList, other.argumentList);
2583 }
2584
2585 @override
2586 bool visitRethrowExpression(RethrowExpression node) {
2587 RethrowExpression other = _other as RethrowExpression;
2588 return isEqualTokens(node.rethrowKeyword, other.rethrowKeyword);
2589 }
2590
2591 @override
2592 bool visitReturnStatement(ReturnStatement node) {
2593 ReturnStatement other = _other as ReturnStatement;
2594 return isEqualTokens(node.returnKeyword, other.returnKeyword) &&
2595 isEqualNodes(node.expression, other.expression) &&
2596 isEqualTokens(node.semicolon, other.semicolon);
2597 }
2598
2599 @override
2600 bool visitScriptTag(ScriptTag node) {
2601 ScriptTag other = _other as ScriptTag;
2602 return isEqualTokens(node.scriptTag, other.scriptTag);
2603 }
2604
2605 @override
2606 bool visitShowCombinator(ShowCombinator node) {
2607 ShowCombinator other = _other as ShowCombinator;
2608 return isEqualTokens(node.keyword, other.keyword) &&
2609 _isEqualNodeLists(node.shownNames, other.shownNames);
2610 }
2611
2612 @override
2613 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
2614 SimpleFormalParameter other = _other as SimpleFormalParameter;
2615 return isEqualNodes(
2616 node.documentationComment, other.documentationComment) &&
2617 _isEqualNodeLists(node.metadata, other.metadata) &&
2618 isEqualTokens(node.keyword, other.keyword) &&
2619 isEqualNodes(node.type, other.type) &&
2620 isEqualNodes(node.identifier, other.identifier);
2621 }
2622
2623 @override
2624 bool visitSimpleIdentifier(SimpleIdentifier node) {
2625 SimpleIdentifier other = _other as SimpleIdentifier;
2626 return isEqualTokens(node.token, other.token);
2627 }
2628
2629 @override
2630 bool visitSimpleStringLiteral(SimpleStringLiteral node) {
2631 SimpleStringLiteral other = _other as SimpleStringLiteral;
2632 return isEqualTokens(node.literal, other.literal) &&
2633 (node.value == other.value);
2634 }
2635
2636 @override
2637 bool visitStringInterpolation(StringInterpolation node) {
2638 StringInterpolation other = _other as StringInterpolation;
2639 return _isEqualNodeLists(node.elements, other.elements);
2640 }
2641
2642 @override
2643 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2644 SuperConstructorInvocation other = _other as SuperConstructorInvocation;
2645 return isEqualTokens(node.superKeyword, other.superKeyword) &&
2646 isEqualTokens(node.period, other.period) &&
2647 isEqualNodes(node.constructorName, other.constructorName) &&
2648 isEqualNodes(node.argumentList, other.argumentList);
2649 }
2650
2651 @override
2652 bool visitSuperExpression(SuperExpression node) {
2653 SuperExpression other = _other as SuperExpression;
2654 return isEqualTokens(node.superKeyword, other.superKeyword);
2655 }
2656
2657 @override
2658 bool visitSwitchCase(SwitchCase node) {
2659 SwitchCase other = _other as SwitchCase;
2660 return _isEqualNodeLists(node.labels, other.labels) &&
2661 isEqualTokens(node.keyword, other.keyword) &&
2662 isEqualNodes(node.expression, other.expression) &&
2663 isEqualTokens(node.colon, other.colon) &&
2664 _isEqualNodeLists(node.statements, other.statements);
2665 }
2666
2667 @override
2668 bool visitSwitchDefault(SwitchDefault node) {
2669 SwitchDefault other = _other as SwitchDefault;
2670 return _isEqualNodeLists(node.labels, other.labels) &&
2671 isEqualTokens(node.keyword, other.keyword) &&
2672 isEqualTokens(node.colon, other.colon) &&
2673 _isEqualNodeLists(node.statements, other.statements);
2674 }
2675
2676 @override
2677 bool visitSwitchStatement(SwitchStatement node) {
2678 SwitchStatement other = _other as SwitchStatement;
2679 return isEqualTokens(node.switchKeyword, other.switchKeyword) &&
2680 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2681 isEqualNodes(node.expression, other.expression) &&
2682 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2683 isEqualTokens(node.leftBracket, other.leftBracket) &&
2684 _isEqualNodeLists(node.members, other.members) &&
2685 isEqualTokens(node.rightBracket, other.rightBracket);
2686 }
2687
2688 @override
2689 bool visitSymbolLiteral(SymbolLiteral node) {
2690 SymbolLiteral other = _other as SymbolLiteral;
2691 return isEqualTokens(node.poundSign, other.poundSign) &&
2692 _isEqualTokenLists(node.components, other.components);
2693 }
2694
2695 @override
2696 bool visitThisExpression(ThisExpression node) {
2697 ThisExpression other = _other as ThisExpression;
2698 return isEqualTokens(node.thisKeyword, other.thisKeyword);
2699 }
2700
2701 @override
2702 bool visitThrowExpression(ThrowExpression node) {
2703 ThrowExpression other = _other as ThrowExpression;
2704 return isEqualTokens(node.throwKeyword, other.throwKeyword) &&
2705 isEqualNodes(node.expression, other.expression);
2706 }
2707
2708 @override
2709 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
2710 TopLevelVariableDeclaration other = _other as TopLevelVariableDeclaration;
2711 return isEqualNodes(
2712 node.documentationComment, other.documentationComment) &&
2713 _isEqualNodeLists(node.metadata, other.metadata) &&
2714 isEqualNodes(node.variables, other.variables) &&
2715 isEqualTokens(node.semicolon, other.semicolon);
2716 }
2717
2718 @override
2719 bool visitTryStatement(TryStatement node) {
2720 TryStatement other = _other as TryStatement;
2721 return isEqualTokens(node.tryKeyword, other.tryKeyword) &&
2722 isEqualNodes(node.body, other.body) &&
2723 _isEqualNodeLists(node.catchClauses, other.catchClauses) &&
2724 isEqualTokens(node.finallyKeyword, other.finallyKeyword) &&
2725 isEqualNodes(node.finallyBlock, other.finallyBlock);
2726 }
2727
2728 @override
2729 bool visitTypeArgumentList(TypeArgumentList node) {
2730 TypeArgumentList other = _other as TypeArgumentList;
2731 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2732 _isEqualNodeLists(node.arguments, other.arguments) &&
2733 isEqualTokens(node.rightBracket, other.rightBracket);
2734 }
2735
2736 @override
2737 bool visitTypeName(TypeName node) {
2738 TypeName other = _other as TypeName;
2739 return isEqualNodes(node.name, other.name) &&
2740 isEqualNodes(node.typeArguments, other.typeArguments);
2741 }
2742
2743 @override
2744 bool visitTypeParameter(TypeParameter node) {
2745 TypeParameter other = _other as TypeParameter;
2746 return isEqualNodes(
2747 node.documentationComment, other.documentationComment) &&
2748 _isEqualNodeLists(node.metadata, other.metadata) &&
2749 isEqualNodes(node.name, other.name) &&
2750 isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2751 isEqualNodes(node.bound, other.bound);
2752 }
2753
2754 @override
2755 bool visitTypeParameterList(TypeParameterList node) {
2756 TypeParameterList other = _other as TypeParameterList;
2757 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2758 _isEqualNodeLists(node.typeParameters, other.typeParameters) &&
2759 isEqualTokens(node.rightBracket, other.rightBracket);
2760 }
2761
2762 @override
2763 bool visitVariableDeclaration(VariableDeclaration node) {
2764 VariableDeclaration other = _other as VariableDeclaration;
2765 return isEqualNodes(
2766 node.documentationComment, other.documentationComment) &&
2767 _isEqualNodeLists(node.metadata, other.metadata) &&
2768 isEqualNodes(node.name, other.name) &&
2769 isEqualTokens(node.equals, other.equals) &&
2770 isEqualNodes(node.initializer, other.initializer);
2771 }
2772
2773 @override
2774 bool visitVariableDeclarationList(VariableDeclarationList node) {
2775 VariableDeclarationList other = _other as VariableDeclarationList;
2776 return isEqualNodes(
2777 node.documentationComment, other.documentationComment) &&
2778 _isEqualNodeLists(node.metadata, other.metadata) &&
2779 isEqualTokens(node.keyword, other.keyword) &&
2780 isEqualNodes(node.type, other.type) &&
2781 _isEqualNodeLists(node.variables, other.variables);
2782 }
2783
2784 @override
2785 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
2786 VariableDeclarationStatement other = _other as VariableDeclarationStatement;
2787 return isEqualNodes(node.variables, other.variables) &&
2788 isEqualTokens(node.semicolon, other.semicolon);
2789 }
2790
2791 @override
2792 bool visitWhileStatement(WhileStatement node) {
2793 WhileStatement other = _other as WhileStatement;
2794 return isEqualTokens(node.whileKeyword, other.whileKeyword) &&
2795 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2796 isEqualNodes(node.condition, other.condition) &&
2797 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2798 isEqualNodes(node.body, other.body);
2799 }
2800
2801 @override
2802 bool visitWithClause(WithClause node) {
2803 WithClause other = _other as WithClause;
2804 return isEqualTokens(node.withKeyword, other.withKeyword) &&
2805 _isEqualNodeLists(node.mixinTypes, other.mixinTypes);
2806 }
2807
2808 @override
2809 bool visitYieldStatement(YieldStatement node) {
2810 YieldStatement other = _other as YieldStatement;
2811 return isEqualTokens(node.yieldKeyword, other.yieldKeyword) &&
2812 isEqualNodes(node.expression, other.expression) &&
2813 isEqualTokens(node.semicolon, other.semicolon);
2814 }
2815
2816 /**
2817 * Return `true` if the [first] and [second] lists of AST nodes have the same
2818 * size and corresponding elements are equal.
2819 */
2820 bool _isEqualNodeLists(NodeList first, NodeList second) {
2821 if (first == null) {
2822 return second == null;
2823 } else if (second == null) {
2824 return false;
2825 }
2826 int size = first.length;
2827 if (second.length != size) {
2828 return false;
2829 }
2830 for (int i = 0; i < size; i++) {
2831 if (!isEqualNodes(first[i], second[i])) {
2832 return false;
2833 }
2834 }
2835 return true;
2836 }
2837
2838 /**
2839 * Return `true` if the [first] and [second] lists of tokens have the same
2840 * length and corresponding elements are equal.
2841 */
2842 bool _isEqualTokenLists(List<Token> first, List<Token> second) {
2843 int length = first.length;
2844 if (second.length != length) {
2845 return false;
2846 }
2847 for (int i = 0; i < length; i++) {
2848 if (!isEqualTokens(first[i], second[i])) {
2849 return false;
2850 }
2851 }
2852 return true;
2853 }
2854
2855 /**
2856 * Return `true` if the [first] and [second] nodes are equal.
2857 */
2858 static bool equalNodes(AstNode first, AstNode second) {
2859 AstComparator comparator = new AstComparator();
2860 return comparator.isEqualNodes(first, second);
2861 }
2862 }
2863
2864 /**
2865 * A node in the AST structure for a Dart program.
2866 */
2867 abstract class AstNode {
2868 /**
2869 * An empty list of AST nodes.
2870 */
2871 @deprecated // Use "AstNode.EMPTY_LIST"
2872 static const List<AstNode> EMPTY_ARRAY = EMPTY_LIST;
2873
2874 /**
2875 * An empty list of AST nodes.
2876 */
2877 static const List<AstNode> EMPTY_LIST = const <AstNode>[];
2878
2879 /**
2880 * A comparator that can be used to sort AST nodes in lexical order. In other
2881 * words, `compare` will return a negative value if the offset of the first
2882 * node is less than the offset of the second node, zero (0) if the nodes have
2883 * the same offset, and a positive value if the offset of the first node is
2884 * greater than the offset of the second node.
2885 */
2886 static Comparator<AstNode> LEXICAL_ORDER = (AstNode first, AstNode second) =>
2887 first.offset - second.offset;
2888
2889 /**
2890 * The parent of the node, or `null` if the node is the root of an AST
2891 * structure.
2892 */
2893 AstNode _parent;
2894
2895 /**
2896 * A table mapping the names of properties to their values, or `null` if this
2897 * node does not have any properties associated with it.
2898 */
2899 Map<String, Object> _propertyMap;
2900
2901 /**
2902 * Return the first token included in this node's source range.
2903 */
2904 Token get beginToken;
2905
2906 /**
2907 * Iterate through all the entities (either AST nodes or tokens) which make
2908 * up the contents of this node, including doc comments but excluding other
2909 * comments.
2910 */
2911 Iterable /*<AstNode | Token>*/ get childEntities;
2912
2913 /**
2914 * Return the offset of the character immediately following the last character
2915 * of this node's source range. This is equivalent to
2916 * `node.getOffset() + node.getLength()`. For a compilation unit this will be
2917 * equal to the length of the unit's source. For synthetic nodes this will be
2918 * equivalent to the node's offset (because the length is zero (0) by
2919 * definition).
2920 */
2921 int get end => offset + length;
2922
2923 /**
2924 * Return the last token included in this node's source range.
2925 */
2926 Token get endToken;
2927
2928 /**
2929 * Return `true` if this node is a synthetic node. A synthetic node is a node
2930 * that was introduced by the parser in order to recover from an error in the
2931 * code. Synthetic nodes always have a length of zero (`0`).
2932 */
2933 bool get isSynthetic => false;
2934
2935 /**
2936 * Return the number of characters in the node's source range.
2937 */
2938 int get length {
2939 Token beginToken = this.beginToken;
2940 Token endToken = this.endToken;
2941 if (beginToken == null || endToken == null) {
2942 return -1;
2943 }
2944 return endToken.offset + endToken.length - beginToken.offset;
2945 }
2946
2947 /**
2948 * Return the offset from the beginning of the file to the first character in
2949 * the node's source range.
2950 */
2951 int get offset {
2952 Token beginToken = this.beginToken;
2953 if (beginToken == null) {
2954 return -1;
2955 }
2956 return beginToken.offset;
2957 }
2958
2959 /**
2960 * Return this node's parent node, or `null` if this node is the root of an
2961 * AST structure.
2962 *
2963 * Note that the relationship between an AST node and its parent node may
2964 * change over the lifetime of a node.
2965 */
2966 AstNode get parent => _parent;
2967
2968 /**
2969 * Set the parent of this node to the [newParent].
2970 */
2971 @deprecated // Never intended for public use.
2972 void set parent(AstNode newParent) {
2973 _parent = newParent;
2974 }
2975
2976 /**
2977 * Return the node at the root of this node's AST structure. Note that this
2978 * method's performance is linear with respect to the depth of the node in the
2979 * AST structure (O(depth)).
2980 */
2981 AstNode get root {
2982 AstNode root = this;
2983 AstNode parent = this.parent;
2984 while (parent != null) {
2985 root = parent;
2986 parent = root.parent;
2987 }
2988 return root;
2989 }
2990
2991 /**
2992 * Use the given [visitor] to visit this node. Return the value returned by
2993 * the visitor as a result of visiting this node.
2994 */
2995 /* <E> E */ accept(AstVisitor /*<E>*/ visitor);
2996
2997 /**
2998 * Make this node the parent of the given [child] node. Return the child node.
2999 */
3000 @deprecated // Never intended for public use.
3001 AstNode becomeParentOf(AstNode child) {
3002 return _becomeParentOf(child);
3003 }
3004
3005 /**
3006 * Return the most immediate ancestor of this node for which the [predicate]
3007 * returns `true`, or `null` if there is no such ancestor. Note that this node
3008 * will never be returned.
3009 */
3010 AstNode getAncestor(Predicate<AstNode> predicate) {
3011 // TODO(brianwilkerson) It is a bug that this method can return `this`.
3012 AstNode node = this;
3013 while (node != null && !predicate(node)) {
3014 node = node.parent;
3015 }
3016 return node;
3017 }
3018
3019 /**
3020 * Return the value of the property with the given [name], or `null` if this
3021 * node does not have a property with the given name.
3022 */
3023 Object getProperty(String name) {
3024 if (_propertyMap == null) {
3025 return null;
3026 }
3027 return _propertyMap[name];
3028 }
3029
3030 /**
3031 * If the given [child] is not `null`, use the given [visitor] to visit it.
3032 */
3033 @deprecated // Never intended for public use.
3034 void safelyVisitChild(AstNode child, AstVisitor visitor) {
3035 if (child != null) {
3036 child.accept(visitor);
3037 }
3038 }
3039
3040 /**
3041 * Set the value of the property with the given [name] to the given [value].
3042 * If the value is `null`, the property will effectively be removed.
3043 */
3044 void setProperty(String name, Object value) {
3045 if (value == null) {
3046 if (_propertyMap != null) {
3047 _propertyMap.remove(name);
3048 if (_propertyMap.isEmpty) {
3049 _propertyMap = null;
3050 }
3051 }
3052 } else {
3053 if (_propertyMap == null) {
3054 _propertyMap = new HashMap<String, Object>();
3055 }
3056 _propertyMap[name] = value;
3057 }
3058 }
3059
3060 /**
3061 * Return a textual description of this node in a form approximating valid
3062 * source. The returned string will not be valid source primarily in the case
3063 * where the node itself is not well-formed.
3064 */
3065 String toSource() {
3066 PrintStringWriter writer = new PrintStringWriter();
3067 accept(new ToSourceVisitor(writer));
3068 return writer.toString();
3069 }
3070
3071 @override
3072 String toString() => toSource();
3073
3074 /**
3075 * Use the given [visitor] to visit all of the children of this node. The
3076 * children will be visited in lexical order.
3077 */
3078 void visitChildren(AstVisitor visitor);
3079
3080 /**
3081 * Make this node the parent of the given [child] node. Return the child node.
3082 */
3083 AstNode _becomeParentOf(AstNode child) {
3084 if (child != null) {
3085 child._parent = this;
3086 }
3087 return child;
3088 }
3089
3090 /**
3091 * If the given [child] is not `null`, use the given [visitor] to visit it.
3092 */
3093 void _safelyVisitChild(AstNode child, AstVisitor visitor) {
3094 if (child != null) {
3095 child.accept(visitor);
3096 }
3097 }
3098 }
3099
3100 /**
3101 * An object that can be used to visit an AST structure.
3102 */
3103 abstract class AstVisitor<R> {
3104 R visitAdjacentStrings(AdjacentStrings node);
3105
3106 R visitAnnotation(Annotation node);
3107
3108 R visitArgumentList(ArgumentList node);
3109
3110 R visitAsExpression(AsExpression node);
3111
3112 R visitAssertStatement(AssertStatement assertStatement);
3113
3114 R visitAssignmentExpression(AssignmentExpression node);
3115
3116 R visitAwaitExpression(AwaitExpression node);
3117
3118 R visitBinaryExpression(BinaryExpression node);
3119
3120 R visitBlock(Block node);
3121
3122 R visitBlockFunctionBody(BlockFunctionBody node);
3123
3124 R visitBooleanLiteral(BooleanLiteral node);
3125
3126 R visitBreakStatement(BreakStatement node);
3127
3128 R visitCascadeExpression(CascadeExpression node);
3129
3130 R visitCatchClause(CatchClause node);
3131
3132 R visitClassDeclaration(ClassDeclaration node);
3133
3134 R visitClassTypeAlias(ClassTypeAlias node);
3135
3136 R visitComment(Comment node);
3137
3138 R visitCommentReference(CommentReference node);
3139
3140 R visitCompilationUnit(CompilationUnit node);
3141
3142 R visitConditionalExpression(ConditionalExpression node);
3143
3144 R visitConstructorDeclaration(ConstructorDeclaration node);
3145
3146 R visitConstructorFieldInitializer(ConstructorFieldInitializer node);
3147
3148 R visitConstructorName(ConstructorName node);
3149
3150 R visitContinueStatement(ContinueStatement node);
3151
3152 R visitDeclaredIdentifier(DeclaredIdentifier node);
3153
3154 R visitDefaultFormalParameter(DefaultFormalParameter node);
3155
3156 R visitDoStatement(DoStatement node);
3157
3158 R visitDoubleLiteral(DoubleLiteral node);
3159
3160 R visitEmptyFunctionBody(EmptyFunctionBody node);
3161
3162 R visitEmptyStatement(EmptyStatement node);
3163
3164 R visitEnumConstantDeclaration(EnumConstantDeclaration node);
3165
3166 R visitEnumDeclaration(EnumDeclaration node);
3167
3168 R visitExportDirective(ExportDirective node);
3169
3170 R visitExpressionFunctionBody(ExpressionFunctionBody node);
3171
3172 R visitExpressionStatement(ExpressionStatement node);
3173
3174 R visitExtendsClause(ExtendsClause node);
3175
3176 R visitFieldDeclaration(FieldDeclaration node);
3177
3178 R visitFieldFormalParameter(FieldFormalParameter node);
3179
3180 R visitForEachStatement(ForEachStatement node);
3181
3182 R visitFormalParameterList(FormalParameterList node);
3183
3184 R visitForStatement(ForStatement node);
3185
3186 R visitFunctionDeclaration(FunctionDeclaration node);
3187
3188 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node);
3189
3190 R visitFunctionExpression(FunctionExpression node);
3191
3192 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node);
3193
3194 R visitFunctionTypeAlias(FunctionTypeAlias functionTypeAlias);
3195
3196 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node);
3197
3198 R visitHideCombinator(HideCombinator node);
3199
3200 R visitIfStatement(IfStatement node);
3201
3202 R visitImplementsClause(ImplementsClause node);
3203
3204 R visitImportDirective(ImportDirective node);
3205
3206 R visitIndexExpression(IndexExpression node);
3207
3208 R visitInstanceCreationExpression(InstanceCreationExpression node);
3209
3210 R visitIntegerLiteral(IntegerLiteral node);
3211
3212 R visitInterpolationExpression(InterpolationExpression node);
3213
3214 R visitInterpolationString(InterpolationString node);
3215
3216 R visitIsExpression(IsExpression node);
3217
3218 R visitLabel(Label node);
3219
3220 R visitLabeledStatement(LabeledStatement node);
3221
3222 R visitLibraryDirective(LibraryDirective node);
3223
3224 R visitLibraryIdentifier(LibraryIdentifier node);
3225
3226 R visitListLiteral(ListLiteral node);
3227
3228 R visitMapLiteral(MapLiteral node);
3229
3230 R visitMapLiteralEntry(MapLiteralEntry node);
3231
3232 R visitMethodDeclaration(MethodDeclaration node);
3233
3234 R visitMethodInvocation(MethodInvocation node);
3235
3236 R visitNamedExpression(NamedExpression node);
3237
3238 R visitNativeClause(NativeClause node);
3239
3240 R visitNativeFunctionBody(NativeFunctionBody node);
3241
3242 R visitNullLiteral(NullLiteral node);
3243
3244 R visitParenthesizedExpression(ParenthesizedExpression node);
3245
3246 R visitPartDirective(PartDirective node);
3247
3248 R visitPartOfDirective(PartOfDirective node);
3249
3250 R visitPostfixExpression(PostfixExpression node);
3251
3252 R visitPrefixedIdentifier(PrefixedIdentifier node);
3253
3254 R visitPrefixExpression(PrefixExpression node);
3255
3256 R visitPropertyAccess(PropertyAccess node);
3257
3258 R visitRedirectingConstructorInvocation(
3259 RedirectingConstructorInvocation node);
3260
3261 R visitRethrowExpression(RethrowExpression node);
3262
3263 R visitReturnStatement(ReturnStatement node);
3264
3265 R visitScriptTag(ScriptTag node);
3266
3267 R visitShowCombinator(ShowCombinator node);
3268
3269 R visitSimpleFormalParameter(SimpleFormalParameter node);
3270
3271 R visitSimpleIdentifier(SimpleIdentifier node);
3272
3273 R visitSimpleStringLiteral(SimpleStringLiteral node);
3274
3275 R visitStringInterpolation(StringInterpolation node);
3276
3277 R visitSuperConstructorInvocation(SuperConstructorInvocation node);
3278
3279 R visitSuperExpression(SuperExpression node);
3280
3281 R visitSwitchCase(SwitchCase node);
3282
3283 R visitSwitchDefault(SwitchDefault node);
3284
3285 R visitSwitchStatement(SwitchStatement node);
3286
3287 R visitSymbolLiteral(SymbolLiteral node);
3288
3289 R visitThisExpression(ThisExpression node);
3290
3291 R visitThrowExpression(ThrowExpression node);
3292
3293 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node);
3294
3295 R visitTryStatement(TryStatement node);
3296
3297 R visitTypeArgumentList(TypeArgumentList node);
3298
3299 R visitTypeName(TypeName node);
3300
3301 R visitTypeParameter(TypeParameter node);
3302
3303 R visitTypeParameterList(TypeParameterList node);
3304
3305 R visitVariableDeclaration(VariableDeclaration node);
3306
3307 R visitVariableDeclarationList(VariableDeclarationList node);
3308
3309 R visitVariableDeclarationStatement(VariableDeclarationStatement node);
3310
3311 R visitWhileStatement(WhileStatement node);
3312
3313 R visitWithClause(WithClause node);
3314
3315 R visitYieldStatement(YieldStatement node);
3316 }
3317
3318 /**
3319 * An await expression.
3320 *
3321 * > awaitExpression ::=
3322 * > 'await' [Expression]
3323 */
3324 class AwaitExpression extends Expression {
3325 /**
3326 * The 'await' keyword.
3327 */
3328 Token awaitKeyword;
3329
3330 /**
3331 * The expression whose value is being waited on.
3332 */
3333 Expression _expression;
3334
3335 /**
3336 * Initialize a newly created await expression.
3337 */
3338 AwaitExpression(this.awaitKeyword, Expression expression) {
3339 _expression = _becomeParentOf(expression);
3340 }
3341
3342 @override
3343 Token get beginToken {
3344 if (awaitKeyword != null) {
3345 return awaitKeyword;
3346 }
3347 return _expression.beginToken;
3348 }
3349
3350 @override
3351 Iterable get childEntities =>
3352 new ChildEntities()..add(awaitKeyword)..add(_expression);
3353
3354 @override
3355 Token get endToken => _expression.endToken;
3356
3357 /**
3358 * Return the expression whose value is being waited on.
3359 */
3360 Expression get expression => _expression;
3361
3362 /**
3363 * Set the expression whose value is being waited on to the given [expression] .
3364 */
3365 void set expression(Expression expression) {
3366 _expression = _becomeParentOf(expression);
3367 }
3368
3369 @override
3370 int get precedence => 0;
3371
3372 @override
3373 accept(AstVisitor visitor) => visitor.visitAwaitExpression(this);
3374
3375 @override
3376 void visitChildren(AstVisitor visitor) {
3377 _safelyVisitChild(_expression, visitor);
3378 }
3379 }
3380
3381 /**
3382 * A binary (infix) expression.
3383 *
3384 * > binaryExpression ::=
3385 * > [Expression] [Token] [Expression]
3386 */
3387 class BinaryExpression extends Expression {
3388 /**
3389 * The expression used to compute the left operand.
3390 */
3391 Expression _leftOperand;
3392
3393 /**
3394 * The binary operator being applied.
3395 */
3396 Token operator;
3397
3398 /**
3399 * The expression used to compute the right operand.
3400 */
3401 Expression _rightOperand;
3402
3403 /**
3404 * The element associated with the operator based on the static type of the
3405 * left operand, or `null` if the AST structure has not been resolved, if the
3406 * operator is not user definable, or if the operator could not be resolved.
3407 */
3408 MethodElement staticElement;
3409
3410 /**
3411 * The element associated with the operator based on the propagated type of
3412 * the left operand, or `null` if the AST structure has not been resolved, if
3413 * the operator is not user definable, or if the operator could not be
3414 * resolved.
3415 */
3416 MethodElement propagatedElement;
3417
3418 /**
3419 * Initialize a newly created binary expression.
3420 */
3421 BinaryExpression(
3422 Expression leftOperand, this.operator, Expression rightOperand) {
3423 _leftOperand = _becomeParentOf(leftOperand);
3424 _rightOperand = _becomeParentOf(rightOperand);
3425 }
3426
3427 @override
3428 Token get beginToken => _leftOperand.beginToken;
3429
3430 /**
3431 * Return the best element available for this operator. If resolution was able
3432 * to find a better element based on type propagation, that element will be
3433 * returned. Otherwise, the element found using the result of static analysis
3434 * will be returned. If resolution has not been performed, then `null` will be
3435 * returned.
3436 */
3437 MethodElement get bestElement {
3438 MethodElement element = propagatedElement;
3439 if (element == null) {
3440 element = staticElement;
3441 }
3442 return element;
3443 }
3444
3445 @override
3446 Iterable get childEntities =>
3447 new ChildEntities()..add(_leftOperand)..add(operator)..add(_rightOperand);
3448
3449 @override
3450 Token get endToken => _rightOperand.endToken;
3451
3452 /**
3453 * Return the expression used to compute the left operand.
3454 */
3455 Expression get leftOperand => _leftOperand;
3456
3457 /**
3458 * Set the expression used to compute the left operand to the given
3459 * [expression].
3460 */
3461 void set leftOperand(Expression expression) {
3462 _leftOperand = _becomeParentOf(expression);
3463 }
3464
3465 @override
3466 int get precedence => operator.type.precedence;
3467
3468 /**
3469 * If the AST structure has been resolved, and the function being invoked is
3470 * known based on propagated type information, then return the parameter
3471 * element representing the parameter to which the value of the right operand
3472 * will be bound. Otherwise, return `null`.
3473 */
3474 @deprecated // Use "expression.propagatedParameterElement"
3475 ParameterElement get propagatedParameterElementForRightOperand {
3476 return _propagatedParameterElementForRightOperand;
3477 }
3478
3479 /**
3480 * Return the expression used to compute the right operand.
3481 */
3482 Expression get rightOperand => _rightOperand;
3483
3484 /**
3485 * Set the expression used to compute the right operand to the given
3486 * [expression].
3487 */
3488 void set rightOperand(Expression expression) {
3489 _rightOperand = _becomeParentOf(expression);
3490 }
3491
3492 /**
3493 * If the AST structure has been resolved, and the function being invoked is
3494 * known based on static type information, then return the parameter element
3495 * representing the parameter to which the value of the right operand will be
3496 * bound. Otherwise, return `null`.
3497 */
3498 @deprecated // Use "expression.staticParameterElement"
3499 ParameterElement get staticParameterElementForRightOperand {
3500 return _staticParameterElementForRightOperand;
3501 }
3502
3503 /**
3504 * If the AST structure has been resolved, and the function being invoked is
3505 * known based on propagated type information, then return the parameter
3506 * element representing the parameter to which the value of the right operand
3507 * will be bound. Otherwise, return `null`.
3508 */
3509 ParameterElement get _propagatedParameterElementForRightOperand {
3510 if (propagatedElement == null) {
3511 return null;
3512 }
3513 List<ParameterElement> parameters = propagatedElement.parameters;
3514 if (parameters.length < 1) {
3515 return null;
3516 }
3517 return parameters[0];
3518 }
3519
3520 /**
3521 * If the AST structure has been resolved, and the function being invoked is
3522 * known based on static type information, then return the parameter element
3523 * representing the parameter to which the value of the right operand will be
3524 * bound. Otherwise, return `null`.
3525 */
3526 ParameterElement get _staticParameterElementForRightOperand {
3527 if (staticElement == null) {
3528 return null;
3529 }
3530 List<ParameterElement> parameters = staticElement.parameters;
3531 if (parameters.length < 1) {
3532 return null;
3533 }
3534 return parameters[0];
3535 }
3536
3537 @override
3538 accept(AstVisitor visitor) => visitor.visitBinaryExpression(this);
3539
3540 @override
3541 void visitChildren(AstVisitor visitor) {
3542 _safelyVisitChild(_leftOperand, visitor);
3543 _safelyVisitChild(_rightOperand, visitor);
3544 }
3545 }
3546
3547 /**
3548 * A sequence of statements.
3549 *
3550 * > block ::=
3551 * > '{' statement* '}'
3552 */
3553 class Block extends Statement {
3554 /**
3555 * The left curly bracket.
3556 */
3557 Token leftBracket;
3558
3559 /**
3560 * The statements contained in the block.
3561 */
3562 NodeList<Statement> _statements;
3563
3564 /**
3565 * The right curly bracket.
3566 */
3567 Token rightBracket;
3568
3569 /**
3570 * Initialize a newly created block of code.
3571 */
3572 Block(this.leftBracket, List<Statement> statements, this.rightBracket) {
3573 _statements = new NodeList<Statement>(this, statements);
3574 }
3575
3576 @override
3577 Token get beginToken => leftBracket;
3578
3579 @override
3580 Iterable get childEntities => new ChildEntities()
3581 ..add(leftBracket)
3582 ..addAll(_statements)
3583 ..add(rightBracket);
3584
3585 @override
3586 Token get endToken => rightBracket;
3587
3588 /**
3589 * Return the statements contained in the block.
3590 */
3591 NodeList<Statement> get statements => _statements;
3592
3593 @override
3594 accept(AstVisitor visitor) => visitor.visitBlock(this);
3595
3596 @override
3597 void visitChildren(AstVisitor visitor) {
3598 _statements.accept(visitor);
3599 }
3600 }
3601
3602 /**
3603 * A function body that consists of a block of statements.
3604 *
3605 * > blockFunctionBody ::=
3606 * > ('async' | 'async' '*' | 'sync' '*')? [Block]
3607 */
3608 class BlockFunctionBody extends FunctionBody {
3609 /**
3610 * The token representing the 'async' or 'sync' keyword, or `null` if there is
3611 * no such keyword.
3612 */
3613 Token keyword;
3614
3615 /**
3616 * The star optionally following the 'async' or 'sync' keyword, or `null` if
3617 * there is wither no such keyword or no star.
3618 */
3619 Token star;
3620
3621 /**
3622 * The block representing the body of the function.
3623 */
3624 Block _block;
3625
3626 /**
3627 * Initialize a newly created function body consisting of a block of
3628 * statements. The [keyword] can be `null` if there is no keyword specified
3629 * for the block. The [star] can be `null` if there is no star following the
3630 * keyword (and must be `null` if there is no keyword).
3631 */
3632 BlockFunctionBody(this.keyword, this.star, Block block) {
3633 _block = _becomeParentOf(block);
3634 }
3635
3636 @override
3637 Token get beginToken {
3638 if (keyword != null) {
3639 return keyword;
3640 }
3641 return _block.beginToken;
3642 }
3643
3644 /**
3645 * Return the block representing the body of the function.
3646 */
3647 Block get block => _block;
3648
3649 /**
3650 * Set the block representing the body of the function to the given [block].
3651 */
3652 void set block(Block block) {
3653 _block = _becomeParentOf(block);
3654 }
3655
3656 @override
3657 Iterable get childEntities =>
3658 new ChildEntities()..add(keyword)..add(star)..add(_block);
3659
3660 @override
3661 Token get endToken => _block.endToken;
3662
3663 @override
3664 bool get isAsynchronous => keyword != null && keyword.lexeme == Parser.ASYNC;
3665
3666 @override
3667 bool get isGenerator => star != null;
3668
3669 @override
3670 bool get isSynchronous => keyword == null || keyword.lexeme != Parser.ASYNC;
3671
3672 @override
3673 accept(AstVisitor visitor) => visitor.visitBlockFunctionBody(this);
3674
3675 @override
3676 void visitChildren(AstVisitor visitor) {
3677 _safelyVisitChild(_block, visitor);
3678 }
3679 }
3680
3681 /**
3682 * A boolean literal expression.
3683 *
3684 * > booleanLiteral ::=
3685 * > 'false' | 'true'
3686 */
3687 class BooleanLiteral extends Literal {
3688 /**
3689 * The token representing the literal.
3690 */
3691 Token literal;
3692
3693 /**
3694 * The value of the literal.
3695 */
3696 bool value = false;
3697
3698 /**
3699 * Initialize a newly created boolean literal.
3700 */
3701 BooleanLiteral(this.literal, this.value);
3702
3703 @override
3704 Token get beginToken => literal;
3705
3706 @override
3707 Iterable get childEntities => new ChildEntities()..add(literal);
3708
3709 @override
3710 Token get endToken => literal;
3711
3712 @override
3713 bool get isSynthetic => literal.isSynthetic;
3714
3715 @override
3716 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this);
3717
3718 @override
3719 void visitChildren(AstVisitor visitor) {
3720 // There are no children to visit.
3721 }
3722 }
3723
3724 /**
3725 * An AST visitor that will recursively visit all of the nodes in an AST
3726 * structure, similar to [GeneralizingAstVisitor]. This visitor uses a
3727 * breadth-first ordering rather than the depth-first ordering of
3728 * [GeneralizingAstVisitor].
3729 *
3730 * Subclasses that override a visit method must either invoke the overridden
3731 * visit method or explicitly invoke the more general visit method. Failure to
3732 * do so will cause the visit methods for superclasses of the node to not be
3733 * invoked and will cause the children of the visited node to not be visited.
3734 *
3735 * In addition, subclasses should <b>not</b> explicitly visit the children of a
3736 * node, but should ensure that the method [visitNode] is used to visit the
3737 * children (either directly or indirectly). Failure to do will break the order
3738 * in which nodes are visited.
3739 */
3740 class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
3741 /**
3742 * A queue holding the nodes that have not yet been visited in the order in
3743 * which they ought to be visited.
3744 */
3745 Queue<AstNode> _queue = new Queue<AstNode>();
3746
3747 /**
3748 * A visitor, used to visit the children of the current node, that will add
3749 * the nodes it visits to the [_queue].
3750 */
3751 GeneralizingAstVisitor<Object> _childVisitor;
3752
3753 /**
3754 * Initialize a newly created visitor.
3755 */
3756 BreadthFirstVisitor() {
3757 _childVisitor = new GeneralizingAstVisitor_BreadthFirstVisitor(this);
3758 }
3759
3760 /**
3761 * Visit all nodes in the tree starting at the given [root] node, in
3762 * breadth-first order.
3763 */
3764 void visitAllNodes(AstNode root) {
3765 _queue.add(root);
3766 while (!_queue.isEmpty) {
3767 AstNode next = _queue.removeFirst();
3768 next.accept(this);
3769 }
3770 }
3771
3772 @override
3773 R visitNode(AstNode node) {
3774 node.visitChildren(_childVisitor);
3775 return null;
3776 }
3777 }
3778
3779 /**
3780 * A break statement.
3781 *
3782 * > breakStatement ::=
3783 * > 'break' [SimpleIdentifier]? ';'
3784 */
3785 class BreakStatement extends Statement {
3786 /**
3787 * The token representing the 'break' keyword.
3788 */
3789 Token breakKeyword;
3790
3791 /**
3792 * The label associated with the statement, or `null` if there is no label.
3793 */
3794 SimpleIdentifier _label;
3795
3796 /**
3797 * The semicolon terminating the statement.
3798 */
3799 Token semicolon;
3800
3801 /**
3802 * The AstNode which this break statement is breaking from. This will be
3803 * either a [Statement] (in the case of breaking out of a loop), a
3804 * [SwitchMember] (in the case of a labeled break statement whose label
3805 * matches a label on a switch case in an enclosing switch statement), or
3806 * `null` if the AST has not yet been resolved or if the target could not be
3807 * resolved. Note that if the source code has errors, the target might be
3808 * invalid (e.g. trying to break to a switch case).
3809 */
3810 AstNode target;
3811
3812 /**
3813 * Initialize a newly created break statement. The [label] can be `null` if
3814 * there is no label associated with the statement.
3815 */
3816 BreakStatement(this.breakKeyword, SimpleIdentifier label, this.semicolon) {
3817 _label = _becomeParentOf(label);
3818 }
3819
3820 @override
3821 Token get beginToken => breakKeyword;
3822
3823 @override
3824 Iterable get childEntities =>
3825 new ChildEntities()..add(breakKeyword)..add(_label)..add(semicolon);
3826
3827 @override
3828 Token get endToken => semicolon;
3829
3830 /**
3831 * Return the token representing the 'break' keyword.
3832 */
3833 @deprecated // Use "this.breakKeyword"
3834 Token get keyword => breakKeyword;
3835
3836 /**
3837 * Set the token representing the 'break' keyword to the given [token].
3838 */
3839 @deprecated // Use "this.breakKeyword"
3840 void set keyword(Token token) {
3841 breakKeyword = token;
3842 }
3843
3844 /**
3845 * Return the label associated with the statement, or `null` if there is no
3846 * label.
3847 */
3848 SimpleIdentifier get label => _label;
3849
3850 /**
3851 * Set the label associated with the statement to the given [identifier].
3852 */
3853 void set label(SimpleIdentifier identifier) {
3854 _label = _becomeParentOf(identifier);
3855 }
3856
3857 @override
3858 accept(AstVisitor visitor) => visitor.visitBreakStatement(this);
3859
3860 @override
3861 void visitChildren(AstVisitor visitor) {
3862 _safelyVisitChild(_label, visitor);
3863 }
3864 }
3865
3866 /**
3867 * A sequence of cascaded expressions: expressions that share a common target.
3868 * There are three kinds of expressions that can be used in a cascade
3869 * expression: [IndexExpression], [MethodInvocation] and [PropertyAccess].
3870 *
3871 * > cascadeExpression ::=
3872 * > [Expression] cascadeSection*
3873 * >
3874 * > cascadeSection ::=
3875 * > '..' (cascadeSelector arguments*) (assignableSelector arguments*)*
3876 * > (assignmentOperator expressionWithoutCascade)?
3877 * >
3878 * > cascadeSelector ::=
3879 * > '[ ' expression '] '
3880 * > | identifier
3881 */
3882 class CascadeExpression extends Expression {
3883 /**
3884 * The target of the cascade sections.
3885 */
3886 Expression _target;
3887
3888 /**
3889 * The cascade sections sharing the common target.
3890 */
3891 NodeList<Expression> _cascadeSections;
3892
3893 /**
3894 * Initialize a newly created cascade expression. The list of
3895 * [cascadeSections] must contain at least one element.
3896 */
3897 CascadeExpression(Expression target, List<Expression> cascadeSections) {
3898 _target = _becomeParentOf(target);
3899 _cascadeSections = new NodeList<Expression>(this, cascadeSections);
3900 }
3901
3902 @override
3903 Token get beginToken => _target.beginToken;
3904
3905 /**
3906 * Return the cascade sections sharing the common target.
3907 */
3908 NodeList<Expression> get cascadeSections => _cascadeSections;
3909
3910 @override
3911 Iterable get childEntities => new ChildEntities()
3912 ..add(_target)
3913 ..addAll(_cascadeSections);
3914
3915 @override
3916 Token get endToken => _cascadeSections.endToken;
3917
3918 @override
3919 int get precedence => 2;
3920
3921 /**
3922 * Return the target of the cascade sections.
3923 */
3924 Expression get target => _target;
3925
3926 /**
3927 * Set the target of the cascade sections to the given [expression].
3928 */
3929 void set target(Expression target) {
3930 _target = _becomeParentOf(target);
3931 }
3932
3933 @override
3934 accept(AstVisitor visitor) => visitor.visitCascadeExpression(this);
3935
3936 @override
3937 void visitChildren(AstVisitor visitor) {
3938 _safelyVisitChild(_target, visitor);
3939 _cascadeSections.accept(visitor);
3940 }
3941 }
3942
3943 /**
3944 * A catch clause within a try statement.
3945 *
3946 * > onPart ::=
3947 * > catchPart [Block]
3948 * > | 'on' type catchPart? [Block]
3949 * >
3950 * > catchPart ::=
3951 * > 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')'
3952 */
3953 class CatchClause extends AstNode {
3954 /**
3955 * The token representing the 'on' keyword, or `null` if there is no 'on'
3956 * keyword.
3957 */
3958 Token onKeyword;
3959
3960 /**
3961 * The type of exceptions caught by this catch clause, or `null` if this catch
3962 * clause catches every type of exception.
3963 */
3964 TypeName _exceptionType;
3965
3966 /**
3967 * The token representing the 'catch' keyword, or `null` if there is no
3968 * 'catch' keyword.
3969 */
3970 Token catchKeyword;
3971
3972 /**
3973 * The left parenthesis, or `null` if there is no 'catch' keyword.
3974 */
3975 Token leftParenthesis;
3976
3977 /**
3978 * The parameter whose value will be the exception that was thrown, or `null`
3979 * if there is no 'catch' keyword.
3980 */
3981 SimpleIdentifier _exceptionParameter;
3982
3983 /**
3984 * The comma separating the exception parameter from the stack trace
3985 * parameter, or `null` if there is no stack trace parameter.
3986 */
3987 Token comma;
3988
3989 /**
3990 * The parameter whose value will be the stack trace associated with the
3991 * exception, or `null` if there is no stack trace parameter.
3992 */
3993 SimpleIdentifier _stackTraceParameter;
3994
3995 /**
3996 * The right parenthesis, or `null` if there is no 'catch' keyword.
3997 */
3998 Token rightParenthesis;
3999
4000 /**
4001 * The body of the catch block.
4002 */
4003 Block _body;
4004
4005 /**
4006 * Initialize a newly created catch clause. The [onKeyword] and
4007 * [exceptionType] can be `null` if the clause will catch all exceptions. The
4008 * [comma] and [stackTraceParameter] can be `null` if the stack trace is not
4009 * referencable within the body.
4010 */
4011 CatchClause(
4012 this.onKeyword,
4013 TypeName exceptionType,
4014 this.catchKeyword,
4015 this.leftParenthesis,
4016 SimpleIdentifier exceptionParameter,
4017 this.comma,
4018 SimpleIdentifier stackTraceParameter,
4019 this.rightParenthesis,
4020 Block body) {
4021 _exceptionType = _becomeParentOf(exceptionType);
4022 _exceptionParameter = _becomeParentOf(exceptionParameter);
4023 _stackTraceParameter = _becomeParentOf(stackTraceParameter);
4024 _body = _becomeParentOf(body);
4025 }
4026
4027 @override
4028 Token get beginToken {
4029 if (onKeyword != null) {
4030 return onKeyword;
4031 }
4032 return catchKeyword;
4033 }
4034
4035 /**
4036 * Return the body of the catch block.
4037 */
4038 Block get body => _body;
4039
4040 /**
4041 * Set the body of the catch block to the given [block].
4042 */
4043 void set body(Block block) {
4044 _body = _becomeParentOf(block);
4045 }
4046
4047 @override
4048 Iterable get childEntities => new ChildEntities()
4049 ..add(onKeyword)
4050 ..add(_exceptionType)
4051 ..add(catchKeyword)
4052 ..add(leftParenthesis)
4053 ..add(_exceptionParameter)
4054 ..add(comma)
4055 ..add(_stackTraceParameter)
4056 ..add(rightParenthesis)
4057 ..add(_body);
4058
4059 @override
4060 Token get endToken => _body.endToken;
4061
4062 /**
4063 * Return the parameter whose value will be the exception that was thrown, or
4064 * `null` if there is no 'catch' keyword.
4065 */
4066 SimpleIdentifier get exceptionParameter => _exceptionParameter;
4067
4068 /**
4069 * Set the parameter whose value will be the exception that was thrown to the
4070 * given [parameter].
4071 */
4072 void set exceptionParameter(SimpleIdentifier parameter) {
4073 _exceptionParameter = _becomeParentOf(parameter);
4074 }
4075
4076 /**
4077 * Return the type of exceptions caught by this catch clause, or `null` if
4078 * this catch clause catches every type of exception.
4079 */
4080 TypeName get exceptionType => _exceptionType;
4081
4082 /**
4083 * Set the type of exceptions caught by this catch clause to the given
4084 * [exceptionType].
4085 */
4086 void set exceptionType(TypeName exceptionType) {
4087 _exceptionType = _becomeParentOf(exceptionType);
4088 }
4089
4090 /**
4091 * Return the parameter whose value will be the stack trace associated with
4092 * the exception, or `null` if there is no stack trace parameter.
4093 */
4094 SimpleIdentifier get stackTraceParameter => _stackTraceParameter;
4095
4096 /**
4097 * Set the parameter whose value will be the stack trace associated with the
4098 * exception to the given [parameter].
4099 */
4100 void set stackTraceParameter(SimpleIdentifier parameter) {
4101 _stackTraceParameter = _becomeParentOf(parameter);
4102 }
4103
4104 @override
4105 accept(AstVisitor visitor) => visitor.visitCatchClause(this);
4106
4107 @override
4108 void visitChildren(AstVisitor visitor) {
4109 _safelyVisitChild(_exceptionType, visitor);
4110 _safelyVisitChild(_exceptionParameter, visitor);
4111 _safelyVisitChild(_stackTraceParameter, visitor);
4112 _safelyVisitChild(_body, visitor);
4113 }
4114 }
4115
4116 /**
4117 * Helper class to allow iteration of child entities of an AST node.
4118 */
4119 class ChildEntities extends Object with IterableMixin implements Iterable {
4120 /**
4121 * The list of child entities to be iterated over.
4122 */
4123 List _entities = [];
4124
4125 @override
4126 Iterator get iterator => _entities.iterator;
4127
4128 /**
4129 * Add an AST node or token as the next child entity, if it is not null.
4130 */
4131 void add(entity) {
4132 if (entity != null) {
4133 assert(entity is Token || entity is AstNode);
4134 _entities.add(entity);
4135 }
4136 }
4137
4138 /**
4139 * Add the given items as the next child entities, if [items] is not null.
4140 */
4141 void addAll(Iterable items) {
4142 if (items != null) {
4143 _entities.addAll(items);
4144 }
4145 }
4146 }
4147
4148 /**
4149 * The declaration of a class.
4150 *
4151 * > classDeclaration ::=
4152 * > 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]?
4153 * > ([ExtendsClause] [WithClause]?)?
4154 * > [ImplementsClause]?
4155 * > '{' [ClassMember]* '}'
4156 */
4157 class ClassDeclaration extends NamedCompilationUnitMember {
4158 /**
4159 * The 'abstract' keyword, or `null` if the keyword was absent.
4160 */
4161 Token abstractKeyword;
4162
4163 /**
4164 * The token representing the 'class' keyword.
4165 */
4166 Token classKeyword;
4167
4168 /**
4169 * The type parameters for the class, or `null` if the class does not have any
4170 * type parameters.
4171 */
4172 TypeParameterList _typeParameters;
4173
4174 /**
4175 * The extends clause for the class, or `null` if the class does not extend
4176 * any other class.
4177 */
4178 ExtendsClause _extendsClause;
4179
4180 /**
4181 * The with clause for the class, or `null` if the class does not have a with
4182 * clause.
4183 */
4184 WithClause _withClause;
4185
4186 /**
4187 * The implements clause for the class, or `null` if the class does not
4188 * implement any interfaces.
4189 */
4190 ImplementsClause _implementsClause;
4191
4192 /**
4193 * The native clause for the class, or `null` if the class does not have a
4194 * native clause.
4195 */
4196 NativeClause _nativeClause;
4197
4198 /**
4199 * The left curly bracket.
4200 */
4201 Token leftBracket;
4202
4203 /**
4204 * The members defined by the class.
4205 */
4206 NodeList<ClassMember> _members;
4207
4208 /**
4209 * The right curly bracket.
4210 */
4211 Token rightBracket;
4212
4213 /**
4214 * Initialize a newly created class declaration. Either or both of the
4215 * [comment] and [metadata] can be `null` if the class does not have the
4216 * corresponding attribute. The [abstractKeyword] can be `null` if the class
4217 * is not abstract. The [typeParameters] can be `null` if the class does not
4218 * have any type parameters. Any or all of the [extendsClause], [withClause],
4219 * and [implementsClause] can be `null` if the class does not have the
4220 * corresponding clause. The list of [members] can be `null` if the class does
4221 * not have any members.
4222 */
4223 ClassDeclaration(
4224 Comment comment,
4225 List<Annotation> metadata,
4226 this.abstractKeyword,
4227 this.classKeyword,
4228 SimpleIdentifier name,
4229 TypeParameterList typeParameters,
4230 ExtendsClause extendsClause,
4231 WithClause withClause,
4232 ImplementsClause implementsClause,
4233 this.leftBracket,
4234 List<ClassMember> members,
4235 this.rightBracket)
4236 : super(comment, metadata, name) {
4237 _typeParameters = _becomeParentOf(typeParameters);
4238 _extendsClause = _becomeParentOf(extendsClause);
4239 _withClause = _becomeParentOf(withClause);
4240 _implementsClause = _becomeParentOf(implementsClause);
4241 _members = new NodeList<ClassMember>(this, members);
4242 }
4243
4244 @override
4245 Iterable get childEntities => super._childEntities
4246 ..add(abstractKeyword)
4247 ..add(classKeyword)
4248 ..add(_name)
4249 ..add(_typeParameters)
4250 ..add(_extendsClause)
4251 ..add(_withClause)
4252 ..add(_implementsClause)
4253 ..add(_nativeClause)
4254 ..add(leftBracket)
4255 ..addAll(members)
4256 ..add(rightBracket);
4257
4258 @override
4259 ClassElement get element =>
4260 _name != null ? (_name.staticElement as ClassElement) : null;
4261
4262 @override
4263 Token get endToken => rightBracket;
4264
4265 /**
4266 * Return the extends clause for this class, or `null` if the class does not
4267 * extend any other class.
4268 */
4269 ExtendsClause get extendsClause => _extendsClause;
4270
4271 /**
4272 * Set the extends clause for this class to the given [extendsClause].
4273 */
4274 void set extendsClause(ExtendsClause extendsClause) {
4275 _extendsClause = _becomeParentOf(extendsClause);
4276 }
4277
4278 @override
4279 Token get firstTokenAfterCommentAndMetadata {
4280 if (abstractKeyword != null) {
4281 return abstractKeyword;
4282 }
4283 return classKeyword;
4284 }
4285
4286 /**
4287 * Return the implements clause for the class, or `null` if the class does not
4288 * implement any interfaces.
4289 */
4290 ImplementsClause get implementsClause => _implementsClause;
4291
4292 /**
4293 * Set the implements clause for the class to the given [implementsClause].
4294 */
4295 void set implementsClause(ImplementsClause implementsClause) {
4296 _implementsClause = _becomeParentOf(implementsClause);
4297 }
4298
4299 /**
4300 * Return `true` if this class is declared to be an abstract class.
4301 */
4302 bool get isAbstract => abstractKeyword != null;
4303
4304 /**
4305 * Return the members defined by the class.
4306 */
4307 NodeList<ClassMember> get members => _members;
4308
4309 /**
4310 * Return the native clause for this class, or `null` if the class does not
4311 * have a native clause.
4312 */
4313 NativeClause get nativeClause => _nativeClause;
4314
4315 /**
4316 * Set the native clause for this class to the given [nativeClause].
4317 */
4318 void set nativeClause(NativeClause nativeClause) {
4319 _nativeClause = _becomeParentOf(nativeClause);
4320 }
4321
4322 /**
4323 * Return the type parameters for the class, or `null` if the class does not
4324 * have any type parameters.
4325 */
4326 TypeParameterList get typeParameters => _typeParameters;
4327
4328 /**
4329 * Set the type parameters for the class to the given list of [typeParameters] .
4330 */
4331 void set typeParameters(TypeParameterList typeParameters) {
4332 _typeParameters = _becomeParentOf(typeParameters);
4333 }
4334
4335 /**
4336 * Return the with clause for the class, or `null` if the class does not have
4337 * a with clause.
4338 */
4339 WithClause get withClause => _withClause;
4340
4341 /**
4342 * Set the with clause for the class to the given [withClause].
4343 */
4344 void set withClause(WithClause withClause) {
4345 _withClause = _becomeParentOf(withClause);
4346 }
4347
4348 @override
4349 accept(AstVisitor visitor) => visitor.visitClassDeclaration(this);
4350
4351 /**
4352 * Return the constructor declared in the class with the given [name], or
4353 * `null` if there is no such constructor. If the [name] is `null` then the
4354 * default constructor will be searched for.
4355 */
4356 ConstructorDeclaration getConstructor(String name) {
4357 for (ClassMember classMember in _members) {
4358 if (classMember is ConstructorDeclaration) {
4359 ConstructorDeclaration constructor = classMember;
4360 SimpleIdentifier constructorName = constructor.name;
4361 if (name == null && constructorName == null) {
4362 return constructor;
4363 }
4364 if (constructorName != null && constructorName.name == name) {
4365 return constructor;
4366 }
4367 }
4368 }
4369 return null;
4370 }
4371
4372 /**
4373 * Return the field declared in the class with the given [name], or `null` if
4374 * there is no such field.
4375 */
4376 VariableDeclaration getField(String name) {
4377 for (ClassMember classMember in _members) {
4378 if (classMember is FieldDeclaration) {
4379 FieldDeclaration fieldDeclaration = classMember;
4380 NodeList<VariableDeclaration> fields =
4381 fieldDeclaration.fields.variables;
4382 for (VariableDeclaration field in fields) {
4383 SimpleIdentifier fieldName = field.name;
4384 if (fieldName != null && name == fieldName.name) {
4385 return field;
4386 }
4387 }
4388 }
4389 }
4390 return null;
4391 }
4392
4393 /**
4394 * Return the method declared in the class with the given [name], or `null` if
4395 * there is no such method.
4396 */
4397 MethodDeclaration getMethod(String name) {
4398 for (ClassMember classMember in _members) {
4399 if (classMember is MethodDeclaration) {
4400 MethodDeclaration method = classMember;
4401 SimpleIdentifier methodName = method.name;
4402 if (methodName != null && name == methodName.name) {
4403 return method;
4404 }
4405 }
4406 }
4407 return null;
4408 }
4409
4410 @override
4411 void visitChildren(AstVisitor visitor) {
4412 super.visitChildren(visitor);
4413 _safelyVisitChild(_name, visitor);
4414 _safelyVisitChild(_typeParameters, visitor);
4415 _safelyVisitChild(_extendsClause, visitor);
4416 _safelyVisitChild(_withClause, visitor);
4417 _safelyVisitChild(_implementsClause, visitor);
4418 _safelyVisitChild(_nativeClause, visitor);
4419 members.accept(visitor);
4420 }
4421 }
4422
4423 /**
4424 * A node that declares a name within the scope of a class.
4425 */
4426 abstract class ClassMember extends Declaration {
4427 /**
4428 * Initialize a newly created member of a class. Either or both of the
4429 * [comment] and [metadata] can be `null` if the member does not have the
4430 * corresponding attribute.
4431 */
4432 ClassMember(Comment comment, List<Annotation> metadata)
4433 : super(comment, metadata);
4434 }
4435
4436 /**
4437 * A class type alias.
4438 *
4439 * > classTypeAlias ::=
4440 * > [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplicatio n
4441 * >
4442 * > mixinApplication ::=
4443 * > [TypeName] [WithClause] [ImplementsClause]? ';'
4444 */
4445 class ClassTypeAlias extends TypeAlias {
4446 /**
4447 * The type parameters for the class, or `null` if the class does not have any
4448 * type parameters.
4449 */
4450 TypeParameterList _typeParameters;
4451
4452 /**
4453 * The token for the '=' separating the name from the definition.
4454 */
4455 Token equals;
4456
4457 /**
4458 * The token for the 'abstract' keyword, or `null` if this is not defining an
4459 * abstract class.
4460 */
4461 Token abstractKeyword;
4462
4463 /**
4464 * The name of the superclass of the class being declared.
4465 */
4466 TypeName _superclass;
4467
4468 /**
4469 * The with clause for this class.
4470 */
4471 WithClause _withClause;
4472
4473 /**
4474 * The implements clause for this class, or `null` if there is no implements
4475 * clause.
4476 */
4477 ImplementsClause _implementsClause;
4478
4479 /**
4480 * Initialize a newly created class type alias. Either or both of the
4481 * [comment] and [metadata] can be `null` if the class type alias does not
4482 * have the corresponding attribute. The [typeParameters] can be `null` if the
4483 * class does not have any type parameters. The [abstractKeyword] can be
4484 * `null` if the class is not abstract. The [implementsClause] can be `null`
4485 * if the class does not implement any interfaces.
4486 */
4487 ClassTypeAlias(
4488 Comment comment,
4489 List<Annotation> metadata,
4490 Token keyword,
4491 SimpleIdentifier name,
4492 TypeParameterList typeParameters,
4493 this.equals,
4494 this.abstractKeyword,
4495 TypeName superclass,
4496 WithClause withClause,
4497 ImplementsClause implementsClause,
4498 Token semicolon)
4499 : super(comment, metadata, keyword, name, semicolon) {
4500 _typeParameters = _becomeParentOf(typeParameters);
4501 _superclass = _becomeParentOf(superclass);
4502 _withClause = _becomeParentOf(withClause);
4503 _implementsClause = _becomeParentOf(implementsClause);
4504 }
4505
4506 @override
4507 Iterable get childEntities => super._childEntities
4508 ..add(typedefKeyword)
4509 ..add(_name)
4510 ..add(_typeParameters)
4511 ..add(equals)
4512 ..add(abstractKeyword)
4513 ..add(_superclass)
4514 ..add(_withClause)
4515 ..add(_implementsClause)
4516 ..add(semicolon);
4517
4518 @override
4519 ClassElement get element =>
4520 _name != null ? (_name.staticElement as ClassElement) : null;
4521
4522 /**
4523 * Return the implements clause for this class, or `null` if there is no
4524 * implements clause.
4525 */
4526 ImplementsClause get implementsClause => _implementsClause;
4527
4528 /**
4529 * Set the implements clause for this class to the given [implementsClause].
4530 */
4531 void set implementsClause(ImplementsClause implementsClause) {
4532 _implementsClause = _becomeParentOf(implementsClause);
4533 }
4534
4535 /**
4536 * Return `true` if this class is declared to be an abstract class.
4537 */
4538 bool get isAbstract => abstractKeyword != null;
4539
4540 /**
4541 * Return the name of the superclass of the class being declared.
4542 */
4543 TypeName get superclass => _superclass;
4544
4545 /**
4546 * Set the name of the superclass of the class being declared to the given
4547 * [superclass] name.
4548 */
4549 void set superclass(TypeName superclass) {
4550 _superclass = _becomeParentOf(superclass);
4551 }
4552
4553 /**
4554 * Return the type parameters for the class, or `null` if the class does not
4555 * have any type parameters.
4556 */
4557 TypeParameterList get typeParameters => _typeParameters;
4558
4559 /**
4560 * Set the type parameters for the class to the given list of [typeParameters] .
4561 */
4562 void set typeParameters(TypeParameterList typeParameters) {
4563 _typeParameters = _becomeParentOf(typeParameters);
4564 }
4565
4566 /**
4567 * Return the with clause for this class.
4568 */
4569 WithClause get withClause => _withClause;
4570
4571 /**
4572 * Set the with clause for this class to the given with [withClause].
4573 */
4574 void set withClause(WithClause withClause) {
4575 _withClause = _becomeParentOf(withClause);
4576 }
4577
4578 @override
4579 accept(AstVisitor visitor) => visitor.visitClassTypeAlias(this);
4580
4581 @override
4582 void visitChildren(AstVisitor visitor) {
4583 super.visitChildren(visitor);
4584 _safelyVisitChild(_name, visitor);
4585 _safelyVisitChild(_typeParameters, visitor);
4586 _safelyVisitChild(_superclass, visitor);
4587 _safelyVisitChild(_withClause, visitor);
4588 _safelyVisitChild(_implementsClause, visitor);
4589 }
4590 }
4591
4592 /**
4593 * A combinator associated with an import or export directive.
4594 *
4595 * > combinator ::=
4596 * > [HideCombinator]
4597 * > | [ShowCombinator]
4598 */
4599 abstract class Combinator extends AstNode {
4600 /**
4601 * The 'hide' or 'show' keyword specifying what kind of processing is to be
4602 * done on the names.
4603 */
4604 Token keyword;
4605
4606 /**
4607 * Initialize a newly created combinator.
4608 */
4609 Combinator(this.keyword);
4610
4611 @override
4612 Token get beginToken => keyword;
4613 }
4614
4615 /**
4616 * A comment within the source code.
4617 *
4618 * > comment ::=
4619 * > endOfLineComment
4620 * > | blockComment
4621 * > | documentationComment
4622 * >
4623 * > endOfLineComment ::=
4624 * > '//' (CHARACTER - EOL)* EOL
4625 * >
4626 * > blockComment ::=
4627 * > '/ *' CHARACTER* '&#42;/'
4628 * >
4629 * > documentationComment ::=
4630 * > '/ **' (CHARACTER | [CommentReference])* '&#42;/'
4631 * > | ('///' (CHARACTER - EOL)* EOL)+
4632 */
4633 class Comment extends AstNode {
4634 /**
4635 * The tokens representing the comment.
4636 */
4637 final List<Token> tokens;
4638
4639 /**
4640 * The type of the comment.
4641 */
4642 final CommentType _type;
4643
4644 /**
4645 * The references embedded within the documentation comment. This list will be
4646 * empty unless this is a documentation comment that has references embedded
4647 * within it.
4648 */
4649 NodeList<CommentReference> _references;
4650
4651 /**
4652 * Initialize a newly created comment. The list of [tokens] must contain at
4653 * least one token. The [type] is the type of the comment. The list of
4654 * [references] can be empty if the comment does not contain any embedded
4655 * references.
4656 */
4657 Comment(this.tokens, this._type, List<CommentReference> references) {
4658 _references = new NodeList<CommentReference>(this, references);
4659 }
4660
4661 @override
4662 Token get beginToken => tokens[0];
4663
4664 @override
4665 Iterable get childEntities => new ChildEntities()..addAll(tokens);
4666
4667 @override
4668 Token get endToken => tokens[tokens.length - 1];
4669
4670 /**
4671 * Return `true` if this is a block comment.
4672 */
4673 bool get isBlock => _type == CommentType.BLOCK;
4674
4675 /**
4676 * Return `true` if this is a documentation comment.
4677 */
4678 bool get isDocumentation => _type == CommentType.DOCUMENTATION;
4679
4680 /**
4681 * Return `true` if this is an end-of-line comment.
4682 */
4683 bool get isEndOfLine => _type == CommentType.END_OF_LINE;
4684
4685 /**
4686 * Return the references embedded within the documentation comment.
4687 */
4688 NodeList<CommentReference> get references => _references;
4689
4690 @override
4691 accept(AstVisitor visitor) => visitor.visitComment(this);
4692
4693 @override
4694 void visitChildren(AstVisitor visitor) {
4695 _references.accept(visitor);
4696 }
4697
4698 /**
4699 * Create a block comment consisting of the given [tokens].
4700 */
4701 static Comment createBlockComment(List<Token> tokens) =>
4702 new Comment(tokens, CommentType.BLOCK, null);
4703
4704 /**
4705 * Create a documentation comment consisting of the given [tokens].
4706 */
4707 static Comment createDocumentationComment(List<Token> tokens) => new Comment(
4708 tokens, CommentType.DOCUMENTATION, new List<CommentReference>());
4709
4710 /**
4711 * Create a documentation comment consisting of the given [tokens] and having
4712 * the given [references] embedded within it.
4713 */
4714 static Comment createDocumentationCommentWithReferences(
4715 List<Token> tokens, List<CommentReference> references) =>
4716 new Comment(tokens, CommentType.DOCUMENTATION, references);
4717
4718 /**
4719 * Create an end-of-line comment consisting of the given [tokens].
4720 */
4721 static Comment createEndOfLineComment(List<Token> tokens) =>
4722 new Comment(tokens, CommentType.END_OF_LINE, null);
4723 }
4724
4725 /**
4726 * A reference to a Dart element that is found within a documentation comment.
4727 *
4728 * > commentReference ::=
4729 * > '[' 'new'? [Identifier] ']'
4730 */
4731 class CommentReference extends AstNode {
4732 /**
4733 * The token representing the 'new' keyword, or `null` if there was no 'new'
4734 * keyword.
4735 */
4736 Token newKeyword;
4737
4738 /**
4739 * The identifier being referenced.
4740 */
4741 Identifier _identifier;
4742
4743 /**
4744 * Initialize a newly created reference to a Dart element. The [newKeyword]
4745 * can be `null` if the reference is not to a constructor.
4746 */
4747 CommentReference(this.newKeyword, Identifier identifier) {
4748 _identifier = _becomeParentOf(identifier);
4749 }
4750
4751 @override
4752 Token get beginToken => _identifier.beginToken;
4753
4754 @override
4755 Iterable get childEntities =>
4756 new ChildEntities()..add(newKeyword)..add(_identifier);
4757
4758 @override
4759 Token get endToken => _identifier.endToken;
4760
4761 /**
4762 * Return the identifier being referenced.
4763 */
4764 Identifier get identifier => _identifier;
4765
4766 /**
4767 * Set the identifier being referenced to the given [identifier].
4768 */
4769 void set identifier(Identifier identifier) {
4770 _identifier = _becomeParentOf(identifier);
4771 }
4772
4773 @override
4774 accept(AstVisitor visitor) => visitor.visitCommentReference(this);
4775
4776 @override
4777 void visitChildren(AstVisitor visitor) {
4778 _safelyVisitChild(_identifier, visitor);
4779 }
4780 }
4781
4782 /**
4783 * The possible types of comments that are recognized by the parser.
4784 */
4785 class CommentType {
4786 /**
4787 * A block comment.
4788 */
4789 static const CommentType BLOCK = const CommentType('BLOCK');
4790
4791 /**
4792 * A documentation comment.
4793 */
4794 static const CommentType DOCUMENTATION = const CommentType('DOCUMENTATION');
4795
4796 /**
4797 * An end-of-line comment.
4798 */
4799 static const CommentType END_OF_LINE = const CommentType('END_OF_LINE');
4800
4801 /**
4802 * The name of the comment type.
4803 */
4804 final String name;
4805
4806 /**
4807 * Initialize a newly created comment type to have the given [name].
4808 */
4809 const CommentType(this.name);
4810
4811 @override
4812 String toString() => name;
4813 }
4814
4815 /**
4816 * A compilation unit.
4817 *
4818 * While the grammar restricts the order of the directives and declarations
4819 * within a compilation unit, this class does not enforce those restrictions.
4820 * In particular, the children of a compilation unit will be visited in lexical
4821 * order even if lexical order does not conform to the restrictions of the
4822 * grammar.
4823 *
4824 * > compilationUnit ::=
4825 * > directives declarations
4826 * >
4827 * > directives ::=
4828 * > [ScriptTag]? [LibraryDirective]? namespaceDirective* [PartDirective]*
4829 * > | [PartOfDirective]
4830 * >
4831 * > namespaceDirective ::=
4832 * > [ImportDirective]
4833 * > | [ExportDirective]
4834 * >
4835 * > declarations ::=
4836 * > [CompilationUnitMember]*
4837 */
4838 class CompilationUnit extends AstNode {
4839 /**
4840 * The first token in the token stream that was parsed to form this
4841 * compilation unit.
4842 */
4843 Token beginToken;
4844
4845 /**
4846 * The script tag at the beginning of the compilation unit, or `null` if there
4847 * is no script tag in this compilation unit.
4848 */
4849 ScriptTag _scriptTag;
4850
4851 /**
4852 * The directives contained in this compilation unit.
4853 */
4854 NodeList<Directive> _directives;
4855
4856 /**
4857 * The declarations contained in this compilation unit.
4858 */
4859 NodeList<CompilationUnitMember> _declarations;
4860
4861 /**
4862 * The last token in the token stream that was parsed to form this compilation
4863 * unit. This token should always have a type of [TokenType.EOF].
4864 */
4865 Token endToken;
4866
4867 /**
4868 * The element associated with this compilation unit, or `null` if the AST
4869 * structure has not been resolved.
4870 */
4871 CompilationUnitElement element;
4872
4873 /**
4874 * The line information for this compilation unit.
4875 */
4876 LineInfo lineInfo;
4877
4878 /**
4879 * Initialize a newly created compilation unit to have the given directives
4880 * and declarations. The [scriptTag] can be `null` if there is no script tag
4881 * in the compilation unit. The list of [directives] can be `null` if there
4882 * are no directives in the compilation unit. The list of [declarations] can
4883 * be `null` if there are no declarations in the compilation unit.
4884 */
4885 CompilationUnit(
4886 this.beginToken,
4887 ScriptTag scriptTag,
4888 List<Directive> directives,
4889 List<CompilationUnitMember> declarations,
4890 this.endToken) {
4891 _scriptTag = _becomeParentOf(scriptTag);
4892 _directives = new NodeList<Directive>(this, directives);
4893 _declarations = new NodeList<CompilationUnitMember>(this, declarations);
4894 }
4895
4896 @override
4897 Iterable get childEntities {
4898 ChildEntities result = new ChildEntities()..add(_scriptTag);
4899 if (_directivesAreBeforeDeclarations) {
4900 result..addAll(_directives)..addAll(_declarations);
4901 } else {
4902 result.addAll(sortedDirectivesAndDeclarations);
4903 }
4904 return result;
4905 }
4906
4907 /**
4908 * Return the declarations contained in this compilation unit.
4909 */
4910 NodeList<CompilationUnitMember> get declarations => _declarations;
4911
4912 /**
4913 * Return the directives contained in this compilation unit.
4914 */
4915 NodeList<Directive> get directives => _directives;
4916
4917 @override
4918 int get length {
4919 Token endToken = this.endToken;
4920 if (endToken == null) {
4921 return 0;
4922 }
4923 return endToken.offset + endToken.length;
4924 }
4925
4926 @override
4927 int get offset => 0;
4928
4929 /**
4930 * Return the script tag at the beginning of the compilation unit, or `null`
4931 * if there is no script tag in this compilation unit.
4932 */
4933 ScriptTag get scriptTag => _scriptTag;
4934
4935 /**
4936 * Set the script tag at the beginning of the compilation unit to the given
4937 * [scriptTag].
4938 */
4939 void set scriptTag(ScriptTag scriptTag) {
4940 _scriptTag = _becomeParentOf(scriptTag);
4941 }
4942
4943 /**
4944 * Return a list containing all of the directives and declarations in this
4945 * compilation unit, sorted in lexical order.
4946 */
4947 List<AstNode> get sortedDirectivesAndDeclarations {
4948 return <AstNode>[]
4949 ..addAll(_directives)
4950 ..addAll(_declarations)
4951 ..sort(AstNode.LEXICAL_ORDER);
4952 }
4953
4954 /**
4955 * Return `true` if all of the directives are lexically before any
4956 * declarations.
4957 */
4958 bool get _directivesAreBeforeDeclarations {
4959 if (_directives.isEmpty || _declarations.isEmpty) {
4960 return true;
4961 }
4962 Directive lastDirective = _directives[_directives.length - 1];
4963 CompilationUnitMember firstDeclaration = _declarations[0];
4964 return lastDirective.offset < firstDeclaration.offset;
4965 }
4966
4967 @override
4968 accept(AstVisitor visitor) => visitor.visitCompilationUnit(this);
4969
4970 @override
4971 void visitChildren(AstVisitor visitor) {
4972 _safelyVisitChild(_scriptTag, visitor);
4973 if (_directivesAreBeforeDeclarations) {
4974 _directives.accept(visitor);
4975 _declarations.accept(visitor);
4976 } else {
4977 for (AstNode child in sortedDirectivesAndDeclarations) {
4978 child.accept(visitor);
4979 }
4980 }
4981 }
4982 }
4983
4984 /**
4985 * A node that declares one or more names within the scope of a compilation
4986 * unit.
4987 *
4988 * > compilationUnitMember ::=
4989 * > [ClassDeclaration]
4990 * > | [TypeAlias]
4991 * > | [FunctionDeclaration]
4992 * > | [MethodDeclaration]
4993 * > | [VariableDeclaration]
4994 * > | [VariableDeclaration]
4995 */
4996 abstract class CompilationUnitMember extends Declaration {
4997 /**
4998 * Initialize a newly created generic compilation unit member. Either or both
4999 * of the [comment] and [metadata] can be `null` if the member does not have
5000 * the corresponding attribute.
5001 */
5002 CompilationUnitMember(Comment comment, List<Annotation> metadata)
5003 : super(comment, metadata);
5004 }
5005
5006 /**
5007 * A conditional expression.
5008 *
5009 * > conditionalExpression ::=
5010 * > [Expression] '?' [Expression] ':' [Expression]
5011 */
5012 class ConditionalExpression extends Expression {
5013 /**
5014 * The condition used to determine which of the expressions is executed next.
5015 */
5016 Expression _condition;
5017
5018 /**
5019 * The token used to separate the condition from the then expression.
5020 */
5021 Token question;
5022
5023 /**
5024 * The expression that is executed if the condition evaluates to `true`.
5025 */
5026 Expression _thenExpression;
5027
5028 /**
5029 * The token used to separate the then expression from the else expression.
5030 */
5031 Token colon;
5032
5033 /**
5034 * The expression that is executed if the condition evaluates to `false`.
5035 */
5036 Expression _elseExpression;
5037
5038 /**
5039 * Initialize a newly created conditional expression.
5040 */
5041 ConditionalExpression(Expression condition, this.question,
5042 Expression thenExpression, this.colon, Expression elseExpression) {
5043 _condition = _becomeParentOf(condition);
5044 _thenExpression = _becomeParentOf(thenExpression);
5045 _elseExpression = _becomeParentOf(elseExpression);
5046 }
5047
5048 @override
5049 Token get beginToken => _condition.beginToken;
5050
5051 @override
5052 Iterable get childEntities => new ChildEntities()
5053 ..add(_condition)
5054 ..add(question)
5055 ..add(_thenExpression)
5056 ..add(colon)
5057 ..add(_elseExpression);
5058
5059 /**
5060 * Return the condition used to determine which of the expressions is executed
5061 * next.
5062 */
5063 Expression get condition => _condition;
5064
5065 /**
5066 * Set the condition used to determine which of the expressions is executed
5067 * next to the given [expression].
5068 */
5069 void set condition(Expression expression) {
5070 _condition = _becomeParentOf(expression);
5071 }
5072
5073 /**
5074 * Return the expression that is executed if the condition evaluates to
5075 * `false`.
5076 */
5077 Expression get elseExpression => _elseExpression;
5078
5079 /**
5080 * Set the expression that is executed if the condition evaluates to `false`
5081 * to the given [expression].
5082 */
5083 void set elseExpression(Expression expression) {
5084 _elseExpression = _becomeParentOf(expression);
5085 }
5086
5087 @override
5088 Token get endToken => _elseExpression.endToken;
5089
5090 @override
5091 int get precedence => 3;
5092
5093 /**
5094 * Return the expression that is executed if the condition evaluates to
5095 * `true`.
5096 */
5097 Expression get thenExpression => _thenExpression;
5098
5099 /**
5100 * Set the expression that is executed if the condition evaluates to `true` to
5101 * the given [expression].
5102 */
5103 void set thenExpression(Expression expression) {
5104 _thenExpression = _becomeParentOf(expression);
5105 }
5106
5107 @override
5108 accept(AstVisitor visitor) => visitor.visitConditionalExpression(this);
5109
5110 @override
5111 void visitChildren(AstVisitor visitor) {
5112 _safelyVisitChild(_condition, visitor);
5113 _safelyVisitChild(_thenExpression, visitor);
5114 _safelyVisitChild(_elseExpression, visitor);
5115 }
5116 }
5117
5118 /// Instances of the class [ConstantEvaluator] evaluate constant expressions to
5119 /// produce their compile-time value.
5120 ///
5121 /// According to the Dart Language Specification:
5122 ///
5123 /// > A constant expression is one of the following:
5124 /// >
5125 /// > * A literal number.
5126 /// > * A literal boolean.
5127 /// > * A literal string where any interpolated expression is a compile-time
5128 /// > constant that evaluates to a numeric, string or boolean value or to
5129 /// > **null**.
5130 /// > * A literal symbol.
5131 /// > * **null**.
5132 /// > * A qualified reference to a static constant variable.
5133 /// > * An identifier expression that denotes a constant variable, class or type
5134 /// > alias.
5135 /// > * A constant constructor invocation.
5136 /// > * A constant list literal.
5137 /// > * A constant map literal.
5138 /// > * A simple or qualified identifier denoting a top-level function or a
5139 /// > static method.
5140 /// > * A parenthesized expression _(e)_ where _e_ is a constant expression.
5141 /// > * <span>
5142 /// > An expression of the form <i>identical(e<sub>1</sub>, e<sub>2</sub>)</i>
5143 /// > where <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5144 /// > expressions and <i>identical()</i> is statically bound to the predefined
5145 /// > dart function <i>identical()</i> discussed above.
5146 /// > </span>
5147 /// > * <span>
5148 /// > An expression of one of the forms <i>e<sub>1</sub> == e<sub>2</sub></i>
5149 /// > or <i>e<sub>1</sub> != e<sub>2</sub></i> where <i>e<sub>1</sub></i> and
5150 /// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a
5151 /// > numeric, string or boolean value.
5152 /// > </span>
5153 /// > * <span>
5154 /// > An expression of one of the forms <i>!e</i>, <i>e<sub>1</sub> &amp;&amp;
5155 /// > e<sub>2</sub></i> or <i>e<sub>1</sub> || e<sub>2</sub></i>, where
5156 /// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5157 /// > expressions that evaluate to a boolean value.
5158 /// > </span>
5159 /// > * <span>
5160 /// > An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^
5161 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> &amp; e<sub>2</sub></i>,
5162 /// > <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;&gt;
5163 /// > e<sub>2</sub></i> or <i>e<sub>1</sub> &lt;&lt; e<sub>2</sub></i>, where
5164 /// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
5165 /// > expressions that evaluate to an integer value or to <b>null</b>.
5166 /// > </span>
5167 /// > * <span>
5168 /// > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> +
5169 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>,
5170 /// > <i>e<sub>1</sub> * e<sub>2</sub></i>, <i>e<sub>1</sub> /
5171 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>,
5172 /// > <i>e<sub>1</sub> &gt; e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;
5173 /// > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;= e<sub>2</sub></i>,
5174 /// > <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</sub> %
5175 /// > e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and
5176 /// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric
5177 /// > value or to <b>null</b>.
5178 /// > </span>
5179 /// > * <span>
5180 /// > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> :
5181 /// > e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and
5182 /// > <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i>
5183 /// > evaluates to a boolean value.
5184 /// > </span>
5185 ///
5186 /// The values returned by instances of this class are therefore `null` and
5187 /// instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
5188 /// `DartObject`.
5189 ///
5190 /// In addition, this class defines several values that can be returned to
5191 /// indicate various conditions encountered during evaluation. These are
5192 /// documented with the static fields that define those values.
5193 class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
5194 /**
5195 * The value returned for expressions (or non-expression nodes) that are not
5196 * compile-time constant expressions.
5197 */
5198 static Object NOT_A_CONSTANT = new Object();
5199
5200 @override
5201 Object visitAdjacentStrings(AdjacentStrings node) {
5202 StringBuffer buffer = new StringBuffer();
5203 for (StringLiteral string in node.strings) {
5204 Object value = string.accept(this);
5205 if (identical(value, NOT_A_CONSTANT)) {
5206 return value;
5207 }
5208 buffer.write(value);
5209 }
5210 return buffer.toString();
5211 }
5212
5213 @override
5214 Object visitBinaryExpression(BinaryExpression node) {
5215 Object leftOperand = node.leftOperand.accept(this);
5216 if (identical(leftOperand, NOT_A_CONSTANT)) {
5217 return leftOperand;
5218 }
5219 Object rightOperand = node.rightOperand.accept(this);
5220 if (identical(rightOperand, NOT_A_CONSTANT)) {
5221 return rightOperand;
5222 }
5223 while (true) {
5224 if (node.operator.type == TokenType.AMPERSAND) {
5225 // integer or {@code null}
5226 if (leftOperand is int && rightOperand is int) {
5227 return leftOperand & rightOperand;
5228 }
5229 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) {
5230 // boolean or {@code null}
5231 if (leftOperand is bool && rightOperand is bool) {
5232 return leftOperand && rightOperand;
5233 }
5234 } else if (node.operator.type == TokenType.BANG_EQ) {
5235 // numeric, string, boolean, or {@code null}
5236 if (leftOperand is bool && rightOperand is bool) {
5237 return leftOperand != rightOperand;
5238 } else if (leftOperand is num && rightOperand is num) {
5239 return leftOperand != rightOperand;
5240 } else if (leftOperand is String && rightOperand is String) {
5241 return leftOperand != rightOperand;
5242 }
5243 } else if (node.operator.type == TokenType.BAR) {
5244 // integer or {@code null}
5245 if (leftOperand is int && rightOperand is int) {
5246 return leftOperand | rightOperand;
5247 }
5248 } else if (node.operator.type == TokenType.BAR_BAR) {
5249 // boolean or {@code null}
5250 if (leftOperand is bool && rightOperand is bool) {
5251 return leftOperand || rightOperand;
5252 }
5253 } else if (node.operator.type == TokenType.CARET) {
5254 // integer or {@code null}
5255 if (leftOperand is int && rightOperand is int) {
5256 return leftOperand ^ rightOperand;
5257 }
5258 } else if (node.operator.type == TokenType.EQ_EQ) {
5259 // numeric, string, boolean, or {@code null}
5260 if (leftOperand is bool && rightOperand is bool) {
5261 return leftOperand == rightOperand;
5262 } else if (leftOperand is num && rightOperand is num) {
5263 return leftOperand == rightOperand;
5264 } else if (leftOperand is String && rightOperand is String) {
5265 return leftOperand == rightOperand;
5266 }
5267 } else if (node.operator.type == TokenType.GT) {
5268 // numeric or {@code null}
5269 if (leftOperand is num && rightOperand is num) {
5270 return leftOperand.compareTo(rightOperand) > 0;
5271 }
5272 } else if (node.operator.type == TokenType.GT_EQ) {
5273 // numeric or {@code null}
5274 if (leftOperand is num && rightOperand is num) {
5275 return leftOperand.compareTo(rightOperand) >= 0;
5276 }
5277 } else if (node.operator.type == TokenType.GT_GT) {
5278 // integer or {@code null}
5279 if (leftOperand is int && rightOperand is int) {
5280 return leftOperand >> rightOperand;
5281 }
5282 } else if (node.operator.type == TokenType.LT) {
5283 // numeric or {@code null}
5284 if (leftOperand is num && rightOperand is num) {
5285 return leftOperand.compareTo(rightOperand) < 0;
5286 }
5287 } else if (node.operator.type == TokenType.LT_EQ) {
5288 // numeric or {@code null}
5289 if (leftOperand is num && rightOperand is num) {
5290 return leftOperand.compareTo(rightOperand) <= 0;
5291 }
5292 } else if (node.operator.type == TokenType.LT_LT) {
5293 // integer or {@code null}
5294 if (leftOperand is int && rightOperand is int) {
5295 return leftOperand << rightOperand;
5296 }
5297 } else if (node.operator.type == TokenType.MINUS) {
5298 // numeric or {@code null}
5299 if (leftOperand is num && rightOperand is num) {
5300 return leftOperand - rightOperand;
5301 }
5302 } else if (node.operator.type == TokenType.PERCENT) {
5303 // numeric or {@code null}
5304 if (leftOperand is num && rightOperand is num) {
5305 return leftOperand.remainder(rightOperand);
5306 }
5307 } else if (node.operator.type == TokenType.PLUS) {
5308 // numeric or {@code null}
5309 if (leftOperand is num && rightOperand is num) {
5310 return leftOperand + rightOperand;
5311 }
5312 } else if (node.operator.type == TokenType.STAR) {
5313 // numeric or {@code null}
5314 if (leftOperand is num && rightOperand is num) {
5315 return leftOperand * rightOperand;
5316 }
5317 } else if (node.operator.type == TokenType.SLASH) {
5318 // numeric or {@code null}
5319 if (leftOperand is num && rightOperand is num) {
5320 return leftOperand / rightOperand;
5321 }
5322 } else if (node.operator.type == TokenType.TILDE_SLASH) {
5323 // numeric or {@code null}
5324 if (leftOperand is num && rightOperand is num) {
5325 return leftOperand ~/ rightOperand;
5326 }
5327 } else {}
5328 break;
5329 }
5330 // TODO(brianwilkerson) This doesn't handle numeric conversions.
5331 return visitExpression(node);
5332 }
5333
5334 @override
5335 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
5336
5337 @override
5338 Object visitDoubleLiteral(DoubleLiteral node) => node.value;
5339
5340 @override
5341 Object visitIntegerLiteral(IntegerLiteral node) => node.value;
5342
5343 @override
5344 Object visitInterpolationExpression(InterpolationExpression node) {
5345 Object value = node.expression.accept(this);
5346 if (value == null || value is bool || value is String || value is num) {
5347 return value;
5348 }
5349 return NOT_A_CONSTANT;
5350 }
5351
5352 @override
5353 Object visitInterpolationString(InterpolationString node) => node.value;
5354
5355 @override
5356 Object visitListLiteral(ListLiteral node) {
5357 List<Object> list = new List<Object>();
5358 for (Expression element in node.elements) {
5359 Object value = element.accept(this);
5360 if (identical(value, NOT_A_CONSTANT)) {
5361 return value;
5362 }
5363 list.add(value);
5364 }
5365 return list;
5366 }
5367
5368 @override
5369 Object visitMapLiteral(MapLiteral node) {
5370 HashMap<String, Object> map = new HashMap<String, Object>();
5371 for (MapLiteralEntry entry in node.entries) {
5372 Object key = entry.key.accept(this);
5373 Object value = entry.value.accept(this);
5374 if (key is! String || identical(value, NOT_A_CONSTANT)) {
5375 return NOT_A_CONSTANT;
5376 }
5377 map[(key as String)] = value;
5378 }
5379 return map;
5380 }
5381
5382 @override
5383 Object visitMethodInvocation(MethodInvocation node) => visitNode(node);
5384
5385 @override
5386 Object visitNode(AstNode node) => NOT_A_CONSTANT;
5387
5388 @override
5389 Object visitNullLiteral(NullLiteral node) => null;
5390
5391 @override
5392 Object visitParenthesizedExpression(ParenthesizedExpression node) =>
5393 node.expression.accept(this);
5394
5395 @override
5396 Object visitPrefixedIdentifier(PrefixedIdentifier node) =>
5397 _getConstantValue(null);
5398
5399 @override
5400 Object visitPrefixExpression(PrefixExpression node) {
5401 Object operand = node.operand.accept(this);
5402 if (identical(operand, NOT_A_CONSTANT)) {
5403 return operand;
5404 }
5405 while (true) {
5406 if (node.operator.type == TokenType.BANG) {
5407 if (identical(operand, true)) {
5408 return false;
5409 } else if (identical(operand, false)) {
5410 return true;
5411 }
5412 } else if (node.operator.type == TokenType.TILDE) {
5413 if (operand is int) {
5414 return ~operand;
5415 }
5416 } else if (node.operator.type == TokenType.MINUS) {
5417 if (operand == null) {
5418 return null;
5419 } else if (operand is num) {
5420 return -operand;
5421 }
5422 } else {}
5423 break;
5424 }
5425 return NOT_A_CONSTANT;
5426 }
5427
5428 @override
5429 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null);
5430
5431 @override
5432 Object visitSimpleIdentifier(SimpleIdentifier node) =>
5433 _getConstantValue(null);
5434
5435 @override
5436 Object visitSimpleStringLiteral(SimpleStringLiteral node) => node.value;
5437
5438 @override
5439 Object visitStringInterpolation(StringInterpolation node) {
5440 StringBuffer buffer = new StringBuffer();
5441 for (InterpolationElement element in node.elements) {
5442 Object value = element.accept(this);
5443 if (identical(value, NOT_A_CONSTANT)) {
5444 return value;
5445 }
5446 buffer.write(value);
5447 }
5448 return buffer.toString();
5449 }
5450
5451 @override
5452 Object visitSymbolLiteral(SymbolLiteral node) {
5453 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String.
5454 StringBuffer buffer = new StringBuffer();
5455 for (Token component in node.components) {
5456 if (buffer.length > 0) {
5457 buffer.writeCharCode(0x2E);
5458 }
5459 buffer.write(component.lexeme);
5460 }
5461 return buffer.toString();
5462 }
5463
5464 /**
5465 * Return the constant value of the static constant represented by the given
5466 * [element].
5467 */
5468 Object _getConstantValue(Element element) {
5469 // TODO(brianwilkerson) Implement this
5470 if (element is FieldElement) {
5471 FieldElement field = element;
5472 if (field.isStatic && field.isConst) {
5473 //field.getConstantValue();
5474 }
5475 // } else if (element instanceof VariableElement) {
5476 // VariableElement variable = (VariableElement) element;
5477 // if (variable.isStatic() && variable.isConst()) {
5478 // //variable.getConstantValue();
5479 // }
5480 }
5481 return NOT_A_CONSTANT;
5482 }
5483 }
5484
5485 /**
5486 * A constructor declaration.
5487 *
5488 * > constructorDeclaration ::=
5489 * > constructorSignature [FunctionBody]?
5490 * > | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier]) ? arguments
5491 * >
5492 * > constructorSignature ::=
5493 * > 'external'? constructorName formalParameterList initializerList?
5494 * > | 'external'? 'factory' factoryName formalParameterList initializerList?
5495 * > | 'external'? 'const' constructorName formalParameterList initializerLis t?
5496 * >
5497 * > constructorName ::=
5498 * > [SimpleIdentifier] ('.' [SimpleIdentifier])?
5499 * >
5500 * > factoryName ::=
5501 * > [Identifier] ('.' [SimpleIdentifier])?
5502 * >
5503 * > initializerList ::=
5504 * > ':' [ConstructorInitializer] (',' [ConstructorInitializer])*
5505 */
5506 class ConstructorDeclaration extends ClassMember {
5507 /**
5508 * The token for the 'external' keyword, or `null` if the constructor is not
5509 * external.
5510 */
5511 Token externalKeyword;
5512
5513 /**
5514 * The token for the 'const' keyword, or `null` if the constructor is not a
5515 * const constructor.
5516 */
5517 Token constKeyword;
5518
5519 /**
5520 * The token for the 'factory' keyword, or `null` if the constructor is not a
5521 * factory constructor.
5522 */
5523 Token factoryKeyword;
5524
5525 /**
5526 * The type of object being created. This can be different than the type in
5527 * which the constructor is being declared if the constructor is the
5528 * implementation of a factory constructor.
5529 */
5530 Identifier _returnType;
5531
5532 /**
5533 * The token for the period before the constructor name, or `null` if the
5534 * constructor being declared is unnamed.
5535 */
5536 Token period;
5537
5538 /**
5539 * The name of the constructor, or `null` if the constructor being declared is
5540 * unnamed.
5541 */
5542 SimpleIdentifier _name;
5543
5544 /**
5545 * The parameters associated with the constructor.
5546 */
5547 FormalParameterList _parameters;
5548
5549 /**
5550 * The token for the separator (colon or equals) before the initializer list
5551 * or redirection, or `null` if there are no initializers.
5552 */
5553 Token separator;
5554
5555 /**
5556 * The initializers associated with the constructor.
5557 */
5558 NodeList<ConstructorInitializer> _initializers;
5559
5560 /**
5561 * The name of the constructor to which this constructor will be redirected,
5562 * or `null` if this is not a redirecting factory constructor.
5563 */
5564 ConstructorName _redirectedConstructor;
5565
5566 /**
5567 * The body of the constructor, or `null` if the constructor does not have a
5568 * body.
5569 */
5570 FunctionBody _body;
5571
5572 /**
5573 * The element associated with this constructor, or `null` if the AST
5574 * structure has not been resolved or if this constructor could not be
5575 * resolved.
5576 */
5577 ConstructorElement element;
5578
5579 /**
5580 * Initialize a newly created constructor declaration. The [externalKeyword]
5581 * can be `null` if the constructor is not external. Either or both of the
5582 * [comment] and [metadata] can be `null` if the constructor does not have the
5583 * corresponding attribute. The [constKeyword] can be `null` if the
5584 * constructor cannot be used to create a constant. The [factoryKeyword] can
5585 * be `null` if the constructor is not a factory. The [period] and [name] can
5586 * both be `null` if the constructor is not a named constructor. The
5587 * [separator] can be `null` if the constructor does not have any initializers
5588 * and does not redirect to a different constructor. The list of
5589 * [initializers] can be `null` if the constructor does not have any
5590 * initializers. The [redirectedConstructor] can be `null` if the constructor
5591 * does not redirect to a different constructor. The [body] can be `null` if
5592 * the constructor does not have a body.
5593 */
5594 ConstructorDeclaration(
5595 Comment comment,
5596 List<Annotation> metadata,
5597 this.externalKeyword,
5598 this.constKeyword,
5599 this.factoryKeyword,
5600 Identifier returnType,
5601 this.period,
5602 SimpleIdentifier name,
5603 FormalParameterList parameters,
5604 this.separator,
5605 List<ConstructorInitializer> initializers,
5606 ConstructorName redirectedConstructor,
5607 FunctionBody body)
5608 : super(comment, metadata) {
5609 _returnType = _becomeParentOf(returnType);
5610 _name = _becomeParentOf(name);
5611 _parameters = _becomeParentOf(parameters);
5612 _initializers = new NodeList<ConstructorInitializer>(this, initializers);
5613 _redirectedConstructor = _becomeParentOf(redirectedConstructor);
5614 _body = _becomeParentOf(body);
5615 }
5616
5617 /**
5618 * Return the body of the constructor, or `null` if the constructor does not
5619 * have a body.
5620 */
5621 FunctionBody get body => _body;
5622
5623 /**
5624 * Set the body of the constructor to the given [functionBody].
5625 */
5626 void set body(FunctionBody functionBody) {
5627 _body = _becomeParentOf(functionBody);
5628 }
5629
5630 @override
5631 Iterable get childEntities => super._childEntities
5632 ..add(externalKeyword)
5633 ..add(constKeyword)
5634 ..add(factoryKeyword)
5635 ..add(_returnType)
5636 ..add(period)
5637 ..add(_name)
5638 ..add(_parameters)
5639 ..add(separator)
5640 ..addAll(initializers)
5641 ..add(_redirectedConstructor)
5642 ..add(_body);
5643
5644 @override
5645 Token get endToken {
5646 if (_body != null) {
5647 return _body.endToken;
5648 } else if (!_initializers.isEmpty) {
5649 return _initializers.endToken;
5650 }
5651 return _parameters.endToken;
5652 }
5653
5654 @override
5655 Token get firstTokenAfterCommentAndMetadata {
5656 Token leftMost =
5657 Token.lexicallyFirst([externalKeyword, constKeyword, factoryKeyword]);
5658 if (leftMost != null) {
5659 return leftMost;
5660 }
5661 return _returnType.beginToken;
5662 }
5663
5664 /**
5665 * Return the initializers associated with the constructor.
5666 */
5667 NodeList<ConstructorInitializer> get initializers => _initializers;
5668
5669 /**
5670 * Return the name of the constructor, or `null` if the constructor being
5671 * declared is unnamed.
5672 */
5673 SimpleIdentifier get name => _name;
5674
5675 /**
5676 * Set the name of the constructor to the given [identifier].
5677 */
5678 void set name(SimpleIdentifier identifier) {
5679 _name = _becomeParentOf(identifier);
5680 }
5681
5682 /**
5683 * Return the parameters associated with the constructor.
5684 */
5685 FormalParameterList get parameters => _parameters;
5686
5687 /**
5688 * Set the parameters associated with the constructor to the given list of
5689 * [parameters].
5690 */
5691 void set parameters(FormalParameterList parameters) {
5692 _parameters = _becomeParentOf(parameters);
5693 }
5694
5695 /**
5696 * Return the name of the constructor to which this constructor will be
5697 * redirected, or `null` if this is not a redirecting factory constructor.
5698 */
5699 ConstructorName get redirectedConstructor => _redirectedConstructor;
5700
5701 /**
5702 * Set the name of the constructor to which this constructor will be
5703 * redirected to the given [redirectedConstructor] name.
5704 */
5705 void set redirectedConstructor(ConstructorName redirectedConstructor) {
5706 _redirectedConstructor = _becomeParentOf(redirectedConstructor);
5707 }
5708
5709 /**
5710 * Return the type of object being created. This can be different than the
5711 * type in which the constructor is being declared if the constructor is the
5712 * implementation of a factory constructor.
5713 */
5714 Identifier get returnType => _returnType;
5715
5716 /**
5717 * Set the type of object being created to the given [typeName].
5718 */
5719 void set returnType(Identifier typeName) {
5720 _returnType = _becomeParentOf(typeName);
5721 }
5722
5723 @override
5724 accept(AstVisitor visitor) => visitor.visitConstructorDeclaration(this);
5725
5726 @override
5727 void visitChildren(AstVisitor visitor) {
5728 super.visitChildren(visitor);
5729 _safelyVisitChild(_returnType, visitor);
5730 _safelyVisitChild(_name, visitor);
5731 _safelyVisitChild(_parameters, visitor);
5732 _initializers.accept(visitor);
5733 _safelyVisitChild(_redirectedConstructor, visitor);
5734 _safelyVisitChild(_body, visitor);
5735 }
5736 }
5737
5738 /**
5739 * The initialization of a field within a constructor's initialization list.
5740 *
5741 * > fieldInitializer ::=
5742 * > ('this' '.')? [SimpleIdentifier] '=' [Expression]
5743 */
5744 class ConstructorFieldInitializer extends ConstructorInitializer {
5745 /**
5746 * The token for the 'this' keyword, or `null` if there is no 'this' keyword.
5747 */
5748 Token thisKeyword;
5749
5750 /**
5751 * The token for the period after the 'this' keyword, or `null` if there is no
5752 * 'this' keyword.
5753 */
5754 Token period;
5755
5756 /**
5757 * The name of the field being initialized.
5758 */
5759 SimpleIdentifier _fieldName;
5760
5761 /**
5762 * The token for the equal sign between the field name and the expression.
5763 */
5764 Token equals;
5765
5766 /**
5767 * The expression computing the value to which the field will be initialized.
5768 */
5769 Expression _expression;
5770
5771 /**
5772 * Initialize a newly created field initializer to initialize the field with
5773 * the given name to the value of the given expression. The [thisKeyword] and
5774 * [period] can be `null` if the 'this' keyword was not specified.
5775 */
5776 ConstructorFieldInitializer(this.thisKeyword, this.period,
5777 SimpleIdentifier fieldName, this.equals, Expression expression) {
5778 _fieldName = _becomeParentOf(fieldName);
5779 _expression = _becomeParentOf(expression);
5780 }
5781
5782 @override
5783 Token get beginToken {
5784 if (thisKeyword != null) {
5785 return thisKeyword;
5786 }
5787 return _fieldName.beginToken;
5788 }
5789
5790 @override
5791 Iterable get childEntities => new ChildEntities()
5792 ..add(thisKeyword)
5793 ..add(period)
5794 ..add(_fieldName)
5795 ..add(equals)
5796 ..add(_expression);
5797
5798 @override
5799 Token get endToken => _expression.endToken;
5800
5801 /**
5802 * Return the expression computing the value to which the field will be
5803 * initialized.
5804 */
5805 Expression get expression => _expression;
5806
5807 /**
5808 * Set the expression computing the value to which the field will be
5809 * initialized to the given [expression].
5810 */
5811 void set expression(Expression expression) {
5812 _expression = _becomeParentOf(expression);
5813 }
5814
5815 /**
5816 * Return the name of the field being initialized.
5817 */
5818 SimpleIdentifier get fieldName => _fieldName;
5819
5820 /**
5821 * Set the name of the field being initialized to the given [identifier].
5822 */
5823 void set fieldName(SimpleIdentifier identifier) {
5824 _fieldName = _becomeParentOf(identifier);
5825 }
5826
5827 /**
5828 * Return the token for the 'this' keyword, or `null` if there is no 'this'
5829 * keyword.
5830 */
5831 @deprecated // Use "this.thisKeyword"
5832 Token get keyword => thisKeyword;
5833
5834 /**
5835 * Set the token for the 'this' keyword to the given [token].
5836 */
5837 @deprecated // Use "this.thisKeyword"
5838 set keyword(Token token) {
5839 thisKeyword = token;
5840 }
5841
5842 @override
5843 accept(AstVisitor visitor) => visitor.visitConstructorFieldInitializer(this);
5844
5845 @override
5846 void visitChildren(AstVisitor visitor) {
5847 _safelyVisitChild(_fieldName, visitor);
5848 _safelyVisitChild(_expression, visitor);
5849 }
5850 }
5851
5852 /**
5853 * A node that can occur in the initializer list of a constructor declaration.
5854 *
5855 * > constructorInitializer ::=
5856 * > [SuperConstructorInvocation]
5857 * > | [ConstructorFieldInitializer]
5858 */
5859 abstract class ConstructorInitializer extends AstNode {}
5860
5861 /**
5862 * The name of the constructor.
5863 *
5864 * > constructorName ::=
5865 * > type ('.' identifier)?
5866 */
5867 class ConstructorName extends AstNode {
5868 /**
5869 * The name of the type defining the constructor.
5870 */
5871 TypeName _type;
5872
5873 /**
5874 * The token for the period before the constructor name, or `null` if the
5875 * specified constructor is the unnamed constructor.
5876 */
5877 Token period;
5878
5879 /**
5880 * The name of the constructor, or `null` if the specified constructor is the
5881 * unnamed constructor.
5882 */
5883 SimpleIdentifier _name;
5884
5885 /**
5886 * The element associated with this constructor name based on static type
5887 * information, or `null` if the AST structure has not been resolved or if
5888 * this constructor name could not be resolved.
5889 */
5890 ConstructorElement staticElement;
5891
5892 /**
5893 * Initialize a newly created constructor name. The [period] and [name] can be
5894 * `null` if the constructor being named is the unnamed constructor.
5895 */
5896 ConstructorName(TypeName type, this.period, SimpleIdentifier name) {
5897 _type = _becomeParentOf(type);
5898 _name = _becomeParentOf(name);
5899 }
5900
5901 @override
5902 Token get beginToken => _type.beginToken;
5903
5904 @override
5905 Iterable get childEntities =>
5906 new ChildEntities()..add(_type)..add(period)..add(_name);
5907
5908 @override
5909 Token get endToken {
5910 if (_name != null) {
5911 return _name.endToken;
5912 }
5913 return _type.endToken;
5914 }
5915
5916 /**
5917 * Return the name of the constructor, or `null` if the specified constructor
5918 * is the unnamed constructor.
5919 */
5920 SimpleIdentifier get name => _name;
5921
5922 /**
5923 * Set the name of the constructor to the given [name].
5924 */
5925 void set name(SimpleIdentifier name) {
5926 _name = _becomeParentOf(name);
5927 }
5928
5929 /**
5930 * Return the name of the type defining the constructor.
5931 */
5932 TypeName get type => _type;
5933
5934 /**
5935 * Set the name of the type defining the constructor to the given [type] name.
5936 */
5937 void set type(TypeName type) {
5938 _type = _becomeParentOf(type);
5939 }
5940
5941 @override
5942 accept(AstVisitor visitor) => visitor.visitConstructorName(this);
5943
5944 @override
5945 void visitChildren(AstVisitor visitor) {
5946 _safelyVisitChild(_type, visitor);
5947 _safelyVisitChild(_name, visitor);
5948 }
5949 }
5950
5951 /**
5952 * A continue statement.
5953 *
5954 * > continueStatement ::=
5955 * > 'continue' [SimpleIdentifier]? ';'
5956 */
5957 class ContinueStatement extends Statement {
5958 /**
5959 * The token representing the 'continue' keyword.
5960 */
5961 Token continueKeyword;
5962
5963 /**
5964 * The label associated with the statement, or `null` if there is no label.
5965 */
5966 SimpleIdentifier _label;
5967
5968 /**
5969 * The semicolon terminating the statement.
5970 */
5971 Token semicolon;
5972
5973 /**
5974 * The AstNode which this continue statement is continuing to. This will be
5975 * either a Statement (in the case of continuing a loop) or a SwitchMember
5976 * (in the case of continuing from one switch case to another). Null if the
5977 * AST has not yet been resolved or if the target could not be resolved.
5978 * Note that if the source code has errors, the target may be invalid (e.g.
5979 * the target may be in an enclosing function).
5980 */
5981 AstNode target;
5982
5983 /**
5984 * Initialize a newly created continue statement. The [label] can be `null` if
5985 * there is no label associated with the statement.
5986 */
5987 ContinueStatement(
5988 this.continueKeyword, SimpleIdentifier label, this.semicolon) {
5989 _label = _becomeParentOf(label);
5990 }
5991
5992 @override
5993 Token get beginToken => continueKeyword;
5994
5995 @override
5996 Iterable get childEntities =>
5997 new ChildEntities()..add(continueKeyword)..add(_label)..add(semicolon);
5998
5999 @override
6000 Token get endToken => semicolon;
6001
6002 /**
6003 * Return the token for the 'continue' keyword, or `null` if there is no
6004 * 'continue' keyword.
6005 */
6006 @deprecated // Use "this.continueKeyword"
6007 Token get keyword => continueKeyword;
6008
6009 /**
6010 * Set the token for the 'continue' keyword to the given [token].
6011 */
6012 @deprecated // Use "this.continueKeyword"
6013 set keyword(Token token) {
6014 continueKeyword = token;
6015 }
6016
6017 /**
6018 * Return the label associated with the statement, or `null` if there is no
6019 * label.
6020 */
6021 SimpleIdentifier get label => _label;
6022
6023 /**
6024 * Set the label associated with the statement to the given [identifier].
6025 */
6026 void set label(SimpleIdentifier identifier) {
6027 _label = _becomeParentOf(identifier);
6028 }
6029
6030 @override
6031 accept(AstVisitor visitor) => visitor.visitContinueStatement(this);
6032
6033 @override
6034 void visitChildren(AstVisitor visitor) {
6035 _safelyVisitChild(_label, visitor);
6036 }
6037 }
6038
6039 /**
6040 * A node that represents the declaration of one or more names. Each declared
6041 * name is visible within a name scope.
6042 */
6043 abstract class Declaration extends AnnotatedNode {
6044 /**
6045 * Initialize a newly created declaration. Either or both of the [comment] and
6046 * [metadata] can be `null` if the declaration does not have the corresponding
6047 * attribute.
6048 */
6049 Declaration(Comment comment, List<Annotation> metadata)
6050 : super(comment, metadata);
6051
6052 /**
6053 * Return the element associated with this declaration, or `null` if either
6054 * this node corresponds to a list of declarations or if the AST structure has
6055 * not been resolved.
6056 */
6057 Element get element;
6058 }
6059
6060 /**
6061 * The declaration of a single identifier.
6062 *
6063 * > declaredIdentifier ::=
6064 * > [Annotation] finalConstVarOrType [SimpleIdentifier]
6065 */
6066 class DeclaredIdentifier extends Declaration {
6067 /**
6068 * The token representing either the 'final', 'const' or 'var' keyword, or
6069 * `null` if no keyword was used.
6070 */
6071 Token keyword;
6072
6073 /**
6074 * The name of the declared type of the parameter, or `null` if the parameter
6075 * does not have a declared type.
6076 */
6077 TypeName _type;
6078
6079 /**
6080 * The name of the variable being declared.
6081 */
6082 SimpleIdentifier _identifier;
6083
6084 /**
6085 * Initialize a newly created formal parameter. Either or both of the
6086 * [comment] and [metadata] can be `null` if the declaration does not have the
6087 * corresponding attribute. The [keyword] can be `null` if a type name is
6088 * given. The [type] must be `null` if the keyword is 'var'.
6089 */
6090 DeclaredIdentifier(Comment comment, List<Annotation> metadata, this.keyword,
6091 TypeName type, SimpleIdentifier identifier)
6092 : super(comment, metadata) {
6093 _type = _becomeParentOf(type);
6094 _identifier = _becomeParentOf(identifier);
6095 }
6096
6097 @override
6098 Iterable get childEntities =>
6099 super._childEntities..add(keyword)..add(_type)..add(_identifier);
6100
6101 @override
6102 LocalVariableElement get element {
6103 if (_identifier == null) {
6104 return null;
6105 }
6106 return _identifier.staticElement as LocalVariableElement;
6107 }
6108
6109 @override
6110 Token get endToken => _identifier.endToken;
6111
6112 @override
6113 Token get firstTokenAfterCommentAndMetadata {
6114 if (keyword != null) {
6115 return keyword;
6116 } else if (_type != null) {
6117 return _type.beginToken;
6118 }
6119 return _identifier.beginToken;
6120 }
6121
6122 /**
6123 * Return the name of the variable being declared.
6124 */
6125 SimpleIdentifier get identifier => _identifier;
6126
6127 /**
6128 * Set the name of the variable being declared to the given [identifier].
6129 */
6130 void set identifier(SimpleIdentifier identifier) {
6131 _identifier = _becomeParentOf(identifier);
6132 }
6133
6134 /**
6135 * Return `true` if this variable was declared with the 'const' modifier.
6136 */
6137 bool get isConst => (keyword is KeywordToken) &&
6138 (keyword as KeywordToken).keyword == Keyword.CONST;
6139
6140 /**
6141 * Return `true` if this variable was declared with the 'final' modifier.
6142 * Variables that are declared with the 'const' modifier will return `false`
6143 * even though they are implicitly final.
6144 */
6145 bool get isFinal => (keyword is KeywordToken) &&
6146 (keyword as KeywordToken).keyword == Keyword.FINAL;
6147
6148 /**
6149 * Return the name of the declared type of the parameter, or `null` if the
6150 * parameter does not have a declared type.
6151 */
6152 TypeName get type => _type;
6153
6154 /**
6155 * Set the name of the declared type of the parameter to the given [typeName].
6156 */
6157 void set type(TypeName typeName) {
6158 _type = _becomeParentOf(typeName);
6159 }
6160
6161 @override
6162 accept(AstVisitor visitor) => visitor.visitDeclaredIdentifier(this);
6163
6164 @override
6165 void visitChildren(AstVisitor visitor) {
6166 super.visitChildren(visitor);
6167 _safelyVisitChild(_type, visitor);
6168 _safelyVisitChild(_identifier, visitor);
6169 }
6170 }
6171
6172 /**
6173 * A formal parameter with a default value. There are two kinds of parameters
6174 * that are both represented by this class: named formal parameters and
6175 * positional formal parameters.
6176 *
6177 * > defaultFormalParameter ::=
6178 * > [NormalFormalParameter] ('=' [Expression])?
6179 * >
6180 * > defaultNamedParameter ::=
6181 * > [NormalFormalParameter] (':' [Expression])?
6182 */
6183 class DefaultFormalParameter extends FormalParameter {
6184 /**
6185 * The formal parameter with which the default value is associated.
6186 */
6187 NormalFormalParameter _parameter;
6188
6189 /**
6190 * The kind of this parameter.
6191 */
6192 ParameterKind kind;
6193
6194 /**
6195 * The token separating the parameter from the default value, or `null` if
6196 * there is no default value.
6197 */
6198 Token separator;
6199
6200 /**
6201 * The expression computing the default value for the parameter, or `null` if
6202 * there is no default value.
6203 */
6204 Expression _defaultValue;
6205
6206 /**
6207 * Initialize a newly created default formal parameter. The [separator] and
6208 * [defaultValue] can be `null` if there is no default value.
6209 */
6210 DefaultFormalParameter(NormalFormalParameter parameter, this.kind,
6211 this.separator, Expression defaultValue) {
6212 _parameter = _becomeParentOf(parameter);
6213 _defaultValue = _becomeParentOf(defaultValue);
6214 }
6215
6216 @override
6217 Token get beginToken => _parameter.beginToken;
6218
6219 @override
6220 Iterable get childEntities =>
6221 new ChildEntities()..add(_parameter)..add(separator)..add(_defaultValue);
6222
6223 /**
6224 * Return the expression computing the default value for the parameter, or
6225 * `null` if there is no default value.
6226 */
6227 Expression get defaultValue => _defaultValue;
6228
6229 /**
6230 * Set the expression computing the default value for the parameter to the
6231 * given [expression].
6232 */
6233 void set defaultValue(Expression expression) {
6234 _defaultValue = _becomeParentOf(expression);
6235 }
6236
6237 @override
6238 Token get endToken {
6239 if (_defaultValue != null) {
6240 return _defaultValue.endToken;
6241 }
6242 return _parameter.endToken;
6243 }
6244
6245 @override
6246 SimpleIdentifier get identifier => _parameter.identifier;
6247
6248 @override
6249 bool get isConst => _parameter != null && _parameter.isConst;
6250
6251 @override
6252 bool get isFinal => _parameter != null && _parameter.isFinal;
6253
6254 @override
6255 NodeList<Annotation> get metadata => _parameter.metadata;
6256
6257 /**
6258 * Return the formal parameter with which the default value is associated.
6259 */
6260 NormalFormalParameter get parameter => _parameter;
6261
6262 /**
6263 * Set the formal parameter with which the default value is associated to the
6264 * given [formalParameter].
6265 */
6266 void set parameter(NormalFormalParameter formalParameter) {
6267 _parameter = _becomeParentOf(formalParameter);
6268 }
6269
6270 @override
6271 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this);
6272
6273 @override
6274 void visitChildren(AstVisitor visitor) {
6275 _safelyVisitChild(_parameter, visitor);
6276 _safelyVisitChild(_defaultValue, visitor);
6277 }
6278 }
6279
6280 /**
6281 * A recursive AST visitor that is used to run over [Expression]s to determine
6282 * whether the expression is composed by at least one deferred
6283 * [PrefixedIdentifier].
6284 *
6285 * See [PrefixedIdentifier.isDeferred].
6286 */
6287 class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<Object> {
6288 /**
6289 * A flag indicating whether an identifier from a deferred library has been
6290 * found.
6291 */
6292 bool _result = false;
6293
6294 /**
6295 * Return `true` if the visitor found a [PrefixedIdentifier] that returned
6296 * `true` to the [PrefixedIdentifier.isDeferred] query.
6297 */
6298 bool get result => _result;
6299
6300 @override
6301 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
6302 if (!_result) {
6303 if (node.isDeferred) {
6304 _result = true;
6305 }
6306 }
6307 return null;
6308 }
6309 }
6310
6311 /**
6312 * A node that represents a directive.
6313 *
6314 * > directive ::=
6315 * > [ExportDirective]
6316 * > | [ImportDirective]
6317 * > | [LibraryDirective]
6318 * > | [PartDirective]
6319 * > | [PartOfDirective]
6320 */
6321 abstract class Directive extends AnnotatedNode {
6322 /**
6323 * The element associated with this directive, or `null` if the AST structure
6324 * has not been resolved or if this directive could not be resolved.
6325 */
6326 Element element;
6327
6328 /**
6329 * Initialize a newly create directive. Either or both of the [comment] and
6330 * [metadata] can be `null` if the directive does not have the corresponding
6331 * attribute.
6332 */
6333 Directive(Comment comment, List<Annotation> metadata)
6334 : super(comment, metadata);
6335
6336 /**
6337 * Return the token representing the keyword that introduces this directive
6338 * ('import', 'export', 'library' or 'part').
6339 */
6340 Token get keyword;
6341 }
6342
6343 /**
6344 * A do statement.
6345 *
6346 * > doStatement ::=
6347 * > 'do' [Statement] 'while' '(' [Expression] ')' ';'
6348 */
6349 class DoStatement extends Statement {
6350 /**
6351 * The token representing the 'do' keyword.
6352 */
6353 Token doKeyword;
6354
6355 /**
6356 * The body of the loop.
6357 */
6358 Statement _body;
6359
6360 /**
6361 * The token representing the 'while' keyword.
6362 */
6363 Token whileKeyword;
6364
6365 /**
6366 * The left parenthesis.
6367 */
6368 Token leftParenthesis;
6369
6370 /**
6371 * The condition that determines when the loop will terminate.
6372 */
6373 Expression _condition;
6374
6375 /**
6376 * The right parenthesis.
6377 */
6378 Token rightParenthesis;
6379
6380 /**
6381 * The semicolon terminating the statement.
6382 */
6383 Token semicolon;
6384
6385 /**
6386 * Initialize a newly created do loop.
6387 */
6388 DoStatement(
6389 this.doKeyword,
6390 Statement body,
6391 this.whileKeyword,
6392 this.leftParenthesis,
6393 Expression condition,
6394 this.rightParenthesis,
6395 this.semicolon) {
6396 _body = _becomeParentOf(body);
6397 _condition = _becomeParentOf(condition);
6398 }
6399
6400 @override
6401 Token get beginToken => doKeyword;
6402
6403 /**
6404 * Return the body of the loop.
6405 */
6406 Statement get body => _body;
6407
6408 /**
6409 * Set the body of the loop to the given [statement].
6410 */
6411 void set body(Statement statement) {
6412 _body = _becomeParentOf(statement);
6413 }
6414
6415 @override
6416 Iterable get childEntities => new ChildEntities()
6417 ..add(doKeyword)
6418 ..add(_body)
6419 ..add(whileKeyword)
6420 ..add(leftParenthesis)
6421 ..add(_condition)
6422 ..add(rightParenthesis)
6423 ..add(semicolon);
6424
6425 /**
6426 * Return the condition that determines when the loop will terminate.
6427 */
6428 Expression get condition => _condition;
6429
6430 /**
6431 * Set the condition that determines when the loop will terminate to the given
6432 * [expression].
6433 */
6434 void set condition(Expression expression) {
6435 _condition = _becomeParentOf(expression);
6436 }
6437
6438 @override
6439 Token get endToken => semicolon;
6440
6441 @override
6442 accept(AstVisitor visitor) => visitor.visitDoStatement(this);
6443
6444 @override
6445 void visitChildren(AstVisitor visitor) {
6446 _safelyVisitChild(_body, visitor);
6447 _safelyVisitChild(_condition, visitor);
6448 }
6449 }
6450
6451 /**
6452 * A floating point literal expression.
6453 *
6454 * > doubleLiteral ::=
6455 * > decimalDigit+ ('.' decimalDigit*)? exponent?
6456 * > | '.' decimalDigit+ exponent?
6457 * >
6458 * > exponent ::=
6459 * > ('e' | 'E') ('+' | '-')? decimalDigit+
6460 */
6461 class DoubleLiteral extends Literal {
6462 /**
6463 * The token representing the literal.
6464 */
6465 Token literal;
6466
6467 /**
6468 * The value of the literal.
6469 */
6470 double value;
6471
6472 /**
6473 * Initialize a newly created floating point literal.
6474 */
6475 DoubleLiteral(this.literal, this.value);
6476
6477 @override
6478 Token get beginToken => literal;
6479
6480 @override
6481 Iterable get childEntities => new ChildEntities()..add(literal);
6482
6483 @override
6484 Token get endToken => literal;
6485
6486 @override
6487 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this);
6488
6489 @override
6490 void visitChildren(AstVisitor visitor) {
6491 // There are no children to visit.
6492 }
6493 }
6494
6495 /**
6496 * An object used to locate the [Element] associated with a given [AstNode].
6497 */
6498 class ElementLocator {
6499 /**
6500 * Return the element associated with the given [node], or `null` if there is
6501 * no element associated with the node.
6502 */
6503 static Element locate(AstNode node) {
6504 if (node == null) {
6505 return null;
6506 }
6507 ElementLocator_ElementMapper mapper = new ElementLocator_ElementMapper();
6508 return node.accept(mapper);
6509 }
6510 }
6511
6512 /**
6513 * Visitor that maps nodes to elements.
6514 */
6515 class ElementLocator_ElementMapper extends GeneralizingAstVisitor<Element> {
6516 @override
6517 Element visitAnnotation(Annotation node) => node.element;
6518
6519 @override
6520 Element visitAssignmentExpression(AssignmentExpression node) =>
6521 node.bestElement;
6522
6523 @override
6524 Element visitBinaryExpression(BinaryExpression node) => node.bestElement;
6525
6526 @override
6527 Element visitClassDeclaration(ClassDeclaration node) => node.element;
6528
6529 @override
6530 Element visitCompilationUnit(CompilationUnit node) => node.element;
6531
6532 @override
6533 Element visitConstructorDeclaration(ConstructorDeclaration node) =>
6534 node.element;
6535
6536 @override
6537 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element;
6538
6539 @override
6540 Element visitIdentifier(Identifier node) {
6541 AstNode parent = node.parent;
6542 // Type name in Annotation
6543 if (parent is Annotation) {
6544 Annotation annotation = parent;
6545 if (identical(annotation.name, node) &&
6546 annotation.constructorName == null) {
6547 return annotation.element;
6548 }
6549 }
6550 // Extra work to map Constructor Declarations to their associated
6551 // Constructor Elements
6552 if (parent is ConstructorDeclaration) {
6553 ConstructorDeclaration decl = parent;
6554 Identifier returnType = decl.returnType;
6555 if (identical(returnType, node)) {
6556 SimpleIdentifier name = decl.name;
6557 if (name != null) {
6558 return name.bestElement;
6559 }
6560 Element element = node.bestElement;
6561 if (element is ClassElement) {
6562 return element.unnamedConstructor;
6563 }
6564 }
6565 }
6566 if (parent is LibraryIdentifier) {
6567 AstNode grandParent = parent.parent;
6568 if (grandParent is PartOfDirective) {
6569 Element element = grandParent.element;
6570 if (element is LibraryElement) {
6571 return element.definingCompilationUnit;
6572 }
6573 }
6574 }
6575 return node.bestElement;
6576 }
6577
6578 @override
6579 Element visitImportDirective(ImportDirective node) => node.element;
6580
6581 @override
6582 Element visitIndexExpression(IndexExpression node) => node.bestElement;
6583
6584 @override
6585 Element visitInstanceCreationExpression(InstanceCreationExpression node) =>
6586 node.staticElement;
6587
6588 @override
6589 Element visitLibraryDirective(LibraryDirective node) => node.element;
6590
6591 @override
6592 Element visitMethodDeclaration(MethodDeclaration node) => node.element;
6593
6594 @override
6595 Element visitMethodInvocation(MethodInvocation node) =>
6596 node.methodName.bestElement;
6597
6598 @override
6599 Element visitPartOfDirective(PartOfDirective node) => node.element;
6600
6601 @override
6602 Element visitPostfixExpression(PostfixExpression node) => node.bestElement;
6603
6604 @override
6605 Element visitPrefixedIdentifier(PrefixedIdentifier node) => node.bestElement;
6606
6607 @override
6608 Element visitPrefixExpression(PrefixExpression node) => node.bestElement;
6609
6610 @override
6611 Element visitStringLiteral(StringLiteral node) {
6612 AstNode parent = node.parent;
6613 if (parent is UriBasedDirective) {
6614 return parent.uriElement;
6615 }
6616 return null;
6617 }
6618
6619 @override
6620 Element visitVariableDeclaration(VariableDeclaration node) => node.element;
6621 }
6622
6623 /**
6624 * An empty function body, which can only appear in constructors or abstract
6625 * methods.
6626 *
6627 * > emptyFunctionBody ::=
6628 * > ';'
6629 */
6630 class EmptyFunctionBody extends FunctionBody {
6631 /**
6632 * The token representing the semicolon that marks the end of the function
6633 * body.
6634 */
6635 Token semicolon;
6636
6637 /**
6638 * Initialize a newly created function body.
6639 */
6640 EmptyFunctionBody(this.semicolon);
6641
6642 @override
6643 Token get beginToken => semicolon;
6644
6645 @override
6646 Iterable get childEntities => new ChildEntities()..add(semicolon);
6647
6648 @override
6649 Token get endToken => semicolon;
6650
6651 @override
6652 accept(AstVisitor visitor) => visitor.visitEmptyFunctionBody(this);
6653
6654 @override
6655 void visitChildren(AstVisitor visitor) {
6656 // Empty function bodies have no children.
6657 }
6658 }
6659
6660 /**
6661 * An empty statement.
6662 *
6663 * > emptyStatement ::=
6664 * > ';'
6665 */
6666 class EmptyStatement extends Statement {
6667 /**
6668 * The semicolon terminating the statement.
6669 */
6670 Token semicolon;
6671
6672 /**
6673 * Initialize a newly created empty statement.
6674 */
6675 EmptyStatement(this.semicolon);
6676
6677 @override
6678 Token get beginToken => semicolon;
6679
6680 @override
6681 Iterable get childEntities => new ChildEntities()..add(semicolon);
6682
6683 @override
6684 Token get endToken => semicolon;
6685
6686 @override
6687 accept(AstVisitor visitor) => visitor.visitEmptyStatement(this);
6688
6689 @override
6690 void visitChildren(AstVisitor visitor) {
6691 // There are no children to visit.
6692 }
6693 }
6694
6695 /**
6696 * The declaration of an enum constant.
6697 */
6698 class EnumConstantDeclaration extends Declaration {
6699 /**
6700 * The name of the constant.
6701 */
6702 SimpleIdentifier _name;
6703
6704 /**
6705 * Initialize a newly created enum constant declaration. Either or both of the
6706 * [comment] and [metadata] can be `null` if the constant does not have the
6707 * corresponding attribute. (Technically, enum constants cannot have metadata,
6708 * but we allow it for consistency.)
6709 */
6710 EnumConstantDeclaration(
6711 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
6712 : super(comment, metadata) {
6713 _name = _becomeParentOf(name);
6714 }
6715
6716 @override
6717 Iterable get childEntities => super._childEntities..add(_name);
6718
6719 @override
6720 FieldElement get element =>
6721 _name == null ? null : (_name.staticElement as FieldElement);
6722
6723 @override
6724 Token get endToken => _name.endToken;
6725
6726 @override
6727 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
6728
6729 /**
6730 * Return the name of the constant.
6731 */
6732 SimpleIdentifier get name => _name;
6733
6734 /**
6735 * Set the name of the constant to the given [name].
6736 */
6737 void set name(SimpleIdentifier name) {
6738 _name = _becomeParentOf(name);
6739 }
6740
6741 @override
6742 accept(AstVisitor visitor) => visitor.visitEnumConstantDeclaration(this);
6743
6744 @override
6745 void visitChildren(AstVisitor visitor) {
6746 super.visitChildren(visitor);
6747 _safelyVisitChild(_name, visitor);
6748 }
6749 }
6750
6751 /**
6752 * The declaration of an enumeration.
6753 *
6754 * > enumType ::=
6755 * > metadata 'enum' [SimpleIdentifier] '{' [SimpleIdentifier] (',' [SimpleI dentifier])* (',')? '}'
6756 */
6757 class EnumDeclaration extends NamedCompilationUnitMember {
6758 /**
6759 * The 'enum' keyword.
6760 */
6761 Token enumKeyword;
6762
6763 /**
6764 * The left curly bracket.
6765 */
6766 Token leftBracket;
6767
6768 /**
6769 * The enumeration constants being declared.
6770 */
6771 NodeList<EnumConstantDeclaration> _constants;
6772
6773 /**
6774 * The right curly bracket.
6775 */
6776 Token rightBracket;
6777
6778 /**
6779 * Initialize a newly created enumeration declaration. Either or both of the
6780 * [comment] and [metadata] can be `null` if the declaration does not have the
6781 * corresponding attribute. The list of [constants] must contain at least one
6782 * value.
6783 */
6784 EnumDeclaration(
6785 Comment comment,
6786 List<Annotation> metadata,
6787 this.enumKeyword,
6788 SimpleIdentifier name,
6789 this.leftBracket,
6790 List<EnumConstantDeclaration> constants,
6791 this.rightBracket)
6792 : super(comment, metadata, name) {
6793 _constants = new NodeList<EnumConstantDeclaration>(this, constants);
6794 }
6795
6796 @override
6797 // TODO(brianwilkerson) Add commas?
6798 Iterable get childEntities => super._childEntities
6799 ..add(enumKeyword)
6800 ..add(_name)
6801 ..add(leftBracket)
6802 ..addAll(_constants)
6803 ..add(rightBracket);
6804
6805 /**
6806 * Return the enumeration constants being declared.
6807 */
6808 NodeList<EnumConstantDeclaration> get constants => _constants;
6809
6810 @override
6811 ClassElement get element =>
6812 _name != null ? (_name.staticElement as ClassElement) : null;
6813
6814 @override
6815 Token get endToken => rightBracket;
6816
6817 @override
6818 Token get firstTokenAfterCommentAndMetadata => enumKeyword;
6819
6820 /**
6821 * Return the token for the 'enum' keyword, or `null` if there is no
6822 * 'enum' keyword.
6823 */
6824 @deprecated // Use "this.enumKeyword"
6825 Token get keyword => enumKeyword;
6826
6827 /**
6828 * Set the token for the 'enum' keyword to the given [token].
6829 */
6830 @deprecated // Use "this.enumKeyword"
6831 set keyword(Token token) {
6832 enumKeyword = token;
6833 }
6834
6835 @override
6836 accept(AstVisitor visitor) => visitor.visitEnumDeclaration(this);
6837
6838 @override
6839 void visitChildren(AstVisitor visitor) {
6840 super.visitChildren(visitor);
6841 _safelyVisitChild(_name, visitor);
6842 _constants.accept(visitor);
6843 }
6844 }
6845
6846 /**
6847 * Ephemeral identifiers are created as needed to mimic the presence of an empty
6848 * identifier.
6849 */
6850 class EphemeralIdentifier extends SimpleIdentifier {
6851 EphemeralIdentifier(AstNode parent, int location)
6852 : super(new StringToken(TokenType.IDENTIFIER, "", location)) {
6853 parent._becomeParentOf(this);
6854 }
6855 }
6856
6857 /**
6858 * An export directive.
6859 *
6860 * > exportDirective ::=
6861 * > [Annotation] 'export' [StringLiteral] [Combinator]* ';'
6862 */
6863 class ExportDirective extends NamespaceDirective {
6864 /**
6865 * Initialize a newly created export directive. Either or both of the
6866 * [comment] and [metadata] can be `null` if the directive does not have the
6867 * corresponding attribute. The list of [combinators] can be `null` if there
6868 * are no combinators.
6869 */
6870 ExportDirective(Comment comment, List<Annotation> metadata, Token keyword,
6871 StringLiteral libraryUri, List<Combinator> combinators, Token semicolon)
6872 : super(comment, metadata, keyword, libraryUri, combinators, semicolon);
6873
6874 @override
6875 Iterable get childEntities => super._childEntities
6876 ..add(_uri)
6877 ..addAll(combinators)
6878 ..add(semicolon);
6879
6880 @override
6881 ExportElement get element => super.element as ExportElement;
6882
6883 @override
6884 LibraryElement get uriElement {
6885 if (element != null) {
6886 return element.exportedLibrary;
6887 }
6888 return null;
6889 }
6890
6891 @override
6892 accept(AstVisitor visitor) => visitor.visitExportDirective(this);
6893
6894 @override
6895 void visitChildren(AstVisitor visitor) {
6896 super.visitChildren(visitor);
6897 combinators.accept(visitor);
6898 }
6899 }
6900
6901 /**
6902 * A node that represents an expression.
6903 *
6904 * > expression ::=
6905 * > [AssignmentExpression]
6906 * > | [ConditionalExpression] cascadeSection*
6907 * > | [ThrowExpression]
6908 */
6909 abstract class Expression extends AstNode {
6910 /**
6911 * An empty list of expressions.
6912 */
6913 @deprecated // Use "Expression.EMPTY_LIST"
6914 static const List<Expression> EMPTY_ARRAY = EMPTY_LIST;
6915
6916 /**
6917 * An empty list of expressions.
6918 */
6919 static const List<Expression> EMPTY_LIST = const <Expression>[];
6920
6921 /**
6922 * The static type of this expression, or `null` if the AST structure has not
6923 * been resolved.
6924 */
6925 DartType staticType;
6926
6927 /**
6928 * The propagated type of this expression, or `null` if type propagation has
6929 * not been performed on the AST structure.
6930 */
6931 DartType propagatedType;
6932
6933 /**
6934 * Return the best parameter element information available for this
6935 * expression. If type propagation was able to find a better parameter element
6936 * than static analysis, that type will be returned. Otherwise, the result of
6937 * static analysis will be returned.
6938 */
6939 ParameterElement get bestParameterElement {
6940 ParameterElement propagatedElement = propagatedParameterElement;
6941 if (propagatedElement != null) {
6942 return propagatedElement;
6943 }
6944 return staticParameterElement;
6945 }
6946
6947 /**
6948 * Return the best type information available for this expression. If type
6949 * propagation was able to find a better type than static analysis, that type
6950 * will be returned. Otherwise, the result of static analysis will be
6951 * returned. If no type analysis has been performed, then the type 'dynamic'
6952 * will be returned.
6953 */
6954 DartType get bestType {
6955 if (propagatedType != null) {
6956 return propagatedType;
6957 } else if (staticType != null) {
6958 return staticType;
6959 }
6960 return DynamicTypeImpl.instance;
6961 }
6962
6963 /**
6964 * Return `true` if this expression is syntactically valid for the LHS of an
6965 * [AssignmentExpression].
6966 */
6967 bool get isAssignable => false;
6968
6969 /**
6970 * Return the precedence of this expression. The precedence is a positive
6971 * integer value that defines how the source code is parsed into an AST. For
6972 * example `a * b + c` is parsed as `(a * b) + c` because the precedence of
6973 * `*` is greater than the precedence of `+`.
6974 *
6975 * Clients should not assume that returned values will stay the same, they
6976 * might change as result of specification change. Only relative order should
6977 * be used.
6978 */
6979 int get precedence;
6980
6981 /**
6982 * If this expression is an argument to an invocation, and the AST structure
6983 * has been resolved, and the function being invoked is known based on
6984 * propagated type information, and this expression corresponds to one of the
6985 * parameters of the function being invoked, then return the parameter element
6986 * representing the parameter to which the value of this expression will be
6987 * bound. Otherwise, return `null`.
6988 */
6989 ParameterElement get propagatedParameterElement {
6990 AstNode parent = this.parent;
6991 if (parent is ArgumentList) {
6992 return parent._getPropagatedParameterElementFor(this);
6993 } else if (parent is IndexExpression) {
6994 IndexExpression indexExpression = parent;
6995 if (identical(indexExpression.index, this)) {
6996 return indexExpression._propagatedParameterElementForIndex;
6997 }
6998 } else if (parent is BinaryExpression) {
6999 BinaryExpression binaryExpression = parent;
7000 if (identical(binaryExpression.rightOperand, this)) {
7001 return binaryExpression._propagatedParameterElementForRightOperand;
7002 }
7003 } else if (parent is AssignmentExpression) {
7004 AssignmentExpression assignmentExpression = parent;
7005 if (identical(assignmentExpression.rightHandSide, this)) {
7006 return assignmentExpression._propagatedParameterElementForRightHandSide;
7007 }
7008 } else if (parent is PrefixExpression) {
7009 return parent._propagatedParameterElementForOperand;
7010 } else if (parent is PostfixExpression) {
7011 return parent._propagatedParameterElementForOperand;
7012 }
7013 return null;
7014 }
7015
7016 /**
7017 * If this expression is an argument to an invocation, and the AST structure
7018 * has been resolved, and the function being invoked is known based on static
7019 * type information, and this expression corresponds to one of the parameters
7020 * of the function being invoked, then return the parameter element
7021 * representing the parameter to which the value of this expression will be
7022 * bound. Otherwise, return `null`.
7023 */
7024 ParameterElement get staticParameterElement {
7025 AstNode parent = this.parent;
7026 if (parent is ArgumentList) {
7027 return parent._getStaticParameterElementFor(this);
7028 } else if (parent is IndexExpression) {
7029 IndexExpression indexExpression = parent;
7030 if (identical(indexExpression.index, this)) {
7031 return indexExpression._staticParameterElementForIndex;
7032 }
7033 } else if (parent is BinaryExpression) {
7034 BinaryExpression binaryExpression = parent;
7035 if (identical(binaryExpression.rightOperand, this)) {
7036 return binaryExpression._staticParameterElementForRightOperand;
7037 }
7038 } else if (parent is AssignmentExpression) {
7039 AssignmentExpression assignmentExpression = parent;
7040 if (identical(assignmentExpression.rightHandSide, this)) {
7041 return assignmentExpression._staticParameterElementForRightHandSide;
7042 }
7043 } else if (parent is PrefixExpression) {
7044 return parent._staticParameterElementForOperand;
7045 } else if (parent is PostfixExpression) {
7046 return parent._staticParameterElementForOperand;
7047 }
7048 return null;
7049 }
7050 }
7051
7052 /**
7053 * A function body consisting of a single expression.
7054 *
7055 * > expressionFunctionBody ::=
7056 * > 'async'? '=>' [Expression] ';'
7057 */
7058 class ExpressionFunctionBody extends FunctionBody {
7059 /**
7060 * The token representing the 'async' keyword, or `null` if there is no such
7061 * keyword.
7062 */
7063 Token keyword;
7064
7065 /**
7066 * The token introducing the expression that represents the body of the
7067 * function.
7068 */
7069 Token functionDefinition;
7070
7071 /**
7072 * The expression representing the body of the function.
7073 */
7074 Expression _expression;
7075
7076 /**
7077 * The semicolon terminating the statement.
7078 */
7079 Token semicolon;
7080
7081 /**
7082 * Initialize a newly created function body consisting of a block of
7083 * statements. The [keyword] can be `null` if the function body is not an
7084 * async function body.
7085 */
7086 ExpressionFunctionBody(this.keyword, this.functionDefinition,
7087 Expression expression, this.semicolon) {
7088 _expression = _becomeParentOf(expression);
7089 }
7090
7091 @override
7092 Token get beginToken {
7093 if (keyword != null) {
7094 return keyword;
7095 }
7096 return functionDefinition;
7097 }
7098
7099 @override
7100 Iterable get childEntities => new ChildEntities()
7101 ..add(keyword)
7102 ..add(functionDefinition)
7103 ..add(_expression)
7104 ..add(semicolon);
7105
7106 @override
7107 Token get endToken {
7108 if (semicolon != null) {
7109 return semicolon;
7110 }
7111 return _expression.endToken;
7112 }
7113
7114 /**
7115 * Return the expression representing the body of the function.
7116 */
7117 Expression get expression => _expression;
7118
7119 /**
7120 * Set the expression representing the body of the function to the given
7121 * [expression].
7122 */
7123 void set expression(Expression expression) {
7124 _expression = _becomeParentOf(expression);
7125 }
7126
7127 @override
7128 bool get isAsynchronous => keyword != null;
7129
7130 @override
7131 bool get isSynchronous => keyword == null;
7132
7133 @override
7134 accept(AstVisitor visitor) => visitor.visitExpressionFunctionBody(this);
7135
7136 @override
7137 void visitChildren(AstVisitor visitor) {
7138 _safelyVisitChild(_expression, visitor);
7139 }
7140 }
7141
7142 /**
7143 * An expression used as a statement.
7144 *
7145 * > expressionStatement ::=
7146 * > [Expression]? ';'
7147 */
7148 class ExpressionStatement extends Statement {
7149 /**
7150 * The expression that comprises the statement.
7151 */
7152 Expression _expression;
7153
7154 /**
7155 * The semicolon terminating the statement, or `null` if the expression is a
7156 * function expression and therefore isn't followed by a semicolon.
7157 */
7158 Token semicolon;
7159
7160 /**
7161 * Initialize a newly created expression statement.
7162 */
7163 ExpressionStatement(Expression expression, this.semicolon) {
7164 _expression = _becomeParentOf(expression);
7165 }
7166
7167 @override
7168 Token get beginToken => _expression.beginToken;
7169
7170 @override
7171 Iterable get childEntities =>
7172 new ChildEntities()..add(_expression)..add(semicolon);
7173
7174 @override
7175 Token get endToken {
7176 if (semicolon != null) {
7177 return semicolon;
7178 }
7179 return _expression.endToken;
7180 }
7181
7182 /**
7183 * Return the expression that comprises the statement.
7184 */
7185 Expression get expression => _expression;
7186
7187 /**
7188 * Set the expression that comprises the statement to the given [expression].
7189 */
7190 void set expression(Expression expression) {
7191 _expression = _becomeParentOf(expression);
7192 }
7193
7194 @override
7195 bool get isSynthetic => _expression.isSynthetic && semicolon.isSynthetic;
7196
7197 @override
7198 accept(AstVisitor visitor) => visitor.visitExpressionStatement(this);
7199
7200 @override
7201 void visitChildren(AstVisitor visitor) {
7202 _safelyVisitChild(_expression, visitor);
7203 }
7204 }
7205
7206 /**
7207 * The "extends" clause in a class declaration.
7208 *
7209 * > extendsClause ::=
7210 * > 'extends' [TypeName]
7211 */
7212 class ExtendsClause extends AstNode {
7213 /**
7214 * The token representing the 'extends' keyword.
7215 */
7216 Token extendsKeyword;
7217
7218 /**
7219 * The name of the class that is being extended.
7220 */
7221 TypeName _superclass;
7222
7223 /**
7224 * Initialize a newly created extends clause.
7225 */
7226 ExtendsClause(this.extendsKeyword, TypeName superclass) {
7227 _superclass = _becomeParentOf(superclass);
7228 }
7229
7230 @override
7231 Token get beginToken => extendsKeyword;
7232
7233 @override
7234 Iterable get childEntities =>
7235 new ChildEntities()..add(extendsKeyword)..add(_superclass);
7236
7237 @override
7238 Token get endToken => _superclass.endToken;
7239
7240 /**
7241 * Return the token for the 'extends' keyword.
7242 */
7243 @deprecated // Use "this.extendsKeyword"
7244 Token get keyword => extendsKeyword;
7245
7246 /**
7247 * Set the token for the 'extends' keyword to the given [token].
7248 */
7249 @deprecated // Use "this.extendsKeyword"
7250 set keyword(Token token) {
7251 extendsKeyword = token;
7252 }
7253
7254 /**
7255 * Return the name of the class that is being extended.
7256 */
7257 TypeName get superclass => _superclass;
7258
7259 /**
7260 * Set the name of the class that is being extended to the given [name].
7261 */
7262 void set superclass(TypeName name) {
7263 _superclass = _becomeParentOf(name);
7264 }
7265
7266 @override
7267 accept(AstVisitor visitor) => visitor.visitExtendsClause(this);
7268
7269 @override
7270 void visitChildren(AstVisitor visitor) {
7271 _safelyVisitChild(_superclass, visitor);
7272 }
7273 }
7274
7275 /**
7276 * The declaration of one or more fields of the same type.
7277 *
7278 * > fieldDeclaration ::=
7279 * > 'static'? [VariableDeclarationList] ';'
7280 */
7281 class FieldDeclaration extends ClassMember {
7282 /**
7283 * The token representing the 'static' keyword, or `null` if the fields are
7284 * not static.
7285 */
7286 Token staticKeyword;
7287
7288 /**
7289 * The fields being declared.
7290 */
7291 VariableDeclarationList _fieldList;
7292
7293 /**
7294 * The semicolon terminating the declaration.
7295 */
7296 Token semicolon;
7297
7298 /**
7299 * Initialize a newly created field declaration. Either or both of the
7300 * [comment] and [metadata] can be `null` if the declaration does not have the
7301 * corresponding attribute. The [staticKeyword] can be `null` if the field is
7302 * not a static field.
7303 */
7304 FieldDeclaration(Comment comment, List<Annotation> metadata,
7305 this.staticKeyword, VariableDeclarationList fieldList, this.semicolon)
7306 : super(comment, metadata) {
7307 _fieldList = _becomeParentOf(fieldList);
7308 }
7309
7310 @override
7311 Iterable get childEntities =>
7312 super._childEntities..add(staticKeyword)..add(_fieldList)..add(semicolon);
7313
7314 @override
7315 Element get element => null;
7316
7317 @override
7318 Token get endToken => semicolon;
7319
7320 /**
7321 * Return the fields being declared.
7322 */
7323 VariableDeclarationList get fields => _fieldList;
7324
7325 /**
7326 * Set the fields being declared to the given list of [fields].
7327 */
7328 void set fields(VariableDeclarationList fields) {
7329 _fieldList = _becomeParentOf(fields);
7330 }
7331
7332 @override
7333 Token get firstTokenAfterCommentAndMetadata {
7334 if (staticKeyword != null) {
7335 return staticKeyword;
7336 }
7337 return _fieldList.beginToken;
7338 }
7339
7340 /**
7341 * Return `true` if the fields are declared to be static.
7342 */
7343 bool get isStatic => staticKeyword != null;
7344
7345 @override
7346 accept(AstVisitor visitor) => visitor.visitFieldDeclaration(this);
7347
7348 @override
7349 void visitChildren(AstVisitor visitor) {
7350 super.visitChildren(visitor);
7351 _safelyVisitChild(_fieldList, visitor);
7352 }
7353 }
7354
7355 /**
7356 * A field formal parameter.
7357 *
7358 * > fieldFormalParameter ::=
7359 * > ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])?
7360 * > 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterLis t])?
7361 */
7362 class FieldFormalParameter extends NormalFormalParameter {
7363 /**
7364 * The token representing either the 'final', 'const' or 'var' keyword, or
7365 * `null` if no keyword was used.
7366 */
7367 Token keyword;
7368
7369 /**
7370 * The name of the declared type of the parameter, or `null` if the parameter
7371 * does not have a declared type.
7372 */
7373 TypeName _type;
7374
7375 /**
7376 * The token representing the 'this' keyword.
7377 */
7378 Token thisKeyword;
7379
7380 /**
7381 * The token representing the period.
7382 */
7383 Token period;
7384
7385 /**
7386 * The type parameters associated with the method, or `null` if the method is
7387 * not a generic method.
7388 */
7389 TypeParameterList _typeParameters;
7390
7391 /**
7392 * The parameters of the function-typed parameter, or `null` if this is not a
7393 * function-typed field formal parameter.
7394 */
7395 FormalParameterList _parameters;
7396
7397 /**
7398 * Initialize a newly created formal parameter. Either or both of the
7399 * [comment] and [metadata] can be `null` if the parameter does not have the
7400 * corresponding attribute. The [keyword] can be `null` if there is a type.
7401 * The [type] must be `null` if the keyword is 'var'. The [thisKeyword] and
7402 * [period] can be `null` if the keyword 'this' was not provided. The
7403 * [parameters] can be `null` if this is not a function-typed field formal
7404 * parameter.
7405 */
7406 FieldFormalParameter(
7407 Comment comment,
7408 List<Annotation> metadata,
7409 this.keyword,
7410 TypeName type,
7411 this.thisKeyword,
7412 this.period,
7413 SimpleIdentifier identifier,
7414 TypeParameterList typeParameters,
7415 FormalParameterList parameters)
7416 : super(comment, metadata, identifier) {
7417 _type = _becomeParentOf(type);
7418 _typeParameters = _becomeParentOf(typeParameters);
7419 _parameters = _becomeParentOf(parameters);
7420 }
7421
7422 @override
7423 Token get beginToken {
7424 if (keyword != null) {
7425 return keyword;
7426 } else if (_type != null) {
7427 return _type.beginToken;
7428 }
7429 return thisKeyword;
7430 }
7431
7432 @override
7433 Iterable get childEntities => super._childEntities
7434 ..add(keyword)
7435 ..add(_type)
7436 ..add(thisKeyword)
7437 ..add(period)
7438 ..add(identifier)
7439 ..add(_parameters);
7440
7441 @override
7442 Token get endToken {
7443 if (_parameters != null) {
7444 return _parameters.endToken;
7445 }
7446 return identifier.endToken;
7447 }
7448
7449 @override
7450 bool get isConst => (keyword is KeywordToken) &&
7451 (keyword as KeywordToken).keyword == Keyword.CONST;
7452
7453 @override
7454 bool get isFinal => (keyword is KeywordToken) &&
7455 (keyword as KeywordToken).keyword == Keyword.FINAL;
7456
7457 /**
7458 * Return the parameters of the function-typed parameter, or `null` if this is
7459 * not a function-typed field formal parameter.
7460 */
7461 FormalParameterList get parameters => _parameters;
7462
7463 /**
7464 * Set the parameters of the function-typed parameter to the given
7465 * [parameters].
7466 */
7467 void set parameters(FormalParameterList parameters) {
7468 _parameters = _becomeParentOf(parameters);
7469 }
7470
7471 /**
7472 * Return the token representing the 'this' keyword.
7473 */
7474 @deprecated // Use "this.thisKeyword"
7475 Token get thisToken => thisKeyword;
7476
7477 /**
7478 * Set the token representing the 'this' keyword to the given [token].
7479 */
7480 @deprecated // Use "this.thisKeyword"
7481 set thisToken(Token token) {
7482 thisKeyword = token;
7483 }
7484
7485 /**
7486 * Return the name of the declared type of the parameter, or `null` if the
7487 * parameter does not have a declared type. Note that if this is a
7488 * function-typed field formal parameter this is the return type of the
7489 * function.
7490 */
7491 TypeName get type => _type;
7492
7493 /**
7494 * Set the name of the declared type of the parameter to the given [typeName].
7495 */
7496 void set type(TypeName typeName) {
7497 _type = _becomeParentOf(typeName);
7498 }
7499
7500 /**
7501 * Return the type parameters associated with this method, or `null` if this
7502 * method is not a generic method.
7503 */
7504 TypeParameterList get typeParameters => _typeParameters;
7505
7506 /**
7507 * Set the type parameters associated with this method to the given
7508 * [typeParameters].
7509 */
7510 void set typeParameters(TypeParameterList typeParameters) {
7511 _typeParameters = _becomeParentOf(typeParameters);
7512 }
7513
7514 @override
7515 accept(AstVisitor visitor) => visitor.visitFieldFormalParameter(this);
7516
7517 @override
7518 void visitChildren(AstVisitor visitor) {
7519 super.visitChildren(visitor);
7520 _safelyVisitChild(_type, visitor);
7521 _safelyVisitChild(identifier, visitor);
7522 _safelyVisitChild(_typeParameters, visitor);
7523 _safelyVisitChild(_parameters, visitor);
7524 }
7525 }
7526
7527 /**
7528 * A for-each statement.
7529 *
7530 * > forEachStatement ::=
7531 * > 'await'? 'for' '(' [DeclaredIdentifier] 'in' [Expression] ')' [Block]
7532 * > | 'await'? 'for' '(' [SimpleIdentifier] 'in' [Expression] ')' [Block]
7533 */
7534 class ForEachStatement extends Statement {
7535 /**
7536 * The token representing the 'await' keyword, or `null` if there is no
7537 * 'await' keyword.
7538 */
7539 Token awaitKeyword;
7540
7541 /**
7542 * The token representing the 'for' keyword.
7543 */
7544 Token forKeyword;
7545
7546 /**
7547 * The left parenthesis.
7548 */
7549 Token leftParenthesis;
7550
7551 /**
7552 * The declaration of the loop variable, or `null` if the loop variable is a
7553 * simple identifier.
7554 */
7555 DeclaredIdentifier _loopVariable;
7556
7557 /**
7558 * The loop variable, or `null` if the loop variable is declared in the 'for'.
7559 */
7560 SimpleIdentifier _identifier;
7561
7562 /**
7563 * The token representing the 'in' keyword.
7564 */
7565 Token inKeyword;
7566
7567 /**
7568 * The expression evaluated to produce the iterator.
7569 */
7570 Expression _iterable;
7571
7572 /**
7573 * The right parenthesis.
7574 */
7575 Token rightParenthesis;
7576
7577 /**
7578 * The body of the loop.
7579 */
7580 Statement _body;
7581
7582 /**
7583 * Initialize a newly created for-each statement. The [awaitKeyword] can be
7584 * `null` if this is not an asynchronous for loop.
7585 */
7586 @deprecated // Use new ForEachStatement.withDeclaration(...)
7587 ForEachStatement.con1(
7588 this.awaitKeyword,
7589 this.forKeyword,
7590 this.leftParenthesis,
7591 DeclaredIdentifier loopVariable,
7592 this.inKeyword,
7593 Expression iterator,
7594 this.rightParenthesis,
7595 Statement body) {
7596 _loopVariable = _becomeParentOf(loopVariable);
7597 _iterable = _becomeParentOf(iterator);
7598 _body = _becomeParentOf(body);
7599 }
7600
7601 /**
7602 * Initialize a newly created for-each statement. The [awaitKeyword] can be
7603 * `null` if this is not an asynchronous for loop.
7604 */
7605 @deprecated // Use new ForEachStatement.withReference(...)
7606 ForEachStatement.con2(
7607 this.awaitKeyword,
7608 this.forKeyword,
7609 this.leftParenthesis,
7610 SimpleIdentifier identifier,
7611 this.inKeyword,
7612 Expression iterator,
7613 this.rightParenthesis,
7614 Statement body) {
7615 _identifier = _becomeParentOf(identifier);
7616 _iterable = _becomeParentOf(iterator);
7617 _body = _becomeParentOf(body);
7618 }
7619
7620 /**
7621 * Initialize a newly created for-each statement whose loop control variable
7622 * is declared internally (in the for-loop part). The [awaitKeyword] can be
7623 * `null` if this is not an asynchronous for loop.
7624 */
7625 ForEachStatement.withDeclaration(
7626 this.awaitKeyword,
7627 this.forKeyword,
7628 this.leftParenthesis,
7629 DeclaredIdentifier loopVariable,
7630 this.inKeyword,
7631 Expression iterator,
7632 this.rightParenthesis,
7633 Statement body) {
7634 _loopVariable = _becomeParentOf(loopVariable);
7635 _iterable = _becomeParentOf(iterator);
7636 _body = _becomeParentOf(body);
7637 }
7638
7639 /**
7640 * Initialize a newly created for-each statement whose loop control variable
7641 * is declared outside the for loop. The [awaitKeyword] can be `null` if this
7642 * is not an asynchronous for loop.
7643 */
7644 ForEachStatement.withReference(
7645 this.awaitKeyword,
7646 this.forKeyword,
7647 this.leftParenthesis,
7648 SimpleIdentifier identifier,
7649 this.inKeyword,
7650 Expression iterator,
7651 this.rightParenthesis,
7652 Statement body) {
7653 _identifier = _becomeParentOf(identifier);
7654 _iterable = _becomeParentOf(iterator);
7655 _body = _becomeParentOf(body);
7656 }
7657
7658 @override
7659 Token get beginToken => forKeyword;
7660
7661 /**
7662 * Return the body of the loop.
7663 */
7664 Statement get body => _body;
7665
7666 /**
7667 * Set the body of the loop to the given [statement].
7668 */
7669 void set body(Statement statement) {
7670 _body = _becomeParentOf(statement);
7671 }
7672
7673 @override
7674 Iterable get childEntities => new ChildEntities()
7675 ..add(awaitKeyword)
7676 ..add(forKeyword)
7677 ..add(leftParenthesis)
7678 ..add(_loopVariable)
7679 ..add(_identifier)
7680 ..add(inKeyword)
7681 ..add(_iterable)
7682 ..add(rightParenthesis)
7683 ..add(_body);
7684
7685 @override
7686 Token get endToken => _body.endToken;
7687
7688 /**
7689 * Return the loop variable, or `null` if the loop variable is declared in the
7690 * 'for'.
7691 */
7692 SimpleIdentifier get identifier => _identifier;
7693
7694 /**
7695 * Set the loop variable to the given [identifier].
7696 */
7697 void set identifier(SimpleIdentifier identifier) {
7698 _identifier = _becomeParentOf(identifier);
7699 }
7700
7701 /**
7702 * Return the expression evaluated to produce the iterator.
7703 */
7704 Expression get iterable => _iterable;
7705
7706 /**
7707 * Set the expression evaluated to produce the iterator to the given
7708 * [expression].
7709 */
7710 void set iterable(Expression expression) {
7711 _iterable = _becomeParentOf(expression);
7712 }
7713
7714 /**
7715 * Return the expression evaluated to produce the iterator.
7716 */
7717 @deprecated // Use "this.iterable"
7718 Expression get iterator => iterable;
7719
7720 /**
7721 * Return the declaration of the loop variable, or `null` if the loop variable
7722 * is a simple identifier.
7723 */
7724 DeclaredIdentifier get loopVariable => _loopVariable;
7725
7726 /**
7727 * Set the declaration of the loop variable to the given [variable].
7728 */
7729 void set loopVariable(DeclaredIdentifier variable) {
7730 _loopVariable = _becomeParentOf(variable);
7731 }
7732
7733 @override
7734 accept(AstVisitor visitor) => visitor.visitForEachStatement(this);
7735
7736 @override
7737 void visitChildren(AstVisitor visitor) {
7738 _safelyVisitChild(_loopVariable, visitor);
7739 _safelyVisitChild(_identifier, visitor);
7740 _safelyVisitChild(_iterable, visitor);
7741 _safelyVisitChild(_body, visitor);
7742 }
7743 }
7744
7745 /**
7746 * A node representing a parameter to a function.
7747 *
7748 * > formalParameter ::=
7749 * > [NormalFormalParameter]
7750 * > | [DefaultFormalParameter]
7751 */
7752 abstract class FormalParameter extends AstNode {
7753 /**
7754 * Return the element representing this parameter, or `null` if this parameter
7755 * has not been resolved.
7756 */
7757 ParameterElement get element {
7758 SimpleIdentifier identifier = this.identifier;
7759 if (identifier == null) {
7760 return null;
7761 }
7762 return identifier.staticElement as ParameterElement;
7763 }
7764
7765 /**
7766 * Return the name of the parameter being declared.
7767 */
7768 SimpleIdentifier get identifier;
7769
7770 /**
7771 * Return `true` if this parameter was declared with the 'const' modifier.
7772 */
7773 bool get isConst;
7774
7775 /**
7776 * Return `true` if this parameter was declared with the 'final' modifier.
7777 * Parameters that are declared with the 'const' modifier will return `false`
7778 * even though they are implicitly final.
7779 */
7780 bool get isFinal;
7781
7782 /**
7783 * Return the kind of this parameter.
7784 */
7785 ParameterKind get kind;
7786
7787 /**
7788 * Return the annotations associated with this parameter.
7789 */
7790 NodeList<Annotation> get metadata;
7791 }
7792
7793 /**
7794 * The formal parameter list of a method declaration, function declaration, or
7795 * function type alias.
7796 *
7797 * While the grammar requires all optional formal parameters to follow all of
7798 * the normal formal parameters and at most one grouping of optional formal
7799 * parameters, this class does not enforce those constraints. All parameters are
7800 * flattened into a single list, which can have any or all kinds of parameters
7801 * (normal, named, and positional) in any order.
7802 *
7803 * > formalParameterList ::=
7804 * > '(' ')'
7805 * > | '(' normalFormalParameters (',' optionalFormalParameters)? ')'
7806 * > | '(' optionalFormalParameters ')'
7807 * >
7808 * > normalFormalParameters ::=
7809 * > [NormalFormalParameter] (',' [NormalFormalParameter])*
7810 * >
7811 * > optionalFormalParameters ::=
7812 * > optionalPositionalFormalParameters
7813 * > | namedFormalParameters
7814 * >
7815 * > optionalPositionalFormalParameters ::=
7816 * > '[' [DefaultFormalParameter] (',' [DefaultFormalParameter])* ']'
7817 * >
7818 * > namedFormalParameters ::=
7819 * > '{' [DefaultFormalParameter] (',' [DefaultFormalParameter])* '}'
7820 */
7821 class FormalParameterList extends AstNode {
7822 /**
7823 * The left parenthesis.
7824 */
7825 Token leftParenthesis;
7826
7827 /**
7828 * The parameters associated with the method.
7829 */
7830 NodeList<FormalParameter> _parameters;
7831
7832 /**
7833 * The left square bracket ('[') or left curly brace ('{') introducing the
7834 * optional parameters, or `null` if there are no optional parameters.
7835 */
7836 Token leftDelimiter;
7837
7838 /**
7839 * The right square bracket (']') or right curly brace ('}') terminating the
7840 * optional parameters, or `null` if there are no optional parameters.
7841 */
7842 Token rightDelimiter;
7843
7844 /**
7845 * The right parenthesis.
7846 */
7847 Token rightParenthesis;
7848
7849 /**
7850 * Initialize a newly created parameter list. The list of [parameters] can be
7851 * `null` if there are no parameters. The [leftDelimiter] and [rightDelimiter]
7852 * can be `null` if there are no optional parameters.
7853 */
7854 FormalParameterList(this.leftParenthesis, List<FormalParameter> parameters,
7855 this.leftDelimiter, this.rightDelimiter, this.rightParenthesis) {
7856 _parameters = new NodeList<FormalParameter>(this, parameters);
7857 }
7858
7859 @override
7860 Token get beginToken => leftParenthesis;
7861
7862 @override
7863 Iterable get childEntities {
7864 // TODO(paulberry): include commas.
7865 ChildEntities result = new ChildEntities()..add(leftParenthesis);
7866 bool leftDelimiterNeeded = leftDelimiter != null;
7867 for (FormalParameter parameter in _parameters) {
7868 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) {
7869 result.add(leftDelimiter);
7870 leftDelimiterNeeded = false;
7871 }
7872 result.add(parameter);
7873 }
7874 return result..add(rightDelimiter)..add(rightParenthesis);
7875 }
7876
7877 @override
7878 Token get endToken => rightParenthesis;
7879
7880 /**
7881 * Return a list containing the elements representing the parameters in this
7882 * list. The list will contain `null`s if the parameters in this list have not
7883 * been resolved.
7884 */
7885 List<ParameterElement> get parameterElements {
7886 int count = _parameters.length;
7887 List<ParameterElement> types = new List<ParameterElement>(count);
7888 for (int i = 0; i < count; i++) {
7889 types[i] = _parameters[i].element;
7890 }
7891 return types;
7892 }
7893
7894 /**
7895 * Return the parameters associated with the method.
7896 */
7897 NodeList<FormalParameter> get parameters => _parameters;
7898
7899 @override
7900 accept(AstVisitor visitor) => visitor.visitFormalParameterList(this);
7901
7902 @override
7903 void visitChildren(AstVisitor visitor) {
7904 _parameters.accept(visitor);
7905 }
7906 }
7907
7908 /**
7909 * A for statement.
7910 *
7911 * > forStatement ::=
7912 * > 'for' '(' forLoopParts ')' [Statement]
7913 * >
7914 * > forLoopParts ::=
7915 * > forInitializerStatement ';' [Expression]? ';' [Expression]?
7916 * >
7917 * > forInitializerStatement ::=
7918 * > [DefaultFormalParameter]
7919 * > | [Expression]?
7920 */
7921 class ForStatement extends Statement {
7922 /**
7923 * The token representing the 'for' keyword.
7924 */
7925 Token forKeyword;
7926
7927 /**
7928 * The left parenthesis.
7929 */
7930 Token leftParenthesis;
7931
7932 /**
7933 * The declaration of the loop variables, or `null` if there are no variables.
7934 * Note that a for statement cannot have both a variable list and an
7935 * initialization expression, but can validly have neither.
7936 */
7937 VariableDeclarationList _variableList;
7938
7939 /**
7940 * The initialization expression, or `null` if there is no initialization
7941 * expression. Note that a for statement cannot have both a variable list and
7942 * an initialization expression, but can validly have neither.
7943 */
7944 Expression _initialization;
7945
7946 /**
7947 * The semicolon separating the initializer and the condition.
7948 */
7949 Token leftSeparator;
7950
7951 /**
7952 * The condition used to determine when to terminate the loop, or `null` if
7953 * there is no condition.
7954 */
7955 Expression _condition;
7956
7957 /**
7958 * The semicolon separating the condition and the updater.
7959 */
7960 Token rightSeparator;
7961
7962 /**
7963 * The list of expressions run after each execution of the loop body.
7964 */
7965 NodeList<Expression> _updaters;
7966
7967 /**
7968 * The right parenthesis.
7969 */
7970 Token rightParenthesis;
7971
7972 /**
7973 * The body of the loop.
7974 */
7975 Statement _body;
7976
7977 /**
7978 * Initialize a newly created for statement. Either the [variableList] or the
7979 * [initialization] must be `null`. Either the [condition] and the list of
7980 * [updaters] can be `null` if the loop does not have the corresponding
7981 * attribute.
7982 */
7983 ForStatement(
7984 this.forKeyword,
7985 this.leftParenthesis,
7986 VariableDeclarationList variableList,
7987 Expression initialization,
7988 this.leftSeparator,
7989 Expression condition,
7990 this.rightSeparator,
7991 List<Expression> updaters,
7992 this.rightParenthesis,
7993 Statement body) {
7994 _variableList = _becomeParentOf(variableList);
7995 _initialization = _becomeParentOf(initialization);
7996 _condition = _becomeParentOf(condition);
7997 _updaters = new NodeList<Expression>(this, updaters);
7998 _body = _becomeParentOf(body);
7999 }
8000
8001 @override
8002 Token get beginToken => forKeyword;
8003
8004 /**
8005 * Return the body of the loop.
8006 */
8007 Statement get body => _body;
8008
8009 /**
8010 * Set the body of the loop to the given [statement].
8011 */
8012 void set body(Statement statement) {
8013 _body = _becomeParentOf(statement);
8014 }
8015
8016 @override
8017 Iterable get childEntities => new ChildEntities()
8018 ..add(forKeyword)
8019 ..add(leftParenthesis)
8020 ..add(_variableList)
8021 ..add(_initialization)
8022 ..add(leftSeparator)
8023 ..add(_condition)
8024 ..add(rightSeparator)
8025 ..addAll(_updaters)
8026 ..add(rightParenthesis)
8027 ..add(_body);
8028
8029 /**
8030 * Return the condition used to determine when to terminate the loop, or
8031 * `null` if there is no condition.
8032 */
8033 Expression get condition => _condition;
8034
8035 /**
8036 * Set the condition used to determine when to terminate the loop to the given
8037 * [expression].
8038 */
8039 void set condition(Expression expression) {
8040 _condition = _becomeParentOf(expression);
8041 }
8042
8043 @override
8044 Token get endToken => _body.endToken;
8045
8046 /**
8047 * Return the initialization expression, or `null` if there is no
8048 * initialization expression.
8049 */
8050 Expression get initialization => _initialization;
8051
8052 /**
8053 * Set the initialization expression to the given [expression].
8054 */
8055 void set initialization(Expression initialization) {
8056 _initialization = _becomeParentOf(initialization);
8057 }
8058
8059 /**
8060 * Return the list of expressions run after each execution of the loop body.
8061 */
8062 NodeList<Expression> get updaters => _updaters;
8063
8064 /**
8065 * Return the declaration of the loop variables, or `null` if there are no
8066 * variables.
8067 */
8068 VariableDeclarationList get variables => _variableList;
8069
8070 /**
8071 * Set the declaration of the loop variables to the given [variableList].
8072 */
8073 void set variables(VariableDeclarationList variableList) {
8074 _variableList = _becomeParentOf(variableList);
8075 }
8076
8077 @override
8078 accept(AstVisitor visitor) => visitor.visitForStatement(this);
8079
8080 @override
8081 void visitChildren(AstVisitor visitor) {
8082 _safelyVisitChild(_variableList, visitor);
8083 _safelyVisitChild(_initialization, visitor);
8084 _safelyVisitChild(_condition, visitor);
8085 _updaters.accept(visitor);
8086 _safelyVisitChild(_body, visitor);
8087 }
8088 }
8089
8090 /**
8091 * A node representing the body of a function or method.
8092 *
8093 * > functionBody ::=
8094 * > [BlockFunctionBody]
8095 * > | [EmptyFunctionBody]
8096 * > | [ExpressionFunctionBody]
8097 */
8098 abstract class FunctionBody extends AstNode {
8099 /**
8100 * Return `true` if this function body is asynchronous.
8101 */
8102 bool get isAsynchronous => false;
8103
8104 /**
8105 * Return `true` if this function body is a generator.
8106 */
8107 bool get isGenerator => false;
8108
8109 /**
8110 * Return `true` if this function body is synchronous.
8111 */
8112 bool get isSynchronous => true;
8113
8114 /**
8115 * Return the token representing the 'async' or 'sync' keyword, or `null` if
8116 * there is no such keyword.
8117 */
8118 Token get keyword => null;
8119
8120 /**
8121 * Return the star following the 'async' or 'sync' keyword, or `null` if there
8122 * is no star.
8123 */
8124 Token get star => null;
8125 }
8126
8127 /**
8128 * A top-level declaration.
8129 *
8130 * > functionDeclaration ::=
8131 * > 'external' functionSignature
8132 * > | functionSignature [FunctionBody]
8133 * >
8134 * > functionSignature ::=
8135 * > [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList]
8136 */
8137 class FunctionDeclaration extends NamedCompilationUnitMember {
8138 /**
8139 * The token representing the 'external' keyword, or `null` if this is not an
8140 * external function.
8141 */
8142 Token externalKeyword;
8143
8144 /**
8145 * The return type of the function, or `null` if no return type was declared.
8146 */
8147 TypeName _returnType;
8148
8149 /**
8150 * The token representing the 'get' or 'set' keyword, or `null` if this is a
8151 * function declaration rather than a property declaration.
8152 */
8153 Token propertyKeyword;
8154
8155 /**
8156 * The function expression being wrapped.
8157 */
8158 FunctionExpression _functionExpression;
8159
8160 /**
8161 * Initialize a newly created function declaration. Either or both of the
8162 * [comment] and [metadata] can be `null` if the function does not have the
8163 * corresponding attribute. The [externalKeyword] can be `null` if the
8164 * function is not an external function. The [returnType] can be `null` if no
8165 * return type was specified. The [propertyKeyword] can be `null` if the
8166 * function is neither a getter or a setter.
8167 */
8168 FunctionDeclaration(
8169 Comment comment,
8170 List<Annotation> metadata,
8171 this.externalKeyword,
8172 TypeName returnType,
8173 this.propertyKeyword,
8174 SimpleIdentifier name,
8175 FunctionExpression functionExpression)
8176 : super(comment, metadata, name) {
8177 _returnType = _becomeParentOf(returnType);
8178 _functionExpression = _becomeParentOf(functionExpression);
8179 }
8180
8181 @override
8182 Iterable get childEntities => super._childEntities
8183 ..add(externalKeyword)
8184 ..add(_returnType)
8185 ..add(propertyKeyword)
8186 ..add(_name)
8187 ..add(_functionExpression);
8188
8189 @override
8190 ExecutableElement get element =>
8191 _name != null ? (_name.staticElement as ExecutableElement) : null;
8192
8193 @override
8194 Token get endToken => _functionExpression.endToken;
8195
8196 @override
8197 Token get firstTokenAfterCommentAndMetadata {
8198 if (externalKeyword != null) {
8199 return externalKeyword;
8200 } else if (_returnType != null) {
8201 return _returnType.beginToken;
8202 } else if (propertyKeyword != null) {
8203 return propertyKeyword;
8204 } else if (_name != null) {
8205 return _name.beginToken;
8206 }
8207 return _functionExpression.beginToken;
8208 }
8209
8210 /**
8211 * Return the function expression being wrapped.
8212 */
8213 FunctionExpression get functionExpression => _functionExpression;
8214
8215 /**
8216 * Set the function expression being wrapped to the given
8217 * [functionExpression].
8218 */
8219 void set functionExpression(FunctionExpression functionExpression) {
8220 _functionExpression = _becomeParentOf(functionExpression);
8221 }
8222
8223 /**
8224 * Return `true` if this function declares a getter.
8225 */
8226 bool get isGetter => propertyKeyword != null &&
8227 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
8228
8229 /**
8230 * Return `true` if this function declares a setter.
8231 */
8232 bool get isSetter => propertyKeyword != null &&
8233 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
8234
8235 /**
8236 * Return the return type of the function, or `null` if no return type was
8237 * declared.
8238 */
8239 TypeName get returnType => _returnType;
8240
8241 /**
8242 * Set the return type of the function to the given [returnType].
8243 */
8244 void set returnType(TypeName returnType) {
8245 _returnType = _becomeParentOf(returnType);
8246 }
8247
8248 @override
8249 accept(AstVisitor visitor) => visitor.visitFunctionDeclaration(this);
8250
8251 @override
8252 void visitChildren(AstVisitor visitor) {
8253 super.visitChildren(visitor);
8254 _safelyVisitChild(_returnType, visitor);
8255 _safelyVisitChild(_name, visitor);
8256 _safelyVisitChild(_functionExpression, visitor);
8257 }
8258 }
8259
8260 /**
8261 * A [FunctionDeclaration] used as a statement.
8262 */
8263 class FunctionDeclarationStatement extends Statement {
8264 /**
8265 * The function declaration being wrapped.
8266 */
8267 FunctionDeclaration _functionDeclaration;
8268
8269 /**
8270 * Initialize a newly created function declaration statement.
8271 */
8272 FunctionDeclarationStatement(FunctionDeclaration functionDeclaration) {
8273 _functionDeclaration = _becomeParentOf(functionDeclaration);
8274 }
8275
8276 @override
8277 Token get beginToken => _functionDeclaration.beginToken;
8278
8279 @override
8280 Iterable get childEntities => new ChildEntities()..add(_functionDeclaration);
8281
8282 @override
8283 Token get endToken => _functionDeclaration.endToken;
8284
8285 /**
8286 * Return the function declaration being wrapped.
8287 */
8288 FunctionDeclaration get functionDeclaration => _functionDeclaration;
8289
8290 /**
8291 * Set the function declaration being wrapped to the given
8292 * [functionDeclaration].
8293 */
8294 void set functionDeclaration(FunctionDeclaration functionDeclaration) {
8295 _functionDeclaration = _becomeParentOf(functionDeclaration);
8296 }
8297
8298 @override
8299 accept(AstVisitor visitor) => visitor.visitFunctionDeclarationStatement(this);
8300
8301 @override
8302 void visitChildren(AstVisitor visitor) {
8303 _safelyVisitChild(_functionDeclaration, visitor);
8304 }
8305 }
8306
8307 /**
8308 * A function expression.
8309 *
8310 * > functionExpression ::=
8311 * > [TypeParameterList]? [FormalParameterList] [FunctionBody]
8312 */
8313 class FunctionExpression extends Expression {
8314 /**
8315 * The type parameters associated with the method, or `null` if the method is
8316 * not a generic method.
8317 */
8318 TypeParameterList _typeParameters;
8319
8320 /**
8321 * The parameters associated with the function.
8322 */
8323 FormalParameterList _parameters;
8324
8325 /**
8326 * The body of the function, or `null` if this is an external function.
8327 */
8328 FunctionBody _body;
8329
8330 /**
8331 * The element associated with the function, or `null` if the AST structure
8332 * has not been resolved.
8333 */
8334 ExecutableElement element;
8335
8336 /**
8337 * Initialize a newly created function declaration.
8338 */
8339 FunctionExpression(TypeParameterList typeParameters,
8340 FormalParameterList parameters, FunctionBody body) {
8341 _typeParameters = _becomeParentOf(typeParameters);
8342 _parameters = _becomeParentOf(parameters);
8343 _body = _becomeParentOf(body);
8344 }
8345
8346 @override
8347 Token get beginToken {
8348 if (_typeParameters != null) {
8349 return _typeParameters.beginToken;
8350 } else if (_parameters != null) {
8351 return _parameters.beginToken;
8352 } else if (_body != null) {
8353 return _body.beginToken;
8354 }
8355 // This should never be reached because external functions must be named,
8356 // hence either the body or the name should be non-null.
8357 throw new IllegalStateException("Non-external functions must have a body");
8358 }
8359
8360 /**
8361 * Return the body of the function, or `null` if this is an external function.
8362 */
8363 FunctionBody get body => _body;
8364
8365 /**
8366 * Set the body of the function to the given [functionBody].
8367 */
8368 void set body(FunctionBody functionBody) {
8369 _body = _becomeParentOf(functionBody);
8370 }
8371
8372 @override
8373 Iterable get childEntities =>
8374 new ChildEntities()..add(_parameters)..add(_body);
8375
8376 @override
8377 Token get endToken {
8378 if (_body != null) {
8379 return _body.endToken;
8380 } else if (_parameters != null) {
8381 return _parameters.endToken;
8382 }
8383 // This should never be reached because external functions must be named,
8384 // hence either the body or the name should be non-null.
8385 throw new IllegalStateException("Non-external functions must have a body");
8386 }
8387
8388 /**
8389 * Return the parameters associated with the function.
8390 */
8391 FormalParameterList get parameters => _parameters;
8392
8393 /**
8394 * Set the parameters associated with the function to the given list of
8395 * [parameters].
8396 */
8397 void set parameters(FormalParameterList parameters) {
8398 _parameters = _becomeParentOf(parameters);
8399 }
8400
8401 @override
8402 int get precedence => 16;
8403
8404 /**
8405 * Return the type parameters associated with this method, or `null` if this
8406 * method is not a generic method.
8407 */
8408 TypeParameterList get typeParameters => _typeParameters;
8409
8410 /**
8411 * Set the type parameters associated with this method to the given
8412 * [typeParameters].
8413 */
8414 void set typeParameters(TypeParameterList typeParameters) {
8415 _typeParameters = _becomeParentOf(typeParameters);
8416 }
8417
8418 @override
8419 accept(AstVisitor visitor) => visitor.visitFunctionExpression(this);
8420
8421 @override
8422 void visitChildren(AstVisitor visitor) {
8423 _safelyVisitChild(_typeParameters, visitor);
8424 _safelyVisitChild(_parameters, visitor);
8425 _safelyVisitChild(_body, visitor);
8426 }
8427 }
8428
8429 /**
8430 * The invocation of a function resulting from evaluating an expression.
8431 * Invocations of methods and other forms of functions are represented by
8432 * [MethodInvocation] nodes. Invocations of getters and setters are represented
8433 * by either [PrefixedIdentifier] or [PropertyAccess] nodes.
8434 *
8435 * > functionExpressionInvoction ::=
8436 * > [Expression] [TypeArgumentList]? [ArgumentList]
8437 */
8438 class FunctionExpressionInvocation extends Expression {
8439 /**
8440 * The expression producing the function being invoked.
8441 */
8442 Expression _function;
8443
8444 /**
8445 * The type arguments to be applied to the method being invoked, or `null` if
8446 * no type arguments were provided.
8447 */
8448 TypeArgumentList _typeArguments;
8449
8450 /**
8451 * The list of arguments to the function.
8452 */
8453 ArgumentList _argumentList;
8454
8455 /**
8456 * The element associated with the function being invoked based on static type
8457 * information, or `null` if the AST structure has not been resolved or the
8458 * function could not be resolved.
8459 */
8460 ExecutableElement staticElement;
8461
8462 /**
8463 * The element associated with the function being invoked based on propagated
8464 * type information, or `null` if the AST structure has not been resolved or
8465 * the function could not be resolved.
8466 */
8467 ExecutableElement propagatedElement;
8468
8469 /**
8470 * Initialize a newly created function expression invocation.
8471 */
8472 FunctionExpressionInvocation(Expression function,
8473 TypeArgumentList typeArguments, ArgumentList argumentList) {
8474 _function = _becomeParentOf(function);
8475 _typeArguments = _becomeParentOf(typeArguments);
8476 _argumentList = _becomeParentOf(argumentList);
8477 }
8478
8479 /**
8480 * Return the list of arguments to the method.
8481 */
8482 ArgumentList get argumentList => _argumentList;
8483
8484 /**
8485 * Set the list of arguments to the method to the given [argumentList].
8486 */
8487 void set argumentList(ArgumentList argumentList) {
8488 _argumentList = _becomeParentOf(argumentList);
8489 }
8490
8491 @override
8492 Token get beginToken => _function.beginToken;
8493
8494 /**
8495 * Return the best element available for the function being invoked. If
8496 * resolution was able to find a better element based on type propagation,
8497 * that element will be returned. Otherwise, the element found using the
8498 * result of static analysis will be returned. If resolution has not been
8499 * performed, then `null` will be returned.
8500 */
8501 ExecutableElement get bestElement {
8502 ExecutableElement element = propagatedElement;
8503 if (element == null) {
8504 element = staticElement;
8505 }
8506 return element;
8507 }
8508
8509 @override
8510 Iterable get childEntities =>
8511 new ChildEntities()..add(_function)..add(_argumentList);
8512
8513 @override
8514 Token get endToken => _argumentList.endToken;
8515
8516 /**
8517 * Return the expression producing the function being invoked.
8518 */
8519 Expression get function => _function;
8520
8521 /**
8522 * Set the expression producing the function being invoked to the given
8523 * [expression].
8524 */
8525 void set function(Expression expression) {
8526 _function = _becomeParentOf(expression);
8527 }
8528
8529 @override
8530 int get precedence => 15;
8531
8532 /**
8533 * Return the type arguments to be applied to the method being invoked, or
8534 * `null` if no type arguments were provided.
8535 */
8536 TypeArgumentList get typeArguments => _typeArguments;
8537
8538 /**
8539 * Set the type arguments to be applied to the method being invoked to the
8540 * given [typeArguments].
8541 */
8542 void set typeArguments(TypeArgumentList typeArguments) {
8543 _typeArguments = _becomeParentOf(typeArguments);
8544 }
8545
8546 @override
8547 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this);
8548
8549 @override
8550 void visitChildren(AstVisitor visitor) {
8551 _safelyVisitChild(_function, visitor);
8552 _safelyVisitChild(_typeArguments, visitor);
8553 _safelyVisitChild(_argumentList, visitor);
8554 }
8555 }
8556
8557 /**
8558 * A function type alias.
8559 *
8560 * > functionTypeAlias ::=
8561 * > functionPrefix [TypeParameterList]? [FormalParameterList] ';'
8562 * >
8563 * > functionPrefix ::=
8564 * > [TypeName]? [SimpleIdentifier]
8565 */
8566 class FunctionTypeAlias extends TypeAlias {
8567 /**
8568 * The name of the return type of the function type being defined, or `null`
8569 * if no return type was given.
8570 */
8571 TypeName _returnType;
8572
8573 /**
8574 * The type parameters for the function type, or `null` if the function type
8575 * does not have any type parameters.
8576 */
8577 TypeParameterList _typeParameters;
8578
8579 /**
8580 * The parameters associated with the function type.
8581 */
8582 FormalParameterList _parameters;
8583
8584 /**
8585 * Initialize a newly created function type alias. Either or both of the
8586 * [comment] and [metadata] can be `null` if the function does not have the
8587 * corresponding attribute. The [returnType] can be `null` if no return type
8588 * was specified. The [typeParameters] can be `null` if the function has no
8589 * type parameters.
8590 */
8591 FunctionTypeAlias(
8592 Comment comment,
8593 List<Annotation> metadata,
8594 Token keyword,
8595 TypeName returnType,
8596 SimpleIdentifier name,
8597 TypeParameterList typeParameters,
8598 FormalParameterList parameters,
8599 Token semicolon)
8600 : super(comment, metadata, keyword, name, semicolon) {
8601 _returnType = _becomeParentOf(returnType);
8602 _typeParameters = _becomeParentOf(typeParameters);
8603 _parameters = _becomeParentOf(parameters);
8604 }
8605
8606 @override
8607 Iterable get childEntities => super._childEntities
8608 ..add(typedefKeyword)
8609 ..add(_returnType)
8610 ..add(_name)
8611 ..add(_typeParameters)
8612 ..add(_parameters)
8613 ..add(semicolon);
8614
8615 @override
8616 FunctionTypeAliasElement get element =>
8617 _name != null ? (_name.staticElement as FunctionTypeAliasElement) : null;
8618
8619 /**
8620 * Return the parameters associated with the function type.
8621 */
8622 FormalParameterList get parameters => _parameters;
8623
8624 /**
8625 * Set the parameters associated with the function type to the given list of
8626 * [parameters].
8627 */
8628 void set parameters(FormalParameterList parameters) {
8629 _parameters = _becomeParentOf(parameters);
8630 }
8631
8632 /**
8633 * Return the name of the return type of the function type being defined, or
8634 * `null` if no return type was given.
8635 */
8636 TypeName get returnType => _returnType;
8637
8638 /**
8639 * Set the name of the return type of the function type being defined to the
8640 * given [typeName].
8641 */
8642 void set returnType(TypeName typeName) {
8643 _returnType = _becomeParentOf(typeName);
8644 }
8645
8646 /**
8647 * Return the type parameters for the function type, or `null` if the function
8648 * type does not have any type parameters.
8649 */
8650 TypeParameterList get typeParameters => _typeParameters;
8651
8652 /**
8653 * Set the type parameters for the function type to the given list of
8654 * [typeParameters].
8655 */
8656 void set typeParameters(TypeParameterList typeParameters) {
8657 _typeParameters = _becomeParentOf(typeParameters);
8658 }
8659
8660 @override
8661 accept(AstVisitor visitor) => visitor.visitFunctionTypeAlias(this);
8662
8663 @override
8664 void visitChildren(AstVisitor visitor) {
8665 super.visitChildren(visitor);
8666 _safelyVisitChild(_returnType, visitor);
8667 _safelyVisitChild(_name, visitor);
8668 _safelyVisitChild(_typeParameters, visitor);
8669 _safelyVisitChild(_parameters, visitor);
8670 }
8671 }
8672
8673 /**
8674 * A function-typed formal parameter.
8675 *
8676 * > functionSignature ::=
8677 * > [TypeName]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterLis t]
8678 */
8679 class FunctionTypedFormalParameter extends NormalFormalParameter {
8680 /**
8681 * The return type of the function, or `null` if the function does not have a
8682 * return type.
8683 */
8684 TypeName _returnType;
8685
8686 /**
8687 * The type parameters associated with the function, or `null` if the function
8688 * is not a generic function.
8689 */
8690 TypeParameterList _typeParameters;
8691
8692 /**
8693 * The parameters of the function-typed parameter.
8694 */
8695 FormalParameterList _parameters;
8696
8697 /**
8698 * Initialize a newly created formal parameter. Either or both of the
8699 * [comment] and [metadata] can be `null` if the parameter does not have the
8700 * corresponding attribute. The [returnType] can be `null` if no return type
8701 * was specified.
8702 */
8703 FunctionTypedFormalParameter(
8704 Comment comment,
8705 List<Annotation> metadata,
8706 TypeName returnType,
8707 SimpleIdentifier identifier,
8708 TypeParameterList typeParameters,
8709 FormalParameterList parameters)
8710 : super(comment, metadata, identifier) {
8711 _returnType = _becomeParentOf(returnType);
8712 _typeParameters = _becomeParentOf(typeParameters);
8713 _parameters = _becomeParentOf(parameters);
8714 }
8715
8716 @override
8717 Token get beginToken {
8718 if (_returnType != null) {
8719 return _returnType.beginToken;
8720 }
8721 return identifier.beginToken;
8722 }
8723
8724 @override
8725 Iterable get childEntities =>
8726 super._childEntities..add(_returnType)..add(identifier)..add(parameters);
8727
8728 @override
8729 Token get endToken => _parameters.endToken;
8730
8731 @override
8732 bool get isConst => false;
8733
8734 @override
8735 bool get isFinal => false;
8736
8737 /**
8738 * Return the parameters of the function-typed parameter.
8739 */
8740 FormalParameterList get parameters => _parameters;
8741
8742 /**
8743 * Set the parameters of the function-typed parameter to the given
8744 * [parameters].
8745 */
8746 void set parameters(FormalParameterList parameters) {
8747 _parameters = _becomeParentOf(parameters);
8748 }
8749
8750 /**
8751 * Return the return type of the function, or `null` if the function does not
8752 * have a return type.
8753 */
8754 TypeName get returnType => _returnType;
8755
8756 /**
8757 * Set the return type of the function to the given [type].
8758 */
8759 void set returnType(TypeName type) {
8760 _returnType = _becomeParentOf(type);
8761 }
8762
8763 /**
8764 * Return the type parameters associated with this function, or `null` if
8765 * this function is not a generic function.
8766 */
8767 TypeParameterList get typeParameters => _typeParameters;
8768
8769 /**
8770 * Set the type parameters associated with this method to the given
8771 * [typeParameters].
8772 */
8773 void set typeParameters(TypeParameterList typeParameters) {
8774 _typeParameters = _becomeParentOf(typeParameters);
8775 }
8776
8777 @override
8778 accept(AstVisitor visitor) => visitor.visitFunctionTypedFormalParameter(this);
8779
8780 @override
8781 void visitChildren(AstVisitor visitor) {
8782 super.visitChildren(visitor);
8783 _safelyVisitChild(_returnType, visitor);
8784 _safelyVisitChild(identifier, visitor);
8785 _safelyVisitChild(_typeParameters, visitor);
8786 _safelyVisitChild(_parameters, visitor);
8787 }
8788 }
8789
8790 /**
8791 * An AST visitor that will recursively visit all of the nodes in an AST
8792 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
8793 * when a node of a specific type is visited not only will the visit method for
8794 * that specific type of node be invoked, but additional methods for the
8795 * superclasses of that node will also be invoked. For example, using an
8796 * instance of this class to visit a [Block] will cause the method [visitBlock]
8797 * to be invoked but will also cause the methods [visitStatement] and
8798 * [visitNode] to be subsequently invoked. This allows visitors to be written
8799 * that visit all statements without needing to override the visit method for
8800 * each of the specific subclasses of [Statement].
8801 *
8802 * Subclasses that override a visit method must either invoke the overridden
8803 * visit method or explicitly invoke the more general visit method. Failure to
8804 * do so will cause the visit methods for superclasses of the node to not be
8805 * invoked and will cause the children of the visited node to not be visited.
8806 */
8807 class GeneralizingAstVisitor<R> implements AstVisitor<R> {
8808 @override
8809 R visitAdjacentStrings(AdjacentStrings node) => visitStringLiteral(node);
8810
8811 R visitAnnotatedNode(AnnotatedNode node) => visitNode(node);
8812
8813 @override
8814 R visitAnnotation(Annotation node) => visitNode(node);
8815
8816 @override
8817 R visitArgumentList(ArgumentList node) => visitNode(node);
8818
8819 @override
8820 R visitAsExpression(AsExpression node) => visitExpression(node);
8821
8822 @override
8823 R visitAssertStatement(AssertStatement node) => visitStatement(node);
8824
8825 @override
8826 R visitAssignmentExpression(AssignmentExpression node) =>
8827 visitExpression(node);
8828
8829 @override
8830 R visitAwaitExpression(AwaitExpression node) => visitExpression(node);
8831
8832 @override
8833 R visitBinaryExpression(BinaryExpression node) => visitExpression(node);
8834
8835 @override
8836 R visitBlock(Block node) => visitStatement(node);
8837
8838 @override
8839 R visitBlockFunctionBody(BlockFunctionBody node) => visitFunctionBody(node);
8840
8841 @override
8842 R visitBooleanLiteral(BooleanLiteral node) => visitLiteral(node);
8843
8844 @override
8845 R visitBreakStatement(BreakStatement node) => visitStatement(node);
8846
8847 @override
8848 R visitCascadeExpression(CascadeExpression node) => visitExpression(node);
8849
8850 @override
8851 R visitCatchClause(CatchClause node) => visitNode(node);
8852
8853 @override
8854 R visitClassDeclaration(ClassDeclaration node) =>
8855 visitNamedCompilationUnitMember(node);
8856
8857 R visitClassMember(ClassMember node) => visitDeclaration(node);
8858
8859 @override
8860 R visitClassTypeAlias(ClassTypeAlias node) => visitTypeAlias(node);
8861
8862 R visitCombinator(Combinator node) => visitNode(node);
8863
8864 @override
8865 R visitComment(Comment node) => visitNode(node);
8866
8867 @override
8868 R visitCommentReference(CommentReference node) => visitNode(node);
8869
8870 @override
8871 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
8872
8873 R visitCompilationUnitMember(CompilationUnitMember node) =>
8874 visitDeclaration(node);
8875
8876 @override
8877 R visitConditionalExpression(ConditionalExpression node) =>
8878 visitExpression(node);
8879
8880 @override
8881 R visitConstructorDeclaration(ConstructorDeclaration node) =>
8882 visitClassMember(node);
8883
8884 @override
8885 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
8886 visitConstructorInitializer(node);
8887
8888 R visitConstructorInitializer(ConstructorInitializer node) => visitNode(node);
8889
8890 @override
8891 R visitConstructorName(ConstructorName node) => visitNode(node);
8892
8893 @override
8894 R visitContinueStatement(ContinueStatement node) => visitStatement(node);
8895
8896 R visitDeclaration(Declaration node) => visitAnnotatedNode(node);
8897
8898 @override
8899 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitDeclaration(node);
8900
8901 @override
8902 R visitDefaultFormalParameter(DefaultFormalParameter node) =>
8903 visitFormalParameter(node);
8904
8905 R visitDirective(Directive node) => visitAnnotatedNode(node);
8906
8907 @override
8908 R visitDoStatement(DoStatement node) => visitStatement(node);
8909
8910 @override
8911 R visitDoubleLiteral(DoubleLiteral node) => visitLiteral(node);
8912
8913 @override
8914 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitFunctionBody(node);
8915
8916 @override
8917 R visitEmptyStatement(EmptyStatement node) => visitStatement(node);
8918
8919 @override
8920 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
8921 visitDeclaration(node);
8922
8923 @override
8924 R visitEnumDeclaration(EnumDeclaration node) =>
8925 visitNamedCompilationUnitMember(node);
8926
8927 @override
8928 R visitExportDirective(ExportDirective node) => visitNamespaceDirective(node);
8929
8930 R visitExpression(Expression node) => visitNode(node);
8931
8932 @override
8933 R visitExpressionFunctionBody(ExpressionFunctionBody node) =>
8934 visitFunctionBody(node);
8935
8936 @override
8937 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node);
8938
8939 @override
8940 R visitExtendsClause(ExtendsClause node) => visitNode(node);
8941
8942 @override
8943 R visitFieldDeclaration(FieldDeclaration node) => visitClassMember(node);
8944
8945 @override
8946 R visitFieldFormalParameter(FieldFormalParameter node) =>
8947 visitNormalFormalParameter(node);
8948
8949 @override
8950 R visitForEachStatement(ForEachStatement node) => visitStatement(node);
8951
8952 R visitFormalParameter(FormalParameter node) => visitNode(node);
8953
8954 @override
8955 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
8956
8957 @override
8958 R visitForStatement(ForStatement node) => visitStatement(node);
8959
8960 R visitFunctionBody(FunctionBody node) => visitNode(node);
8961
8962 @override
8963 R visitFunctionDeclaration(FunctionDeclaration node) =>
8964 visitNamedCompilationUnitMember(node);
8965
8966 @override
8967 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
8968 visitStatement(node);
8969
8970 @override
8971 R visitFunctionExpression(FunctionExpression node) => visitExpression(node);
8972
8973 @override
8974 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
8975 visitExpression(node);
8976
8977 @override
8978 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitTypeAlias(node);
8979
8980 @override
8981 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
8982 visitNormalFormalParameter(node);
8983
8984 @override
8985 R visitHideCombinator(HideCombinator node) => visitCombinator(node);
8986
8987 R visitIdentifier(Identifier node) => visitExpression(node);
8988
8989 @override
8990 R visitIfStatement(IfStatement node) => visitStatement(node);
8991
8992 @override
8993 R visitImplementsClause(ImplementsClause node) => visitNode(node);
8994
8995 @override
8996 R visitImportDirective(ImportDirective node) => visitNamespaceDirective(node);
8997
8998 @override
8999 R visitIndexExpression(IndexExpression node) => visitExpression(node);
9000
9001 @override
9002 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
9003 visitExpression(node);
9004
9005 @override
9006 R visitIntegerLiteral(IntegerLiteral node) => visitLiteral(node);
9007
9008 R visitInterpolationElement(InterpolationElement node) => visitNode(node);
9009
9010 @override
9011 R visitInterpolationExpression(InterpolationExpression node) =>
9012 visitInterpolationElement(node);
9013
9014 @override
9015 R visitInterpolationString(InterpolationString node) =>
9016 visitInterpolationElement(node);
9017
9018 @override
9019 R visitIsExpression(IsExpression node) => visitExpression(node);
9020
9021 @override
9022 R visitLabel(Label node) => visitNode(node);
9023
9024 @override
9025 R visitLabeledStatement(LabeledStatement node) => visitStatement(node);
9026
9027 @override
9028 R visitLibraryDirective(LibraryDirective node) => visitDirective(node);
9029
9030 @override
9031 R visitLibraryIdentifier(LibraryIdentifier node) => visitIdentifier(node);
9032
9033 @override
9034 R visitListLiteral(ListLiteral node) => visitTypedLiteral(node);
9035
9036 R visitLiteral(Literal node) => visitExpression(node);
9037
9038 @override
9039 R visitMapLiteral(MapLiteral node) => visitTypedLiteral(node);
9040
9041 @override
9042 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
9043
9044 @override
9045 R visitMethodDeclaration(MethodDeclaration node) => visitClassMember(node);
9046
9047 @override
9048 R visitMethodInvocation(MethodInvocation node) => visitExpression(node);
9049
9050 R visitNamedCompilationUnitMember(NamedCompilationUnitMember node) =>
9051 visitCompilationUnitMember(node);
9052
9053 @override
9054 R visitNamedExpression(NamedExpression node) => visitExpression(node);
9055
9056 R visitNamespaceDirective(NamespaceDirective node) =>
9057 visitUriBasedDirective(node);
9058
9059 @override
9060 R visitNativeClause(NativeClause node) => visitNode(node);
9061
9062 @override
9063 R visitNativeFunctionBody(NativeFunctionBody node) => visitFunctionBody(node);
9064
9065 R visitNode(AstNode node) {
9066 node.visitChildren(this);
9067 return null;
9068 }
9069
9070 R visitNormalFormalParameter(NormalFormalParameter node) =>
9071 visitFormalParameter(node);
9072
9073 @override
9074 R visitNullLiteral(NullLiteral node) => visitLiteral(node);
9075
9076 @override
9077 R visitParenthesizedExpression(ParenthesizedExpression node) =>
9078 visitExpression(node);
9079
9080 @override
9081 R visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
9082
9083 @override
9084 R visitPartOfDirective(PartOfDirective node) => visitDirective(node);
9085
9086 @override
9087 R visitPostfixExpression(PostfixExpression node) => visitExpression(node);
9088
9089 @override
9090 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitIdentifier(node);
9091
9092 @override
9093 R visitPrefixExpression(PrefixExpression node) => visitExpression(node);
9094
9095 @override
9096 R visitPropertyAccess(PropertyAccess node) => visitExpression(node);
9097
9098 @override
9099 R visitRedirectingConstructorInvocation(
9100 RedirectingConstructorInvocation node) =>
9101 visitConstructorInitializer(node);
9102
9103 @override
9104 R visitRethrowExpression(RethrowExpression node) => visitExpression(node);
9105
9106 @override
9107 R visitReturnStatement(ReturnStatement node) => visitStatement(node);
9108
9109 @override
9110 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
9111
9112 @override
9113 R visitShowCombinator(ShowCombinator node) => visitCombinator(node);
9114
9115 @override
9116 R visitSimpleFormalParameter(SimpleFormalParameter node) =>
9117 visitNormalFormalParameter(node);
9118
9119 @override
9120 R visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node);
9121
9122 @override
9123 R visitSimpleStringLiteral(SimpleStringLiteral node) =>
9124 visitSingleStringLiteral(node);
9125
9126 R visitSingleStringLiteral(SingleStringLiteral node) =>
9127 visitStringLiteral(node);
9128
9129 R visitStatement(Statement node) => visitNode(node);
9130
9131 @override
9132 R visitStringInterpolation(StringInterpolation node) =>
9133 visitSingleStringLiteral(node);
9134
9135 R visitStringLiteral(StringLiteral node) => visitLiteral(node);
9136
9137 @override
9138 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
9139 visitConstructorInitializer(node);
9140
9141 @override
9142 R visitSuperExpression(SuperExpression node) => visitExpression(node);
9143
9144 @override
9145 R visitSwitchCase(SwitchCase node) => visitSwitchMember(node);
9146
9147 @override
9148 R visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
9149
9150 R visitSwitchMember(SwitchMember node) => visitNode(node);
9151
9152 @override
9153 R visitSwitchStatement(SwitchStatement node) => visitStatement(node);
9154
9155 @override
9156 R visitSymbolLiteral(SymbolLiteral node) => visitLiteral(node);
9157
9158 @override
9159 R visitThisExpression(ThisExpression node) => visitExpression(node);
9160
9161 @override
9162 R visitThrowExpression(ThrowExpression node) => visitExpression(node);
9163
9164 @override
9165 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
9166 visitCompilationUnitMember(node);
9167
9168 @override
9169 R visitTryStatement(TryStatement node) => visitStatement(node);
9170
9171 R visitTypeAlias(TypeAlias node) => visitNamedCompilationUnitMember(node);
9172
9173 @override
9174 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
9175
9176 R visitTypedLiteral(TypedLiteral node) => visitLiteral(node);
9177
9178 @override
9179 R visitTypeName(TypeName node) => visitNode(node);
9180
9181 @override
9182 R visitTypeParameter(TypeParameter node) => visitNode(node);
9183
9184 @override
9185 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
9186
9187 R visitUriBasedDirective(UriBasedDirective node) => visitDirective(node);
9188
9189 @override
9190 R visitVariableDeclaration(VariableDeclaration node) =>
9191 visitDeclaration(node);
9192
9193 @override
9194 R visitVariableDeclarationList(VariableDeclarationList node) =>
9195 visitNode(node);
9196
9197 @override
9198 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
9199 visitStatement(node);
9200
9201 @override
9202 R visitWhileStatement(WhileStatement node) => visitStatement(node);
9203
9204 @override
9205 R visitWithClause(WithClause node) => visitNode(node);
9206
9207 @override
9208 R visitYieldStatement(YieldStatement node) => visitStatement(node);
9209 }
9210
9211 class GeneralizingAstVisitor_BreadthFirstVisitor
9212 extends GeneralizingAstVisitor<Object> {
9213 final BreadthFirstVisitor BreadthFirstVisitor_this;
9214
9215 GeneralizingAstVisitor_BreadthFirstVisitor(this.BreadthFirstVisitor_this)
9216 : super();
9217
9218 @override
9219 Object visitNode(AstNode node) {
9220 BreadthFirstVisitor_this._queue.add(node);
9221 return null;
9222 }
9223 }
9224
9225 /**
9226 * A combinator that restricts the names being imported to those that are not in
9227 * a given list.
9228 *
9229 * > hideCombinator ::=
9230 * > 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])*
9231 */
9232 class HideCombinator extends Combinator {
9233 /**
9234 * The list of names from the library that are hidden by this combinator.
9235 */
9236 NodeList<SimpleIdentifier> _hiddenNames;
9237
9238 /**
9239 * Initialize a newly created import show combinator.
9240 */
9241 HideCombinator(Token keyword, List<SimpleIdentifier> hiddenNames)
9242 : super(keyword) {
9243 _hiddenNames = new NodeList<SimpleIdentifier>(this, hiddenNames);
9244 }
9245
9246 @override
9247 Iterable get childEntities => new ChildEntities()
9248 ..add(keyword)
9249 ..addAll(_hiddenNames);
9250
9251 @override
9252 Token get endToken => _hiddenNames.endToken;
9253
9254 /**
9255 * Return the list of names from the library that are hidden by this
9256 * combinator.
9257 */
9258 NodeList<SimpleIdentifier> get hiddenNames => _hiddenNames;
9259
9260 @override
9261 accept(AstVisitor visitor) => visitor.visitHideCombinator(this);
9262
9263 @override
9264 void visitChildren(AstVisitor visitor) {
9265 _hiddenNames.accept(visitor);
9266 }
9267 }
9268
9269 /**
9270 * A node that represents an identifier.
9271 *
9272 * > identifier ::=
9273 * > [SimpleIdentifier]
9274 * > | [PrefixedIdentifier]
9275 */
9276 abstract class Identifier extends Expression {
9277 /**
9278 * Return the best element available for this operator. If resolution was able
9279 * to find a better element based on type propagation, that element will be
9280 * returned. Otherwise, the element found using the result of static analysis
9281 * will be returned. If resolution has not been performed, then `null` will be
9282 * returned.
9283 */
9284 Element get bestElement;
9285
9286 @override
9287 bool get isAssignable => true;
9288
9289 /**
9290 * Return the lexical representation of the identifier.
9291 */
9292 String get name;
9293
9294 /**
9295 * Return the element associated with this identifier based on propagated type
9296 * information, or `null` if the AST structure has not been resolved or if
9297 * this identifier could not be resolved. One example of the latter case is an
9298 * identifier that is not defined within the scope in which it appears.
9299 */
9300 Element get propagatedElement;
9301
9302 /**
9303 * Return the element associated with this identifier based on static type
9304 * information, or `null` if the AST structure has not been resolved or if
9305 * this identifier could not be resolved. One example of the latter case is an
9306 * identifier that is not defined within the scope in which it appears
9307 */
9308 Element get staticElement;
9309
9310 /**
9311 * Return `true` if the given [name] is visible only within the library in
9312 * which it is declared.
9313 */
9314 static bool isPrivateName(String name) =>
9315 StringUtilities.startsWithChar(name, 0x5F);
9316 }
9317
9318 /**
9319 * An if statement.
9320 *
9321 * > ifStatement ::=
9322 * > 'if' '(' [Expression] ')' [Statement] ('else' [Statement])?
9323 */
9324 class IfStatement extends Statement {
9325 /**
9326 * The token representing the 'if' keyword.
9327 */
9328 Token ifKeyword;
9329
9330 /**
9331 * The left parenthesis.
9332 */
9333 Token leftParenthesis;
9334
9335 /**
9336 * The condition used to determine which of the statements is executed next.
9337 */
9338 Expression _condition;
9339
9340 /**
9341 * The right parenthesis.
9342 */
9343 Token rightParenthesis;
9344
9345 /**
9346 * The statement that is executed if the condition evaluates to `true`.
9347 */
9348 Statement _thenStatement;
9349
9350 /**
9351 * The token representing the 'else' keyword, or `null` if there is no else
9352 * statement.
9353 */
9354 Token elseKeyword;
9355
9356 /**
9357 * The statement that is executed if the condition evaluates to `false`, or
9358 * `null` if there is no else statement.
9359 */
9360 Statement _elseStatement;
9361
9362 /**
9363 * Initialize a newly created if statement. The [elseKeyword] and
9364 * [elseStatement] can be `null` if there is no else clause.
9365 */
9366 IfStatement(
9367 this.ifKeyword,
9368 this.leftParenthesis,
9369 Expression condition,
9370 this.rightParenthesis,
9371 Statement thenStatement,
9372 this.elseKeyword,
9373 Statement elseStatement) {
9374 _condition = _becomeParentOf(condition);
9375 _thenStatement = _becomeParentOf(thenStatement);
9376 _elseStatement = _becomeParentOf(elseStatement);
9377 }
9378
9379 @override
9380 Token get beginToken => ifKeyword;
9381
9382 @override
9383 Iterable get childEntities => new ChildEntities()
9384 ..add(ifKeyword)
9385 ..add(leftParenthesis)
9386 ..add(_condition)
9387 ..add(rightParenthesis)
9388 ..add(_thenStatement)
9389 ..add(elseKeyword)
9390 ..add(_elseStatement);
9391
9392 /**
9393 * Return the condition used to determine which of the statements is executed
9394 * next.
9395 */
9396 Expression get condition => _condition;
9397
9398 /**
9399 * Set the condition used to determine which of the statements is executed
9400 * next to the given [expression].
9401 */
9402 void set condition(Expression expression) {
9403 _condition = _becomeParentOf(expression);
9404 }
9405
9406 /**
9407 * Return the statement that is executed if the condition evaluates to
9408 * `false`, or `null` if there is no else statement.
9409 */
9410 Statement get elseStatement => _elseStatement;
9411
9412 /**
9413 * Set the statement that is executed if the condition evaluates to `false`
9414 * to the given [statement].
9415 */
9416 void set elseStatement(Statement statement) {
9417 _elseStatement = _becomeParentOf(statement);
9418 }
9419
9420 @override
9421 Token get endToken {
9422 if (_elseStatement != null) {
9423 return _elseStatement.endToken;
9424 }
9425 return _thenStatement.endToken;
9426 }
9427
9428 /**
9429 * Return the statement that is executed if the condition evaluates to `true`.
9430 */
9431 Statement get thenStatement => _thenStatement;
9432
9433 /**
9434 * Set the statement that is executed if the condition evaluates to `true` to
9435 * the given [statement].
9436 */
9437 void set thenStatement(Statement statement) {
9438 _thenStatement = _becomeParentOf(statement);
9439 }
9440
9441 @override
9442 accept(AstVisitor visitor) => visitor.visitIfStatement(this);
9443
9444 @override
9445 void visitChildren(AstVisitor visitor) {
9446 _safelyVisitChild(_condition, visitor);
9447 _safelyVisitChild(_thenStatement, visitor);
9448 _safelyVisitChild(_elseStatement, visitor);
9449 }
9450 }
9451
9452 /**
9453 * The "implements" clause in an class declaration.
9454 *
9455 * > implementsClause ::=
9456 * > 'implements' [TypeName] (',' [TypeName])*
9457 */
9458 class ImplementsClause extends AstNode {
9459 /**
9460 * The token representing the 'implements' keyword.
9461 */
9462 Token implementsKeyword;
9463
9464 /**
9465 * The interfaces that are being implemented.
9466 */
9467 NodeList<TypeName> _interfaces;
9468
9469 /**
9470 * Initialize a newly created implements clause.
9471 */
9472 ImplementsClause(this.implementsKeyword, List<TypeName> interfaces) {
9473 _interfaces = new NodeList<TypeName>(this, interfaces);
9474 }
9475
9476 @override
9477 Token get beginToken => implementsKeyword;
9478
9479 @override
9480 // TODO(paulberry): add commas.
9481 Iterable get childEntities => new ChildEntities()
9482 ..add(implementsKeyword)
9483 ..addAll(interfaces);
9484
9485 @override
9486 Token get endToken => _interfaces.endToken;
9487
9488 /**
9489 * Return the list of the interfaces that are being implemented.
9490 */
9491 NodeList<TypeName> get interfaces => _interfaces;
9492
9493 /**
9494 * Return the token representing the 'implements' keyword.
9495 */
9496 @deprecated // Use "this.implementsKeyword"
9497 Token get keyword => implementsKeyword;
9498
9499 /**
9500 * Set the token representing the 'implements' keyword to the given [token].
9501 */
9502 @deprecated // Use "this.implementsKeyword"
9503 set keyword(Token token) {
9504 implementsKeyword = token;
9505 }
9506
9507 @override
9508 accept(AstVisitor visitor) => visitor.visitImplementsClause(this);
9509
9510 @override
9511 void visitChildren(AstVisitor visitor) {
9512 _interfaces.accept(visitor);
9513 }
9514 }
9515
9516 /**
9517 * An import directive.
9518 *
9519 * > importDirective ::=
9520 * > [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* ';'
9521 * > | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combi nator]* ';'
9522 */
9523 class ImportDirective extends NamespaceDirective {
9524 static Comparator<ImportDirective> COMPARATOR =
9525 (ImportDirective import1, ImportDirective import2) {
9526 //
9527 // uri
9528 //
9529 StringLiteral uri1 = import1.uri;
9530 StringLiteral uri2 = import2.uri;
9531 String uriStr1 = uri1.stringValue;
9532 String uriStr2 = uri2.stringValue;
9533 if (uriStr1 != null || uriStr2 != null) {
9534 if (uriStr1 == null) {
9535 return -1;
9536 } else if (uriStr2 == null) {
9537 return 1;
9538 } else {
9539 int compare = uriStr1.compareTo(uriStr2);
9540 if (compare != 0) {
9541 return compare;
9542 }
9543 }
9544 }
9545 //
9546 // as
9547 //
9548 SimpleIdentifier prefix1 = import1.prefix;
9549 SimpleIdentifier prefix2 = import2.prefix;
9550 String prefixStr1 = prefix1 != null ? prefix1.name : null;
9551 String prefixStr2 = prefix2 != null ? prefix2.name : null;
9552 if (prefixStr1 != null || prefixStr2 != null) {
9553 if (prefixStr1 == null) {
9554 return -1;
9555 } else if (prefixStr2 == null) {
9556 return 1;
9557 } else {
9558 int compare = prefixStr1.compareTo(prefixStr2);
9559 if (compare != 0) {
9560 return compare;
9561 }
9562 }
9563 }
9564 //
9565 // hides and shows
9566 //
9567 NodeList<Combinator> combinators1 = import1.combinators;
9568 List<String> allHides1 = new List<String>();
9569 List<String> allShows1 = new List<String>();
9570 for (Combinator combinator in combinators1) {
9571 if (combinator is HideCombinator) {
9572 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9573 for (SimpleIdentifier simpleIdentifier in hides) {
9574 allHides1.add(simpleIdentifier.name);
9575 }
9576 } else {
9577 NodeList<SimpleIdentifier> shows =
9578 (combinator as ShowCombinator).shownNames;
9579 for (SimpleIdentifier simpleIdentifier in shows) {
9580 allShows1.add(simpleIdentifier.name);
9581 }
9582 }
9583 }
9584 NodeList<Combinator> combinators2 = import2.combinators;
9585 List<String> allHides2 = new List<String>();
9586 List<String> allShows2 = new List<String>();
9587 for (Combinator combinator in combinators2) {
9588 if (combinator is HideCombinator) {
9589 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9590 for (SimpleIdentifier simpleIdentifier in hides) {
9591 allHides2.add(simpleIdentifier.name);
9592 }
9593 } else {
9594 NodeList<SimpleIdentifier> shows =
9595 (combinator as ShowCombinator).shownNames;
9596 for (SimpleIdentifier simpleIdentifier in shows) {
9597 allShows2.add(simpleIdentifier.name);
9598 }
9599 }
9600 }
9601 // test lengths of combinator lists first
9602 if (allHides1.length != allHides2.length) {
9603 return allHides1.length - allHides2.length;
9604 }
9605 if (allShows1.length != allShows2.length) {
9606 return allShows1.length - allShows2.length;
9607 }
9608 // next ensure that the lists are equivalent
9609 if (!javaCollectionContainsAll(allHides1, allHides2)) {
9610 return -1;
9611 }
9612 if (!javaCollectionContainsAll(allShows1, allShows2)) {
9613 return -1;
9614 }
9615 return 0;
9616 };
9617
9618 /**
9619 * The token representing the 'deferred' keyword, or `null` if the imported is
9620 * not deferred.
9621 */
9622 Token deferredKeyword;
9623
9624 /**
9625 * The token representing the 'as' keyword, or `null` if the imported names ar e
9626 * not prefixed.
9627 */
9628 Token asKeyword;
9629
9630 /**
9631 * The prefix to be used with the imported names, or `null` if the imported
9632 * names are not prefixed.
9633 */
9634 SimpleIdentifier _prefix;
9635
9636 /**
9637 * Initialize a newly created import directive. Either or both of the
9638 * [comment] and [metadata] can be `null` if the function does not have the
9639 * corresponding attribute. The [deferredKeyword] can be `null` if the import
9640 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import
9641 * does not specify a prefix. The list of [combinators] can be `null` if there
9642 * are no combinators.
9643 */
9644 ImportDirective(
9645 Comment comment,
9646 List<Annotation> metadata,
9647 Token keyword,
9648 StringLiteral libraryUri,
9649 this.deferredKeyword,
9650 this.asKeyword,
9651 SimpleIdentifier prefix,
9652 List<Combinator> combinators,
9653 Token semicolon)
9654 : super(comment, metadata, keyword, libraryUri, combinators, semicolon) {
9655 _prefix = _becomeParentOf(prefix);
9656 }
9657
9658 /**
9659 * The token representing the 'as' token, or `null` if the imported names are
9660 * not prefixed.
9661 */
9662 @deprecated // Use "this.asKeyword"
9663 Token get asToken => asKeyword;
9664
9665 /**
9666 * The token representing the 'as' token to the given token.
9667 */
9668 @deprecated // Use "this.asKeyword"
9669 set asToken(Token token) {
9670 asKeyword = token;
9671 }
9672
9673 @override
9674 Iterable get childEntities => super._childEntities
9675 ..add(_uri)
9676 ..add(deferredKeyword)
9677 ..add(asKeyword)
9678 ..add(_prefix)
9679 ..addAll(combinators)
9680 ..add(semicolon);
9681
9682 /**
9683 * Return the token representing the 'deferred' token, or `null` if the
9684 * imported is not deferred.
9685 */
9686 @deprecated // Use "this.deferredKeyword"
9687 Token get deferredToken => deferredKeyword;
9688
9689 /**
9690 * Set the token representing the 'deferred' token to the given token.
9691 */
9692 @deprecated // Use "this.deferredKeyword"
9693 set deferredToken(Token token) {
9694 deferredKeyword = token;
9695 }
9696
9697 @override
9698 ImportElement get element => super.element as ImportElement;
9699
9700 /**
9701 * Return the prefix to be used with the imported names, or `null` if the
9702 * imported names are not prefixed.
9703 */
9704 SimpleIdentifier get prefix => _prefix;
9705
9706 /**
9707 * Set the prefix to be used with the imported names to the given [identifier] .
9708 */
9709 void set prefix(SimpleIdentifier identifier) {
9710 _prefix = _becomeParentOf(identifier);
9711 }
9712
9713 @override
9714 LibraryElement get uriElement {
9715 ImportElement element = this.element;
9716 if (element == null) {
9717 return null;
9718 }
9719 return element.importedLibrary;
9720 }
9721
9722 @override
9723 accept(AstVisitor visitor) => visitor.visitImportDirective(this);
9724
9725 @override
9726 void visitChildren(AstVisitor visitor) {
9727 super.visitChildren(visitor);
9728 _safelyVisitChild(_prefix, visitor);
9729 combinators.accept(visitor);
9730 }
9731 }
9732
9733 /**
9734 * An object that will clone any AST structure that it visits. The cloner will
9735 * clone the structure, replacing the specified ASTNode with a new ASTNode,
9736 * mapping the old token stream to a new token stream, and preserving resolution
9737 * results.
9738 */
9739 class IncrementalAstCloner implements AstVisitor<AstNode> {
9740 /**
9741 * The node to be replaced during the cloning process.
9742 */
9743 final AstNode _oldNode;
9744
9745 /**
9746 * The replacement node used during the cloning process.
9747 */
9748 final AstNode _newNode;
9749
9750 /**
9751 * A mapping of old tokens to new tokens used during the cloning process.
9752 */
9753 final TokenMap _tokenMap;
9754
9755 /**
9756 * Construct a new instance that will replace the [oldNode] with the [newNode]
9757 * in the process of cloning an existing AST structure. The [tokenMap] is a
9758 * mapping of old tokens to new tokens.
9759 */
9760 IncrementalAstCloner(this._oldNode, this._newNode, this._tokenMap);
9761
9762 @override
9763 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
9764 new AdjacentStrings(_cloneNodeList(node.strings));
9765
9766 @override
9767 Annotation visitAnnotation(Annotation node) {
9768 Annotation copy = new Annotation(
9769 _mapToken(node.atSign),
9770 _cloneNode(node.name),
9771 _mapToken(node.period),
9772 _cloneNode(node.constructorName),
9773 _cloneNode(node.arguments));
9774 copy.element = node.element;
9775 return copy;
9776 }
9777
9778 @override
9779 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
9780 _mapToken(node.leftParenthesis),
9781 _cloneNodeList(node.arguments),
9782 _mapToken(node.rightParenthesis));
9783
9784 @override
9785 AsExpression visitAsExpression(AsExpression node) {
9786 AsExpression copy = new AsExpression(_cloneNode(node.expression),
9787 _mapToken(node.asOperator), _cloneNode(node.type));
9788 copy.propagatedType = node.propagatedType;
9789 copy.staticType = node.staticType;
9790 return copy;
9791 }
9792
9793 @override
9794 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
9795 _mapToken(node.assertKeyword),
9796 _mapToken(node.leftParenthesis),
9797 _cloneNode(node.condition),
9798 _mapToken(node.rightParenthesis),
9799 _mapToken(node.semicolon));
9800
9801 @override
9802 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) {
9803 AssignmentExpression copy = new AssignmentExpression(
9804 _cloneNode(node.leftHandSide),
9805 _mapToken(node.operator),
9806 _cloneNode(node.rightHandSide));
9807 copy.propagatedElement = node.propagatedElement;
9808 copy.propagatedType = node.propagatedType;
9809 copy.staticElement = node.staticElement;
9810 copy.staticType = node.staticType;
9811 return copy;
9812 }
9813
9814 @override
9815 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
9816 new AwaitExpression(
9817 _mapToken(node.awaitKeyword), _cloneNode(node.expression));
9818
9819 @override
9820 BinaryExpression visitBinaryExpression(BinaryExpression node) {
9821 BinaryExpression copy = new BinaryExpression(_cloneNode(node.leftOperand),
9822 _mapToken(node.operator), _cloneNode(node.rightOperand));
9823 copy.propagatedElement = node.propagatedElement;
9824 copy.propagatedType = node.propagatedType;
9825 copy.staticElement = node.staticElement;
9826 copy.staticType = node.staticType;
9827 return copy;
9828 }
9829
9830 @override
9831 Block visitBlock(Block node) => new Block(_mapToken(node.leftBracket),
9832 _cloneNodeList(node.statements), _mapToken(node.rightBracket));
9833
9834 @override
9835 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) =>
9836 new BlockFunctionBody(_mapToken(node.keyword), _mapToken(node.star),
9837 _cloneNode(node.block));
9838
9839 @override
9840 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) {
9841 BooleanLiteral copy =
9842 new BooleanLiteral(_mapToken(node.literal), node.value);
9843 copy.propagatedType = node.propagatedType;
9844 copy.staticType = node.staticType;
9845 return copy;
9846 }
9847
9848 @override
9849 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
9850 _mapToken(node.breakKeyword),
9851 _cloneNode(node.label),
9852 _mapToken(node.semicolon));
9853
9854 @override
9855 CascadeExpression visitCascadeExpression(CascadeExpression node) {
9856 CascadeExpression copy = new CascadeExpression(
9857 _cloneNode(node.target), _cloneNodeList(node.cascadeSections));
9858 copy.propagatedType = node.propagatedType;
9859 copy.staticType = node.staticType;
9860 return copy;
9861 }
9862
9863 @override
9864 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
9865 _mapToken(node.onKeyword),
9866 _cloneNode(node.exceptionType),
9867 _mapToken(node.catchKeyword),
9868 _mapToken(node.leftParenthesis),
9869 _cloneNode(node.exceptionParameter),
9870 _mapToken(node.comma),
9871 _cloneNode(node.stackTraceParameter),
9872 _mapToken(node.rightParenthesis),
9873 _cloneNode(node.body));
9874
9875 @override
9876 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
9877 ClassDeclaration copy = new ClassDeclaration(
9878 _cloneNode(node.documentationComment),
9879 _cloneNodeList(node.metadata),
9880 _mapToken(node.abstractKeyword),
9881 _mapToken(node.classKeyword),
9882 _cloneNode(node.name),
9883 _cloneNode(node.typeParameters),
9884 _cloneNode(node.extendsClause),
9885 _cloneNode(node.withClause),
9886 _cloneNode(node.implementsClause),
9887 _mapToken(node.leftBracket),
9888 _cloneNodeList(node.members),
9889 _mapToken(node.rightBracket));
9890 copy.nativeClause = _cloneNode(node.nativeClause);
9891 return copy;
9892 }
9893
9894 @override
9895 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
9896 _cloneNode(node.documentationComment),
9897 _cloneNodeList(node.metadata),
9898 _mapToken(node.typedefKeyword),
9899 _cloneNode(node.name),
9900 _cloneNode(node.typeParameters),
9901 _mapToken(node.equals),
9902 _mapToken(node.abstractKeyword),
9903 _cloneNode(node.superclass),
9904 _cloneNode(node.withClause),
9905 _cloneNode(node.implementsClause),
9906 _mapToken(node.semicolon));
9907
9908 @override
9909 Comment visitComment(Comment node) {
9910 if (node.isDocumentation) {
9911 return Comment.createDocumentationCommentWithReferences(
9912 _mapTokens(node.tokens), _cloneNodeList(node.references));
9913 } else if (node.isBlock) {
9914 return Comment.createBlockComment(_mapTokens(node.tokens));
9915 }
9916 return Comment.createEndOfLineComment(_mapTokens(node.tokens));
9917 }
9918
9919 @override
9920 CommentReference visitCommentReference(CommentReference node) =>
9921 new CommentReference(
9922 _mapToken(node.newKeyword), _cloneNode(node.identifier));
9923
9924 @override
9925 CompilationUnit visitCompilationUnit(CompilationUnit node) {
9926 CompilationUnit copy = new CompilationUnit(
9927 _mapToken(node.beginToken),
9928 _cloneNode(node.scriptTag),
9929 _cloneNodeList(node.directives),
9930 _cloneNodeList(node.declarations),
9931 _mapToken(node.endToken));
9932 copy.lineInfo = node.lineInfo;
9933 copy.element = node.element;
9934 return copy;
9935 }
9936
9937 @override
9938 ConditionalExpression visitConditionalExpression(ConditionalExpression node) {
9939 ConditionalExpression copy = new ConditionalExpression(
9940 _cloneNode(node.condition),
9941 _mapToken(node.question),
9942 _cloneNode(node.thenExpression),
9943 _mapToken(node.colon),
9944 _cloneNode(node.elseExpression));
9945 copy.propagatedType = node.propagatedType;
9946 copy.staticType = node.staticType;
9947 return copy;
9948 }
9949
9950 @override
9951 ConstructorDeclaration visitConstructorDeclaration(
9952 ConstructorDeclaration node) {
9953 ConstructorDeclaration copy = new ConstructorDeclaration(
9954 _cloneNode(node.documentationComment),
9955 _cloneNodeList(node.metadata),
9956 _mapToken(node.externalKeyword),
9957 _mapToken(node.constKeyword),
9958 _mapToken(node.factoryKeyword),
9959 _cloneNode(node.returnType),
9960 _mapToken(node.period),
9961 _cloneNode(node.name),
9962 _cloneNode(node.parameters),
9963 _mapToken(node.separator),
9964 _cloneNodeList(node.initializers),
9965 _cloneNode(node.redirectedConstructor),
9966 _cloneNode(node.body));
9967 copy.element = node.element;
9968 return copy;
9969 }
9970
9971 @override
9972 ConstructorFieldInitializer visitConstructorFieldInitializer(
9973 ConstructorFieldInitializer node) =>
9974 new ConstructorFieldInitializer(
9975 _mapToken(node.thisKeyword),
9976 _mapToken(node.period),
9977 _cloneNode(node.fieldName),
9978 _mapToken(node.equals),
9979 _cloneNode(node.expression));
9980
9981 @override
9982 ConstructorName visitConstructorName(ConstructorName node) {
9983 ConstructorName copy = new ConstructorName(
9984 _cloneNode(node.type), _mapToken(node.period), _cloneNode(node.name));
9985 copy.staticElement = node.staticElement;
9986 return copy;
9987 }
9988
9989 @override
9990 ContinueStatement visitContinueStatement(ContinueStatement node) =>
9991 new ContinueStatement(_mapToken(node.continueKeyword),
9992 _cloneNode(node.label), _mapToken(node.semicolon));
9993
9994 @override
9995 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
9996 new DeclaredIdentifier(
9997 _cloneNode(node.documentationComment),
9998 _cloneNodeList(node.metadata),
9999 _mapToken(node.keyword),
10000 _cloneNode(node.type),
10001 _cloneNode(node.identifier));
10002
10003 @override
10004 DefaultFormalParameter visitDefaultFormalParameter(
10005 DefaultFormalParameter node) =>
10006 new DefaultFormalParameter(_cloneNode(node.parameter), node.kind,
10007 _mapToken(node.separator), _cloneNode(node.defaultValue));
10008
10009 @override
10010 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
10011 _mapToken(node.doKeyword),
10012 _cloneNode(node.body),
10013 _mapToken(node.whileKeyword),
10014 _mapToken(node.leftParenthesis),
10015 _cloneNode(node.condition),
10016 _mapToken(node.rightParenthesis),
10017 _mapToken(node.semicolon));
10018
10019 @override
10020 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) {
10021 DoubleLiteral copy = new DoubleLiteral(_mapToken(node.literal), node.value);
10022 copy.propagatedType = node.propagatedType;
10023 copy.staticType = node.staticType;
10024 return copy;
10025 }
10026
10027 @override
10028 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
10029 new EmptyFunctionBody(_mapToken(node.semicolon));
10030
10031 @override
10032 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
10033 new EmptyStatement(_mapToken(node.semicolon));
10034
10035 @override
10036 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
10037 new EnumConstantDeclaration(_cloneNode(node.documentationComment),
10038 _cloneNodeList(node.metadata), _cloneNode(node.name));
10039
10040 @override
10041 AstNode visitEnumDeclaration(EnumDeclaration node) => new EnumDeclaration(
10042 _cloneNode(node.documentationComment),
10043 _cloneNodeList(node.metadata),
10044 _mapToken(node.enumKeyword),
10045 _cloneNode(node.name),
10046 _mapToken(node.leftBracket),
10047 _cloneNodeList(node.constants),
10048 _mapToken(node.rightBracket));
10049
10050 @override
10051 ExportDirective visitExportDirective(ExportDirective node) {
10052 ExportDirective copy = new ExportDirective(
10053 _cloneNode(node.documentationComment),
10054 _cloneNodeList(node.metadata),
10055 _mapToken(node.keyword),
10056 _cloneNode(node.uri),
10057 _cloneNodeList(node.combinators),
10058 _mapToken(node.semicolon));
10059 copy.element = node.element;
10060 return copy;
10061 }
10062
10063 @override
10064 ExpressionFunctionBody visitExpressionFunctionBody(
10065 ExpressionFunctionBody node) =>
10066 new ExpressionFunctionBody(
10067 _mapToken(node.keyword),
10068 _mapToken(node.functionDefinition),
10069 _cloneNode(node.expression),
10070 _mapToken(node.semicolon));
10071
10072 @override
10073 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
10074 new ExpressionStatement(
10075 _cloneNode(node.expression), _mapToken(node.semicolon));
10076
10077 @override
10078 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
10079 _mapToken(node.extendsKeyword), _cloneNode(node.superclass));
10080
10081 @override
10082 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
10083 new FieldDeclaration(
10084 _cloneNode(node.documentationComment),
10085 _cloneNodeList(node.metadata),
10086 _mapToken(node.staticKeyword),
10087 _cloneNode(node.fields),
10088 _mapToken(node.semicolon));
10089
10090 @override
10091 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
10092 new FieldFormalParameter(
10093 _cloneNode(node.documentationComment),
10094 _cloneNodeList(node.metadata),
10095 _mapToken(node.keyword),
10096 _cloneNode(node.type),
10097 _mapToken(node.thisKeyword),
10098 _mapToken(node.period),
10099 _cloneNode(node.identifier),
10100 _cloneNode(node.typeParameters),
10101 _cloneNode(node.parameters));
10102
10103 @override
10104 ForEachStatement visitForEachStatement(ForEachStatement node) {
10105 DeclaredIdentifier loopVariable = node.loopVariable;
10106 if (loopVariable == null) {
10107 return new ForEachStatement.withReference(
10108 _mapToken(node.awaitKeyword),
10109 _mapToken(node.forKeyword),
10110 _mapToken(node.leftParenthesis),
10111 _cloneNode(node.identifier),
10112 _mapToken(node.inKeyword),
10113 _cloneNode(node.iterable),
10114 _mapToken(node.rightParenthesis),
10115 _cloneNode(node.body));
10116 }
10117 return new ForEachStatement.withDeclaration(
10118 _mapToken(node.awaitKeyword),
10119 _mapToken(node.forKeyword),
10120 _mapToken(node.leftParenthesis),
10121 _cloneNode(loopVariable),
10122 _mapToken(node.inKeyword),
10123 _cloneNode(node.iterable),
10124 _mapToken(node.rightParenthesis),
10125 _cloneNode(node.body));
10126 }
10127
10128 @override
10129 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
10130 new FormalParameterList(
10131 _mapToken(node.leftParenthesis),
10132 _cloneNodeList(node.parameters),
10133 _mapToken(node.leftDelimiter),
10134 _mapToken(node.rightDelimiter),
10135 _mapToken(node.rightParenthesis));
10136
10137 @override
10138 ForStatement visitForStatement(ForStatement node) => new ForStatement(
10139 _mapToken(node.forKeyword),
10140 _mapToken(node.leftParenthesis),
10141 _cloneNode(node.variables),
10142 _cloneNode(node.initialization),
10143 _mapToken(node.leftSeparator),
10144 _cloneNode(node.condition),
10145 _mapToken(node.rightSeparator),
10146 _cloneNodeList(node.updaters),
10147 _mapToken(node.rightParenthesis),
10148 _cloneNode(node.body));
10149
10150 @override
10151 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
10152 new FunctionDeclaration(
10153 _cloneNode(node.documentationComment),
10154 _cloneNodeList(node.metadata),
10155 _mapToken(node.externalKeyword),
10156 _cloneNode(node.returnType),
10157 _mapToken(node.propertyKeyword),
10158 _cloneNode(node.name),
10159 _cloneNode(node.functionExpression));
10160
10161 @override
10162 FunctionDeclarationStatement visitFunctionDeclarationStatement(
10163 FunctionDeclarationStatement node) =>
10164 new FunctionDeclarationStatement(_cloneNode(node.functionDeclaration));
10165
10166 @override
10167 FunctionExpression visitFunctionExpression(FunctionExpression node) {
10168 FunctionExpression copy = new FunctionExpression(
10169 _cloneNode(node.typeParameters),
10170 _cloneNode(node.parameters),
10171 _cloneNode(node.body));
10172 copy.element = node.element;
10173 copy.propagatedType = node.propagatedType;
10174 copy.staticType = node.staticType;
10175 return copy;
10176 }
10177
10178 @override
10179 FunctionExpressionInvocation visitFunctionExpressionInvocation(
10180 FunctionExpressionInvocation node) {
10181 FunctionExpressionInvocation copy = new FunctionExpressionInvocation(
10182 _cloneNode(node.function),
10183 _cloneNode(node.typeArguments),
10184 _cloneNode(node.argumentList));
10185 copy.propagatedElement = node.propagatedElement;
10186 copy.propagatedType = node.propagatedType;
10187 copy.staticElement = node.staticElement;
10188 copy.staticType = node.staticType;
10189 return copy;
10190 }
10191
10192 @override
10193 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
10194 new FunctionTypeAlias(
10195 _cloneNode(node.documentationComment),
10196 _cloneNodeList(node.metadata),
10197 _mapToken(node.typedefKeyword),
10198 _cloneNode(node.returnType),
10199 _cloneNode(node.name),
10200 _cloneNode(node.typeParameters),
10201 _cloneNode(node.parameters),
10202 _mapToken(node.semicolon));
10203
10204 @override
10205 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
10206 FunctionTypedFormalParameter node) =>
10207 new FunctionTypedFormalParameter(
10208 _cloneNode(node.documentationComment),
10209 _cloneNodeList(node.metadata),
10210 _cloneNode(node.returnType),
10211 _cloneNode(node.identifier),
10212 _cloneNode(node.typeParameters),
10213 _cloneNode(node.parameters));
10214
10215 @override
10216 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
10217 _mapToken(node.keyword), _cloneNodeList(node.hiddenNames));
10218
10219 @override
10220 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
10221 _mapToken(node.ifKeyword),
10222 _mapToken(node.leftParenthesis),
10223 _cloneNode(node.condition),
10224 _mapToken(node.rightParenthesis),
10225 _cloneNode(node.thenStatement),
10226 _mapToken(node.elseKeyword),
10227 _cloneNode(node.elseStatement));
10228
10229 @override
10230 ImplementsClause visitImplementsClause(ImplementsClause node) =>
10231 new ImplementsClause(
10232 _mapToken(node.implementsKeyword), _cloneNodeList(node.interfaces));
10233
10234 @override
10235 ImportDirective visitImportDirective(ImportDirective node) =>
10236 new ImportDirective(
10237 _cloneNode(node.documentationComment),
10238 _cloneNodeList(node.metadata),
10239 _mapToken(node.keyword),
10240 _cloneNode(node.uri),
10241 _mapToken(node.deferredKeyword),
10242 _mapToken(node.asKeyword),
10243 _cloneNode(node.prefix),
10244 _cloneNodeList(node.combinators),
10245 _mapToken(node.semicolon));
10246
10247 @override
10248 IndexExpression visitIndexExpression(IndexExpression node) {
10249 Token period = _mapToken(node.period);
10250 IndexExpression copy;
10251 if (period == null) {
10252 copy = new IndexExpression.forTarget(
10253 _cloneNode(node.target),
10254 _mapToken(node.leftBracket),
10255 _cloneNode(node.index),
10256 _mapToken(node.rightBracket));
10257 } else {
10258 copy = new IndexExpression.forCascade(period, _mapToken(node.leftBracket),
10259 _cloneNode(node.index), _mapToken(node.rightBracket));
10260 }
10261 copy.auxiliaryElements = node.auxiliaryElements;
10262 copy.propagatedElement = node.propagatedElement;
10263 copy.propagatedType = node.propagatedType;
10264 copy.staticElement = node.staticElement;
10265 copy.staticType = node.staticType;
10266 return copy;
10267 }
10268
10269 @override
10270 InstanceCreationExpression visitInstanceCreationExpression(
10271 InstanceCreationExpression node) {
10272 InstanceCreationExpression copy = new InstanceCreationExpression(
10273 _mapToken(node.keyword),
10274 _cloneNode(node.constructorName),
10275 _cloneNode(node.argumentList));
10276 copy.propagatedType = node.propagatedType;
10277 copy.staticElement = node.staticElement;
10278 copy.staticType = node.staticType;
10279 return copy;
10280 }
10281
10282 @override
10283 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) {
10284 IntegerLiteral copy =
10285 new IntegerLiteral(_mapToken(node.literal), node.value);
10286 copy.propagatedType = node.propagatedType;
10287 copy.staticType = node.staticType;
10288 return copy;
10289 }
10290
10291 @override
10292 InterpolationExpression visitInterpolationExpression(
10293 InterpolationExpression node) =>
10294 new InterpolationExpression(_mapToken(node.leftBracket),
10295 _cloneNode(node.expression), _mapToken(node.rightBracket));
10296
10297 @override
10298 InterpolationString visitInterpolationString(InterpolationString node) =>
10299 new InterpolationString(_mapToken(node.contents), node.value);
10300
10301 @override
10302 IsExpression visitIsExpression(IsExpression node) {
10303 IsExpression copy = new IsExpression(
10304 _cloneNode(node.expression),
10305 _mapToken(node.isOperator),
10306 _mapToken(node.notOperator),
10307 _cloneNode(node.type));
10308 copy.propagatedType = node.propagatedType;
10309 copy.staticType = node.staticType;
10310 return copy;
10311 }
10312
10313 @override
10314 Label visitLabel(Label node) =>
10315 new Label(_cloneNode(node.label), _mapToken(node.colon));
10316
10317 @override
10318 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
10319 new LabeledStatement(
10320 _cloneNodeList(node.labels), _cloneNode(node.statement));
10321
10322 @override
10323 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
10324 new LibraryDirective(
10325 _cloneNode(node.documentationComment),
10326 _cloneNodeList(node.metadata),
10327 _mapToken(node.libraryKeyword),
10328 _cloneNode(node.name),
10329 _mapToken(node.semicolon));
10330
10331 @override
10332 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) {
10333 LibraryIdentifier copy =
10334 new LibraryIdentifier(_cloneNodeList(node.components));
10335 copy.propagatedType = node.propagatedType;
10336 copy.staticType = node.staticType;
10337 return copy;
10338 }
10339
10340 @override
10341 ListLiteral visitListLiteral(ListLiteral node) {
10342 ListLiteral copy = new ListLiteral(
10343 _mapToken(node.constKeyword),
10344 _cloneNode(node.typeArguments),
10345 _mapToken(node.leftBracket),
10346 _cloneNodeList(node.elements),
10347 _mapToken(node.rightBracket));
10348 copy.propagatedType = node.propagatedType;
10349 copy.staticType = node.staticType;
10350 return copy;
10351 }
10352
10353 @override
10354 MapLiteral visitMapLiteral(MapLiteral node) {
10355 MapLiteral copy = new MapLiteral(
10356 _mapToken(node.constKeyword),
10357 _cloneNode(node.typeArguments),
10358 _mapToken(node.leftBracket),
10359 _cloneNodeList(node.entries),
10360 _mapToken(node.rightBracket));
10361 copy.propagatedType = node.propagatedType;
10362 copy.staticType = node.staticType;
10363 return copy;
10364 }
10365
10366 @override
10367 MapLiteralEntry visitMapLiteralEntry(MapLiteralEntry node) =>
10368 new MapLiteralEntry(_cloneNode(node.key), _mapToken(node.separator),
10369 _cloneNode(node.value));
10370
10371 @override
10372 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
10373 new MethodDeclaration(
10374 _cloneNode(node.documentationComment),
10375 _cloneNodeList(node.metadata),
10376 _mapToken(node.externalKeyword),
10377 _mapToken(node.modifierKeyword),
10378 _cloneNode(node.returnType),
10379 _mapToken(node.propertyKeyword),
10380 _mapToken(node.operatorKeyword),
10381 _cloneNode(node.name),
10382 _cloneNode(node._typeParameters),
10383 _cloneNode(node.parameters),
10384 _cloneNode(node.body));
10385
10386 @override
10387 MethodInvocation visitMethodInvocation(MethodInvocation node) {
10388 MethodInvocation copy = new MethodInvocation(
10389 _cloneNode(node.target),
10390 _mapToken(node.operator),
10391 _cloneNode(node.methodName),
10392 _cloneNode(node.typeArguments),
10393 _cloneNode(node.argumentList));
10394 copy.propagatedType = node.propagatedType;
10395 copy.staticType = node.staticType;
10396 return copy;
10397 }
10398
10399 @override
10400 NamedExpression visitNamedExpression(NamedExpression node) {
10401 NamedExpression copy =
10402 new NamedExpression(_cloneNode(node.name), _cloneNode(node.expression));
10403 copy.propagatedType = node.propagatedType;
10404 copy.staticType = node.staticType;
10405 return copy;
10406 }
10407
10408 @override
10409 AstNode visitNativeClause(NativeClause node) =>
10410 new NativeClause(_mapToken(node.nativeKeyword), _cloneNode(node.name));
10411
10412 @override
10413 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
10414 new NativeFunctionBody(_mapToken(node.nativeKeyword),
10415 _cloneNode(node.stringLiteral), _mapToken(node.semicolon));
10416
10417 @override
10418 NullLiteral visitNullLiteral(NullLiteral node) {
10419 NullLiteral copy = new NullLiteral(_mapToken(node.literal));
10420 copy.propagatedType = node.propagatedType;
10421 copy.staticType = node.staticType;
10422 return copy;
10423 }
10424
10425 @override
10426 ParenthesizedExpression visitParenthesizedExpression(
10427 ParenthesizedExpression node) {
10428 ParenthesizedExpression copy = new ParenthesizedExpression(
10429 _mapToken(node.leftParenthesis),
10430 _cloneNode(node.expression),
10431 _mapToken(node.rightParenthesis));
10432 copy.propagatedType = node.propagatedType;
10433 copy.staticType = node.staticType;
10434 return copy;
10435 }
10436
10437 @override
10438 PartDirective visitPartDirective(PartDirective node) {
10439 PartDirective copy = new PartDirective(
10440 _cloneNode(node.documentationComment),
10441 _cloneNodeList(node.metadata),
10442 _mapToken(node.partKeyword),
10443 _cloneNode(node.uri),
10444 _mapToken(node.semicolon));
10445 copy.element = node.element;
10446 return copy;
10447 }
10448
10449 @override
10450 PartOfDirective visitPartOfDirective(PartOfDirective node) {
10451 PartOfDirective copy = new PartOfDirective(
10452 _cloneNode(node.documentationComment),
10453 _cloneNodeList(node.metadata),
10454 _mapToken(node.partKeyword),
10455 _mapToken(node.ofKeyword),
10456 _cloneNode(node.libraryName),
10457 _mapToken(node.semicolon));
10458 copy.element = node.element;
10459 return copy;
10460 }
10461
10462 @override
10463 PostfixExpression visitPostfixExpression(PostfixExpression node) {
10464 PostfixExpression copy = new PostfixExpression(
10465 _cloneNode(node.operand), _mapToken(node.operator));
10466 copy.propagatedElement = node.propagatedElement;
10467 copy.propagatedType = node.propagatedType;
10468 copy.staticElement = node.staticElement;
10469 copy.staticType = node.staticType;
10470 return copy;
10471 }
10472
10473 @override
10474 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) {
10475 PrefixedIdentifier copy = new PrefixedIdentifier(_cloneNode(node.prefix),
10476 _mapToken(node.period), _cloneNode(node.identifier));
10477 copy.propagatedType = node.propagatedType;
10478 copy.staticType = node.staticType;
10479 return copy;
10480 }
10481
10482 @override
10483 PrefixExpression visitPrefixExpression(PrefixExpression node) {
10484 PrefixExpression copy = new PrefixExpression(
10485 _mapToken(node.operator), _cloneNode(node.operand));
10486 copy.propagatedElement = node.propagatedElement;
10487 copy.propagatedType = node.propagatedType;
10488 copy.staticElement = node.staticElement;
10489 copy.staticType = node.staticType;
10490 return copy;
10491 }
10492
10493 @override
10494 PropertyAccess visitPropertyAccess(PropertyAccess node) {
10495 PropertyAccess copy = new PropertyAccess(_cloneNode(node.target),
10496 _mapToken(node.operator), _cloneNode(node.propertyName));
10497 copy.propagatedType = node.propagatedType;
10498 copy.staticType = node.staticType;
10499 return copy;
10500 }
10501
10502 @override
10503 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
10504 RedirectingConstructorInvocation node) {
10505 RedirectingConstructorInvocation copy =
10506 new RedirectingConstructorInvocation(
10507 _mapToken(node.thisKeyword),
10508 _mapToken(node.period),
10509 _cloneNode(node.constructorName),
10510 _cloneNode(node.argumentList));
10511 copy.staticElement = node.staticElement;
10512 return copy;
10513 }
10514
10515 @override
10516 RethrowExpression visitRethrowExpression(RethrowExpression node) {
10517 RethrowExpression copy =
10518 new RethrowExpression(_mapToken(node.rethrowKeyword));
10519 copy.propagatedType = node.propagatedType;
10520 copy.staticType = node.staticType;
10521 return copy;
10522 }
10523
10524 @override
10525 ReturnStatement visitReturnStatement(ReturnStatement node) =>
10526 new ReturnStatement(_mapToken(node.returnKeyword),
10527 _cloneNode(node.expression), _mapToken(node.semicolon));
10528
10529 @override
10530 ScriptTag visitScriptTag(ScriptTag node) =>
10531 new ScriptTag(_mapToken(node.scriptTag));
10532
10533 @override
10534 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
10535 _mapToken(node.keyword), _cloneNodeList(node.shownNames));
10536
10537 @override
10538 SimpleFormalParameter visitSimpleFormalParameter(
10539 SimpleFormalParameter node) =>
10540 new SimpleFormalParameter(
10541 _cloneNode(node.documentationComment),
10542 _cloneNodeList(node.metadata),
10543 _mapToken(node.keyword),
10544 _cloneNode(node.type),
10545 _cloneNode(node.identifier));
10546
10547 @override
10548 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
10549 Token mappedToken = _mapToken(node.token);
10550 if (mappedToken == null) {
10551 // This only happens for SimpleIdentifiers created by the parser as part
10552 // of scanning documentation comments (the tokens for those identifiers
10553 // are not in the original token stream and hence do not get copied).
10554 // This extra check can be removed if the scanner is changed to scan
10555 // documentation comments for the parser.
10556 mappedToken = node.token;
10557 }
10558 SimpleIdentifier copy = new SimpleIdentifier(mappedToken);
10559 copy.auxiliaryElements = node.auxiliaryElements;
10560 copy.propagatedElement = node.propagatedElement;
10561 copy.propagatedType = node.propagatedType;
10562 copy.staticElement = node.staticElement;
10563 copy.staticType = node.staticType;
10564 return copy;
10565 }
10566
10567 @override
10568 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) {
10569 SimpleStringLiteral copy =
10570 new SimpleStringLiteral(_mapToken(node.literal), node.value);
10571 copy.propagatedType = node.propagatedType;
10572 copy.staticType = node.staticType;
10573 return copy;
10574 }
10575
10576 @override
10577 StringInterpolation visitStringInterpolation(StringInterpolation node) {
10578 StringInterpolation copy =
10579 new StringInterpolation(_cloneNodeList(node.elements));
10580 copy.propagatedType = node.propagatedType;
10581 copy.staticType = node.staticType;
10582 return copy;
10583 }
10584
10585 @override
10586 SuperConstructorInvocation visitSuperConstructorInvocation(
10587 SuperConstructorInvocation node) {
10588 SuperConstructorInvocation copy = new SuperConstructorInvocation(
10589 _mapToken(node.superKeyword),
10590 _mapToken(node.period),
10591 _cloneNode(node.constructorName),
10592 _cloneNode(node.argumentList));
10593 copy.staticElement = node.staticElement;
10594 return copy;
10595 }
10596
10597 @override
10598 SuperExpression visitSuperExpression(SuperExpression node) {
10599 SuperExpression copy = new SuperExpression(_mapToken(node.superKeyword));
10600 copy.propagatedType = node.propagatedType;
10601 copy.staticType = node.staticType;
10602 return copy;
10603 }
10604
10605 @override
10606 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
10607 _cloneNodeList(node.labels),
10608 _mapToken(node.keyword),
10609 _cloneNode(node.expression),
10610 _mapToken(node.colon),
10611 _cloneNodeList(node.statements));
10612
10613 @override
10614 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
10615 _cloneNodeList(node.labels),
10616 _mapToken(node.keyword),
10617 _mapToken(node.colon),
10618 _cloneNodeList(node.statements));
10619
10620 @override
10621 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
10622 new SwitchStatement(
10623 _mapToken(node.switchKeyword),
10624 _mapToken(node.leftParenthesis),
10625 _cloneNode(node.expression),
10626 _mapToken(node.rightParenthesis),
10627 _mapToken(node.leftBracket),
10628 _cloneNodeList(node.members),
10629 _mapToken(node.rightBracket));
10630
10631 @override
10632 AstNode visitSymbolLiteral(SymbolLiteral node) {
10633 SymbolLiteral copy = new SymbolLiteral(
10634 _mapToken(node.poundSign), _mapTokens(node.components));
10635 copy.propagatedType = node.propagatedType;
10636 copy.staticType = node.staticType;
10637 return copy;
10638 }
10639
10640 @override
10641 ThisExpression visitThisExpression(ThisExpression node) {
10642 ThisExpression copy = new ThisExpression(_mapToken(node.thisKeyword));
10643 copy.propagatedType = node.propagatedType;
10644 copy.staticType = node.staticType;
10645 return copy;
10646 }
10647
10648 @override
10649 ThrowExpression visitThrowExpression(ThrowExpression node) {
10650 ThrowExpression copy = new ThrowExpression(
10651 _mapToken(node.throwKeyword), _cloneNode(node.expression));
10652 copy.propagatedType = node.propagatedType;
10653 copy.staticType = node.staticType;
10654 return copy;
10655 }
10656
10657 @override
10658 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
10659 TopLevelVariableDeclaration node) =>
10660 new TopLevelVariableDeclaration(
10661 _cloneNode(node.documentationComment),
10662 _cloneNodeList(node.metadata),
10663 _cloneNode(node.variables),
10664 _mapToken(node.semicolon));
10665
10666 @override
10667 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
10668 _mapToken(node.tryKeyword),
10669 _cloneNode(node.body),
10670 _cloneNodeList(node.catchClauses),
10671 _mapToken(node.finallyKeyword),
10672 _cloneNode(node.finallyBlock));
10673
10674 @override
10675 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
10676 new TypeArgumentList(_mapToken(node.leftBracket),
10677 _cloneNodeList(node.arguments), _mapToken(node.rightBracket));
10678
10679 @override
10680 TypeName visitTypeName(TypeName node) {
10681 TypeName copy =
10682 new TypeName(_cloneNode(node.name), _cloneNode(node.typeArguments));
10683 copy.type = node.type;
10684 return copy;
10685 }
10686
10687 @override
10688 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
10689 _cloneNode(node.documentationComment),
10690 _cloneNodeList(node.metadata),
10691 _cloneNode(node.name),
10692 _mapToken(node.extendsKeyword),
10693 _cloneNode(node.bound));
10694
10695 @override
10696 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
10697 new TypeParameterList(_mapToken(node.leftBracket),
10698 _cloneNodeList(node.typeParameters), _mapToken(node.rightBracket));
10699
10700 @override
10701 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
10702 new VariableDeclaration(_cloneNode(node.name), _mapToken(node.equals),
10703 _cloneNode(node.initializer));
10704
10705 @override
10706 VariableDeclarationList visitVariableDeclarationList(
10707 VariableDeclarationList node) =>
10708 new VariableDeclarationList(
10709 null,
10710 _cloneNodeList(node.metadata),
10711 _mapToken(node.keyword),
10712 _cloneNode(node.type),
10713 _cloneNodeList(node.variables));
10714
10715 @override
10716 VariableDeclarationStatement visitVariableDeclarationStatement(
10717 VariableDeclarationStatement node) =>
10718 new VariableDeclarationStatement(
10719 _cloneNode(node.variables), _mapToken(node.semicolon));
10720
10721 @override
10722 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
10723 _mapToken(node.whileKeyword),
10724 _mapToken(node.leftParenthesis),
10725 _cloneNode(node.condition),
10726 _mapToken(node.rightParenthesis),
10727 _cloneNode(node.body));
10728
10729 @override
10730 WithClause visitWithClause(WithClause node) => new WithClause(
10731 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes));
10732
10733 @override
10734 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
10735 _mapToken(node.yieldKeyword),
10736 _mapToken(node.star),
10737 _cloneNode(node.expression),
10738 _mapToken(node.semicolon));
10739
10740 AstNode _cloneNode(AstNode node) {
10741 if (node == null) {
10742 return null;
10743 }
10744 if (identical(node, _oldNode)) {
10745 return _newNode;
10746 }
10747 return node.accept(this) as AstNode;
10748 }
10749
10750 List _cloneNodeList(NodeList nodes) {
10751 List clonedNodes = new List();
10752 for (AstNode node in nodes) {
10753 clonedNodes.add(_cloneNode(node));
10754 }
10755 return clonedNodes;
10756 }
10757
10758 Token _mapToken(Token oldToken) {
10759 if (oldToken == null) {
10760 return null;
10761 }
10762 return _tokenMap.get(oldToken);
10763 }
10764
10765 List<Token> _mapTokens(List<Token> oldTokens) {
10766 List<Token> newTokens = new List<Token>(oldTokens.length);
10767 for (int index = 0; index < newTokens.length; index++) {
10768 newTokens[index] = _mapToken(oldTokens[index]);
10769 }
10770 return newTokens;
10771 }
10772 }
10773
10774 /**
10775 * An index expression.
10776 *
10777 * > indexExpression ::=
10778 * > [Expression] '[' [Expression] ']'
10779 */
10780 class IndexExpression extends Expression {
10781 /**
10782 * The expression used to compute the object being indexed, or `null` if this
10783 * index expression is part of a cascade expression.
10784 */
10785 Expression _target;
10786
10787 /**
10788 * The period ("..") before a cascaded index expression, or `null` if this
10789 * index expression is not part of a cascade expression.
10790 */
10791 Token period;
10792
10793 /**
10794 * The left square bracket.
10795 */
10796 Token leftBracket;
10797
10798 /**
10799 * The expression used to compute the index.
10800 */
10801 Expression _index;
10802
10803 /**
10804 * The right square bracket.
10805 */
10806 Token rightBracket;
10807
10808 /**
10809 * The element associated with the operator based on the static type of the
10810 * target, or `null` if the AST structure has not been resolved or if the
10811 * operator could not be resolved.
10812 */
10813 MethodElement staticElement;
10814
10815 /**
10816 * The element associated with the operator based on the propagated type of
10817 * the target, or `null` if the AST structure has not been resolved or if the
10818 * operator could not be resolved.
10819 */
10820 MethodElement propagatedElement;
10821
10822 /**
10823 * If this expression is both in a getter and setter context, the
10824 * [AuxiliaryElements] will be set to hold onto the static and propagated
10825 * information. The auxiliary element will hold onto the elements from the
10826 * getter context.
10827 */
10828 AuxiliaryElements auxiliaryElements = null;
10829
10830 /**
10831 * Initialize a newly created index expression.
10832 */
10833 IndexExpression.forCascade(
10834 this.period, this.leftBracket, Expression index, this.rightBracket) {
10835 _index = _becomeParentOf(index);
10836 }
10837
10838 /**
10839 * Initialize a newly created index expression.
10840 */
10841 IndexExpression.forTarget(Expression target, this.leftBracket,
10842 Expression index, this.rightBracket) {
10843 _target = _becomeParentOf(target);
10844 _index = _becomeParentOf(index);
10845 }
10846
10847 @override
10848 Token get beginToken {
10849 if (_target != null) {
10850 return _target.beginToken;
10851 }
10852 return period;
10853 }
10854
10855 /**
10856 * Return the best element available for this operator. If resolution was able
10857 * to find a better element based on type propagation, that element will be
10858 * returned. Otherwise, the element found using the result of static analysis
10859 * will be returned. If resolution has not been performed, then `null` will be
10860 * returned.
10861 */
10862 MethodElement get bestElement {
10863 MethodElement element = propagatedElement;
10864 if (element == null) {
10865 element = staticElement;
10866 }
10867 return element;
10868 }
10869
10870 @override
10871 Iterable get childEntities => new ChildEntities()
10872 ..add(_target)
10873 ..add(period)
10874 ..add(leftBracket)
10875 ..add(_index)
10876 ..add(rightBracket);
10877
10878 @override
10879 Token get endToken => rightBracket;
10880
10881 /**
10882 * Return the expression used to compute the index.
10883 */
10884 Expression get index => _index;
10885
10886 /**
10887 * Set the expression used to compute the index to the given [expression].
10888 */
10889 void set index(Expression expression) {
10890 _index = _becomeParentOf(expression);
10891 }
10892
10893 @override
10894 bool get isAssignable => true;
10895
10896 /**
10897 * Return `true` if this expression is cascaded. If it is, then the target of
10898 * this expression is not stored locally but is stored in the nearest ancestor
10899 * that is a [CascadeExpression].
10900 */
10901 bool get isCascaded => period != null;
10902
10903 @override
10904 int get precedence => 15;
10905
10906 /**
10907 * If the AST structure has been resolved, and the function being invoked is
10908 * known based on propagated type information, then return the parameter
10909 * element representing the parameter to which the value of the index
10910 * expression will be bound. Otherwise, return `null`.
10911 */
10912 @deprecated // Use "expression.propagatedParameterElement"
10913 ParameterElement get propagatedParameterElementForIndex {
10914 return _propagatedParameterElementForIndex;
10915 }
10916
10917 /**
10918 * Return the expression used to compute the object being indexed. If this
10919 * index expression is not part of a cascade expression, then this is the same
10920 * as [target]. If this index expression is part of a cascade expression, then
10921 * the target expression stored with the cascade expression is returned.
10922 */
10923 Expression get realTarget {
10924 if (isCascaded) {
10925 AstNode ancestor = parent;
10926 while (ancestor is! CascadeExpression) {
10927 if (ancestor == null) {
10928 return _target;
10929 }
10930 ancestor = ancestor.parent;
10931 }
10932 return (ancestor as CascadeExpression).target;
10933 }
10934 return _target;
10935 }
10936
10937 /**
10938 * If the AST structure has been resolved, and the function being invoked is
10939 * known based on static type information, then return the parameter element
10940 * representing the parameter to which the value of the index expression will
10941 * be bound. Otherwise, return `null`.
10942 */
10943 @deprecated // Use "expression.propagatedParameterElement"
10944 ParameterElement get staticParameterElementForIndex {
10945 return _staticParameterElementForIndex;
10946 }
10947
10948 /**
10949 * Return the expression used to compute the object being indexed, or `null`
10950 * if this index expression is part of a cascade expression.
10951 *
10952 * Use [realTarget] to get the target independent of whether this is part of a
10953 * cascade expression.
10954 */
10955 Expression get target => _target;
10956
10957 /**
10958 * Set the expression used to compute the object being indexed to the given
10959 * [expression].
10960 */
10961 void set target(Expression expression) {
10962 _target = _becomeParentOf(expression);
10963 }
10964
10965 /**
10966 * If the AST structure has been resolved, and the function being invoked is
10967 * known based on propagated type information, then return the parameter
10968 * element representing the parameter to which the value of the index
10969 * expression will be bound. Otherwise, return `null`.
10970 */
10971 ParameterElement get _propagatedParameterElementForIndex {
10972 if (propagatedElement == null) {
10973 return null;
10974 }
10975 List<ParameterElement> parameters = propagatedElement.parameters;
10976 if (parameters.length < 1) {
10977 return null;
10978 }
10979 return parameters[0];
10980 }
10981
10982 /**
10983 * If the AST structure has been resolved, and the function being invoked is
10984 * known based on static type information, then return the parameter element
10985 * representing the parameter to which the value of the index expression will
10986 * be bound. Otherwise, return `null`.
10987 */
10988 ParameterElement get _staticParameterElementForIndex {
10989 if (staticElement == null) {
10990 return null;
10991 }
10992 List<ParameterElement> parameters = staticElement.parameters;
10993 if (parameters.length < 1) {
10994 return null;
10995 }
10996 return parameters[0];
10997 }
10998
10999 @override
11000 accept(AstVisitor visitor) => visitor.visitIndexExpression(this);
11001
11002 /**
11003 * Return `true` if this expression is computing a right-hand value (that is,
11004 * if this expression is in a context where the operator '[]' will be
11005 * invoked).
11006 *
11007 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
11008 * are they mutually exclusive. In other words, it is possible for both
11009 * methods to return `true` when invoked on the same node.
11010 */
11011 bool inGetterContext() {
11012 // TODO(brianwilkerson) Convert this to a getter.
11013 AstNode parent = this.parent;
11014 if (parent is AssignmentExpression) {
11015 AssignmentExpression assignment = parent;
11016 if (identical(assignment.leftHandSide, this) &&
11017 assignment.operator.type == TokenType.EQ) {
11018 return false;
11019 }
11020 }
11021 return true;
11022 }
11023
11024 /**
11025 * Return `true` if this expression is computing a left-hand value (that is,
11026 * if this expression is in a context where the operator '[]=' will be
11027 * invoked).
11028 *
11029 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
11030 * are they mutually exclusive. In other words, it is possible for both
11031 * methods to return `true` when invoked on the same node.
11032 */
11033 bool inSetterContext() {
11034 // TODO(brianwilkerson) Convert this to a getter.
11035 AstNode parent = this.parent;
11036 if (parent is PrefixExpression) {
11037 return parent.operator.type.isIncrementOperator;
11038 } else if (parent is PostfixExpression) {
11039 return true;
11040 } else if (parent is AssignmentExpression) {
11041 return identical(parent.leftHandSide, this);
11042 }
11043 return false;
11044 }
11045
11046 @override
11047 void visitChildren(AstVisitor visitor) {
11048 _safelyVisitChild(_target, visitor);
11049 _safelyVisitChild(_index, visitor);
11050 }
11051 }
11052
11053 /**
11054 * An instance creation expression.
11055 *
11056 * > newExpression ::=
11057 * > ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList]
11058 */
11059 class InstanceCreationExpression extends Expression {
11060 /**
11061 * The 'new' or 'const' keyword used to indicate how an object should be
11062 * created.
11063 */
11064 Token keyword;
11065
11066 /**
11067 * The name of the constructor to be invoked.
11068 */
11069 ConstructorName _constructorName;
11070
11071 /**
11072 * The list of arguments to the constructor.
11073 */
11074 ArgumentList _argumentList;
11075
11076 /**
11077 * The element associated with the constructor based on static type
11078 * information, or `null` if the AST structure has not been resolved or if the
11079 * constructor could not be resolved.
11080 */
11081 ConstructorElement staticElement;
11082
11083 /**
11084 * Initialize a newly created instance creation expression.
11085 */
11086 InstanceCreationExpression(this.keyword, ConstructorName constructorName,
11087 ArgumentList argumentList) {
11088 _constructorName = _becomeParentOf(constructorName);
11089 _argumentList = _becomeParentOf(argumentList);
11090 }
11091
11092 /**
11093 * Return the list of arguments to the constructor.
11094 */
11095 ArgumentList get argumentList => _argumentList;
11096
11097 /**
11098 * Set the list of arguments to the constructor to the given [argumentList].
11099 */
11100 void set argumentList(ArgumentList argumentList) {
11101 _argumentList = _becomeParentOf(argumentList);
11102 }
11103
11104 @override
11105 Token get beginToken => keyword;
11106
11107 @override
11108 Iterable get childEntities => new ChildEntities()
11109 ..add(keyword)
11110 ..add(_constructorName)
11111 ..add(_argumentList);
11112
11113 /**
11114 * Return the name of the constructor to be invoked.
11115 */
11116 ConstructorName get constructorName => _constructorName;
11117
11118 /**
11119 * Set the name of the constructor to be invoked to the given [name].
11120 */
11121 void set constructorName(ConstructorName name) {
11122 _constructorName = _becomeParentOf(name);
11123 }
11124
11125 @override
11126 Token get endToken => _argumentList.endToken;
11127
11128 /**
11129 * Return `true` if this creation expression is used to invoke a constant
11130 * constructor.
11131 */
11132 bool get isConst => keyword is KeywordToken &&
11133 (keyword as KeywordToken).keyword == Keyword.CONST;
11134
11135 @override
11136 int get precedence => 16;
11137
11138 @override
11139 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this);
11140
11141 @override
11142 void visitChildren(AstVisitor visitor) {
11143 _safelyVisitChild(_constructorName, visitor);
11144 _safelyVisitChild(_argumentList, visitor);
11145 }
11146 }
11147
11148 /**
11149 * An integer literal expression.
11150 *
11151 * > integerLiteral ::=
11152 * > decimalIntegerLiteral
11153 * > | hexidecimalIntegerLiteral
11154 * >
11155 * > decimalIntegerLiteral ::=
11156 * > decimalDigit+
11157 * >
11158 * > hexidecimalIntegerLiteral ::=
11159 * > '0x' hexidecimalDigit+
11160 * > | '0X' hexidecimalDigit+
11161 */
11162 class IntegerLiteral extends Literal {
11163 /**
11164 * The token representing the literal.
11165 */
11166 Token literal;
11167
11168 /**
11169 * The value of the literal.
11170 */
11171 int value = 0;
11172
11173 /**
11174 * Initialize a newly created integer literal.
11175 */
11176 IntegerLiteral(this.literal, this.value);
11177
11178 @override
11179 Token get beginToken => literal;
11180
11181 @override
11182 Iterable get childEntities => new ChildEntities()..add(literal);
11183
11184 @override
11185 Token get endToken => literal;
11186
11187 @override
11188 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this);
11189
11190 @override
11191 void visitChildren(AstVisitor visitor) {
11192 // There are no children to visit.
11193 }
11194 }
11195
11196 /**
11197 * A node within a [StringInterpolation].
11198 *
11199 * > interpolationElement ::=
11200 * > [InterpolationExpression]
11201 * > | [InterpolationString]
11202 */
11203 abstract class InterpolationElement extends AstNode {}
11204
11205 /**
11206 * An expression embedded in a string interpolation.
11207 *
11208 * > interpolationExpression ::=
11209 * > '$' [SimpleIdentifier]
11210 * > | '$' '{' [Expression] '}'
11211 */
11212 class InterpolationExpression extends InterpolationElement {
11213 /**
11214 * The token used to introduce the interpolation expression; either '$' if the
11215 * expression is a simple identifier or '${' if the expression is a full
11216 * expression.
11217 */
11218 Token leftBracket;
11219
11220 /**
11221 * The expression to be evaluated for the value to be converted into a string.
11222 */
11223 Expression _expression;
11224
11225 /**
11226 * The right curly bracket, or `null` if the expression is an identifier
11227 * without brackets.
11228 */
11229 Token rightBracket;
11230
11231 /**
11232 * Initialize a newly created interpolation expression.
11233 */
11234 InterpolationExpression(
11235 this.leftBracket, Expression expression, this.rightBracket) {
11236 _expression = _becomeParentOf(expression);
11237 }
11238
11239 @override
11240 Token get beginToken => leftBracket;
11241
11242 @override
11243 Iterable get childEntities => new ChildEntities()
11244 ..add(leftBracket)
11245 ..add(_expression)
11246 ..add(rightBracket);
11247
11248 @override
11249 Token get endToken {
11250 if (rightBracket != null) {
11251 return rightBracket;
11252 }
11253 return _expression.endToken;
11254 }
11255
11256 /**
11257 * Return the expression to be evaluated for the value to be converted into a
11258 * string.
11259 */
11260 Expression get expression => _expression;
11261
11262 /**
11263 * Set the expression to be evaluated for the value to be converted into a
11264 * string to the given [expression].
11265 */
11266 void set expression(Expression expression) {
11267 _expression = _becomeParentOf(expression);
11268 }
11269
11270 @override
11271 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this);
11272
11273 @override
11274 void visitChildren(AstVisitor visitor) {
11275 _safelyVisitChild(_expression, visitor);
11276 }
11277 }
11278
11279 /**
11280 * A non-empty substring of an interpolated string.
11281 *
11282 * > interpolationString ::=
11283 * > characters
11284 */
11285 class InterpolationString extends InterpolationElement {
11286 /**
11287 * The characters that will be added to the string.
11288 */
11289 Token contents;
11290
11291 /**
11292 * The value of the literal.
11293 */
11294 String value;
11295
11296 /**
11297 * Initialize a newly created string of characters that are part of a string
11298 * interpolation.
11299 */
11300 InterpolationString(this.contents, this.value);
11301
11302 @override
11303 Token get beginToken => contents;
11304
11305 @override
11306 Iterable get childEntities => new ChildEntities()..add(contents);
11307
11308 /**
11309 * Return the offset of the after-last contents character.
11310 */
11311 int get contentsEnd {
11312 String lexeme = contents.lexeme;
11313 return offset + new StringLexemeHelper(lexeme, true, true).end;
11314 }
11315
11316 /**
11317 * Return the offset of the first contents character.
11318 */
11319 int get contentsOffset {
11320 int offset = contents.offset;
11321 String lexeme = contents.lexeme;
11322 return offset + new StringLexemeHelper(lexeme, true, true).start;
11323 }
11324
11325 @override
11326 Token get endToken => contents;
11327
11328 @override
11329 accept(AstVisitor visitor) => visitor.visitInterpolationString(this);
11330
11331 @override
11332 void visitChildren(AstVisitor visitor) {}
11333 }
11334
11335 /**
11336 * An is expression.
11337 *
11338 * > isExpression ::=
11339 * > [Expression] 'is' '!'? [TypeName]
11340 */
11341 class IsExpression extends Expression {
11342 /**
11343 * The expression used to compute the value whose type is being tested.
11344 */
11345 Expression _expression;
11346
11347 /**
11348 * The is operator.
11349 */
11350 Token isOperator;
11351
11352 /**
11353 * The not operator, or `null` if the sense of the test is not negated.
11354 */
11355 Token notOperator;
11356
11357 /**
11358 * The name of the type being tested for.
11359 */
11360 TypeName _type;
11361
11362 /**
11363 * Initialize a newly created is expression. The [notOperator] can be `null`
11364 * if the sense of the test is not negated.
11365 */
11366 IsExpression(
11367 Expression expression, this.isOperator, this.notOperator, TypeName type) {
11368 _expression = _becomeParentOf(expression);
11369 _type = _becomeParentOf(type);
11370 }
11371
11372 @override
11373 Token get beginToken => _expression.beginToken;
11374
11375 @override
11376 Iterable get childEntities => new ChildEntities()
11377 ..add(_expression)
11378 ..add(isOperator)
11379 ..add(notOperator)
11380 ..add(_type);
11381
11382 @override
11383 Token get endToken => _type.endToken;
11384
11385 /**
11386 * Return the expression used to compute the value whose type is being tested.
11387 */
11388 Expression get expression => _expression;
11389
11390 /**
11391 * Set the expression used to compute the value whose type is being tested to
11392 * the given [expression].
11393 */
11394 void set expression(Expression expression) {
11395 _expression = _becomeParentOf(expression);
11396 }
11397
11398 @override
11399 int get precedence => 7;
11400
11401 /**
11402 * Return the name of the type being tested for.
11403 */
11404 TypeName get type => _type;
11405
11406 /**
11407 * Set the name of the type being tested for to the given [name].
11408 */
11409 void set type(TypeName name) {
11410 _type = _becomeParentOf(name);
11411 }
11412
11413 @override
11414 accept(AstVisitor visitor) => visitor.visitIsExpression(this);
11415
11416 @override
11417 void visitChildren(AstVisitor visitor) {
11418 _safelyVisitChild(_expression, visitor);
11419 _safelyVisitChild(_type, visitor);
11420 }
11421 }
11422
11423 /**
11424 * A label on either a [LabeledStatement] or a [NamedExpression].
11425 *
11426 * > label ::=
11427 * > [SimpleIdentifier] ':'
11428 */
11429 class Label extends AstNode {
11430 /**
11431 * The label being associated with the statement.
11432 */
11433 SimpleIdentifier _label;
11434
11435 /**
11436 * The colon that separates the label from the statement.
11437 */
11438 Token colon;
11439
11440 /**
11441 * Initialize a newly created label.
11442 */
11443 Label(SimpleIdentifier label, this.colon) {
11444 _label = _becomeParentOf(label);
11445 }
11446
11447 @override
11448 Token get beginToken => _label.beginToken;
11449
11450 @override
11451 Iterable get childEntities => new ChildEntities()..add(_label)..add(colon);
11452
11453 @override
11454 Token get endToken => colon;
11455
11456 /**
11457 * Return the label being associated with the statement.
11458 */
11459 SimpleIdentifier get label => _label;
11460
11461 /**
11462 * Set the label being associated with the statement to the given [label].
11463 */
11464 void set label(SimpleIdentifier label) {
11465 _label = _becomeParentOf(label);
11466 }
11467
11468 @override
11469 accept(AstVisitor visitor) => visitor.visitLabel(this);
11470
11471 @override
11472 void visitChildren(AstVisitor visitor) {
11473 _safelyVisitChild(_label, visitor);
11474 }
11475 }
11476
11477 /**
11478 * A statement that has a label associated with them.
11479 *
11480 * > labeledStatement ::=
11481 * > [Label]+ [Statement]
11482 */
11483 class LabeledStatement extends Statement {
11484 /**
11485 * The labels being associated with the statement.
11486 */
11487 NodeList<Label> _labels;
11488
11489 /**
11490 * The statement with which the labels are being associated.
11491 */
11492 Statement _statement;
11493
11494 /**
11495 * Initialize a newly created labeled statement.
11496 */
11497 LabeledStatement(List<Label> labels, Statement statement) {
11498 _labels = new NodeList<Label>(this, labels);
11499 _statement = _becomeParentOf(statement);
11500 }
11501
11502 @override
11503 Token get beginToken {
11504 if (!_labels.isEmpty) {
11505 return _labels.beginToken;
11506 }
11507 return _statement.beginToken;
11508 }
11509
11510 @override
11511 Iterable get childEntities => new ChildEntities()
11512 ..addAll(_labels)
11513 ..add(_statement);
11514
11515 @override
11516 Token get endToken => _statement.endToken;
11517
11518 /**
11519 * Return the labels being associated with the statement.
11520 */
11521 NodeList<Label> get labels => _labels;
11522
11523 /**
11524 * Return the statement with which the labels are being associated.
11525 */
11526 Statement get statement => _statement;
11527
11528 /**
11529 * Set the statement with which the labels are being associated to the given
11530 * [statement].
11531 */
11532 void set statement(Statement statement) {
11533 _statement = _becomeParentOf(statement);
11534 }
11535
11536 @override
11537 Statement get unlabeled => _statement.unlabeled;
11538
11539 @override
11540 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this);
11541
11542 @override
11543 void visitChildren(AstVisitor visitor) {
11544 _labels.accept(visitor);
11545 _safelyVisitChild(_statement, visitor);
11546 }
11547 }
11548
11549 /**
11550 * A library directive.
11551 *
11552 * > libraryDirective ::=
11553 * > [Annotation] 'library' [Identifier] ';'
11554 */
11555 class LibraryDirective extends Directive {
11556 /**
11557 * The token representing the 'library' keyword.
11558 */
11559 Token libraryKeyword;
11560
11561 /**
11562 * The name of the library being defined.
11563 */
11564 LibraryIdentifier _name;
11565
11566 /**
11567 * The semicolon terminating the directive.
11568 */
11569 Token semicolon;
11570
11571 /**
11572 * Initialize a newly created library directive. Either or both of the
11573 * [comment] and [metadata] can be `null` if the directive does not have the
11574 * corresponding attribute.
11575 */
11576 LibraryDirective(Comment comment, List<Annotation> metadata,
11577 this.libraryKeyword, LibraryIdentifier name, this.semicolon)
11578 : super(comment, metadata) {
11579 _name = _becomeParentOf(name);
11580 }
11581
11582 @override
11583 Iterable get childEntities =>
11584 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon);
11585
11586 @override
11587 Token get endToken => semicolon;
11588
11589 @override
11590 Token get firstTokenAfterCommentAndMetadata => libraryKeyword;
11591
11592 @override
11593 Token get keyword => libraryKeyword;
11594
11595 /**
11596 * Return the token representing the 'library' token.
11597 */
11598 @deprecated // Use "this.libraryKeyword"
11599 Token get libraryToken => libraryKeyword;
11600
11601 /**
11602 * Set the token representing the 'library' token to the given [token].
11603 */
11604 @deprecated // Use "this.libraryKeyword"
11605 set libraryToken(Token token) {
11606 libraryKeyword = token;
11607 }
11608
11609 /**
11610 * Return the name of the library being defined.
11611 */
11612 LibraryIdentifier get name => _name;
11613
11614 /**
11615 * Set the name of the library being defined to the given [name].
11616 */
11617 void set name(LibraryIdentifier name) {
11618 _name = _becomeParentOf(name);
11619 }
11620
11621 @override
11622 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this);
11623
11624 @override
11625 void visitChildren(AstVisitor visitor) {
11626 super.visitChildren(visitor);
11627 _safelyVisitChild(_name, visitor);
11628 }
11629 }
11630
11631 /**
11632 * The identifier for a library.
11633 *
11634 * > libraryIdentifier ::=
11635 * > [SimpleIdentifier] ('.' [SimpleIdentifier])*
11636 */
11637 class LibraryIdentifier extends Identifier {
11638 /**
11639 * The components of the identifier.
11640 */
11641 NodeList<SimpleIdentifier> _components;
11642
11643 /**
11644 * Initialize a newly created prefixed identifier.
11645 */
11646 LibraryIdentifier(List<SimpleIdentifier> components) {
11647 _components = new NodeList<SimpleIdentifier>(this, components);
11648 }
11649
11650 @override
11651 Token get beginToken => _components.beginToken;
11652
11653 @override
11654 Element get bestElement => staticElement;
11655
11656 @override
11657 // TODO(paulberry): add "." tokens.
11658 Iterable get childEntities => new ChildEntities()..addAll(_components);
11659
11660 /**
11661 * Return the components of the identifier.
11662 */
11663 NodeList<SimpleIdentifier> get components => _components;
11664
11665 @override
11666 Token get endToken => _components.endToken;
11667
11668 @override
11669 String get name {
11670 StringBuffer buffer = new StringBuffer();
11671 bool needsPeriod = false;
11672 for (SimpleIdentifier identifier in _components) {
11673 if (needsPeriod) {
11674 buffer.write(".");
11675 } else {
11676 needsPeriod = true;
11677 }
11678 buffer.write(identifier.name);
11679 }
11680 return buffer.toString();
11681 }
11682
11683 @override
11684 int get precedence => 15;
11685
11686 @override
11687 Element get propagatedElement => null;
11688
11689 @override
11690 Element get staticElement => null;
11691
11692 @override
11693 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this);
11694
11695 @override
11696 void visitChildren(AstVisitor visitor) {
11697 _components.accept(visitor);
11698 }
11699 }
11700
11701 /**
11702 * A list literal.
11703 *
11704 * > listLiteral ::=
11705 * > 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']'
11706 */
11707 class ListLiteral extends TypedLiteral {
11708 /**
11709 * The left square bracket.
11710 */
11711 Token leftBracket;
11712
11713 /**
11714 * The expressions used to compute the elements of the list.
11715 */
11716 NodeList<Expression> _elements;
11717
11718 /**
11719 * The right square bracket.
11720 */
11721 Token rightBracket;
11722
11723 /**
11724 * Initialize a newly created list literal. The [constKeyword] can be `null`
11725 * if the literal is not a constant. The [typeArguments] can be `null` if no
11726 * type arguments were declared. The list of [elements] can be `null` if the
11727 * list is empty.
11728 */
11729 ListLiteral(Token constKeyword, TypeArgumentList typeArguments,
11730 this.leftBracket, List<Expression> elements, this.rightBracket)
11731 : super(constKeyword, typeArguments) {
11732 _elements = new NodeList<Expression>(this, elements);
11733 }
11734
11735 @override
11736 Token get beginToken {
11737 if (constKeyword != null) {
11738 return constKeyword;
11739 }
11740 TypeArgumentList typeArguments = this.typeArguments;
11741 if (typeArguments != null) {
11742 return typeArguments.beginToken;
11743 }
11744 return leftBracket;
11745 }
11746
11747 @override
11748 // TODO(paulberry): add commas.
11749 Iterable get childEntities => super._childEntities
11750 ..add(leftBracket)
11751 ..addAll(_elements)
11752 ..add(rightBracket);
11753
11754 /**
11755 * Return the expressions used to compute the elements of the list.
11756 */
11757 NodeList<Expression> get elements => _elements;
11758
11759 @override
11760 Token get endToken => rightBracket;
11761
11762 @override
11763 accept(AstVisitor visitor) => visitor.visitListLiteral(this);
11764
11765 @override
11766 void visitChildren(AstVisitor visitor) {
11767 super.visitChildren(visitor);
11768 _elements.accept(visitor);
11769 }
11770 }
11771
11772 /**
11773 * A node that represents a literal expression.
11774 *
11775 * > literal ::=
11776 * > [BooleanLiteral]
11777 * > | [DoubleLiteral]
11778 * > | [IntegerLiteral]
11779 * > | [ListLiteral]
11780 * > | [MapLiteral]
11781 * > | [NullLiteral]
11782 * > | [StringLiteral]
11783 */
11784 abstract class Literal extends Expression {
11785 @override
11786 int get precedence => 16;
11787 }
11788
11789 /**
11790 * A literal map.
11791 *
11792 * > mapLiteral ::=
11793 * > 'const'? ('<' [TypeName] (',' [TypeName])* '>')?
11794 * > '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}'
11795 */
11796 class MapLiteral extends TypedLiteral {
11797 /**
11798 * The left curly bracket.
11799 */
11800 Token leftBracket;
11801
11802 /**
11803 * The entries in the map.
11804 */
11805 NodeList<MapLiteralEntry> _entries;
11806
11807 /**
11808 * The right curly bracket.
11809 */
11810 Token rightBracket;
11811
11812 /**
11813 * Initialize a newly created map literal. The [constKeyword] can be `null` if
11814 * the literal is not a constant. The [typeArguments] can be `null` if no type
11815 * arguments were declared. The [entries] can be `null` if the map is empty.
11816 */
11817 MapLiteral(Token constKeyword, TypeArgumentList typeArguments,
11818 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket)
11819 : super(constKeyword, typeArguments) {
11820 _entries = new NodeList<MapLiteralEntry>(this, entries);
11821 }
11822
11823 @override
11824 Token get beginToken {
11825 if (constKeyword != null) {
11826 return constKeyword;
11827 }
11828 TypeArgumentList typeArguments = this.typeArguments;
11829 if (typeArguments != null) {
11830 return typeArguments.beginToken;
11831 }
11832 return leftBracket;
11833 }
11834
11835 @override
11836 // TODO(paulberry): add commas.
11837 Iterable get childEntities => super._childEntities
11838 ..add(leftBracket)
11839 ..addAll(entries)
11840 ..add(rightBracket);
11841
11842 @override
11843 Token get endToken => rightBracket;
11844
11845 /**
11846 * Return the entries in the map.
11847 */
11848 NodeList<MapLiteralEntry> get entries => _entries;
11849
11850 @override
11851 accept(AstVisitor visitor) => visitor.visitMapLiteral(this);
11852
11853 @override
11854 void visitChildren(AstVisitor visitor) {
11855 super.visitChildren(visitor);
11856 _entries.accept(visitor);
11857 }
11858 }
11859
11860 /**
11861 * A single key/value pair in a map literal.
11862 *
11863 * > mapLiteralEntry ::=
11864 * > [Expression] ':' [Expression]
11865 */
11866 class MapLiteralEntry extends AstNode {
11867 /**
11868 * The expression computing the key with which the value will be associated.
11869 */
11870 Expression _key;
11871
11872 /**
11873 * The colon that separates the key from the value.
11874 */
11875 Token separator;
11876
11877 /**
11878 * The expression computing the value that will be associated with the key.
11879 */
11880 Expression _value;
11881
11882 /**
11883 * Initialize a newly created map literal entry.
11884 */
11885 MapLiteralEntry(Expression key, this.separator, Expression value) {
11886 _key = _becomeParentOf(key);
11887 _value = _becomeParentOf(value);
11888 }
11889
11890 @override
11891 Token get beginToken => _key.beginToken;
11892
11893 @override
11894 Iterable get childEntities =>
11895 new ChildEntities()..add(_key)..add(separator)..add(_value);
11896
11897 @override
11898 Token get endToken => _value.endToken;
11899
11900 /**
11901 * Return the expression computing the key with which the value will be
11902 * associated.
11903 */
11904 Expression get key => _key;
11905
11906 /**
11907 * Set the expression computing the key with which the value will be
11908 * associated to the given [string].
11909 */
11910 void set key(Expression string) {
11911 _key = _becomeParentOf(string);
11912 }
11913
11914 /**
11915 * Return the expression computing the value that will be associated with the
11916 * key.
11917 */
11918 Expression get value => _value;
11919
11920 /**
11921 * Set the expression computing the value that will be associated with the key
11922 * to the given [expression].
11923 */
11924 void set value(Expression expression) {
11925 _value = _becomeParentOf(expression);
11926 }
11927
11928 @override
11929 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this);
11930
11931 @override
11932 void visitChildren(AstVisitor visitor) {
11933 _safelyVisitChild(_key, visitor);
11934 _safelyVisitChild(_value, visitor);
11935 }
11936 }
11937
11938 /**
11939 * A method declaration.
11940 *
11941 * > methodDeclaration ::=
11942 * > methodSignature [FunctionBody]
11943 * >
11944 * > methodSignature ::=
11945 * > 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')?
11946 * > methodName [TypeParameterList] [FormalParameterList]
11947 * >
11948 * > methodName ::=
11949 * > [SimpleIdentifier]
11950 * > | 'operator' [SimpleIdentifier]
11951 */
11952 class MethodDeclaration extends ClassMember {
11953 /**
11954 * The token for the 'external' keyword, or `null` if the constructor is not
11955 * external.
11956 */
11957 Token externalKeyword;
11958
11959 /**
11960 * The token representing the 'abstract' or 'static' keyword, or `null` if
11961 * neither modifier was specified.
11962 */
11963 Token modifierKeyword;
11964
11965 /**
11966 * The return type of the method, or `null` if no return type was declared.
11967 */
11968 TypeName _returnType;
11969
11970 /**
11971 * The token representing the 'get' or 'set' keyword, or `null` if this is a
11972 * method declaration rather than a property declaration.
11973 */
11974 Token propertyKeyword;
11975
11976 /**
11977 * The token representing the 'operator' keyword, or `null` if this method
11978 * does not declare an operator.
11979 */
11980 Token operatorKeyword;
11981
11982 /**
11983 * The name of the method.
11984 */
11985 SimpleIdentifier _name;
11986
11987 /**
11988 * The type parameters associated with the method, or `null` if the method is
11989 * not a generic method.
11990 */
11991 TypeParameterList _typeParameters;
11992
11993 /**
11994 * The parameters associated with the method, or `null` if this method
11995 * declares a getter.
11996 */
11997 FormalParameterList _parameters;
11998
11999 /**
12000 * The body of the method.
12001 */
12002 FunctionBody _body;
12003
12004 /**
12005 * Initialize a newly created method declaration. Either or both of the
12006 * [comment] and [metadata] can be `null` if the declaration does not have the
12007 * corresponding attribute. The [externalKeyword] can be `null` if the method
12008 * is not external. The [modifierKeyword] can be `null` if the method is
12009 * neither abstract nor static. The [returnType] can be `null` if no return
12010 * type was specified. The [propertyKeyword] can be `null` if the method is
12011 * neither a getter or a setter. The [operatorKeyword] can be `null` if the
12012 * method does not implement an operator. The [parameters] must be `null` if
12013 * this method declares a getter.
12014 */
12015 MethodDeclaration(
12016 Comment comment,
12017 List<Annotation> metadata,
12018 this.externalKeyword,
12019 this.modifierKeyword,
12020 TypeName returnType,
12021 this.propertyKeyword,
12022 this.operatorKeyword,
12023 SimpleIdentifier name,
12024 TypeParameterList typeParameters,
12025 FormalParameterList parameters,
12026 FunctionBody body)
12027 : super(comment, metadata) {
12028 _returnType = _becomeParentOf(returnType);
12029 _name = _becomeParentOf(name);
12030 _typeParameters = _becomeParentOf(typeParameters);
12031 _parameters = _becomeParentOf(parameters);
12032 _body = _becomeParentOf(body);
12033 }
12034
12035 /**
12036 * Return the body of the method.
12037 */
12038 FunctionBody get body => _body;
12039
12040 /**
12041 * Set the body of the method to the given [functionBody].
12042 */
12043 void set body(FunctionBody functionBody) {
12044 _body = _becomeParentOf(functionBody);
12045 }
12046
12047 @override
12048 Iterable get childEntities => super._childEntities
12049 ..add(externalKeyword)
12050 ..add(modifierKeyword)
12051 ..add(_returnType)
12052 ..add(propertyKeyword)
12053 ..add(operatorKeyword)
12054 ..add(_name)
12055 ..add(_parameters)
12056 ..add(_body);
12057
12058 /**
12059 * Return the element associated with this method, or `null` if the AST
12060 * structure has not been resolved. The element can either be a
12061 * [MethodElement], if this represents the declaration of a normal method, or
12062 * a [PropertyAccessorElement] if this represents the declaration of either a
12063 * getter or a setter.
12064 */
12065 @override
12066 ExecutableElement get element =>
12067 _name != null ? (_name.staticElement as ExecutableElement) : null;
12068
12069 @override
12070 Token get endToken => _body.endToken;
12071
12072 @override
12073 Token get firstTokenAfterCommentAndMetadata {
12074 if (modifierKeyword != null) {
12075 return modifierKeyword;
12076 } else if (_returnType != null) {
12077 return _returnType.beginToken;
12078 } else if (propertyKeyword != null) {
12079 return propertyKeyword;
12080 } else if (operatorKeyword != null) {
12081 return operatorKeyword;
12082 }
12083 return _name.beginToken;
12084 }
12085
12086 /**
12087 * Return `true` if this method is declared to be an abstract method.
12088 */
12089 bool get isAbstract {
12090 FunctionBody body = _body;
12091 return externalKeyword == null &&
12092 (body is EmptyFunctionBody && !body.semicolon.isSynthetic);
12093 }
12094
12095 /**
12096 * Return `true` if this method declares a getter.
12097 */
12098 bool get isGetter => propertyKeyword != null &&
12099 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
12100
12101 /**
12102 * Return `true` if this method declares an operator.
12103 */
12104 bool get isOperator => operatorKeyword != null;
12105
12106 /**
12107 * Return `true` if this method declares a setter.
12108 */
12109 bool get isSetter => propertyKeyword != null &&
12110 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
12111
12112 /**
12113 * Return `true` if this method is declared to be a static method.
12114 */
12115 bool get isStatic => modifierKeyword != null &&
12116 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC;
12117
12118 /**
12119 * Return the name of the method.
12120 */
12121 SimpleIdentifier get name => _name;
12122
12123 /**
12124 * Set the name of the method to the given [identifier].
12125 */
12126 void set name(SimpleIdentifier identifier) {
12127 _name = _becomeParentOf(identifier);
12128 }
12129
12130 /**
12131 * Return the parameters associated with the method, or `null` if this method
12132 * declares a getter.
12133 */
12134 FormalParameterList get parameters => _parameters;
12135
12136 /**
12137 * Set the parameters associated with the method to the given list of
12138 * [parameters].
12139 */
12140 void set parameters(FormalParameterList parameters) {
12141 _parameters = _becomeParentOf(parameters);
12142 }
12143
12144 /**
12145 * Return the return type of the method, or `null` if no return type was
12146 * declared.
12147 */
12148 TypeName get returnType => _returnType;
12149
12150 /**
12151 * Set the return type of the method to the given [typeName].
12152 */
12153 void set returnType(TypeName typeName) {
12154 _returnType = _becomeParentOf(typeName);
12155 }
12156
12157 /**
12158 * Return the type parameters associated with this method, or `null` if this
12159 * method is not a generic method.
12160 */
12161 TypeParameterList get typeParameters => _typeParameters;
12162
12163 /**
12164 * Set the type parameters associated with this method to the given
12165 * [typeParameters].
12166 */
12167 void set typeParameters(TypeParameterList typeParameters) {
12168 _typeParameters = _becomeParentOf(typeParameters);
12169 }
12170
12171 @override
12172 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this);
12173
12174 @override
12175 void visitChildren(AstVisitor visitor) {
12176 super.visitChildren(visitor);
12177 _safelyVisitChild(_returnType, visitor);
12178 _safelyVisitChild(_name, visitor);
12179 _safelyVisitChild(_typeParameters, visitor);
12180 _safelyVisitChild(_parameters, visitor);
12181 _safelyVisitChild(_body, visitor);
12182 }
12183 }
12184
12185 /**
12186 * The invocation of either a function or a method. Invocations of functions
12187 * resulting from evaluating an expression are represented by
12188 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are
12189 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes.
12190 *
12191 * > methodInvoction ::=
12192 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t]
12193 */
12194 class MethodInvocation extends Expression {
12195 /**
12196 * The expression producing the object on which the method is defined, or
12197 * `null` if there is no target (that is, the target is implicitly `this`).
12198 */
12199 Expression _target;
12200
12201 /**
12202 * The operator that separates the target from the method name, or `null`
12203 * if there is no target. In an ordinary method invocation this will be a
12204 * period ('.'). In a cascade section this will be the cascade operator
12205 * ('..').
12206 */
12207 Token operator;
12208
12209 /**
12210 * The name of the method being invoked.
12211 */
12212 SimpleIdentifier _methodName;
12213
12214 /**
12215 * The type arguments to be applied to the method being invoked, or `null` if
12216 * no type arguments were provided.
12217 */
12218 TypeArgumentList _typeArguments;
12219
12220 /**
12221 * The list of arguments to the method.
12222 */
12223 ArgumentList _argumentList;
12224
12225 /**
12226 * Initialize a newly created method invocation. The [target] and [operator]
12227 * can be `null` if there is no target.
12228 */
12229 MethodInvocation(
12230 Expression target,
12231 this.operator,
12232 SimpleIdentifier methodName,
12233 TypeArgumentList typeArguments,
12234 ArgumentList argumentList) {
12235 _target = _becomeParentOf(target);
12236 _methodName = _becomeParentOf(methodName);
12237 _typeArguments = _becomeParentOf(typeArguments);
12238 _argumentList = _becomeParentOf(argumentList);
12239 }
12240
12241 /**
12242 * Return the list of arguments to the method.
12243 */
12244 ArgumentList get argumentList => _argumentList;
12245
12246 /**
12247 * Set the list of arguments to the method to the given [argumentList].
12248 */
12249 void set argumentList(ArgumentList argumentList) {
12250 _argumentList = _becomeParentOf(argumentList);
12251 }
12252
12253 @override
12254 Token get beginToken {
12255 if (_target != null) {
12256 return _target.beginToken;
12257 } else if (operator != null) {
12258 return operator;
12259 }
12260 return _methodName.beginToken;
12261 }
12262
12263 @override
12264 Iterable get childEntities => new ChildEntities()
12265 ..add(_target)
12266 ..add(operator)
12267 ..add(_methodName)
12268 ..add(_argumentList);
12269
12270 @override
12271 Token get endToken => _argumentList.endToken;
12272
12273 /**
12274 * Return `true` if this expression is cascaded. If it is, then the target of
12275 * this expression is not stored locally but is stored in the nearest ancestor
12276 * that is a [CascadeExpression].
12277 */
12278 bool get isCascaded =>
12279 operator != null && operator.type == TokenType.PERIOD_PERIOD;
12280
12281 /**
12282 * Return the name of the method being invoked.
12283 */
12284 SimpleIdentifier get methodName => _methodName;
12285
12286 /**
12287 * Set the name of the method being invoked to the given [identifier].
12288 */
12289 void set methodName(SimpleIdentifier identifier) {
12290 _methodName = _becomeParentOf(identifier);
12291 }
12292
12293 /**
12294 * The operator that separates the target from the method name, or `null`
12295 * if there is no target. In an ordinary method invocation this will be a
12296 * period ('.'). In a cascade section this will be the cascade operator
12297 * ('..').
12298 */
12299 @deprecated // Use this.operator
12300 Token get period => operator;
12301
12302 /**
12303 * The operator that separates the target from the method name, or `null`
12304 * if there is no target. In an ordinary method invocation this will be a
12305 * period ('.'). In a cascade section this will be the cascade operator
12306 * ('..').
12307 */
12308 @deprecated // Use this.operator
12309 void set period(Token value) {
12310 operator = value;
12311 }
12312
12313 @override
12314 int get precedence => 15;
12315
12316 /**
12317 * Return the expression used to compute the receiver of the invocation. If
12318 * this invocation is not part of a cascade expression, then this is the same
12319 * as [target]. If this invocation is part of a cascade expression, then the
12320 * target stored with the cascade expression is returned.
12321 */
12322 Expression get realTarget {
12323 if (isCascaded) {
12324 AstNode ancestor = parent;
12325 while (ancestor is! CascadeExpression) {
12326 if (ancestor == null) {
12327 return _target;
12328 }
12329 ancestor = ancestor.parent;
12330 }
12331 return (ancestor as CascadeExpression).target;
12332 }
12333 return _target;
12334 }
12335
12336 /**
12337 * Return the expression producing the object on which the method is defined,
12338 * or `null` if there is no target (that is, the target is implicitly `this`)
12339 * or if this method invocation is part of a cascade expression.
12340 *
12341 * Use [realTarget] to get the target independent of whether this is part of a
12342 * cascade expression.
12343 */
12344 Expression get target => _target;
12345
12346 /**
12347 * Set the expression producing the object on which the method is defined to
12348 * the given [expression].
12349 */
12350 void set target(Expression expression) {
12351 _target = _becomeParentOf(expression);
12352 }
12353
12354 /**
12355 * Return the type arguments to be applied to the method being invoked, or
12356 * `null` if no type arguments were provided.
12357 */
12358 TypeArgumentList get typeArguments => _typeArguments;
12359
12360 /**
12361 * Set the type arguments to be applied to the method being invoked to the
12362 * given [typeArguments].
12363 */
12364 void set typeArguments(TypeArgumentList typeArguments) {
12365 _typeArguments = _becomeParentOf(typeArguments);
12366 }
12367
12368 @override
12369 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this);
12370
12371 @override
12372 void visitChildren(AstVisitor visitor) {
12373 _safelyVisitChild(_target, visitor);
12374 _safelyVisitChild(_methodName, visitor);
12375 _safelyVisitChild(_typeArguments, visitor);
12376 _safelyVisitChild(_argumentList, visitor);
12377 }
12378 }
12379
12380 /**
12381 * A node that declares a single name within the scope of a compilation unit.
12382 */
12383 abstract class NamedCompilationUnitMember extends CompilationUnitMember {
12384 /**
12385 * The name of the member being declared.
12386 */
12387 SimpleIdentifier _name;
12388
12389 /**
12390 * Initialize a newly created compilation unit member with the given [name].
12391 * Either or both of the [comment] and [metadata] can be `null` if the member
12392 * does not have the corresponding attribute.
12393 */
12394 NamedCompilationUnitMember(
12395 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
12396 : super(comment, metadata) {
12397 _name = _becomeParentOf(name);
12398 }
12399
12400 /**
12401 * Return the name of the member being declared.
12402 */
12403 SimpleIdentifier get name => _name;
12404
12405 /**
12406 * Set the name of the member being declared to the given [identifier].
12407 */
12408 void set name(SimpleIdentifier identifier) {
12409 _name = _becomeParentOf(identifier);
12410 }
12411 }
12412
12413 /**
12414 * An expression that has a name associated with it. They are used in method
12415 * invocations when there are named parameters.
12416 *
12417 * > namedExpression ::=
12418 * > [Label] [Expression]
12419 */
12420 class NamedExpression extends Expression {
12421 /**
12422 * The name associated with the expression.
12423 */
12424 Label _name;
12425
12426 /**
12427 * The expression with which the name is associated.
12428 */
12429 Expression _expression;
12430
12431 /**
12432 * Initialize a newly created named expression..
12433 */
12434 NamedExpression(Label name, Expression expression) {
12435 _name = _becomeParentOf(name);
12436 _expression = _becomeParentOf(expression);
12437 }
12438
12439 @override
12440 Token get beginToken => _name.beginToken;
12441
12442 @override
12443 Iterable get childEntities =>
12444 new ChildEntities()..add(_name)..add(_expression);
12445
12446 /**
12447 * Return the element representing the parameter being named by this
12448 * expression, or `null` if the AST structure has not been resolved or if
12449 * there is no parameter with the same name as this expression.
12450 */
12451 ParameterElement get element {
12452 Element element = _name.label.staticElement;
12453 if (element is ParameterElement) {
12454 return element;
12455 }
12456 return null;
12457 }
12458
12459 @override
12460 Token get endToken => _expression.endToken;
12461
12462 /**
12463 * Return the expression with which the name is associated.
12464 */
12465 Expression get expression => _expression;
12466
12467 /**
12468 * Set the expression with which the name is associated to the given
12469 * [expression].
12470 */
12471 void set expression(Expression expression) {
12472 _expression = _becomeParentOf(expression);
12473 }
12474
12475 /**
12476 * Return the name associated with the expression.
12477 */
12478 Label get name => _name;
12479
12480 /**
12481 * Set the name associated with the expression to the given [identifier].
12482 */
12483 void set name(Label identifier) {
12484 _name = _becomeParentOf(identifier);
12485 }
12486
12487 @override
12488 int get precedence => 0;
12489
12490 @override
12491 accept(AstVisitor visitor) => visitor.visitNamedExpression(this);
12492
12493 @override
12494 void visitChildren(AstVisitor visitor) {
12495 _safelyVisitChild(_name, visitor);
12496 _safelyVisitChild(_expression, visitor);
12497 }
12498 }
12499
12500 /**
12501 * A node that represents a directive that impacts the namespace of a library.
12502 *
12503 * > directive ::=
12504 * > [ExportDirective]
12505 * > | [ImportDirective]
12506 */
12507 abstract class NamespaceDirective extends UriBasedDirective {
12508 /**
12509 * The token representing the 'import' or 'export' keyword.
12510 */
12511 Token keyword;
12512
12513 /**
12514 * The combinators used to control which names are imported or exported.
12515 */
12516 NodeList<Combinator> _combinators;
12517
12518 /**
12519 * The semicolon terminating the directive.
12520 */
12521 Token semicolon;
12522
12523 /**
12524 * Initialize a newly created namespace directive. Either or both of the
12525 * [comment] and [metadata] can be `null` if the directive does not have the
12526 * corresponding attribute. The list of [combinators] can be `null` if there
12527 * are no combinators.
12528 */
12529 NamespaceDirective(Comment comment, List<Annotation> metadata, this.keyword,
12530 StringLiteral libraryUri, List<Combinator> combinators, this.semicolon)
12531 : super(comment, metadata, libraryUri) {
12532 _combinators = new NodeList<Combinator>(this, combinators);
12533 }
12534
12535 /**
12536 * Return the combinators used to control how names are imported or exported.
12537 */
12538 NodeList<Combinator> get combinators => _combinators;
12539
12540 @override
12541 Token get endToken => semicolon;
12542
12543 @override
12544 Token get firstTokenAfterCommentAndMetadata => keyword;
12545
12546 @override
12547 LibraryElement get uriElement;
12548 }
12549
12550 /**
12551 * The "native" clause in an class declaration.
12552 *
12553 * > nativeClause ::=
12554 * > 'native' [StringLiteral]
12555 */
12556 class NativeClause extends AstNode {
12557 /**
12558 * The token representing the 'native' keyword.
12559 */
12560 Token nativeKeyword;
12561
12562 /**
12563 * The name of the native object that implements the class.
12564 */
12565 StringLiteral _name;
12566
12567 /**
12568 * Initialize a newly created native clause.
12569 */
12570 NativeClause(this.nativeKeyword, StringLiteral name) {
12571 _name = _becomeParentOf(name);
12572 }
12573
12574 @override
12575 Token get beginToken => nativeKeyword;
12576
12577 @override
12578 Iterable get childEntities =>
12579 new ChildEntities()..add(nativeKeyword)..add(_name);
12580
12581 @override
12582 Token get endToken => _name.endToken;
12583
12584 /**
12585 * Get the token representing the 'native' keyword.
12586 */
12587 @deprecated // Use "this.nativeKeyword"
12588 Token get keyword => nativeKeyword;
12589
12590 /**
12591 * Set the token representing the 'native' keyword to the given [token].
12592 */
12593 @deprecated // Use "this.nativeKeyword"
12594 set keyword(Token token) {
12595 nativeKeyword = token;
12596 }
12597
12598 /**
12599 * Return the name of the native object that implements the class.
12600 */
12601 StringLiteral get name => _name;
12602
12603 /**
12604 * Set the name of the native object that implements the class to the given
12605 * [name].
12606 */
12607 void set name(StringLiteral name) {
12608 _name = _becomeParentOf(name);
12609 }
12610
12611 @override
12612 accept(AstVisitor visitor) => visitor.visitNativeClause(this);
12613
12614 @override
12615 void visitChildren(AstVisitor visitor) {
12616 _safelyVisitChild(_name, visitor);
12617 }
12618 }
12619
12620 /**
12621 * A function body that consists of a native keyword followed by a string
12622 * literal.
12623 *
12624 * > nativeFunctionBody ::=
12625 * > 'native' [SimpleStringLiteral] ';'
12626 */
12627 class NativeFunctionBody extends FunctionBody {
12628 /**
12629 * The token representing 'native' that marks the start of the function body.
12630 */
12631 Token nativeKeyword;
12632
12633 /**
12634 * The string literal, after the 'native' token.
12635 */
12636 StringLiteral _stringLiteral;
12637
12638 /**
12639 * The token representing the semicolon that marks the end of the function
12640 * body.
12641 */
12642 Token semicolon;
12643
12644 /**
12645 * Initialize a newly created function body consisting of the 'native' token,
12646 * a string literal, and a semicolon.
12647 */
12648 NativeFunctionBody(
12649 this.nativeKeyword, StringLiteral stringLiteral, this.semicolon) {
12650 _stringLiteral = _becomeParentOf(stringLiteral);
12651 }
12652
12653 @override
12654 Token get beginToken => nativeKeyword;
12655
12656 @override
12657 Iterable get childEntities => new ChildEntities()
12658 ..add(nativeKeyword)
12659 ..add(_stringLiteral)
12660 ..add(semicolon);
12661
12662 @override
12663 Token get endToken => semicolon;
12664
12665 /**
12666 * Return the token representing 'native' that marks the start of the function
12667 * body.
12668 */
12669 @deprecated // Use "this.nativeKeyword"
12670 Token get nativeToken => nativeKeyword;
12671
12672 /**
12673 * Set the token representing 'native' that marks the start of the function
12674 * body to the given [token].
12675 */
12676 @deprecated // Use "this.nativeKeyword"
12677 set nativeToken(Token token) {
12678 nativeKeyword = token;
12679 }
12680
12681 /**
12682 * Return the string literal representing the string after the 'native' token.
12683 */
12684 StringLiteral get stringLiteral => _stringLiteral;
12685
12686 /**
12687 * Set the string literal representing the string after the 'native' token to
12688 * the given [stringLiteral].
12689 */
12690 void set stringLiteral(StringLiteral stringLiteral) {
12691 _stringLiteral = _becomeParentOf(stringLiteral);
12692 }
12693
12694 @override
12695 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this);
12696
12697 @override
12698 void visitChildren(AstVisitor visitor) {
12699 _safelyVisitChild(_stringLiteral, visitor);
12700 }
12701 }
12702
12703 /**
12704 * A list of AST nodes that have a common parent.
12705 */
12706 class NodeList<E extends AstNode> extends Object with ListMixin<E> {
12707 /**
12708 * The node that is the parent of each of the elements in the list.
12709 */
12710 AstNode owner;
12711
12712 /**
12713 * The elements contained in the list.
12714 */
12715 List<E> _elements = <E>[];
12716
12717 /**
12718 * Initialize a newly created list of nodes such that all of the nodes that
12719 * are added to the list will have their parent set to the given [owner]. The
12720 * list will initially be populated with the given [elements].
12721 */
12722 NodeList(this.owner, [List<E> elements]) {
12723 addAll(elements);
12724 }
12725
12726 /**
12727 * Return the first token included in this node list's source range, or `null`
12728 * if the list is empty.
12729 */
12730 Token get beginToken {
12731 if (_elements.length == 0) {
12732 return null;
12733 }
12734 return _elements[0].beginToken;
12735 }
12736
12737 /**
12738 * Return the last token included in this node list's source range, or `null`
12739 * if the list is empty.
12740 */
12741 Token get endToken {
12742 int length = _elements.length;
12743 if (length == 0) {
12744 return null;
12745 }
12746 return _elements[length - 1].endToken;
12747 }
12748
12749 int get length => _elements.length;
12750
12751 @deprecated // Never intended for public use.
12752 void set length(int value) {
12753 throw new UnsupportedError("Cannot resize NodeList.");
12754 }
12755
12756 E operator [](int index) {
12757 if (index < 0 || index >= _elements.length) {
12758 throw new RangeError("Index: $index, Size: ${_elements.length}");
12759 }
12760 return _elements[index];
12761 }
12762
12763 void operator []=(int index, E node) {
12764 if (index < 0 || index >= _elements.length) {
12765 throw new RangeError("Index: $index, Size: ${_elements.length}");
12766 }
12767 owner._becomeParentOf(node);
12768 _elements[index] = node;
12769 }
12770
12771 /**
12772 * Use the given [visitor] to visit each of the nodes in this list.
12773 */
12774 accept(AstVisitor visitor) {
12775 int length = _elements.length;
12776 for (var i = 0; i < length; i++) {
12777 _elements[i].accept(visitor);
12778 }
12779 }
12780
12781 @override
12782 void add(E node) {
12783 insert(length, node);
12784 }
12785
12786 @override
12787 bool addAll(Iterable<E> nodes) {
12788 if (nodes != null && !nodes.isEmpty) {
12789 _elements.addAll(nodes);
12790 for (E node in nodes) {
12791 owner._becomeParentOf(node);
12792 }
12793 return true;
12794 }
12795 return false;
12796 }
12797
12798 @override
12799 void clear() {
12800 _elements = <E>[];
12801 }
12802
12803 @override
12804 void insert(int index, E node) {
12805 int length = _elements.length;
12806 if (index < 0 || index > length) {
12807 throw new RangeError("Index: $index, Size: ${_elements.length}");
12808 }
12809 owner._becomeParentOf(node);
12810 if (length == 0) {
12811 _elements.add(node);
12812 } else {
12813 _elements.insert(index, node);
12814 }
12815 }
12816
12817 @override
12818 E removeAt(int index) {
12819 if (index < 0 || index >= _elements.length) {
12820 throw new RangeError("Index: $index, Size: ${_elements.length}");
12821 }
12822 E removedNode = _elements[index];
12823 _elements.removeAt(index);
12824 return removedNode;
12825 }
12826
12827 /**
12828 * Create an empty list with the given [owner].
12829 */
12830 @deprecated // Use "new NodeList<E>(owner)"
12831 static NodeList create(AstNode owner) => new NodeList(owner);
12832 }
12833
12834 /**
12835 * An object used to locate the [AstNode] associated with a source range, given
12836 * the AST structure built from the source. More specifically, they will return
12837 * the [AstNode] with the shortest length whose source range completely
12838 * encompasses the specified range.
12839 */
12840 class NodeLocator extends UnifyingAstVisitor<Object> {
12841 /**
12842 * The start offset of the range used to identify the node.
12843 */
12844 int _startOffset = 0;
12845
12846 /**
12847 * The end offset of the range used to identify the node.
12848 */
12849 int _endOffset = 0;
12850
12851 /**
12852 * The element that was found that corresponds to the given source range, or
12853 * `null` if there is no such element.
12854 */
12855 AstNode _foundNode;
12856
12857 /**
12858 * Initialize a newly created locator to locate an [AstNode] by locating the
12859 * node within an AST structure that corresponds to the given range of
12860 * characters (between the [startOffset] and [endOffset] in the source.
12861 */
12862 NodeLocator(int startOffset, [int endOffset])
12863 : this._startOffset = startOffset,
12864 this._endOffset = endOffset == null ? startOffset : endOffset;
12865
12866 /**
12867 * Initialize a newly created locator to locate an [AstNode] by locating the
12868 * node within an AST structure that corresponds to the given [offset] in the
12869 * source.
12870 */
12871 @deprecated // Use new NodeLocator(offset)
12872 NodeLocator.con1(int offset) : this(offset);
12873
12874 /**
12875 * Initialize a newly created locator to locate an [AstNode] by locating the
12876 * node within an AST structure that corresponds to the given range of
12877 * characters (between the [startOffset] and [endOffset] in the source.
12878 */
12879 @deprecated // Use new NodeLocator(startOffset, endOffset)
12880 NodeLocator.con2(this._startOffset, this._endOffset);
12881
12882 /**
12883 * Return the node that was found that corresponds to the given source range
12884 * or `null` if there is no such node.
12885 */
12886 AstNode get foundNode => _foundNode;
12887
12888 /**
12889 * Search within the given AST [node] for an identifier representing an
12890 * element in the specified source range. Return the element that was found,
12891 * or `null` if no element was found.
12892 */
12893 AstNode searchWithin(AstNode node) {
12894 if (node == null) {
12895 return null;
12896 }
12897 try {
12898 node.accept(this);
12899 } on NodeLocator_NodeFoundException {
12900 // A node with the right source position was found.
12901 } catch (exception, stackTrace) {
12902 AnalysisEngine.instance.logger.logInformation(
12903 "Unable to locate element at offset ($_startOffset - $_endOffset)",
12904 new CaughtException(exception, stackTrace));
12905 return null;
12906 }
12907 return _foundNode;
12908 }
12909
12910 @override
12911 Object visitNode(AstNode node) {
12912 Token beginToken = node.beginToken;
12913 Token endToken = node.endToken;
12914 // Don't include synthetic tokens.
12915 while (endToken != beginToken) {
12916 if (endToken.type == TokenType.EOF || !endToken.isSynthetic) {
12917 break;
12918 }
12919 endToken = endToken.previous;
12920 }
12921 int end = endToken.end;
12922 int start = node.offset;
12923 if (end < _startOffset) {
12924 return null;
12925 }
12926 if (start > _endOffset) {
12927 return null;
12928 }
12929 try {
12930 node.visitChildren(this);
12931 } on NodeLocator_NodeFoundException {
12932 rethrow;
12933 } catch (exception, stackTrace) {
12934 // Ignore the exception and proceed in order to visit the rest of the
12935 // structure.
12936 AnalysisEngine.instance.logger.logInformation(
12937 "Exception caught while traversing an AST structure.",
12938 new CaughtException(exception, stackTrace));
12939 }
12940 if (start <= _startOffset && _endOffset <= end) {
12941 _foundNode = node;
12942 throw new NodeLocator_NodeFoundException();
12943 }
12944 return null;
12945 }
12946 }
12947
12948 /**
12949 * An exception used by [NodeLocator] to cancel visiting after a node has been
12950 * found.
12951 */
12952 class NodeLocator_NodeFoundException extends RuntimeException {}
12953
12954 /**
12955 * An object that will replace one child node in an AST node with another node.
12956 */
12957 class NodeReplacer implements AstVisitor<bool> {
12958 /**
12959 * The node being replaced.
12960 */
12961 final AstNode _oldNode;
12962
12963 /**
12964 * The node that is replacing the old node.
12965 */
12966 final AstNode _newNode;
12967
12968 /**
12969 * Initialize a newly created node locator to replace the [_oldNode] with the
12970 * [_newNode].
12971 */
12972 NodeReplacer(this._oldNode, this._newNode);
12973
12974 @override
12975 bool visitAdjacentStrings(AdjacentStrings node) {
12976 if (_replaceInList(node.strings)) {
12977 return true;
12978 }
12979 return visitNode(node);
12980 }
12981
12982 bool visitAnnotatedNode(AnnotatedNode node) {
12983 if (identical(node.documentationComment, _oldNode)) {
12984 node.documentationComment = _newNode as Comment;
12985 return true;
12986 } else if (_replaceInList(node.metadata)) {
12987 return true;
12988 }
12989 return visitNode(node);
12990 }
12991
12992 @override
12993 bool visitAnnotation(Annotation node) {
12994 if (identical(node.arguments, _oldNode)) {
12995 node.arguments = _newNode as ArgumentList;
12996 return true;
12997 } else if (identical(node.constructorName, _oldNode)) {
12998 node.constructorName = _newNode as SimpleIdentifier;
12999 return true;
13000 } else if (identical(node.name, _oldNode)) {
13001 node.name = _newNode as Identifier;
13002 return true;
13003 }
13004 return visitNode(node);
13005 }
13006
13007 @override
13008 bool visitArgumentList(ArgumentList node) {
13009 if (_replaceInList(node.arguments)) {
13010 return true;
13011 }
13012 return visitNode(node);
13013 }
13014
13015 @override
13016 bool visitAsExpression(AsExpression node) {
13017 if (identical(node.expression, _oldNode)) {
13018 node.expression = _newNode as Expression;
13019 return true;
13020 } else if (identical(node.type, _oldNode)) {
13021 node.type = _newNode as TypeName;
13022 return true;
13023 }
13024 return visitNode(node);
13025 }
13026
13027 @override
13028 bool visitAssertStatement(AssertStatement node) {
13029 if (identical(node.condition, _oldNode)) {
13030 node.condition = _newNode as Expression;
13031 return true;
13032 }
13033 return visitNode(node);
13034 }
13035
13036 @override
13037 bool visitAssignmentExpression(AssignmentExpression node) {
13038 if (identical(node.leftHandSide, _oldNode)) {
13039 node.leftHandSide = _newNode as Expression;
13040 return true;
13041 } else if (identical(node.rightHandSide, _oldNode)) {
13042 node.rightHandSide = _newNode as Expression;
13043 return true;
13044 }
13045 return visitNode(node);
13046 }
13047
13048 @override
13049 bool visitAwaitExpression(AwaitExpression node) {
13050 if (identical(node.expression, _oldNode)) {
13051 node.expression = _newNode as Expression;
13052 return true;
13053 }
13054 return visitNode(node);
13055 }
13056
13057 @override
13058 bool visitBinaryExpression(BinaryExpression node) {
13059 if (identical(node.leftOperand, _oldNode)) {
13060 node.leftOperand = _newNode as Expression;
13061 return true;
13062 } else if (identical(node.rightOperand, _oldNode)) {
13063 node.rightOperand = _newNode as Expression;
13064 return true;
13065 }
13066 return visitNode(node);
13067 }
13068
13069 @override
13070 bool visitBlock(Block node) {
13071 if (_replaceInList(node.statements)) {
13072 return true;
13073 }
13074 return visitNode(node);
13075 }
13076
13077 @override
13078 bool visitBlockFunctionBody(BlockFunctionBody node) {
13079 if (identical(node.block, _oldNode)) {
13080 node.block = _newNode as Block;
13081 return true;
13082 }
13083 return visitNode(node);
13084 }
13085
13086 @override
13087 bool visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
13088
13089 @override
13090 bool visitBreakStatement(BreakStatement node) {
13091 if (identical(node.label, _oldNode)) {
13092 node.label = _newNode as SimpleIdentifier;
13093 return true;
13094 }
13095 return visitNode(node);
13096 }
13097
13098 @override
13099 bool visitCascadeExpression(CascadeExpression node) {
13100 if (identical(node.target, _oldNode)) {
13101 node.target = _newNode as Expression;
13102 return true;
13103 } else if (_replaceInList(node.cascadeSections)) {
13104 return true;
13105 }
13106 return visitNode(node);
13107 }
13108
13109 @override
13110 bool visitCatchClause(CatchClause node) {
13111 if (identical(node.exceptionType, _oldNode)) {
13112 node.exceptionType = _newNode as TypeName;
13113 return true;
13114 } else if (identical(node.exceptionParameter, _oldNode)) {
13115 node.exceptionParameter = _newNode as SimpleIdentifier;
13116 return true;
13117 } else if (identical(node.stackTraceParameter, _oldNode)) {
13118 node.stackTraceParameter = _newNode as SimpleIdentifier;
13119 return true;
13120 }
13121 return visitNode(node);
13122 }
13123
13124 @override
13125 bool visitClassDeclaration(ClassDeclaration node) {
13126 if (identical(node.name, _oldNode)) {
13127 node.name = _newNode as SimpleIdentifier;
13128 return true;
13129 } else if (identical(node.typeParameters, _oldNode)) {
13130 node.typeParameters = _newNode as TypeParameterList;
13131 return true;
13132 } else if (identical(node.extendsClause, _oldNode)) {
13133 node.extendsClause = _newNode as ExtendsClause;
13134 return true;
13135 } else if (identical(node.withClause, _oldNode)) {
13136 node.withClause = _newNode as WithClause;
13137 return true;
13138 } else if (identical(node.implementsClause, _oldNode)) {
13139 node.implementsClause = _newNode as ImplementsClause;
13140 return true;
13141 } else if (identical(node.nativeClause, _oldNode)) {
13142 node.nativeClause = _newNode as NativeClause;
13143 return true;
13144 } else if (_replaceInList(node.members)) {
13145 return true;
13146 }
13147 return visitAnnotatedNode(node);
13148 }
13149
13150 @override
13151 bool visitClassTypeAlias(ClassTypeAlias node) {
13152 if (identical(node.name, _oldNode)) {
13153 node.name = _newNode as SimpleIdentifier;
13154 return true;
13155 } else if (identical(node.typeParameters, _oldNode)) {
13156 node.typeParameters = _newNode as TypeParameterList;
13157 return true;
13158 } else if (identical(node.superclass, _oldNode)) {
13159 node.superclass = _newNode as TypeName;
13160 return true;
13161 } else if (identical(node.withClause, _oldNode)) {
13162 node.withClause = _newNode as WithClause;
13163 return true;
13164 } else if (identical(node.implementsClause, _oldNode)) {
13165 node.implementsClause = _newNode as ImplementsClause;
13166 return true;
13167 }
13168 return visitAnnotatedNode(node);
13169 }
13170
13171 @override
13172 bool visitComment(Comment node) {
13173 if (_replaceInList(node.references)) {
13174 return true;
13175 }
13176 return visitNode(node);
13177 }
13178
13179 @override
13180 bool visitCommentReference(CommentReference node) {
13181 if (identical(node.identifier, _oldNode)) {
13182 node.identifier = _newNode as Identifier;
13183 return true;
13184 }
13185 return visitNode(node);
13186 }
13187
13188 @override
13189 bool visitCompilationUnit(CompilationUnit node) {
13190 if (identical(node.scriptTag, _oldNode)) {
13191 node.scriptTag = _newNode as ScriptTag;
13192 return true;
13193 } else if (_replaceInList(node.directives)) {
13194 return true;
13195 } else if (_replaceInList(node.declarations)) {
13196 return true;
13197 }
13198 return visitNode(node);
13199 }
13200
13201 @override
13202 bool visitConditionalExpression(ConditionalExpression node) {
13203 if (identical(node.condition, _oldNode)) {
13204 node.condition = _newNode as Expression;
13205 return true;
13206 } else if (identical(node.thenExpression, _oldNode)) {
13207 node.thenExpression = _newNode as Expression;
13208 return true;
13209 } else if (identical(node.elseExpression, _oldNode)) {
13210 node.elseExpression = _newNode as Expression;
13211 return true;
13212 }
13213 return visitNode(node);
13214 }
13215
13216 @override
13217 bool visitConstructorDeclaration(ConstructorDeclaration node) {
13218 if (identical(node.returnType, _oldNode)) {
13219 node.returnType = _newNode as Identifier;
13220 return true;
13221 } else if (identical(node.name, _oldNode)) {
13222 node.name = _newNode as SimpleIdentifier;
13223 return true;
13224 } else if (identical(node.parameters, _oldNode)) {
13225 node.parameters = _newNode as FormalParameterList;
13226 return true;
13227 } else if (identical(node.redirectedConstructor, _oldNode)) {
13228 node.redirectedConstructor = _newNode as ConstructorName;
13229 return true;
13230 } else if (identical(node.body, _oldNode)) {
13231 node.body = _newNode as FunctionBody;
13232 return true;
13233 } else if (_replaceInList(node.initializers)) {
13234 return true;
13235 }
13236 return visitAnnotatedNode(node);
13237 }
13238
13239 @override
13240 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
13241 if (identical(node.fieldName, _oldNode)) {
13242 node.fieldName = _newNode as SimpleIdentifier;
13243 return true;
13244 } else if (identical(node.expression, _oldNode)) {
13245 node.expression = _newNode as Expression;
13246 return true;
13247 }
13248 return visitNode(node);
13249 }
13250
13251 @override
13252 bool visitConstructorName(ConstructorName node) {
13253 if (identical(node.type, _oldNode)) {
13254 node.type = _newNode as TypeName;
13255 return true;
13256 } else if (identical(node.name, _oldNode)) {
13257 node.name = _newNode as SimpleIdentifier;
13258 return true;
13259 }
13260 return visitNode(node);
13261 }
13262
13263 @override
13264 bool visitContinueStatement(ContinueStatement node) {
13265 if (identical(node.label, _oldNode)) {
13266 node.label = _newNode as SimpleIdentifier;
13267 return true;
13268 }
13269 return visitNode(node);
13270 }
13271
13272 @override
13273 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
13274 if (identical(node.type, _oldNode)) {
13275 node.type = _newNode as TypeName;
13276 return true;
13277 } else if (identical(node.identifier, _oldNode)) {
13278 node.identifier = _newNode as SimpleIdentifier;
13279 return true;
13280 }
13281 return visitAnnotatedNode(node);
13282 }
13283
13284 @override
13285 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
13286 if (identical(node.parameter, _oldNode)) {
13287 node.parameter = _newNode as NormalFormalParameter;
13288 return true;
13289 } else if (identical(node.defaultValue, _oldNode)) {
13290 node.defaultValue = _newNode as Expression;
13291 return true;
13292 }
13293 return visitNode(node);
13294 }
13295
13296 @override
13297 bool visitDoStatement(DoStatement node) {
13298 if (identical(node.body, _oldNode)) {
13299 node.body = _newNode as Statement;
13300 return true;
13301 } else if (identical(node.condition, _oldNode)) {
13302 node.condition = _newNode as Expression;
13303 return true;
13304 }
13305 return visitNode(node);
13306 }
13307
13308 @override
13309 bool visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
13310
13311 @override
13312 bool visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
13313
13314 @override
13315 bool visitEmptyStatement(EmptyStatement node) => visitNode(node);
13316
13317 @override
13318 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
13319 if (identical(node.name, _oldNode)) {
13320 node.name = _newNode as SimpleIdentifier;
13321 return true;
13322 }
13323 return visitAnnotatedNode(node);
13324 }
13325
13326 @override
13327 bool visitEnumDeclaration(EnumDeclaration node) {
13328 if (identical(node.name, _oldNode)) {
13329 node.name = _newNode as SimpleIdentifier;
13330 return true;
13331 } else if (_replaceInList(node.constants)) {
13332 return true;
13333 }
13334 return visitAnnotatedNode(node);
13335 }
13336
13337 @override
13338 bool visitExportDirective(ExportDirective node) =>
13339 visitNamespaceDirective(node);
13340
13341 @override
13342 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
13343 if (identical(node.expression, _oldNode)) {
13344 node.expression = _newNode as Expression;
13345 return true;
13346 }
13347 return visitNode(node);
13348 }
13349
13350 @override
13351 bool visitExpressionStatement(ExpressionStatement node) {
13352 if (identical(node.expression, _oldNode)) {
13353 node.expression = _newNode as Expression;
13354 return true;
13355 }
13356 return visitNode(node);
13357 }
13358
13359 @override
13360 bool visitExtendsClause(ExtendsClause node) {
13361 if (identical(node.superclass, _oldNode)) {
13362 node.superclass = _newNode as TypeName;
13363 return true;
13364 }
13365 return visitNode(node);
13366 }
13367
13368 @override
13369 bool visitFieldDeclaration(FieldDeclaration node) {
13370 if (identical(node.fields, _oldNode)) {
13371 node.fields = _newNode as VariableDeclarationList;
13372 return true;
13373 }
13374 return visitAnnotatedNode(node);
13375 }
13376
13377 @override
13378 bool visitFieldFormalParameter(FieldFormalParameter node) {
13379 if (identical(node.type, _oldNode)) {
13380 node.type = _newNode as TypeName;
13381 return true;
13382 } else if (identical(node.parameters, _oldNode)) {
13383 node.parameters = _newNode as FormalParameterList;
13384 return true;
13385 }
13386 return visitNormalFormalParameter(node);
13387 }
13388
13389 @override
13390 bool visitForEachStatement(ForEachStatement node) {
13391 if (identical(node.loopVariable, _oldNode)) {
13392 node.loopVariable = _newNode as DeclaredIdentifier;
13393 return true;
13394 } else if (identical(node.identifier, _oldNode)) {
13395 node.identifier = _newNode as SimpleIdentifier;
13396 return true;
13397 } else if (identical(node.iterable, _oldNode)) {
13398 node.iterable = _newNode as Expression;
13399 return true;
13400 } else if (identical(node.body, _oldNode)) {
13401 node.body = _newNode as Statement;
13402 return true;
13403 }
13404 return visitNode(node);
13405 }
13406
13407 @override
13408 bool visitFormalParameterList(FormalParameterList node) {
13409 if (_replaceInList(node.parameters)) {
13410 return true;
13411 }
13412 return visitNode(node);
13413 }
13414
13415 @override
13416 bool visitForStatement(ForStatement node) {
13417 if (identical(node.variables, _oldNode)) {
13418 node.variables = _newNode as VariableDeclarationList;
13419 return true;
13420 } else if (identical(node.initialization, _oldNode)) {
13421 node.initialization = _newNode as Expression;
13422 return true;
13423 } else if (identical(node.condition, _oldNode)) {
13424 node.condition = _newNode as Expression;
13425 return true;
13426 } else if (identical(node.body, _oldNode)) {
13427 node.body = _newNode as Statement;
13428 return true;
13429 } else if (_replaceInList(node.updaters)) {
13430 return true;
13431 }
13432 return visitNode(node);
13433 }
13434
13435 @override
13436 bool visitFunctionDeclaration(FunctionDeclaration node) {
13437 if (identical(node.returnType, _oldNode)) {
13438 node.returnType = _newNode as TypeName;
13439 return true;
13440 } else if (identical(node.name, _oldNode)) {
13441 node.name = _newNode as SimpleIdentifier;
13442 return true;
13443 } else if (identical(node.functionExpression, _oldNode)) {
13444 node.functionExpression = _newNode as FunctionExpression;
13445 return true;
13446 }
13447 return visitAnnotatedNode(node);
13448 }
13449
13450 @override
13451 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
13452 if (identical(node.functionDeclaration, _oldNode)) {
13453 node.functionDeclaration = _newNode as FunctionDeclaration;
13454 return true;
13455 }
13456 return visitNode(node);
13457 }
13458
13459 @override
13460 bool visitFunctionExpression(FunctionExpression node) {
13461 if (identical(node.parameters, _oldNode)) {
13462 node.parameters = _newNode as FormalParameterList;
13463 return true;
13464 } else if (identical(node.body, _oldNode)) {
13465 node.body = _newNode as FunctionBody;
13466 return true;
13467 }
13468 return visitNode(node);
13469 }
13470
13471 @override
13472 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
13473 if (identical(node.function, _oldNode)) {
13474 node.function = _newNode as Expression;
13475 return true;
13476 } else if (identical(node.argumentList, _oldNode)) {
13477 node.argumentList = _newNode as ArgumentList;
13478 return true;
13479 }
13480 return visitNode(node);
13481 }
13482
13483 @override
13484 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
13485 if (identical(node.returnType, _oldNode)) {
13486 node.returnType = _newNode as TypeName;
13487 return true;
13488 } else if (identical(node.name, _oldNode)) {
13489 node.name = _newNode as SimpleIdentifier;
13490 return true;
13491 } else if (identical(node.typeParameters, _oldNode)) {
13492 node.typeParameters = _newNode as TypeParameterList;
13493 return true;
13494 } else if (identical(node.parameters, _oldNode)) {
13495 node.parameters = _newNode as FormalParameterList;
13496 return true;
13497 }
13498 return visitAnnotatedNode(node);
13499 }
13500
13501 @override
13502 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
13503 if (identical(node.returnType, _oldNode)) {
13504 node.returnType = _newNode as TypeName;
13505 return true;
13506 } else if (identical(node.parameters, _oldNode)) {
13507 node.parameters = _newNode as FormalParameterList;
13508 return true;
13509 }
13510 return visitNormalFormalParameter(node);
13511 }
13512
13513 @override
13514 bool visitHideCombinator(HideCombinator node) {
13515 if (_replaceInList(node.hiddenNames)) {
13516 return true;
13517 }
13518 return visitNode(node);
13519 }
13520
13521 @override
13522 bool visitIfStatement(IfStatement node) {
13523 if (identical(node.condition, _oldNode)) {
13524 node.condition = _newNode as Expression;
13525 return true;
13526 } else if (identical(node.thenStatement, _oldNode)) {
13527 node.thenStatement = _newNode as Statement;
13528 return true;
13529 } else if (identical(node.elseStatement, _oldNode)) {
13530 node.elseStatement = _newNode as Statement;
13531 return true;
13532 }
13533 return visitNode(node);
13534 }
13535
13536 @override
13537 bool visitImplementsClause(ImplementsClause node) {
13538 if (_replaceInList(node.interfaces)) {
13539 return true;
13540 }
13541 return visitNode(node);
13542 }
13543
13544 @override
13545 bool visitImportDirective(ImportDirective node) {
13546 if (identical(node.prefix, _oldNode)) {
13547 node.prefix = _newNode as SimpleIdentifier;
13548 return true;
13549 }
13550 return visitNamespaceDirective(node);
13551 }
13552
13553 @override
13554 bool visitIndexExpression(IndexExpression node) {
13555 if (identical(node.target, _oldNode)) {
13556 node.target = _newNode as Expression;
13557 return true;
13558 } else if (identical(node.index, _oldNode)) {
13559 node.index = _newNode as Expression;
13560 return true;
13561 }
13562 return visitNode(node);
13563 }
13564
13565 @override
13566 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
13567 if (identical(node.constructorName, _oldNode)) {
13568 node.constructorName = _newNode as ConstructorName;
13569 return true;
13570 } else if (identical(node.argumentList, _oldNode)) {
13571 node.argumentList = _newNode as ArgumentList;
13572 return true;
13573 }
13574 return visitNode(node);
13575 }
13576
13577 @override
13578 bool visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
13579
13580 @override
13581 bool visitInterpolationExpression(InterpolationExpression node) {
13582 if (identical(node.expression, _oldNode)) {
13583 node.expression = _newNode as Expression;
13584 return true;
13585 }
13586 return visitNode(node);
13587 }
13588
13589 @override
13590 bool visitInterpolationString(InterpolationString node) => visitNode(node);
13591
13592 @override
13593 bool visitIsExpression(IsExpression node) {
13594 if (identical(node.expression, _oldNode)) {
13595 node.expression = _newNode as Expression;
13596 return true;
13597 } else if (identical(node.type, _oldNode)) {
13598 node.type = _newNode as TypeName;
13599 return true;
13600 }
13601 return visitNode(node);
13602 }
13603
13604 @override
13605 bool visitLabel(Label node) {
13606 if (identical(node.label, _oldNode)) {
13607 node.label = _newNode as SimpleIdentifier;
13608 return true;
13609 }
13610 return visitNode(node);
13611 }
13612
13613 @override
13614 bool visitLabeledStatement(LabeledStatement node) {
13615 if (identical(node.statement, _oldNode)) {
13616 node.statement = _newNode as Statement;
13617 return true;
13618 } else if (_replaceInList(node.labels)) {
13619 return true;
13620 }
13621 return visitNode(node);
13622 }
13623
13624 @override
13625 bool visitLibraryDirective(LibraryDirective node) {
13626 if (identical(node.name, _oldNode)) {
13627 node.name = _newNode as LibraryIdentifier;
13628 return true;
13629 }
13630 return visitAnnotatedNode(node);
13631 }
13632
13633 @override
13634 bool visitLibraryIdentifier(LibraryIdentifier node) {
13635 if (_replaceInList(node.components)) {
13636 return true;
13637 }
13638 return visitNode(node);
13639 }
13640
13641 @override
13642 bool visitListLiteral(ListLiteral node) {
13643 if (_replaceInList(node.elements)) {
13644 return true;
13645 }
13646 return visitTypedLiteral(node);
13647 }
13648
13649 @override
13650 bool visitMapLiteral(MapLiteral node) {
13651 if (_replaceInList(node.entries)) {
13652 return true;
13653 }
13654 return visitTypedLiteral(node);
13655 }
13656
13657 @override
13658 bool visitMapLiteralEntry(MapLiteralEntry node) {
13659 if (identical(node.key, _oldNode)) {
13660 node.key = _newNode as Expression;
13661 return true;
13662 } else if (identical(node.value, _oldNode)) {
13663 node.value = _newNode as Expression;
13664 return true;
13665 }
13666 return visitNode(node);
13667 }
13668
13669 @override
13670 bool visitMethodDeclaration(MethodDeclaration node) {
13671 if (identical(node.returnType, _oldNode)) {
13672 node.returnType = _newNode as TypeName;
13673 return true;
13674 } else if (identical(node.name, _oldNode)) {
13675 node.name = _newNode as SimpleIdentifier;
13676 return true;
13677 } else if (identical(node.parameters, _oldNode)) {
13678 node.parameters = _newNode as FormalParameterList;
13679 return true;
13680 } else if (identical(node.body, _oldNode)) {
13681 node.body = _newNode as FunctionBody;
13682 return true;
13683 }
13684 return visitAnnotatedNode(node);
13685 }
13686
13687 @override
13688 bool visitMethodInvocation(MethodInvocation node) {
13689 if (identical(node.target, _oldNode)) {
13690 node.target = _newNode as Expression;
13691 return true;
13692 } else if (identical(node.methodName, _oldNode)) {
13693 node.methodName = _newNode as SimpleIdentifier;
13694 return true;
13695 } else if (identical(node.argumentList, _oldNode)) {
13696 node.argumentList = _newNode as ArgumentList;
13697 return true;
13698 }
13699 return visitNode(node);
13700 }
13701
13702 @override
13703 bool visitNamedExpression(NamedExpression node) {
13704 if (identical(node.name, _oldNode)) {
13705 node.name = _newNode as Label;
13706 return true;
13707 } else if (identical(node.expression, _oldNode)) {
13708 node.expression = _newNode as Expression;
13709 return true;
13710 }
13711 return visitNode(node);
13712 }
13713
13714 bool visitNamespaceDirective(NamespaceDirective node) {
13715 if (_replaceInList(node.combinators)) {
13716 return true;
13717 }
13718 return visitUriBasedDirective(node);
13719 }
13720
13721 @override
13722 bool visitNativeClause(NativeClause node) {
13723 if (identical(node.name, _oldNode)) {
13724 node.name = _newNode as StringLiteral;
13725 return true;
13726 }
13727 return visitNode(node);
13728 }
13729
13730 @override
13731 bool visitNativeFunctionBody(NativeFunctionBody node) {
13732 if (identical(node.stringLiteral, _oldNode)) {
13733 node.stringLiteral = _newNode as StringLiteral;
13734 return true;
13735 }
13736 return visitNode(node);
13737 }
13738
13739 bool visitNode(AstNode node) {
13740 throw new IllegalArgumentException(
13741 "The old node is not a child of it's parent");
13742 }
13743
13744 bool visitNormalFormalParameter(NormalFormalParameter node) {
13745 if (identical(node.documentationComment, _oldNode)) {
13746 node.documentationComment = _newNode as Comment;
13747 return true;
13748 } else if (identical(node.identifier, _oldNode)) {
13749 node.identifier = _newNode as SimpleIdentifier;
13750 return true;
13751 } else if (_replaceInList(node.metadata)) {
13752 return true;
13753 }
13754 return visitNode(node);
13755 }
13756
13757 @override
13758 bool visitNullLiteral(NullLiteral node) => visitNode(node);
13759
13760 @override
13761 bool visitParenthesizedExpression(ParenthesizedExpression node) {
13762 if (identical(node.expression, _oldNode)) {
13763 node.expression = _newNode as Expression;
13764 return true;
13765 }
13766 return visitNode(node);
13767 }
13768
13769 @override
13770 bool visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
13771
13772 @override
13773 bool visitPartOfDirective(PartOfDirective node) {
13774 if (identical(node.libraryName, _oldNode)) {
13775 node.libraryName = _newNode as LibraryIdentifier;
13776 return true;
13777 }
13778 return visitAnnotatedNode(node);
13779 }
13780
13781 @override
13782 bool visitPostfixExpression(PostfixExpression node) {
13783 if (identical(node.operand, _oldNode)) {
13784 node.operand = _newNode as Expression;
13785 return true;
13786 }
13787 return visitNode(node);
13788 }
13789
13790 @override
13791 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
13792 if (identical(node.prefix, _oldNode)) {
13793 node.prefix = _newNode as SimpleIdentifier;
13794 return true;
13795 } else if (identical(node.identifier, _oldNode)) {
13796 node.identifier = _newNode as SimpleIdentifier;
13797 return true;
13798 }
13799 return visitNode(node);
13800 }
13801
13802 @override
13803 bool visitPrefixExpression(PrefixExpression node) {
13804 if (identical(node.operand, _oldNode)) {
13805 node.operand = _newNode as Expression;
13806 return true;
13807 }
13808 return visitNode(node);
13809 }
13810
13811 @override
13812 bool visitPropertyAccess(PropertyAccess node) {
13813 if (identical(node.target, _oldNode)) {
13814 node.target = _newNode as Expression;
13815 return true;
13816 } else if (identical(node.propertyName, _oldNode)) {
13817 node.propertyName = _newNode as SimpleIdentifier;
13818 return true;
13819 }
13820 return visitNode(node);
13821 }
13822
13823 @override
13824 bool visitRedirectingConstructorInvocation(
13825 RedirectingConstructorInvocation node) {
13826 if (identical(node.constructorName, _oldNode)) {
13827 node.constructorName = _newNode as SimpleIdentifier;
13828 return true;
13829 } else if (identical(node.argumentList, _oldNode)) {
13830 node.argumentList = _newNode as ArgumentList;
13831 return true;
13832 }
13833 return visitNode(node);
13834 }
13835
13836 @override
13837 bool visitRethrowExpression(RethrowExpression node) => visitNode(node);
13838
13839 @override
13840 bool visitReturnStatement(ReturnStatement node) {
13841 if (identical(node.expression, _oldNode)) {
13842 node.expression = _newNode as Expression;
13843 return true;
13844 }
13845 return visitNode(node);
13846 }
13847
13848 @override
13849 bool visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
13850
13851 @override
13852 bool visitShowCombinator(ShowCombinator node) {
13853 if (_replaceInList(node.shownNames)) {
13854 return true;
13855 }
13856 return visitNode(node);
13857 }
13858
13859 @override
13860 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
13861 if (identical(node.type, _oldNode)) {
13862 node.type = _newNode as TypeName;
13863 return true;
13864 }
13865 return visitNormalFormalParameter(node);
13866 }
13867
13868 @override
13869 bool visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
13870
13871 @override
13872 bool visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
13873
13874 @override
13875 bool visitStringInterpolation(StringInterpolation node) {
13876 if (_replaceInList(node.elements)) {
13877 return true;
13878 }
13879 return visitNode(node);
13880 }
13881
13882 @override
13883 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
13884 if (identical(node.constructorName, _oldNode)) {
13885 node.constructorName = _newNode as SimpleIdentifier;
13886 return true;
13887 } else if (identical(node.argumentList, _oldNode)) {
13888 node.argumentList = _newNode as ArgumentList;
13889 return true;
13890 }
13891 return visitNode(node);
13892 }
13893
13894 @override
13895 bool visitSuperExpression(SuperExpression node) => visitNode(node);
13896
13897 @override
13898 bool visitSwitchCase(SwitchCase node) {
13899 if (identical(node.expression, _oldNode)) {
13900 node.expression = _newNode as Expression;
13901 return true;
13902 }
13903 return visitSwitchMember(node);
13904 }
13905
13906 @override
13907 bool visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
13908
13909 bool visitSwitchMember(SwitchMember node) {
13910 if (_replaceInList(node.labels)) {
13911 return true;
13912 } else if (_replaceInList(node.statements)) {
13913 return true;
13914 }
13915 return visitNode(node);
13916 }
13917
13918 @override
13919 bool visitSwitchStatement(SwitchStatement node) {
13920 if (identical(node.expression, _oldNode)) {
13921 node.expression = _newNode as Expression;
13922 return true;
13923 } else if (_replaceInList(node.members)) {
13924 return true;
13925 }
13926 return visitNode(node);
13927 }
13928
13929 @override
13930 bool visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
13931
13932 @override
13933 bool visitThisExpression(ThisExpression node) => visitNode(node);
13934
13935 @override
13936 bool visitThrowExpression(ThrowExpression node) {
13937 if (identical(node.expression, _oldNode)) {
13938 node.expression = _newNode as Expression;
13939 return true;
13940 }
13941 return visitNode(node);
13942 }
13943
13944 @override
13945 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
13946 if (identical(node.variables, _oldNode)) {
13947 node.variables = _newNode as VariableDeclarationList;
13948 return true;
13949 }
13950 return visitAnnotatedNode(node);
13951 }
13952
13953 @override
13954 bool visitTryStatement(TryStatement node) {
13955 if (identical(node.body, _oldNode)) {
13956 node.body = _newNode as Block;
13957 return true;
13958 } else if (identical(node.finallyBlock, _oldNode)) {
13959 node.finallyBlock = _newNode as Block;
13960 return true;
13961 } else if (_replaceInList(node.catchClauses)) {
13962 return true;
13963 }
13964 return visitNode(node);
13965 }
13966
13967 @override
13968 bool visitTypeArgumentList(TypeArgumentList node) {
13969 if (_replaceInList(node.arguments)) {
13970 return true;
13971 }
13972 return visitNode(node);
13973 }
13974
13975 bool visitTypedLiteral(TypedLiteral node) {
13976 if (identical(node.typeArguments, _oldNode)) {
13977 node.typeArguments = _newNode as TypeArgumentList;
13978 return true;
13979 }
13980 return visitNode(node);
13981 }
13982
13983 @override
13984 bool visitTypeName(TypeName node) {
13985 if (identical(node.name, _oldNode)) {
13986 node.name = _newNode as Identifier;
13987 return true;
13988 } else if (identical(node.typeArguments, _oldNode)) {
13989 node.typeArguments = _newNode as TypeArgumentList;
13990 return true;
13991 }
13992 return visitNode(node);
13993 }
13994
13995 @override
13996 bool visitTypeParameter(TypeParameter node) {
13997 if (identical(node.name, _oldNode)) {
13998 node.name = _newNode as SimpleIdentifier;
13999 return true;
14000 } else if (identical(node.bound, _oldNode)) {
14001 node.bound = _newNode as TypeName;
14002 return true;
14003 }
14004 return visitNode(node);
14005 }
14006
14007 @override
14008 bool visitTypeParameterList(TypeParameterList node) {
14009 if (_replaceInList(node.typeParameters)) {
14010 return true;
14011 }
14012 return visitNode(node);
14013 }
14014
14015 bool visitUriBasedDirective(UriBasedDirective node) {
14016 if (identical(node.uri, _oldNode)) {
14017 node.uri = _newNode as StringLiteral;
14018 return true;
14019 }
14020 return visitAnnotatedNode(node);
14021 }
14022
14023 @override
14024 bool visitVariableDeclaration(VariableDeclaration node) {
14025 if (identical(node.name, _oldNode)) {
14026 node.name = _newNode as SimpleIdentifier;
14027 return true;
14028 } else if (identical(node.initializer, _oldNode)) {
14029 node.initializer = _newNode as Expression;
14030 return true;
14031 }
14032 return visitAnnotatedNode(node);
14033 }
14034
14035 @override
14036 bool visitVariableDeclarationList(VariableDeclarationList node) {
14037 if (identical(node.type, _oldNode)) {
14038 node.type = _newNode as TypeName;
14039 return true;
14040 } else if (_replaceInList(node.variables)) {
14041 return true;
14042 }
14043 return visitNode(node);
14044 }
14045
14046 @override
14047 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
14048 if (identical(node.variables, _oldNode)) {
14049 node.variables = _newNode as VariableDeclarationList;
14050 return true;
14051 }
14052 return visitNode(node);
14053 }
14054
14055 @override
14056 bool visitWhileStatement(WhileStatement node) {
14057 if (identical(node.condition, _oldNode)) {
14058 node.condition = _newNode as Expression;
14059 return true;
14060 } else if (identical(node.body, _oldNode)) {
14061 node.body = _newNode as Statement;
14062 return true;
14063 }
14064 return visitNode(node);
14065 }
14066
14067 @override
14068 bool visitWithClause(WithClause node) {
14069 if (_replaceInList(node.mixinTypes)) {
14070 return true;
14071 }
14072 return visitNode(node);
14073 }
14074
14075 @override
14076 bool visitYieldStatement(YieldStatement node) {
14077 if (identical(node.expression, _oldNode)) {
14078 node.expression = _newNode as Expression;
14079 return true;
14080 }
14081 return visitNode(node);
14082 }
14083
14084 bool _replaceInList(NodeList list) {
14085 int count = list.length;
14086 for (int i = 0; i < count; i++) {
14087 if (identical(_oldNode, list[i])) {
14088 list[i] = _newNode;
14089 return true;
14090 }
14091 }
14092 return false;
14093 }
14094
14095 /**
14096 * Replace the [oldNode] with the [newNode] in the AST structure containing
14097 * the old node. Return `true` if the replacement was successful.
14098 *
14099 * Throws an [IllegalArgumentException] if either node is `null`, if the old
14100 * node does not have a parent node, or if the AST structure has been
14101 * corrupted.
14102 */
14103 static bool replace(AstNode oldNode, AstNode newNode) {
14104 if (oldNode == null || newNode == null) {
14105 throw new IllegalArgumentException(
14106 "The old and new nodes must be non-null");
14107 } else if (identical(oldNode, newNode)) {
14108 return true;
14109 }
14110 AstNode parent = oldNode.parent;
14111 if (parent == null) {
14112 throw new IllegalArgumentException(
14113 "The old node is not a child of another node");
14114 }
14115 NodeReplacer replacer = new NodeReplacer(oldNode, newNode);
14116 return parent.accept(replacer);
14117 }
14118 }
14119
14120 /**
14121 * A formal parameter that is required (is not optional).
14122 *
14123 * > normalFormalParameter ::=
14124 * > [FunctionTypedFormalParameter]
14125 * > | [FieldFormalParameter]
14126 * > | [SimpleFormalParameter]
14127 */
14128 abstract class NormalFormalParameter extends FormalParameter {
14129 /**
14130 * The documentation comment associated with this parameter, or `null` if this
14131 * parameter does not have a documentation comment associated with it.
14132 */
14133 Comment _comment;
14134
14135 /**
14136 * The annotations associated with this parameter.
14137 */
14138 NodeList<Annotation> _metadata;
14139
14140 /**
14141 * The name of the parameter being declared.
14142 */
14143 SimpleIdentifier _identifier;
14144
14145 /**
14146 * Initialize a newly created formal parameter. Either or both of the
14147 * [comment] and [metadata] can be `null` if the parameter does not have the
14148 * corresponding attribute.
14149 */
14150 NormalFormalParameter(
14151 Comment comment, List<Annotation> metadata, SimpleIdentifier identifier) {
14152 _comment = _becomeParentOf(comment);
14153 _metadata = new NodeList<Annotation>(this, metadata);
14154 _identifier = _becomeParentOf(identifier);
14155 }
14156
14157 /**
14158 * Return the documentation comment associated with this parameter, or `null`
14159 * if this parameter does not have a documentation comment associated with it.
14160 */
14161 Comment get documentationComment => _comment;
14162
14163 /**
14164 * Set the documentation comment associated with this parameter to the given
14165 * [comment].
14166 */
14167 void set documentationComment(Comment comment) {
14168 _comment = _becomeParentOf(comment);
14169 }
14170
14171 @override
14172 SimpleIdentifier get identifier => _identifier;
14173
14174 /**
14175 * Set the name of the parameter being declared to the given [identifier].
14176 */
14177 void set identifier(SimpleIdentifier identifier) {
14178 _identifier = _becomeParentOf(identifier);
14179 }
14180
14181 @override
14182 ParameterKind get kind {
14183 AstNode parent = this.parent;
14184 if (parent is DefaultFormalParameter) {
14185 return parent.kind;
14186 }
14187 return ParameterKind.REQUIRED;
14188 }
14189
14190 @override
14191 NodeList<Annotation> get metadata => _metadata;
14192
14193 /**
14194 * Set the metadata associated with this node to the given [metadata].
14195 */
14196 void set metadata(List<Annotation> metadata) {
14197 _metadata.clear();
14198 _metadata.addAll(metadata);
14199 }
14200
14201 /**
14202 * Return a list containing the comment and annotations associated with this
14203 * parameter, sorted in lexical order.
14204 */
14205 List<AstNode> get sortedCommentAndAnnotations {
14206 return <AstNode>[]
14207 ..add(_comment)
14208 ..addAll(_metadata)
14209 ..sort(AstNode.LEXICAL_ORDER);
14210 }
14211
14212 ChildEntities get _childEntities {
14213 ChildEntities result = new ChildEntities();
14214 if (_commentIsBeforeAnnotations()) {
14215 result
14216 ..add(_comment)
14217 ..addAll(_metadata);
14218 } else {
14219 result.addAll(sortedCommentAndAnnotations);
14220 }
14221 return result;
14222 }
14223
14224 @override
14225 void visitChildren(AstVisitor visitor) {
14226 //
14227 // Note that subclasses are responsible for visiting the identifier because
14228 // they often need to visit other nodes before visiting the identifier.
14229 //
14230 if (_commentIsBeforeAnnotations()) {
14231 _safelyVisitChild(_comment, visitor);
14232 _metadata.accept(visitor);
14233 } else {
14234 for (AstNode child in sortedCommentAndAnnotations) {
14235 child.accept(visitor);
14236 }
14237 }
14238 }
14239
14240 /**
14241 * Return `true` if the comment is lexically before any annotations.
14242 */
14243 bool _commentIsBeforeAnnotations() {
14244 if (_comment == null || _metadata.isEmpty) {
14245 return true;
14246 }
14247 Annotation firstAnnotation = _metadata[0];
14248 return _comment.offset < firstAnnotation.offset;
14249 }
14250 }
14251
14252 /**
14253 * A null literal expression.
14254 *
14255 * > nullLiteral ::=
14256 * > 'null'
14257 */
14258 class NullLiteral extends Literal {
14259 /**
14260 * The token representing the literal.
14261 */
14262 Token literal;
14263
14264 /**
14265 * Initialize a newly created null literal.
14266 */
14267 NullLiteral(this.literal);
14268
14269 @override
14270 Token get beginToken => literal;
14271
14272 @override
14273 Iterable get childEntities => new ChildEntities()..add(literal);
14274
14275 @override
14276 Token get endToken => literal;
14277
14278 @override
14279 accept(AstVisitor visitor) => visitor.visitNullLiteral(this);
14280
14281 @override
14282 void visitChildren(AstVisitor visitor) {
14283 // There are no children to visit.
14284 }
14285 }
14286
14287 /**
14288 * A parenthesized expression.
14289 *
14290 * > parenthesizedExpression ::=
14291 * > '(' [Expression] ')'
14292 */
14293 class ParenthesizedExpression extends Expression {
14294 /**
14295 * The left parenthesis.
14296 */
14297 Token leftParenthesis;
14298
14299 /**
14300 * The expression within the parentheses.
14301 */
14302 Expression _expression;
14303
14304 /**
14305 * The right parenthesis.
14306 */
14307 Token rightParenthesis;
14308
14309 /**
14310 * Initialize a newly created parenthesized expression.
14311 */
14312 ParenthesizedExpression(
14313 this.leftParenthesis, Expression expression, this.rightParenthesis) {
14314 _expression = _becomeParentOf(expression);
14315 }
14316
14317 @override
14318 Token get beginToken => leftParenthesis;
14319
14320 @override
14321 Iterable get childEntities => new ChildEntities()
14322 ..add(leftParenthesis)
14323 ..add(_expression)
14324 ..add(rightParenthesis);
14325
14326 @override
14327 Token get endToken => rightParenthesis;
14328
14329 /**
14330 * Return the expression within the parentheses.
14331 */
14332 Expression get expression => _expression;
14333
14334 /**
14335 * Set the expression within the parentheses to the given [expression].
14336 */
14337 void set expression(Expression expression) {
14338 _expression = _becomeParentOf(expression);
14339 }
14340
14341 @override
14342 int get precedence => 15;
14343
14344 @override
14345 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this);
14346
14347 @override
14348 void visitChildren(AstVisitor visitor) {
14349 _safelyVisitChild(_expression, visitor);
14350 }
14351 }
14352
14353 /**
14354 * A part directive.
14355 *
14356 * > partDirective ::=
14357 * > [Annotation] 'part' [StringLiteral] ';'
14358 */
14359 class PartDirective extends UriBasedDirective {
14360 /**
14361 * The token representing the 'part' keyword.
14362 */
14363 Token partKeyword;
14364
14365 /**
14366 * The semicolon terminating the directive.
14367 */
14368 Token semicolon;
14369
14370 /**
14371 * Initialize a newly created part directive. Either or both of the [comment]
14372 * and [metadata] can be `null` if the directive does not have the
14373 * corresponding attribute.
14374 */
14375 PartDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
14376 StringLiteral partUri, this.semicolon)
14377 : super(comment, metadata, partUri);
14378
14379 @override
14380 Iterable get childEntities =>
14381 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon);
14382
14383 @override
14384 Token get endToken => semicolon;
14385
14386 @override
14387 Token get firstTokenAfterCommentAndMetadata => partKeyword;
14388
14389 @override
14390 Token get keyword => partKeyword;
14391
14392 /**
14393 * Return the token representing the 'part' token.
14394 */
14395 @deprecated // Use "this.partKeyword"
14396 Token get partToken => partKeyword;
14397
14398 /**
14399 * Set the token representing the 'part' token to the given [token].
14400 */
14401 @deprecated // Use "this.partKeyword"
14402 set partToken(Token token) {
14403 partKeyword = token;
14404 }
14405
14406 @override
14407 CompilationUnitElement get uriElement => element as CompilationUnitElement;
14408
14409 @override
14410 accept(AstVisitor visitor) => visitor.visitPartDirective(this);
14411 }
14412
14413 /**
14414 * A part-of directive.
14415 *
14416 * > partOfDirective ::=
14417 * > [Annotation] 'part' 'of' [Identifier] ';'
14418 */
14419 class PartOfDirective extends Directive {
14420 /**
14421 * The token representing the 'part' keyword.
14422 */
14423 Token partKeyword;
14424
14425 /**
14426 * The token representing the 'of' keyword.
14427 */
14428 Token ofKeyword;
14429
14430 /**
14431 * The name of the library that the containing compilation unit is part of.
14432 */
14433 LibraryIdentifier _libraryName;
14434
14435 /**
14436 * The semicolon terminating the directive.
14437 */
14438 Token semicolon;
14439
14440 /**
14441 * Initialize a newly created part-of directive. Either or both of the
14442 * [comment] and [metadata] can be `null` if the directive does not have the
14443 * corresponding attribute.
14444 */
14445 PartOfDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
14446 this.ofKeyword, LibraryIdentifier libraryName, this.semicolon)
14447 : super(comment, metadata) {
14448 _libraryName = _becomeParentOf(libraryName);
14449 }
14450
14451 @override
14452 Iterable get childEntities => super._childEntities
14453 ..add(partKeyword)
14454 ..add(ofKeyword)
14455 ..add(_libraryName)
14456 ..add(semicolon);
14457
14458 @override
14459 Token get endToken => semicolon;
14460
14461 @override
14462 Token get firstTokenAfterCommentAndMetadata => partKeyword;
14463
14464 @override
14465 Token get keyword => partKeyword;
14466
14467 /**
14468 * Return the name of the library that the containing compilation unit is part
14469 * of.
14470 */
14471 LibraryIdentifier get libraryName => _libraryName;
14472
14473 /**
14474 * Set the name of the library that the containing compilation unit is part of
14475 * to the given [libraryName].
14476 */
14477 void set libraryName(LibraryIdentifier libraryName) {
14478 _libraryName = _becomeParentOf(libraryName);
14479 }
14480
14481 /**
14482 * Return the token representing the 'of' token.
14483 */
14484 @deprecated // Use "this.ofKeyword"
14485 Token get ofToken => ofKeyword;
14486
14487 /**
14488 * Set the token representing the 'of' token to the given [token].
14489 */
14490 @deprecated // Use "this.ofKeyword"
14491 set ofToken(Token token) {
14492 ofKeyword = token;
14493 }
14494
14495 /**
14496 * Return the token representing the 'part' token.
14497 */
14498 @deprecated // Use "this.partKeyword"
14499 Token get partToken => partKeyword;
14500
14501 /**
14502 * Set the token representing the 'part' token to the given [token].
14503 */
14504 @deprecated // Use "this.partKeyword"
14505 set partToken(Token token) {
14506 partKeyword = token;
14507 }
14508
14509 @override
14510 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this);
14511
14512 @override
14513 void visitChildren(AstVisitor visitor) {
14514 super.visitChildren(visitor);
14515 _safelyVisitChild(_libraryName, visitor);
14516 }
14517 }
14518
14519 /**
14520 * A postfix unary expression.
14521 *
14522 * > postfixExpression ::=
14523 * > [Expression] [Token]
14524 */
14525 class PostfixExpression extends Expression {
14526 /**
14527 * The expression computing the operand for the operator.
14528 */
14529 Expression _operand;
14530
14531 /**
14532 * The postfix operator being applied to the operand.
14533 */
14534 Token operator;
14535
14536 /**
14537 * The element associated with this the operator based on the propagated type
14538 * of the operand, or `null` if the AST structure has not been resolved, if
14539 * the operator is not user definable, or if the operator could not be
14540 * resolved.
14541 */
14542 MethodElement propagatedElement;
14543
14544 /**
14545 * The element associated with the operator based on the static type of the
14546 * operand, or `null` if the AST structure has not been resolved, if the
14547 * operator is not user definable, or if the operator could not be resolved.
14548 */
14549 MethodElement staticElement;
14550
14551 /**
14552 * Initialize a newly created postfix expression.
14553 */
14554 PostfixExpression(Expression operand, this.operator) {
14555 _operand = _becomeParentOf(operand);
14556 }
14557
14558 @override
14559 Token get beginToken => _operand.beginToken;
14560
14561 /**
14562 * Return the best element available for this operator. If resolution was able
14563 * to find a better element based on type propagation, that element will be
14564 * returned. Otherwise, the element found using the result of static analysis
14565 * will be returned. If resolution has not been performed, then `null` will be
14566 * returned.
14567 */
14568 MethodElement get bestElement {
14569 MethodElement element = propagatedElement;
14570 if (element == null) {
14571 element = staticElement;
14572 }
14573 return element;
14574 }
14575
14576 @override
14577 Iterable get childEntities =>
14578 new ChildEntities()..add(_operand)..add(operator);
14579
14580 @override
14581 Token get endToken => operator;
14582
14583 /**
14584 * Return the expression computing the operand for the operator.
14585 */
14586 Expression get operand => _operand;
14587
14588 /**
14589 * Set the expression computing the operand for the operator to the given
14590 * [expression].
14591 */
14592 void set operand(Expression expression) {
14593 _operand = _becomeParentOf(expression);
14594 }
14595
14596 @override
14597 int get precedence => 15;
14598
14599 /**
14600 * If the AST structure has been resolved, and the function being invoked is
14601 * known based on propagated type information, then return the parameter
14602 * element representing the parameter to which the value of the operand will
14603 * be bound. Otherwise, return `null`.
14604 */
14605 @deprecated // Use "expression.propagatedParameterElement"
14606 ParameterElement get propagatedParameterElementForOperand {
14607 return _propagatedParameterElementForOperand;
14608 }
14609
14610 /**
14611 * If the AST structure has been resolved, and the function being invoked is
14612 * known based on static type information, then return the parameter element
14613 * representing the parameter to which the value of the operand will be bound.
14614 * Otherwise, return `null`.
14615 */
14616 @deprecated // Use "expression.propagatedParameterElement"
14617 ParameterElement get staticParameterElementForOperand {
14618 return _staticParameterElementForOperand;
14619 }
14620
14621 /**
14622 * If the AST structure has been resolved, and the function being invoked is
14623 * known based on propagated type information, then return the parameter
14624 * element representing the parameter to which the value of the operand will
14625 * be bound. Otherwise, return `null`.
14626 */
14627 ParameterElement get _propagatedParameterElementForOperand {
14628 if (propagatedElement == null) {
14629 return null;
14630 }
14631 List<ParameterElement> parameters = propagatedElement.parameters;
14632 if (parameters.length < 1) {
14633 return null;
14634 }
14635 return parameters[0];
14636 }
14637
14638 /**
14639 * If the AST structure has been resolved, and the function being invoked is
14640 * known based on static type information, then return the parameter element
14641 * representing the parameter to which the value of the operand will be bound.
14642 * Otherwise, return `null`.
14643 */
14644 ParameterElement get _staticParameterElementForOperand {
14645 if (staticElement == null) {
14646 return null;
14647 }
14648 List<ParameterElement> parameters = staticElement.parameters;
14649 if (parameters.length < 1) {
14650 return null;
14651 }
14652 return parameters[0];
14653 }
14654
14655 @override
14656 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this);
14657
14658 @override
14659 void visitChildren(AstVisitor visitor) {
14660 _safelyVisitChild(_operand, visitor);
14661 }
14662 }
14663
14664 /**
14665 * An identifier that is prefixed or an access to an object property where the
14666 * target of the property access is a simple identifier.
14667 *
14668 * > prefixedIdentifier ::=
14669 * > [SimpleIdentifier] '.' [SimpleIdentifier]
14670 */
14671 class PrefixedIdentifier extends Identifier {
14672 /**
14673 * The prefix associated with the library in which the identifier is defined.
14674 */
14675 SimpleIdentifier _prefix;
14676
14677 /**
14678 * The period used to separate the prefix from the identifier.
14679 */
14680 Token period;
14681
14682 /**
14683 * The identifier being prefixed.
14684 */
14685 SimpleIdentifier _identifier;
14686
14687 /**
14688 * Initialize a newly created prefixed identifier.
14689 */
14690 PrefixedIdentifier(
14691 SimpleIdentifier prefix, this.period, SimpleIdentifier identifier) {
14692 _prefix = _becomeParentOf(prefix);
14693 _identifier = _becomeParentOf(identifier);
14694 }
14695
14696 @override
14697 Token get beginToken => _prefix.beginToken;
14698
14699 @override
14700 Element get bestElement {
14701 if (_identifier == null) {
14702 return null;
14703 }
14704 return _identifier.bestElement;
14705 }
14706
14707 @override
14708 Iterable get childEntities =>
14709 new ChildEntities()..add(_prefix)..add(period)..add(_identifier);
14710
14711 @override
14712 Token get endToken => _identifier.endToken;
14713
14714 /**
14715 * Return the identifier being prefixed.
14716 */
14717 SimpleIdentifier get identifier => _identifier;
14718
14719 /**
14720 * Set the identifier being prefixed to the given [identifier].
14721 */
14722 void set identifier(SimpleIdentifier identifier) {
14723 _identifier = _becomeParentOf(identifier);
14724 }
14725
14726 /**
14727 * Return `true` if this type is a deferred type. If the AST structure has not
14728 * been resolved, then return `false`.
14729 *
14730 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form
14731 * </i>p.T</i> where <i>p</i> is a deferred prefix.
14732 */
14733 bool get isDeferred {
14734 Element element = _prefix.staticElement;
14735 if (element is! PrefixElement) {
14736 return false;
14737 }
14738 PrefixElement prefixElement = element as PrefixElement;
14739 List<ImportElement> imports =
14740 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement);
14741 if (imports.length != 1) {
14742 return false;
14743 }
14744 return imports[0].isDeferred;
14745 }
14746
14747 @override
14748 String get name => "${_prefix.name}.${_identifier.name}";
14749
14750 @override
14751 int get precedence => 15;
14752
14753 /**
14754 * Return the prefix associated with the library in which the identifier is
14755 * defined.
14756 */
14757 SimpleIdentifier get prefix => _prefix;
14758
14759 /**
14760 * Set the prefix associated with the library in which the identifier is
14761 * defined to the given [identifier].
14762 */
14763 void set prefix(SimpleIdentifier identifier) {
14764 _prefix = _becomeParentOf(identifier);
14765 }
14766
14767 @override
14768 Element get propagatedElement {
14769 if (_identifier == null) {
14770 return null;
14771 }
14772 return _identifier.propagatedElement;
14773 }
14774
14775 @override
14776 Element get staticElement {
14777 if (_identifier == null) {
14778 return null;
14779 }
14780 return _identifier.staticElement;
14781 }
14782
14783 @override
14784 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this);
14785
14786 @override
14787 void visitChildren(AstVisitor visitor) {
14788 _safelyVisitChild(_prefix, visitor);
14789 _safelyVisitChild(_identifier, visitor);
14790 }
14791 }
14792
14793 /**
14794 * A prefix unary expression.
14795 *
14796 * > prefixExpression ::=
14797 * > [Token] [Expression]
14798 */
14799 class PrefixExpression extends Expression {
14800 /**
14801 * The prefix operator being applied to the operand.
14802 */
14803 Token operator;
14804
14805 /**
14806 * The expression computing the operand for the operator.
14807 */
14808 Expression _operand;
14809
14810 /**
14811 * The element associated with the operator based on the static type of the
14812 * operand, or `null` if the AST structure has not been resolved, if the
14813 * operator is not user definable, or if the operator could not be resolved.
14814 */
14815 MethodElement staticElement;
14816
14817 /**
14818 * The element associated with the operator based on the propagated type of
14819 * the operand, or `null` if the AST structure has not been resolved, if the
14820 * operator is not user definable, or if the operator could not be resolved.
14821 */
14822 MethodElement propagatedElement;
14823
14824 /**
14825 * Initialize a newly created prefix expression.
14826 */
14827 PrefixExpression(this.operator, Expression operand) {
14828 _operand = _becomeParentOf(operand);
14829 }
14830
14831 @override
14832 Token get beginToken => operator;
14833
14834 /**
14835 * Return the best element available for this operator. If resolution was able
14836 * to find a better element based on type propagation, that element will be
14837 * returned. Otherwise, the element found using the result of static analysis
14838 * will be returned. If resolution has not been performed, then `null` will be
14839 * returned.
14840 */
14841 MethodElement get bestElement {
14842 MethodElement element = propagatedElement;
14843 if (element == null) {
14844 element = staticElement;
14845 }
14846 return element;
14847 }
14848
14849 @override
14850 Iterable get childEntities =>
14851 new ChildEntities()..add(operator)..add(_operand);
14852
14853 @override
14854 Token get endToken => _operand.endToken;
14855
14856 /**
14857 * Return the expression computing the operand for the operator.
14858 */
14859 Expression get operand => _operand;
14860
14861 /**
14862 * Set the expression computing the operand for the operator to the given
14863 * [expression].
14864 */
14865 void set operand(Expression expression) {
14866 _operand = _becomeParentOf(expression);
14867 }
14868
14869 @override
14870 int get precedence => 14;
14871
14872 /**
14873 * If the AST structure has been resolved, and the function being invoked is
14874 * known based on propagated type information, then return the parameter
14875 * element representing the parameter to which the value of the operand will
14876 * be bound. Otherwise, return `null`.
14877 */
14878 @deprecated // Use "expression.propagatedParameterElement"
14879 ParameterElement get propagatedParameterElementForOperand {
14880 return _propagatedParameterElementForOperand;
14881 }
14882
14883 /**
14884 * If the AST structure has been resolved, and the function being invoked is
14885 * known based on static type information, then return the parameter element
14886 * representing the parameter to which the value of the operand will be bound.
14887 * Otherwise, return `null`.
14888 */
14889 @deprecated // Use "expression.propagatedParameterElement"
14890 ParameterElement get staticParameterElementForOperand {
14891 return _staticParameterElementForOperand;
14892 }
14893
14894 /**
14895 * If the AST structure has been resolved, and the function being invoked is
14896 * known based on propagated type information, then return the parameter
14897 * element representing the parameter to which the value of the operand will
14898 * be bound. Otherwise, return `null`.
14899 */
14900 ParameterElement get _propagatedParameterElementForOperand {
14901 if (propagatedElement == null) {
14902 return null;
14903 }
14904 List<ParameterElement> parameters = propagatedElement.parameters;
14905 if (parameters.length < 1) {
14906 return null;
14907 }
14908 return parameters[0];
14909 }
14910
14911 /**
14912 * If the AST structure has been resolved, and the function being invoked is
14913 * known based on static type information, then return the parameter element
14914 * representing the parameter to which the value of the operand will be bound.
14915 * Otherwise, return `null`.
14916 */
14917 ParameterElement get _staticParameterElementForOperand {
14918 if (staticElement == null) {
14919 return null;
14920 }
14921 List<ParameterElement> parameters = staticElement.parameters;
14922 if (parameters.length < 1) {
14923 return null;
14924 }
14925 return parameters[0];
14926 }
14927
14928 @override
14929 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this);
14930
14931 @override
14932 void visitChildren(AstVisitor visitor) {
14933 _safelyVisitChild(_operand, visitor);
14934 }
14935 }
14936
14937 /**
14938 * The access of a property of an object.
14939 *
14940 * Note, however, that accesses to properties of objects can also be represented
14941 * as [PrefixedIdentifier] nodes in cases where the target is also a simple
14942 * identifier.
14943 *
14944 * > propertyAccess ::=
14945 * > [Expression] '.' [SimpleIdentifier]
14946 */
14947 class PropertyAccess extends Expression {
14948 /**
14949 * The expression computing the object defining the property being accessed.
14950 */
14951 Expression _target;
14952
14953 /**
14954 * The property access operator.
14955 */
14956 Token operator;
14957
14958 /**
14959 * The name of the property being accessed.
14960 */
14961 SimpleIdentifier _propertyName;
14962
14963 /**
14964 * Initialize a newly created property access expression.
14965 */
14966 PropertyAccess(
14967 Expression target, this.operator, SimpleIdentifier propertyName) {
14968 _target = _becomeParentOf(target);
14969 _propertyName = _becomeParentOf(propertyName);
14970 }
14971
14972 @override
14973 Token get beginToken {
14974 if (_target != null) {
14975 return _target.beginToken;
14976 }
14977 return operator;
14978 }
14979
14980 @override
14981 Iterable get childEntities =>
14982 new ChildEntities()..add(_target)..add(operator)..add(_propertyName);
14983
14984 @override
14985 Token get endToken => _propertyName.endToken;
14986
14987 @override
14988 bool get isAssignable => true;
14989
14990 /**
14991 * Return `true` if this expression is cascaded. If it is, then the target of
14992 * this expression is not stored locally but is stored in the nearest ancestor
14993 * that is a [CascadeExpression].
14994 */
14995 bool get isCascaded =>
14996 operator != null && operator.type == TokenType.PERIOD_PERIOD;
14997
14998 @override
14999 int get precedence => 15;
15000
15001 /**
15002 * Return the name of the property being accessed.
15003 */
15004 SimpleIdentifier get propertyName => _propertyName;
15005
15006 /**
15007 * Set the name of the property being accessed to the given [identifier].
15008 */
15009 void set propertyName(SimpleIdentifier identifier) {
15010 _propertyName = _becomeParentOf(identifier);
15011 }
15012
15013 /**
15014 * Return the expression used to compute the receiver of the invocation. If
15015 * this invocation is not part of a cascade expression, then this is the same
15016 * as [target]. If this invocation is part of a cascade expression, then the
15017 * target stored with the cascade expression is returned.
15018 */
15019 Expression get realTarget {
15020 if (isCascaded) {
15021 AstNode ancestor = parent;
15022 while (ancestor is! CascadeExpression) {
15023 if (ancestor == null) {
15024 return _target;
15025 }
15026 ancestor = ancestor.parent;
15027 }
15028 return (ancestor as CascadeExpression).target;
15029 }
15030 return _target;
15031 }
15032
15033 /**
15034 * Return the expression computing the object defining the property being
15035 * accessed, or `null` if this property access is part of a cascade expression .
15036 *
15037 * Use [realTarget] to get the target independent of whether this is part of a
15038 * cascade expression.
15039 */
15040 Expression get target => _target;
15041
15042 /**
15043 * Set the expression computing the object defining the property being
15044 * accessed to the given [expression].
15045 */
15046 void set target(Expression expression) {
15047 _target = _becomeParentOf(expression);
15048 }
15049
15050 @override
15051 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this);
15052
15053 @override
15054 void visitChildren(AstVisitor visitor) {
15055 _safelyVisitChild(_target, visitor);
15056 _safelyVisitChild(_propertyName, visitor);
15057 }
15058 }
15059
15060 /**
15061 * An AST visitor that will recursively visit all of the nodes in an AST
15062 * structure. For example, using an instance of this class to visit a [Block]
15063 * will also cause all of the statements in the block to be visited.
15064 *
15065 * Subclasses that override a visit method must either invoke the overridden
15066 * visit method or must explicitly ask the visited node to visit its children.
15067 * Failure to do so will cause the children of the visited node to not be
15068 * visited.
15069 */
15070 class RecursiveAstVisitor<R> implements AstVisitor<R> {
15071 @override
15072 R visitAdjacentStrings(AdjacentStrings node) {
15073 node.visitChildren(this);
15074 return null;
15075 }
15076
15077 @override
15078 R visitAnnotation(Annotation node) {
15079 node.visitChildren(this);
15080 return null;
15081 }
15082
15083 @override
15084 R visitArgumentList(ArgumentList node) {
15085 node.visitChildren(this);
15086 return null;
15087 }
15088
15089 @override
15090 R visitAsExpression(AsExpression node) {
15091 node.visitChildren(this);
15092 return null;
15093 }
15094
15095 @override
15096 R visitAssertStatement(AssertStatement node) {
15097 node.visitChildren(this);
15098 return null;
15099 }
15100
15101 @override
15102 R visitAssignmentExpression(AssignmentExpression node) {
15103 node.visitChildren(this);
15104 return null;
15105 }
15106
15107 @override
15108 R visitAwaitExpression(AwaitExpression node) {
15109 node.visitChildren(this);
15110 return null;
15111 }
15112
15113 @override
15114 R visitBinaryExpression(BinaryExpression node) {
15115 node.visitChildren(this);
15116 return null;
15117 }
15118
15119 @override
15120 R visitBlock(Block node) {
15121 node.visitChildren(this);
15122 return null;
15123 }
15124
15125 @override
15126 R visitBlockFunctionBody(BlockFunctionBody node) {
15127 node.visitChildren(this);
15128 return null;
15129 }
15130
15131 @override
15132 R visitBooleanLiteral(BooleanLiteral node) {
15133 node.visitChildren(this);
15134 return null;
15135 }
15136
15137 @override
15138 R visitBreakStatement(BreakStatement node) {
15139 node.visitChildren(this);
15140 return null;
15141 }
15142
15143 @override
15144 R visitCascadeExpression(CascadeExpression node) {
15145 node.visitChildren(this);
15146 return null;
15147 }
15148
15149 @override
15150 R visitCatchClause(CatchClause node) {
15151 node.visitChildren(this);
15152 return null;
15153 }
15154
15155 @override
15156 R visitClassDeclaration(ClassDeclaration node) {
15157 node.visitChildren(this);
15158 return null;
15159 }
15160
15161 @override
15162 R visitClassTypeAlias(ClassTypeAlias node) {
15163 node.visitChildren(this);
15164 return null;
15165 }
15166
15167 @override
15168 R visitComment(Comment node) {
15169 node.visitChildren(this);
15170 return null;
15171 }
15172
15173 @override
15174 R visitCommentReference(CommentReference node) {
15175 node.visitChildren(this);
15176 return null;
15177 }
15178
15179 @override
15180 R visitCompilationUnit(CompilationUnit node) {
15181 node.visitChildren(this);
15182 return null;
15183 }
15184
15185 @override
15186 R visitConditionalExpression(ConditionalExpression node) {
15187 node.visitChildren(this);
15188 return null;
15189 }
15190
15191 @override
15192 R visitConstructorDeclaration(ConstructorDeclaration node) {
15193 node.visitChildren(this);
15194 return null;
15195 }
15196
15197 @override
15198 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
15199 node.visitChildren(this);
15200 return null;
15201 }
15202
15203 @override
15204 R visitConstructorName(ConstructorName node) {
15205 node.visitChildren(this);
15206 return null;
15207 }
15208
15209 @override
15210 R visitContinueStatement(ContinueStatement node) {
15211 node.visitChildren(this);
15212 return null;
15213 }
15214
15215 @override
15216 R visitDeclaredIdentifier(DeclaredIdentifier node) {
15217 node.visitChildren(this);
15218 return null;
15219 }
15220
15221 @override
15222 R visitDefaultFormalParameter(DefaultFormalParameter node) {
15223 node.visitChildren(this);
15224 return null;
15225 }
15226
15227 @override
15228 R visitDoStatement(DoStatement node) {
15229 node.visitChildren(this);
15230 return null;
15231 }
15232
15233 @override
15234 R visitDoubleLiteral(DoubleLiteral node) {
15235 node.visitChildren(this);
15236 return null;
15237 }
15238
15239 @override
15240 R visitEmptyFunctionBody(EmptyFunctionBody node) {
15241 node.visitChildren(this);
15242 return null;
15243 }
15244
15245 @override
15246 R visitEmptyStatement(EmptyStatement node) {
15247 node.visitChildren(this);
15248 return null;
15249 }
15250
15251 @override
15252 R visitEnumConstantDeclaration(EnumConstantDeclaration node) {
15253 node.visitChildren(this);
15254 return null;
15255 }
15256
15257 @override
15258 R visitEnumDeclaration(EnumDeclaration node) {
15259 node.visitChildren(this);
15260 return null;
15261 }
15262
15263 @override
15264 R visitExportDirective(ExportDirective node) {
15265 node.visitChildren(this);
15266 return null;
15267 }
15268
15269 @override
15270 R visitExpressionFunctionBody(ExpressionFunctionBody node) {
15271 node.visitChildren(this);
15272 return null;
15273 }
15274
15275 @override
15276 R visitExpressionStatement(ExpressionStatement node) {
15277 node.visitChildren(this);
15278 return null;
15279 }
15280
15281 @override
15282 R visitExtendsClause(ExtendsClause node) {
15283 node.visitChildren(this);
15284 return null;
15285 }
15286
15287 @override
15288 R visitFieldDeclaration(FieldDeclaration node) {
15289 node.visitChildren(this);
15290 return null;
15291 }
15292
15293 @override
15294 R visitFieldFormalParameter(FieldFormalParameter node) {
15295 node.visitChildren(this);
15296 return null;
15297 }
15298
15299 @override
15300 R visitForEachStatement(ForEachStatement node) {
15301 node.visitChildren(this);
15302 return null;
15303 }
15304
15305 @override
15306 R visitFormalParameterList(FormalParameterList node) {
15307 node.visitChildren(this);
15308 return null;
15309 }
15310
15311 @override
15312 R visitForStatement(ForStatement node) {
15313 node.visitChildren(this);
15314 return null;
15315 }
15316
15317 @override
15318 R visitFunctionDeclaration(FunctionDeclaration node) {
15319 node.visitChildren(this);
15320 return null;
15321 }
15322
15323 @override
15324 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
15325 node.visitChildren(this);
15326 return null;
15327 }
15328
15329 @override
15330 R visitFunctionExpression(FunctionExpression node) {
15331 node.visitChildren(this);
15332 return null;
15333 }
15334
15335 @override
15336 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
15337 node.visitChildren(this);
15338 return null;
15339 }
15340
15341 @override
15342 R visitFunctionTypeAlias(FunctionTypeAlias node) {
15343 node.visitChildren(this);
15344 return null;
15345 }
15346
15347 @override
15348 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
15349 node.visitChildren(this);
15350 return null;
15351 }
15352
15353 @override
15354 R visitHideCombinator(HideCombinator node) {
15355 node.visitChildren(this);
15356 return null;
15357 }
15358
15359 @override
15360 R visitIfStatement(IfStatement node) {
15361 node.visitChildren(this);
15362 return null;
15363 }
15364
15365 @override
15366 R visitImplementsClause(ImplementsClause node) {
15367 node.visitChildren(this);
15368 return null;
15369 }
15370
15371 @override
15372 R visitImportDirective(ImportDirective node) {
15373 node.visitChildren(this);
15374 return null;
15375 }
15376
15377 @override
15378 R visitIndexExpression(IndexExpression node) {
15379 node.visitChildren(this);
15380 return null;
15381 }
15382
15383 @override
15384 R visitInstanceCreationExpression(InstanceCreationExpression node) {
15385 node.visitChildren(this);
15386 return null;
15387 }
15388
15389 @override
15390 R visitIntegerLiteral(IntegerLiteral node) {
15391 node.visitChildren(this);
15392 return null;
15393 }
15394
15395 @override
15396 R visitInterpolationExpression(InterpolationExpression node) {
15397 node.visitChildren(this);
15398 return null;
15399 }
15400
15401 @override
15402 R visitInterpolationString(InterpolationString node) {
15403 node.visitChildren(this);
15404 return null;
15405 }
15406
15407 @override
15408 R visitIsExpression(IsExpression node) {
15409 node.visitChildren(this);
15410 return null;
15411 }
15412
15413 @override
15414 R visitLabel(Label node) {
15415 node.visitChildren(this);
15416 return null;
15417 }
15418
15419 @override
15420 R visitLabeledStatement(LabeledStatement node) {
15421 node.visitChildren(this);
15422 return null;
15423 }
15424
15425 @override
15426 R visitLibraryDirective(LibraryDirective node) {
15427 node.visitChildren(this);
15428 return null;
15429 }
15430
15431 @override
15432 R visitLibraryIdentifier(LibraryIdentifier node) {
15433 node.visitChildren(this);
15434 return null;
15435 }
15436
15437 @override
15438 R visitListLiteral(ListLiteral node) {
15439 node.visitChildren(this);
15440 return null;
15441 }
15442
15443 @override
15444 R visitMapLiteral(MapLiteral node) {
15445 node.visitChildren(this);
15446 return null;
15447 }
15448
15449 @override
15450 R visitMapLiteralEntry(MapLiteralEntry node) {
15451 node.visitChildren(this);
15452 return null;
15453 }
15454
15455 @override
15456 R visitMethodDeclaration(MethodDeclaration node) {
15457 node.visitChildren(this);
15458 return null;
15459 }
15460
15461 @override
15462 R visitMethodInvocation(MethodInvocation node) {
15463 node.visitChildren(this);
15464 return null;
15465 }
15466
15467 @override
15468 R visitNamedExpression(NamedExpression node) {
15469 node.visitChildren(this);
15470 return null;
15471 }
15472
15473 @override
15474 R visitNativeClause(NativeClause node) {
15475 node.visitChildren(this);
15476 return null;
15477 }
15478
15479 @override
15480 R visitNativeFunctionBody(NativeFunctionBody node) {
15481 node.visitChildren(this);
15482 return null;
15483 }
15484
15485 @override
15486 R visitNullLiteral(NullLiteral node) {
15487 node.visitChildren(this);
15488 return null;
15489 }
15490
15491 @override
15492 R visitParenthesizedExpression(ParenthesizedExpression node) {
15493 node.visitChildren(this);
15494 return null;
15495 }
15496
15497 @override
15498 R visitPartDirective(PartDirective node) {
15499 node.visitChildren(this);
15500 return null;
15501 }
15502
15503 @override
15504 R visitPartOfDirective(PartOfDirective node) {
15505 node.visitChildren(this);
15506 return null;
15507 }
15508
15509 @override
15510 R visitPostfixExpression(PostfixExpression node) {
15511 node.visitChildren(this);
15512 return null;
15513 }
15514
15515 @override
15516 R visitPrefixedIdentifier(PrefixedIdentifier node) {
15517 node.visitChildren(this);
15518 return null;
15519 }
15520
15521 @override
15522 R visitPrefixExpression(PrefixExpression node) {
15523 node.visitChildren(this);
15524 return null;
15525 }
15526
15527 @override
15528 R visitPropertyAccess(PropertyAccess node) {
15529 node.visitChildren(this);
15530 return null;
15531 }
15532
15533 @override
15534 R visitRedirectingConstructorInvocation(
15535 RedirectingConstructorInvocation node) {
15536 node.visitChildren(this);
15537 return null;
15538 }
15539
15540 @override
15541 R visitRethrowExpression(RethrowExpression node) {
15542 node.visitChildren(this);
15543 return null;
15544 }
15545
15546 @override
15547 R visitReturnStatement(ReturnStatement node) {
15548 node.visitChildren(this);
15549 return null;
15550 }
15551
15552 @override
15553 R visitScriptTag(ScriptTag node) {
15554 node.visitChildren(this);
15555 return null;
15556 }
15557
15558 @override
15559 R visitShowCombinator(ShowCombinator node) {
15560 node.visitChildren(this);
15561 return null;
15562 }
15563
15564 @override
15565 R visitSimpleFormalParameter(SimpleFormalParameter node) {
15566 node.visitChildren(this);
15567 return null;
15568 }
15569
15570 @override
15571 R visitSimpleIdentifier(SimpleIdentifier node) {
15572 node.visitChildren(this);
15573 return null;
15574 }
15575
15576 @override
15577 R visitSimpleStringLiteral(SimpleStringLiteral node) {
15578 node.visitChildren(this);
15579 return null;
15580 }
15581
15582 @override
15583 R visitStringInterpolation(StringInterpolation node) {
15584 node.visitChildren(this);
15585 return null;
15586 }
15587
15588 @override
15589 R visitSuperConstructorInvocation(SuperConstructorInvocation node) {
15590 node.visitChildren(this);
15591 return null;
15592 }
15593
15594 @override
15595 R visitSuperExpression(SuperExpression node) {
15596 node.visitChildren(this);
15597 return null;
15598 }
15599
15600 @override
15601 R visitSwitchCase(SwitchCase node) {
15602 node.visitChildren(this);
15603 return null;
15604 }
15605
15606 @override
15607 R visitSwitchDefault(SwitchDefault node) {
15608 node.visitChildren(this);
15609 return null;
15610 }
15611
15612 @override
15613 R visitSwitchStatement(SwitchStatement node) {
15614 node.visitChildren(this);
15615 return null;
15616 }
15617
15618 @override
15619 R visitSymbolLiteral(SymbolLiteral node) {
15620 node.visitChildren(this);
15621 return null;
15622 }
15623
15624 @override
15625 R visitThisExpression(ThisExpression node) {
15626 node.visitChildren(this);
15627 return null;
15628 }
15629
15630 @override
15631 R visitThrowExpression(ThrowExpression node) {
15632 node.visitChildren(this);
15633 return null;
15634 }
15635
15636 @override
15637 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
15638 node.visitChildren(this);
15639 return null;
15640 }
15641
15642 @override
15643 R visitTryStatement(TryStatement node) {
15644 node.visitChildren(this);
15645 return null;
15646 }
15647
15648 @override
15649 R visitTypeArgumentList(TypeArgumentList node) {
15650 node.visitChildren(this);
15651 return null;
15652 }
15653
15654 @override
15655 R visitTypeName(TypeName node) {
15656 node.visitChildren(this);
15657 return null;
15658 }
15659
15660 @override
15661 R visitTypeParameter(TypeParameter node) {
15662 node.visitChildren(this);
15663 return null;
15664 }
15665
15666 @override
15667 R visitTypeParameterList(TypeParameterList node) {
15668 node.visitChildren(this);
15669 return null;
15670 }
15671
15672 @override
15673 R visitVariableDeclaration(VariableDeclaration node) {
15674 node.visitChildren(this);
15675 return null;
15676 }
15677
15678 @override
15679 R visitVariableDeclarationList(VariableDeclarationList node) {
15680 node.visitChildren(this);
15681 return null;
15682 }
15683
15684 @override
15685 R visitVariableDeclarationStatement(VariableDeclarationStatement node) {
15686 node.visitChildren(this);
15687 return null;
15688 }
15689
15690 @override
15691 R visitWhileStatement(WhileStatement node) {
15692 node.visitChildren(this);
15693 return null;
15694 }
15695
15696 @override
15697 R visitWithClause(WithClause node) {
15698 node.visitChildren(this);
15699 return null;
15700 }
15701
15702 @override
15703 R visitYieldStatement(YieldStatement node) {
15704 node.visitChildren(this);
15705 return null;
15706 }
15707 }
15708
15709 /**
15710 * The invocation of a constructor in the same class from within a constructor's
15711 * initialization list.
15712 *
15713 * > redirectingConstructorInvocation ::=
15714 * > 'this' ('.' identifier)? arguments
15715 */
15716 class RedirectingConstructorInvocation extends ConstructorInitializer {
15717 /**
15718 * The token for the 'this' keyword.
15719 */
15720 Token thisKeyword;
15721
15722 /**
15723 * The token for the period before the name of the constructor that is being
15724 * invoked, or `null` if the unnamed constructor is being invoked.
15725 */
15726 Token period;
15727
15728 /**
15729 * The name of the constructor that is being invoked, or `null` if the unnamed
15730 * constructor is being invoked.
15731 */
15732 SimpleIdentifier _constructorName;
15733
15734 /**
15735 * The list of arguments to the constructor.
15736 */
15737 ArgumentList _argumentList;
15738
15739 /**
15740 * The element associated with the constructor based on static type
15741 * information, or `null` if the AST structure has not been resolved or if the
15742 * constructor could not be resolved.
15743 */
15744 ConstructorElement staticElement;
15745
15746 /**
15747 * Initialize a newly created redirecting invocation to invoke the constructor
15748 * with the given name with the given arguments. The [constructorName] can be
15749 * `null` if the constructor being invoked is the unnamed constructor.
15750 */
15751 RedirectingConstructorInvocation(this.thisKeyword, this.period,
15752 SimpleIdentifier constructorName, ArgumentList argumentList) {
15753 _constructorName = _becomeParentOf(constructorName);
15754 _argumentList = _becomeParentOf(argumentList);
15755 }
15756
15757 /**
15758 * Return the list of arguments to the constructor.
15759 */
15760 ArgumentList get argumentList => _argumentList;
15761
15762 /**
15763 * Set the list of arguments to the constructor to the given [argumentList].
15764 */
15765 void set argumentList(ArgumentList argumentList) {
15766 _argumentList = _becomeParentOf(argumentList);
15767 }
15768
15769 @override
15770 Token get beginToken => thisKeyword;
15771
15772 @override
15773 Iterable get childEntities => new ChildEntities()
15774 ..add(thisKeyword)
15775 ..add(period)
15776 ..add(_constructorName)
15777 ..add(_argumentList);
15778
15779 /**
15780 * Return the name of the constructor that is being invoked, or `null` if the
15781 * unnamed constructor is being invoked.
15782 */
15783 SimpleIdentifier get constructorName => _constructorName;
15784
15785 /**
15786 * Set the name of the constructor that is being invoked to the given
15787 * [identifier].
15788 */
15789 void set constructorName(SimpleIdentifier identifier) {
15790 _constructorName = _becomeParentOf(identifier);
15791 }
15792
15793 @override
15794 Token get endToken => _argumentList.endToken;
15795
15796 /**
15797 * Return the token for the 'this' keyword.
15798 */
15799 @deprecated // Use "this.thisKeyword"
15800 Token get keyword => thisKeyword;
15801
15802 /**
15803 * Set the token for the 'this' keyword to the given [token].
15804 */
15805 @deprecated // Use "this.thisKeyword"
15806 set keyword(Token token) {
15807 thisKeyword = token;
15808 }
15809
15810 @override
15811 accept(AstVisitor visitor) =>
15812 visitor.visitRedirectingConstructorInvocation(this);
15813
15814 @override
15815 void visitChildren(AstVisitor visitor) {
15816 _safelyVisitChild(_constructorName, visitor);
15817 _safelyVisitChild(_argumentList, visitor);
15818 }
15819 }
15820
15821 /**
15822 * A rethrow expression.
15823 *
15824 * > rethrowExpression ::=
15825 * > 'rethrow'
15826 */
15827 class RethrowExpression extends Expression {
15828 /**
15829 * The token representing the 'rethrow' keyword.
15830 */
15831 Token rethrowKeyword;
15832
15833 /**
15834 * Initialize a newly created rethrow expression.
15835 */
15836 RethrowExpression(this.rethrowKeyword);
15837
15838 @override
15839 Token get beginToken => rethrowKeyword;
15840
15841 @override
15842 Iterable get childEntities => new ChildEntities()..add(rethrowKeyword);
15843
15844 @override
15845 Token get endToken => rethrowKeyword;
15846
15847 /**
15848 * Return the token representing the 'rethrow' keyword.
15849 */
15850 @deprecated // Use "this.rethrowKeyword"
15851 Token get keyword => rethrowKeyword;
15852
15853 /**
15854 * Set the token representing the 'rethrow' keyword to the given [token].
15855 */
15856 @deprecated // Use "this.rethrowKeyword"
15857 set keyword(Token token) {
15858 rethrowKeyword = token;
15859 }
15860
15861 @override
15862 int get precedence => 0;
15863
15864 @override
15865 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this);
15866
15867 @override
15868 void visitChildren(AstVisitor visitor) {
15869 // There are no children to visit.
15870 }
15871 }
15872
15873 /**
15874 * A return statement.
15875 *
15876 * > returnStatement ::=
15877 * > 'return' [Expression]? ';'
15878 */
15879 class ReturnStatement extends Statement {
15880 /**
15881 * The token representing the 'return' keyword.
15882 */
15883 Token returnKeyword;
15884
15885 /**
15886 * The expression computing the value to be returned, or `null` if no explicit
15887 * value was provided.
15888 */
15889 Expression _expression;
15890
15891 /**
15892 * The semicolon terminating the statement.
15893 */
15894 Token semicolon;
15895
15896 /**
15897 * Initialize a newly created return statement. The [expression] can be `null`
15898 * if no explicit value was provided.
15899 */
15900 ReturnStatement(this.returnKeyword, Expression expression, this.semicolon) {
15901 _expression = _becomeParentOf(expression);
15902 }
15903
15904 @override
15905 Token get beginToken => returnKeyword;
15906
15907 @override
15908 Iterable get childEntities =>
15909 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon);
15910
15911 @override
15912 Token get endToken => semicolon;
15913
15914 /**
15915 * Return the expression computing the value to be returned, or `null` if no
15916 * explicit value was provided.
15917 */
15918 Expression get expression => _expression;
15919
15920 /**
15921 * Set the expression computing the value to be returned to the given
15922 * [expression].
15923 */
15924 void set expression(Expression expression) {
15925 _expression = _becomeParentOf(expression);
15926 }
15927
15928 /**
15929 * Return the token representing the 'return' keyword.
15930 */
15931 @deprecated // Use "this.returnKeyword"
15932 Token get keyword => returnKeyword;
15933
15934 /**
15935 * Set the token representing the 'return' keyword to the given [token].
15936 */
15937 @deprecated // Use "this.returnKeyword"
15938 set keyword(Token token) {
15939 returnKeyword = token;
15940 }
15941
15942 @override
15943 accept(AstVisitor visitor) => visitor.visitReturnStatement(this);
15944
15945 @override
15946 void visitChildren(AstVisitor visitor) {
15947 _safelyVisitChild(_expression, visitor);
15948 }
15949 }
15950
15951 /**
15952 * Traverse the AST from initial child node to successive parents, building a
15953 * collection of local variable and parameter names visible to the initial child
15954 * node. In case of name shadowing, the first name seen is the most specific one
15955 * so names are not redefined.
15956 *
15957 * Completion test code coverage is 95%. The two basic blocks that are not
15958 * executed cannot be executed. They are included for future reference.
15959 */
15960 class ScopedNameFinder extends GeneralizingAstVisitor<Object> {
15961 Declaration _declarationNode;
15962
15963 AstNode _immediateChild;
15964
15965 Map<String, SimpleIdentifier> _locals =
15966 new HashMap<String, SimpleIdentifier>();
15967
15968 final int _position;
15969
15970 bool _referenceIsWithinLocalFunction = false;
15971
15972 ScopedNameFinder(this._position);
15973
15974 Declaration get declaration => _declarationNode;
15975
15976 Map<String, SimpleIdentifier> get locals => _locals;
15977
15978 @override
15979 Object visitBlock(Block node) {
15980 _checkStatements(node.statements);
15981 return super.visitBlock(node);
15982 }
15983
15984 @override
15985 Object visitCatchClause(CatchClause node) {
15986 _addToScope(node.exceptionParameter);
15987 _addToScope(node.stackTraceParameter);
15988 return super.visitCatchClause(node);
15989 }
15990
15991 @override
15992 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15993 if (!identical(_immediateChild, node.parameters)) {
15994 _addParameters(node.parameters.parameters);
15995 }
15996 _declarationNode = node;
15997 return null;
15998 }
15999
16000 @override
16001 Object visitFieldDeclaration(FieldDeclaration node) {
16002 _declarationNode = node;
16003 return null;
16004 }
16005
16006 @override
16007 Object visitForEachStatement(ForEachStatement node) {
16008 DeclaredIdentifier loopVariable = node.loopVariable;
16009 if (loopVariable != null) {
16010 _addToScope(loopVariable.identifier);
16011 }
16012 return super.visitForEachStatement(node);
16013 }
16014
16015 @override
16016 Object visitForStatement(ForStatement node) {
16017 if (!identical(_immediateChild, node.variables) && node.variables != null) {
16018 _addVariables(node.variables.variables);
16019 }
16020 return super.visitForStatement(node);
16021 }
16022
16023 @override
16024 Object visitFunctionDeclaration(FunctionDeclaration node) {
16025 if (node.parent is! FunctionDeclarationStatement) {
16026 _declarationNode = node;
16027 return null;
16028 }
16029 return super.visitFunctionDeclaration(node);
16030 }
16031
16032 @override
16033 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
16034 _referenceIsWithinLocalFunction = true;
16035 return super.visitFunctionDeclarationStatement(node);
16036 }
16037
16038 @override
16039 Object visitFunctionExpression(FunctionExpression node) {
16040 if (node.parameters != null &&
16041 !identical(_immediateChild, node.parameters)) {
16042 _addParameters(node.parameters.parameters);
16043 }
16044 return super.visitFunctionExpression(node);
16045 }
16046
16047 @override
16048 Object visitMethodDeclaration(MethodDeclaration node) {
16049 _declarationNode = node;
16050 if (node.parameters == null) {
16051 return null;
16052 }
16053 if (!identical(_immediateChild, node.parameters)) {
16054 _addParameters(node.parameters.parameters);
16055 }
16056 return null;
16057 }
16058
16059 @override
16060 Object visitNode(AstNode node) {
16061 _immediateChild = node;
16062 AstNode parent = node.parent;
16063 if (parent != null) {
16064 parent.accept(this);
16065 }
16066 return null;
16067 }
16068
16069 @override
16070 Object visitSwitchMember(SwitchMember node) {
16071 _checkStatements(node.statements);
16072 return super.visitSwitchMember(node);
16073 }
16074
16075 @override
16076 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
16077 _declarationNode = node;
16078 return null;
16079 }
16080
16081 @override
16082 Object visitTypeAlias(TypeAlias node) {
16083 _declarationNode = node;
16084 return null;
16085 }
16086
16087 void _addParameters(NodeList<FormalParameter> vars) {
16088 for (FormalParameter var2 in vars) {
16089 _addToScope(var2.identifier);
16090 }
16091 }
16092
16093 void _addToScope(SimpleIdentifier identifier) {
16094 if (identifier != null && _isInRange(identifier)) {
16095 String name = identifier.name;
16096 if (!_locals.containsKey(name)) {
16097 _locals[name] = identifier;
16098 }
16099 }
16100 }
16101
16102 void _addVariables(NodeList<VariableDeclaration> variables) {
16103 for (VariableDeclaration variable in variables) {
16104 _addToScope(variable.name);
16105 }
16106 }
16107
16108 /**
16109 * Check the given list of [statements] for any that come before the immediate
16110 * child and that define a name that would be visible to the immediate child.
16111 */
16112 void _checkStatements(List<Statement> statements) {
16113 for (Statement statement in statements) {
16114 if (identical(statement, _immediateChild)) {
16115 return;
16116 }
16117 if (statement is VariableDeclarationStatement) {
16118 _addVariables(statement.variables.variables);
16119 } else if (statement is FunctionDeclarationStatement &&
16120 !_referenceIsWithinLocalFunction) {
16121 _addToScope(statement.functionDeclaration.name);
16122 }
16123 }
16124 }
16125
16126 bool _isInRange(AstNode node) {
16127 if (_position < 0) {
16128 // if source position is not set then all nodes are in range
16129 return true;
16130 // not reached
16131 }
16132 return node.end < _position;
16133 }
16134 }
16135
16136 /**
16137 * A script tag that can optionally occur at the beginning of a compilation unit .
16138 *
16139 * > scriptTag ::=
16140 * > '#!' (~NEWLINE)* NEWLINE
16141 */
16142 class ScriptTag extends AstNode {
16143 /**
16144 * The token representing this script tag.
16145 */
16146 Token scriptTag;
16147
16148 /**
16149 * Initialize a newly created script tag.
16150 */
16151 ScriptTag(this.scriptTag);
16152
16153 @override
16154 Token get beginToken => scriptTag;
16155
16156 @override
16157 Iterable get childEntities => new ChildEntities()..add(scriptTag);
16158
16159 @override
16160 Token get endToken => scriptTag;
16161
16162 @override
16163 accept(AstVisitor visitor) => visitor.visitScriptTag(this);
16164
16165 @override
16166 void visitChildren(AstVisitor visitor) {
16167 // There are no children to visit.
16168 }
16169 }
16170
16171 /**
16172 * A combinator that restricts the names being imported to those in a given list .
16173 *
16174 * > showCombinator ::=
16175 * > 'show' [SimpleIdentifier] (',' [SimpleIdentifier])*
16176 */
16177 class ShowCombinator extends Combinator {
16178 /**
16179 * The list of names from the library that are made visible by this combinator .
16180 */
16181 NodeList<SimpleIdentifier> _shownNames;
16182
16183 /**
16184 * Initialize a newly created import show combinator.
16185 */
16186 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames)
16187 : super(keyword) {
16188 _shownNames = new NodeList<SimpleIdentifier>(this, shownNames);
16189 }
16190
16191 @override
16192 // TODO(paulberry): add commas.
16193 Iterable get childEntities => new ChildEntities()
16194 ..add(keyword)
16195 ..addAll(_shownNames);
16196
16197 @override
16198 Token get endToken => _shownNames.endToken;
16199
16200 /**
16201 * Return the list of names from the library that are made visible by this
16202 * combinator.
16203 */
16204 NodeList<SimpleIdentifier> get shownNames => _shownNames;
16205
16206 @override
16207 accept(AstVisitor visitor) => visitor.visitShowCombinator(this);
16208
16209 @override
16210 void visitChildren(AstVisitor visitor) {
16211 _shownNames.accept(visitor);
16212 }
16213 }
16214
16215 /**
16216 * An AST visitor that will do nothing when visiting an AST node. It is intended
16217 * to be a superclass for classes that use the visitor pattern primarily as a
16218 * dispatch mechanism (and hence don't need to recursively visit a whole
16219 * structure) and that only need to visit a small number of node types.
16220 */
16221 class SimpleAstVisitor<R> implements AstVisitor<R> {
16222 @override
16223 R visitAdjacentStrings(AdjacentStrings node) => null;
16224
16225 @override
16226 R visitAnnotation(Annotation node) => null;
16227
16228 @override
16229 R visitArgumentList(ArgumentList node) => null;
16230
16231 @override
16232 R visitAsExpression(AsExpression node) => null;
16233
16234 @override
16235 R visitAssertStatement(AssertStatement node) => null;
16236
16237 @override
16238 R visitAssignmentExpression(AssignmentExpression node) => null;
16239
16240 @override
16241 R visitAwaitExpression(AwaitExpression node) => null;
16242
16243 @override
16244 R visitBinaryExpression(BinaryExpression node) => null;
16245
16246 @override
16247 R visitBlock(Block node) => null;
16248
16249 @override
16250 R visitBlockFunctionBody(BlockFunctionBody node) => null;
16251
16252 @override
16253 R visitBooleanLiteral(BooleanLiteral node) => null;
16254
16255 @override
16256 R visitBreakStatement(BreakStatement node) => null;
16257
16258 @override
16259 R visitCascadeExpression(CascadeExpression node) => null;
16260
16261 @override
16262 R visitCatchClause(CatchClause node) => null;
16263
16264 @override
16265 R visitClassDeclaration(ClassDeclaration node) => null;
16266
16267 @override
16268 R visitClassTypeAlias(ClassTypeAlias node) => null;
16269
16270 @override
16271 R visitComment(Comment node) => null;
16272
16273 @override
16274 R visitCommentReference(CommentReference node) => null;
16275
16276 @override
16277 R visitCompilationUnit(CompilationUnit node) => null;
16278
16279 @override
16280 R visitConditionalExpression(ConditionalExpression node) => null;
16281
16282 @override
16283 R visitConstructorDeclaration(ConstructorDeclaration node) => null;
16284
16285 @override
16286 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => null;
16287
16288 @override
16289 R visitConstructorName(ConstructorName node) => null;
16290
16291 @override
16292 R visitContinueStatement(ContinueStatement node) => null;
16293
16294 @override
16295 R visitDeclaredIdentifier(DeclaredIdentifier node) => null;
16296
16297 @override
16298 R visitDefaultFormalParameter(DefaultFormalParameter node) => null;
16299
16300 @override
16301 R visitDoStatement(DoStatement node) => null;
16302
16303 @override
16304 R visitDoubleLiteral(DoubleLiteral node) => null;
16305
16306 @override
16307 R visitEmptyFunctionBody(EmptyFunctionBody node) => null;
16308
16309 @override
16310 R visitEmptyStatement(EmptyStatement node) => null;
16311
16312 @override
16313 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => null;
16314
16315 @override
16316 R visitEnumDeclaration(EnumDeclaration node) => null;
16317
16318 @override
16319 R visitExportDirective(ExportDirective node) => null;
16320
16321 @override
16322 R visitExpressionFunctionBody(ExpressionFunctionBody node) => null;
16323
16324 @override
16325 R visitExpressionStatement(ExpressionStatement node) => null;
16326
16327 @override
16328 R visitExtendsClause(ExtendsClause node) => null;
16329
16330 @override
16331 R visitFieldDeclaration(FieldDeclaration node) => null;
16332
16333 @override
16334 R visitFieldFormalParameter(FieldFormalParameter node) => null;
16335
16336 @override
16337 R visitForEachStatement(ForEachStatement node) => null;
16338
16339 @override
16340 R visitFormalParameterList(FormalParameterList node) => null;
16341
16342 @override
16343 R visitForStatement(ForStatement node) => null;
16344
16345 @override
16346 R visitFunctionDeclaration(FunctionDeclaration node) => null;
16347
16348 @override
16349 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
16350 null;
16351
16352 @override
16353 R visitFunctionExpression(FunctionExpression node) => null;
16354
16355 @override
16356 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
16357 null;
16358
16359 @override
16360 R visitFunctionTypeAlias(FunctionTypeAlias node) => null;
16361
16362 @override
16363 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
16364 null;
16365
16366 @override
16367 R visitHideCombinator(HideCombinator node) => null;
16368
16369 @override
16370 R visitIfStatement(IfStatement node) => null;
16371
16372 @override
16373 R visitImplementsClause(ImplementsClause node) => null;
16374
16375 @override
16376 R visitImportDirective(ImportDirective node) => null;
16377
16378 @override
16379 R visitIndexExpression(IndexExpression node) => null;
16380
16381 @override
16382 R visitInstanceCreationExpression(InstanceCreationExpression node) => null;
16383
16384 @override
16385 R visitIntegerLiteral(IntegerLiteral node) => null;
16386
16387 @override
16388 R visitInterpolationExpression(InterpolationExpression node) => null;
16389
16390 @override
16391 R visitInterpolationString(InterpolationString node) => null;
16392
16393 @override
16394 R visitIsExpression(IsExpression node) => null;
16395
16396 @override
16397 R visitLabel(Label node) => null;
16398
16399 @override
16400 R visitLabeledStatement(LabeledStatement node) => null;
16401
16402 @override
16403 R visitLibraryDirective(LibraryDirective node) => null;
16404
16405 @override
16406 R visitLibraryIdentifier(LibraryIdentifier node) => null;
16407
16408 @override
16409 R visitListLiteral(ListLiteral node) => null;
16410
16411 @override
16412 R visitMapLiteral(MapLiteral node) => null;
16413
16414 @override
16415 R visitMapLiteralEntry(MapLiteralEntry node) => null;
16416
16417 @override
16418 R visitMethodDeclaration(MethodDeclaration node) => null;
16419
16420 @override
16421 R visitMethodInvocation(MethodInvocation node) => null;
16422
16423 @override
16424 R visitNamedExpression(NamedExpression node) => null;
16425
16426 @override
16427 R visitNativeClause(NativeClause node) => null;
16428
16429 @override
16430 R visitNativeFunctionBody(NativeFunctionBody node) => null;
16431
16432 @override
16433 R visitNullLiteral(NullLiteral node) => null;
16434
16435 @override
16436 R visitParenthesizedExpression(ParenthesizedExpression node) => null;
16437
16438 @override
16439 R visitPartDirective(PartDirective node) => null;
16440
16441 @override
16442 R visitPartOfDirective(PartOfDirective node) => null;
16443
16444 @override
16445 R visitPostfixExpression(PostfixExpression node) => null;
16446
16447 @override
16448 R visitPrefixedIdentifier(PrefixedIdentifier node) => null;
16449
16450 @override
16451 R visitPrefixExpression(PrefixExpression node) => null;
16452
16453 @override
16454 R visitPropertyAccess(PropertyAccess node) => null;
16455
16456 @override
16457 R visitRedirectingConstructorInvocation(
16458 RedirectingConstructorInvocation node) =>
16459 null;
16460
16461 @override
16462 R visitRethrowExpression(RethrowExpression node) => null;
16463
16464 @override
16465 R visitReturnStatement(ReturnStatement node) => null;
16466
16467 @override
16468 R visitScriptTag(ScriptTag node) => null;
16469
16470 @override
16471 R visitShowCombinator(ShowCombinator node) => null;
16472
16473 @override
16474 R visitSimpleFormalParameter(SimpleFormalParameter node) => null;
16475
16476 @override
16477 R visitSimpleIdentifier(SimpleIdentifier node) => null;
16478
16479 @override
16480 R visitSimpleStringLiteral(SimpleStringLiteral node) => null;
16481
16482 @override
16483 R visitStringInterpolation(StringInterpolation node) => null;
16484
16485 @override
16486 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => null;
16487
16488 @override
16489 R visitSuperExpression(SuperExpression node) => null;
16490
16491 @override
16492 R visitSwitchCase(SwitchCase node) => null;
16493
16494 @override
16495 R visitSwitchDefault(SwitchDefault node) => null;
16496
16497 @override
16498 R visitSwitchStatement(SwitchStatement node) => null;
16499
16500 @override
16501 R visitSymbolLiteral(SymbolLiteral node) => null;
16502
16503 @override
16504 R visitThisExpression(ThisExpression node) => null;
16505
16506 @override
16507 R visitThrowExpression(ThrowExpression node) => null;
16508
16509 @override
16510 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => null;
16511
16512 @override
16513 R visitTryStatement(TryStatement node) => null;
16514
16515 @override
16516 R visitTypeArgumentList(TypeArgumentList node) => null;
16517
16518 @override
16519 R visitTypeName(TypeName node) => null;
16520
16521 @override
16522 R visitTypeParameter(TypeParameter node) => null;
16523
16524 @override
16525 R visitTypeParameterList(TypeParameterList node) => null;
16526
16527 @override
16528 R visitVariableDeclaration(VariableDeclaration node) => null;
16529
16530 @override
16531 R visitVariableDeclarationList(VariableDeclarationList node) => null;
16532
16533 @override
16534 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
16535 null;
16536
16537 @override
16538 R visitWhileStatement(WhileStatement node) => null;
16539
16540 @override
16541 R visitWithClause(WithClause node) => null;
16542
16543 @override
16544 R visitYieldStatement(YieldStatement node) => null;
16545 }
16546
16547 /**
16548 * A simple formal parameter.
16549 *
16550 * > simpleFormalParameter ::=
16551 * > ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier]
16552 */
16553 class SimpleFormalParameter extends NormalFormalParameter {
16554 /**
16555 * The token representing either the 'final', 'const' or 'var' keyword, or
16556 * `null` if no keyword was used.
16557 */
16558 Token keyword;
16559
16560 /**
16561 * The name of the declared type of the parameter, or `null` if the parameter
16562 * does not have a declared type.
16563 */
16564 TypeName _type;
16565
16566 /**
16567 * Initialize a newly created formal parameter. Either or both of the
16568 * [comment] and [metadata] can be `null` if the parameter does not have the
16569 * corresponding attribute. The [keyword] can be `null` if a type was
16570 * specified. The [type] must be `null` if the keyword is 'var'.
16571 */
16572 SimpleFormalParameter(Comment comment, List<Annotation> metadata,
16573 this.keyword, TypeName type, SimpleIdentifier identifier)
16574 : super(comment, metadata, identifier) {
16575 _type = _becomeParentOf(type);
16576 }
16577
16578 @override
16579 Token get beginToken {
16580 NodeList<Annotation> metadata = this.metadata;
16581 if (!metadata.isEmpty) {
16582 return metadata.beginToken;
16583 } else if (keyword != null) {
16584 return keyword;
16585 } else if (_type != null) {
16586 return _type.beginToken;
16587 }
16588 return identifier.beginToken;
16589 }
16590
16591 @override
16592 Iterable get childEntities =>
16593 super._childEntities..add(keyword)..add(_type)..add(identifier);
16594
16595 @override
16596 Token get endToken => identifier.endToken;
16597
16598 @override
16599 bool get isConst => (keyword is KeywordToken) &&
16600 (keyword as KeywordToken).keyword == Keyword.CONST;
16601
16602 @override
16603 bool get isFinal => (keyword is KeywordToken) &&
16604 (keyword as KeywordToken).keyword == Keyword.FINAL;
16605
16606 /**
16607 * Return the name of the declared type of the parameter, or `null` if the
16608 * parameter does not have a declared type.
16609 */
16610 TypeName get type => _type;
16611
16612 /**
16613 * Set the name of the declared type of the parameter to the given [typeName].
16614 */
16615 void set type(TypeName typeName) {
16616 _type = _becomeParentOf(typeName);
16617 }
16618
16619 @override
16620 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this);
16621
16622 @override
16623 void visitChildren(AstVisitor visitor) {
16624 super.visitChildren(visitor);
16625 _safelyVisitChild(_type, visitor);
16626 _safelyVisitChild(identifier, visitor);
16627 }
16628 }
16629
16630 /**
16631 * A simple identifier.
16632 *
16633 * > simpleIdentifier ::=
16634 * > initialCharacter internalCharacter*
16635 * >
16636 * > initialCharacter ::= '_' | '$' | letter
16637 * >
16638 * > internalCharacter ::= '_' | '$' | letter | digit
16639 */
16640 class SimpleIdentifier extends Identifier {
16641 /**
16642 * The token representing the identifier.
16643 */
16644 Token token;
16645
16646 /**
16647 * The element associated with this identifier based on static type
16648 * information, or `null` if the AST structure has not been resolved or if
16649 * this identifier could not be resolved.
16650 */
16651 Element _staticElement;
16652
16653 /**
16654 * The element associated with this identifier based on propagated type
16655 * information, or `null` if the AST structure has not been resolved or if
16656 * this identifier could not be resolved.
16657 */
16658 Element _propagatedElement;
16659
16660 /**
16661 * If this expression is both in a getter and setter context, the
16662 * [AuxiliaryElements] will be set to hold onto the static and propagated
16663 * information. The auxiliary element will hold onto the elements from the
16664 * getter context.
16665 */
16666 AuxiliaryElements auxiliaryElements = null;
16667
16668 /**
16669 * Initialize a newly created identifier.
16670 */
16671 SimpleIdentifier(this.token);
16672
16673 @override
16674 Token get beginToken => token;
16675
16676 @override
16677 Element get bestElement {
16678 if (_propagatedElement == null) {
16679 return _staticElement;
16680 }
16681 return _propagatedElement;
16682 }
16683
16684 @override
16685 Iterable get childEntities => new ChildEntities()..add(token);
16686
16687 @override
16688 Token get endToken => token;
16689
16690 /**
16691 * Return `true` if this identifier is the "name" part of a prefixed
16692 * identifier or a method invocation.
16693 */
16694 bool get isQualified {
16695 AstNode parent = this.parent;
16696 if (parent is PrefixedIdentifier) {
16697 return identical(parent.identifier, this);
16698 }
16699 if (parent is PropertyAccess) {
16700 return identical(parent.propertyName, this);
16701 }
16702 if (parent is MethodInvocation) {
16703 MethodInvocation invocation = parent;
16704 return identical(invocation.methodName, this) &&
16705 invocation.realTarget != null;
16706 }
16707 return false;
16708 }
16709
16710 @override
16711 bool get isSynthetic => token.isSynthetic;
16712
16713 @override
16714 String get name => token.lexeme;
16715
16716 @override
16717 int get precedence => 16;
16718
16719 @override
16720 Element get propagatedElement => _propagatedElement;
16721
16722 /**
16723 * Set the element associated with this identifier based on propagated type
16724 * information to the given [element].
16725 */
16726 void set propagatedElement(Element element) {
16727 _propagatedElement = _validateElement(element);
16728 }
16729
16730 @override
16731 Element get staticElement => _staticElement;
16732
16733 /**
16734 * Set the element associated with this identifier based on static type
16735 * information to the given [element].
16736 */
16737 void set staticElement(Element element) {
16738 _staticElement = _validateElement(element);
16739 }
16740
16741 @override
16742 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this);
16743
16744 /**
16745 * Return `true` if this identifier is the name being declared in a
16746 * declaration.
16747 */
16748 bool inDeclarationContext() {
16749 // TODO(brianwilkerson) Convert this to a getter.
16750 AstNode parent = this.parent;
16751 if (parent is CatchClause) {
16752 CatchClause clause = parent;
16753 return identical(this, clause.exceptionParameter) ||
16754 identical(this, clause.stackTraceParameter);
16755 } else if (parent is ClassDeclaration) {
16756 return identical(this, parent.name);
16757 } else if (parent is ClassTypeAlias) {
16758 return identical(this, parent.name);
16759 } else if (parent is ConstructorDeclaration) {
16760 return identical(this, parent.name);
16761 } else if (parent is DeclaredIdentifier) {
16762 return identical(this, parent.identifier);
16763 } else if (parent is EnumDeclaration) {
16764 return identical(this, parent.name);
16765 } else if (parent is EnumConstantDeclaration) {
16766 return identical(this, parent.name);
16767 } else if (parent is FunctionDeclaration) {
16768 return identical(this, parent.name);
16769 } else if (parent is FunctionTypeAlias) {
16770 return identical(this, parent.name);
16771 } else if (parent is ImportDirective) {
16772 return identical(this, parent.prefix);
16773 } else if (parent is Label) {
16774 return identical(this, parent.label) &&
16775 (parent.parent is LabeledStatement);
16776 } else if (parent is MethodDeclaration) {
16777 return identical(this, parent.name);
16778 } else if (parent is FunctionTypedFormalParameter ||
16779 parent is SimpleFormalParameter) {
16780 return identical(this, (parent as NormalFormalParameter).identifier);
16781 } else if (parent is TypeParameter) {
16782 return identical(this, parent.name);
16783 } else if (parent is VariableDeclaration) {
16784 return identical(this, parent.name);
16785 }
16786 return false;
16787 }
16788
16789 /**
16790 * Return `true` if this expression is computing a right-hand value.
16791 *
16792 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16793 * are they mutually exclusive. In other words, it is possible for both
16794 * methods to return `true` when invoked on the same node.
16795 */
16796 bool inGetterContext() {
16797 // TODO(brianwilkerson) Convert this to a getter.
16798 AstNode parent = this.parent;
16799 AstNode target = this;
16800 // skip prefix
16801 if (parent is PrefixedIdentifier) {
16802 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16803 if (identical(prefixed.prefix, this)) {
16804 return true;
16805 }
16806 parent = prefixed.parent;
16807 target = prefixed;
16808 } else if (parent is PropertyAccess) {
16809 PropertyAccess access = parent as PropertyAccess;
16810 if (identical(access.target, this)) {
16811 return true;
16812 }
16813 parent = access.parent;
16814 target = access;
16815 }
16816 // skip label
16817 if (parent is Label) {
16818 return false;
16819 }
16820 // analyze usage
16821 if (parent is AssignmentExpression) {
16822 if (identical(parent.leftHandSide, target) &&
16823 parent.operator.type == TokenType.EQ) {
16824 return false;
16825 }
16826 }
16827 if (parent is ForEachStatement) {
16828 if (identical(parent.identifier, target)) {
16829 return false;
16830 }
16831 }
16832 return true;
16833 }
16834
16835 /**
16836 * Return `true` if this expression is computing a left-hand value.
16837 *
16838 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16839 * are they mutually exclusive. In other words, it is possible for both
16840 * methods to return `true` when invoked on the same node.
16841 */
16842 bool inSetterContext() {
16843 // TODO(brianwilkerson) Convert this to a getter.
16844 AstNode parent = this.parent;
16845 AstNode target = this;
16846 // skip prefix
16847 if (parent is PrefixedIdentifier) {
16848 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16849 // if this is the prefix, then return false
16850 if (identical(prefixed.prefix, this)) {
16851 return false;
16852 }
16853 parent = prefixed.parent;
16854 target = prefixed;
16855 } else if (parent is PropertyAccess) {
16856 PropertyAccess access = parent as PropertyAccess;
16857 if (identical(access.target, this)) {
16858 return false;
16859 }
16860 parent = access.parent;
16861 target = access;
16862 }
16863 // analyze usage
16864 if (parent is PrefixExpression) {
16865 return parent.operator.type.isIncrementOperator;
16866 } else if (parent is PostfixExpression) {
16867 return true;
16868 } else if (parent is AssignmentExpression) {
16869 return identical(parent.leftHandSide, target);
16870 } else if (parent is ForEachStatement) {
16871 return identical(parent.identifier, target);
16872 }
16873 return false;
16874 }
16875
16876 @override
16877 void visitChildren(AstVisitor visitor) {
16878 // There are no children to visit.
16879 }
16880
16881 /**
16882 * Return the given element if it is valid, or report the problem and return
16883 * `null` if it is not appropriate.
16884 *
16885 * The [parent] is the parent of the element, used for reporting when there is
16886 * a problem.
16887 * The [isValid] is `true` if the element is appropriate.
16888 * The [element] is the element to be associated with this identifier.
16889 */
16890 Element _returnOrReportElement(
16891 AstNode parent, bool isValid, Element element) {
16892 if (!isValid) {
16893 AnalysisEngine.instance.logger.logInformation(
16894 "Internal error: attempting to set the name of a ${parent.runtimeType} to a ${element.runtimeType}",
16895 new CaughtException(new AnalysisException(), null));
16896 return null;
16897 }
16898 return element;
16899 }
16900
16901 /**
16902 * Return the given [element] if it is an appropriate element based on the
16903 * parent of this identifier, or `null` if it is not appropriate.
16904 */
16905 Element _validateElement(Element element) {
16906 if (element == null) {
16907 return null;
16908 }
16909 AstNode parent = this.parent;
16910 if (parent is ClassDeclaration && identical(parent.name, this)) {
16911 return _returnOrReportElement(parent, element is ClassElement, element);
16912 } else if (parent is ClassTypeAlias && identical(parent.name, this)) {
16913 return _returnOrReportElement(parent, element is ClassElement, element);
16914 } else if (parent is DeclaredIdentifier &&
16915 identical(parent.identifier, this)) {
16916 return _returnOrReportElement(
16917 parent, element is LocalVariableElement, element);
16918 } else if (parent is FormalParameter &&
16919 identical(parent.identifier, this)) {
16920 return _returnOrReportElement(
16921 parent, element is ParameterElement, element);
16922 } else if (parent is FunctionDeclaration && identical(parent.name, this)) {
16923 return _returnOrReportElement(
16924 parent, element is ExecutableElement, element);
16925 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) {
16926 return _returnOrReportElement(
16927 parent, element is FunctionTypeAliasElement, element);
16928 } else if (parent is MethodDeclaration && identical(parent.name, this)) {
16929 return _returnOrReportElement(
16930 parent, element is ExecutableElement, element);
16931 } else if (parent is TypeParameter && identical(parent.name, this)) {
16932 return _returnOrReportElement(
16933 parent, element is TypeParameterElement, element);
16934 } else if (parent is VariableDeclaration && identical(parent.name, this)) {
16935 return _returnOrReportElement(
16936 parent, element is VariableElement, element);
16937 }
16938 return element;
16939 }
16940 }
16941
16942 /**
16943 * A string literal expression that does not contain any interpolations.
16944 *
16945 * > simpleStringLiteral ::=
16946 * > rawStringLiteral
16947 * > | basicStringLiteral
16948 * >
16949 * > rawStringLiteral ::=
16950 * > 'r' basicStringLiteral
16951 * >
16952 * > simpleStringLiteral ::=
16953 * > multiLineStringLiteral
16954 * > | singleLineStringLiteral
16955 * >
16956 * > multiLineStringLiteral ::=
16957 * > "'''" characters "'''"
16958 * > | '"""' characters '"""'
16959 * >
16960 * > singleLineStringLiteral ::=
16961 * > "'" characters "'"
16962 * > | '"' characters '"'
16963 */
16964 class SimpleStringLiteral extends SingleStringLiteral {
16965 /**
16966 * The token representing the literal.
16967 */
16968 Token literal;
16969
16970 /**
16971 * The value of the literal.
16972 */
16973 String _value;
16974
16975 /**
16976 * The toolkit specific element associated with this literal, or `null`.
16977 */
16978 @deprecated // No replacement
16979 Element toolkitElement;
16980
16981 /**
16982 * Initialize a newly created simple string literal.
16983 */
16984 SimpleStringLiteral(this.literal, String value) {
16985 _value = StringUtilities.intern(value);
16986 }
16987
16988 @override
16989 Token get beginToken => literal;
16990
16991 @override
16992 Iterable get childEntities => new ChildEntities()..add(literal);
16993
16994 @override
16995 int get contentsEnd => offset + _helper.end;
16996
16997 @override
16998 int get contentsOffset => offset + _helper.start;
16999
17000 @override
17001 Token get endToken => literal;
17002
17003 @override
17004 bool get isMultiline => _helper.isMultiline;
17005
17006 @override
17007 bool get isRaw => _helper.isRaw;
17008
17009 @override
17010 bool get isSingleQuoted => _helper.isSingleQuoted;
17011
17012 @override
17013 bool get isSynthetic => literal.isSynthetic;
17014
17015 /**
17016 * Return the value of the literal.
17017 */
17018 String get value => _value;
17019
17020 /**
17021 * Set the value of the literal to the given [string].
17022 */
17023 void set value(String string) {
17024 _value = StringUtilities.intern(_value);
17025 }
17026
17027 StringLexemeHelper get _helper {
17028 return new StringLexemeHelper(literal.lexeme, true, true);
17029 }
17030
17031 @override
17032 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this);
17033
17034 @override
17035 void visitChildren(AstVisitor visitor) {
17036 // There are no children to visit.
17037 }
17038
17039 @override
17040 void _appendStringValue(StringBuffer buffer) {
17041 buffer.write(value);
17042 }
17043 }
17044
17045 /**
17046 * A single string literal expression.
17047 *
17048 * > singleStringLiteral ::=
17049 * > [SimpleStringLiteral]
17050 * > | [StringInterpolation]
17051 */
17052 abstract class SingleStringLiteral extends StringLiteral {
17053 /**
17054 * Return the offset of the after-last contents character.
17055 */
17056 int get contentsEnd;
17057
17058 /**
17059 * Return the offset of the first contents character.
17060 * If the string is multiline, then leading whitespaces are skipped.
17061 */
17062 int get contentsOffset;
17063
17064 /**
17065 * Return `true` if this string literal is a multi-line string.
17066 */
17067 bool get isMultiline;
17068
17069 /**
17070 * Return `true` if this string literal is a raw string.
17071 */
17072 bool get isRaw;
17073
17074 /**
17075 * Return `true` if this string literal uses single qoutes (' or ''').
17076 * Return `false` if this string literal uses double qoutes (" or """).
17077 */
17078 bool get isSingleQuoted;
17079 }
17080
17081 /**
17082 * A node that represents a statement.
17083 *
17084 * > statement ::=
17085 * > [Block]
17086 * > | [VariableDeclarationStatement]
17087 * > | [ForStatement]
17088 * > | [ForEachStatement]
17089 * > | [WhileStatement]
17090 * > | [DoStatement]
17091 * > | [SwitchStatement]
17092 * > | [IfStatement]
17093 * > | [TryStatement]
17094 * > | [BreakStatement]
17095 * > | [ContinueStatement]
17096 * > | [ReturnStatement]
17097 * > | [ExpressionStatement]
17098 * > | [FunctionDeclarationStatement]
17099 */
17100 abstract class Statement extends AstNode {
17101 /**
17102 * If this is a labeled statement, return the unlabeled portion of the
17103 * statement. Otherwise return the statement itself.
17104 */
17105 Statement get unlabeled => this;
17106 }
17107
17108 /**
17109 * A string interpolation literal.
17110 *
17111 * > stringInterpolation ::=
17112 * > ''' [InterpolationElement]* '''
17113 * > | '"' [InterpolationElement]* '"'
17114 */
17115 class StringInterpolation extends SingleStringLiteral {
17116 /**
17117 * The elements that will be composed to produce the resulting string.
17118 */
17119 NodeList<InterpolationElement> _elements;
17120
17121 /**
17122 * Initialize a newly created string interpolation expression.
17123 */
17124 StringInterpolation(List<InterpolationElement> elements) {
17125 _elements = new NodeList<InterpolationElement>(this, elements);
17126 }
17127
17128 @override
17129 Token get beginToken => _elements.beginToken;
17130
17131 @override
17132 Iterable get childEntities => new ChildEntities()..addAll(_elements);
17133
17134 @override
17135 int get contentsEnd {
17136 InterpolationString element = _elements.last;
17137 return element.contentsEnd;
17138 }
17139
17140 @override
17141 int get contentsOffset {
17142 InterpolationString element = _elements.first;
17143 return element.contentsOffset;
17144 }
17145
17146 /**
17147 * Return the elements that will be composed to produce the resulting string.
17148 */
17149 NodeList<InterpolationElement> get elements => _elements;
17150
17151 @override
17152 Token get endToken => _elements.endToken;
17153
17154 @override
17155 bool get isMultiline => _firstHelper.isMultiline;
17156
17157 @override
17158 bool get isRaw => false;
17159
17160 @override
17161 bool get isSingleQuoted => _firstHelper.isSingleQuoted;
17162
17163 StringLexemeHelper get _firstHelper {
17164 InterpolationString lastString = _elements.first;
17165 String lexeme = lastString.contents.lexeme;
17166 return new StringLexemeHelper(lexeme, true, false);
17167 }
17168
17169 @override
17170 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this);
17171
17172 @override
17173 void visitChildren(AstVisitor visitor) {
17174 _elements.accept(visitor);
17175 }
17176
17177 @override
17178 void _appendStringValue(StringBuffer buffer) {
17179 throw new IllegalArgumentException();
17180 }
17181 }
17182
17183 /**
17184 * A helper for analyzing string lexemes.
17185 */
17186 class StringLexemeHelper {
17187 final String lexeme;
17188 final bool isFirst;
17189 final bool isLast;
17190
17191 bool isRaw = false;
17192 bool isSingleQuoted = false;
17193 bool isMultiline = false;
17194 int start = 0;
17195 int end;
17196
17197 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) {
17198 if (isFirst) {
17199 isRaw = StringUtilities.startsWithChar(lexeme, 0x72);
17200 if (isRaw) {
17201 start++;
17202 }
17203 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) {
17204 isSingleQuoted = true;
17205 isMultiline = true;
17206 start += 3;
17207 start = _trimInitialWhitespace(start);
17208 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) {
17209 isSingleQuoted = false;
17210 isMultiline = true;
17211 start += 3;
17212 start = _trimInitialWhitespace(start);
17213 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) {
17214 isSingleQuoted = true;
17215 isMultiline = false;
17216 start++;
17217 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) {
17218 isSingleQuoted = false;
17219 isMultiline = false;
17220 start++;
17221 }
17222 }
17223 end = lexeme.length;
17224 if (isLast) {
17225 if (start + 3 <= end &&
17226 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
17227 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) {
17228 end -= 3;
17229 } else if (start + 1 <= end &&
17230 (StringUtilities.endsWithChar(lexeme, 0x22) ||
17231 StringUtilities.endsWithChar(lexeme, 0x27))) {
17232 end -= 1;
17233 }
17234 }
17235 }
17236
17237 /**
17238 * Given the [lexeme] for a multi-line string whose content begins at the
17239 * given [start] index, return the index of the first character that is
17240 * included in the value of the string. According to the specification:
17241 *
17242 * If the first line of a multiline string consists solely of the whitespace
17243 * characters defined by the production WHITESPACE 20.1), possibly prefixed
17244 * by \, then that line is ignored, including the new line at its end.
17245 */
17246 int _trimInitialWhitespace(int start) {
17247 int length = lexeme.length;
17248 int index = start;
17249 while (index < length) {
17250 int currentChar = lexeme.codeUnitAt(index);
17251 if (currentChar == 0x0D) {
17252 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
17253 return index + 2;
17254 }
17255 return index + 1;
17256 } else if (currentChar == 0x0A) {
17257 return index + 1;
17258 } else if (currentChar == 0x5C) {
17259 if (index + 1 >= length) {
17260 return start;
17261 }
17262 currentChar = lexeme.codeUnitAt(index + 1);
17263 if (currentChar != 0x0D &&
17264 currentChar != 0x0A &&
17265 currentChar != 0x09 &&
17266 currentChar != 0x20) {
17267 return start;
17268 }
17269 } else if (currentChar != 0x09 && currentChar != 0x20) {
17270 return start;
17271 }
17272 index++;
17273 }
17274 return start;
17275 }
17276 }
17277
17278 /**
17279 * A string literal expression.
17280 *
17281 * > stringLiteral ::=
17282 * > [SimpleStringLiteral]
17283 * > | [AdjacentStrings]
17284 * > | [StringInterpolation]
17285 */
17286 abstract class StringLiteral extends Literal {
17287 /**
17288 * Return the value of the string literal, or `null` if the string is not a
17289 * constant string without any string interpolation.
17290 */
17291 String get stringValue {
17292 StringBuffer buffer = new StringBuffer();
17293 try {
17294 _appendStringValue(buffer);
17295 } on IllegalArgumentException {
17296 return null;
17297 }
17298 return buffer.toString();
17299 }
17300
17301 /**
17302 * Append the value of this string literal to the given [buffer]. Throw an
17303 * [IllegalArgumentException] if the string is not a constant string without
17304 * any string interpolation.
17305 */
17306 @deprecated // Use "this.stringValue"
17307 void appendStringValue(StringBuffer buffer) => _appendStringValue(buffer);
17308
17309 /**
17310 * Append the value of this string literal to the given [buffer]. Throw an
17311 * [IllegalArgumentException] if the string is not a constant string without
17312 * any string interpolation.
17313 */
17314 void _appendStringValue(StringBuffer buffer);
17315 }
17316
17317 /**
17318 * The invocation of a superclass' constructor from within a constructor's
17319 * initialization list.
17320 *
17321 * > superInvocation ::=
17322 * > 'super' ('.' [SimpleIdentifier])? [ArgumentList]
17323 */
17324 class SuperConstructorInvocation extends ConstructorInitializer {
17325 /**
17326 * The token for the 'super' keyword.
17327 */
17328 Token superKeyword;
17329
17330 /**
17331 * The token for the period before the name of the constructor that is being
17332 * invoked, or `null` if the unnamed constructor is being invoked.
17333 */
17334 Token period;
17335
17336 /**
17337 * The name of the constructor that is being invoked, or `null` if the unnamed
17338 * constructor is being invoked.
17339 */
17340 SimpleIdentifier _constructorName;
17341
17342 /**
17343 * The list of arguments to the constructor.
17344 */
17345 ArgumentList _argumentList;
17346
17347 /**
17348 * The element associated with the constructor based on static type
17349 * information, or `null` if the AST structure has not been resolved or if the
17350 * constructor could not be resolved.
17351 */
17352 ConstructorElement staticElement;
17353
17354 /**
17355 * Initialize a newly created super invocation to invoke the inherited
17356 * constructor with the given name with the given arguments. The [period] and
17357 * [constructorName] can be `null` if the constructor being invoked is the
17358 * unnamed constructor.
17359 */
17360 SuperConstructorInvocation(this.superKeyword, this.period,
17361 SimpleIdentifier constructorName, ArgumentList argumentList) {
17362 _constructorName = _becomeParentOf(constructorName);
17363 _argumentList = _becomeParentOf(argumentList);
17364 }
17365
17366 /**
17367 * Return the list of arguments to the constructor.
17368 */
17369 ArgumentList get argumentList => _argumentList;
17370
17371 /**
17372 * Set the list of arguments to the constructor to the given [argumentList].
17373 */
17374 void set argumentList(ArgumentList argumentList) {
17375 _argumentList = _becomeParentOf(argumentList);
17376 }
17377
17378 @override
17379 Token get beginToken => superKeyword;
17380
17381 @override
17382 Iterable get childEntities => new ChildEntities()
17383 ..add(superKeyword)
17384 ..add(period)
17385 ..add(_constructorName)
17386 ..add(_argumentList);
17387
17388 /**
17389 * Return the name of the constructor that is being invoked, or `null` if the
17390 * unnamed constructor is being invoked.
17391 */
17392 SimpleIdentifier get constructorName => _constructorName;
17393
17394 /**
17395 * Set the name of the constructor that is being invoked to the given
17396 * [identifier].
17397 */
17398 void set constructorName(SimpleIdentifier identifier) {
17399 _constructorName = _becomeParentOf(identifier);
17400 }
17401
17402 @override
17403 Token get endToken => _argumentList.endToken;
17404
17405 /**
17406 * Return the token for the 'super' keyword.
17407 */
17408 @deprecated // Use "this.superKeyword"
17409 Token get keyword => superKeyword;
17410
17411 /**
17412 * Set the token for the 'super' keyword to the given [token].
17413 */
17414 @deprecated // Use "this.superKeyword"
17415 set keyword(Token token) {
17416 superKeyword = token;
17417 }
17418
17419 @override
17420 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this);
17421
17422 @override
17423 void visitChildren(AstVisitor visitor) {
17424 _safelyVisitChild(_constructorName, visitor);
17425 _safelyVisitChild(_argumentList, visitor);
17426 }
17427 }
17428
17429 /**
17430 * A super expression.
17431 *
17432 * > superExpression ::=
17433 * > 'super'
17434 */
17435 class SuperExpression extends Expression {
17436 /**
17437 * The token representing the 'super' keyword.
17438 */
17439 Token superKeyword;
17440
17441 /**
17442 * Initialize a newly created super expression.
17443 */
17444 SuperExpression(this.superKeyword);
17445
17446 @override
17447 Token get beginToken => superKeyword;
17448
17449 @override
17450 Iterable get childEntities => new ChildEntities()..add(superKeyword);
17451
17452 @override
17453 Token get endToken => superKeyword;
17454
17455 /**
17456 * Return the token for the 'super' keyword.
17457 */
17458 @deprecated // Use "this.superKeyword"
17459 Token get keyword => superKeyword;
17460
17461 /**
17462 * Set the token for the 'super' keyword to the given [token].
17463 */
17464 @deprecated // Use "this.superKeyword"
17465 set keyword(Token token) {
17466 superKeyword = token;
17467 }
17468
17469 @override
17470 int get precedence => 16;
17471
17472 @override
17473 accept(AstVisitor visitor) => visitor.visitSuperExpression(this);
17474
17475 @override
17476 void visitChildren(AstVisitor visitor) {
17477 // There are no children to visit.
17478 }
17479 }
17480
17481 /**
17482 * A case in a switch statement.
17483 *
17484 * > switchCase ::=
17485 * > [SimpleIdentifier]* 'case' [Expression] ':' [Statement]*
17486 */
17487 class SwitchCase extends SwitchMember {
17488 /**
17489 * The expression controlling whether the statements will be executed.
17490 */
17491 Expression _expression;
17492
17493 /**
17494 * Initialize a newly created switch case. The list of [labels] can be `null`
17495 * if there are no labels.
17496 */
17497 SwitchCase(List<Label> labels, Token keyword, Expression expression,
17498 Token colon, List<Statement> statements)
17499 : super(labels, keyword, colon, statements) {
17500 _expression = _becomeParentOf(expression);
17501 }
17502
17503 @override
17504 Iterable get childEntities => new ChildEntities()
17505 ..addAll(labels)
17506 ..add(keyword)
17507 ..add(_expression)
17508 ..add(colon)
17509 ..addAll(statements);
17510
17511 /**
17512 * Return the expression controlling whether the statements will be executed.
17513 */
17514 Expression get expression => _expression;
17515
17516 /**
17517 * Set the expression controlling whether the statements will be executed to
17518 * the given [expression].
17519 */
17520 void set expression(Expression expression) {
17521 _expression = _becomeParentOf(expression);
17522 }
17523
17524 @override
17525 accept(AstVisitor visitor) => visitor.visitSwitchCase(this);
17526
17527 @override
17528 void visitChildren(AstVisitor visitor) {
17529 labels.accept(visitor);
17530 _safelyVisitChild(_expression, visitor);
17531 statements.accept(visitor);
17532 }
17533 }
17534
17535 /**
17536 * The default case in a switch statement.
17537 *
17538 * > switchDefault ::=
17539 * > [SimpleIdentifier]* 'default' ':' [Statement]*
17540 */
17541 class SwitchDefault extends SwitchMember {
17542 /**
17543 * Initialize a newly created switch default. The list of [labels] can be
17544 * `null` if there are no labels.
17545 */
17546 SwitchDefault(List<Label> labels, Token keyword, Token colon,
17547 List<Statement> statements)
17548 : super(labels, keyword, colon, statements);
17549
17550 @override
17551 Iterable get childEntities => new ChildEntities()
17552 ..addAll(labels)
17553 ..add(keyword)
17554 ..add(colon)
17555 ..addAll(statements);
17556
17557 @override
17558 accept(AstVisitor visitor) => visitor.visitSwitchDefault(this);
17559
17560 @override
17561 void visitChildren(AstVisitor visitor) {
17562 labels.accept(visitor);
17563 statements.accept(visitor);
17564 }
17565 }
17566
17567 /**
17568 * An element within a switch statement.
17569 *
17570 * > switchMember ::=
17571 * > switchCase
17572 * > | switchDefault
17573 */
17574 abstract class SwitchMember extends AstNode {
17575 /**
17576 * The labels associated with the switch member.
17577 */
17578 NodeList<Label> _labels;
17579
17580 /**
17581 * The token representing the 'case' or 'default' keyword.
17582 */
17583 Token keyword;
17584
17585 /**
17586 * The colon separating the keyword or the expression from the statements.
17587 */
17588 Token colon;
17589
17590 /**
17591 * The statements that will be executed if this switch member is selected.
17592 */
17593 NodeList<Statement> _statements;
17594
17595 /**
17596 * Initialize a newly created switch member. The list of [labels] can be
17597 * `null` if there are no labels.
17598 */
17599 SwitchMember(List<Label> labels, this.keyword, this.colon,
17600 List<Statement> statements) {
17601 _labels = new NodeList<Label>(this, labels);
17602 _statements = new NodeList<Statement>(this, statements);
17603 }
17604
17605 @override
17606 Token get beginToken {
17607 if (!_labels.isEmpty) {
17608 return _labels.beginToken;
17609 }
17610 return keyword;
17611 }
17612
17613 @override
17614 Token get endToken {
17615 if (!_statements.isEmpty) {
17616 return _statements.endToken;
17617 }
17618 return colon;
17619 }
17620
17621 /**
17622 * Return the labels associated with the switch member.
17623 */
17624 NodeList<Label> get labels => _labels;
17625
17626 /**
17627 * Return the statements that will be executed if this switch member is
17628 * selected.
17629 */
17630 NodeList<Statement> get statements => _statements;
17631 }
17632
17633 /**
17634 * A switch statement.
17635 *
17636 * > switchStatement ::=
17637 * > 'switch' '(' [Expression] ')' '{' [SwitchCase]* [SwitchDefault]? '}'
17638 */
17639 class SwitchStatement extends Statement {
17640 /**
17641 * The token representing the 'switch' keyword.
17642 */
17643 Token switchKeyword;
17644
17645 /**
17646 * The left parenthesis.
17647 */
17648 Token leftParenthesis;
17649
17650 /**
17651 * The expression used to determine which of the switch members will be
17652 * selected.
17653 */
17654 Expression _expression;
17655
17656 /**
17657 * The right parenthesis.
17658 */
17659 Token rightParenthesis;
17660
17661 /**
17662 * The left curly bracket.
17663 */
17664 Token leftBracket;
17665
17666 /**
17667 * The switch members that can be selected by the expression.
17668 */
17669 NodeList<SwitchMember> _members;
17670
17671 /**
17672 * The right curly bracket.
17673 */
17674 Token rightBracket;
17675
17676 /**
17677 * Initialize a newly created switch statement. The list of [members] can be
17678 * `null` if there are no switch members.
17679 */
17680 SwitchStatement(
17681 this.switchKeyword,
17682 this.leftParenthesis,
17683 Expression expression,
17684 this.rightParenthesis,
17685 this.leftBracket,
17686 List<SwitchMember> members,
17687 this.rightBracket) {
17688 _expression = _becomeParentOf(expression);
17689 _members = new NodeList<SwitchMember>(this, members);
17690 }
17691
17692 @override
17693 Token get beginToken => switchKeyword;
17694
17695 @override
17696 Iterable get childEntities => new ChildEntities()
17697 ..add(switchKeyword)
17698 ..add(leftParenthesis)
17699 ..add(_expression)
17700 ..add(rightParenthesis)
17701 ..add(leftBracket)
17702 ..addAll(_members)
17703 ..add(rightBracket);
17704
17705 @override
17706 Token get endToken => rightBracket;
17707
17708 /**
17709 * Return the expression used to determine which of the switch members will be
17710 * selected.
17711 */
17712 Expression get expression => _expression;
17713
17714 /**
17715 * Set the expression used to determine which of the switch members will be
17716 * selected to the given [expression].
17717 */
17718 void set expression(Expression expression) {
17719 _expression = _becomeParentOf(expression);
17720 }
17721
17722 /**
17723 * Return the token representing the 'switch' keyword.
17724 */
17725 @deprecated // Use "this.switchKeyword"
17726 Token get keyword => switchKeyword;
17727
17728 /**
17729 * Set the token representing the 'switch' keyword to the given [token].
17730 */
17731 @deprecated // Use "this.switchKeyword"
17732 set keyword(Token token) {
17733 switchKeyword = token;
17734 }
17735
17736 /**
17737 * Return the switch members that can be selected by the expression.
17738 */
17739 NodeList<SwitchMember> get members => _members;
17740
17741 @override
17742 accept(AstVisitor visitor) => visitor.visitSwitchStatement(this);
17743
17744 @override
17745 void visitChildren(AstVisitor visitor) {
17746 _safelyVisitChild(_expression, visitor);
17747 _members.accept(visitor);
17748 }
17749 }
17750
17751 /**
17752 * A symbol literal expression.
17753 *
17754 * > symbolLiteral ::=
17755 * > '#' (operator | (identifier ('.' identifier)*))
17756 */
17757 class SymbolLiteral extends Literal {
17758 /**
17759 * The token introducing the literal.
17760 */
17761 Token poundSign;
17762
17763 /**
17764 * The components of the literal.
17765 */
17766 final List<Token> components;
17767
17768 /**
17769 * Initialize a newly created symbol literal.
17770 */
17771 SymbolLiteral(this.poundSign, this.components);
17772
17773 @override
17774 Token get beginToken => poundSign;
17775
17776 @override
17777 // TODO(paulberry): add "." tokens.
17778 Iterable get childEntities => new ChildEntities()
17779 ..add(poundSign)
17780 ..addAll(components);
17781
17782 @override
17783 Token get endToken => components[components.length - 1];
17784
17785 @override
17786 accept(AstVisitor visitor) => visitor.visitSymbolLiteral(this);
17787
17788 @override
17789 void visitChildren(AstVisitor visitor) {
17790 // There are no children to visit.
17791 }
17792 }
17793
17794 /**
17795 * A this expression.
17796 *
17797 * > thisExpression ::=
17798 * > 'this'
17799 */
17800 class ThisExpression extends Expression {
17801 /**
17802 * The token representing the 'this' keyword.
17803 */
17804 Token thisKeyword;
17805
17806 /**
17807 * Initialize a newly created this expression.
17808 */
17809 ThisExpression(this.thisKeyword);
17810
17811 @override
17812 Token get beginToken => thisKeyword;
17813
17814 @override
17815 Iterable get childEntities => new ChildEntities()..add(thisKeyword);
17816
17817 @override
17818 Token get endToken => thisKeyword;
17819
17820 /**
17821 * Return the token representing the 'this' keyword.
17822 */
17823 @deprecated // Use "this.thisKeyword"
17824 Token get keyword => thisKeyword;
17825
17826 /**
17827 * Set the token representing the 'this' keyword to the given [token].
17828 */
17829 @deprecated // Use "this.thisKeyword"
17830 set keyword(Token token) {
17831 thisKeyword = token;
17832 }
17833
17834 @override
17835 int get precedence => 16;
17836
17837 @override
17838 accept(AstVisitor visitor) => visitor.visitThisExpression(this);
17839
17840 @override
17841 void visitChildren(AstVisitor visitor) {
17842 // There are no children to visit.
17843 }
17844 }
17845
17846 /**
17847 * A throw expression.
17848 *
17849 * > throwExpression ::=
17850 * > 'throw' [Expression]
17851 */
17852 class ThrowExpression extends Expression {
17853 /**
17854 * The token representing the 'throw' keyword.
17855 */
17856 Token throwKeyword;
17857
17858 /**
17859 * The expression computing the exception to be thrown.
17860 */
17861 Expression _expression;
17862
17863 /**
17864 * Initialize a newly created throw expression.
17865 */
17866 ThrowExpression(this.throwKeyword, Expression expression) {
17867 _expression = _becomeParentOf(expression);
17868 }
17869
17870 @override
17871 Token get beginToken => throwKeyword;
17872
17873 @override
17874 Iterable get childEntities =>
17875 new ChildEntities()..add(throwKeyword)..add(_expression);
17876
17877 @override
17878 Token get endToken {
17879 if (_expression != null) {
17880 return _expression.endToken;
17881 }
17882 return throwKeyword;
17883 }
17884
17885 /**
17886 * Return the expression computing the exception to be thrown.
17887 */
17888 Expression get expression => _expression;
17889
17890 /**
17891 * Set the expression computing the exception to be thrown to the given
17892 * [expression].
17893 */
17894 void set expression(Expression expression) {
17895 _expression = _becomeParentOf(expression);
17896 }
17897
17898 /**
17899 * Return the token representing the 'throw' keyword.
17900 */
17901 @deprecated // Use "this.throwKeyword"
17902 Token get keyword => throwKeyword;
17903
17904 /**
17905 * Set the token representing the 'throw' keyword to the given [token].
17906 */
17907 @deprecated // Use "this.throwKeyword"
17908 set keyword(Token token) {
17909 throwKeyword = token;
17910 }
17911
17912 @override
17913 int get precedence => 0;
17914
17915 @override
17916 accept(AstVisitor visitor) => visitor.visitThrowExpression(this);
17917
17918 @override
17919 void visitChildren(AstVisitor visitor) {
17920 _safelyVisitChild(_expression, visitor);
17921 }
17922 }
17923
17924 /**
17925 * The declaration of one or more top-level variables of the same type.
17926 *
17927 * > topLevelVariableDeclaration ::=
17928 * > ('final' | 'const') type? staticFinalDeclarationList ';'
17929 * > | variableDeclaration ';'
17930 */
17931 class TopLevelVariableDeclaration extends CompilationUnitMember {
17932 /**
17933 * The top-level variables being declared.
17934 */
17935 VariableDeclarationList _variableList;
17936
17937 /**
17938 * The semicolon terminating the declaration.
17939 */
17940 Token semicolon;
17941
17942 /**
17943 * Initialize a newly created top-level variable declaration. Either or both
17944 * of the [comment] and [metadata] can be `null` if the variable does not have
17945 * the corresponding attribute.
17946 */
17947 TopLevelVariableDeclaration(Comment comment, List<Annotation> metadata,
17948 VariableDeclarationList variableList, this.semicolon)
17949 : super(comment, metadata) {
17950 _variableList = _becomeParentOf(variableList);
17951 }
17952
17953 @override
17954 Iterable get childEntities =>
17955 super._childEntities..add(_variableList)..add(semicolon);
17956
17957 @override
17958 Element get element => null;
17959
17960 @override
17961 Token get endToken => semicolon;
17962
17963 @override
17964 Token get firstTokenAfterCommentAndMetadata => _variableList.beginToken;
17965
17966 /**
17967 * Return the top-level variables being declared.
17968 */
17969 VariableDeclarationList get variables => _variableList;
17970
17971 /**
17972 * Set the top-level variables being declared to the given list of
17973 * [variables].
17974 */
17975 void set variables(VariableDeclarationList variables) {
17976 _variableList = _becomeParentOf(variables);
17977 }
17978
17979 @override
17980 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this);
17981
17982 @override
17983 void visitChildren(AstVisitor visitor) {
17984 super.visitChildren(visitor);
17985 _safelyVisitChild(_variableList, visitor);
17986 }
17987 }
17988
17989 /**
17990 * A visitor used to write a source representation of a visited AST node (and
17991 * all of it's children) to a writer.
17992 */
17993 class ToSourceVisitor implements AstVisitor<Object> {
17994 /**
17995 * The writer to which the source is to be written.
17996 */
17997 final PrintWriter _writer;
17998
17999 /**
18000 * Initialize a newly created visitor to write source code representing the
18001 * visited nodes to the given [writer].
18002 */
18003 ToSourceVisitor(this._writer);
18004
18005 @override
18006 Object visitAdjacentStrings(AdjacentStrings node) {
18007 _visitNodeListWithSeparator(node.strings, " ");
18008 return null;
18009 }
18010
18011 @override
18012 Object visitAnnotation(Annotation node) {
18013 _writer.print('@');
18014 _visitNode(node.name);
18015 _visitNodeWithPrefix(".", node.constructorName);
18016 _visitNode(node.arguments);
18017 return null;
18018 }
18019
18020 @override
18021 Object visitArgumentList(ArgumentList node) {
18022 _writer.print('(');
18023 _visitNodeListWithSeparator(node.arguments, ", ");
18024 _writer.print(')');
18025 return null;
18026 }
18027
18028 @override
18029 Object visitAsExpression(AsExpression node) {
18030 _visitNode(node.expression);
18031 _writer.print(" as ");
18032 _visitNode(node.type);
18033 return null;
18034 }
18035
18036 @override
18037 Object visitAssertStatement(AssertStatement node) {
18038 _writer.print("assert (");
18039 _visitNode(node.condition);
18040 _writer.print(");");
18041 return null;
18042 }
18043
18044 @override
18045 Object visitAssignmentExpression(AssignmentExpression node) {
18046 _visitNode(node.leftHandSide);
18047 _writer.print(' ');
18048 _writer.print(node.operator.lexeme);
18049 _writer.print(' ');
18050 _visitNode(node.rightHandSide);
18051 return null;
18052 }
18053
18054 @override
18055 Object visitAwaitExpression(AwaitExpression node) {
18056 _writer.print("await ");
18057 _visitNode(node.expression);
18058 return null;
18059 }
18060
18061 @override
18062 Object visitBinaryExpression(BinaryExpression node) {
18063 _visitNode(node.leftOperand);
18064 _writer.print(' ');
18065 _writer.print(node.operator.lexeme);
18066 _writer.print(' ');
18067 _visitNode(node.rightOperand);
18068 return null;
18069 }
18070
18071 @override
18072 Object visitBlock(Block node) {
18073 _writer.print('{');
18074 _visitNodeListWithSeparator(node.statements, " ");
18075 _writer.print('}');
18076 return null;
18077 }
18078
18079 @override
18080 Object visitBlockFunctionBody(BlockFunctionBody node) {
18081 Token keyword = node.keyword;
18082 if (keyword != null) {
18083 _writer.print(keyword.lexeme);
18084 if (node.star != null) {
18085 _writer.print('*');
18086 }
18087 _writer.print(' ');
18088 }
18089 _visitNode(node.block);
18090 return null;
18091 }
18092
18093 @override
18094 Object visitBooleanLiteral(BooleanLiteral node) {
18095 _writer.print(node.literal.lexeme);
18096 return null;
18097 }
18098
18099 @override
18100 Object visitBreakStatement(BreakStatement node) {
18101 _writer.print("break");
18102 _visitNodeWithPrefix(" ", node.label);
18103 _writer.print(";");
18104 return null;
18105 }
18106
18107 @override
18108 Object visitCascadeExpression(CascadeExpression node) {
18109 _visitNode(node.target);
18110 _visitNodeList(node.cascadeSections);
18111 return null;
18112 }
18113
18114 @override
18115 Object visitCatchClause(CatchClause node) {
18116 _visitNodeWithPrefix("on ", node.exceptionType);
18117 if (node.catchKeyword != null) {
18118 if (node.exceptionType != null) {
18119 _writer.print(' ');
18120 }
18121 _writer.print("catch (");
18122 _visitNode(node.exceptionParameter);
18123 _visitNodeWithPrefix(", ", node.stackTraceParameter);
18124 _writer.print(") ");
18125 } else {
18126 _writer.print(" ");
18127 }
18128 _visitNode(node.body);
18129 return null;
18130 }
18131
18132 @override
18133 Object visitClassDeclaration(ClassDeclaration node) {
18134 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18135 _visitTokenWithSuffix(node.abstractKeyword, " ");
18136 _writer.print("class ");
18137 _visitNode(node.name);
18138 _visitNode(node.typeParameters);
18139 _visitNodeWithPrefix(" ", node.extendsClause);
18140 _visitNodeWithPrefix(" ", node.withClause);
18141 _visitNodeWithPrefix(" ", node.implementsClause);
18142 _writer.print(" {");
18143 _visitNodeListWithSeparator(node.members, " ");
18144 _writer.print("}");
18145 return null;
18146 }
18147
18148 @override
18149 Object visitClassTypeAlias(ClassTypeAlias node) {
18150 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18151 if (node.abstractKeyword != null) {
18152 _writer.print("abstract ");
18153 }
18154 _writer.print("class ");
18155 _visitNode(node.name);
18156 _visitNode(node.typeParameters);
18157 _writer.print(" = ");
18158 _visitNode(node.superclass);
18159 _visitNodeWithPrefix(" ", node.withClause);
18160 _visitNodeWithPrefix(" ", node.implementsClause);
18161 _writer.print(";");
18162 return null;
18163 }
18164
18165 @override
18166 Object visitComment(Comment node) => null;
18167
18168 @override
18169 Object visitCommentReference(CommentReference node) => null;
18170
18171 @override
18172 Object visitCompilationUnit(CompilationUnit node) {
18173 ScriptTag scriptTag = node.scriptTag;
18174 NodeList<Directive> directives = node.directives;
18175 _visitNode(scriptTag);
18176 String prefix = scriptTag == null ? "" : " ";
18177 _visitNodeListWithSeparatorAndPrefix(prefix, directives, " ");
18178 prefix = scriptTag == null && directives.isEmpty ? "" : " ";
18179 _visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, " ");
18180 return null;
18181 }
18182
18183 @override
18184 Object visitConditionalExpression(ConditionalExpression node) {
18185 _visitNode(node.condition);
18186 _writer.print(" ? ");
18187 _visitNode(node.thenExpression);
18188 _writer.print(" : ");
18189 _visitNode(node.elseExpression);
18190 return null;
18191 }
18192
18193 @override
18194 Object visitConstructorDeclaration(ConstructorDeclaration node) {
18195 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18196 _visitTokenWithSuffix(node.externalKeyword, " ");
18197 _visitTokenWithSuffix(node.constKeyword, " ");
18198 _visitTokenWithSuffix(node.factoryKeyword, " ");
18199 _visitNode(node.returnType);
18200 _visitNodeWithPrefix(".", node.name);
18201 _visitNode(node.parameters);
18202 _visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", ");
18203 _visitNodeWithPrefix(" = ", node.redirectedConstructor);
18204 _visitFunctionWithPrefix(" ", node.body);
18205 return null;
18206 }
18207
18208 @override
18209 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
18210 _visitTokenWithSuffix(node.thisKeyword, ".");
18211 _visitNode(node.fieldName);
18212 _writer.print(" = ");
18213 _visitNode(node.expression);
18214 return null;
18215 }
18216
18217 @override
18218 Object visitConstructorName(ConstructorName node) {
18219 _visitNode(node.type);
18220 _visitNodeWithPrefix(".", node.name);
18221 return null;
18222 }
18223
18224 @override
18225 Object visitContinueStatement(ContinueStatement node) {
18226 _writer.print("continue");
18227 _visitNodeWithPrefix(" ", node.label);
18228 _writer.print(";");
18229 return null;
18230 }
18231
18232 @override
18233 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
18234 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18235 _visitTokenWithSuffix(node.keyword, " ");
18236 _visitNodeWithSuffix(node.type, " ");
18237 _visitNode(node.identifier);
18238 return null;
18239 }
18240
18241 @override
18242 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
18243 _visitNode(node.parameter);
18244 if (node.separator != null) {
18245 _writer.print(" ");
18246 _writer.print(node.separator.lexeme);
18247 _visitNodeWithPrefix(" ", node.defaultValue);
18248 }
18249 return null;
18250 }
18251
18252 @override
18253 Object visitDoStatement(DoStatement node) {
18254 _writer.print("do ");
18255 _visitNode(node.body);
18256 _writer.print(" while (");
18257 _visitNode(node.condition);
18258 _writer.print(");");
18259 return null;
18260 }
18261
18262 @override
18263 Object visitDoubleLiteral(DoubleLiteral node) {
18264 _writer.print(node.literal.lexeme);
18265 return null;
18266 }
18267
18268 @override
18269 Object visitEmptyFunctionBody(EmptyFunctionBody node) {
18270 _writer.print(';');
18271 return null;
18272 }
18273
18274 @override
18275 Object visitEmptyStatement(EmptyStatement node) {
18276 _writer.print(';');
18277 return null;
18278 }
18279
18280 @override
18281 Object visitEnumConstantDeclaration(EnumConstantDeclaration node) {
18282 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18283 _visitNode(node.name);
18284 return null;
18285 }
18286
18287 @override
18288 Object visitEnumDeclaration(EnumDeclaration node) {
18289 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18290 _writer.print("enum ");
18291 _visitNode(node.name);
18292 _writer.print(" {");
18293 _visitNodeListWithSeparator(node.constants, ", ");
18294 _writer.print("}");
18295 return null;
18296 }
18297
18298 @override
18299 Object visitExportDirective(ExportDirective node) {
18300 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18301 _writer.print("export ");
18302 _visitNode(node.uri);
18303 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
18304 _writer.print(';');
18305 return null;
18306 }
18307
18308 @override
18309 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
18310 Token keyword = node.keyword;
18311 if (keyword != null) {
18312 _writer.print(keyword.lexeme);
18313 _writer.print(' ');
18314 }
18315 _writer.print("=> ");
18316 _visitNode(node.expression);
18317 if (node.semicolon != null) {
18318 _writer.print(';');
18319 }
18320 return null;
18321 }
18322
18323 @override
18324 Object visitExpressionStatement(ExpressionStatement node) {
18325 _visitNode(node.expression);
18326 _writer.print(';');
18327 return null;
18328 }
18329
18330 @override
18331 Object visitExtendsClause(ExtendsClause node) {
18332 _writer.print("extends ");
18333 _visitNode(node.superclass);
18334 return null;
18335 }
18336
18337 @override
18338 Object visitFieldDeclaration(FieldDeclaration node) {
18339 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18340 _visitTokenWithSuffix(node.staticKeyword, " ");
18341 _visitNode(node.fields);
18342 _writer.print(";");
18343 return null;
18344 }
18345
18346 @override
18347 Object visitFieldFormalParameter(FieldFormalParameter node) {
18348 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18349 _visitTokenWithSuffix(node.keyword, " ");
18350 _visitNodeWithSuffix(node.type, " ");
18351 _writer.print("this.");
18352 _visitNode(node.identifier);
18353 _visitNode(node.typeParameters);
18354 _visitNode(node.parameters);
18355 return null;
18356 }
18357
18358 @override
18359 Object visitForEachStatement(ForEachStatement node) {
18360 DeclaredIdentifier loopVariable = node.loopVariable;
18361 if (node.awaitKeyword != null) {
18362 _writer.print("await ");
18363 }
18364 _writer.print("for (");
18365 if (loopVariable == null) {
18366 _visitNode(node.identifier);
18367 } else {
18368 _visitNode(loopVariable);
18369 }
18370 _writer.print(" in ");
18371 _visitNode(node.iterable);
18372 _writer.print(") ");
18373 _visitNode(node.body);
18374 return null;
18375 }
18376
18377 @override
18378 Object visitFormalParameterList(FormalParameterList node) {
18379 String groupEnd = null;
18380 _writer.print('(');
18381 NodeList<FormalParameter> parameters = node.parameters;
18382 int size = parameters.length;
18383 for (int i = 0; i < size; i++) {
18384 FormalParameter parameter = parameters[i];
18385 if (i > 0) {
18386 _writer.print(", ");
18387 }
18388 if (groupEnd == null && parameter is DefaultFormalParameter) {
18389 if (parameter.kind == ParameterKind.NAMED) {
18390 groupEnd = "}";
18391 _writer.print('{');
18392 } else {
18393 groupEnd = "]";
18394 _writer.print('[');
18395 }
18396 }
18397 parameter.accept(this);
18398 }
18399 if (groupEnd != null) {
18400 _writer.print(groupEnd);
18401 }
18402 _writer.print(')');
18403 return null;
18404 }
18405
18406 @override
18407 Object visitForStatement(ForStatement node) {
18408 Expression initialization = node.initialization;
18409 _writer.print("for (");
18410 if (initialization != null) {
18411 _visitNode(initialization);
18412 } else {
18413 _visitNode(node.variables);
18414 }
18415 _writer.print(";");
18416 _visitNodeWithPrefix(" ", node.condition);
18417 _writer.print(";");
18418 _visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", ");
18419 _writer.print(") ");
18420 _visitNode(node.body);
18421 return null;
18422 }
18423
18424 @override
18425 Object visitFunctionDeclaration(FunctionDeclaration node) {
18426 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18427 _visitTokenWithSuffix(node.externalKeyword, " ");
18428 _visitNodeWithSuffix(node.returnType, " ");
18429 _visitTokenWithSuffix(node.propertyKeyword, " ");
18430 _visitNode(node.name);
18431 _visitNode(node.functionExpression);
18432 return null;
18433 }
18434
18435 @override
18436 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
18437 _visitNode(node.functionDeclaration);
18438 return null;
18439 }
18440
18441 @override
18442 Object visitFunctionExpression(FunctionExpression node) {
18443 _visitNode(node.typeParameters);
18444 _visitNode(node.parameters);
18445 if (node.body is! EmptyFunctionBody) {
18446 _writer.print(' ');
18447 }
18448 _visitNode(node.body);
18449 return null;
18450 }
18451
18452 @override
18453 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
18454 _visitNode(node.function);
18455 _visitNode(node.typeArguments);
18456 _visitNode(node.argumentList);
18457 return null;
18458 }
18459
18460 @override
18461 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
18462 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18463 _writer.print("typedef ");
18464 _visitNodeWithSuffix(node.returnType, " ");
18465 _visitNode(node.name);
18466 _visitNode(node.typeParameters);
18467 _visitNode(node.parameters);
18468 _writer.print(";");
18469 return null;
18470 }
18471
18472 @override
18473 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
18474 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18475 _visitNodeWithSuffix(node.returnType, " ");
18476 _visitNode(node.identifier);
18477 _visitNode(node.typeParameters);
18478 _visitNode(node.parameters);
18479 return null;
18480 }
18481
18482 @override
18483 Object visitHideCombinator(HideCombinator node) {
18484 _writer.print("hide ");
18485 _visitNodeListWithSeparator(node.hiddenNames, ", ");
18486 return null;
18487 }
18488
18489 @override
18490 Object visitIfStatement(IfStatement node) {
18491 _writer.print("if (");
18492 _visitNode(node.condition);
18493 _writer.print(") ");
18494 _visitNode(node.thenStatement);
18495 _visitNodeWithPrefix(" else ", node.elseStatement);
18496 return null;
18497 }
18498
18499 @override
18500 Object visitImplementsClause(ImplementsClause node) {
18501 _writer.print("implements ");
18502 _visitNodeListWithSeparator(node.interfaces, ", ");
18503 return null;
18504 }
18505
18506 @override
18507 Object visitImportDirective(ImportDirective node) {
18508 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18509 _writer.print("import ");
18510 _visitNode(node.uri);
18511 if (node.deferredKeyword != null) {
18512 _writer.print(" deferred");
18513 }
18514 _visitNodeWithPrefix(" as ", node.prefix);
18515 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
18516 _writer.print(';');
18517 return null;
18518 }
18519
18520 @override
18521 Object visitIndexExpression(IndexExpression node) {
18522 if (node.isCascaded) {
18523 _writer.print("..");
18524 } else {
18525 _visitNode(node.target);
18526 }
18527 _writer.print('[');
18528 _visitNode(node.index);
18529 _writer.print(']');
18530 return null;
18531 }
18532
18533 @override
18534 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
18535 _visitTokenWithSuffix(node.keyword, " ");
18536 _visitNode(node.constructorName);
18537 _visitNode(node.argumentList);
18538 return null;
18539 }
18540
18541 @override
18542 Object visitIntegerLiteral(IntegerLiteral node) {
18543 _writer.print(node.literal.lexeme);
18544 return null;
18545 }
18546
18547 @override
18548 Object visitInterpolationExpression(InterpolationExpression node) {
18549 if (node.rightBracket != null) {
18550 _writer.print("\${");
18551 _visitNode(node.expression);
18552 _writer.print("}");
18553 } else {
18554 _writer.print("\$");
18555 _visitNode(node.expression);
18556 }
18557 return null;
18558 }
18559
18560 @override
18561 Object visitInterpolationString(InterpolationString node) {
18562 _writer.print(node.contents.lexeme);
18563 return null;
18564 }
18565
18566 @override
18567 Object visitIsExpression(IsExpression node) {
18568 _visitNode(node.expression);
18569 if (node.notOperator == null) {
18570 _writer.print(" is ");
18571 } else {
18572 _writer.print(" is! ");
18573 }
18574 _visitNode(node.type);
18575 return null;
18576 }
18577
18578 @override
18579 Object visitLabel(Label node) {
18580 _visitNode(node.label);
18581 _writer.print(":");
18582 return null;
18583 }
18584
18585 @override
18586 Object visitLabeledStatement(LabeledStatement node) {
18587 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18588 _visitNode(node.statement);
18589 return null;
18590 }
18591
18592 @override
18593 Object visitLibraryDirective(LibraryDirective node) {
18594 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18595 _writer.print("library ");
18596 _visitNode(node.name);
18597 _writer.print(';');
18598 return null;
18599 }
18600
18601 @override
18602 Object visitLibraryIdentifier(LibraryIdentifier node) {
18603 _writer.print(node.name);
18604 return null;
18605 }
18606
18607 @override
18608 Object visitListLiteral(ListLiteral node) {
18609 if (node.constKeyword != null) {
18610 _writer.print(node.constKeyword.lexeme);
18611 _writer.print(' ');
18612 }
18613 _visitNodeWithSuffix(node.typeArguments, " ");
18614 _writer.print("[");
18615 _visitNodeListWithSeparator(node.elements, ", ");
18616 _writer.print("]");
18617 return null;
18618 }
18619
18620 @override
18621 Object visitMapLiteral(MapLiteral node) {
18622 if (node.constKeyword != null) {
18623 _writer.print(node.constKeyword.lexeme);
18624 _writer.print(' ');
18625 }
18626 _visitNodeWithSuffix(node.typeArguments, " ");
18627 _writer.print("{");
18628 _visitNodeListWithSeparator(node.entries, ", ");
18629 _writer.print("}");
18630 return null;
18631 }
18632
18633 @override
18634 Object visitMapLiteralEntry(MapLiteralEntry node) {
18635 _visitNode(node.key);
18636 _writer.print(" : ");
18637 _visitNode(node.value);
18638 return null;
18639 }
18640
18641 @override
18642 Object visitMethodDeclaration(MethodDeclaration node) {
18643 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18644 _visitTokenWithSuffix(node.externalKeyword, " ");
18645 _visitTokenWithSuffix(node.modifierKeyword, " ");
18646 _visitNodeWithSuffix(node.returnType, " ");
18647 _visitTokenWithSuffix(node.propertyKeyword, " ");
18648 _visitTokenWithSuffix(node.operatorKeyword, " ");
18649 _visitNode(node.name);
18650 if (!node.isGetter) {
18651 _visitNode(node.typeParameters);
18652 _visitNode(node.parameters);
18653 }
18654 _visitFunctionWithPrefix(" ", node.body);
18655 return null;
18656 }
18657
18658 @override
18659 Object visitMethodInvocation(MethodInvocation node) {
18660 if (node.isCascaded) {
18661 _writer.print("..");
18662 } else {
18663 if (node.target != null) {
18664 node.target.accept(this);
18665 _writer.print(node.operator.lexeme);
18666 }
18667 }
18668 _visitNode(node.methodName);
18669 _visitNode(node.typeArguments);
18670 _visitNode(node.argumentList);
18671 return null;
18672 }
18673
18674 @override
18675 Object visitNamedExpression(NamedExpression node) {
18676 _visitNode(node.name);
18677 _visitNodeWithPrefix(" ", node.expression);
18678 return null;
18679 }
18680
18681 @override
18682 Object visitNativeClause(NativeClause node) {
18683 _writer.print("native ");
18684 _visitNode(node.name);
18685 return null;
18686 }
18687
18688 @override
18689 Object visitNativeFunctionBody(NativeFunctionBody node) {
18690 _writer.print("native ");
18691 _visitNode(node.stringLiteral);
18692 _writer.print(';');
18693 return null;
18694 }
18695
18696 @override
18697 Object visitNullLiteral(NullLiteral node) {
18698 _writer.print("null");
18699 return null;
18700 }
18701
18702 @override
18703 Object visitParenthesizedExpression(ParenthesizedExpression node) {
18704 _writer.print('(');
18705 _visitNode(node.expression);
18706 _writer.print(')');
18707 return null;
18708 }
18709
18710 @override
18711 Object visitPartDirective(PartDirective node) {
18712 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18713 _writer.print("part ");
18714 _visitNode(node.uri);
18715 _writer.print(';');
18716 return null;
18717 }
18718
18719 @override
18720 Object visitPartOfDirective(PartOfDirective node) {
18721 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18722 _writer.print("part of ");
18723 _visitNode(node.libraryName);
18724 _writer.print(';');
18725 return null;
18726 }
18727
18728 @override
18729 Object visitPostfixExpression(PostfixExpression node) {
18730 _visitNode(node.operand);
18731 _writer.print(node.operator.lexeme);
18732 return null;
18733 }
18734
18735 @override
18736 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
18737 _visitNode(node.prefix);
18738 _writer.print('.');
18739 _visitNode(node.identifier);
18740 return null;
18741 }
18742
18743 @override
18744 Object visitPrefixExpression(PrefixExpression node) {
18745 _writer.print(node.operator.lexeme);
18746 _visitNode(node.operand);
18747 return null;
18748 }
18749
18750 @override
18751 Object visitPropertyAccess(PropertyAccess node) {
18752 if (node.isCascaded) {
18753 _writer.print("..");
18754 } else {
18755 _visitNode(node.target);
18756 _writer.print(node.operator.lexeme);
18757 }
18758 _visitNode(node.propertyName);
18759 return null;
18760 }
18761
18762 @override
18763 Object visitRedirectingConstructorInvocation(
18764 RedirectingConstructorInvocation node) {
18765 _writer.print("this");
18766 _visitNodeWithPrefix(".", node.constructorName);
18767 _visitNode(node.argumentList);
18768 return null;
18769 }
18770
18771 @override
18772 Object visitRethrowExpression(RethrowExpression node) {
18773 _writer.print("rethrow");
18774 return null;
18775 }
18776
18777 @override
18778 Object visitReturnStatement(ReturnStatement node) {
18779 Expression expression = node.expression;
18780 if (expression == null) {
18781 _writer.print("return;");
18782 } else {
18783 _writer.print("return ");
18784 expression.accept(this);
18785 _writer.print(";");
18786 }
18787 return null;
18788 }
18789
18790 @override
18791 Object visitScriptTag(ScriptTag node) {
18792 _writer.print(node.scriptTag.lexeme);
18793 return null;
18794 }
18795
18796 @override
18797 Object visitShowCombinator(ShowCombinator node) {
18798 _writer.print("show ");
18799 _visitNodeListWithSeparator(node.shownNames, ", ");
18800 return null;
18801 }
18802
18803 @override
18804 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
18805 _visitNodeListWithSeparatorAndSuffix(node.metadata, ' ', ' ');
18806 _visitTokenWithSuffix(node.keyword, " ");
18807 _visitNodeWithSuffix(node.type, " ");
18808 _visitNode(node.identifier);
18809 return null;
18810 }
18811
18812 @override
18813 Object visitSimpleIdentifier(SimpleIdentifier node) {
18814 _writer.print(node.token.lexeme);
18815 return null;
18816 }
18817
18818 @override
18819 Object visitSimpleStringLiteral(SimpleStringLiteral node) {
18820 _writer.print(node.literal.lexeme);
18821 return null;
18822 }
18823
18824 @override
18825 Object visitStringInterpolation(StringInterpolation node) {
18826 _visitNodeList(node.elements);
18827 return null;
18828 }
18829
18830 @override
18831 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
18832 _writer.print("super");
18833 _visitNodeWithPrefix(".", node.constructorName);
18834 _visitNode(node.argumentList);
18835 return null;
18836 }
18837
18838 @override
18839 Object visitSuperExpression(SuperExpression node) {
18840 _writer.print("super");
18841 return null;
18842 }
18843
18844 @override
18845 Object visitSwitchCase(SwitchCase node) {
18846 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18847 _writer.print("case ");
18848 _visitNode(node.expression);
18849 _writer.print(": ");
18850 _visitNodeListWithSeparator(node.statements, " ");
18851 return null;
18852 }
18853
18854 @override
18855 Object visitSwitchDefault(SwitchDefault node) {
18856 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18857 _writer.print("default: ");
18858 _visitNodeListWithSeparator(node.statements, " ");
18859 return null;
18860 }
18861
18862 @override
18863 Object visitSwitchStatement(SwitchStatement node) {
18864 _writer.print("switch (");
18865 _visitNode(node.expression);
18866 _writer.print(") {");
18867 _visitNodeListWithSeparator(node.members, " ");
18868 _writer.print("}");
18869 return null;
18870 }
18871
18872 @override
18873 Object visitSymbolLiteral(SymbolLiteral node) {
18874 _writer.print("#");
18875 List<Token> components = node.components;
18876 for (int i = 0; i < components.length; i++) {
18877 if (i > 0) {
18878 _writer.print(".");
18879 }
18880 _writer.print(components[i].lexeme);
18881 }
18882 return null;
18883 }
18884
18885 @override
18886 Object visitThisExpression(ThisExpression node) {
18887 _writer.print("this");
18888 return null;
18889 }
18890
18891 @override
18892 Object visitThrowExpression(ThrowExpression node) {
18893 _writer.print("throw ");
18894 _visitNode(node.expression);
18895 return null;
18896 }
18897
18898 @override
18899 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
18900 _visitNodeWithSuffix(node.variables, ";");
18901 return null;
18902 }
18903
18904 @override
18905 Object visitTryStatement(TryStatement node) {
18906 _writer.print("try ");
18907 _visitNode(node.body);
18908 _visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " ");
18909 _visitNodeWithPrefix(" finally ", node.finallyBlock);
18910 return null;
18911 }
18912
18913 @override
18914 Object visitTypeArgumentList(TypeArgumentList node) {
18915 _writer.print('<');
18916 _visitNodeListWithSeparator(node.arguments, ", ");
18917 _writer.print('>');
18918 return null;
18919 }
18920
18921 @override
18922 Object visitTypeName(TypeName node) {
18923 _visitNode(node.name);
18924 _visitNode(node.typeArguments);
18925 return null;
18926 }
18927
18928 @override
18929 Object visitTypeParameter(TypeParameter node) {
18930 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18931 _visitNode(node.name);
18932 _visitNodeWithPrefix(" extends ", node.bound);
18933 return null;
18934 }
18935
18936 @override
18937 Object visitTypeParameterList(TypeParameterList node) {
18938 _writer.print('<');
18939 _visitNodeListWithSeparator(node.typeParameters, ", ");
18940 _writer.print('>');
18941 return null;
18942 }
18943
18944 @override
18945 Object visitVariableDeclaration(VariableDeclaration node) {
18946 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18947 _visitNode(node.name);
18948 _visitNodeWithPrefix(" = ", node.initializer);
18949 return null;
18950 }
18951
18952 @override
18953 Object visitVariableDeclarationList(VariableDeclarationList node) {
18954 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18955 _visitTokenWithSuffix(node.keyword, " ");
18956 _visitNodeWithSuffix(node.type, " ");
18957 _visitNodeListWithSeparator(node.variables, ", ");
18958 return null;
18959 }
18960
18961 @override
18962 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
18963 _visitNode(node.variables);
18964 _writer.print(";");
18965 return null;
18966 }
18967
18968 @override
18969 Object visitWhileStatement(WhileStatement node) {
18970 _writer.print("while (");
18971 _visitNode(node.condition);
18972 _writer.print(") ");
18973 _visitNode(node.body);
18974 return null;
18975 }
18976
18977 @override
18978 Object visitWithClause(WithClause node) {
18979 _writer.print("with ");
18980 _visitNodeListWithSeparator(node.mixinTypes, ", ");
18981 return null;
18982 }
18983
18984 @override
18985 Object visitYieldStatement(YieldStatement node) {
18986 if (node.star != null) {
18987 _writer.print("yield* ");
18988 } else {
18989 _writer.print("yield ");
18990 }
18991 _visitNode(node.expression);
18992 _writer.print(";");
18993 return null;
18994 }
18995
18996 /**
18997 * Visit the given function [body], printing the [prefix] before if the body
18998 * is not empty.
18999 */
19000 void _visitFunctionWithPrefix(String prefix, FunctionBody body) {
19001 if (body is! EmptyFunctionBody) {
19002 _writer.print(prefix);
19003 }
19004 _visitNode(body);
19005 }
19006
19007 /**
19008 * Safely visit the given [node].
19009 */
19010 void _visitNode(AstNode node) {
19011 if (node != null) {
19012 node.accept(this);
19013 }
19014 }
19015
19016 /**
19017 * Print a list of [nodes] without any separation.
19018 */
19019 void _visitNodeList(NodeList<AstNode> nodes) {
19020 _visitNodeListWithSeparator(nodes, "");
19021 }
19022
19023 /**
19024 * Print a list of [nodes], separated by the given [separator].
19025 */
19026 void _visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) {
19027 if (nodes != null) {
19028 int size = nodes.length;
19029 for (int i = 0; i < size; i++) {
19030 if (i > 0) {
19031 _writer.print(separator);
19032 }
19033 nodes[i].accept(this);
19034 }
19035 }
19036 }
19037
19038 /**
19039 * Print a list of [nodes], prefixed by the given [prefix] if the list is not
19040 * empty, and separated by the given [separator].
19041 */
19042 void _visitNodeListWithSeparatorAndPrefix(
19043 String prefix, NodeList<AstNode> nodes, String separator) {
19044 if (nodes != null) {
19045 int size = nodes.length;
19046 if (size > 0) {
19047 _writer.print(prefix);
19048 for (int i = 0; i < size; i++) {
19049 if (i > 0) {
19050 _writer.print(separator);
19051 }
19052 nodes[i].accept(this);
19053 }
19054 }
19055 }
19056 }
19057
19058 /**
19059 * Print a list of [nodes], separated by the given [separator], followed by
19060 * the given [suffix] if the list is not empty.
19061 */
19062 void _visitNodeListWithSeparatorAndSuffix(
19063 NodeList<AstNode> nodes, String separator, String suffix) {
19064 if (nodes != null) {
19065 int size = nodes.length;
19066 if (size > 0) {
19067 for (int i = 0; i < size; i++) {
19068 if (i > 0) {
19069 _writer.print(separator);
19070 }
19071 nodes[i].accept(this);
19072 }
19073 _writer.print(suffix);
19074 }
19075 }
19076 }
19077
19078 /**
19079 * Safely visit the given [node], printing the [prefix] before the node if it
19080 * is non-`null`.
19081 */
19082 void _visitNodeWithPrefix(String prefix, AstNode node) {
19083 if (node != null) {
19084 _writer.print(prefix);
19085 node.accept(this);
19086 }
19087 }
19088
19089 /**
19090 * Safely visit the given [node], printing the [suffix] after the node if it
19091 * is non-`null`.
19092 */
19093 void _visitNodeWithSuffix(AstNode node, String suffix) {
19094 if (node != null) {
19095 node.accept(this);
19096 _writer.print(suffix);
19097 }
19098 }
19099
19100 /**
19101 * Safely visit the given [token], printing the [suffix] after the token if it
19102 * is non-`null`.
19103 */
19104 void _visitTokenWithSuffix(Token token, String suffix) {
19105 if (token != null) {
19106 _writer.print(token.lexeme);
19107 _writer.print(suffix);
19108 }
19109 }
19110 }
19111
19112 /**
19113 * A try statement.
19114 *
19115 * > tryStatement ::=
19116 * > 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause)
19117 * >
19118 * > finallyClause ::=
19119 * > 'finally' [Block]
19120 */
19121 class TryStatement extends Statement {
19122 /**
19123 * The token representing the 'try' keyword.
19124 */
19125 Token tryKeyword;
19126
19127 /**
19128 * The body of the statement.
19129 */
19130 Block _body;
19131
19132 /**
19133 * The catch clauses contained in the try statement.
19134 */
19135 NodeList<CatchClause> _catchClauses;
19136
19137 /**
19138 * The token representing the 'finally' keyword, or `null` if the statement
19139 * does not contain a finally clause.
19140 */
19141 Token finallyKeyword;
19142
19143 /**
19144 * The finally block contained in the try statement, or `null` if the
19145 * statement does not contain a finally clause.
19146 */
19147 Block _finallyBlock;
19148
19149 /**
19150 * Initialize a newly created try statement. The list of [catchClauses] can be
19151 * `null` if there are no catch clauses. The [finallyKeyword] and
19152 * [finallyBlock] can be `null` if there is no finally clause.
19153 */
19154 TryStatement(this.tryKeyword, Block body, List<CatchClause> catchClauses,
19155 this.finallyKeyword, Block finallyBlock) {
19156 _body = _becomeParentOf(body);
19157 _catchClauses = new NodeList<CatchClause>(this, catchClauses);
19158 _finallyBlock = _becomeParentOf(finallyBlock);
19159 }
19160
19161 @override
19162 Token get beginToken => tryKeyword;
19163
19164 /**
19165 * Return the body of the statement.
19166 */
19167 Block get body => _body;
19168
19169 /**
19170 * Set the body of the statement to the given [block].
19171 */
19172 void set body(Block block) {
19173 _body = _becomeParentOf(block);
19174 }
19175
19176 /**
19177 * Return the catch clauses contained in the try statement.
19178 */
19179 NodeList<CatchClause> get catchClauses => _catchClauses;
19180
19181 @override
19182 Iterable get childEntities => new ChildEntities()
19183 ..add(tryKeyword)
19184 ..add(_body)
19185 ..addAll(_catchClauses)
19186 ..add(finallyKeyword)
19187 ..add(_finallyBlock);
19188
19189 @override
19190 Token get endToken {
19191 if (_finallyBlock != null) {
19192 return _finallyBlock.endToken;
19193 } else if (finallyKeyword != null) {
19194 return finallyKeyword;
19195 } else if (!_catchClauses.isEmpty) {
19196 return _catchClauses.endToken;
19197 }
19198 return _body.endToken;
19199 }
19200
19201 /**
19202 * Return the finally block contained in the try statement, or `null` if the
19203 * statement does not contain a finally clause.
19204 */
19205 Block get finallyBlock => _finallyBlock;
19206
19207 /**
19208 * Set the finally block contained in the try statement to the given [block].
19209 */
19210 void set finallyBlock(Block block) {
19211 _finallyBlock = _becomeParentOf(block);
19212 }
19213
19214 @override
19215 accept(AstVisitor visitor) => visitor.visitTryStatement(this);
19216
19217 @override
19218 void visitChildren(AstVisitor visitor) {
19219 _safelyVisitChild(_body, visitor);
19220 _catchClauses.accept(visitor);
19221 _safelyVisitChild(_finallyBlock, visitor);
19222 }
19223 }
19224
19225 /**
19226 * The declaration of a type alias.
19227 *
19228 * > typeAlias ::=
19229 * > 'typedef' typeAliasBody
19230 * >
19231 * > typeAliasBody ::=
19232 * > classTypeAlias
19233 * > | functionTypeAlias
19234 */
19235 abstract class TypeAlias extends NamedCompilationUnitMember {
19236 /**
19237 * The token representing the 'typedef' keyword.
19238 */
19239 Token typedefKeyword;
19240
19241 /**
19242 * The semicolon terminating the declaration.
19243 */
19244 Token semicolon;
19245
19246 /**
19247 * Initialize a newly created type alias. Either or both of the [comment] and
19248 * [metadata] can be `null` if the declaration does not have the corresponding
19249 * attribute.
19250 */
19251 TypeAlias(Comment comment, List<Annotation> metadata, this.typedefKeyword,
19252 SimpleIdentifier name, this.semicolon)
19253 : super(comment, metadata, name);
19254
19255 @override
19256 Token get endToken => semicolon;
19257
19258 @override
19259 Token get firstTokenAfterCommentAndMetadata => typedefKeyword;
19260
19261 /**
19262 * Return the token representing the 'typedef' keyword.
19263 */
19264 @deprecated // Use "this.typedefKeyword"
19265 Token get keyword => typedefKeyword;
19266
19267 /**
19268 * Set the token representing the 'typedef' keyword to the given [token].
19269 */
19270 @deprecated // Use "this.typedefKeyword"
19271 set keyword(Token token) {
19272 typedefKeyword = token;
19273 }
19274 }
19275
19276 /**
19277 * A list of type arguments.
19278 *
19279 * > typeArguments ::=
19280 * > '<' typeName (',' typeName)* '>'
19281 */
19282 class TypeArgumentList extends AstNode {
19283 /**
19284 * The left bracket.
19285 */
19286 Token leftBracket;
19287
19288 /**
19289 * The type arguments associated with the type.
19290 */
19291 NodeList<TypeName> _arguments;
19292
19293 /**
19294 * The right bracket.
19295 */
19296 Token rightBracket;
19297
19298 /**
19299 * Initialize a newly created list of type arguments.
19300 */
19301 TypeArgumentList(
19302 this.leftBracket, List<TypeName> arguments, this.rightBracket) {
19303 _arguments = new NodeList<TypeName>(this, arguments);
19304 }
19305
19306 /**
19307 * Return the type arguments associated with the type.
19308 */
19309 NodeList<TypeName> get arguments => _arguments;
19310
19311 @override
19312 Token get beginToken => leftBracket;
19313
19314 @override
19315 // TODO(paulberry): Add commas.
19316 Iterable get childEntities => new ChildEntities()
19317 ..add(leftBracket)
19318 ..addAll(_arguments)
19319 ..add(rightBracket);
19320
19321 @override
19322 Token get endToken => rightBracket;
19323
19324 @override
19325 accept(AstVisitor visitor) => visitor.visitTypeArgumentList(this);
19326
19327 @override
19328 void visitChildren(AstVisitor visitor) {
19329 _arguments.accept(visitor);
19330 }
19331 }
19332
19333 /**
19334 * A literal that has a type associated with it.
19335 *
19336 * > typedLiteral ::=
19337 * > [ListLiteral]
19338 * > | [MapLiteral]
19339 */
19340 abstract class TypedLiteral extends Literal {
19341 /**
19342 * The token representing the 'const' keyword, or `null` if the literal is not
19343 * a constant.
19344 */
19345 Token constKeyword;
19346
19347 /**
19348 * The type argument associated with this literal, or `null` if no type
19349 * arguments were declared.
19350 */
19351 TypeArgumentList _typeArguments;
19352
19353 /**
19354 * Initialize a newly created typed literal. The [constKeyword] can be `null`\
19355 * if the literal is not a constant. The [typeArguments] can be `null` if no
19356 * type arguments were declared.
19357 */
19358 TypedLiteral(this.constKeyword, TypeArgumentList typeArguments) {
19359 _typeArguments = _becomeParentOf(typeArguments);
19360 }
19361
19362 /**
19363 * Return the type argument associated with this literal, or `null` if no type
19364 * arguments were declared.
19365 */
19366 TypeArgumentList get typeArguments => _typeArguments;
19367
19368 /**
19369 * Set the type argument associated with this literal to the given
19370 * [typeArguments].
19371 */
19372 void set typeArguments(TypeArgumentList typeArguments) {
19373 _typeArguments = _becomeParentOf(typeArguments);
19374 }
19375
19376 ChildEntities get _childEntities =>
19377 new ChildEntities()..add(constKeyword)..add(_typeArguments);
19378
19379 @override
19380 void visitChildren(AstVisitor visitor) {
19381 _safelyVisitChild(_typeArguments, visitor);
19382 }
19383 }
19384
19385 /**
19386 * The name of a type, which can optionally include type arguments.
19387 *
19388 * > typeName ::=
19389 * > [Identifier] typeArguments?
19390 */
19391 class TypeName extends AstNode {
19392 /**
19393 * The name of the type.
19394 */
19395 Identifier _name;
19396
19397 /**
19398 * The type arguments associated with the type, or `null` if there are no type
19399 * arguments.
19400 */
19401 TypeArgumentList _typeArguments;
19402
19403 /**
19404 * The type being named, or `null` if the AST structure has not been resolved.
19405 */
19406 DartType type;
19407
19408 /**
19409 * Initialize a newly created type name. The [typeArguments] can be `null` if
19410 * there are no type arguments.
19411 */
19412 TypeName(Identifier name, TypeArgumentList typeArguments) {
19413 _name = _becomeParentOf(name);
19414 _typeArguments = _becomeParentOf(typeArguments);
19415 }
19416
19417 @override
19418 Token get beginToken => _name.beginToken;
19419
19420 @override
19421 Iterable get childEntities =>
19422 new ChildEntities()..add(_name)..add(_typeArguments);
19423
19424 @override
19425 Token get endToken {
19426 if (_typeArguments != null) {
19427 return _typeArguments.endToken;
19428 }
19429 return _name.endToken;
19430 }
19431
19432 /**
19433 * Return `true` if this type is a deferred type.
19434 *
19435 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form
19436 * </i>p.T</i> where <i>p</i> is a deferred prefix.
19437 */
19438 bool get isDeferred {
19439 Identifier identifier = name;
19440 if (identifier is! PrefixedIdentifier) {
19441 return false;
19442 }
19443 return (identifier as PrefixedIdentifier).isDeferred;
19444 }
19445
19446 @override
19447 bool get isSynthetic => _name.isSynthetic && _typeArguments == null;
19448
19449 /**
19450 * Return the name of the type.
19451 */
19452 Identifier get name => _name;
19453
19454 /**
19455 * Set the name of the type to the given [identifier].
19456 */
19457 void set name(Identifier identifier) {
19458 _name = _becomeParentOf(identifier);
19459 }
19460
19461 /**
19462 * Return the type arguments associated with the type, or `null` if there are
19463 * no type arguments.
19464 */
19465 TypeArgumentList get typeArguments => _typeArguments;
19466
19467 /**
19468 * Set the type arguments associated with the type to the given
19469 * [typeArguments].
19470 */
19471 void set typeArguments(TypeArgumentList typeArguments) {
19472 _typeArguments = _becomeParentOf(typeArguments);
19473 }
19474
19475 @override
19476 accept(AstVisitor visitor) => visitor.visitTypeName(this);
19477
19478 @override
19479 void visitChildren(AstVisitor visitor) {
19480 _safelyVisitChild(_name, visitor);
19481 _safelyVisitChild(_typeArguments, visitor);
19482 }
19483 }
19484
19485 /**
19486 * A type parameter.
19487 *
19488 * > typeParameter ::=
19489 * > [SimpleIdentifier] ('extends' [TypeName])?
19490 */
19491 class TypeParameter extends Declaration {
19492 /**
19493 * The name of the type parameter.
19494 */
19495 SimpleIdentifier _name;
19496
19497 /**
19498 * The token representing the 'extends' keyword, or `null` if there is no
19499 * explicit upper bound.
19500 */
19501 Token extendsKeyword;
19502
19503 /**
19504 * The name of the upper bound for legal arguments, or `null` if there is no
19505 * explicit upper bound.
19506 */
19507 TypeName _bound;
19508
19509 /**
19510 * Initialize a newly created type parameter. Either or both of the [comment]
19511 * and [metadata] can be `null` if the parameter does not have the
19512 * corresponding attribute. The [extendsKeyword] and [bound] can be `null` if
19513 * the parameter does not have an upper bound.
19514 */
19515 TypeParameter(Comment comment, List<Annotation> metadata,
19516 SimpleIdentifier name, this.extendsKeyword, TypeName bound)
19517 : super(comment, metadata) {
19518 _name = _becomeParentOf(name);
19519 _bound = _becomeParentOf(bound);
19520 }
19521
19522 /**
19523 * Return the name of the upper bound for legal arguments, or `null` if there
19524 * is no explicit upper bound.
19525 */
19526 TypeName get bound => _bound;
19527
19528 /**
19529 * Set the name of the upper bound for legal arguments to the given
19530 * [typeName].
19531 */
19532 void set bound(TypeName typeName) {
19533 _bound = _becomeParentOf(typeName);
19534 }
19535
19536 @override
19537 Iterable get childEntities =>
19538 super._childEntities..add(_name)..add(extendsKeyword)..add(_bound);
19539
19540 @override
19541 TypeParameterElement get element =>
19542 _name != null ? (_name.staticElement as TypeParameterElement) : null;
19543
19544 @override
19545 Token get endToken {
19546 if (_bound == null) {
19547 return _name.endToken;
19548 }
19549 return _bound.endToken;
19550 }
19551
19552 @override
19553 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
19554
19555 /**
19556 * Return the token representing the 'extends' keyword, or `null` if there is
19557 * no explicit upper bound.
19558 */
19559 @deprecated // Use "this.extendsKeyword"
19560 Token get keyword => extendsKeyword;
19561
19562 /**
19563 * Set the token representing the 'extends' keyword to the given [token].
19564 */
19565 @deprecated // Use "this.extendsKeyword"
19566 set keyword(Token token) {
19567 extendsKeyword = token;
19568 }
19569
19570 /**
19571 * Return the name of the type parameter.
19572 */
19573 SimpleIdentifier get name => _name;
19574
19575 /**
19576 * Set the name of the type parameter to the given [identifier].
19577 */
19578 void set name(SimpleIdentifier identifier) {
19579 _name = _becomeParentOf(identifier);
19580 }
19581
19582 @override
19583 accept(AstVisitor visitor) => visitor.visitTypeParameter(this);
19584
19585 @override
19586 void visitChildren(AstVisitor visitor) {
19587 super.visitChildren(visitor);
19588 _safelyVisitChild(_name, visitor);
19589 _safelyVisitChild(_bound, visitor);
19590 }
19591 }
19592
19593 /**
19594 * Type parameters within a declaration.
19595 *
19596 * > typeParameterList ::=
19597 * > '<' [TypeParameter] (',' [TypeParameter])* '>'
19598 */
19599 class TypeParameterList extends AstNode {
19600 /**
19601 * The left angle bracket.
19602 */
19603 final Token leftBracket;
19604
19605 /**
19606 * The type parameters in the list.
19607 */
19608 NodeList<TypeParameter> _typeParameters;
19609
19610 /**
19611 * The right angle bracket.
19612 */
19613 final Token rightBracket;
19614
19615 /**
19616 * Initialize a newly created list of type parameters.
19617 */
19618 TypeParameterList(
19619 this.leftBracket, List<TypeParameter> typeParameters, this.rightBracket) {
19620 _typeParameters = new NodeList<TypeParameter>(this, typeParameters);
19621 }
19622
19623 @override
19624 Token get beginToken => leftBracket;
19625
19626 @override
19627 Iterable get childEntities => new ChildEntities()
19628 ..add(leftBracket)
19629 ..addAll(_typeParameters)
19630 ..add(rightBracket);
19631
19632 @override
19633 Token get endToken => rightBracket;
19634
19635 /**
19636 * Return the type parameters for the type.
19637 */
19638 NodeList<TypeParameter> get typeParameters => _typeParameters;
19639
19640 @override
19641 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this);
19642
19643 @override
19644 void visitChildren(AstVisitor visitor) {
19645 _typeParameters.accept(visitor);
19646 }
19647 }
19648
19649 /**
19650 * An AST visitor that will recursively visit all of the nodes in an AST
19651 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
19652 * every node will also be visited by using a single unified [visitNode] method.
19653 *
19654 * Subclasses that override a visit method must either invoke the overridden
19655 * visit method or explicitly invoke the more general [visitNode] method.
19656 * Failure to do so will cause the children of the visited node to not be
19657 * visited.
19658 */
19659 class UnifyingAstVisitor<R> implements AstVisitor<R> {
19660 @override
19661 R visitAdjacentStrings(AdjacentStrings node) => visitNode(node);
19662
19663 @override
19664 R visitAnnotation(Annotation node) => visitNode(node);
19665
19666 @override
19667 R visitArgumentList(ArgumentList node) => visitNode(node);
19668
19669 @override
19670 R visitAsExpression(AsExpression node) => visitNode(node);
19671
19672 @override
19673 R visitAssertStatement(AssertStatement node) => visitNode(node);
19674
19675 @override
19676 R visitAssignmentExpression(AssignmentExpression node) => visitNode(node);
19677
19678 @override
19679 R visitAwaitExpression(AwaitExpression node) => visitNode(node);
19680
19681 @override
19682 R visitBinaryExpression(BinaryExpression node) => visitNode(node);
19683
19684 @override
19685 R visitBlock(Block node) => visitNode(node);
19686
19687 @override
19688 R visitBlockFunctionBody(BlockFunctionBody node) => visitNode(node);
19689
19690 @override
19691 R visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
19692
19693 @override
19694 R visitBreakStatement(BreakStatement node) => visitNode(node);
19695
19696 @override
19697 R visitCascadeExpression(CascadeExpression node) => visitNode(node);
19698
19699 @override
19700 R visitCatchClause(CatchClause node) => visitNode(node);
19701
19702 @override
19703 R visitClassDeclaration(ClassDeclaration node) => visitNode(node);
19704
19705 @override
19706 R visitClassTypeAlias(ClassTypeAlias node) => visitNode(node);
19707
19708 @override
19709 R visitComment(Comment node) => visitNode(node);
19710
19711 @override
19712 R visitCommentReference(CommentReference node) => visitNode(node);
19713
19714 @override
19715 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
19716
19717 @override
19718 R visitConditionalExpression(ConditionalExpression node) => visitNode(node);
19719
19720 @override
19721 R visitConstructorDeclaration(ConstructorDeclaration node) => visitNode(node);
19722
19723 @override
19724 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
19725 visitNode(node);
19726
19727 @override
19728 R visitConstructorName(ConstructorName node) => visitNode(node);
19729
19730 @override
19731 R visitContinueStatement(ContinueStatement node) => visitNode(node);
19732
19733 @override
19734 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitNode(node);
19735
19736 @override
19737 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitNode(node);
19738
19739 @override
19740 R visitDoStatement(DoStatement node) => visitNode(node);
19741
19742 @override
19743 R visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
19744
19745 @override
19746 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
19747
19748 @override
19749 R visitEmptyStatement(EmptyStatement node) => visitNode(node);
19750
19751 @override
19752 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
19753 visitNode(node);
19754
19755 @override
19756 R visitEnumDeclaration(EnumDeclaration node) => visitNode(node);
19757
19758 @override
19759 R visitExportDirective(ExportDirective node) => visitNode(node);
19760
19761 @override
19762 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitNode(node);
19763
19764 @override
19765 R visitExpressionStatement(ExpressionStatement node) => visitNode(node);
19766
19767 @override
19768 R visitExtendsClause(ExtendsClause node) => visitNode(node);
19769
19770 @override
19771 R visitFieldDeclaration(FieldDeclaration node) => visitNode(node);
19772
19773 @override
19774 R visitFieldFormalParameter(FieldFormalParameter node) => visitNode(node);
19775
19776 @override
19777 R visitForEachStatement(ForEachStatement node) => visitNode(node);
19778
19779 @override
19780 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
19781
19782 @override
19783 R visitForStatement(ForStatement node) => visitNode(node);
19784
19785 @override
19786 R visitFunctionDeclaration(FunctionDeclaration node) => visitNode(node);
19787
19788 @override
19789 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
19790 visitNode(node);
19791
19792 @override
19793 R visitFunctionExpression(FunctionExpression node) => visitNode(node);
19794
19795 @override
19796 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
19797 visitNode(node);
19798
19799 @override
19800 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitNode(node);
19801
19802 @override
19803 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
19804 visitNode(node);
19805
19806 @override
19807 R visitHideCombinator(HideCombinator node) => visitNode(node);
19808
19809 @override
19810 R visitIfStatement(IfStatement node) => visitNode(node);
19811
19812 @override
19813 R visitImplementsClause(ImplementsClause node) => visitNode(node);
19814
19815 @override
19816 R visitImportDirective(ImportDirective node) => visitNode(node);
19817
19818 @override
19819 R visitIndexExpression(IndexExpression node) => visitNode(node);
19820
19821 @override
19822 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
19823 visitNode(node);
19824
19825 @override
19826 R visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
19827
19828 @override
19829 R visitInterpolationExpression(InterpolationExpression node) =>
19830 visitNode(node);
19831
19832 @override
19833 R visitInterpolationString(InterpolationString node) => visitNode(node);
19834
19835 @override
19836 R visitIsExpression(IsExpression node) => visitNode(node);
19837
19838 @override
19839 R visitLabel(Label node) => visitNode(node);
19840
19841 @override
19842 R visitLabeledStatement(LabeledStatement node) => visitNode(node);
19843
19844 @override
19845 R visitLibraryDirective(LibraryDirective node) => visitNode(node);
19846
19847 @override
19848 R visitLibraryIdentifier(LibraryIdentifier node) => visitNode(node);
19849
19850 @override
19851 R visitListLiteral(ListLiteral node) => visitNode(node);
19852
19853 @override
19854 R visitMapLiteral(MapLiteral node) => visitNode(node);
19855
19856 @override
19857 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
19858
19859 @override
19860 R visitMethodDeclaration(MethodDeclaration node) => visitNode(node);
19861
19862 @override
19863 R visitMethodInvocation(MethodInvocation node) => visitNode(node);
19864
19865 @override
19866 R visitNamedExpression(NamedExpression node) => visitNode(node);
19867
19868 @override
19869 R visitNativeClause(NativeClause node) => visitNode(node);
19870
19871 @override
19872 R visitNativeFunctionBody(NativeFunctionBody node) => visitNode(node);
19873
19874 R visitNode(AstNode node) {
19875 node.visitChildren(this);
19876 return null;
19877 }
19878
19879 @override
19880 R visitNullLiteral(NullLiteral node) => visitNode(node);
19881
19882 @override
19883 R visitParenthesizedExpression(ParenthesizedExpression node) =>
19884 visitNode(node);
19885
19886 @override
19887 R visitPartDirective(PartDirective node) => visitNode(node);
19888
19889 @override
19890 R visitPartOfDirective(PartOfDirective node) => visitNode(node);
19891
19892 @override
19893 R visitPostfixExpression(PostfixExpression node) => visitNode(node);
19894
19895 @override
19896 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitNode(node);
19897
19898 @override
19899 R visitPrefixExpression(PrefixExpression node) => visitNode(node);
19900
19901 @override
19902 R visitPropertyAccess(PropertyAccess node) => visitNode(node);
19903
19904 @override
19905 R visitRedirectingConstructorInvocation(
19906 RedirectingConstructorInvocation node) =>
19907 visitNode(node);
19908
19909 @override
19910 R visitRethrowExpression(RethrowExpression node) => visitNode(node);
19911
19912 @override
19913 R visitReturnStatement(ReturnStatement node) => visitNode(node);
19914
19915 @override
19916 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
19917
19918 @override
19919 R visitShowCombinator(ShowCombinator node) => visitNode(node);
19920
19921 @override
19922 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNode(node);
19923
19924 @override
19925 R visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
19926
19927 @override
19928 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
19929
19930 @override
19931 R visitStringInterpolation(StringInterpolation node) => visitNode(node);
19932
19933 @override
19934 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
19935 visitNode(node);
19936
19937 @override
19938 R visitSuperExpression(SuperExpression node) => visitNode(node);
19939
19940 @override
19941 R visitSwitchCase(SwitchCase node) => visitNode(node);
19942
19943 @override
19944 R visitSwitchDefault(SwitchDefault node) => visitNode(node);
19945
19946 @override
19947 R visitSwitchStatement(SwitchStatement node) => visitNode(node);
19948
19949 @override
19950 R visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
19951
19952 @override
19953 R visitThisExpression(ThisExpression node) => visitNode(node);
19954
19955 @override
19956 R visitThrowExpression(ThrowExpression node) => visitNode(node);
19957
19958 @override
19959 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
19960 visitNode(node);
19961
19962 @override
19963 R visitTryStatement(TryStatement node) => visitNode(node);
19964
19965 @override
19966 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
19967
19968 @override
19969 R visitTypeName(TypeName node) => visitNode(node);
19970
19971 @override
19972 R visitTypeParameter(TypeParameter node) => visitNode(node);
19973
19974 @override
19975 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
19976
19977 @override
19978 R visitVariableDeclaration(VariableDeclaration node) => visitNode(node);
19979
19980 @override
19981 R visitVariableDeclarationList(VariableDeclarationList node) =>
19982 visitNode(node);
19983
19984 @override
19985 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
19986 visitNode(node);
19987
19988 @override
19989 R visitWhileStatement(WhileStatement node) => visitNode(node);
19990
19991 @override
19992 R visitWithClause(WithClause node) => visitNode(node);
19993
19994 @override
19995 R visitYieldStatement(YieldStatement node) => visitNode(node);
19996 }
19997
19998 /**
19999 * A directive that references a URI.
20000 *
20001 * > uriBasedDirective ::=
20002 * > [ExportDirective]
20003 * > | [ImportDirective]
20004 * > | [PartDirective]
20005 */
20006 abstract class UriBasedDirective extends Directive {
20007 /**
20008 * The prefix of a URI using the `dart-ext` scheme to reference a native code
20009 * library.
20010 */
20011 static String _DART_EXT_SCHEME = "dart-ext:";
20012
20013 /**
20014 * The URI referenced by this directive.
20015 */
20016 StringLiteral _uri;
20017
20018 /**
20019 * The content of the URI.
20020 */
20021 String uriContent;
20022
20023 /**
20024 * The source to which the URI was resolved.
20025 */
20026 Source source;
20027
20028 /**
20029 * Initialize a newly create URI-based directive. Either or both of the
20030 * [comment] and [metadata] can be `null` if the directive does not have the
20031 * corresponding attribute.
20032 */
20033 UriBasedDirective(
20034 Comment comment, List<Annotation> metadata, StringLiteral uri)
20035 : super(comment, metadata) {
20036 _uri = _becomeParentOf(uri);
20037 }
20038
20039 /**
20040 * Return the URI referenced by this directive.
20041 */
20042 StringLiteral get uri => _uri;
20043
20044 /**
20045 * Set the URI referenced by this directive to the given [uri].
20046 */
20047 void set uri(StringLiteral uri) {
20048 _uri = _becomeParentOf(uri);
20049 }
20050
20051 /**
20052 * Return the element associated with the URI of this directive, or `null` if
20053 * the AST structure has not been resolved or if the URI could not be
20054 * resolved. Examples of the latter case include a directive that contains an
20055 * invalid URL or a URL that does not exist.
20056 */
20057 Element get uriElement;
20058
20059 /**
20060 * Validate this directive, but do not check for existence. Return a code
20061 * indicating the problem if there is one, or `null` no problem
20062 */
20063 UriValidationCode validate() {
20064 StringLiteral uriLiteral = uri;
20065 if (uriLiteral is StringInterpolation) {
20066 return UriValidationCode.URI_WITH_INTERPOLATION;
20067 }
20068 String uriContent = this.uriContent;
20069 if (uriContent == null) {
20070 return UriValidationCode.INVALID_URI;
20071 }
20072 if (this is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME)) {
20073 return UriValidationCode.URI_WITH_DART_EXT_SCHEME;
20074 }
20075 try {
20076 parseUriWithException(Uri.encodeFull(uriContent));
20077 } on URISyntaxException {
20078 return UriValidationCode.INVALID_URI;
20079 }
20080 return null;
20081 }
20082
20083 @override
20084 void visitChildren(AstVisitor visitor) {
20085 super.visitChildren(visitor);
20086 _safelyVisitChild(_uri, visitor);
20087 }
20088 }
20089
20090 /**
20091 * Validation codes returned by [UriBasedDirective.validate].
20092 */
20093 class UriValidationCode {
20094 static const UriValidationCode INVALID_URI =
20095 const UriValidationCode('INVALID_URI');
20096
20097 static const UriValidationCode URI_WITH_INTERPOLATION =
20098 const UriValidationCode('URI_WITH_INTERPOLATION');
20099
20100 static const UriValidationCode URI_WITH_DART_EXT_SCHEME =
20101 const UriValidationCode('URI_WITH_DART_EXT_SCHEME');
20102
20103 /**
20104 * The name of the validation code.
20105 */
20106 final String name;
20107
20108 /**
20109 * Initialize a newly created validation code to have the given [name].
20110 */
20111 const UriValidationCode(this.name);
20112
20113 @override
20114 String toString() => name;
20115 }
20116
20117 /**
20118 * An identifier that has an initial value associated with it. Instances of this
20119 * class are always children of the class [VariableDeclarationList].
20120 *
20121 * > variableDeclaration ::=
20122 * > [SimpleIdentifier] ('=' [Expression])?
20123 *
20124 * TODO(paulberry): the grammar does not allow metadata to be associated with
20125 * a VariableDeclaration, and currently we don't record comments for it either.
20126 * Consider changing the class hierarchy so that [VariableDeclaration] does not
20127 * extend [Declaration].
20128 */
20129 class VariableDeclaration extends Declaration {
20130 /**
20131 * The name of the variable being declared.
20132 */
20133 SimpleIdentifier _name;
20134
20135 /**
20136 * The equal sign separating the variable name from the initial value, or
20137 * `null` if the initial value was not specified.
20138 */
20139 Token equals;
20140
20141 /**
20142 * The expression used to compute the initial value for the variable, or
20143 * `null` if the initial value was not specified.
20144 */
20145 Expression _initializer;
20146
20147 /**
20148 * Initialize a newly created variable declaration. The [equals] and
20149 * [initializer] can be `null` if there is no initializer.
20150 */
20151 VariableDeclaration(
20152 SimpleIdentifier name, this.equals, Expression initializer)
20153 : super(null, null) {
20154 _name = _becomeParentOf(name);
20155 _initializer = _becomeParentOf(initializer);
20156 }
20157
20158 @override
20159 Iterable get childEntities =>
20160 super._childEntities..add(_name)..add(equals)..add(_initializer);
20161
20162 /**
20163 * This overridden implementation of getDocumentationComment() looks in the
20164 * grandparent node for dartdoc comments if no documentation is specifically
20165 * available on the node.
20166 */
20167 @override
20168 Comment get documentationComment {
20169 Comment comment = super.documentationComment;
20170 if (comment == null) {
20171 if (parent != null && parent.parent != null) {
20172 AstNode node = parent.parent;
20173 if (node is AnnotatedNode) {
20174 return node.documentationComment;
20175 }
20176 }
20177 }
20178 return comment;
20179 }
20180
20181 @override
20182 VariableElement get element =>
20183 _name != null ? (_name.staticElement as VariableElement) : null;
20184
20185 @override
20186 Token get endToken {
20187 if (_initializer != null) {
20188 return _initializer.endToken;
20189 }
20190 return _name.endToken;
20191 }
20192
20193 @override
20194 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
20195
20196 /**
20197 * Return the expression used to compute the initial value for the variable,
20198 * or `null` if the initial value was not specified.
20199 */
20200 Expression get initializer => _initializer;
20201
20202 /**
20203 * Set the expression used to compute the initial value for the variable to
20204 * the given [expression].
20205 */
20206 void set initializer(Expression expression) {
20207 _initializer = _becomeParentOf(expression);
20208 }
20209
20210 /**
20211 * Return `true` if this variable was declared with the 'const' modifier.
20212 */
20213 bool get isConst {
20214 AstNode parent = this.parent;
20215 return parent is VariableDeclarationList && parent.isConst;
20216 }
20217
20218 /**
20219 * Return `true` if this variable was declared with the 'final' modifier.
20220 * Variables that are declared with the 'const' modifier will return `false`
20221 * even though they are implicitly final.
20222 */
20223 bool get isFinal {
20224 AstNode parent = this.parent;
20225 return parent is VariableDeclarationList && parent.isFinal;
20226 }
20227
20228 /**
20229 * Return the name of the variable being declared.
20230 */
20231 SimpleIdentifier get name => _name;
20232
20233 /**
20234 * Set the name of the variable being declared to the given [identifier].
20235 */
20236 void set name(SimpleIdentifier identifier) {
20237 _name = _becomeParentOf(identifier);
20238 }
20239
20240 @override
20241 accept(AstVisitor visitor) => visitor.visitVariableDeclaration(this);
20242
20243 @override
20244 void visitChildren(AstVisitor visitor) {
20245 super.visitChildren(visitor);
20246 _safelyVisitChild(_name, visitor);
20247 _safelyVisitChild(_initializer, visitor);
20248 }
20249 }
20250
20251 /**
20252 * The declaration of one or more variables of the same type.
20253 *
20254 * > variableDeclarationList ::=
20255 * > finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])*
20256 * >
20257 * > finalConstVarOrType ::=
20258 * > | 'final' [TypeName]?
20259 * > | 'const' [TypeName]?
20260 * > | 'var'
20261 * > | [TypeName]
20262 */
20263 class VariableDeclarationList extends AnnotatedNode {
20264 /**
20265 * The token representing the 'final', 'const' or 'var' keyword, or `null` if
20266 * no keyword was included.
20267 */
20268 Token keyword;
20269
20270 /**
20271 * The type of the variables being declared, or `null` if no type was provided .
20272 */
20273 TypeName _type;
20274
20275 /**
20276 * A list containing the individual variables being declared.
20277 */
20278 NodeList<VariableDeclaration> _variables;
20279
20280 /**
20281 * Initialize a newly created variable declaration list. Either or both of the
20282 * [comment] and [metadata] can be `null` if the variable list does not have
20283 * the corresponding attribute. The [keyword] can be `null` if a type was
20284 * specified. The [type] must be `null` if the keyword is 'var'.
20285 */
20286 VariableDeclarationList(Comment comment, List<Annotation> metadata,
20287 this.keyword, TypeName type, List<VariableDeclaration> variables)
20288 : super(comment, metadata) {
20289 _type = _becomeParentOf(type);
20290 _variables = new NodeList<VariableDeclaration>(this, variables);
20291 }
20292
20293 @override
20294 // TODO(paulberry): include commas.
20295 Iterable get childEntities => super._childEntities
20296 ..add(keyword)
20297 ..add(_type)
20298 ..addAll(_variables);
20299
20300 @override
20301 Token get endToken => _variables.endToken;
20302
20303 @override
20304 Token get firstTokenAfterCommentAndMetadata {
20305 if (keyword != null) {
20306 return keyword;
20307 } else if (_type != null) {
20308 return _type.beginToken;
20309 }
20310 return _variables.beginToken;
20311 }
20312
20313 /**
20314 * Return `true` if the variables in this list were declared with the 'const'
20315 * modifier.
20316 */
20317 bool get isConst => keyword is KeywordToken &&
20318 (keyword as KeywordToken).keyword == Keyword.CONST;
20319
20320 /**
20321 * Return `true` if the variables in this list were declared with the 'final'
20322 * modifier. Variables that are declared with the 'const' modifier will return
20323 * `false` even though they are implicitly final. (In other words, this is a
20324 * syntactic check rather than a semantic check.)
20325 */
20326 bool get isFinal => keyword is KeywordToken &&
20327 (keyword as KeywordToken).keyword == Keyword.FINAL;
20328
20329 /**
20330 * Return the type of the variables being declared, or `null` if no type was
20331 * provided.
20332 */
20333 TypeName get type => _type;
20334
20335 /**
20336 * Set the type of the variables being declared to the given [typeName].
20337 */
20338 void set type(TypeName typeName) {
20339 _type = _becomeParentOf(typeName);
20340 }
20341
20342 /**
20343 * Return a list containing the individual variables being declared.
20344 */
20345 NodeList<VariableDeclaration> get variables => _variables;
20346
20347 @override
20348 accept(AstVisitor visitor) => visitor.visitVariableDeclarationList(this);
20349
20350 @override
20351 void visitChildren(AstVisitor visitor) {
20352 super.visitChildren(visitor);
20353 _safelyVisitChild(_type, visitor);
20354 _variables.accept(visitor);
20355 }
20356 }
20357
20358 /**
20359 * A list of variables that are being declared in a context where a statement is
20360 * required.
20361 *
20362 * > variableDeclarationStatement ::=
20363 * > [VariableDeclarationList] ';'
20364 */
20365 class VariableDeclarationStatement extends Statement {
20366 /**
20367 * The variables being declared.
20368 */
20369 VariableDeclarationList _variableList;
20370
20371 /**
20372 * The semicolon terminating the statement.
20373 */
20374 Token semicolon;
20375
20376 /**
20377 * Initialize a newly created variable declaration statement.
20378 */
20379 VariableDeclarationStatement(
20380 VariableDeclarationList variableList, this.semicolon) {
20381 _variableList = _becomeParentOf(variableList);
20382 }
20383
20384 @override
20385 Token get beginToken => _variableList.beginToken;
20386
20387 @override
20388 Iterable get childEntities =>
20389 new ChildEntities()..add(_variableList)..add(semicolon);
20390
20391 @override
20392 Token get endToken => semicolon;
20393
20394 /**
20395 * Return the variables being declared.
20396 */
20397 VariableDeclarationList get variables => _variableList;
20398
20399 /**
20400 * Set the variables being declared to the given list of [variables].
20401 */
20402 void set variables(VariableDeclarationList variables) {
20403 _variableList = _becomeParentOf(variables);
20404 }
20405
20406 @override
20407 accept(AstVisitor visitor) => visitor.visitVariableDeclarationStatement(this);
20408
20409 @override
20410 void visitChildren(AstVisitor visitor) {
20411 _safelyVisitChild(_variableList, visitor);
20412 }
20413 }
20414
20415 /**
20416 * A while statement.
20417 *
20418 * > whileStatement ::=
20419 * > 'while' '(' [Expression] ')' [Statement]
20420 */
20421 class WhileStatement extends Statement {
20422 /**
20423 * The token representing the 'while' keyword.
20424 */
20425 Token whileKeyword;
20426
20427 /**
20428 * The left parenthesis.
20429 */
20430 Token leftParenthesis;
20431
20432 /**
20433 * The expression used to determine whether to execute the body of the loop.
20434 */
20435 Expression _condition;
20436
20437 /**
20438 * The right parenthesis.
20439 */
20440 Token rightParenthesis;
20441
20442 /**
20443 * The body of the loop.
20444 */
20445 Statement _body;
20446
20447 /**
20448 * Initialize a newly created while statement.
20449 */
20450 WhileStatement(this.whileKeyword, this.leftParenthesis, Expression condition,
20451 this.rightParenthesis, Statement body) {
20452 _condition = _becomeParentOf(condition);
20453 _body = _becomeParentOf(body);
20454 }
20455
20456 @override
20457 Token get beginToken => whileKeyword;
20458
20459 /**
20460 * Return the body of the loop.
20461 */
20462 Statement get body => _body;
20463
20464 /**
20465 * Set the body of the loop to the given [statement].
20466 */
20467 void set body(Statement statement) {
20468 _body = _becomeParentOf(statement);
20469 }
20470
20471 @override
20472 Iterable get childEntities => new ChildEntities()
20473 ..add(whileKeyword)
20474 ..add(leftParenthesis)
20475 ..add(_condition)
20476 ..add(rightParenthesis)
20477 ..add(_body);
20478
20479 /**
20480 * Return the expression used to determine whether to execute the body of the
20481 * loop.
20482 */
20483 Expression get condition => _condition;
20484
20485 /**
20486 * Set the expression used to determine whether to execute the body of the
20487 * loop to the given [expression].
20488 */
20489 void set condition(Expression expression) {
20490 _condition = _becomeParentOf(expression);
20491 }
20492
20493 @override
20494 Token get endToken => _body.endToken;
20495
20496 /**
20497 * Return the token representing the 'while' keyword.
20498 */
20499 @deprecated // Use "this.whileKeyword"
20500 Token get keyword => whileKeyword;
20501
20502 /**
20503 * Set the token representing the 'while' keyword to the given [token].
20504 */
20505 @deprecated // Use "this.whileKeyword"
20506 set keyword(Token token) {
20507 whileKeyword = token;
20508 }
20509
20510 @override
20511 accept(AstVisitor visitor) => visitor.visitWhileStatement(this);
20512
20513 @override
20514 void visitChildren(AstVisitor visitor) {
20515 _safelyVisitChild(_condition, visitor);
20516 _safelyVisitChild(_body, visitor);
20517 }
20518 }
20519
20520 /**
20521 * The with clause in a class declaration.
20522 *
20523 * > withClause ::=
20524 * > 'with' [TypeName] (',' [TypeName])*
20525 */
20526 class WithClause extends AstNode {
20527 /**
20528 * The token representing the 'with' keyword.
20529 */
20530 Token withKeyword;
20531
20532 /**
20533 * The names of the mixins that were specified.
20534 */
20535 NodeList<TypeName> _mixinTypes;
20536
20537 /**
20538 * Initialize a newly created with clause.
20539 */
20540 WithClause(this.withKeyword, List<TypeName> mixinTypes) {
20541 _mixinTypes = new NodeList<TypeName>(this, mixinTypes);
20542 }
20543
20544 @override
20545 Token get beginToken => withKeyword;
20546
20547 @override
20548 // TODO(paulberry): add commas.
20549 Iterable get childEntities => new ChildEntities()
20550 ..add(withKeyword)
20551 ..addAll(_mixinTypes);
20552
20553 @override
20554 Token get endToken => _mixinTypes.endToken;
20555
20556 /**
20557 * Set the token representing the 'with' keyword to the given [token].
20558 */
20559 @deprecated // Use "this.withKeyword"
20560 void set mixinKeyword(Token token) {
20561 this.withKeyword = token;
20562 }
20563
20564 /**
20565 * Return the names of the mixins that were specified.
20566 */
20567 NodeList<TypeName> get mixinTypes => _mixinTypes;
20568
20569 @override
20570 accept(AstVisitor visitor) => visitor.visitWithClause(this);
20571
20572 @override
20573 void visitChildren(AstVisitor visitor) {
20574 _mixinTypes.accept(visitor);
20575 }
20576 }
20577
20578 /**
20579 * A yield statement.
20580 *
20581 * > yieldStatement ::=
20582 * > 'yield' '*'? [Expression] ‘;’
20583 */
20584 class YieldStatement extends Statement {
20585 /**
20586 * The 'yield' keyword.
20587 */
20588 Token yieldKeyword;
20589
20590 /**
20591 * The star optionally following the 'yield' keyword.
20592 */
20593 Token star;
20594
20595 /**
20596 * The expression whose value will be yielded.
20597 */
20598 Expression _expression;
20599
20600 /**
20601 * The semicolon following the expression.
20602 */
20603 Token semicolon;
20604
20605 /**
20606 * Initialize a newly created yield expression. The [star] can be `null` if no
20607 * star was provided.
20608 */
20609 YieldStatement(
20610 this.yieldKeyword, this.star, Expression expression, this.semicolon) {
20611 _expression = _becomeParentOf(expression);
20612 }
20613
20614 @override
20615 Token get beginToken {
20616 if (yieldKeyword != null) {
20617 return yieldKeyword;
20618 }
20619 return _expression.beginToken;
20620 }
20621
20622 @override
20623 Iterable get childEntities => new ChildEntities()
20624 ..add(yieldKeyword)
20625 ..add(star)
20626 ..add(_expression)
20627 ..add(semicolon);
20628
20629 @override
20630 Token get endToken {
20631 if (semicolon != null) {
20632 return semicolon;
20633 }
20634 return _expression.endToken;
20635 }
20636
20637 /**
20638 * Return the expression whose value will be yielded.
20639 */
20640 Expression get expression => _expression;
20641
20642 /**
20643 * Set the expression whose value will be yielded to the given [expression].
20644 */
20645 void set expression(Expression expression) {
20646 _expression = _becomeParentOf(expression);
20647 }
20648
20649 @override
20650 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20651
20652 @override
20653 void visitChildren(AstVisitor visitor) {
20654 _safelyVisitChild(_expression, visitor);
20655 }
20656 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/error/pending_error.dart ('k') | packages/analyzer/lib/src/generated/bazel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698