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

Side by Side Diff: packages/analyzer/test/generated/ast_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_test;
6
7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/java_core.dart';
9 import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
10 import 'package:analyzer/src/generated/java_engine.dart';
11 import 'package:analyzer/src/generated/scanner.dart';
12 import 'package:analyzer/src/generated/testing/ast_factory.dart';
13 import 'package:analyzer/src/generated/testing/token_factory.dart';
14 import 'package:unittest/unittest.dart';
15
16 import '../reflective_tests.dart';
17 import '../utils.dart';
18 import 'parser_test.dart' show ParserTestCase;
19 import 'test_support.dart';
20
21 main() {
22 initializeTestEnvironment();
23 runReflectiveTests(BreadthFirstVisitorTest);
24 runReflectiveTests(ClassDeclarationTest);
25 runReflectiveTests(ClassTypeAliasTest);
26 runReflectiveTests(ConstantEvaluatorTest);
27 runReflectiveTests(ConstructorDeclarationTest);
28 runReflectiveTests(FieldFormalParameterTest);
29 runReflectiveTests(IndexExpressionTest);
30 runReflectiveTests(NodeListTest);
31 runReflectiveTests(NodeLocatorTest);
32 runReflectiveTests(SimpleIdentifierTest);
33 runReflectiveTests(SimpleStringLiteralTest);
34 runReflectiveTests(StringInterpolationTest);
35 runReflectiveTests(ToSourceVisitorTest);
36 runReflectiveTests(VariableDeclarationTest);
37 }
38
39 class AssignmentKind extends Enum<AssignmentKind> {
40 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
41
42 static const AssignmentKind COMPOUND_LEFT =
43 const AssignmentKind('COMPOUND_LEFT', 1);
44
45 static const AssignmentKind COMPOUND_RIGHT =
46 const AssignmentKind('COMPOUND_RIGHT', 2);
47
48 static const AssignmentKind POSTFIX_INC =
49 const AssignmentKind('POSTFIX_INC', 3);
50
51 static const AssignmentKind PREFIX_DEC =
52 const AssignmentKind('PREFIX_DEC', 4);
53
54 static const AssignmentKind PREFIX_INC =
55 const AssignmentKind('PREFIX_INC', 5);
56
57 static const AssignmentKind PREFIX_NOT =
58 const AssignmentKind('PREFIX_NOT', 6);
59
60 static const AssignmentKind SIMPLE_LEFT =
61 const AssignmentKind('SIMPLE_LEFT', 7);
62
63 static const AssignmentKind SIMPLE_RIGHT =
64 const AssignmentKind('SIMPLE_RIGHT', 8);
65
66 static const AssignmentKind NONE = const AssignmentKind('NONE', 9);
67
68 static const List<AssignmentKind> values = const [
69 BINARY,
70 COMPOUND_LEFT,
71 COMPOUND_RIGHT,
72 POSTFIX_INC,
73 PREFIX_DEC,
74 PREFIX_INC,
75 PREFIX_NOT,
76 SIMPLE_LEFT,
77 SIMPLE_RIGHT,
78 NONE
79 ];
80
81 const AssignmentKind(String name, int ordinal) : super(name, ordinal);
82 }
83
84 class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt
85 extends BreadthFirstVisitor<Object> {
86 List<AstNode> nodes;
87
88 BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
89
90 @override
91 Object visitNode(AstNode node) {
92 nodes.add(node);
93 return super.visitNode(node);
94 }
95 }
96
97 @reflectiveTest
98 class BreadthFirstVisitorTest extends ParserTestCase {
99 void test_it() {
100 String source = r'''
101 class A {
102 bool get g => true;
103 }
104 class B {
105 int f() {
106 num q() {
107 return 3;
108 }
109 return q() + 4;
110 }
111 }
112 A f(var p) {
113 if ((p as A).g) {
114 return p;
115 } else {
116 return null;
117 }
118 }''';
119 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source);
120 List<AstNode> nodes = new List<AstNode>();
121 BreadthFirstVisitor<Object> visitor =
122 new BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(nodes);
123 visitor.visitAllNodes(unit);
124 expect(nodes, hasLength(59));
125 EngineTestCase.assertInstanceOf(
126 (obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
127 EngineTestCase.assertInstanceOf(
128 (obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
129 EngineTestCase.assertInstanceOf(
130 (obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
131 EngineTestCase.assertInstanceOf(
132 (obj) => obj is FunctionDeclarationStatement,
133 FunctionDeclarationStatement,
134 nodes[27]);
135 EngineTestCase.assertInstanceOf(
136 (obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
137 //3
138 }
139 }
140
141 @reflectiveTest
142 class ClassDeclarationTest extends ParserTestCase {
143 void test_getConstructor() {
144 List<ConstructorInitializer> initializers =
145 new List<ConstructorInitializer>();
146 ConstructorDeclaration defaultConstructor = AstFactory
147 .constructorDeclaration(AstFactory.identifier3("Test"), null,
148 AstFactory.formalParameterList(), initializers);
149 ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(
150 AstFactory.identifier3("Test"),
151 "a",
152 AstFactory.formalParameterList(),
153 initializers);
154 ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(
155 AstFactory.identifier3("Test"),
156 "b",
157 AstFactory.formalParameterList(),
158 initializers);
159 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null,
160 null, null, null, [defaultConstructor, aConstructor, bConstructor]);
161 expect(clazz.getConstructor(null), same(defaultConstructor));
162 expect(clazz.getConstructor("a"), same(aConstructor));
163 expect(clazz.getConstructor("b"), same(bConstructor));
164 expect(clazz.getConstructor("noSuchConstructor"), same(null));
165 }
166
167 void test_getField() {
168 VariableDeclaration aVar = AstFactory.variableDeclaration("a");
169 VariableDeclaration bVar = AstFactory.variableDeclaration("b");
170 VariableDeclaration cVar = AstFactory.variableDeclaration("c");
171 ClassDeclaration clazz =
172 AstFactory.classDeclaration(null, "Test", null, null, null, null, [
173 AstFactory.fieldDeclaration2(false, null, [aVar]),
174 AstFactory.fieldDeclaration2(false, null, [bVar, cVar])
175 ]);
176 expect(clazz.getField("a"), same(aVar));
177 expect(clazz.getField("b"), same(bVar));
178 expect(clazz.getField("c"), same(cVar));
179 expect(clazz.getField("noSuchField"), same(null));
180 }
181
182 void test_getMethod() {
183 MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null,
184 null, AstFactory.identifier3("a"), AstFactory.formalParameterList());
185 MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null,
186 null, AstFactory.identifier3("b"), AstFactory.formalParameterList());
187 ClassDeclaration clazz = AstFactory.classDeclaration(
188 null, "Test", null, null, null, null, [aMethod, bMethod]);
189 expect(clazz.getMethod("a"), same(aMethod));
190 expect(clazz.getMethod("b"), same(bMethod));
191 expect(clazz.getMethod("noSuchMethod"), same(null));
192 }
193
194 void test_isAbstract() {
195 expect(
196 AstFactory
197 .classDeclaration(null, "A", null, null, null, null)
198 .isAbstract,
199 isFalse);
200 expect(
201 AstFactory
202 .classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null)
203 .isAbstract,
204 isTrue);
205 }
206 }
207
208 @reflectiveTest
209 class ClassTypeAliasTest extends ParserTestCase {
210 void test_isAbstract() {
211 expect(
212 AstFactory.classTypeAlias("A", null, null, null, null, null).isAbstract,
213 isFalse);
214 expect(
215 AstFactory
216 .classTypeAlias("B", null, Keyword.ABSTRACT, null, null, null)
217 .isAbstract,
218 isTrue);
219 }
220 }
221
222 @reflectiveTest
223 class ConstantEvaluatorTest extends ParserTestCase {
224 void fail_constructor() {
225 Object value = _getConstantValue("?");
226 expect(value, null);
227 }
228
229 void fail_identifier_class() {
230 Object value = _getConstantValue("?");
231 expect(value, null);
232 }
233
234 void fail_identifier_function() {
235 Object value = _getConstantValue("?");
236 expect(value, null);
237 }
238
239 void fail_identifier_static() {
240 Object value = _getConstantValue("?");
241 expect(value, null);
242 }
243
244 void fail_identifier_staticMethod() {
245 Object value = _getConstantValue("?");
246 expect(value, null);
247 }
248
249 void fail_identifier_topLevel() {
250 Object value = _getConstantValue("?");
251 expect(value, null);
252 }
253
254 void fail_identifier_typeParameter() {
255 Object value = _getConstantValue("?");
256 expect(value, null);
257 }
258
259 void test_binary_bitAnd() {
260 Object value = _getConstantValue("74 & 42");
261 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
262 expect(value as int, 74 & 42);
263 }
264
265 void test_binary_bitOr() {
266 Object value = _getConstantValue("74 | 42");
267 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
268 expect(value as int, 74 | 42);
269 }
270
271 void test_binary_bitXor() {
272 Object value = _getConstantValue("74 ^ 42");
273 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
274 expect(value as int, 74 ^ 42);
275 }
276
277 void test_binary_divide_double() {
278 Object value = _getConstantValue("3.2 / 2.3");
279 expect(value, 3.2 / 2.3);
280 }
281
282 void test_binary_divide_integer() {
283 Object value = _getConstantValue("3 / 2");
284 expect(value, 1.5);
285 }
286
287 void test_binary_equal_boolean() {
288 Object value = _getConstantValue("true == false");
289 expect(value, false);
290 }
291
292 void test_binary_equal_integer() {
293 Object value = _getConstantValue("2 == 3");
294 expect(value, false);
295 }
296
297 void test_binary_equal_invalidLeft() {
298 Object value = _getConstantValue("a == 3");
299 expect(value, ConstantEvaluator.NOT_A_CONSTANT);
300 }
301
302 void test_binary_equal_invalidRight() {
303 Object value = _getConstantValue("2 == a");
304 expect(value, ConstantEvaluator.NOT_A_CONSTANT);
305 }
306
307 void test_binary_equal_string() {
308 Object value = _getConstantValue("'a' == 'b'");
309 expect(value, false);
310 }
311
312 void test_binary_greaterThan() {
313 Object value = _getConstantValue("2 > 3");
314 expect(value, false);
315 }
316
317 void test_binary_greaterThanOrEqual() {
318 Object value = _getConstantValue("2 >= 3");
319 expect(value, false);
320 }
321
322 void test_binary_leftShift() {
323 Object value = _getConstantValue("16 << 2");
324 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
325 expect(value as int, 64);
326 }
327
328 void test_binary_lessThan() {
329 Object value = _getConstantValue("2 < 3");
330 expect(value, true);
331 }
332
333 void test_binary_lessThanOrEqual() {
334 Object value = _getConstantValue("2 <= 3");
335 expect(value, true);
336 }
337
338 void test_binary_logicalAnd() {
339 Object value = _getConstantValue("true && false");
340 expect(value, false);
341 }
342
343 void test_binary_logicalOr() {
344 Object value = _getConstantValue("true || false");
345 expect(value, true);
346 }
347
348 void test_binary_minus_double() {
349 Object value = _getConstantValue("3.2 - 2.3");
350 expect(value, 3.2 - 2.3);
351 }
352
353 void test_binary_minus_integer() {
354 Object value = _getConstantValue("3 - 2");
355 expect(value, 1);
356 }
357
358 void test_binary_notEqual_boolean() {
359 Object value = _getConstantValue("true != false");
360 expect(value, true);
361 }
362
363 void test_binary_notEqual_integer() {
364 Object value = _getConstantValue("2 != 3");
365 expect(value, true);
366 }
367
368 void test_binary_notEqual_invalidLeft() {
369 Object value = _getConstantValue("a != 3");
370 expect(value, ConstantEvaluator.NOT_A_CONSTANT);
371 }
372
373 void test_binary_notEqual_invalidRight() {
374 Object value = _getConstantValue("2 != a");
375 expect(value, ConstantEvaluator.NOT_A_CONSTANT);
376 }
377
378 void test_binary_notEqual_string() {
379 Object value = _getConstantValue("'a' != 'b'");
380 expect(value, true);
381 }
382
383 void test_binary_plus_double() {
384 Object value = _getConstantValue("2.3 + 3.2");
385 expect(value, 2.3 + 3.2);
386 }
387
388 void test_binary_plus_integer() {
389 Object value = _getConstantValue("2 + 3");
390 expect(value, 5);
391 }
392
393 void test_binary_remainder_double() {
394 Object value = _getConstantValue("3.2 % 2.3");
395 expect(value, 3.2 % 2.3);
396 }
397
398 void test_binary_remainder_integer() {
399 Object value = _getConstantValue("8 % 3");
400 expect(value, 2);
401 }
402
403 void test_binary_rightShift() {
404 Object value = _getConstantValue("64 >> 2");
405 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
406 expect(value as int, 16);
407 }
408
409 void test_binary_times_double() {
410 Object value = _getConstantValue("2.3 * 3.2");
411 expect(value, 2.3 * 3.2);
412 }
413
414 void test_binary_times_integer() {
415 Object value = _getConstantValue("2 * 3");
416 expect(value, 6);
417 }
418
419 void test_binary_truncatingDivide_double() {
420 Object value = _getConstantValue("3.2 ~/ 2.3");
421 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
422 expect(value as int, 1);
423 }
424
425 void test_binary_truncatingDivide_integer() {
426 Object value = _getConstantValue("10 ~/ 3");
427 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
428 expect(value as int, 3);
429 }
430
431 void test_literal_boolean_false() {
432 Object value = _getConstantValue("false");
433 expect(value, false);
434 }
435
436 void test_literal_boolean_true() {
437 Object value = _getConstantValue("true");
438 expect(value, true);
439 }
440
441 void test_literal_list() {
442 Object value = _getConstantValue("['a', 'b', 'c']");
443 EngineTestCase.assertInstanceOf((obj) => obj is List, List, value);
444 List list = value as List;
445 expect(list.length, 3);
446 expect(list[0], "a");
447 expect(list[1], "b");
448 expect(list[2], "c");
449 }
450
451 void test_literal_map() {
452 Object value = _getConstantValue("{'a' : 'm', 'b' : 'n', 'c' : 'o'}");
453 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, value);
454 Map map = value as Map;
455 expect(map.length, 3);
456 expect(map["a"], "m");
457 expect(map["b"], "n");
458 expect(map["c"], "o");
459 }
460
461 void test_literal_null() {
462 Object value = _getConstantValue("null");
463 expect(value, null);
464 }
465
466 void test_literal_number_double() {
467 Object value = _getConstantValue("3.45");
468 expect(value, 3.45);
469 }
470
471 void test_literal_number_integer() {
472 Object value = _getConstantValue("42");
473 expect(value, 42);
474 }
475
476 void test_literal_string_adjacent() {
477 Object value = _getConstantValue("'abc' 'def'");
478 expect(value, "abcdef");
479 }
480
481 void test_literal_string_interpolation_invalid() {
482 Object value = _getConstantValue("'a\${f()}c'");
483 expect(value, ConstantEvaluator.NOT_A_CONSTANT);
484 }
485
486 void test_literal_string_interpolation_valid() {
487 Object value = _getConstantValue("'a\${3}c'");
488 expect(value, "a3c");
489 }
490
491 void test_literal_string_simple() {
492 Object value = _getConstantValue("'abc'");
493 expect(value, "abc");
494 }
495
496 void test_parenthesizedExpression() {
497 Object value = _getConstantValue("('a')");
498 expect(value, "a");
499 }
500
501 void test_unary_bitNot() {
502 Object value = _getConstantValue("~42");
503 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
504 expect(value as int, ~42);
505 }
506
507 void test_unary_logicalNot() {
508 Object value = _getConstantValue("!true");
509 expect(value, false);
510 }
511
512 void test_unary_negated_double() {
513 Object value = _getConstantValue("-42.3");
514 expect(value, -42.3);
515 }
516
517 void test_unary_negated_integer() {
518 Object value = _getConstantValue("-42");
519 expect(value, -42);
520 }
521
522 Object _getConstantValue(String source) =>
523 parseExpression(source).accept(new ConstantEvaluator());
524 }
525
526 @reflectiveTest
527 class ConstructorDeclarationTest extends EngineTestCase {
528 void test_firstTokenAfterCommentAndMetadata_all_inverted() {
529 Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
530 externalKeyword.offset = 14;
531 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
532 Keyword.CONST,
533 Keyword.FACTORY,
534 AstFactory.identifier3('int'),
535 null,
536 null,
537 null,
538 null);
539 declaration.externalKeyword = externalKeyword;
540 declaration.constKeyword.offset = 8;
541 Token factoryKeyword = declaration.factoryKeyword;
542 factoryKeyword.offset = 0;
543 expect(declaration.firstTokenAfterCommentAndMetadata, factoryKeyword);
544 }
545
546 void test_firstTokenAfterCommentAndMetadata_all_normal() {
547 Token token = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
548 token.offset = 0;
549 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
550 Keyword.CONST,
551 Keyword.FACTORY,
552 AstFactory.identifier3('int'),
553 null,
554 null,
555 null,
556 null);
557 declaration.externalKeyword = token;
558 declaration.constKeyword.offset = 9;
559 declaration.factoryKeyword.offset = 15;
560 expect(declaration.firstTokenAfterCommentAndMetadata, token);
561 }
562
563 void test_firstTokenAfterCommentAndMetadata_constOnly() {
564 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
565 Keyword.CONST,
566 null,
567 AstFactory.identifier3('int'),
568 null,
569 null,
570 null,
571 null);
572 expect(declaration.firstTokenAfterCommentAndMetadata,
573 declaration.constKeyword);
574 }
575
576 void test_firstTokenAfterCommentAndMetadata_externalOnly() {
577 Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
578 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
579 null, null, AstFactory.identifier3('int'), null, null, null, null);
580 declaration.externalKeyword = externalKeyword;
581 expect(declaration.firstTokenAfterCommentAndMetadata, externalKeyword);
582 }
583
584 void test_firstTokenAfterCommentAndMetadata_factoryOnly() {
585 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
586 null,
587 Keyword.FACTORY,
588 AstFactory.identifier3('int'),
589 null,
590 null,
591 null,
592 null);
593 expect(declaration.firstTokenAfterCommentAndMetadata,
594 declaration.factoryKeyword);
595 }
596 }
597
598 @reflectiveTest
599 class FieldFormalParameterTest extends EngineTestCase {
600 void test_endToken_noParameters() {
601 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('field');
602 expect(parameter.endToken, parameter.identifier.endToken);
603 }
604
605 void test_endToken_parameters() {
606 FieldFormalParameter parameter = AstFactory.fieldFormalParameter(
607 null, null, 'field', AstFactory.formalParameterList([]));
608 expect(parameter.endToken, parameter.parameters.endToken);
609 }
610 }
611
612 @reflectiveTest
613 class IndexExpressionTest extends EngineTestCase {
614 void test_inGetterContext_assignment_compound_left() {
615 IndexExpression expression = AstFactory.indexExpression(
616 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
617 // a[b] += c
618 AstFactory.assignmentExpression(
619 expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
620 expect(expression.inGetterContext(), isTrue);
621 }
622
623 void test_inGetterContext_assignment_simple_left() {
624 IndexExpression expression = AstFactory.indexExpression(
625 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
626 // a[b] = c
627 AstFactory.assignmentExpression(
628 expression, TokenType.EQ, AstFactory.identifier3("c"));
629 expect(expression.inGetterContext(), isFalse);
630 }
631
632 void test_inGetterContext_nonAssignment() {
633 IndexExpression expression = AstFactory.indexExpression(
634 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
635 // a[b] + c
636 AstFactory.binaryExpression(
637 expression, TokenType.PLUS, AstFactory.identifier3("c"));
638 expect(expression.inGetterContext(), isTrue);
639 }
640
641 void test_inSetterContext_assignment_compound_left() {
642 IndexExpression expression = AstFactory.indexExpression(
643 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
644 // a[b] += c
645 AstFactory.assignmentExpression(
646 expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
647 expect(expression.inSetterContext(), isTrue);
648 }
649
650 void test_inSetterContext_assignment_compound_right() {
651 IndexExpression expression = AstFactory.indexExpression(
652 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
653 // c += a[b]
654 AstFactory.assignmentExpression(
655 AstFactory.identifier3("c"), TokenType.PLUS_EQ, expression);
656 expect(expression.inSetterContext(), isFalse);
657 }
658
659 void test_inSetterContext_assignment_simple_left() {
660 IndexExpression expression = AstFactory.indexExpression(
661 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
662 // a[b] = c
663 AstFactory.assignmentExpression(
664 expression, TokenType.EQ, AstFactory.identifier3("c"));
665 expect(expression.inSetterContext(), isTrue);
666 }
667
668 void test_inSetterContext_assignment_simple_right() {
669 IndexExpression expression = AstFactory.indexExpression(
670 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
671 // c = a[b]
672 AstFactory.assignmentExpression(
673 AstFactory.identifier3("c"), TokenType.EQ, expression);
674 expect(expression.inSetterContext(), isFalse);
675 }
676
677 void test_inSetterContext_nonAssignment() {
678 IndexExpression expression = AstFactory.indexExpression(
679 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
680 AstFactory.binaryExpression(
681 expression, TokenType.PLUS, AstFactory.identifier3("c"));
682 // a[b] + cc
683 expect(expression.inSetterContext(), isFalse);
684 }
685
686 void test_inSetterContext_postfix() {
687 IndexExpression expression = AstFactory.indexExpression(
688 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
689 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
690 // a[b]++
691 expect(expression.inSetterContext(), isTrue);
692 }
693
694 void test_inSetterContext_prefix_bang() {
695 IndexExpression expression = AstFactory.indexExpression(
696 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
697 // !a[b]
698 AstFactory.prefixExpression(TokenType.BANG, expression);
699 expect(expression.inSetterContext(), isFalse);
700 }
701
702 void test_inSetterContext_prefix_minusMinus() {
703 IndexExpression expression = AstFactory.indexExpression(
704 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
705 // --a[b]
706 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
707 expect(expression.inSetterContext(), isTrue);
708 }
709
710 void test_inSetterContext_prefix_plusPlus() {
711 IndexExpression expression = AstFactory.indexExpression(
712 AstFactory.identifier3("a"), AstFactory.identifier3("b"));
713 // ++a[b]
714 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
715 expect(expression.inSetterContext(), isTrue);
716 }
717 }
718
719 @reflectiveTest
720 class NodeListTest extends EngineTestCase {
721 void test_add() {
722 AstNode parent = AstFactory.argumentList();
723 AstNode firstNode = AstFactory.booleanLiteral(true);
724 AstNode secondNode = AstFactory.booleanLiteral(false);
725 NodeList<AstNode> list = new NodeList<AstNode>(parent);
726 list.insert(0, secondNode);
727 list.insert(0, firstNode);
728 expect(list, hasLength(2));
729 expect(list[0], same(firstNode));
730 expect(list[1], same(secondNode));
731 expect(firstNode.parent, same(parent));
732 expect(secondNode.parent, same(parent));
733 AstNode thirdNode = AstFactory.booleanLiteral(false);
734 list.insert(1, thirdNode);
735 expect(list, hasLength(3));
736 expect(list[0], same(firstNode));
737 expect(list[1], same(thirdNode));
738 expect(list[2], same(secondNode));
739 expect(firstNode.parent, same(parent));
740 expect(secondNode.parent, same(parent));
741 expect(thirdNode.parent, same(parent));
742 }
743
744 void test_add_negative() {
745 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
746 try {
747 list.insert(-1, AstFactory.booleanLiteral(true));
748 fail("Expected IndexOutOfBoundsException");
749 } on RangeError {
750 // Expected
751 }
752 }
753
754 void test_add_tooBig() {
755 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
756 try {
757 list.insert(1, AstFactory.booleanLiteral(true));
758 fail("Expected IndexOutOfBoundsException");
759 } on RangeError {
760 // Expected
761 }
762 }
763
764 void test_addAll() {
765 AstNode parent = AstFactory.argumentList();
766 List<AstNode> firstNodes = new List<AstNode>();
767 AstNode firstNode = AstFactory.booleanLiteral(true);
768 AstNode secondNode = AstFactory.booleanLiteral(false);
769 firstNodes.add(firstNode);
770 firstNodes.add(secondNode);
771 NodeList<AstNode> list = new NodeList<AstNode>(parent);
772 list.addAll(firstNodes);
773 expect(list, hasLength(2));
774 expect(list[0], same(firstNode));
775 expect(list[1], same(secondNode));
776 expect(firstNode.parent, same(parent));
777 expect(secondNode.parent, same(parent));
778 List<AstNode> secondNodes = new List<AstNode>();
779 AstNode thirdNode = AstFactory.booleanLiteral(true);
780 AstNode fourthNode = AstFactory.booleanLiteral(false);
781 secondNodes.add(thirdNode);
782 secondNodes.add(fourthNode);
783 list.addAll(secondNodes);
784 expect(list, hasLength(4));
785 expect(list[0], same(firstNode));
786 expect(list[1], same(secondNode));
787 expect(list[2], same(thirdNode));
788 expect(list[3], same(fourthNode));
789 expect(firstNode.parent, same(parent));
790 expect(secondNode.parent, same(parent));
791 expect(thirdNode.parent, same(parent));
792 expect(fourthNode.parent, same(parent));
793 }
794
795 void test_creation() {
796 AstNode owner = AstFactory.argumentList();
797 NodeList<AstNode> list = new NodeList<AstNode>(owner);
798 expect(list, isNotNull);
799 expect(list, hasLength(0));
800 expect(list.owner, same(owner));
801 }
802
803 void test_get_negative() {
804 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
805 try {
806 list[-1];
807 fail("Expected IndexOutOfBoundsException");
808 } on RangeError {
809 // Expected
810 }
811 }
812
813 void test_get_tooBig() {
814 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
815 try {
816 list[1];
817 fail("Expected IndexOutOfBoundsException");
818 } on RangeError {
819 // Expected
820 }
821 }
822
823 void test_getBeginToken_empty() {
824 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
825 expect(list.beginToken, isNull);
826 }
827
828 void test_getBeginToken_nonEmpty() {
829 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
830 AstNode node =
831 AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
832 list.add(node);
833 expect(list.beginToken, same(node.beginToken));
834 }
835
836 void test_getEndToken_empty() {
837 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
838 expect(list.endToken, isNull);
839 }
840
841 void test_getEndToken_nonEmpty() {
842 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
843 AstNode node =
844 AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
845 list.add(node);
846 expect(list.endToken, same(node.endToken));
847 }
848
849 void test_indexOf() {
850 List<AstNode> nodes = new List<AstNode>();
851 AstNode firstNode = AstFactory.booleanLiteral(true);
852 AstNode secondNode = AstFactory.booleanLiteral(false);
853 AstNode thirdNode = AstFactory.booleanLiteral(true);
854 AstNode fourthNode = AstFactory.booleanLiteral(false);
855 nodes.add(firstNode);
856 nodes.add(secondNode);
857 nodes.add(thirdNode);
858 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
859 list.addAll(nodes);
860 expect(list, hasLength(3));
861 expect(list.indexOf(firstNode), 0);
862 expect(list.indexOf(secondNode), 1);
863 expect(list.indexOf(thirdNode), 2);
864 expect(list.indexOf(fourthNode), -1);
865 expect(list.indexOf(null), -1);
866 }
867
868 void test_remove() {
869 List<AstNode> nodes = new List<AstNode>();
870 AstNode firstNode = AstFactory.booleanLiteral(true);
871 AstNode secondNode = AstFactory.booleanLiteral(false);
872 AstNode thirdNode = AstFactory.booleanLiteral(true);
873 nodes.add(firstNode);
874 nodes.add(secondNode);
875 nodes.add(thirdNode);
876 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
877 list.addAll(nodes);
878 expect(list, hasLength(3));
879 expect(list.removeAt(1), same(secondNode));
880 expect(list, hasLength(2));
881 expect(list[0], same(firstNode));
882 expect(list[1], same(thirdNode));
883 }
884
885 void test_remove_negative() {
886 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
887 try {
888 list.removeAt(-1);
889 fail("Expected IndexOutOfBoundsException");
890 } on RangeError {
891 // Expected
892 }
893 }
894
895 void test_remove_tooBig() {
896 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
897 try {
898 list.removeAt(1);
899 fail("Expected IndexOutOfBoundsException");
900 } on RangeError {
901 // Expected
902 }
903 }
904
905 void test_set() {
906 List<AstNode> nodes = new List<AstNode>();
907 AstNode firstNode = AstFactory.booleanLiteral(true);
908 AstNode secondNode = AstFactory.booleanLiteral(false);
909 AstNode thirdNode = AstFactory.booleanLiteral(true);
910 nodes.add(firstNode);
911 nodes.add(secondNode);
912 nodes.add(thirdNode);
913 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
914 list.addAll(nodes);
915 expect(list, hasLength(3));
916 AstNode fourthNode = AstFactory.integer(0);
917 expect(javaListSet(list, 1, fourthNode), same(secondNode));
918 expect(list, hasLength(3));
919 expect(list[0], same(firstNode));
920 expect(list[1], same(fourthNode));
921 expect(list[2], same(thirdNode));
922 }
923
924 void test_set_negative() {
925 AstNode node = AstFactory.booleanLiteral(true);
926 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
927 try {
928 javaListSet(list, -1, node);
929 fail("Expected IndexOutOfBoundsException");
930 } on RangeError {
931 // Expected
932 }
933 }
934
935 void test_set_tooBig() {
936 AstNode node = AstFactory.booleanLiteral(true);
937 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
938 try {
939 javaListSet(list, 1, node);
940 fail("Expected IndexOutOfBoundsException");
941 } on RangeError {
942 // Expected
943 }
944 }
945 }
946
947 @reflectiveTest
948 class NodeLocatorTest extends ParserTestCase {
949 void test_range() {
950 CompilationUnit unit =
951 ParserTestCase.parseCompilationUnit("library myLib;");
952 _assertLocate(
953 unit, 4, 10, (node) => node is LibraryDirective, LibraryDirective);
954 }
955
956 void test_searchWithin_null() {
957 NodeLocator locator = new NodeLocator(0, 0);
958 expect(locator.searchWithin(null), isNull);
959 }
960
961 void test_searchWithin_offset() {
962 CompilationUnit unit =
963 ParserTestCase.parseCompilationUnit("library myLib;");
964 _assertLocate(
965 unit, 10, 10, (node) => node is SimpleIdentifier, SimpleIdentifier);
966 }
967
968 void test_searchWithin_offsetAfterNode() {
969 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
970 class A {}
971 class B {}''');
972 NodeLocator locator = new NodeLocator(1024, 1024);
973 AstNode node = locator.searchWithin(unit.declarations[0]);
974 expect(node, isNull);
975 }
976
977 void test_searchWithin_offsetBeforeNode() {
978 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
979 class A {}
980 class B {}''');
981 NodeLocator locator = new NodeLocator(0, 0);
982 AstNode node = locator.searchWithin(unit.declarations[1]);
983 expect(node, isNull);
984 }
985
986 void _assertLocate(CompilationUnit unit, int start, int end,
987 Predicate<AstNode> predicate, Type expectedClass) {
988 NodeLocator locator = new NodeLocator(start, end);
989 AstNode node = locator.searchWithin(unit);
990 expect(node, isNotNull);
991 expect(locator.foundNode, same(node));
992 expect(node.offset <= start, isTrue, reason: "Node starts after range");
993 expect(node.offset + node.length > end, isTrue,
994 reason: "Node ends before range");
995 EngineTestCase.assertInstanceOf(predicate, expectedClass, node);
996 }
997 }
998
999 @reflectiveTest
1000 class SimpleIdentifierTest extends ParserTestCase {
1001 void test_inDeclarationContext_catch_exception() {
1002 SimpleIdentifier identifier =
1003 AstFactory.catchClause("e").exceptionParameter;
1004 expect(identifier.inDeclarationContext(), isTrue);
1005 }
1006
1007 void test_inDeclarationContext_catch_stack() {
1008 SimpleIdentifier identifier =
1009 AstFactory.catchClause2("e", "s").stackTraceParameter;
1010 expect(identifier.inDeclarationContext(), isTrue);
1011 }
1012
1013 void test_inDeclarationContext_classDeclaration() {
1014 SimpleIdentifier identifier =
1015 AstFactory.classDeclaration(null, "C", null, null, null, null).name;
1016 expect(identifier.inDeclarationContext(), isTrue);
1017 }
1018
1019 void test_inDeclarationContext_classTypeAlias() {
1020 SimpleIdentifier identifier =
1021 AstFactory.classTypeAlias("C", null, null, null, null, null).name;
1022 expect(identifier.inDeclarationContext(), isTrue);
1023 }
1024
1025 void test_inDeclarationContext_constructorDeclaration() {
1026 SimpleIdentifier identifier = AstFactory
1027 .constructorDeclaration(AstFactory.identifier3("C"), "c", null, null)
1028 .name;
1029 expect(identifier.inDeclarationContext(), isTrue);
1030 }
1031
1032 void test_inDeclarationContext_declaredIdentifier() {
1033 DeclaredIdentifier declaredIdentifier = AstFactory.declaredIdentifier3("v");
1034 SimpleIdentifier identifier = declaredIdentifier.identifier;
1035 expect(identifier.inDeclarationContext(), isTrue);
1036 }
1037
1038 void test_inDeclarationContext_enumConstantDeclaration() {
1039 EnumDeclaration enumDeclaration =
1040 AstFactory.enumDeclaration2('MyEnum', ['CONST']);
1041 SimpleIdentifier identifier = enumDeclaration.constants[0].name;
1042 expect(identifier.inDeclarationContext(), isTrue);
1043 }
1044
1045 void test_inDeclarationContext_enumDeclaration() {
1046 EnumDeclaration enumDeclaration =
1047 AstFactory.enumDeclaration2('MyEnum', ['A', 'B', 'C']);
1048 SimpleIdentifier identifier = enumDeclaration.name;
1049 expect(identifier.inDeclarationContext(), isTrue);
1050 }
1051
1052 void test_inDeclarationContext_fieldFormalParameter() {
1053 SimpleIdentifier identifier =
1054 AstFactory.fieldFormalParameter2("p").identifier;
1055 expect(identifier.inDeclarationContext(), isFalse);
1056 }
1057
1058 void test_inDeclarationContext_functionDeclaration() {
1059 SimpleIdentifier identifier =
1060 AstFactory.functionDeclaration(null, null, "f", null).name;
1061 expect(identifier.inDeclarationContext(), isTrue);
1062 }
1063
1064 void test_inDeclarationContext_functionTypeAlias() {
1065 SimpleIdentifier identifier =
1066 AstFactory.typeAlias(null, "F", null, null).name;
1067 expect(identifier.inDeclarationContext(), isTrue);
1068 }
1069
1070 void test_inDeclarationContext_label_false() {
1071 SimpleIdentifier identifier =
1072 AstFactory.namedExpression2("l", AstFactory.integer(0)).name.label;
1073 expect(identifier.inDeclarationContext(), isFalse);
1074 }
1075
1076 void test_inDeclarationContext_label_true() {
1077 Label label = AstFactory.label2("l");
1078 SimpleIdentifier identifier = label.label;
1079 AstFactory.labeledStatement([label], AstFactory.emptyStatement());
1080 expect(identifier.inDeclarationContext(), isTrue);
1081 }
1082
1083 void test_inDeclarationContext_methodDeclaration() {
1084 SimpleIdentifier identifier = AstFactory.identifier3("m");
1085 AstFactory.methodDeclaration2(
1086 null, null, null, null, identifier, null, null);
1087 expect(identifier.inDeclarationContext(), isTrue);
1088 }
1089
1090 void test_inDeclarationContext_prefix() {
1091 SimpleIdentifier identifier =
1092 AstFactory.importDirective3("uri", "pref").prefix;
1093 expect(identifier.inDeclarationContext(), isTrue);
1094 }
1095
1096 void test_inDeclarationContext_simpleFormalParameter() {
1097 SimpleIdentifier identifier =
1098 AstFactory.simpleFormalParameter3("p").identifier;
1099 expect(identifier.inDeclarationContext(), isTrue);
1100 }
1101
1102 void test_inDeclarationContext_typeParameter_bound() {
1103 TypeName bound = AstFactory.typeName4("A");
1104 SimpleIdentifier identifier = bound.name as SimpleIdentifier;
1105 AstFactory.typeParameter2("E", bound);
1106 expect(identifier.inDeclarationContext(), isFalse);
1107 }
1108
1109 void test_inDeclarationContext_typeParameter_name() {
1110 SimpleIdentifier identifier = AstFactory.typeParameter("E").name;
1111 expect(identifier.inDeclarationContext(), isTrue);
1112 }
1113
1114 void test_inDeclarationContext_variableDeclaration() {
1115 SimpleIdentifier identifier = AstFactory.variableDeclaration("v").name;
1116 expect(identifier.inDeclarationContext(), isTrue);
1117 }
1118
1119 void test_inGetterContext() {
1120 for (WrapperKind wrapper in WrapperKind.values) {
1121 for (AssignmentKind assignment in AssignmentKind.values) {
1122 SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
1123 if (assignment == AssignmentKind.SIMPLE_LEFT &&
1124 wrapper != WrapperKind.PREFIXED_LEFT &&
1125 wrapper != WrapperKind.PROPERTY_LEFT) {
1126 if (identifier.inGetterContext()) {
1127 fail("Expected ${_topMostNode(identifier).toSource()} to be false");
1128 }
1129 } else {
1130 if (!identifier.inGetterContext()) {
1131 fail("Expected ${_topMostNode(identifier).toSource()} to be true");
1132 }
1133 }
1134 }
1135 }
1136 }
1137
1138 void test_inGetterContext_forEachLoop() {
1139 SimpleIdentifier identifier = AstFactory.identifier3("a");
1140 Expression iterator = AstFactory.listLiteral();
1141 Statement body = AstFactory.block();
1142 AstFactory.forEachStatement2(identifier, iterator, body);
1143 expect(identifier.inGetterContext(), isFalse);
1144 }
1145
1146 void test_inReferenceContext() {
1147 SimpleIdentifier identifier = AstFactory.identifier3("id");
1148 AstFactory.namedExpression(
1149 AstFactory.label(identifier), AstFactory.identifier3("_"));
1150 expect(identifier.inGetterContext(), isFalse);
1151 expect(identifier.inSetterContext(), isFalse);
1152 }
1153
1154 void test_inSetterContext() {
1155 for (WrapperKind wrapper in WrapperKind.values) {
1156 for (AssignmentKind assignment in AssignmentKind.values) {
1157 SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
1158 if (wrapper == WrapperKind.PREFIXED_LEFT ||
1159 wrapper == WrapperKind.PROPERTY_LEFT ||
1160 assignment == AssignmentKind.BINARY ||
1161 assignment == AssignmentKind.COMPOUND_RIGHT ||
1162 assignment == AssignmentKind.PREFIX_NOT ||
1163 assignment == AssignmentKind.SIMPLE_RIGHT ||
1164 assignment == AssignmentKind.NONE) {
1165 if (identifier.inSetterContext()) {
1166 fail("Expected ${_topMostNode(identifier).toSource()} to be false");
1167 }
1168 } else {
1169 if (!identifier.inSetterContext()) {
1170 fail("Expected ${_topMostNode(identifier).toSource()} to be true");
1171 }
1172 }
1173 }
1174 }
1175 }
1176
1177 void test_inSetterContext_forEachLoop() {
1178 SimpleIdentifier identifier = AstFactory.identifier3("a");
1179 Expression iterator = AstFactory.listLiteral();
1180 Statement body = AstFactory.block();
1181 AstFactory.forEachStatement2(identifier, iterator, body);
1182 expect(identifier.inSetterContext(), isTrue);
1183 }
1184
1185 void test_isQualified_inMethodInvocation_noTarget() {
1186 MethodInvocation invocation =
1187 AstFactory.methodInvocation2("test", [AstFactory.identifier3("arg0")]);
1188 SimpleIdentifier identifier = invocation.methodName;
1189 expect(identifier.isQualified, isFalse);
1190 }
1191
1192 void test_isQualified_inMethodInvocation_withTarget() {
1193 MethodInvocation invocation = AstFactory.methodInvocation(
1194 AstFactory.identifier3("target"),
1195 "test",
1196 [AstFactory.identifier3("arg0")]);
1197 SimpleIdentifier identifier = invocation.methodName;
1198 expect(identifier.isQualified, isTrue);
1199 }
1200
1201 void test_isQualified_inPrefixedIdentifier_name() {
1202 SimpleIdentifier identifier = AstFactory.identifier3("test");
1203 AstFactory.identifier4("prefix", identifier);
1204 expect(identifier.isQualified, isTrue);
1205 }
1206
1207 void test_isQualified_inPrefixedIdentifier_prefix() {
1208 SimpleIdentifier identifier = AstFactory.identifier3("test");
1209 AstFactory.identifier(identifier, AstFactory.identifier3("name"));
1210 expect(identifier.isQualified, isFalse);
1211 }
1212
1213 void test_isQualified_inPropertyAccess_name() {
1214 SimpleIdentifier identifier = AstFactory.identifier3("test");
1215 AstFactory.propertyAccess(AstFactory.identifier3("target"), identifier);
1216 expect(identifier.isQualified, isTrue);
1217 }
1218
1219 void test_isQualified_inPropertyAccess_target() {
1220 SimpleIdentifier identifier = AstFactory.identifier3("test");
1221 AstFactory.propertyAccess(identifier, AstFactory.identifier3("name"));
1222 expect(identifier.isQualified, isFalse);
1223 }
1224
1225 void test_isQualified_inReturnStatement() {
1226 SimpleIdentifier identifier = AstFactory.identifier3("test");
1227 AstFactory.returnStatement2(identifier);
1228 expect(identifier.isQualified, isFalse);
1229 }
1230
1231 SimpleIdentifier _createIdentifier(
1232 WrapperKind wrapper, AssignmentKind assignment) {
1233 SimpleIdentifier identifier = AstFactory.identifier3("a");
1234 Expression expression = identifier;
1235 while (true) {
1236 if (wrapper == WrapperKind.PREFIXED_LEFT) {
1237 expression =
1238 AstFactory.identifier(identifier, AstFactory.identifier3("_"));
1239 } else if (wrapper == WrapperKind.PREFIXED_RIGHT) {
1240 expression =
1241 AstFactory.identifier(AstFactory.identifier3("_"), identifier);
1242 } else if (wrapper == WrapperKind.PROPERTY_LEFT) {
1243 expression = AstFactory.propertyAccess2(expression, "_");
1244 } else if (wrapper == WrapperKind.PROPERTY_RIGHT) {
1245 expression =
1246 AstFactory.propertyAccess(AstFactory.identifier3("_"), identifier);
1247 } else if (wrapper == WrapperKind.NONE) {}
1248 break;
1249 }
1250 while (true) {
1251 if (assignment == AssignmentKind.BINARY) {
1252 AstFactory.binaryExpression(
1253 expression, TokenType.PLUS, AstFactory.identifier3("_"));
1254 } else if (assignment == AssignmentKind.COMPOUND_LEFT) {
1255 AstFactory.assignmentExpression(
1256 expression, TokenType.PLUS_EQ, AstFactory.identifier3("_"));
1257 } else if (assignment == AssignmentKind.COMPOUND_RIGHT) {
1258 AstFactory.assignmentExpression(
1259 AstFactory.identifier3("_"), TokenType.PLUS_EQ, expression);
1260 } else if (assignment == AssignmentKind.POSTFIX_INC) {
1261 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
1262 } else if (assignment == AssignmentKind.PREFIX_DEC) {
1263 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
1264 } else if (assignment == AssignmentKind.PREFIX_INC) {
1265 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
1266 } else if (assignment == AssignmentKind.PREFIX_NOT) {
1267 AstFactory.prefixExpression(TokenType.BANG, expression);
1268 } else if (assignment == AssignmentKind.SIMPLE_LEFT) {
1269 AstFactory.assignmentExpression(
1270 expression, TokenType.EQ, AstFactory.identifier3("_"));
1271 } else if (assignment == AssignmentKind.SIMPLE_RIGHT) {
1272 AstFactory.assignmentExpression(
1273 AstFactory.identifier3("_"), TokenType.EQ, expression);
1274 } else if (assignment == AssignmentKind.NONE) {}
1275 break;
1276 }
1277 return identifier;
1278 }
1279
1280 /**
1281 * Return the top-most node in the AST structure containing the given identifi er.
1282 *
1283 * @param identifier the identifier in the AST structure being traversed
1284 * @return the root of the AST structure containing the identifier
1285 */
1286 AstNode _topMostNode(SimpleIdentifier identifier) {
1287 AstNode child = identifier;
1288 AstNode parent = identifier.parent;
1289 while (parent != null) {
1290 child = parent;
1291 parent = parent.parent;
1292 }
1293 return child;
1294 }
1295 }
1296
1297 @reflectiveTest
1298 class SimpleStringLiteralTest extends ParserTestCase {
1299 void test_contentsEnd() {
1300 expect(
1301 new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
1302 .contentsEnd,
1303 2);
1304 expect(
1305 new SimpleStringLiteral(TokenFactory.tokenFromString('"X"'), "X")
1306 .contentsEnd,
1307 2);
1308
1309 expect(
1310 new SimpleStringLiteral(TokenFactory.tokenFromString('"""X"""'), "X")
1311 .contentsEnd,
1312 4);
1313 expect(
1314 new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
1315 .contentsEnd,
1316 4);
1317 expect(
1318 new SimpleStringLiteral(
1319 TokenFactory.tokenFromString("''' \nX'''"), "X").contentsEnd,
1320 7);
1321
1322 expect(
1323 new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
1324 .contentsEnd,
1325 3);
1326 expect(
1327 new SimpleStringLiteral(TokenFactory.tokenFromString('r"X"'), "X")
1328 .contentsEnd,
1329 3);
1330
1331 expect(
1332 new SimpleStringLiteral(TokenFactory.tokenFromString('r"""X"""'), "X")
1333 .contentsEnd,
1334 5);
1335 expect(
1336 new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
1337 .contentsEnd,
1338 5);
1339 expect(
1340 new SimpleStringLiteral(
1341 TokenFactory.tokenFromString("r''' \nX'''"), "X").contentsEnd,
1342 8);
1343 }
1344
1345 void test_contentsOffset() {
1346 expect(
1347 new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
1348 .contentsOffset,
1349 1);
1350 expect(
1351 new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
1352 .contentsOffset,
1353 1);
1354 expect(
1355 new SimpleStringLiteral(
1356 TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").contentsOffset,
1357 3);
1358 expect(
1359 new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
1360 .contentsOffset,
1361 3);
1362 expect(
1363 new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
1364 .contentsOffset,
1365 2);
1366 expect(
1367 new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
1368 .contentsOffset,
1369 2);
1370 expect(
1371 new SimpleStringLiteral(
1372 TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").contentsOffset,
1373 4);
1374 expect(
1375 new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
1376 .contentsOffset,
1377 4);
1378 // leading whitespace
1379 expect(
1380 new SimpleStringLiteral(
1381 TokenFactory.tokenFromString("''' \ \nX''"), "X").contentsOffset,
1382 6);
1383 expect(
1384 new SimpleStringLiteral(
1385 TokenFactory.tokenFromString('r""" \ \nX"""'), "X").contentsOffset,
1386 7);
1387 }
1388
1389 void test_isMultiline() {
1390 expect(
1391 new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
1392 .isMultiline,
1393 isFalse);
1394 expect(
1395 new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
1396 .isMultiline,
1397 isFalse);
1398 expect(
1399 new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
1400 .isMultiline,
1401 isFalse);
1402 expect(
1403 new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
1404 .isMultiline,
1405 isFalse);
1406 expect(
1407 new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
1408 .isMultiline,
1409 isTrue);
1410 expect(
1411 new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
1412 .isMultiline,
1413 isTrue);
1414 expect(
1415 new SimpleStringLiteral(
1416 TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").isMultiline,
1417 isTrue);
1418 expect(
1419 new SimpleStringLiteral(
1420 TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").isMultiline,
1421 isTrue);
1422 }
1423
1424 void test_isRaw() {
1425 expect(
1426 new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X").isRaw,
1427 isFalse);
1428 expect(
1429 new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
1430 .isRaw,
1431 isFalse);
1432 expect(
1433 new SimpleStringLiteral(
1434 TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").isRaw,
1435 isFalse);
1436 expect(
1437 new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
1438 .isRaw,
1439 isFalse);
1440 expect(
1441 new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
1442 .isRaw,
1443 isTrue);
1444 expect(
1445 new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
1446 .isRaw,
1447 isTrue);
1448 expect(
1449 new SimpleStringLiteral(
1450 TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").isRaw,
1451 isTrue);
1452 expect(
1453 new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
1454 .isRaw,
1455 isTrue);
1456 }
1457
1458 void test_isSingleQuoted() {
1459 // '
1460 {
1461 var token = TokenFactory.tokenFromString("'X'");
1462 var node = new SimpleStringLiteral(token, null);
1463 expect(node.isSingleQuoted, isTrue);
1464 }
1465 // '''
1466 {
1467 var token = TokenFactory.tokenFromString("'''X'''");
1468 var node = new SimpleStringLiteral(token, null);
1469 expect(node.isSingleQuoted, isTrue);
1470 }
1471 // "
1472 {
1473 var token = TokenFactory.tokenFromString('"X"');
1474 var node = new SimpleStringLiteral(token, null);
1475 expect(node.isSingleQuoted, isFalse);
1476 }
1477 // """
1478 {
1479 var token = TokenFactory.tokenFromString('"""X"""');
1480 var node = new SimpleStringLiteral(token, null);
1481 expect(node.isSingleQuoted, isFalse);
1482 }
1483 }
1484
1485 void test_isSingleQuoted_raw() {
1486 // r'
1487 {
1488 var token = TokenFactory.tokenFromString("r'X'");
1489 var node = new SimpleStringLiteral(token, null);
1490 expect(node.isSingleQuoted, isTrue);
1491 }
1492 // r'''
1493 {
1494 var token = TokenFactory.tokenFromString("r'''X'''");
1495 var node = new SimpleStringLiteral(token, null);
1496 expect(node.isSingleQuoted, isTrue);
1497 }
1498 // r"
1499 {
1500 var token = TokenFactory.tokenFromString('r"X"');
1501 var node = new SimpleStringLiteral(token, null);
1502 expect(node.isSingleQuoted, isFalse);
1503 }
1504 // r"""
1505 {
1506 var token = TokenFactory.tokenFromString('r"""X"""');
1507 var node = new SimpleStringLiteral(token, null);
1508 expect(node.isSingleQuoted, isFalse);
1509 }
1510 }
1511
1512 void test_simple() {
1513 Token token = TokenFactory.tokenFromString("'value'");
1514 SimpleStringLiteral stringLiteral = new SimpleStringLiteral(token, "value");
1515 expect(stringLiteral.literal, same(token));
1516 expect(stringLiteral.beginToken, same(token));
1517 expect(stringLiteral.endToken, same(token));
1518 expect(stringLiteral.value, "value");
1519 }
1520 }
1521
1522 @reflectiveTest
1523 class StringInterpolationTest extends ParserTestCase {
1524 void test_contentsOffsetEnd() {
1525 AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
1526 // 'a${bb}ccc'
1527 {
1528 var ae = AstFactory.interpolationString("'a", "a");
1529 var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
1530 var cElement = new InterpolationString(cToken, 'ccc');
1531 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1532 expect(node.contentsOffset, 1);
1533 expect(node.contentsEnd, 10 + 4 - 1);
1534 }
1535 // '''a${bb}ccc'''
1536 {
1537 var ae = AstFactory.interpolationString("'''a", "a");
1538 var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
1539 var cElement = new InterpolationString(cToken, 'ccc');
1540 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1541 expect(node.contentsOffset, 3);
1542 expect(node.contentsEnd, 10 + 4 - 1);
1543 }
1544 // """a${bb}ccc"""
1545 {
1546 var ae = AstFactory.interpolationString('"""a', "a");
1547 var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
1548 var cElement = new InterpolationString(cToken, 'ccc');
1549 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1550 expect(node.contentsOffset, 3);
1551 expect(node.contentsEnd, 10 + 4 - 1);
1552 }
1553 // r'a${bb}ccc'
1554 {
1555 var ae = AstFactory.interpolationString("r'a", "a");
1556 var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
1557 var cElement = new InterpolationString(cToken, 'ccc');
1558 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1559 expect(node.contentsOffset, 2);
1560 expect(node.contentsEnd, 10 + 4 - 1);
1561 }
1562 // r'''a${bb}ccc'''
1563 {
1564 var ae = AstFactory.interpolationString("r'''a", "a");
1565 var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
1566 var cElement = new InterpolationString(cToken, 'ccc');
1567 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1568 expect(node.contentsOffset, 4);
1569 expect(node.contentsEnd, 10 + 4 - 1);
1570 }
1571 // r"""a${bb}ccc"""
1572 {
1573 var ae = AstFactory.interpolationString('r"""a', "a");
1574 var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
1575 var cElement = new InterpolationString(cToken, 'ccc');
1576 StringInterpolation node = AstFactory.string([ae, ae, cElement]);
1577 expect(node.contentsOffset, 4);
1578 expect(node.contentsEnd, 10 + 4 - 1);
1579 }
1580 }
1581
1582 void test_isMultiline() {
1583 var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
1584 // '
1585 {
1586 var a = AstFactory.interpolationString("'a", "a");
1587 var c = AstFactory.interpolationString("ccc'", "ccc");
1588 StringInterpolation node = AstFactory.string([a, b, c]);
1589 expect(node.isMultiline, isFalse);
1590 }
1591 // '''
1592 {
1593 var a = AstFactory.interpolationString("'''a", "a");
1594 var c = AstFactory.interpolationString("ccc'''", "ccc");
1595 StringInterpolation node = AstFactory.string([a, b, c]);
1596 expect(node.isMultiline, isTrue);
1597 }
1598 // "
1599 {
1600 var a = AstFactory.interpolationString('"a', "a");
1601 var c = AstFactory.interpolationString('ccc"', "ccc");
1602 StringInterpolation node = AstFactory.string([a, b, c]);
1603 expect(node.isMultiline, isFalse);
1604 }
1605 // """
1606 {
1607 var a = AstFactory.interpolationString('"""a', "a");
1608 var c = AstFactory.interpolationString('ccc"""', "ccc");
1609 StringInterpolation node = AstFactory.string([a, b, c]);
1610 expect(node.isMultiline, isTrue);
1611 }
1612 }
1613
1614 void test_isRaw() {
1615 StringInterpolation node = AstFactory.string();
1616 expect(node.isRaw, isFalse);
1617 }
1618
1619 void test_isSingleQuoted() {
1620 var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
1621 // "
1622 {
1623 var a = AstFactory.interpolationString('"a', "a");
1624 var c = AstFactory.interpolationString('ccc"', "ccc");
1625 StringInterpolation node = AstFactory.string([a, b, c]);
1626 expect(node.isSingleQuoted, isFalse);
1627 }
1628 // """
1629 {
1630 var a = AstFactory.interpolationString('"""a', "a");
1631 var c = AstFactory.interpolationString('ccc"""', "ccc");
1632 StringInterpolation node = AstFactory.string([a, b, c]);
1633 expect(node.isSingleQuoted, isFalse);
1634 }
1635 // '
1636 {
1637 var a = AstFactory.interpolationString("'a", "a");
1638 var c = AstFactory.interpolationString("ccc'", "ccc");
1639 StringInterpolation node = AstFactory.string([a, b, c]);
1640 expect(node.isSingleQuoted, isTrue);
1641 }
1642 // '''
1643 {
1644 var a = AstFactory.interpolationString("'''a", "a");
1645 var c = AstFactory.interpolationString("ccc'''", "ccc");
1646 StringInterpolation node = AstFactory.string([a, b, c]);
1647 expect(node.isSingleQuoted, isTrue);
1648 }
1649 }
1650 }
1651
1652 @reflectiveTest
1653 class ToSourceVisitorTest extends EngineTestCase {
1654 void test_visitAdjacentStrings() {
1655 _assertSource(
1656 "'a' 'b'",
1657 AstFactory.adjacentStrings(
1658 [AstFactory.string2("a"), AstFactory.string2("b")]));
1659 }
1660
1661 void test_visitAnnotation_constant() {
1662 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A")));
1663 }
1664
1665 void test_visitAnnotation_constructor() {
1666 _assertSource(
1667 "@A.c()",
1668 AstFactory.annotation2(AstFactory.identifier3("A"),
1669 AstFactory.identifier3("c"), AstFactory.argumentList()));
1670 }
1671
1672 void test_visitArgumentList() {
1673 _assertSource(
1674 "(a, b)",
1675 AstFactory.argumentList(
1676 [AstFactory.identifier3("a"), AstFactory.identifier3("b")]));
1677 }
1678
1679 void test_visitAsExpression() {
1680 _assertSource(
1681 "e as T",
1682 AstFactory.asExpression(
1683 AstFactory.identifier3("e"), AstFactory.typeName4("T")));
1684 }
1685
1686 void test_visitAssertStatement() {
1687 _assertSource(
1688 "assert (a);", AstFactory.assertStatement(AstFactory.identifier3("a")));
1689 }
1690
1691 void test_visitAssignmentExpression() {
1692 _assertSource(
1693 "a = b",
1694 AstFactory.assignmentExpression(AstFactory.identifier3("a"),
1695 TokenType.EQ, AstFactory.identifier3("b")));
1696 }
1697
1698 void test_visitAwaitExpression() {
1699 _assertSource(
1700 "await e", AstFactory.awaitExpression(AstFactory.identifier3("e")));
1701 }
1702
1703 void test_visitBinaryExpression() {
1704 _assertSource(
1705 "a + b",
1706 AstFactory.binaryExpression(AstFactory.identifier3("a"), TokenType.PLUS,
1707 AstFactory.identifier3("b")));
1708 }
1709
1710 void test_visitBlock_empty() {
1711 _assertSource("{}", AstFactory.block());
1712 }
1713
1714 void test_visitBlock_nonEmpty() {
1715 _assertSource(
1716 "{break; break;}",
1717 AstFactory
1718 .block([AstFactory.breakStatement(), AstFactory.breakStatement()]));
1719 }
1720
1721 void test_visitBlockFunctionBody_async() {
1722 _assertSource("async {}", AstFactory.asyncBlockFunctionBody());
1723 }
1724
1725 void test_visitBlockFunctionBody_async_star() {
1726 _assertSource("async* {}", AstFactory.asyncGeneratorBlockFunctionBody());
1727 }
1728
1729 void test_visitBlockFunctionBody_simple() {
1730 _assertSource("{}", AstFactory.blockFunctionBody2());
1731 }
1732
1733 void test_visitBlockFunctionBody_sync() {
1734 _assertSource("sync {}", AstFactory.syncBlockFunctionBody());
1735 }
1736
1737 void test_visitBlockFunctionBody_sync_star() {
1738 _assertSource("sync* {}", AstFactory.syncGeneratorBlockFunctionBody());
1739 }
1740
1741 void test_visitBooleanLiteral_false() {
1742 _assertSource("false", AstFactory.booleanLiteral(false));
1743 }
1744
1745 void test_visitBooleanLiteral_true() {
1746 _assertSource("true", AstFactory.booleanLiteral(true));
1747 }
1748
1749 void test_visitBreakStatement_label() {
1750 _assertSource("break l;", AstFactory.breakStatement2("l"));
1751 }
1752
1753 void test_visitBreakStatement_noLabel() {
1754 _assertSource("break;", AstFactory.breakStatement());
1755 }
1756
1757 void test_visitCascadeExpression_field() {
1758 _assertSource(
1759 "a..b..c",
1760 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [
1761 AstFactory.cascadedPropertyAccess("b"),
1762 AstFactory.cascadedPropertyAccess("c")
1763 ]));
1764 }
1765
1766 void test_visitCascadeExpression_index() {
1767 _assertSource(
1768 "a..[0]..[1]",
1769 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [
1770 AstFactory.cascadedIndexExpression(AstFactory.integer(0)),
1771 AstFactory.cascadedIndexExpression(AstFactory.integer(1))
1772 ]));
1773 }
1774
1775 void test_visitCascadeExpression_method() {
1776 _assertSource(
1777 "a..b()..c()",
1778 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [
1779 AstFactory.cascadedMethodInvocation("b"),
1780 AstFactory.cascadedMethodInvocation("c")
1781 ]));
1782 }
1783
1784 void test_visitCatchClause_catch_noStack() {
1785 _assertSource("catch (e) {}", AstFactory.catchClause("e"));
1786 }
1787
1788 void test_visitCatchClause_catch_stack() {
1789 _assertSource("catch (e, s) {}", AstFactory.catchClause2("e", "s"));
1790 }
1791
1792 void test_visitCatchClause_on() {
1793 _assertSource(
1794 "on E {}", AstFactory.catchClause3(AstFactory.typeName4("E")));
1795 }
1796
1797 void test_visitCatchClause_on_catch() {
1798 _assertSource("on E catch (e) {}",
1799 AstFactory.catchClause4(AstFactory.typeName4("E"), "e"));
1800 }
1801
1802 void test_visitClassDeclaration_abstract() {
1803 _assertSource(
1804 "abstract class C {}",
1805 AstFactory.classDeclaration(
1806 Keyword.ABSTRACT, "C", null, null, null, null));
1807 }
1808
1809 void test_visitClassDeclaration_empty() {
1810 _assertSource("class C {}",
1811 AstFactory.classDeclaration(null, "C", null, null, null, null));
1812 }
1813
1814 void test_visitClassDeclaration_extends() {
1815 _assertSource(
1816 "class C extends A {}",
1817 AstFactory.classDeclaration(null, "C", null,
1818 AstFactory.extendsClause(AstFactory.typeName4("A")), null, null));
1819 }
1820
1821 void test_visitClassDeclaration_extends_implements() {
1822 _assertSource(
1823 "class C extends A implements B {}",
1824 AstFactory.classDeclaration(
1825 null,
1826 "C",
1827 null,
1828 AstFactory.extendsClause(AstFactory.typeName4("A")),
1829 null,
1830 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1831 }
1832
1833 void test_visitClassDeclaration_extends_with() {
1834 _assertSource(
1835 "class C extends A with M {}",
1836 AstFactory.classDeclaration(
1837 null,
1838 "C",
1839 null,
1840 AstFactory.extendsClause(AstFactory.typeName4("A")),
1841 AstFactory.withClause([AstFactory.typeName4("M")]),
1842 null));
1843 }
1844
1845 void test_visitClassDeclaration_extends_with_implements() {
1846 _assertSource(
1847 "class C extends A with M implements B {}",
1848 AstFactory.classDeclaration(
1849 null,
1850 "C",
1851 null,
1852 AstFactory.extendsClause(AstFactory.typeName4("A")),
1853 AstFactory.withClause([AstFactory.typeName4("M")]),
1854 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1855 }
1856
1857 void test_visitClassDeclaration_implements() {
1858 _assertSource(
1859 "class C implements B {}",
1860 AstFactory.classDeclaration(null, "C", null, null, null,
1861 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1862 }
1863
1864 void test_visitClassDeclaration_multipleMember() {
1865 _assertSource(
1866 "class C {var a; var b;}",
1867 AstFactory.classDeclaration(null, "C", null, null, null, null, [
1868 AstFactory.fieldDeclaration2(
1869 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]),
1870 AstFactory.fieldDeclaration2(
1871 false, Keyword.VAR, [AstFactory.variableDeclaration("b")])
1872 ]));
1873 }
1874
1875 void test_visitClassDeclaration_parameters() {
1876 _assertSource(
1877 "class C<E> {}",
1878 AstFactory.classDeclaration(
1879 null, "C", AstFactory.typeParameterList(["E"]), null, null, null));
1880 }
1881
1882 void test_visitClassDeclaration_parameters_extends() {
1883 _assertSource(
1884 "class C<E> extends A {}",
1885 AstFactory.classDeclaration(
1886 null,
1887 "C",
1888 AstFactory.typeParameterList(["E"]),
1889 AstFactory.extendsClause(AstFactory.typeName4("A")),
1890 null,
1891 null));
1892 }
1893
1894 void test_visitClassDeclaration_parameters_extends_implements() {
1895 _assertSource(
1896 "class C<E> extends A implements B {}",
1897 AstFactory.classDeclaration(
1898 null,
1899 "C",
1900 AstFactory.typeParameterList(["E"]),
1901 AstFactory.extendsClause(AstFactory.typeName4("A")),
1902 null,
1903 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1904 }
1905
1906 void test_visitClassDeclaration_parameters_extends_with() {
1907 _assertSource(
1908 "class C<E> extends A with M {}",
1909 AstFactory.classDeclaration(
1910 null,
1911 "C",
1912 AstFactory.typeParameterList(["E"]),
1913 AstFactory.extendsClause(AstFactory.typeName4("A")),
1914 AstFactory.withClause([AstFactory.typeName4("M")]),
1915 null));
1916 }
1917
1918 void test_visitClassDeclaration_parameters_extends_with_implements() {
1919 _assertSource(
1920 "class C<E> extends A with M implements B {}",
1921 AstFactory.classDeclaration(
1922 null,
1923 "C",
1924 AstFactory.typeParameterList(["E"]),
1925 AstFactory.extendsClause(AstFactory.typeName4("A")),
1926 AstFactory.withClause([AstFactory.typeName4("M")]),
1927 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1928 }
1929
1930 void test_visitClassDeclaration_parameters_implements() {
1931 _assertSource(
1932 "class C<E> implements B {}",
1933 AstFactory.classDeclaration(
1934 null,
1935 "C",
1936 AstFactory.typeParameterList(["E"]),
1937 null,
1938 null,
1939 AstFactory.implementsClause([AstFactory.typeName4("B")])));
1940 }
1941
1942 void test_visitClassDeclaration_singleMember() {
1943 _assertSource(
1944 "class C {var a;}",
1945 AstFactory.classDeclaration(null, "C", null, null, null, null, [
1946 AstFactory.fieldDeclaration2(
1947 false, Keyword.VAR, [AstFactory.variableDeclaration("a")])
1948 ]));
1949 }
1950
1951 void test_visitClassDeclaration_withMetadata() {
1952 ClassDeclaration declaration =
1953 AstFactory.classDeclaration(null, "C", null, null, null, null);
1954 declaration.metadata
1955 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
1956 _assertSource("@deprecated class C {}", declaration);
1957 }
1958
1959 void test_visitClassTypeAlias_abstract() {
1960 _assertSource(
1961 "abstract class C = S with M1;",
1962 AstFactory.classTypeAlias(
1963 "C",
1964 null,
1965 Keyword.ABSTRACT,
1966 AstFactory.typeName4("S"),
1967 AstFactory.withClause([AstFactory.typeName4("M1")]),
1968 null));
1969 }
1970
1971 void test_visitClassTypeAlias_abstract_implements() {
1972 _assertSource(
1973 "abstract class C = S with M1 implements I;",
1974 AstFactory.classTypeAlias(
1975 "C",
1976 null,
1977 Keyword.ABSTRACT,
1978 AstFactory.typeName4("S"),
1979 AstFactory.withClause([AstFactory.typeName4("M1")]),
1980 AstFactory.implementsClause([AstFactory.typeName4("I")])));
1981 }
1982
1983 void test_visitClassTypeAlias_generic() {
1984 _assertSource(
1985 "class C<E> = S<E> with M1<E>;",
1986 AstFactory.classTypeAlias(
1987 "C",
1988 AstFactory.typeParameterList(["E"]),
1989 null,
1990 AstFactory.typeName4("S", [AstFactory.typeName4("E")]),
1991 AstFactory.withClause([
1992 AstFactory.typeName4("M1", [AstFactory.typeName4("E")])
1993 ]),
1994 null));
1995 }
1996
1997 void test_visitClassTypeAlias_implements() {
1998 _assertSource(
1999 "class C = S with M1 implements I;",
2000 AstFactory.classTypeAlias(
2001 "C",
2002 null,
2003 null,
2004 AstFactory.typeName4("S"),
2005 AstFactory.withClause([AstFactory.typeName4("M1")]),
2006 AstFactory.implementsClause([AstFactory.typeName4("I")])));
2007 }
2008
2009 void test_visitClassTypeAlias_minimal() {
2010 _assertSource(
2011 "class C = S with M1;",
2012 AstFactory.classTypeAlias("C", null, null, AstFactory.typeName4("S"),
2013 AstFactory.withClause([AstFactory.typeName4("M1")]), null));
2014 }
2015
2016 void test_visitClassTypeAlias_parameters_abstract() {
2017 _assertSource(
2018 "abstract class C<E> = S with M1;",
2019 AstFactory.classTypeAlias(
2020 "C",
2021 AstFactory.typeParameterList(["E"]),
2022 Keyword.ABSTRACT,
2023 AstFactory.typeName4("S"),
2024 AstFactory.withClause([AstFactory.typeName4("M1")]),
2025 null));
2026 }
2027
2028 void test_visitClassTypeAlias_parameters_abstract_implements() {
2029 _assertSource(
2030 "abstract class C<E> = S with M1 implements I;",
2031 AstFactory.classTypeAlias(
2032 "C",
2033 AstFactory.typeParameterList(["E"]),
2034 Keyword.ABSTRACT,
2035 AstFactory.typeName4("S"),
2036 AstFactory.withClause([AstFactory.typeName4("M1")]),
2037 AstFactory.implementsClause([AstFactory.typeName4("I")])));
2038 }
2039
2040 void test_visitClassTypeAlias_parameters_implements() {
2041 _assertSource(
2042 "class C<E> = S with M1 implements I;",
2043 AstFactory.classTypeAlias(
2044 "C",
2045 AstFactory.typeParameterList(["E"]),
2046 null,
2047 AstFactory.typeName4("S"),
2048 AstFactory.withClause([AstFactory.typeName4("M1")]),
2049 AstFactory.implementsClause([AstFactory.typeName4("I")])));
2050 }
2051
2052 void test_visitClassTypeAlias_withMetadata() {
2053 ClassTypeAlias declaration = AstFactory.classTypeAlias(
2054 "C",
2055 null,
2056 null,
2057 AstFactory.typeName4("S"),
2058 AstFactory.withClause([AstFactory.typeName4("M1")]),
2059 null);
2060 declaration.metadata
2061 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2062 _assertSource("@deprecated class C = S with M1;", declaration);
2063 }
2064
2065 void test_visitComment() {
2066 _assertSource(
2067 "",
2068 Comment.createBlockComment(
2069 <Token>[TokenFactory.tokenFromString("/* comment */")]));
2070 }
2071
2072 void test_visitCommentReference() {
2073 _assertSource("", new CommentReference(null, AstFactory.identifier3("a")));
2074 }
2075
2076 void test_visitCompilationUnit_declaration() {
2077 _assertSource(
2078 "var a;",
2079 AstFactory.compilationUnit2([
2080 AstFactory.topLevelVariableDeclaration2(
2081 Keyword.VAR, [AstFactory.variableDeclaration("a")])
2082 ]));
2083 }
2084
2085 void test_visitCompilationUnit_directive() {
2086 _assertSource("library l;",
2087 AstFactory.compilationUnit3([AstFactory.libraryDirective2("l")]));
2088 }
2089
2090 void test_visitCompilationUnit_directive_declaration() {
2091 _assertSource(
2092 "library l; var a;",
2093 AstFactory.compilationUnit4([
2094 AstFactory.libraryDirective2("l")
2095 ], [
2096 AstFactory.topLevelVariableDeclaration2(
2097 Keyword.VAR, [AstFactory.variableDeclaration("a")])
2098 ]));
2099 }
2100
2101 void test_visitCompilationUnit_empty() {
2102 _assertSource("", AstFactory.compilationUnit());
2103 }
2104
2105 void test_visitCompilationUnit_script() {
2106 _assertSource(
2107 "!#/bin/dartvm", AstFactory.compilationUnit5("!#/bin/dartvm"));
2108 }
2109
2110 void test_visitCompilationUnit_script_declaration() {
2111 _assertSource(
2112 "!#/bin/dartvm var a;",
2113 AstFactory.compilationUnit6("!#/bin/dartvm", [
2114 AstFactory.topLevelVariableDeclaration2(
2115 Keyword.VAR, [AstFactory.variableDeclaration("a")])
2116 ]));
2117 }
2118
2119 void test_visitCompilationUnit_script_directive() {
2120 _assertSource(
2121 "!#/bin/dartvm library l;",
2122 AstFactory.compilationUnit7(
2123 "!#/bin/dartvm", [AstFactory.libraryDirective2("l")]));
2124 }
2125
2126 void test_visitCompilationUnit_script_directives_declarations() {
2127 _assertSource(
2128 "!#/bin/dartvm library l; var a;",
2129 AstFactory.compilationUnit8("!#/bin/dartvm", [
2130 AstFactory.libraryDirective2("l")
2131 ], [
2132 AstFactory.topLevelVariableDeclaration2(
2133 Keyword.VAR, [AstFactory.variableDeclaration("a")])
2134 ]));
2135 }
2136
2137 void test_visitConditionalExpression() {
2138 _assertSource(
2139 "a ? b : c",
2140 AstFactory.conditionalExpression(AstFactory.identifier3("a"),
2141 AstFactory.identifier3("b"), AstFactory.identifier3("c")));
2142 }
2143
2144 void test_visitConstructorDeclaration_const() {
2145 _assertSource(
2146 "const C() {}",
2147 AstFactory.constructorDeclaration2(
2148 Keyword.CONST,
2149 null,
2150 AstFactory.identifier3("C"),
2151 null,
2152 AstFactory.formalParameterList(),
2153 null,
2154 AstFactory.blockFunctionBody2()));
2155 }
2156
2157 void test_visitConstructorDeclaration_external() {
2158 _assertSource(
2159 "external C();",
2160 AstFactory.constructorDeclaration(AstFactory.identifier3("C"), null,
2161 AstFactory.formalParameterList(), null));
2162 }
2163
2164 void test_visitConstructorDeclaration_minimal() {
2165 _assertSource(
2166 "C() {}",
2167 AstFactory.constructorDeclaration2(
2168 null,
2169 null,
2170 AstFactory.identifier3("C"),
2171 null,
2172 AstFactory.formalParameterList(),
2173 null,
2174 AstFactory.blockFunctionBody2()));
2175 }
2176
2177 void test_visitConstructorDeclaration_multipleInitializers() {
2178 _assertSource(
2179 "C() : a = b, c = d {}",
2180 AstFactory.constructorDeclaration2(
2181 null,
2182 null,
2183 AstFactory.identifier3("C"),
2184 null,
2185 AstFactory.formalParameterList(),
2186 [
2187 AstFactory.constructorFieldInitializer(
2188 false, "a", AstFactory.identifier3("b")),
2189 AstFactory.constructorFieldInitializer(
2190 false, "c", AstFactory.identifier3("d"))
2191 ],
2192 AstFactory.blockFunctionBody2()));
2193 }
2194
2195 void test_visitConstructorDeclaration_multipleParameters() {
2196 _assertSource(
2197 "C(var a, var b) {}",
2198 AstFactory.constructorDeclaration2(
2199 null,
2200 null,
2201 AstFactory.identifier3("C"),
2202 null,
2203 AstFactory.formalParameterList([
2204 AstFactory.simpleFormalParameter(Keyword.VAR, "a"),
2205 AstFactory.simpleFormalParameter(Keyword.VAR, "b")
2206 ]),
2207 null,
2208 AstFactory.blockFunctionBody2()));
2209 }
2210
2211 void test_visitConstructorDeclaration_named() {
2212 _assertSource(
2213 "C.m() {}",
2214 AstFactory.constructorDeclaration2(
2215 null,
2216 null,
2217 AstFactory.identifier3("C"),
2218 "m",
2219 AstFactory.formalParameterList(),
2220 null,
2221 AstFactory.blockFunctionBody2()));
2222 }
2223
2224 void test_visitConstructorDeclaration_singleInitializer() {
2225 _assertSource(
2226 "C() : a = b {}",
2227 AstFactory.constructorDeclaration2(
2228 null,
2229 null,
2230 AstFactory.identifier3("C"),
2231 null,
2232 AstFactory.formalParameterList(),
2233 [
2234 AstFactory.constructorFieldInitializer(
2235 false, "a", AstFactory.identifier3("b"))
2236 ],
2237 AstFactory.blockFunctionBody2()));
2238 }
2239
2240 void test_visitConstructorDeclaration_withMetadata() {
2241 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
2242 null,
2243 null,
2244 AstFactory.identifier3("C"),
2245 null,
2246 AstFactory.formalParameterList(),
2247 null,
2248 AstFactory.blockFunctionBody2());
2249 declaration.metadata
2250 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2251 _assertSource("@deprecated C() {}", declaration);
2252 }
2253
2254 void test_visitConstructorFieldInitializer_withoutThis() {
2255 _assertSource(
2256 "a = b",
2257 AstFactory.constructorFieldInitializer(
2258 false, "a", AstFactory.identifier3("b")));
2259 }
2260
2261 void test_visitConstructorFieldInitializer_withThis() {
2262 _assertSource(
2263 "this.a = b",
2264 AstFactory.constructorFieldInitializer(
2265 true, "a", AstFactory.identifier3("b")));
2266 }
2267
2268 void test_visitConstructorName_named_prefix() {
2269 _assertSource("p.C.n",
2270 AstFactory.constructorName(AstFactory.typeName4("p.C.n"), null));
2271 }
2272
2273 void test_visitConstructorName_unnamed_noPrefix() {
2274 _assertSource(
2275 "C", AstFactory.constructorName(AstFactory.typeName4("C"), null));
2276 }
2277
2278 void test_visitConstructorName_unnamed_prefix() {
2279 _assertSource(
2280 "p.C",
2281 AstFactory.constructorName(
2282 AstFactory.typeName3(AstFactory.identifier5("p", "C")), null));
2283 }
2284
2285 void test_visitContinueStatement_label() {
2286 _assertSource("continue l;", AstFactory.continueStatement("l"));
2287 }
2288
2289 void test_visitContinueStatement_noLabel() {
2290 _assertSource("continue;", AstFactory.continueStatement());
2291 }
2292
2293 void test_visitDefaultFormalParameter_named_noValue() {
2294 _assertSource(
2295 "p",
2296 AstFactory.namedFormalParameter(
2297 AstFactory.simpleFormalParameter3("p"), null));
2298 }
2299
2300 void test_visitDefaultFormalParameter_named_value() {
2301 _assertSource(
2302 "p : 0",
2303 AstFactory.namedFormalParameter(
2304 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0)));
2305 }
2306
2307 void test_visitDefaultFormalParameter_positional_noValue() {
2308 _assertSource(
2309 "p",
2310 AstFactory.positionalFormalParameter(
2311 AstFactory.simpleFormalParameter3("p"), null));
2312 }
2313
2314 void test_visitDefaultFormalParameter_positional_value() {
2315 _assertSource(
2316 "p = 0",
2317 AstFactory.positionalFormalParameter(
2318 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0)));
2319 }
2320
2321 void test_visitDefaultFormalParameter_annotation() {
2322 DefaultFormalParameter parameter = AstFactory.positionalFormalParameter(
2323 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0));
2324 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
2325 _assertSource('@A p = 0', parameter);
2326 }
2327
2328 void test_visitDoStatement() {
2329 _assertSource(
2330 "do {} while (c);",
2331 AstFactory.doStatement(
2332 AstFactory.block(), AstFactory.identifier3("c")));
2333 }
2334
2335 void test_visitDoubleLiteral() {
2336 _assertSource("4.2", AstFactory.doubleLiteral(4.2));
2337 }
2338
2339 void test_visitEmptyFunctionBody() {
2340 _assertSource(";", AstFactory.emptyFunctionBody());
2341 }
2342
2343 void test_visitEmptyStatement() {
2344 _assertSource(";", AstFactory.emptyStatement());
2345 }
2346
2347 void test_visitEnumDeclaration_multiple() {
2348 _assertSource(
2349 "enum E {ONE, TWO}", AstFactory.enumDeclaration2("E", ["ONE", "TWO"]));
2350 }
2351
2352 void test_visitEnumDeclaration_single() {
2353 _assertSource("enum E {ONE}", AstFactory.enumDeclaration2("E", ["ONE"]));
2354 }
2355
2356 void test_visitExportDirective_combinator() {
2357 _assertSource(
2358 "export 'a.dart' show A;",
2359 AstFactory.exportDirective2("a.dart", [
2360 AstFactory.showCombinator([AstFactory.identifier3("A")])
2361 ]));
2362 }
2363
2364 void test_visitExportDirective_combinators() {
2365 _assertSource(
2366 "export 'a.dart' show A hide B;",
2367 AstFactory.exportDirective2("a.dart", [
2368 AstFactory.showCombinator([AstFactory.identifier3("A")]),
2369 AstFactory.hideCombinator([AstFactory.identifier3("B")])
2370 ]));
2371 }
2372
2373 void test_visitExportDirective_minimal() {
2374 _assertSource("export 'a.dart';", AstFactory.exportDirective2("a.dart"));
2375 }
2376
2377 void test_visitExportDirective_withMetadata() {
2378 ExportDirective directive = AstFactory.exportDirective2("a.dart");
2379 directive.metadata
2380 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2381 _assertSource("@deprecated export 'a.dart';", directive);
2382 }
2383
2384 void test_visitExpressionFunctionBody_async() {
2385 _assertSource("async => a;",
2386 AstFactory.asyncExpressionFunctionBody(AstFactory.identifier3("a")));
2387 }
2388
2389 void test_visitExpressionFunctionBody_simple() {
2390 _assertSource("=> a;",
2391 AstFactory.expressionFunctionBody(AstFactory.identifier3("a")));
2392 }
2393
2394 void test_visitExpressionStatement() {
2395 _assertSource(
2396 "a;", AstFactory.expressionStatement(AstFactory.identifier3("a")));
2397 }
2398
2399 void test_visitExtendsClause() {
2400 _assertSource(
2401 "extends C", AstFactory.extendsClause(AstFactory.typeName4("C")));
2402 }
2403
2404 void test_visitFieldDeclaration_instance() {
2405 _assertSource(
2406 "var a;",
2407 AstFactory.fieldDeclaration2(
2408 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]));
2409 }
2410
2411 void test_visitFieldDeclaration_static() {
2412 _assertSource(
2413 "static var a;",
2414 AstFactory.fieldDeclaration2(
2415 true, Keyword.VAR, [AstFactory.variableDeclaration("a")]));
2416 }
2417
2418 void test_visitFieldDeclaration_withMetadata() {
2419 FieldDeclaration declaration = AstFactory.fieldDeclaration2(
2420 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]);
2421 declaration.metadata
2422 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2423 _assertSource("@deprecated var a;", declaration);
2424 }
2425
2426 void test_visitFieldFormalParameter_functionTyped() {
2427 _assertSource(
2428 "A this.a(b)",
2429 AstFactory.fieldFormalParameter(
2430 null,
2431 AstFactory.typeName4("A"),
2432 "a",
2433 AstFactory.formalParameterList(
2434 [AstFactory.simpleFormalParameter3("b")])));
2435 }
2436
2437 void test_visitFieldFormalParameter_functionTyped_typeParameters() {
2438 _assertSource(
2439 "A this.a<E, F>(b)",
2440 new FieldFormalParameter(
2441 null,
2442 null,
2443 null,
2444 AstFactory.typeName4('A'),
2445 TokenFactory.tokenFromKeyword(Keyword.THIS),
2446 TokenFactory.tokenFromType(TokenType.PERIOD),
2447 AstFactory.identifier3('a'),
2448 AstFactory.typeParameterList(['E', 'F']),
2449 AstFactory.formalParameterList(
2450 [AstFactory.simpleFormalParameter3("b")])));
2451 }
2452
2453 void test_visitFieldFormalParameter_keyword() {
2454 _assertSource(
2455 "var this.a", AstFactory.fieldFormalParameter(Keyword.VAR, null, "a"));
2456 }
2457
2458 void test_visitFieldFormalParameter_keywordAndType() {
2459 _assertSource(
2460 "final A this.a",
2461 AstFactory.fieldFormalParameter(
2462 Keyword.FINAL, AstFactory.typeName4("A"), "a"));
2463 }
2464
2465 void test_visitFieldFormalParameter_type() {
2466 _assertSource("A this.a",
2467 AstFactory.fieldFormalParameter(null, AstFactory.typeName4("A"), "a"));
2468 }
2469
2470 void test_visitFieldFormalParameter_annotation() {
2471 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('f');
2472 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
2473 _assertSource('@A this.f', parameter);
2474 }
2475
2476 void test_visitForEachStatement_declared() {
2477 _assertSource(
2478 "for (var a in b) {}",
2479 AstFactory.forEachStatement(AstFactory.declaredIdentifier3("a"),
2480 AstFactory.identifier3("b"), AstFactory.block()));
2481 }
2482
2483 void test_visitForEachStatement_variable() {
2484 _assertSource(
2485 "for (a in b) {}",
2486 new ForEachStatement.withReference(
2487 null,
2488 TokenFactory.tokenFromKeyword(Keyword.FOR),
2489 TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
2490 AstFactory.identifier3("a"),
2491 TokenFactory.tokenFromKeyword(Keyword.IN),
2492 AstFactory.identifier3("b"),
2493 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
2494 AstFactory.block()));
2495 }
2496
2497 void test_visitForEachStatement_variable_await() {
2498 _assertSource(
2499 "await for (a in b) {}",
2500 new ForEachStatement.withReference(
2501 TokenFactory.tokenFromString("await"),
2502 TokenFactory.tokenFromKeyword(Keyword.FOR),
2503 TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
2504 AstFactory.identifier3("a"),
2505 TokenFactory.tokenFromKeyword(Keyword.IN),
2506 AstFactory.identifier3("b"),
2507 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
2508 AstFactory.block()));
2509 }
2510
2511 void test_visitFormalParameterList_empty() {
2512 _assertSource("()", AstFactory.formalParameterList());
2513 }
2514
2515 void test_visitFormalParameterList_n() {
2516 _assertSource(
2517 "({a : 0})",
2518 AstFactory.formalParameterList([
2519 AstFactory.namedFormalParameter(
2520 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0))
2521 ]));
2522 }
2523
2524 void test_visitFormalParameterList_nn() {
2525 _assertSource(
2526 "({a : 0, b : 1})",
2527 AstFactory.formalParameterList([
2528 AstFactory.namedFormalParameter(
2529 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)),
2530 AstFactory.namedFormalParameter(
2531 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1))
2532 ]));
2533 }
2534
2535 void test_visitFormalParameterList_p() {
2536 _assertSource(
2537 "([a = 0])",
2538 AstFactory.formalParameterList([
2539 AstFactory.positionalFormalParameter(
2540 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0))
2541 ]));
2542 }
2543
2544 void test_visitFormalParameterList_pp() {
2545 _assertSource(
2546 "([a = 0, b = 1])",
2547 AstFactory.formalParameterList([
2548 AstFactory.positionalFormalParameter(
2549 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)),
2550 AstFactory.positionalFormalParameter(
2551 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1))
2552 ]));
2553 }
2554
2555 void test_visitFormalParameterList_r() {
2556 _assertSource(
2557 "(a)",
2558 AstFactory
2559 .formalParameterList([AstFactory.simpleFormalParameter3("a")]));
2560 }
2561
2562 void test_visitFormalParameterList_rn() {
2563 _assertSource(
2564 "(a, {b : 1})",
2565 AstFactory.formalParameterList([
2566 AstFactory.simpleFormalParameter3("a"),
2567 AstFactory.namedFormalParameter(
2568 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1))
2569 ]));
2570 }
2571
2572 void test_visitFormalParameterList_rnn() {
2573 _assertSource(
2574 "(a, {b : 1, c : 2})",
2575 AstFactory.formalParameterList([
2576 AstFactory.simpleFormalParameter3("a"),
2577 AstFactory.namedFormalParameter(
2578 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)),
2579 AstFactory.namedFormalParameter(
2580 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2))
2581 ]));
2582 }
2583
2584 void test_visitFormalParameterList_rp() {
2585 _assertSource(
2586 "(a, [b = 1])",
2587 AstFactory.formalParameterList([
2588 AstFactory.simpleFormalParameter3("a"),
2589 AstFactory.positionalFormalParameter(
2590 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1))
2591 ]));
2592 }
2593
2594 void test_visitFormalParameterList_rpp() {
2595 _assertSource(
2596 "(a, [b = 1, c = 2])",
2597 AstFactory.formalParameterList([
2598 AstFactory.simpleFormalParameter3("a"),
2599 AstFactory.positionalFormalParameter(
2600 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)),
2601 AstFactory.positionalFormalParameter(
2602 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2))
2603 ]));
2604 }
2605
2606 void test_visitFormalParameterList_rr() {
2607 _assertSource(
2608 "(a, b)",
2609 AstFactory.formalParameterList([
2610 AstFactory.simpleFormalParameter3("a"),
2611 AstFactory.simpleFormalParameter3("b")
2612 ]));
2613 }
2614
2615 void test_visitFormalParameterList_rrn() {
2616 _assertSource(
2617 "(a, b, {c : 3})",
2618 AstFactory.formalParameterList([
2619 AstFactory.simpleFormalParameter3("a"),
2620 AstFactory.simpleFormalParameter3("b"),
2621 AstFactory.namedFormalParameter(
2622 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3))
2623 ]));
2624 }
2625
2626 void test_visitFormalParameterList_rrnn() {
2627 _assertSource(
2628 "(a, b, {c : 3, d : 4})",
2629 AstFactory.formalParameterList([
2630 AstFactory.simpleFormalParameter3("a"),
2631 AstFactory.simpleFormalParameter3("b"),
2632 AstFactory.namedFormalParameter(
2633 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)),
2634 AstFactory.namedFormalParameter(
2635 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4))
2636 ]));
2637 }
2638
2639 void test_visitFormalParameterList_rrp() {
2640 _assertSource(
2641 "(a, b, [c = 3])",
2642 AstFactory.formalParameterList([
2643 AstFactory.simpleFormalParameter3("a"),
2644 AstFactory.simpleFormalParameter3("b"),
2645 AstFactory.positionalFormalParameter(
2646 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3))
2647 ]));
2648 }
2649
2650 void test_visitFormalParameterList_rrpp() {
2651 _assertSource(
2652 "(a, b, [c = 3, d = 4])",
2653 AstFactory.formalParameterList([
2654 AstFactory.simpleFormalParameter3("a"),
2655 AstFactory.simpleFormalParameter3("b"),
2656 AstFactory.positionalFormalParameter(
2657 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)),
2658 AstFactory.positionalFormalParameter(
2659 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4))
2660 ]));
2661 }
2662
2663 void test_visitForStatement_c() {
2664 _assertSource(
2665 "for (; c;) {}",
2666 AstFactory.forStatement(
2667 null, AstFactory.identifier3("c"), null, AstFactory.block()));
2668 }
2669
2670 void test_visitForStatement_cu() {
2671 _assertSource(
2672 "for (; c; u) {}",
2673 AstFactory.forStatement(null, AstFactory.identifier3("c"),
2674 [AstFactory.identifier3("u")], AstFactory.block()));
2675 }
2676
2677 void test_visitForStatement_e() {
2678 _assertSource(
2679 "for (e;;) {}",
2680 AstFactory.forStatement(
2681 AstFactory.identifier3("e"), null, null, AstFactory.block()));
2682 }
2683
2684 void test_visitForStatement_ec() {
2685 _assertSource(
2686 "for (e; c;) {}",
2687 AstFactory.forStatement(AstFactory.identifier3("e"),
2688 AstFactory.identifier3("c"), null, AstFactory.block()));
2689 }
2690
2691 void test_visitForStatement_ecu() {
2692 _assertSource(
2693 "for (e; c; u) {}",
2694 AstFactory.forStatement(
2695 AstFactory.identifier3("e"),
2696 AstFactory.identifier3("c"),
2697 [AstFactory.identifier3("u")],
2698 AstFactory.block()));
2699 }
2700
2701 void test_visitForStatement_eu() {
2702 _assertSource(
2703 "for (e;; u) {}",
2704 AstFactory.forStatement(AstFactory.identifier3("e"), null,
2705 [AstFactory.identifier3("u")], AstFactory.block()));
2706 }
2707
2708 void test_visitForStatement_i() {
2709 _assertSource(
2710 "for (var i;;) {}",
2711 AstFactory.forStatement2(
2712 AstFactory.variableDeclarationList2(
2713 Keyword.VAR, [AstFactory.variableDeclaration("i")]),
2714 null,
2715 null,
2716 AstFactory.block()));
2717 }
2718
2719 void test_visitForStatement_ic() {
2720 _assertSource(
2721 "for (var i; c;) {}",
2722 AstFactory.forStatement2(
2723 AstFactory.variableDeclarationList2(
2724 Keyword.VAR, [AstFactory.variableDeclaration("i")]),
2725 AstFactory.identifier3("c"),
2726 null,
2727 AstFactory.block()));
2728 }
2729
2730 void test_visitForStatement_icu() {
2731 _assertSource(
2732 "for (var i; c; u) {}",
2733 AstFactory.forStatement2(
2734 AstFactory.variableDeclarationList2(
2735 Keyword.VAR, [AstFactory.variableDeclaration("i")]),
2736 AstFactory.identifier3("c"),
2737 [AstFactory.identifier3("u")],
2738 AstFactory.block()));
2739 }
2740
2741 void test_visitForStatement_iu() {
2742 _assertSource(
2743 "for (var i;; u) {}",
2744 AstFactory.forStatement2(
2745 AstFactory.variableDeclarationList2(
2746 Keyword.VAR, [AstFactory.variableDeclaration("i")]),
2747 null,
2748 [AstFactory.identifier3("u")],
2749 AstFactory.block()));
2750 }
2751
2752 void test_visitForStatement_u() {
2753 _assertSource(
2754 "for (;; u) {}",
2755 AstFactory.forStatement(
2756 null, null, [AstFactory.identifier3("u")], AstFactory.block()));
2757 }
2758
2759 void test_visitFunctionDeclaration_external() {
2760 FunctionDeclaration functionDeclaration = AstFactory.functionDeclaration(
2761 null,
2762 null,
2763 "f",
2764 AstFactory.functionExpression2(
2765 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()));
2766 functionDeclaration.externalKeyword =
2767 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
2768 _assertSource("external f();", functionDeclaration);
2769 }
2770
2771 void test_visitFunctionDeclaration_getter() {
2772 _assertSource(
2773 "get f() {}",
2774 AstFactory.functionDeclaration(
2775 null, Keyword.GET, "f", AstFactory.functionExpression()));
2776 }
2777
2778 void test_visitFunctionDeclaration_local_blockBody() {
2779 FunctionDeclaration f = AstFactory.functionDeclaration(
2780 null, null, "f", AstFactory.functionExpression());
2781 FunctionDeclarationStatement fStatement =
2782 new FunctionDeclarationStatement(f);
2783 _assertSource(
2784 "main() {f() {} 42;}",
2785 AstFactory.functionDeclaration(
2786 null,
2787 null,
2788 "main",
2789 AstFactory.functionExpression2(
2790 AstFactory.formalParameterList(),
2791 AstFactory.blockFunctionBody2([
2792 fStatement,
2793 AstFactory.expressionStatement(AstFactory.integer(42))
2794 ]))));
2795 }
2796
2797 void test_visitFunctionDeclaration_local_expressionBody() {
2798 FunctionDeclaration f = AstFactory.functionDeclaration(
2799 null,
2800 null,
2801 "f",
2802 AstFactory.functionExpression2(AstFactory.formalParameterList(),
2803 AstFactory.expressionFunctionBody(AstFactory.integer(1))));
2804 FunctionDeclarationStatement fStatement =
2805 new FunctionDeclarationStatement(f);
2806 _assertSource(
2807 "main() {f() => 1; 2;}",
2808 AstFactory.functionDeclaration(
2809 null,
2810 null,
2811 "main",
2812 AstFactory.functionExpression2(
2813 AstFactory.formalParameterList(),
2814 AstFactory.blockFunctionBody2([
2815 fStatement,
2816 AstFactory.expressionStatement(AstFactory.integer(2))
2817 ]))));
2818 }
2819
2820 void test_visitFunctionDeclaration_normal() {
2821 _assertSource(
2822 "f() {}",
2823 AstFactory.functionDeclaration(
2824 null, null, "f", AstFactory.functionExpression()));
2825 }
2826
2827 void test_visitFunctionDeclaration_setter() {
2828 _assertSource(
2829 "set f() {}",
2830 AstFactory.functionDeclaration(
2831 null, Keyword.SET, "f", AstFactory.functionExpression()));
2832 }
2833
2834 void test_visitFunctionDeclaration_typeParameters() {
2835 _assertSource(
2836 "f<E>() {}",
2837 AstFactory.functionDeclaration(
2838 null,
2839 null,
2840 "f",
2841 AstFactory.functionExpression3(
2842 AstFactory.typeParameterList(['E']),
2843 AstFactory.formalParameterList(),
2844 AstFactory.blockFunctionBody2())));
2845 }
2846
2847 void test_visitFunctionDeclaration_withMetadata() {
2848 FunctionDeclaration declaration = AstFactory.functionDeclaration(
2849 null, null, "f", AstFactory.functionExpression());
2850 declaration.metadata
2851 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2852 _assertSource("@deprecated f() {}", declaration);
2853 }
2854
2855 void test_visitFunctionDeclarationStatement() {
2856 _assertSource(
2857 "f() {}",
2858 AstFactory.functionDeclarationStatement(
2859 null, null, "f", AstFactory.functionExpression()));
2860 }
2861
2862 void test_visitFunctionExpression() {
2863 _assertSource("() {}", AstFactory.functionExpression());
2864 }
2865
2866 void test_visitFunctionExpression_typeParameters() {
2867 _assertSource(
2868 "<E>() {}",
2869 AstFactory.functionExpression3(AstFactory.typeParameterList(['E']),
2870 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()));
2871 }
2872
2873 void test_visitFunctionExpressionInvocation_minimal() {
2874 _assertSource("f()",
2875 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")));
2876 }
2877
2878 void test_visitFunctionExpressionInvocation_typeArguments() {
2879 _assertSource(
2880 "f<A>()",
2881 AstFactory.functionExpressionInvocation2(AstFactory.identifier3("f"),
2882 AstFactory.typeArgumentList([AstFactory.typeName4('A')])));
2883 }
2884
2885 void test_visitFunctionTypeAlias_generic() {
2886 _assertSource(
2887 "typedef A F<B>();",
2888 AstFactory.typeAlias(
2889 AstFactory.typeName4("A"),
2890 "F",
2891 AstFactory.typeParameterList(["B"]),
2892 AstFactory.formalParameterList()));
2893 }
2894
2895 void test_visitFunctionTypeAlias_nonGeneric() {
2896 _assertSource(
2897 "typedef A F();",
2898 AstFactory.typeAlias(AstFactory.typeName4("A"), "F", null,
2899 AstFactory.formalParameterList()));
2900 }
2901
2902 void test_visitFunctionTypeAlias_withMetadata() {
2903 FunctionTypeAlias declaration = AstFactory.typeAlias(
2904 AstFactory.typeName4("A"), "F", null, AstFactory.formalParameterList());
2905 declaration.metadata
2906 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
2907 _assertSource("@deprecated typedef A F();", declaration);
2908 }
2909
2910 void test_visitFunctionTypedFormalParameter_noType() {
2911 _assertSource("f()", AstFactory.functionTypedFormalParameter(null, "f"));
2912 }
2913
2914 void test_visitFunctionTypedFormalParameter_annotation() {
2915 FunctionTypedFormalParameter parameter = AstFactory.functionTypedFormalParam eter(null, "f");
2916 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
2917 _assertSource('@A f()', parameter);
2918 }
2919
2920 void test_visitFunctionTypedFormalParameter_type() {
2921 _assertSource(
2922 "T f()",
2923 AstFactory.functionTypedFormalParameter(
2924 AstFactory.typeName4("T"), "f"));
2925 }
2926
2927 void test_visitFunctionTypedFormalParameter_typeParameters() {
2928 _assertSource(
2929 "T f<E>()",
2930 new FunctionTypedFormalParameter(
2931 null,
2932 null,
2933 AstFactory.typeName4("T"),
2934 AstFactory.identifier3('f'),
2935 AstFactory.typeParameterList(['E']),
2936 AstFactory.formalParameterList([])));
2937 }
2938
2939 void test_visitIfStatement_withElse() {
2940 _assertSource(
2941 "if (c) {} else {}",
2942 AstFactory.ifStatement2(AstFactory.identifier3("c"), AstFactory.block(),
2943 AstFactory.block()));
2944 }
2945
2946 void test_visitIfStatement_withoutElse() {
2947 _assertSource(
2948 "if (c) {}",
2949 AstFactory.ifStatement(
2950 AstFactory.identifier3("c"), AstFactory.block()));
2951 }
2952
2953 void test_visitImplementsClause_multiple() {
2954 _assertSource(
2955 "implements A, B",
2956 AstFactory.implementsClause(
2957 [AstFactory.typeName4("A"), AstFactory.typeName4("B")]));
2958 }
2959
2960 void test_visitImplementsClause_single() {
2961 _assertSource("implements A",
2962 AstFactory.implementsClause([AstFactory.typeName4("A")]));
2963 }
2964
2965 void test_visitImportDirective_combinator() {
2966 _assertSource(
2967 "import 'a.dart' show A;",
2968 AstFactory.importDirective3("a.dart", null, [
2969 AstFactory.showCombinator([AstFactory.identifier3("A")])
2970 ]));
2971 }
2972
2973 void test_visitImportDirective_combinators() {
2974 _assertSource(
2975 "import 'a.dart' show A hide B;",
2976 AstFactory.importDirective3("a.dart", null, [
2977 AstFactory.showCombinator([AstFactory.identifier3("A")]),
2978 AstFactory.hideCombinator([AstFactory.identifier3("B")])
2979 ]));
2980 }
2981
2982 void test_visitImportDirective_deferred() {
2983 _assertSource("import 'a.dart' deferred as p;",
2984 AstFactory.importDirective2("a.dart", true, "p"));
2985 }
2986
2987 void test_visitImportDirective_minimal() {
2988 _assertSource(
2989 "import 'a.dart';", AstFactory.importDirective3("a.dart", null));
2990 }
2991
2992 void test_visitImportDirective_prefix() {
2993 _assertSource(
2994 "import 'a.dart' as p;", AstFactory.importDirective3("a.dart", "p"));
2995 }
2996
2997 void test_visitImportDirective_prefix_combinator() {
2998 _assertSource(
2999 "import 'a.dart' as p show A;",
3000 AstFactory.importDirective3("a.dart", "p", [
3001 AstFactory.showCombinator([AstFactory.identifier3("A")])
3002 ]));
3003 }
3004
3005 void test_visitImportDirective_prefix_combinators() {
3006 _assertSource(
3007 "import 'a.dart' as p show A hide B;",
3008 AstFactory.importDirective3("a.dart", "p", [
3009 AstFactory.showCombinator([AstFactory.identifier3("A")]),
3010 AstFactory.hideCombinator([AstFactory.identifier3("B")])
3011 ]));
3012 }
3013
3014 void test_visitImportDirective_withMetadata() {
3015 ImportDirective directive = AstFactory.importDirective3("a.dart", null);
3016 directive.metadata
3017 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3018 _assertSource("@deprecated import 'a.dart';", directive);
3019 }
3020
3021 void test_visitImportHideCombinator_multiple() {
3022 _assertSource(
3023 "hide a, b",
3024 AstFactory.hideCombinator(
3025 [AstFactory.identifier3("a"), AstFactory.identifier3("b")]));
3026 }
3027
3028 void test_visitImportHideCombinator_single() {
3029 _assertSource(
3030 "hide a", AstFactory.hideCombinator([AstFactory.identifier3("a")]));
3031 }
3032
3033 void test_visitImportShowCombinator_multiple() {
3034 _assertSource(
3035 "show a, b",
3036 AstFactory.showCombinator(
3037 [AstFactory.identifier3("a"), AstFactory.identifier3("b")]));
3038 }
3039
3040 void test_visitImportShowCombinator_single() {
3041 _assertSource(
3042 "show a", AstFactory.showCombinator([AstFactory.identifier3("a")]));
3043 }
3044
3045 void test_visitIndexExpression() {
3046 _assertSource(
3047 "a[i]",
3048 AstFactory.indexExpression(
3049 AstFactory.identifier3("a"), AstFactory.identifier3("i")));
3050 }
3051
3052 void test_visitInstanceCreationExpression_const() {
3053 _assertSource(
3054 "const C()",
3055 AstFactory.instanceCreationExpression2(
3056 Keyword.CONST, AstFactory.typeName4("C")));
3057 }
3058
3059 void test_visitInstanceCreationExpression_named() {
3060 _assertSource(
3061 "new C.c()",
3062 AstFactory.instanceCreationExpression3(
3063 Keyword.NEW, AstFactory.typeName4("C"), "c"));
3064 }
3065
3066 void test_visitInstanceCreationExpression_unnamed() {
3067 _assertSource(
3068 "new C()",
3069 AstFactory.instanceCreationExpression2(
3070 Keyword.NEW, AstFactory.typeName4("C")));
3071 }
3072
3073 void test_visitIntegerLiteral() {
3074 _assertSource("42", AstFactory.integer(42));
3075 }
3076
3077 void test_visitInterpolationExpression_expression() {
3078 _assertSource("\${a}",
3079 AstFactory.interpolationExpression(AstFactory.identifier3("a")));
3080 }
3081
3082 void test_visitInterpolationExpression_identifier() {
3083 _assertSource("\$a", AstFactory.interpolationExpression2("a"));
3084 }
3085
3086 void test_visitInterpolationString() {
3087 _assertSource("'x", AstFactory.interpolationString("'x", "x"));
3088 }
3089
3090 void test_visitIsExpression_negated() {
3091 _assertSource(
3092 "a is! C",
3093 AstFactory.isExpression(
3094 AstFactory.identifier3("a"), true, AstFactory.typeName4("C")));
3095 }
3096
3097 void test_visitIsExpression_normal() {
3098 _assertSource(
3099 "a is C",
3100 AstFactory.isExpression(
3101 AstFactory.identifier3("a"), false, AstFactory.typeName4("C")));
3102 }
3103
3104 void test_visitLabel() {
3105 _assertSource("a:", AstFactory.label2("a"));
3106 }
3107
3108 void test_visitLabeledStatement_multiple() {
3109 _assertSource(
3110 "a: b: return;",
3111 AstFactory.labeledStatement(
3112 [AstFactory.label2("a"), AstFactory.label2("b")],
3113 AstFactory.returnStatement()));
3114 }
3115
3116 void test_visitLabeledStatement_single() {
3117 _assertSource(
3118 "a: return;",
3119 AstFactory.labeledStatement(
3120 [AstFactory.label2("a")], AstFactory.returnStatement()));
3121 }
3122
3123 void test_visitLibraryDirective() {
3124 _assertSource("library l;", AstFactory.libraryDirective2("l"));
3125 }
3126
3127 void test_visitLibraryDirective_withMetadata() {
3128 LibraryDirective directive = AstFactory.libraryDirective2("l");
3129 directive.metadata
3130 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3131 _assertSource("@deprecated library l;", directive);
3132 }
3133
3134 void test_visitLibraryIdentifier_multiple() {
3135 _assertSource(
3136 "a.b.c",
3137 AstFactory.libraryIdentifier([
3138 AstFactory.identifier3("a"),
3139 AstFactory.identifier3("b"),
3140 AstFactory.identifier3("c")
3141 ]));
3142 }
3143
3144 void test_visitLibraryIdentifier_single() {
3145 _assertSource(
3146 "a", AstFactory.libraryIdentifier([AstFactory.identifier3("a")]));
3147 }
3148
3149 void test_visitListLiteral_const() {
3150 _assertSource("const []", AstFactory.listLiteral2(Keyword.CONST, null));
3151 }
3152
3153 void test_visitListLiteral_empty() {
3154 _assertSource("[]", AstFactory.listLiteral());
3155 }
3156
3157 void test_visitListLiteral_nonEmpty() {
3158 _assertSource(
3159 "[a, b, c]",
3160 AstFactory.listLiteral([
3161 AstFactory.identifier3("a"),
3162 AstFactory.identifier3("b"),
3163 AstFactory.identifier3("c")
3164 ]));
3165 }
3166
3167 void test_visitMapLiteral_const() {
3168 _assertSource("const {}", AstFactory.mapLiteral(Keyword.CONST, null));
3169 }
3170
3171 void test_visitMapLiteral_empty() {
3172 _assertSource("{}", AstFactory.mapLiteral2());
3173 }
3174
3175 void test_visitMapLiteral_nonEmpty() {
3176 _assertSource(
3177 "{'a' : a, 'b' : b, 'c' : c}",
3178 AstFactory.mapLiteral2([
3179 AstFactory.mapLiteralEntry("a", AstFactory.identifier3("a")),
3180 AstFactory.mapLiteralEntry("b", AstFactory.identifier3("b")),
3181 AstFactory.mapLiteralEntry("c", AstFactory.identifier3("c"))
3182 ]));
3183 }
3184
3185 void test_visitMapLiteralEntry() {
3186 _assertSource("'a' : b",
3187 AstFactory.mapLiteralEntry("a", AstFactory.identifier3("b")));
3188 }
3189
3190 void test_visitMethodDeclaration_external() {
3191 _assertSource(
3192 "external m();",
3193 AstFactory.methodDeclaration(null, null, null, null,
3194 AstFactory.identifier3("m"), AstFactory.formalParameterList()));
3195 }
3196
3197 void test_visitMethodDeclaration_external_returnType() {
3198 _assertSource(
3199 "external T m();",
3200 AstFactory.methodDeclaration(
3201 null,
3202 AstFactory.typeName4("T"),
3203 null,
3204 null,
3205 AstFactory.identifier3("m"),
3206 AstFactory.formalParameterList()));
3207 }
3208
3209 void test_visitMethodDeclaration_getter() {
3210 _assertSource(
3211 "get m {}",
3212 AstFactory.methodDeclaration2(
3213 null,
3214 null,
3215 Keyword.GET,
3216 null,
3217 AstFactory.identifier3("m"),
3218 null,
3219 AstFactory.blockFunctionBody2()));
3220 }
3221
3222 void test_visitMethodDeclaration_getter_returnType() {
3223 _assertSource(
3224 "T get m {}",
3225 AstFactory.methodDeclaration2(
3226 null,
3227 AstFactory.typeName4("T"),
3228 Keyword.GET,
3229 null,
3230 AstFactory.identifier3("m"),
3231 null,
3232 AstFactory.blockFunctionBody2()));
3233 }
3234
3235 void test_visitMethodDeclaration_getter_seturnType() {
3236 _assertSource(
3237 "T set m(var v) {}",
3238 AstFactory.methodDeclaration2(
3239 null,
3240 AstFactory.typeName4("T"),
3241 Keyword.SET,
3242 null,
3243 AstFactory.identifier3("m"),
3244 AstFactory.formalParameterList(
3245 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]),
3246 AstFactory.blockFunctionBody2()));
3247 }
3248
3249 void test_visitMethodDeclaration_minimal() {
3250 _assertSource(
3251 "m() {}",
3252 AstFactory.methodDeclaration2(
3253 null,
3254 null,
3255 null,
3256 null,
3257 AstFactory.identifier3("m"),
3258 AstFactory.formalParameterList(),
3259 AstFactory.blockFunctionBody2()));
3260 }
3261
3262 void test_visitMethodDeclaration_multipleParameters() {
3263 _assertSource(
3264 "m(var a, var b) {}",
3265 AstFactory.methodDeclaration2(
3266 null,
3267 null,
3268 null,
3269 null,
3270 AstFactory.identifier3("m"),
3271 AstFactory.formalParameterList([
3272 AstFactory.simpleFormalParameter(Keyword.VAR, "a"),
3273 AstFactory.simpleFormalParameter(Keyword.VAR, "b")
3274 ]),
3275 AstFactory.blockFunctionBody2()));
3276 }
3277
3278 void test_visitMethodDeclaration_operator() {
3279 _assertSource(
3280 "operator +() {}",
3281 AstFactory.methodDeclaration2(
3282 null,
3283 null,
3284 null,
3285 Keyword.OPERATOR,
3286 AstFactory.identifier3("+"),
3287 AstFactory.formalParameterList(),
3288 AstFactory.blockFunctionBody2()));
3289 }
3290
3291 void test_visitMethodDeclaration_operator_returnType() {
3292 _assertSource(
3293 "T operator +() {}",
3294 AstFactory.methodDeclaration2(
3295 null,
3296 AstFactory.typeName4("T"),
3297 null,
3298 Keyword.OPERATOR,
3299 AstFactory.identifier3("+"),
3300 AstFactory.formalParameterList(),
3301 AstFactory.blockFunctionBody2()));
3302 }
3303
3304 void test_visitMethodDeclaration_returnType() {
3305 _assertSource(
3306 "T m() {}",
3307 AstFactory.methodDeclaration2(
3308 null,
3309 AstFactory.typeName4("T"),
3310 null,
3311 null,
3312 AstFactory.identifier3("m"),
3313 AstFactory.formalParameterList(),
3314 AstFactory.blockFunctionBody2()));
3315 }
3316
3317 void test_visitMethodDeclaration_setter() {
3318 _assertSource(
3319 "set m(var v) {}",
3320 AstFactory.methodDeclaration2(
3321 null,
3322 null,
3323 Keyword.SET,
3324 null,
3325 AstFactory.identifier3("m"),
3326 AstFactory.formalParameterList(
3327 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]),
3328 AstFactory.blockFunctionBody2()));
3329 }
3330
3331 void test_visitMethodDeclaration_static() {
3332 _assertSource(
3333 "static m() {}",
3334 AstFactory.methodDeclaration2(
3335 Keyword.STATIC,
3336 null,
3337 null,
3338 null,
3339 AstFactory.identifier3("m"),
3340 AstFactory.formalParameterList(),
3341 AstFactory.blockFunctionBody2()));
3342 }
3343
3344 void test_visitMethodDeclaration_static_returnType() {
3345 _assertSource(
3346 "static T m() {}",
3347 AstFactory.methodDeclaration2(
3348 Keyword.STATIC,
3349 AstFactory.typeName4("T"),
3350 null,
3351 null,
3352 AstFactory.identifier3("m"),
3353 AstFactory.formalParameterList(),
3354 AstFactory.blockFunctionBody2()));
3355 }
3356
3357 void test_visitMethodDeclaration_typeParameters() {
3358 _assertSource(
3359 "m<E>() {}",
3360 AstFactory.methodDeclaration3(
3361 null,
3362 null,
3363 null,
3364 null,
3365 AstFactory.identifier3("m"),
3366 AstFactory.typeParameterList(['E']),
3367 AstFactory.formalParameterList(),
3368 AstFactory.blockFunctionBody2()));
3369 }
3370
3371 void test_visitMethodDeclaration_withMetadata() {
3372 MethodDeclaration declaration = AstFactory.methodDeclaration2(
3373 null,
3374 null,
3375 null,
3376 null,
3377 AstFactory.identifier3("m"),
3378 AstFactory.formalParameterList(),
3379 AstFactory.blockFunctionBody2());
3380 declaration.metadata
3381 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3382 _assertSource("@deprecated m() {}", declaration);
3383 }
3384
3385 void test_visitMethodInvocation_conditional() {
3386 _assertSource(
3387 "t?.m()",
3388 AstFactory.methodInvocation(
3389 AstFactory.identifier3("t"), "m", null, TokenType.QUESTION_PERIOD));
3390 }
3391
3392 void test_visitMethodInvocation_noTarget() {
3393 _assertSource("m()", AstFactory.methodInvocation2("m"));
3394 }
3395
3396 void test_visitMethodInvocation_target() {
3397 _assertSource(
3398 "t.m()", AstFactory.methodInvocation(AstFactory.identifier3("t"), "m"));
3399 }
3400
3401 void test_visitMethodInvocation_typeArguments() {
3402 _assertSource(
3403 "m<A>()",
3404 AstFactory.methodInvocation3(null, "m",
3405 AstFactory.typeArgumentList([AstFactory.typeName4('A')])));
3406 }
3407
3408 void test_visitNamedExpression() {
3409 _assertSource(
3410 "a: b", AstFactory.namedExpression2("a", AstFactory.identifier3("b")));
3411 }
3412
3413 void test_visitNamedFormalParameter() {
3414 _assertSource(
3415 "var a : 0",
3416 AstFactory.namedFormalParameter(
3417 AstFactory.simpleFormalParameter(Keyword.VAR, "a"),
3418 AstFactory.integer(0)));
3419 }
3420
3421 void test_visitNativeClause() {
3422 _assertSource("native 'code'", AstFactory.nativeClause("code"));
3423 }
3424
3425 void test_visitNativeFunctionBody() {
3426 _assertSource("native 'str';", AstFactory.nativeFunctionBody("str"));
3427 }
3428
3429 void test_visitNullLiteral() {
3430 _assertSource("null", AstFactory.nullLiteral());
3431 }
3432
3433 void test_visitParenthesizedExpression() {
3434 _assertSource(
3435 "(a)", AstFactory.parenthesizedExpression(AstFactory.identifier3("a")));
3436 }
3437
3438 void test_visitPartDirective() {
3439 _assertSource("part 'a.dart';", AstFactory.partDirective2("a.dart"));
3440 }
3441
3442 void test_visitPartDirective_withMetadata() {
3443 PartDirective directive = AstFactory.partDirective2("a.dart");
3444 directive.metadata
3445 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3446 _assertSource("@deprecated part 'a.dart';", directive);
3447 }
3448
3449 void test_visitPartOfDirective() {
3450 _assertSource("part of l;",
3451 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"])));
3452 }
3453
3454 void test_visitPartOfDirective_withMetadata() {
3455 PartOfDirective directive =
3456 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"]));
3457 directive.metadata
3458 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3459 _assertSource("@deprecated part of l;", directive);
3460 }
3461
3462 void test_visitPositionalFormalParameter() {
3463 _assertSource(
3464 "var a = 0",
3465 AstFactory.positionalFormalParameter(
3466 AstFactory.simpleFormalParameter(Keyword.VAR, "a"),
3467 AstFactory.integer(0)));
3468 }
3469
3470 void test_visitPostfixExpression() {
3471 _assertSource(
3472 "a++",
3473 AstFactory.postfixExpression(
3474 AstFactory.identifier3("a"), TokenType.PLUS_PLUS));
3475 }
3476
3477 void test_visitPrefixedIdentifier() {
3478 _assertSource("a.b", AstFactory.identifier5("a", "b"));
3479 }
3480
3481 void test_visitPrefixExpression() {
3482 _assertSource(
3483 "-a",
3484 AstFactory.prefixExpression(
3485 TokenType.MINUS, AstFactory.identifier3("a")));
3486 }
3487
3488 void test_visitPropertyAccess() {
3489 _assertSource(
3490 "a.b", AstFactory.propertyAccess2(AstFactory.identifier3("a"), "b"));
3491 }
3492
3493 void test_visitPropertyAccess_conditional() {
3494 _assertSource(
3495 "a?.b",
3496 AstFactory.propertyAccess2(
3497 AstFactory.identifier3("a"), "b", TokenType.QUESTION_PERIOD));
3498 }
3499
3500 void test_visitRedirectingConstructorInvocation_named() {
3501 _assertSource(
3502 "this.c()", AstFactory.redirectingConstructorInvocation2("c"));
3503 }
3504
3505 void test_visitRedirectingConstructorInvocation_unnamed() {
3506 _assertSource("this()", AstFactory.redirectingConstructorInvocation());
3507 }
3508
3509 void test_visitRethrowExpression() {
3510 _assertSource("rethrow", AstFactory.rethrowExpression());
3511 }
3512
3513 void test_visitReturnStatement_expression() {
3514 _assertSource(
3515 "return a;", AstFactory.returnStatement2(AstFactory.identifier3("a")));
3516 }
3517
3518 void test_visitReturnStatement_noExpression() {
3519 _assertSource("return;", AstFactory.returnStatement());
3520 }
3521
3522 void test_visitScriptTag() {
3523 String scriptTag = "!#/bin/dart.exe";
3524 _assertSource(scriptTag, AstFactory.scriptTag(scriptTag));
3525 }
3526
3527 void test_visitSimpleFormalParameter_keyword() {
3528 _assertSource("var a", AstFactory.simpleFormalParameter(Keyword.VAR, "a"));
3529 }
3530
3531 void test_visitSimpleFormalParameter_keyword_type() {
3532 _assertSource(
3533 "final A a",
3534 AstFactory.simpleFormalParameter2(
3535 Keyword.FINAL, AstFactory.typeName4("A"), "a"));
3536 }
3537
3538 void test_visitSimpleFormalParameter_type() {
3539 _assertSource("A a",
3540 AstFactory.simpleFormalParameter4(AstFactory.typeName4("A"), "a"));
3541 }
3542
3543 void test_visitSimpleFormalParameter_annotation() {
3544 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3('x');
3545 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
3546 _assertSource('@A x', parameter);
3547 }
3548
3549 void test_visitSimpleIdentifier() {
3550 _assertSource("a", AstFactory.identifier3("a"));
3551 }
3552
3553 void test_visitSimpleStringLiteral() {
3554 _assertSource("'a'", AstFactory.string2("a"));
3555 }
3556
3557 void test_visitStringInterpolation() {
3558 _assertSource(
3559 "'a\${e}b'",
3560 AstFactory.string([
3561 AstFactory.interpolationString("'a", "a"),
3562 AstFactory.interpolationExpression(AstFactory.identifier3("e")),
3563 AstFactory.interpolationString("b'", "b")
3564 ]));
3565 }
3566
3567 void test_visitSuperConstructorInvocation() {
3568 _assertSource("super()", AstFactory.superConstructorInvocation());
3569 }
3570
3571 void test_visitSuperConstructorInvocation_named() {
3572 _assertSource("super.c()", AstFactory.superConstructorInvocation2("c"));
3573 }
3574
3575 void test_visitSuperExpression() {
3576 _assertSource("super", AstFactory.superExpression());
3577 }
3578
3579 void test_visitSwitchCase_multipleLabels() {
3580 _assertSource(
3581 "l1: l2: case a: {}",
3582 AstFactory.switchCase2(
3583 [AstFactory.label2("l1"), AstFactory.label2("l2")],
3584 AstFactory.identifier3("a"),
3585 [AstFactory.block()]));
3586 }
3587
3588 void test_visitSwitchCase_multipleStatements() {
3589 _assertSource(
3590 "case a: {} {}",
3591 AstFactory.switchCase(AstFactory.identifier3("a"),
3592 [AstFactory.block(), AstFactory.block()]));
3593 }
3594
3595 void test_visitSwitchCase_noLabels() {
3596 _assertSource(
3597 "case a: {}",
3598 AstFactory.switchCase(
3599 AstFactory.identifier3("a"), [AstFactory.block()]));
3600 }
3601
3602 void test_visitSwitchCase_singleLabel() {
3603 _assertSource(
3604 "l1: case a: {}",
3605 AstFactory.switchCase2([AstFactory.label2("l1")],
3606 AstFactory.identifier3("a"), [AstFactory.block()]));
3607 }
3608
3609 void test_visitSwitchDefault_multipleLabels() {
3610 _assertSource(
3611 "l1: l2: default: {}",
3612 AstFactory.switchDefault(
3613 [AstFactory.label2("l1"), AstFactory.label2("l2")],
3614 [AstFactory.block()]));
3615 }
3616
3617 void test_visitSwitchDefault_multipleStatements() {
3618 _assertSource("default: {} {}",
3619 AstFactory.switchDefault2([AstFactory.block(), AstFactory.block()]));
3620 }
3621
3622 void test_visitSwitchDefault_noLabels() {
3623 _assertSource(
3624 "default: {}", AstFactory.switchDefault2([AstFactory.block()]));
3625 }
3626
3627 void test_visitSwitchDefault_singleLabel() {
3628 _assertSource(
3629 "l1: default: {}",
3630 AstFactory.switchDefault(
3631 [AstFactory.label2("l1")], [AstFactory.block()]));
3632 }
3633
3634 void test_visitSwitchStatement() {
3635 _assertSource(
3636 "switch (a) {case 'b': {} default: {}}",
3637 AstFactory.switchStatement(AstFactory.identifier3("a"), [
3638 AstFactory.switchCase(AstFactory.string2("b"), [AstFactory.block()]),
3639 AstFactory.switchDefault2([AstFactory.block()])
3640 ]));
3641 }
3642
3643 void test_visitSymbolLiteral_multiple() {
3644 _assertSource("#a.b.c", AstFactory.symbolLiteral(["a", "b", "c"]));
3645 }
3646
3647 void test_visitSymbolLiteral_single() {
3648 _assertSource("#a", AstFactory.symbolLiteral(["a"]));
3649 }
3650
3651 void test_visitThisExpression() {
3652 _assertSource("this", AstFactory.thisExpression());
3653 }
3654
3655 void test_visitThrowStatement() {
3656 _assertSource(
3657 "throw e", AstFactory.throwExpression2(AstFactory.identifier3("e")));
3658 }
3659
3660 void test_visitTopLevelVariableDeclaration_multiple() {
3661 _assertSource(
3662 "var a;",
3663 AstFactory.topLevelVariableDeclaration2(
3664 Keyword.VAR, [AstFactory.variableDeclaration("a")]));
3665 }
3666
3667 void test_visitTopLevelVariableDeclaration_single() {
3668 _assertSource(
3669 "var a, b;",
3670 AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [
3671 AstFactory.variableDeclaration("a"),
3672 AstFactory.variableDeclaration("b")
3673 ]));
3674 }
3675
3676 void test_visitTryStatement_catch() {
3677 _assertSource(
3678 "try {} on E {}",
3679 AstFactory.tryStatement2(AstFactory.block(),
3680 [AstFactory.catchClause3(AstFactory.typeName4("E"))]));
3681 }
3682
3683 void test_visitTryStatement_catches() {
3684 _assertSource(
3685 "try {} on E {} on F {}",
3686 AstFactory.tryStatement2(AstFactory.block(), [
3687 AstFactory.catchClause3(AstFactory.typeName4("E")),
3688 AstFactory.catchClause3(AstFactory.typeName4("F"))
3689 ]));
3690 }
3691
3692 void test_visitTryStatement_catchFinally() {
3693 _assertSource(
3694 "try {} on E {} finally {}",
3695 AstFactory.tryStatement3(
3696 AstFactory.block(),
3697 [AstFactory.catchClause3(AstFactory.typeName4("E"))],
3698 AstFactory.block()));
3699 }
3700
3701 void test_visitTryStatement_finally() {
3702 _assertSource("try {} finally {}",
3703 AstFactory.tryStatement(AstFactory.block(), AstFactory.block()));
3704 }
3705
3706 void test_visitTypeArgumentList_multiple() {
3707 _assertSource(
3708 "<E, F>",
3709 AstFactory.typeArgumentList(
3710 [AstFactory.typeName4("E"), AstFactory.typeName4("F")]));
3711 }
3712
3713 void test_visitTypeArgumentList_single() {
3714 _assertSource(
3715 "<E>", AstFactory.typeArgumentList([AstFactory.typeName4("E")]));
3716 }
3717
3718 void test_visitTypeName_multipleArgs() {
3719 _assertSource(
3720 "C<D, E>",
3721 AstFactory.typeName4(
3722 "C", [AstFactory.typeName4("D"), AstFactory.typeName4("E")]));
3723 }
3724
3725 void test_visitTypeName_nestedArg() {
3726 _assertSource(
3727 "C<D<E>>",
3728 AstFactory.typeName4("C", [
3729 AstFactory.typeName4("D", [AstFactory.typeName4("E")])
3730 ]));
3731 }
3732
3733 void test_visitTypeName_noArgs() {
3734 _assertSource("C", AstFactory.typeName4("C"));
3735 }
3736
3737 void test_visitTypeName_singleArg() {
3738 _assertSource(
3739 "C<D>", AstFactory.typeName4("C", [AstFactory.typeName4("D")]));
3740 }
3741
3742 void test_visitTypeParameter_withExtends() {
3743 _assertSource("E extends C",
3744 AstFactory.typeParameter2("E", AstFactory.typeName4("C")));
3745 }
3746
3747 void test_visitTypeParameter_withMetadata() {
3748 TypeParameter parameter = AstFactory.typeParameter("E");
3749 parameter.metadata
3750 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3751 _assertSource("@deprecated E", parameter);
3752 }
3753
3754 void test_visitTypeParameter_withoutExtends() {
3755 _assertSource("E", AstFactory.typeParameter("E"));
3756 }
3757
3758 void test_visitTypeParameterList_multiple() {
3759 _assertSource("<E, F>", AstFactory.typeParameterList(["E", "F"]));
3760 }
3761
3762 void test_visitTypeParameterList_single() {
3763 _assertSource("<E>", AstFactory.typeParameterList(["E"]));
3764 }
3765
3766 void test_visitVariableDeclaration_initialized() {
3767 _assertSource("a = b",
3768 AstFactory.variableDeclaration2("a", AstFactory.identifier3("b")));
3769 }
3770
3771 void test_visitVariableDeclaration_uninitialized() {
3772 _assertSource("a", AstFactory.variableDeclaration("a"));
3773 }
3774
3775 void test_visitVariableDeclaration_withMetadata() {
3776 VariableDeclaration declaration = AstFactory.variableDeclaration("a");
3777 declaration.metadata
3778 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3779 _assertSource("@deprecated a", declaration);
3780 }
3781
3782 void test_visitVariableDeclarationList_const_type() {
3783 _assertSource(
3784 "const C a, b",
3785 AstFactory.variableDeclarationList(
3786 Keyword.CONST, AstFactory.typeName4("C"), [
3787 AstFactory.variableDeclaration("a"),
3788 AstFactory.variableDeclaration("b")
3789 ]));
3790 }
3791
3792 void test_visitVariableDeclarationList_final_noType() {
3793 _assertSource(
3794 "final a, b",
3795 AstFactory.variableDeclarationList2(Keyword.FINAL, [
3796 AstFactory.variableDeclaration("a"),
3797 AstFactory.variableDeclaration("b")
3798 ]));
3799 }
3800
3801 void test_visitVariableDeclarationList_final_withMetadata() {
3802 VariableDeclarationList declarationList = AstFactory
3803 .variableDeclarationList2(Keyword.FINAL, [
3804 AstFactory.variableDeclaration("a"),
3805 AstFactory.variableDeclaration("b")
3806 ]);
3807 declarationList.metadata
3808 .add(AstFactory.annotation(AstFactory.identifier3("deprecated")));
3809 _assertSource("@deprecated final a, b", declarationList);
3810 }
3811
3812 void test_visitVariableDeclarationList_type() {
3813 _assertSource(
3814 "C a, b",
3815 AstFactory.variableDeclarationList(null, AstFactory.typeName4("C"), [
3816 AstFactory.variableDeclaration("a"),
3817 AstFactory.variableDeclaration("b")
3818 ]));
3819 }
3820
3821 void test_visitVariableDeclarationList_var() {
3822 _assertSource(
3823 "var a, b",
3824 AstFactory.variableDeclarationList2(Keyword.VAR, [
3825 AstFactory.variableDeclaration("a"),
3826 AstFactory.variableDeclaration("b")
3827 ]));
3828 }
3829
3830 void test_visitVariableDeclarationStatement() {
3831 _assertSource(
3832 "C c;",
3833 AstFactory.variableDeclarationStatement(null, AstFactory.typeName4("C"),
3834 [AstFactory.variableDeclaration("c")]));
3835 }
3836
3837 void test_visitWhileStatement() {
3838 _assertSource(
3839 "while (c) {}",
3840 AstFactory.whileStatement(
3841 AstFactory.identifier3("c"), AstFactory.block()));
3842 }
3843
3844 void test_visitWithClause_multiple() {
3845 _assertSource(
3846 "with A, B, C",
3847 AstFactory.withClause([
3848 AstFactory.typeName4("A"),
3849 AstFactory.typeName4("B"),
3850 AstFactory.typeName4("C")
3851 ]));
3852 }
3853
3854 void test_visitWithClause_single() {
3855 _assertSource("with A", AstFactory.withClause([AstFactory.typeName4("A")]));
3856 }
3857
3858 void test_visitYieldStatement() {
3859 _assertSource(
3860 "yield e;", AstFactory.yieldStatement(AstFactory.identifier3("e")));
3861 }
3862
3863 void test_visitYieldStatement_each() {
3864 _assertSource("yield* e;",
3865 AstFactory.yieldEachStatement(AstFactory.identifier3("e")));
3866 }
3867
3868 /**
3869 * Assert that a `ToSourceVisitor` will produce the expected source when visit ing the given
3870 * node.
3871 *
3872 * @param expectedSource the source string that the visitor is expected to pro duce
3873 * @param node the AST node being visited to produce the actual source
3874 * @throws AFE if the visitor does not produce the expected source for the giv en node
3875 */
3876 void _assertSource(String expectedSource, AstNode node) {
3877 PrintStringWriter writer = new PrintStringWriter();
3878 node.accept(new ToSourceVisitor(writer));
3879 expect(writer.toString(), expectedSource);
3880 }
3881 }
3882
3883 @reflectiveTest
3884 class VariableDeclarationTest extends ParserTestCase {
3885 void test_getDocumentationComment_onGrandParent() {
3886 VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
3887 TopLevelVariableDeclaration decl =
3888 AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [varDecl]);
3889 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
3890 expect(varDecl.documentationComment, isNull);
3891 decl.documentationComment = comment;
3892 expect(varDecl.documentationComment, isNotNull);
3893 expect(decl.documentationComment, isNotNull);
3894 }
3895
3896 void test_getDocumentationComment_onNode() {
3897 VariableDeclaration decl = AstFactory.variableDeclaration("a");
3898 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
3899 decl.documentationComment = comment;
3900 expect(decl.documentationComment, isNotNull);
3901 }
3902 }
3903
3904 class WrapperKind extends Enum<WrapperKind> {
3905 static const WrapperKind PREFIXED_LEFT =
3906 const WrapperKind('PREFIXED_LEFT', 0);
3907
3908 static const WrapperKind PREFIXED_RIGHT =
3909 const WrapperKind('PREFIXED_RIGHT', 1);
3910
3911 static const WrapperKind PROPERTY_LEFT =
3912 const WrapperKind('PROPERTY_LEFT', 2);
3913
3914 static const WrapperKind PROPERTY_RIGHT =
3915 const WrapperKind('PROPERTY_RIGHT', 3);
3916
3917 static const WrapperKind NONE = const WrapperKind('NONE', 4);
3918
3919 static const List<WrapperKind> values = const [
3920 PREFIXED_LEFT,
3921 PREFIXED_RIGHT,
3922 PROPERTY_LEFT,
3923 PROPERTY_RIGHT,
3924 NONE
3925 ];
3926
3927 const WrapperKind(String name, int ordinal) : super(name, ordinal);
3928 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/generated/analysis_context_factory.dart ('k') | packages/analyzer/test/generated/bazel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698