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

Side by Side Diff: mojo/public/dart/third_party/analyzer/lib/src/generated/ast.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library engine.ast;
6
7 import 'dart:collection';
8
9 import 'element.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 /**
427 * TODO(paulberry): Add commas.
428 */
429 @override
430 Iterable get childEntities => new ChildEntities()
431 ..add(leftParenthesis)
432 ..addAll(_arguments)
433 ..add(rightParenthesis);
434
435 /**
436 * Set the parameter elements corresponding to each of the arguments in this
437 * list to the given list of [parameters]. The list of parameters must be the
438 * same length as the number of arguments, but can contain `null` entries if a
439 * given argument does not correspond to a formal parameter.
440 */
441 void set correspondingPropagatedParameters(
442 List<ParameterElement> parameters) {
443 if (parameters.length != _arguments.length) {
444 throw new IllegalArgumentException(
445 "Expected ${_arguments.length} parameters, not ${parameters.length}");
446 }
447 _correspondingPropagatedParameters = parameters;
448 }
449
450 /**
451 * Set the parameter elements corresponding to each of the arguments in this
452 * list to the given list of parameters. The list of parameters must be the
453 * same length as the number of arguments, but can contain `null` entries if a
454 * given argument does not correspond to a formal parameter.
455 */
456 void set correspondingStaticParameters(List<ParameterElement> parameters) {
457 if (parameters.length != _arguments.length) {
458 throw new IllegalArgumentException(
459 "Expected ${_arguments.length} parameters, not ${parameters.length}");
460 }
461 _correspondingStaticParameters = parameters;
462 }
463
464 @override
465 Token get endToken => rightParenthesis;
466
467 @override
468 accept(AstVisitor visitor) => visitor.visitArgumentList(this);
469
470 /**
471 * If
472 * * the given [expression] is a child of this list,
473 * * the AST structure has been resolved,
474 * * the function being invoked is known based on propagated type information,
475 * and
476 * * the expression corresponds to one of the parameters of the function being
477 * invoked,
478 * then return the parameter element representing the parameter to which the
479 * value of the given expression will be bound. Otherwise, return `null`.
480 */
481 @deprecated // Use "expression.propagatedParameterElement"
482 ParameterElement getPropagatedParameterElementFor(Expression expression) {
483 return _getPropagatedParameterElementFor(expression);
484 }
485
486 /**
487 * If
488 * * the given [expression] is a child of this list,
489 * * the AST structure has been resolved,
490 * * the function being invoked is known based on static type information, and
491 * * the expression corresponds to one of the parameters of the function being
492 * invoked,
493 * then return the parameter element representing the parameter to which the
494 * value of the given expression will be bound. Otherwise, return `null`.
495 */
496 @deprecated // Use "expression.staticParameterElement"
497 ParameterElement getStaticParameterElementFor(Expression expression) {
498 return _getStaticParameterElementFor(expression);
499 }
500
501 @override
502 void visitChildren(AstVisitor visitor) {
503 _arguments.accept(visitor);
504 }
505
506 /**
507 * If
508 * * the given [expression] is a child of this list,
509 * * the AST structure has been resolved,
510 * * the function being invoked is known based on propagated type information,
511 * and
512 * * the expression corresponds to one of the parameters of the function being
513 * invoked,
514 * then return the parameter element representing the parameter to which the
515 * value of the given expression will be bound. Otherwise, return `null`.
516 */
517 ParameterElement _getPropagatedParameterElementFor(Expression expression) {
518 if (_correspondingPropagatedParameters == null ||
519 _correspondingPropagatedParameters.length != _arguments.length) {
520 // Either the AST structure has not been resolved, the invocation of which
521 // this list is a part could not be resolved, or the argument list was
522 // modified after the parameters were set.
523 return null;
524 }
525 int index = _arguments.indexOf(expression);
526 if (index < 0) {
527 // The expression isn't a child of this node.
528 return null;
529 }
530 return _correspondingPropagatedParameters[index];
531 }
532
533 /**
534 * If
535 * * the given [expression] is a child of this list,
536 * * the AST structure has been resolved,
537 * * the function being invoked is known based on static type information, and
538 * * the expression corresponds to one of the parameters of the function being
539 * invoked,
540 * then return the parameter element representing the parameter to which the
541 * value of the given expression will be bound. Otherwise, return `null`.
542 */
543 ParameterElement _getStaticParameterElementFor(Expression expression) {
544 if (_correspondingStaticParameters == null ||
545 _correspondingStaticParameters.length != _arguments.length) {
546 // Either the AST structure has not been resolved, the invocation of which
547 // this list is a part could not be resolved, or the argument list was
548 // modified after the parameters were set.
549 return null;
550 }
551 int index = _arguments.indexOf(expression);
552 if (index < 0) {
553 // The expression isn't a child of this node.
554 return null;
555 }
556 return _correspondingStaticParameters[index];
557 }
558 }
559
560 /**
561 * An as expression.
562 *
563 * > asExpression ::=
564 * > [Expression] 'as' [TypeName]
565 */
566 class AsExpression extends Expression {
567 /**
568 * The expression used to compute the value being cast.
569 */
570 Expression _expression;
571
572 /**
573 * The 'as' operator.
574 */
575 Token asOperator;
576
577 /**
578 * The name of the type being cast to.
579 */
580 TypeName _type;
581
582 /**
583 * Initialize a newly created as expression.
584 */
585 AsExpression(Expression expression, this.asOperator, TypeName type) {
586 _expression = _becomeParentOf(expression);
587 _type = _becomeParentOf(type);
588 }
589
590 @override
591 Token get beginToken => _expression.beginToken;
592
593 @override
594 Iterable get childEntities =>
595 new ChildEntities()..add(_expression)..add(asOperator)..add(_type);
596
597 @override
598 Token get endToken => _type.endToken;
599
600 /**
601 * Return the expression used to compute the value being cast.
602 */
603 Expression get expression => _expression;
604
605 /**
606 * Set the expression used to compute the value being cast to the given
607 * [expression].
608 */
609 void set expression(Expression expression) {
610 _expression = _becomeParentOf(expression);
611 }
612
613 @override
614 int get precedence => 7;
615
616 /**
617 * Return the name of the type being cast to.
618 */
619 TypeName get type => _type;
620
621 /**
622 * Set the name of the type being cast to to the given [name].
623 */
624 void set type(TypeName name) {
625 _type = _becomeParentOf(name);
626 }
627
628 @override
629 accept(AstVisitor visitor) => visitor.visitAsExpression(this);
630
631 @override
632 void visitChildren(AstVisitor visitor) {
633 _safelyVisitChild(_expression, visitor);
634 _safelyVisitChild(_type, visitor);
635 }
636 }
637
638 /**
639 * An assert statement.
640 *
641 * > assertStatement ::=
642 * > 'assert' '(' [Expression] ')' ';'
643 */
644 class AssertStatement extends Statement {
645 /**
646 * The token representing the 'assert' keyword.
647 */
648 Token assertKeyword;
649
650 /**
651 * The left parenthesis.
652 */
653 Token leftParenthesis;
654
655 /**
656 * The condition that is being asserted to be `true`.
657 */
658 Expression _condition;
659
660 /**
661 * The right parenthesis.
662 */
663 Token rightParenthesis;
664
665 /**
666 * The semicolon terminating the statement.
667 */
668 Token semicolon;
669
670 /**
671 * Initialize a newly created assert statement.
672 */
673 AssertStatement(this.assertKeyword, this.leftParenthesis,
674 Expression condition, this.rightParenthesis, this.semicolon) {
675 _condition = _becomeParentOf(condition);
676 }
677
678 @override
679 Token get beginToken => assertKeyword;
680
681 @override
682 Iterable get childEntities => new ChildEntities()
683 ..add(assertKeyword)
684 ..add(leftParenthesis)
685 ..add(_condition)
686 ..add(rightParenthesis)
687 ..add(semicolon);
688
689 /**
690 * Return the condition that is being asserted to be `true`.
691 */
692 Expression get condition => _condition;
693
694 /**
695 * Set the condition that is being asserted to be `true` to the given
696 * [expression].
697 */
698 void set condition(Expression condition) {
699 _condition = _becomeParentOf(condition);
700 }
701
702 @override
703 Token get endToken => semicolon;
704
705 /**
706 * Return the token representing the 'assert' keyword.
707 */
708 @deprecated // Use "this.assertKeyword"
709 Token get keyword => assertKeyword;
710
711 /**
712 * Set the token representing the 'assert' keyword to the given [token].
713 */
714 @deprecated // Use "this.assertKeyword"
715 set keyword(Token token) {
716 assertKeyword = token;
717 }
718
719 @override
720 accept(AstVisitor visitor) => visitor.visitAssertStatement(this);
721
722 @override
723 void visitChildren(AstVisitor visitor) {
724 _safelyVisitChild(_condition, visitor);
725 }
726 }
727
728 /**
729 * An assignment expression.
730 *
731 * > assignmentExpression ::=
732 * > [Expression] operator [Expression]
733 */
734 class AssignmentExpression extends Expression {
735 /**
736 * The expression used to compute the left hand side.
737 */
738 Expression _leftHandSide;
739
740 /**
741 * The assignment operator being applied.
742 */
743 Token operator;
744
745 /**
746 * The expression used to compute the right hand side.
747 */
748 Expression _rightHandSide;
749
750 /**
751 * The element associated with the operator based on the static type of the
752 * left-hand-side, or `null` if the AST structure has not been resolved, if
753 * the operator is not a compound operator, or if the operator could not be
754 * resolved.
755 */
756 MethodElement staticElement;
757
758 /**
759 * The element associated with the operator based on the propagated type of
760 * the left-hand-side, or `null` if the AST structure has not been resolved,
761 * if the operator is not a compound operator, or if the operator could not be
762 * resolved.
763 */
764 MethodElement propagatedElement;
765
766 /**
767 * Initialize a newly created assignment expression.
768 */
769 AssignmentExpression(
770 Expression leftHandSide, this.operator, Expression rightHandSide) {
771 if (leftHandSide == null || rightHandSide == null) {
772 String message;
773 if (leftHandSide == null) {
774 if (rightHandSide == null) {
775 message = "Both the left-hand and right-hand sides are null";
776 } else {
777 message = "The left-hand size is null";
778 }
779 } else {
780 message = "The right-hand size is null";
781 }
782 AnalysisEngine.instance.logger.logError(
783 message, new CaughtException(new AnalysisException(message), null));
784 }
785 _leftHandSide = _becomeParentOf(leftHandSide);
786 _rightHandSide = _becomeParentOf(rightHandSide);
787 }
788
789 @override
790 Token get beginToken => _leftHandSide.beginToken;
791
792 /**
793 * Return the best element available for this operator. If resolution was able
794 * to find a better element based on type propagation, that element will be
795 * returned. Otherwise, the element found using the result of static analysis
796 * will be returned. If resolution has not been performed, then `null` will be
797 * returned.
798 */
799 MethodElement get bestElement {
800 MethodElement element = propagatedElement;
801 if (element == null) {
802 element = staticElement;
803 }
804 return element;
805 }
806
807 @override
808 Iterable get childEntities => new ChildEntities()
809 ..add(_leftHandSide)
810 ..add(operator)
811 ..add(_rightHandSide);
812
813 @override
814 Token get endToken => _rightHandSide.endToken;
815
816 /**
817 * Set the expression used to compute the left hand side to the given
818 * [expression].
819 */
820 Expression get leftHandSide => _leftHandSide;
821
822 /**
823 * Return the expression used to compute the left hand side.
824 */
825 void set leftHandSide(Expression expression) {
826 _leftHandSide = _becomeParentOf(expression);
827 }
828
829 @override
830 int get precedence => 1;
831
832 /**
833 * If the AST structure has been resolved, and the function being invoked is
834 * known based on propagated type information, then return the parameter
835 * element representing the parameter to which the value of the right operand
836 * will be bound. Otherwise, return `null`.
837 */
838 @deprecated // Use "expression.propagatedParameterElement"
839 ParameterElement get propagatedParameterElementForRightHandSide {
840 return _propagatedParameterElementForRightHandSide;
841 }
842
843 /**
844 * Return the expression used to compute the right hand side.
845 */
846 Expression get rightHandSide => _rightHandSide;
847
848 /**
849 * Set the expression used to compute the left hand side to the given
850 * [expression].
851 */
852 void set rightHandSide(Expression expression) {
853 _rightHandSide = _becomeParentOf(expression);
854 }
855
856 /**
857 * If the AST structure has been resolved, and the function being invoked is
858 * known based on static type information, then return the parameter element
859 * representing the parameter to which the value of the right operand will be
860 * bound. Otherwise, return `null`.
861 */
862 @deprecated // Use "expression.staticParameterElement"
863 ParameterElement get staticParameterElementForRightHandSide {
864 return _staticParameterElementForRightHandSide;
865 }
866
867 /**
868 * If the AST structure has been resolved, and the function being invoked is
869 * known based on propagated type information, then return the parameter
870 * element representing the parameter to which the value of the right operand
871 * will be bound. Otherwise, return `null`.
872 */
873 ParameterElement get _propagatedParameterElementForRightHandSide {
874 ExecutableElement executableElement = null;
875 if (propagatedElement != null) {
876 executableElement = propagatedElement;
877 } else {
878 if (_leftHandSide is Identifier) {
879 Identifier identifier = _leftHandSide as Identifier;
880 Element leftElement = identifier.propagatedElement;
881 if (leftElement is ExecutableElement) {
882 executableElement = leftElement;
883 }
884 }
885 if (_leftHandSide is PropertyAccess) {
886 SimpleIdentifier identifier =
887 (_leftHandSide as PropertyAccess).propertyName;
888 Element leftElement = identifier.propagatedElement;
889 if (leftElement is ExecutableElement) {
890 executableElement = leftElement;
891 }
892 }
893 }
894 if (executableElement == null) {
895 return null;
896 }
897 List<ParameterElement> parameters = executableElement.parameters;
898 if (parameters.length < 1) {
899 return null;
900 }
901 return parameters[0];
902 }
903
904 /**
905 * If the AST structure has been resolved, and the function being invoked is
906 * known based on static type information, then return the parameter element
907 * representing the parameter to which the value of the right operand will be
908 * bound. Otherwise, return `null`.
909 */
910 ParameterElement get _staticParameterElementForRightHandSide {
911 ExecutableElement executableElement = null;
912 if (staticElement != null) {
913 executableElement = staticElement;
914 } else {
915 if (_leftHandSide is Identifier) {
916 Element leftElement = (_leftHandSide as Identifier).staticElement;
917 if (leftElement is ExecutableElement) {
918 executableElement = leftElement;
919 }
920 }
921 if (_leftHandSide is PropertyAccess) {
922 Element leftElement =
923 (_leftHandSide as PropertyAccess).propertyName.staticElement;
924 if (leftElement is ExecutableElement) {
925 executableElement = leftElement;
926 }
927 }
928 }
929 if (executableElement == null) {
930 return null;
931 }
932 List<ParameterElement> parameters = executableElement.parameters;
933 if (parameters.length < 1) {
934 return null;
935 }
936 return parameters[0];
937 }
938
939 @override
940 accept(AstVisitor visitor) => visitor.visitAssignmentExpression(this);
941
942 @override
943 void visitChildren(AstVisitor visitor) {
944 _safelyVisitChild(_leftHandSide, visitor);
945 _safelyVisitChild(_rightHandSide, visitor);
946 }
947 }
948
949 /**
950 * An AST visitor that will clone any AST structure that it visits. The cloner
951 * will only clone the structure, it will not preserve any resolution results or
952 * properties associated with the nodes.
953 */
954 class AstCloner implements AstVisitor<AstNode> {
955 /**
956 * A flag indicating whether tokens should be cloned while cloning an AST
957 * structure.
958 */
959 final bool cloneTokens;
960
961 /**
962 * Initialize a newly created AST cloner to optionally clone tokens while
963 * cloning AST nodes if [cloneTokens] is `true`.
964 */
965 AstCloner(
966 [this.cloneTokens = false]); // TODO(brianwilkerson) Change this to be a n amed parameter.
967
968 /**
969 * Return a clone of the given [node].
970 */
971 AstNode cloneNode(AstNode node) {
972 if (node == null) {
973 return null;
974 }
975 return node.accept(this) as AstNode;
976 }
977
978 /**
979 * Return a list containing cloned versions of the nodes in the given list of
980 * [nodes].
981 */
982 List<AstNode> cloneNodeList(NodeList nodes) {
983 int count = nodes.length;
984 List clonedNodes = new List();
985 for (int i = 0; i < count; i++) {
986 clonedNodes.add((nodes[i]).accept(this) as AstNode);
987 }
988 return clonedNodes;
989 }
990
991 /**
992 * Clone the given [token] if tokens are supposed to be cloned.
993 */
994 Token cloneToken(Token token) {
995 if (cloneTokens) {
996 return (token == null ? null : token.copy());
997 } else {
998 return token;
999 }
1000 }
1001
1002 /**
1003 * Clone the given [tokens] if tokens are supposed to be cloned.
1004 */
1005 List<Token> cloneTokenList(List<Token> tokens) {
1006 if (cloneTokens) {
1007 return tokens.map((Token token) => token.copy()).toList();
1008 }
1009 return tokens;
1010 }
1011
1012 @override
1013 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
1014 new AdjacentStrings(cloneNodeList(node.strings));
1015
1016 @override
1017 Annotation visitAnnotation(Annotation node) => new Annotation(
1018 cloneToken(node.atSign), cloneNode(node.name), cloneToken(node.period),
1019 cloneNode(node.constructorName), cloneNode(node.arguments));
1020
1021 @override
1022 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
1023 cloneToken(node.leftParenthesis), cloneNodeList(node.arguments),
1024 cloneToken(node.rightParenthesis));
1025
1026 @override
1027 AsExpression visitAsExpression(AsExpression node) => new AsExpression(
1028 cloneNode(node.expression), cloneToken(node.asOperator),
1029 cloneNode(node.type));
1030
1031 @override
1032 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
1033 cloneToken(node.assertKeyword), cloneToken(node.leftParenthesis),
1034 cloneNode(node.condition), cloneToken(node.rightParenthesis),
1035 cloneToken(node.semicolon));
1036
1037 @override
1038 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) =>
1039 new AssignmentExpression(cloneNode(node.leftHandSide),
1040 cloneToken(node.operator), cloneNode(node.rightHandSide));
1041
1042 @override
1043 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
1044 new AwaitExpression(
1045 cloneToken(node.awaitKeyword), cloneNode(node.expression));
1046
1047 @override
1048 BinaryExpression visitBinaryExpression(BinaryExpression node) =>
1049 new BinaryExpression(cloneNode(node.leftOperand),
1050 cloneToken(node.operator), cloneNode(node.rightOperand));
1051
1052 @override
1053 Block visitBlock(Block node) => new Block(cloneToken(node.leftBracket),
1054 cloneNodeList(node.statements), cloneToken(node.rightBracket));
1055
1056 @override
1057 BlockFunctionBody visitBlockFunctionBody(
1058 BlockFunctionBody node) => new BlockFunctionBody(
1059 cloneToken(node.keyword), cloneToken(node.star), cloneNode(node.block));
1060
1061 @override
1062 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) =>
1063 new BooleanLiteral(cloneToken(node.literal), node.value);
1064
1065 @override
1066 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
1067 cloneToken(node.breakKeyword), cloneNode(node.label),
1068 cloneToken(node.semicolon));
1069
1070 @override
1071 CascadeExpression visitCascadeExpression(CascadeExpression node) =>
1072 new CascadeExpression(
1073 cloneNode(node.target), cloneNodeList(node.cascadeSections));
1074
1075 @override
1076 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
1077 cloneToken(node.onKeyword), cloneNode(node.exceptionType),
1078 cloneToken(node.catchKeyword), cloneToken(node.leftParenthesis),
1079 cloneNode(node.exceptionParameter), cloneToken(node.comma),
1080 cloneNode(node.stackTraceParameter), cloneToken(node.rightParenthesis),
1081 cloneNode(node.body));
1082
1083 @override
1084 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
1085 ClassDeclaration copy = new ClassDeclaration(
1086 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1087 cloneToken(node.abstractKeyword), cloneToken(node.classKeyword),
1088 cloneNode(node.name), cloneNode(node.typeParameters),
1089 cloneNode(node.extendsClause), cloneNode(node.withClause),
1090 cloneNode(node.implementsClause), cloneToken(node.leftBracket),
1091 cloneNodeList(node.members), cloneToken(node.rightBracket));
1092 copy.nativeClause = cloneNode(node.nativeClause);
1093 return copy;
1094 }
1095
1096 @override
1097 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
1098 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1099 cloneToken(node.typedefKeyword), cloneNode(node.name),
1100 cloneNode(node.typeParameters), cloneToken(node.equals),
1101 cloneToken(node.abstractKeyword), cloneNode(node.superclass),
1102 cloneNode(node.withClause), cloneNode(node.implementsClause),
1103 cloneToken(node.semicolon));
1104
1105 @override
1106 Comment visitComment(Comment node) {
1107 if (node.isDocumentation) {
1108 return Comment.createDocumentationCommentWithReferences(
1109 cloneTokenList(node.tokens), cloneNodeList(node.references));
1110 } else if (node.isBlock) {
1111 return Comment.createBlockComment(cloneTokenList(node.tokens));
1112 }
1113 return Comment.createEndOfLineComment(cloneTokenList(node.tokens));
1114 }
1115
1116 @override
1117 CommentReference visitCommentReference(CommentReference node) =>
1118 new CommentReference(
1119 cloneToken(node.newKeyword), cloneNode(node.identifier));
1120
1121 @override
1122 CompilationUnit visitCompilationUnit(CompilationUnit node) {
1123 CompilationUnit clone = new CompilationUnit(cloneToken(node.beginToken),
1124 cloneNode(node.scriptTag), cloneNodeList(node.directives),
1125 cloneNodeList(node.declarations), cloneToken(node.endToken));
1126 clone.lineInfo = node.lineInfo;
1127 return clone;
1128 }
1129
1130 @override
1131 ConditionalExpression visitConditionalExpression(
1132 ConditionalExpression node) => new ConditionalExpression(
1133 cloneNode(node.condition), cloneToken(node.question),
1134 cloneNode(node.thenExpression), cloneToken(node.colon),
1135 cloneNode(node.elseExpression));
1136
1137 @override
1138 ConstructorDeclaration visitConstructorDeclaration(
1139 ConstructorDeclaration node) => new ConstructorDeclaration(
1140 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1141 cloneToken(node.externalKeyword), cloneToken(node.constKeyword),
1142 cloneToken(node.factoryKeyword), cloneNode(node.returnType),
1143 cloneToken(node.period), cloneNode(node.name), cloneNode(node.parameters),
1144 cloneToken(node.separator), cloneNodeList(node.initializers),
1145 cloneNode(node.redirectedConstructor), cloneNode(node.body));
1146
1147 @override
1148 ConstructorFieldInitializer visitConstructorFieldInitializer(
1149 ConstructorFieldInitializer node) => new ConstructorFieldInitializer(
1150 cloneToken(node.thisKeyword), cloneToken(node.period),
1151 cloneNode(node.fieldName), cloneToken(node.equals),
1152 cloneNode(node.expression));
1153
1154 @override
1155 ConstructorName visitConstructorName(ConstructorName node) =>
1156 new ConstructorName(
1157 cloneNode(node.type), cloneToken(node.period), cloneNode(node.name));
1158
1159 @override
1160 ContinueStatement visitContinueStatement(ContinueStatement node) =>
1161 new ContinueStatement(cloneToken(node.continueKeyword),
1162 cloneNode(node.label), cloneToken(node.semicolon));
1163
1164 @override
1165 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
1166 new DeclaredIdentifier(cloneNode(node.documentationComment),
1167 cloneNodeList(node.metadata), cloneToken(node.keyword),
1168 cloneNode(node.type), cloneNode(node.identifier));
1169
1170 @override
1171 DefaultFormalParameter visitDefaultFormalParameter(
1172 DefaultFormalParameter node) => new DefaultFormalParameter(
1173 cloneNode(node.parameter), node.kind, cloneToken(node.separator),
1174 cloneNode(node.defaultValue));
1175
1176 @override
1177 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
1178 cloneToken(node.doKeyword), cloneNode(node.body),
1179 cloneToken(node.whileKeyword), cloneToken(node.leftParenthesis),
1180 cloneNode(node.condition), cloneToken(node.rightParenthesis),
1181 cloneToken(node.semicolon));
1182
1183 @override
1184 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) =>
1185 new DoubleLiteral(cloneToken(node.literal), node.value);
1186
1187 @override
1188 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
1189 new EmptyFunctionBody(cloneToken(node.semicolon));
1190
1191 @override
1192 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
1193 new EmptyStatement(cloneToken(node.semicolon));
1194
1195 @override
1196 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
1197 new EnumConstantDeclaration(cloneNode(node.documentationComment),
1198 cloneNodeList(node.metadata), cloneNode(node.name));
1199
1200 @override
1201 EnumDeclaration visitEnumDeclaration(EnumDeclaration node) =>
1202 new EnumDeclaration(cloneNode(node.documentationComment),
1203 cloneNodeList(node.metadata), cloneToken(node.enumKeyword),
1204 cloneNode(node.name), cloneToken(node.leftBracket),
1205 cloneNodeList(node.constants), cloneToken(node.rightBracket));
1206
1207 @override
1208 ExportDirective visitExportDirective(ExportDirective node) {
1209 ExportDirective directive = new ExportDirective(
1210 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1211 cloneToken(node.keyword), cloneNode(node.uri),
1212 cloneNodeList(node.combinators), cloneToken(node.semicolon));
1213 directive.source = node.source;
1214 directive.uriContent = node.uriContent;
1215 return directive;
1216 }
1217
1218 @override
1219 ExpressionFunctionBody visitExpressionFunctionBody(
1220 ExpressionFunctionBody node) => new ExpressionFunctionBody(
1221 cloneToken(node.keyword), cloneToken(node.functionDefinition),
1222 cloneNode(node.expression), cloneToken(node.semicolon));
1223
1224 @override
1225 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
1226 new ExpressionStatement(
1227 cloneNode(node.expression), cloneToken(node.semicolon));
1228
1229 @override
1230 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
1231 cloneToken(node.extendsKeyword), cloneNode(node.superclass));
1232
1233 @override
1234 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
1235 new FieldDeclaration(cloneNode(node.documentationComment),
1236 cloneNodeList(node.metadata), cloneToken(node.staticKeyword),
1237 cloneNode(node.fields), cloneToken(node.semicolon));
1238
1239 @override
1240 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
1241 new FieldFormalParameter(cloneNode(node.documentationComment),
1242 cloneNodeList(node.metadata), cloneToken(node.keyword),
1243 cloneNode(node.type), cloneToken(node.thisKeyword),
1244 cloneToken(node.period), cloneNode(node.identifier),
1245 cloneNode(node.typeParameters), cloneNode(node.parameters));
1246
1247 @override
1248 ForEachStatement visitForEachStatement(ForEachStatement node) {
1249 DeclaredIdentifier loopVariable = node.loopVariable;
1250 if (loopVariable == null) {
1251 return new ForEachStatement.withReference(cloneToken(node.awaitKeyword),
1252 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis),
1253 cloneNode(node.identifier), cloneToken(node.inKeyword),
1254 cloneNode(node.iterable), cloneToken(node.rightParenthesis),
1255 cloneNode(node.body));
1256 }
1257 return new ForEachStatement.withDeclaration(cloneToken(node.awaitKeyword),
1258 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis),
1259 cloneNode(loopVariable), cloneToken(node.inKeyword),
1260 cloneNode(node.iterable), cloneToken(node.rightParenthesis),
1261 cloneNode(node.body));
1262 }
1263
1264 @override
1265 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
1266 new FormalParameterList(cloneToken(node.leftParenthesis),
1267 cloneNodeList(node.parameters), cloneToken(node.leftDelimiter),
1268 cloneToken(node.rightDelimiter), cloneToken(node.rightParenthesis));
1269
1270 @override
1271 ForStatement visitForStatement(ForStatement node) => new ForStatement(
1272 cloneToken(node.forKeyword), cloneToken(node.leftParenthesis),
1273 cloneNode(node.variables), cloneNode(node.initialization),
1274 cloneToken(node.leftSeparator), cloneNode(node.condition),
1275 cloneToken(node.rightSeparator), cloneNodeList(node.updaters),
1276 cloneToken(node.rightParenthesis), cloneNode(node.body));
1277
1278 @override
1279 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
1280 new FunctionDeclaration(cloneNode(node.documentationComment),
1281 cloneNodeList(node.metadata), cloneToken(node.externalKeyword),
1282 cloneNode(node.returnType), cloneToken(node.propertyKeyword),
1283 cloneNode(node.name), cloneNode(node.functionExpression));
1284
1285 @override
1286 FunctionDeclarationStatement visitFunctionDeclarationStatement(
1287 FunctionDeclarationStatement node) =>
1288 new FunctionDeclarationStatement(cloneNode(node.functionDeclaration));
1289
1290 @override
1291 FunctionExpression visitFunctionExpression(FunctionExpression node) =>
1292 new FunctionExpression(cloneNode(node.typeParameters),
1293 cloneNode(node.parameters), cloneNode(node.body));
1294
1295 @override
1296 FunctionExpressionInvocation visitFunctionExpressionInvocation(
1297 FunctionExpressionInvocation node) => new FunctionExpressionInvocation(
1298 cloneNode(node.function), cloneNode(node.typeArguments),
1299 cloneNode(node.argumentList));
1300
1301 @override
1302 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
1303 new FunctionTypeAlias(cloneNode(node.documentationComment),
1304 cloneNodeList(node.metadata), cloneToken(node.typedefKeyword),
1305 cloneNode(node.returnType), cloneNode(node.name),
1306 cloneNode(node.typeParameters), cloneNode(node.parameters),
1307 cloneToken(node.semicolon));
1308
1309 @override
1310 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
1311 FunctionTypedFormalParameter node) => new FunctionTypedFormalParameter(
1312 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1313 cloneNode(node.returnType), cloneNode(node.identifier),
1314 cloneNode(node.typeParameters), cloneNode(node.parameters));
1315
1316 @override
1317 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
1318 cloneToken(node.keyword), cloneNodeList(node.hiddenNames));
1319
1320 @override
1321 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
1322 cloneToken(node.ifKeyword), cloneToken(node.leftParenthesis),
1323 cloneNode(node.condition), cloneToken(node.rightParenthesis),
1324 cloneNode(node.thenStatement), cloneToken(node.elseKeyword),
1325 cloneNode(node.elseStatement));
1326
1327 @override
1328 ImplementsClause visitImplementsClause(ImplementsClause node) =>
1329 new ImplementsClause(
1330 cloneToken(node.implementsKeyword), cloneNodeList(node.interfaces));
1331
1332 @override
1333 ImportDirective visitImportDirective(ImportDirective node) {
1334 ImportDirective directive = new ImportDirective(
1335 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1336 cloneToken(node.keyword), cloneNode(node.uri),
1337 cloneToken(node.deferredKeyword), cloneToken(node.asKeyword),
1338 cloneNode(node.prefix), cloneNodeList(node.combinators),
1339 cloneToken(node.semicolon));
1340 directive.source = node.source;
1341 directive.uriContent = node.uriContent;
1342 return directive;
1343 }
1344
1345 @override
1346 IndexExpression visitIndexExpression(IndexExpression node) {
1347 Token period = node.period;
1348 if (period == null) {
1349 return new IndexExpression.forTarget(cloneNode(node.target),
1350 cloneToken(node.leftBracket), cloneNode(node.index),
1351 cloneToken(node.rightBracket));
1352 } else {
1353 return new IndexExpression.forCascade(cloneToken(period),
1354 cloneToken(node.leftBracket), cloneNode(node.index),
1355 cloneToken(node.rightBracket));
1356 }
1357 }
1358
1359 @override
1360 InstanceCreationExpression visitInstanceCreationExpression(
1361 InstanceCreationExpression node) => new InstanceCreationExpression(
1362 cloneToken(node.keyword), cloneNode(node.constructorName),
1363 cloneNode(node.argumentList));
1364
1365 @override
1366 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) =>
1367 new IntegerLiteral(cloneToken(node.literal), node.value);
1368
1369 @override
1370 InterpolationExpression visitInterpolationExpression(
1371 InterpolationExpression node) => new InterpolationExpression(
1372 cloneToken(node.leftBracket), cloneNode(node.expression),
1373 cloneToken(node.rightBracket));
1374
1375 @override
1376 InterpolationString visitInterpolationString(InterpolationString node) =>
1377 new InterpolationString(cloneToken(node.contents), node.value);
1378
1379 @override
1380 IsExpression visitIsExpression(IsExpression node) => new IsExpression(
1381 cloneNode(node.expression), cloneToken(node.isOperator),
1382 cloneToken(node.notOperator), cloneNode(node.type));
1383
1384 @override
1385 Label visitLabel(Label node) =>
1386 new Label(cloneNode(node.label), cloneToken(node.colon));
1387
1388 @override
1389 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
1390 new LabeledStatement(
1391 cloneNodeList(node.labels), cloneNode(node.statement));
1392
1393 @override
1394 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
1395 new LibraryDirective(cloneNode(node.documentationComment),
1396 cloneNodeList(node.metadata), cloneToken(node.libraryKeyword),
1397 cloneNode(node.name), cloneToken(node.semicolon));
1398
1399 @override
1400 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) =>
1401 new LibraryIdentifier(cloneNodeList(node.components));
1402
1403 @override
1404 ListLiteral visitListLiteral(ListLiteral node) => new ListLiteral(
1405 cloneToken(node.constKeyword), cloneNode(node.typeArguments),
1406 cloneToken(node.leftBracket), cloneNodeList(node.elements),
1407 cloneToken(node.rightBracket));
1408
1409 @override
1410 MapLiteral visitMapLiteral(MapLiteral node) => new MapLiteral(
1411 cloneToken(node.constKeyword), cloneNode(node.typeArguments),
1412 cloneToken(node.leftBracket), cloneNodeList(node.entries),
1413 cloneToken(node.rightBracket));
1414
1415 @override
1416 MapLiteralEntry visitMapLiteralEntry(
1417 MapLiteralEntry node) => new MapLiteralEntry(
1418 cloneNode(node.key), cloneToken(node.separator), cloneNode(node.value));
1419
1420 @override
1421 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
1422 new MethodDeclaration(cloneNode(node.documentationComment),
1423 cloneNodeList(node.metadata), cloneToken(node.externalKeyword),
1424 cloneToken(node.modifierKeyword), cloneNode(node.returnType),
1425 cloneToken(node.propertyKeyword), cloneToken(node.operatorKeyword),
1426 cloneNode(node.name), cloneNode(node.typeParameters),
1427 cloneNode(node.parameters), cloneNode(node.body));
1428
1429 @override
1430 MethodInvocation visitMethodInvocation(MethodInvocation node) =>
1431 new MethodInvocation(cloneNode(node.target), cloneToken(node.operator),
1432 cloneNode(node.methodName), cloneNode(node.typeArguments),
1433 cloneNode(node.argumentList));
1434
1435 @override
1436 NamedExpression visitNamedExpression(NamedExpression node) =>
1437 new NamedExpression(cloneNode(node.name), cloneNode(node.expression));
1438
1439 @override
1440 AstNode visitNativeClause(NativeClause node) =>
1441 new NativeClause(cloneToken(node.nativeKeyword), cloneNode(node.name));
1442
1443 @override
1444 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
1445 new NativeFunctionBody(cloneToken(node.nativeKeyword),
1446 cloneNode(node.stringLiteral), cloneToken(node.semicolon));
1447
1448 @override
1449 NullLiteral visitNullLiteral(NullLiteral node) =>
1450 new NullLiteral(cloneToken(node.literal));
1451
1452 @override
1453 ParenthesizedExpression visitParenthesizedExpression(
1454 ParenthesizedExpression node) => new ParenthesizedExpression(
1455 cloneToken(node.leftParenthesis), cloneNode(node.expression),
1456 cloneToken(node.rightParenthesis));
1457
1458 @override
1459 PartDirective visitPartDirective(PartDirective node) {
1460 PartDirective directive = new PartDirective(
1461 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1462 cloneToken(node.partKeyword), cloneNode(node.uri),
1463 cloneToken(node.semicolon));
1464 directive.source = node.source;
1465 directive.uriContent = node.uriContent;
1466 return directive;
1467 }
1468
1469 @override
1470 PartOfDirective visitPartOfDirective(PartOfDirective node) =>
1471 new PartOfDirective(cloneNode(node.documentationComment),
1472 cloneNodeList(node.metadata), cloneToken(node.partKeyword),
1473 cloneToken(node.ofKeyword), cloneNode(node.libraryName),
1474 cloneToken(node.semicolon));
1475
1476 @override
1477 PostfixExpression visitPostfixExpression(PostfixExpression node) =>
1478 new PostfixExpression(cloneNode(node.operand), cloneToken(node.operator));
1479
1480 @override
1481 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) =>
1482 new PrefixedIdentifier(cloneNode(node.prefix), cloneToken(node.period),
1483 cloneNode(node.identifier));
1484
1485 @override
1486 PrefixExpression visitPrefixExpression(PrefixExpression node) =>
1487 new PrefixExpression(cloneToken(node.operator), cloneNode(node.operand));
1488
1489 @override
1490 PropertyAccess visitPropertyAccess(PropertyAccess node) => new PropertyAccess(
1491 cloneNode(node.target), cloneToken(node.operator),
1492 cloneNode(node.propertyName));
1493
1494 @override
1495 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
1496 RedirectingConstructorInvocation node) =>
1497 new RedirectingConstructorInvocation(cloneToken(node.thisKeyword),
1498 cloneToken(node.period), cloneNode(node.constructorName),
1499 cloneNode(node.argumentList));
1500
1501 @override
1502 RethrowExpression visitRethrowExpression(RethrowExpression node) =>
1503 new RethrowExpression(cloneToken(node.rethrowKeyword));
1504
1505 @override
1506 ReturnStatement visitReturnStatement(ReturnStatement node) =>
1507 new ReturnStatement(cloneToken(node.returnKeyword),
1508 cloneNode(node.expression), cloneToken(node.semicolon));
1509
1510 @override
1511 ScriptTag visitScriptTag(ScriptTag node) =>
1512 new ScriptTag(cloneToken(node.scriptTag));
1513
1514 @override
1515 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
1516 cloneToken(node.keyword), cloneNodeList(node.shownNames));
1517
1518 @override
1519 SimpleFormalParameter visitSimpleFormalParameter(
1520 SimpleFormalParameter node) => new SimpleFormalParameter(
1521 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1522 cloneToken(node.keyword), cloneNode(node.type),
1523 cloneNode(node.identifier));
1524
1525 @override
1526 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) =>
1527 new SimpleIdentifier(cloneToken(node.token));
1528
1529 @override
1530 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) =>
1531 new SimpleStringLiteral(cloneToken(node.literal), node.value);
1532
1533 @override
1534 StringInterpolation visitStringInterpolation(StringInterpolation node) =>
1535 new StringInterpolation(cloneNodeList(node.elements));
1536
1537 @override
1538 SuperConstructorInvocation visitSuperConstructorInvocation(
1539 SuperConstructorInvocation node) => new SuperConstructorInvocation(
1540 cloneToken(node.superKeyword), cloneToken(node.period),
1541 cloneNode(node.constructorName), cloneNode(node.argumentList));
1542
1543 @override
1544 SuperExpression visitSuperExpression(SuperExpression node) =>
1545 new SuperExpression(cloneToken(node.superKeyword));
1546
1547 @override
1548 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
1549 cloneNodeList(node.labels), cloneToken(node.keyword),
1550 cloneNode(node.expression), cloneToken(node.colon),
1551 cloneNodeList(node.statements));
1552
1553 @override
1554 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
1555 cloneNodeList(node.labels), cloneToken(node.keyword),
1556 cloneToken(node.colon), cloneNodeList(node.statements));
1557
1558 @override
1559 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
1560 new SwitchStatement(cloneToken(node.switchKeyword),
1561 cloneToken(node.leftParenthesis), cloneNode(node.expression),
1562 cloneToken(node.rightParenthesis), cloneToken(node.leftBracket),
1563 cloneNodeList(node.members), cloneToken(node.rightBracket));
1564
1565 @override
1566 SymbolLiteral visitSymbolLiteral(SymbolLiteral node) => new SymbolLiteral(
1567 cloneToken(node.poundSign), cloneTokenList(node.components));
1568
1569 @override
1570 ThisExpression visitThisExpression(ThisExpression node) =>
1571 new ThisExpression(cloneToken(node.thisKeyword));
1572
1573 @override
1574 ThrowExpression visitThrowExpression(ThrowExpression node) =>
1575 new ThrowExpression(
1576 cloneToken(node.throwKeyword), cloneNode(node.expression));
1577
1578 @override
1579 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
1580 TopLevelVariableDeclaration node) => new TopLevelVariableDeclaration(
1581 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1582 cloneNode(node.variables), cloneToken(node.semicolon));
1583
1584 @override
1585 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
1586 cloneToken(node.tryKeyword), cloneNode(node.body),
1587 cloneNodeList(node.catchClauses), cloneToken(node.finallyKeyword),
1588 cloneNode(node.finallyBlock));
1589
1590 @override
1591 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
1592 new TypeArgumentList(cloneToken(node.leftBracket),
1593 cloneNodeList(node.arguments), cloneToken(node.rightBracket));
1594
1595 @override
1596 TypeName visitTypeName(TypeName node) =>
1597 new TypeName(cloneNode(node.name), cloneNode(node.typeArguments));
1598
1599 @override
1600 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
1601 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1602 cloneNode(node.name), cloneToken(node.extendsKeyword),
1603 cloneNode(node.bound));
1604
1605 @override
1606 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
1607 new TypeParameterList(cloneToken(node.leftBracket),
1608 cloneNodeList(node.typeParameters), cloneToken(node.rightBracket));
1609
1610 @override
1611 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
1612 new VariableDeclaration(cloneNode(node.name), cloneToken(node.equals),
1613 cloneNode(node.initializer));
1614
1615 @override
1616 VariableDeclarationList visitVariableDeclarationList(
1617 VariableDeclarationList node) => new VariableDeclarationList(
1618 cloneNode(node.documentationComment), cloneNodeList(node.metadata),
1619 cloneToken(node.keyword), cloneNode(node.type),
1620 cloneNodeList(node.variables));
1621
1622 @override
1623 VariableDeclarationStatement visitVariableDeclarationStatement(
1624 VariableDeclarationStatement node) => new VariableDeclarationStatement(
1625 cloneNode(node.variables), cloneToken(node.semicolon));
1626
1627 @override
1628 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
1629 cloneToken(node.whileKeyword), cloneToken(node.leftParenthesis),
1630 cloneNode(node.condition), cloneToken(node.rightParenthesis),
1631 cloneNode(node.body));
1632
1633 @override
1634 WithClause visitWithClause(WithClause node) => new WithClause(
1635 cloneToken(node.withKeyword), cloneNodeList(node.mixinTypes));
1636
1637 @override
1638 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
1639 cloneToken(node.yieldKeyword), cloneToken(node.star),
1640 cloneNode(node.expression), cloneToken(node.semicolon));
1641
1642 /**
1643 * Return a clone of the given [node].
1644 */
1645 static AstNode clone(AstNode node) {
1646 return node.accept(new AstCloner());
1647 }
1648 }
1649
1650 /**
1651 * An AstVisitor that compares the structure of two AstNodes to see whether they
1652 * are equal.
1653 */
1654 class AstComparator implements AstVisitor<bool> {
1655 /**
1656 * The AST node with which the node being visited is to be compared. This is
1657 * only valid at the beginning of each visit method (until [isEqualNodes] is
1658 * invoked).
1659 */
1660 AstNode _other;
1661
1662 /**
1663 * Return `true` if the [first] node and the [second] node have the same
1664 * structure.
1665 *
1666 * *Note:* This method is only visible for testing purposes and should not be
1667 * used by clients.
1668 */
1669 bool isEqualNodes(AstNode first, AstNode second) {
1670 if (first == null) {
1671 return second == null;
1672 } else if (second == null) {
1673 return false;
1674 } else if (first.runtimeType != second.runtimeType) {
1675 return false;
1676 }
1677 _other = second;
1678 return first.accept(this);
1679 }
1680
1681 /**
1682 * Return `true` if the [first] token and the [second] token have the same
1683 * structure.
1684 *
1685 * *Note:* This method is only visible for testing purposes and should not be
1686 * used by clients.
1687 */
1688 bool isEqualTokens(Token first, Token second) {
1689 if (first == null) {
1690 return second == null;
1691 } else if (second == null) {
1692 return false;
1693 } else if (identical(first, second)) {
1694 return true;
1695 }
1696 return first.offset == second.offset &&
1697 first.length == second.length &&
1698 first.lexeme == second.lexeme;
1699 }
1700
1701 @override
1702 bool visitAdjacentStrings(AdjacentStrings node) {
1703 AdjacentStrings other = _other as AdjacentStrings;
1704 return _isEqualNodeLists(node.strings, other.strings);
1705 }
1706
1707 @override
1708 bool visitAnnotation(Annotation node) {
1709 Annotation other = _other as Annotation;
1710 return isEqualTokens(node.atSign, other.atSign) &&
1711 isEqualNodes(node.name, other.name) &&
1712 isEqualTokens(node.period, other.period) &&
1713 isEqualNodes(node.constructorName, other.constructorName) &&
1714 isEqualNodes(node.arguments, other.arguments);
1715 }
1716
1717 @override
1718 bool visitArgumentList(ArgumentList node) {
1719 ArgumentList other = _other as ArgumentList;
1720 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1721 _isEqualNodeLists(node.arguments, other.arguments) &&
1722 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
1723 }
1724
1725 @override
1726 bool visitAsExpression(AsExpression node) {
1727 AsExpression other = _other as AsExpression;
1728 return isEqualNodes(node.expression, other.expression) &&
1729 isEqualTokens(node.asOperator, other.asOperator) &&
1730 isEqualNodes(node.type, other.type);
1731 }
1732
1733 @override
1734 bool visitAssertStatement(AssertStatement node) {
1735 AssertStatement other = _other as AssertStatement;
1736 return isEqualTokens(node.assertKeyword, other.assertKeyword) &&
1737 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1738 isEqualNodes(node.condition, other.condition) &&
1739 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1740 isEqualTokens(node.semicolon, other.semicolon);
1741 }
1742
1743 @override
1744 bool visitAssignmentExpression(AssignmentExpression node) {
1745 AssignmentExpression other = _other as AssignmentExpression;
1746 return isEqualNodes(node.leftHandSide, other.leftHandSide) &&
1747 isEqualTokens(node.operator, other.operator) &&
1748 isEqualNodes(node.rightHandSide, other.rightHandSide);
1749 }
1750
1751 @override
1752 bool visitAwaitExpression(AwaitExpression node) {
1753 AwaitExpression other = _other as AwaitExpression;
1754 return isEqualTokens(node.awaitKeyword, other.awaitKeyword) &&
1755 isEqualNodes(node.expression, other.expression);
1756 }
1757
1758 @override
1759 bool visitBinaryExpression(BinaryExpression node) {
1760 BinaryExpression other = _other as BinaryExpression;
1761 return isEqualNodes(node.leftOperand, other.leftOperand) &&
1762 isEqualTokens(node.operator, other.operator) &&
1763 isEqualNodes(node.rightOperand, other.rightOperand);
1764 }
1765
1766 @override
1767 bool visitBlock(Block node) {
1768 Block other = _other as Block;
1769 return isEqualTokens(node.leftBracket, other.leftBracket) &&
1770 _isEqualNodeLists(node.statements, other.statements) &&
1771 isEqualTokens(node.rightBracket, other.rightBracket);
1772 }
1773
1774 @override
1775 bool visitBlockFunctionBody(BlockFunctionBody node) {
1776 BlockFunctionBody other = _other as BlockFunctionBody;
1777 return isEqualNodes(node.block, other.block);
1778 }
1779
1780 @override
1781 bool visitBooleanLiteral(BooleanLiteral node) {
1782 BooleanLiteral other = _other as BooleanLiteral;
1783 return isEqualTokens(node.literal, other.literal) &&
1784 node.value == other.value;
1785 }
1786
1787 @override
1788 bool visitBreakStatement(BreakStatement node) {
1789 BreakStatement other = _other as BreakStatement;
1790 return isEqualTokens(node.breakKeyword, other.breakKeyword) &&
1791 isEqualNodes(node.label, other.label) &&
1792 isEqualTokens(node.semicolon, other.semicolon);
1793 }
1794
1795 @override
1796 bool visitCascadeExpression(CascadeExpression node) {
1797 CascadeExpression other = _other as CascadeExpression;
1798 return isEqualNodes(node.target, other.target) &&
1799 _isEqualNodeLists(node.cascadeSections, other.cascadeSections);
1800 }
1801
1802 @override
1803 bool visitCatchClause(CatchClause node) {
1804 CatchClause other = _other as CatchClause;
1805 return isEqualTokens(node.onKeyword, other.onKeyword) &&
1806 isEqualNodes(node.exceptionType, other.exceptionType) &&
1807 isEqualTokens(node.catchKeyword, other.catchKeyword) &&
1808 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1809 isEqualNodes(node.exceptionParameter, other.exceptionParameter) &&
1810 isEqualTokens(node.comma, other.comma) &&
1811 isEqualNodes(node.stackTraceParameter, other.stackTraceParameter) &&
1812 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1813 isEqualNodes(node.body, other.body);
1814 }
1815
1816 @override
1817 bool visitClassDeclaration(ClassDeclaration node) {
1818 ClassDeclaration other = _other as ClassDeclaration;
1819 return isEqualNodes(
1820 node.documentationComment, other.documentationComment) &&
1821 _isEqualNodeLists(node.metadata, other.metadata) &&
1822 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
1823 isEqualTokens(node.classKeyword, other.classKeyword) &&
1824 isEqualNodes(node.name, other.name) &&
1825 isEqualNodes(node.typeParameters, other.typeParameters) &&
1826 isEqualNodes(node.extendsClause, other.extendsClause) &&
1827 isEqualNodes(node.withClause, other.withClause) &&
1828 isEqualNodes(node.implementsClause, other.implementsClause) &&
1829 isEqualTokens(node.leftBracket, other.leftBracket) &&
1830 _isEqualNodeLists(node.members, other.members) &&
1831 isEqualTokens(node.rightBracket, other.rightBracket);
1832 }
1833
1834 @override
1835 bool visitClassTypeAlias(ClassTypeAlias node) {
1836 ClassTypeAlias other = _other as ClassTypeAlias;
1837 return isEqualNodes(
1838 node.documentationComment, other.documentationComment) &&
1839 _isEqualNodeLists(node.metadata, other.metadata) &&
1840 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
1841 isEqualNodes(node.name, other.name) &&
1842 isEqualNodes(node.typeParameters, other.typeParameters) &&
1843 isEqualTokens(node.equals, other.equals) &&
1844 isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
1845 isEqualNodes(node.superclass, other.superclass) &&
1846 isEqualNodes(node.withClause, other.withClause) &&
1847 isEqualNodes(node.implementsClause, other.implementsClause) &&
1848 isEqualTokens(node.semicolon, other.semicolon);
1849 }
1850
1851 @override
1852 bool visitComment(Comment node) {
1853 Comment other = _other as Comment;
1854 return _isEqualNodeLists(node.references, other.references);
1855 }
1856
1857 @override
1858 bool visitCommentReference(CommentReference node) {
1859 CommentReference other = _other as CommentReference;
1860 return isEqualTokens(node.newKeyword, other.newKeyword) &&
1861 isEqualNodes(node.identifier, other.identifier);
1862 }
1863
1864 @override
1865 bool visitCompilationUnit(CompilationUnit node) {
1866 CompilationUnit other = _other as CompilationUnit;
1867 return isEqualTokens(node.beginToken, other.beginToken) &&
1868 isEqualNodes(node.scriptTag, other.scriptTag) &&
1869 _isEqualNodeLists(node.directives, other.directives) &&
1870 _isEqualNodeLists(node.declarations, other.declarations) &&
1871 isEqualTokens(node.endToken, other.endToken);
1872 }
1873
1874 @override
1875 bool visitConditionalExpression(ConditionalExpression node) {
1876 ConditionalExpression other = _other as ConditionalExpression;
1877 return isEqualNodes(node.condition, other.condition) &&
1878 isEqualTokens(node.question, other.question) &&
1879 isEqualNodes(node.thenExpression, other.thenExpression) &&
1880 isEqualTokens(node.colon, other.colon) &&
1881 isEqualNodes(node.elseExpression, other.elseExpression);
1882 }
1883
1884 @override
1885 bool visitConstructorDeclaration(ConstructorDeclaration node) {
1886 ConstructorDeclaration other = _other as ConstructorDeclaration;
1887 return isEqualNodes(
1888 node.documentationComment, other.documentationComment) &&
1889 _isEqualNodeLists(node.metadata, other.metadata) &&
1890 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
1891 isEqualTokens(node.constKeyword, other.constKeyword) &&
1892 isEqualTokens(node.factoryKeyword, other.factoryKeyword) &&
1893 isEqualNodes(node.returnType, other.returnType) &&
1894 isEqualTokens(node.period, other.period) &&
1895 isEqualNodes(node.name, other.name) &&
1896 isEqualNodes(node.parameters, other.parameters) &&
1897 isEqualTokens(node.separator, other.separator) &&
1898 _isEqualNodeLists(node.initializers, other.initializers) &&
1899 isEqualNodes(node.redirectedConstructor, other.redirectedConstructor) &&
1900 isEqualNodes(node.body, other.body);
1901 }
1902
1903 @override
1904 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
1905 ConstructorFieldInitializer other = _other as ConstructorFieldInitializer;
1906 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
1907 isEqualTokens(node.period, other.period) &&
1908 isEqualNodes(node.fieldName, other.fieldName) &&
1909 isEqualTokens(node.equals, other.equals) &&
1910 isEqualNodes(node.expression, other.expression);
1911 }
1912
1913 @override
1914 bool visitConstructorName(ConstructorName node) {
1915 ConstructorName other = _other as ConstructorName;
1916 return isEqualNodes(node.type, other.type) &&
1917 isEqualTokens(node.period, other.period) &&
1918 isEqualNodes(node.name, other.name);
1919 }
1920
1921 @override
1922 bool visitContinueStatement(ContinueStatement node) {
1923 ContinueStatement other = _other as ContinueStatement;
1924 return isEqualTokens(node.continueKeyword, other.continueKeyword) &&
1925 isEqualNodes(node.label, other.label) &&
1926 isEqualTokens(node.semicolon, other.semicolon);
1927 }
1928
1929 @override
1930 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
1931 DeclaredIdentifier other = _other as DeclaredIdentifier;
1932 return isEqualNodes(
1933 node.documentationComment, other.documentationComment) &&
1934 _isEqualNodeLists(node.metadata, other.metadata) &&
1935 isEqualTokens(node.keyword, other.keyword) &&
1936 isEqualNodes(node.type, other.type) &&
1937 isEqualNodes(node.identifier, other.identifier);
1938 }
1939
1940 @override
1941 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
1942 DefaultFormalParameter other = _other as DefaultFormalParameter;
1943 return isEqualNodes(node.parameter, other.parameter) &&
1944 node.kind == other.kind &&
1945 isEqualTokens(node.separator, other.separator) &&
1946 isEqualNodes(node.defaultValue, other.defaultValue);
1947 }
1948
1949 @override
1950 bool visitDoStatement(DoStatement node) {
1951 DoStatement other = _other as DoStatement;
1952 return isEqualTokens(node.doKeyword, other.doKeyword) &&
1953 isEqualNodes(node.body, other.body) &&
1954 isEqualTokens(node.whileKeyword, other.whileKeyword) &&
1955 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
1956 isEqualNodes(node.condition, other.condition) &&
1957 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
1958 isEqualTokens(node.semicolon, other.semicolon);
1959 }
1960
1961 @override
1962 bool visitDoubleLiteral(DoubleLiteral node) {
1963 DoubleLiteral other = _other as DoubleLiteral;
1964 return isEqualTokens(node.literal, other.literal) &&
1965 node.value == other.value;
1966 }
1967
1968 @override
1969 bool visitEmptyFunctionBody(EmptyFunctionBody node) {
1970 EmptyFunctionBody other = _other as EmptyFunctionBody;
1971 return isEqualTokens(node.semicolon, other.semicolon);
1972 }
1973
1974 @override
1975 bool visitEmptyStatement(EmptyStatement node) {
1976 EmptyStatement other = _other as EmptyStatement;
1977 return isEqualTokens(node.semicolon, other.semicolon);
1978 }
1979
1980 @override
1981 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
1982 EnumConstantDeclaration other = _other as EnumConstantDeclaration;
1983 return isEqualNodes(
1984 node.documentationComment, other.documentationComment) &&
1985 _isEqualNodeLists(node.metadata, other.metadata) &&
1986 isEqualNodes(node.name, other.name);
1987 }
1988
1989 @override
1990 bool visitEnumDeclaration(EnumDeclaration node) {
1991 EnumDeclaration other = _other as EnumDeclaration;
1992 return isEqualNodes(
1993 node.documentationComment, other.documentationComment) &&
1994 _isEqualNodeLists(node.metadata, other.metadata) &&
1995 isEqualTokens(node.enumKeyword, other.enumKeyword) &&
1996 isEqualNodes(node.name, other.name) &&
1997 isEqualTokens(node.leftBracket, other.leftBracket) &&
1998 _isEqualNodeLists(node.constants, other.constants) &&
1999 isEqualTokens(node.rightBracket, other.rightBracket);
2000 }
2001
2002 @override
2003 bool visitExportDirective(ExportDirective node) {
2004 ExportDirective other = _other as ExportDirective;
2005 return isEqualNodes(
2006 node.documentationComment, other.documentationComment) &&
2007 _isEqualNodeLists(node.metadata, other.metadata) &&
2008 isEqualTokens(node.keyword, other.keyword) &&
2009 isEqualNodes(node.uri, other.uri) &&
2010 _isEqualNodeLists(node.combinators, other.combinators) &&
2011 isEqualTokens(node.semicolon, other.semicolon);
2012 }
2013
2014 @override
2015 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
2016 ExpressionFunctionBody other = _other as ExpressionFunctionBody;
2017 return isEqualTokens(node.functionDefinition, other.functionDefinition) &&
2018 isEqualNodes(node.expression, other.expression) &&
2019 isEqualTokens(node.semicolon, other.semicolon);
2020 }
2021
2022 @override
2023 bool visitExpressionStatement(ExpressionStatement node) {
2024 ExpressionStatement other = _other as ExpressionStatement;
2025 return isEqualNodes(node.expression, other.expression) &&
2026 isEqualTokens(node.semicolon, other.semicolon);
2027 }
2028
2029 @override
2030 bool visitExtendsClause(ExtendsClause node) {
2031 ExtendsClause other = _other as ExtendsClause;
2032 return isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2033 isEqualNodes(node.superclass, other.superclass);
2034 }
2035
2036 @override
2037 bool visitFieldDeclaration(FieldDeclaration node) {
2038 FieldDeclaration other = _other as FieldDeclaration;
2039 return isEqualNodes(
2040 node.documentationComment, other.documentationComment) &&
2041 _isEqualNodeLists(node.metadata, other.metadata) &&
2042 isEqualTokens(node.staticKeyword, other.staticKeyword) &&
2043 isEqualNodes(node.fields, other.fields) &&
2044 isEqualTokens(node.semicolon, other.semicolon);
2045 }
2046
2047 @override
2048 bool visitFieldFormalParameter(FieldFormalParameter node) {
2049 FieldFormalParameter other = _other as FieldFormalParameter;
2050 return isEqualNodes(
2051 node.documentationComment, other.documentationComment) &&
2052 _isEqualNodeLists(node.metadata, other.metadata) &&
2053 isEqualTokens(node.keyword, other.keyword) &&
2054 isEqualNodes(node.type, other.type) &&
2055 isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2056 isEqualTokens(node.period, other.period) &&
2057 isEqualNodes(node.identifier, other.identifier);
2058 }
2059
2060 @override
2061 bool visitForEachStatement(ForEachStatement node) {
2062 ForEachStatement other = _other as ForEachStatement;
2063 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2064 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2065 isEqualNodes(node.loopVariable, other.loopVariable) &&
2066 isEqualTokens(node.inKeyword, other.inKeyword) &&
2067 isEqualNodes(node.iterable, other.iterable) &&
2068 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2069 isEqualNodes(node.body, other.body);
2070 }
2071
2072 @override
2073 bool visitFormalParameterList(FormalParameterList node) {
2074 FormalParameterList other = _other as FormalParameterList;
2075 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2076 _isEqualNodeLists(node.parameters, other.parameters) &&
2077 isEqualTokens(node.leftDelimiter, other.leftDelimiter) &&
2078 isEqualTokens(node.rightDelimiter, other.rightDelimiter) &&
2079 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2080 }
2081
2082 @override
2083 bool visitForStatement(ForStatement node) {
2084 ForStatement other = _other as ForStatement;
2085 return isEqualTokens(node.forKeyword, other.forKeyword) &&
2086 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2087 isEqualNodes(node.variables, other.variables) &&
2088 isEqualNodes(node.initialization, other.initialization) &&
2089 isEqualTokens(node.leftSeparator, other.leftSeparator) &&
2090 isEqualNodes(node.condition, other.condition) &&
2091 isEqualTokens(node.rightSeparator, other.rightSeparator) &&
2092 _isEqualNodeLists(node.updaters, other.updaters) &&
2093 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2094 isEqualNodes(node.body, other.body);
2095 }
2096
2097 @override
2098 bool visitFunctionDeclaration(FunctionDeclaration node) {
2099 FunctionDeclaration other = _other as FunctionDeclaration;
2100 return isEqualNodes(
2101 node.documentationComment, other.documentationComment) &&
2102 _isEqualNodeLists(node.metadata, other.metadata) &&
2103 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2104 isEqualNodes(node.returnType, other.returnType) &&
2105 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2106 isEqualNodes(node.name, other.name) &&
2107 isEqualNodes(node.functionExpression, other.functionExpression);
2108 }
2109
2110 @override
2111 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
2112 FunctionDeclarationStatement other = _other as FunctionDeclarationStatement;
2113 return isEqualNodes(node.functionDeclaration, other.functionDeclaration);
2114 }
2115
2116 @override
2117 bool visitFunctionExpression(FunctionExpression node) {
2118 FunctionExpression other = _other as FunctionExpression;
2119 return isEqualNodes(node.parameters, other.parameters) &&
2120 isEqualNodes(node.body, other.body);
2121 }
2122
2123 @override
2124 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
2125 FunctionExpressionInvocation other = _other as FunctionExpressionInvocation;
2126 return isEqualNodes(node.function, other.function) &&
2127 isEqualNodes(node.argumentList, other.argumentList);
2128 }
2129
2130 @override
2131 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
2132 FunctionTypeAlias other = _other as FunctionTypeAlias;
2133 return isEqualNodes(
2134 node.documentationComment, other.documentationComment) &&
2135 _isEqualNodeLists(node.metadata, other.metadata) &&
2136 isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
2137 isEqualNodes(node.returnType, other.returnType) &&
2138 isEqualNodes(node.name, other.name) &&
2139 isEqualNodes(node.typeParameters, other.typeParameters) &&
2140 isEqualNodes(node.parameters, other.parameters) &&
2141 isEqualTokens(node.semicolon, other.semicolon);
2142 }
2143
2144 @override
2145 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2146 FunctionTypedFormalParameter other = _other as FunctionTypedFormalParameter;
2147 return isEqualNodes(
2148 node.documentationComment, other.documentationComment) &&
2149 _isEqualNodeLists(node.metadata, other.metadata) &&
2150 isEqualNodes(node.returnType, other.returnType) &&
2151 isEqualNodes(node.identifier, other.identifier) &&
2152 isEqualNodes(node.parameters, other.parameters);
2153 }
2154
2155 @override
2156 bool visitHideCombinator(HideCombinator node) {
2157 HideCombinator other = _other as HideCombinator;
2158 return isEqualTokens(node.keyword, other.keyword) &&
2159 _isEqualNodeLists(node.hiddenNames, other.hiddenNames);
2160 }
2161
2162 @override
2163 bool visitIfStatement(IfStatement node) {
2164 IfStatement other = _other as IfStatement;
2165 return isEqualTokens(node.ifKeyword, other.ifKeyword) &&
2166 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2167 isEqualNodes(node.condition, other.condition) &&
2168 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2169 isEqualNodes(node.thenStatement, other.thenStatement) &&
2170 isEqualTokens(node.elseKeyword, other.elseKeyword) &&
2171 isEqualNodes(node.elseStatement, other.elseStatement);
2172 }
2173
2174 @override
2175 bool visitImplementsClause(ImplementsClause node) {
2176 ImplementsClause other = _other as ImplementsClause;
2177 return isEqualTokens(node.implementsKeyword, other.implementsKeyword) &&
2178 _isEqualNodeLists(node.interfaces, other.interfaces);
2179 }
2180
2181 @override
2182 bool visitImportDirective(ImportDirective node) {
2183 ImportDirective other = _other as ImportDirective;
2184 return isEqualNodes(
2185 node.documentationComment, other.documentationComment) &&
2186 _isEqualNodeLists(node.metadata, other.metadata) &&
2187 isEqualTokens(node.keyword, other.keyword) &&
2188 isEqualNodes(node.uri, other.uri) &&
2189 isEqualTokens(node.deferredKeyword, other.deferredKeyword) &&
2190 isEqualTokens(node.asKeyword, other.asKeyword) &&
2191 isEqualNodes(node.prefix, other.prefix) &&
2192 _isEqualNodeLists(node.combinators, other.combinators) &&
2193 isEqualTokens(node.semicolon, other.semicolon);
2194 }
2195
2196 @override
2197 bool visitIndexExpression(IndexExpression node) {
2198 IndexExpression other = _other as IndexExpression;
2199 return isEqualNodes(node.target, other.target) &&
2200 isEqualTokens(node.leftBracket, other.leftBracket) &&
2201 isEqualNodes(node.index, other.index) &&
2202 isEqualTokens(node.rightBracket, other.rightBracket);
2203 }
2204
2205 @override
2206 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
2207 InstanceCreationExpression other = _other as InstanceCreationExpression;
2208 return isEqualTokens(node.keyword, other.keyword) &&
2209 isEqualNodes(node.constructorName, other.constructorName) &&
2210 isEqualNodes(node.argumentList, other.argumentList);
2211 }
2212
2213 @override
2214 bool visitIntegerLiteral(IntegerLiteral node) {
2215 IntegerLiteral other = _other as IntegerLiteral;
2216 return isEqualTokens(node.literal, other.literal) &&
2217 (node.value == other.value);
2218 }
2219
2220 @override
2221 bool visitInterpolationExpression(InterpolationExpression node) {
2222 InterpolationExpression other = _other as InterpolationExpression;
2223 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2224 isEqualNodes(node.expression, other.expression) &&
2225 isEqualTokens(node.rightBracket, other.rightBracket);
2226 }
2227
2228 @override
2229 bool visitInterpolationString(InterpolationString node) {
2230 InterpolationString other = _other as InterpolationString;
2231 return isEqualTokens(node.contents, other.contents) &&
2232 node.value == other.value;
2233 }
2234
2235 @override
2236 bool visitIsExpression(IsExpression node) {
2237 IsExpression other = _other as IsExpression;
2238 return isEqualNodes(node.expression, other.expression) &&
2239 isEqualTokens(node.isOperator, other.isOperator) &&
2240 isEqualTokens(node.notOperator, other.notOperator) &&
2241 isEqualNodes(node.type, other.type);
2242 }
2243
2244 @override
2245 bool visitLabel(Label node) {
2246 Label other = _other as Label;
2247 return isEqualNodes(node.label, other.label) &&
2248 isEqualTokens(node.colon, other.colon);
2249 }
2250
2251 @override
2252 bool visitLabeledStatement(LabeledStatement node) {
2253 LabeledStatement other = _other as LabeledStatement;
2254 return _isEqualNodeLists(node.labels, other.labels) &&
2255 isEqualNodes(node.statement, other.statement);
2256 }
2257
2258 @override
2259 bool visitLibraryDirective(LibraryDirective node) {
2260 LibraryDirective other = _other as LibraryDirective;
2261 return isEqualNodes(
2262 node.documentationComment, other.documentationComment) &&
2263 _isEqualNodeLists(node.metadata, other.metadata) &&
2264 isEqualTokens(node.libraryKeyword, other.libraryKeyword) &&
2265 isEqualNodes(node.name, other.name) &&
2266 isEqualTokens(node.semicolon, other.semicolon);
2267 }
2268
2269 @override
2270 bool visitLibraryIdentifier(LibraryIdentifier node) {
2271 LibraryIdentifier other = _other as LibraryIdentifier;
2272 return _isEqualNodeLists(node.components, other.components);
2273 }
2274
2275 @override
2276 bool visitListLiteral(ListLiteral node) {
2277 ListLiteral other = _other as ListLiteral;
2278 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2279 isEqualNodes(node.typeArguments, other.typeArguments) &&
2280 isEqualTokens(node.leftBracket, other.leftBracket) &&
2281 _isEqualNodeLists(node.elements, other.elements) &&
2282 isEqualTokens(node.rightBracket, other.rightBracket);
2283 }
2284
2285 @override
2286 bool visitMapLiteral(MapLiteral node) {
2287 MapLiteral other = _other as MapLiteral;
2288 return isEqualTokens(node.constKeyword, other.constKeyword) &&
2289 isEqualNodes(node.typeArguments, other.typeArguments) &&
2290 isEqualTokens(node.leftBracket, other.leftBracket) &&
2291 _isEqualNodeLists(node.entries, other.entries) &&
2292 isEqualTokens(node.rightBracket, other.rightBracket);
2293 }
2294
2295 @override
2296 bool visitMapLiteralEntry(MapLiteralEntry node) {
2297 MapLiteralEntry other = _other as MapLiteralEntry;
2298 return isEqualNodes(node.key, other.key) &&
2299 isEqualTokens(node.separator, other.separator) &&
2300 isEqualNodes(node.value, other.value);
2301 }
2302
2303 @override
2304 bool visitMethodDeclaration(MethodDeclaration node) {
2305 MethodDeclaration other = _other as MethodDeclaration;
2306 return isEqualNodes(
2307 node.documentationComment, other.documentationComment) &&
2308 _isEqualNodeLists(node.metadata, other.metadata) &&
2309 isEqualTokens(node.externalKeyword, other.externalKeyword) &&
2310 isEqualTokens(node.modifierKeyword, other.modifierKeyword) &&
2311 isEqualNodes(node.returnType, other.returnType) &&
2312 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2313 isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
2314 isEqualNodes(node.name, other.name) &&
2315 isEqualNodes(node.parameters, other.parameters) &&
2316 isEqualNodes(node.body, other.body);
2317 }
2318
2319 @override
2320 bool visitMethodInvocation(MethodInvocation node) {
2321 MethodInvocation other = _other as MethodInvocation;
2322 return isEqualNodes(node.target, other.target) &&
2323 isEqualTokens(node.operator, other.operator) &&
2324 isEqualNodes(node.methodName, other.methodName) &&
2325 isEqualNodes(node.argumentList, other.argumentList);
2326 }
2327
2328 @override
2329 bool visitNamedExpression(NamedExpression node) {
2330 NamedExpression other = _other as NamedExpression;
2331 return isEqualNodes(node.name, other.name) &&
2332 isEqualNodes(node.expression, other.expression);
2333 }
2334
2335 @override
2336 bool visitNativeClause(NativeClause node) {
2337 NativeClause other = _other as NativeClause;
2338 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2339 isEqualNodes(node.name, other.name);
2340 }
2341
2342 @override
2343 bool visitNativeFunctionBody(NativeFunctionBody node) {
2344 NativeFunctionBody other = _other as NativeFunctionBody;
2345 return isEqualTokens(node.nativeKeyword, other.nativeKeyword) &&
2346 isEqualNodes(node.stringLiteral, other.stringLiteral) &&
2347 isEqualTokens(node.semicolon, other.semicolon);
2348 }
2349
2350 @override
2351 bool visitNullLiteral(NullLiteral node) {
2352 NullLiteral other = _other as NullLiteral;
2353 return isEqualTokens(node.literal, other.literal);
2354 }
2355
2356 @override
2357 bool visitParenthesizedExpression(ParenthesizedExpression node) {
2358 ParenthesizedExpression other = _other as ParenthesizedExpression;
2359 return isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2360 isEqualNodes(node.expression, other.expression) &&
2361 isEqualTokens(node.rightParenthesis, other.rightParenthesis);
2362 }
2363
2364 @override
2365 bool visitPartDirective(PartDirective node) {
2366 PartDirective other = _other as PartDirective;
2367 return isEqualNodes(
2368 node.documentationComment, other.documentationComment) &&
2369 _isEqualNodeLists(node.metadata, other.metadata) &&
2370 isEqualTokens(node.partKeyword, other.partKeyword) &&
2371 isEqualNodes(node.uri, other.uri) &&
2372 isEqualTokens(node.semicolon, other.semicolon);
2373 }
2374
2375 @override
2376 bool visitPartOfDirective(PartOfDirective node) {
2377 PartOfDirective other = _other as PartOfDirective;
2378 return isEqualNodes(
2379 node.documentationComment, other.documentationComment) &&
2380 _isEqualNodeLists(node.metadata, other.metadata) &&
2381 isEqualTokens(node.partKeyword, other.partKeyword) &&
2382 isEqualTokens(node.ofKeyword, other.ofKeyword) &&
2383 isEqualNodes(node.libraryName, other.libraryName) &&
2384 isEqualTokens(node.semicolon, other.semicolon);
2385 }
2386
2387 @override
2388 bool visitPostfixExpression(PostfixExpression node) {
2389 PostfixExpression other = _other as PostfixExpression;
2390 return isEqualNodes(node.operand, other.operand) &&
2391 isEqualTokens(node.operator, other.operator);
2392 }
2393
2394 @override
2395 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
2396 PrefixedIdentifier other = _other as PrefixedIdentifier;
2397 return isEqualNodes(node.prefix, other.prefix) &&
2398 isEqualTokens(node.period, other.period) &&
2399 isEqualNodes(node.identifier, other.identifier);
2400 }
2401
2402 @override
2403 bool visitPrefixExpression(PrefixExpression node) {
2404 PrefixExpression other = _other as PrefixExpression;
2405 return isEqualTokens(node.operator, other.operator) &&
2406 isEqualNodes(node.operand, other.operand);
2407 }
2408
2409 @override
2410 bool visitPropertyAccess(PropertyAccess node) {
2411 PropertyAccess other = _other as PropertyAccess;
2412 return isEqualNodes(node.target, other.target) &&
2413 isEqualTokens(node.operator, other.operator) &&
2414 isEqualNodes(node.propertyName, other.propertyName);
2415 }
2416
2417 @override
2418 bool visitRedirectingConstructorInvocation(
2419 RedirectingConstructorInvocation node) {
2420 RedirectingConstructorInvocation other =
2421 _other as RedirectingConstructorInvocation;
2422 return isEqualTokens(node.thisKeyword, other.thisKeyword) &&
2423 isEqualTokens(node.period, other.period) &&
2424 isEqualNodes(node.constructorName, other.constructorName) &&
2425 isEqualNodes(node.argumentList, other.argumentList);
2426 }
2427
2428 @override
2429 bool visitRethrowExpression(RethrowExpression node) {
2430 RethrowExpression other = _other as RethrowExpression;
2431 return isEqualTokens(node.rethrowKeyword, other.rethrowKeyword);
2432 }
2433
2434 @override
2435 bool visitReturnStatement(ReturnStatement node) {
2436 ReturnStatement other = _other as ReturnStatement;
2437 return isEqualTokens(node.returnKeyword, other.returnKeyword) &&
2438 isEqualNodes(node.expression, other.expression) &&
2439 isEqualTokens(node.semicolon, other.semicolon);
2440 }
2441
2442 @override
2443 bool visitScriptTag(ScriptTag node) {
2444 ScriptTag other = _other as ScriptTag;
2445 return isEqualTokens(node.scriptTag, other.scriptTag);
2446 }
2447
2448 @override
2449 bool visitShowCombinator(ShowCombinator node) {
2450 ShowCombinator other = _other as ShowCombinator;
2451 return isEqualTokens(node.keyword, other.keyword) &&
2452 _isEqualNodeLists(node.shownNames, other.shownNames);
2453 }
2454
2455 @override
2456 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
2457 SimpleFormalParameter other = _other as SimpleFormalParameter;
2458 return isEqualNodes(
2459 node.documentationComment, other.documentationComment) &&
2460 _isEqualNodeLists(node.metadata, other.metadata) &&
2461 isEqualTokens(node.keyword, other.keyword) &&
2462 isEqualNodes(node.type, other.type) &&
2463 isEqualNodes(node.identifier, other.identifier);
2464 }
2465
2466 @override
2467 bool visitSimpleIdentifier(SimpleIdentifier node) {
2468 SimpleIdentifier other = _other as SimpleIdentifier;
2469 return isEqualTokens(node.token, other.token);
2470 }
2471
2472 @override
2473 bool visitSimpleStringLiteral(SimpleStringLiteral node) {
2474 SimpleStringLiteral other = _other as SimpleStringLiteral;
2475 return isEqualTokens(node.literal, other.literal) &&
2476 (node.value == other.value);
2477 }
2478
2479 @override
2480 bool visitStringInterpolation(StringInterpolation node) {
2481 StringInterpolation other = _other as StringInterpolation;
2482 return _isEqualNodeLists(node.elements, other.elements);
2483 }
2484
2485 @override
2486 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2487 SuperConstructorInvocation other = _other as SuperConstructorInvocation;
2488 return isEqualTokens(node.superKeyword, other.superKeyword) &&
2489 isEqualTokens(node.period, other.period) &&
2490 isEqualNodes(node.constructorName, other.constructorName) &&
2491 isEqualNodes(node.argumentList, other.argumentList);
2492 }
2493
2494 @override
2495 bool visitSuperExpression(SuperExpression node) {
2496 SuperExpression other = _other as SuperExpression;
2497 return isEqualTokens(node.superKeyword, other.superKeyword);
2498 }
2499
2500 @override
2501 bool visitSwitchCase(SwitchCase node) {
2502 SwitchCase other = _other as SwitchCase;
2503 return _isEqualNodeLists(node.labels, other.labels) &&
2504 isEqualTokens(node.keyword, other.keyword) &&
2505 isEqualNodes(node.expression, other.expression) &&
2506 isEqualTokens(node.colon, other.colon) &&
2507 _isEqualNodeLists(node.statements, other.statements);
2508 }
2509
2510 @override
2511 bool visitSwitchDefault(SwitchDefault node) {
2512 SwitchDefault other = _other as SwitchDefault;
2513 return _isEqualNodeLists(node.labels, other.labels) &&
2514 isEqualTokens(node.keyword, other.keyword) &&
2515 isEqualTokens(node.colon, other.colon) &&
2516 _isEqualNodeLists(node.statements, other.statements);
2517 }
2518
2519 @override
2520 bool visitSwitchStatement(SwitchStatement node) {
2521 SwitchStatement other = _other as SwitchStatement;
2522 return isEqualTokens(node.switchKeyword, other.switchKeyword) &&
2523 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2524 isEqualNodes(node.expression, other.expression) &&
2525 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2526 isEqualTokens(node.leftBracket, other.leftBracket) &&
2527 _isEqualNodeLists(node.members, other.members) &&
2528 isEqualTokens(node.rightBracket, other.rightBracket);
2529 }
2530
2531 @override
2532 bool visitSymbolLiteral(SymbolLiteral node) {
2533 SymbolLiteral other = _other as SymbolLiteral;
2534 return isEqualTokens(node.poundSign, other.poundSign) &&
2535 _isEqualTokenLists(node.components, other.components);
2536 }
2537
2538 @override
2539 bool visitThisExpression(ThisExpression node) {
2540 ThisExpression other = _other as ThisExpression;
2541 return isEqualTokens(node.thisKeyword, other.thisKeyword);
2542 }
2543
2544 @override
2545 bool visitThrowExpression(ThrowExpression node) {
2546 ThrowExpression other = _other as ThrowExpression;
2547 return isEqualTokens(node.throwKeyword, other.throwKeyword) &&
2548 isEqualNodes(node.expression, other.expression);
2549 }
2550
2551 @override
2552 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
2553 TopLevelVariableDeclaration other = _other as TopLevelVariableDeclaration;
2554 return isEqualNodes(
2555 node.documentationComment, other.documentationComment) &&
2556 _isEqualNodeLists(node.metadata, other.metadata) &&
2557 isEqualNodes(node.variables, other.variables) &&
2558 isEqualTokens(node.semicolon, other.semicolon);
2559 }
2560
2561 @override
2562 bool visitTryStatement(TryStatement node) {
2563 TryStatement other = _other as TryStatement;
2564 return isEqualTokens(node.tryKeyword, other.tryKeyword) &&
2565 isEqualNodes(node.body, other.body) &&
2566 _isEqualNodeLists(node.catchClauses, other.catchClauses) &&
2567 isEqualTokens(node.finallyKeyword, other.finallyKeyword) &&
2568 isEqualNodes(node.finallyBlock, other.finallyBlock);
2569 }
2570
2571 @override
2572 bool visitTypeArgumentList(TypeArgumentList node) {
2573 TypeArgumentList other = _other as TypeArgumentList;
2574 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2575 _isEqualNodeLists(node.arguments, other.arguments) &&
2576 isEqualTokens(node.rightBracket, other.rightBracket);
2577 }
2578
2579 @override
2580 bool visitTypeName(TypeName node) {
2581 TypeName other = _other as TypeName;
2582 return isEqualNodes(node.name, other.name) &&
2583 isEqualNodes(node.typeArguments, other.typeArguments);
2584 }
2585
2586 @override
2587 bool visitTypeParameter(TypeParameter node) {
2588 TypeParameter other = _other as TypeParameter;
2589 return isEqualNodes(
2590 node.documentationComment, other.documentationComment) &&
2591 _isEqualNodeLists(node.metadata, other.metadata) &&
2592 isEqualNodes(node.name, other.name) &&
2593 isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
2594 isEqualNodes(node.bound, other.bound);
2595 }
2596
2597 @override
2598 bool visitTypeParameterList(TypeParameterList node) {
2599 TypeParameterList other = _other as TypeParameterList;
2600 return isEqualTokens(node.leftBracket, other.leftBracket) &&
2601 _isEqualNodeLists(node.typeParameters, other.typeParameters) &&
2602 isEqualTokens(node.rightBracket, other.rightBracket);
2603 }
2604
2605 @override
2606 bool visitVariableDeclaration(VariableDeclaration node) {
2607 VariableDeclaration other = _other as VariableDeclaration;
2608 return isEqualNodes(
2609 node.documentationComment, other.documentationComment) &&
2610 _isEqualNodeLists(node.metadata, other.metadata) &&
2611 isEqualNodes(node.name, other.name) &&
2612 isEqualTokens(node.equals, other.equals) &&
2613 isEqualNodes(node.initializer, other.initializer);
2614 }
2615
2616 @override
2617 bool visitVariableDeclarationList(VariableDeclarationList node) {
2618 VariableDeclarationList other = _other as VariableDeclarationList;
2619 return isEqualNodes(
2620 node.documentationComment, other.documentationComment) &&
2621 _isEqualNodeLists(node.metadata, other.metadata) &&
2622 isEqualTokens(node.keyword, other.keyword) &&
2623 isEqualNodes(node.type, other.type) &&
2624 _isEqualNodeLists(node.variables, other.variables);
2625 }
2626
2627 @override
2628 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
2629 VariableDeclarationStatement other = _other as VariableDeclarationStatement;
2630 return isEqualNodes(node.variables, other.variables) &&
2631 isEqualTokens(node.semicolon, other.semicolon);
2632 }
2633
2634 @override
2635 bool visitWhileStatement(WhileStatement node) {
2636 WhileStatement other = _other as WhileStatement;
2637 return isEqualTokens(node.whileKeyword, other.whileKeyword) &&
2638 isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
2639 isEqualNodes(node.condition, other.condition) &&
2640 isEqualTokens(node.rightParenthesis, other.rightParenthesis) &&
2641 isEqualNodes(node.body, other.body);
2642 }
2643
2644 @override
2645 bool visitWithClause(WithClause node) {
2646 WithClause other = _other as WithClause;
2647 return isEqualTokens(node.withKeyword, other.withKeyword) &&
2648 _isEqualNodeLists(node.mixinTypes, other.mixinTypes);
2649 }
2650
2651 @override
2652 bool visitYieldStatement(YieldStatement node) {
2653 YieldStatement other = _other as YieldStatement;
2654 return isEqualTokens(node.yieldKeyword, other.yieldKeyword) &&
2655 isEqualNodes(node.expression, other.expression) &&
2656 isEqualTokens(node.semicolon, other.semicolon);
2657 }
2658
2659 /**
2660 * Return `true` if the [first] and [second] lists of AST nodes have the same
2661 * size and corresponding elements are equal.
2662 */
2663 bool _isEqualNodeLists(NodeList first, NodeList second) {
2664 if (first == null) {
2665 return second == null;
2666 } else if (second == null) {
2667 return false;
2668 }
2669 int size = first.length;
2670 if (second.length != size) {
2671 return false;
2672 }
2673 for (int i = 0; i < size; i++) {
2674 if (!isEqualNodes(first[i], second[i])) {
2675 return false;
2676 }
2677 }
2678 return true;
2679 }
2680
2681 /**
2682 * Return `true` if the [first] and [second] lists of tokens have the same
2683 * length and corresponding elements are equal.
2684 */
2685 bool _isEqualTokenLists(List<Token> first, List<Token> second) {
2686 int length = first.length;
2687 if (second.length != length) {
2688 return false;
2689 }
2690 for (int i = 0; i < length; i++) {
2691 if (!isEqualTokens(first[i], second[i])) {
2692 return false;
2693 }
2694 }
2695 return true;
2696 }
2697
2698 /**
2699 * Return `true` if the [first] and [second] nodes are equal.
2700 */
2701 static bool equalNodes(AstNode first, AstNode second) {
2702 AstComparator comparator = new AstComparator();
2703 return comparator.isEqualNodes(first, second);
2704 }
2705 }
2706
2707 /**
2708 * A node in the AST structure for a Dart program.
2709 */
2710 abstract class AstNode {
2711 /**
2712 * An empty list of AST nodes.
2713 */
2714 @deprecated // Use "AstNode.EMPTY_LIST"
2715 static const List<AstNode> EMPTY_ARRAY = EMPTY_LIST;
2716
2717 /**
2718 * An empty list of AST nodes.
2719 */
2720 static const List<AstNode> EMPTY_LIST = const <AstNode>[];
2721
2722 /**
2723 * A comparator that can be used to sort AST nodes in lexical order. In other
2724 * words, `compare` will return a negative value if the offset of the first
2725 * node is less than the offset of the second node, zero (0) if the nodes have
2726 * the same offset, and a positive value if the offset of the first node is
2727 * greater than the offset of the second node.
2728 */
2729 static Comparator<AstNode> LEXICAL_ORDER =
2730 (AstNode first, AstNode second) => first.offset - second.offset;
2731
2732 /**
2733 * The parent of the node, or `null` if the node is the root of an AST
2734 * structure.
2735 */
2736 AstNode _parent;
2737
2738 /**
2739 * A table mapping the names of properties to their values, or `null` if this
2740 * node does not have any properties associated with it.
2741 */
2742 Map<String, Object> _propertyMap;
2743
2744 /**
2745 * Return the first token included in this node's source range.
2746 */
2747 Token get beginToken;
2748
2749 /**
2750 * Iterate through all the entities (either AST nodes or tokens) which make
2751 * up the contents of this node, including doc comments but excluding other
2752 * comments.
2753 */
2754 Iterable /*<AstNode | Token>*/ get childEntities;
2755
2756 /**
2757 * Return the offset of the character immediately following the last character
2758 * of this node's source range. This is equivalent to
2759 * `node.getOffset() + node.getLength()`. For a compilation unit this will be
2760 * equal to the length of the unit's source. For synthetic nodes this will be
2761 * equivalent to the node's offset (because the length is zero (0) by
2762 * definition).
2763 */
2764 int get end => offset + length;
2765
2766 /**
2767 * Return the last token included in this node's source range.
2768 */
2769 Token get endToken;
2770
2771 /**
2772 * Return `true` if this node is a synthetic node. A synthetic node is a node
2773 * that was introduced by the parser in order to recover from an error in the
2774 * code. Synthetic nodes always have a length of zero (`0`).
2775 */
2776 bool get isSynthetic => false;
2777
2778 /**
2779 * Return the number of characters in the node's source range.
2780 */
2781 int get length {
2782 Token beginToken = this.beginToken;
2783 Token endToken = this.endToken;
2784 if (beginToken == null || endToken == null) {
2785 return -1;
2786 }
2787 return endToken.offset + endToken.length - beginToken.offset;
2788 }
2789
2790 /**
2791 * Return the offset from the beginning of the file to the first character in
2792 * the node's source range.
2793 */
2794 int get offset {
2795 Token beginToken = this.beginToken;
2796 if (beginToken == null) {
2797 return -1;
2798 }
2799 return beginToken.offset;
2800 }
2801
2802 /**
2803 * Return this node's parent node, or `null` if this node is the root of an
2804 * AST structure.
2805 *
2806 * Note that the relationship between an AST node and its parent node may
2807 * change over the lifetime of a node.
2808 */
2809 AstNode get parent => _parent;
2810
2811 /**
2812 * Set the parent of this node to the [newParent].
2813 */
2814 @deprecated // Never intended for public use.
2815 void set parent(AstNode newParent) {
2816 _parent = newParent;
2817 }
2818
2819 /**
2820 * Return the node at the root of this node's AST structure. Note that this
2821 * method's performance is linear with respect to the depth of the node in the
2822 * AST structure (O(depth)).
2823 */
2824 AstNode get root {
2825 AstNode root = this;
2826 AstNode parent = this.parent;
2827 while (parent != null) {
2828 root = parent;
2829 parent = root.parent;
2830 }
2831 return root;
2832 }
2833
2834 /**
2835 * Use the given [visitor] to visit this node. Return the value returned by
2836 * the visitor as a result of visiting this node.
2837 */
2838 /* <E> E */ accept(AstVisitor /*<E>*/ visitor);
2839
2840 /**
2841 * Make this node the parent of the given [child] node. Return the child node.
2842 */
2843 @deprecated // Never intended for public use.
2844 AstNode becomeParentOf(AstNode child) {
2845 return _becomeParentOf(child);
2846 }
2847
2848 /**
2849 * Return the most immediate ancestor of this node for which the [predicate]
2850 * returns `true`, or `null` if there is no such ancestor. Note that this node
2851 * will never be returned.
2852 */
2853 AstNode getAncestor(Predicate<AstNode> predicate) {
2854 // TODO(brianwilkerson) It is a bug that this method can return `this`.
2855 AstNode node = this;
2856 while (node != null && !predicate(node)) {
2857 node = node.parent;
2858 }
2859 return node;
2860 }
2861
2862 /**
2863 * Return the value of the property with the given [name], or `null` if this
2864 * node does not have a property with the given name.
2865 */
2866 Object getProperty(String name) {
2867 if (_propertyMap == null) {
2868 return null;
2869 }
2870 return _propertyMap[name];
2871 }
2872
2873 /**
2874 * If the given [child] is not `null`, use the given [visitor] to visit it.
2875 */
2876 @deprecated // Never intended for public use.
2877 void safelyVisitChild(AstNode child, AstVisitor visitor) {
2878 if (child != null) {
2879 child.accept(visitor);
2880 }
2881 }
2882
2883 /**
2884 * Set the value of the property with the given [name] to the given [value].
2885 * If the value is `null`, the property will effectively be removed.
2886 */
2887 void setProperty(String name, Object value) {
2888 if (value == null) {
2889 if (_propertyMap != null) {
2890 _propertyMap.remove(name);
2891 if (_propertyMap.isEmpty) {
2892 _propertyMap = null;
2893 }
2894 }
2895 } else {
2896 if (_propertyMap == null) {
2897 _propertyMap = new HashMap<String, Object>();
2898 }
2899 _propertyMap[name] = value;
2900 }
2901 }
2902
2903 /**
2904 * Return a textual description of this node in a form approximating valid
2905 * source. The returned string will not be valid source primarily in the case
2906 * where the node itself is not well-formed.
2907 */
2908 String toSource() {
2909 PrintStringWriter writer = new PrintStringWriter();
2910 accept(new ToSourceVisitor(writer));
2911 return writer.toString();
2912 }
2913
2914 @override
2915 String toString() => toSource();
2916
2917 /**
2918 * Use the given [visitor] to visit all of the children of this node. The
2919 * children will be visited in lexical order.
2920 */
2921 void visitChildren(AstVisitor visitor);
2922
2923 /**
2924 * Make this node the parent of the given [child] node. Return the child node.
2925 */
2926 AstNode _becomeParentOf(AstNode child) {
2927 if (child != null) {
2928 child._parent = this;
2929 }
2930 return child;
2931 }
2932
2933 /**
2934 * If the given [child] is not `null`, use the given [visitor] to visit it.
2935 */
2936 void _safelyVisitChild(AstNode child, AstVisitor visitor) {
2937 if (child != null) {
2938 child.accept(visitor);
2939 }
2940 }
2941 }
2942
2943 /**
2944 * An object that can be used to visit an AST structure.
2945 */
2946 abstract class AstVisitor<R> {
2947 R visitAdjacentStrings(AdjacentStrings node);
2948
2949 R visitAnnotation(Annotation node);
2950
2951 R visitArgumentList(ArgumentList node);
2952
2953 R visitAsExpression(AsExpression node);
2954
2955 R visitAssertStatement(AssertStatement assertStatement);
2956
2957 R visitAssignmentExpression(AssignmentExpression node);
2958
2959 R visitAwaitExpression(AwaitExpression node);
2960
2961 R visitBinaryExpression(BinaryExpression node);
2962
2963 R visitBlock(Block node);
2964
2965 R visitBlockFunctionBody(BlockFunctionBody node);
2966
2967 R visitBooleanLiteral(BooleanLiteral node);
2968
2969 R visitBreakStatement(BreakStatement node);
2970
2971 R visitCascadeExpression(CascadeExpression node);
2972
2973 R visitCatchClause(CatchClause node);
2974
2975 R visitClassDeclaration(ClassDeclaration node);
2976
2977 R visitClassTypeAlias(ClassTypeAlias node);
2978
2979 R visitComment(Comment node);
2980
2981 R visitCommentReference(CommentReference node);
2982
2983 R visitCompilationUnit(CompilationUnit node);
2984
2985 R visitConditionalExpression(ConditionalExpression node);
2986
2987 R visitConstructorDeclaration(ConstructorDeclaration node);
2988
2989 R visitConstructorFieldInitializer(ConstructorFieldInitializer node);
2990
2991 R visitConstructorName(ConstructorName node);
2992
2993 R visitContinueStatement(ContinueStatement node);
2994
2995 R visitDeclaredIdentifier(DeclaredIdentifier node);
2996
2997 R visitDefaultFormalParameter(DefaultFormalParameter node);
2998
2999 R visitDoStatement(DoStatement node);
3000
3001 R visitDoubleLiteral(DoubleLiteral node);
3002
3003 R visitEmptyFunctionBody(EmptyFunctionBody node);
3004
3005 R visitEmptyStatement(EmptyStatement node);
3006
3007 R visitEnumConstantDeclaration(EnumConstantDeclaration node);
3008
3009 R visitEnumDeclaration(EnumDeclaration node);
3010
3011 R visitExportDirective(ExportDirective node);
3012
3013 R visitExpressionFunctionBody(ExpressionFunctionBody node);
3014
3015 R visitExpressionStatement(ExpressionStatement node);
3016
3017 R visitExtendsClause(ExtendsClause node);
3018
3019 R visitFieldDeclaration(FieldDeclaration node);
3020
3021 R visitFieldFormalParameter(FieldFormalParameter node);
3022
3023 R visitForEachStatement(ForEachStatement node);
3024
3025 R visitFormalParameterList(FormalParameterList node);
3026
3027 R visitForStatement(ForStatement node);
3028
3029 R visitFunctionDeclaration(FunctionDeclaration node);
3030
3031 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node);
3032
3033 R visitFunctionExpression(FunctionExpression node);
3034
3035 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node);
3036
3037 R visitFunctionTypeAlias(FunctionTypeAlias functionTypeAlias);
3038
3039 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node);
3040
3041 R visitHideCombinator(HideCombinator node);
3042
3043 R visitIfStatement(IfStatement node);
3044
3045 R visitImplementsClause(ImplementsClause node);
3046
3047 R visitImportDirective(ImportDirective node);
3048
3049 R visitIndexExpression(IndexExpression node);
3050
3051 R visitInstanceCreationExpression(InstanceCreationExpression node);
3052
3053 R visitIntegerLiteral(IntegerLiteral node);
3054
3055 R visitInterpolationExpression(InterpolationExpression node);
3056
3057 R visitInterpolationString(InterpolationString node);
3058
3059 R visitIsExpression(IsExpression node);
3060
3061 R visitLabel(Label node);
3062
3063 R visitLabeledStatement(LabeledStatement node);
3064
3065 R visitLibraryDirective(LibraryDirective node);
3066
3067 R visitLibraryIdentifier(LibraryIdentifier node);
3068
3069 R visitListLiteral(ListLiteral node);
3070
3071 R visitMapLiteral(MapLiteral node);
3072
3073 R visitMapLiteralEntry(MapLiteralEntry node);
3074
3075 R visitMethodDeclaration(MethodDeclaration node);
3076
3077 R visitMethodInvocation(MethodInvocation node);
3078
3079 R visitNamedExpression(NamedExpression node);
3080
3081 R visitNativeClause(NativeClause node);
3082
3083 R visitNativeFunctionBody(NativeFunctionBody node);
3084
3085 R visitNullLiteral(NullLiteral node);
3086
3087 R visitParenthesizedExpression(ParenthesizedExpression node);
3088
3089 R visitPartDirective(PartDirective node);
3090
3091 R visitPartOfDirective(PartOfDirective node);
3092
3093 R visitPostfixExpression(PostfixExpression node);
3094
3095 R visitPrefixedIdentifier(PrefixedIdentifier node);
3096
3097 R visitPrefixExpression(PrefixExpression node);
3098
3099 R visitPropertyAccess(PropertyAccess node);
3100
3101 R visitRedirectingConstructorInvocation(
3102 RedirectingConstructorInvocation node);
3103
3104 R visitRethrowExpression(RethrowExpression node);
3105
3106 R visitReturnStatement(ReturnStatement node);
3107
3108 R visitScriptTag(ScriptTag node);
3109
3110 R visitShowCombinator(ShowCombinator node);
3111
3112 R visitSimpleFormalParameter(SimpleFormalParameter node);
3113
3114 R visitSimpleIdentifier(SimpleIdentifier node);
3115
3116 R visitSimpleStringLiteral(SimpleStringLiteral node);
3117
3118 R visitStringInterpolation(StringInterpolation node);
3119
3120 R visitSuperConstructorInvocation(SuperConstructorInvocation node);
3121
3122 R visitSuperExpression(SuperExpression node);
3123
3124 R visitSwitchCase(SwitchCase node);
3125
3126 R visitSwitchDefault(SwitchDefault node);
3127
3128 R visitSwitchStatement(SwitchStatement node);
3129
3130 R visitSymbolLiteral(SymbolLiteral node);
3131
3132 R visitThisExpression(ThisExpression node);
3133
3134 R visitThrowExpression(ThrowExpression node);
3135
3136 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node);
3137
3138 R visitTryStatement(TryStatement node);
3139
3140 R visitTypeArgumentList(TypeArgumentList node);
3141
3142 R visitTypeName(TypeName node);
3143
3144 R visitTypeParameter(TypeParameter node);
3145
3146 R visitTypeParameterList(TypeParameterList node);
3147
3148 R visitVariableDeclaration(VariableDeclaration node);
3149
3150 R visitVariableDeclarationList(VariableDeclarationList node);
3151
3152 R visitVariableDeclarationStatement(VariableDeclarationStatement node);
3153
3154 R visitWhileStatement(WhileStatement node);
3155
3156 R visitWithClause(WithClause node);
3157
3158 R visitYieldStatement(YieldStatement node);
3159 }
3160
3161 /**
3162 * An await expression.
3163 *
3164 * > awaitExpression ::=
3165 * > 'await' [Expression]
3166 */
3167 class AwaitExpression extends Expression {
3168 /**
3169 * The 'await' keyword.
3170 */
3171 Token awaitKeyword;
3172
3173 /**
3174 * The expression whose value is being waited on.
3175 */
3176 Expression _expression;
3177
3178 /**
3179 * Initialize a newly created await expression.
3180 */
3181 AwaitExpression(this.awaitKeyword, Expression expression) {
3182 _expression = _becomeParentOf(expression);
3183 }
3184
3185 @override
3186 Token get beginToken {
3187 if (awaitKeyword != null) {
3188 return awaitKeyword;
3189 }
3190 return _expression.beginToken;
3191 }
3192
3193 @override
3194 Iterable get childEntities =>
3195 new ChildEntities()..add(awaitKeyword)..add(_expression);
3196
3197 @override
3198 Token get endToken => _expression.endToken;
3199
3200 /**
3201 * Return the expression whose value is being waited on.
3202 */
3203 Expression get expression => _expression;
3204
3205 /**
3206 * Set the expression whose value is being waited on to the given [expression] .
3207 */
3208 void set expression(Expression expression) {
3209 _expression = _becomeParentOf(expression);
3210 }
3211
3212 @override
3213 int get precedence => 0;
3214
3215 @override
3216 accept(AstVisitor visitor) => visitor.visitAwaitExpression(this);
3217
3218 @override
3219 void visitChildren(AstVisitor visitor) {
3220 _safelyVisitChild(_expression, visitor);
3221 }
3222 }
3223
3224 /**
3225 * A binary (infix) expression.
3226 *
3227 * > binaryExpression ::=
3228 * > [Expression] [Token] [Expression]
3229 */
3230 class BinaryExpression extends Expression {
3231 /**
3232 * The expression used to compute the left operand.
3233 */
3234 Expression _leftOperand;
3235
3236 /**
3237 * The binary operator being applied.
3238 */
3239 Token operator;
3240
3241 /**
3242 * The expression used to compute the right operand.
3243 */
3244 Expression _rightOperand;
3245
3246 /**
3247 * The element associated with the operator based on the static type of the
3248 * left operand, or `null` if the AST structure has not been resolved, if the
3249 * operator is not user definable, or if the operator could not be resolved.
3250 */
3251 MethodElement staticElement;
3252
3253 /**
3254 * The element associated with the operator based on the propagated type of
3255 * the left operand, or `null` if the AST structure has not been resolved, if
3256 * the operator is not user definable, or if the operator could not be
3257 * resolved.
3258 */
3259 MethodElement propagatedElement;
3260
3261 /**
3262 * Initialize a newly created binary expression.
3263 */
3264 BinaryExpression(
3265 Expression leftOperand, this.operator, Expression rightOperand) {
3266 _leftOperand = _becomeParentOf(leftOperand);
3267 _rightOperand = _becomeParentOf(rightOperand);
3268 }
3269
3270 @override
3271 Token get beginToken => _leftOperand.beginToken;
3272
3273 /**
3274 * Return the best element available for this operator. If resolution was able
3275 * to find a better element based on type propagation, that element will be
3276 * returned. Otherwise, the element found using the result of static analysis
3277 * will be returned. If resolution has not been performed, then `null` will be
3278 * returned.
3279 */
3280 MethodElement get bestElement {
3281 MethodElement element = propagatedElement;
3282 if (element == null) {
3283 element = staticElement;
3284 }
3285 return element;
3286 }
3287
3288 @override
3289 Iterable get childEntities =>
3290 new ChildEntities()..add(_leftOperand)..add(operator)..add(_rightOperand);
3291
3292 @override
3293 Token get endToken => _rightOperand.endToken;
3294
3295 /**
3296 * Return the expression used to compute the left operand.
3297 */
3298 Expression get leftOperand => _leftOperand;
3299
3300 /**
3301 * Set the expression used to compute the left operand to the given
3302 * [expression].
3303 */
3304 void set leftOperand(Expression expression) {
3305 _leftOperand = _becomeParentOf(expression);
3306 }
3307
3308 @override
3309 int get precedence => operator.type.precedence;
3310
3311 /**
3312 * If the AST structure has been resolved, and the function being invoked is
3313 * known based on propagated type information, then return the parameter
3314 * element representing the parameter to which the value of the right operand
3315 * will be bound. Otherwise, return `null`.
3316 */
3317 @deprecated // Use "expression.propagatedParameterElement"
3318 ParameterElement get propagatedParameterElementForRightOperand {
3319 return _propagatedParameterElementForRightOperand;
3320 }
3321
3322 /**
3323 * Return the expression used to compute the right operand.
3324 */
3325 Expression get rightOperand => _rightOperand;
3326
3327 /**
3328 * Set the expression used to compute the right operand to the given
3329 * [expression].
3330 */
3331 void set rightOperand(Expression expression) {
3332 _rightOperand = _becomeParentOf(expression);
3333 }
3334
3335 /**
3336 * If the AST structure has been resolved, and the function being invoked is
3337 * known based on static type information, then return the parameter element
3338 * representing the parameter to which the value of the right operand will be
3339 * bound. Otherwise, return `null`.
3340 */
3341 @deprecated // Use "expression.staticParameterElement"
3342 ParameterElement get staticParameterElementForRightOperand {
3343 return _staticParameterElementForRightOperand;
3344 }
3345
3346 /**
3347 * If the AST structure has been resolved, and the function being invoked is
3348 * known based on propagated type information, then return the parameter
3349 * element representing the parameter to which the value of the right operand
3350 * will be bound. Otherwise, return `null`.
3351 */
3352 ParameterElement get _propagatedParameterElementForRightOperand {
3353 if (propagatedElement == null) {
3354 return null;
3355 }
3356 List<ParameterElement> parameters = propagatedElement.parameters;
3357 if (parameters.length < 1) {
3358 return null;
3359 }
3360 return parameters[0];
3361 }
3362
3363 /**
3364 * If the AST structure has been resolved, and the function being invoked is
3365 * known based on static type information, then return the parameter element
3366 * representing the parameter to which the value of the right operand will be
3367 * bound. Otherwise, return `null`.
3368 */
3369 ParameterElement get _staticParameterElementForRightOperand {
3370 if (staticElement == null) {
3371 return null;
3372 }
3373 List<ParameterElement> parameters = staticElement.parameters;
3374 if (parameters.length < 1) {
3375 return null;
3376 }
3377 return parameters[0];
3378 }
3379
3380 @override
3381 accept(AstVisitor visitor) => visitor.visitBinaryExpression(this);
3382
3383 @override
3384 void visitChildren(AstVisitor visitor) {
3385 _safelyVisitChild(_leftOperand, visitor);
3386 _safelyVisitChild(_rightOperand, visitor);
3387 }
3388 }
3389
3390 /**
3391 * A sequence of statements.
3392 *
3393 * > block ::=
3394 * > '{' statement* '}'
3395 */
3396 class Block extends Statement {
3397 /**
3398 * The left curly bracket.
3399 */
3400 Token leftBracket;
3401
3402 /**
3403 * The statements contained in the block.
3404 */
3405 NodeList<Statement> _statements;
3406
3407 /**
3408 * The right curly bracket.
3409 */
3410 Token rightBracket;
3411
3412 /**
3413 * Initialize a newly created block of code.
3414 */
3415 Block(this.leftBracket, List<Statement> statements, this.rightBracket) {
3416 _statements = new NodeList<Statement>(this, statements);
3417 }
3418
3419 @override
3420 Token get beginToken => leftBracket;
3421
3422 @override
3423 Iterable get childEntities => new ChildEntities()
3424 ..add(leftBracket)
3425 ..addAll(_statements)
3426 ..add(rightBracket);
3427
3428 @override
3429 Token get endToken => rightBracket;
3430
3431 /**
3432 * Return the statements contained in the block.
3433 */
3434 NodeList<Statement> get statements => _statements;
3435
3436 @override
3437 accept(AstVisitor visitor) => visitor.visitBlock(this);
3438
3439 @override
3440 void visitChildren(AstVisitor visitor) {
3441 _statements.accept(visitor);
3442 }
3443 }
3444
3445 /**
3446 * A function body that consists of a block of statements.
3447 *
3448 * > blockFunctionBody ::=
3449 * > ('async' | 'async' '*' | 'sync' '*')? [Block]
3450 */
3451 class BlockFunctionBody extends FunctionBody {
3452 /**
3453 * The token representing the 'async' or 'sync' keyword, or `null` if there is
3454 * no such keyword.
3455 */
3456 Token keyword;
3457
3458 /**
3459 * The star optionally following the 'async' or 'sync' keyword, or `null` if
3460 * there is wither no such keyword or no star.
3461 */
3462 Token star;
3463
3464 /**
3465 * The block representing the body of the function.
3466 */
3467 Block _block;
3468
3469 /**
3470 * Initialize a newly created function body consisting of a block of
3471 * statements. The [keyword] can be `null` if there is no keyword specified
3472 * for the block. The [star] can be `null` if there is no star following the
3473 * keyword (and must be `null` if there is no keyword).
3474 */
3475 BlockFunctionBody(this.keyword, this.star, Block block) {
3476 _block = _becomeParentOf(block);
3477 }
3478
3479 @override
3480 Token get beginToken => _block.beginToken;
3481
3482 /**
3483 * Return the block representing the body of the function.
3484 */
3485 Block get block => _block;
3486
3487 /**
3488 * Set the block representing the body of the function to the given [block].
3489 */
3490 void set block(Block block) {
3491 _block = _becomeParentOf(block);
3492 }
3493
3494 @override
3495 Iterable get childEntities =>
3496 new ChildEntities()..add(keyword)..add(star)..add(_block);
3497
3498 @override
3499 Token get endToken => _block.endToken;
3500
3501 @override
3502 bool get isAsynchronous => keyword != null && keyword.lexeme == Parser.ASYNC;
3503
3504 @override
3505 bool get isGenerator => star != null;
3506
3507 @override
3508 bool get isSynchronous => keyword == null || keyword.lexeme != Parser.ASYNC;
3509
3510 @override
3511 accept(AstVisitor visitor) => visitor.visitBlockFunctionBody(this);
3512
3513 @override
3514 void visitChildren(AstVisitor visitor) {
3515 _safelyVisitChild(_block, visitor);
3516 }
3517 }
3518
3519 /**
3520 * A boolean literal expression.
3521 *
3522 * > booleanLiteral ::=
3523 * > 'false' | 'true'
3524 */
3525 class BooleanLiteral extends Literal {
3526 /**
3527 * The token representing the literal.
3528 */
3529 Token literal;
3530
3531 /**
3532 * The value of the literal.
3533 */
3534 bool value = false;
3535
3536 /**
3537 * Initialize a newly created boolean literal.
3538 */
3539 BooleanLiteral(this.literal, this.value);
3540
3541 @override
3542 Token get beginToken => literal;
3543
3544 @override
3545 Iterable get childEntities => new ChildEntities()..add(literal);
3546
3547 @override
3548 Token get endToken => literal;
3549
3550 @override
3551 bool get isSynthetic => literal.isSynthetic;
3552
3553 @override
3554 accept(AstVisitor visitor) => visitor.visitBooleanLiteral(this);
3555
3556 @override
3557 void visitChildren(AstVisitor visitor) {
3558 // There are no children to visit.
3559 }
3560 }
3561
3562 /**
3563 * An AST visitor that will recursively visit all of the nodes in an AST
3564 * structure, similar to [GeneralizingAstVisitor]. This visitor uses a
3565 * breadth-first ordering rather than the depth-first ordering of
3566 * [GeneralizingAstVisitor].
3567 *
3568 * Subclasses that override a visit method must either invoke the overridden
3569 * visit method or explicitly invoke the more general visit method. Failure to
3570 * do so will cause the visit methods for superclasses of the node to not be
3571 * invoked and will cause the children of the visited node to not be visited.
3572 *
3573 * In addition, subclasses should <b>not</b> explicitly visit the children of a
3574 * node, but should ensure that the method [visitNode] is used to visit the
3575 * children (either directly or indirectly). Failure to do will break the order
3576 * in which nodes are visited.
3577 */
3578 class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
3579 /**
3580 * A queue holding the nodes that have not yet been visited in the order in
3581 * which they ought to be visited.
3582 */
3583 Queue<AstNode> _queue = new Queue<AstNode>();
3584
3585 /**
3586 * A visitor, used to visit the children of the current node, that will add
3587 * the nodes it visits to the [_queue].
3588 */
3589 GeneralizingAstVisitor<Object> _childVisitor;
3590
3591 /**
3592 * Initialize a newly created visitor.
3593 */
3594 BreadthFirstVisitor() {
3595 _childVisitor = new GeneralizingAstVisitor_BreadthFirstVisitor(this);
3596 }
3597
3598 /**
3599 * Visit all nodes in the tree starting at the given [root] node, in
3600 * breadth-first order.
3601 */
3602 void visitAllNodes(AstNode root) {
3603 _queue.add(root);
3604 while (!_queue.isEmpty) {
3605 AstNode next = _queue.removeFirst();
3606 next.accept(this);
3607 }
3608 }
3609
3610 @override
3611 R visitNode(AstNode node) {
3612 node.visitChildren(_childVisitor);
3613 return null;
3614 }
3615 }
3616
3617 /**
3618 * A break statement.
3619 *
3620 * > breakStatement ::=
3621 * > 'break' [SimpleIdentifier]? ';'
3622 */
3623 class BreakStatement extends Statement {
3624 /**
3625 * The token representing the 'break' keyword.
3626 */
3627 Token breakKeyword;
3628
3629 /**
3630 * The label associated with the statement, or `null` if there is no label.
3631 */
3632 SimpleIdentifier _label;
3633
3634 /**
3635 * The semicolon terminating the statement.
3636 */
3637 Token semicolon;
3638
3639 /**
3640 * The AstNode which this break statement is breaking from. This will be
3641 * either a [Statement] (in the case of breaking out of a loop), a
3642 * [SwitchMember] (in the case of a labeled break statement whose label
3643 * matches a label on a switch case in an enclosing switch statement), or
3644 * `null` if the AST has not yet been resolved or if the target could not be
3645 * resolved. Note that if the source code has errors, the target might be
3646 * invalid (e.g. trying to break to a switch case).
3647 */
3648 AstNode target;
3649
3650 /**
3651 * Initialize a newly created break statement. The [label] can be `null` if
3652 * there is no label associated with the statement.
3653 */
3654 BreakStatement(this.breakKeyword, SimpleIdentifier label, this.semicolon) {
3655 _label = _becomeParentOf(label);
3656 }
3657
3658 @override
3659 Token get beginToken => breakKeyword;
3660
3661 @override
3662 Iterable get childEntities =>
3663 new ChildEntities()..add(breakKeyword)..add(_label)..add(semicolon);
3664
3665 @override
3666 Token get endToken => semicolon;
3667
3668 /**
3669 * Return the token representing the 'break' keyword.
3670 */
3671 @deprecated // Use "this.breakKeyword"
3672 Token get keyword => breakKeyword;
3673
3674 /**
3675 * Sethe token representing the 'break' keyword to the given [token].
3676 */
3677 @deprecated // Use "this.breakKeyword"
3678 void set keyword(Token token) {
3679 breakKeyword = token;
3680 }
3681
3682 /**
3683 * Return the label associated with the statement, or `null` if there is no
3684 * label.
3685 */
3686 SimpleIdentifier get label => _label;
3687
3688 /**
3689 * Set the label associated with the statement to the given [identifier].
3690 */
3691 void set label(SimpleIdentifier identifier) {
3692 _label = _becomeParentOf(identifier);
3693 }
3694
3695 @override
3696 accept(AstVisitor visitor) => visitor.visitBreakStatement(this);
3697
3698 @override
3699 void visitChildren(AstVisitor visitor) {
3700 _safelyVisitChild(_label, visitor);
3701 }
3702 }
3703
3704 /**
3705 * A sequence of cascaded expressions: expressions that share a common target.
3706 * There are three kinds of expressions that can be used in a cascade
3707 * expression: [IndexExpression], [MethodInvocation] and [PropertyAccess].
3708 *
3709 * > cascadeExpression ::=
3710 * > [Expression] cascadeSection*
3711 * >
3712 * > cascadeSection ::=
3713 * > '..' (cascadeSelector arguments*) (assignableSelector arguments*)*
3714 * > (assignmentOperator expressionWithoutCascade)?
3715 * >
3716 * > cascadeSelector ::=
3717 * > '[ ' expression '] '
3718 * > | identifier
3719 */
3720 class CascadeExpression extends Expression {
3721 /**
3722 * The target of the cascade sections.
3723 */
3724 Expression _target;
3725
3726 /**
3727 * The cascade sections sharing the common target.
3728 */
3729 NodeList<Expression> _cascadeSections;
3730
3731 /**
3732 * Initialize a newly created cascade expression. The list of
3733 * [cascadeSections] must contain at least one element.
3734 */
3735 CascadeExpression(Expression target, List<Expression> cascadeSections) {
3736 _target = _becomeParentOf(target);
3737 _cascadeSections = new NodeList<Expression>(this, cascadeSections);
3738 }
3739
3740 @override
3741 Token get beginToken => _target.beginToken;
3742
3743 /**
3744 * Return the cascade sections sharing the common target.
3745 */
3746 NodeList<Expression> get cascadeSections => _cascadeSections;
3747
3748 @override
3749 Iterable get childEntities => new ChildEntities()
3750 ..add(_target)
3751 ..addAll(_cascadeSections);
3752
3753 @override
3754 Token get endToken => _cascadeSections.endToken;
3755
3756 @override
3757 int get precedence => 2;
3758
3759 /**
3760 * Return the target of the cascade sections.
3761 */
3762 Expression get target => _target;
3763
3764 /**
3765 * Set the target of the cascade sections to the given [expression].
3766 */
3767 void set target(Expression target) {
3768 _target = _becomeParentOf(target);
3769 }
3770
3771 @override
3772 accept(AstVisitor visitor) => visitor.visitCascadeExpression(this);
3773
3774 @override
3775 void visitChildren(AstVisitor visitor) {
3776 _safelyVisitChild(_target, visitor);
3777 _cascadeSections.accept(visitor);
3778 }
3779 }
3780
3781 /**
3782 * A catch clause within a try statement.
3783 *
3784 * > onPart ::=
3785 * > catchPart [Block]
3786 * > | 'on' type catchPart? [Block]
3787 * >
3788 * > catchPart ::=
3789 * > 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')'
3790 */
3791 class CatchClause extends AstNode {
3792 /**
3793 * The token representing the 'on' keyword, or `null` if there is no 'on'
3794 * keyword.
3795 */
3796 Token onKeyword;
3797
3798 /**
3799 * The type of exceptions caught by this catch clause, or `null` if this catch
3800 * clause catches every type of exception.
3801 */
3802 TypeName _exceptionType;
3803
3804 /**
3805 * The token representing the 'catch' keyword, or `null` if there is no
3806 * 'catch' keyword.
3807 */
3808 Token catchKeyword;
3809
3810 /**
3811 * The left parenthesis, or `null` if there is no 'catch' keyword.
3812 */
3813 Token leftParenthesis;
3814
3815 /**
3816 * The parameter whose value will be the exception that was thrown, or `null`
3817 * if there is no 'catch' keyword.
3818 */
3819 SimpleIdentifier _exceptionParameter;
3820
3821 /**
3822 * The comma separating the exception parameter from the stack trace
3823 * parameter, or `null` if there is no stack trace parameter.
3824 */
3825 Token comma;
3826
3827 /**
3828 * The parameter whose value will be the stack trace associated with the
3829 * exception, or `null` if there is no stack trace parameter.
3830 */
3831 SimpleIdentifier _stackTraceParameter;
3832
3833 /**
3834 * The right parenthesis, or `null` if there is no 'catch' keyword.
3835 */
3836 Token rightParenthesis;
3837
3838 /**
3839 * The body of the catch block.
3840 */
3841 Block _body;
3842
3843 /**
3844 * Initialize a newly created catch clause. The [onKeyword] and
3845 * [exceptionType] can be `null` if the clause will catch all exceptions. The
3846 * [comma] and [stackTraceParameter] can be `null` if the stack trace is not
3847 * referencable within the body.
3848 */
3849 CatchClause(this.onKeyword, TypeName exceptionType, this.catchKeyword,
3850 this.leftParenthesis, SimpleIdentifier exceptionParameter, this.comma,
3851 SimpleIdentifier stackTraceParameter, this.rightParenthesis, Block body) {
3852 _exceptionType = _becomeParentOf(exceptionType);
3853 _exceptionParameter = _becomeParentOf(exceptionParameter);
3854 _stackTraceParameter = _becomeParentOf(stackTraceParameter);
3855 _body = _becomeParentOf(body);
3856 }
3857
3858 @override
3859 Token get beginToken {
3860 if (onKeyword != null) {
3861 return onKeyword;
3862 }
3863 return catchKeyword;
3864 }
3865
3866 /**
3867 * Return the body of the catch block.
3868 */
3869 Block get body => _body;
3870
3871 /**
3872 * Set the body of the catch block to the given [block].
3873 */
3874 void set body(Block block) {
3875 _body = _becomeParentOf(block);
3876 }
3877
3878 @override
3879 Iterable get childEntities => new ChildEntities()
3880 ..add(onKeyword)
3881 ..add(_exceptionType)
3882 ..add(catchKeyword)
3883 ..add(leftParenthesis)
3884 ..add(_exceptionParameter)
3885 ..add(comma)
3886 ..add(_stackTraceParameter)
3887 ..add(rightParenthesis)
3888 ..add(_body);
3889
3890 @override
3891 Token get endToken => _body.endToken;
3892
3893 /**
3894 * Return the parameter whose value will be the exception that was thrown, or
3895 * `null` if there is no 'catch' keyword.
3896 */
3897 SimpleIdentifier get exceptionParameter => _exceptionParameter;
3898
3899 /**
3900 * Set the parameter whose value will be the exception that was thrown to the
3901 * given [parameter].
3902 */
3903 void set exceptionParameter(SimpleIdentifier parameter) {
3904 _exceptionParameter = _becomeParentOf(parameter);
3905 }
3906
3907 /**
3908 * Return the type of exceptions caught by this catch clause, or `null` if
3909 * this catch clause catches every type of exception.
3910 */
3911 TypeName get exceptionType => _exceptionType;
3912
3913 /**
3914 * Set the type of exceptions caught by this catch clause to the given
3915 * [exceptionType].
3916 */
3917 void set exceptionType(TypeName exceptionType) {
3918 _exceptionType = _becomeParentOf(exceptionType);
3919 }
3920
3921 /**
3922 * Return the parameter whose value will be the stack trace associated with
3923 * the exception, or `null` if there is no stack trace parameter.
3924 */
3925 SimpleIdentifier get stackTraceParameter => _stackTraceParameter;
3926
3927 /**
3928 * Set the parameter whose value will be the stack trace associated with the
3929 * exception to the given [parameter].
3930 */
3931 void set stackTraceParameter(SimpleIdentifier parameter) {
3932 _stackTraceParameter = _becomeParentOf(parameter);
3933 }
3934
3935 @override
3936 accept(AstVisitor visitor) => visitor.visitCatchClause(this);
3937
3938 @override
3939 void visitChildren(AstVisitor visitor) {
3940 _safelyVisitChild(_exceptionType, visitor);
3941 _safelyVisitChild(_exceptionParameter, visitor);
3942 _safelyVisitChild(_stackTraceParameter, visitor);
3943 _safelyVisitChild(_body, visitor);
3944 }
3945 }
3946
3947 /**
3948 * Helper class to allow iteration of child entities of an AST node.
3949 */
3950 class ChildEntities extends Object with IterableMixin implements Iterable {
3951 /**
3952 * The list of child entities to be iterated over.
3953 */
3954 List _entities = [];
3955
3956 @override
3957 Iterator get iterator => _entities.iterator;
3958
3959 /**
3960 * Add an AST node or token as the next child entity, if it is not null.
3961 */
3962 void add(entity) {
3963 if (entity != null) {
3964 assert(entity is Token || entity is AstNode);
3965 _entities.add(entity);
3966 }
3967 }
3968
3969 /**
3970 * Add the given items as the next child entities, if [items] is not null.
3971 */
3972 void addAll(Iterable items) {
3973 if (items != null) {
3974 _entities.addAll(items);
3975 }
3976 }
3977 }
3978
3979 /**
3980 * The declaration of a class.
3981 *
3982 * > classDeclaration ::=
3983 * > 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]?
3984 * > ([ExtendsClause] [WithClause]?)?
3985 * > [ImplementsClause]?
3986 * > '{' [ClassMember]* '}'
3987 */
3988 class ClassDeclaration extends NamedCompilationUnitMember {
3989 /**
3990 * The 'abstract' keyword, or `null` if the keyword was absent.
3991 */
3992 Token abstractKeyword;
3993
3994 /**
3995 * The token representing the 'class' keyword.
3996 */
3997 Token classKeyword;
3998
3999 /**
4000 * The type parameters for the class, or `null` if the class does not have any
4001 * type parameters.
4002 */
4003 TypeParameterList _typeParameters;
4004
4005 /**
4006 * The extends clause for the class, or `null` if the class does not extend
4007 * any other class.
4008 */
4009 ExtendsClause _extendsClause;
4010
4011 /**
4012 * The with clause for the class, or `null` if the class does not have a with
4013 * clause.
4014 */
4015 WithClause _withClause;
4016
4017 /**
4018 * The implements clause for the class, or `null` if the class does not
4019 * implement any interfaces.
4020 */
4021 ImplementsClause _implementsClause;
4022
4023 /**
4024 * The native clause for the class, or `null` if the class does not have a
4025 * native clause.
4026 */
4027 NativeClause _nativeClause;
4028
4029 /**
4030 * The left curly bracket.
4031 */
4032 Token leftBracket;
4033
4034 /**
4035 * The members defined by the class.
4036 */
4037 NodeList<ClassMember> _members;
4038
4039 /**
4040 * The right curly bracket.
4041 */
4042 Token rightBracket;
4043
4044 /**
4045 * Initialize a newly created class declaration. Either or both of the
4046 * [comment] and [metadata] can be `null` if the class does not have the
4047 * corresponding attribute. The [abstractKeyword] can be `null` if the class
4048 * is not abstract. The [typeParameters] can be `null` if the class does not
4049 * have any type parameters. Any or all of the [extendsClause], [withClause],
4050 * and [implementsClause] can be `null` if the class does not have the
4051 * corresponding clause. The list of [members] can be `null` if the class does
4052 * not have any members.
4053 */
4054 ClassDeclaration(Comment comment, List<Annotation> metadata,
4055 this.abstractKeyword, this.classKeyword, SimpleIdentifier name,
4056 TypeParameterList typeParameters, ExtendsClause extendsClause,
4057 WithClause withClause, ImplementsClause implementsClause,
4058 this.leftBracket, List<ClassMember> members, this.rightBracket)
4059 : super(comment, metadata, name) {
4060 _typeParameters = _becomeParentOf(typeParameters);
4061 _extendsClause = _becomeParentOf(extendsClause);
4062 _withClause = _becomeParentOf(withClause);
4063 _implementsClause = _becomeParentOf(implementsClause);
4064 _members = new NodeList<ClassMember>(this, members);
4065 }
4066
4067 @override
4068 Iterable get childEntities => super._childEntities
4069 ..add(abstractKeyword)
4070 ..add(classKeyword)
4071 ..add(_name)
4072 ..add(_typeParameters)
4073 ..add(_extendsClause)
4074 ..add(_withClause)
4075 ..add(_implementsClause)
4076 ..add(_nativeClause)
4077 ..add(leftBracket)
4078 ..addAll(members)
4079 ..add(rightBracket);
4080
4081 @override
4082 ClassElement get element =>
4083 _name != null ? (_name.staticElement as ClassElement) : null;
4084
4085 @override
4086 Token get endToken => rightBracket;
4087
4088 /**
4089 * Return the extends clause for this class, or `null` if the class does not
4090 * extend any other class.
4091 */
4092 ExtendsClause get extendsClause => _extendsClause;
4093
4094 /**
4095 * Set the extends clause for this class to the given [extendsClause].
4096 */
4097 void set extendsClause(ExtendsClause extendsClause) {
4098 _extendsClause = _becomeParentOf(extendsClause);
4099 }
4100
4101 @override
4102 Token get firstTokenAfterCommentAndMetadata {
4103 if (abstractKeyword != null) {
4104 return abstractKeyword;
4105 }
4106 return classKeyword;
4107 }
4108
4109 /**
4110 * Return the implements clause for the class, or `null` if the class does not
4111 * implement any interfaces.
4112 */
4113 ImplementsClause get implementsClause => _implementsClause;
4114
4115 /**
4116 * Set the implements clause for the class to the given [implementsClause].
4117 */
4118 void set implementsClause(ImplementsClause implementsClause) {
4119 _implementsClause = _becomeParentOf(implementsClause);
4120 }
4121
4122 /**
4123 * Return `true` if this class is declared to be an abstract class.
4124 */
4125 bool get isAbstract => abstractKeyword != null;
4126
4127 /**
4128 * Return the members defined by the class.
4129 */
4130 NodeList<ClassMember> get members => _members;
4131
4132 /**
4133 * Return the native clause for this class, or `null` if the class does not
4134 * have a native clause.
4135 */
4136 NativeClause get nativeClause => _nativeClause;
4137
4138 /**
4139 * Set the native clause for this class to the given [nativeClause].
4140 */
4141 void set nativeClause(NativeClause nativeClause) {
4142 _nativeClause = _becomeParentOf(nativeClause);
4143 }
4144
4145 /**
4146 * Return the type parameters for the class, or `null` if the class does not
4147 * have any type parameters.
4148 */
4149 TypeParameterList get typeParameters => _typeParameters;
4150
4151 /**
4152 * Set the type parameters for the class to the given list of [typeParameters] .
4153 */
4154 void set typeParameters(TypeParameterList typeParameters) {
4155 _typeParameters = _becomeParentOf(typeParameters);
4156 }
4157
4158 /**
4159 * Return the with clause for the class, or `null` if the class does not have
4160 * a with clause.
4161 */
4162 WithClause get withClause => _withClause;
4163
4164 /**
4165 * Set the with clause for the class to the given [withClause].
4166 */
4167 void set withClause(WithClause withClause) {
4168 _withClause = _becomeParentOf(withClause);
4169 }
4170
4171 @override
4172 accept(AstVisitor visitor) => visitor.visitClassDeclaration(this);
4173
4174 /**
4175 * Return the constructor declared in the class with the given [name], or
4176 * `null` if there is no such constructor. If the [name] is `null` then the
4177 * default constructor will be searched for.
4178 */
4179 ConstructorDeclaration getConstructor(String name) {
4180 for (ClassMember classMember in _members) {
4181 if (classMember is ConstructorDeclaration) {
4182 ConstructorDeclaration constructor = classMember;
4183 SimpleIdentifier constructorName = constructor.name;
4184 if (name == null && constructorName == null) {
4185 return constructor;
4186 }
4187 if (constructorName != null && constructorName.name == name) {
4188 return constructor;
4189 }
4190 }
4191 }
4192 return null;
4193 }
4194
4195 /**
4196 * Return the field declared in the class with the given [name], or `null` if
4197 * there is no such field.
4198 */
4199 VariableDeclaration getField(String name) {
4200 for (ClassMember classMember in _members) {
4201 if (classMember is FieldDeclaration) {
4202 FieldDeclaration fieldDeclaration = classMember;
4203 NodeList<VariableDeclaration> fields =
4204 fieldDeclaration.fields.variables;
4205 for (VariableDeclaration field in fields) {
4206 SimpleIdentifier fieldName = field.name;
4207 if (fieldName != null && name == fieldName.name) {
4208 return field;
4209 }
4210 }
4211 }
4212 }
4213 return null;
4214 }
4215
4216 /**
4217 * Return the method declared in the class with the given [name], or `null` if
4218 * there is no such method.
4219 */
4220 MethodDeclaration getMethod(String name) {
4221 for (ClassMember classMember in _members) {
4222 if (classMember is MethodDeclaration) {
4223 MethodDeclaration method = classMember;
4224 SimpleIdentifier methodName = method.name;
4225 if (methodName != null && name == methodName.name) {
4226 return method;
4227 }
4228 }
4229 }
4230 return null;
4231 }
4232
4233 @override
4234 void visitChildren(AstVisitor visitor) {
4235 super.visitChildren(visitor);
4236 _safelyVisitChild(_name, visitor);
4237 _safelyVisitChild(_typeParameters, visitor);
4238 _safelyVisitChild(_extendsClause, visitor);
4239 _safelyVisitChild(_withClause, visitor);
4240 _safelyVisitChild(_implementsClause, visitor);
4241 _safelyVisitChild(_nativeClause, visitor);
4242 members.accept(visitor);
4243 }
4244 }
4245
4246 /**
4247 * A node that declares a name within the scope of a class.
4248 */
4249 abstract class ClassMember extends Declaration {
4250 /**
4251 * Initialize a newly created member of a class. Either or both of the
4252 * [comment] and [metadata] can be `null` if the member does not have the
4253 * corresponding attribute.
4254 */
4255 ClassMember(Comment comment, List<Annotation> metadata)
4256 : super(comment, metadata);
4257 }
4258
4259 /**
4260 * A class type alias.
4261 *
4262 * > classTypeAlias ::=
4263 * > [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplicatio n
4264 * >
4265 * > mixinApplication ::=
4266 * > [TypeName] [WithClause] [ImplementsClause]? ';'
4267 */
4268 class ClassTypeAlias extends TypeAlias {
4269 /**
4270 * The type parameters for the class, or `null` if the class does not have any
4271 * type parameters.
4272 */
4273 TypeParameterList _typeParameters;
4274
4275 /**
4276 * The token for the '=' separating the name from the definition.
4277 */
4278 Token equals;
4279
4280 /**
4281 * The token for the 'abstract' keyword, or `null` if this is not defining an
4282 * abstract class.
4283 */
4284 Token abstractKeyword;
4285
4286 /**
4287 * The name of the superclass of the class being declared.
4288 */
4289 TypeName _superclass;
4290
4291 /**
4292 * The with clause for this class.
4293 */
4294 WithClause _withClause;
4295
4296 /**
4297 * The implements clause for this class, or `null` if there is no implements
4298 * clause.
4299 */
4300 ImplementsClause _implementsClause;
4301
4302 /**
4303 * Initialize a newly created class type alias. Either or both of the
4304 * [comment] and [metadata] can be `null` if the class type alias does not
4305 * have the corresponding attribute. The [typeParameters] can be `null` if the
4306 * class does not have any type parameters. The [abstractKeyword] can be
4307 * `null` if the class is not abstract. The [implementsClause] can be `null`
4308 * if the class does not implement any interfaces.
4309 */
4310 ClassTypeAlias(Comment comment, List<Annotation> metadata, Token keyword,
4311 SimpleIdentifier name, TypeParameterList typeParameters, this.equals,
4312 this.abstractKeyword, TypeName superclass, WithClause withClause,
4313 ImplementsClause implementsClause, Token semicolon)
4314 : super(comment, metadata, keyword, name, semicolon) {
4315 _typeParameters = _becomeParentOf(typeParameters);
4316 _superclass = _becomeParentOf(superclass);
4317 _withClause = _becomeParentOf(withClause);
4318 _implementsClause = _becomeParentOf(implementsClause);
4319 }
4320
4321 @override
4322 Iterable get childEntities => super._childEntities
4323 ..add(typedefKeyword)
4324 ..add(_name)
4325 ..add(_typeParameters)
4326 ..add(equals)
4327 ..add(abstractKeyword)
4328 ..add(_superclass)
4329 ..add(_withClause)
4330 ..add(_implementsClause)
4331 ..add(semicolon);
4332
4333 @override
4334 ClassElement get element =>
4335 _name != null ? (_name.staticElement as ClassElement) : null;
4336
4337 /**
4338 * Return the implements clause for this class, or `null` if there is no
4339 * implements clause.
4340 */
4341 ImplementsClause get implementsClause => _implementsClause;
4342
4343 /**
4344 * Set the implements clause for this class to the given [implementsClause].
4345 */
4346 void set implementsClause(ImplementsClause implementsClause) {
4347 _implementsClause = _becomeParentOf(implementsClause);
4348 }
4349
4350 /**
4351 * Return `true` if this class is declared to be an abstract class.
4352 */
4353 bool get isAbstract => abstractKeyword != null;
4354
4355 /**
4356 * Return the name of the superclass of the class being declared.
4357 */
4358 TypeName get superclass => _superclass;
4359
4360 /**
4361 * Set the name of the superclass of the class being declared to the given
4362 * [superclass] name.
4363 */
4364 void set superclass(TypeName superclass) {
4365 _superclass = _becomeParentOf(superclass);
4366 }
4367
4368 /**
4369 * Return the type parameters for the class, or `null` if the class does not
4370 * have any type parameters.
4371 */
4372 TypeParameterList get typeParameters => _typeParameters;
4373
4374 /**
4375 * Set the type parameters for the class to the given list of [typeParameters] .
4376 */
4377 void set typeParameters(TypeParameterList typeParameters) {
4378 _typeParameters = _becomeParentOf(typeParameters);
4379 }
4380
4381 /**
4382 * Return the with clause for this class.
4383 */
4384 WithClause get withClause => _withClause;
4385
4386 /**
4387 * Set the with clause for this class to the given with [withClause].
4388 */
4389 void set withClause(WithClause withClause) {
4390 _withClause = _becomeParentOf(withClause);
4391 }
4392
4393 @override
4394 accept(AstVisitor visitor) => visitor.visitClassTypeAlias(this);
4395
4396 @override
4397 void visitChildren(AstVisitor visitor) {
4398 super.visitChildren(visitor);
4399 _safelyVisitChild(_name, visitor);
4400 _safelyVisitChild(_typeParameters, visitor);
4401 _safelyVisitChild(_superclass, visitor);
4402 _safelyVisitChild(_withClause, visitor);
4403 _safelyVisitChild(_implementsClause, visitor);
4404 }
4405 }
4406
4407 /**
4408 * A combinator associated with an import or export directive.
4409 *
4410 * > combinator ::=
4411 * > [HideCombinator]
4412 * > | [ShowCombinator]
4413 */
4414 abstract class Combinator extends AstNode {
4415 /**
4416 * The 'hide' or 'show' keyword specifying what kind of processing is to be
4417 * done on the names.
4418 */
4419 Token keyword;
4420
4421 /**
4422 * Initialize a newly created combinator.
4423 */
4424 Combinator(this.keyword);
4425
4426 @override
4427 Token get beginToken => keyword;
4428 }
4429
4430 /**
4431 * A comment within the source code.
4432 *
4433 * > comment ::=
4434 * > endOfLineComment
4435 * > | blockComment
4436 * > | documentationComment
4437 * >
4438 * > endOfLineComment ::=
4439 * > '//' (CHARACTER - EOL)* EOL
4440 * >
4441 * > blockComment ::=
4442 * > '/ *' CHARACTER* '&#42;/'
4443 * >
4444 * > documentationComment ::=
4445 * > '/ **' (CHARACTER | [CommentReference])* '&#42;/'
4446 * > | ('///' (CHARACTER - EOL)* EOL)+
4447 */
4448 class Comment extends AstNode {
4449 /**
4450 * The tokens representing the comment.
4451 */
4452 final List<Token> tokens;
4453
4454 /**
4455 * The type of the comment.
4456 */
4457 final CommentType _type;
4458
4459 /**
4460 * The references embedded within the documentation comment. This list will be
4461 * empty unless this is a documentation comment that has references embedded
4462 * within it.
4463 */
4464 NodeList<CommentReference> _references;
4465
4466 /**
4467 * Initialize a newly created comment. The list of [tokens] must contain at
4468 * least one token. The [type] is the type of the comment. The list of
4469 * [references] can be empty if the comment does not contain any embedded
4470 * references.
4471 */
4472 Comment(this.tokens, this._type, List<CommentReference> references) {
4473 _references = new NodeList<CommentReference>(this, references);
4474 }
4475
4476 @override
4477 Token get beginToken => tokens[0];
4478
4479 @override
4480 Iterable get childEntities => new ChildEntities()..addAll(tokens);
4481
4482 @override
4483 Token get endToken => tokens[tokens.length - 1];
4484
4485 /**
4486 * Return `true` if this is a block comment.
4487 */
4488 bool get isBlock => _type == CommentType.BLOCK;
4489
4490 /**
4491 * Return `true` if this is a documentation comment.
4492 */
4493 bool get isDocumentation => _type == CommentType.DOCUMENTATION;
4494
4495 /**
4496 * Return `true` if this is an end-of-line comment.
4497 */
4498 bool get isEndOfLine => _type == CommentType.END_OF_LINE;
4499
4500 /**
4501 * Return the references embedded within the documentation comment.
4502 */
4503 NodeList<CommentReference> get references => _references;
4504
4505 @override
4506 accept(AstVisitor visitor) => visitor.visitComment(this);
4507
4508 @override
4509 void visitChildren(AstVisitor visitor) {
4510 _references.accept(visitor);
4511 }
4512
4513 /**
4514 * Create a block comment consisting of the given [tokens].
4515 */
4516 static Comment createBlockComment(List<Token> tokens) =>
4517 new Comment(tokens, CommentType.BLOCK, null);
4518
4519 /**
4520 * Create a documentation comment consisting of the given [tokens].
4521 */
4522 static Comment createDocumentationComment(List<Token> tokens) => new Comment(
4523 tokens, CommentType.DOCUMENTATION, new List<CommentReference>());
4524
4525 /**
4526 * Create a documentation comment consisting of the given [tokens] and having
4527 * the given [references] embedded within it.
4528 */
4529 static Comment createDocumentationCommentWithReferences(
4530 List<Token> tokens, List<CommentReference> references) =>
4531 new Comment(tokens, CommentType.DOCUMENTATION, references);
4532
4533 /**
4534 * Create an end-of-line comment consisting of the given [tokens].
4535 */
4536 static Comment createEndOfLineComment(List<Token> tokens) =>
4537 new Comment(tokens, CommentType.END_OF_LINE, null);
4538 }
4539
4540 /**
4541 * A reference to a Dart element that is found within a documentation comment.
4542 *
4543 * > commentReference ::=
4544 * > '[' 'new'? [Identifier] ']'
4545 */
4546 class CommentReference extends AstNode {
4547 /**
4548 * The token representing the 'new' keyword, or `null` if there was no 'new'
4549 * keyword.
4550 */
4551 Token newKeyword;
4552
4553 /**
4554 * The identifier being referenced.
4555 */
4556 Identifier _identifier;
4557
4558 /**
4559 * Initialize a newly created reference to a Dart element. The [newKeyword]
4560 * can be `null` if the reference is not to a constructor.
4561 */
4562 CommentReference(this.newKeyword, Identifier identifier) {
4563 _identifier = _becomeParentOf(identifier);
4564 }
4565
4566 @override
4567 Token get beginToken => _identifier.beginToken;
4568
4569 @override
4570 Iterable get childEntities =>
4571 new ChildEntities()..add(newKeyword)..add(_identifier);
4572
4573 @override
4574 Token get endToken => _identifier.endToken;
4575
4576 /**
4577 * Return the identifier being referenced.
4578 */
4579 Identifier get identifier => _identifier;
4580
4581 /**
4582 * Set the identifier being referenced to the given [identifier].
4583 */
4584 void set identifier(Identifier identifier) {
4585 _identifier = _becomeParentOf(identifier);
4586 }
4587
4588 @override
4589 accept(AstVisitor visitor) => visitor.visitCommentReference(this);
4590
4591 @override
4592 void visitChildren(AstVisitor visitor) {
4593 _safelyVisitChild(_identifier, visitor);
4594 }
4595 }
4596
4597 /**
4598 * The possible types of comments that are recognized by the parser.
4599 */
4600 class CommentType {
4601 /**
4602 * A block comment.
4603 */
4604 static const CommentType BLOCK = const CommentType('BLOCK');
4605
4606 /**
4607 * A documentation comment.
4608 */
4609 static const CommentType DOCUMENTATION = const CommentType('DOCUMENTATION');
4610
4611 /**
4612 * An end-of-line comment.
4613 */
4614 static const CommentType END_OF_LINE = const CommentType('END_OF_LINE');
4615
4616 /**
4617 * The name of the comment type.
4618 */
4619 final String name;
4620
4621 /**
4622 * Initialize a newly created comment type to have the given [name].
4623 */
4624 const CommentType(this.name);
4625
4626 @override
4627 String toString() => name;
4628 }
4629
4630 /**
4631 * A compilation unit.
4632 *
4633 * While the grammar restricts the order of the directives and declarations
4634 * within a compilation unit, this class does not enforce those restrictions.
4635 * In particular, the children of a compilation unit will be visited in lexical
4636 * order even if lexical order does not conform to the restrictions of the
4637 * grammar.
4638 *
4639 * > compilationUnit ::=
4640 * > directives declarations
4641 * >
4642 * > directives ::=
4643 * > [ScriptTag]? [LibraryDirective]? namespaceDirective* [PartDirective]*
4644 * > | [PartOfDirective]
4645 * >
4646 * > namespaceDirective ::=
4647 * > [ImportDirective]
4648 * > | [ExportDirective]
4649 * >
4650 * > declarations ::=
4651 * > [CompilationUnitMember]*
4652 */
4653 class CompilationUnit extends AstNode {
4654 /**
4655 * The first token in the token stream that was parsed to form this
4656 * compilation unit.
4657 */
4658 Token beginToken;
4659
4660 /**
4661 * The script tag at the beginning of the compilation unit, or `null` if there
4662 * is no script tag in this compilation unit.
4663 */
4664 ScriptTag _scriptTag;
4665
4666 /**
4667 * The directives contained in this compilation unit.
4668 */
4669 NodeList<Directive> _directives;
4670
4671 /**
4672 * The declarations contained in this compilation unit.
4673 */
4674 NodeList<CompilationUnitMember> _declarations;
4675
4676 /**
4677 * The last token in the token stream that was parsed to form this compilation
4678 * unit. This token should always have a type of [TokenType.EOF].
4679 */
4680 Token endToken;
4681
4682 /**
4683 * The element associated with this compilation unit, or `null` if the AST
4684 * structure has not been resolved.
4685 */
4686 CompilationUnitElement element;
4687
4688 /**
4689 * The line information for this compilation unit.
4690 */
4691 LineInfo lineInfo;
4692
4693 /**
4694 * Initialize a newly created compilation unit to have the given directives
4695 * and declarations. The [scriptTag] can be `null` if there is no script tag
4696 * in the compilation unit. The list of [directives] can be `null` if there
4697 * are no directives in the compilation unit. The list of [declarations] can
4698 * be `null` if there are no declarations in the compilation unit.
4699 */
4700 CompilationUnit(this.beginToken, ScriptTag scriptTag,
4701 List<Directive> directives, List<CompilationUnitMember> declarations,
4702 this.endToken) {
4703 _scriptTag = _becomeParentOf(scriptTag);
4704 _directives = new NodeList<Directive>(this, directives);
4705 _declarations = new NodeList<CompilationUnitMember>(this, declarations);
4706 }
4707
4708 @override
4709 Iterable get childEntities {
4710 ChildEntities result = new ChildEntities()..add(_scriptTag);
4711 if (_directivesAreBeforeDeclarations) {
4712 result..addAll(_directives)..addAll(_declarations);
4713 } else {
4714 result.addAll(sortedDirectivesAndDeclarations);
4715 }
4716 return result;
4717 }
4718
4719 /**
4720 * Return the declarations contained in this compilation unit.
4721 */
4722 NodeList<CompilationUnitMember> get declarations => _declarations;
4723
4724 /**
4725 * Return the directives contained in this compilation unit.
4726 */
4727 NodeList<Directive> get directives => _directives;
4728
4729 @override
4730 int get length {
4731 Token endToken = this.endToken;
4732 if (endToken == null) {
4733 return 0;
4734 }
4735 return endToken.offset + endToken.length;
4736 }
4737
4738 @override
4739 int get offset => 0;
4740
4741 /**
4742 * Return the script tag at the beginning of the compilation unit, or `null`
4743 * if there is no script tag in this compilation unit.
4744 */
4745 ScriptTag get scriptTag => _scriptTag;
4746
4747 /**
4748 * Set the script tag at the beginning of the compilation unit to the given
4749 * [scriptTag].
4750 */
4751 void set scriptTag(ScriptTag scriptTag) {
4752 _scriptTag = _becomeParentOf(scriptTag);
4753 }
4754
4755 /**
4756 * Return a list containing all of the directives and declarations in this
4757 * compilation unit, sorted in lexical order.
4758 */
4759 List<AstNode> get sortedDirectivesAndDeclarations {
4760 return <AstNode>[]
4761 ..addAll(_directives)
4762 ..addAll(_declarations)
4763 ..sort(AstNode.LEXICAL_ORDER);
4764 }
4765
4766 /**
4767 * Return `true` if all of the directives are lexically before any
4768 * declarations.
4769 */
4770 bool get _directivesAreBeforeDeclarations {
4771 if (_directives.isEmpty || _declarations.isEmpty) {
4772 return true;
4773 }
4774 Directive lastDirective = _directives[_directives.length - 1];
4775 CompilationUnitMember firstDeclaration = _declarations[0];
4776 return lastDirective.offset < firstDeclaration.offset;
4777 }
4778
4779 @override
4780 accept(AstVisitor visitor) => visitor.visitCompilationUnit(this);
4781
4782 @override
4783 void visitChildren(AstVisitor visitor) {
4784 _safelyVisitChild(_scriptTag, visitor);
4785 if (_directivesAreBeforeDeclarations) {
4786 _directives.accept(visitor);
4787 _declarations.accept(visitor);
4788 } else {
4789 for (AstNode child in sortedDirectivesAndDeclarations) {
4790 child.accept(visitor);
4791 }
4792 }
4793 }
4794 }
4795
4796 /**
4797 * A node that declares one or more names within the scope of a compilation
4798 * unit.
4799 *
4800 * > compilationUnitMember ::=
4801 * > [ClassDeclaration]
4802 * > | [TypeAlias]
4803 * > | [FunctionDeclaration]
4804 * > | [MethodDeclaration]
4805 * > | [VariableDeclaration]
4806 * > | [VariableDeclaration]
4807 */
4808 abstract class CompilationUnitMember extends Declaration {
4809 /**
4810 * Initialize a newly created generic compilation unit member. Either or both
4811 * of the [comment] and [metadata] can be `null` if the member does not have
4812 * the corresponding attribute.
4813 */
4814 CompilationUnitMember(Comment comment, List<Annotation> metadata)
4815 : super(comment, metadata);
4816 }
4817
4818 /**
4819 * A conditional expression.
4820 *
4821 * > conditionalExpression ::=
4822 * > [Expression] '?' [Expression] ':' [Expression]
4823 */
4824 class ConditionalExpression extends Expression {
4825 /**
4826 * The condition used to determine which of the expressions is executed next.
4827 */
4828 Expression _condition;
4829
4830 /**
4831 * The token used to separate the condition from the then expression.
4832 */
4833 Token question;
4834
4835 /**
4836 * The expression that is executed if the condition evaluates to `true`.
4837 */
4838 Expression _thenExpression;
4839
4840 /**
4841 * The token used to separate the then expression from the else expression.
4842 */
4843 Token colon;
4844
4845 /**
4846 * The expression that is executed if the condition evaluates to `false`.
4847 */
4848 Expression _elseExpression;
4849
4850 /**
4851 * Initialize a newly created conditional expression.
4852 */
4853 ConditionalExpression(Expression condition, this.question,
4854 Expression thenExpression, this.colon, Expression elseExpression) {
4855 _condition = _becomeParentOf(condition);
4856 _thenExpression = _becomeParentOf(thenExpression);
4857 _elseExpression = _becomeParentOf(elseExpression);
4858 }
4859
4860 @override
4861 Token get beginToken => _condition.beginToken;
4862
4863 @override
4864 Iterable get childEntities => new ChildEntities()
4865 ..add(_condition)
4866 ..add(question)
4867 ..add(_thenExpression)
4868 ..add(colon)
4869 ..add(_elseExpression);
4870
4871 /**
4872 * Return the condition used to determine which of the expressions is executed
4873 * next.
4874 */
4875 Expression get condition => _condition;
4876
4877 /**
4878 * Set the condition used to determine which of the expressions is executed
4879 * next to the given [expression].
4880 */
4881 void set condition(Expression expression) {
4882 _condition = _becomeParentOf(expression);
4883 }
4884
4885 /**
4886 * Return the expression that is executed if the condition evaluates to
4887 * `false`.
4888 */
4889 Expression get elseExpression => _elseExpression;
4890
4891 /**
4892 * Set the expression that is executed if the condition evaluates to `false`
4893 * to the given [expression].
4894 */
4895 void set elseExpression(Expression expression) {
4896 _elseExpression = _becomeParentOf(expression);
4897 }
4898
4899 @override
4900 Token get endToken => _elseExpression.endToken;
4901
4902 @override
4903 int get precedence => 3;
4904
4905 /**
4906 * Return the expression that is executed if the condition evaluates to
4907 * `true`.
4908 */
4909 Expression get thenExpression => _thenExpression;
4910
4911 /**
4912 * Set the expression that is executed if the condition evaluates to `true` to
4913 * the given [expression].
4914 */
4915 void set thenExpression(Expression expression) {
4916 _thenExpression = _becomeParentOf(expression);
4917 }
4918
4919 @override
4920 accept(AstVisitor visitor) => visitor.visitConditionalExpression(this);
4921
4922 @override
4923 void visitChildren(AstVisitor visitor) {
4924 _safelyVisitChild(_condition, visitor);
4925 _safelyVisitChild(_thenExpression, visitor);
4926 _safelyVisitChild(_elseExpression, visitor);
4927 }
4928 }
4929
4930 /**
4931 * An object that can be used to evaluate constant expressions to produce their
4932 * compile-time value. According to the Dart Language Specification:
4933 * <blockquote>
4934 * A constant expression is one of the following:
4935 * * A literal number.
4936 * * A literal boolean.
4937 * * A literal string where any interpolated expression is a compile-time
4938 * constant that evaluates to a numeric, string or boolean value or to `null`.
4939 * * `null`.
4940 * * A reference to a static constant variable.
4941 * * An identifier expression that denotes a constant variable, a class or a
4942 * type parameter.
4943 * * A constant constructor invocation.
4944 * * A constant list literal.
4945 * * A constant map literal.
4946 * * A simple or qualified identifier denoting a top-level function or a static
4947 * method.
4948 * * A parenthesized expression `(e)` where `e` is a constant expression.
4949 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`,
4950 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a
4951 * numeric, string or boolean value or to `null`.
4952 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where
4953 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean
4954 * value or to `null`.
4955 * * An expression of one of the forms `~e`, `e1 ^ e2`, `e1 & e2`, `e1 | e2`,
4956 * `e1 >> e2` or `e1 << e2`, where `e`, `e1` and `e2` are constant expressions
4957 * that evaluate to an integer value or to `null`.
4958 * * An expression of one of the forms `-e`, `e1 + e2`, `e1 - e2`, `e1 * e2`,
4959 * `e1 / e2`, `e1 ~/ e2`, `e1 > e2`, `e1 < e2`, `e1 >= e2`, `e1 <= e2` or
4960 * `e1 % e2`, where `e`, `e1` and `e2` are constant expressions that evaluate
4961 * to a numeric value or to `null`.
4962 * </blockquote>
4963 * The values returned by instances of this class are therefore `null` and
4964 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
4965 * `DartObject`.
4966 *
4967 * In addition, this class defines several values that can be returned to
4968 * indicate various conditions encountered during evaluation. These are
4969 * documented with the static fields that define those values.
4970 */
4971 class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
4972 /**
4973 * The value returned for expressions (or non-expression nodes) that are not
4974 * compile-time constant expressions.
4975 */
4976 static Object NOT_A_CONSTANT = new Object();
4977
4978 @override
4979 Object visitAdjacentStrings(AdjacentStrings node) {
4980 StringBuffer buffer = new StringBuffer();
4981 for (StringLiteral string in node.strings) {
4982 Object value = string.accept(this);
4983 if (identical(value, NOT_A_CONSTANT)) {
4984 return value;
4985 }
4986 buffer.write(value);
4987 }
4988 return buffer.toString();
4989 }
4990
4991 @override
4992 Object visitBinaryExpression(BinaryExpression node) {
4993 Object leftOperand = node.leftOperand.accept(this);
4994 if (identical(leftOperand, NOT_A_CONSTANT)) {
4995 return leftOperand;
4996 }
4997 Object rightOperand = node.rightOperand.accept(this);
4998 if (identical(rightOperand, NOT_A_CONSTANT)) {
4999 return rightOperand;
5000 }
5001 while (true) {
5002 if (node.operator.type == TokenType.AMPERSAND) {
5003 // integer or {@code null}
5004 if (leftOperand is int && rightOperand is int) {
5005 return leftOperand & rightOperand;
5006 }
5007 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) {
5008 // boolean or {@code null}
5009 if (leftOperand is bool && rightOperand is bool) {
5010 return leftOperand && rightOperand;
5011 }
5012 } else if (node.operator.type == TokenType.BANG_EQ) {
5013 // numeric, string, boolean, or {@code null}
5014 if (leftOperand is bool && rightOperand is bool) {
5015 return leftOperand != rightOperand;
5016 } else if (leftOperand is num && rightOperand is num) {
5017 return leftOperand != rightOperand;
5018 } else if (leftOperand is String && rightOperand is String) {
5019 return leftOperand != rightOperand;
5020 }
5021 } else if (node.operator.type == TokenType.BAR) {
5022 // integer or {@code null}
5023 if (leftOperand is int && rightOperand is int) {
5024 return leftOperand | rightOperand;
5025 }
5026 } else if (node.operator.type == TokenType.BAR_BAR) {
5027 // boolean or {@code null}
5028 if (leftOperand is bool && rightOperand is bool) {
5029 return leftOperand || rightOperand;
5030 }
5031 } else if (node.operator.type == TokenType.CARET) {
5032 // integer or {@code null}
5033 if (leftOperand is int && rightOperand is int) {
5034 return leftOperand ^ rightOperand;
5035 }
5036 } else if (node.operator.type == TokenType.EQ_EQ) {
5037 // numeric, string, boolean, or {@code null}
5038 if (leftOperand is bool && rightOperand is bool) {
5039 return leftOperand == rightOperand;
5040 } else if (leftOperand is num && rightOperand is num) {
5041 return leftOperand == rightOperand;
5042 } else if (leftOperand is String && rightOperand is String) {
5043 return leftOperand == rightOperand;
5044 }
5045 } else if (node.operator.type == TokenType.GT) {
5046 // numeric or {@code null}
5047 if (leftOperand is num && rightOperand is num) {
5048 return leftOperand.compareTo(rightOperand) > 0;
5049 }
5050 } else if (node.operator.type == TokenType.GT_EQ) {
5051 // numeric or {@code null}
5052 if (leftOperand is num && rightOperand is num) {
5053 return leftOperand.compareTo(rightOperand) >= 0;
5054 }
5055 } else if (node.operator.type == TokenType.GT_GT) {
5056 // integer or {@code null}
5057 if (leftOperand is int && rightOperand is int) {
5058 return leftOperand >> rightOperand;
5059 }
5060 } else if (node.operator.type == TokenType.LT) {
5061 // numeric or {@code null}
5062 if (leftOperand is num && rightOperand is num) {
5063 return leftOperand.compareTo(rightOperand) < 0;
5064 }
5065 } else if (node.operator.type == TokenType.LT_EQ) {
5066 // numeric or {@code null}
5067 if (leftOperand is num && rightOperand is num) {
5068 return leftOperand.compareTo(rightOperand) <= 0;
5069 }
5070 } else if (node.operator.type == TokenType.LT_LT) {
5071 // integer or {@code null}
5072 if (leftOperand is int && rightOperand is int) {
5073 return leftOperand << rightOperand;
5074 }
5075 } else if (node.operator.type == TokenType.MINUS) {
5076 // numeric or {@code null}
5077 if (leftOperand is num && rightOperand is num) {
5078 return leftOperand - rightOperand;
5079 }
5080 } else if (node.operator.type == TokenType.PERCENT) {
5081 // numeric or {@code null}
5082 if (leftOperand is num && rightOperand is num) {
5083 return leftOperand.remainder(rightOperand);
5084 }
5085 } else if (node.operator.type == TokenType.PLUS) {
5086 // numeric or {@code null}
5087 if (leftOperand is num && rightOperand is num) {
5088 return leftOperand + rightOperand;
5089 }
5090 } else if (node.operator.type == TokenType.STAR) {
5091 // numeric or {@code null}
5092 if (leftOperand is num && rightOperand is num) {
5093 return leftOperand * rightOperand;
5094 }
5095 } else if (node.operator.type == TokenType.SLASH) {
5096 // numeric or {@code null}
5097 if (leftOperand is num && rightOperand is num) {
5098 return leftOperand / rightOperand;
5099 }
5100 } else if (node.operator.type == TokenType.TILDE_SLASH) {
5101 // numeric or {@code null}
5102 if (leftOperand is num && rightOperand is num) {
5103 return leftOperand ~/ rightOperand;
5104 }
5105 } else {}
5106 break;
5107 }
5108 // TODO(brianwilkerson) This doesn't handle numeric conversions.
5109 return visitExpression(node);
5110 }
5111
5112 @override
5113 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
5114
5115 @override
5116 Object visitDoubleLiteral(DoubleLiteral node) => node.value;
5117
5118 @override
5119 Object visitIntegerLiteral(IntegerLiteral node) => node.value;
5120
5121 @override
5122 Object visitInterpolationExpression(InterpolationExpression node) {
5123 Object value = node.expression.accept(this);
5124 if (value == null || value is bool || value is String || value is num) {
5125 return value;
5126 }
5127 return NOT_A_CONSTANT;
5128 }
5129
5130 @override
5131 Object visitInterpolationString(InterpolationString node) => node.value;
5132
5133 @override
5134 Object visitListLiteral(ListLiteral node) {
5135 List<Object> list = new List<Object>();
5136 for (Expression element in node.elements) {
5137 Object value = element.accept(this);
5138 if (identical(value, NOT_A_CONSTANT)) {
5139 return value;
5140 }
5141 list.add(value);
5142 }
5143 return list;
5144 }
5145
5146 @override
5147 Object visitMapLiteral(MapLiteral node) {
5148 HashMap<String, Object> map = new HashMap<String, Object>();
5149 for (MapLiteralEntry entry in node.entries) {
5150 Object key = entry.key.accept(this);
5151 Object value = entry.value.accept(this);
5152 if (key is! String || identical(value, NOT_A_CONSTANT)) {
5153 return NOT_A_CONSTANT;
5154 }
5155 map[(key as String)] = value;
5156 }
5157 return map;
5158 }
5159
5160 @override
5161 Object visitMethodInvocation(MethodInvocation node) => visitNode(node);
5162
5163 @override
5164 Object visitNode(AstNode node) => NOT_A_CONSTANT;
5165
5166 @override
5167 Object visitNullLiteral(NullLiteral node) => null;
5168
5169 @override
5170 Object visitParenthesizedExpression(ParenthesizedExpression node) =>
5171 node.expression.accept(this);
5172
5173 @override
5174 Object visitPrefixedIdentifier(PrefixedIdentifier node) =>
5175 _getConstantValue(null);
5176
5177 @override
5178 Object visitPrefixExpression(PrefixExpression node) {
5179 Object operand = node.operand.accept(this);
5180 if (identical(operand, NOT_A_CONSTANT)) {
5181 return operand;
5182 }
5183 while (true) {
5184 if (node.operator.type == TokenType.BANG) {
5185 if (identical(operand, true)) {
5186 return false;
5187 } else if (identical(operand, false)) {
5188 return true;
5189 }
5190 } else if (node.operator.type == TokenType.TILDE) {
5191 if (operand is int) {
5192 return ~operand;
5193 }
5194 } else if (node.operator.type == TokenType.MINUS) {
5195 if (operand == null) {
5196 return null;
5197 } else if (operand is num) {
5198 return -operand;
5199 }
5200 } else {}
5201 break;
5202 }
5203 return NOT_A_CONSTANT;
5204 }
5205
5206 @override
5207 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null);
5208
5209 @override
5210 Object visitSimpleIdentifier(SimpleIdentifier node) =>
5211 _getConstantValue(null);
5212
5213 @override
5214 Object visitSimpleStringLiteral(SimpleStringLiteral node) => node.value;
5215
5216 @override
5217 Object visitStringInterpolation(StringInterpolation node) {
5218 StringBuffer buffer = new StringBuffer();
5219 for (InterpolationElement element in node.elements) {
5220 Object value = element.accept(this);
5221 if (identical(value, NOT_A_CONSTANT)) {
5222 return value;
5223 }
5224 buffer.write(value);
5225 }
5226 return buffer.toString();
5227 }
5228
5229 @override
5230 Object visitSymbolLiteral(SymbolLiteral node) {
5231 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String.
5232 StringBuffer buffer = new StringBuffer();
5233 for (Token component in node.components) {
5234 if (buffer.length > 0) {
5235 buffer.writeCharCode(0x2E);
5236 }
5237 buffer.write(component.lexeme);
5238 }
5239 return buffer.toString();
5240 }
5241
5242 /**
5243 * Return the constant value of the static constant represented by the given
5244 * [element].
5245 */
5246 Object _getConstantValue(Element element) {
5247 // TODO(brianwilkerson) Implement this
5248 if (element is FieldElement) {
5249 FieldElement field = element;
5250 if (field.isStatic && field.isConst) {
5251 //field.getConstantValue();
5252 }
5253 // } else if (element instanceof VariableElement) {
5254 // VariableElement variable = (VariableElement) element;
5255 // if (variable.isStatic() && variable.isConst()) {
5256 // //variable.getConstantValue();
5257 // }
5258 }
5259 return NOT_A_CONSTANT;
5260 }
5261 }
5262
5263 /**
5264 * A constructor declaration.
5265 *
5266 * > constructorDeclaration ::=
5267 * > constructorSignature [FunctionBody]?
5268 * > | constructorName formalParameterList ':' 'this' ('.' [SimpleIdentifier]) ? arguments
5269 * >
5270 * > constructorSignature ::=
5271 * > 'external'? constructorName formalParameterList initializerList?
5272 * > | 'external'? 'factory' factoryName formalParameterList initializerList?
5273 * > | 'external'? 'const' constructorName formalParameterList initializerLis t?
5274 * >
5275 * > constructorName ::=
5276 * > [SimpleIdentifier] ('.' [SimpleIdentifier])?
5277 * >
5278 * > factoryName ::=
5279 * > [Identifier] ('.' [SimpleIdentifier])?
5280 * >
5281 * > initializerList ::=
5282 * > ':' [ConstructorInitializer] (',' [ConstructorInitializer])*
5283 */
5284 class ConstructorDeclaration extends ClassMember {
5285 /**
5286 * The token for the 'external' keyword, or `null` if the constructor is not
5287 * external.
5288 */
5289 Token externalKeyword;
5290
5291 /**
5292 * The token for the 'const' keyword, or `null` if the constructor is not a
5293 * const constructor.
5294 */
5295 Token constKeyword;
5296
5297 /**
5298 * The token for the 'factory' keyword, or `null` if the constructor is not a
5299 * factory constructor.
5300 */
5301 Token factoryKeyword;
5302
5303 /**
5304 * The type of object being created. This can be different than the type in
5305 * which the constructor is being declared if the constructor is the
5306 * implementation of a factory constructor.
5307 */
5308 Identifier _returnType;
5309
5310 /**
5311 * The token for the period before the constructor name, or `null` if the
5312 * constructor being declared is unnamed.
5313 */
5314 Token period;
5315
5316 /**
5317 * The name of the constructor, or `null` if the constructor being declared is
5318 * unnamed.
5319 */
5320 SimpleIdentifier _name;
5321
5322 /**
5323 * The parameters associated with the constructor.
5324 */
5325 FormalParameterList _parameters;
5326
5327 /**
5328 * The token for the separator (colon or equals) before the initializer list
5329 * or redirection, or `null` if there are no initializers.
5330 */
5331 Token separator;
5332
5333 /**
5334 * The initializers associated with the constructor.
5335 */
5336 NodeList<ConstructorInitializer> _initializers;
5337
5338 /**
5339 * The name of the constructor to which this constructor will be redirected,
5340 * or `null` if this is not a redirecting factory constructor.
5341 */
5342 ConstructorName _redirectedConstructor;
5343
5344 /**
5345 * The body of the constructor, or `null` if the constructor does not have a
5346 * body.
5347 */
5348 FunctionBody _body;
5349
5350 /**
5351 * The element associated with this constructor, or `null` if the AST
5352 * structure has not been resolved or if this constructor could not be
5353 * resolved.
5354 */
5355 ConstructorElement element;
5356
5357 /**
5358 * Initialize a newly created constructor declaration. The [externalKeyword]
5359 * can be `null` if the constructor is not external. Either or both of the
5360 * [comment] and [metadata] can be `null` if the constructor does not have the
5361 * corresponding attribute. The [constKeyword] can be `null` if the
5362 * constructor cannot be used to create a constant. The [factoryKeyword] can
5363 * be `null` if the constructor is not a factory. The [period] and [name] can
5364 * both be `null` if the constructor is not a named constructor. The
5365 * [separator] can be `null` if the constructor does not have any initializers
5366 * and does not redirect to a different constructor. The list of
5367 * [initializers] can be `null` if the constructor does not have any
5368 * initializers. The [redirectedConstructor] can be `null` if the constructor
5369 * does not redirect to a different constructor. The [body] can be `null` if
5370 * the constructor does not have a body.
5371 */
5372 ConstructorDeclaration(Comment comment, List<Annotation> metadata,
5373 this.externalKeyword, this.constKeyword, this.factoryKeyword,
5374 Identifier returnType, this.period, SimpleIdentifier name,
5375 FormalParameterList parameters, this.separator,
5376 List<ConstructorInitializer> initializers,
5377 ConstructorName redirectedConstructor, FunctionBody body)
5378 : super(comment, metadata) {
5379 _returnType = _becomeParentOf(returnType);
5380 _name = _becomeParentOf(name);
5381 _parameters = _becomeParentOf(parameters);
5382 _initializers = new NodeList<ConstructorInitializer>(this, initializers);
5383 _redirectedConstructor = _becomeParentOf(redirectedConstructor);
5384 _body = _becomeParentOf(body);
5385 }
5386
5387 /**
5388 * Return the body of the constructor, or `null` if the constructor does not
5389 * have a body.
5390 */
5391 FunctionBody get body => _body;
5392
5393 /**
5394 * Set the body of the constructor to the given [functionBody].
5395 */
5396 void set body(FunctionBody functionBody) {
5397 _body = _becomeParentOf(functionBody);
5398 }
5399
5400 @override
5401 Iterable get childEntities => super._childEntities
5402 ..add(externalKeyword)
5403 ..add(constKeyword)
5404 ..add(factoryKeyword)
5405 ..add(_returnType)
5406 ..add(period)
5407 ..add(_name)
5408 ..add(_parameters)
5409 ..add(separator)
5410 ..addAll(initializers)
5411 ..add(_redirectedConstructor)
5412 ..add(_body);
5413
5414 @override
5415 Token get endToken {
5416 if (_body != null) {
5417 return _body.endToken;
5418 } else if (!_initializers.isEmpty) {
5419 return _initializers.endToken;
5420 }
5421 return _parameters.endToken;
5422 }
5423
5424 @override
5425 Token get firstTokenAfterCommentAndMetadata {
5426 Token leftMost =
5427 Token.lexicallyFirst([externalKeyword, constKeyword, factoryKeyword]);
5428 if (leftMost != null) {
5429 return leftMost;
5430 }
5431 return _returnType.beginToken;
5432 }
5433
5434 /**
5435 * Return the initializers associated with the constructor.
5436 */
5437 NodeList<ConstructorInitializer> get initializers => _initializers;
5438
5439 /**
5440 * Return the name of the constructor, or `null` if the constructor being
5441 * declared is unnamed.
5442 */
5443 SimpleIdentifier get name => _name;
5444
5445 /**
5446 * Set the name of the constructor to the given [identifier].
5447 */
5448 void set name(SimpleIdentifier identifier) {
5449 _name = _becomeParentOf(identifier);
5450 }
5451
5452 /**
5453 * Return the parameters associated with the constructor.
5454 */
5455 FormalParameterList get parameters => _parameters;
5456
5457 /**
5458 * Set the parameters associated with the constructor to the given list of
5459 * [parameters].
5460 */
5461 void set parameters(FormalParameterList parameters) {
5462 _parameters = _becomeParentOf(parameters);
5463 }
5464
5465 /**
5466 * Return the name of the constructor to which this constructor will be
5467 * redirected, or `null` if this is not a redirecting factory constructor.
5468 */
5469 ConstructorName get redirectedConstructor => _redirectedConstructor;
5470
5471 /**
5472 * Set the name of the constructor to which this constructor will be
5473 * redirected to the given [redirectedConstructor] name.
5474 */
5475 void set redirectedConstructor(ConstructorName redirectedConstructor) {
5476 _redirectedConstructor = _becomeParentOf(redirectedConstructor);
5477 }
5478
5479 /**
5480 * Return the type of object being created. This can be different than the
5481 * type in which the constructor is being declared if the constructor is the
5482 * implementation of a factory constructor.
5483 */
5484 Identifier get returnType => _returnType;
5485
5486 /**
5487 * Set the type of object being created to the given [typeName].
5488 */
5489 void set returnType(Identifier typeName) {
5490 _returnType = _becomeParentOf(typeName);
5491 }
5492
5493 @override
5494 accept(AstVisitor visitor) => visitor.visitConstructorDeclaration(this);
5495
5496 @override
5497 void visitChildren(AstVisitor visitor) {
5498 super.visitChildren(visitor);
5499 _safelyVisitChild(_returnType, visitor);
5500 _safelyVisitChild(_name, visitor);
5501 _safelyVisitChild(_parameters, visitor);
5502 _initializers.accept(visitor);
5503 _safelyVisitChild(_redirectedConstructor, visitor);
5504 _safelyVisitChild(_body, visitor);
5505 }
5506 }
5507
5508 /**
5509 * The initialization of a field within a constructor's initialization list.
5510 *
5511 * > fieldInitializer ::=
5512 * > ('this' '.')? [SimpleIdentifier] '=' [Expression]
5513 */
5514 class ConstructorFieldInitializer extends ConstructorInitializer {
5515 /**
5516 * The token for the 'this' keyword, or `null` if there is no 'this' keyword.
5517 */
5518 Token thisKeyword;
5519
5520 /**
5521 * The token for the period after the 'this' keyword, or `null` if there is no
5522 * 'this' keyword.
5523 */
5524 Token period;
5525
5526 /**
5527 * The name of the field being initialized.
5528 */
5529 SimpleIdentifier _fieldName;
5530
5531 /**
5532 * The token for the equal sign between the field name and the expression.
5533 */
5534 Token equals;
5535
5536 /**
5537 * The expression computing the value to which the field will be initialized.
5538 */
5539 Expression _expression;
5540
5541 /**
5542 * Initialize a newly created field initializer to initialize the field with
5543 * the given name to the value of the given expression. The [thisKeyword] and
5544 * [period] can be `null` if the 'this' keyword was not specified.
5545 */
5546 ConstructorFieldInitializer(this.thisKeyword, this.period,
5547 SimpleIdentifier fieldName, this.equals, Expression expression) {
5548 _fieldName = _becomeParentOf(fieldName);
5549 _expression = _becomeParentOf(expression);
5550 }
5551
5552 @override
5553 Token get beginToken {
5554 if (thisKeyword != null) {
5555 return thisKeyword;
5556 }
5557 return _fieldName.beginToken;
5558 }
5559
5560 @override
5561 Iterable get childEntities => new ChildEntities()
5562 ..add(thisKeyword)
5563 ..add(period)
5564 ..add(_fieldName)
5565 ..add(equals)
5566 ..add(_expression);
5567
5568 @override
5569 Token get endToken => _expression.endToken;
5570
5571 /**
5572 * Return the expression computing the value to which the field will be
5573 * initialized.
5574 */
5575 Expression get expression => _expression;
5576
5577 /**
5578 * Set the expression computing the value to which the field will be
5579 * initialized to the given [expression].
5580 */
5581 void set expression(Expression expression) {
5582 _expression = _becomeParentOf(expression);
5583 }
5584
5585 /**
5586 * Return the name of the field being initialized.
5587 */
5588 SimpleIdentifier get fieldName => _fieldName;
5589
5590 /**
5591 * Set the name of the field being initialized to the given [identifier].
5592 */
5593 void set fieldName(SimpleIdentifier identifier) {
5594 _fieldName = _becomeParentOf(identifier);
5595 }
5596
5597 /**
5598 * Return the token for the 'this' keyword, or `null` if there is no 'this'
5599 * keyword.
5600 */
5601 @deprecated // Use "this.thisKeyword"
5602 Token get keyword => thisKeyword;
5603
5604 /**
5605 * Set the token for the 'this' keyword to the given [token].
5606 */
5607 @deprecated // Use "this.thisKeyword"
5608 set keyword(Token token) {
5609 thisKeyword = token;
5610 }
5611
5612 @override
5613 accept(AstVisitor visitor) => visitor.visitConstructorFieldInitializer(this);
5614
5615 @override
5616 void visitChildren(AstVisitor visitor) {
5617 _safelyVisitChild(_fieldName, visitor);
5618 _safelyVisitChild(_expression, visitor);
5619 }
5620 }
5621
5622 /**
5623 * A node that can occur in the initializer list of a constructor declaration.
5624 *
5625 * > constructorInitializer ::=
5626 * > [SuperConstructorInvocation]
5627 * > | [ConstructorFieldInitializer]
5628 */
5629 abstract class ConstructorInitializer extends AstNode {}
5630
5631 /**
5632 * The name of the constructor.
5633 *
5634 * > constructorName ::=
5635 * > type ('.' identifier)?
5636 */
5637 class ConstructorName extends AstNode {
5638 /**
5639 * The name of the type defining the constructor.
5640 */
5641 TypeName _type;
5642
5643 /**
5644 * The token for the period before the constructor name, or `null` if the
5645 * specified constructor is the unnamed constructor.
5646 */
5647 Token period;
5648
5649 /**
5650 * The name of the constructor, or `null` if the specified constructor is the
5651 * unnamed constructor.
5652 */
5653 SimpleIdentifier _name;
5654
5655 /**
5656 * The element associated with this constructor name based on static type
5657 * information, or `null` if the AST structure has not been resolved or if
5658 * this constructor name could not be resolved.
5659 */
5660 ConstructorElement staticElement;
5661
5662 /**
5663 * Initialize a newly created constructor name. The [period] and [name] can be
5664 * `null` if the constructor being named is the unnamed constructor.
5665 */
5666 ConstructorName(TypeName type, this.period, SimpleIdentifier name) {
5667 _type = _becomeParentOf(type);
5668 _name = _becomeParentOf(name);
5669 }
5670
5671 @override
5672 Token get beginToken => _type.beginToken;
5673
5674 @override
5675 Iterable get childEntities =>
5676 new ChildEntities()..add(_type)..add(period)..add(_name);
5677
5678 @override
5679 Token get endToken {
5680 if (_name != null) {
5681 return _name.endToken;
5682 }
5683 return _type.endToken;
5684 }
5685
5686 /**
5687 * Return the name of the constructor, or `null` if the specified constructor
5688 * is the unnamed constructor.
5689 */
5690 SimpleIdentifier get name => _name;
5691
5692 /**
5693 * Set the name of the constructor to the given [name].
5694 */
5695 void set name(SimpleIdentifier name) {
5696 _name = _becomeParentOf(name);
5697 }
5698
5699 /**
5700 * Return the name of the type defining the constructor.
5701 */
5702 TypeName get type => _type;
5703
5704 /**
5705 * Set the name of the type defining the constructor to the given [type] name.
5706 */
5707 void set type(TypeName type) {
5708 _type = _becomeParentOf(type);
5709 }
5710
5711 @override
5712 accept(AstVisitor visitor) => visitor.visitConstructorName(this);
5713
5714 @override
5715 void visitChildren(AstVisitor visitor) {
5716 _safelyVisitChild(_type, visitor);
5717 _safelyVisitChild(_name, visitor);
5718 }
5719 }
5720
5721 /**
5722 * A continue statement.
5723 *
5724 * > continueStatement ::=
5725 * > 'continue' [SimpleIdentifier]? ';'
5726 */
5727 class ContinueStatement extends Statement {
5728 /**
5729 * The token representing the 'continue' keyword.
5730 */
5731 Token continueKeyword;
5732
5733 /**
5734 * The label associated with the statement, or `null` if there is no label.
5735 */
5736 SimpleIdentifier _label;
5737
5738 /**
5739 * The semicolon terminating the statement.
5740 */
5741 Token semicolon;
5742
5743 /**
5744 * The AstNode which this continue statement is continuing to. This will be
5745 * either a Statement (in the case of continuing a loop) or a SwitchMember
5746 * (in the case of continuing from one switch case to another). Null if the
5747 * AST has not yet been resolved or if the target could not be resolved.
5748 * Note that if the source code has errors, the target may be invalid (e.g.
5749 * the target may be in an enclosing function).
5750 */
5751 AstNode target;
5752
5753 /**
5754 * Initialize a newly created continue statement. The [label] can be `null` if
5755 * there is no label associated with the statement.
5756 */
5757 ContinueStatement(
5758 this.continueKeyword, SimpleIdentifier label, this.semicolon) {
5759 _label = _becomeParentOf(label);
5760 }
5761
5762 @override
5763 Token get beginToken => continueKeyword;
5764
5765 @override
5766 Iterable get childEntities =>
5767 new ChildEntities()..add(continueKeyword)..add(_label)..add(semicolon);
5768
5769 @override
5770 Token get endToken => semicolon;
5771
5772 /**
5773 * Return the token for the 'continue' keyword, or `null` if there is no
5774 * 'continue' keyword.
5775 */
5776 @deprecated // Use "this.continueKeyword"
5777 Token get keyword => continueKeyword;
5778
5779 /**
5780 * Set the token for the 'continue' keyword to the given [token].
5781 */
5782 @deprecated // Use "this.continueKeyword"
5783 set keyword(Token token) {
5784 continueKeyword = token;
5785 }
5786
5787 /**
5788 * Return the label associated with the statement, or `null` if there is no
5789 * label.
5790 */
5791 SimpleIdentifier get label => _label;
5792
5793 /**
5794 * Set the label associated with the statement to the given [identifier].
5795 */
5796 void set label(SimpleIdentifier identifier) {
5797 _label = _becomeParentOf(identifier);
5798 }
5799
5800 @override
5801 accept(AstVisitor visitor) => visitor.visitContinueStatement(this);
5802
5803 @override
5804 void visitChildren(AstVisitor visitor) {
5805 _safelyVisitChild(_label, visitor);
5806 }
5807 }
5808
5809 /**
5810 * A node that represents the declaration of one or more names. Each declared
5811 * name is visible within a name scope.
5812 */
5813 abstract class Declaration extends AnnotatedNode {
5814 /**
5815 * Initialize a newly created declaration. Either or both of the [comment] and
5816 * [metadata] can be `null` if the declaration does not have the corresponding
5817 * attribute.
5818 */
5819 Declaration(Comment comment, List<Annotation> metadata)
5820 : super(comment, metadata);
5821
5822 /**
5823 * Return the element associated with this declaration, or `null` if either
5824 * this node corresponds to a list of declarations or if the AST structure has
5825 * not been resolved.
5826 */
5827 Element get element;
5828 }
5829
5830 /**
5831 * The declaration of a single identifier.
5832 *
5833 * > declaredIdentifier ::=
5834 * > [Annotation] finalConstVarOrType [SimpleIdentifier]
5835 */
5836 class DeclaredIdentifier extends Declaration {
5837 /**
5838 * The token representing either the 'final', 'const' or 'var' keyword, or
5839 * `null` if no keyword was used.
5840 */
5841 Token keyword;
5842
5843 /**
5844 * The name of the declared type of the parameter, or `null` if the parameter
5845 * does not have a declared type.
5846 */
5847 TypeName _type;
5848
5849 /**
5850 * The name of the variable being declared.
5851 */
5852 SimpleIdentifier _identifier;
5853
5854 /**
5855 * Initialize a newly created formal parameter. Either or both of the
5856 * [comment] and [metadata] can be `null` if the declaration does not have the
5857 * corresponding attribute. The [keyword] can be `null` if a type name is
5858 * given. The [type] must be `null` if the keyword is 'var'.
5859 */
5860 DeclaredIdentifier(Comment comment, List<Annotation> metadata, this.keyword,
5861 TypeName type, SimpleIdentifier identifier)
5862 : super(comment, metadata) {
5863 _type = _becomeParentOf(type);
5864 _identifier = _becomeParentOf(identifier);
5865 }
5866
5867 @override
5868 Iterable get childEntities =>
5869 super._childEntities..add(keyword)..add(_type)..add(_identifier);
5870
5871 @override
5872 LocalVariableElement get element {
5873 if (_identifier == null) {
5874 return null;
5875 }
5876 return _identifier.staticElement as LocalVariableElement;
5877 }
5878
5879 @override
5880 Token get endToken => _identifier.endToken;
5881
5882 @override
5883 Token get firstTokenAfterCommentAndMetadata {
5884 if (keyword != null) {
5885 return keyword;
5886 } else if (_type != null) {
5887 return _type.beginToken;
5888 }
5889 return _identifier.beginToken;
5890 }
5891
5892 /**
5893 * Return the name of the variable being declared.
5894 */
5895 SimpleIdentifier get identifier => _identifier;
5896
5897 /**
5898 * Set the name of the variable being declared to the given [identifier].
5899 */
5900 void set identifier(SimpleIdentifier identifier) {
5901 _identifier = _becomeParentOf(identifier);
5902 }
5903
5904 /**
5905 * Return `true` if this variable was declared with the 'const' modifier.
5906 */
5907 bool get isConst => (keyword is KeywordToken) &&
5908 (keyword as KeywordToken).keyword == Keyword.CONST;
5909
5910 /**
5911 * Return `true` if this variable was declared with the 'final' modifier.
5912 * Variables that are declared with the 'const' modifier will return `false`
5913 * even though they are implicitly final.
5914 */
5915 bool get isFinal => (keyword is KeywordToken) &&
5916 (keyword as KeywordToken).keyword == Keyword.FINAL;
5917
5918 /**
5919 * Return the name of the declared type of the parameter, or `null` if the
5920 * parameter does not have a declared type.
5921 */
5922 TypeName get type => _type;
5923
5924 /**
5925 * Set the name of the declared type of the parameter to the given [typeName].
5926 */
5927 void set type(TypeName typeName) {
5928 _type = _becomeParentOf(typeName);
5929 }
5930
5931 @override
5932 accept(AstVisitor visitor) => visitor.visitDeclaredIdentifier(this);
5933
5934 @override
5935 void visitChildren(AstVisitor visitor) {
5936 super.visitChildren(visitor);
5937 _safelyVisitChild(_type, visitor);
5938 _safelyVisitChild(_identifier, visitor);
5939 }
5940 }
5941
5942 /**
5943 * A formal parameter with a default value. There are two kinds of parameters
5944 * that are both represented by this class: named formal parameters and
5945 * positional formal parameters.
5946 *
5947 * > defaultFormalParameter ::=
5948 * > [NormalFormalParameter] ('=' [Expression])?
5949 * >
5950 * > defaultNamedParameter ::=
5951 * > [NormalFormalParameter] (':' [Expression])?
5952 */
5953 class DefaultFormalParameter extends FormalParameter {
5954 /**
5955 * The formal parameter with which the default value is associated.
5956 */
5957 NormalFormalParameter _parameter;
5958
5959 /**
5960 * The kind of this parameter.
5961 */
5962 ParameterKind kind;
5963
5964 /**
5965 * The token separating the parameter from the default value, or `null` if
5966 * there is no default value.
5967 */
5968 Token separator;
5969
5970 /**
5971 * The expression computing the default value for the parameter, or `null` if
5972 * there is no default value.
5973 */
5974 Expression _defaultValue;
5975
5976 /**
5977 * Initialize a newly created default formal parameter. The [separator] and
5978 * [defaultValue] can be `null` if there is no default value.
5979 */
5980 DefaultFormalParameter(NormalFormalParameter parameter, this.kind,
5981 this.separator, Expression defaultValue) {
5982 _parameter = _becomeParentOf(parameter);
5983 _defaultValue = _becomeParentOf(defaultValue);
5984 }
5985
5986 @override
5987 Token get beginToken => _parameter.beginToken;
5988
5989 @override
5990 Iterable get childEntities =>
5991 new ChildEntities()..add(_parameter)..add(separator)..add(_defaultValue);
5992
5993 /**
5994 * Return the expression computing the default value for the parameter, or
5995 * `null` if there is no default value.
5996 */
5997 Expression get defaultValue => _defaultValue;
5998
5999 /**
6000 * Set the expression computing the default value for the parameter to the
6001 * given [expression].
6002 */
6003 void set defaultValue(Expression expression) {
6004 _defaultValue = _becomeParentOf(expression);
6005 }
6006
6007 @override
6008 Token get endToken {
6009 if (_defaultValue != null) {
6010 return _defaultValue.endToken;
6011 }
6012 return _parameter.endToken;
6013 }
6014
6015 @override
6016 SimpleIdentifier get identifier => _parameter.identifier;
6017
6018 @override
6019 bool get isConst => _parameter != null && _parameter.isConst;
6020
6021 @override
6022 bool get isFinal => _parameter != null && _parameter.isFinal;
6023
6024 @override
6025 NodeList<Annotation> get metadata => _parameter.metadata;
6026
6027 /**
6028 * Return the formal parameter with which the default value is associated.
6029 */
6030 NormalFormalParameter get parameter => _parameter;
6031
6032 /**
6033 * Set the formal parameter with which the default value is associated to the
6034 * given [formalParameter].
6035 */
6036 void set parameter(NormalFormalParameter formalParameter) {
6037 _parameter = _becomeParentOf(formalParameter);
6038 }
6039
6040 @override
6041 accept(AstVisitor visitor) => visitor.visitDefaultFormalParameter(this);
6042
6043 @override
6044 void visitChildren(AstVisitor visitor) {
6045 _safelyVisitChild(_parameter, visitor);
6046 _safelyVisitChild(_defaultValue, visitor);
6047 }
6048 }
6049
6050 /**
6051 * A recursive AST visitor that is used to run over [Expression]s to determine
6052 * whether the expression is composed by at least one deferred
6053 * [PrefixedIdentifier].
6054 *
6055 * See [PrefixedIdentifier.isDeferred].
6056 */
6057 class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<Object> {
6058 /**
6059 * A flag indicating whether an identifier from a deferred library has been
6060 * found.
6061 */
6062 bool _result = false;
6063
6064 /**
6065 * Return `true` if the visitor found a [PrefixedIdentifier] that returned
6066 * `true` to the [PrefixedIdentifier.isDeferred] query.
6067 */
6068 bool get result => _result;
6069
6070 @override
6071 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
6072 if (!_result) {
6073 if (node.isDeferred) {
6074 _result = true;
6075 }
6076 }
6077 return null;
6078 }
6079 }
6080
6081 /**
6082 * A node that represents a directive.
6083 *
6084 * > directive ::=
6085 * > [ExportDirective]
6086 * > | [ImportDirective]
6087 * > | [LibraryDirective]
6088 * > | [PartDirective]
6089 * > | [PartOfDirective]
6090 */
6091 abstract class Directive extends AnnotatedNode {
6092 /**
6093 * The element associated with this directive, or `null` if the AST structure
6094 * has not been resolved or if this directive could not be resolved.
6095 */
6096 Element element;
6097
6098 /**
6099 * Initialize a newly create directive. Either or both of the [comment] and
6100 * [metadata] can be `null` if the directive does not have the corresponding
6101 * attribute.
6102 */
6103 Directive(Comment comment, List<Annotation> metadata)
6104 : super(comment, metadata);
6105
6106 /**
6107 * Return the token representing the keyword that introduces this directive
6108 * ('import', 'export', 'library' or 'part').
6109 */
6110 Token get keyword;
6111 }
6112
6113 /**
6114 * A do statement.
6115 *
6116 * > doStatement ::=
6117 * > 'do' [Statement] 'while' '(' [Expression] ')' ';'
6118 */
6119 class DoStatement extends Statement {
6120 /**
6121 * The token representing the 'do' keyword.
6122 */
6123 Token doKeyword;
6124
6125 /**
6126 * The body of the loop.
6127 */
6128 Statement _body;
6129
6130 /**
6131 * The token representing the 'while' keyword.
6132 */
6133 Token whileKeyword;
6134
6135 /**
6136 * The left parenthesis.
6137 */
6138 Token leftParenthesis;
6139
6140 /**
6141 * The condition that determines when the loop will terminate.
6142 */
6143 Expression _condition;
6144
6145 /**
6146 * The right parenthesis.
6147 */
6148 Token rightParenthesis;
6149
6150 /**
6151 * The semicolon terminating the statement.
6152 */
6153 Token semicolon;
6154
6155 /**
6156 * Initialize a newly created do loop.
6157 */
6158 DoStatement(this.doKeyword, Statement body, this.whileKeyword,
6159 this.leftParenthesis, Expression condition, this.rightParenthesis,
6160 this.semicolon) {
6161 _body = _becomeParentOf(body);
6162 _condition = _becomeParentOf(condition);
6163 }
6164
6165 @override
6166 Token get beginToken => doKeyword;
6167
6168 /**
6169 * Return the body of the loop.
6170 */
6171 Statement get body => _body;
6172
6173 /**
6174 * Set the body of the loop to the given [statement].
6175 */
6176 void set body(Statement statement) {
6177 _body = _becomeParentOf(statement);
6178 }
6179
6180 @override
6181 Iterable get childEntities => new ChildEntities()
6182 ..add(doKeyword)
6183 ..add(_body)
6184 ..add(whileKeyword)
6185 ..add(leftParenthesis)
6186 ..add(_condition)
6187 ..add(rightParenthesis)
6188 ..add(semicolon);
6189
6190 /**
6191 * Return the condition that determines when the loop will terminate.
6192 */
6193 Expression get condition => _condition;
6194
6195 /**
6196 * Set the condition that determines when the loop will terminate to the given
6197 * [expression].
6198 */
6199 void set condition(Expression expression) {
6200 _condition = _becomeParentOf(expression);
6201 }
6202
6203 @override
6204 Token get endToken => semicolon;
6205
6206 @override
6207 accept(AstVisitor visitor) => visitor.visitDoStatement(this);
6208
6209 @override
6210 void visitChildren(AstVisitor visitor) {
6211 _safelyVisitChild(_body, visitor);
6212 _safelyVisitChild(_condition, visitor);
6213 }
6214 }
6215
6216 /**
6217 * A floating point literal expression.
6218 *
6219 * > doubleLiteral ::=
6220 * > decimalDigit+ ('.' decimalDigit*)? exponent?
6221 * > | '.' decimalDigit+ exponent?
6222 * >
6223 * > exponent ::=
6224 * > ('e' | 'E') ('+' | '-')? decimalDigit+
6225 */
6226 class DoubleLiteral extends Literal {
6227 /**
6228 * The token representing the literal.
6229 */
6230 Token literal;
6231
6232 /**
6233 * The value of the literal.
6234 */
6235 double value;
6236
6237 /**
6238 * Initialize a newly created floating point literal.
6239 */
6240 DoubleLiteral(this.literal, this.value);
6241
6242 @override
6243 Token get beginToken => literal;
6244
6245 @override
6246 Iterable get childEntities => new ChildEntities()..add(literal);
6247
6248 @override
6249 Token get endToken => literal;
6250
6251 @override
6252 accept(AstVisitor visitor) => visitor.visitDoubleLiteral(this);
6253
6254 @override
6255 void visitChildren(AstVisitor visitor) {
6256 // There are no children to visit.
6257 }
6258 }
6259
6260 /**
6261 * An object used to locate the [Element] associated with a given [AstNode].
6262 */
6263 class ElementLocator {
6264 /**
6265 * Return the element associated with the given [node], or `null` if there is
6266 * no element associated with the node.
6267 */
6268 static Element locate(AstNode node) {
6269 if (node == null) {
6270 return null;
6271 }
6272 ElementLocator_ElementMapper mapper = new ElementLocator_ElementMapper();
6273 return node.accept(mapper);
6274 }
6275
6276 /**
6277 * Return the element associated with the given [node], or `null` if there is
6278 * no element associated with the node.
6279 */
6280 static Element locateWithOffset(AstNode node, int offset) {
6281 // TODO(brianwilkerson) 'offset' is not used. Figure out what's going on:
6282 // whether there's a bug or whether this method is unnecessary.
6283 if (node == null) {
6284 return null;
6285 }
6286 // try to get Element from node
6287 Element nodeElement = locate(node);
6288 if (nodeElement != null) {
6289 return nodeElement;
6290 }
6291 // no Element
6292 return null;
6293 }
6294 }
6295
6296 /**
6297 * Visitor that maps nodes to elements.
6298 */
6299 class ElementLocator_ElementMapper extends GeneralizingAstVisitor<Element> {
6300 @override
6301 Element visitAnnotation(Annotation node) => node.element;
6302
6303 @override
6304 Element visitAssignmentExpression(AssignmentExpression node) =>
6305 node.bestElement;
6306
6307 @override
6308 Element visitBinaryExpression(BinaryExpression node) => node.bestElement;
6309
6310 @override
6311 Element visitClassDeclaration(ClassDeclaration node) => node.element;
6312
6313 @override
6314 Element visitCompilationUnit(CompilationUnit node) => node.element;
6315
6316 @override
6317 Element visitConstructorDeclaration(ConstructorDeclaration node) =>
6318 node.element;
6319
6320 @override
6321 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element;
6322
6323 @override
6324 Element visitIdentifier(Identifier node) {
6325 AstNode parent = node.parent;
6326 // Type name in Annotation
6327 if (parent is Annotation) {
6328 Annotation annotation = parent;
6329 if (identical(annotation.name, node) &&
6330 annotation.constructorName == null) {
6331 return annotation.element;
6332 }
6333 }
6334 // Extra work to map Constructor Declarations to their associated
6335 // Constructor Elements
6336 if (parent is ConstructorDeclaration) {
6337 ConstructorDeclaration decl = parent;
6338 Identifier returnType = decl.returnType;
6339 if (identical(returnType, node)) {
6340 SimpleIdentifier name = decl.name;
6341 if (name != null) {
6342 return name.bestElement;
6343 }
6344 Element element = node.bestElement;
6345 if (element is ClassElement) {
6346 return element.unnamedConstructor;
6347 }
6348 }
6349 }
6350 if (parent is LibraryIdentifier) {
6351 AstNode grandParent = parent.parent;
6352 if (grandParent is PartOfDirective) {
6353 Element element = grandParent.element;
6354 if (element is LibraryElement) {
6355 return element.definingCompilationUnit;
6356 }
6357 }
6358 }
6359 return node.bestElement;
6360 }
6361
6362 @override
6363 Element visitImportDirective(ImportDirective node) => node.element;
6364
6365 @override
6366 Element visitIndexExpression(IndexExpression node) => node.bestElement;
6367
6368 @override
6369 Element visitInstanceCreationExpression(InstanceCreationExpression node) =>
6370 node.staticElement;
6371
6372 @override
6373 Element visitLibraryDirective(LibraryDirective node) => node.element;
6374
6375 @override
6376 Element visitMethodDeclaration(MethodDeclaration node) => node.element;
6377
6378 @override
6379 Element visitMethodInvocation(MethodInvocation node) =>
6380 node.methodName.bestElement;
6381
6382 @override
6383 Element visitPostfixExpression(PostfixExpression node) => node.bestElement;
6384
6385 @override
6386 Element visitPrefixedIdentifier(PrefixedIdentifier node) => node.bestElement;
6387
6388 @override
6389 Element visitPrefixExpression(PrefixExpression node) => node.bestElement;
6390
6391 @override
6392 Element visitStringLiteral(StringLiteral node) {
6393 AstNode parent = node.parent;
6394 if (parent is UriBasedDirective) {
6395 return parent.uriElement;
6396 }
6397 return null;
6398 }
6399
6400 @override
6401 Element visitVariableDeclaration(VariableDeclaration node) => node.element;
6402 }
6403
6404 /**
6405 * An empty function body, which can only appear in constructors or abstract
6406 * methods.
6407 *
6408 * > emptyFunctionBody ::=
6409 * > ';'
6410 */
6411 class EmptyFunctionBody extends FunctionBody {
6412 /**
6413 * The token representing the semicolon that marks the end of the function
6414 * body.
6415 */
6416 Token semicolon;
6417
6418 /**
6419 * Initialize a newly created function body.
6420 */
6421 EmptyFunctionBody(this.semicolon);
6422
6423 @override
6424 Token get beginToken => semicolon;
6425
6426 @override
6427 Iterable get childEntities => new ChildEntities()..add(semicolon);
6428
6429 @override
6430 Token get endToken => semicolon;
6431
6432 @override
6433 accept(AstVisitor visitor) => visitor.visitEmptyFunctionBody(this);
6434
6435 @override
6436 void visitChildren(AstVisitor visitor) {
6437 // Empty function bodies have no children.
6438 }
6439 }
6440
6441 /**
6442 * An empty statement.
6443 *
6444 * > emptyStatement ::=
6445 * > ';'
6446 */
6447 class EmptyStatement extends Statement {
6448 /**
6449 * The semicolon terminating the statement.
6450 */
6451 Token semicolon;
6452
6453 /**
6454 * Initialize a newly created empty statement.
6455 */
6456 EmptyStatement(this.semicolon);
6457
6458 @override
6459 Token get beginToken => semicolon;
6460
6461 @override
6462 Iterable get childEntities => new ChildEntities()..add(semicolon);
6463
6464 @override
6465 Token get endToken => semicolon;
6466
6467 @override
6468 accept(AstVisitor visitor) => visitor.visitEmptyStatement(this);
6469
6470 @override
6471 void visitChildren(AstVisitor visitor) {
6472 // There are no children to visit.
6473 }
6474 }
6475
6476 /**
6477 * The declaration of an enum constant.
6478 */
6479 class EnumConstantDeclaration extends Declaration {
6480 /**
6481 * The name of the constant.
6482 */
6483 SimpleIdentifier _name;
6484
6485 /**
6486 * Initialize a newly created enum constant declaration. Either or both of the
6487 * [comment] and [metadata] can be `null` if the constant does not have the
6488 * corresponding attribute. (Technically, enum constants cannot have metadata,
6489 * but we allow it for consistency.)
6490 */
6491 EnumConstantDeclaration(
6492 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
6493 : super(comment, metadata) {
6494 _name = _becomeParentOf(name);
6495 }
6496
6497 @override
6498 Iterable get childEntities => super._childEntities..add(_name);
6499
6500 @override
6501 FieldElement get element =>
6502 _name == null ? null : (_name.staticElement as FieldElement);
6503
6504 @override
6505 Token get endToken => _name.endToken;
6506
6507 @override
6508 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
6509
6510 /**
6511 * Return the name of the constant.
6512 */
6513 SimpleIdentifier get name => _name;
6514
6515 /**
6516 * Set the name of the constant to the given [name].
6517 */
6518 void set name(SimpleIdentifier name) {
6519 _name = _becomeParentOf(name);
6520 }
6521
6522 @override
6523 accept(AstVisitor visitor) => visitor.visitEnumConstantDeclaration(this);
6524
6525 @override
6526 void visitChildren(AstVisitor visitor) {
6527 super.visitChildren(visitor);
6528 _safelyVisitChild(_name, visitor);
6529 }
6530 }
6531
6532 /**
6533 * The declaration of an enumeration.
6534 *
6535 * > enumType ::=
6536 * > metadata 'enum' [SimpleIdentifier] '{' [SimpleIdentifier] (',' [SimpleI dentifier])* (',')? '}'
6537 */
6538 class EnumDeclaration extends NamedCompilationUnitMember {
6539 /**
6540 * The 'enum' keyword.
6541 */
6542 Token enumKeyword;
6543
6544 /**
6545 * The left curly bracket.
6546 */
6547 Token leftBracket;
6548
6549 /**
6550 * The enumeration constants being declared.
6551 */
6552 NodeList<EnumConstantDeclaration> _constants;
6553
6554 /**
6555 * The right curly bracket.
6556 */
6557 Token rightBracket;
6558
6559 /**
6560 * Initialize a newly created enumeration declaration. Either or both of the
6561 * [comment] and [metadata] can be `null` if the declaration does not have the
6562 * corresponding attribute. The list of [constants] must contain at least one
6563 * value.
6564 */
6565 EnumDeclaration(Comment comment, List<Annotation> metadata, this.enumKeyword,
6566 SimpleIdentifier name, this.leftBracket,
6567 List<EnumConstantDeclaration> constants, this.rightBracket)
6568 : super(comment, metadata, name) {
6569 _constants = new NodeList<EnumConstantDeclaration>(this, constants);
6570 }
6571
6572 @override
6573 // TODO(brianwilkerson) Add commas?
6574 Iterable get childEntities => super._childEntities
6575 ..add(enumKeyword)
6576 ..add(_name)
6577 ..add(leftBracket)
6578 ..addAll(_constants)
6579 ..add(rightBracket);
6580
6581 /**
6582 * Return the enumeration constants being declared.
6583 */
6584 NodeList<EnumConstantDeclaration> get constants => _constants;
6585
6586 @override
6587 ClassElement get element =>
6588 _name != null ? (_name.staticElement as ClassElement) : null;
6589
6590 @override
6591 Token get endToken => rightBracket;
6592
6593 @override
6594 Token get firstTokenAfterCommentAndMetadata => enumKeyword;
6595
6596 /**
6597 * Return the token for the 'enum' keyword, or `null` if there is no
6598 * 'enum' keyword.
6599 */
6600 @deprecated // Use "this.enumKeyword"
6601 Token get keyword => enumKeyword;
6602
6603 /**
6604 * Set the token for the 'enum' keyword to the given [token].
6605 */
6606 @deprecated // Use "this.enumKeyword"
6607 set keyword(Token token) {
6608 enumKeyword = token;
6609 }
6610
6611 @override
6612 accept(AstVisitor visitor) => visitor.visitEnumDeclaration(this);
6613
6614 @override
6615 void visitChildren(AstVisitor visitor) {
6616 super.visitChildren(visitor);
6617 _safelyVisitChild(_name, visitor);
6618 _constants.accept(visitor);
6619 }
6620 }
6621
6622 /**
6623 * Ephemeral identifiers are created as needed to mimic the presence of an empty
6624 * identifier.
6625 */
6626 class EphemeralIdentifier extends SimpleIdentifier {
6627 EphemeralIdentifier(AstNode parent, int location)
6628 : super(new StringToken(TokenType.IDENTIFIER, "", location)) {
6629 parent._becomeParentOf(this);
6630 }
6631 }
6632
6633 /**
6634 * An export directive.
6635 *
6636 * > exportDirective ::=
6637 * > [Annotation] 'export' [StringLiteral] [Combinator]* ';'
6638 */
6639 class ExportDirective extends NamespaceDirective {
6640 /**
6641 * Initialize a newly created export directive. Either or both of the
6642 * [comment] and [metadata] can be `null` if the directive does not have the
6643 * corresponding attribute. The list of [combinators] can be `null` if there
6644 * are no combinators.
6645 */
6646 ExportDirective(Comment comment, List<Annotation> metadata, Token keyword,
6647 StringLiteral libraryUri, List<Combinator> combinators, Token semicolon)
6648 : super(comment, metadata, keyword, libraryUri, combinators, semicolon);
6649
6650 @override
6651 Iterable get childEntities => super._childEntities
6652 ..add(_uri)
6653 ..addAll(combinators)
6654 ..add(semicolon);
6655
6656 @override
6657 ExportElement get element => super.element as ExportElement;
6658
6659 @override
6660 LibraryElement get uriElement {
6661 if (element != null) {
6662 return element.exportedLibrary;
6663 }
6664 return null;
6665 }
6666
6667 @override
6668 accept(AstVisitor visitor) => visitor.visitExportDirective(this);
6669
6670 @override
6671 void visitChildren(AstVisitor visitor) {
6672 super.visitChildren(visitor);
6673 combinators.accept(visitor);
6674 }
6675 }
6676
6677 /**
6678 * A node that represents an expression.
6679 *
6680 * > expression ::=
6681 * > [AssignmentExpression]
6682 * > | [ConditionalExpression] cascadeSection*
6683 * > | [ThrowExpression]
6684 */
6685 abstract class Expression extends AstNode {
6686 /**
6687 * An empty list of expressions.
6688 */
6689 @deprecated // Use "Expression.EMPTY_LIST"
6690 static const List<Expression> EMPTY_ARRAY = EMPTY_LIST;
6691
6692 /**
6693 * An empty list of expressions.
6694 */
6695 static const List<Expression> EMPTY_LIST = const <Expression>[];
6696
6697 /**
6698 * The static type of this expression, or `null` if the AST structure has not
6699 * been resolved.
6700 */
6701 DartType staticType;
6702
6703 /**
6704 * The propagated type of this expression, or `null` if type propagation has
6705 * not been performed on the AST structure.
6706 */
6707 DartType propagatedType;
6708
6709 /**
6710 * Return the best parameter element information available for this
6711 * expression. If type propagation was able to find a better parameter element
6712 * than static analysis, that type will be returned. Otherwise, the result of
6713 * static analysis will be returned.
6714 */
6715 ParameterElement get bestParameterElement {
6716 ParameterElement propagatedElement = propagatedParameterElement;
6717 if (propagatedElement != null) {
6718 return propagatedElement;
6719 }
6720 return staticParameterElement;
6721 }
6722
6723 /**
6724 * Return the best type information available for this expression. If type
6725 * propagation was able to find a better type than static analysis, that type
6726 * will be returned. Otherwise, the result of static analysis will be
6727 * returned. If no type analysis has been performed, then the type 'dynamic'
6728 * will be returned.
6729 */
6730 DartType get bestType {
6731 if (propagatedType != null) {
6732 return propagatedType;
6733 } else if (staticType != null) {
6734 return staticType;
6735 }
6736 return DynamicTypeImpl.instance;
6737 }
6738
6739 /**
6740 * Return `true` if this expression is syntactically valid for the LHS of an
6741 * [AssignmentExpression].
6742 */
6743 bool get isAssignable => false;
6744
6745 /**
6746 * Return the precedence of this expression. The precedence is a positive
6747 * integer value that defines how the source code is parsed into an AST. For
6748 * example `a * b + c` is parsed as `(a * b) + c` because the precedence of
6749 * `*` is greater than the precedence of `+`.
6750 *
6751 * Clients should not assume that returned values will stay the same, they
6752 * might change as result of specification change. Only relative order should
6753 * be used.
6754 */
6755 int get precedence;
6756
6757 /**
6758 * If this expression is an argument to an invocation, and the AST structure
6759 * has been resolved, and the function being invoked is known based on
6760 * propagated type information, and this expression corresponds to one of the
6761 * parameters of the function being invoked, then return the parameter element
6762 * representing the parameter to which the value of this expression will be
6763 * bound. Otherwise, return `null`.
6764 */
6765 ParameterElement get propagatedParameterElement {
6766 AstNode parent = this.parent;
6767 if (parent is ArgumentList) {
6768 return parent._getPropagatedParameterElementFor(this);
6769 } else if (parent is IndexExpression) {
6770 IndexExpression indexExpression = parent;
6771 if (identical(indexExpression.index, this)) {
6772 return indexExpression._propagatedParameterElementForIndex;
6773 }
6774 } else if (parent is BinaryExpression) {
6775 BinaryExpression binaryExpression = parent;
6776 if (identical(binaryExpression.rightOperand, this)) {
6777 return binaryExpression._propagatedParameterElementForRightOperand;
6778 }
6779 } else if (parent is AssignmentExpression) {
6780 AssignmentExpression assignmentExpression = parent;
6781 if (identical(assignmentExpression.rightHandSide, this)) {
6782 return assignmentExpression._propagatedParameterElementForRightHandSide;
6783 }
6784 } else if (parent is PrefixExpression) {
6785 return parent._propagatedParameterElementForOperand;
6786 } else if (parent is PostfixExpression) {
6787 return parent._propagatedParameterElementForOperand;
6788 }
6789 return null;
6790 }
6791
6792 /**
6793 * If this expression is an argument to an invocation, and the AST structure
6794 * has been resolved, and the function being invoked is known based on static
6795 * type information, and this expression corresponds to one of the parameters
6796 * of the function being invoked, then return the parameter element
6797 * representing the parameter to which the value of this expression will be
6798 * bound. Otherwise, return `null`.
6799 */
6800 ParameterElement get staticParameterElement {
6801 AstNode parent = this.parent;
6802 if (parent is ArgumentList) {
6803 return parent._getStaticParameterElementFor(this);
6804 } else if (parent is IndexExpression) {
6805 IndexExpression indexExpression = parent;
6806 if (identical(indexExpression.index, this)) {
6807 return indexExpression._staticParameterElementForIndex;
6808 }
6809 } else if (parent is BinaryExpression) {
6810 BinaryExpression binaryExpression = parent;
6811 if (identical(binaryExpression.rightOperand, this)) {
6812 return binaryExpression._staticParameterElementForRightOperand;
6813 }
6814 } else if (parent is AssignmentExpression) {
6815 AssignmentExpression assignmentExpression = parent;
6816 if (identical(assignmentExpression.rightHandSide, this)) {
6817 return assignmentExpression._staticParameterElementForRightHandSide;
6818 }
6819 } else if (parent is PrefixExpression) {
6820 return parent._staticParameterElementForOperand;
6821 } else if (parent is PostfixExpression) {
6822 return parent._staticParameterElementForOperand;
6823 }
6824 return null;
6825 }
6826 }
6827
6828 /**
6829 * A function body consisting of a single expression.
6830 *
6831 * > expressionFunctionBody ::=
6832 * > 'async'? '=>' [Expression] ';'
6833 */
6834 class ExpressionFunctionBody extends FunctionBody {
6835 /**
6836 * The token representing the 'async' keyword, or `null` if there is no such
6837 * keyword.
6838 */
6839 Token keyword;
6840
6841 /**
6842 * The token introducing the expression that represents the body of the
6843 * function.
6844 */
6845 Token functionDefinition;
6846
6847 /**
6848 * The expression representing the body of the function.
6849 */
6850 Expression _expression;
6851
6852 /**
6853 * The semicolon terminating the statement.
6854 */
6855 Token semicolon;
6856
6857 /**
6858 * Initialize a newly created function body consisting of a block of
6859 * statements. The [keyword] can be `null` if the function body is not an
6860 * async function body.
6861 */
6862 ExpressionFunctionBody(this.keyword, this.functionDefinition,
6863 Expression expression, this.semicolon) {
6864 _expression = _becomeParentOf(expression);
6865 }
6866
6867 @override
6868 Token get beginToken {
6869 if (keyword != null) {
6870 return keyword;
6871 }
6872 return functionDefinition;
6873 }
6874
6875 @override
6876 Iterable get childEntities => new ChildEntities()
6877 ..add(keyword)
6878 ..add(functionDefinition)
6879 ..add(_expression)
6880 ..add(semicolon);
6881
6882 @override
6883 Token get endToken {
6884 if (semicolon != null) {
6885 return semicolon;
6886 }
6887 return _expression.endToken;
6888 }
6889
6890 /**
6891 * Return the expression representing the body of the function.
6892 */
6893 Expression get expression => _expression;
6894
6895 /**
6896 * Set the expression representing the body of the function to the given
6897 * [expression].
6898 */
6899 void set expression(Expression expression) {
6900 _expression = _becomeParentOf(expression);
6901 }
6902
6903 @override
6904 bool get isAsynchronous => keyword != null;
6905
6906 @override
6907 bool get isSynchronous => keyword == null;
6908
6909 @override
6910 accept(AstVisitor visitor) => visitor.visitExpressionFunctionBody(this);
6911
6912 @override
6913 void visitChildren(AstVisitor visitor) {
6914 _safelyVisitChild(_expression, visitor);
6915 }
6916 }
6917
6918 /**
6919 * An expression used as a statement.
6920 *
6921 * > expressionStatement ::=
6922 * > [Expression]? ';'
6923 */
6924 class ExpressionStatement extends Statement {
6925 /**
6926 * The expression that comprises the statement.
6927 */
6928 Expression _expression;
6929
6930 /**
6931 * The semicolon terminating the statement, or `null` if the expression is a
6932 * function expression and therefore isn't followed by a semicolon.
6933 */
6934 Token semicolon;
6935
6936 /**
6937 * Initialize a newly created expression statement.
6938 */
6939 ExpressionStatement(Expression expression, this.semicolon) {
6940 _expression = _becomeParentOf(expression);
6941 }
6942
6943 @override
6944 Token get beginToken => _expression.beginToken;
6945
6946 @override
6947 Iterable get childEntities =>
6948 new ChildEntities()..add(_expression)..add(semicolon);
6949
6950 @override
6951 Token get endToken {
6952 if (semicolon != null) {
6953 return semicolon;
6954 }
6955 return _expression.endToken;
6956 }
6957
6958 /**
6959 * Return the expression that comprises the statement.
6960 */
6961 Expression get expression => _expression;
6962
6963 /**
6964 * Set the expression that comprises the statement to the given [expression].
6965 */
6966 void set expression(Expression expression) {
6967 _expression = _becomeParentOf(expression);
6968 }
6969
6970 @override
6971 bool get isSynthetic => _expression.isSynthetic && semicolon.isSynthetic;
6972
6973 @override
6974 accept(AstVisitor visitor) => visitor.visitExpressionStatement(this);
6975
6976 @override
6977 void visitChildren(AstVisitor visitor) {
6978 _safelyVisitChild(_expression, visitor);
6979 }
6980 }
6981
6982 /**
6983 * The "extends" clause in a class declaration.
6984 *
6985 * > extendsClause ::=
6986 * > 'extends' [TypeName]
6987 */
6988 class ExtendsClause extends AstNode {
6989 /**
6990 * The token representing the 'extends' keyword.
6991 */
6992 Token extendsKeyword;
6993
6994 /**
6995 * The name of the class that is being extended.
6996 */
6997 TypeName _superclass;
6998
6999 /**
7000 * Initialize a newly created extends clause.
7001 */
7002 ExtendsClause(this.extendsKeyword, TypeName superclass) {
7003 _superclass = _becomeParentOf(superclass);
7004 }
7005
7006 @override
7007 Token get beginToken => extendsKeyword;
7008
7009 @override
7010 Iterable get childEntities =>
7011 new ChildEntities()..add(extendsKeyword)..add(_superclass);
7012
7013 @override
7014 Token get endToken => _superclass.endToken;
7015
7016 /**
7017 * Return the token for the 'extends' keyword.
7018 */
7019 @deprecated // Use "this.extendsKeyword"
7020 Token get keyword => extendsKeyword;
7021
7022 /**
7023 * Set the token for the 'extends' keyword to the given [token].
7024 */
7025 @deprecated // Use "this.extendsKeyword"
7026 set keyword(Token token) {
7027 extendsKeyword = token;
7028 }
7029
7030 /**
7031 * Return the name of the class that is being extended.
7032 */
7033 TypeName get superclass => _superclass;
7034
7035 /**
7036 * Set the name of the class that is being extended to the given [name].
7037 */
7038 void set superclass(TypeName name) {
7039 _superclass = _becomeParentOf(name);
7040 }
7041
7042 @override
7043 accept(AstVisitor visitor) => visitor.visitExtendsClause(this);
7044
7045 @override
7046 void visitChildren(AstVisitor visitor) {
7047 _safelyVisitChild(_superclass, visitor);
7048 }
7049 }
7050
7051 /**
7052 * The declaration of one or more fields of the same type.
7053 *
7054 * > fieldDeclaration ::=
7055 * > 'static'? [VariableDeclarationList] ';'
7056 */
7057 class FieldDeclaration extends ClassMember {
7058 /**
7059 * The token representing the 'static' keyword, or `null` if the fields are
7060 * not static.
7061 */
7062 Token staticKeyword;
7063
7064 /**
7065 * The fields being declared.
7066 */
7067 VariableDeclarationList _fieldList;
7068
7069 /**
7070 * The semicolon terminating the declaration.
7071 */
7072 Token semicolon;
7073
7074 /**
7075 * Initialize a newly created field declaration. Either or both of the
7076 * [comment] and [metadata] can be `null` if the declaration does not have the
7077 * corresponding attribute. The [staticKeyword] can be `null` if the field is
7078 * not a static field.
7079 */
7080 FieldDeclaration(Comment comment, List<Annotation> metadata,
7081 this.staticKeyword, VariableDeclarationList fieldList, this.semicolon)
7082 : super(comment, metadata) {
7083 _fieldList = _becomeParentOf(fieldList);
7084 }
7085
7086 @override
7087 Iterable get childEntities =>
7088 super._childEntities..add(staticKeyword)..add(_fieldList)..add(semicolon);
7089
7090 @override
7091 Element get element => null;
7092
7093 @override
7094 Token get endToken => semicolon;
7095
7096 /**
7097 * Return the fields being declared.
7098 */
7099 VariableDeclarationList get fields => _fieldList;
7100
7101 /**
7102 * Set the fields being declared to the given list of [fields].
7103 */
7104 void set fields(VariableDeclarationList fields) {
7105 _fieldList = _becomeParentOf(fields);
7106 }
7107
7108 @override
7109 Token get firstTokenAfterCommentAndMetadata {
7110 if (staticKeyword != null) {
7111 return staticKeyword;
7112 }
7113 return _fieldList.beginToken;
7114 }
7115
7116 /**
7117 * Return `true` if the fields are declared to be static.
7118 */
7119 bool get isStatic => staticKeyword != null;
7120
7121 @override
7122 accept(AstVisitor visitor) => visitor.visitFieldDeclaration(this);
7123
7124 @override
7125 void visitChildren(AstVisitor visitor) {
7126 super.visitChildren(visitor);
7127 _safelyVisitChild(_fieldList, visitor);
7128 }
7129 }
7130
7131 /**
7132 * A field formal parameter.
7133 *
7134 * > fieldFormalParameter ::=
7135 * > ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])?
7136 * > 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterLis t])?
7137 */
7138 class FieldFormalParameter extends NormalFormalParameter {
7139 /**
7140 * The token representing either the 'final', 'const' or 'var' keyword, or
7141 * `null` if no keyword was used.
7142 */
7143 Token keyword;
7144
7145 /**
7146 * The name of the declared type of the parameter, or `null` if the parameter
7147 * does not have a declared type.
7148 */
7149 TypeName _type;
7150
7151 /**
7152 * The token representing the 'this' keyword.
7153 */
7154 Token thisKeyword;
7155
7156 /**
7157 * The token representing the period.
7158 */
7159 Token period;
7160
7161 /**
7162 * The type parameters associated with the method, or `null` if the method is
7163 * not a generic method.
7164 */
7165 TypeParameterList _typeParameters;
7166
7167 /**
7168 * The parameters of the function-typed parameter, or `null` if this is not a
7169 * function-typed field formal parameter.
7170 */
7171 FormalParameterList _parameters;
7172
7173 /**
7174 * Initialize a newly created formal parameter. Either or both of the
7175 * [comment] and [metadata] can be `null` if the parameter does not have the
7176 * corresponding attribute. The [keyword] can be `null` if there is a type.
7177 * The [type] must be `null` if the keyword is 'var'. The [thisKeyword] and
7178 * [period] can be `null` if the keyword 'this' was not provided. The
7179 * [parameters] can be `null` if this is not a function-typed field formal
7180 * parameter.
7181 */
7182 FieldFormalParameter(Comment comment, List<Annotation> metadata, this.keyword,
7183 TypeName type, this.thisKeyword, this.period, SimpleIdentifier identifier,
7184 TypeParameterList typeParameters, FormalParameterList parameters)
7185 : super(comment, metadata, identifier) {
7186 _type = _becomeParentOf(type);
7187 _typeParameters = _becomeParentOf(typeParameters);
7188 _parameters = _becomeParentOf(parameters);
7189 }
7190
7191 @override
7192 Token get beginToken {
7193 if (keyword != null) {
7194 return keyword;
7195 } else if (_type != null) {
7196 return _type.beginToken;
7197 }
7198 return thisKeyword;
7199 }
7200
7201 @override
7202 Iterable get childEntities => super._childEntities
7203 ..add(keyword)
7204 ..add(_type)
7205 ..add(thisKeyword)
7206 ..add(period)
7207 ..add(identifier)
7208 ..add(_parameters);
7209
7210 @override
7211 Token get endToken {
7212 if (_parameters != null) {
7213 return _parameters.endToken;
7214 }
7215 return identifier.endToken;
7216 }
7217
7218 @override
7219 bool get isConst => (keyword is KeywordToken) &&
7220 (keyword as KeywordToken).keyword == Keyword.CONST;
7221
7222 @override
7223 bool get isFinal => (keyword is KeywordToken) &&
7224 (keyword as KeywordToken).keyword == Keyword.FINAL;
7225
7226 /**
7227 * Return the parameters of the function-typed parameter, or `null` if this is
7228 * not a function-typed field formal parameter.
7229 */
7230 FormalParameterList get parameters => _parameters;
7231
7232 /**
7233 * Set the parameters of the function-typed parameter to the given
7234 * [parameters].
7235 */
7236 void set parameters(FormalParameterList parameters) {
7237 _parameters = _becomeParentOf(parameters);
7238 }
7239
7240 /**
7241 * Return the token representing the 'this' keyword.
7242 */
7243 @deprecated // Use "this.thisKeyword"
7244 Token get thisToken => thisKeyword;
7245
7246 /**
7247 * Set the token representing the 'this' keyword to the given [token].
7248 */
7249 @deprecated // Use "this.thisKeyword"
7250 set thisToken(Token token) {
7251 thisKeyword = token;
7252 }
7253
7254 /**
7255 * Return the name of the declared type of the parameter, or `null` if the
7256 * parameter does not have a declared type. Note that if this is a
7257 * function-typed field formal parameter this is the return type of the
7258 * function.
7259 */
7260 TypeName get type => _type;
7261
7262 /**
7263 * Set the name of the declared type of the parameter to the given [typeName].
7264 */
7265 void set type(TypeName typeName) {
7266 _type = _becomeParentOf(typeName);
7267 }
7268
7269 /**
7270 * Return the type parameters associated with this method, or `null` if this
7271 * method is not a generic method.
7272 */
7273 TypeParameterList get typeParameters => _typeParameters;
7274
7275 /**
7276 * Set the type parameters associated with this method to the given
7277 * [typeParameters].
7278 */
7279 void set typeParameters(TypeParameterList typeParameters) {
7280 _typeParameters = _becomeParentOf(typeParameters);
7281 }
7282
7283 @override
7284 accept(AstVisitor visitor) => visitor.visitFieldFormalParameter(this);
7285
7286 @override
7287 void visitChildren(AstVisitor visitor) {
7288 super.visitChildren(visitor);
7289 _safelyVisitChild(_type, visitor);
7290 _safelyVisitChild(identifier, visitor);
7291 _safelyVisitChild(_typeParameters, visitor);
7292 _safelyVisitChild(_parameters, visitor);
7293 }
7294 }
7295
7296 /**
7297 * A for-each statement.
7298 *
7299 * > forEachStatement ::=
7300 * > 'await'? 'for' '(' [DeclaredIdentifier] 'in' [Expression] ')' [Block]
7301 * > | 'await'? 'for' '(' [SimpleIdentifier] 'in' [Expression] ')' [Block]
7302 */
7303 class ForEachStatement extends Statement {
7304 /**
7305 * The token representing the 'await' keyword, or `null` if there is no
7306 * 'await' keyword.
7307 */
7308 Token awaitKeyword;
7309
7310 /**
7311 * The token representing the 'for' keyword.
7312 */
7313 Token forKeyword;
7314
7315 /**
7316 * The left parenthesis.
7317 */
7318 Token leftParenthesis;
7319
7320 /**
7321 * The declaration of the loop variable, or `null` if the loop variable is a
7322 * simple identifier.
7323 */
7324 DeclaredIdentifier _loopVariable;
7325
7326 /**
7327 * The loop variable, or `null` if the loop variable is declared in the 'for'.
7328 */
7329 SimpleIdentifier _identifier;
7330
7331 /**
7332 * The token representing the 'in' keyword.
7333 */
7334 Token inKeyword;
7335
7336 /**
7337 * The expression evaluated to produce the iterator.
7338 */
7339 Expression _iterable;
7340
7341 /**
7342 * The right parenthesis.
7343 */
7344 Token rightParenthesis;
7345
7346 /**
7347 * The body of the loop.
7348 */
7349 Statement _body;
7350
7351 /**
7352 * Initialize a newly created for-each statement. The [awaitKeyword] can be
7353 * `null` if this is not an asynchronous for loop.
7354 */
7355 @deprecated // Use new ForEachStatement.withDeclaration(...)
7356 ForEachStatement.con1(this.awaitKeyword, this.forKeyword,
7357 this.leftParenthesis, DeclaredIdentifier loopVariable, this.inKeyword,
7358 Expression iterator, this.rightParenthesis, Statement body) {
7359 _loopVariable = _becomeParentOf(loopVariable);
7360 _iterable = _becomeParentOf(iterator);
7361 _body = _becomeParentOf(body);
7362 }
7363
7364 /**
7365 * Initialize a newly created for-each statement. The [awaitKeyword] can be
7366 * `null` if this is not an asynchronous for loop.
7367 */
7368 @deprecated // Use new ForEachStatement.withReference(...)
7369 ForEachStatement.con2(this.awaitKeyword, this.forKeyword,
7370 this.leftParenthesis, SimpleIdentifier identifier, this.inKeyword,
7371 Expression iterator, this.rightParenthesis, Statement body) {
7372 _identifier = _becomeParentOf(identifier);
7373 _iterable = _becomeParentOf(iterator);
7374 _body = _becomeParentOf(body);
7375 }
7376
7377 /**
7378 * Initialize a newly created for-each statement whose loop control variable
7379 * is declared internally (in the for-loop part). The [awaitKeyword] can be
7380 * `null` if this is not an asynchronous for loop.
7381 */
7382 ForEachStatement.withDeclaration(this.awaitKeyword, this.forKeyword,
7383 this.leftParenthesis, DeclaredIdentifier loopVariable, this.inKeyword,
7384 Expression iterator, this.rightParenthesis, Statement body) {
7385 _loopVariable = _becomeParentOf(loopVariable);
7386 _iterable = _becomeParentOf(iterator);
7387 _body = _becomeParentOf(body);
7388 }
7389
7390 /**
7391 * Initialize a newly created for-each statement whose loop control variable
7392 * is declared outside the for loop. The [awaitKeyword] can be `null` if this
7393 * is not an asynchronous for loop.
7394 */
7395 ForEachStatement.withReference(this.awaitKeyword, this.forKeyword,
7396 this.leftParenthesis, SimpleIdentifier identifier, this.inKeyword,
7397 Expression iterator, this.rightParenthesis, Statement body) {
7398 _identifier = _becomeParentOf(identifier);
7399 _iterable = _becomeParentOf(iterator);
7400 _body = _becomeParentOf(body);
7401 }
7402
7403 @override
7404 Token get beginToken => forKeyword;
7405
7406 /**
7407 * Return the body of the loop.
7408 */
7409 Statement get body => _body;
7410
7411 /**
7412 * Set the body of the loop to the given [statement].
7413 */
7414 void set body(Statement statement) {
7415 _body = _becomeParentOf(statement);
7416 }
7417
7418 @override
7419 Iterable get childEntities => new ChildEntities()
7420 ..add(awaitKeyword)
7421 ..add(forKeyword)
7422 ..add(leftParenthesis)
7423 ..add(_loopVariable)
7424 ..add(_identifier)
7425 ..add(inKeyword)
7426 ..add(_iterable)
7427 ..add(rightParenthesis)
7428 ..add(_body);
7429
7430 @override
7431 Token get endToken => _body.endToken;
7432
7433 /**
7434 * Return the loop variable, or `null` if the loop variable is declared in the
7435 * 'for'.
7436 */
7437 SimpleIdentifier get identifier => _identifier;
7438
7439 /**
7440 * Set the loop variable to the given [identifier].
7441 */
7442 void set identifier(SimpleIdentifier identifier) {
7443 _identifier = _becomeParentOf(identifier);
7444 }
7445
7446 /**
7447 * Return the expression evaluated to produce the iterator.
7448 */
7449 Expression get iterable => _iterable;
7450
7451 /**
7452 * Set the expression evaluated to produce the iterator to the given
7453 * [expression].
7454 */
7455 void set iterable(Expression expression) {
7456 _iterable = _becomeParentOf(expression);
7457 }
7458
7459 /**
7460 * Return the expression evaluated to produce the iterator.
7461 */
7462 @deprecated // Use "this.iterable"
7463 Expression get iterator => iterable;
7464
7465 /**
7466 * Return the declaration of the loop variable, or `null` if the loop variable
7467 * is a simple identifier.
7468 */
7469 DeclaredIdentifier get loopVariable => _loopVariable;
7470
7471 /**
7472 * Set the declaration of the loop variable to the given [variable].
7473 */
7474 void set loopVariable(DeclaredIdentifier variable) {
7475 _loopVariable = _becomeParentOf(variable);
7476 }
7477
7478 @override
7479 accept(AstVisitor visitor) => visitor.visitForEachStatement(this);
7480
7481 @override
7482 void visitChildren(AstVisitor visitor) {
7483 _safelyVisitChild(_loopVariable, visitor);
7484 _safelyVisitChild(_identifier, visitor);
7485 _safelyVisitChild(_iterable, visitor);
7486 _safelyVisitChild(_body, visitor);
7487 }
7488 }
7489
7490 /**
7491 * A node representing a parameter to a function.
7492 *
7493 * > formalParameter ::=
7494 * > [NormalFormalParameter]
7495 * > | [DefaultFormalParameter]
7496 */
7497 abstract class FormalParameter extends AstNode {
7498 /**
7499 * Return the element representing this parameter, or `null` if this parameter
7500 * has not been resolved.
7501 */
7502 ParameterElement get element {
7503 SimpleIdentifier identifier = this.identifier;
7504 if (identifier == null) {
7505 return null;
7506 }
7507 return identifier.staticElement as ParameterElement;
7508 }
7509
7510 /**
7511 * Return the name of the parameter being declared.
7512 */
7513 SimpleIdentifier get identifier;
7514
7515 /**
7516 * Return `true` if this parameter was declared with the 'const' modifier.
7517 */
7518 bool get isConst;
7519
7520 /**
7521 * Return `true` if this parameter was declared with the 'final' modifier.
7522 * Parameters that are declared with the 'const' modifier will return `false`
7523 * even though they are implicitly final.
7524 */
7525 bool get isFinal;
7526
7527 /**
7528 * Return the kind of this parameter.
7529 */
7530 ParameterKind get kind;
7531
7532 /**
7533 * Return the annotations associated with this parameter.
7534 */
7535 NodeList<Annotation> get metadata;
7536 }
7537
7538 /**
7539 * The formal parameter list of a method declaration, function declaration, or
7540 * function type alias.
7541 *
7542 * While the grammar requires all optional formal parameters to follow all of
7543 * the normal formal parameters and at most one grouping of optional formal
7544 * parameters, this class does not enforce those constraints. All parameters are
7545 * flattened into a single list, which can have any or all kinds of parameters
7546 * (normal, named, and positional) in any order.
7547 *
7548 * > formalParameterList ::=
7549 * > '(' ')'
7550 * > | '(' normalFormalParameters (',' optionalFormalParameters)? ')'
7551 * > | '(' optionalFormalParameters ')'
7552 * >
7553 * > normalFormalParameters ::=
7554 * > [NormalFormalParameter] (',' [NormalFormalParameter])*
7555 * >
7556 * > optionalFormalParameters ::=
7557 * > optionalPositionalFormalParameters
7558 * > | namedFormalParameters
7559 * >
7560 * > optionalPositionalFormalParameters ::=
7561 * > '[' [DefaultFormalParameter] (',' [DefaultFormalParameter])* ']'
7562 * >
7563 * > namedFormalParameters ::=
7564 * > '{' [DefaultFormalParameter] (',' [DefaultFormalParameter])* '}'
7565 */
7566 class FormalParameterList extends AstNode {
7567 /**
7568 * The left parenthesis.
7569 */
7570 Token leftParenthesis;
7571
7572 /**
7573 * The parameters associated with the method.
7574 */
7575 NodeList<FormalParameter> _parameters;
7576
7577 /**
7578 * The left square bracket ('[') or left curly brace ('{') introducing the
7579 * optional parameters, or `null` if there are no optional parameters.
7580 */
7581 Token leftDelimiter;
7582
7583 /**
7584 * The right square bracket (']') or right curly brace ('}') terminating the
7585 * optional parameters, or `null` if there are no optional parameters.
7586 */
7587 Token rightDelimiter;
7588
7589 /**
7590 * The right parenthesis.
7591 */
7592 Token rightParenthesis;
7593
7594 /**
7595 * Initialize a newly created parameter list. The list of [parameters] can be
7596 * `null` if there are no parameters. The [leftDelimiter] and [rightDelimiter]
7597 * can be `null` if there are no optional parameters.
7598 */
7599 FormalParameterList(this.leftParenthesis, List<FormalParameter> parameters,
7600 this.leftDelimiter, this.rightDelimiter, this.rightParenthesis) {
7601 _parameters = new NodeList<FormalParameter>(this, parameters);
7602 }
7603
7604 @override
7605 Token get beginToken => leftParenthesis;
7606
7607 @override
7608 Iterable get childEntities {
7609 // TODO(paulberry): include commas.
7610 ChildEntities result = new ChildEntities()..add(leftParenthesis);
7611 bool leftDelimiterNeeded = leftDelimiter != null;
7612 for (FormalParameter parameter in _parameters) {
7613 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) {
7614 result.add(leftDelimiter);
7615 leftDelimiterNeeded = false;
7616 }
7617 result.add(parameter);
7618 }
7619 return result..add(rightDelimiter)..add(rightParenthesis);
7620 }
7621
7622 @override
7623 Token get endToken => rightParenthesis;
7624
7625 /**
7626 * Return a list containing the elements representing the parameters in this
7627 * list. The list will contain `null`s if the parameters in this list have not
7628 * been resolved.
7629 */
7630 List<ParameterElement> get parameterElements {
7631 int count = _parameters.length;
7632 List<ParameterElement> types = new List<ParameterElement>(count);
7633 for (int i = 0; i < count; i++) {
7634 types[i] = _parameters[i].element;
7635 }
7636 return types;
7637 }
7638
7639 /**
7640 * Return the parameters associated with the method.
7641 */
7642 NodeList<FormalParameter> get parameters => _parameters;
7643
7644 @override
7645 accept(AstVisitor visitor) => visitor.visitFormalParameterList(this);
7646
7647 @override
7648 void visitChildren(AstVisitor visitor) {
7649 _parameters.accept(visitor);
7650 }
7651 }
7652
7653 /**
7654 * A for statement.
7655 *
7656 * > forStatement ::=
7657 * > 'for' '(' forLoopParts ')' [Statement]
7658 * >
7659 * > forLoopParts ::=
7660 * > forInitializerStatement ';' [Expression]? ';' [Expression]?
7661 * >
7662 * > forInitializerStatement ::=
7663 * > [DefaultFormalParameter]
7664 * > | [Expression]?
7665 */
7666 class ForStatement extends Statement {
7667 /**
7668 * The token representing the 'for' keyword.
7669 */
7670 Token forKeyword;
7671
7672 /**
7673 * The left parenthesis.
7674 */
7675 Token leftParenthesis;
7676
7677 /**
7678 * The declaration of the loop variables, or `null` if there are no variables.
7679 * Note that a for statement cannot have both a variable list and an
7680 * initialization expression, but can validly have neither.
7681 */
7682 VariableDeclarationList _variableList;
7683
7684 /**
7685 * The initialization expression, or `null` if there is no initialization
7686 * expression. Note that a for statement cannot have both a variable list and
7687 * an initialization expression, but can validly have neither.
7688 */
7689 Expression _initialization;
7690
7691 /**
7692 * The semicolon separating the initializer and the condition.
7693 */
7694 Token leftSeparator;
7695
7696 /**
7697 * The condition used to determine when to terminate the loop, or `null` if
7698 * there is no condition.
7699 */
7700 Expression _condition;
7701
7702 /**
7703 * The semicolon separating the condition and the updater.
7704 */
7705 Token rightSeparator;
7706
7707 /**
7708 * The list of expressions run after each execution of the loop body.
7709 */
7710 NodeList<Expression> _updaters;
7711
7712 /**
7713 * The right parenthesis.
7714 */
7715 Token rightParenthesis;
7716
7717 /**
7718 * The body of the loop.
7719 */
7720 Statement _body;
7721
7722 /**
7723 * Initialize a newly created for statement. Either the [variableList] or the
7724 * [initialization] must be `null`. Either the [condition] and the list of
7725 * [updaters] can be `null` if the loop does not have the corresponding
7726 * attribute.
7727 */
7728 ForStatement(this.forKeyword, this.leftParenthesis,
7729 VariableDeclarationList variableList, Expression initialization,
7730 this.leftSeparator, Expression condition, this.rightSeparator,
7731 List<Expression> updaters, this.rightParenthesis, Statement body) {
7732 _variableList = _becomeParentOf(variableList);
7733 _initialization = _becomeParentOf(initialization);
7734 _condition = _becomeParentOf(condition);
7735 _updaters = new NodeList<Expression>(this, updaters);
7736 _body = _becomeParentOf(body);
7737 }
7738
7739 @override
7740 Token get beginToken => forKeyword;
7741
7742 /**
7743 * Return the body of the loop.
7744 */
7745 Statement get body => _body;
7746
7747 /**
7748 * Set the body of the loop to the given [statement].
7749 */
7750 void set body(Statement statement) {
7751 _body = _becomeParentOf(statement);
7752 }
7753
7754 @override
7755 Iterable get childEntities => new ChildEntities()
7756 ..add(forKeyword)
7757 ..add(leftParenthesis)
7758 ..add(_variableList)
7759 ..add(_initialization)
7760 ..add(leftSeparator)
7761 ..add(_condition)
7762 ..add(rightSeparator)
7763 ..addAll(_updaters)
7764 ..add(rightParenthesis)
7765 ..add(_body);
7766
7767 /**
7768 * Return the condition used to determine when to terminate the loop, or
7769 * `null` if there is no condition.
7770 */
7771 Expression get condition => _condition;
7772
7773 /**
7774 * Set the condition used to determine when to terminate the loop to the given
7775 * [expression].
7776 */
7777 void set condition(Expression expression) {
7778 _condition = _becomeParentOf(expression);
7779 }
7780
7781 @override
7782 Token get endToken => _body.endToken;
7783
7784 /**
7785 * Return the initialization expression, or `null` if there is no
7786 * initialization expression.
7787 */
7788 Expression get initialization => _initialization;
7789
7790 /**
7791 * Set the initialization expression to the given [expression].
7792 */
7793 void set initialization(Expression initialization) {
7794 _initialization = _becomeParentOf(initialization);
7795 }
7796
7797 /**
7798 * Return the list of expressions run after each execution of the loop body.
7799 */
7800 NodeList<Expression> get updaters => _updaters;
7801
7802 /**
7803 * Return the declaration of the loop variables, or `null` if there are no
7804 * variables.
7805 */
7806 VariableDeclarationList get variables => _variableList;
7807
7808 /**
7809 * Set the declaration of the loop variables to the given [variableList].
7810 */
7811 void set variables(VariableDeclarationList variableList) {
7812 _variableList = _becomeParentOf(variableList);
7813 }
7814
7815 @override
7816 accept(AstVisitor visitor) => visitor.visitForStatement(this);
7817
7818 @override
7819 void visitChildren(AstVisitor visitor) {
7820 _safelyVisitChild(_variableList, visitor);
7821 _safelyVisitChild(_initialization, visitor);
7822 _safelyVisitChild(_condition, visitor);
7823 _updaters.accept(visitor);
7824 _safelyVisitChild(_body, visitor);
7825 }
7826 }
7827
7828 /**
7829 * A node representing the body of a function or method.
7830 *
7831 * > functionBody ::=
7832 * > [BlockFunctionBody]
7833 * > | [EmptyFunctionBody]
7834 * > | [ExpressionFunctionBody]
7835 */
7836 abstract class FunctionBody extends AstNode {
7837 /**
7838 * Return `true` if this function body is asynchronous.
7839 */
7840 bool get isAsynchronous => false;
7841
7842 /**
7843 * Return `true` if this function body is a generator.
7844 */
7845 bool get isGenerator => false;
7846
7847 /**
7848 * Return `true` if this function body is synchronous.
7849 */
7850 bool get isSynchronous => true;
7851
7852 /**
7853 * Return the token representing the 'async' or 'sync' keyword, or `null` if
7854 * there is no such keyword.
7855 */
7856 Token get keyword => null;
7857
7858 /**
7859 * Return the star following the 'async' or 'sync' keyword, or `null` if there
7860 * is no star.
7861 */
7862 Token get star => null;
7863 }
7864
7865 /**
7866 * A top-level declaration.
7867 *
7868 * > functionDeclaration ::=
7869 * > 'external' functionSignature
7870 * > | functionSignature [FunctionBody]
7871 * >
7872 * > functionSignature ::=
7873 * > [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList]
7874 */
7875 class FunctionDeclaration extends NamedCompilationUnitMember {
7876 /**
7877 * The token representing the 'external' keyword, or `null` if this is not an
7878 * external function.
7879 */
7880 Token externalKeyword;
7881
7882 /**
7883 * The return type of the function, or `null` if no return type was declared.
7884 */
7885 TypeName _returnType;
7886
7887 /**
7888 * The token representing the 'get' or 'set' keyword, or `null` if this is a
7889 * function declaration rather than a property declaration.
7890 */
7891 Token propertyKeyword;
7892
7893 /**
7894 * The function expression being wrapped.
7895 */
7896 FunctionExpression _functionExpression;
7897
7898 /**
7899 * Initialize a newly created function declaration. Either or both of the
7900 * [comment] and [metadata] can be `null` if the function does not have the
7901 * corresponding attribute. The [externalKeyword] can be `null` if the
7902 * function is not an external function. The [returnType] can be `null` if no
7903 * return type was specified. The [propertyKeyword] can be `null` if the
7904 * function is neither a getter or a setter.
7905 */
7906 FunctionDeclaration(Comment comment, List<Annotation> metadata,
7907 this.externalKeyword, TypeName returnType, this.propertyKeyword,
7908 SimpleIdentifier name, FunctionExpression functionExpression)
7909 : super(comment, metadata, name) {
7910 _returnType = _becomeParentOf(returnType);
7911 _functionExpression = _becomeParentOf(functionExpression);
7912 }
7913
7914 @override
7915 Iterable get childEntities => super._childEntities
7916 ..add(externalKeyword)
7917 ..add(_returnType)
7918 ..add(propertyKeyword)
7919 ..add(_name)
7920 ..add(_functionExpression);
7921
7922 @override
7923 ExecutableElement get element =>
7924 _name != null ? (_name.staticElement as ExecutableElement) : null;
7925
7926 @override
7927 Token get endToken => _functionExpression.endToken;
7928
7929 @override
7930 Token get firstTokenAfterCommentAndMetadata {
7931 if (externalKeyword != null) {
7932 return externalKeyword;
7933 } else if (_returnType != null) {
7934 return _returnType.beginToken;
7935 } else if (propertyKeyword != null) {
7936 return propertyKeyword;
7937 } else if (_name != null) {
7938 return _name.beginToken;
7939 }
7940 return _functionExpression.beginToken;
7941 }
7942
7943 /**
7944 * Return the function expression being wrapped.
7945 */
7946 FunctionExpression get functionExpression => _functionExpression;
7947
7948 /**
7949 * Set the function expression being wrapped to the given
7950 * [functionExpression].
7951 */
7952 void set functionExpression(FunctionExpression functionExpression) {
7953 _functionExpression = _becomeParentOf(functionExpression);
7954 }
7955
7956 /**
7957 * Return `true` if this function declares a getter.
7958 */
7959 bool get isGetter => propertyKeyword != null &&
7960 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
7961
7962 /**
7963 * Return `true` if this function declares a setter.
7964 */
7965 bool get isSetter => propertyKeyword != null &&
7966 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
7967
7968 /**
7969 * Return the return type of the function, or `null` if no return type was
7970 * declared.
7971 */
7972 TypeName get returnType => _returnType;
7973
7974 /**
7975 * Set the return type of the function to the given [returnType].
7976 */
7977 void set returnType(TypeName returnType) {
7978 _returnType = _becomeParentOf(returnType);
7979 }
7980
7981 @override
7982 accept(AstVisitor visitor) => visitor.visitFunctionDeclaration(this);
7983
7984 @override
7985 void visitChildren(AstVisitor visitor) {
7986 super.visitChildren(visitor);
7987 _safelyVisitChild(_returnType, visitor);
7988 _safelyVisitChild(_name, visitor);
7989 _safelyVisitChild(_functionExpression, visitor);
7990 }
7991 }
7992
7993 /**
7994 * A [FunctionDeclaration] used as a statement.
7995 */
7996 class FunctionDeclarationStatement extends Statement {
7997 /**
7998 * The function declaration being wrapped.
7999 */
8000 FunctionDeclaration _functionDeclaration;
8001
8002 /**
8003 * Initialize a newly created function declaration statement.
8004 */
8005 FunctionDeclarationStatement(FunctionDeclaration functionDeclaration) {
8006 _functionDeclaration = _becomeParentOf(functionDeclaration);
8007 }
8008
8009 @override
8010 Token get beginToken => _functionDeclaration.beginToken;
8011
8012 @override
8013 Iterable get childEntities => new ChildEntities()..add(_functionDeclaration);
8014
8015 @override
8016 Token get endToken => _functionDeclaration.endToken;
8017
8018 /**
8019 * Return the function declaration being wrapped.
8020 */
8021 FunctionDeclaration get functionDeclaration => _functionDeclaration;
8022
8023 /**
8024 * Set the function declaration being wrapped to the given
8025 * [functionDeclaration].
8026 */
8027 void set functionDeclaration(FunctionDeclaration functionDeclaration) {
8028 _functionDeclaration = _becomeParentOf(functionDeclaration);
8029 }
8030
8031 @override
8032 accept(AstVisitor visitor) => visitor.visitFunctionDeclarationStatement(this);
8033
8034 @override
8035 void visitChildren(AstVisitor visitor) {
8036 _safelyVisitChild(_functionDeclaration, visitor);
8037 }
8038 }
8039
8040 /**
8041 * A function expression.
8042 *
8043 * > functionExpression ::=
8044 * > [TypeParameterList]? [FormalParameterList] [FunctionBody]
8045 */
8046 class FunctionExpression extends Expression {
8047 /**
8048 * The type parameters associated with the method, or `null` if the method is
8049 * not a generic method.
8050 */
8051 TypeParameterList _typeParameters;
8052
8053 /**
8054 * The parameters associated with the function.
8055 */
8056 FormalParameterList _parameters;
8057
8058 /**
8059 * The body of the function, or `null` if this is an external function.
8060 */
8061 FunctionBody _body;
8062
8063 /**
8064 * The element associated with the function, or `null` if the AST structure
8065 * has not been resolved.
8066 */
8067 ExecutableElement element;
8068
8069 /**
8070 * Initialize a newly created function declaration.
8071 */
8072 FunctionExpression(TypeParameterList typeParameters,
8073 FormalParameterList parameters, FunctionBody body) {
8074 _typeParameters = _becomeParentOf(typeParameters);
8075 _parameters = _becomeParentOf(parameters);
8076 _body = _becomeParentOf(body);
8077 }
8078
8079 @override
8080 Token get beginToken {
8081 if (_typeParameters != null) {
8082 return _typeParameters.beginToken;
8083 } else if (_parameters != null) {
8084 return _parameters.beginToken;
8085 } else if (_body != null) {
8086 return _body.beginToken;
8087 }
8088 // This should never be reached because external functions must be named,
8089 // hence either the body or the name should be non-null.
8090 throw new IllegalStateException("Non-external functions must have a body");
8091 }
8092
8093 /**
8094 * Return the body of the function, or `null` if this is an external function.
8095 */
8096 FunctionBody get body => _body;
8097
8098 /**
8099 * Set the body of the function to the given [functionBody].
8100 */
8101 void set body(FunctionBody functionBody) {
8102 _body = _becomeParentOf(functionBody);
8103 }
8104
8105 @override
8106 Iterable get childEntities =>
8107 new ChildEntities()..add(_parameters)..add(_body);
8108
8109 @override
8110 Token get endToken {
8111 if (_body != null) {
8112 return _body.endToken;
8113 } else if (_parameters != null) {
8114 return _parameters.endToken;
8115 }
8116 // This should never be reached because external functions must be named,
8117 // hence either the body or the name should be non-null.
8118 throw new IllegalStateException("Non-external functions must have a body");
8119 }
8120
8121 /**
8122 * Return the parameters associated with the function.
8123 */
8124 FormalParameterList get parameters => _parameters;
8125
8126 /**
8127 * Set the parameters associated with the function to the given list of
8128 * [parameters].
8129 */
8130 void set parameters(FormalParameterList parameters) {
8131 _parameters = _becomeParentOf(parameters);
8132 }
8133
8134 @override
8135 int get precedence => 16;
8136
8137 /**
8138 * Return the type parameters associated with this method, or `null` if this
8139 * method is not a generic method.
8140 */
8141 TypeParameterList get typeParameters => _typeParameters;
8142
8143 /**
8144 * Set the type parameters associated with this method to the given
8145 * [typeParameters].
8146 */
8147 void set typeParameters(TypeParameterList typeParameters) {
8148 _typeParameters = _becomeParentOf(typeParameters);
8149 }
8150
8151 @override
8152 accept(AstVisitor visitor) => visitor.visitFunctionExpression(this);
8153
8154 @override
8155 void visitChildren(AstVisitor visitor) {
8156 _safelyVisitChild(_typeParameters, visitor);
8157 _safelyVisitChild(_parameters, visitor);
8158 _safelyVisitChild(_body, visitor);
8159 }
8160 }
8161
8162 /**
8163 * The invocation of a function resulting from evaluating an expression.
8164 * Invocations of methods and other forms of functions are represented by
8165 * [MethodInvocation] nodes. Invocations of getters and setters are represented
8166 * by either [PrefixedIdentifier] or [PropertyAccess] nodes.
8167 *
8168 * > functionExpressionInvoction ::=
8169 * > [Expression] [TypeArgumentList]? [ArgumentList]
8170 */
8171 class FunctionExpressionInvocation extends Expression {
8172 /**
8173 * The expression producing the function being invoked.
8174 */
8175 Expression _function;
8176
8177 /**
8178 * The type arguments to be applied to the method being invoked, or `null` if
8179 * no type arguments were provided.
8180 */
8181 TypeArgumentList _typeArguments;
8182
8183 /**
8184 * The list of arguments to the function.
8185 */
8186 ArgumentList _argumentList;
8187
8188 /**
8189 * The element associated with the function being invoked based on static type
8190 * information, or `null` if the AST structure has not been resolved or the
8191 * function could not be resolved.
8192 */
8193 ExecutableElement staticElement;
8194
8195 /**
8196 * The element associated with the function being invoked based on propagated
8197 * type information, or `null` if the AST structure has not been resolved or
8198 * the function could not be resolved.
8199 */
8200 ExecutableElement propagatedElement;
8201
8202 /**
8203 * Initialize a newly created function expression invocation.
8204 */
8205 FunctionExpressionInvocation(Expression function,
8206 TypeArgumentList typeArguments, ArgumentList argumentList) {
8207 _function = _becomeParentOf(function);
8208 _typeArguments = _becomeParentOf(typeArguments);
8209 _argumentList = _becomeParentOf(argumentList);
8210 }
8211
8212 /**
8213 * Return the list of arguments to the method.
8214 */
8215 ArgumentList get argumentList => _argumentList;
8216
8217 /**
8218 * Set the list of arguments to the method to the given [argumentList].
8219 */
8220 void set argumentList(ArgumentList argumentList) {
8221 _argumentList = _becomeParentOf(argumentList);
8222 }
8223
8224 @override
8225 Token get beginToken => _function.beginToken;
8226
8227 /**
8228 * Return the best element available for the function being invoked. If
8229 * resolution was able to find a better element based on type propagation,
8230 * that element will be returned. Otherwise, the element found using the
8231 * result of static analysis will be returned. If resolution has not been
8232 * performed, then `null` will be returned.
8233 */
8234 ExecutableElement get bestElement {
8235 ExecutableElement element = propagatedElement;
8236 if (element == null) {
8237 element = staticElement;
8238 }
8239 return element;
8240 }
8241
8242 @override
8243 Iterable get childEntities =>
8244 new ChildEntities()..add(_function)..add(_argumentList);
8245
8246 @override
8247 Token get endToken => _argumentList.endToken;
8248
8249 /**
8250 * Return the expression producing the function being invoked.
8251 */
8252 Expression get function => _function;
8253
8254 /**
8255 * Set the expression producing the function being invoked to the given
8256 * [expression].
8257 */
8258 void set function(Expression expression) {
8259 _function = _becomeParentOf(expression);
8260 }
8261
8262 @override
8263 int get precedence => 15;
8264
8265 /**
8266 * Return the type arguments to be applied to the method being invoked, or
8267 * `null` if no type arguments were provided.
8268 */
8269 TypeArgumentList get typeArguments => _typeArguments;
8270
8271 /**
8272 * Set the type arguments to be applied to the method being invoked to the
8273 * given [typeArguments].
8274 */
8275 void set typeArguments(TypeArgumentList typeArguments) {
8276 _typeArguments = _becomeParentOf(typeArguments);
8277 }
8278
8279 @override
8280 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this);
8281
8282 @override
8283 void visitChildren(AstVisitor visitor) {
8284 _safelyVisitChild(_function, visitor);
8285 _safelyVisitChild(_typeArguments, visitor);
8286 _safelyVisitChild(_argumentList, visitor);
8287 }
8288 }
8289
8290 /**
8291 * A function type alias.
8292 *
8293 * > functionTypeAlias ::=
8294 * > functionPrefix [TypeParameterList]? [FormalParameterList] ';'
8295 * >
8296 * > functionPrefix ::=
8297 * > [TypeName]? [SimpleIdentifier]
8298 */
8299 class FunctionTypeAlias extends TypeAlias {
8300 /**
8301 * The name of the return type of the function type being defined, or `null`
8302 * if no return type was given.
8303 */
8304 TypeName _returnType;
8305
8306 /**
8307 * The type parameters for the function type, or `null` if the function type
8308 * does not have any type parameters.
8309 */
8310 TypeParameterList _typeParameters;
8311
8312 /**
8313 * The parameters associated with the function type.
8314 */
8315 FormalParameterList _parameters;
8316
8317 /**
8318 * Initialize a newly created function type alias. Either or both of the
8319 * [comment] and [metadata] can be `null` if the function does not have the
8320 * corresponding attribute. The [returnType] can be `null` if no return type
8321 * was specified. The [typeParameters] can be `null` if the function has no
8322 * type parameters.
8323 */
8324 FunctionTypeAlias(Comment comment, List<Annotation> metadata, Token keyword,
8325 TypeName returnType, SimpleIdentifier name,
8326 TypeParameterList typeParameters, FormalParameterList parameters,
8327 Token semicolon)
8328 : super(comment, metadata, keyword, name, semicolon) {
8329 _returnType = _becomeParentOf(returnType);
8330 _typeParameters = _becomeParentOf(typeParameters);
8331 _parameters = _becomeParentOf(parameters);
8332 }
8333
8334 @override
8335 Iterable get childEntities => super._childEntities
8336 ..add(typedefKeyword)
8337 ..add(_returnType)
8338 ..add(_name)
8339 ..add(_typeParameters)
8340 ..add(_parameters)
8341 ..add(semicolon);
8342
8343 @override
8344 FunctionTypeAliasElement get element =>
8345 _name != null ? (_name.staticElement as FunctionTypeAliasElement) : null;
8346
8347 /**
8348 * Return the parameters associated with the function type.
8349 */
8350 FormalParameterList get parameters => _parameters;
8351
8352 /**
8353 * Set the parameters associated with the function type to the given list of
8354 * [parameters].
8355 */
8356 void set parameters(FormalParameterList parameters) {
8357 _parameters = _becomeParentOf(parameters);
8358 }
8359
8360 /**
8361 * Return the name of the return type of the function type being defined, or
8362 * `null` if no return type was given.
8363 */
8364 TypeName get returnType => _returnType;
8365
8366 /**
8367 * Set the name of the return type of the function type being defined to the
8368 * given [typeName].
8369 */
8370 void set returnType(TypeName typeName) {
8371 _returnType = _becomeParentOf(typeName);
8372 }
8373
8374 /**
8375 * Return the type parameters for the function type, or `null` if the function
8376 * type does not have any type parameters.
8377 */
8378 TypeParameterList get typeParameters => _typeParameters;
8379
8380 /**
8381 * Set the type parameters for the function type to the given list of
8382 * [typeParameters].
8383 */
8384 void set typeParameters(TypeParameterList typeParameters) {
8385 _typeParameters = _becomeParentOf(typeParameters);
8386 }
8387
8388 @override
8389 accept(AstVisitor visitor) => visitor.visitFunctionTypeAlias(this);
8390
8391 @override
8392 void visitChildren(AstVisitor visitor) {
8393 super.visitChildren(visitor);
8394 _safelyVisitChild(_returnType, visitor);
8395 _safelyVisitChild(_name, visitor);
8396 _safelyVisitChild(_typeParameters, visitor);
8397 _safelyVisitChild(_parameters, visitor);
8398 }
8399 }
8400
8401 /**
8402 * A function-typed formal parameter.
8403 *
8404 * > functionSignature ::=
8405 * > [TypeName]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterLis t]
8406 */
8407 class FunctionTypedFormalParameter extends NormalFormalParameter {
8408 /**
8409 * The return type of the function, or `null` if the function does not have a
8410 * return type.
8411 */
8412 TypeName _returnType;
8413
8414 /**
8415 * The type parameters associated with the function, or `null` if the function
8416 * is not a generic function.
8417 */
8418 TypeParameterList _typeParameters;
8419
8420 /**
8421 * The parameters of the function-typed parameter.
8422 */
8423 FormalParameterList _parameters;
8424
8425 /**
8426 * Initialize a newly created formal parameter. Either or both of the
8427 * [comment] and [metadata] can be `null` if the parameter does not have the
8428 * corresponding attribute. The [returnType] can be `null` if no return type
8429 * was specified.
8430 */
8431 FunctionTypedFormalParameter(Comment comment, List<Annotation> metadata,
8432 TypeName returnType, SimpleIdentifier identifier,
8433 TypeParameterList typeParameters, FormalParameterList parameters)
8434 : super(comment, metadata, identifier) {
8435 _returnType = _becomeParentOf(returnType);
8436 _typeParameters = _becomeParentOf(typeParameters);
8437 _parameters = _becomeParentOf(parameters);
8438 }
8439
8440 @override
8441 Token get beginToken {
8442 if (_returnType != null) {
8443 return _returnType.beginToken;
8444 }
8445 return identifier.beginToken;
8446 }
8447
8448 @override
8449 Iterable get childEntities =>
8450 super._childEntities..add(_returnType)..add(identifier)..add(parameters);
8451
8452 @override
8453 Token get endToken => _parameters.endToken;
8454
8455 @override
8456 bool get isConst => false;
8457
8458 @override
8459 bool get isFinal => false;
8460
8461 /**
8462 * Return the parameters of the function-typed parameter.
8463 */
8464 FormalParameterList get parameters => _parameters;
8465
8466 /**
8467 * Set the parameters of the function-typed parameter to the given
8468 * [parameters].
8469 */
8470 void set parameters(FormalParameterList parameters) {
8471 _parameters = _becomeParentOf(parameters);
8472 }
8473
8474 /**
8475 * Return the return type of the function, or `null` if the function does not
8476 * have a return type.
8477 */
8478 TypeName get returnType => _returnType;
8479
8480 /**
8481 * Set the return type of the function to the given [type].
8482 */
8483 void set returnType(TypeName type) {
8484 _returnType = _becomeParentOf(type);
8485 }
8486
8487 /**
8488 * Return the type parameters associated with this function, or `null` if
8489 * this function is not a generic function.
8490 */
8491 TypeParameterList get typeParameters => _typeParameters;
8492
8493 /**
8494 * Set the type parameters associated with this method to the given
8495 * [typeParameters].
8496 */
8497 void set typeParameters(TypeParameterList typeParameters) {
8498 _typeParameters = _becomeParentOf(typeParameters);
8499 }
8500
8501 @override
8502 accept(AstVisitor visitor) => visitor.visitFunctionTypedFormalParameter(this);
8503
8504 @override
8505 void visitChildren(AstVisitor visitor) {
8506 super.visitChildren(visitor);
8507 _safelyVisitChild(_returnType, visitor);
8508 _safelyVisitChild(identifier, visitor);
8509 _safelyVisitChild(_typeParameters, visitor);
8510 _safelyVisitChild(_parameters, visitor);
8511 }
8512 }
8513
8514 /**
8515 * An AST visitor that will recursively visit all of the nodes in an AST
8516 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
8517 * when a node of a specific type is visited not only will the visit method for
8518 * that specific type of node be invoked, but additional methods for the
8519 * superclasses of that node will also be invoked. For example, using an
8520 * instance of this class to visit a [Block] will cause the method [visitBlock]
8521 * to be invoked but will also cause the methods [visitStatement] and
8522 * [visitNode] to be subsequently invoked. This allows visitors to be written
8523 * that visit all statements without needing to override the visit method for
8524 * each of the specific subclasses of [Statement].
8525 *
8526 * Subclasses that override a visit method must either invoke the overridden
8527 * visit method or explicitly invoke the more general visit method. Failure to
8528 * do so will cause the visit methods for superclasses of the node to not be
8529 * invoked and will cause the children of the visited node to not be visited.
8530 */
8531 class GeneralizingAstVisitor<R> implements AstVisitor<R> {
8532 @override
8533 R visitAdjacentStrings(AdjacentStrings node) => visitStringLiteral(node);
8534
8535 R visitAnnotatedNode(AnnotatedNode node) => visitNode(node);
8536
8537 @override
8538 R visitAnnotation(Annotation node) => visitNode(node);
8539
8540 @override
8541 R visitArgumentList(ArgumentList node) => visitNode(node);
8542
8543 @override
8544 R visitAsExpression(AsExpression node) => visitExpression(node);
8545
8546 @override
8547 R visitAssertStatement(AssertStatement node) => visitStatement(node);
8548
8549 @override
8550 R visitAssignmentExpression(AssignmentExpression node) =>
8551 visitExpression(node);
8552
8553 @override
8554 R visitAwaitExpression(AwaitExpression node) => visitExpression(node);
8555
8556 @override
8557 R visitBinaryExpression(BinaryExpression node) => visitExpression(node);
8558
8559 @override
8560 R visitBlock(Block node) => visitStatement(node);
8561
8562 @override
8563 R visitBlockFunctionBody(BlockFunctionBody node) => visitFunctionBody(node);
8564
8565 @override
8566 R visitBooleanLiteral(BooleanLiteral node) => visitLiteral(node);
8567
8568 @override
8569 R visitBreakStatement(BreakStatement node) => visitStatement(node);
8570
8571 @override
8572 R visitCascadeExpression(CascadeExpression node) => visitExpression(node);
8573
8574 @override
8575 R visitCatchClause(CatchClause node) => visitNode(node);
8576
8577 @override
8578 R visitClassDeclaration(ClassDeclaration node) =>
8579 visitNamedCompilationUnitMember(node);
8580
8581 R visitClassMember(ClassMember node) => visitDeclaration(node);
8582
8583 @override
8584 R visitClassTypeAlias(ClassTypeAlias node) => visitTypeAlias(node);
8585
8586 R visitCombinator(Combinator node) => visitNode(node);
8587
8588 @override
8589 R visitComment(Comment node) => visitNode(node);
8590
8591 @override
8592 R visitCommentReference(CommentReference node) => visitNode(node);
8593
8594 @override
8595 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
8596
8597 R visitCompilationUnitMember(CompilationUnitMember node) =>
8598 visitDeclaration(node);
8599
8600 @override
8601 R visitConditionalExpression(ConditionalExpression node) =>
8602 visitExpression(node);
8603
8604 @override
8605 R visitConstructorDeclaration(ConstructorDeclaration node) =>
8606 visitClassMember(node);
8607
8608 @override
8609 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
8610 visitConstructorInitializer(node);
8611
8612 R visitConstructorInitializer(ConstructorInitializer node) => visitNode(node);
8613
8614 @override
8615 R visitConstructorName(ConstructorName node) => visitNode(node);
8616
8617 @override
8618 R visitContinueStatement(ContinueStatement node) => visitStatement(node);
8619
8620 R visitDeclaration(Declaration node) => visitAnnotatedNode(node);
8621
8622 @override
8623 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitDeclaration(node);
8624
8625 @override
8626 R visitDefaultFormalParameter(DefaultFormalParameter node) =>
8627 visitFormalParameter(node);
8628
8629 R visitDirective(Directive node) => visitAnnotatedNode(node);
8630
8631 @override
8632 R visitDoStatement(DoStatement node) => visitStatement(node);
8633
8634 @override
8635 R visitDoubleLiteral(DoubleLiteral node) => visitLiteral(node);
8636
8637 @override
8638 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitFunctionBody(node);
8639
8640 @override
8641 R visitEmptyStatement(EmptyStatement node) => visitStatement(node);
8642
8643 @override
8644 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
8645 visitDeclaration(node);
8646
8647 @override
8648 R visitEnumDeclaration(EnumDeclaration node) =>
8649 visitNamedCompilationUnitMember(node);
8650
8651 @override
8652 R visitExportDirective(ExportDirective node) => visitNamespaceDirective(node);
8653
8654 R visitExpression(Expression node) => visitNode(node);
8655
8656 @override
8657 R visitExpressionFunctionBody(ExpressionFunctionBody node) =>
8658 visitFunctionBody(node);
8659
8660 @override
8661 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node);
8662
8663 @override
8664 R visitExtendsClause(ExtendsClause node) => visitNode(node);
8665
8666 @override
8667 R visitFieldDeclaration(FieldDeclaration node) => visitClassMember(node);
8668
8669 @override
8670 R visitFieldFormalParameter(FieldFormalParameter node) =>
8671 visitNormalFormalParameter(node);
8672
8673 @override
8674 R visitForEachStatement(ForEachStatement node) => visitStatement(node);
8675
8676 R visitFormalParameter(FormalParameter node) => visitNode(node);
8677
8678 @override
8679 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
8680
8681 @override
8682 R visitForStatement(ForStatement node) => visitStatement(node);
8683
8684 R visitFunctionBody(FunctionBody node) => visitNode(node);
8685
8686 @override
8687 R visitFunctionDeclaration(FunctionDeclaration node) =>
8688 visitNamedCompilationUnitMember(node);
8689
8690 @override
8691 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
8692 visitStatement(node);
8693
8694 @override
8695 R visitFunctionExpression(FunctionExpression node) => visitExpression(node);
8696
8697 @override
8698 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
8699 visitExpression(node);
8700
8701 @override
8702 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitTypeAlias(node);
8703
8704 @override
8705 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
8706 visitNormalFormalParameter(node);
8707
8708 @override
8709 R visitHideCombinator(HideCombinator node) => visitCombinator(node);
8710
8711 R visitIdentifier(Identifier node) => visitExpression(node);
8712
8713 @override
8714 R visitIfStatement(IfStatement node) => visitStatement(node);
8715
8716 @override
8717 R visitImplementsClause(ImplementsClause node) => visitNode(node);
8718
8719 @override
8720 R visitImportDirective(ImportDirective node) => visitNamespaceDirective(node);
8721
8722 @override
8723 R visitIndexExpression(IndexExpression node) => visitExpression(node);
8724
8725 @override
8726 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
8727 visitExpression(node);
8728
8729 @override
8730 R visitIntegerLiteral(IntegerLiteral node) => visitLiteral(node);
8731
8732 R visitInterpolationElement(InterpolationElement node) => visitNode(node);
8733
8734 @override
8735 R visitInterpolationExpression(InterpolationExpression node) =>
8736 visitInterpolationElement(node);
8737
8738 @override
8739 R visitInterpolationString(InterpolationString node) =>
8740 visitInterpolationElement(node);
8741
8742 @override
8743 R visitIsExpression(IsExpression node) => visitExpression(node);
8744
8745 @override
8746 R visitLabel(Label node) => visitNode(node);
8747
8748 @override
8749 R visitLabeledStatement(LabeledStatement node) => visitStatement(node);
8750
8751 @override
8752 R visitLibraryDirective(LibraryDirective node) => visitDirective(node);
8753
8754 @override
8755 R visitLibraryIdentifier(LibraryIdentifier node) => visitIdentifier(node);
8756
8757 @override
8758 R visitListLiteral(ListLiteral node) => visitTypedLiteral(node);
8759
8760 R visitLiteral(Literal node) => visitExpression(node);
8761
8762 @override
8763 R visitMapLiteral(MapLiteral node) => visitTypedLiteral(node);
8764
8765 @override
8766 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
8767
8768 @override
8769 R visitMethodDeclaration(MethodDeclaration node) => visitClassMember(node);
8770
8771 @override
8772 R visitMethodInvocation(MethodInvocation node) => visitExpression(node);
8773
8774 R visitNamedCompilationUnitMember(NamedCompilationUnitMember node) =>
8775 visitCompilationUnitMember(node);
8776
8777 @override
8778 R visitNamedExpression(NamedExpression node) => visitExpression(node);
8779
8780 R visitNamespaceDirective(NamespaceDirective node) =>
8781 visitUriBasedDirective(node);
8782
8783 @override
8784 R visitNativeClause(NativeClause node) => visitNode(node);
8785
8786 @override
8787 R visitNativeFunctionBody(NativeFunctionBody node) => visitFunctionBody(node);
8788
8789 R visitNode(AstNode node) {
8790 node.visitChildren(this);
8791 return null;
8792 }
8793
8794 R visitNormalFormalParameter(NormalFormalParameter node) =>
8795 visitFormalParameter(node);
8796
8797 @override
8798 R visitNullLiteral(NullLiteral node) => visitLiteral(node);
8799
8800 @override
8801 R visitParenthesizedExpression(ParenthesizedExpression node) =>
8802 visitExpression(node);
8803
8804 @override
8805 R visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
8806
8807 @override
8808 R visitPartOfDirective(PartOfDirective node) => visitDirective(node);
8809
8810 @override
8811 R visitPostfixExpression(PostfixExpression node) => visitExpression(node);
8812
8813 @override
8814 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitIdentifier(node);
8815
8816 @override
8817 R visitPrefixExpression(PrefixExpression node) => visitExpression(node);
8818
8819 @override
8820 R visitPropertyAccess(PropertyAccess node) => visitExpression(node);
8821
8822 @override
8823 R visitRedirectingConstructorInvocation(
8824 RedirectingConstructorInvocation node) =>
8825 visitConstructorInitializer(node);
8826
8827 @override
8828 R visitRethrowExpression(RethrowExpression node) => visitExpression(node);
8829
8830 @override
8831 R visitReturnStatement(ReturnStatement node) => visitStatement(node);
8832
8833 @override
8834 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
8835
8836 @override
8837 R visitShowCombinator(ShowCombinator node) => visitCombinator(node);
8838
8839 @override
8840 R visitSimpleFormalParameter(SimpleFormalParameter node) =>
8841 visitNormalFormalParameter(node);
8842
8843 @override
8844 R visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node);
8845
8846 @override
8847 R visitSimpleStringLiteral(SimpleStringLiteral node) =>
8848 visitSingleStringLiteral(node);
8849
8850 R visitSingleStringLiteral(SingleStringLiteral node) =>
8851 visitStringLiteral(node);
8852
8853 R visitStatement(Statement node) => visitNode(node);
8854
8855 @override
8856 R visitStringInterpolation(StringInterpolation node) =>
8857 visitSingleStringLiteral(node);
8858
8859 R visitStringLiteral(StringLiteral node) => visitLiteral(node);
8860
8861 @override
8862 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
8863 visitConstructorInitializer(node);
8864
8865 @override
8866 R visitSuperExpression(SuperExpression node) => visitExpression(node);
8867
8868 @override
8869 R visitSwitchCase(SwitchCase node) => visitSwitchMember(node);
8870
8871 @override
8872 R visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
8873
8874 R visitSwitchMember(SwitchMember node) => visitNode(node);
8875
8876 @override
8877 R visitSwitchStatement(SwitchStatement node) => visitStatement(node);
8878
8879 @override
8880 R visitSymbolLiteral(SymbolLiteral node) => visitLiteral(node);
8881
8882 @override
8883 R visitThisExpression(ThisExpression node) => visitExpression(node);
8884
8885 @override
8886 R visitThrowExpression(ThrowExpression node) => visitExpression(node);
8887
8888 @override
8889 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
8890 visitCompilationUnitMember(node);
8891
8892 @override
8893 R visitTryStatement(TryStatement node) => visitStatement(node);
8894
8895 R visitTypeAlias(TypeAlias node) => visitNamedCompilationUnitMember(node);
8896
8897 @override
8898 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
8899
8900 R visitTypedLiteral(TypedLiteral node) => visitLiteral(node);
8901
8902 @override
8903 R visitTypeName(TypeName node) => visitNode(node);
8904
8905 @override
8906 R visitTypeParameter(TypeParameter node) => visitNode(node);
8907
8908 @override
8909 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
8910
8911 R visitUriBasedDirective(UriBasedDirective node) => visitDirective(node);
8912
8913 @override
8914 R visitVariableDeclaration(VariableDeclaration node) =>
8915 visitDeclaration(node);
8916
8917 @override
8918 R visitVariableDeclarationList(VariableDeclarationList node) =>
8919 visitNode(node);
8920
8921 @override
8922 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
8923 visitStatement(node);
8924
8925 @override
8926 R visitWhileStatement(WhileStatement node) => visitStatement(node);
8927
8928 @override
8929 R visitWithClause(WithClause node) => visitNode(node);
8930
8931 @override
8932 R visitYieldStatement(YieldStatement node) => visitStatement(node);
8933 }
8934
8935 class GeneralizingAstVisitor_BreadthFirstVisitor
8936 extends GeneralizingAstVisitor<Object> {
8937 final BreadthFirstVisitor BreadthFirstVisitor_this;
8938
8939 GeneralizingAstVisitor_BreadthFirstVisitor(this.BreadthFirstVisitor_this)
8940 : super();
8941
8942 @override
8943 Object visitNode(AstNode node) {
8944 BreadthFirstVisitor_this._queue.add(node);
8945 return null;
8946 }
8947 }
8948
8949 /**
8950 * A combinator that restricts the names being imported to those that are not in
8951 * a given list.
8952 *
8953 * > hideCombinator ::=
8954 * > 'hide' [SimpleIdentifier] (',' [SimpleIdentifier])*
8955 */
8956 class HideCombinator extends Combinator {
8957 /**
8958 * The list of names from the library that are hidden by this combinator.
8959 */
8960 NodeList<SimpleIdentifier> _hiddenNames;
8961
8962 /**
8963 * Initialize a newly created import show combinator.
8964 */
8965 HideCombinator(Token keyword, List<SimpleIdentifier> hiddenNames)
8966 : super(keyword) {
8967 _hiddenNames = new NodeList<SimpleIdentifier>(this, hiddenNames);
8968 }
8969
8970 @override
8971 Iterable get childEntities => new ChildEntities()
8972 ..add(keyword)
8973 ..addAll(_hiddenNames);
8974
8975 @override
8976 Token get endToken => _hiddenNames.endToken;
8977
8978 /**
8979 * Return the list of names from the library that are hidden by this
8980 * combinator.
8981 */
8982 NodeList<SimpleIdentifier> get hiddenNames => _hiddenNames;
8983
8984 @override
8985 accept(AstVisitor visitor) => visitor.visitHideCombinator(this);
8986
8987 @override
8988 void visitChildren(AstVisitor visitor) {
8989 _hiddenNames.accept(visitor);
8990 }
8991 }
8992
8993 /**
8994 * A node that represents an identifier.
8995 *
8996 * > identifier ::=
8997 * > [SimpleIdentifier]
8998 * > | [PrefixedIdentifier]
8999 */
9000 abstract class Identifier extends Expression {
9001 /**
9002 * Return the best element available for this operator. If resolution was able
9003 * to find a better element based on type propagation, that element will be
9004 * returned. Otherwise, the element found using the result of static analysis
9005 * will be returned. If resolution has not been performed, then `null` will be
9006 * returned.
9007 */
9008 Element get bestElement;
9009
9010 @override
9011 bool get isAssignable => true;
9012
9013 /**
9014 * Return the lexical representation of the identifier.
9015 */
9016 String get name;
9017
9018 /**
9019 * Return the element associated with this identifier based on propagated type
9020 * information, or `null` if the AST structure has not been resolved or if
9021 * this identifier could not be resolved. One example of the latter case is an
9022 * identifier that is not defined within the scope in which it appears.
9023 */
9024 Element get propagatedElement;
9025
9026 /**
9027 * Return the element associated with this identifier based on static type
9028 * information, or `null` if the AST structure has not been resolved or if
9029 * this identifier could not be resolved. One example of the latter case is an
9030 * identifier that is not defined within the scope in which it appears
9031 */
9032 Element get staticElement;
9033
9034 /**
9035 * Return `true` if the given [name] is visible only within the library in
9036 * which it is declared.
9037 */
9038 static bool isPrivateName(String name) =>
9039 StringUtilities.startsWithChar(name, 0x5F);
9040 }
9041
9042 /**
9043 * An if statement.
9044 *
9045 * > ifStatement ::=
9046 * > 'if' '(' [Expression] ')' [Statement] ('else' [Statement])?
9047 */
9048 class IfStatement extends Statement {
9049 /**
9050 * The token representing the 'if' keyword.
9051 */
9052 Token ifKeyword;
9053
9054 /**
9055 * The left parenthesis.
9056 */
9057 Token leftParenthesis;
9058
9059 /**
9060 * The condition used to determine which of the statements is executed next.
9061 */
9062 Expression _condition;
9063
9064 /**
9065 * The right parenthesis.
9066 */
9067 Token rightParenthesis;
9068
9069 /**
9070 * The statement that is executed if the condition evaluates to `true`.
9071 */
9072 Statement _thenStatement;
9073
9074 /**
9075 * The token representing the 'else' keyword, or `null` if there is no else
9076 * statement.
9077 */
9078 Token elseKeyword;
9079
9080 /**
9081 * The statement that is executed if the condition evaluates to `false`, or
9082 * `null` if there is no else statement.
9083 */
9084 Statement _elseStatement;
9085
9086 /**
9087 * Initialize a newly created if statement. The [elseKeyword] and
9088 * [elseStatement] can be `null` if there is no else clause.
9089 */
9090 IfStatement(this.ifKeyword, this.leftParenthesis, Expression condition,
9091 this.rightParenthesis, Statement thenStatement, this.elseKeyword,
9092 Statement elseStatement) {
9093 _condition = _becomeParentOf(condition);
9094 _thenStatement = _becomeParentOf(thenStatement);
9095 _elseStatement = _becomeParentOf(elseStatement);
9096 }
9097
9098 @override
9099 Token get beginToken => ifKeyword;
9100
9101 @override
9102 Iterable get childEntities => new ChildEntities()
9103 ..add(ifKeyword)
9104 ..add(leftParenthesis)
9105 ..add(_condition)
9106 ..add(rightParenthesis)
9107 ..add(_thenStatement)
9108 ..add(elseKeyword)
9109 ..add(_elseStatement);
9110
9111 /**
9112 * Return the condition used to determine which of the statements is executed
9113 * next.
9114 */
9115 Expression get condition => _condition;
9116
9117 /**
9118 * Set the condition used to determine which of the statements is executed
9119 * next to the given [expression].
9120 */
9121 void set condition(Expression expression) {
9122 _condition = _becomeParentOf(expression);
9123 }
9124
9125 /**
9126 * Return the statement that is executed if the condition evaluates to
9127 * `false`, or `null` if there is no else statement.
9128 */
9129 Statement get elseStatement => _elseStatement;
9130
9131 /**
9132 * Set the statement that is executed if the condition evaluates to `false`
9133 * to the given [statement].
9134 */
9135 void set elseStatement(Statement statement) {
9136 _elseStatement = _becomeParentOf(statement);
9137 }
9138
9139 @override
9140 Token get endToken {
9141 if (_elseStatement != null) {
9142 return _elseStatement.endToken;
9143 }
9144 return _thenStatement.endToken;
9145 }
9146
9147 /**
9148 * Return the statement that is executed if the condition evaluates to `true`.
9149 */
9150 Statement get thenStatement => _thenStatement;
9151
9152 /**
9153 * Set the statement that is executed if the condition evaluates to `true` to
9154 * the given [statement].
9155 */
9156 void set thenStatement(Statement statement) {
9157 _thenStatement = _becomeParentOf(statement);
9158 }
9159
9160 @override
9161 accept(AstVisitor visitor) => visitor.visitIfStatement(this);
9162
9163 @override
9164 void visitChildren(AstVisitor visitor) {
9165 _safelyVisitChild(_condition, visitor);
9166 _safelyVisitChild(_thenStatement, visitor);
9167 _safelyVisitChild(_elseStatement, visitor);
9168 }
9169 }
9170
9171 /**
9172 * The "implements" clause in an class declaration.
9173 *
9174 * > implementsClause ::=
9175 * > 'implements' [TypeName] (',' [TypeName])*
9176 */
9177 class ImplementsClause extends AstNode {
9178 /**
9179 * The token representing the 'implements' keyword.
9180 */
9181 Token implementsKeyword;
9182
9183 /**
9184 * The interfaces that are being implemented.
9185 */
9186 NodeList<TypeName> _interfaces;
9187
9188 /**
9189 * Initialize a newly created implements clause.
9190 */
9191 ImplementsClause(this.implementsKeyword, List<TypeName> interfaces) {
9192 _interfaces = new NodeList<TypeName>(this, interfaces);
9193 }
9194
9195 @override
9196 Token get beginToken => implementsKeyword;
9197
9198 /**
9199 * TODO(paulberry): add commas.
9200 */
9201 @override
9202 Iterable get childEntities => new ChildEntities()
9203 ..add(implementsKeyword)
9204 ..addAll(interfaces);
9205
9206 @override
9207 Token get endToken => _interfaces.endToken;
9208
9209 /**
9210 * Return the list of the interfaces that are being implemented.
9211 */
9212 NodeList<TypeName> get interfaces => _interfaces;
9213
9214 /**
9215 * Return the token representing the 'implements' keyword.
9216 */
9217 @deprecated // Use "this.implementsKeyword"
9218 Token get keyword => implementsKeyword;
9219
9220 /**
9221 * Set the token representing the 'implements' keyword to the given [token].
9222 */
9223 @deprecated // Use "this.implementsKeyword"
9224 set keyword(Token token) {
9225 implementsKeyword = token;
9226 }
9227
9228 @override
9229 accept(AstVisitor visitor) => visitor.visitImplementsClause(this);
9230
9231 @override
9232 void visitChildren(AstVisitor visitor) {
9233 _interfaces.accept(visitor);
9234 }
9235 }
9236
9237 /**
9238 * An import directive.
9239 *
9240 * > importDirective ::=
9241 * > [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* ';'
9242 * > | [Annotation] 'import' [StringLiteral] 'deferred' 'as' identifier [Combi nator]* ';'
9243 */
9244 class ImportDirective extends NamespaceDirective {
9245 static Comparator<ImportDirective> COMPARATOR = (ImportDirective import1,
9246 ImportDirective import2) {
9247 //
9248 // uri
9249 //
9250 StringLiteral uri1 = import1.uri;
9251 StringLiteral uri2 = import2.uri;
9252 String uriStr1 = uri1.stringValue;
9253 String uriStr2 = uri2.stringValue;
9254 if (uriStr1 != null || uriStr2 != null) {
9255 if (uriStr1 == null) {
9256 return -1;
9257 } else if (uriStr2 == null) {
9258 return 1;
9259 } else {
9260 int compare = uriStr1.compareTo(uriStr2);
9261 if (compare != 0) {
9262 return compare;
9263 }
9264 }
9265 }
9266 //
9267 // as
9268 //
9269 SimpleIdentifier prefix1 = import1.prefix;
9270 SimpleIdentifier prefix2 = import2.prefix;
9271 String prefixStr1 = prefix1 != null ? prefix1.name : null;
9272 String prefixStr2 = prefix2 != null ? prefix2.name : null;
9273 if (prefixStr1 != null || prefixStr2 != null) {
9274 if (prefixStr1 == null) {
9275 return -1;
9276 } else if (prefixStr2 == null) {
9277 return 1;
9278 } else {
9279 int compare = prefixStr1.compareTo(prefixStr2);
9280 if (compare != 0) {
9281 return compare;
9282 }
9283 }
9284 }
9285 //
9286 // hides and shows
9287 //
9288 NodeList<Combinator> combinators1 = import1.combinators;
9289 List<String> allHides1 = new List<String>();
9290 List<String> allShows1 = new List<String>();
9291 for (Combinator combinator in combinators1) {
9292 if (combinator is HideCombinator) {
9293 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9294 for (SimpleIdentifier simpleIdentifier in hides) {
9295 allHides1.add(simpleIdentifier.name);
9296 }
9297 } else {
9298 NodeList<SimpleIdentifier> shows =
9299 (combinator as ShowCombinator).shownNames;
9300 for (SimpleIdentifier simpleIdentifier in shows) {
9301 allShows1.add(simpleIdentifier.name);
9302 }
9303 }
9304 }
9305 NodeList<Combinator> combinators2 = import2.combinators;
9306 List<String> allHides2 = new List<String>();
9307 List<String> allShows2 = new List<String>();
9308 for (Combinator combinator in combinators2) {
9309 if (combinator is HideCombinator) {
9310 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
9311 for (SimpleIdentifier simpleIdentifier in hides) {
9312 allHides2.add(simpleIdentifier.name);
9313 }
9314 } else {
9315 NodeList<SimpleIdentifier> shows =
9316 (combinator as ShowCombinator).shownNames;
9317 for (SimpleIdentifier simpleIdentifier in shows) {
9318 allShows2.add(simpleIdentifier.name);
9319 }
9320 }
9321 }
9322 // test lengths of combinator lists first
9323 if (allHides1.length != allHides2.length) {
9324 return allHides1.length - allHides2.length;
9325 }
9326 if (allShows1.length != allShows2.length) {
9327 return allShows1.length - allShows2.length;
9328 }
9329 // next ensure that the lists are equivalent
9330 if (!javaCollectionContainsAll(allHides1, allHides2)) {
9331 return -1;
9332 }
9333 if (!javaCollectionContainsAll(allShows1, allShows2)) {
9334 return -1;
9335 }
9336 return 0;
9337 };
9338
9339 /**
9340 * The token representing the 'deferred' keyword, or `null` if the imported is
9341 * not deferred.
9342 */
9343 Token deferredKeyword;
9344
9345 /**
9346 * The token representing the 'as' keyword, or `null` if the imported names ar e
9347 * not prefixed.
9348 */
9349 Token asKeyword;
9350
9351 /**
9352 * The prefix to be used with the imported names, or `null` if the imported
9353 * names are not prefixed.
9354 */
9355 SimpleIdentifier _prefix;
9356
9357 /**
9358 * Initialize a newly created import directive. Either or both of the
9359 * [comment] and [metadata] can be `null` if the function does not have the
9360 * corresponding attribute. The [deferredKeyword] can be `null` if the import
9361 * is not deferred. The [asKeyword] and [prefix] can be `null` if the import
9362 * does not specify a prefix. The list of [combinators] can be `null` if there
9363 * are no combinators.
9364 */
9365 ImportDirective(Comment comment, List<Annotation> metadata, Token keyword,
9366 StringLiteral libraryUri, this.deferredKeyword, this.asKeyword,
9367 SimpleIdentifier prefix, List<Combinator> combinators, Token semicolon)
9368 : super(comment, metadata, keyword, libraryUri, combinators, semicolon) {
9369 _prefix = _becomeParentOf(prefix);
9370 }
9371
9372 /**
9373 * The token representing the 'as' token, or `null` if the imported names are
9374 * not prefixed.
9375 */
9376 @deprecated // Use "this.asKeyword"
9377 Token get asToken => asKeyword;
9378
9379 /**
9380 * The token representing the 'as' token to the given token.
9381 */
9382 @deprecated // Use "this.asKeyword"
9383 set asToken(Token token) {
9384 asKeyword = token;
9385 }
9386
9387 @override
9388 Iterable get childEntities => super._childEntities
9389 ..add(_uri)
9390 ..add(deferredKeyword)
9391 ..add(asKeyword)
9392 ..add(_prefix)
9393 ..addAll(combinators)
9394 ..add(semicolon);
9395
9396 /**
9397 * Return the token representing the 'deferred' token, or `null` if the
9398 * imported is not deferred.
9399 */
9400 @deprecated // Use "this.deferredKeyword"
9401 Token get deferredToken => deferredKeyword;
9402
9403 /**
9404 * Set the token representing the 'deferred' token to the given token.
9405 */
9406 @deprecated // Use "this.deferredKeyword"
9407 set deferredToken(Token token) {
9408 deferredKeyword = token;
9409 }
9410
9411 @override
9412 ImportElement get element => super.element as ImportElement;
9413
9414 /**
9415 * Return the prefix to be used with the imported names, or `null` if the
9416 * imported names are not prefixed.
9417 */
9418 SimpleIdentifier get prefix => _prefix;
9419
9420 /**
9421 * Set the prefix to be used with the imported names to the given [identifier] .
9422 */
9423 void set prefix(SimpleIdentifier identifier) {
9424 _prefix = _becomeParentOf(identifier);
9425 }
9426
9427 @override
9428 LibraryElement get uriElement {
9429 ImportElement element = this.element;
9430 if (element == null) {
9431 return null;
9432 }
9433 return element.importedLibrary;
9434 }
9435
9436 @override
9437 accept(AstVisitor visitor) => visitor.visitImportDirective(this);
9438
9439 @override
9440 void visitChildren(AstVisitor visitor) {
9441 super.visitChildren(visitor);
9442 _safelyVisitChild(_prefix, visitor);
9443 combinators.accept(visitor);
9444 }
9445 }
9446
9447 /**
9448 * An object that will clone any AST structure that it visits. The cloner will
9449 * clone the structure, replacing the specified ASTNode with a new ASTNode,
9450 * mapping the old token stream to a new token stream, and preserving resolution
9451 * results.
9452 */
9453 class IncrementalAstCloner implements AstVisitor<AstNode> {
9454 /**
9455 * The node to be replaced during the cloning process.
9456 */
9457 final AstNode _oldNode;
9458
9459 /**
9460 * The replacement node used during the cloning process.
9461 */
9462 final AstNode _newNode;
9463
9464 /**
9465 * A mapping of old tokens to new tokens used during the cloning process.
9466 */
9467 final TokenMap _tokenMap;
9468
9469 /**
9470 * Construct a new instance that will replace the [oldNode] with the [newNode]
9471 * in the process of cloning an existing AST structure. The [tokenMap] is a
9472 * mapping of old tokens to new tokens.
9473 */
9474 IncrementalAstCloner(this._oldNode, this._newNode, this._tokenMap);
9475
9476 @override
9477 AdjacentStrings visitAdjacentStrings(AdjacentStrings node) =>
9478 new AdjacentStrings(_cloneNodeList(node.strings));
9479
9480 @override
9481 Annotation visitAnnotation(Annotation node) {
9482 Annotation copy = new Annotation(_mapToken(node.atSign),
9483 _cloneNode(node.name), _mapToken(node.period),
9484 _cloneNode(node.constructorName), _cloneNode(node.arguments));
9485 copy.element = node.element;
9486 return copy;
9487 }
9488
9489 @override
9490 ArgumentList visitArgumentList(ArgumentList node) => new ArgumentList(
9491 _mapToken(node.leftParenthesis), _cloneNodeList(node.arguments),
9492 _mapToken(node.rightParenthesis));
9493
9494 @override
9495 AsExpression visitAsExpression(AsExpression node) {
9496 AsExpression copy = new AsExpression(_cloneNode(node.expression),
9497 _mapToken(node.asOperator), _cloneNode(node.type));
9498 copy.propagatedType = node.propagatedType;
9499 copy.staticType = node.staticType;
9500 return copy;
9501 }
9502
9503 @override
9504 AstNode visitAssertStatement(AssertStatement node) => new AssertStatement(
9505 _mapToken(node.assertKeyword), _mapToken(node.leftParenthesis),
9506 _cloneNode(node.condition), _mapToken(node.rightParenthesis),
9507 _mapToken(node.semicolon));
9508
9509 @override
9510 AssignmentExpression visitAssignmentExpression(AssignmentExpression node) {
9511 AssignmentExpression copy = new AssignmentExpression(
9512 _cloneNode(node.leftHandSide), _mapToken(node.operator),
9513 _cloneNode(node.rightHandSide));
9514 copy.propagatedElement = node.propagatedElement;
9515 copy.propagatedType = node.propagatedType;
9516 copy.staticElement = node.staticElement;
9517 copy.staticType = node.staticType;
9518 return copy;
9519 }
9520
9521 @override
9522 AwaitExpression visitAwaitExpression(AwaitExpression node) =>
9523 new AwaitExpression(
9524 _mapToken(node.awaitKeyword), _cloneNode(node.expression));
9525
9526 @override
9527 BinaryExpression visitBinaryExpression(BinaryExpression node) {
9528 BinaryExpression copy = new BinaryExpression(_cloneNode(node.leftOperand),
9529 _mapToken(node.operator), _cloneNode(node.rightOperand));
9530 copy.propagatedElement = node.propagatedElement;
9531 copy.propagatedType = node.propagatedType;
9532 copy.staticElement = node.staticElement;
9533 copy.staticType = node.staticType;
9534 return copy;
9535 }
9536
9537 @override
9538 Block visitBlock(Block node) => new Block(_mapToken(node.leftBracket),
9539 _cloneNodeList(node.statements), _mapToken(node.rightBracket));
9540
9541 @override
9542 BlockFunctionBody visitBlockFunctionBody(
9543 BlockFunctionBody node) => new BlockFunctionBody(
9544 _mapToken(node.keyword), _mapToken(node.star), _cloneNode(node.block));
9545
9546 @override
9547 BooleanLiteral visitBooleanLiteral(BooleanLiteral node) {
9548 BooleanLiteral copy =
9549 new BooleanLiteral(_mapToken(node.literal), node.value);
9550 copy.propagatedType = node.propagatedType;
9551 copy.staticType = node.staticType;
9552 return copy;
9553 }
9554
9555 @override
9556 BreakStatement visitBreakStatement(BreakStatement node) => new BreakStatement(
9557 _mapToken(node.breakKeyword), _cloneNode(node.label),
9558 _mapToken(node.semicolon));
9559
9560 @override
9561 CascadeExpression visitCascadeExpression(CascadeExpression node) {
9562 CascadeExpression copy = new CascadeExpression(
9563 _cloneNode(node.target), _cloneNodeList(node.cascadeSections));
9564 copy.propagatedType = node.propagatedType;
9565 copy.staticType = node.staticType;
9566 return copy;
9567 }
9568
9569 @override
9570 CatchClause visitCatchClause(CatchClause node) => new CatchClause(
9571 _mapToken(node.onKeyword), _cloneNode(node.exceptionType),
9572 _mapToken(node.catchKeyword), _mapToken(node.leftParenthesis),
9573 _cloneNode(node.exceptionParameter), _mapToken(node.comma),
9574 _cloneNode(node.stackTraceParameter), _mapToken(node.rightParenthesis),
9575 _cloneNode(node.body));
9576
9577 @override
9578 ClassDeclaration visitClassDeclaration(ClassDeclaration node) {
9579 ClassDeclaration copy = new ClassDeclaration(
9580 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9581 _mapToken(node.abstractKeyword), _mapToken(node.classKeyword),
9582 _cloneNode(node.name), _cloneNode(node.typeParameters),
9583 _cloneNode(node.extendsClause), _cloneNode(node.withClause),
9584 _cloneNode(node.implementsClause), _mapToken(node.leftBracket),
9585 _cloneNodeList(node.members), _mapToken(node.rightBracket));
9586 copy.nativeClause = _cloneNode(node.nativeClause);
9587 return copy;
9588 }
9589
9590 @override
9591 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) => new ClassTypeAlias(
9592 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9593 _mapToken(node.typedefKeyword), _cloneNode(node.name),
9594 _cloneNode(node.typeParameters), _mapToken(node.equals),
9595 _mapToken(node.abstractKeyword), _cloneNode(node.superclass),
9596 _cloneNode(node.withClause), _cloneNode(node.implementsClause),
9597 _mapToken(node.semicolon));
9598
9599 @override
9600 Comment visitComment(Comment node) {
9601 if (node.isDocumentation) {
9602 return Comment.createDocumentationCommentWithReferences(
9603 _mapTokens(node.tokens), _cloneNodeList(node.references));
9604 } else if (node.isBlock) {
9605 return Comment.createBlockComment(_mapTokens(node.tokens));
9606 }
9607 return Comment.createEndOfLineComment(_mapTokens(node.tokens));
9608 }
9609
9610 @override
9611 CommentReference visitCommentReference(CommentReference node) =>
9612 new CommentReference(
9613 _mapToken(node.newKeyword), _cloneNode(node.identifier));
9614
9615 @override
9616 CompilationUnit visitCompilationUnit(CompilationUnit node) {
9617 CompilationUnit copy = new CompilationUnit(_mapToken(node.beginToken),
9618 _cloneNode(node.scriptTag), _cloneNodeList(node.directives),
9619 _cloneNodeList(node.declarations), _mapToken(node.endToken));
9620 copy.lineInfo = node.lineInfo;
9621 copy.element = node.element;
9622 return copy;
9623 }
9624
9625 @override
9626 ConditionalExpression visitConditionalExpression(ConditionalExpression node) {
9627 ConditionalExpression copy = new ConditionalExpression(
9628 _cloneNode(node.condition), _mapToken(node.question),
9629 _cloneNode(node.thenExpression), _mapToken(node.colon),
9630 _cloneNode(node.elseExpression));
9631 copy.propagatedType = node.propagatedType;
9632 copy.staticType = node.staticType;
9633 return copy;
9634 }
9635
9636 @override
9637 ConstructorDeclaration visitConstructorDeclaration(
9638 ConstructorDeclaration node) {
9639 ConstructorDeclaration copy = new ConstructorDeclaration(
9640 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9641 _mapToken(node.externalKeyword), _mapToken(node.constKeyword),
9642 _mapToken(node.factoryKeyword), _cloneNode(node.returnType),
9643 _mapToken(node.period), _cloneNode(node.name),
9644 _cloneNode(node.parameters), _mapToken(node.separator),
9645 _cloneNodeList(node.initializers),
9646 _cloneNode(node.redirectedConstructor), _cloneNode(node.body));
9647 copy.element = node.element;
9648 return copy;
9649 }
9650
9651 @override
9652 ConstructorFieldInitializer visitConstructorFieldInitializer(
9653 ConstructorFieldInitializer node) => new ConstructorFieldInitializer(
9654 _mapToken(node.thisKeyword), _mapToken(node.period),
9655 _cloneNode(node.fieldName), _mapToken(node.equals),
9656 _cloneNode(node.expression));
9657
9658 @override
9659 ConstructorName visitConstructorName(ConstructorName node) {
9660 ConstructorName copy = new ConstructorName(
9661 _cloneNode(node.type), _mapToken(node.period), _cloneNode(node.name));
9662 copy.staticElement = node.staticElement;
9663 return copy;
9664 }
9665
9666 @override
9667 ContinueStatement visitContinueStatement(ContinueStatement node) =>
9668 new ContinueStatement(_mapToken(node.continueKeyword),
9669 _cloneNode(node.label), _mapToken(node.semicolon));
9670
9671 @override
9672 DeclaredIdentifier visitDeclaredIdentifier(DeclaredIdentifier node) =>
9673 new DeclaredIdentifier(_cloneNode(node.documentationComment),
9674 _cloneNodeList(node.metadata), _mapToken(node.keyword),
9675 _cloneNode(node.type), _cloneNode(node.identifier));
9676
9677 @override
9678 DefaultFormalParameter visitDefaultFormalParameter(
9679 DefaultFormalParameter node) => new DefaultFormalParameter(
9680 _cloneNode(node.parameter), node.kind, _mapToken(node.separator),
9681 _cloneNode(node.defaultValue));
9682
9683 @override
9684 DoStatement visitDoStatement(DoStatement node) => new DoStatement(
9685 _mapToken(node.doKeyword), _cloneNode(node.body),
9686 _mapToken(node.whileKeyword), _mapToken(node.leftParenthesis),
9687 _cloneNode(node.condition), _mapToken(node.rightParenthesis),
9688 _mapToken(node.semicolon));
9689
9690 @override
9691 DoubleLiteral visitDoubleLiteral(DoubleLiteral node) {
9692 DoubleLiteral copy = new DoubleLiteral(_mapToken(node.literal), node.value);
9693 copy.propagatedType = node.propagatedType;
9694 copy.staticType = node.staticType;
9695 return copy;
9696 }
9697
9698 @override
9699 EmptyFunctionBody visitEmptyFunctionBody(EmptyFunctionBody node) =>
9700 new EmptyFunctionBody(_mapToken(node.semicolon));
9701
9702 @override
9703 EmptyStatement visitEmptyStatement(EmptyStatement node) =>
9704 new EmptyStatement(_mapToken(node.semicolon));
9705
9706 @override
9707 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
9708 new EnumConstantDeclaration(_cloneNode(node.documentationComment),
9709 _cloneNodeList(node.metadata), _cloneNode(node.name));
9710
9711 @override
9712 AstNode visitEnumDeclaration(EnumDeclaration node) => new EnumDeclaration(
9713 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9714 _mapToken(node.enumKeyword), _cloneNode(node.name),
9715 _mapToken(node.leftBracket), _cloneNodeList(node.constants),
9716 _mapToken(node.rightBracket));
9717
9718 @override
9719 ExportDirective visitExportDirective(ExportDirective node) {
9720 ExportDirective copy = new ExportDirective(
9721 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9722 _mapToken(node.keyword), _cloneNode(node.uri),
9723 _cloneNodeList(node.combinators), _mapToken(node.semicolon));
9724 copy.element = node.element;
9725 return copy;
9726 }
9727
9728 @override
9729 ExpressionFunctionBody visitExpressionFunctionBody(
9730 ExpressionFunctionBody node) => new ExpressionFunctionBody(
9731 _mapToken(node.keyword), _mapToken(node.functionDefinition),
9732 _cloneNode(node.expression), _mapToken(node.semicolon));
9733
9734 @override
9735 ExpressionStatement visitExpressionStatement(ExpressionStatement node) =>
9736 new ExpressionStatement(
9737 _cloneNode(node.expression), _mapToken(node.semicolon));
9738
9739 @override
9740 ExtendsClause visitExtendsClause(ExtendsClause node) => new ExtendsClause(
9741 _mapToken(node.extendsKeyword), _cloneNode(node.superclass));
9742
9743 @override
9744 FieldDeclaration visitFieldDeclaration(FieldDeclaration node) =>
9745 new FieldDeclaration(_cloneNode(node.documentationComment),
9746 _cloneNodeList(node.metadata), _mapToken(node.staticKeyword),
9747 _cloneNode(node.fields), _mapToken(node.semicolon));
9748
9749 @override
9750 FieldFormalParameter visitFieldFormalParameter(FieldFormalParameter node) =>
9751 new FieldFormalParameter(_cloneNode(node.documentationComment),
9752 _cloneNodeList(node.metadata), _mapToken(node.keyword),
9753 _cloneNode(node.type), _mapToken(node.thisKeyword),
9754 _mapToken(node.period), _cloneNode(node.identifier),
9755 _cloneNode(node.typeParameters), _cloneNode(node.parameters));
9756
9757 @override
9758 ForEachStatement visitForEachStatement(ForEachStatement node) {
9759 DeclaredIdentifier loopVariable = node.loopVariable;
9760 if (loopVariable == null) {
9761 return new ForEachStatement.withReference(_mapToken(node.awaitKeyword),
9762 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis),
9763 _cloneNode(node.identifier), _mapToken(node.inKeyword),
9764 _cloneNode(node.iterable), _mapToken(node.rightParenthesis),
9765 _cloneNode(node.body));
9766 }
9767 return new ForEachStatement.withDeclaration(_mapToken(node.awaitKeyword),
9768 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis),
9769 _cloneNode(loopVariable), _mapToken(node.inKeyword),
9770 _cloneNode(node.iterable), _mapToken(node.rightParenthesis),
9771 _cloneNode(node.body));
9772 }
9773
9774 @override
9775 FormalParameterList visitFormalParameterList(FormalParameterList node) =>
9776 new FormalParameterList(_mapToken(node.leftParenthesis),
9777 _cloneNodeList(node.parameters), _mapToken(node.leftDelimiter),
9778 _mapToken(node.rightDelimiter), _mapToken(node.rightParenthesis));
9779
9780 @override
9781 ForStatement visitForStatement(ForStatement node) => new ForStatement(
9782 _mapToken(node.forKeyword), _mapToken(node.leftParenthesis),
9783 _cloneNode(node.variables), _cloneNode(node.initialization),
9784 _mapToken(node.leftSeparator), _cloneNode(node.condition),
9785 _mapToken(node.rightSeparator), _cloneNodeList(node.updaters),
9786 _mapToken(node.rightParenthesis), _cloneNode(node.body));
9787
9788 @override
9789 FunctionDeclaration visitFunctionDeclaration(FunctionDeclaration node) =>
9790 new FunctionDeclaration(_cloneNode(node.documentationComment),
9791 _cloneNodeList(node.metadata), _mapToken(node.externalKeyword),
9792 _cloneNode(node.returnType), _mapToken(node.propertyKeyword),
9793 _cloneNode(node.name), _cloneNode(node.functionExpression));
9794
9795 @override
9796 FunctionDeclarationStatement visitFunctionDeclarationStatement(
9797 FunctionDeclarationStatement node) =>
9798 new FunctionDeclarationStatement(_cloneNode(node.functionDeclaration));
9799
9800 @override
9801 FunctionExpression visitFunctionExpression(FunctionExpression node) {
9802 FunctionExpression copy = new FunctionExpression(
9803 _cloneNode(node.typeParameters), _cloneNode(node.parameters),
9804 _cloneNode(node.body));
9805 copy.element = node.element;
9806 copy.propagatedType = node.propagatedType;
9807 copy.staticType = node.staticType;
9808 return copy;
9809 }
9810
9811 @override
9812 FunctionExpressionInvocation visitFunctionExpressionInvocation(
9813 FunctionExpressionInvocation node) {
9814 FunctionExpressionInvocation copy = new FunctionExpressionInvocation(
9815 _cloneNode(node.function), _cloneNode(node.typeArguments),
9816 _cloneNode(node.argumentList));
9817 copy.propagatedElement = node.propagatedElement;
9818 copy.propagatedType = node.propagatedType;
9819 copy.staticElement = node.staticElement;
9820 copy.staticType = node.staticType;
9821 return copy;
9822 }
9823
9824 @override
9825 FunctionTypeAlias visitFunctionTypeAlias(FunctionTypeAlias node) =>
9826 new FunctionTypeAlias(_cloneNode(node.documentationComment),
9827 _cloneNodeList(node.metadata), _mapToken(node.typedefKeyword),
9828 _cloneNode(node.returnType), _cloneNode(node.name),
9829 _cloneNode(node.typeParameters), _cloneNode(node.parameters),
9830 _mapToken(node.semicolon));
9831
9832 @override
9833 FunctionTypedFormalParameter visitFunctionTypedFormalParameter(
9834 FunctionTypedFormalParameter node) => new FunctionTypedFormalParameter(
9835 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
9836 _cloneNode(node.returnType), _cloneNode(node.identifier),
9837 _cloneNode(node.typeParameters), _cloneNode(node.parameters));
9838
9839 @override
9840 HideCombinator visitHideCombinator(HideCombinator node) => new HideCombinator(
9841 _mapToken(node.keyword), _cloneNodeList(node.hiddenNames));
9842
9843 @override
9844 IfStatement visitIfStatement(IfStatement node) => new IfStatement(
9845 _mapToken(node.ifKeyword), _mapToken(node.leftParenthesis),
9846 _cloneNode(node.condition), _mapToken(node.rightParenthesis),
9847 _cloneNode(node.thenStatement), _mapToken(node.elseKeyword),
9848 _cloneNode(node.elseStatement));
9849
9850 @override
9851 ImplementsClause visitImplementsClause(ImplementsClause node) =>
9852 new ImplementsClause(
9853 _mapToken(node.implementsKeyword), _cloneNodeList(node.interfaces));
9854
9855 @override
9856 ImportDirective visitImportDirective(ImportDirective node) =>
9857 new ImportDirective(_cloneNode(node.documentationComment),
9858 _cloneNodeList(node.metadata), _mapToken(node.keyword),
9859 _cloneNode(node.uri), _mapToken(node.deferredKeyword),
9860 _mapToken(node.asKeyword), _cloneNode(node.prefix),
9861 _cloneNodeList(node.combinators), _mapToken(node.semicolon));
9862
9863 @override
9864 IndexExpression visitIndexExpression(IndexExpression node) {
9865 Token period = _mapToken(node.period);
9866 IndexExpression copy;
9867 if (period == null) {
9868 copy = new IndexExpression.forTarget(_cloneNode(node.target),
9869 _mapToken(node.leftBracket), _cloneNode(node.index),
9870 _mapToken(node.rightBracket));
9871 } else {
9872 copy = new IndexExpression.forCascade(period, _mapToken(node.leftBracket),
9873 _cloneNode(node.index), _mapToken(node.rightBracket));
9874 }
9875 copy.auxiliaryElements = node.auxiliaryElements;
9876 copy.propagatedElement = node.propagatedElement;
9877 copy.propagatedType = node.propagatedType;
9878 copy.staticElement = node.staticElement;
9879 copy.staticType = node.staticType;
9880 return copy;
9881 }
9882
9883 @override
9884 InstanceCreationExpression visitInstanceCreationExpression(
9885 InstanceCreationExpression node) {
9886 InstanceCreationExpression copy = new InstanceCreationExpression(
9887 _mapToken(node.keyword), _cloneNode(node.constructorName),
9888 _cloneNode(node.argumentList));
9889 copy.propagatedType = node.propagatedType;
9890 copy.staticElement = node.staticElement;
9891 copy.staticType = node.staticType;
9892 return copy;
9893 }
9894
9895 @override
9896 IntegerLiteral visitIntegerLiteral(IntegerLiteral node) {
9897 IntegerLiteral copy =
9898 new IntegerLiteral(_mapToken(node.literal), node.value);
9899 copy.propagatedType = node.propagatedType;
9900 copy.staticType = node.staticType;
9901 return copy;
9902 }
9903
9904 @override
9905 InterpolationExpression visitInterpolationExpression(
9906 InterpolationExpression node) => new InterpolationExpression(
9907 _mapToken(node.leftBracket), _cloneNode(node.expression),
9908 _mapToken(node.rightBracket));
9909
9910 @override
9911 InterpolationString visitInterpolationString(InterpolationString node) =>
9912 new InterpolationString(_mapToken(node.contents), node.value);
9913
9914 @override
9915 IsExpression visitIsExpression(IsExpression node) {
9916 IsExpression copy = new IsExpression(_cloneNode(node.expression),
9917 _mapToken(node.isOperator), _mapToken(node.notOperator),
9918 _cloneNode(node.type));
9919 copy.propagatedType = node.propagatedType;
9920 copy.staticType = node.staticType;
9921 return copy;
9922 }
9923
9924 @override
9925 Label visitLabel(Label node) =>
9926 new Label(_cloneNode(node.label), _mapToken(node.colon));
9927
9928 @override
9929 LabeledStatement visitLabeledStatement(LabeledStatement node) =>
9930 new LabeledStatement(
9931 _cloneNodeList(node.labels), _cloneNode(node.statement));
9932
9933 @override
9934 LibraryDirective visitLibraryDirective(LibraryDirective node) =>
9935 new LibraryDirective(_cloneNode(node.documentationComment),
9936 _cloneNodeList(node.metadata), _mapToken(node.libraryKeyword),
9937 _cloneNode(node.name), _mapToken(node.semicolon));
9938
9939 @override
9940 LibraryIdentifier visitLibraryIdentifier(LibraryIdentifier node) {
9941 LibraryIdentifier copy =
9942 new LibraryIdentifier(_cloneNodeList(node.components));
9943 copy.propagatedType = node.propagatedType;
9944 copy.staticType = node.staticType;
9945 return copy;
9946 }
9947
9948 @override
9949 ListLiteral visitListLiteral(ListLiteral node) {
9950 ListLiteral copy = new ListLiteral(_mapToken(node.constKeyword),
9951 _cloneNode(node.typeArguments), _mapToken(node.leftBracket),
9952 _cloneNodeList(node.elements), _mapToken(node.rightBracket));
9953 copy.propagatedType = node.propagatedType;
9954 copy.staticType = node.staticType;
9955 return copy;
9956 }
9957
9958 @override
9959 MapLiteral visitMapLiteral(MapLiteral node) {
9960 MapLiteral copy = new MapLiteral(_mapToken(node.constKeyword),
9961 _cloneNode(node.typeArguments), _mapToken(node.leftBracket),
9962 _cloneNodeList(node.entries), _mapToken(node.rightBracket));
9963 copy.propagatedType = node.propagatedType;
9964 copy.staticType = node.staticType;
9965 return copy;
9966 }
9967
9968 @override
9969 MapLiteralEntry visitMapLiteralEntry(
9970 MapLiteralEntry node) => new MapLiteralEntry(
9971 _cloneNode(node.key), _mapToken(node.separator), _cloneNode(node.value));
9972
9973 @override
9974 MethodDeclaration visitMethodDeclaration(MethodDeclaration node) =>
9975 new MethodDeclaration(_cloneNode(node.documentationComment),
9976 _cloneNodeList(node.metadata), _mapToken(node.externalKeyword),
9977 _mapToken(node.modifierKeyword), _cloneNode(node.returnType),
9978 _mapToken(node.propertyKeyword), _mapToken(node.operatorKeyword),
9979 _cloneNode(node.name), _cloneNode(node._typeParameters),
9980 _cloneNode(node.parameters), _cloneNode(node.body));
9981
9982 @override
9983 MethodInvocation visitMethodInvocation(MethodInvocation node) {
9984 MethodInvocation copy = new MethodInvocation(_cloneNode(node.target),
9985 _mapToken(node.operator), _cloneNode(node.methodName),
9986 _cloneNode(node.typeArguments), _cloneNode(node.argumentList));
9987 copy.propagatedType = node.propagatedType;
9988 copy.staticType = node.staticType;
9989 return copy;
9990 }
9991
9992 @override
9993 NamedExpression visitNamedExpression(NamedExpression node) {
9994 NamedExpression copy =
9995 new NamedExpression(_cloneNode(node.name), _cloneNode(node.expression));
9996 copy.propagatedType = node.propagatedType;
9997 copy.staticType = node.staticType;
9998 return copy;
9999 }
10000
10001 @override
10002 AstNode visitNativeClause(NativeClause node) =>
10003 new NativeClause(_mapToken(node.nativeKeyword), _cloneNode(node.name));
10004
10005 @override
10006 NativeFunctionBody visitNativeFunctionBody(NativeFunctionBody node) =>
10007 new NativeFunctionBody(_mapToken(node.nativeKeyword),
10008 _cloneNode(node.stringLiteral), _mapToken(node.semicolon));
10009
10010 @override
10011 NullLiteral visitNullLiteral(NullLiteral node) {
10012 NullLiteral copy = new NullLiteral(_mapToken(node.literal));
10013 copy.propagatedType = node.propagatedType;
10014 copy.staticType = node.staticType;
10015 return copy;
10016 }
10017
10018 @override
10019 ParenthesizedExpression visitParenthesizedExpression(
10020 ParenthesizedExpression node) {
10021 ParenthesizedExpression copy = new ParenthesizedExpression(
10022 _mapToken(node.leftParenthesis), _cloneNode(node.expression),
10023 _mapToken(node.rightParenthesis));
10024 copy.propagatedType = node.propagatedType;
10025 copy.staticType = node.staticType;
10026 return copy;
10027 }
10028
10029 @override
10030 PartDirective visitPartDirective(PartDirective node) {
10031 PartDirective copy = new PartDirective(
10032 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
10033 _mapToken(node.partKeyword), _cloneNode(node.uri),
10034 _mapToken(node.semicolon));
10035 copy.element = node.element;
10036 return copy;
10037 }
10038
10039 @override
10040 PartOfDirective visitPartOfDirective(PartOfDirective node) {
10041 PartOfDirective copy = new PartOfDirective(
10042 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
10043 _mapToken(node.partKeyword), _mapToken(node.ofKeyword),
10044 _cloneNode(node.libraryName), _mapToken(node.semicolon));
10045 copy.element = node.element;
10046 return copy;
10047 }
10048
10049 @override
10050 PostfixExpression visitPostfixExpression(PostfixExpression node) {
10051 PostfixExpression copy = new PostfixExpression(
10052 _cloneNode(node.operand), _mapToken(node.operator));
10053 copy.propagatedElement = node.propagatedElement;
10054 copy.propagatedType = node.propagatedType;
10055 copy.staticElement = node.staticElement;
10056 copy.staticType = node.staticType;
10057 return copy;
10058 }
10059
10060 @override
10061 PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) {
10062 PrefixedIdentifier copy = new PrefixedIdentifier(_cloneNode(node.prefix),
10063 _mapToken(node.period), _cloneNode(node.identifier));
10064 copy.propagatedType = node.propagatedType;
10065 copy.staticType = node.staticType;
10066 return copy;
10067 }
10068
10069 @override
10070 PrefixExpression visitPrefixExpression(PrefixExpression node) {
10071 PrefixExpression copy = new PrefixExpression(
10072 _mapToken(node.operator), _cloneNode(node.operand));
10073 copy.propagatedElement = node.propagatedElement;
10074 copy.propagatedType = node.propagatedType;
10075 copy.staticElement = node.staticElement;
10076 copy.staticType = node.staticType;
10077 return copy;
10078 }
10079
10080 @override
10081 PropertyAccess visitPropertyAccess(PropertyAccess node) {
10082 PropertyAccess copy = new PropertyAccess(_cloneNode(node.target),
10083 _mapToken(node.operator), _cloneNode(node.propertyName));
10084 copy.propagatedType = node.propagatedType;
10085 copy.staticType = node.staticType;
10086 return copy;
10087 }
10088
10089 @override
10090 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
10091 RedirectingConstructorInvocation node) {
10092 RedirectingConstructorInvocation copy =
10093 new RedirectingConstructorInvocation(_mapToken(node.thisKeyword),
10094 _mapToken(node.period), _cloneNode(node.constructorName),
10095 _cloneNode(node.argumentList));
10096 copy.staticElement = node.staticElement;
10097 return copy;
10098 }
10099
10100 @override
10101 RethrowExpression visitRethrowExpression(RethrowExpression node) {
10102 RethrowExpression copy =
10103 new RethrowExpression(_mapToken(node.rethrowKeyword));
10104 copy.propagatedType = node.propagatedType;
10105 copy.staticType = node.staticType;
10106 return copy;
10107 }
10108
10109 @override
10110 ReturnStatement visitReturnStatement(ReturnStatement node) =>
10111 new ReturnStatement(_mapToken(node.returnKeyword),
10112 _cloneNode(node.expression), _mapToken(node.semicolon));
10113
10114 @override
10115 ScriptTag visitScriptTag(ScriptTag node) =>
10116 new ScriptTag(_mapToken(node.scriptTag));
10117
10118 @override
10119 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator(
10120 _mapToken(node.keyword), _cloneNodeList(node.shownNames));
10121
10122 @override
10123 SimpleFormalParameter visitSimpleFormalParameter(
10124 SimpleFormalParameter node) => new SimpleFormalParameter(
10125 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
10126 _mapToken(node.keyword), _cloneNode(node.type),
10127 _cloneNode(node.identifier));
10128
10129 @override
10130 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
10131 Token mappedToken = _mapToken(node.token);
10132 if (mappedToken == null) {
10133 // This only happens for SimpleIdentifiers created by the parser as part
10134 // of scanning documentation comments (the tokens for those identifiers
10135 // are not in the original token stream and hence do not get copied).
10136 // This extra check can be removed if the scanner is changed to scan
10137 // documentation comments for the parser.
10138 mappedToken = node.token;
10139 }
10140 SimpleIdentifier copy = new SimpleIdentifier(mappedToken);
10141 copy.auxiliaryElements = node.auxiliaryElements;
10142 copy.propagatedElement = node.propagatedElement;
10143 copy.propagatedType = node.propagatedType;
10144 copy.staticElement = node.staticElement;
10145 copy.staticType = node.staticType;
10146 return copy;
10147 }
10148
10149 @override
10150 SimpleStringLiteral visitSimpleStringLiteral(SimpleStringLiteral node) {
10151 SimpleStringLiteral copy =
10152 new SimpleStringLiteral(_mapToken(node.literal), node.value);
10153 copy.propagatedType = node.propagatedType;
10154 copy.staticType = node.staticType;
10155 return copy;
10156 }
10157
10158 @override
10159 StringInterpolation visitStringInterpolation(StringInterpolation node) {
10160 StringInterpolation copy =
10161 new StringInterpolation(_cloneNodeList(node.elements));
10162 copy.propagatedType = node.propagatedType;
10163 copy.staticType = node.staticType;
10164 return copy;
10165 }
10166
10167 @override
10168 SuperConstructorInvocation visitSuperConstructorInvocation(
10169 SuperConstructorInvocation node) {
10170 SuperConstructorInvocation copy = new SuperConstructorInvocation(
10171 _mapToken(node.superKeyword), _mapToken(node.period),
10172 _cloneNode(node.constructorName), _cloneNode(node.argumentList));
10173 copy.staticElement = node.staticElement;
10174 return copy;
10175 }
10176
10177 @override
10178 SuperExpression visitSuperExpression(SuperExpression node) {
10179 SuperExpression copy = new SuperExpression(_mapToken(node.superKeyword));
10180 copy.propagatedType = node.propagatedType;
10181 copy.staticType = node.staticType;
10182 return copy;
10183 }
10184
10185 @override
10186 SwitchCase visitSwitchCase(SwitchCase node) => new SwitchCase(
10187 _cloneNodeList(node.labels), _mapToken(node.keyword),
10188 _cloneNode(node.expression), _mapToken(node.colon),
10189 _cloneNodeList(node.statements));
10190
10191 @override
10192 SwitchDefault visitSwitchDefault(SwitchDefault node) => new SwitchDefault(
10193 _cloneNodeList(node.labels), _mapToken(node.keyword),
10194 _mapToken(node.colon), _cloneNodeList(node.statements));
10195
10196 @override
10197 SwitchStatement visitSwitchStatement(SwitchStatement node) =>
10198 new SwitchStatement(_mapToken(node.switchKeyword),
10199 _mapToken(node.leftParenthesis), _cloneNode(node.expression),
10200 _mapToken(node.rightParenthesis), _mapToken(node.leftBracket),
10201 _cloneNodeList(node.members), _mapToken(node.rightBracket));
10202
10203 @override
10204 AstNode visitSymbolLiteral(SymbolLiteral node) {
10205 SymbolLiteral copy = new SymbolLiteral(
10206 _mapToken(node.poundSign), _mapTokens(node.components));
10207 copy.propagatedType = node.propagatedType;
10208 copy.staticType = node.staticType;
10209 return copy;
10210 }
10211
10212 @override
10213 ThisExpression visitThisExpression(ThisExpression node) {
10214 ThisExpression copy = new ThisExpression(_mapToken(node.thisKeyword));
10215 copy.propagatedType = node.propagatedType;
10216 copy.staticType = node.staticType;
10217 return copy;
10218 }
10219
10220 @override
10221 ThrowExpression visitThrowExpression(ThrowExpression node) {
10222 ThrowExpression copy = new ThrowExpression(
10223 _mapToken(node.throwKeyword), _cloneNode(node.expression));
10224 copy.propagatedType = node.propagatedType;
10225 copy.staticType = node.staticType;
10226 return copy;
10227 }
10228
10229 @override
10230 TopLevelVariableDeclaration visitTopLevelVariableDeclaration(
10231 TopLevelVariableDeclaration node) => new TopLevelVariableDeclaration(
10232 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
10233 _cloneNode(node.variables), _mapToken(node.semicolon));
10234
10235 @override
10236 TryStatement visitTryStatement(TryStatement node) => new TryStatement(
10237 _mapToken(node.tryKeyword), _cloneNode(node.body),
10238 _cloneNodeList(node.catchClauses), _mapToken(node.finallyKeyword),
10239 _cloneNode(node.finallyBlock));
10240
10241 @override
10242 TypeArgumentList visitTypeArgumentList(TypeArgumentList node) =>
10243 new TypeArgumentList(_mapToken(node.leftBracket),
10244 _cloneNodeList(node.arguments), _mapToken(node.rightBracket));
10245
10246 @override
10247 TypeName visitTypeName(TypeName node) {
10248 TypeName copy =
10249 new TypeName(_cloneNode(node.name), _cloneNode(node.typeArguments));
10250 copy.type = node.type;
10251 return copy;
10252 }
10253
10254 @override
10255 TypeParameter visitTypeParameter(TypeParameter node) => new TypeParameter(
10256 _cloneNode(node.documentationComment), _cloneNodeList(node.metadata),
10257 _cloneNode(node.name), _mapToken(node.extendsKeyword),
10258 _cloneNode(node.bound));
10259
10260 @override
10261 TypeParameterList visitTypeParameterList(TypeParameterList node) =>
10262 new TypeParameterList(_mapToken(node.leftBracket),
10263 _cloneNodeList(node.typeParameters), _mapToken(node.rightBracket));
10264
10265 @override
10266 VariableDeclaration visitVariableDeclaration(VariableDeclaration node) =>
10267 new VariableDeclaration(_cloneNode(node.name), _mapToken(node.equals),
10268 _cloneNode(node.initializer));
10269
10270 @override
10271 VariableDeclarationList visitVariableDeclarationList(
10272 VariableDeclarationList node) => new VariableDeclarationList(null,
10273 _cloneNodeList(node.metadata), _mapToken(node.keyword),
10274 _cloneNode(node.type), _cloneNodeList(node.variables));
10275
10276 @override
10277 VariableDeclarationStatement visitVariableDeclarationStatement(
10278 VariableDeclarationStatement node) => new VariableDeclarationStatement(
10279 _cloneNode(node.variables), _mapToken(node.semicolon));
10280
10281 @override
10282 WhileStatement visitWhileStatement(WhileStatement node) => new WhileStatement(
10283 _mapToken(node.whileKeyword), _mapToken(node.leftParenthesis),
10284 _cloneNode(node.condition), _mapToken(node.rightParenthesis),
10285 _cloneNode(node.body));
10286
10287 @override
10288 WithClause visitWithClause(WithClause node) => new WithClause(
10289 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes));
10290
10291 @override
10292 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement(
10293 _mapToken(node.yieldKeyword), _mapToken(node.star),
10294 _cloneNode(node.expression), _mapToken(node.semicolon));
10295
10296 AstNode _cloneNode(AstNode node) {
10297 if (node == null) {
10298 return null;
10299 }
10300 if (identical(node, _oldNode)) {
10301 return _newNode;
10302 }
10303 return node.accept(this) as AstNode;
10304 }
10305
10306 List _cloneNodeList(NodeList nodes) {
10307 List clonedNodes = new List();
10308 for (AstNode node in nodes) {
10309 clonedNodes.add(_cloneNode(node));
10310 }
10311 return clonedNodes;
10312 }
10313
10314 Token _mapToken(Token oldToken) {
10315 if (oldToken == null) {
10316 return null;
10317 }
10318 return _tokenMap.get(oldToken);
10319 }
10320
10321 List<Token> _mapTokens(List<Token> oldTokens) {
10322 List<Token> newTokens = new List<Token>(oldTokens.length);
10323 for (int index = 0; index < newTokens.length; index++) {
10324 newTokens[index] = _mapToken(oldTokens[index]);
10325 }
10326 return newTokens;
10327 }
10328 }
10329
10330 /**
10331 * An index expression.
10332 *
10333 * > indexExpression ::=
10334 * > [Expression] '[' [Expression] ']'
10335 */
10336 class IndexExpression extends Expression {
10337 /**
10338 * The expression used to compute the object being indexed, or `null` if this
10339 * index expression is part of a cascade expression.
10340 */
10341 Expression _target;
10342
10343 /**
10344 * The period ("..") before a cascaded index expression, or `null` if this
10345 * index expression is not part of a cascade expression.
10346 */
10347 Token period;
10348
10349 /**
10350 * The left square bracket.
10351 */
10352 Token leftBracket;
10353
10354 /**
10355 * The expression used to compute the index.
10356 */
10357 Expression _index;
10358
10359 /**
10360 * The right square bracket.
10361 */
10362 Token rightBracket;
10363
10364 /**
10365 * The element associated with the operator based on the static type of the
10366 * target, or `null` if the AST structure has not been resolved or if the
10367 * operator could not be resolved.
10368 */
10369 MethodElement staticElement;
10370
10371 /**
10372 * The element associated with the operator based on the propagated type of
10373 * the target, or `null` if the AST structure has not been resolved or if the
10374 * operator could not be resolved.
10375 */
10376 MethodElement propagatedElement;
10377
10378 /**
10379 * If this expression is both in a getter and setter context, the
10380 * [AuxiliaryElements] will be set to hold onto the static and propagated
10381 * information. The auxiliary element will hold onto the elements from the
10382 * getter context.
10383 */
10384 AuxiliaryElements auxiliaryElements = null;
10385
10386 /**
10387 * Initialize a newly created index expression.
10388 */
10389 IndexExpression.forCascade(
10390 this.period, this.leftBracket, Expression index, this.rightBracket) {
10391 _index = _becomeParentOf(index);
10392 }
10393
10394 /**
10395 * Initialize a newly created index expression.
10396 */
10397 IndexExpression.forTarget(Expression target, this.leftBracket,
10398 Expression index, this.rightBracket) {
10399 _target = _becomeParentOf(target);
10400 _index = _becomeParentOf(index);
10401 }
10402
10403 @override
10404 Token get beginToken {
10405 if (_target != null) {
10406 return _target.beginToken;
10407 }
10408 return period;
10409 }
10410
10411 /**
10412 * Return the best element available for this operator. If resolution was able
10413 * to find a better element based on type propagation, that element will be
10414 * returned. Otherwise, the element found using the result of static analysis
10415 * will be returned. If resolution has not been performed, then `null` will be
10416 * returned.
10417 */
10418 MethodElement get bestElement {
10419 MethodElement element = propagatedElement;
10420 if (element == null) {
10421 element = staticElement;
10422 }
10423 return element;
10424 }
10425
10426 @override
10427 Iterable get childEntities => new ChildEntities()
10428 ..add(_target)
10429 ..add(period)
10430 ..add(leftBracket)
10431 ..add(_index)
10432 ..add(rightBracket);
10433
10434 @override
10435 Token get endToken => rightBracket;
10436
10437 /**
10438 * Return the expression used to compute the index.
10439 */
10440 Expression get index => _index;
10441
10442 /**
10443 * Set the expression used to compute the index to the given [expression].
10444 */
10445 void set index(Expression expression) {
10446 _index = _becomeParentOf(expression);
10447 }
10448
10449 @override
10450 bool get isAssignable => true;
10451
10452 /**
10453 * Return `true` if this expression is cascaded. If it is, then the target of
10454 * this expression is not stored locally but is stored in the nearest ancestor
10455 * that is a [CascadeExpression].
10456 */
10457 bool get isCascaded => period != null;
10458
10459 @override
10460 int get precedence => 15;
10461
10462 /**
10463 * If the AST structure has been resolved, and the function being invoked is
10464 * known based on propagated type information, then return the parameter
10465 * element representing the parameter to which the value of the index
10466 * expression will be bound. Otherwise, return `null`.
10467 */
10468 @deprecated // Use "expression.propagatedParameterElement"
10469 ParameterElement get propagatedParameterElementForIndex {
10470 return _propagatedParameterElementForIndex;
10471 }
10472
10473 /**
10474 * Return the expression used to compute the object being indexed. If this
10475 * index expression is not part of a cascade expression, then this is the same
10476 * as [target]. If this index expression is part of a cascade expression, then
10477 * the target expression stored with the cascade expression is returned.
10478 */
10479 Expression get realTarget {
10480 if (isCascaded) {
10481 AstNode ancestor = parent;
10482 while (ancestor is! CascadeExpression) {
10483 if (ancestor == null) {
10484 return _target;
10485 }
10486 ancestor = ancestor.parent;
10487 }
10488 return (ancestor as CascadeExpression).target;
10489 }
10490 return _target;
10491 }
10492
10493 /**
10494 * If the AST structure has been resolved, and the function being invoked is
10495 * known based on static type information, then return the parameter element
10496 * representing the parameter to which the value of the index expression will
10497 * be bound. Otherwise, return `null`.
10498 */
10499 @deprecated // Use "expression.propagatedParameterElement"
10500 ParameterElement get staticParameterElementForIndex {
10501 return _staticParameterElementForIndex;
10502 }
10503
10504 /**
10505 * Return the expression used to compute the object being indexed, or `null`
10506 * if this index expression is part of a cascade expression.
10507 *
10508 * Use [realTarget] to get the target independent of whether this is part of a
10509 * cascade expression.
10510 */
10511 Expression get target => _target;
10512
10513 /**
10514 * Set the expression used to compute the object being indexed to the given
10515 * [expression].
10516 */
10517 void set target(Expression expression) {
10518 _target = _becomeParentOf(expression);
10519 }
10520
10521 /**
10522 * If the AST structure has been resolved, and the function being invoked is
10523 * known based on propagated type information, then return the parameter
10524 * element representing the parameter to which the value of the index
10525 * expression will be bound. Otherwise, return `null`.
10526 */
10527 ParameterElement get _propagatedParameterElementForIndex {
10528 if (propagatedElement == null) {
10529 return null;
10530 }
10531 List<ParameterElement> parameters = propagatedElement.parameters;
10532 if (parameters.length < 1) {
10533 return null;
10534 }
10535 return parameters[0];
10536 }
10537
10538 /**
10539 * If the AST structure has been resolved, and the function being invoked is
10540 * known based on static type information, then return the parameter element
10541 * representing the parameter to which the value of the index expression will
10542 * be bound. Otherwise, return `null`.
10543 */
10544 ParameterElement get _staticParameterElementForIndex {
10545 if (staticElement == null) {
10546 return null;
10547 }
10548 List<ParameterElement> parameters = staticElement.parameters;
10549 if (parameters.length < 1) {
10550 return null;
10551 }
10552 return parameters[0];
10553 }
10554
10555 @override
10556 accept(AstVisitor visitor) => visitor.visitIndexExpression(this);
10557
10558 /**
10559 * Return `true` if this expression is computing a right-hand value (that is,
10560 * if this expression is in a context where the operator '[]' will be
10561 * invoked).
10562 *
10563 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10564 * are they mutually exclusive. In other words, it is possible for both
10565 * methods to return `true` when invoked on the same node.
10566 */
10567 bool inGetterContext() {
10568 // TODO(brianwilkerson) Convert this to a getter.
10569 AstNode parent = this.parent;
10570 if (parent is AssignmentExpression) {
10571 AssignmentExpression assignment = parent;
10572 if (identical(assignment.leftHandSide, this) &&
10573 assignment.operator.type == TokenType.EQ) {
10574 return false;
10575 }
10576 }
10577 return true;
10578 }
10579
10580 /**
10581 * Return `true` if this expression is computing a left-hand value (that is,
10582 * if this expression is in a context where the operator '[]=' will be
10583 * invoked).
10584 *
10585 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
10586 * are they mutually exclusive. In other words, it is possible for both
10587 * methods to return `true` when invoked on the same node.
10588 */
10589 bool inSetterContext() {
10590 // TODO(brianwilkerson) Convert this to a getter.
10591 AstNode parent = this.parent;
10592 if (parent is PrefixExpression) {
10593 return parent.operator.type.isIncrementOperator;
10594 } else if (parent is PostfixExpression) {
10595 return true;
10596 } else if (parent is AssignmentExpression) {
10597 return identical(parent.leftHandSide, this);
10598 }
10599 return false;
10600 }
10601
10602 @override
10603 void visitChildren(AstVisitor visitor) {
10604 _safelyVisitChild(_target, visitor);
10605 _safelyVisitChild(_index, visitor);
10606 }
10607 }
10608
10609 /**
10610 * An instance creation expression.
10611 *
10612 * > newExpression ::=
10613 * > ('new' | 'const') [TypeName] ('.' [SimpleIdentifier])? [ArgumentList]
10614 */
10615 class InstanceCreationExpression extends Expression {
10616 /**
10617 * The 'new' or 'const' keyword used to indicate how an object should be
10618 * created.
10619 */
10620 Token keyword;
10621
10622 /**
10623 * The name of the constructor to be invoked.
10624 */
10625 ConstructorName _constructorName;
10626
10627 /**
10628 * The list of arguments to the constructor.
10629 */
10630 ArgumentList _argumentList;
10631
10632 /**
10633 * The element associated with the constructor based on static type
10634 * information, or `null` if the AST structure has not been resolved or if the
10635 * constructor could not be resolved.
10636 */
10637 ConstructorElement staticElement;
10638
10639 /**
10640 * Initialize a newly created instance creation expression.
10641 */
10642 InstanceCreationExpression(this.keyword, ConstructorName constructorName,
10643 ArgumentList argumentList) {
10644 _constructorName = _becomeParentOf(constructorName);
10645 _argumentList = _becomeParentOf(argumentList);
10646 }
10647
10648 /**
10649 * Return the list of arguments to the constructor.
10650 */
10651 ArgumentList get argumentList => _argumentList;
10652
10653 /**
10654 * Set the list of arguments to the constructor to the given [argumentList].
10655 */
10656 void set argumentList(ArgumentList argumentList) {
10657 _argumentList = _becomeParentOf(argumentList);
10658 }
10659
10660 @override
10661 Token get beginToken => keyword;
10662
10663 @override
10664 Iterable get childEntities => new ChildEntities()
10665 ..add(keyword)
10666 ..add(_constructorName)
10667 ..add(_argumentList);
10668
10669 /**
10670 * Return the name of the constructor to be invoked.
10671 */
10672 ConstructorName get constructorName => _constructorName;
10673
10674 /**
10675 * Set the name of the constructor to be invoked to the given [name].
10676 */
10677 void set constructorName(ConstructorName name) {
10678 _constructorName = _becomeParentOf(name);
10679 }
10680
10681 @override
10682 Token get endToken => _argumentList.endToken;
10683
10684 /**
10685 * Return `true` if this creation expression is used to invoke a constant
10686 * constructor.
10687 */
10688 bool get isConst => keyword is KeywordToken &&
10689 (keyword as KeywordToken).keyword == Keyword.CONST;
10690
10691 @override
10692 int get precedence => 16;
10693
10694 @override
10695 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this);
10696
10697 @override
10698 void visitChildren(AstVisitor visitor) {
10699 _safelyVisitChild(_constructorName, visitor);
10700 _safelyVisitChild(_argumentList, visitor);
10701 }
10702 }
10703
10704 /**
10705 * An integer literal expression.
10706 *
10707 * > integerLiteral ::=
10708 * > decimalIntegerLiteral
10709 * > | hexidecimalIntegerLiteral
10710 * >
10711 * > decimalIntegerLiteral ::=
10712 * > decimalDigit+
10713 * >
10714 * > hexidecimalIntegerLiteral ::=
10715 * > '0x' hexidecimalDigit+
10716 * > | '0X' hexidecimalDigit+
10717 */
10718 class IntegerLiteral extends Literal {
10719 /**
10720 * The token representing the literal.
10721 */
10722 Token literal;
10723
10724 /**
10725 * The value of the literal.
10726 */
10727 int value = 0;
10728
10729 /**
10730 * Initialize a newly created integer literal.
10731 */
10732 IntegerLiteral(this.literal, this.value);
10733
10734 @override
10735 Token get beginToken => literal;
10736
10737 @override
10738 Iterable get childEntities => new ChildEntities()..add(literal);
10739
10740 @override
10741 Token get endToken => literal;
10742
10743 @override
10744 accept(AstVisitor visitor) => visitor.visitIntegerLiteral(this);
10745
10746 @override
10747 void visitChildren(AstVisitor visitor) {
10748 // There are no children to visit.
10749 }
10750 }
10751
10752 /**
10753 * A node within a [StringInterpolation].
10754 *
10755 * > interpolationElement ::=
10756 * > [InterpolationExpression]
10757 * > | [InterpolationString]
10758 */
10759 abstract class InterpolationElement extends AstNode {}
10760
10761 /**
10762 * An expression embedded in a string interpolation.
10763 *
10764 * > interpolationExpression ::=
10765 * > '$' [SimpleIdentifier]
10766 * > | '$' '{' [Expression] '}'
10767 */
10768 class InterpolationExpression extends InterpolationElement {
10769 /**
10770 * The token used to introduce the interpolation expression; either '$' if the
10771 * expression is a simple identifier or '${' if the expression is a full
10772 * expression.
10773 */
10774 Token leftBracket;
10775
10776 /**
10777 * The expression to be evaluated for the value to be converted into a string.
10778 */
10779 Expression _expression;
10780
10781 /**
10782 * The right curly bracket, or `null` if the expression is an identifier
10783 * without brackets.
10784 */
10785 Token rightBracket;
10786
10787 /**
10788 * Initialize a newly created interpolation expression.
10789 */
10790 InterpolationExpression(
10791 this.leftBracket, Expression expression, this.rightBracket) {
10792 _expression = _becomeParentOf(expression);
10793 }
10794
10795 @override
10796 Token get beginToken => leftBracket;
10797
10798 @override
10799 Iterable get childEntities => new ChildEntities()
10800 ..add(leftBracket)
10801 ..add(_expression)
10802 ..add(rightBracket);
10803
10804 @override
10805 Token get endToken {
10806 if (rightBracket != null) {
10807 return rightBracket;
10808 }
10809 return _expression.endToken;
10810 }
10811
10812 /**
10813 * Return the expression to be evaluated for the value to be converted into a
10814 * string.
10815 */
10816 Expression get expression => _expression;
10817
10818 /**
10819 * Set the expression to be evaluated for the value to be converted into a
10820 * string to the given [expression].
10821 */
10822 void set expression(Expression expression) {
10823 _expression = _becomeParentOf(expression);
10824 }
10825
10826 @override
10827 accept(AstVisitor visitor) => visitor.visitInterpolationExpression(this);
10828
10829 @override
10830 void visitChildren(AstVisitor visitor) {
10831 _safelyVisitChild(_expression, visitor);
10832 }
10833 }
10834
10835 /**
10836 * A non-empty substring of an interpolated string.
10837 *
10838 * > interpolationString ::=
10839 * > characters
10840 */
10841 class InterpolationString extends InterpolationElement {
10842 /**
10843 * The characters that will be added to the string.
10844 */
10845 Token contents;
10846
10847 /**
10848 * The value of the literal.
10849 */
10850 String value;
10851
10852 /**
10853 * Initialize a newly created string of characters that are part of a string
10854 * interpolation.
10855 */
10856 InterpolationString(this.contents, this.value);
10857
10858 @override
10859 Token get beginToken => contents;
10860
10861 @override
10862 Iterable get childEntities => new ChildEntities()..add(contents);
10863
10864 /**
10865 * Return the offset of the after-last contents character.
10866 */
10867 int get contentsEnd {
10868 String lexeme = contents.lexeme;
10869 return offset + new StringLexemeHelper(lexeme, true, true).end;
10870 }
10871
10872 /**
10873 * Return the offset of the first contents character.
10874 */
10875 int get contentsOffset {
10876 int offset = contents.offset;
10877 String lexeme = contents.lexeme;
10878 return offset + new StringLexemeHelper(lexeme, true, true).start;
10879 }
10880
10881 @override
10882 Token get endToken => contents;
10883
10884 @override
10885 accept(AstVisitor visitor) => visitor.visitInterpolationString(this);
10886
10887 @override
10888 void visitChildren(AstVisitor visitor) {}
10889 }
10890
10891 /**
10892 * An is expression.
10893 *
10894 * > isExpression ::=
10895 * > [Expression] 'is' '!'? [TypeName]
10896 */
10897 class IsExpression extends Expression {
10898 /**
10899 * The expression used to compute the value whose type is being tested.
10900 */
10901 Expression _expression;
10902
10903 /**
10904 * The is operator.
10905 */
10906 Token isOperator;
10907
10908 /**
10909 * The not operator, or `null` if the sense of the test is not negated.
10910 */
10911 Token notOperator;
10912
10913 /**
10914 * The name of the type being tested for.
10915 */
10916 TypeName _type;
10917
10918 /**
10919 * Initialize a newly created is expression. The [notOperator] can be `null`
10920 * if the sense of the test is not negated.
10921 */
10922 IsExpression(
10923 Expression expression, this.isOperator, this.notOperator, TypeName type) {
10924 _expression = _becomeParentOf(expression);
10925 _type = _becomeParentOf(type);
10926 }
10927
10928 @override
10929 Token get beginToken => _expression.beginToken;
10930
10931 @override
10932 Iterable get childEntities => new ChildEntities()
10933 ..add(_expression)
10934 ..add(isOperator)
10935 ..add(notOperator)
10936 ..add(_type);
10937
10938 @override
10939 Token get endToken => _type.endToken;
10940
10941 /**
10942 * Return the expression used to compute the value whose type is being tested.
10943 */
10944 Expression get expression => _expression;
10945
10946 /**
10947 * Set the expression used to compute the value whose type is being tested to
10948 * the given [expression].
10949 */
10950 void set expression(Expression expression) {
10951 _expression = _becomeParentOf(expression);
10952 }
10953
10954 @override
10955 int get precedence => 7;
10956
10957 /**
10958 * Return the name of the type being tested for.
10959 */
10960 TypeName get type => _type;
10961
10962 /**
10963 * Set the name of the type being tested for to the given [name].
10964 */
10965 void set type(TypeName name) {
10966 _type = _becomeParentOf(name);
10967 }
10968
10969 @override
10970 accept(AstVisitor visitor) => visitor.visitIsExpression(this);
10971
10972 @override
10973 void visitChildren(AstVisitor visitor) {
10974 _safelyVisitChild(_expression, visitor);
10975 _safelyVisitChild(_type, visitor);
10976 }
10977 }
10978
10979 /**
10980 * A label on either a [LabeledStatement] or a [NamedExpression].
10981 *
10982 * > label ::=
10983 * > [SimpleIdentifier] ':'
10984 */
10985 class Label extends AstNode {
10986 /**
10987 * The label being associated with the statement.
10988 */
10989 SimpleIdentifier _label;
10990
10991 /**
10992 * The colon that separates the label from the statement.
10993 */
10994 Token colon;
10995
10996 /**
10997 * Initialize a newly created label.
10998 */
10999 Label(SimpleIdentifier label, this.colon) {
11000 _label = _becomeParentOf(label);
11001 }
11002
11003 @override
11004 Token get beginToken => _label.beginToken;
11005
11006 @override
11007 Iterable get childEntities => new ChildEntities()..add(_label)..add(colon);
11008
11009 @override
11010 Token get endToken => colon;
11011
11012 /**
11013 * Return the label being associated with the statement.
11014 */
11015 SimpleIdentifier get label => _label;
11016
11017 /**
11018 * Set the label being associated with the statement to the given [label].
11019 */
11020 void set label(SimpleIdentifier label) {
11021 _label = _becomeParentOf(label);
11022 }
11023
11024 @override
11025 accept(AstVisitor visitor) => visitor.visitLabel(this);
11026
11027 @override
11028 void visitChildren(AstVisitor visitor) {
11029 _safelyVisitChild(_label, visitor);
11030 }
11031 }
11032
11033 /**
11034 * A statement that has a label associated with them.
11035 *
11036 * > labeledStatement ::=
11037 * > [Label]+ [Statement]
11038 */
11039 class LabeledStatement extends Statement {
11040 /**
11041 * The labels being associated with the statement.
11042 */
11043 NodeList<Label> _labels;
11044
11045 /**
11046 * The statement with which the labels are being associated.
11047 */
11048 Statement _statement;
11049
11050 /**
11051 * Initialize a newly created labeled statement.
11052 */
11053 LabeledStatement(List<Label> labels, Statement statement) {
11054 _labels = new NodeList<Label>(this, labels);
11055 _statement = _becomeParentOf(statement);
11056 }
11057
11058 @override
11059 Token get beginToken {
11060 if (!_labels.isEmpty) {
11061 return _labels.beginToken;
11062 }
11063 return _statement.beginToken;
11064 }
11065
11066 @override
11067 Iterable get childEntities => new ChildEntities()
11068 ..addAll(_labels)
11069 ..add(_statement);
11070
11071 @override
11072 Token get endToken => _statement.endToken;
11073
11074 /**
11075 * Return the labels being associated with the statement.
11076 */
11077 NodeList<Label> get labels => _labels;
11078
11079 /**
11080 * Return the statement with which the labels are being associated.
11081 */
11082 Statement get statement => _statement;
11083
11084 /**
11085 * Set the statement with which the labels are being associated to the given
11086 * [statement].
11087 */
11088 void set statement(Statement statement) {
11089 _statement = _becomeParentOf(statement);
11090 }
11091
11092 @override
11093 Statement get unlabeled => _statement.unlabeled;
11094
11095 @override
11096 accept(AstVisitor visitor) => visitor.visitLabeledStatement(this);
11097
11098 @override
11099 void visitChildren(AstVisitor visitor) {
11100 _labels.accept(visitor);
11101 _safelyVisitChild(_statement, visitor);
11102 }
11103 }
11104
11105 /**
11106 * A library directive.
11107 *
11108 * > libraryDirective ::=
11109 * > [Annotation] 'library' [Identifier] ';'
11110 */
11111 class LibraryDirective extends Directive {
11112 /**
11113 * The token representing the 'library' keyword.
11114 */
11115 Token libraryKeyword;
11116
11117 /**
11118 * The name of the library being defined.
11119 */
11120 LibraryIdentifier _name;
11121
11122 /**
11123 * The semicolon terminating the directive.
11124 */
11125 Token semicolon;
11126
11127 /**
11128 * Initialize a newly created library directive. Either or both of the
11129 * [comment] and [metadata] can be `null` if the directive does not have the
11130 * corresponding attribute.
11131 */
11132 LibraryDirective(Comment comment, List<Annotation> metadata,
11133 this.libraryKeyword, LibraryIdentifier name, this.semicolon)
11134 : super(comment, metadata) {
11135 _name = _becomeParentOf(name);
11136 }
11137
11138 @override
11139 Iterable get childEntities =>
11140 super._childEntities..add(libraryKeyword)..add(_name)..add(semicolon);
11141
11142 @override
11143 Token get endToken => semicolon;
11144
11145 @override
11146 Token get firstTokenAfterCommentAndMetadata => libraryKeyword;
11147
11148 @override
11149 Token get keyword => libraryKeyword;
11150
11151 /**
11152 * Return the token representing the 'library' token.
11153 */
11154 @deprecated // Use "this.libraryKeyword"
11155 Token get libraryToken => libraryKeyword;
11156
11157 /**
11158 * Set the token representing the 'library' token to the given [token].
11159 */
11160 @deprecated // Use "this.libraryKeyword"
11161 set libraryToken(Token token) {
11162 libraryKeyword = token;
11163 }
11164
11165 /**
11166 * Return the name of the library being defined.
11167 */
11168 LibraryIdentifier get name => _name;
11169
11170 /**
11171 * Set the name of the library being defined to the given [name].
11172 */
11173 void set name(LibraryIdentifier name) {
11174 _name = _becomeParentOf(name);
11175 }
11176
11177 @override
11178 accept(AstVisitor visitor) => visitor.visitLibraryDirective(this);
11179
11180 @override
11181 void visitChildren(AstVisitor visitor) {
11182 super.visitChildren(visitor);
11183 _safelyVisitChild(_name, visitor);
11184 }
11185 }
11186
11187 /**
11188 * The identifier for a library.
11189 *
11190 * > libraryIdentifier ::=
11191 * > [SimpleIdentifier] ('.' [SimpleIdentifier])*
11192 */
11193 class LibraryIdentifier extends Identifier {
11194 /**
11195 * The components of the identifier.
11196 */
11197 NodeList<SimpleIdentifier> _components;
11198
11199 /**
11200 * Initialize a newly created prefixed identifier.
11201 */
11202 LibraryIdentifier(List<SimpleIdentifier> components) {
11203 _components = new NodeList<SimpleIdentifier>(this, components);
11204 }
11205
11206 @override
11207 Token get beginToken => _components.beginToken;
11208
11209 @override
11210 Element get bestElement => staticElement;
11211
11212 /**
11213 * TODO(paulberry): add "." tokens.
11214 */
11215 @override
11216 Iterable get childEntities => new ChildEntities()..addAll(_components);
11217
11218 /**
11219 * Return the components of the identifier.
11220 */
11221 NodeList<SimpleIdentifier> get components => _components;
11222
11223 @override
11224 Token get endToken => _components.endToken;
11225
11226 @override
11227 String get name {
11228 StringBuffer buffer = new StringBuffer();
11229 bool needsPeriod = false;
11230 for (SimpleIdentifier identifier in _components) {
11231 if (needsPeriod) {
11232 buffer.write(".");
11233 } else {
11234 needsPeriod = true;
11235 }
11236 buffer.write(identifier.name);
11237 }
11238 return buffer.toString();
11239 }
11240
11241 @override
11242 int get precedence => 15;
11243
11244 @override
11245 Element get propagatedElement => null;
11246
11247 @override
11248 Element get staticElement => null;
11249
11250 @override
11251 accept(AstVisitor visitor) => visitor.visitLibraryIdentifier(this);
11252
11253 @override
11254 void visitChildren(AstVisitor visitor) {
11255 _components.accept(visitor);
11256 }
11257 }
11258
11259 /**
11260 * A list literal.
11261 *
11262 * > listLiteral ::=
11263 * > 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']'
11264 */
11265 class ListLiteral extends TypedLiteral {
11266 /**
11267 * The left square bracket.
11268 */
11269 Token leftBracket;
11270
11271 /**
11272 * The expressions used to compute the elements of the list.
11273 */
11274 NodeList<Expression> _elements;
11275
11276 /**
11277 * The right square bracket.
11278 */
11279 Token rightBracket;
11280
11281 /**
11282 * Initialize a newly created list literal. The [constKeyword] can be `null`
11283 * if the literal is not a constant. The [typeArguments] can be `null` if no
11284 * type arguments were declared. The list of [elements] can be `null` if the
11285 * list is empty.
11286 */
11287 ListLiteral(Token constKeyword, TypeArgumentList typeArguments,
11288 this.leftBracket, List<Expression> elements, this.rightBracket)
11289 : super(constKeyword, typeArguments) {
11290 _elements = new NodeList<Expression>(this, elements);
11291 }
11292
11293 @override
11294 Token get beginToken {
11295 if (constKeyword != null) {
11296 return constKeyword;
11297 }
11298 TypeArgumentList typeArguments = this.typeArguments;
11299 if (typeArguments != null) {
11300 return typeArguments.beginToken;
11301 }
11302 return leftBracket;
11303 }
11304
11305 /**
11306 * TODO(paulberry): add commas.
11307 */
11308 @override
11309 Iterable get childEntities => super._childEntities
11310 ..add(leftBracket)
11311 ..addAll(_elements)
11312 ..add(rightBracket);
11313
11314 /**
11315 * Return the expressions used to compute the elements of the list.
11316 */
11317 NodeList<Expression> get elements => _elements;
11318
11319 @override
11320 Token get endToken => rightBracket;
11321
11322 @override
11323 accept(AstVisitor visitor) => visitor.visitListLiteral(this);
11324
11325 @override
11326 void visitChildren(AstVisitor visitor) {
11327 super.visitChildren(visitor);
11328 _elements.accept(visitor);
11329 }
11330 }
11331
11332 /**
11333 * A node that represents a literal expression.
11334 *
11335 * > literal ::=
11336 * > [BooleanLiteral]
11337 * > | [DoubleLiteral]
11338 * > | [IntegerLiteral]
11339 * > | [ListLiteral]
11340 * > | [MapLiteral]
11341 * > | [NullLiteral]
11342 * > | [StringLiteral]
11343 */
11344 abstract class Literal extends Expression {
11345 @override
11346 int get precedence => 16;
11347 }
11348
11349 /**
11350 * A literal map.
11351 *
11352 * > mapLiteral ::=
11353 * > 'const'? ('<' [TypeName] (',' [TypeName])* '>')?
11354 * > '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}'
11355 */
11356 class MapLiteral extends TypedLiteral {
11357 /**
11358 * The left curly bracket.
11359 */
11360 Token leftBracket;
11361
11362 /**
11363 * The entries in the map.
11364 */
11365 NodeList<MapLiteralEntry> _entries;
11366
11367 /**
11368 * The right curly bracket.
11369 */
11370 Token rightBracket;
11371
11372 /**
11373 * Initialize a newly created map literal. The [constKeyword] can be `null` if
11374 * the literal is not a constant. The [typeArguments] can be `null` if no type
11375 * arguments were declared. The [entries] can be `null` if the map is empty.
11376 */
11377 MapLiteral(Token constKeyword, TypeArgumentList typeArguments,
11378 this.leftBracket, List<MapLiteralEntry> entries, this.rightBracket)
11379 : super(constKeyword, typeArguments) {
11380 _entries = new NodeList<MapLiteralEntry>(this, entries);
11381 }
11382
11383 @override
11384 Token get beginToken {
11385 if (constKeyword != null) {
11386 return constKeyword;
11387 }
11388 TypeArgumentList typeArguments = this.typeArguments;
11389 if (typeArguments != null) {
11390 return typeArguments.beginToken;
11391 }
11392 return leftBracket;
11393 }
11394
11395 /**
11396 * TODO(paulberry): add commas.
11397 */
11398 @override
11399 Iterable get childEntities => super._childEntities
11400 ..add(leftBracket)
11401 ..addAll(entries)
11402 ..add(rightBracket);
11403
11404 @override
11405 Token get endToken => rightBracket;
11406
11407 /**
11408 * Return the entries in the map.
11409 */
11410 NodeList<MapLiteralEntry> get entries => _entries;
11411
11412 @override
11413 accept(AstVisitor visitor) => visitor.visitMapLiteral(this);
11414
11415 @override
11416 void visitChildren(AstVisitor visitor) {
11417 super.visitChildren(visitor);
11418 _entries.accept(visitor);
11419 }
11420 }
11421
11422 /**
11423 * A single key/value pair in a map literal.
11424 *
11425 * > mapLiteralEntry ::=
11426 * > [Expression] ':' [Expression]
11427 */
11428 class MapLiteralEntry extends AstNode {
11429 /**
11430 * The expression computing the key with which the value will be associated.
11431 */
11432 Expression _key;
11433
11434 /**
11435 * The colon that separates the key from the value.
11436 */
11437 Token separator;
11438
11439 /**
11440 * The expression computing the value that will be associated with the key.
11441 */
11442 Expression _value;
11443
11444 /**
11445 * Initialize a newly created map literal entry.
11446 */
11447 MapLiteralEntry(Expression key, this.separator, Expression value) {
11448 _key = _becomeParentOf(key);
11449 _value = _becomeParentOf(value);
11450 }
11451
11452 @override
11453 Token get beginToken => _key.beginToken;
11454
11455 @override
11456 Iterable get childEntities =>
11457 new ChildEntities()..add(_key)..add(separator)..add(_value);
11458
11459 @override
11460 Token get endToken => _value.endToken;
11461
11462 /**
11463 * Return the expression computing the key with which the value will be
11464 * associated.
11465 */
11466 Expression get key => _key;
11467
11468 /**
11469 * Set the expression computing the key with which the value will be
11470 * associated to the given [string].
11471 */
11472 void set key(Expression string) {
11473 _key = _becomeParentOf(string);
11474 }
11475
11476 /**
11477 * Return the expression computing the value that will be associated with the
11478 * key.
11479 */
11480 Expression get value => _value;
11481
11482 /**
11483 * Set the expression computing the value that will be associated with the key
11484 * to the given [expression].
11485 */
11486 void set value(Expression expression) {
11487 _value = _becomeParentOf(expression);
11488 }
11489
11490 @override
11491 accept(AstVisitor visitor) => visitor.visitMapLiteralEntry(this);
11492
11493 @override
11494 void visitChildren(AstVisitor visitor) {
11495 _safelyVisitChild(_key, visitor);
11496 _safelyVisitChild(_value, visitor);
11497 }
11498 }
11499
11500 /**
11501 * A method declaration.
11502 *
11503 * > methodDeclaration ::=
11504 * > methodSignature [FunctionBody]
11505 * >
11506 * > methodSignature ::=
11507 * > 'external'? ('abstract' | 'static')? [Type]? ('get' | 'set')?
11508 * > methodName [TypeParameterList] [FormalParameterList]
11509 * >
11510 * > methodName ::=
11511 * > [SimpleIdentifier]
11512 * > | 'operator' [SimpleIdentifier]
11513 */
11514 class MethodDeclaration extends ClassMember {
11515 /**
11516 * The token for the 'external' keyword, or `null` if the constructor is not
11517 * external.
11518 */
11519 Token externalKeyword;
11520
11521 /**
11522 * The token representing the 'abstract' or 'static' keyword, or `null` if
11523 * neither modifier was specified.
11524 */
11525 Token modifierKeyword;
11526
11527 /**
11528 * The return type of the method, or `null` if no return type was declared.
11529 */
11530 TypeName _returnType;
11531
11532 /**
11533 * The token representing the 'get' or 'set' keyword, or `null` if this is a
11534 * method declaration rather than a property declaration.
11535 */
11536 Token propertyKeyword;
11537
11538 /**
11539 * The token representing the 'operator' keyword, or `null` if this method
11540 * does not declare an operator.
11541 */
11542 Token operatorKeyword;
11543
11544 /**
11545 * The name of the method.
11546 */
11547 SimpleIdentifier _name;
11548
11549 /**
11550 * The type parameters associated with the method, or `null` if the method is
11551 * not a generic method.
11552 */
11553 TypeParameterList _typeParameters;
11554
11555 /**
11556 * The parameters associated with the method, or `null` if this method
11557 * declares a getter.
11558 */
11559 FormalParameterList _parameters;
11560
11561 /**
11562 * The body of the method.
11563 */
11564 FunctionBody _body;
11565
11566 /**
11567 * Initialize a newly created method declaration. Either or both of the
11568 * [comment] and [metadata] can be `null` if the declaration does not have the
11569 * corresponding attribute. The [externalKeyword] can be `null` if the method
11570 * is not external. The [modifierKeyword] can be `null` if the method is
11571 * neither abstract nor static. The [returnType] can be `null` if no return
11572 * type was specified. The [propertyKeyword] can be `null` if the method is
11573 * neither a getter or a setter. The [operatorKeyword] can be `null` if the
11574 * method does not implement an operator. The [parameters] must be `null` if
11575 * this method declares a getter.
11576 */
11577 MethodDeclaration(Comment comment, List<Annotation> metadata,
11578 this.externalKeyword, this.modifierKeyword, TypeName returnType,
11579 this.propertyKeyword, this.operatorKeyword, SimpleIdentifier name,
11580 TypeParameterList typeParameters, FormalParameterList parameters,
11581 FunctionBody body)
11582 : super(comment, metadata) {
11583 _returnType = _becomeParentOf(returnType);
11584 _name = _becomeParentOf(name);
11585 _typeParameters = _becomeParentOf(typeParameters);
11586 _parameters = _becomeParentOf(parameters);
11587 _body = _becomeParentOf(body);
11588 }
11589
11590 /**
11591 * Return the body of the method.
11592 */
11593 FunctionBody get body => _body;
11594
11595 /**
11596 * Set the body of the method to the given [functionBody].
11597 */
11598 void set body(FunctionBody functionBody) {
11599 _body = _becomeParentOf(functionBody);
11600 }
11601
11602 @override
11603 Iterable get childEntities => super._childEntities
11604 ..add(externalKeyword)
11605 ..add(modifierKeyword)
11606 ..add(_returnType)
11607 ..add(propertyKeyword)
11608 ..add(operatorKeyword)
11609 ..add(_name)
11610 ..add(_parameters)
11611 ..add(_body);
11612
11613 /**
11614 * Return the element associated with this method, or `null` if the AST
11615 * structure has not been resolved. The element can either be a
11616 * [MethodElement], if this represents the declaration of a normal method, or
11617 * a [PropertyAccessorElement] if this represents the declaration of either a
11618 * getter or a setter.
11619 */
11620 @override
11621 ExecutableElement get element =>
11622 _name != null ? (_name.staticElement as ExecutableElement) : null;
11623
11624 @override
11625 Token get endToken => _body.endToken;
11626
11627 @override
11628 Token get firstTokenAfterCommentAndMetadata {
11629 if (modifierKeyword != null) {
11630 return modifierKeyword;
11631 } else if (_returnType != null) {
11632 return _returnType.beginToken;
11633 } else if (propertyKeyword != null) {
11634 return propertyKeyword;
11635 } else if (operatorKeyword != null) {
11636 return operatorKeyword;
11637 }
11638 return _name.beginToken;
11639 }
11640
11641 /**
11642 * Return `true` if this method is declared to be an abstract method.
11643 */
11644 bool get isAbstract {
11645 FunctionBody body = _body;
11646 return externalKeyword == null &&
11647 (body is EmptyFunctionBody && !body.semicolon.isSynthetic);
11648 }
11649
11650 /**
11651 * Return `true` if this method declares a getter.
11652 */
11653 bool get isGetter => propertyKeyword != null &&
11654 (propertyKeyword as KeywordToken).keyword == Keyword.GET;
11655
11656 /**
11657 * Return `true` if this method declares an operator.
11658 */
11659 bool get isOperator => operatorKeyword != null;
11660
11661 /**
11662 * Return `true` if this method declares a setter.
11663 */
11664 bool get isSetter => propertyKeyword != null &&
11665 (propertyKeyword as KeywordToken).keyword == Keyword.SET;
11666
11667 /**
11668 * Return `true` if this method is declared to be a static method.
11669 */
11670 bool get isStatic => modifierKeyword != null &&
11671 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC;
11672
11673 /**
11674 * Return the name of the method.
11675 */
11676 SimpleIdentifier get name => _name;
11677
11678 /**
11679 * Set the name of the method to the given [identifier].
11680 */
11681 void set name(SimpleIdentifier identifier) {
11682 _name = _becomeParentOf(identifier);
11683 }
11684
11685 /**
11686 * Return the parameters associated with the method, or `null` if this method
11687 * declares a getter.
11688 */
11689 FormalParameterList get parameters => _parameters;
11690
11691 /**
11692 * Set the parameters associated with the method to the given list of
11693 * [parameters].
11694 */
11695 void set parameters(FormalParameterList parameters) {
11696 _parameters = _becomeParentOf(parameters);
11697 }
11698
11699 /**
11700 * Return the return type of the method, or `null` if no return type was
11701 * declared.
11702 */
11703 TypeName get returnType => _returnType;
11704
11705 /**
11706 * Set the return type of the method to the given [typeName].
11707 */
11708 void set returnType(TypeName typeName) {
11709 _returnType = _becomeParentOf(typeName);
11710 }
11711
11712 /**
11713 * Return the type parameters associated with this method, or `null` if this
11714 * method is not a generic method.
11715 */
11716 TypeParameterList get typeParameters => _typeParameters;
11717
11718 /**
11719 * Set the type parameters associated with this method to the given
11720 * [typeParameters].
11721 */
11722 void set typeParameters(TypeParameterList typeParameters) {
11723 _typeParameters = _becomeParentOf(typeParameters);
11724 }
11725
11726 @override
11727 accept(AstVisitor visitor) => visitor.visitMethodDeclaration(this);
11728
11729 @override
11730 void visitChildren(AstVisitor visitor) {
11731 super.visitChildren(visitor);
11732 _safelyVisitChild(_returnType, visitor);
11733 _safelyVisitChild(_name, visitor);
11734 _safelyVisitChild(_typeParameters, visitor);
11735 _safelyVisitChild(_parameters, visitor);
11736 _safelyVisitChild(_body, visitor);
11737 }
11738 }
11739
11740 /**
11741 * The invocation of either a function or a method. Invocations of functions
11742 * resulting from evaluating an expression are represented by
11743 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are
11744 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes.
11745 *
11746 * > methodInvoction ::=
11747 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t]
11748 */
11749 class MethodInvocation extends Expression {
11750 /**
11751 * The expression producing the object on which the method is defined, or
11752 * `null` if there is no target (that is, the target is implicitly `this`).
11753 */
11754 Expression _target;
11755
11756 /**
11757 * The operator that separates the target from the method name, or `null`
11758 * if there is no target. In an ordinary method invocation this will be a
11759 * period ('.'). In a cascade section this will be the cascade operator
11760 * ('..').
11761 */
11762 Token operator;
11763
11764 /**
11765 * The name of the method being invoked.
11766 */
11767 SimpleIdentifier _methodName;
11768
11769 /**
11770 * The type arguments to be applied to the method being invoked, or `null` if
11771 * no type arguments were provided.
11772 */
11773 TypeArgumentList _typeArguments;
11774
11775 /**
11776 * The list of arguments to the method.
11777 */
11778 ArgumentList _argumentList;
11779
11780 /**
11781 * Initialize a newly created method invocation. The [target] and [operator]
11782 * can be `null` if there is no target.
11783 */
11784 MethodInvocation(Expression target, this.operator,
11785 SimpleIdentifier methodName, TypeArgumentList typeArguments,
11786 ArgumentList argumentList) {
11787 _target = _becomeParentOf(target);
11788 _methodName = _becomeParentOf(methodName);
11789 _typeArguments = _becomeParentOf(typeArguments);
11790 _argumentList = _becomeParentOf(argumentList);
11791 }
11792
11793 /**
11794 * Return the list of arguments to the method.
11795 */
11796 ArgumentList get argumentList => _argumentList;
11797
11798 /**
11799 * Set the list of arguments to the method to the given [argumentList].
11800 */
11801 void set argumentList(ArgumentList argumentList) {
11802 _argumentList = _becomeParentOf(argumentList);
11803 }
11804
11805 @override
11806 Token get beginToken {
11807 if (_target != null) {
11808 return _target.beginToken;
11809 } else if (operator != null) {
11810 return operator;
11811 }
11812 return _methodName.beginToken;
11813 }
11814
11815 @override
11816 Iterable get childEntities => new ChildEntities()
11817 ..add(_target)
11818 ..add(operator)
11819 ..add(_methodName)
11820 ..add(_argumentList);
11821
11822 @override
11823 Token get endToken => _argumentList.endToken;
11824
11825 /**
11826 * Return `true` if this expression is cascaded. If it is, then the target of
11827 * this expression is not stored locally but is stored in the nearest ancestor
11828 * that is a [CascadeExpression].
11829 */
11830 bool get isCascaded =>
11831 operator != null && operator.type == TokenType.PERIOD_PERIOD;
11832
11833 /**
11834 * Return the name of the method being invoked.
11835 */
11836 SimpleIdentifier get methodName => _methodName;
11837
11838 /**
11839 * Set the name of the method being invoked to the given [identifier].
11840 */
11841 void set methodName(SimpleIdentifier identifier) {
11842 _methodName = _becomeParentOf(identifier);
11843 }
11844
11845 /**
11846 * The operator that separates the target from the method name, or `null`
11847 * if there is no target. In an ordinary method invocation this will be a
11848 * period ('.'). In a cascade section this will be the cascade operator
11849 * ('..').
11850 */
11851 @deprecated // Use this.operator
11852 Token get period => operator;
11853
11854 /**
11855 * The operator that separates the target from the method name, or `null`
11856 * if there is no target. In an ordinary method invocation this will be a
11857 * period ('.'). In a cascade section this will be the cascade operator
11858 * ('..').
11859 */
11860 @deprecated // Use this.operator
11861 void set period(Token value) {
11862 operator = value;
11863 }
11864
11865 @override
11866 int get precedence => 15;
11867
11868 /**
11869 * Return the expression used to compute the receiver of the invocation. If
11870 * this invocation is not part of a cascade expression, then this is the same
11871 * as [target]. If this invocation is part of a cascade expression, then the
11872 * target stored with the cascade expression is returned.
11873 */
11874 Expression get realTarget {
11875 if (isCascaded) {
11876 AstNode ancestor = parent;
11877 while (ancestor is! CascadeExpression) {
11878 if (ancestor == null) {
11879 return _target;
11880 }
11881 ancestor = ancestor.parent;
11882 }
11883 return (ancestor as CascadeExpression).target;
11884 }
11885 return _target;
11886 }
11887
11888 /**
11889 * Return the expression producing the object on which the method is defined,
11890 * or `null` if there is no target (that is, the target is implicitly `this`)
11891 * or if this method invocation is part of a cascade expression.
11892 *
11893 * Use [realTarget] to get the target independent of whether this is part of a
11894 * cascade expression.
11895 */
11896 Expression get target => _target;
11897
11898 /**
11899 * Set the expression producing the object on which the method is defined to
11900 * the given [expression].
11901 */
11902 void set target(Expression expression) {
11903 _target = _becomeParentOf(expression);
11904 }
11905
11906 /**
11907 * Return the type arguments to be applied to the method being invoked, or
11908 * `null` if no type arguments were provided.
11909 */
11910 TypeArgumentList get typeArguments => _typeArguments;
11911
11912 /**
11913 * Set the type arguments to be applied to the method being invoked to the
11914 * given [typeArguments].
11915 */
11916 void set typeArguments(TypeArgumentList typeArguments) {
11917 _typeArguments = _becomeParentOf(typeArguments);
11918 }
11919
11920 @override
11921 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this);
11922
11923 @override
11924 void visitChildren(AstVisitor visitor) {
11925 _safelyVisitChild(_target, visitor);
11926 _safelyVisitChild(_methodName, visitor);
11927 _safelyVisitChild(_typeArguments, visitor);
11928 _safelyVisitChild(_argumentList, visitor);
11929 }
11930 }
11931
11932 /**
11933 * A node that declares a single name within the scope of a compilation unit.
11934 */
11935 abstract class NamedCompilationUnitMember extends CompilationUnitMember {
11936 /**
11937 * The name of the member being declared.
11938 */
11939 SimpleIdentifier _name;
11940
11941 /**
11942 * Initialize a newly created compilation unit member with the given [name].
11943 * Either or both of the [comment] and [metadata] can be `null` if the member
11944 * does not have the corresponding attribute.
11945 */
11946 NamedCompilationUnitMember(
11947 Comment comment, List<Annotation> metadata, SimpleIdentifier name)
11948 : super(comment, metadata) {
11949 _name = _becomeParentOf(name);
11950 }
11951
11952 /**
11953 * Return the name of the member being declared.
11954 */
11955 SimpleIdentifier get name => _name;
11956
11957 /**
11958 * Set the name of the member being declared to the given [identifier].
11959 */
11960 void set name(SimpleIdentifier identifier) {
11961 _name = _becomeParentOf(identifier);
11962 }
11963 }
11964
11965 /**
11966 * An expression that has a name associated with it. They are used in method
11967 * invocations when there are named parameters.
11968 *
11969 * > namedExpression ::=
11970 * > [Label] [Expression]
11971 */
11972 class NamedExpression extends Expression {
11973 /**
11974 * The name associated with the expression.
11975 */
11976 Label _name;
11977
11978 /**
11979 * The expression with which the name is associated.
11980 */
11981 Expression _expression;
11982
11983 /**
11984 * Initialize a newly created named expression..
11985 */
11986 NamedExpression(Label name, Expression expression) {
11987 _name = _becomeParentOf(name);
11988 _expression = _becomeParentOf(expression);
11989 }
11990
11991 @override
11992 Token get beginToken => _name.beginToken;
11993
11994 @override
11995 Iterable get childEntities =>
11996 new ChildEntities()..add(_name)..add(_expression);
11997
11998 /**
11999 * Return the element representing the parameter being named by this
12000 * expression, or `null` if the AST structure has not been resolved or if
12001 * there is no parameter with the same name as this expression.
12002 */
12003 ParameterElement get element {
12004 Element element = _name.label.staticElement;
12005 if (element is ParameterElement) {
12006 return element;
12007 }
12008 return null;
12009 }
12010
12011 @override
12012 Token get endToken => _expression.endToken;
12013
12014 /**
12015 * Return the expression with which the name is associated.
12016 */
12017 Expression get expression => _expression;
12018
12019 /**
12020 * Set the expression with which the name is associated to the given
12021 * [expression].
12022 */
12023 void set expression(Expression expression) {
12024 _expression = _becomeParentOf(expression);
12025 }
12026
12027 /**
12028 * Return the name associated with the expression.
12029 */
12030 Label get name => _name;
12031
12032 /**
12033 * Set the name associated with the expression to the given [identifier].
12034 */
12035 void set name(Label identifier) {
12036 _name = _becomeParentOf(identifier);
12037 }
12038
12039 @override
12040 int get precedence => 0;
12041
12042 @override
12043 accept(AstVisitor visitor) => visitor.visitNamedExpression(this);
12044
12045 @override
12046 void visitChildren(AstVisitor visitor) {
12047 _safelyVisitChild(_name, visitor);
12048 _safelyVisitChild(_expression, visitor);
12049 }
12050 }
12051
12052 /**
12053 * A node that represents a directive that impacts the namespace of a library.
12054 *
12055 * > directive ::=
12056 * > [ExportDirective]
12057 * > | [ImportDirective]
12058 */
12059 abstract class NamespaceDirective extends UriBasedDirective {
12060 /**
12061 * The token representing the 'import' or 'export' keyword.
12062 */
12063 Token keyword;
12064
12065 /**
12066 * The combinators used to control which names are imported or exported.
12067 */
12068 NodeList<Combinator> _combinators;
12069
12070 /**
12071 * The semicolon terminating the directive.
12072 */
12073 Token semicolon;
12074
12075 /**
12076 * Initialize a newly created namespace directive. Either or both of the
12077 * [comment] and [metadata] can be `null` if the directive does not have the
12078 * corresponding attribute. The list of [combinators] can be `null` if there
12079 * are no combinators.
12080 */
12081 NamespaceDirective(Comment comment, List<Annotation> metadata, this.keyword,
12082 StringLiteral libraryUri, List<Combinator> combinators, this.semicolon)
12083 : super(comment, metadata, libraryUri) {
12084 _combinators = new NodeList<Combinator>(this, combinators);
12085 }
12086
12087 /**
12088 * Return the combinators used to control how names are imported or exported.
12089 */
12090 NodeList<Combinator> get combinators => _combinators;
12091
12092 @override
12093 Token get endToken => semicolon;
12094
12095 @override
12096 Token get firstTokenAfterCommentAndMetadata => keyword;
12097
12098 @override
12099 LibraryElement get uriElement;
12100 }
12101
12102 /**
12103 * The "native" clause in an class declaration.
12104 *
12105 * > nativeClause ::=
12106 * > 'native' [StringLiteral]
12107 */
12108 class NativeClause extends AstNode {
12109 /**
12110 * The token representing the 'native' keyword.
12111 */
12112 Token nativeKeyword;
12113
12114 /**
12115 * The name of the native object that implements the class.
12116 */
12117 StringLiteral _name;
12118
12119 /**
12120 * Initialize a newly created native clause.
12121 */
12122 NativeClause(this.nativeKeyword, StringLiteral name) {
12123 _name = _becomeParentOf(name);
12124 }
12125
12126 @override
12127 Token get beginToken => nativeKeyword;
12128
12129 @override
12130 Iterable get childEntities =>
12131 new ChildEntities()..add(nativeKeyword)..add(_name);
12132
12133 @override
12134 Token get endToken => _name.endToken;
12135
12136 /**
12137 * Get the token representing the 'native' keyword.
12138 */
12139 @deprecated // Use "this.nativeKeyword"
12140 Token get keyword => nativeKeyword;
12141
12142 /**
12143 * Set the token representing the 'native' keyword to the given [token].
12144 */
12145 @deprecated // Use "this.nativeKeyword"
12146 set keyword(Token token) {
12147 nativeKeyword = token;
12148 }
12149
12150 /**
12151 * Return the name of the native object that implements the class.
12152 */
12153 StringLiteral get name => _name;
12154
12155 /**
12156 * Sets the name of the native object that implements the class to the given
12157 * [name].
12158 */
12159 void set name(StringLiteral name) {
12160 _name = _becomeParentOf(name);
12161 }
12162
12163 @override
12164 accept(AstVisitor visitor) => visitor.visitNativeClause(this);
12165
12166 @override
12167 void visitChildren(AstVisitor visitor) {
12168 _safelyVisitChild(_name, visitor);
12169 }
12170 }
12171
12172 /**
12173 * A function body that consists of a native keyword followed by a string
12174 * literal.
12175 *
12176 * > nativeFunctionBody ::=
12177 * > 'native' [SimpleStringLiteral] ';'
12178 */
12179 class NativeFunctionBody extends FunctionBody {
12180 /**
12181 * The token representing 'native' that marks the start of the function body.
12182 */
12183 Token nativeKeyword;
12184
12185 /**
12186 * The string literal, after the 'native' token.
12187 */
12188 StringLiteral _stringLiteral;
12189
12190 /**
12191 * The token representing the semicolon that marks the end of the function
12192 * body.
12193 */
12194 Token semicolon;
12195
12196 /**
12197 * Initialize a newly created function body consisting of the 'native' token,
12198 * a string literal, and a semicolon.
12199 */
12200 NativeFunctionBody(
12201 this.nativeKeyword, StringLiteral stringLiteral, this.semicolon) {
12202 _stringLiteral = _becomeParentOf(stringLiteral);
12203 }
12204
12205 @override
12206 Token get beginToken => nativeKeyword;
12207
12208 @override
12209 Iterable get childEntities => new ChildEntities()
12210 ..add(nativeKeyword)
12211 ..add(_stringLiteral)
12212 ..add(semicolon);
12213
12214 @override
12215 Token get endToken => semicolon;
12216
12217 /**
12218 * Return the token representing 'native' that marks the start of the function
12219 * body.
12220 */
12221 @deprecated // Use "this.nativeKeyword"
12222 Token get nativeToken => nativeKeyword;
12223
12224 /**
12225 * Set the token representing 'native' that marks the start of the function
12226 * body to the given [token].
12227 */
12228 @deprecated // Use "this.nativeKeyword"
12229 set nativeToken(Token token) {
12230 nativeKeyword = token;
12231 }
12232
12233 /**
12234 * Return the string literal representing the string after the 'native' token.
12235 */
12236 StringLiteral get stringLiteral => _stringLiteral;
12237
12238 /**
12239 * Set the string literal representing the string after the 'native' token to
12240 * the given [stringLiteral].
12241 */
12242 void set stringLiteral(StringLiteral stringLiteral) {
12243 _stringLiteral = _becomeParentOf(stringLiteral);
12244 }
12245
12246 @override
12247 accept(AstVisitor visitor) => visitor.visitNativeFunctionBody(this);
12248
12249 @override
12250 void visitChildren(AstVisitor visitor) {
12251 _safelyVisitChild(_stringLiteral, visitor);
12252 }
12253 }
12254
12255 /**
12256 * A list of AST nodes that have a common parent.
12257 */
12258 class NodeList<E extends AstNode> extends Object with ListMixin<E> {
12259 /**
12260 * The node that is the parent of each of the elements in the list.
12261 */
12262 AstNode owner;
12263
12264 /**
12265 * The elements contained in the list.
12266 */
12267 List<E> _elements = <E>[];
12268
12269 /**
12270 * Initialize a newly created list of nodes such that all of the nodes that
12271 * are added to the list will have their parent set to the given [owner]. The
12272 * list will initially be populated with the given [elements].
12273 */
12274 NodeList(this.owner, [List<E> elements]) {
12275 addAll(elements);
12276 }
12277
12278 /**
12279 * Return the first token included in this node list's source range, or `null`
12280 * if the list is empty.
12281 */
12282 Token get beginToken {
12283 if (_elements.length == 0) {
12284 return null;
12285 }
12286 return _elements[0].beginToken;
12287 }
12288
12289 /**
12290 * Return the last token included in this node list's source range, or `null`
12291 * if the list is empty.
12292 */
12293 Token get endToken {
12294 int length = _elements.length;
12295 if (length == 0) {
12296 return null;
12297 }
12298 return _elements[length - 1].endToken;
12299 }
12300
12301 int get length => _elements.length;
12302
12303 @deprecated // Never intended for public use.
12304 void set length(int value) {
12305 throw new UnsupportedError("Cannot resize NodeList.");
12306 }
12307
12308 E operator [](int index) {
12309 if (index < 0 || index >= _elements.length) {
12310 throw new RangeError("Index: $index, Size: ${_elements.length}");
12311 }
12312 return _elements[index];
12313 }
12314
12315 void operator []=(int index, E node) {
12316 if (index < 0 || index >= _elements.length) {
12317 throw new RangeError("Index: $index, Size: ${_elements.length}");
12318 }
12319 owner._becomeParentOf(node);
12320 _elements[index] = node;
12321 }
12322
12323 /**
12324 * Use the given [visitor] to visit each of the nodes in this list.
12325 */
12326 accept(AstVisitor visitor) {
12327 int length = _elements.length;
12328 for (var i = 0; i < length; i++) {
12329 _elements[i].accept(visitor);
12330 }
12331 }
12332
12333 @override
12334 void add(E node) {
12335 insert(length, node);
12336 }
12337
12338 @override
12339 bool addAll(Iterable<E> nodes) {
12340 if (nodes != null && !nodes.isEmpty) {
12341 _elements.addAll(nodes);
12342 for (E node in nodes) {
12343 owner._becomeParentOf(node);
12344 }
12345 return true;
12346 }
12347 return false;
12348 }
12349
12350 @override
12351 void clear() {
12352 _elements = <E>[];
12353 }
12354
12355 @override
12356 void insert(int index, E node) {
12357 int length = _elements.length;
12358 if (index < 0 || index > length) {
12359 throw new RangeError("Index: $index, Size: ${_elements.length}");
12360 }
12361 owner._becomeParentOf(node);
12362 if (length == 0) {
12363 _elements.add(node);
12364 } else {
12365 _elements.insert(index, node);
12366 }
12367 }
12368
12369 @override
12370 E removeAt(int index) {
12371 if (index < 0 || index >= _elements.length) {
12372 throw new RangeError("Index: $index, Size: ${_elements.length}");
12373 }
12374 E removedNode = _elements[index];
12375 _elements.removeAt(index);
12376 return removedNode;
12377 }
12378
12379 /**
12380 * Create an empty list with the given [owner].
12381 */
12382 @deprecated // Use "new NodeList<E>(owner)"
12383 static NodeList create(AstNode owner) => new NodeList(owner);
12384 }
12385
12386 /**
12387 * An object used to locate the [AstNode] associated with a source range, given
12388 * the AST structure built from the source. More specifically, they will return
12389 * the [AstNode] with the shortest length whose source range completely
12390 * encompasses the specified range.
12391 */
12392 class NodeLocator extends UnifyingAstVisitor<Object> {
12393 /**
12394 * The start offset of the range used to identify the node.
12395 */
12396 int _startOffset = 0;
12397
12398 /**
12399 * The end offset of the range used to identify the node.
12400 */
12401 int _endOffset = 0;
12402
12403 /**
12404 * The element that was found that corresponds to the given source range, or
12405 * `null` if there is no such element.
12406 */
12407 AstNode _foundNode;
12408
12409 /**
12410 * Initialize a newly created locator to locate an [AstNode] by locating the
12411 * node within an AST structure that corresponds to the given range of
12412 * characters (between the [startOffset] and [endOffset] in the source.
12413 */
12414 NodeLocator(int startOffset, [int endOffset])
12415 : this._startOffset = startOffset,
12416 this._endOffset = endOffset == null ? startOffset : endOffset;
12417
12418 /**
12419 * Initialize a newly created locator to locate an [AstNode] by locating the
12420 * node within an AST structure that corresponds to the given [offset] in the
12421 * source.
12422 */
12423 @deprecated // Use new NodeLocator(offset)
12424 NodeLocator.con1(int offset) : this(offset);
12425
12426 /**
12427 * Initialize a newly created locator to locate an [AstNode] by locating the
12428 * node within an AST structure that corresponds to the given range of
12429 * characters (between the [startOffset] and [endOffset] in the source.
12430 */
12431 @deprecated // Use new NodeLocator(startOffset, endOffset)
12432 NodeLocator.con2(this._startOffset, this._endOffset);
12433
12434 /**
12435 * Return the node that was found that corresponds to the given source range
12436 * or `null` if there is no such node.
12437 */
12438 AstNode get foundNode => _foundNode;
12439
12440 /**
12441 * Search within the given AST [node] for an identifier representing an
12442 * element in the specified source range. Return the element that was found,
12443 * or `null` if no element was found.
12444 */
12445 AstNode searchWithin(AstNode node) {
12446 if (node == null) {
12447 return null;
12448 }
12449 try {
12450 node.accept(this);
12451 } on NodeLocator_NodeFoundException {
12452 // A node with the right source position was found.
12453 } catch (exception, stackTrace) {
12454 AnalysisEngine.instance.logger.logInformation(
12455 "Unable to locate element at offset ($_startOffset - $_endOffset)",
12456 new CaughtException(exception, stackTrace));
12457 return null;
12458 }
12459 return _foundNode;
12460 }
12461
12462 @override
12463 Object visitNode(AstNode node) {
12464 Token beginToken = node.beginToken;
12465 Token endToken = node.endToken;
12466 // Don't include synthetic tokens.
12467 while (endToken != beginToken) {
12468 if (endToken.type == TokenType.EOF || !endToken.isSynthetic) {
12469 break;
12470 }
12471 endToken = endToken.previous;
12472 }
12473 int end = endToken.end;
12474 int start = node.offset;
12475 if (end < _startOffset) {
12476 return null;
12477 }
12478 if (start > _endOffset) {
12479 return null;
12480 }
12481 try {
12482 node.visitChildren(this);
12483 } on NodeLocator_NodeFoundException {
12484 rethrow;
12485 } catch (exception, stackTrace) {
12486 // Ignore the exception and proceed in order to visit the rest of the
12487 // structure.
12488 AnalysisEngine.instance.logger.logInformation(
12489 "Exception caught while traversing an AST structure.",
12490 new CaughtException(exception, stackTrace));
12491 }
12492 if (start <= _startOffset && _endOffset <= end) {
12493 _foundNode = node;
12494 throw new NodeLocator_NodeFoundException();
12495 }
12496 return null;
12497 }
12498 }
12499
12500 /**
12501 * An exception used by [NodeLocator] to cancel visiting after a node has been
12502 * found.
12503 */
12504 class NodeLocator_NodeFoundException extends RuntimeException {}
12505
12506 /**
12507 * An object that will replace one child node in an AST node with another node.
12508 */
12509 class NodeReplacer implements AstVisitor<bool> {
12510 /**
12511 * The node being replaced.
12512 */
12513 final AstNode _oldNode;
12514
12515 /**
12516 * The node that is replacing the old node.
12517 */
12518 final AstNode _newNode;
12519
12520 /**
12521 * Initialize a newly created node locator to replace the [_oldNode] with the
12522 * [_newNode].
12523 */
12524 NodeReplacer(this._oldNode, this._newNode);
12525
12526 @override
12527 bool visitAdjacentStrings(AdjacentStrings node) {
12528 if (_replaceInList(node.strings)) {
12529 return true;
12530 }
12531 return visitNode(node);
12532 }
12533
12534 bool visitAnnotatedNode(AnnotatedNode node) {
12535 if (identical(node.documentationComment, _oldNode)) {
12536 node.documentationComment = _newNode as Comment;
12537 return true;
12538 } else if (_replaceInList(node.metadata)) {
12539 return true;
12540 }
12541 return visitNode(node);
12542 }
12543
12544 @override
12545 bool visitAnnotation(Annotation node) {
12546 if (identical(node.arguments, _oldNode)) {
12547 node.arguments = _newNode as ArgumentList;
12548 return true;
12549 } else if (identical(node.constructorName, _oldNode)) {
12550 node.constructorName = _newNode as SimpleIdentifier;
12551 return true;
12552 } else if (identical(node.name, _oldNode)) {
12553 node.name = _newNode as Identifier;
12554 return true;
12555 }
12556 return visitNode(node);
12557 }
12558
12559 @override
12560 bool visitArgumentList(ArgumentList node) {
12561 if (_replaceInList(node.arguments)) {
12562 return true;
12563 }
12564 return visitNode(node);
12565 }
12566
12567 @override
12568 bool visitAsExpression(AsExpression node) {
12569 if (identical(node.expression, _oldNode)) {
12570 node.expression = _newNode as Expression;
12571 return true;
12572 } else if (identical(node.type, _oldNode)) {
12573 node.type = _newNode as TypeName;
12574 return true;
12575 }
12576 return visitNode(node);
12577 }
12578
12579 @override
12580 bool visitAssertStatement(AssertStatement node) {
12581 if (identical(node.condition, _oldNode)) {
12582 node.condition = _newNode as Expression;
12583 return true;
12584 }
12585 return visitNode(node);
12586 }
12587
12588 @override
12589 bool visitAssignmentExpression(AssignmentExpression node) {
12590 if (identical(node.leftHandSide, _oldNode)) {
12591 node.leftHandSide = _newNode as Expression;
12592 return true;
12593 } else if (identical(node.rightHandSide, _oldNode)) {
12594 node.rightHandSide = _newNode as Expression;
12595 return true;
12596 }
12597 return visitNode(node);
12598 }
12599
12600 @override
12601 bool visitAwaitExpression(AwaitExpression node) {
12602 if (identical(node.expression, _oldNode)) {
12603 node.expression = _newNode as Expression;
12604 return true;
12605 }
12606 return visitNode(node);
12607 }
12608
12609 @override
12610 bool visitBinaryExpression(BinaryExpression node) {
12611 if (identical(node.leftOperand, _oldNode)) {
12612 node.leftOperand = _newNode as Expression;
12613 return true;
12614 } else if (identical(node.rightOperand, _oldNode)) {
12615 node.rightOperand = _newNode as Expression;
12616 return true;
12617 }
12618 return visitNode(node);
12619 }
12620
12621 @override
12622 bool visitBlock(Block node) {
12623 if (_replaceInList(node.statements)) {
12624 return true;
12625 }
12626 return visitNode(node);
12627 }
12628
12629 @override
12630 bool visitBlockFunctionBody(BlockFunctionBody node) {
12631 if (identical(node.block, _oldNode)) {
12632 node.block = _newNode as Block;
12633 return true;
12634 }
12635 return visitNode(node);
12636 }
12637
12638 @override
12639 bool visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
12640
12641 @override
12642 bool visitBreakStatement(BreakStatement node) {
12643 if (identical(node.label, _oldNode)) {
12644 node.label = _newNode as SimpleIdentifier;
12645 return true;
12646 }
12647 return visitNode(node);
12648 }
12649
12650 @override
12651 bool visitCascadeExpression(CascadeExpression node) {
12652 if (identical(node.target, _oldNode)) {
12653 node.target = _newNode as Expression;
12654 return true;
12655 } else if (_replaceInList(node.cascadeSections)) {
12656 return true;
12657 }
12658 return visitNode(node);
12659 }
12660
12661 @override
12662 bool visitCatchClause(CatchClause node) {
12663 if (identical(node.exceptionType, _oldNode)) {
12664 node.exceptionType = _newNode as TypeName;
12665 return true;
12666 } else if (identical(node.exceptionParameter, _oldNode)) {
12667 node.exceptionParameter = _newNode as SimpleIdentifier;
12668 return true;
12669 } else if (identical(node.stackTraceParameter, _oldNode)) {
12670 node.stackTraceParameter = _newNode as SimpleIdentifier;
12671 return true;
12672 }
12673 return visitNode(node);
12674 }
12675
12676 @override
12677 bool visitClassDeclaration(ClassDeclaration node) {
12678 if (identical(node.name, _oldNode)) {
12679 node.name = _newNode as SimpleIdentifier;
12680 return true;
12681 } else if (identical(node.typeParameters, _oldNode)) {
12682 node.typeParameters = _newNode as TypeParameterList;
12683 return true;
12684 } else if (identical(node.extendsClause, _oldNode)) {
12685 node.extendsClause = _newNode as ExtendsClause;
12686 return true;
12687 } else if (identical(node.withClause, _oldNode)) {
12688 node.withClause = _newNode as WithClause;
12689 return true;
12690 } else if (identical(node.implementsClause, _oldNode)) {
12691 node.implementsClause = _newNode as ImplementsClause;
12692 return true;
12693 } else if (identical(node.nativeClause, _oldNode)) {
12694 node.nativeClause = _newNode as NativeClause;
12695 return true;
12696 } else if (_replaceInList(node.members)) {
12697 return true;
12698 }
12699 return visitAnnotatedNode(node);
12700 }
12701
12702 @override
12703 bool visitClassTypeAlias(ClassTypeAlias node) {
12704 if (identical(node.name, _oldNode)) {
12705 node.name = _newNode as SimpleIdentifier;
12706 return true;
12707 } else if (identical(node.typeParameters, _oldNode)) {
12708 node.typeParameters = _newNode as TypeParameterList;
12709 return true;
12710 } else if (identical(node.superclass, _oldNode)) {
12711 node.superclass = _newNode as TypeName;
12712 return true;
12713 } else if (identical(node.withClause, _oldNode)) {
12714 node.withClause = _newNode as WithClause;
12715 return true;
12716 } else if (identical(node.implementsClause, _oldNode)) {
12717 node.implementsClause = _newNode as ImplementsClause;
12718 return true;
12719 }
12720 return visitAnnotatedNode(node);
12721 }
12722
12723 @override
12724 bool visitComment(Comment node) {
12725 if (_replaceInList(node.references)) {
12726 return true;
12727 }
12728 return visitNode(node);
12729 }
12730
12731 @override
12732 bool visitCommentReference(CommentReference node) {
12733 if (identical(node.identifier, _oldNode)) {
12734 node.identifier = _newNode as Identifier;
12735 return true;
12736 }
12737 return visitNode(node);
12738 }
12739
12740 @override
12741 bool visitCompilationUnit(CompilationUnit node) {
12742 if (identical(node.scriptTag, _oldNode)) {
12743 node.scriptTag = _newNode as ScriptTag;
12744 return true;
12745 } else if (_replaceInList(node.directives)) {
12746 return true;
12747 } else if (_replaceInList(node.declarations)) {
12748 return true;
12749 }
12750 return visitNode(node);
12751 }
12752
12753 @override
12754 bool visitConditionalExpression(ConditionalExpression node) {
12755 if (identical(node.condition, _oldNode)) {
12756 node.condition = _newNode as Expression;
12757 return true;
12758 } else if (identical(node.thenExpression, _oldNode)) {
12759 node.thenExpression = _newNode as Expression;
12760 return true;
12761 } else if (identical(node.elseExpression, _oldNode)) {
12762 node.elseExpression = _newNode as Expression;
12763 return true;
12764 }
12765 return visitNode(node);
12766 }
12767
12768 @override
12769 bool visitConstructorDeclaration(ConstructorDeclaration node) {
12770 if (identical(node.returnType, _oldNode)) {
12771 node.returnType = _newNode as Identifier;
12772 return true;
12773 } else if (identical(node.name, _oldNode)) {
12774 node.name = _newNode as SimpleIdentifier;
12775 return true;
12776 } else if (identical(node.parameters, _oldNode)) {
12777 node.parameters = _newNode as FormalParameterList;
12778 return true;
12779 } else if (identical(node.redirectedConstructor, _oldNode)) {
12780 node.redirectedConstructor = _newNode as ConstructorName;
12781 return true;
12782 } else if (identical(node.body, _oldNode)) {
12783 node.body = _newNode as FunctionBody;
12784 return true;
12785 } else if (_replaceInList(node.initializers)) {
12786 return true;
12787 }
12788 return visitAnnotatedNode(node);
12789 }
12790
12791 @override
12792 bool visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
12793 if (identical(node.fieldName, _oldNode)) {
12794 node.fieldName = _newNode as SimpleIdentifier;
12795 return true;
12796 } else if (identical(node.expression, _oldNode)) {
12797 node.expression = _newNode as Expression;
12798 return true;
12799 }
12800 return visitNode(node);
12801 }
12802
12803 @override
12804 bool visitConstructorName(ConstructorName node) {
12805 if (identical(node.type, _oldNode)) {
12806 node.type = _newNode as TypeName;
12807 return true;
12808 } else if (identical(node.name, _oldNode)) {
12809 node.name = _newNode as SimpleIdentifier;
12810 return true;
12811 }
12812 return visitNode(node);
12813 }
12814
12815 @override
12816 bool visitContinueStatement(ContinueStatement node) {
12817 if (identical(node.label, _oldNode)) {
12818 node.label = _newNode as SimpleIdentifier;
12819 return true;
12820 }
12821 return visitNode(node);
12822 }
12823
12824 @override
12825 bool visitDeclaredIdentifier(DeclaredIdentifier node) {
12826 if (identical(node.type, _oldNode)) {
12827 node.type = _newNode as TypeName;
12828 return true;
12829 } else if (identical(node.identifier, _oldNode)) {
12830 node.identifier = _newNode as SimpleIdentifier;
12831 return true;
12832 }
12833 return visitAnnotatedNode(node);
12834 }
12835
12836 @override
12837 bool visitDefaultFormalParameter(DefaultFormalParameter node) {
12838 if (identical(node.parameter, _oldNode)) {
12839 node.parameter = _newNode as NormalFormalParameter;
12840 return true;
12841 } else if (identical(node.defaultValue, _oldNode)) {
12842 node.defaultValue = _newNode as Expression;
12843 return true;
12844 }
12845 return visitNode(node);
12846 }
12847
12848 @override
12849 bool visitDoStatement(DoStatement node) {
12850 if (identical(node.body, _oldNode)) {
12851 node.body = _newNode as Statement;
12852 return true;
12853 } else if (identical(node.condition, _oldNode)) {
12854 node.condition = _newNode as Expression;
12855 return true;
12856 }
12857 return visitNode(node);
12858 }
12859
12860 @override
12861 bool visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
12862
12863 @override
12864 bool visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
12865
12866 @override
12867 bool visitEmptyStatement(EmptyStatement node) => visitNode(node);
12868
12869 @override
12870 bool visitEnumConstantDeclaration(EnumConstantDeclaration node) {
12871 if (identical(node.name, _oldNode)) {
12872 node.name = _newNode as SimpleIdentifier;
12873 return true;
12874 }
12875 return visitAnnotatedNode(node);
12876 }
12877
12878 @override
12879 bool visitEnumDeclaration(EnumDeclaration node) {
12880 if (identical(node.name, _oldNode)) {
12881 node.name = _newNode as SimpleIdentifier;
12882 return true;
12883 } else if (_replaceInList(node.constants)) {
12884 return true;
12885 }
12886 return visitAnnotatedNode(node);
12887 }
12888
12889 @override
12890 bool visitExportDirective(ExportDirective node) =>
12891 visitNamespaceDirective(node);
12892
12893 @override
12894 bool visitExpressionFunctionBody(ExpressionFunctionBody node) {
12895 if (identical(node.expression, _oldNode)) {
12896 node.expression = _newNode as Expression;
12897 return true;
12898 }
12899 return visitNode(node);
12900 }
12901
12902 @override
12903 bool visitExpressionStatement(ExpressionStatement node) {
12904 if (identical(node.expression, _oldNode)) {
12905 node.expression = _newNode as Expression;
12906 return true;
12907 }
12908 return visitNode(node);
12909 }
12910
12911 @override
12912 bool visitExtendsClause(ExtendsClause node) {
12913 if (identical(node.superclass, _oldNode)) {
12914 node.superclass = _newNode as TypeName;
12915 return true;
12916 }
12917 return visitNode(node);
12918 }
12919
12920 @override
12921 bool visitFieldDeclaration(FieldDeclaration node) {
12922 if (identical(node.fields, _oldNode)) {
12923 node.fields = _newNode as VariableDeclarationList;
12924 return true;
12925 }
12926 return visitAnnotatedNode(node);
12927 }
12928
12929 @override
12930 bool visitFieldFormalParameter(FieldFormalParameter node) {
12931 if (identical(node.type, _oldNode)) {
12932 node.type = _newNode as TypeName;
12933 return true;
12934 } else if (identical(node.parameters, _oldNode)) {
12935 node.parameters = _newNode as FormalParameterList;
12936 return true;
12937 }
12938 return visitNormalFormalParameter(node);
12939 }
12940
12941 @override
12942 bool visitForEachStatement(ForEachStatement node) {
12943 if (identical(node.loopVariable, _oldNode)) {
12944 node.loopVariable = _newNode as DeclaredIdentifier;
12945 return true;
12946 } else if (identical(node.identifier, _oldNode)) {
12947 node.identifier = _newNode as SimpleIdentifier;
12948 return true;
12949 } else if (identical(node.iterable, _oldNode)) {
12950 node.iterable = _newNode as Expression;
12951 return true;
12952 } else if (identical(node.body, _oldNode)) {
12953 node.body = _newNode as Statement;
12954 return true;
12955 }
12956 return visitNode(node);
12957 }
12958
12959 @override
12960 bool visitFormalParameterList(FormalParameterList node) {
12961 if (_replaceInList(node.parameters)) {
12962 return true;
12963 }
12964 return visitNode(node);
12965 }
12966
12967 @override
12968 bool visitForStatement(ForStatement node) {
12969 if (identical(node.variables, _oldNode)) {
12970 node.variables = _newNode as VariableDeclarationList;
12971 return true;
12972 } else if (identical(node.initialization, _oldNode)) {
12973 node.initialization = _newNode as Expression;
12974 return true;
12975 } else if (identical(node.condition, _oldNode)) {
12976 node.condition = _newNode as Expression;
12977 return true;
12978 } else if (identical(node.body, _oldNode)) {
12979 node.body = _newNode as Statement;
12980 return true;
12981 } else if (_replaceInList(node.updaters)) {
12982 return true;
12983 }
12984 return visitNode(node);
12985 }
12986
12987 @override
12988 bool visitFunctionDeclaration(FunctionDeclaration node) {
12989 if (identical(node.returnType, _oldNode)) {
12990 node.returnType = _newNode as TypeName;
12991 return true;
12992 } else if (identical(node.name, _oldNode)) {
12993 node.name = _newNode as SimpleIdentifier;
12994 return true;
12995 } else if (identical(node.functionExpression, _oldNode)) {
12996 node.functionExpression = _newNode as FunctionExpression;
12997 return true;
12998 }
12999 return visitAnnotatedNode(node);
13000 }
13001
13002 @override
13003 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
13004 if (identical(node.functionDeclaration, _oldNode)) {
13005 node.functionDeclaration = _newNode as FunctionDeclaration;
13006 return true;
13007 }
13008 return visitNode(node);
13009 }
13010
13011 @override
13012 bool visitFunctionExpression(FunctionExpression node) {
13013 if (identical(node.parameters, _oldNode)) {
13014 node.parameters = _newNode as FormalParameterList;
13015 return true;
13016 } else if (identical(node.body, _oldNode)) {
13017 node.body = _newNode as FunctionBody;
13018 return true;
13019 }
13020 return visitNode(node);
13021 }
13022
13023 @override
13024 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
13025 if (identical(node.function, _oldNode)) {
13026 node.function = _newNode as Expression;
13027 return true;
13028 } else if (identical(node.argumentList, _oldNode)) {
13029 node.argumentList = _newNode as ArgumentList;
13030 return true;
13031 }
13032 return visitNode(node);
13033 }
13034
13035 @override
13036 bool visitFunctionTypeAlias(FunctionTypeAlias node) {
13037 if (identical(node.returnType, _oldNode)) {
13038 node.returnType = _newNode as TypeName;
13039 return true;
13040 } else if (identical(node.name, _oldNode)) {
13041 node.name = _newNode as SimpleIdentifier;
13042 return true;
13043 } else if (identical(node.typeParameters, _oldNode)) {
13044 node.typeParameters = _newNode as TypeParameterList;
13045 return true;
13046 } else if (identical(node.parameters, _oldNode)) {
13047 node.parameters = _newNode as FormalParameterList;
13048 return true;
13049 }
13050 return visitAnnotatedNode(node);
13051 }
13052
13053 @override
13054 bool visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
13055 if (identical(node.returnType, _oldNode)) {
13056 node.returnType = _newNode as TypeName;
13057 return true;
13058 } else if (identical(node.parameters, _oldNode)) {
13059 node.parameters = _newNode as FormalParameterList;
13060 return true;
13061 }
13062 return visitNormalFormalParameter(node);
13063 }
13064
13065 @override
13066 bool visitHideCombinator(HideCombinator node) {
13067 if (_replaceInList(node.hiddenNames)) {
13068 return true;
13069 }
13070 return visitNode(node);
13071 }
13072
13073 @override
13074 bool visitIfStatement(IfStatement node) {
13075 if (identical(node.condition, _oldNode)) {
13076 node.condition = _newNode as Expression;
13077 return true;
13078 } else if (identical(node.thenStatement, _oldNode)) {
13079 node.thenStatement = _newNode as Statement;
13080 return true;
13081 } else if (identical(node.elseStatement, _oldNode)) {
13082 node.elseStatement = _newNode as Statement;
13083 return true;
13084 }
13085 return visitNode(node);
13086 }
13087
13088 @override
13089 bool visitImplementsClause(ImplementsClause node) {
13090 if (_replaceInList(node.interfaces)) {
13091 return true;
13092 }
13093 return visitNode(node);
13094 }
13095
13096 @override
13097 bool visitImportDirective(ImportDirective node) {
13098 if (identical(node.prefix, _oldNode)) {
13099 node.prefix = _newNode as SimpleIdentifier;
13100 return true;
13101 }
13102 return visitNamespaceDirective(node);
13103 }
13104
13105 @override
13106 bool visitIndexExpression(IndexExpression node) {
13107 if (identical(node.target, _oldNode)) {
13108 node.target = _newNode as Expression;
13109 return true;
13110 } else if (identical(node.index, _oldNode)) {
13111 node.index = _newNode as Expression;
13112 return true;
13113 }
13114 return visitNode(node);
13115 }
13116
13117 @override
13118 bool visitInstanceCreationExpression(InstanceCreationExpression node) {
13119 if (identical(node.constructorName, _oldNode)) {
13120 node.constructorName = _newNode as ConstructorName;
13121 return true;
13122 } else if (identical(node.argumentList, _oldNode)) {
13123 node.argumentList = _newNode as ArgumentList;
13124 return true;
13125 }
13126 return visitNode(node);
13127 }
13128
13129 @override
13130 bool visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
13131
13132 @override
13133 bool visitInterpolationExpression(InterpolationExpression node) {
13134 if (identical(node.expression, _oldNode)) {
13135 node.expression = _newNode as Expression;
13136 return true;
13137 }
13138 return visitNode(node);
13139 }
13140
13141 @override
13142 bool visitInterpolationString(InterpolationString node) => visitNode(node);
13143
13144 @override
13145 bool visitIsExpression(IsExpression node) {
13146 if (identical(node.expression, _oldNode)) {
13147 node.expression = _newNode as Expression;
13148 return true;
13149 } else if (identical(node.type, _oldNode)) {
13150 node.type = _newNode as TypeName;
13151 return true;
13152 }
13153 return visitNode(node);
13154 }
13155
13156 @override
13157 bool visitLabel(Label node) {
13158 if (identical(node.label, _oldNode)) {
13159 node.label = _newNode as SimpleIdentifier;
13160 return true;
13161 }
13162 return visitNode(node);
13163 }
13164
13165 @override
13166 bool visitLabeledStatement(LabeledStatement node) {
13167 if (identical(node.statement, _oldNode)) {
13168 node.statement = _newNode as Statement;
13169 return true;
13170 } else if (_replaceInList(node.labels)) {
13171 return true;
13172 }
13173 return visitNode(node);
13174 }
13175
13176 @override
13177 bool visitLibraryDirective(LibraryDirective node) {
13178 if (identical(node.name, _oldNode)) {
13179 node.name = _newNode as LibraryIdentifier;
13180 return true;
13181 }
13182 return visitAnnotatedNode(node);
13183 }
13184
13185 @override
13186 bool visitLibraryIdentifier(LibraryIdentifier node) {
13187 if (_replaceInList(node.components)) {
13188 return true;
13189 }
13190 return visitNode(node);
13191 }
13192
13193 @override
13194 bool visitListLiteral(ListLiteral node) {
13195 if (_replaceInList(node.elements)) {
13196 return true;
13197 }
13198 return visitTypedLiteral(node);
13199 }
13200
13201 @override
13202 bool visitMapLiteral(MapLiteral node) {
13203 if (_replaceInList(node.entries)) {
13204 return true;
13205 }
13206 return visitTypedLiteral(node);
13207 }
13208
13209 @override
13210 bool visitMapLiteralEntry(MapLiteralEntry node) {
13211 if (identical(node.key, _oldNode)) {
13212 node.key = _newNode as Expression;
13213 return true;
13214 } else if (identical(node.value, _oldNode)) {
13215 node.value = _newNode as Expression;
13216 return true;
13217 }
13218 return visitNode(node);
13219 }
13220
13221 @override
13222 bool visitMethodDeclaration(MethodDeclaration node) {
13223 if (identical(node.returnType, _oldNode)) {
13224 node.returnType = _newNode as TypeName;
13225 return true;
13226 } else if (identical(node.name, _oldNode)) {
13227 node.name = _newNode as SimpleIdentifier;
13228 return true;
13229 } else if (identical(node.parameters, _oldNode)) {
13230 node.parameters = _newNode as FormalParameterList;
13231 return true;
13232 } else if (identical(node.body, _oldNode)) {
13233 node.body = _newNode as FunctionBody;
13234 return true;
13235 }
13236 return visitAnnotatedNode(node);
13237 }
13238
13239 @override
13240 bool visitMethodInvocation(MethodInvocation node) {
13241 if (identical(node.target, _oldNode)) {
13242 node.target = _newNode as Expression;
13243 return true;
13244 } else if (identical(node.methodName, _oldNode)) {
13245 node.methodName = _newNode as SimpleIdentifier;
13246 return true;
13247 } else if (identical(node.argumentList, _oldNode)) {
13248 node.argumentList = _newNode as ArgumentList;
13249 return true;
13250 }
13251 return visitNode(node);
13252 }
13253
13254 @override
13255 bool visitNamedExpression(NamedExpression node) {
13256 if (identical(node.name, _oldNode)) {
13257 node.name = _newNode as Label;
13258 return true;
13259 } else if (identical(node.expression, _oldNode)) {
13260 node.expression = _newNode as Expression;
13261 return true;
13262 }
13263 return visitNode(node);
13264 }
13265
13266 bool visitNamespaceDirective(NamespaceDirective node) {
13267 if (_replaceInList(node.combinators)) {
13268 return true;
13269 }
13270 return visitUriBasedDirective(node);
13271 }
13272
13273 @override
13274 bool visitNativeClause(NativeClause node) {
13275 if (identical(node.name, _oldNode)) {
13276 node.name = _newNode as StringLiteral;
13277 return true;
13278 }
13279 return visitNode(node);
13280 }
13281
13282 @override
13283 bool visitNativeFunctionBody(NativeFunctionBody node) {
13284 if (identical(node.stringLiteral, _oldNode)) {
13285 node.stringLiteral = _newNode as StringLiteral;
13286 return true;
13287 }
13288 return visitNode(node);
13289 }
13290
13291 bool visitNode(AstNode node) {
13292 throw new IllegalArgumentException(
13293 "The old node is not a child of it's parent");
13294 }
13295
13296 bool visitNormalFormalParameter(NormalFormalParameter node) {
13297 if (identical(node.documentationComment, _oldNode)) {
13298 node.documentationComment = _newNode as Comment;
13299 return true;
13300 } else if (identical(node.identifier, _oldNode)) {
13301 node.identifier = _newNode as SimpleIdentifier;
13302 return true;
13303 } else if (_replaceInList(node.metadata)) {
13304 return true;
13305 }
13306 return visitNode(node);
13307 }
13308
13309 @override
13310 bool visitNullLiteral(NullLiteral node) => visitNode(node);
13311
13312 @override
13313 bool visitParenthesizedExpression(ParenthesizedExpression node) {
13314 if (identical(node.expression, _oldNode)) {
13315 node.expression = _newNode as Expression;
13316 return true;
13317 }
13318 return visitNode(node);
13319 }
13320
13321 @override
13322 bool visitPartDirective(PartDirective node) => visitUriBasedDirective(node);
13323
13324 @override
13325 bool visitPartOfDirective(PartOfDirective node) {
13326 if (identical(node.libraryName, _oldNode)) {
13327 node.libraryName = _newNode as LibraryIdentifier;
13328 return true;
13329 }
13330 return visitAnnotatedNode(node);
13331 }
13332
13333 @override
13334 bool visitPostfixExpression(PostfixExpression node) {
13335 if (identical(node.operand, _oldNode)) {
13336 node.operand = _newNode as Expression;
13337 return true;
13338 }
13339 return visitNode(node);
13340 }
13341
13342 @override
13343 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
13344 if (identical(node.prefix, _oldNode)) {
13345 node.prefix = _newNode as SimpleIdentifier;
13346 return true;
13347 } else if (identical(node.identifier, _oldNode)) {
13348 node.identifier = _newNode as SimpleIdentifier;
13349 return true;
13350 }
13351 return visitNode(node);
13352 }
13353
13354 @override
13355 bool visitPrefixExpression(PrefixExpression node) {
13356 if (identical(node.operand, _oldNode)) {
13357 node.operand = _newNode as Expression;
13358 return true;
13359 }
13360 return visitNode(node);
13361 }
13362
13363 @override
13364 bool visitPropertyAccess(PropertyAccess node) {
13365 if (identical(node.target, _oldNode)) {
13366 node.target = _newNode as Expression;
13367 return true;
13368 } else if (identical(node.propertyName, _oldNode)) {
13369 node.propertyName = _newNode as SimpleIdentifier;
13370 return true;
13371 }
13372 return visitNode(node);
13373 }
13374
13375 @override
13376 bool visitRedirectingConstructorInvocation(
13377 RedirectingConstructorInvocation node) {
13378 if (identical(node.constructorName, _oldNode)) {
13379 node.constructorName = _newNode as SimpleIdentifier;
13380 return true;
13381 } else if (identical(node.argumentList, _oldNode)) {
13382 node.argumentList = _newNode as ArgumentList;
13383 return true;
13384 }
13385 return visitNode(node);
13386 }
13387
13388 @override
13389 bool visitRethrowExpression(RethrowExpression node) => visitNode(node);
13390
13391 @override
13392 bool visitReturnStatement(ReturnStatement node) {
13393 if (identical(node.expression, _oldNode)) {
13394 node.expression = _newNode as Expression;
13395 return true;
13396 }
13397 return visitNode(node);
13398 }
13399
13400 @override
13401 bool visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
13402
13403 @override
13404 bool visitShowCombinator(ShowCombinator node) {
13405 if (_replaceInList(node.shownNames)) {
13406 return true;
13407 }
13408 return visitNode(node);
13409 }
13410
13411 @override
13412 bool visitSimpleFormalParameter(SimpleFormalParameter node) {
13413 if (identical(node.type, _oldNode)) {
13414 node.type = _newNode as TypeName;
13415 return true;
13416 }
13417 return visitNormalFormalParameter(node);
13418 }
13419
13420 @override
13421 bool visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
13422
13423 @override
13424 bool visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
13425
13426 @override
13427 bool visitStringInterpolation(StringInterpolation node) {
13428 if (_replaceInList(node.elements)) {
13429 return true;
13430 }
13431 return visitNode(node);
13432 }
13433
13434 @override
13435 bool visitSuperConstructorInvocation(SuperConstructorInvocation node) {
13436 if (identical(node.constructorName, _oldNode)) {
13437 node.constructorName = _newNode as SimpleIdentifier;
13438 return true;
13439 } else if (identical(node.argumentList, _oldNode)) {
13440 node.argumentList = _newNode as ArgumentList;
13441 return true;
13442 }
13443 return visitNode(node);
13444 }
13445
13446 @override
13447 bool visitSuperExpression(SuperExpression node) => visitNode(node);
13448
13449 @override
13450 bool visitSwitchCase(SwitchCase node) {
13451 if (identical(node.expression, _oldNode)) {
13452 node.expression = _newNode as Expression;
13453 return true;
13454 }
13455 return visitSwitchMember(node);
13456 }
13457
13458 @override
13459 bool visitSwitchDefault(SwitchDefault node) => visitSwitchMember(node);
13460
13461 bool visitSwitchMember(SwitchMember node) {
13462 if (_replaceInList(node.labels)) {
13463 return true;
13464 } else if (_replaceInList(node.statements)) {
13465 return true;
13466 }
13467 return visitNode(node);
13468 }
13469
13470 @override
13471 bool visitSwitchStatement(SwitchStatement node) {
13472 if (identical(node.expression, _oldNode)) {
13473 node.expression = _newNode as Expression;
13474 return true;
13475 } else if (_replaceInList(node.members)) {
13476 return true;
13477 }
13478 return visitNode(node);
13479 }
13480
13481 @override
13482 bool visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
13483
13484 @override
13485 bool visitThisExpression(ThisExpression node) => visitNode(node);
13486
13487 @override
13488 bool visitThrowExpression(ThrowExpression node) {
13489 if (identical(node.expression, _oldNode)) {
13490 node.expression = _newNode as Expression;
13491 return true;
13492 }
13493 return visitNode(node);
13494 }
13495
13496 @override
13497 bool visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
13498 if (identical(node.variables, _oldNode)) {
13499 node.variables = _newNode as VariableDeclarationList;
13500 return true;
13501 }
13502 return visitAnnotatedNode(node);
13503 }
13504
13505 @override
13506 bool visitTryStatement(TryStatement node) {
13507 if (identical(node.body, _oldNode)) {
13508 node.body = _newNode as Block;
13509 return true;
13510 } else if (identical(node.finallyBlock, _oldNode)) {
13511 node.finallyBlock = _newNode as Block;
13512 return true;
13513 } else if (_replaceInList(node.catchClauses)) {
13514 return true;
13515 }
13516 return visitNode(node);
13517 }
13518
13519 @override
13520 bool visitTypeArgumentList(TypeArgumentList node) {
13521 if (_replaceInList(node.arguments)) {
13522 return true;
13523 }
13524 return visitNode(node);
13525 }
13526
13527 bool visitTypedLiteral(TypedLiteral node) {
13528 if (identical(node.typeArguments, _oldNode)) {
13529 node.typeArguments = _newNode as TypeArgumentList;
13530 return true;
13531 }
13532 return visitNode(node);
13533 }
13534
13535 @override
13536 bool visitTypeName(TypeName node) {
13537 if (identical(node.name, _oldNode)) {
13538 node.name = _newNode as Identifier;
13539 return true;
13540 } else if (identical(node.typeArguments, _oldNode)) {
13541 node.typeArguments = _newNode as TypeArgumentList;
13542 return true;
13543 }
13544 return visitNode(node);
13545 }
13546
13547 @override
13548 bool visitTypeParameter(TypeParameter node) {
13549 if (identical(node.name, _oldNode)) {
13550 node.name = _newNode as SimpleIdentifier;
13551 return true;
13552 } else if (identical(node.bound, _oldNode)) {
13553 node.bound = _newNode as TypeName;
13554 return true;
13555 }
13556 return visitNode(node);
13557 }
13558
13559 @override
13560 bool visitTypeParameterList(TypeParameterList node) {
13561 if (_replaceInList(node.typeParameters)) {
13562 return true;
13563 }
13564 return visitNode(node);
13565 }
13566
13567 bool visitUriBasedDirective(UriBasedDirective node) {
13568 if (identical(node.uri, _oldNode)) {
13569 node.uri = _newNode as StringLiteral;
13570 return true;
13571 }
13572 return visitAnnotatedNode(node);
13573 }
13574
13575 @override
13576 bool visitVariableDeclaration(VariableDeclaration node) {
13577 if (identical(node.name, _oldNode)) {
13578 node.name = _newNode as SimpleIdentifier;
13579 return true;
13580 } else if (identical(node.initializer, _oldNode)) {
13581 node.initializer = _newNode as Expression;
13582 return true;
13583 }
13584 return visitAnnotatedNode(node);
13585 }
13586
13587 @override
13588 bool visitVariableDeclarationList(VariableDeclarationList node) {
13589 if (identical(node.type, _oldNode)) {
13590 node.type = _newNode as TypeName;
13591 return true;
13592 } else if (_replaceInList(node.variables)) {
13593 return true;
13594 }
13595 return visitNode(node);
13596 }
13597
13598 @override
13599 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) {
13600 if (identical(node.variables, _oldNode)) {
13601 node.variables = _newNode as VariableDeclarationList;
13602 return true;
13603 }
13604 return visitNode(node);
13605 }
13606
13607 @override
13608 bool visitWhileStatement(WhileStatement node) {
13609 if (identical(node.condition, _oldNode)) {
13610 node.condition = _newNode as Expression;
13611 return true;
13612 } else if (identical(node.body, _oldNode)) {
13613 node.body = _newNode as Statement;
13614 return true;
13615 }
13616 return visitNode(node);
13617 }
13618
13619 @override
13620 bool visitWithClause(WithClause node) {
13621 if (_replaceInList(node.mixinTypes)) {
13622 return true;
13623 }
13624 return visitNode(node);
13625 }
13626
13627 @override
13628 bool visitYieldStatement(YieldStatement node) {
13629 if (identical(node.expression, _oldNode)) {
13630 node.expression = _newNode as Expression;
13631 return true;
13632 }
13633 return visitNode(node);
13634 }
13635
13636 bool _replaceInList(NodeList list) {
13637 int count = list.length;
13638 for (int i = 0; i < count; i++) {
13639 if (identical(_oldNode, list[i])) {
13640 list[i] = _newNode;
13641 return true;
13642 }
13643 }
13644 return false;
13645 }
13646
13647 /**
13648 * Replace the [oldNode] with the [newNode] in the AST structure containing
13649 * the old node. Return `true` if the replacement was successful.
13650 *
13651 * Throws an [IllegalArgumentException] if either node is `null`, if the old
13652 * node does not have a parent node, or if the AST structure has been
13653 * corrupted.
13654 */
13655 static bool replace(AstNode oldNode, AstNode newNode) {
13656 if (oldNode == null || newNode == null) {
13657 throw new IllegalArgumentException(
13658 "The old and new nodes must be non-null");
13659 } else if (identical(oldNode, newNode)) {
13660 return true;
13661 }
13662 AstNode parent = oldNode.parent;
13663 if (parent == null) {
13664 throw new IllegalArgumentException(
13665 "The old node is not a child of another node");
13666 }
13667 NodeReplacer replacer = new NodeReplacer(oldNode, newNode);
13668 return parent.accept(replacer);
13669 }
13670 }
13671
13672 /**
13673 * A formal parameter that is required (is not optional).
13674 *
13675 * > normalFormalParameter ::=
13676 * > [FunctionTypedFormalParameter]
13677 * > | [FieldFormalParameter]
13678 * > | [SimpleFormalParameter]
13679 */
13680 abstract class NormalFormalParameter extends FormalParameter {
13681 /**
13682 * The documentation comment associated with this parameter, or `null` if this
13683 * parameter does not have a documentation comment associated with it.
13684 */
13685 Comment _comment;
13686
13687 /**
13688 * The annotations associated with this parameter.
13689 */
13690 NodeList<Annotation> _metadata;
13691
13692 /**
13693 * The name of the parameter being declared.
13694 */
13695 SimpleIdentifier _identifier;
13696
13697 /**
13698 * Initialize a newly created formal parameter. Either or both of the
13699 * [comment] and [metadata] can be `null` if the parameter does not have the
13700 * corresponding attribute.
13701 */
13702 NormalFormalParameter(
13703 Comment comment, List<Annotation> metadata, SimpleIdentifier identifier) {
13704 _comment = _becomeParentOf(comment);
13705 _metadata = new NodeList<Annotation>(this, metadata);
13706 _identifier = _becomeParentOf(identifier);
13707 }
13708
13709 /**
13710 * Return the documentation comment associated with this parameter, or `null`
13711 * if this parameter does not have a documentation comment associated with it.
13712 */
13713 Comment get documentationComment => _comment;
13714
13715 /**
13716 * Set the documentation comment associated with this parameter to the given
13717 * [comment].
13718 */
13719 void set documentationComment(Comment comment) {
13720 _comment = _becomeParentOf(comment);
13721 }
13722
13723 @override
13724 SimpleIdentifier get identifier => _identifier;
13725
13726 /**
13727 * Set the name of the parameter being declared to the given [identifier].
13728 */
13729 void set identifier(SimpleIdentifier identifier) {
13730 _identifier = _becomeParentOf(identifier);
13731 }
13732
13733 @override
13734 ParameterKind get kind {
13735 AstNode parent = this.parent;
13736 if (parent is DefaultFormalParameter) {
13737 return parent.kind;
13738 }
13739 return ParameterKind.REQUIRED;
13740 }
13741
13742 @override
13743 NodeList<Annotation> get metadata => _metadata;
13744
13745 /**
13746 * Set the metadata associated with this node to the given [metadata].
13747 */
13748 void set metadata(List<Annotation> metadata) {
13749 _metadata.clear();
13750 _metadata.addAll(metadata);
13751 }
13752
13753 /**
13754 * Return a list containing the comment and annotations associated with this
13755 * parameter, sorted in lexical order.
13756 */
13757 List<AstNode> get sortedCommentAndAnnotations {
13758 return <AstNode>[]
13759 ..add(_comment)
13760 ..addAll(_metadata)
13761 ..sort(AstNode.LEXICAL_ORDER);
13762 }
13763
13764 ChildEntities get _childEntities {
13765 ChildEntities result = new ChildEntities();
13766 if (_commentIsBeforeAnnotations()) {
13767 result
13768 ..add(_comment)
13769 ..addAll(_metadata);
13770 } else {
13771 result.addAll(sortedCommentAndAnnotations);
13772 }
13773 return result;
13774 }
13775
13776 @override
13777 void visitChildren(AstVisitor visitor) {
13778 //
13779 // Note that subclasses are responsible for visiting the identifier because
13780 // they often need to visit other nodes before visiting the identifier.
13781 //
13782 if (_commentIsBeforeAnnotations()) {
13783 _safelyVisitChild(_comment, visitor);
13784 _metadata.accept(visitor);
13785 } else {
13786 for (AstNode child in sortedCommentAndAnnotations) {
13787 child.accept(visitor);
13788 }
13789 }
13790 }
13791
13792 /**
13793 * Return `true` if the comment is lexically before any annotations.
13794 */
13795 bool _commentIsBeforeAnnotations() {
13796 if (_comment == null || _metadata.isEmpty) {
13797 return true;
13798 }
13799 Annotation firstAnnotation = _metadata[0];
13800 return _comment.offset < firstAnnotation.offset;
13801 }
13802 }
13803
13804 /**
13805 * A null literal expression.
13806 *
13807 * > nullLiteral ::=
13808 * > 'null'
13809 */
13810 class NullLiteral extends Literal {
13811 /**
13812 * The token representing the literal.
13813 */
13814 Token literal;
13815
13816 /**
13817 * Initialize a newly created null literal.
13818 */
13819 NullLiteral(this.literal);
13820
13821 @override
13822 Token get beginToken => literal;
13823
13824 @override
13825 Iterable get childEntities => new ChildEntities()..add(literal);
13826
13827 @override
13828 Token get endToken => literal;
13829
13830 @override
13831 accept(AstVisitor visitor) => visitor.visitNullLiteral(this);
13832
13833 @override
13834 void visitChildren(AstVisitor visitor) {
13835 // There are no children to visit.
13836 }
13837 }
13838
13839 /**
13840 * A parenthesized expression.
13841 *
13842 * > parenthesizedExpression ::=
13843 * > '(' [Expression] ')'
13844 */
13845 class ParenthesizedExpression extends Expression {
13846 /**
13847 * The left parenthesis.
13848 */
13849 Token leftParenthesis;
13850
13851 /**
13852 * The expression within the parentheses.
13853 */
13854 Expression _expression;
13855
13856 /**
13857 * The right parenthesis.
13858 */
13859 Token rightParenthesis;
13860
13861 /**
13862 * Initialize a newly created parenthesized expression.
13863 */
13864 ParenthesizedExpression(
13865 this.leftParenthesis, Expression expression, this.rightParenthesis) {
13866 _expression = _becomeParentOf(expression);
13867 }
13868
13869 @override
13870 Token get beginToken => leftParenthesis;
13871
13872 @override
13873 Iterable get childEntities => new ChildEntities()
13874 ..add(leftParenthesis)
13875 ..add(_expression)
13876 ..add(rightParenthesis);
13877
13878 @override
13879 Token get endToken => rightParenthesis;
13880
13881 /**
13882 * Return the expression within the parentheses.
13883 */
13884 Expression get expression => _expression;
13885
13886 /**
13887 * Set the expression within the parentheses to the given [expression].
13888 */
13889 void set expression(Expression expression) {
13890 _expression = _becomeParentOf(expression);
13891 }
13892
13893 @override
13894 int get precedence => 15;
13895
13896 @override
13897 accept(AstVisitor visitor) => visitor.visitParenthesizedExpression(this);
13898
13899 @override
13900 void visitChildren(AstVisitor visitor) {
13901 _safelyVisitChild(_expression, visitor);
13902 }
13903 }
13904
13905 /**
13906 * A part directive.
13907 *
13908 * > partDirective ::=
13909 * > [Annotation] 'part' [StringLiteral] ';'
13910 */
13911 class PartDirective extends UriBasedDirective {
13912 /**
13913 * The token representing the 'part' keyword.
13914 */
13915 Token partKeyword;
13916
13917 /**
13918 * The semicolon terminating the directive.
13919 */
13920 Token semicolon;
13921
13922 /**
13923 * Initialize a newly created part directive. Either or both of the [comment]
13924 * and [metadata] can be `null` if the directive does not have the
13925 * corresponding attribute.
13926 */
13927 PartDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
13928 StringLiteral partUri, this.semicolon)
13929 : super(comment, metadata, partUri);
13930
13931 @override
13932 Iterable get childEntities =>
13933 super._childEntities..add(partKeyword)..add(_uri)..add(semicolon);
13934
13935 @override
13936 Token get endToken => semicolon;
13937
13938 @override
13939 Token get firstTokenAfterCommentAndMetadata => partKeyword;
13940
13941 @override
13942 Token get keyword => partKeyword;
13943
13944 /**
13945 * Return the token representing the 'part' token.
13946 */
13947 @deprecated // Use "this.partKeyword"
13948 Token get partToken => partKeyword;
13949
13950 /**
13951 * Set the token representing the 'part' token to the given [token].
13952 */
13953 @deprecated // Use "this.partKeyword"
13954 set partToken(Token token) {
13955 partKeyword = token;
13956 }
13957
13958 @override
13959 CompilationUnitElement get uriElement => element as CompilationUnitElement;
13960
13961 @override
13962 accept(AstVisitor visitor) => visitor.visitPartDirective(this);
13963 }
13964
13965 /**
13966 * A part-of directive.
13967 *
13968 * > partOfDirective ::=
13969 * > [Annotation] 'part' 'of' [Identifier] ';'
13970 */
13971 class PartOfDirective extends Directive {
13972 /**
13973 * The token representing the 'part' keyword.
13974 */
13975 Token partKeyword;
13976
13977 /**
13978 * The token representing the 'of' keyword.
13979 */
13980 Token ofKeyword;
13981
13982 /**
13983 * The name of the library that the containing compilation unit is part of.
13984 */
13985 LibraryIdentifier _libraryName;
13986
13987 /**
13988 * The semicolon terminating the directive.
13989 */
13990 Token semicolon;
13991
13992 /**
13993 * Initialize a newly created part-of directive. Either or both of the
13994 * [comment] and [metadata] can be `null` if the directive does not have the
13995 * corresponding attribute.
13996 */
13997 PartOfDirective(Comment comment, List<Annotation> metadata, this.partKeyword,
13998 this.ofKeyword, LibraryIdentifier libraryName, this.semicolon)
13999 : super(comment, metadata) {
14000 _libraryName = _becomeParentOf(libraryName);
14001 }
14002
14003 @override
14004 Iterable get childEntities => super._childEntities
14005 ..add(partKeyword)
14006 ..add(ofKeyword)
14007 ..add(_libraryName)
14008 ..add(semicolon);
14009
14010 @override
14011 Token get endToken => semicolon;
14012
14013 @override
14014 Token get firstTokenAfterCommentAndMetadata => partKeyword;
14015
14016 @override
14017 Token get keyword => partKeyword;
14018
14019 /**
14020 * Return the name of the library that the containing compilation unit is part
14021 * of.
14022 */
14023 LibraryIdentifier get libraryName => _libraryName;
14024
14025 /**
14026 * Set the name of the library that the containing compilation unit is part of
14027 * to the given [libraryName].
14028 */
14029 void set libraryName(LibraryIdentifier libraryName) {
14030 _libraryName = _becomeParentOf(libraryName);
14031 }
14032
14033 /**
14034 * Return the token representing the 'of' token.
14035 */
14036 @deprecated // Use "this.ofKeyword"
14037 Token get ofToken => ofKeyword;
14038
14039 /**
14040 * Set the token representing the 'of' token to the given [token].
14041 */
14042 @deprecated // Use "this.ofKeyword"
14043 set ofToken(Token token) {
14044 ofKeyword = token;
14045 }
14046
14047 /**
14048 * Return the token representing the 'part' token.
14049 */
14050 @deprecated // Use "this.partKeyword"
14051 Token get partToken => partKeyword;
14052
14053 /**
14054 * Set the token representing the 'part' token to the given [token].
14055 */
14056 @deprecated // Use "this.partKeyword"
14057 set partToken(Token token) {
14058 partKeyword = token;
14059 }
14060
14061 @override
14062 accept(AstVisitor visitor) => visitor.visitPartOfDirective(this);
14063
14064 @override
14065 void visitChildren(AstVisitor visitor) {
14066 super.visitChildren(visitor);
14067 _safelyVisitChild(_libraryName, visitor);
14068 }
14069 }
14070
14071 /**
14072 * A postfix unary expression.
14073 *
14074 * > postfixExpression ::=
14075 * > [Expression] [Token]
14076 */
14077 class PostfixExpression extends Expression {
14078 /**
14079 * The expression computing the operand for the operator.
14080 */
14081 Expression _operand;
14082
14083 /**
14084 * The postfix operator being applied to the operand.
14085 */
14086 Token operator;
14087
14088 /**
14089 * The element associated with this the operator based on the propagated type
14090 * of the operand, or `null` if the AST structure has not been resolved, if
14091 * the operator is not user definable, or if the operator could not be
14092 * resolved.
14093 */
14094 MethodElement propagatedElement;
14095
14096 /**
14097 * The element associated with the operator based on the static type of the
14098 * operand, or `null` if the AST structure has not been resolved, if the
14099 * operator is not user definable, or if the operator could not be resolved.
14100 */
14101 MethodElement staticElement;
14102
14103 /**
14104 * Initialize a newly created postfix expression.
14105 */
14106 PostfixExpression(Expression operand, this.operator) {
14107 _operand = _becomeParentOf(operand);
14108 }
14109
14110 @override
14111 Token get beginToken => _operand.beginToken;
14112
14113 /**
14114 * Return the best element available for this operator. If resolution was able
14115 * to find a better element based on type propagation, that element will be
14116 * returned. Otherwise, the element found using the result of static analysis
14117 * will be returned. If resolution has not been performed, then `null` will be
14118 * returned.
14119 */
14120 MethodElement get bestElement {
14121 MethodElement element = propagatedElement;
14122 if (element == null) {
14123 element = staticElement;
14124 }
14125 return element;
14126 }
14127
14128 @override
14129 Iterable get childEntities =>
14130 new ChildEntities()..add(_operand)..add(operator);
14131
14132 @override
14133 Token get endToken => operator;
14134
14135 /**
14136 * Return the expression computing the operand for the operator.
14137 */
14138 Expression get operand => _operand;
14139
14140 /**
14141 * Set the expression computing the operand for the operator to the given
14142 * [expression].
14143 */
14144 void set operand(Expression expression) {
14145 _operand = _becomeParentOf(expression);
14146 }
14147
14148 @override
14149 int get precedence => 15;
14150
14151 /**
14152 * If the AST structure has been resolved, and the function being invoked is
14153 * known based on propagated type information, then return the parameter
14154 * element representing the parameter to which the value of the operand will
14155 * be bound. Otherwise, return `null`.
14156 */
14157 @deprecated // Use "expression.propagatedParameterElement"
14158 ParameterElement get propagatedParameterElementForOperand {
14159 return _propagatedParameterElementForOperand;
14160 }
14161
14162 /**
14163 * If the AST structure has been resolved, and the function being invoked is
14164 * known based on static type information, then return the parameter element
14165 * representing the parameter to which the value of the operand will be bound.
14166 * Otherwise, return `null`.
14167 */
14168 @deprecated // Use "expression.propagatedParameterElement"
14169 ParameterElement get staticParameterElementForOperand {
14170 return _staticParameterElementForOperand;
14171 }
14172
14173 /**
14174 * If the AST structure has been resolved, and the function being invoked is
14175 * known based on propagated type information, then return the parameter
14176 * element representing the parameter to which the value of the operand will
14177 * be bound. Otherwise, return `null`.
14178 */
14179 ParameterElement get _propagatedParameterElementForOperand {
14180 if (propagatedElement == null) {
14181 return null;
14182 }
14183 List<ParameterElement> parameters = propagatedElement.parameters;
14184 if (parameters.length < 1) {
14185 return null;
14186 }
14187 return parameters[0];
14188 }
14189
14190 /**
14191 * If the AST structure has been resolved, and the function being invoked is
14192 * known based on static type information, then return the parameter element
14193 * representing the parameter to which the value of the operand will be bound.
14194 * Otherwise, return `null`.
14195 */
14196 ParameterElement get _staticParameterElementForOperand {
14197 if (staticElement == null) {
14198 return null;
14199 }
14200 List<ParameterElement> parameters = staticElement.parameters;
14201 if (parameters.length < 1) {
14202 return null;
14203 }
14204 return parameters[0];
14205 }
14206
14207 @override
14208 accept(AstVisitor visitor) => visitor.visitPostfixExpression(this);
14209
14210 @override
14211 void visitChildren(AstVisitor visitor) {
14212 _safelyVisitChild(_operand, visitor);
14213 }
14214 }
14215
14216 /**
14217 * An identifier that is prefixed or an access to an object property where the
14218 * target of the property access is a simple identifier.
14219 *
14220 * > prefixedIdentifier ::=
14221 * > [SimpleIdentifier] '.' [SimpleIdentifier]
14222 */
14223 class PrefixedIdentifier extends Identifier {
14224 /**
14225 * The prefix associated with the library in which the identifier is defined.
14226 */
14227 SimpleIdentifier _prefix;
14228
14229 /**
14230 * The period used to separate the prefix from the identifier.
14231 */
14232 Token period;
14233
14234 /**
14235 * The identifier being prefixed.
14236 */
14237 SimpleIdentifier _identifier;
14238
14239 /**
14240 * Initialize a newly created prefixed identifier.
14241 */
14242 PrefixedIdentifier(
14243 SimpleIdentifier prefix, this.period, SimpleIdentifier identifier) {
14244 _prefix = _becomeParentOf(prefix);
14245 _identifier = _becomeParentOf(identifier);
14246 }
14247
14248 @override
14249 Token get beginToken => _prefix.beginToken;
14250
14251 @override
14252 Element get bestElement {
14253 if (_identifier == null) {
14254 return null;
14255 }
14256 return _identifier.bestElement;
14257 }
14258
14259 @override
14260 Iterable get childEntities =>
14261 new ChildEntities()..add(_prefix)..add(period)..add(_identifier);
14262
14263 @override
14264 Token get endToken => _identifier.endToken;
14265
14266 /**
14267 * Return the identifier being prefixed.
14268 */
14269 SimpleIdentifier get identifier => _identifier;
14270
14271 /**
14272 * Set the identifier being prefixed to the given [identifier].
14273 */
14274 void set identifier(SimpleIdentifier identifier) {
14275 _identifier = _becomeParentOf(identifier);
14276 }
14277
14278 /**
14279 * Return `true` if this type is a deferred type. If the AST structure has not
14280 * been resolved, then return `false`.
14281 *
14282 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form
14283 * </i>p.T</i> where <i>p</i> is a deferred prefix.
14284 */
14285 bool get isDeferred {
14286 Element element = _prefix.staticElement;
14287 if (element is! PrefixElement) {
14288 return false;
14289 }
14290 PrefixElement prefixElement = element as PrefixElement;
14291 List<ImportElement> imports =
14292 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement);
14293 if (imports.length != 1) {
14294 return false;
14295 }
14296 return imports[0].isDeferred;
14297 }
14298
14299 @override
14300 String get name => "${_prefix.name}.${_identifier.name}";
14301
14302 @override
14303 int get precedence => 15;
14304
14305 /**
14306 * Return the prefix associated with the library in which the identifier is
14307 * defined.
14308 */
14309 SimpleIdentifier get prefix => _prefix;
14310
14311 /**
14312 * Set the prefix associated with the library in which the identifier is
14313 * defined to the given [identifier].
14314 */
14315 void set prefix(SimpleIdentifier identifier) {
14316 _prefix = _becomeParentOf(identifier);
14317 }
14318
14319 @override
14320 Element get propagatedElement {
14321 if (_identifier == null) {
14322 return null;
14323 }
14324 return _identifier.propagatedElement;
14325 }
14326
14327 @override
14328 Element get staticElement {
14329 if (_identifier == null) {
14330 return null;
14331 }
14332 return _identifier.staticElement;
14333 }
14334
14335 @override
14336 accept(AstVisitor visitor) => visitor.visitPrefixedIdentifier(this);
14337
14338 @override
14339 void visitChildren(AstVisitor visitor) {
14340 _safelyVisitChild(_prefix, visitor);
14341 _safelyVisitChild(_identifier, visitor);
14342 }
14343 }
14344
14345 /**
14346 * A prefix unary expression.
14347 *
14348 * > prefixExpression ::=
14349 * > [Token] [Expression]
14350 */
14351 class PrefixExpression extends Expression {
14352 /**
14353 * The prefix operator being applied to the operand.
14354 */
14355 Token operator;
14356
14357 /**
14358 * The expression computing the operand for the operator.
14359 */
14360 Expression _operand;
14361
14362 /**
14363 * The element associated with the operator based on the static type of the
14364 * operand, or `null` if the AST structure has not been resolved, if the
14365 * operator is not user definable, or if the operator could not be resolved.
14366 */
14367 MethodElement staticElement;
14368
14369 /**
14370 * The element associated with the operator based on the propagated type of
14371 * the operand, or `null` if the AST structure has not been resolved, if the
14372 * operator is not user definable, or if the operator could not be resolved.
14373 */
14374 MethodElement propagatedElement;
14375
14376 /**
14377 * Initialize a newly created prefix expression.
14378 */
14379 PrefixExpression(this.operator, Expression operand) {
14380 _operand = _becomeParentOf(operand);
14381 }
14382
14383 @override
14384 Token get beginToken => operator;
14385
14386 /**
14387 * Return the best element available for this operator. If resolution was able
14388 * to find a better element based on type propagation, that element will be
14389 * returned. Otherwise, the element found using the result of static analysis
14390 * will be returned. If resolution has not been performed, then `null` will be
14391 * returned.
14392 */
14393 MethodElement get bestElement {
14394 MethodElement element = propagatedElement;
14395 if (element == null) {
14396 element = staticElement;
14397 }
14398 return element;
14399 }
14400
14401 @override
14402 Iterable get childEntities =>
14403 new ChildEntities()..add(operator)..add(_operand);
14404
14405 @override
14406 Token get endToken => _operand.endToken;
14407
14408 /**
14409 * Return the expression computing the operand for the operator.
14410 */
14411 Expression get operand => _operand;
14412
14413 /**
14414 * Set the expression computing the operand for the operator to the given
14415 * [expression].
14416 */
14417 void set operand(Expression expression) {
14418 _operand = _becomeParentOf(expression);
14419 }
14420
14421 @override
14422 int get precedence => 14;
14423
14424 /**
14425 * If the AST structure has been resolved, and the function being invoked is
14426 * known based on propagated type information, then return the parameter
14427 * element representing the parameter to which the value of the operand will
14428 * be bound. Otherwise, return `null`.
14429 */
14430 @deprecated // Use "expression.propagatedParameterElement"
14431 ParameterElement get propagatedParameterElementForOperand {
14432 return _propagatedParameterElementForOperand;
14433 }
14434
14435 /**
14436 * If the AST structure has been resolved, and the function being invoked is
14437 * known based on static type information, then return the parameter element
14438 * representing the parameter to which the value of the operand will be bound.
14439 * Otherwise, return `null`.
14440 */
14441 @deprecated // Use "expression.propagatedParameterElement"
14442 ParameterElement get staticParameterElementForOperand {
14443 return _staticParameterElementForOperand;
14444 }
14445
14446 /**
14447 * If the AST structure has been resolved, and the function being invoked is
14448 * known based on propagated type information, then return the parameter
14449 * element representing the parameter to which the value of the operand will
14450 * be bound. Otherwise, return `null`.
14451 */
14452 ParameterElement get _propagatedParameterElementForOperand {
14453 if (propagatedElement == null) {
14454 return null;
14455 }
14456 List<ParameterElement> parameters = propagatedElement.parameters;
14457 if (parameters.length < 1) {
14458 return null;
14459 }
14460 return parameters[0];
14461 }
14462
14463 /**
14464 * If the AST structure has been resolved, and the function being invoked is
14465 * known based on static type information, then return the parameter element
14466 * representing the parameter to which the value of the operand will be bound.
14467 * Otherwise, return `null`.
14468 */
14469 ParameterElement get _staticParameterElementForOperand {
14470 if (staticElement == null) {
14471 return null;
14472 }
14473 List<ParameterElement> parameters = staticElement.parameters;
14474 if (parameters.length < 1) {
14475 return null;
14476 }
14477 return parameters[0];
14478 }
14479
14480 @override
14481 accept(AstVisitor visitor) => visitor.visitPrefixExpression(this);
14482
14483 @override
14484 void visitChildren(AstVisitor visitor) {
14485 _safelyVisitChild(_operand, visitor);
14486 }
14487 }
14488
14489 /**
14490 * The access of a property of an object.
14491 *
14492 * Note, however, that accesses to properties of objects can also be represented
14493 * as [PrefixedIdentifier] nodes in cases where the target is also a simple
14494 * identifier.
14495 *
14496 * > propertyAccess ::=
14497 * > [Expression] '.' [SimpleIdentifier]
14498 */
14499 class PropertyAccess extends Expression {
14500 /**
14501 * The expression computing the object defining the property being accessed.
14502 */
14503 Expression _target;
14504
14505 /**
14506 * The property access operator.
14507 */
14508 Token operator;
14509
14510 /**
14511 * The name of the property being accessed.
14512 */
14513 SimpleIdentifier _propertyName;
14514
14515 /**
14516 * Initialize a newly created property access expression.
14517 */
14518 PropertyAccess(
14519 Expression target, this.operator, SimpleIdentifier propertyName) {
14520 _target = _becomeParentOf(target);
14521 _propertyName = _becomeParentOf(propertyName);
14522 }
14523
14524 @override
14525 Token get beginToken {
14526 if (_target != null) {
14527 return _target.beginToken;
14528 }
14529 return operator;
14530 }
14531
14532 @override
14533 Iterable get childEntities =>
14534 new ChildEntities()..add(_target)..add(operator)..add(_propertyName);
14535
14536 @override
14537 Token get endToken => _propertyName.endToken;
14538
14539 @override
14540 bool get isAssignable => true;
14541
14542 /**
14543 * Return `true` if this expression is cascaded. If it is, then the target of
14544 * this expression is not stored locally but is stored in the nearest ancestor
14545 * that is a [CascadeExpression].
14546 */
14547 bool get isCascaded =>
14548 operator != null && operator.type == TokenType.PERIOD_PERIOD;
14549
14550 @override
14551 int get precedence => 15;
14552
14553 /**
14554 * Return the name of the property being accessed.
14555 */
14556 SimpleIdentifier get propertyName => _propertyName;
14557
14558 /**
14559 * Set the name of the property being accessed to the given [identifier].
14560 */
14561 void set propertyName(SimpleIdentifier identifier) {
14562 _propertyName = _becomeParentOf(identifier);
14563 }
14564
14565 /**
14566 * Return the expression used to compute the receiver of the invocation. If
14567 * this invocation is not part of a cascade expression, then this is the same
14568 * as [target]. If this invocation is part of a cascade expression, then the
14569 * target stored with the cascade expression is returned.
14570 */
14571 Expression get realTarget {
14572 if (isCascaded) {
14573 AstNode ancestor = parent;
14574 while (ancestor is! CascadeExpression) {
14575 if (ancestor == null) {
14576 return _target;
14577 }
14578 ancestor = ancestor.parent;
14579 }
14580 return (ancestor as CascadeExpression).target;
14581 }
14582 return _target;
14583 }
14584
14585 /**
14586 * Return the expression computing the object defining the property being
14587 * accessed, or `null` if this property access is part of a cascade expression .
14588 *
14589 * Use [realTarget] to get the target independent of whether this is part of a
14590 * cascade expression.
14591 */
14592 Expression get target => _target;
14593
14594 /**
14595 * Set the expression computing the object defining the property being
14596 * accessed to the given [expression].
14597 */
14598 void set target(Expression expression) {
14599 _target = _becomeParentOf(expression);
14600 }
14601
14602 @override
14603 accept(AstVisitor visitor) => visitor.visitPropertyAccess(this);
14604
14605 @override
14606 void visitChildren(AstVisitor visitor) {
14607 _safelyVisitChild(_target, visitor);
14608 _safelyVisitChild(_propertyName, visitor);
14609 }
14610 }
14611
14612 /**
14613 * An AST visitor that will recursively visit all of the nodes in an AST
14614 * structure. For example, using an instance of this class to visit a [Block]
14615 * will also cause all of the statements in the block to be visited.
14616 *
14617 * Subclasses that override a visit method must either invoke the overridden
14618 * visit method or must explicitly ask the visited node to visit its children.
14619 * Failure to do so will cause the children of the visited node to not be
14620 * visited.
14621 */
14622 class RecursiveAstVisitor<R> implements AstVisitor<R> {
14623 @override
14624 R visitAdjacentStrings(AdjacentStrings node) {
14625 node.visitChildren(this);
14626 return null;
14627 }
14628
14629 @override
14630 R visitAnnotation(Annotation node) {
14631 node.visitChildren(this);
14632 return null;
14633 }
14634
14635 @override
14636 R visitArgumentList(ArgumentList node) {
14637 node.visitChildren(this);
14638 return null;
14639 }
14640
14641 @override
14642 R visitAsExpression(AsExpression node) {
14643 node.visitChildren(this);
14644 return null;
14645 }
14646
14647 @override
14648 R visitAssertStatement(AssertStatement node) {
14649 node.visitChildren(this);
14650 return null;
14651 }
14652
14653 @override
14654 R visitAssignmentExpression(AssignmentExpression node) {
14655 node.visitChildren(this);
14656 return null;
14657 }
14658
14659 @override
14660 R visitAwaitExpression(AwaitExpression node) {
14661 node.visitChildren(this);
14662 return null;
14663 }
14664
14665 @override
14666 R visitBinaryExpression(BinaryExpression node) {
14667 node.visitChildren(this);
14668 return null;
14669 }
14670
14671 @override
14672 R visitBlock(Block node) {
14673 node.visitChildren(this);
14674 return null;
14675 }
14676
14677 @override
14678 R visitBlockFunctionBody(BlockFunctionBody node) {
14679 node.visitChildren(this);
14680 return null;
14681 }
14682
14683 @override
14684 R visitBooleanLiteral(BooleanLiteral node) {
14685 node.visitChildren(this);
14686 return null;
14687 }
14688
14689 @override
14690 R visitBreakStatement(BreakStatement node) {
14691 node.visitChildren(this);
14692 return null;
14693 }
14694
14695 @override
14696 R visitCascadeExpression(CascadeExpression node) {
14697 node.visitChildren(this);
14698 return null;
14699 }
14700
14701 @override
14702 R visitCatchClause(CatchClause node) {
14703 node.visitChildren(this);
14704 return null;
14705 }
14706
14707 @override
14708 R visitClassDeclaration(ClassDeclaration node) {
14709 node.visitChildren(this);
14710 return null;
14711 }
14712
14713 @override
14714 R visitClassTypeAlias(ClassTypeAlias node) {
14715 node.visitChildren(this);
14716 return null;
14717 }
14718
14719 @override
14720 R visitComment(Comment node) {
14721 node.visitChildren(this);
14722 return null;
14723 }
14724
14725 @override
14726 R visitCommentReference(CommentReference node) {
14727 node.visitChildren(this);
14728 return null;
14729 }
14730
14731 @override
14732 R visitCompilationUnit(CompilationUnit node) {
14733 node.visitChildren(this);
14734 return null;
14735 }
14736
14737 @override
14738 R visitConditionalExpression(ConditionalExpression node) {
14739 node.visitChildren(this);
14740 return null;
14741 }
14742
14743 @override
14744 R visitConstructorDeclaration(ConstructorDeclaration node) {
14745 node.visitChildren(this);
14746 return null;
14747 }
14748
14749 @override
14750 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
14751 node.visitChildren(this);
14752 return null;
14753 }
14754
14755 @override
14756 R visitConstructorName(ConstructorName node) {
14757 node.visitChildren(this);
14758 return null;
14759 }
14760
14761 @override
14762 R visitContinueStatement(ContinueStatement node) {
14763 node.visitChildren(this);
14764 return null;
14765 }
14766
14767 @override
14768 R visitDeclaredIdentifier(DeclaredIdentifier node) {
14769 node.visitChildren(this);
14770 return null;
14771 }
14772
14773 @override
14774 R visitDefaultFormalParameter(DefaultFormalParameter node) {
14775 node.visitChildren(this);
14776 return null;
14777 }
14778
14779 @override
14780 R visitDoStatement(DoStatement node) {
14781 node.visitChildren(this);
14782 return null;
14783 }
14784
14785 @override
14786 R visitDoubleLiteral(DoubleLiteral node) {
14787 node.visitChildren(this);
14788 return null;
14789 }
14790
14791 @override
14792 R visitEmptyFunctionBody(EmptyFunctionBody node) {
14793 node.visitChildren(this);
14794 return null;
14795 }
14796
14797 @override
14798 R visitEmptyStatement(EmptyStatement node) {
14799 node.visitChildren(this);
14800 return null;
14801 }
14802
14803 @override
14804 R visitEnumConstantDeclaration(EnumConstantDeclaration node) {
14805 node.visitChildren(this);
14806 return null;
14807 }
14808
14809 @override
14810 R visitEnumDeclaration(EnumDeclaration node) {
14811 node.visitChildren(this);
14812 return null;
14813 }
14814
14815 @override
14816 R visitExportDirective(ExportDirective node) {
14817 node.visitChildren(this);
14818 return null;
14819 }
14820
14821 @override
14822 R visitExpressionFunctionBody(ExpressionFunctionBody node) {
14823 node.visitChildren(this);
14824 return null;
14825 }
14826
14827 @override
14828 R visitExpressionStatement(ExpressionStatement node) {
14829 node.visitChildren(this);
14830 return null;
14831 }
14832
14833 @override
14834 R visitExtendsClause(ExtendsClause node) {
14835 node.visitChildren(this);
14836 return null;
14837 }
14838
14839 @override
14840 R visitFieldDeclaration(FieldDeclaration node) {
14841 node.visitChildren(this);
14842 return null;
14843 }
14844
14845 @override
14846 R visitFieldFormalParameter(FieldFormalParameter node) {
14847 node.visitChildren(this);
14848 return null;
14849 }
14850
14851 @override
14852 R visitForEachStatement(ForEachStatement node) {
14853 node.visitChildren(this);
14854 return null;
14855 }
14856
14857 @override
14858 R visitFormalParameterList(FormalParameterList node) {
14859 node.visitChildren(this);
14860 return null;
14861 }
14862
14863 @override
14864 R visitForStatement(ForStatement node) {
14865 node.visitChildren(this);
14866 return null;
14867 }
14868
14869 @override
14870 R visitFunctionDeclaration(FunctionDeclaration node) {
14871 node.visitChildren(this);
14872 return null;
14873 }
14874
14875 @override
14876 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
14877 node.visitChildren(this);
14878 return null;
14879 }
14880
14881 @override
14882 R visitFunctionExpression(FunctionExpression node) {
14883 node.visitChildren(this);
14884 return null;
14885 }
14886
14887 @override
14888 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
14889 node.visitChildren(this);
14890 return null;
14891 }
14892
14893 @override
14894 R visitFunctionTypeAlias(FunctionTypeAlias node) {
14895 node.visitChildren(this);
14896 return null;
14897 }
14898
14899 @override
14900 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
14901 node.visitChildren(this);
14902 return null;
14903 }
14904
14905 @override
14906 R visitHideCombinator(HideCombinator node) {
14907 node.visitChildren(this);
14908 return null;
14909 }
14910
14911 @override
14912 R visitIfStatement(IfStatement node) {
14913 node.visitChildren(this);
14914 return null;
14915 }
14916
14917 @override
14918 R visitImplementsClause(ImplementsClause node) {
14919 node.visitChildren(this);
14920 return null;
14921 }
14922
14923 @override
14924 R visitImportDirective(ImportDirective node) {
14925 node.visitChildren(this);
14926 return null;
14927 }
14928
14929 @override
14930 R visitIndexExpression(IndexExpression node) {
14931 node.visitChildren(this);
14932 return null;
14933 }
14934
14935 @override
14936 R visitInstanceCreationExpression(InstanceCreationExpression node) {
14937 node.visitChildren(this);
14938 return null;
14939 }
14940
14941 @override
14942 R visitIntegerLiteral(IntegerLiteral node) {
14943 node.visitChildren(this);
14944 return null;
14945 }
14946
14947 @override
14948 R visitInterpolationExpression(InterpolationExpression node) {
14949 node.visitChildren(this);
14950 return null;
14951 }
14952
14953 @override
14954 R visitInterpolationString(InterpolationString node) {
14955 node.visitChildren(this);
14956 return null;
14957 }
14958
14959 @override
14960 R visitIsExpression(IsExpression node) {
14961 node.visitChildren(this);
14962 return null;
14963 }
14964
14965 @override
14966 R visitLabel(Label node) {
14967 node.visitChildren(this);
14968 return null;
14969 }
14970
14971 @override
14972 R visitLabeledStatement(LabeledStatement node) {
14973 node.visitChildren(this);
14974 return null;
14975 }
14976
14977 @override
14978 R visitLibraryDirective(LibraryDirective node) {
14979 node.visitChildren(this);
14980 return null;
14981 }
14982
14983 @override
14984 R visitLibraryIdentifier(LibraryIdentifier node) {
14985 node.visitChildren(this);
14986 return null;
14987 }
14988
14989 @override
14990 R visitListLiteral(ListLiteral node) {
14991 node.visitChildren(this);
14992 return null;
14993 }
14994
14995 @override
14996 R visitMapLiteral(MapLiteral node) {
14997 node.visitChildren(this);
14998 return null;
14999 }
15000
15001 @override
15002 R visitMapLiteralEntry(MapLiteralEntry node) {
15003 node.visitChildren(this);
15004 return null;
15005 }
15006
15007 @override
15008 R visitMethodDeclaration(MethodDeclaration node) {
15009 node.visitChildren(this);
15010 return null;
15011 }
15012
15013 @override
15014 R visitMethodInvocation(MethodInvocation node) {
15015 node.visitChildren(this);
15016 return null;
15017 }
15018
15019 @override
15020 R visitNamedExpression(NamedExpression node) {
15021 node.visitChildren(this);
15022 return null;
15023 }
15024
15025 @override
15026 R visitNativeClause(NativeClause node) {
15027 node.visitChildren(this);
15028 return null;
15029 }
15030
15031 @override
15032 R visitNativeFunctionBody(NativeFunctionBody node) {
15033 node.visitChildren(this);
15034 return null;
15035 }
15036
15037 @override
15038 R visitNullLiteral(NullLiteral node) {
15039 node.visitChildren(this);
15040 return null;
15041 }
15042
15043 @override
15044 R visitParenthesizedExpression(ParenthesizedExpression node) {
15045 node.visitChildren(this);
15046 return null;
15047 }
15048
15049 @override
15050 R visitPartDirective(PartDirective node) {
15051 node.visitChildren(this);
15052 return null;
15053 }
15054
15055 @override
15056 R visitPartOfDirective(PartOfDirective node) {
15057 node.visitChildren(this);
15058 return null;
15059 }
15060
15061 @override
15062 R visitPostfixExpression(PostfixExpression node) {
15063 node.visitChildren(this);
15064 return null;
15065 }
15066
15067 @override
15068 R visitPrefixedIdentifier(PrefixedIdentifier node) {
15069 node.visitChildren(this);
15070 return null;
15071 }
15072
15073 @override
15074 R visitPrefixExpression(PrefixExpression node) {
15075 node.visitChildren(this);
15076 return null;
15077 }
15078
15079 @override
15080 R visitPropertyAccess(PropertyAccess node) {
15081 node.visitChildren(this);
15082 return null;
15083 }
15084
15085 @override
15086 R visitRedirectingConstructorInvocation(
15087 RedirectingConstructorInvocation node) {
15088 node.visitChildren(this);
15089 return null;
15090 }
15091
15092 @override
15093 R visitRethrowExpression(RethrowExpression node) {
15094 node.visitChildren(this);
15095 return null;
15096 }
15097
15098 @override
15099 R visitReturnStatement(ReturnStatement node) {
15100 node.visitChildren(this);
15101 return null;
15102 }
15103
15104 @override
15105 R visitScriptTag(ScriptTag node) {
15106 node.visitChildren(this);
15107 return null;
15108 }
15109
15110 @override
15111 R visitShowCombinator(ShowCombinator node) {
15112 node.visitChildren(this);
15113 return null;
15114 }
15115
15116 @override
15117 R visitSimpleFormalParameter(SimpleFormalParameter node) {
15118 node.visitChildren(this);
15119 return null;
15120 }
15121
15122 @override
15123 R visitSimpleIdentifier(SimpleIdentifier node) {
15124 node.visitChildren(this);
15125 return null;
15126 }
15127
15128 @override
15129 R visitSimpleStringLiteral(SimpleStringLiteral node) {
15130 node.visitChildren(this);
15131 return null;
15132 }
15133
15134 @override
15135 R visitStringInterpolation(StringInterpolation node) {
15136 node.visitChildren(this);
15137 return null;
15138 }
15139
15140 @override
15141 R visitSuperConstructorInvocation(SuperConstructorInvocation node) {
15142 node.visitChildren(this);
15143 return null;
15144 }
15145
15146 @override
15147 R visitSuperExpression(SuperExpression node) {
15148 node.visitChildren(this);
15149 return null;
15150 }
15151
15152 @override
15153 R visitSwitchCase(SwitchCase node) {
15154 node.visitChildren(this);
15155 return null;
15156 }
15157
15158 @override
15159 R visitSwitchDefault(SwitchDefault node) {
15160 node.visitChildren(this);
15161 return null;
15162 }
15163
15164 @override
15165 R visitSwitchStatement(SwitchStatement node) {
15166 node.visitChildren(this);
15167 return null;
15168 }
15169
15170 @override
15171 R visitSymbolLiteral(SymbolLiteral node) {
15172 node.visitChildren(this);
15173 return null;
15174 }
15175
15176 @override
15177 R visitThisExpression(ThisExpression node) {
15178 node.visitChildren(this);
15179 return null;
15180 }
15181
15182 @override
15183 R visitThrowExpression(ThrowExpression node) {
15184 node.visitChildren(this);
15185 return null;
15186 }
15187
15188 @override
15189 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
15190 node.visitChildren(this);
15191 return null;
15192 }
15193
15194 @override
15195 R visitTryStatement(TryStatement node) {
15196 node.visitChildren(this);
15197 return null;
15198 }
15199
15200 @override
15201 R visitTypeArgumentList(TypeArgumentList node) {
15202 node.visitChildren(this);
15203 return null;
15204 }
15205
15206 @override
15207 R visitTypeName(TypeName node) {
15208 node.visitChildren(this);
15209 return null;
15210 }
15211
15212 @override
15213 R visitTypeParameter(TypeParameter node) {
15214 node.visitChildren(this);
15215 return null;
15216 }
15217
15218 @override
15219 R visitTypeParameterList(TypeParameterList node) {
15220 node.visitChildren(this);
15221 return null;
15222 }
15223
15224 @override
15225 R visitVariableDeclaration(VariableDeclaration node) {
15226 node.visitChildren(this);
15227 return null;
15228 }
15229
15230 @override
15231 R visitVariableDeclarationList(VariableDeclarationList node) {
15232 node.visitChildren(this);
15233 return null;
15234 }
15235
15236 @override
15237 R visitVariableDeclarationStatement(VariableDeclarationStatement node) {
15238 node.visitChildren(this);
15239 return null;
15240 }
15241
15242 @override
15243 R visitWhileStatement(WhileStatement node) {
15244 node.visitChildren(this);
15245 return null;
15246 }
15247
15248 @override
15249 R visitWithClause(WithClause node) {
15250 node.visitChildren(this);
15251 return null;
15252 }
15253
15254 @override
15255 R visitYieldStatement(YieldStatement node) {
15256 node.visitChildren(this);
15257 return null;
15258 }
15259 }
15260
15261 /**
15262 * The invocation of a constructor in the same class from within a constructor's
15263 * initialization list.
15264 *
15265 * > redirectingConstructorInvocation ::=
15266 * > 'this' ('.' identifier)? arguments
15267 */
15268 class RedirectingConstructorInvocation extends ConstructorInitializer {
15269 /**
15270 * The token for the 'this' keyword.
15271 */
15272 Token thisKeyword;
15273
15274 /**
15275 * The token for the period before the name of the constructor that is being
15276 * invoked, or `null` if the unnamed constructor is being invoked.
15277 */
15278 Token period;
15279
15280 /**
15281 * The name of the constructor that is being invoked, or `null` if the unnamed
15282 * constructor is being invoked.
15283 */
15284 SimpleIdentifier _constructorName;
15285
15286 /**
15287 * The list of arguments to the constructor.
15288 */
15289 ArgumentList _argumentList;
15290
15291 /**
15292 * The element associated with the constructor based on static type
15293 * information, or `null` if the AST structure has not been resolved or if the
15294 * constructor could not be resolved.
15295 */
15296 ConstructorElement staticElement;
15297
15298 /**
15299 * Initialize a newly created redirecting invocation to invoke the constructor
15300 * with the given name with the given arguments. The [constructorName] can be
15301 * `null` if the constructor being invoked is the unnamed constructor.
15302 */
15303 RedirectingConstructorInvocation(this.thisKeyword, this.period,
15304 SimpleIdentifier constructorName, ArgumentList argumentList) {
15305 _constructorName = _becomeParentOf(constructorName);
15306 _argumentList = _becomeParentOf(argumentList);
15307 }
15308
15309 /**
15310 * Return the list of arguments to the constructor.
15311 */
15312 ArgumentList get argumentList => _argumentList;
15313
15314 /**
15315 * Set the list of arguments to the constructor to the given [argumentList].
15316 */
15317 void set argumentList(ArgumentList argumentList) {
15318 _argumentList = _becomeParentOf(argumentList);
15319 }
15320
15321 @override
15322 Token get beginToken => thisKeyword;
15323
15324 @override
15325 Iterable get childEntities => new ChildEntities()
15326 ..add(thisKeyword)
15327 ..add(period)
15328 ..add(_constructorName)
15329 ..add(_argumentList);
15330
15331 /**
15332 * Return the name of the constructor that is being invoked, or `null` if the
15333 * unnamed constructor is being invoked.
15334 */
15335 SimpleIdentifier get constructorName => _constructorName;
15336
15337 /**
15338 * Set the name of the constructor that is being invoked to the given
15339 * [identifier].
15340 */
15341 void set constructorName(SimpleIdentifier identifier) {
15342 _constructorName = _becomeParentOf(identifier);
15343 }
15344
15345 @override
15346 Token get endToken => _argumentList.endToken;
15347
15348 /**
15349 * Return the token for the 'this' keyword.
15350 */
15351 @deprecated // Use "this.thisKeyword"
15352 Token get keyword => thisKeyword;
15353
15354 /**
15355 * Set the token for the 'this' keyword to the given [token].
15356 */
15357 @deprecated // Use "this.thisKeyword"
15358 set keyword(Token token) {
15359 thisKeyword = token;
15360 }
15361
15362 @override
15363 accept(AstVisitor visitor) =>
15364 visitor.visitRedirectingConstructorInvocation(this);
15365
15366 @override
15367 void visitChildren(AstVisitor visitor) {
15368 _safelyVisitChild(_constructorName, visitor);
15369 _safelyVisitChild(_argumentList, visitor);
15370 }
15371 }
15372
15373 /**
15374 * A rethrow expression.
15375 *
15376 * > rethrowExpression ::=
15377 * > 'rethrow'
15378 */
15379 class RethrowExpression extends Expression {
15380 /**
15381 * The token representing the 'rethrow' keyword.
15382 */
15383 Token rethrowKeyword;
15384
15385 /**
15386 * Initialize a newly created rethrow expression.
15387 */
15388 RethrowExpression(this.rethrowKeyword);
15389
15390 @override
15391 Token get beginToken => rethrowKeyword;
15392
15393 @override
15394 Iterable get childEntities => new ChildEntities()..add(rethrowKeyword);
15395
15396 @override
15397 Token get endToken => rethrowKeyword;
15398
15399 /**
15400 * Return the token representing the 'rethrow' keyword.
15401 */
15402 @deprecated // Use "this.rethrowKeyword"
15403 Token get keyword => rethrowKeyword;
15404
15405 /**
15406 * Set the token representing the 'rethrow' keyword to the given [token].
15407 */
15408 @deprecated // Use "this.rethrowKeyword"
15409 set keyword(Token token) {
15410 rethrowKeyword = token;
15411 }
15412
15413 @override
15414 int get precedence => 0;
15415
15416 @override
15417 accept(AstVisitor visitor) => visitor.visitRethrowExpression(this);
15418
15419 @override
15420 void visitChildren(AstVisitor visitor) {
15421 // There are no children to visit.
15422 }
15423 }
15424
15425 /**
15426 * A return statement.
15427 *
15428 * > returnStatement ::=
15429 * > 'return' [Expression]? ';'
15430 */
15431 class ReturnStatement extends Statement {
15432 /**
15433 * The token representing the 'return' keyword.
15434 */
15435 Token returnKeyword;
15436
15437 /**
15438 * The expression computing the value to be returned, or `null` if no explicit
15439 * value was provided.
15440 */
15441 Expression _expression;
15442
15443 /**
15444 * The semicolon terminating the statement.
15445 */
15446 Token semicolon;
15447
15448 /**
15449 * Initialize a newly created return statement. The [expression] can be `null`
15450 * if no explicit value was provided.
15451 */
15452 ReturnStatement(this.returnKeyword, Expression expression, this.semicolon) {
15453 _expression = _becomeParentOf(expression);
15454 }
15455
15456 @override
15457 Token get beginToken => returnKeyword;
15458
15459 @override
15460 Iterable get childEntities =>
15461 new ChildEntities()..add(returnKeyword)..add(_expression)..add(semicolon);
15462
15463 @override
15464 Token get endToken => semicolon;
15465
15466 /**
15467 * Return the expression computing the value to be returned, or `null` if no
15468 * explicit value was provided.
15469 */
15470 Expression get expression => _expression;
15471
15472 /**
15473 * Set the expression computing the value to be returned to the given
15474 * [expression].
15475 */
15476 void set expression(Expression expression) {
15477 _expression = _becomeParentOf(expression);
15478 }
15479
15480 /**
15481 * Return the token representing the 'return' keyword.
15482 */
15483 @deprecated // Use "this.returnKeyword"
15484 Token get keyword => returnKeyword;
15485
15486 /**
15487 * Set the token representing the 'return' keyword to the given [token].
15488 */
15489 @deprecated // Use "this.returnKeyword"
15490 set keyword(Token token) {
15491 returnKeyword = token;
15492 }
15493
15494 @override
15495 accept(AstVisitor visitor) => visitor.visitReturnStatement(this);
15496
15497 @override
15498 void visitChildren(AstVisitor visitor) {
15499 _safelyVisitChild(_expression, visitor);
15500 }
15501 }
15502
15503 /**
15504 * Traverse the AST from initial child node to successive parents, building a
15505 * collection of local variable and parameter names visible to the initial child
15506 * node. In case of name shadowing, the first name seen is the most specific one
15507 * so names are not redefined.
15508 *
15509 * Completion test code coverage is 95%. The two basic blocks that are not
15510 * executed cannot be executed. They are included for future reference.
15511 */
15512 class ScopedNameFinder extends GeneralizingAstVisitor<Object> {
15513 Declaration _declarationNode;
15514
15515 AstNode _immediateChild;
15516
15517 Map<String, SimpleIdentifier> _locals =
15518 new HashMap<String, SimpleIdentifier>();
15519
15520 final int _position;
15521
15522 bool _referenceIsWithinLocalFunction = false;
15523
15524 ScopedNameFinder(this._position);
15525
15526 Declaration get declaration => _declarationNode;
15527
15528 Map<String, SimpleIdentifier> get locals => _locals;
15529
15530 @override
15531 Object visitBlock(Block node) {
15532 _checkStatements(node.statements);
15533 return super.visitBlock(node);
15534 }
15535
15536 @override
15537 Object visitCatchClause(CatchClause node) {
15538 _addToScope(node.exceptionParameter);
15539 _addToScope(node.stackTraceParameter);
15540 return super.visitCatchClause(node);
15541 }
15542
15543 @override
15544 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15545 if (!identical(_immediateChild, node.parameters)) {
15546 _addParameters(node.parameters.parameters);
15547 }
15548 _declarationNode = node;
15549 return null;
15550 }
15551
15552 @override
15553 Object visitFieldDeclaration(FieldDeclaration node) {
15554 _declarationNode = node;
15555 return null;
15556 }
15557
15558 @override
15559 Object visitForEachStatement(ForEachStatement node) {
15560 DeclaredIdentifier loopVariable = node.loopVariable;
15561 if (loopVariable != null) {
15562 _addToScope(loopVariable.identifier);
15563 }
15564 return super.visitForEachStatement(node);
15565 }
15566
15567 @override
15568 Object visitForStatement(ForStatement node) {
15569 if (!identical(_immediateChild, node.variables) && node.variables != null) {
15570 _addVariables(node.variables.variables);
15571 }
15572 return super.visitForStatement(node);
15573 }
15574
15575 @override
15576 Object visitFunctionDeclaration(FunctionDeclaration node) {
15577 if (node.parent is! FunctionDeclarationStatement) {
15578 _declarationNode = node;
15579 return null;
15580 }
15581 return super.visitFunctionDeclaration(node);
15582 }
15583
15584 @override
15585 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
15586 _referenceIsWithinLocalFunction = true;
15587 return super.visitFunctionDeclarationStatement(node);
15588 }
15589
15590 @override
15591 Object visitFunctionExpression(FunctionExpression node) {
15592 if (node.parameters != null &&
15593 !identical(_immediateChild, node.parameters)) {
15594 _addParameters(node.parameters.parameters);
15595 }
15596 return super.visitFunctionExpression(node);
15597 }
15598
15599 @override
15600 Object visitMethodDeclaration(MethodDeclaration node) {
15601 _declarationNode = node;
15602 if (node.parameters == null) {
15603 return null;
15604 }
15605 if (!identical(_immediateChild, node.parameters)) {
15606 _addParameters(node.parameters.parameters);
15607 }
15608 return null;
15609 }
15610
15611 @override
15612 Object visitNode(AstNode node) {
15613 _immediateChild = node;
15614 AstNode parent = node.parent;
15615 if (parent != null) {
15616 parent.accept(this);
15617 }
15618 return null;
15619 }
15620
15621 @override
15622 Object visitSwitchMember(SwitchMember node) {
15623 _checkStatements(node.statements);
15624 return super.visitSwitchMember(node);
15625 }
15626
15627 @override
15628 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
15629 _declarationNode = node;
15630 return null;
15631 }
15632
15633 @override
15634 Object visitTypeAlias(TypeAlias node) {
15635 _declarationNode = node;
15636 return null;
15637 }
15638
15639 void _addParameters(NodeList<FormalParameter> vars) {
15640 for (FormalParameter var2 in vars) {
15641 _addToScope(var2.identifier);
15642 }
15643 }
15644
15645 void _addToScope(SimpleIdentifier identifier) {
15646 if (identifier != null && _isInRange(identifier)) {
15647 String name = identifier.name;
15648 if (!_locals.containsKey(name)) {
15649 _locals[name] = identifier;
15650 }
15651 }
15652 }
15653
15654 void _addVariables(NodeList<VariableDeclaration> variables) {
15655 for (VariableDeclaration variable in variables) {
15656 _addToScope(variable.name);
15657 }
15658 }
15659
15660 /**
15661 * Check the given list of [statements] for any that come before the immediate
15662 * child and that define a name that would be visible to the immediate child.
15663 */
15664 void _checkStatements(List<Statement> statements) {
15665 for (Statement statement in statements) {
15666 if (identical(statement, _immediateChild)) {
15667 return;
15668 }
15669 if (statement is VariableDeclarationStatement) {
15670 _addVariables(statement.variables.variables);
15671 } else if (statement is FunctionDeclarationStatement &&
15672 !_referenceIsWithinLocalFunction) {
15673 _addToScope(statement.functionDeclaration.name);
15674 }
15675 }
15676 }
15677
15678 bool _isInRange(AstNode node) {
15679 if (_position < 0) {
15680 // if source position is not set then all nodes are in range
15681 return true;
15682 // not reached
15683 }
15684 return node.end < _position;
15685 }
15686 }
15687
15688 /**
15689 * A script tag that can optionally occur at the beginning of a compilation unit .
15690 *
15691 * > scriptTag ::=
15692 * > '#!' (~NEWLINE)* NEWLINE
15693 */
15694 class ScriptTag extends AstNode {
15695 /**
15696 * The token representing this script tag.
15697 */
15698 Token scriptTag;
15699
15700 /**
15701 * Initialize a newly created script tag.
15702 */
15703 ScriptTag(this.scriptTag);
15704
15705 @override
15706 Token get beginToken => scriptTag;
15707
15708 @override
15709 Iterable get childEntities => new ChildEntities()..add(scriptTag);
15710
15711 @override
15712 Token get endToken => scriptTag;
15713
15714 @override
15715 accept(AstVisitor visitor) => visitor.visitScriptTag(this);
15716
15717 @override
15718 void visitChildren(AstVisitor visitor) {
15719 // There are no children to visit.
15720 }
15721 }
15722
15723 /**
15724 * A combinator that restricts the names being imported to those in a given list .
15725 *
15726 * > showCombinator ::=
15727 * > 'show' [SimpleIdentifier] (',' [SimpleIdentifier])*
15728 */
15729 class ShowCombinator extends Combinator {
15730 /**
15731 * The list of names from the library that are made visible by this combinator .
15732 */
15733 NodeList<SimpleIdentifier> _shownNames;
15734
15735 /**
15736 * Initialize a newly created import show combinator.
15737 */
15738 ShowCombinator(Token keyword, List<SimpleIdentifier> shownNames)
15739 : super(keyword) {
15740 _shownNames = new NodeList<SimpleIdentifier>(this, shownNames);
15741 }
15742
15743 /**
15744 * TODO(paulberry): add commas.
15745 */
15746 @override
15747 Iterable get childEntities => new ChildEntities()
15748 ..add(keyword)
15749 ..addAll(_shownNames);
15750
15751 @override
15752 Token get endToken => _shownNames.endToken;
15753
15754 /**
15755 * Return the list of names from the library that are made visible by this
15756 * combinator.
15757 */
15758 NodeList<SimpleIdentifier> get shownNames => _shownNames;
15759
15760 @override
15761 accept(AstVisitor visitor) => visitor.visitShowCombinator(this);
15762
15763 @override
15764 void visitChildren(AstVisitor visitor) {
15765 _shownNames.accept(visitor);
15766 }
15767 }
15768
15769 /**
15770 * An AST visitor that will do nothing when visiting an AST node. It is intended
15771 * to be a superclass for classes that use the visitor pattern primarily as a
15772 * dispatch mechanism (and hence don't need to recursively visit a whole
15773 * structure) and that only need to visit a small number of node types.
15774 */
15775 class SimpleAstVisitor<R> implements AstVisitor<R> {
15776 @override
15777 R visitAdjacentStrings(AdjacentStrings node) => null;
15778
15779 @override
15780 R visitAnnotation(Annotation node) => null;
15781
15782 @override
15783 R visitArgumentList(ArgumentList node) => null;
15784
15785 @override
15786 R visitAsExpression(AsExpression node) => null;
15787
15788 @override
15789 R visitAssertStatement(AssertStatement node) => null;
15790
15791 @override
15792 R visitAssignmentExpression(AssignmentExpression node) => null;
15793
15794 @override
15795 R visitAwaitExpression(AwaitExpression node) => null;
15796
15797 @override
15798 R visitBinaryExpression(BinaryExpression node) => null;
15799
15800 @override
15801 R visitBlock(Block node) => null;
15802
15803 @override
15804 R visitBlockFunctionBody(BlockFunctionBody node) => null;
15805
15806 @override
15807 R visitBooleanLiteral(BooleanLiteral node) => null;
15808
15809 @override
15810 R visitBreakStatement(BreakStatement node) => null;
15811
15812 @override
15813 R visitCascadeExpression(CascadeExpression node) => null;
15814
15815 @override
15816 R visitCatchClause(CatchClause node) => null;
15817
15818 @override
15819 R visitClassDeclaration(ClassDeclaration node) => null;
15820
15821 @override
15822 R visitClassTypeAlias(ClassTypeAlias node) => null;
15823
15824 @override
15825 R visitComment(Comment node) => null;
15826
15827 @override
15828 R visitCommentReference(CommentReference node) => null;
15829
15830 @override
15831 R visitCompilationUnit(CompilationUnit node) => null;
15832
15833 @override
15834 R visitConditionalExpression(ConditionalExpression node) => null;
15835
15836 @override
15837 R visitConstructorDeclaration(ConstructorDeclaration node) => null;
15838
15839 @override
15840 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) => null;
15841
15842 @override
15843 R visitConstructorName(ConstructorName node) => null;
15844
15845 @override
15846 R visitContinueStatement(ContinueStatement node) => null;
15847
15848 @override
15849 R visitDeclaredIdentifier(DeclaredIdentifier node) => null;
15850
15851 @override
15852 R visitDefaultFormalParameter(DefaultFormalParameter node) => null;
15853
15854 @override
15855 R visitDoStatement(DoStatement node) => null;
15856
15857 @override
15858 R visitDoubleLiteral(DoubleLiteral node) => null;
15859
15860 @override
15861 R visitEmptyFunctionBody(EmptyFunctionBody node) => null;
15862
15863 @override
15864 R visitEmptyStatement(EmptyStatement node) => null;
15865
15866 @override
15867 R visitEnumConstantDeclaration(EnumConstantDeclaration node) => null;
15868
15869 @override
15870 R visitEnumDeclaration(EnumDeclaration node) => null;
15871
15872 @override
15873 R visitExportDirective(ExportDirective node) => null;
15874
15875 @override
15876 R visitExpressionFunctionBody(ExpressionFunctionBody node) => null;
15877
15878 @override
15879 R visitExpressionStatement(ExpressionStatement node) => null;
15880
15881 @override
15882 R visitExtendsClause(ExtendsClause node) => null;
15883
15884 @override
15885 R visitFieldDeclaration(FieldDeclaration node) => null;
15886
15887 @override
15888 R visitFieldFormalParameter(FieldFormalParameter node) => null;
15889
15890 @override
15891 R visitForEachStatement(ForEachStatement node) => null;
15892
15893 @override
15894 R visitFormalParameterList(FormalParameterList node) => null;
15895
15896 @override
15897 R visitForStatement(ForStatement node) => null;
15898
15899 @override
15900 R visitFunctionDeclaration(FunctionDeclaration node) => null;
15901
15902 @override
15903 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
15904 null;
15905
15906 @override
15907 R visitFunctionExpression(FunctionExpression node) => null;
15908
15909 @override
15910 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
15911 null;
15912
15913 @override
15914 R visitFunctionTypeAlias(FunctionTypeAlias node) => null;
15915
15916 @override
15917 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
15918 null;
15919
15920 @override
15921 R visitHideCombinator(HideCombinator node) => null;
15922
15923 @override
15924 R visitIfStatement(IfStatement node) => null;
15925
15926 @override
15927 R visitImplementsClause(ImplementsClause node) => null;
15928
15929 @override
15930 R visitImportDirective(ImportDirective node) => null;
15931
15932 @override
15933 R visitIndexExpression(IndexExpression node) => null;
15934
15935 @override
15936 R visitInstanceCreationExpression(InstanceCreationExpression node) => null;
15937
15938 @override
15939 R visitIntegerLiteral(IntegerLiteral node) => null;
15940
15941 @override
15942 R visitInterpolationExpression(InterpolationExpression node) => null;
15943
15944 @override
15945 R visitInterpolationString(InterpolationString node) => null;
15946
15947 @override
15948 R visitIsExpression(IsExpression node) => null;
15949
15950 @override
15951 R visitLabel(Label node) => null;
15952
15953 @override
15954 R visitLabeledStatement(LabeledStatement node) => null;
15955
15956 @override
15957 R visitLibraryDirective(LibraryDirective node) => null;
15958
15959 @override
15960 R visitLibraryIdentifier(LibraryIdentifier node) => null;
15961
15962 @override
15963 R visitListLiteral(ListLiteral node) => null;
15964
15965 @override
15966 R visitMapLiteral(MapLiteral node) => null;
15967
15968 @override
15969 R visitMapLiteralEntry(MapLiteralEntry node) => null;
15970
15971 @override
15972 R visitMethodDeclaration(MethodDeclaration node) => null;
15973
15974 @override
15975 R visitMethodInvocation(MethodInvocation node) => null;
15976
15977 @override
15978 R visitNamedExpression(NamedExpression node) => null;
15979
15980 @override
15981 R visitNativeClause(NativeClause node) => null;
15982
15983 @override
15984 R visitNativeFunctionBody(NativeFunctionBody node) => null;
15985
15986 @override
15987 R visitNullLiteral(NullLiteral node) => null;
15988
15989 @override
15990 R visitParenthesizedExpression(ParenthesizedExpression node) => null;
15991
15992 @override
15993 R visitPartDirective(PartDirective node) => null;
15994
15995 @override
15996 R visitPartOfDirective(PartOfDirective node) => null;
15997
15998 @override
15999 R visitPostfixExpression(PostfixExpression node) => null;
16000
16001 @override
16002 R visitPrefixedIdentifier(PrefixedIdentifier node) => null;
16003
16004 @override
16005 R visitPrefixExpression(PrefixExpression node) => null;
16006
16007 @override
16008 R visitPropertyAccess(PropertyAccess node) => null;
16009
16010 @override
16011 R visitRedirectingConstructorInvocation(
16012 RedirectingConstructorInvocation node) => null;
16013
16014 @override
16015 R visitRethrowExpression(RethrowExpression node) => null;
16016
16017 @override
16018 R visitReturnStatement(ReturnStatement node) => null;
16019
16020 @override
16021 R visitScriptTag(ScriptTag node) => null;
16022
16023 @override
16024 R visitShowCombinator(ShowCombinator node) => null;
16025
16026 @override
16027 R visitSimpleFormalParameter(SimpleFormalParameter node) => null;
16028
16029 @override
16030 R visitSimpleIdentifier(SimpleIdentifier node) => null;
16031
16032 @override
16033 R visitSimpleStringLiteral(SimpleStringLiteral node) => null;
16034
16035 @override
16036 R visitStringInterpolation(StringInterpolation node) => null;
16037
16038 @override
16039 R visitSuperConstructorInvocation(SuperConstructorInvocation node) => null;
16040
16041 @override
16042 R visitSuperExpression(SuperExpression node) => null;
16043
16044 @override
16045 R visitSwitchCase(SwitchCase node) => null;
16046
16047 @override
16048 R visitSwitchDefault(SwitchDefault node) => null;
16049
16050 @override
16051 R visitSwitchStatement(SwitchStatement node) => null;
16052
16053 @override
16054 R visitSymbolLiteral(SymbolLiteral node) => null;
16055
16056 @override
16057 R visitThisExpression(ThisExpression node) => null;
16058
16059 @override
16060 R visitThrowExpression(ThrowExpression node) => null;
16061
16062 @override
16063 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => null;
16064
16065 @override
16066 R visitTryStatement(TryStatement node) => null;
16067
16068 @override
16069 R visitTypeArgumentList(TypeArgumentList node) => null;
16070
16071 @override
16072 R visitTypeName(TypeName node) => null;
16073
16074 @override
16075 R visitTypeParameter(TypeParameter node) => null;
16076
16077 @override
16078 R visitTypeParameterList(TypeParameterList node) => null;
16079
16080 @override
16081 R visitVariableDeclaration(VariableDeclaration node) => null;
16082
16083 @override
16084 R visitVariableDeclarationList(VariableDeclarationList node) => null;
16085
16086 @override
16087 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
16088 null;
16089
16090 @override
16091 R visitWhileStatement(WhileStatement node) => null;
16092
16093 @override
16094 R visitWithClause(WithClause node) => null;
16095
16096 @override
16097 R visitYieldStatement(YieldStatement node) => null;
16098 }
16099
16100 /**
16101 * A simple formal parameter.
16102 *
16103 * > simpleFormalParameter ::=
16104 * > ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier]
16105 */
16106 class SimpleFormalParameter extends NormalFormalParameter {
16107 /**
16108 * The token representing either the 'final', 'const' or 'var' keyword, or
16109 * `null` if no keyword was used.
16110 */
16111 Token keyword;
16112
16113 /**
16114 * The name of the declared type of the parameter, or `null` if the parameter
16115 * does not have a declared type.
16116 */
16117 TypeName _type;
16118
16119 /**
16120 * Initialize a newly created formal parameter. Either or both of the
16121 * [comment] and [metadata] can be `null` if the parameter does not have the
16122 * corresponding attribute. The [keyword] can be `null` if a type was
16123 * specified. The [type] must be `null` if the keyword is 'var'.
16124 */
16125 SimpleFormalParameter(Comment comment, List<Annotation> metadata,
16126 this.keyword, TypeName type, SimpleIdentifier identifier)
16127 : super(comment, metadata, identifier) {
16128 _type = _becomeParentOf(type);
16129 }
16130
16131 @override
16132 Token get beginToken {
16133 NodeList<Annotation> metadata = this.metadata;
16134 if (!metadata.isEmpty) {
16135 return metadata.beginToken;
16136 } else if (keyword != null) {
16137 return keyword;
16138 } else if (_type != null) {
16139 return _type.beginToken;
16140 }
16141 return identifier.beginToken;
16142 }
16143
16144 @override
16145 Iterable get childEntities =>
16146 super._childEntities..add(keyword)..add(_type)..add(identifier);
16147
16148 @override
16149 Token get endToken => identifier.endToken;
16150
16151 @override
16152 bool get isConst => (keyword is KeywordToken) &&
16153 (keyword as KeywordToken).keyword == Keyword.CONST;
16154
16155 @override
16156 bool get isFinal => (keyword is KeywordToken) &&
16157 (keyword as KeywordToken).keyword == Keyword.FINAL;
16158
16159 /**
16160 * Return the name of the declared type of the parameter, or `null` if the
16161 * parameter does not have a declared type.
16162 */
16163 TypeName get type => _type;
16164
16165 /**
16166 * Set the name of the declared type of the parameter to the given [typeName].
16167 */
16168 void set type(TypeName typeName) {
16169 _type = _becomeParentOf(typeName);
16170 }
16171
16172 @override
16173 accept(AstVisitor visitor) => visitor.visitSimpleFormalParameter(this);
16174
16175 @override
16176 void visitChildren(AstVisitor visitor) {
16177 super.visitChildren(visitor);
16178 _safelyVisitChild(_type, visitor);
16179 _safelyVisitChild(identifier, visitor);
16180 }
16181 }
16182
16183 /**
16184 * A simple identifier.
16185 *
16186 * > simpleIdentifier ::=
16187 * > initialCharacter internalCharacter*
16188 * >
16189 * > initialCharacter ::= '_' | '$' | letter
16190 * >
16191 * > internalCharacter ::= '_' | '$' | letter | digit
16192 */
16193 class SimpleIdentifier extends Identifier {
16194 /**
16195 * The token representing the identifier.
16196 */
16197 Token token;
16198
16199 /**
16200 * The element associated with this identifier based on static type
16201 * information, or `null` if the AST structure has not been resolved or if
16202 * this identifier could not be resolved.
16203 */
16204 Element _staticElement;
16205
16206 /**
16207 * The element associated with this identifier based on propagated type
16208 * information, or `null` if the AST structure has not been resolved or if
16209 * this identifier could not be resolved.
16210 */
16211 Element _propagatedElement;
16212
16213 /**
16214 * If this expression is both in a getter and setter context, the
16215 * [AuxiliaryElements] will be set to hold onto the static and propagated
16216 * information. The auxiliary element will hold onto the elements from the
16217 * getter context.
16218 */
16219 AuxiliaryElements auxiliaryElements = null;
16220
16221 /**
16222 * Initialize a newly created identifier.
16223 */
16224 SimpleIdentifier(this.token);
16225
16226 @override
16227 Token get beginToken => token;
16228
16229 @override
16230 Element get bestElement {
16231 if (_propagatedElement == null) {
16232 return _staticElement;
16233 }
16234 return _propagatedElement;
16235 }
16236
16237 @override
16238 Iterable get childEntities => new ChildEntities()..add(token);
16239
16240 @override
16241 Token get endToken => token;
16242
16243 /**
16244 * Returns `true` if this identifier is the "name" part of a prefixed
16245 * identifier or a method invocation.
16246 */
16247 bool get isQualified {
16248 AstNode parent = this.parent;
16249 if (parent is PrefixedIdentifier) {
16250 return identical(parent.identifier, this);
16251 }
16252 if (parent is PropertyAccess) {
16253 return identical(parent.propertyName, this);
16254 }
16255 if (parent is MethodInvocation) {
16256 MethodInvocation invocation = parent;
16257 return identical(invocation.methodName, this) &&
16258 invocation.realTarget != null;
16259 }
16260 return false;
16261 }
16262
16263 @override
16264 bool get isSynthetic => token.isSynthetic;
16265
16266 @override
16267 String get name => token.lexeme;
16268
16269 @override
16270 int get precedence => 16;
16271
16272 @override
16273 Element get propagatedElement => _propagatedElement;
16274
16275 /**
16276 * Set the element associated with this identifier based on propagated type
16277 * information to the given [element].
16278 */
16279 void set propagatedElement(Element element) {
16280 _propagatedElement = _validateElement(element);
16281 }
16282
16283 @override
16284 Element get staticElement => _staticElement;
16285
16286 /**
16287 * Set the element associated with this identifier based on static type
16288 * information to the given [element].
16289 */
16290 void set staticElement(Element element) {
16291 _staticElement = _validateElement(element);
16292 }
16293
16294 @override
16295 accept(AstVisitor visitor) => visitor.visitSimpleIdentifier(this);
16296
16297 /**
16298 * Return `true` if this identifier is the name being declared in a
16299 * declaration.
16300 */
16301 bool inDeclarationContext() {
16302 // TODO(brianwilkerson) Convert this to a getter.
16303 AstNode parent = this.parent;
16304 if (parent is CatchClause) {
16305 CatchClause clause = parent;
16306 return identical(this, clause.exceptionParameter) ||
16307 identical(this, clause.stackTraceParameter);
16308 } else if (parent is ClassDeclaration) {
16309 return identical(this, parent.name);
16310 } else if (parent is ClassTypeAlias) {
16311 return identical(this, parent.name);
16312 } else if (parent is ConstructorDeclaration) {
16313 return identical(this, parent.name);
16314 } else if (parent is DeclaredIdentifier) {
16315 return identical(this, parent.identifier);
16316 } else if (parent is EnumDeclaration) {
16317 return identical(this, parent.name);
16318 } else if (parent is EnumConstantDeclaration) {
16319 return identical(this, parent.name);
16320 } else if (parent is FunctionDeclaration) {
16321 return identical(this, parent.name);
16322 } else if (parent is FunctionTypeAlias) {
16323 return identical(this, parent.name);
16324 } else if (parent is ImportDirective) {
16325 return identical(this, parent.prefix);
16326 } else if (parent is Label) {
16327 return identical(this, parent.label) &&
16328 (parent.parent is LabeledStatement);
16329 } else if (parent is MethodDeclaration) {
16330 return identical(this, parent.name);
16331 } else if (parent is FunctionTypedFormalParameter ||
16332 parent is SimpleFormalParameter) {
16333 return identical(this, (parent as NormalFormalParameter).identifier);
16334 } else if (parent is TypeParameter) {
16335 return identical(this, parent.name);
16336 } else if (parent is VariableDeclaration) {
16337 return identical(this, parent.name);
16338 }
16339 return false;
16340 }
16341
16342 /**
16343 * Return `true` if this expression is computing a right-hand value.
16344 *
16345 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16346 * are they mutually exclusive. In other words, it is possible for both
16347 * methods to return `true` when invoked on the same node.
16348 */
16349 bool inGetterContext() {
16350 // TODO(brianwilkerson) Convert this to a getter.
16351 AstNode parent = this.parent;
16352 AstNode target = this;
16353 // skip prefix
16354 if (parent is PrefixedIdentifier) {
16355 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16356 if (identical(prefixed.prefix, this)) {
16357 return true;
16358 }
16359 parent = prefixed.parent;
16360 target = prefixed;
16361 } else if (parent is PropertyAccess) {
16362 PropertyAccess access = parent as PropertyAccess;
16363 if (identical(access.target, this)) {
16364 return true;
16365 }
16366 parent = access.parent;
16367 target = access;
16368 }
16369 // skip label
16370 if (parent is Label) {
16371 return false;
16372 }
16373 // analyze usage
16374 if (parent is AssignmentExpression) {
16375 if (identical(parent.leftHandSide, target) &&
16376 parent.operator.type == TokenType.EQ) {
16377 return false;
16378 }
16379 }
16380 if (parent is ForEachStatement) {
16381 if (identical(parent.identifier, target)) {
16382 return false;
16383 }
16384 }
16385 return true;
16386 }
16387
16388 /**
16389 * Return `true` if this expression is computing a left-hand value.
16390 *
16391 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor
16392 * are they mutually exclusive. In other words, it is possible for both
16393 * methods to return `true` when invoked on the same node.
16394 */
16395 bool inSetterContext() {
16396 // TODO(brianwilkerson) Convert this to a getter.
16397 AstNode parent = this.parent;
16398 AstNode target = this;
16399 // skip prefix
16400 if (parent is PrefixedIdentifier) {
16401 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
16402 // if this is the prefix, then return false
16403 if (identical(prefixed.prefix, this)) {
16404 return false;
16405 }
16406 parent = prefixed.parent;
16407 target = prefixed;
16408 } else if (parent is PropertyAccess) {
16409 PropertyAccess access = parent as PropertyAccess;
16410 if (identical(access.target, this)) {
16411 return false;
16412 }
16413 parent = access.parent;
16414 target = access;
16415 }
16416 // analyze usage
16417 if (parent is PrefixExpression) {
16418 return parent.operator.type.isIncrementOperator;
16419 } else if (parent is PostfixExpression) {
16420 return true;
16421 } else if (parent is AssignmentExpression) {
16422 return identical(parent.leftHandSide, target);
16423 } else if (parent is ForEachStatement) {
16424 return identical(parent.identifier, target);
16425 }
16426 return false;
16427 }
16428
16429 @override
16430 void visitChildren(AstVisitor visitor) {
16431 // There are no children to visit.
16432 }
16433
16434 /**
16435 * Return the given element if it is valid, or report the problem and return
16436 * `null` if it is not appropriate.
16437 *
16438 * The [parent] is the parent of the element, used for reporting when there is
16439 * a problem.
16440 * The [isValid] is `true` if the element is appropriate.
16441 * The [element] is the element to be associated with this identifier.
16442 */
16443 Element _returnOrReportElement(
16444 AstNode parent, bool isValid, Element element) {
16445 if (!isValid) {
16446 AnalysisEngine.instance.logger.logInformation(
16447 "Internal error: attempting to set the name of a ${parent.runtimeType} to a ${element.runtimeType}",
16448 new CaughtException(new AnalysisException(), null));
16449 return null;
16450 }
16451 return element;
16452 }
16453
16454 /**
16455 * Return the given [element] if it is an appropriate element based on the
16456 * parent of this identifier, or `null` if it is not appropriate.
16457 */
16458 Element _validateElement(Element element) {
16459 if (element == null) {
16460 return null;
16461 }
16462 AstNode parent = this.parent;
16463 if (parent is ClassDeclaration && identical(parent.name, this)) {
16464 return _returnOrReportElement(parent, element is ClassElement, element);
16465 } else if (parent is ClassTypeAlias && identical(parent.name, this)) {
16466 return _returnOrReportElement(parent, element is ClassElement, element);
16467 } else if (parent is DeclaredIdentifier &&
16468 identical(parent.identifier, this)) {
16469 return _returnOrReportElement(
16470 parent, element is LocalVariableElement, element);
16471 } else if (parent is FormalParameter &&
16472 identical(parent.identifier, this)) {
16473 return _returnOrReportElement(
16474 parent, element is ParameterElement, element);
16475 } else if (parent is FunctionDeclaration && identical(parent.name, this)) {
16476 return _returnOrReportElement(
16477 parent, element is ExecutableElement, element);
16478 } else if (parent is FunctionTypeAlias && identical(parent.name, this)) {
16479 return _returnOrReportElement(
16480 parent, element is FunctionTypeAliasElement, element);
16481 } else if (parent is MethodDeclaration && identical(parent.name, this)) {
16482 return _returnOrReportElement(
16483 parent, element is ExecutableElement, element);
16484 } else if (parent is TypeParameter && identical(parent.name, this)) {
16485 return _returnOrReportElement(
16486 parent, element is TypeParameterElement, element);
16487 } else if (parent is VariableDeclaration && identical(parent.name, this)) {
16488 return _returnOrReportElement(
16489 parent, element is VariableElement, element);
16490 }
16491 return element;
16492 }
16493 }
16494
16495 /**
16496 * A string literal expression that does not contain any interpolations.
16497 *
16498 * > simpleStringLiteral ::=
16499 * > rawStringLiteral
16500 * > | basicStringLiteral
16501 * >
16502 * > rawStringLiteral ::=
16503 * > 'r' basicStringLiteral
16504 * >
16505 * > simpleStringLiteral ::=
16506 * > multiLineStringLiteral
16507 * > | singleLineStringLiteral
16508 * >
16509 * > multiLineStringLiteral ::=
16510 * > "'''" characters "'''"
16511 * > | '"""' characters '"""'
16512 * >
16513 * > singleLineStringLiteral ::=
16514 * > "'" characters "'"
16515 * > | '"' characters '"'
16516 */
16517 class SimpleStringLiteral extends SingleStringLiteral {
16518 /**
16519 * The token representing the literal.
16520 */
16521 Token literal;
16522
16523 /**
16524 * The value of the literal.
16525 */
16526 String _value;
16527
16528 /**
16529 * The toolkit specific element associated with this literal, or `null`.
16530 */
16531 @deprecated // No replacement
16532 Element toolkitElement;
16533
16534 /**
16535 * Initialize a newly created simple string literal.
16536 */
16537 SimpleStringLiteral(this.literal, String value) {
16538 _value = StringUtilities.intern(value);
16539 }
16540
16541 @override
16542 Token get beginToken => literal;
16543
16544 @override
16545 Iterable get childEntities => new ChildEntities()..add(literal);
16546
16547 @override
16548 int get contentsEnd => offset + _helper.end;
16549
16550 @override
16551 int get contentsOffset => offset + _helper.start;
16552
16553 @override
16554 Token get endToken => literal;
16555
16556 @override
16557 bool get isMultiline => _helper.isMultiline;
16558
16559 @override
16560 bool get isRaw => _helper.isRaw;
16561
16562 @override
16563 bool get isSingleQuoted => _helper.isSingleQuoted;
16564
16565 @override
16566 bool get isSynthetic => literal.isSynthetic;
16567
16568 /**
16569 * Return the value of the literal.
16570 */
16571 String get value => _value;
16572
16573 /**
16574 * Set the value of the literal to the given [string].
16575 */
16576 void set value(String string) {
16577 _value = StringUtilities.intern(_value);
16578 }
16579
16580 StringLexemeHelper get _helper {
16581 return new StringLexemeHelper(literal.lexeme, true, true);
16582 }
16583
16584 @override
16585 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this);
16586
16587 @override
16588 void visitChildren(AstVisitor visitor) {
16589 // There are no children to visit.
16590 }
16591
16592 @override
16593 void _appendStringValue(StringBuffer buffer) {
16594 buffer.write(value);
16595 }
16596 }
16597
16598 /**
16599 * A single string literal expression.
16600 *
16601 * > singleStringLiteral ::=
16602 * > [SimpleStringLiteral]
16603 * > | [StringInterpolation]
16604 */
16605 abstract class SingleStringLiteral extends StringLiteral {
16606 /**
16607 * Return the offset of the after-last contents character.
16608 */
16609 int get contentsEnd;
16610
16611 /**
16612 * Return the offset of the first contents character.
16613 * If the string is multiline, then leading whitespaces are skipped.
16614 */
16615 int get contentsOffset;
16616
16617 /**
16618 * Return `true` if this string literal is a multi-line string.
16619 */
16620 bool get isMultiline;
16621
16622 /**
16623 * Return `true` if this string literal is a raw string.
16624 */
16625 bool get isRaw;
16626
16627 /**
16628 * Return `true` if this string literal uses single qoutes (' or ''').
16629 * Return `false` if this string literal uses double qoutes (" or """).
16630 */
16631 bool get isSingleQuoted;
16632 }
16633
16634 /**
16635 * A node that represents a statement.
16636 *
16637 * > statement ::=
16638 * > [Block]
16639 * > | [VariableDeclarationStatement]
16640 * > | [ForStatement]
16641 * > | [ForEachStatement]
16642 * > | [WhileStatement]
16643 * > | [DoStatement]
16644 * > | [SwitchStatement]
16645 * > | [IfStatement]
16646 * > | [TryStatement]
16647 * > | [BreakStatement]
16648 * > | [ContinueStatement]
16649 * > | [ReturnStatement]
16650 * > | [ExpressionStatement]
16651 * > | [FunctionDeclarationStatement]
16652 */
16653 abstract class Statement extends AstNode {
16654 /**
16655 * If this is a labeled statement, return the unlabeled portion of the
16656 * statement. Otherwise return the statement itself.
16657 */
16658 Statement get unlabeled => this;
16659 }
16660
16661 /**
16662 * A string interpolation literal.
16663 *
16664 * > stringInterpolation ::=
16665 * > ''' [InterpolationElement]* '''
16666 * > | '"' [InterpolationElement]* '"'
16667 */
16668 class StringInterpolation extends SingleStringLiteral {
16669 /**
16670 * The elements that will be composed to produce the resulting string.
16671 */
16672 NodeList<InterpolationElement> _elements;
16673
16674 /**
16675 * Initialize a newly created string interpolation expression.
16676 */
16677 StringInterpolation(List<InterpolationElement> elements) {
16678 _elements = new NodeList<InterpolationElement>(this, elements);
16679 }
16680
16681 @override
16682 Token get beginToken => _elements.beginToken;
16683
16684 @override
16685 Iterable get childEntities => new ChildEntities()..addAll(_elements);
16686
16687 @override
16688 int get contentsEnd {
16689 InterpolationString element = _elements.last;
16690 return element.contentsEnd;
16691 }
16692
16693 @override
16694 int get contentsOffset {
16695 InterpolationString element = _elements.first;
16696 return element.contentsOffset;
16697 }
16698
16699 /**
16700 * Return the elements that will be composed to produce the resulting string.
16701 */
16702 NodeList<InterpolationElement> get elements => _elements;
16703
16704 @override
16705 Token get endToken => _elements.endToken;
16706
16707 @override
16708 bool get isMultiline => _firstHelper.isMultiline;
16709
16710 @override
16711 bool get isRaw => false;
16712
16713 @override
16714 bool get isSingleQuoted => _firstHelper.isSingleQuoted;
16715
16716 StringLexemeHelper get _firstHelper {
16717 InterpolationString lastString = _elements.first;
16718 String lexeme = lastString.contents.lexeme;
16719 return new StringLexemeHelper(lexeme, true, false);
16720 }
16721
16722 @override
16723 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this);
16724
16725 @override
16726 void visitChildren(AstVisitor visitor) {
16727 _elements.accept(visitor);
16728 }
16729
16730 @override
16731 void _appendStringValue(StringBuffer buffer) {
16732 throw new IllegalArgumentException();
16733 }
16734 }
16735
16736 /**
16737 * A helper for analyzing string lexemes.
16738 */
16739 class StringLexemeHelper {
16740 final String lexeme;
16741 final bool isFirst;
16742 final bool isLast;
16743
16744 bool isRaw = false;
16745 bool isSingleQuoted = false;
16746 bool isMultiline = false;
16747 int start = 0;
16748 int end;
16749
16750 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) {
16751 if (isFirst) {
16752 isRaw = StringUtilities.startsWithChar(lexeme, 0x72);
16753 if (isRaw) {
16754 start++;
16755 }
16756 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) {
16757 isSingleQuoted = true;
16758 isMultiline = true;
16759 start += 3;
16760 start = _trimInitialWhitespace(start);
16761 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) {
16762 isSingleQuoted = false;
16763 isMultiline = true;
16764 start += 3;
16765 start = _trimInitialWhitespace(start);
16766 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) {
16767 isSingleQuoted = true;
16768 isMultiline = false;
16769 start++;
16770 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) {
16771 isSingleQuoted = false;
16772 isMultiline = false;
16773 start++;
16774 }
16775 }
16776 end = lexeme.length;
16777 if (isLast) {
16778 if (start + 3 <= end &&
16779 (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
16780 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27))) {
16781 end -= 3;
16782 } else if (start + 1 <= end &&
16783 (StringUtilities.endsWithChar(lexeme, 0x22) ||
16784 StringUtilities.endsWithChar(lexeme, 0x27))) {
16785 end -= 1;
16786 }
16787 }
16788 }
16789
16790 /**
16791 * Given the [lexeme] for a multi-line string whose content begins at the
16792 * given [start] index, return the index of the first character that is
16793 * included in the value of the string. According to the specification:
16794 *
16795 * If the first line of a multiline string consists solely of the whitespace
16796 * characters defined by the production WHITESPACE 20.1), possibly prefixed
16797 * by \, then that line is ignored, including the new line at its end.
16798 */
16799 int _trimInitialWhitespace(int start) {
16800 int length = lexeme.length;
16801 int index = start;
16802 while (index < length) {
16803 int currentChar = lexeme.codeUnitAt(index);
16804 if (currentChar == 0x0D) {
16805 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
16806 return index + 2;
16807 }
16808 return index + 1;
16809 } else if (currentChar == 0x0A) {
16810 return index + 1;
16811 } else if (currentChar == 0x5C) {
16812 if (index + 1 >= length) {
16813 return start;
16814 }
16815 currentChar = lexeme.codeUnitAt(index + 1);
16816 if (currentChar != 0x0D &&
16817 currentChar != 0x0A &&
16818 currentChar != 0x09 &&
16819 currentChar != 0x20) {
16820 return start;
16821 }
16822 } else if (currentChar != 0x09 && currentChar != 0x20) {
16823 return start;
16824 }
16825 index++;
16826 }
16827 return start;
16828 }
16829 }
16830
16831 /**
16832 * A string literal expression.
16833 *
16834 * > stringLiteral ::=
16835 * > [SimpleStringLiteral]
16836 * > | [AdjacentStrings]
16837 * > | [StringInterpolation]
16838 */
16839 abstract class StringLiteral extends Literal {
16840 /**
16841 * Return the value of the string literal, or `null` if the string is not a
16842 * constant string without any string interpolation.
16843 */
16844 String get stringValue {
16845 StringBuffer buffer = new StringBuffer();
16846 try {
16847 _appendStringValue(buffer);
16848 } on IllegalArgumentException {
16849 return null;
16850 }
16851 return buffer.toString();
16852 }
16853
16854 /**
16855 * Append the value of this string literal to the given [buffer]. Throw an
16856 * [IllegalArgumentException] if the string is not a constant string without
16857 * any string interpolation.
16858 */
16859 @deprecated // Use "this.stringValue"
16860 void appendStringValue(StringBuffer buffer) => _appendStringValue(buffer);
16861
16862 /**
16863 * Append the value of this string literal to the given [buffer]. Throw an
16864 * [IllegalArgumentException] if the string is not a constant string without
16865 * any string interpolation.
16866 */
16867 void _appendStringValue(StringBuffer buffer);
16868 }
16869
16870 /**
16871 * The invocation of a superclass' constructor from within a constructor's
16872 * initialization list.
16873 *
16874 * > superInvocation ::=
16875 * > 'super' ('.' [SimpleIdentifier])? [ArgumentList]
16876 */
16877 class SuperConstructorInvocation extends ConstructorInitializer {
16878 /**
16879 * The token for the 'super' keyword.
16880 */
16881 Token superKeyword;
16882
16883 /**
16884 * The token for the period before the name of the constructor that is being
16885 * invoked, or `null` if the unnamed constructor is being invoked.
16886 */
16887 Token period;
16888
16889 /**
16890 * The name of the constructor that is being invoked, or `null` if the unnamed
16891 * constructor is being invoked.
16892 */
16893 SimpleIdentifier _constructorName;
16894
16895 /**
16896 * The list of arguments to the constructor.
16897 */
16898 ArgumentList _argumentList;
16899
16900 /**
16901 * The element associated with the constructor based on static type
16902 * information, or `null` if the AST structure has not been resolved or if the
16903 * constructor could not be resolved.
16904 */
16905 ConstructorElement staticElement;
16906
16907 /**
16908 * Initialize a newly created super invocation to invoke the inherited
16909 * constructor with the given name with the given arguments. The [period] and
16910 * [constructorName] can be `null` if the constructor being invoked is the
16911 * unnamed constructor.
16912 */
16913 SuperConstructorInvocation(this.superKeyword, this.period,
16914 SimpleIdentifier constructorName, ArgumentList argumentList) {
16915 _constructorName = _becomeParentOf(constructorName);
16916 _argumentList = _becomeParentOf(argumentList);
16917 }
16918
16919 /**
16920 * Return the list of arguments to the constructor.
16921 */
16922 ArgumentList get argumentList => _argumentList;
16923
16924 /**
16925 * Set the list of arguments to the constructor to the given [argumentList].
16926 */
16927 void set argumentList(ArgumentList argumentList) {
16928 _argumentList = _becomeParentOf(argumentList);
16929 }
16930
16931 @override
16932 Token get beginToken => superKeyword;
16933
16934 @override
16935 Iterable get childEntities => new ChildEntities()
16936 ..add(superKeyword)
16937 ..add(period)
16938 ..add(_constructorName)
16939 ..add(_argumentList);
16940
16941 /**
16942 * Return the name of the constructor that is being invoked, or `null` if the
16943 * unnamed constructor is being invoked.
16944 */
16945 SimpleIdentifier get constructorName => _constructorName;
16946
16947 /**
16948 * Set the name of the constructor that is being invoked to the given
16949 * [identifier].
16950 */
16951 void set constructorName(SimpleIdentifier identifier) {
16952 _constructorName = _becomeParentOf(identifier);
16953 }
16954
16955 @override
16956 Token get endToken => _argumentList.endToken;
16957
16958 /**
16959 * Return the token for the 'super' keyword.
16960 */
16961 @deprecated // Use "this.superKeyword"
16962 Token get keyword => superKeyword;
16963
16964 /**
16965 * Set the token for the 'super' keyword to the given [token].
16966 */
16967 @deprecated // Use "this.superKeyword"
16968 set keyword(Token token) {
16969 superKeyword = token;
16970 }
16971
16972 @override
16973 accept(AstVisitor visitor) => visitor.visitSuperConstructorInvocation(this);
16974
16975 @override
16976 void visitChildren(AstVisitor visitor) {
16977 _safelyVisitChild(_constructorName, visitor);
16978 _safelyVisitChild(_argumentList, visitor);
16979 }
16980 }
16981
16982 /**
16983 * A super expression.
16984 *
16985 * > superExpression ::=
16986 * > 'super'
16987 */
16988 class SuperExpression extends Expression {
16989 /**
16990 * The token representing the 'super' keyword.
16991 */
16992 Token superKeyword;
16993
16994 /**
16995 * Initialize a newly created super expression.
16996 */
16997 SuperExpression(this.superKeyword);
16998
16999 @override
17000 Token get beginToken => superKeyword;
17001
17002 @override
17003 Iterable get childEntities => new ChildEntities()..add(superKeyword);
17004
17005 @override
17006 Token get endToken => superKeyword;
17007
17008 /**
17009 * Return the token for the 'super' keyword.
17010 */
17011 @deprecated // Use "this.superKeyword"
17012 Token get keyword => superKeyword;
17013
17014 /**
17015 * Set the token for the 'super' keyword to the given [token].
17016 */
17017 @deprecated // Use "this.superKeyword"
17018 set keyword(Token token) {
17019 superKeyword = token;
17020 }
17021
17022 @override
17023 int get precedence => 16;
17024
17025 @override
17026 accept(AstVisitor visitor) => visitor.visitSuperExpression(this);
17027
17028 @override
17029 void visitChildren(AstVisitor visitor) {
17030 // There are no children to visit.
17031 }
17032 }
17033
17034 /**
17035 * A case in a switch statement.
17036 *
17037 * > switchCase ::=
17038 * > [SimpleIdentifier]* 'case' [Expression] ':' [Statement]*
17039 */
17040 class SwitchCase extends SwitchMember {
17041 /**
17042 * The expression controlling whether the statements will be executed.
17043 */
17044 Expression _expression;
17045
17046 /**
17047 * Initialize a newly created switch case. The list of [labels] can be `null`
17048 * if there are no labels.
17049 */
17050 SwitchCase(List<Label> labels, Token keyword, Expression expression,
17051 Token colon, List<Statement> statements)
17052 : super(labels, keyword, colon, statements) {
17053 _expression = _becomeParentOf(expression);
17054 }
17055
17056 @override
17057 Iterable get childEntities => new ChildEntities()
17058 ..addAll(labels)
17059 ..add(keyword)
17060 ..add(_expression)
17061 ..add(colon)
17062 ..addAll(statements);
17063
17064 /**
17065 * Return the expression controlling whether the statements will be executed.
17066 */
17067 Expression get expression => _expression;
17068
17069 /**
17070 * Set the expression controlling whether the statements will be executed to
17071 * the given [expression].
17072 */
17073 void set expression(Expression expression) {
17074 _expression = _becomeParentOf(expression);
17075 }
17076
17077 @override
17078 accept(AstVisitor visitor) => visitor.visitSwitchCase(this);
17079
17080 @override
17081 void visitChildren(AstVisitor visitor) {
17082 labels.accept(visitor);
17083 _safelyVisitChild(_expression, visitor);
17084 statements.accept(visitor);
17085 }
17086 }
17087
17088 /**
17089 * The default case in a switch statement.
17090 *
17091 * > switchDefault ::=
17092 * > [SimpleIdentifier]* 'default' ':' [Statement]*
17093 */
17094 class SwitchDefault extends SwitchMember {
17095 /**
17096 * Initialize a newly created switch default. The list of [labels] can be
17097 * `null` if there are no labels.
17098 */
17099 SwitchDefault(List<Label> labels, Token keyword, Token colon,
17100 List<Statement> statements)
17101 : super(labels, keyword, colon, statements);
17102
17103 @override
17104 Iterable get childEntities => new ChildEntities()
17105 ..addAll(labels)
17106 ..add(keyword)
17107 ..add(colon)
17108 ..addAll(statements);
17109
17110 @override
17111 accept(AstVisitor visitor) => visitor.visitSwitchDefault(this);
17112
17113 @override
17114 void visitChildren(AstVisitor visitor) {
17115 labels.accept(visitor);
17116 statements.accept(visitor);
17117 }
17118 }
17119
17120 /**
17121 * An element within a switch statement.
17122 *
17123 * > switchMember ::=
17124 * > switchCase
17125 * > | switchDefault
17126 */
17127 abstract class SwitchMember extends AstNode {
17128 /**
17129 * The labels associated with the switch member.
17130 */
17131 NodeList<Label> _labels;
17132
17133 /**
17134 * The token representing the 'case' or 'default' keyword.
17135 */
17136 Token keyword;
17137
17138 /**
17139 * The colon separating the keyword or the expression from the statements.
17140 */
17141 Token colon;
17142
17143 /**
17144 * The statements that will be executed if this switch member is selected.
17145 */
17146 NodeList<Statement> _statements;
17147
17148 /**
17149 * Initialize a newly created switch member. The list of [labels] can be
17150 * `null` if there are no labels.
17151 */
17152 SwitchMember(List<Label> labels, this.keyword, this.colon,
17153 List<Statement> statements) {
17154 _labels = new NodeList<Label>(this, labels);
17155 _statements = new NodeList<Statement>(this, statements);
17156 }
17157
17158 @override
17159 Token get beginToken {
17160 if (!_labels.isEmpty) {
17161 return _labels.beginToken;
17162 }
17163 return keyword;
17164 }
17165
17166 @override
17167 Token get endToken {
17168 if (!_statements.isEmpty) {
17169 return _statements.endToken;
17170 }
17171 return colon;
17172 }
17173
17174 /**
17175 * Return the labels associated with the switch member.
17176 */
17177 NodeList<Label> get labels => _labels;
17178
17179 /**
17180 * Return the statements that will be executed if this switch member is
17181 * selected.
17182 */
17183 NodeList<Statement> get statements => _statements;
17184 }
17185
17186 /**
17187 * A switch statement.
17188 *
17189 * > switchStatement ::=
17190 * > 'switch' '(' [Expression] ')' '{' [SwitchCase]* [SwitchDefault]? '}'
17191 */
17192 class SwitchStatement extends Statement {
17193 /**
17194 * The token representing the 'switch' keyword.
17195 */
17196 Token switchKeyword;
17197
17198 /**
17199 * The left parenthesis.
17200 */
17201 Token leftParenthesis;
17202
17203 /**
17204 * The expression used to determine which of the switch members will be
17205 * selected.
17206 */
17207 Expression _expression;
17208
17209 /**
17210 * The right parenthesis.
17211 */
17212 Token rightParenthesis;
17213
17214 /**
17215 * The left curly bracket.
17216 */
17217 Token leftBracket;
17218
17219 /**
17220 * The switch members that can be selected by the expression.
17221 */
17222 NodeList<SwitchMember> _members;
17223
17224 /**
17225 * The right curly bracket.
17226 */
17227 Token rightBracket;
17228
17229 /**
17230 * Initialize a newly created switch statement. The list of [members] can be
17231 * `null` if there are no switch members.
17232 */
17233 SwitchStatement(this.switchKeyword, this.leftParenthesis,
17234 Expression expression, this.rightParenthesis, this.leftBracket,
17235 List<SwitchMember> members, this.rightBracket) {
17236 _expression = _becomeParentOf(expression);
17237 _members = new NodeList<SwitchMember>(this, members);
17238 }
17239
17240 @override
17241 Token get beginToken => switchKeyword;
17242
17243 @override
17244 Iterable get childEntities => new ChildEntities()
17245 ..add(switchKeyword)
17246 ..add(leftParenthesis)
17247 ..add(_expression)
17248 ..add(rightParenthesis)
17249 ..add(leftBracket)
17250 ..addAll(_members)
17251 ..add(rightBracket);
17252
17253 @override
17254 Token get endToken => rightBracket;
17255
17256 /**
17257 * Return the expression used to determine which of the switch members will be
17258 * selected.
17259 */
17260 Expression get expression => _expression;
17261
17262 /**
17263 * Set the expression used to determine which of the switch members will be
17264 * selected to the given [expression].
17265 */
17266 void set expression(Expression expression) {
17267 _expression = _becomeParentOf(expression);
17268 }
17269
17270 /**
17271 * Return the token representing the 'switch' keyword.
17272 */
17273 @deprecated // Use "this.switchKeyword"
17274 Token get keyword => switchKeyword;
17275
17276 /**
17277 * Set the token representing the 'switch' keyword to the given [token].
17278 */
17279 @deprecated // Use "this.switchKeyword"
17280 set keyword(Token token) {
17281 switchKeyword = token;
17282 }
17283
17284 /**
17285 * Return the switch members that can be selected by the expression.
17286 */
17287 NodeList<SwitchMember> get members => _members;
17288
17289 @override
17290 accept(AstVisitor visitor) => visitor.visitSwitchStatement(this);
17291
17292 @override
17293 void visitChildren(AstVisitor visitor) {
17294 _safelyVisitChild(_expression, visitor);
17295 _members.accept(visitor);
17296 }
17297 }
17298
17299 /**
17300 * A symbol literal expression.
17301 *
17302 * > symbolLiteral ::=
17303 * > '#' (operator | (identifier ('.' identifier)*))
17304 */
17305 class SymbolLiteral extends Literal {
17306 /**
17307 * The token introducing the literal.
17308 */
17309 Token poundSign;
17310
17311 /**
17312 * The components of the literal.
17313 */
17314 final List<Token> components;
17315
17316 /**
17317 * Initialize a newly created symbol literal.
17318 */
17319 SymbolLiteral(this.poundSign, this.components);
17320
17321 @override
17322 Token get beginToken => poundSign;
17323
17324 /**
17325 * TODO(paulberry): add "." tokens.
17326 */
17327 @override
17328 Iterable get childEntities => new ChildEntities()
17329 ..add(poundSign)
17330 ..addAll(components);
17331
17332 @override
17333 Token get endToken => components[components.length - 1];
17334
17335 @override
17336 accept(AstVisitor visitor) => visitor.visitSymbolLiteral(this);
17337
17338 @override
17339 void visitChildren(AstVisitor visitor) {
17340 // There are no children to visit.
17341 }
17342 }
17343
17344 /**
17345 * A this expression.
17346 *
17347 * > thisExpression ::=
17348 * > 'this'
17349 */
17350 class ThisExpression extends Expression {
17351 /**
17352 * The token representing the 'this' keyword.
17353 */
17354 Token thisKeyword;
17355
17356 /**
17357 * Initialize a newly created this expression.
17358 */
17359 ThisExpression(this.thisKeyword);
17360
17361 @override
17362 Token get beginToken => thisKeyword;
17363
17364 @override
17365 Iterable get childEntities => new ChildEntities()..add(thisKeyword);
17366
17367 @override
17368 Token get endToken => thisKeyword;
17369
17370 /**
17371 * Return the token representing the 'this' keyword.
17372 */
17373 @deprecated // Use "this.thisKeyword"
17374 Token get keyword => thisKeyword;
17375
17376 /**
17377 * Set the token representing the 'this' keyword to the given [token].
17378 */
17379 @deprecated // Use "this.thisKeyword"
17380 set keyword(Token token) {
17381 thisKeyword = token;
17382 }
17383
17384 @override
17385 int get precedence => 16;
17386
17387 @override
17388 accept(AstVisitor visitor) => visitor.visitThisExpression(this);
17389
17390 @override
17391 void visitChildren(AstVisitor visitor) {
17392 // There are no children to visit.
17393 }
17394 }
17395
17396 /**
17397 * A throw expression.
17398 *
17399 * > throwExpression ::=
17400 * > 'throw' [Expression]
17401 */
17402 class ThrowExpression extends Expression {
17403 /**
17404 * The token representing the 'throw' keyword.
17405 */
17406 Token throwKeyword;
17407
17408 /**
17409 * The expression computing the exception to be thrown.
17410 */
17411 Expression _expression;
17412
17413 /**
17414 * Initialize a newly created throw expression.
17415 */
17416 ThrowExpression(this.throwKeyword, Expression expression) {
17417 _expression = _becomeParentOf(expression);
17418 }
17419
17420 @override
17421 Token get beginToken => throwKeyword;
17422
17423 @override
17424 Iterable get childEntities =>
17425 new ChildEntities()..add(throwKeyword)..add(_expression);
17426
17427 @override
17428 Token get endToken {
17429 if (_expression != null) {
17430 return _expression.endToken;
17431 }
17432 return throwKeyword;
17433 }
17434
17435 /**
17436 * Return the expression computing the exception to be thrown.
17437 */
17438 Expression get expression => _expression;
17439
17440 /**
17441 * Set the expression computing the exception to be thrown to the given
17442 * [expression].
17443 */
17444 void set expression(Expression expression) {
17445 _expression = _becomeParentOf(expression);
17446 }
17447
17448 /**
17449 * Return the token representing the 'throw' keyword.
17450 */
17451 @deprecated // Use "this.throwKeyword"
17452 Token get keyword => throwKeyword;
17453
17454 /**
17455 * Set the token representing the 'throw' keyword to the given [token].
17456 */
17457 @deprecated // Use "this.throwKeyword"
17458 set keyword(Token token) {
17459 throwKeyword = token;
17460 }
17461
17462 @override
17463 int get precedence => 0;
17464
17465 @override
17466 accept(AstVisitor visitor) => visitor.visitThrowExpression(this);
17467
17468 @override
17469 void visitChildren(AstVisitor visitor) {
17470 _safelyVisitChild(_expression, visitor);
17471 }
17472 }
17473
17474 /**
17475 * The declaration of one or more top-level variables of the same type.
17476 *
17477 * > topLevelVariableDeclaration ::=
17478 * > ('final' | 'const') type? staticFinalDeclarationList ';'
17479 * > | variableDeclaration ';'
17480 */
17481 class TopLevelVariableDeclaration extends CompilationUnitMember {
17482 /**
17483 * The top-level variables being declared.
17484 */
17485 VariableDeclarationList _variableList;
17486
17487 /**
17488 * The semicolon terminating the declaration.
17489 */
17490 Token semicolon;
17491
17492 /**
17493 * Initialize a newly created top-level variable declaration. Either or both
17494 * of the [comment] and [metadata] can be `null` if the variable does not have
17495 * the corresponding attribute.
17496 */
17497 TopLevelVariableDeclaration(Comment comment, List<Annotation> metadata,
17498 VariableDeclarationList variableList, this.semicolon)
17499 : super(comment, metadata) {
17500 _variableList = _becomeParentOf(variableList);
17501 }
17502
17503 @override
17504 Iterable get childEntities =>
17505 super._childEntities..add(_variableList)..add(semicolon);
17506
17507 @override
17508 Element get element => null;
17509
17510 @override
17511 Token get endToken => semicolon;
17512
17513 @override
17514 Token get firstTokenAfterCommentAndMetadata => _variableList.beginToken;
17515
17516 /**
17517 * Return the top-level variables being declared.
17518 */
17519 VariableDeclarationList get variables => _variableList;
17520
17521 /**
17522 * Set the top-level variables being declared to the given list of
17523 * [variables].
17524 */
17525 void set variables(VariableDeclarationList variables) {
17526 _variableList = _becomeParentOf(variables);
17527 }
17528
17529 @override
17530 accept(AstVisitor visitor) => visitor.visitTopLevelVariableDeclaration(this);
17531
17532 @override
17533 void visitChildren(AstVisitor visitor) {
17534 super.visitChildren(visitor);
17535 _safelyVisitChild(_variableList, visitor);
17536 }
17537 }
17538
17539 /**
17540 * A visitor used to write a source representation of a visited AST node (and
17541 * all of it's children) to a writer.
17542 */
17543 class ToSourceVisitor implements AstVisitor<Object> {
17544 /**
17545 * The writer to which the source is to be written.
17546 */
17547 final PrintWriter _writer;
17548
17549 /**
17550 * Initialize a newly created visitor to write source code representing the
17551 * visited nodes to the given [writer].
17552 */
17553 ToSourceVisitor(this._writer);
17554
17555 @override
17556 Object visitAdjacentStrings(AdjacentStrings node) {
17557 _visitNodeListWithSeparator(node.strings, " ");
17558 return null;
17559 }
17560
17561 @override
17562 Object visitAnnotation(Annotation node) {
17563 _writer.print('@');
17564 _visitNode(node.name);
17565 _visitNodeWithPrefix(".", node.constructorName);
17566 _visitNode(node.arguments);
17567 return null;
17568 }
17569
17570 @override
17571 Object visitArgumentList(ArgumentList node) {
17572 _writer.print('(');
17573 _visitNodeListWithSeparator(node.arguments, ", ");
17574 _writer.print(')');
17575 return null;
17576 }
17577
17578 @override
17579 Object visitAsExpression(AsExpression node) {
17580 _visitNode(node.expression);
17581 _writer.print(" as ");
17582 _visitNode(node.type);
17583 return null;
17584 }
17585
17586 @override
17587 Object visitAssertStatement(AssertStatement node) {
17588 _writer.print("assert (");
17589 _visitNode(node.condition);
17590 _writer.print(");");
17591 return null;
17592 }
17593
17594 @override
17595 Object visitAssignmentExpression(AssignmentExpression node) {
17596 _visitNode(node.leftHandSide);
17597 _writer.print(' ');
17598 _writer.print(node.operator.lexeme);
17599 _writer.print(' ');
17600 _visitNode(node.rightHandSide);
17601 return null;
17602 }
17603
17604 @override
17605 Object visitAwaitExpression(AwaitExpression node) {
17606 _writer.print("await ");
17607 _visitNode(node.expression);
17608 _writer.print(";");
17609 return null;
17610 }
17611
17612 @override
17613 Object visitBinaryExpression(BinaryExpression node) {
17614 _visitNode(node.leftOperand);
17615 _writer.print(' ');
17616 _writer.print(node.operator.lexeme);
17617 _writer.print(' ');
17618 _visitNode(node.rightOperand);
17619 return null;
17620 }
17621
17622 @override
17623 Object visitBlock(Block node) {
17624 _writer.print('{');
17625 _visitNodeListWithSeparator(node.statements, " ");
17626 _writer.print('}');
17627 return null;
17628 }
17629
17630 @override
17631 Object visitBlockFunctionBody(BlockFunctionBody node) {
17632 Token keyword = node.keyword;
17633 if (keyword != null) {
17634 _writer.print(keyword.lexeme);
17635 if (node.star != null) {
17636 _writer.print('*');
17637 }
17638 _writer.print(' ');
17639 }
17640 _visitNode(node.block);
17641 return null;
17642 }
17643
17644 @override
17645 Object visitBooleanLiteral(BooleanLiteral node) {
17646 _writer.print(node.literal.lexeme);
17647 return null;
17648 }
17649
17650 @override
17651 Object visitBreakStatement(BreakStatement node) {
17652 _writer.print("break");
17653 _visitNodeWithPrefix(" ", node.label);
17654 _writer.print(";");
17655 return null;
17656 }
17657
17658 @override
17659 Object visitCascadeExpression(CascadeExpression node) {
17660 _visitNode(node.target);
17661 _visitNodeList(node.cascadeSections);
17662 return null;
17663 }
17664
17665 @override
17666 Object visitCatchClause(CatchClause node) {
17667 _visitNodeWithPrefix("on ", node.exceptionType);
17668 if (node.catchKeyword != null) {
17669 if (node.exceptionType != null) {
17670 _writer.print(' ');
17671 }
17672 _writer.print("catch (");
17673 _visitNode(node.exceptionParameter);
17674 _visitNodeWithPrefix(", ", node.stackTraceParameter);
17675 _writer.print(") ");
17676 } else {
17677 _writer.print(" ");
17678 }
17679 _visitNode(node.body);
17680 return null;
17681 }
17682
17683 @override
17684 Object visitClassDeclaration(ClassDeclaration node) {
17685 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17686 _visitTokenWithSuffix(node.abstractKeyword, " ");
17687 _writer.print("class ");
17688 _visitNode(node.name);
17689 _visitNode(node.typeParameters);
17690 _visitNodeWithPrefix(" ", node.extendsClause);
17691 _visitNodeWithPrefix(" ", node.withClause);
17692 _visitNodeWithPrefix(" ", node.implementsClause);
17693 _writer.print(" {");
17694 _visitNodeListWithSeparator(node.members, " ");
17695 _writer.print("}");
17696 return null;
17697 }
17698
17699 @override
17700 Object visitClassTypeAlias(ClassTypeAlias node) {
17701 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17702 if (node.abstractKeyword != null) {
17703 _writer.print("abstract ");
17704 }
17705 _writer.print("class ");
17706 _visitNode(node.name);
17707 _visitNode(node.typeParameters);
17708 _writer.print(" = ");
17709 _visitNode(node.superclass);
17710 _visitNodeWithPrefix(" ", node.withClause);
17711 _visitNodeWithPrefix(" ", node.implementsClause);
17712 _writer.print(";");
17713 return null;
17714 }
17715
17716 @override
17717 Object visitComment(Comment node) => null;
17718
17719 @override
17720 Object visitCommentReference(CommentReference node) => null;
17721
17722 @override
17723 Object visitCompilationUnit(CompilationUnit node) {
17724 ScriptTag scriptTag = node.scriptTag;
17725 NodeList<Directive> directives = node.directives;
17726 _visitNode(scriptTag);
17727 String prefix = scriptTag == null ? "" : " ";
17728 _visitNodeListWithSeparatorAndPrefix(prefix, directives, " ");
17729 prefix = scriptTag == null && directives.isEmpty ? "" : " ";
17730 _visitNodeListWithSeparatorAndPrefix(prefix, node.declarations, " ");
17731 return null;
17732 }
17733
17734 @override
17735 Object visitConditionalExpression(ConditionalExpression node) {
17736 _visitNode(node.condition);
17737 _writer.print(" ? ");
17738 _visitNode(node.thenExpression);
17739 _writer.print(" : ");
17740 _visitNode(node.elseExpression);
17741 return null;
17742 }
17743
17744 @override
17745 Object visitConstructorDeclaration(ConstructorDeclaration node) {
17746 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17747 _visitTokenWithSuffix(node.externalKeyword, " ");
17748 _visitTokenWithSuffix(node.constKeyword, " ");
17749 _visitTokenWithSuffix(node.factoryKeyword, " ");
17750 _visitNode(node.returnType);
17751 _visitNodeWithPrefix(".", node.name);
17752 _visitNode(node.parameters);
17753 _visitNodeListWithSeparatorAndPrefix(" : ", node.initializers, ", ");
17754 _visitNodeWithPrefix(" = ", node.redirectedConstructor);
17755 _visitFunctionWithPrefix(" ", node.body);
17756 return null;
17757 }
17758
17759 @override
17760 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
17761 _visitTokenWithSuffix(node.thisKeyword, ".");
17762 _visitNode(node.fieldName);
17763 _writer.print(" = ");
17764 _visitNode(node.expression);
17765 return null;
17766 }
17767
17768 @override
17769 Object visitConstructorName(ConstructorName node) {
17770 _visitNode(node.type);
17771 _visitNodeWithPrefix(".", node.name);
17772 return null;
17773 }
17774
17775 @override
17776 Object visitContinueStatement(ContinueStatement node) {
17777 _writer.print("continue");
17778 _visitNodeWithPrefix(" ", node.label);
17779 _writer.print(";");
17780 return null;
17781 }
17782
17783 @override
17784 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
17785 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17786 _visitTokenWithSuffix(node.keyword, " ");
17787 _visitNodeWithSuffix(node.type, " ");
17788 _visitNode(node.identifier);
17789 return null;
17790 }
17791
17792 @override
17793 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
17794 _visitNode(node.parameter);
17795 if (node.separator != null) {
17796 _writer.print(" ");
17797 _writer.print(node.separator.lexeme);
17798 _visitNodeWithPrefix(" ", node.defaultValue);
17799 }
17800 return null;
17801 }
17802
17803 @override
17804 Object visitDoStatement(DoStatement node) {
17805 _writer.print("do ");
17806 _visitNode(node.body);
17807 _writer.print(" while (");
17808 _visitNode(node.condition);
17809 _writer.print(");");
17810 return null;
17811 }
17812
17813 @override
17814 Object visitDoubleLiteral(DoubleLiteral node) {
17815 _writer.print(node.literal.lexeme);
17816 return null;
17817 }
17818
17819 @override
17820 Object visitEmptyFunctionBody(EmptyFunctionBody node) {
17821 _writer.print(';');
17822 return null;
17823 }
17824
17825 @override
17826 Object visitEmptyStatement(EmptyStatement node) {
17827 _writer.print(';');
17828 return null;
17829 }
17830
17831 @override
17832 Object visitEnumConstantDeclaration(EnumConstantDeclaration node) {
17833 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17834 _visitNode(node.name);
17835 return null;
17836 }
17837
17838 @override
17839 Object visitEnumDeclaration(EnumDeclaration node) {
17840 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17841 _writer.print("enum ");
17842 _visitNode(node.name);
17843 _writer.print(" {");
17844 _visitNodeListWithSeparator(node.constants, ", ");
17845 _writer.print("}");
17846 return null;
17847 }
17848
17849 @override
17850 Object visitExportDirective(ExportDirective node) {
17851 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17852 _writer.print("export ");
17853 _visitNode(node.uri);
17854 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
17855 _writer.print(';');
17856 return null;
17857 }
17858
17859 @override
17860 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
17861 Token keyword = node.keyword;
17862 if (keyword != null) {
17863 _writer.print(keyword.lexeme);
17864 _writer.print(' ');
17865 }
17866 _writer.print("=> ");
17867 _visitNode(node.expression);
17868 if (node.semicolon != null) {
17869 _writer.print(';');
17870 }
17871 return null;
17872 }
17873
17874 @override
17875 Object visitExpressionStatement(ExpressionStatement node) {
17876 _visitNode(node.expression);
17877 _writer.print(';');
17878 return null;
17879 }
17880
17881 @override
17882 Object visitExtendsClause(ExtendsClause node) {
17883 _writer.print("extends ");
17884 _visitNode(node.superclass);
17885 return null;
17886 }
17887
17888 @override
17889 Object visitFieldDeclaration(FieldDeclaration node) {
17890 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17891 _visitTokenWithSuffix(node.staticKeyword, " ");
17892 _visitNode(node.fields);
17893 _writer.print(";");
17894 return null;
17895 }
17896
17897 @override
17898 Object visitFieldFormalParameter(FieldFormalParameter node) {
17899 _visitTokenWithSuffix(node.keyword, " ");
17900 _visitNodeWithSuffix(node.type, " ");
17901 _writer.print("this.");
17902 _visitNode(node.identifier);
17903 _visitNode(node.typeParameters);
17904 _visitNode(node.parameters);
17905 return null;
17906 }
17907
17908 @override
17909 Object visitForEachStatement(ForEachStatement node) {
17910 DeclaredIdentifier loopVariable = node.loopVariable;
17911 if (node.awaitKeyword != null) {
17912 _writer.print("await ");
17913 }
17914 _writer.print("for (");
17915 if (loopVariable == null) {
17916 _visitNode(node.identifier);
17917 } else {
17918 _visitNode(loopVariable);
17919 }
17920 _writer.print(" in ");
17921 _visitNode(node.iterable);
17922 _writer.print(") ");
17923 _visitNode(node.body);
17924 return null;
17925 }
17926
17927 @override
17928 Object visitFormalParameterList(FormalParameterList node) {
17929 String groupEnd = null;
17930 _writer.print('(');
17931 NodeList<FormalParameter> parameters = node.parameters;
17932 int size = parameters.length;
17933 for (int i = 0; i < size; i++) {
17934 FormalParameter parameter = parameters[i];
17935 if (i > 0) {
17936 _writer.print(", ");
17937 }
17938 if (groupEnd == null && parameter is DefaultFormalParameter) {
17939 if (parameter.kind == ParameterKind.NAMED) {
17940 groupEnd = "}";
17941 _writer.print('{');
17942 } else {
17943 groupEnd = "]";
17944 _writer.print('[');
17945 }
17946 }
17947 parameter.accept(this);
17948 }
17949 if (groupEnd != null) {
17950 _writer.print(groupEnd);
17951 }
17952 _writer.print(')');
17953 return null;
17954 }
17955
17956 @override
17957 Object visitForStatement(ForStatement node) {
17958 Expression initialization = node.initialization;
17959 _writer.print("for (");
17960 if (initialization != null) {
17961 _visitNode(initialization);
17962 } else {
17963 _visitNode(node.variables);
17964 }
17965 _writer.print(";");
17966 _visitNodeWithPrefix(" ", node.condition);
17967 _writer.print(";");
17968 _visitNodeListWithSeparatorAndPrefix(" ", node.updaters, ", ");
17969 _writer.print(") ");
17970 _visitNode(node.body);
17971 return null;
17972 }
17973
17974 @override
17975 Object visitFunctionDeclaration(FunctionDeclaration node) {
17976 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
17977 _visitTokenWithSuffix(node.externalKeyword, " ");
17978 _visitNodeWithSuffix(node.returnType, " ");
17979 _visitTokenWithSuffix(node.propertyKeyword, " ");
17980 _visitNode(node.name);
17981 _visitNode(node.functionExpression);
17982 return null;
17983 }
17984
17985 @override
17986 Object visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
17987 _visitNode(node.functionDeclaration);
17988 return null;
17989 }
17990
17991 @override
17992 Object visitFunctionExpression(FunctionExpression node) {
17993 _visitNode(node.typeParameters);
17994 _visitNode(node.parameters);
17995 if (node.body is! EmptyFunctionBody) {
17996 _writer.print(' ');
17997 }
17998 _visitNode(node.body);
17999 return null;
18000 }
18001
18002 @override
18003 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
18004 _visitNode(node.function);
18005 _visitNode(node.typeArguments);
18006 _visitNode(node.argumentList);
18007 return null;
18008 }
18009
18010 @override
18011 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
18012 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18013 _writer.print("typedef ");
18014 _visitNodeWithSuffix(node.returnType, " ");
18015 _visitNode(node.name);
18016 _visitNode(node.typeParameters);
18017 _visitNode(node.parameters);
18018 _writer.print(";");
18019 return null;
18020 }
18021
18022 @override
18023 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
18024 _visitNodeWithSuffix(node.returnType, " ");
18025 _visitNode(node.identifier);
18026 _visitNode(node.typeParameters);
18027 _visitNode(node.parameters);
18028 return null;
18029 }
18030
18031 @override
18032 Object visitHideCombinator(HideCombinator node) {
18033 _writer.print("hide ");
18034 _visitNodeListWithSeparator(node.hiddenNames, ", ");
18035 return null;
18036 }
18037
18038 @override
18039 Object visitIfStatement(IfStatement node) {
18040 _writer.print("if (");
18041 _visitNode(node.condition);
18042 _writer.print(") ");
18043 _visitNode(node.thenStatement);
18044 _visitNodeWithPrefix(" else ", node.elseStatement);
18045 return null;
18046 }
18047
18048 @override
18049 Object visitImplementsClause(ImplementsClause node) {
18050 _writer.print("implements ");
18051 _visitNodeListWithSeparator(node.interfaces, ", ");
18052 return null;
18053 }
18054
18055 @override
18056 Object visitImportDirective(ImportDirective node) {
18057 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18058 _writer.print("import ");
18059 _visitNode(node.uri);
18060 if (node.deferredKeyword != null) {
18061 _writer.print(" deferred");
18062 }
18063 _visitNodeWithPrefix(" as ", node.prefix);
18064 _visitNodeListWithSeparatorAndPrefix(" ", node.combinators, " ");
18065 _writer.print(';');
18066 return null;
18067 }
18068
18069 @override
18070 Object visitIndexExpression(IndexExpression node) {
18071 if (node.isCascaded) {
18072 _writer.print("..");
18073 } else {
18074 _visitNode(node.target);
18075 }
18076 _writer.print('[');
18077 _visitNode(node.index);
18078 _writer.print(']');
18079 return null;
18080 }
18081
18082 @override
18083 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
18084 _visitTokenWithSuffix(node.keyword, " ");
18085 _visitNode(node.constructorName);
18086 _visitNode(node.argumentList);
18087 return null;
18088 }
18089
18090 @override
18091 Object visitIntegerLiteral(IntegerLiteral node) {
18092 _writer.print(node.literal.lexeme);
18093 return null;
18094 }
18095
18096 @override
18097 Object visitInterpolationExpression(InterpolationExpression node) {
18098 if (node.rightBracket != null) {
18099 _writer.print("\${");
18100 _visitNode(node.expression);
18101 _writer.print("}");
18102 } else {
18103 _writer.print("\$");
18104 _visitNode(node.expression);
18105 }
18106 return null;
18107 }
18108
18109 @override
18110 Object visitInterpolationString(InterpolationString node) {
18111 _writer.print(node.contents.lexeme);
18112 return null;
18113 }
18114
18115 @override
18116 Object visitIsExpression(IsExpression node) {
18117 _visitNode(node.expression);
18118 if (node.notOperator == null) {
18119 _writer.print(" is ");
18120 } else {
18121 _writer.print(" is! ");
18122 }
18123 _visitNode(node.type);
18124 return null;
18125 }
18126
18127 @override
18128 Object visitLabel(Label node) {
18129 _visitNode(node.label);
18130 _writer.print(":");
18131 return null;
18132 }
18133
18134 @override
18135 Object visitLabeledStatement(LabeledStatement node) {
18136 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18137 _visitNode(node.statement);
18138 return null;
18139 }
18140
18141 @override
18142 Object visitLibraryDirective(LibraryDirective node) {
18143 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18144 _writer.print("library ");
18145 _visitNode(node.name);
18146 _writer.print(';');
18147 return null;
18148 }
18149
18150 @override
18151 Object visitLibraryIdentifier(LibraryIdentifier node) {
18152 _writer.print(node.name);
18153 return null;
18154 }
18155
18156 @override
18157 Object visitListLiteral(ListLiteral node) {
18158 if (node.constKeyword != null) {
18159 _writer.print(node.constKeyword.lexeme);
18160 _writer.print(' ');
18161 }
18162 _visitNodeWithSuffix(node.typeArguments, " ");
18163 _writer.print("[");
18164 _visitNodeListWithSeparator(node.elements, ", ");
18165 _writer.print("]");
18166 return null;
18167 }
18168
18169 @override
18170 Object visitMapLiteral(MapLiteral node) {
18171 if (node.constKeyword != null) {
18172 _writer.print(node.constKeyword.lexeme);
18173 _writer.print(' ');
18174 }
18175 _visitNodeWithSuffix(node.typeArguments, " ");
18176 _writer.print("{");
18177 _visitNodeListWithSeparator(node.entries, ", ");
18178 _writer.print("}");
18179 return null;
18180 }
18181
18182 @override
18183 Object visitMapLiteralEntry(MapLiteralEntry node) {
18184 _visitNode(node.key);
18185 _writer.print(" : ");
18186 _visitNode(node.value);
18187 return null;
18188 }
18189
18190 @override
18191 Object visitMethodDeclaration(MethodDeclaration node) {
18192 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18193 _visitTokenWithSuffix(node.externalKeyword, " ");
18194 _visitTokenWithSuffix(node.modifierKeyword, " ");
18195 _visitNodeWithSuffix(node.returnType, " ");
18196 _visitTokenWithSuffix(node.propertyKeyword, " ");
18197 _visitTokenWithSuffix(node.operatorKeyword, " ");
18198 _visitNode(node.name);
18199 if (!node.isGetter) {
18200 _visitNode(node.typeParameters);
18201 _visitNode(node.parameters);
18202 }
18203 _visitFunctionWithPrefix(" ", node.body);
18204 return null;
18205 }
18206
18207 @override
18208 Object visitMethodInvocation(MethodInvocation node) {
18209 if (node.isCascaded) {
18210 _writer.print("..");
18211 } else {
18212 if (node.target != null) {
18213 node.target.accept(this);
18214 _writer.print(node.operator.lexeme);
18215 }
18216 }
18217 _visitNode(node.methodName);
18218 _visitNode(node.typeArguments);
18219 _visitNode(node.argumentList);
18220 return null;
18221 }
18222
18223 @override
18224 Object visitNamedExpression(NamedExpression node) {
18225 _visitNode(node.name);
18226 _visitNodeWithPrefix(" ", node.expression);
18227 return null;
18228 }
18229
18230 @override
18231 Object visitNativeClause(NativeClause node) {
18232 _writer.print("native ");
18233 _visitNode(node.name);
18234 return null;
18235 }
18236
18237 @override
18238 Object visitNativeFunctionBody(NativeFunctionBody node) {
18239 _writer.print("native ");
18240 _visitNode(node.stringLiteral);
18241 _writer.print(';');
18242 return null;
18243 }
18244
18245 @override
18246 Object visitNullLiteral(NullLiteral node) {
18247 _writer.print("null");
18248 return null;
18249 }
18250
18251 @override
18252 Object visitParenthesizedExpression(ParenthesizedExpression node) {
18253 _writer.print('(');
18254 _visitNode(node.expression);
18255 _writer.print(')');
18256 return null;
18257 }
18258
18259 @override
18260 Object visitPartDirective(PartDirective node) {
18261 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18262 _writer.print("part ");
18263 _visitNode(node.uri);
18264 _writer.print(';');
18265 return null;
18266 }
18267
18268 @override
18269 Object visitPartOfDirective(PartOfDirective node) {
18270 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18271 _writer.print("part of ");
18272 _visitNode(node.libraryName);
18273 _writer.print(';');
18274 return null;
18275 }
18276
18277 @override
18278 Object visitPostfixExpression(PostfixExpression node) {
18279 _visitNode(node.operand);
18280 _writer.print(node.operator.lexeme);
18281 return null;
18282 }
18283
18284 @override
18285 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
18286 _visitNode(node.prefix);
18287 _writer.print('.');
18288 _visitNode(node.identifier);
18289 return null;
18290 }
18291
18292 @override
18293 Object visitPrefixExpression(PrefixExpression node) {
18294 _writer.print(node.operator.lexeme);
18295 _visitNode(node.operand);
18296 return null;
18297 }
18298
18299 @override
18300 Object visitPropertyAccess(PropertyAccess node) {
18301 if (node.isCascaded) {
18302 _writer.print("..");
18303 } else {
18304 _visitNode(node.target);
18305 _writer.print(node.operator.lexeme);
18306 }
18307 _visitNode(node.propertyName);
18308 return null;
18309 }
18310
18311 @override
18312 Object visitRedirectingConstructorInvocation(
18313 RedirectingConstructorInvocation node) {
18314 _writer.print("this");
18315 _visitNodeWithPrefix(".", node.constructorName);
18316 _visitNode(node.argumentList);
18317 return null;
18318 }
18319
18320 @override
18321 Object visitRethrowExpression(RethrowExpression node) {
18322 _writer.print("rethrow");
18323 return null;
18324 }
18325
18326 @override
18327 Object visitReturnStatement(ReturnStatement node) {
18328 Expression expression = node.expression;
18329 if (expression == null) {
18330 _writer.print("return;");
18331 } else {
18332 _writer.print("return ");
18333 expression.accept(this);
18334 _writer.print(";");
18335 }
18336 return null;
18337 }
18338
18339 @override
18340 Object visitScriptTag(ScriptTag node) {
18341 _writer.print(node.scriptTag.lexeme);
18342 return null;
18343 }
18344
18345 @override
18346 Object visitShowCombinator(ShowCombinator node) {
18347 _writer.print("show ");
18348 _visitNodeListWithSeparator(node.shownNames, ", ");
18349 return null;
18350 }
18351
18352 @override
18353 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
18354 _visitTokenWithSuffix(node.keyword, " ");
18355 _visitNodeWithSuffix(node.type, " ");
18356 _visitNode(node.identifier);
18357 return null;
18358 }
18359
18360 @override
18361 Object visitSimpleIdentifier(SimpleIdentifier node) {
18362 _writer.print(node.token.lexeme);
18363 return null;
18364 }
18365
18366 @override
18367 Object visitSimpleStringLiteral(SimpleStringLiteral node) {
18368 _writer.print(node.literal.lexeme);
18369 return null;
18370 }
18371
18372 @override
18373 Object visitStringInterpolation(StringInterpolation node) {
18374 _visitNodeList(node.elements);
18375 return null;
18376 }
18377
18378 @override
18379 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
18380 _writer.print("super");
18381 _visitNodeWithPrefix(".", node.constructorName);
18382 _visitNode(node.argumentList);
18383 return null;
18384 }
18385
18386 @override
18387 Object visitSuperExpression(SuperExpression node) {
18388 _writer.print("super");
18389 return null;
18390 }
18391
18392 @override
18393 Object visitSwitchCase(SwitchCase node) {
18394 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18395 _writer.print("case ");
18396 _visitNode(node.expression);
18397 _writer.print(": ");
18398 _visitNodeListWithSeparator(node.statements, " ");
18399 return null;
18400 }
18401
18402 @override
18403 Object visitSwitchDefault(SwitchDefault node) {
18404 _visitNodeListWithSeparatorAndSuffix(node.labels, " ", " ");
18405 _writer.print("default: ");
18406 _visitNodeListWithSeparator(node.statements, " ");
18407 return null;
18408 }
18409
18410 @override
18411 Object visitSwitchStatement(SwitchStatement node) {
18412 _writer.print("switch (");
18413 _visitNode(node.expression);
18414 _writer.print(") {");
18415 _visitNodeListWithSeparator(node.members, " ");
18416 _writer.print("}");
18417 return null;
18418 }
18419
18420 @override
18421 Object visitSymbolLiteral(SymbolLiteral node) {
18422 _writer.print("#");
18423 List<Token> components = node.components;
18424 for (int i = 0; i < components.length; i++) {
18425 if (i > 0) {
18426 _writer.print(".");
18427 }
18428 _writer.print(components[i].lexeme);
18429 }
18430 return null;
18431 }
18432
18433 @override
18434 Object visitThisExpression(ThisExpression node) {
18435 _writer.print("this");
18436 return null;
18437 }
18438
18439 @override
18440 Object visitThrowExpression(ThrowExpression node) {
18441 _writer.print("throw ");
18442 _visitNode(node.expression);
18443 return null;
18444 }
18445
18446 @override
18447 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
18448 _visitNodeWithSuffix(node.variables, ";");
18449 return null;
18450 }
18451
18452 @override
18453 Object visitTryStatement(TryStatement node) {
18454 _writer.print("try ");
18455 _visitNode(node.body);
18456 _visitNodeListWithSeparatorAndPrefix(" ", node.catchClauses, " ");
18457 _visitNodeWithPrefix(" finally ", node.finallyBlock);
18458 return null;
18459 }
18460
18461 @override
18462 Object visitTypeArgumentList(TypeArgumentList node) {
18463 _writer.print('<');
18464 _visitNodeListWithSeparator(node.arguments, ", ");
18465 _writer.print('>');
18466 return null;
18467 }
18468
18469 @override
18470 Object visitTypeName(TypeName node) {
18471 _visitNode(node.name);
18472 _visitNode(node.typeArguments);
18473 return null;
18474 }
18475
18476 @override
18477 Object visitTypeParameter(TypeParameter node) {
18478 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18479 _visitNode(node.name);
18480 _visitNodeWithPrefix(" extends ", node.bound);
18481 return null;
18482 }
18483
18484 @override
18485 Object visitTypeParameterList(TypeParameterList node) {
18486 _writer.print('<');
18487 _visitNodeListWithSeparator(node.typeParameters, ", ");
18488 _writer.print('>');
18489 return null;
18490 }
18491
18492 @override
18493 Object visitVariableDeclaration(VariableDeclaration node) {
18494 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18495 _visitNode(node.name);
18496 _visitNodeWithPrefix(" = ", node.initializer);
18497 return null;
18498 }
18499
18500 @override
18501 Object visitVariableDeclarationList(VariableDeclarationList node) {
18502 _visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
18503 _visitTokenWithSuffix(node.keyword, " ");
18504 _visitNodeWithSuffix(node.type, " ");
18505 _visitNodeListWithSeparator(node.variables, ", ");
18506 return null;
18507 }
18508
18509 @override
18510 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
18511 _visitNode(node.variables);
18512 _writer.print(";");
18513 return null;
18514 }
18515
18516 @override
18517 Object visitWhileStatement(WhileStatement node) {
18518 _writer.print("while (");
18519 _visitNode(node.condition);
18520 _writer.print(") ");
18521 _visitNode(node.body);
18522 return null;
18523 }
18524
18525 @override
18526 Object visitWithClause(WithClause node) {
18527 _writer.print("with ");
18528 _visitNodeListWithSeparator(node.mixinTypes, ", ");
18529 return null;
18530 }
18531
18532 @override
18533 Object visitYieldStatement(YieldStatement node) {
18534 if (node.star != null) {
18535 _writer.print("yield* ");
18536 } else {
18537 _writer.print("yield ");
18538 }
18539 _visitNode(node.expression);
18540 _writer.print(";");
18541 return null;
18542 }
18543
18544 /**
18545 * Visit the given function [body], printing the [prefix] before if the body
18546 * is not empty.
18547 */
18548 void _visitFunctionWithPrefix(String prefix, FunctionBody body) {
18549 if (body is! EmptyFunctionBody) {
18550 _writer.print(prefix);
18551 }
18552 _visitNode(body);
18553 }
18554
18555 /**
18556 * Safely visit the given [node].
18557 */
18558 void _visitNode(AstNode node) {
18559 if (node != null) {
18560 node.accept(this);
18561 }
18562 }
18563
18564 /**
18565 * Print a list of [nodes] without any separation.
18566 */
18567 void _visitNodeList(NodeList<AstNode> nodes) {
18568 _visitNodeListWithSeparator(nodes, "");
18569 }
18570
18571 /**
18572 * Print a list of [nodes], separated by the given [separator].
18573 */
18574 void _visitNodeListWithSeparator(NodeList<AstNode> nodes, String separator) {
18575 if (nodes != null) {
18576 int size = nodes.length;
18577 for (int i = 0; i < size; i++) {
18578 if (i > 0) {
18579 _writer.print(separator);
18580 }
18581 nodes[i].accept(this);
18582 }
18583 }
18584 }
18585
18586 /**
18587 * Print a list of [nodes], prefixed by the given [prefix] if the list is not
18588 * empty, and separated by the given [separator].
18589 */
18590 void _visitNodeListWithSeparatorAndPrefix(
18591 String prefix, NodeList<AstNode> nodes, String separator) {
18592 if (nodes != null) {
18593 int size = nodes.length;
18594 if (size > 0) {
18595 _writer.print(prefix);
18596 for (int i = 0; i < size; i++) {
18597 if (i > 0) {
18598 _writer.print(separator);
18599 }
18600 nodes[i].accept(this);
18601 }
18602 }
18603 }
18604 }
18605
18606 /**
18607 * Print a list of [nodes], separated by the given [separator], followed by
18608 * the given [suffix] if the list is not empty.
18609 */
18610 void _visitNodeListWithSeparatorAndSuffix(
18611 NodeList<AstNode> nodes, String separator, String suffix) {
18612 if (nodes != null) {
18613 int size = nodes.length;
18614 if (size > 0) {
18615 for (int i = 0; i < size; i++) {
18616 if (i > 0) {
18617 _writer.print(separator);
18618 }
18619 nodes[i].accept(this);
18620 }
18621 _writer.print(suffix);
18622 }
18623 }
18624 }
18625
18626 /**
18627 * Safely visit the given [node], printing the [prefix] before the node if it
18628 * is non-`null`.
18629 */
18630 void _visitNodeWithPrefix(String prefix, AstNode node) {
18631 if (node != null) {
18632 _writer.print(prefix);
18633 node.accept(this);
18634 }
18635 }
18636
18637 /**
18638 * Safely visit the given [node], printing the [suffix] after the node if it
18639 * is non-`null`.
18640 */
18641 void _visitNodeWithSuffix(AstNode node, String suffix) {
18642 if (node != null) {
18643 node.accept(this);
18644 _writer.print(suffix);
18645 }
18646 }
18647
18648 /**
18649 * Safely visit the given [token], printing the [suffix] after the token if it
18650 * is non-`null`.
18651 */
18652 void _visitTokenWithSuffix(Token token, String suffix) {
18653 if (token != null) {
18654 _writer.print(token.lexeme);
18655 _writer.print(suffix);
18656 }
18657 }
18658 }
18659
18660 /**
18661 * A try statement.
18662 *
18663 * > tryStatement ::=
18664 * > 'try' [Block] ([CatchClause]+ finallyClause? | finallyClause)
18665 * >
18666 * > finallyClause ::=
18667 * > 'finally' [Block]
18668 */
18669 class TryStatement extends Statement {
18670 /**
18671 * The token representing the 'try' keyword.
18672 */
18673 Token tryKeyword;
18674
18675 /**
18676 * The body of the statement.
18677 */
18678 Block _body;
18679
18680 /**
18681 * The catch clauses contained in the try statement.
18682 */
18683 NodeList<CatchClause> _catchClauses;
18684
18685 /**
18686 * The token representing the 'finally' keyword, or `null` if the statement
18687 * does not contain a finally clause.
18688 */
18689 Token finallyKeyword;
18690
18691 /**
18692 * The finally block contained in the try statement, or `null` if the
18693 * statement does not contain a finally clause.
18694 */
18695 Block _finallyBlock;
18696
18697 /**
18698 * Initialize a newly created try statement. The list of [catchClauses] can be
18699 * `null` if there are no catch clauses. The [finallyKeyword] and
18700 * [finallyBlock] can be `null` if there is no finally clause.
18701 */
18702 TryStatement(this.tryKeyword, Block body, List<CatchClause> catchClauses,
18703 this.finallyKeyword, Block finallyBlock) {
18704 _body = _becomeParentOf(body);
18705 _catchClauses = new NodeList<CatchClause>(this, catchClauses);
18706 _finallyBlock = _becomeParentOf(finallyBlock);
18707 }
18708
18709 @override
18710 Token get beginToken => tryKeyword;
18711
18712 /**
18713 * Return the body of the statement.
18714 */
18715 Block get body => _body;
18716
18717 /**
18718 * Set the body of the statement to the given [block].
18719 */
18720 void set body(Block block) {
18721 _body = _becomeParentOf(block);
18722 }
18723
18724 /**
18725 * Return the catch clauses contained in the try statement.
18726 */
18727 NodeList<CatchClause> get catchClauses => _catchClauses;
18728
18729 @override
18730 Iterable get childEntities => new ChildEntities()
18731 ..add(tryKeyword)
18732 ..add(_body)
18733 ..addAll(_catchClauses)
18734 ..add(finallyKeyword)
18735 ..add(_finallyBlock);
18736
18737 @override
18738 Token get endToken {
18739 if (_finallyBlock != null) {
18740 return _finallyBlock.endToken;
18741 } else if (finallyKeyword != null) {
18742 return finallyKeyword;
18743 } else if (!_catchClauses.isEmpty) {
18744 return _catchClauses.endToken;
18745 }
18746 return _body.endToken;
18747 }
18748
18749 /**
18750 * Return the finally block contained in the try statement, or `null` if the
18751 * statement does not contain a finally clause.
18752 */
18753 Block get finallyBlock => _finallyBlock;
18754
18755 /**
18756 * Set the finally block contained in the try statement to the given [block].
18757 */
18758 void set finallyBlock(Block block) {
18759 _finallyBlock = _becomeParentOf(block);
18760 }
18761
18762 @override
18763 accept(AstVisitor visitor) => visitor.visitTryStatement(this);
18764
18765 @override
18766 void visitChildren(AstVisitor visitor) {
18767 _safelyVisitChild(_body, visitor);
18768 _catchClauses.accept(visitor);
18769 _safelyVisitChild(_finallyBlock, visitor);
18770 }
18771 }
18772
18773 /**
18774 * The declaration of a type alias.
18775 *
18776 * > typeAlias ::=
18777 * > 'typedef' typeAliasBody
18778 * >
18779 * > typeAliasBody ::=
18780 * > classTypeAlias
18781 * > | functionTypeAlias
18782 */
18783 abstract class TypeAlias extends NamedCompilationUnitMember {
18784 /**
18785 * The token representing the 'typedef' keyword.
18786 */
18787 Token typedefKeyword;
18788
18789 /**
18790 * The semicolon terminating the declaration.
18791 */
18792 Token semicolon;
18793
18794 /**
18795 * Initialize a newly created type alias. Either or both of the [comment] and
18796 * [metadata] can be `null` if the declaration does not have the corresponding
18797 * attribute.
18798 */
18799 TypeAlias(Comment comment, List<Annotation> metadata, this.typedefKeyword,
18800 SimpleIdentifier name, this.semicolon)
18801 : super(comment, metadata, name);
18802
18803 @override
18804 Token get endToken => semicolon;
18805
18806 @override
18807 Token get firstTokenAfterCommentAndMetadata => typedefKeyword;
18808
18809 /**
18810 * Return the token representing the 'typedef' keyword.
18811 */
18812 @deprecated // Use "this.typedefKeyword"
18813 Token get keyword => typedefKeyword;
18814
18815 /**
18816 * Set the token representing the 'typedef' keyword to the given [token].
18817 */
18818 @deprecated // Use "this.typedefKeyword"
18819 set keyword(Token token) {
18820 typedefKeyword = token;
18821 }
18822 }
18823
18824 /**
18825 * A list of type arguments.
18826 *
18827 * > typeArguments ::=
18828 * > '<' typeName (',' typeName)* '>'
18829 */
18830 class TypeArgumentList extends AstNode {
18831 /**
18832 * The left bracket.
18833 */
18834 Token leftBracket;
18835
18836 /**
18837 * The type arguments associated with the type.
18838 */
18839 NodeList<TypeName> _arguments;
18840
18841 /**
18842 * The right bracket.
18843 */
18844 Token rightBracket;
18845
18846 /**
18847 * Initialize a newly created list of type arguments.
18848 */
18849 TypeArgumentList(
18850 this.leftBracket, List<TypeName> arguments, this.rightBracket) {
18851 _arguments = new NodeList<TypeName>(this, arguments);
18852 }
18853
18854 /**
18855 * Return the type arguments associated with the type.
18856 */
18857 NodeList<TypeName> get arguments => _arguments;
18858
18859 @override
18860 Token get beginToken => leftBracket;
18861
18862 /**
18863 * TODO(paulberry): Add commas.
18864 */
18865 @override
18866 Iterable get childEntities => new ChildEntities()
18867 ..add(leftBracket)
18868 ..addAll(_arguments)
18869 ..add(rightBracket);
18870
18871 @override
18872 Token get endToken => rightBracket;
18873
18874 @override
18875 accept(AstVisitor visitor) => visitor.visitTypeArgumentList(this);
18876
18877 @override
18878 void visitChildren(AstVisitor visitor) {
18879 _arguments.accept(visitor);
18880 }
18881 }
18882
18883 /**
18884 * A literal that has a type associated with it.
18885 *
18886 * > typedLiteral ::=
18887 * > [ListLiteral]
18888 * > | [MapLiteral]
18889 */
18890 abstract class TypedLiteral extends Literal {
18891 /**
18892 * The token representing the 'const' keyword, or `null` if the literal is not
18893 * a constant.
18894 */
18895 Token constKeyword;
18896
18897 /**
18898 * The type argument associated with this literal, or `null` if no type
18899 * arguments were declared.
18900 */
18901 TypeArgumentList _typeArguments;
18902
18903 /**
18904 * Initialize a newly created typed literal. The [constKeyword] can be `null`\
18905 * if the literal is not a constant. The [typeArguments] can be `null` if no
18906 * type arguments were declared.
18907 */
18908 TypedLiteral(this.constKeyword, TypeArgumentList typeArguments) {
18909 _typeArguments = _becomeParentOf(typeArguments);
18910 }
18911
18912 /**
18913 * Return the type argument associated with this literal, or `null` if no type
18914 * arguments were declared.
18915 */
18916 TypeArgumentList get typeArguments => _typeArguments;
18917
18918 /**
18919 * Set the type argument associated with this literal to the given
18920 * [typeArguments].
18921 */
18922 void set typeArguments(TypeArgumentList typeArguments) {
18923 _typeArguments = _becomeParentOf(typeArguments);
18924 }
18925
18926 ChildEntities get _childEntities =>
18927 new ChildEntities()..add(constKeyword)..add(_typeArguments);
18928
18929 @override
18930 void visitChildren(AstVisitor visitor) {
18931 _safelyVisitChild(_typeArguments, visitor);
18932 }
18933 }
18934
18935 /**
18936 * The name of a type, which can optionally include type arguments.
18937 *
18938 * > typeName ::=
18939 * > [Identifier] typeArguments?
18940 */
18941 class TypeName extends AstNode {
18942 /**
18943 * The name of the type.
18944 */
18945 Identifier _name;
18946
18947 /**
18948 * The type arguments associated with the type, or `null` if there are no type
18949 * arguments.
18950 */
18951 TypeArgumentList _typeArguments;
18952
18953 /**
18954 * The type being named, or `null` if the AST structure has not been resolved.
18955 */
18956 DartType type;
18957
18958 /**
18959 * Initialize a newly created type name. The [typeArguments] can be `null` if
18960 * there are no type arguments.
18961 */
18962 TypeName(Identifier name, TypeArgumentList typeArguments) {
18963 _name = _becomeParentOf(name);
18964 _typeArguments = _becomeParentOf(typeArguments);
18965 }
18966
18967 @override
18968 Token get beginToken => _name.beginToken;
18969
18970 @override
18971 Iterable get childEntities =>
18972 new ChildEntities()..add(_name)..add(_typeArguments);
18973
18974 @override
18975 Token get endToken {
18976 if (_typeArguments != null) {
18977 return _typeArguments.endToken;
18978 }
18979 return _name.endToken;
18980 }
18981
18982 /**
18983 * Return `true` if this type is a deferred type.
18984 *
18985 * 15.1 Static Types: A type <i>T</i> is deferred iff it is of the form
18986 * </i>p.T</i> where <i>p</i> is a deferred prefix.
18987 */
18988 bool get isDeferred {
18989 Identifier identifier = name;
18990 if (identifier is! PrefixedIdentifier) {
18991 return false;
18992 }
18993 return (identifier as PrefixedIdentifier).isDeferred;
18994 }
18995
18996 @override
18997 bool get isSynthetic => _name.isSynthetic && _typeArguments == null;
18998
18999 /**
19000 * Return the name of the type.
19001 */
19002 Identifier get name => _name;
19003
19004 /**
19005 * Set the name of the type to the given [identifier].
19006 */
19007 void set name(Identifier identifier) {
19008 _name = _becomeParentOf(identifier);
19009 }
19010
19011 /**
19012 * Return the type arguments associated with the type, or `null` if there are
19013 * no type arguments.
19014 */
19015 TypeArgumentList get typeArguments => _typeArguments;
19016
19017 /**
19018 * Set the type arguments associated with the type to the given
19019 * [typeArguments].
19020 */
19021 void set typeArguments(TypeArgumentList typeArguments) {
19022 _typeArguments = _becomeParentOf(typeArguments);
19023 }
19024
19025 @override
19026 accept(AstVisitor visitor) => visitor.visitTypeName(this);
19027
19028 @override
19029 void visitChildren(AstVisitor visitor) {
19030 _safelyVisitChild(_name, visitor);
19031 _safelyVisitChild(_typeArguments, visitor);
19032 }
19033 }
19034
19035 /**
19036 * A type parameter.
19037 *
19038 * > typeParameter ::=
19039 * > [SimpleIdentifier] ('extends' [TypeName])?
19040 */
19041 class TypeParameter extends Declaration {
19042 /**
19043 * The name of the type parameter.
19044 */
19045 SimpleIdentifier _name;
19046
19047 /**
19048 * The token representing the 'extends' keyword, or `null` if there is no
19049 * explicit upper bound.
19050 */
19051 Token extendsKeyword;
19052
19053 /**
19054 * The name of the upper bound for legal arguments, or `null` if there is no
19055 * explicit upper bound.
19056 */
19057 TypeName _bound;
19058
19059 /**
19060 * Initialize a newly created type parameter. Either or both of the [comment]
19061 * and [metadata] can be `null` if the parameter does not have the
19062 * corresponding attribute. The [extendsKeyword] and [bound] can be `null` if
19063 * the parameter does not have an upper bound.
19064 */
19065 TypeParameter(Comment comment, List<Annotation> metadata,
19066 SimpleIdentifier name, this.extendsKeyword, TypeName bound)
19067 : super(comment, metadata) {
19068 _name = _becomeParentOf(name);
19069 _bound = _becomeParentOf(bound);
19070 }
19071
19072 /**
19073 * Return the name of the upper bound for legal arguments, or `null` if there
19074 * is no explicit upper bound.
19075 */
19076 TypeName get bound => _bound;
19077
19078 /**
19079 * Set the name of the upper bound for legal arguments to the given
19080 * [typeName].
19081 */
19082 void set bound(TypeName typeName) {
19083 _bound = _becomeParentOf(typeName);
19084 }
19085
19086 @override
19087 Iterable get childEntities =>
19088 super._childEntities..add(_name)..add(extendsKeyword)..add(_bound);
19089
19090 @override
19091 TypeParameterElement get element =>
19092 _name != null ? (_name.staticElement as TypeParameterElement) : null;
19093
19094 @override
19095 Token get endToken {
19096 if (_bound == null) {
19097 return _name.endToken;
19098 }
19099 return _bound.endToken;
19100 }
19101
19102 @override
19103 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
19104
19105 /**
19106 * Return the token representing the 'extends' keyword, or `null` if there is
19107 * no explicit upper bound.
19108 */
19109 @deprecated // Use "this.extendsKeyword"
19110 Token get keyword => extendsKeyword;
19111
19112 /**
19113 * Set the token representing the 'extends' keyword to the given [token].
19114 */
19115 @deprecated // Use "this.extendsKeyword"
19116 set keyword(Token token) {
19117 extendsKeyword = token;
19118 }
19119
19120 /**
19121 * Return the name of the type parameter.
19122 */
19123 SimpleIdentifier get name => _name;
19124
19125 /**
19126 * Set the name of the type parameter to the given [identifier].
19127 */
19128 void set name(SimpleIdentifier identifier) {
19129 _name = _becomeParentOf(identifier);
19130 }
19131
19132 @override
19133 accept(AstVisitor visitor) => visitor.visitTypeParameter(this);
19134
19135 @override
19136 void visitChildren(AstVisitor visitor) {
19137 super.visitChildren(visitor);
19138 _safelyVisitChild(_name, visitor);
19139 _safelyVisitChild(_bound, visitor);
19140 }
19141 }
19142
19143 /**
19144 * Type parameters within a declaration.
19145 *
19146 * > typeParameterList ::=
19147 * > '<' [TypeParameter] (',' [TypeParameter])* '>'
19148 */
19149 class TypeParameterList extends AstNode {
19150 /**
19151 * The left angle bracket.
19152 */
19153 final Token leftBracket;
19154
19155 /**
19156 * The type parameters in the list.
19157 */
19158 NodeList<TypeParameter> _typeParameters;
19159
19160 /**
19161 * The right angle bracket.
19162 */
19163 final Token rightBracket;
19164
19165 /**
19166 * Initialize a newly created list of type parameters.
19167 */
19168 TypeParameterList(
19169 this.leftBracket, List<TypeParameter> typeParameters, this.rightBracket) {
19170 _typeParameters = new NodeList<TypeParameter>(this, typeParameters);
19171 }
19172
19173 @override
19174 Token get beginToken => leftBracket;
19175
19176 @override
19177 Iterable get childEntities => new ChildEntities()
19178 ..add(leftBracket)
19179 ..addAll(_typeParameters)
19180 ..add(rightBracket);
19181
19182 @override
19183 Token get endToken => rightBracket;
19184
19185 /**
19186 * Return the type parameters for the type.
19187 */
19188 NodeList<TypeParameter> get typeParameters => _typeParameters;
19189
19190 @override
19191 accept(AstVisitor visitor) => visitor.visitTypeParameterList(this);
19192
19193 @override
19194 void visitChildren(AstVisitor visitor) {
19195 _typeParameters.accept(visitor);
19196 }
19197 }
19198
19199 /**
19200 * An AST visitor that will recursively visit all of the nodes in an AST
19201 * structure (like instances of the class [RecursiveAstVisitor]). In addition,
19202 * every node will also be visited by using a single unified [visitNode] method.
19203 *
19204 * Subclasses that override a visit method must either invoke the overridden
19205 * visit method or explicitly invoke the more general [visitNode] method.
19206 * Failure to do so will cause the children of the visited node to not be
19207 * visited.
19208 */
19209 class UnifyingAstVisitor<R> implements AstVisitor<R> {
19210 @override
19211 R visitAdjacentStrings(AdjacentStrings node) => visitNode(node);
19212
19213 @override
19214 R visitAnnotation(Annotation node) => visitNode(node);
19215
19216 @override
19217 R visitArgumentList(ArgumentList node) => visitNode(node);
19218
19219 @override
19220 R visitAsExpression(AsExpression node) => visitNode(node);
19221
19222 @override
19223 R visitAssertStatement(AssertStatement node) => visitNode(node);
19224
19225 @override
19226 R visitAssignmentExpression(AssignmentExpression node) => visitNode(node);
19227
19228 @override
19229 R visitAwaitExpression(AwaitExpression node) => visitNode(node);
19230
19231 @override
19232 R visitBinaryExpression(BinaryExpression node) => visitNode(node);
19233
19234 @override
19235 R visitBlock(Block node) => visitNode(node);
19236
19237 @override
19238 R visitBlockFunctionBody(BlockFunctionBody node) => visitNode(node);
19239
19240 @override
19241 R visitBooleanLiteral(BooleanLiteral node) => visitNode(node);
19242
19243 @override
19244 R visitBreakStatement(BreakStatement node) => visitNode(node);
19245
19246 @override
19247 R visitCascadeExpression(CascadeExpression node) => visitNode(node);
19248
19249 @override
19250 R visitCatchClause(CatchClause node) => visitNode(node);
19251
19252 @override
19253 R visitClassDeclaration(ClassDeclaration node) => visitNode(node);
19254
19255 @override
19256 R visitClassTypeAlias(ClassTypeAlias node) => visitNode(node);
19257
19258 @override
19259 R visitComment(Comment node) => visitNode(node);
19260
19261 @override
19262 R visitCommentReference(CommentReference node) => visitNode(node);
19263
19264 @override
19265 R visitCompilationUnit(CompilationUnit node) => visitNode(node);
19266
19267 @override
19268 R visitConditionalExpression(ConditionalExpression node) => visitNode(node);
19269
19270 @override
19271 R visitConstructorDeclaration(ConstructorDeclaration node) => visitNode(node);
19272
19273 @override
19274 R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
19275 visitNode(node);
19276
19277 @override
19278 R visitConstructorName(ConstructorName node) => visitNode(node);
19279
19280 @override
19281 R visitContinueStatement(ContinueStatement node) => visitNode(node);
19282
19283 @override
19284 R visitDeclaredIdentifier(DeclaredIdentifier node) => visitNode(node);
19285
19286 @override
19287 R visitDefaultFormalParameter(DefaultFormalParameter node) => visitNode(node);
19288
19289 @override
19290 R visitDoStatement(DoStatement node) => visitNode(node);
19291
19292 @override
19293 R visitDoubleLiteral(DoubleLiteral node) => visitNode(node);
19294
19295 @override
19296 R visitEmptyFunctionBody(EmptyFunctionBody node) => visitNode(node);
19297
19298 @override
19299 R visitEmptyStatement(EmptyStatement node) => visitNode(node);
19300
19301 @override
19302 R visitEnumConstantDeclaration(EnumConstantDeclaration node) =>
19303 visitNode(node);
19304
19305 @override
19306 R visitEnumDeclaration(EnumDeclaration node) => visitNode(node);
19307
19308 @override
19309 R visitExportDirective(ExportDirective node) => visitNode(node);
19310
19311 @override
19312 R visitExpressionFunctionBody(ExpressionFunctionBody node) => visitNode(node);
19313
19314 @override
19315 R visitExpressionStatement(ExpressionStatement node) => visitNode(node);
19316
19317 @override
19318 R visitExtendsClause(ExtendsClause node) => visitNode(node);
19319
19320 @override
19321 R visitFieldDeclaration(FieldDeclaration node) => visitNode(node);
19322
19323 @override
19324 R visitFieldFormalParameter(FieldFormalParameter node) => visitNode(node);
19325
19326 @override
19327 R visitForEachStatement(ForEachStatement node) => visitNode(node);
19328
19329 @override
19330 R visitFormalParameterList(FormalParameterList node) => visitNode(node);
19331
19332 @override
19333 R visitForStatement(ForStatement node) => visitNode(node);
19334
19335 @override
19336 R visitFunctionDeclaration(FunctionDeclaration node) => visitNode(node);
19337
19338 @override
19339 R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
19340 visitNode(node);
19341
19342 @override
19343 R visitFunctionExpression(FunctionExpression node) => visitNode(node);
19344
19345 @override
19346 R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
19347 visitNode(node);
19348
19349 @override
19350 R visitFunctionTypeAlias(FunctionTypeAlias node) => visitNode(node);
19351
19352 @override
19353 R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
19354 visitNode(node);
19355
19356 @override
19357 R visitHideCombinator(HideCombinator node) => visitNode(node);
19358
19359 @override
19360 R visitIfStatement(IfStatement node) => visitNode(node);
19361
19362 @override
19363 R visitImplementsClause(ImplementsClause node) => visitNode(node);
19364
19365 @override
19366 R visitImportDirective(ImportDirective node) => visitNode(node);
19367
19368 @override
19369 R visitIndexExpression(IndexExpression node) => visitNode(node);
19370
19371 @override
19372 R visitInstanceCreationExpression(InstanceCreationExpression node) =>
19373 visitNode(node);
19374
19375 @override
19376 R visitIntegerLiteral(IntegerLiteral node) => visitNode(node);
19377
19378 @override
19379 R visitInterpolationExpression(InterpolationExpression node) =>
19380 visitNode(node);
19381
19382 @override
19383 R visitInterpolationString(InterpolationString node) => visitNode(node);
19384
19385 @override
19386 R visitIsExpression(IsExpression node) => visitNode(node);
19387
19388 @override
19389 R visitLabel(Label node) => visitNode(node);
19390
19391 @override
19392 R visitLabeledStatement(LabeledStatement node) => visitNode(node);
19393
19394 @override
19395 R visitLibraryDirective(LibraryDirective node) => visitNode(node);
19396
19397 @override
19398 R visitLibraryIdentifier(LibraryIdentifier node) => visitNode(node);
19399
19400 @override
19401 R visitListLiteral(ListLiteral node) => visitNode(node);
19402
19403 @override
19404 R visitMapLiteral(MapLiteral node) => visitNode(node);
19405
19406 @override
19407 R visitMapLiteralEntry(MapLiteralEntry node) => visitNode(node);
19408
19409 @override
19410 R visitMethodDeclaration(MethodDeclaration node) => visitNode(node);
19411
19412 @override
19413 R visitMethodInvocation(MethodInvocation node) => visitNode(node);
19414
19415 @override
19416 R visitNamedExpression(NamedExpression node) => visitNode(node);
19417
19418 @override
19419 R visitNativeClause(NativeClause node) => visitNode(node);
19420
19421 @override
19422 R visitNativeFunctionBody(NativeFunctionBody node) => visitNode(node);
19423
19424 R visitNode(AstNode node) {
19425 node.visitChildren(this);
19426 return null;
19427 }
19428
19429 @override
19430 R visitNullLiteral(NullLiteral node) => visitNode(node);
19431
19432 @override
19433 R visitParenthesizedExpression(ParenthesizedExpression node) =>
19434 visitNode(node);
19435
19436 @override
19437 R visitPartDirective(PartDirective node) => visitNode(node);
19438
19439 @override
19440 R visitPartOfDirective(PartOfDirective node) => visitNode(node);
19441
19442 @override
19443 R visitPostfixExpression(PostfixExpression node) => visitNode(node);
19444
19445 @override
19446 R visitPrefixedIdentifier(PrefixedIdentifier node) => visitNode(node);
19447
19448 @override
19449 R visitPrefixExpression(PrefixExpression node) => visitNode(node);
19450
19451 @override
19452 R visitPropertyAccess(PropertyAccess node) => visitNode(node);
19453
19454 @override
19455 R visitRedirectingConstructorInvocation(
19456 RedirectingConstructorInvocation node) => visitNode(node);
19457
19458 @override
19459 R visitRethrowExpression(RethrowExpression node) => visitNode(node);
19460
19461 @override
19462 R visitReturnStatement(ReturnStatement node) => visitNode(node);
19463
19464 @override
19465 R visitScriptTag(ScriptTag scriptTag) => visitNode(scriptTag);
19466
19467 @override
19468 R visitShowCombinator(ShowCombinator node) => visitNode(node);
19469
19470 @override
19471 R visitSimpleFormalParameter(SimpleFormalParameter node) => visitNode(node);
19472
19473 @override
19474 R visitSimpleIdentifier(SimpleIdentifier node) => visitNode(node);
19475
19476 @override
19477 R visitSimpleStringLiteral(SimpleStringLiteral node) => visitNode(node);
19478
19479 @override
19480 R visitStringInterpolation(StringInterpolation node) => visitNode(node);
19481
19482 @override
19483 R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
19484 visitNode(node);
19485
19486 @override
19487 R visitSuperExpression(SuperExpression node) => visitNode(node);
19488
19489 @override
19490 R visitSwitchCase(SwitchCase node) => visitNode(node);
19491
19492 @override
19493 R visitSwitchDefault(SwitchDefault node) => visitNode(node);
19494
19495 @override
19496 R visitSwitchStatement(SwitchStatement node) => visitNode(node);
19497
19498 @override
19499 R visitSymbolLiteral(SymbolLiteral node) => visitNode(node);
19500
19501 @override
19502 R visitThisExpression(ThisExpression node) => visitNode(node);
19503
19504 @override
19505 R visitThrowExpression(ThrowExpression node) => visitNode(node);
19506
19507 @override
19508 R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
19509 visitNode(node);
19510
19511 @override
19512 R visitTryStatement(TryStatement node) => visitNode(node);
19513
19514 @override
19515 R visitTypeArgumentList(TypeArgumentList node) => visitNode(node);
19516
19517 @override
19518 R visitTypeName(TypeName node) => visitNode(node);
19519
19520 @override
19521 R visitTypeParameter(TypeParameter node) => visitNode(node);
19522
19523 @override
19524 R visitTypeParameterList(TypeParameterList node) => visitNode(node);
19525
19526 @override
19527 R visitVariableDeclaration(VariableDeclaration node) => visitNode(node);
19528
19529 @override
19530 R visitVariableDeclarationList(VariableDeclarationList node) =>
19531 visitNode(node);
19532
19533 @override
19534 R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
19535 visitNode(node);
19536
19537 @override
19538 R visitWhileStatement(WhileStatement node) => visitNode(node);
19539
19540 @override
19541 R visitWithClause(WithClause node) => visitNode(node);
19542
19543 @override
19544 R visitYieldStatement(YieldStatement node) => visitNode(node);
19545 }
19546
19547 /**
19548 * A directive that references a URI.
19549 *
19550 * > uriBasedDirective ::=
19551 * > [ExportDirective]
19552 * > | [ImportDirective]
19553 * > | [PartDirective]
19554 */
19555 abstract class UriBasedDirective extends Directive {
19556 /**
19557 * The prefix of a URI using the `dart-ext` scheme to reference a native code
19558 * library.
19559 */
19560 static String _DART_EXT_SCHEME = "dart-ext:";
19561
19562 /**
19563 * The URI referenced by this directive.
19564 */
19565 StringLiteral _uri;
19566
19567 /**
19568 * The content of the URI.
19569 */
19570 String uriContent;
19571
19572 /**
19573 * The source to which the URI was resolved.
19574 */
19575 Source source;
19576
19577 /**
19578 * Initialize a newly create URI-based directive. Either or both of the
19579 * [comment] and [metadata] can be `null` if the directive does not have the
19580 * corresponding attribute.
19581 */
19582 UriBasedDirective(
19583 Comment comment, List<Annotation> metadata, StringLiteral uri)
19584 : super(comment, metadata) {
19585 _uri = _becomeParentOf(uri);
19586 }
19587
19588 /**
19589 * Return the URI referenced by this directive.
19590 */
19591 StringLiteral get uri => _uri;
19592
19593 /**
19594 * Set the URI referenced by this directive to the given [uri].
19595 */
19596 void set uri(StringLiteral uri) {
19597 _uri = _becomeParentOf(uri);
19598 }
19599
19600 /**
19601 * Return the element associated with the URI of this directive, or `null` if
19602 * the AST structure has not been resolved or if the URI could not be
19603 * resolved. Examples of the latter case include a directive that contains an
19604 * invalid URL or a URL that does not exist.
19605 */
19606 Element get uriElement;
19607
19608 /**
19609 * Validate this directive, but do not check for existence. Return a code
19610 * indicating the problem if there is one, or `null` no problem
19611 */
19612 UriValidationCode validate() {
19613 StringLiteral uriLiteral = uri;
19614 if (uriLiteral is StringInterpolation) {
19615 return UriValidationCode.URI_WITH_INTERPOLATION;
19616 }
19617 String uriContent = this.uriContent;
19618 if (uriContent == null) {
19619 return UriValidationCode.INVALID_URI;
19620 }
19621 if (this is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME)) {
19622 return UriValidationCode.URI_WITH_DART_EXT_SCHEME;
19623 }
19624 try {
19625 parseUriWithException(Uri.encodeFull(uriContent));
19626 } on URISyntaxException {
19627 return UriValidationCode.INVALID_URI;
19628 }
19629 return null;
19630 }
19631
19632 @override
19633 void visitChildren(AstVisitor visitor) {
19634 super.visitChildren(visitor);
19635 _safelyVisitChild(_uri, visitor);
19636 }
19637 }
19638
19639 /**
19640 * Validation codes returned by [UriBasedDirective.validate].
19641 */
19642 class UriValidationCode {
19643 static const UriValidationCode INVALID_URI =
19644 const UriValidationCode('INVALID_URI');
19645
19646 static const UriValidationCode URI_WITH_INTERPOLATION =
19647 const UriValidationCode('URI_WITH_INTERPOLATION');
19648
19649 static const UriValidationCode URI_WITH_DART_EXT_SCHEME =
19650 const UriValidationCode('URI_WITH_DART_EXT_SCHEME');
19651
19652 /**
19653 * The name of the validation code.
19654 */
19655 final String name;
19656
19657 /**
19658 * Initialize a newly created validation code to have the given [name].
19659 */
19660 const UriValidationCode(this.name);
19661
19662 @override
19663 String toString() => name;
19664 }
19665
19666 /**
19667 * An identifier that has an initial value associated with it. Instances of this
19668 * class are always children of the class [VariableDeclarationList].
19669 *
19670 * > variableDeclaration ::=
19671 * > [SimpleIdentifier] ('=' [Expression])?
19672 *
19673 * TODO(paulberry): the grammar does not allow metadata to be associated with
19674 * a VariableDeclaration, and currently we don't record comments for it either.
19675 * Consider changing the class hierarchy so that [VariableDeclaration] does not
19676 * extend [Declaration].
19677 */
19678 class VariableDeclaration extends Declaration {
19679 /**
19680 * The name of the variable being declared.
19681 */
19682 SimpleIdentifier _name;
19683
19684 /**
19685 * The equal sign separating the variable name from the initial value, or
19686 * `null` if the initial value was not specified.
19687 */
19688 Token equals;
19689
19690 /**
19691 * The expression used to compute the initial value for the variable, or
19692 * `null` if the initial value was not specified.
19693 */
19694 Expression _initializer;
19695
19696 /**
19697 * Initialize a newly created variable declaration. The [equals] and
19698 * [initializer] can be `null` if there is no initializer.
19699 */
19700 VariableDeclaration(
19701 SimpleIdentifier name, this.equals, Expression initializer)
19702 : super(null, null) {
19703 _name = _becomeParentOf(name);
19704 _initializer = _becomeParentOf(initializer);
19705 }
19706
19707 @override
19708 Iterable get childEntities =>
19709 super._childEntities..add(_name)..add(equals)..add(_initializer);
19710
19711 /**
19712 * This overridden implementation of getDocumentationComment() looks in the
19713 * grandparent node for dartdoc comments if no documentation is specifically
19714 * available on the node.
19715 */
19716 @override
19717 Comment get documentationComment {
19718 Comment comment = super.documentationComment;
19719 if (comment == null) {
19720 if (parent != null && parent.parent != null) {
19721 AstNode node = parent.parent;
19722 if (node is AnnotatedNode) {
19723 return node.documentationComment;
19724 }
19725 }
19726 }
19727 return comment;
19728 }
19729
19730 @override
19731 VariableElement get element =>
19732 _name != null ? (_name.staticElement as VariableElement) : null;
19733
19734 @override
19735 Token get endToken {
19736 if (_initializer != null) {
19737 return _initializer.endToken;
19738 }
19739 return _name.endToken;
19740 }
19741
19742 @override
19743 Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
19744
19745 /**
19746 * Return the expression used to compute the initial value for the variable,
19747 * or `null` if the initial value was not specified.
19748 */
19749 Expression get initializer => _initializer;
19750
19751 /**
19752 * Set the expression used to compute the initial value for the variable to
19753 * the given [expression].
19754 */
19755 void set initializer(Expression expression) {
19756 _initializer = _becomeParentOf(expression);
19757 }
19758
19759 /**
19760 * Return `true` if this variable was declared with the 'const' modifier.
19761 */
19762 bool get isConst {
19763 AstNode parent = this.parent;
19764 return parent is VariableDeclarationList && parent.isConst;
19765 }
19766
19767 /**
19768 * Return `true` if this variable was declared with the 'final' modifier.
19769 * Variables that are declared with the 'const' modifier will return `false`
19770 * even though they are implicitly final.
19771 */
19772 bool get isFinal {
19773 AstNode parent = this.parent;
19774 return parent is VariableDeclarationList && parent.isFinal;
19775 }
19776
19777 /**
19778 * Return the name of the variable being declared.
19779 */
19780 SimpleIdentifier get name => _name;
19781
19782 /**
19783 * Set the name of the variable being declared to the given [identifier].
19784 */
19785 void set name(SimpleIdentifier identifier) {
19786 _name = _becomeParentOf(identifier);
19787 }
19788
19789 @override
19790 accept(AstVisitor visitor) => visitor.visitVariableDeclaration(this);
19791
19792 @override
19793 void visitChildren(AstVisitor visitor) {
19794 super.visitChildren(visitor);
19795 _safelyVisitChild(_name, visitor);
19796 _safelyVisitChild(_initializer, visitor);
19797 }
19798 }
19799
19800 /**
19801 * The declaration of one or more variables of the same type.
19802 *
19803 * > variableDeclarationList ::=
19804 * > finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])*
19805 * >
19806 * > finalConstVarOrType ::=
19807 * > | 'final' [TypeName]?
19808 * > | 'const' [TypeName]?
19809 * > | 'var'
19810 * > | [TypeName]
19811 */
19812 class VariableDeclarationList extends AnnotatedNode {
19813 /**
19814 * The token representing the 'final', 'const' or 'var' keyword, or `null` if
19815 * no keyword was included.
19816 */
19817 Token keyword;
19818
19819 /**
19820 * The type of the variables being declared, or `null` if no type was provided .
19821 */
19822 TypeName _type;
19823
19824 /**
19825 * A list containing the individual variables being declared.
19826 */
19827 NodeList<VariableDeclaration> _variables;
19828
19829 /**
19830 * Initialize a newly created variable declaration list. Either or both of the
19831 * [comment] and [metadata] can be `null` if the variable list does not have
19832 * the corresponding attribute. The [keyword] can be `null` if a type was
19833 * specified. The [type] must be `null` if the keyword is 'var'.
19834 */
19835 VariableDeclarationList(Comment comment, List<Annotation> metadata,
19836 this.keyword, TypeName type, List<VariableDeclaration> variables)
19837 : super(comment, metadata) {
19838 _type = _becomeParentOf(type);
19839 _variables = new NodeList<VariableDeclaration>(this, variables);
19840 }
19841
19842 /**
19843 * TODO(paulberry): include commas.
19844 */
19845 @override
19846 Iterable get childEntities => super._childEntities
19847 ..add(keyword)
19848 ..add(_type)
19849 ..addAll(_variables);
19850
19851 @override
19852 Token get endToken => _variables.endToken;
19853
19854 @override
19855 Token get firstTokenAfterCommentAndMetadata {
19856 if (keyword != null) {
19857 return keyword;
19858 } else if (_type != null) {
19859 return _type.beginToken;
19860 }
19861 return _variables.beginToken;
19862 }
19863
19864 /**
19865 * Return `true` if the variables in this list were declared with the 'const'
19866 * modifier.
19867 */
19868 bool get isConst => keyword is KeywordToken &&
19869 (keyword as KeywordToken).keyword == Keyword.CONST;
19870
19871 /**
19872 * Return `true` if the variables in this list were declared with the 'final'
19873 * modifier. Variables that are declared with the 'const' modifier will return
19874 * `false` even though they are implicitly final. (In other words, this is a
19875 * syntactic check rather than a semantic check.)
19876 */
19877 bool get isFinal => keyword is KeywordToken &&
19878 (keyword as KeywordToken).keyword == Keyword.FINAL;
19879
19880 /**
19881 * Return the type of the variables being declared, or `null` if no type was
19882 * provided.
19883 */
19884 TypeName get type => _type;
19885
19886 /**
19887 * Set the type of the variables being declared to the given [typeName].
19888 */
19889 void set type(TypeName typeName) {
19890 _type = _becomeParentOf(typeName);
19891 }
19892
19893 /**
19894 * Return a list containing the individual variables being declared.
19895 */
19896 NodeList<VariableDeclaration> get variables => _variables;
19897
19898 @override
19899 accept(AstVisitor visitor) => visitor.visitVariableDeclarationList(this);
19900
19901 @override
19902 void visitChildren(AstVisitor visitor) {
19903 super.visitChildren(visitor);
19904 _safelyVisitChild(_type, visitor);
19905 _variables.accept(visitor);
19906 }
19907 }
19908
19909 /**
19910 * A list of variables that are being declared in a context where a statement is
19911 * required.
19912 *
19913 * > variableDeclarationStatement ::=
19914 * > [VariableDeclarationList] ';'
19915 */
19916 class VariableDeclarationStatement extends Statement {
19917 /**
19918 * The variables being declared.
19919 */
19920 VariableDeclarationList _variableList;
19921
19922 /**
19923 * The semicolon terminating the statement.
19924 */
19925 Token semicolon;
19926
19927 /**
19928 * Initialize a newly created variable declaration statement.
19929 */
19930 VariableDeclarationStatement(
19931 VariableDeclarationList variableList, this.semicolon) {
19932 _variableList = _becomeParentOf(variableList);
19933 }
19934
19935 @override
19936 Token get beginToken => _variableList.beginToken;
19937
19938 @override
19939 Iterable get childEntities =>
19940 new ChildEntities()..add(_variableList)..add(semicolon);
19941
19942 @override
19943 Token get endToken => semicolon;
19944
19945 /**
19946 * Return the variables being declared.
19947 */
19948 VariableDeclarationList get variables => _variableList;
19949
19950 /**
19951 * Set the variables being declared to the given list of [variables].
19952 */
19953 void set variables(VariableDeclarationList variables) {
19954 _variableList = _becomeParentOf(variables);
19955 }
19956
19957 @override
19958 accept(AstVisitor visitor) => visitor.visitVariableDeclarationStatement(this);
19959
19960 @override
19961 void visitChildren(AstVisitor visitor) {
19962 _safelyVisitChild(_variableList, visitor);
19963 }
19964 }
19965
19966 /**
19967 * A while statement.
19968 *
19969 * > whileStatement ::=
19970 * > 'while' '(' [Expression] ')' [Statement]
19971 */
19972 class WhileStatement extends Statement {
19973 /**
19974 * The token representing the 'while' keyword.
19975 */
19976 Token whileKeyword;
19977
19978 /**
19979 * The left parenthesis.
19980 */
19981 Token leftParenthesis;
19982
19983 /**
19984 * The expression used to determine whether to execute the body of the loop.
19985 */
19986 Expression _condition;
19987
19988 /**
19989 * The right parenthesis.
19990 */
19991 Token rightParenthesis;
19992
19993 /**
19994 * The body of the loop.
19995 */
19996 Statement _body;
19997
19998 /**
19999 * Initialize a newly created while statement.
20000 */
20001 WhileStatement(this.whileKeyword, this.leftParenthesis, Expression condition,
20002 this.rightParenthesis, Statement body) {
20003 _condition = _becomeParentOf(condition);
20004 _body = _becomeParentOf(body);
20005 }
20006
20007 @override
20008 Token get beginToken => whileKeyword;
20009
20010 /**
20011 * Return the body of the loop.
20012 */
20013 Statement get body => _body;
20014
20015 /**
20016 * Set the body of the loop to the given [statement].
20017 */
20018 void set body(Statement statement) {
20019 _body = _becomeParentOf(statement);
20020 }
20021
20022 @override
20023 Iterable get childEntities => new ChildEntities()
20024 ..add(whileKeyword)
20025 ..add(leftParenthesis)
20026 ..add(_condition)
20027 ..add(rightParenthesis)
20028 ..add(_body);
20029
20030 /**
20031 * Return the expression used to determine whether to execute the body of the
20032 * loop.
20033 */
20034 Expression get condition => _condition;
20035
20036 /**
20037 * Set the expression used to determine whether to execute the body of the
20038 * loop to the given [expression].
20039 */
20040 void set condition(Expression expression) {
20041 _condition = _becomeParentOf(expression);
20042 }
20043
20044 @override
20045 Token get endToken => _body.endToken;
20046
20047 /**
20048 * Return the token representing the 'while' keyword.
20049 */
20050 @deprecated // Use "this.whileKeyword"
20051 Token get keyword => whileKeyword;
20052
20053 /**
20054 * Set the token representing the 'while' keyword to the given [token].
20055 */
20056 @deprecated // Use "this.whileKeyword"
20057 set keyword(Token token) {
20058 whileKeyword = token;
20059 }
20060
20061 @override
20062 accept(AstVisitor visitor) => visitor.visitWhileStatement(this);
20063
20064 @override
20065 void visitChildren(AstVisitor visitor) {
20066 _safelyVisitChild(_condition, visitor);
20067 _safelyVisitChild(_body, visitor);
20068 }
20069 }
20070
20071 /**
20072 * The with clause in a class declaration.
20073 *
20074 * > withClause ::=
20075 * > 'with' [TypeName] (',' [TypeName])*
20076 */
20077 class WithClause extends AstNode {
20078 /**
20079 * The token representing the 'with' keyword.
20080 */
20081 Token withKeyword;
20082
20083 /**
20084 * The names of the mixins that were specified.
20085 */
20086 NodeList<TypeName> _mixinTypes;
20087
20088 /**
20089 * Initialize a newly created with clause.
20090 */
20091 WithClause(this.withKeyword, List<TypeName> mixinTypes) {
20092 _mixinTypes = new NodeList<TypeName>(this, mixinTypes);
20093 }
20094
20095 @override
20096 Token get beginToken => withKeyword;
20097
20098 /**
20099 * TODO(paulberry): add commas.
20100 */
20101 @override
20102 Iterable get childEntities => new ChildEntities()
20103 ..add(withKeyword)
20104 ..addAll(_mixinTypes);
20105
20106 @override
20107 Token get endToken => _mixinTypes.endToken;
20108
20109 /**
20110 * Set the token representing the 'with' keyword to the given [token].
20111 */
20112 @deprecated // Use "this.withKeyword"
20113 void set mixinKeyword(Token token) {
20114 this.withKeyword = token;
20115 }
20116
20117 /**
20118 * Return the names of the mixins that were specified.
20119 */
20120 NodeList<TypeName> get mixinTypes => _mixinTypes;
20121
20122 @override
20123 accept(AstVisitor visitor) => visitor.visitWithClause(this);
20124
20125 @override
20126 void visitChildren(AstVisitor visitor) {
20127 _mixinTypes.accept(visitor);
20128 }
20129 }
20130
20131 /**
20132 * A yield statement.
20133 *
20134 * > yieldStatement ::=
20135 * > 'yield' '*'? [Expression] ‘;’
20136 */
20137 class YieldStatement extends Statement {
20138 /**
20139 * The 'yield' keyword.
20140 */
20141 Token yieldKeyword;
20142
20143 /**
20144 * The star optionally following the 'yield' keyword.
20145 */
20146 Token star;
20147
20148 /**
20149 * The expression whose value will be yielded.
20150 */
20151 Expression _expression;
20152
20153 /**
20154 * The semicolon following the expression.
20155 */
20156 Token semicolon;
20157
20158 /**
20159 * Initialize a newly created yield expression. The [star] can be `null` if no
20160 * star was provided.
20161 */
20162 YieldStatement(
20163 this.yieldKeyword, this.star, Expression expression, this.semicolon) {
20164 _expression = _becomeParentOf(expression);
20165 }
20166
20167 @override
20168 Token get beginToken {
20169 if (yieldKeyword != null) {
20170 return yieldKeyword;
20171 }
20172 return _expression.beginToken;
20173 }
20174
20175 @override
20176 Iterable get childEntities => new ChildEntities()
20177 ..add(yieldKeyword)
20178 ..add(star)
20179 ..add(_expression)
20180 ..add(semicolon);
20181
20182 @override
20183 Token get endToken {
20184 if (semicolon != null) {
20185 return semicolon;
20186 }
20187 return _expression.endToken;
20188 }
20189
20190 /**
20191 * Return the expression whose value will be yielded.
20192 */
20193 Expression get expression => _expression;
20194
20195 /**
20196 * Set the expression whose value will be yielded to the given [expression].
20197 */
20198 void set expression(Expression expression) {
20199 _expression = _becomeParentOf(expression);
20200 }
20201
20202 @override
20203 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20204
20205 @override
20206 void visitChildren(AstVisitor visitor) {
20207 _safelyVisitChild(_expression, visitor);
20208 }
20209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698